fix
songhuangfeng123
2022-09-20 f1f506172a3edff8d31e4db77b8940f115660919
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
package com.gkhy.safePlatform.targetDuty.service.impl;
 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gkhy.safePlatform.commons.co.ContextCacheUser;
import com.gkhy.safePlatform.targetDuty.entity.ExamineItem;
import com.gkhy.safePlatform.targetDuty.entity.TargetDivideDetail;
import com.gkhy.safePlatform.targetDuty.entity.TargetMng;
import com.gkhy.safePlatform.targetDuty.enums.TargetDutyResultCodes;
import com.gkhy.safePlatform.targetDuty.excepiton.TargetDutyException;
import com.gkhy.safePlatform.targetDuty.model.dto.req.ExamineTemplateSaveOrUpdate;
import com.gkhy.safePlatform.targetDuty.repository.ExamineItemRepository;
import com.gkhy.safePlatform.targetDuty.repository.ExamineTemplateRepository;
import com.gkhy.safePlatform.targetDuty.entity.ExamineTemplate;
import com.gkhy.safePlatform.targetDuty.service.CommonService;
import com.gkhy.safePlatform.targetDuty.service.ExamineItemService;
import com.gkhy.safePlatform.targetDuty.service.ExamineTemplateService;
import com.gkhy.safePlatform.targetDuty.service.baseService.ExamineItemBaseService;
import com.gkhy.safePlatform.targetDuty.service.baseService.ExamineTemplateBaseService;
import org.springframework.security.core.Authentication;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;
import com.gkhy.safePlatform.commons.enums.ResultCodes;
import com.gkhy.safePlatform.commons.query.PageQuery;
import com.gkhy.safePlatform.commons.vo.ResultVO;
import com.gkhy.safePlatform.commons.vo.SearchResultVO;
import com.gkhy.safePlatform.targetDuty.model.dto.req.ExamineTemplateQueryCriteria;
import com.gkhy.safePlatform.targetDuty.model.dto.resp.ExamineTemplateDto;
import com.gkhy.safePlatform.targetDuty.utils.QueryHelpPlus;
import com.gkhy.safePlatform.commons.utils.BeanCopyUtils;
import org.springframework.util.StringUtils;
 
import javax.annotation.Resource;
import java.io.Serializable;
import java.sql.Timestamp;
import java.util.*;
import java.util.stream.Collectors;
 
/**
 * 绩效考核标准(ExamineTemplate)表服务实现类
 *
 * @author xurui
 * @since 2022-07-21 10:58:10
 */
@Service("examineTemplateService")
public class ExamineTemplateServiceImpl implements ExamineTemplateService {
 
    @Autowired
    private ExamineTemplateBaseService examineTemplateBaseService;
 
    @Autowired
    private ExamineItemBaseService examineItemBaseService;
 
    @Resource
    private CommonService commonService;
    
    
    @Override
    public ResultVO queryAll(PageQuery<ExamineTemplateQueryCriteria> pageQuery) {
        Long pageIndex = pageQuery.getPageIndex();
        Long pageSize = pageQuery.getPageSize();
        IPage<ExamineTemplate> page = new Page<>(pageIndex, pageSize);
 
        page = examineTemplateBaseService.selectPage(page,
                QueryHelpPlus.getPredicate(ExamineTemplate.class, pageQuery.getSearchParams()));
        List<ExamineTemplateDto> respList = BeanCopyUtils.copyBeanList(page.getRecords(), ExamineTemplateDto.class);
 
        // --------------------------- 获取部门信息-----------------------
        //收集所用到的部门ID
        Set<Long> collectDepIdSet = new HashSet();
        respList.forEach(f->{
            collectDepIdSet.add(f.getSetPersonDepartmentId());
        });
        //获取部门名集合
        Map<Long,String> depNameMap = commonService.getDepName(collectDepIdSet);
 
        respList.forEach(f->{
            f.setSetPersonDepartmentName(depNameMap.get(f.getSetPersonDepartmentId()));
        });
 
        //获取考核项目明细
        respList.forEach(f->{
            List<ExamineItem> list = examineItemBaseService.selectList(new QueryWrapper<ExamineItem>().eq("examine_template_id",f.getId()));
            f.setExamineItemList(list);
        });
 
 
        return new SearchResultVO<>(
                true,
                pageIndex,
                pageSize,page.getPages(),
                page.getTotal(),
                respList,
                ResultCodes.OK
        );
    }
 
 
    @Override
    public List<ExamineTemplate> queryAll(ExamineTemplateQueryCriteria criteria) {
        return examineTemplateBaseService.queryAll(criteria);
    }
 
    @Override
    public ExamineTemplateDto selectOne(Serializable id) {
        ExamineTemplate template = examineTemplateBaseService.getById(id);
        if(template == null){
            return null;
        }
 
        ExamineTemplateDto dto = BeanCopyUtils.copyBean(template, ExamineTemplateDto.class);
 
        List<ExamineItem> list = examineItemBaseService.selectList(new QueryWrapper<ExamineItem>().eq("examine_template_id",template.getId()));
        dto.setExamineItemList(list);
        return dto;
    }
 
    @Override
    public void addOrUpdate(ExamineTemplateSaveOrUpdate infoDto, Authentication authentication) {
        if(!StringUtils.hasText(infoDto.getTitle())){
            throw new TargetDutyException("缺少title");
        }
        // 获取当前用户
        ContextCacheUser currentUser = (ContextCacheUser) authentication.getPrincipal();
 
        //设置设定人ID和设定人部门ID
        infoDto.setSetPersonDepartmentId(currentUser.getDepId());
        infoDto.setSetPersonId(currentUser.getUid());
 
        if(StringUtils.hasText(infoDto.getDelExamineItems())){
            List<Long> idList = Arrays.stream(infoDto.getDelExamineItems().split(",")).map(s-> Long.parseLong(s.trim()))
                    .collect(Collectors.toList());
            List<ExamineItem> delList = new ArrayList<>();
            idList.forEach(f->{
                ExamineItem info = new ExamineItem();
                info.setDelFlag(1);
                info.setId(f);
                delList.add(info);
            });
            examineItemBaseService.updateBatchById(delList);
        }
 
        ExamineTemplate examineTemplate = BeanCopyUtils.copyBean(infoDto, ExamineTemplate.class);
        examineTemplate.setSetTimem(new Timestamp(new java.util.Date().getTime()));
        if (infoDto.getId() == null) {
            examineTemplateBaseService.save(examineTemplate);
        } else {
            examineTemplateBaseService.update(examineTemplate,new UpdateWrapper<ExamineTemplate>().eq("id",examineTemplate.getId()));
        }
 
        List<ExamineItem> list = infoDto.getExamineItemList();
        list.forEach(f->{f.setExamineTemplateId(infoDto.getId());});
        examineItemBaseService.saveOrUpdateBatch(list);
 
    }
 
    @Override
    public void delete(Long[] ids) {
        if(ids == null){
            throw  new TargetDutyException(ResultCodes.CLIENT_PARAM_ILLEGAL);
        }
        List<Long> idList = Arrays.asList(ids);
 
        List<ExamineTemplate> delList = new ArrayList<>();
        idList.forEach(f->{
            ExamineTemplate info = new ExamineTemplate();
            info.setDelFlag(1);
            info.setId(f);
            delList.add(info);
        });
        examineTemplateBaseService.updateBatchById(delList);
    }
}