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();
|
}
|
}
|