|
|
@ -1,5 +1,9 @@ |
|
|
|
package org.dromara.platform.service.impl; |
|
|
|
|
|
|
|
import cn.hutool.core.collection.CollectionUtil; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
|
|
|
import jakarta.annotation.Resource; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.apache.ibatis.executor.BatchResult; |
|
|
|
import org.dromara.common.core.utils.MapstructUtils; |
|
|
|
import org.dromara.common.core.utils.StringUtils; |
|
|
@ -9,6 +13,11 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
|
|
|
import lombok.RequiredArgsConstructor; |
|
|
|
import org.dromara.platform.domain.EvaluationInfo; |
|
|
|
import org.dromara.platform.domain.dto.EvaluationTreeDto; |
|
|
|
import org.dromara.platform.mapper.EvaluationInfoMapper; |
|
|
|
import org.dromara.platform.service.IEvaluationInfoService; |
|
|
|
import org.springframework.beans.BeanUtils; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.dromara.platform.domain.bo.EvaluationTemplateBo; |
|
|
|
import org.dromara.platform.domain.vo.EvaluationTemplateVo; |
|
|
@ -16,10 +25,7 @@ import org.dromara.platform.domain.EvaluationTemplate; |
|
|
|
import org.dromara.platform.mapper.EvaluationTemplateMapper; |
|
|
|
import org.dromara.platform.service.IEvaluationTemplateService; |
|
|
|
|
|
|
|
import java.util.Comparator; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.Collection; |
|
|
|
import java.util.*; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
/** |
|
|
@ -30,9 +36,14 @@ import java.util.stream.Collectors; |
|
|
|
*/ |
|
|
|
@RequiredArgsConstructor |
|
|
|
@Service |
|
|
|
@Slf4j |
|
|
|
public class EvaluationTemplateServiceImpl implements IEvaluationTemplateService { |
|
|
|
|
|
|
|
private final EvaluationTemplateMapper baseMapper; |
|
|
|
@Resource |
|
|
|
private IEvaluationInfoService evaluationInfoService; |
|
|
|
@Resource |
|
|
|
private EvaluationInfoMapper evaluationInfoMapper; |
|
|
|
|
|
|
|
/** |
|
|
|
* 查询考核评分信息-模板 |
|
|
@ -149,6 +160,7 @@ public class EvaluationTemplateServiceImpl implements IEvaluationTemplateService |
|
|
|
if (StringUtils.isNotBlank(flag)) { |
|
|
|
LambdaQueryWrapper<EvaluationTemplate> lqw = Wrappers.lambdaQuery(); |
|
|
|
lqw.eq(EvaluationTemplate::getFlag, flag); |
|
|
|
|
|
|
|
List<EvaluationTemplate> evaluationTemplates = baseMapper.selectList(lqw); |
|
|
|
|
|
|
|
List<EvaluationTemplate> sortedRecords = evaluationTemplates.stream() |
|
|
@ -164,6 +176,86 @@ public class EvaluationTemplateServiceImpl implements IEvaluationTemplateService |
|
|
|
public int batchEdit(List<EvaluationTemplate> updateList) { |
|
|
|
List<BatchResult> batchResults = baseMapper.updateById(updateList); |
|
|
|
int size = batchResults.size(); |
|
|
|
if (size>0) { |
|
|
|
String flag = updateList.get(0).getFlag(); |
|
|
|
// 定义变量用于累加总分和扣分
|
|
|
|
double totalSumRating = 0; |
|
|
|
double totalSubRating = 0; |
|
|
|
for (EvaluationTemplate item : updateList) { |
|
|
|
// 累加总分
|
|
|
|
if (item.getSumRating() != null) { |
|
|
|
totalSumRating += item.getSumRating(); |
|
|
|
} |
|
|
|
|
|
|
|
// 累加扣分
|
|
|
|
if (item.getSubRating() != null) { |
|
|
|
totalSubRating += item.getSubRating(); |
|
|
|
} |
|
|
|
} |
|
|
|
Double finalScore = totalSumRating - totalSubRating; |
|
|
|
LambdaUpdateWrapper<EvaluationInfo> updateWrapper = new LambdaUpdateWrapper<>(); |
|
|
|
updateWrapper.eq(EvaluationInfo::getId, flag); |
|
|
|
updateWrapper.set(EvaluationInfo::getCheckRating, finalScore); |
|
|
|
int update = evaluationInfoMapper.update(null, updateWrapper); |
|
|
|
if (update>0){ |
|
|
|
log.info("批量修改成功,考核分数为{}",finalScore); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
return size; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public Map<String, Object> getTree() { |
|
|
|
// 1.封装数据
|
|
|
|
List<EvaluationTreeDto> dtoList = new ArrayList<>(); |
|
|
|
LambdaUpdateWrapper<EvaluationTemplate> queryWrapper = new LambdaUpdateWrapper<>(); |
|
|
|
queryWrapper.eq(EvaluationTemplate::getFlag, "模板1"); |
|
|
|
List<EvaluationTemplate> evaluationTemplates = baseMapper.selectList(queryWrapper); |
|
|
|
for (EvaluationTemplate template : evaluationTemplates) { |
|
|
|
EvaluationTreeDto evaluationTreeDto = new EvaluationTreeDto(); |
|
|
|
BeanUtils.copyProperties(template, evaluationTreeDto); |
|
|
|
dtoList.add(evaluationTreeDto); |
|
|
|
} |
|
|
|
if (CollectionUtil.isNotEmpty(dtoList)){ |
|
|
|
return buildTreeWithUniqueId(dtoList); |
|
|
|
} |
|
|
|
return null; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private Map<String, Object> buildTreeWithUniqueId(List<EvaluationTreeDto> list) { |
|
|
|
// 构建树状结构
|
|
|
|
Map<String, List<EvaluationTreeDto>> treeMap = list.stream() |
|
|
|
.collect(Collectors.groupingBy(EvaluationTreeDto::getLargeRating)); |
|
|
|
|
|
|
|
// 将树状结构转换为适合JSON传输的格式,并为每个 largeRating 分配唯一ID
|
|
|
|
List<Map<String, Object>> result = new ArrayList<>(); |
|
|
|
for (Map.Entry<String, List<EvaluationTreeDto>> entry : treeMap.entrySet()) { |
|
|
|
Map<String, Object> node = new HashMap<>(); |
|
|
|
String uniqueId = generateUniqueId();// 生成唯一ID
|
|
|
|
node.put("id", uniqueId); // 添加唯一ID
|
|
|
|
node.put("name", entry.getKey()); // largeRating 名称
|
|
|
|
List<Map<String, String>> children = entry.getValue().stream() |
|
|
|
.map(dto -> { |
|
|
|
Map<String, String> child = new HashMap<>(); |
|
|
|
child.put("id", dto.getId()); |
|
|
|
child.put("name", dto.getSmallRating()); |
|
|
|
return child; |
|
|
|
}).collect(Collectors.toList()); |
|
|
|
node.put("children", children); |
|
|
|
result.add(node); |
|
|
|
} |
|
|
|
|
|
|
|
return Collections.singletonMap("tree", result); // 包装为单个根节点
|
|
|
|
} |
|
|
|
|
|
|
|
private static final Random random = new Random(); |
|
|
|
private String generateUniqueId() { |
|
|
|
// 生成一个0到999之间的随机整数,并加上1000,确保结果在1000到1999之间
|
|
|
|
|
|
|
|
int uniqueIdInt = 1000 + random.nextInt(1000); |
|
|
|
String uniqueId = Integer.toString(uniqueIdInt); |
|
|
|
return uniqueId; |
|
|
|
} |
|
|
|
} |
|
|
|