From 3b0516a2959e25576e4f3fda697a3b025d06c8c9 Mon Sep 17 00:00:00 2001
From: zxl <763096477@qq.com>
Date: 星期二, 24 六月 2025 14:09:07 +0800
Subject: [PATCH] 每日录像可用指标添加日志,修改大屏为查看当前月平均

---
 ycl-server/src/main/java/com/ycl/platform/service/impl/CheckTemplateServiceImpl.java |  130 +++++++++++++++++++++++++++---------------
 1 files changed, 83 insertions(+), 47 deletions(-)

diff --git a/ycl-server/src/main/java/com/ycl/platform/service/impl/CheckTemplateServiceImpl.java b/ycl-server/src/main/java/com/ycl/platform/service/impl/CheckTemplateServiceImpl.java
index c7158ab..1deba5d 100644
--- a/ycl-server/src/main/java/com/ycl/platform/service/impl/CheckTemplateServiceImpl.java
+++ b/ycl-server/src/main/java/com/ycl/platform/service/impl/CheckTemplateServiceImpl.java
@@ -3,6 +3,7 @@
 import com.alibaba.fastjson2.JSONArray;
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.ycl.exception.job.TaskException;
 import com.ycl.platform.base.BaseSelect;
 import com.ycl.platform.domain.entity.CheckTemplate;
 import com.ycl.platform.domain.entity.CheckTemplateRule;
@@ -11,11 +12,15 @@
 import com.ycl.platform.mapper.CheckTemplateRuleMapper;
 import com.ycl.platform.service.ICheckTemplateRuleService;
 import com.ycl.platform.service.ICheckTemplateService;
+import com.ycl.system.AjaxResult;
 import com.ycl.system.Result;
+import com.ycl.system.domain.SysJob;
 import com.ycl.system.entity.SysDept;
 import com.ycl.system.service.ISysDeptService;
+import com.ycl.system.service.ISysJobService;
 import com.ycl.utils.SecurityUtils;
 import constant.CheckConstants;
+import org.quartz.SchedulerException;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.context.annotation.Bean;
@@ -36,13 +41,16 @@
  * @date 2024-04-01
  */
 @Service
-public class CheckTemplateServiceImpl extends ServiceImpl<CheckTemplateMapper,CheckTemplate> implements ICheckTemplateService {
+public class CheckTemplateServiceImpl extends ServiceImpl<CheckTemplateMapper, CheckTemplate> implements ICheckTemplateService {
     @Autowired
     private CheckTemplateMapper checkTemplateMapper;
     @Autowired
     private ICheckTemplateRuleService templateRuleServicee;
     @Autowired
     private CheckTemplateRuleMapper checkTemplateRuleMapper;
+    @Autowired
+    private ISysJobService jobService;
+
     /**
      * 鏌ヨ鑰冩牳妯℃澘
      *
@@ -56,19 +64,18 @@
         BeanUtils.copyProperties(checkTemplate, checkTemplateQuery);
         List<Integer> deptIds = JSONArray.parseArray(checkTemplate.getDeptId(), Integer.class);
         checkTemplateQuery.setDeptId(deptIds)
-                .setAlarmScore(checkTemplate.getAlarmScore()+"");
+                .setAdjustCoefficient(checkTemplate.getAdjustCoefficient() + "")
+                .setAlarmScore(checkTemplate.getAlarmScore() + "");
         //鏌ヨ瑙勫垯鏉冮噸
         List<CheckTemplateRule> templateRuleList = checkTemplateRuleMapper.selectListByTemplateId(checkTemplate.getId());
-        List<Map<String,Object>> list = new ArrayList<>();
+        List<Map<String, Object>> list = new ArrayList<>();
         for (CheckTemplateRule checkTemplateRule : templateRuleList) {
-            Map<String,Object> map = new HashMap<>();
-            map.put("ruleId",checkTemplateRule.getCheckRuleId());
-            map.put("weight",checkTemplateRule.getWeight());
+            Map<String, Object> map = new HashMap<>();
+            map.put("ruleId", checkTemplateRule.getCheckRuleId());
+            map.put("weight", checkTemplateRule.getWeight());
             list.add(map);
         }
         checkTemplateQuery.setRuleFormList(list);
-        //TODO:鏌ヨtemplate_rule琛ㄤ腑鐨勬潈閲嶄俊鎭��
-
 
         return checkTemplateQuery;
     }
@@ -88,7 +95,8 @@
             List<Integer> deptIds = JSONArray.parseArray(template.getDeptId(), Integer.class);
             CheckTemplateQuery checkTemplateQuery = new CheckTemplateQuery();
             BeanUtils.copyProperties(template, checkTemplateQuery);
-            checkTemplateQuery.setDeptId(deptIds);
+            checkTemplateQuery.setDeptId(deptIds)
+                    .setAdjustCoefficient(template.getAdjustCoefficient() + "");
             checkTemplateList.add(checkTemplateQuery);
         }
 
@@ -103,10 +111,7 @@
      */
     @Override
     @Transactional(rollbackFor = Exception.class)
-    public int insertCheckTemplate(CheckTemplateQuery checkTemplateDTO) {
-        //TODO:鏂板瀹氭椂浠诲姟锛岀姸鎬佸悓妯℃澘,鐒跺悗璧嬪�糺obId缁檛emplate
-
-
+    public int insertCheckTemplate(CheckTemplateQuery checkTemplateDTO) throws SchedulerException, TaskException {
         String username = SecurityUtils.getUsername();
         /** 鎻掑叆t_template */
         CheckTemplate checkTemplate = new CheckTemplate();
@@ -118,14 +123,22 @@
         checkTemplate.setDeptId(JSONArray.toJSONString(deptId))
                 .setUpdateUserName(username)
                 .setCreateUserName(username)
+                .setAdjustCoefficient(new BigDecimal(checkTemplateDTO.getAdjustCoefficient() + ""))
                 //涓嶅~鎶ヨ鍒嗘暟---->闆跺垎---->涓嶆姤璀�
-                .setAlarmScore(new BigDecimal(checkTemplateDTO.getAlarmScore() == null? "":checkTemplateDTO.getAlarmScore()));
+                .setAlarmScore(new BigDecimal(checkTemplateDTO.getAlarmScore() == null ? "" : checkTemplateDTO.getAlarmScore()));
         int i = checkTemplateMapper.insertCheckTemplate(checkTemplate);
+
+        //鏂板瀹氭椂浠诲姟锛岀姸鎬佸悓妯℃澘,鐒跺悗璧嬪�糺obId缁檛emplate
+        SysJob sysJob = addJob(checkTemplateDTO.setId(checkTemplate.getId()));
+        checkTemplate.setJobId(Integer.parseInt(sysJob.getJobId() + ""));
+        checkTemplateMapper.updateCheckTemplate(checkTemplate);
+
         /** t_template_rule鏂板鏉冮噸 */
         insertTemlpateRule(checkTemplateDTO, checkTemplate);
 
         return i;
     }
+
     /**
      * 澶嶅埗鑰冩牳妯℃澘
      *
@@ -134,9 +147,7 @@
      */
     @Override
     @Transactional(rollbackFor = Exception.class)
-    public int copyCheckTemplate(CheckTemplateQuery checkTemplateDTO) {
-        //TODO:鏂板瀹氭椂浠诲姟锛岀姸鎬佸悓妯℃澘,鐒跺悗璧嬪�糺obId缁檛emplate
-
+    public int copyCheckTemplate(CheckTemplateQuery checkTemplateDTO) throws SchedulerException, TaskException {
         //鎻掑叆妯℃澘琛�
         CheckTemplate checkTemplate = checkTemplateMapper.selectCheckTemplateById(checkTemplateDTO.getId());
         String username = SecurityUtils.getUsername();
@@ -149,7 +160,10 @@
         List<CheckTemplateRule> templateRuleList = checkTemplateRuleMapper.selectListByTemplateId(checkTemplateDTO.getId());
         templateRuleList.forEach(checkTemplateRule -> checkTemplateRule.setCheckTemplateId(checkTemplate.getId()).setId(null));
         templateRuleServicee.saveBatch(templateRuleList);
-
+        //鏂板瀹氭椂浠诲姟锛岀姸鎬佸悓妯℃澘,鐒跺悗璧嬪�糺obId缁檛emplate
+        SysJob sysJob = addJob(checkTemplateDTO.setId(checkTemplate.getId()));
+        checkTemplate.setJobId(Integer.parseInt(sysJob.getJobId() + ""));
+        checkTemplateMapper.updateCheckTemplate(checkTemplate);
         return i;
     }
 
@@ -161,34 +175,28 @@
      */
     @Override
     @Transactional(rollbackFor = Exception.class)
-    public int updateCheckTemplate(CheckTemplateQuery checkTemplateDTO) {
+    public AjaxResult updateCheckTemplate(CheckTemplateQuery checkTemplateDTO) throws SchedulerException, TaskException {
         CheckTemplate checkTemplate = new CheckTemplate();
         BeanUtils.copyProperties(checkTemplateDTO, checkTemplate);
         checkTemplate.setUpdateUserName(SecurityUtils.getUsername());
         List<Integer> deptId = checkTemplateDTO.getDeptId();
         Collections.sort(deptId);
-        checkTemplate.setDeptId(JSONArray.toJSONString(deptId));
-        int i = checkTemplateMapper.updateCheckTemplate(checkTemplate);
+        checkTemplate.setDeptId(JSONArray.toJSONString(deptId))
+                .setAdjustCoefficient(new BigDecimal(checkTemplateDTO.getAdjustCoefficient() + ""));
+        checkTemplateMapper.updateCheckTemplate(checkTemplate);
+
         /** t_template_rule淇敼鏉冮噸 */
-        //鍏堝垹闄ゅ師鏁版嵁
-        checkTemplateRuleMapper.deleteByTemplateId(checkTemplate.getId());
-        //鎻掑叆鏂拌鍒欐暟鎹�
-        insertTemlpateRule(checkTemplateDTO, checkTemplate);
-
-        //TODO:鍒ゆ柇鐘舵�佹槸鍚︿慨鏀癸紝璋冩暣job琛ㄩ噷鐨勭姸鎬�
-
-        return i;
-    }
-
-    /**
-     * 鎵归噺鍒犻櫎鑰冩牳妯℃澘
-     *
-     * @param ids 闇�瑕佸垹闄ょ殑鑰冩牳妯℃澘涓婚敭
-     * @return 缁撴灉
-     */
-    @Override
-    public int deleteCheckTemplateByIds(Integer[] ids) {
-        return checkTemplateMapper.deleteCheckTemplateByIds(ids);
+        if (!CollectionUtils.isEmpty(checkTemplateDTO.getRuleFormList())) {
+            //鍏堝垹闄ゅ師鏁版嵁
+            checkTemplateRuleMapper.deleteByTemplateId(checkTemplate.getId());
+            //鎻掑叆鏂拌鍒欐暟鎹�
+            insertTemlpateRule(checkTemplateDTO, checkTemplate);
+        }
+        //璋冩暣job琛ㄩ噷鐨勭姸鎬�
+        SysJob job = jobService.selectJobById(Long.valueOf(checkTemplateDTO.getJobId()));
+        job.setStatus(checkTemplateDTO.getStatus());
+        jobService.updateJob(job);
+        return AjaxResult.success();
     }
 
     /**
@@ -198,12 +206,16 @@
      * @return 缁撴灉
      */
     @Override
-    public int deleteCheckTemplateById(Integer id) {
-        //TODO:鍒犻櫎瀹氭椂浠诲姟
-
-
-        return checkTemplateMapper.updateCheckTemplate(new CheckTemplate().setId(id)
-                .setDeleted(CheckConstants.Delete));
+    public int deleteCheckTemplateById(Integer id) throws SchedulerException {
+        CheckTemplate checkTemplate = checkTemplateMapper.selectCheckTemplateById(id);
+        //鍒犻櫎瀹氭椂浠诲姟
+        SysJob job = new SysJob();
+        if (checkTemplate.getJobId() != null) {
+            job.setJobId(Long.valueOf(checkTemplate.getJobId()));
+            job.setJobGroup("CHECK");
+            jobService.deleteJob(job);
+        }
+        return checkTemplateMapper.deleteCheckTemplateById(id);
     }
 
     @Override
@@ -212,7 +224,6 @@
 
         return Result.ok().data(checkTemplates);
     }
-
 
 
     private void insertTemlpateRule(CheckTemplateQuery checkTemplateDTO, CheckTemplate checkTemplate) {
@@ -229,4 +240,29 @@
             templateRuleServicee.saveBatch(templateRuleList);
         }
     }
+
+    private SysJob addJob(CheckTemplateQuery checkTemplateDTO) throws SchedulerException, TaskException {
+        SysJob job = new SysJob();
+        job.setCreateBy(SecurityUtils.getLoginUser().getUsername());
+        //璋冪敤鏂规硶鍚�
+        job.setInvokeTarget("checkScoreTask.executeTemplate(" + checkTemplateDTO.getId() + ")");
+        job.setConcurrent("1");
+        job.setStatus(checkTemplateDTO.getStatus());
+        job.setJobGroup("CHECK");
+        job.setCronExpression("0 0 8 * * ?");
+        job.setJobName(checkTemplateDTO.getTemplateName());
+        int i = jobService.insertJob(job);
+        return job;
+    }
+
+    //    /**
+//     * 鎵归噺鍒犻櫎鑰冩牳妯℃澘
+//     *
+//     * @param ids 闇�瑕佸垹闄ょ殑鑰冩牳妯℃澘涓婚敭
+//     * @return 缁撴灉
+//     */
+//    @Override
+//    public int deleteCheckTemplateByIds(Integer[] ids) {
+//        return checkTemplateMapper.deleteCheckTemplateByIds(ids);
+//    }
 }

--
Gitblit v1.8.0