songhuangfeng123
2022-08-02 aace11a7e1201a8d1fc0b50b659368918d23e794
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
package com.gkhy.safePlatform.targetDuty.service.impl;
 
import com.alibaba.fastjson.JSONObject;
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.targetDuty.entity.ExamineItem;
import com.gkhy.safePlatform.targetDuty.model.dto.resp.CurrentExamineDto;
import com.gkhy.safePlatform.targetDuty.repository.ExamineItemRepository;
import com.gkhy.safePlatform.targetDuty.repository.ExamineMngRepository;
import com.gkhy.safePlatform.targetDuty.entity.ExamineMng;
import com.gkhy.safePlatform.targetDuty.service.ExamineMngService;
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.ExamineMngQueryCriteria;
import com.gkhy.safePlatform.targetDuty.model.dto.resp.ExamineMngDto;
import com.gkhy.safePlatform.targetDuty.utils.QueryHelpPlus;
import com.gkhy.safePlatform.commons.utils.BeanCopyUtils;
import org.springframework.util.StringUtils;
 
import java.io.Serializable;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;
 
/**
 * 安全考核管理(ExamineMng)表服务实现类
 *
 * @author xurui
 * @since 2022-07-21 13:43:08
 */
@Service("examineMngService")
public class ExamineMngServiceImpl extends ServiceImpl<ExamineMngRepository, ExamineMng> implements ExamineMngService {
 
    @Autowired
    private ExamineMngRepository examineMngRepository;
    @Autowired
    private ExamineItemRepository examineItemRepository;
 
 
    @Override
    public ResultVO queryAll(PageQuery<ExamineMngQueryCriteria> pageQuery) {
        Long pageIndex = pageQuery.getPageIndex();
        Long pageSize = pageQuery.getPageSize();
        IPage<ExamineMng> page = new Page<>(pageIndex, pageSize);
 
        page = baseMapper.selectPage(page,
                QueryHelpPlus.getPredicate(ExamineMng.class, pageQuery.getSearchParams()));
        List<ExamineMngDto> respList = BeanCopyUtils.copyBeanList(page.getRecords(), ExamineMngDto.class);
        // TODO:获取考核部门名称
 
        // TODO:获取被考核部门名称
 
        return new SearchResultVO<>(
                true,
                pageIndex,
                pageSize,page.getPages(),
                page.getTotal(),
                respList,
                ResultCodes.OK
        );
    }
 
 
    @Override
    public List<ExamineMng> queryAll(ExamineMngQueryCriteria criteria) {
        return baseMapper.selectList(QueryHelpPlus.getPredicate(ExamineMng.class, criteria));
    }
 
    @Override
    public ExamineMngDto selectOne(Serializable id) {
        ExamineMng examineMng = this.getById(id);
        if(examineMng == null){
            return null;
        }
 
        ExamineMngDto dto = BeanCopyUtils.copyBean(examineMng, ExamineMngDto.class);
        if(!StringUtils.hasText(examineMng.getNumberDetailJson())){
            return dto;
        }
 
        //获取打分明细
        List<CurrentExamineDto> list = JSONObject.parseArray( examineMng.getNumberDetailJson(), CurrentExamineDto.class);
        List<Long> idList = list.stream().map(CurrentExamineDto::getId).collect(Collectors.toList());
 
        List<ExamineItem> itemList = examineItemRepository.selectBatchIds(idList);
        Map<Long,ExamineItem> itemMap = itemList.stream().collect(
                Collectors.toMap(ExamineItem::getId, Function.identity(),(k1, k2)->k1));
 
        if(itemMap != null){
            list.forEach(f->{
                ExamineItem item = itemMap.get(f.getId());
                if(item != null){
                    f.setItemDetail(item.getItemDetail());
                    f.setContent(item.getContent());
                }
            });
        }
        dto.setCurrentExamineDtoList(list);
        return dto;
    }
}