From eb806b5ec0bb72536e78c1a7fcffb94bcd24cbbe Mon Sep 17 00:00:00 2001
From: 龚焕茏 <2842157468@qq.com>
Date: 星期五, 26 四月 2024 18:24:27 +0800
Subject: [PATCH] 考核结果应用规则(算钱)新增、展示

---
 ycl-server/src/main/java/com/ycl/platform/service/impl/CheckTemplateServiceImpl.java |  201 ++++++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 170 insertions(+), 31 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 db6d9a1..96a0be0 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
@@ -1,97 +1,236 @@
 package com.ycl.platform.service.impl;
 
+import com.alibaba.fastjson2.JSONArray;
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.ycl.platform.base.BaseSelect;
 import com.ycl.platform.domain.entity.CheckTemplate;
+import com.ycl.platform.domain.entity.CheckTemplateRule;
+import com.ycl.platform.domain.query.CheckTemplateQuery;
 import com.ycl.platform.mapper.CheckTemplateMapper;
+import com.ycl.platform.mapper.CheckTemplateRuleMapper;
+import com.ycl.platform.service.ICheckTemplateRuleService;
 import com.ycl.platform.service.ICheckTemplateService;
+import com.ycl.system.Result;
+import com.ycl.system.entity.SysDept;
+import com.ycl.system.service.ISysDeptService;
+import com.ycl.utils.SecurityUtils;
+import constant.CheckConstants;
+import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Bean;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+import org.springframework.util.CollectionUtils;
 import utils.DateUtils;
+import utils.StringUtils;
 
-import java.util.List;
+import java.math.BigDecimal;
+import java.util.*;
+import java.util.stream.Collectors;
 
 /**
  * 鑰冩牳妯℃澘Service涓氬姟灞傚鐞�
- * 
+ *
  * @author ruoyi
  * @date 2024-04-01
  */
 @Service
-public class CheckTemplateServiceImpl implements ICheckTemplateService 
-{
+public class CheckTemplateServiceImpl extends ServiceImpl<CheckTemplateMapper,CheckTemplate> implements ICheckTemplateService {
     @Autowired
     private CheckTemplateMapper checkTemplateMapper;
-
+    @Autowired
+    private ICheckTemplateRuleService templateRuleServicee;
+    @Autowired
+    private CheckTemplateRuleMapper checkTemplateRuleMapper;
     /**
      * 鏌ヨ鑰冩牳妯℃澘
-     * 
+     *
      * @param id 鑰冩牳妯℃澘涓婚敭
      * @return 鑰冩牳妯℃澘
      */
     @Override
-    public CheckTemplate selectCheckTemplateById(Long id)
-    {
-        return checkTemplateMapper.selectCheckTemplateById(id);
+    public CheckTemplateQuery selectCheckTemplateById(Integer id) {
+        CheckTemplate checkTemplate = checkTemplateMapper.selectCheckTemplateById(id);
+        CheckTemplateQuery checkTemplateQuery = new CheckTemplateQuery();
+        BeanUtils.copyProperties(checkTemplate, checkTemplateQuery);
+        List<Integer> deptIds = JSONArray.parseArray(checkTemplate.getDeptId(), Integer.class);
+        checkTemplateQuery.setDeptId(deptIds)
+                .setAdjustCoefficient(checkTemplate.getAdjustCoefficient()+"")
+                .setAlarmScore(checkTemplate.getAlarmScore()+"");
+        //鏌ヨ瑙勫垯鏉冮噸
+        List<CheckTemplateRule> templateRuleList = checkTemplateRuleMapper.selectListByTemplateId(checkTemplate.getId());
+        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());
+            list.add(map);
+        }
+        checkTemplateQuery.setRuleFormList(list);
+        //TODO:鏌ヨtemplate_rule琛ㄤ腑鐨勬潈閲嶄俊鎭��
+
+
+        return checkTemplateQuery;
     }
 
     /**
      * 鏌ヨ鑰冩牳妯℃澘鍒楄〃
-     * 
-     * @param checkTemplate 鑰冩牳妯℃澘
+     *
+     * @param checkTemplateDTO 鑰冩牳妯℃澘
      * @return 鑰冩牳妯℃澘
      */
     @Override
-    public List<CheckTemplate> selectCheckTemplateList(CheckTemplate checkTemplate)
-    {
-        return checkTemplateMapper.selectCheckTemplateList(checkTemplate);
+    public List<CheckTemplateQuery> selectCheckTemplateList(CheckTemplateQuery checkTemplateDTO) {
+        List<CheckTemplate> checkTemplates = checkTemplateMapper.selectCheckTemplateList(checkTemplateDTO);
+        List<CheckTemplateQuery> checkTemplateList = new ArrayList<>();
+        //杞崲閮ㄩ棬id涓洪泦鍚�,杞崲alarmScore涓簊tring
+        for (CheckTemplate template : checkTemplates) {
+            List<Integer> deptIds = JSONArray.parseArray(template.getDeptId(), Integer.class);
+            CheckTemplateQuery checkTemplateQuery = new CheckTemplateQuery();
+            BeanUtils.copyProperties(template, checkTemplateQuery);
+            checkTemplateQuery.setDeptId(deptIds)
+                    .setAdjustCoefficient(template.getAdjustCoefficient()+"");
+            checkTemplateList.add(checkTemplateQuery);
+        }
+
+        return checkTemplateList;
     }
 
     /**
      * 鏂板鑰冩牳妯℃澘
-     * 
+     *
+     * @param checkTemplateDTO 鑰冩牳妯℃澘
+     * @return 缁撴灉
+     */
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public int insertCheckTemplate(CheckTemplateQuery checkTemplateDTO) {
+        //TODO:鏂板瀹氭椂浠诲姟锛岀姸鎬佸悓妯℃澘,鐒跺悗璧嬪�糺obId缁檛emplate
+
+
+        String username = SecurityUtils.getUsername();
+        /** 鎻掑叆t_template */
+        CheckTemplate checkTemplate = new CheckTemplate();
+        BeanUtils.copyProperties(checkTemplateDTO, checkTemplate);
+        //浠庡皬鍒板ぇ鎺掑簭
+        List<Integer> deptId = checkTemplateDTO.getDeptId();
+        Collections.sort(deptId);
+        Date nowDate = DateUtils.getNowDate();
+        checkTemplate.setDeptId(JSONArray.toJSONString(deptId))
+                .setUpdateUserName(username)
+                .setCreateUserName(username)
+                .setAdjustCoefficient(new BigDecimal(checkTemplateDTO.getAdjustCoefficient()+""))
+                //涓嶅~鎶ヨ鍒嗘暟---->闆跺垎---->涓嶆姤璀�
+                .setAlarmScore(new BigDecimal(checkTemplateDTO.getAlarmScore() == null? "":checkTemplateDTO.getAlarmScore()));
+        int i = checkTemplateMapper.insertCheckTemplate(checkTemplate);
+        /** t_template_rule鏂板鏉冮噸 */
+        insertTemlpateRule(checkTemplateDTO, checkTemplate);
+
+        return i;
+    }
+    /**
+     * 澶嶅埗鑰冩牳妯℃澘
+     *
      * @param checkTemplate 鑰冩牳妯℃澘
      * @return 缁撴灉
      */
     @Override
-    public int insertCheckTemplate(CheckTemplate checkTemplate)
-    {
-        checkTemplate.setCreateTime(DateUtils.getNowDate());
-        return checkTemplateMapper.insertCheckTemplate(checkTemplate);
+    @Transactional(rollbackFor = Exception.class)
+    public int copyCheckTemplate(CheckTemplateQuery checkTemplateDTO) {
+        //TODO:鏂板瀹氭椂浠诲姟锛岀姸鎬佸悓妯℃澘,鐒跺悗璧嬪�糺obId缁檛emplate
+
+        //鎻掑叆妯℃澘琛�
+        CheckTemplate checkTemplate = checkTemplateMapper.selectCheckTemplateById(checkTemplateDTO.getId());
+        String username = SecurityUtils.getUsername();
+        checkTemplate.setUpdateUserName(username)
+                .setCreateUserName(username)
+                .setStatus(CheckConstants.Status_Stop)
+                .setId(null);
+        int i = checkTemplateMapper.insertCheckTemplate(checkTemplate);
+        //鎻掑叆template_rule琛�
+        List<CheckTemplateRule> templateRuleList = checkTemplateRuleMapper.selectListByTemplateId(checkTemplateDTO.getId());
+        templateRuleList.forEach(checkTemplateRule -> checkTemplateRule.setCheckTemplateId(checkTemplate.getId()).setId(null));
+        templateRuleServicee.saveBatch(templateRuleList);
+
+        return i;
     }
 
     /**
      * 淇敼鑰冩牳妯℃澘
-     * 
+     *
      * @param checkTemplate 鑰冩牳妯℃澘
      * @return 缁撴灉
      */
     @Override
-    public int updateCheckTemplate(CheckTemplate checkTemplate)
-    {
-        checkTemplate.setUpdateTime(DateUtils.getNowDate());
-        return checkTemplateMapper.updateCheckTemplate(checkTemplate);
+    @Transactional(rollbackFor = Exception.class)
+    public int updateCheckTemplate(CheckTemplateQuery checkTemplateDTO) {
+        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))
+                .setAdjustCoefficient(new BigDecimal(checkTemplateDTO.getAdjustCoefficient()+""));
+        int i = checkTemplateMapper.updateCheckTemplate(checkTemplate);
+        /** t_template_rule淇敼鏉冮噸 */
+        //鍏堝垹闄ゅ師鏁版嵁
+        checkTemplateRuleMapper.deleteByTemplateId(checkTemplate.getId());
+        //鎻掑叆鏂拌鍒欐暟鎹�
+        insertTemlpateRule(checkTemplateDTO, checkTemplate);
+
+        //TODO:鍒ゆ柇鐘舵�佹槸鍚︿慨鏀癸紝璋冩暣job琛ㄩ噷鐨勭姸鎬�
+
+        return i;
     }
 
     /**
      * 鎵归噺鍒犻櫎鑰冩牳妯℃澘
-     * 
+     *
      * @param ids 闇�瑕佸垹闄ょ殑鑰冩牳妯℃澘涓婚敭
      * @return 缁撴灉
      */
     @Override
-    public int deleteCheckTemplateByIds(Long[] ids)
-    {
+    public int deleteCheckTemplateByIds(Integer[] ids) {
         return checkTemplateMapper.deleteCheckTemplateByIds(ids);
     }
 
     /**
      * 鍒犻櫎鑰冩牳妯℃澘淇℃伅
-     * 
+     *
      * @param id 鑰冩牳妯℃澘涓婚敭
      * @return 缁撴灉
      */
     @Override
-    public int deleteCheckTemplateById(Long id)
-    {
-        return checkTemplateMapper.deleteCheckTemplateById(id);
+    public int deleteCheckTemplateById(Integer id) {
+        //TODO:鍒犻櫎瀹氭椂浠诲姟
+
+
+        return checkTemplateMapper.updateCheckTemplate(new CheckTemplate().setId(id)
+                .setDeleted(CheckConstants.Delete));
+    }
+
+    @Override
+    public Result pullList() {
+        List<CheckTemplate> checkTemplates = checkTemplateMapper.selectCheckTemplateList(new CheckTemplateQuery());
+
+        return Result.ok().data(checkTemplates);
+    }
+
+
+
+    private void insertTemlpateRule(CheckTemplateQuery checkTemplateDTO, CheckTemplate checkTemplate) {
+        List<Map<String, Object>> ruleFormList = checkTemplateDTO.getRuleFormList();
+        if (!CollectionUtils.isEmpty(ruleFormList)) {
+            List<CheckTemplateRule> templateRuleList = new ArrayList<>();
+            for (Map<String, Object> map : ruleFormList) {
+                templateRuleList.add(new CheckTemplateRule()
+                        .setCheckRuleId((Integer) map.get("ruleId"))
+                        .setCheckTemplateId(checkTemplate.getId())
+                        .setWeight(new BigDecimal(map.get("weight").toString())));
+            }
+            //鎵归噺鎻掑叆鏁版嵁搴�
+            templateRuleServicee.saveBatch(templateRuleList);
+        }
     }
 }

--
Gitblit v1.8.0