From 23003e5ece97193921dacc7a7dc98926449b64d6 Mon Sep 17 00:00:00 2001
From: 龚焕茏 <2842157468@qq.com>
Date: 星期二, 09 四月 2024 11:55:46 +0800
Subject: [PATCH] 新增工单

---
 ycl-server/src/main/java/com/ycl/platform/service/impl/CheckTemplateServiceImpl.java |  248 ++++++++++++++++++------------------------------
 1 files changed, 94 insertions(+), 154 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 b7d8729..e05625e 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,203 +1,143 @@
 package com.ycl.platform.service.impl;
 
-import com.baomidou.mybatisplus.extension.conditions.update.LambdaUpdateChainWrapper;
 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.entity.YwUnit;
-import com.ycl.platform.domain.vo.RuleItemVO;
-import com.ycl.platform.mapper.CheckTemplateMapper;
-import com.ycl.platform.mapper.CheckTemplateRuleMapper;
-import com.ycl.platform.service.CheckTemplateService;
-import com.ycl.platform.service.YwUnitService;
-import com.ycl.system.Result;
-import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
-import com.ycl.platform.domain.form.CheckTemplateForm;
-import com.ycl.platform.domain.vo.CheckTemplateVO;
 import com.ycl.platform.domain.query.CheckTemplateQuery;
-import java.util.List;
-
-import com.baomidou.mybatisplus.core.metadata.IPage;
-import com.ycl.system.page.PageUtil;
-import com.ycl.utils.DateUtils;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Service;
-import org.springframework.security.core.context.SecurityContextHolder;
+import com.ycl.platform.mapper.CheckTemplateMapper;
+import com.ycl.platform.service.ICheckTemplateService;
+import com.ycl.system.Result;
+import com.ycl.system.entity.SysDept;
+import com.ycl.system.service.ISysDeptService;
+import io.jsonwebtoken.lang.Collections;
 import org.springframework.beans.BeanUtils;
-import org.springframework.transaction.annotation.Transactional;
-import org.springframework.util.Assert;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Bean;
+import org.springframework.stereotype.Service;
+import utils.DateUtils;
+import utils.StringUtils;
+
 import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
 import java.util.Objects;
 import java.util.stream.Collectors;
-import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
-import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
-import lombok.RequiredArgsConstructor;
-import org.springframework.util.StringUtils;
 
 /**
- * 鑰冩牳妯℃澘 鏈嶅姟瀹炵幇绫�
+ * 鑰冩牳妯℃澘Service涓氬姟灞傚鐞�
  *
- * @author xp
- * @since 2024-03-06
+ * @author ruoyi
+ * @date 2024-04-01
  */
 @Service
-@RequiredArgsConstructor
-public class CheckTemplateServiceImpl extends ServiceImpl<CheckTemplateMapper, CheckTemplate> implements CheckTemplateService {
-
-    private final CheckTemplateMapper checkTemplateMapper;
-    private final CheckTemplateRuleMapper checkTemplateRuleMapper;
+public class CheckTemplateServiceImpl implements ICheckTemplateService {
     @Autowired
-    private YwUnitService unitService;
+    private CheckTemplateMapper checkTemplateMapper;
+    @Autowired
+    private ISysDeptService deptService;
+
     /**
-     * 娣诲姞
-     * @param form
-     * @return
+     * 鏌ヨ鑰冩牳妯℃澘
+     *
+     * @param id 鑰冩牳妯℃澘涓婚敭
+     * @return 鑰冩牳妯℃澘
      */
     @Override
-    @Transactional(rollbackFor = Exception.class)
-    public Result add(CheckTemplateForm form) {
-        CheckTemplate entity = CheckTemplateForm.getEntityByForm(form, null);
-        baseMapper.insert(entity);
-        form.getRuleFormList().stream().forEach(rule -> {
-            CheckTemplateRule checkTemplateRule = new CheckTemplateRule();
-            checkTemplateRule.setCheckTemplateId(entity.getId());
-            checkTemplateRule.setCheckRuleId(rule.getRuleId());
-            checkTemplateRule.setWeight(rule.getWeight());
-            checkTemplateRuleMapper.insert(checkTemplateRule);
-        });
-        return Result.ok("娣诲姞鎴愬姛");
+    public CheckTemplateQuery selectCheckTemplateById(Long id) {
+        CheckTemplate checkTemplate = checkTemplateMapper.selectCheckTemplateById(id);
+        CheckTemplateQuery checkTemplateQuery = new CheckTemplateQuery();
+        BeanUtils.copyProperties(checkTemplate,checkTemplateQuery);
+        String deptId = checkTemplate.getDeptId();
+        String deptIdStr = deptId.substring(1, deptId.length() - 1);
+        List<Integer> deptIds = Arrays.stream(deptIdStr.split(","))
+                .mapToInt(Integer::parseInt)
+                .boxed().collect(Collectors.toList());
+        checkTemplateQuery.setDeptId(deptIds);
+        return checkTemplateQuery;
     }
 
     /**
-     * 淇敼
-     * @param form
-     * @return
+     * 鏌ヨ鑰冩牳妯℃澘鍒楄〃
+     *
+     * @param checkTemplateDTO 鑰冩牳妯℃澘
+     * @return 鑰冩牳妯℃澘
      */
     @Override
-    @Transactional(rollbackFor = Exception.class)
-    public Result update(CheckTemplateForm form) {
+    public List<CheckTemplate> selectCheckTemplateList(CheckTemplateQuery checkTemplateDTO) {
+        List<CheckTemplate> checkTemplates = checkTemplateMapper.selectCheckTemplateList(checkTemplateDTO);
+        //閮ㄩ棬鍖哄煙涓嬫媺鍒楄〃
+        Result all = deptService.pullList();
+        List<BaseSelect> data = (List<BaseSelect>) all.get("data");
+        //缈昏瘧閮ㄩ棬id
+        for (CheckTemplate template : checkTemplates) {
+            if(template.getDeptId() == null)continue;
+            String[] deptIds = template.getDeptId().replace("[", "").replace("]", "").split(",");
+            List<String> deptName = new ArrayList<>();
+            for (String deptId : deptIds) {
+                List<String> deptStr = data.stream()
+                        .filter(baseSelect -> baseSelect.getId().equals(Integer.parseInt(deptId)))
+                        .map(BaseSelect::getValue)
+                        .collect(Collectors.toList());
+                deptName.addAll(deptStr);
+            }
+            template.setDeptId(StringUtils.join(deptName,","));
+        }
 
-        CheckTemplate entity = baseMapper.selectById(form.getId());
-        // 涓虹┖鎶汭llegalArgumentException锛屽仛鍏ㄥ眬寮傚父澶勭悊
-        Assert.notNull(entity, "璁板綍涓嶅瓨鍦�");
-        BeanUtils.copyProperties(form, entity);
-        baseMapper.updateById(entity);
-
-        // 鍏堝垹闄ゅ師鍏堢殑瀵瑰簲鍏崇郴
-        new LambdaUpdateChainWrapper<>(checkTemplateRuleMapper)
-                .eq(CheckTemplateRule::getCheckTemplateId, form.getId())
-                .remove();
-        // 鍐嶉噸鏂版坊鍔�
-        form.getRuleFormList().stream().forEach(rule -> {
-            CheckTemplateRule checkTemplateRule = new CheckTemplateRule();
-            checkTemplateRule.setCheckTemplateId(entity.getId());
-            checkTemplateRule.setCheckRuleId(rule.getRuleId());
-            checkTemplateRule.setWeight(rule.getWeight());
-            checkTemplateRuleMapper.insert(checkTemplateRule);
-        });
-        return Result.ok("淇敼鎴愬姛");
+        return checkTemplates;
     }
 
     /**
-     * 鎵归噺鍒犻櫎
-     * @param ids
-     * @return
+     * 鏂板鑰冩牳妯℃澘
+     *
+     * @param checkTemplateDTO 鑰冩牳妯℃澘
+     * @return 缁撴灉
      */
     @Override
-    @Transactional(rollbackFor = Exception.class)
-    public Result remove(List<String> ids) {
-        baseMapper.deleteBatchIds(ids);
-        new LambdaUpdateChainWrapper<>(checkTemplateRuleMapper)
-                .in(CheckTemplateRule::getCheckTemplateId, ids)
-                .remove();
-        return Result.ok("鍒犻櫎鎴愬姛");
+    public int insertCheckTemplate(CheckTemplateQuery checkTemplateDTO) {
+        checkTemplateDTO.setCreateTime(DateUtils.getNowDate());
+        CheckTemplate checkTemplate = new CheckTemplate();
+        BeanUtils.copyProperties(checkTemplateDTO,checkTemplate);
+        checkTemplate.setDeptId(checkTemplateDTO.getDeptId().toString().replaceAll(" ",""));
+        return checkTemplateMapper.insertCheckTemplate(checkTemplate);
     }
 
     /**
-     * id鍒犻櫎
-     * @param id
-     * @return
+     * 淇敼鑰冩牳妯℃澘
+     *
+     * @param checkTemplate 鑰冩牳妯℃澘
+     * @return 缁撴灉
      */
     @Override
-    @Transactional(rollbackFor = Exception.class)
-    public Result removeById(String id) {
-        baseMapper.deleteById(id);
-        new LambdaUpdateChainWrapper<>(checkTemplateRuleMapper)
-                .eq(CheckTemplateRule::getCheckTemplateId, id)
-                .remove();
-        return Result.ok("鍒犻櫎鎴愬姛");
+    public int updateCheckTemplate(CheckTemplate checkTemplate) {
+        checkTemplate.setUpdateTime(DateUtils.getNowDate());
+        return checkTemplateMapper.updateCheckTemplate(checkTemplate);
     }
 
     /**
-     * 鍒嗛〉鏌ヨ
-     * @param query
-     * @return
+     * 鎵归噺鍒犻櫎鑰冩牳妯℃澘
+     *
+     * @param ids 闇�瑕佸垹闄ょ殑鑰冩牳妯℃澘涓婚敭
+     * @return 缁撴灉
      */
     @Override
-    public Result page(CheckTemplateQuery query) {
-        IPage<CheckTemplate> page = new LambdaQueryChainWrapper<>(baseMapper)
-                .like(StringUtils.hasText(query.getTemplateName()), CheckTemplate::getTemplateName, query.getTemplateName())
-                .eq(StringUtils.hasText(query.getStatus()), CheckTemplate::getStatus, query.getStatus())
-                .between(Objects.nonNull(query.getStart()) && Objects.nonNull(query.getEnd()),
-                        CheckTemplate::getCreateTime,
-                        DateUtils.getDayStart(query.getStart()),
-                        DateUtils.getDayEnd(query.getEnd()))
-                .orderByDesc(CheckTemplate::getCreateTime)
-                .page(PageUtil.getPage(query, CheckTemplate.class));
-
-        List<CheckTemplateVO> vos = page.getRecords().stream()
-                .map(
-                        entity -> CheckTemplateVO.getVoByEntity(entity, null)
-//                                .setUnitName(unitService.getById(entity.getUnitId()).getUnitName())
-                )
-                .collect(Collectors.toList());
-        return Result.ok().data(vos).total(page.getTotal());
+    public int deleteCheckTemplateByIds(Long[] ids) {
+        return checkTemplateMapper.deleteCheckTemplateByIds(ids);
     }
 
     /**
-     * 鏍规嵁id鏌ユ壘
-     * @param id
-     * @return
+     * 鍒犻櫎鑰冩牳妯℃澘淇℃伅
+     *
+     * @param id 鑰冩牳妯℃澘涓婚敭
+     * @return 缁撴灉
      */
     @Override
-    public Result detail(String id) {
-
-        CheckTemplate entity = baseMapper.selectById(id);
-        Assert.notNull(entity, "璁板綍涓嶅瓨鍦�");
-        CheckTemplateVO vo = CheckTemplateVO.getVoByEntity(entity, null);
-
-        // 鏌ヨ�冩牳瑙勫垯
-        List<CheckTemplateRule> ruleList = new LambdaQueryChainWrapper<>(checkTemplateRuleMapper)
-                .eq(CheckTemplateRule::getCheckTemplateId, entity.getId())
-                .list();
-        List<RuleItemVO> ruleVOS = ruleList.stream().map(rule -> {
-            RuleItemVO ruleItemVO = new RuleItemVO();
-            ruleItemVO.setRuleId(rule.getCheckRuleId());
-            ruleItemVO.setWeight(rule.getWeight());
-            return ruleItemVO;
-        }).collect(Collectors.toList());
-        vo.setRuleFormList(ruleVOS);
-
-        return Result.ok().data(vo);
+    public int deleteCheckTemplateById(Long id) {
+        return checkTemplateMapper.deleteCheckTemplateById(id);
     }
 
-    /**
-     * 鍒楄〃
-     * @return
-     */
     @Override
-    public Result all() {
-        List<CheckTemplate> entities = baseMapper.selectList(null);
-        List<BaseSelect> vos = entities.stream()
-                .map(
-                        entity -> {
-                            BaseSelect baseSelect = new BaseSelect();
-                            baseSelect.setId(entity.getId());
-                            baseSelect.setValue(entity.getTemplateName());
-                            return baseSelect;
-                        }
-                )
-                .collect(Collectors.toList());
-        return Result.ok().data(vos);
+    public Result pullList() {
+        List<CheckTemplate> checkTemplates = checkTemplateMapper.selectCheckTemplateList(new CheckTemplateQuery());
+
+        return Result.ok().data(checkTemplates);
     }
 }

--
Gitblit v1.8.0