heheng
2025-11-14 6b652d0e9269156936a1d6425829e104b7e680b5
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
package com.gkhy.exam.system.service.impl;
 
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gkhy.exam.common.api.CommonPage;
import com.gkhy.exam.common.api.CommonResult;
import com.gkhy.exam.common.utils.PageUtils;
import com.gkhy.exam.common.utils.SecurityUtils;
import com.gkhy.exam.system.domain.PerformanceEvaluation;
import com.gkhy.exam.system.domain.PerformanceEvaluationAnalyse;
import com.gkhy.exam.system.domain.PerformanceEvaluationType;
import com.gkhy.exam.system.mapper.PerformanceEvaluationAnalyseMapper;
import com.gkhy.exam.system.mapper.PerformanceEvaluationMapper;
import com.gkhy.exam.system.mapper.PerformanceEvaluationTypeMapper;
import com.gkhy.exam.system.service.PerformanceEvaluationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
 
@Service
public class PerformanceEvaluationServiceImpl extends ServiceImpl<PerformanceEvaluationMapper, PerformanceEvaluation> implements PerformanceEvaluationService {
 
    @Autowired
    private PerformanceEvaluationMapper performanceEvaluationMapper;
 
    @Autowired
    private PerformanceEvaluationTypeMapper performanceEvaluationTypeMapper;
 
    @Autowired
    private PerformanceEvaluationAnalyseMapper performanceEvaluationAnalyseMapper;
 
 
    @Override
    public CommonPage selectPerformanceEvaluationList(PerformanceEvaluation performanceEvaluation) {
        if (!SecurityUtils.adminUser()){
            if (performanceEvaluation.getCompanyId()==null){
                throw new RuntimeException("非管理员操作,查询条件不可为空");
            }
        }
        PageUtils.startPage();
        List<PerformanceEvaluation> performanceEvaluations = performanceEvaluationMapper.selectEvaluationList(performanceEvaluation);
        for (PerformanceEvaluation evaluation : performanceEvaluations) {
            List<PerformanceEvaluationType> performanceEvaluationTypes = performanceEvaluationTypeMapper.selectTypeList(evaluation.getId());
            for (PerformanceEvaluationType performanceEvaluationType : performanceEvaluationTypes) {
                List<PerformanceEvaluationAnalyse> performanceEvaluationAnalyses = performanceEvaluationAnalyseMapper.selectByEvaluationId(performanceEvaluationType.getId());
                performanceEvaluationType.setAnalyses(performanceEvaluationAnalyses);
            }
            evaluation.setTypes(performanceEvaluationTypes);
        }
        return CommonPage.restPage(performanceEvaluations);
    }
 
    @Override
    @Transactional
    public CommonResult insertPerformanceEvaluation(PerformanceEvaluation performanceEvaluation) {
        List<PerformanceEvaluationType> types = performanceEvaluation.getTypes();
        performanceEvaluation.setCreateTime(LocalDateTime.now());
        performanceEvaluation.setCreateBy(SecurityUtils.getUsername());
        int insert = performanceEvaluationMapper.insert(performanceEvaluation);
        ArrayList<PerformanceEvaluationAnalyse> performanceEvaluationAnalyses = new ArrayList<>();
        if (insert>0){
            if (types != null && !types.isEmpty()) {
                for (PerformanceEvaluationType type : types) {
                    type.setEvaluationId(performanceEvaluation.getId());
                }
                performanceEvaluationTypeMapper.insertTypes(types);
            }
            List<PerformanceEvaluationAnalyse> allAnalyses = types.stream()
                    .filter(type -> type.getAnalyses() != null)
                    .flatMap(type -> {
                        type.getAnalyses().forEach(analysis ->
                                analysis.setTypeId(type.getId()));
                        return type.getAnalyses().stream();
                    })
                    .collect(Collectors.toList());
 
            if (!allAnalyses.isEmpty()) {
                performanceEvaluationAnalyseMapper.saveAnalyse(allAnalyses);
            }
        }
        return CommonResult.success();
    }
 
    @Override
    @Transactional
    public CommonResult updatePerformanceEvaluation(PerformanceEvaluation performanceEvaluation) {
        List<PerformanceEvaluationType> types = performanceEvaluation.getTypes();
        performanceEvaluation.setUpdateBy(SecurityUtils.getUsername());
        performanceEvaluation.setUpdateTime(LocalDateTime.now());
        int update = performanceEvaluationMapper.updateById(performanceEvaluation);
        if (update>0){
            performanceEvaluationTypeMapper.deleteByEvaluationId(performanceEvaluation.getId());
            if (types != null && !types.isEmpty()) {
                for (PerformanceEvaluationType type : types) {
                    type.setEvaluationId(performanceEvaluation.getId());
                }
                performanceEvaluationTypeMapper.insertTypes(types);
            }
            List<PerformanceEvaluationAnalyse> allAnalyses = types.stream()
                    .filter(type -> type.getAnalyses() != null)
                    .flatMap(type -> {
                        type.getAnalyses().forEach(analysis ->
                                analysis.setTypeId(type.getId()));
                        return type.getAnalyses().stream();
                    })
                    .collect(Collectors.toList());
 
            if (!allAnalyses.isEmpty()) {
                performanceEvaluationAnalyseMapper.saveAnalyse(allAnalyses);
            }
        }
        return CommonResult.success();
    }
 
    @Override
    public CommonResult deletedPerformanceEvaluation(Integer evaluationId) {
        PerformanceEvaluation performanceEvaluation = new PerformanceEvaluation();
        performanceEvaluation.setId(evaluationId);
        performanceEvaluation.setDelFlag(2);
        performanceEvaluation.setUpdateTime(LocalDateTime.now());
        performanceEvaluation.setUpdateBy(SecurityUtils.getUsername());
        int update = performanceEvaluationMapper.updateById(performanceEvaluation);
        if (update>0){
            return CommonResult.success();
        }
        return CommonResult.failed();
    }
}