Explorar el Código

需求红包消耗统计: 清除看课记录备份记录优化

wangxy hace 6 días
padre
commit
a98fb6f6a3

+ 1 - 1
fs-company-app/src/main/java/com/fs/app/controller/UserController.java

@@ -166,7 +166,7 @@ public class UserController extends AppBaseController {
         try {
 
             //判断用户基本规则
-            CompanyUser companyUser = userService.selectUserByUserName(param.getAccount());
+            CompanyUser companyUser = userService.selectUserByUserName(param.getAccount().trim());
             if (companyUser == null) {
                 return R.error("工号不存在");
             }

+ 53 - 34
fs-company/src/main/java/com/fs/company/controller/course/FsCourseRedPacketLogController.java

@@ -11,10 +11,12 @@ import com.fs.common.core.page.TableDataInfo;
 import com.fs.common.enums.BusinessType;
 import com.fs.common.utils.ServletUtils;
 import com.fs.common.utils.poi.ExcelUtil;
+import com.fs.company.vo.RedPacketMoneyVO;
 import com.fs.course.config.CourseConfig;
 import com.fs.course.domain.FsCourseRedPacketLog;
 import com.fs.course.mapper.FsUserCourseMapper;
 import com.fs.course.mapper.FsUserCourseVideoMapper;
+import com.fs.course.param.CourseRedPacketStatisticsParam;
 import com.fs.course.param.FsCourseRedPacketLogParam;
 import com.fs.course.service.IFsCourseRedPacketLogService;
 import com.fs.course.vo.FsCourseRedPacketLogListPVO;
@@ -39,8 +41,7 @@ import static com.fs.his.utils.PhoneUtil.encryptPhone;
  */
 @RestController
 @RequestMapping("/course/courseRedPacketLog")
-public class FsCourseRedPacketLogController extends BaseController
-{
+public class FsCourseRedPacketLogController extends BaseController {
     @Autowired
     private IFsCourseRedPacketLogService fsCourseRedPacketLogService;
     @Autowired
@@ -51,13 +52,13 @@ public class FsCourseRedPacketLogController extends BaseController
     private TokenService tokenService;
     @Autowired
     private ISysConfigService configService;
+
     /**
      * 查询短链课程看课记录列表
      */
     @PreAuthorize("@ss.hasPermi('course:courseRedPacketLog:list')")
     @GetMapping("/list")
-    public TableDataInfo list(FsCourseRedPacketLogParam fsCourseRedPacketLog)
-    {
+    public TableDataInfo list(FsCourseRedPacketLogParam fsCourseRedPacketLog) {
         startPage();
         if (fsCourseRedPacketLog.getPhoneMk() != null && fsCourseRedPacketLog.getPhoneMk() != "") {
             fsCourseRedPacketLog.setPhone(encryptPhone(fsCourseRedPacketLog.getPhoneMk()));
@@ -67,8 +68,8 @@ public class FsCourseRedPacketLogController extends BaseController
         Long userId = loginUser.getUser().getUserId();
         String json = configService.selectConfigByKey("course.config");
         CourseConfig config = JSONUtil.toBean(json, CourseConfig.class);
-        if (ObjectUtil.isNotEmpty(config.getIsBound())&&config.getIsBound()){
-            fsCourseRedPacketLog.setCompanyId( loginUser.getCompany().getCompanyId());
+        if (ObjectUtil.isNotEmpty(config.getIsBound()) && config.getIsBound()) {
+            fsCourseRedPacketLog.setCompanyId(loginUser.getCompany().getCompanyId());
         }
 
         List<FsCourseRedPacketLogListPVO> list = fsCourseRedPacketLogService.selectFsCourseRedPacketLogListVO(fsCourseRedPacketLog);
@@ -84,11 +85,10 @@ public class FsCourseRedPacketLogController extends BaseController
      */
     @PreAuthorize("@ss.hasPermi('course:courseRedPacketLog:myList')")
     @GetMapping("/myList")
-    public TableDataInfo myList(FsCourseRedPacketLogParam fsCourseRedPacketLog)
-    {
+    public TableDataInfo myList(FsCourseRedPacketLogParam fsCourseRedPacketLog) {
         startPage();
         LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
-        fsCourseRedPacketLog.setCompanyId( loginUser.getCompany().getCompanyId());
+        fsCourseRedPacketLog.setCompanyId(loginUser.getCompany().getCompanyId());
         //fsCourseRedPacketLog.setCompanyUserId(loginUser.getUser().getUserId());
         if (fsCourseRedPacketLog.getPhoneMk() != null && fsCourseRedPacketLog.getPhoneMk() != "") {
             fsCourseRedPacketLog.setPhone(encryptPhone(fsCourseRedPacketLog.getPhoneMk()));
@@ -103,11 +103,10 @@ public class FsCourseRedPacketLogController extends BaseController
 
     @PreAuthorize("@ss.hasPermi('course:courseRedPacketLog:myList')")
     @GetMapping("/myListNew")
-    public TableDataInfo myListNew(FsCourseRedPacketLogParam fsCourseRedPacketLog)
-    {
+    public TableDataInfo myListNew(FsCourseRedPacketLogParam fsCourseRedPacketLog) {
         startPage();
         LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
-        fsCourseRedPacketLog.setCompanyId( loginUser.getCompany().getCompanyId());
+        fsCourseRedPacketLog.setCompanyId(loginUser.getCompany().getCompanyId());
 
         if (fsCourseRedPacketLog.getPhoneMk() != null && fsCourseRedPacketLog.getPhoneMk() != "") {
             fsCourseRedPacketLog.setPhone(encryptPhone(fsCourseRedPacketLog.getPhoneMk()));
@@ -126,12 +125,11 @@ public class FsCourseRedPacketLogController extends BaseController
     @PreAuthorize("@ss.hasPermi('course:courseRedPacketLog:export')")
     @Log(title = "短链课程看课记录", businessType = BusinessType.EXPORT)
     @GetMapping("/export")
-    public AjaxResult export(FsCourseRedPacketLogParam fsCourseRedPacketLog)
-    {
+    public AjaxResult export(FsCourseRedPacketLogParam fsCourseRedPacketLog) {
 //        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
 //        fsCourseRedPacketLog.setCompanyId( loginUser.getCompany().getCompanyId());
 
-        if (fsCourseRedPacketLog.getPhoneMk()!=null&&fsCourseRedPacketLog.getPhoneMk()!=""){
+        if (fsCourseRedPacketLog.getPhoneMk() != null && fsCourseRedPacketLog.getPhoneMk() != "") {
             fsCourseRedPacketLog.setPhone(encryptPhone(fsCourseRedPacketLog.getPhoneMk()));
         }
         List<FsCourseRedPacketLogListPVO> list = fsCourseRedPacketLogService.selectFsCourseRedPacketLogListVO(fsCourseRedPacketLog);
@@ -142,18 +140,18 @@ public class FsCourseRedPacketLogController extends BaseController
         ExcelUtil<FsCourseRedPacketLogListPVO> util = new ExcelUtil<FsCourseRedPacketLogListPVO>(FsCourseRedPacketLogListPVO.class);
         return util.exportExcel(list, "短链课程看课记录数据");
     }
+
     /**
      * 导出短链课程看课记录列表
      */
     @PreAuthorize("@ss.hasPermi('course:courseRedPacketLog:myExport')")
     @Log(title = "短链课程看课记录", businessType = BusinessType.EXPORT)
     @GetMapping("/myExport")
-    public AjaxResult myExport(FsCourseRedPacketLogParam fsCourseRedPacketLog)
-    {
+    public AjaxResult myExport(FsCourseRedPacketLogParam fsCourseRedPacketLog) {
         LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
-        fsCourseRedPacketLog.setCompanyId( loginUser.getCompany().getCompanyId());
+        fsCourseRedPacketLog.setCompanyId(loginUser.getCompany().getCompanyId());
 
-        if (fsCourseRedPacketLog.getPhoneMk()!=null&&fsCourseRedPacketLog.getPhoneMk()!=""){
+        if (fsCourseRedPacketLog.getPhoneMk() != null && fsCourseRedPacketLog.getPhoneMk() != "") {
             fsCourseRedPacketLog.setPhone(encryptPhone(fsCourseRedPacketLog.getPhoneMk()));
         }
         List<FsCourseRedPacketLogListPVO> list = fsCourseRedPacketLogService.selectFsCourseRedPacketLogListVO(fsCourseRedPacketLog);
@@ -170,8 +168,7 @@ public class FsCourseRedPacketLogController extends BaseController
      */
     @PreAuthorize("@ss.hasPermi('course:courseRedPacketLog:query')")
     @GetMapping(value = "/{logId}")
-    public AjaxResult getInfo(@PathVariable("logId") Long logId)
-    {
+    public AjaxResult getInfo(@PathVariable("logId") Long logId) {
         return AjaxResult.success(fsCourseRedPacketLogService.selectFsCourseRedPacketLogByLogId(logId));
     }
 
@@ -181,8 +178,7 @@ public class FsCourseRedPacketLogController extends BaseController
     @PreAuthorize("@ss.hasPermi('course:courseRedPacketLog:add')")
     @Log(title = "短链课程看课记录", businessType = BusinessType.INSERT)
     @PostMapping
-    public AjaxResult add(@RequestBody FsCourseRedPacketLog fsCourseRedPacketLog)
-    {
+    public AjaxResult add(@RequestBody FsCourseRedPacketLog fsCourseRedPacketLog) {
         return toAjax(fsCourseRedPacketLogService.insertFsCourseRedPacketLog(fsCourseRedPacketLog));
     }
 
@@ -192,8 +188,7 @@ public class FsCourseRedPacketLogController extends BaseController
     @PreAuthorize("@ss.hasPermi('course:courseRedPacketLog:edit')")
     @Log(title = "短链课程看课记录", businessType = BusinessType.UPDATE)
     @PutMapping
-    public AjaxResult edit(@RequestBody FsCourseRedPacketLog fsCourseRedPacketLog)
-    {
+    public AjaxResult edit(@RequestBody FsCourseRedPacketLog fsCourseRedPacketLog) {
         return toAjax(fsCourseRedPacketLogService.updateFsCourseRedPacketLog(fsCourseRedPacketLog));
     }
 
@@ -202,9 +197,8 @@ public class FsCourseRedPacketLogController extends BaseController
      */
     @PreAuthorize("@ss.hasPermi('course:courseRedPacketLog:remove')")
     @Log(title = "短链课程看课记录", businessType = BusinessType.DELETE)
-	@DeleteMapping("/{logIds}")
-    public AjaxResult remove(@PathVariable Long[] logIds)
-    {
+    @DeleteMapping("/{logIds}")
+    public AjaxResult remove(@PathVariable Long[] logIds) {
         return toAjax(fsCourseRedPacketLogService.deleteFsCourseRedPacketLogByLogIds(logIds));
     }
 
@@ -216,14 +210,12 @@ public class FsCourseRedPacketLogController extends BaseController
     @Log(title = "短链课程看课记录", businessType = BusinessType.DELETE)
     @PutMapping("/retryCourseRedPacketLog/{logIds}")
     @RepeatSubmit
-    public R retryCourseRedPacketLog(@PathVariable Long[] logIds)
-    {
+    public R retryCourseRedPacketLog(@PathVariable Long[] logIds) {
         return fsCourseRedPacketLogService.retryCourseRedPacketLog(logIds);
     }
 
     @GetMapping("/courseList")
-    public R courseList()
-    {
+    public R courseList() {
 
         LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
         List<OptionsVO> optionsVOS = fsUserCourseMapper.selectFsUserCourseByCompany(loginUser.getCompany().getCompanyId());
@@ -231,9 +223,36 @@ public class FsCourseRedPacketLogController extends BaseController
     }
 
     @GetMapping(value = "/videoList/{id}")
-    public R videoList(@PathVariable("id") Long id)
-    {
+    public R videoList(@PathVariable("id") Long id) {
         List<OptionsVO> optionsVOS = fsUserCourseVideoMapper.selectFsUserCourseVodeAllList(id);
         return R.ok().put("list", optionsVOS);
     }
+
+    /**
+     * 项目红包消耗统计列表
+     */
+    @PreAuthorize("@ss.hasPermi('course:courseRedPacketLog:moneyList')")
+    @GetMapping("/getProjectRedPacketMoney")
+    public TableDataInfo getProjectRedPacketMoney(CourseRedPacketStatisticsParam param) {
+        startPage();
+        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
+        param.setCompanyId(loginUser.getCompany().getCompanyId());
+        List<RedPacketMoneyVO> list = fsCourseRedPacketLogService.getProjectRedPacketMoney(param);
+        return getDataTable(list);
+    }
+
+    /**
+     * 导出项目红包消耗统计列表
+     *
+     */
+    @PreAuthorize("@ss.hasPermi('course:courseRedPacketLog:exportMoneyList')")
+    @GetMapping("/exportMoneyList")
+    public AjaxResult exportMoneyList(CourseRedPacketStatisticsParam param) {
+        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
+        param.setCompanyId(loginUser.getCompany().getCompanyId());
+        List<RedPacketMoneyVO> list = fsCourseRedPacketLogService.getProjectRedPacketMoney(param);
+        ExcelUtil<RedPacketMoneyVO> util = new ExcelUtil<RedPacketMoneyVO>(RedPacketMoneyVO.class);
+        return util.exportExcel(list, "项目红包消耗统计数据");
+    }
+
 }

+ 7 - 0
fs-service/src/main/java/com/fs/company/vo/RedPacketMoneyVO.java

@@ -1,5 +1,6 @@
 package com.fs.company.vo;
 
+import com.fs.common.annotation.Excel;
 import lombok.Data;
 
 import java.math.BigDecimal;
@@ -8,5 +9,11 @@ import java.math.BigDecimal;
 public class RedPacketMoneyVO {
    Long companyId;
 
+   @Excel(name = "红包金额")
    BigDecimal money;
+
+   private  Long  projectId;
+
+   @Excel(name = "项目名称")
+   private  String projectName;
 }

+ 56 - 0
fs-service/src/main/java/com/fs/course/domain/WatchLogBak.java

@@ -0,0 +1,56 @@
+package com.fs.course.domain;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+import lombok.Data;
+
+import java.time.LocalDate;
+import java.time.LocalDateTime;
+import java.util.Date;
+
+@Data
+public class WatchLogBak {
+
+    @TableId(type = IdType.AUTO)
+    private Long backupId;
+
+    // 原始数据字段
+    private Long originalLogId;
+    private Long userId;
+    private Long videoId;
+    private Integer logType;
+    private Date createTime;
+    private Date updateTime;
+    private Long qwExternalContactId;
+    private Long duration;
+    private Long qwUserId;
+    private Long companyUserId;
+    private Long companyId;
+    private Long courseId;
+    private Integer sendType;
+    private Integer rewardType;
+    private LocalDateTime lastHeartbeatTime;
+    private String sopId;
+    private Date finishTime;
+    private Integer sendFinishMsg;
+    private Date campPeriodTime;
+    private Long day;
+    private Long project;
+    private String createBy;
+    private String updateBy;
+    private Long periodId;
+    private Integer projectId;
+    private Long imMsgSendDetailId;
+    private Integer watchType;
+
+    // 删除相关字段
+    private Date deleteTime;
+    private Long  deleteBy;
+    private Integer deleteMethod = 1; // 1手动删除 2自动清理
+    private String originalData; // JSON格式的完整原始数据
+
+    // 备份相关字段
+    private String backupOperator;
+    private String backupBatchNo;
+    private String remark;
+}

+ 7 - 0
fs-service/src/main/java/com/fs/course/mapper/FsCourseRedPacketLogMapper.java

@@ -186,4 +186,11 @@ public interface FsCourseRedPacketLogMapper
      */
     @Select("select * from fs_course_red_packet_log where status = 0 and batch_id is not null and create_time >= #{startTime} and create_time <= #{endTime}")
     List<FsCourseRedPacketLog> selectRedPacketLogListByCreateTime(@Param("startTime") LocalDateTime startTime, @Param("endTime") LocalDateTime endTime);
+
+    /**
+     * 项目维度的红包消耗统计
+     * @param param
+     * @return
+     */
+    List<RedPacketMoneyVO> selectMoneyByProject(CourseRedPacketStatisticsParam param);
 }

+ 12 - 0
fs-service/src/main/java/com/fs/course/mapper/FsCourseWatchLogMapper.java

@@ -2,6 +2,7 @@ package com.fs.course.mapper;
 
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.fs.course.domain.FsCourseWatchLog;
+import com.fs.course.domain.WatchLogBak;
 import com.fs.course.dto.WatchLogDTO;
 import com.fs.course.param.*;
 import com.fs.course.vo.*;
@@ -72,6 +73,16 @@ public interface FsCourseWatchLogMapper extends BaseMapper<FsCourseWatchLog> {
      */
     public int insertFsCourseWatchLog(FsCourseWatchLog fsCourseWatchLog);
 
+    /**
+     * 新增短链课程看课记录备份
+     *
+     * @param watchLogBak 短链课程看课记录备份
+     * @return 结果
+     */
+    int insertBackup(WatchLogBak watchLogBak);
+
+
+
     public int insertOrUpdateFsCourseWatchLog(FsCourseWatchLog fsCourseWatchLog);
 
     /**
@@ -242,6 +253,7 @@ public interface FsCourseWatchLogMapper extends BaseMapper<FsCourseWatchLog> {
             "v.title videoName,uc.course_name,\n" +
             "SUM(CASE WHEN o.log_type = '1' THEN 1 ELSE 0 END) AS type1,\n" +
             "SUM(CASE WHEN o.log_type = '2' THEN 1 ELSE 0 END) AS type2,\n" +
+            "COUNT(DISTINCT CASE WHEN o.log_type = '2' THEN o.user_id END) AS type5,\n" +
             "SUM(CASE WHEN o.log_type = '3' THEN 1 ELSE 0 END) AS type3,\n" +
             "SUM(CASE WHEN o.log_type = '4' THEN 1 ELSE 0 END) AS type4,\n" +
             "(\n" +

+ 8 - 0
fs-service/src/main/java/com/fs/course/service/IFsCourseRedPacketLogService.java

@@ -6,7 +6,9 @@ import java.util.List;
 import java.util.Map;
 
 import com.fs.common.core.domain.R;
+import com.fs.company.vo.RedPacketMoneyVO;
 import com.fs.course.domain.FsCourseRedPacketLog;
+import com.fs.course.param.CourseRedPacketStatisticsParam;
 import com.fs.course.param.FsCourseRedPacketLogParam;
 import com.fs.course.vo.FsCourseRedPacketLogListPVO;
 
@@ -89,4 +91,10 @@ public interface IFsCourseRedPacketLogService
     void sendRedPacketBf();
 
     void queryRedPacketResult(String startTime, String endTime);
+
+    /**
+     * 项目红包金额
+     * @return
+     */
+    List<RedPacketMoneyVO> getProjectRedPacketMoney(CourseRedPacketStatisticsParam param);
 }

+ 22 - 4
fs-service/src/main/java/com/fs/course/service/impl/FsCourseRedPacketLogServiceImpl.java

@@ -4,14 +4,13 @@ import java.math.BigDecimal;
 import java.time.LocalDate;
 import java.time.LocalDateTime;
 import java.time.format.DateTimeFormatter;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
+import java.util.stream.Collectors;
 
 import cn.hutool.json.JSONUtil;
 import com.alibaba.fastjson.JSON;
 import com.fs.common.core.domain.R;
+import com.fs.common.core.domain.entity.SysDictData;
 import com.fs.common.utils.DateUtils;
 import com.fs.common.utils.StringUtils;
 import com.fs.company.domain.Company;
@@ -19,16 +18,19 @@ import com.fs.company.domain.CompanyMoneyLogs;
 import com.fs.company.mapper.CompanyMapper;
 import com.fs.company.mapper.CompanyMoneyLogsMapper;
 import com.fs.company.util.CompanyRedPacketBalanceUtil;
+import com.fs.company.vo.RedPacketMoneyVO;
 import com.fs.course.config.CourseConfig;
 import com.fs.course.config.RedPacketConfig;
 import com.fs.course.domain.FsCourseWatchLog;
 import com.fs.course.mapper.FsCourseWatchLogMapper;
+import com.fs.course.param.CourseRedPacketStatisticsParam;
 import com.fs.course.param.FsCourseRedPacketLogParam;
 import com.fs.course.vo.FsCourseRedPacketLogListPVO;
 import com.fs.his.domain.FsUser;
 import com.fs.his.mapper.FsUserMapper;
 import com.fs.his.param.WxSendRedPacketParam;
 import com.fs.his.service.IFsStorePaymentService;
+import com.fs.system.mapper.SysDictDataMapper;
 import com.fs.system.service.ISysConfigService;
 import com.github.binarywang.wxpay.bean.transfer.TransferBillsGetResult;
 import com.github.binarywang.wxpay.bean.transfer.TransferBillsResult;
@@ -65,6 +67,9 @@ public class FsCourseRedPacketLogServiceImpl implements IFsCourseRedPacketLogSer
     private CompanyRedPacketBalanceUtil companyRedPacketBalanceUtil;
     @Autowired
     private ISysConfigService configService;
+
+    @Autowired
+    private SysDictDataMapper dictDataMapper;
     /**
      * 查询短链课程看课记录
      *
@@ -376,6 +381,19 @@ public class FsCourseRedPacketLogServiceImpl implements IFsCourseRedPacketLogSer
         }
     }
 
+    @Override
+    public List<RedPacketMoneyVO> getProjectRedPacketMoney(CourseRedPacketStatisticsParam param) {
+        List<RedPacketMoneyVO> list = fsCourseRedPacketLogMapper.selectMoneyByProject(param);
+        //字典获取项目名
+        List<SysDictData> courseProject = dictDataMapper.selectDictDataByType("sys_course_project");
+        Map<String, String> projectMap = courseProject.stream()
+                .collect(Collectors.toMap(SysDictData::getDictValue, SysDictData::getDictLabel));
+        list.forEach(vo -> {
+            vo.setProjectName(projectMap.getOrDefault(vo.getProjectId().toString(),""));
+        });
+        return list;
+    }
+
 
     private void processRedPacket(FsCourseRedPacketLog redPacket, CourseConfig config) {
         // 获取用户信息

+ 92 - 0
fs-service/src/main/java/com/fs/course/service/impl/FsCourseWatchLogServiceImpl.java

@@ -6,6 +6,7 @@ import cn.hutool.json.JSONUtil;
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
+import com.baidu.dev2.thirdparty.jackson.databind.ObjectMapper;
 import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.fs.common.core.domain.R;
@@ -87,6 +88,8 @@ import java.util.stream.Collectors;
 @Service
 public class FsCourseWatchLogServiceImpl extends ServiceImpl<FsCourseWatchLogMapper, FsCourseWatchLog> implements IFsCourseWatchLogService {
     private static final Logger log = LoggerFactory.getLogger(FsCourseWatchLogServiceImpl.class);
+
+    private static final ObjectMapper objectMapper = new ObjectMapper();
     @Autowired
     private FsCourseWatchLogMapper fsCourseWatchLogMapper;
     @Autowired
@@ -1867,6 +1870,13 @@ public class FsCourseWatchLogServiceImpl extends ServiceImpl<FsCourseWatchLogMap
             int i = fsCourseWatchLogMapper.deleteById(fsCourseWatchLog.getLogId());
             if (i < 0) {
                 return R.error("清除失败");
+            }else {
+                //备份看课记录
+                WatchLogBak watchLogBak = convertToBackupWithDeleteInfo(fsCourseWatchLog, userId, 1);
+                int j = fsCourseWatchLogMapper.insertBackup(watchLogBak);
+                if (j < 0) {
+                    return R.error("备份失败");
+                }
             }
         }else {
             return R.error("没有需要清除的记录");
@@ -1874,4 +1884,86 @@ public class FsCourseWatchLogServiceImpl extends ServiceImpl<FsCourseWatchLogMap
         return R.ok("清除成功");
     }
 
+    public WatchLogBak convertToBackupWithDeleteInfo(FsCourseWatchLog original, Long deleteBy,
+                                                     Integer deleteMethod) {
+        WatchLogBak backup = convertToBackup(original);
+        if (backup != null) {
+            backup.setDeleteBy(deleteBy);
+            if (deleteMethod != null) {
+                backup.setDeleteMethod(deleteMethod);
+            }
+        }
+        return backup;
+    }
+
+    public WatchLogBak convertToBackup(FsCourseWatchLog original) {
+        if (original == null) {
+            return null;
+        }
+
+        WatchLogBak backup = new WatchLogBak();
+
+        // 复制原始数据字段
+        backup.setOriginalLogId(original.getLogId());
+        backup.setUserId(original.getUserId());
+        backup.setVideoId(original.getVideoId());
+        backup.setLogType(original.getLogType());
+        backup.setCreateTime(original.getCreateTime());
+        backup.setUpdateTime(original.getUpdateTime());
+        backup.setQwExternalContactId(original.getQwExternalContactId());
+        backup.setDuration(original.getDuration());
+        backup.setQwUserId(original.getQwUserId());
+        backup.setCompanyUserId(original.getCompanyUserId());
+        backup.setCompanyId(original.getCompanyId());
+        backup.setCourseId(original.getCourseId());
+        backup.setSendType(original.getSendType());
+        backup.setRewardType(original.getRewardType());
+        backup.setLastHeartbeatTime(original.getLastHeartbeatTime());
+        backup.setSopId(original.getSopId());
+        backup.setFinishTime(original.getFinishTime());
+        backup.setSendFinishMsg(original.getSendFinishMsg());
+        backup.setCampPeriodTime(original.getCampPeriodTime());
+        backup.setDay(original.getDay());
+        backup.setProject(original.getProject());
+        backup.setCreateBy(original.getCreateBy());
+        backup.setUpdateBy(original.getUpdateBy());
+        backup.setPeriodId(original.getPeriodId());
+        backup.setImMsgSendDetailId(original.getImMsgSendDetailId());
+        backup.setWatchType(original.getWatchType());
+
+        // 设置删除信息(调用时传入)
+        backup.setDeleteTime(new Date());
+
+        // 保存完整的原始数据为JSON
+        backup.setOriginalData(convertToJson(original));
+
+        return backup;
+    }
+
+    private String convertToJson(FsCourseWatchLog original) {
+        try {
+            // 使用 FastJSON 进行序列化,它对复杂对象有更好的处理
+            String jsonString = JSON.toJSONString(original);
+
+            // 验证 JSON 格式是否有效
+            if (isValidJson(jsonString)) {
+                return jsonString;
+            }
+        } catch (Exception e) {
+            log.error("转换JSON失败: {}, 原始对象ID: {}", e.getMessage(), original.getLogId());
+        }
+        return null;
+    }
+
+    private boolean isValidJson(String jsonString) {
+        try {
+            JSON.parse(jsonString);
+            return true;
+        } catch (Exception e) {
+            log.error("无效的JSON格式: {}", e.getMessage());
+            return false;
+        }
+    }
+
+
 }

+ 3 - 1
fs-service/src/main/java/com/fs/course/vo/FsCourseWatchLogStatisticsListVO.java

@@ -24,8 +24,10 @@ public class FsCourseWatchLogStatisticsListVO {
 
     @Excel(name = "看课中")
     private String type1;
-    @Excel(name = "已完")
+    @Excel(name = "已完")
     private String type2;
+    @Excel(name = "完播人数")
+    private String type5;
     @Excel(name = "待看课")
     private String type3;
     @Excel(name = "看课中断")

+ 22 - 0
fs-service/src/main/resources/mapper/course/FsCourseRedPacketLogMapper.xml

@@ -212,4 +212,26 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         <include refid="selectFsCourseRedPacketLogVo"/> where status != 1 and create_time &gt;= #{maps.startTime} and create_time &lt;= #{maps.endTime}
 
     </select>
+    <select id="selectMoneyByProject" resultType="com.fs.company.vo.RedPacketMoneyVO">
+        SELECT
+        uc.project projectId,
+        SUM(packet.amount) money
+        FROM
+        fs_course_red_packet_log packet
+        LEFT JOIN fs_user_course uc ON packet.course_id = uc.course_id
+        <where>
+            packet.status = 1
+            <if test="companyId != null">
+                and packet.company_id = #{companyId}
+            </if>
+            <if test="startTime != null">
+                and date_format(packet.create_time,'%Y-%m-%d') &gt;= date_format(#{startTime},'%Y-%m-%d')
+            </if>
+            <if test="endTime != null">
+                and date_format(packet.create_time,'%Y-%m-%d') &lt;= date_format(#{endTime},'%Y-%m-%d')
+            </if>
+        </where>
+        GROUP BY
+        uc.project
+    </select>
 </mapper>

+ 73 - 2
fs-service/src/main/resources/mapper/course/FsCourseWatchLogMapper.xml

@@ -388,8 +388,79 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         update_time = NOW(),
         im_msg_send_detail_id = VALUES(im_msg_send_detail_id)
     </insert>
-
-
+    <insert id="insertBackup">
+        INSERT INTO fs_course_watch_log_bak (
+            original_log_id,
+            user_id,
+            video_id,
+            log_type,
+            create_time,
+            update_time,
+            qw_external_contact_id,
+            duration,
+            qw_user_id,
+            company_user_id,
+            company_id,
+            course_id,
+            send_type,
+            reward_type,
+            last_heartbeat_time,
+            sop_id,
+            finish_time,
+            send_finish_msg,
+            camp_period_time,
+            day,
+            project,
+            create_by,
+            update_by,
+            period_id,
+            project_id,
+            im_msg_send_detail_id,
+            watch_type,
+            delete_time,
+            delete_by,
+            delete_method,
+            original_data,
+            backup_operator,
+            backup_batch_no,
+            remark
+        ) VALUES (
+                     #{originalLogId},
+                     #{userId},
+                     #{videoId},
+                     #{logType},
+                     #{createTime},
+                     #{updateTime},
+                     #{qwExternalContactId},
+                     #{duration},
+                     #{qwUserId},
+                     #{companyUserId},
+                     #{companyId},
+                     #{courseId},
+                     #{sendType},
+                     #{rewardType},
+                     #{lastHeartbeatTime},
+                     #{sopId},
+                     #{finishTime},
+                     #{sendFinishMsg},
+                     #{campPeriodTime},
+                     #{day},
+                     #{project},
+                     #{createBy},
+                     #{updateBy},
+                     #{periodId},
+                     #{projectId},
+                     #{imMsgSendDetailId},
+                     #{watchType},
+                     #{deleteTime},
+                     #{deleteBy},
+                     #{deleteMethod},
+                     #{originalData},
+                     #{backupOperator},
+                     #{backupBatchNo},
+                     #{remark}
+                 )
+    </insert>
 
     <update id="updateFsCourseWatchLog" parameterType="FsCourseWatchLog">
         update fs_course_watch_log

+ 2 - 4
fs-service/src/main/resources/mapper/his/FsUserMapper.xml

@@ -406,12 +406,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 <!--                AND ucu.company_user_id = #{companyUserId}-->
 <!--            </if>-->
             <if test="registerStartTime != null and registerStartTime !='' ">
-                AND ucu.update_time &gt;= #{registerStartTime}
+                AND fs_user.create_time &gt;= CONCAT(#{registerStartTime}, ' 00:00:00')
             </if>
             <if test="registerEndTime != null and registerEndTime !='' ">
-            <![CDATA[
-                AND ucu.update_time < date_add(#{registerEndTime}, interval 1 day)
-            ]]>
+                AND fs_user.create_time &lt;= CONCAT(#{registerEndTime}, ' 23:59:59')
             </if>
 <!--            <if test="companyUserIds != null and companyUserIds.size > 0">-->
 <!--                AND ucu.company_user_id in-->