fuliqi
2024-04-07 b1a41509684c3823d41ec1c184f6a5f7ba49dfb7
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
package com.ycl.platform.service.impl;
 
import com.ycl.platform.base.BaseSelect;
import com.ycl.platform.domain.entity.CheckTemplate;
import com.ycl.platform.domain.query.CheckTemplateQuery;
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.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;
 
/**
 * 考核模板Service业务层处理
 *
 * @author ruoyi
 * @date 2024-04-01
 */
@Service
public class CheckTemplateServiceImpl implements ICheckTemplateService {
    @Autowired
    private CheckTemplateMapper checkTemplateMapper;
    @Autowired
    private ISysDeptService deptService;
 
    /**
     * 查询考核模板
     *
     * @param id 考核模板主键
     * @return 考核模板
     */
    @Override
    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 checkTemplateDTO 考核模板
     * @return 考核模板
     */
    @Override
    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,","));
        }
 
        return checkTemplates;
    }
 
    /**
     * 新增考核模板
     *
     * @param checkTemplateDTO 考核模板
     * @return 结果
     */
    @Override
    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);
    }
 
    /**
     * 修改考核模板
     *
     * @param checkTemplate 考核模板
     * @return 结果
     */
    @Override
    public int updateCheckTemplate(CheckTemplate checkTemplate) {
        checkTemplate.setUpdateTime(DateUtils.getNowDate());
        return checkTemplateMapper.updateCheckTemplate(checkTemplate);
    }
 
    /**
     * 批量删除考核模板
     *
     * @param ids 需要删除的考核模板主键
     * @return 结果
     */
    @Override
    public int deleteCheckTemplateByIds(Long[] ids) {
        return checkTemplateMapper.deleteCheckTemplateByIds(ids);
    }
 
    /**
     * 删除考核模板信息
     *
     * @param id 考核模板主键
     * @return 结果
     */
    @Override
    public int deleteCheckTemplateById(Long id) {
        return checkTemplateMapper.deleteCheckTemplateById(id);
    }
 
    @Override
    public Result pullList() {
        List<CheckTemplate> checkTemplates = checkTemplateMapper.selectCheckTemplateList(new CheckTemplateQuery());
 
        return Result.ok().data(checkTemplates);
    }
}