|
@@ -46,6 +46,7 @@ import java.math.BigDecimal; |
|
|
import java.time.LocalDateTime; |
|
|
import java.time.LocalDateTime; |
|
|
import java.util.Arrays; |
|
|
import java.util.Arrays; |
|
|
import java.util.List; |
|
|
import java.util.List; |
|
|
|
|
|
import java.util.Map; |
|
|
import java.util.Objects; |
|
|
import java.util.Objects; |
|
|
import java.util.stream.Collectors; |
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
@@ -375,20 +376,73 @@ public class IndicatorConfigManage { |
|
|
// 新增指标详情 |
|
|
// 新增指标详情 |
|
|
List<PerformanceIndicatorProjectTemplateDetail> projectTemplateDetails = indicatorProjectTemplateDetailService.list(Wrappers.lambdaQuery(PerformanceIndicatorProjectTemplateDetail.class) |
|
|
List<PerformanceIndicatorProjectTemplateDetail> projectTemplateDetails = indicatorProjectTemplateDetailService.list(Wrappers.lambdaQuery(PerformanceIndicatorProjectTemplateDetail.class) |
|
|
.eq(PerformanceIndicatorProjectTemplateDetail::getTemplateId, templateId)); |
|
|
.eq(PerformanceIndicatorProjectTemplateDetail::getTemplateId, templateId)); |
|
|
// 逐个新增并保存各指标 |
|
|
|
|
|
for (PerformanceIndicatorProjectTemplateDetail projectTemplateDetail : projectTemplateDetails) { |
|
|
|
|
|
PerformanceIndicatorProjectTemplateDetail newProjectTemplateDetail = new PerformanceIndicatorProjectTemplateDetail(); |
|
|
|
|
|
BeanUtils.copyProperties(projectTemplateDetail, newProjectTemplateDetail); |
|
|
|
|
|
newProjectTemplateDetail.setTemplateId(newTemplate.getId()); |
|
|
|
|
|
newProjectTemplateDetail.setCreateOn(LocalDateTime.now()); |
|
|
|
|
|
newProjectTemplateDetail.setCreateBy(user.getUsername()); |
|
|
|
|
|
newProjectTemplateDetail.setUpdateOn(LocalDateTime.now()); |
|
|
|
|
|
newProjectTemplateDetail.setUpdateBy(user.getUsername()); |
|
|
|
|
|
// 新的指标ID要置空 |
|
|
|
|
|
newProjectTemplateDetail.setId(null); |
|
|
|
|
|
indicatorProjectTemplateDetailService.save(newProjectTemplateDetail); |
|
|
|
|
|
|
|
|
Map<Long, PerformanceIndicatorProjectTemplateDetail> detailMap = projectTemplateDetails.stream().collect(Collectors.toMap(PerformanceIndicatorProjectTemplateDetail::getId, p -> p)); |
|
|
|
|
|
// 按层级逐个新增并保存各指标 |
|
|
|
|
|
// 从三级指标开始 |
|
|
|
|
|
List<PerformanceIndicatorProjectTemplateDetail> thirdList = projectTemplateDetails.stream() |
|
|
|
|
|
.filter(p -> PerformanceTemplateTypeEnum.THIRD_INDEX.getCode().equals(p.getType())) |
|
|
|
|
|
.collect(Collectors.toList()); |
|
|
|
|
|
if (CollUtil.isEmpty(thirdList)){ |
|
|
|
|
|
throw new BizException("当前模板未配置三级指!"); |
|
|
|
|
|
} |
|
|
|
|
|
List<PerformanceIndicatorProjectTemplateDetail> templateDetails = Lists.newArrayList(); |
|
|
|
|
|
for (PerformanceIndicatorProjectTemplateDetail templateDetail : thirdList) { |
|
|
|
|
|
PerformanceIndicatorProjectTemplateDetail newThirdTemplateDetail = new PerformanceIndicatorProjectTemplateDetail(); |
|
|
|
|
|
BeanUtils.copyProperties(templateDetail, newThirdTemplateDetail); |
|
|
|
|
|
newThirdTemplateDetail.setTemplateId(newTemplate.getId()); |
|
|
|
|
|
newThirdTemplateDetail.setCreateOn(LocalDateTime.now()); |
|
|
|
|
|
newThirdTemplateDetail.setCreateBy(user.getUsername()); |
|
|
|
|
|
newThirdTemplateDetail.setUpdateOn(LocalDateTime.now()); |
|
|
|
|
|
newThirdTemplateDetail.setUpdateBy(user.getUsername()); |
|
|
|
|
|
// 新的指标ID、parentId要置空 |
|
|
|
|
|
newThirdTemplateDetail.setId(null); |
|
|
|
|
|
newThirdTemplateDetail.setParentId(null); |
|
|
|
|
|
indicatorProjectTemplateDetailService.save(newThirdTemplateDetail); |
|
|
|
|
|
// 再保存关联的二级指标 |
|
|
|
|
|
Long thirdParentId = templateDetail.getParentId(); |
|
|
|
|
|
PerformanceIndicatorProjectTemplateDetail secondTemplateDetail = detailMap.get(thirdParentId); |
|
|
|
|
|
if (Objects.isNull(secondTemplateDetail)){ |
|
|
|
|
|
throw new BizException("三级指标:" + templateDetail.getName() + "对应的二级指标不存在"); |
|
|
|
|
|
} |
|
|
|
|
|
PerformanceIndicatorProjectTemplateDetail newSecondTemplateDetail = new PerformanceIndicatorProjectTemplateDetail(); |
|
|
|
|
|
BeanUtils.copyProperties(secondTemplateDetail, newSecondTemplateDetail); |
|
|
|
|
|
newSecondTemplateDetail.setTemplateId(newTemplate.getId()); |
|
|
|
|
|
newSecondTemplateDetail.setCreateOn(LocalDateTime.now()); |
|
|
|
|
|
newSecondTemplateDetail.setCreateBy(user.getUsername()); |
|
|
|
|
|
newSecondTemplateDetail.setUpdateOn(LocalDateTime.now()); |
|
|
|
|
|
newSecondTemplateDetail.setUpdateBy(user.getUsername()); |
|
|
|
|
|
// 新的指标Id、parentId要置空 |
|
|
|
|
|
newSecondTemplateDetail.setId(null); |
|
|
|
|
|
newSecondTemplateDetail.setParentId(null); |
|
|
|
|
|
indicatorProjectTemplateDetailService.save(newSecondTemplateDetail); |
|
|
|
|
|
// 关联三级指标 |
|
|
|
|
|
newThirdTemplateDetail.setParentId(newSecondTemplateDetail.getId()); |
|
|
|
|
|
templateDetails.add(newThirdTemplateDetail); |
|
|
|
|
|
// 再保存关联的一级指标 |
|
|
|
|
|
Long secondParentId = secondTemplateDetail.getParentId(); |
|
|
|
|
|
PerformanceIndicatorProjectTemplateDetail firstTemplateDetail = detailMap.get(secondParentId); |
|
|
|
|
|
if (Objects.isNull(firstTemplateDetail)){ |
|
|
|
|
|
throw new BizException("二级指标:" + secondTemplateDetail.getName() + "对应的一级指标不存在"); |
|
|
|
|
|
} |
|
|
|
|
|
PerformanceIndicatorProjectTemplateDetail newFirstTemplateDetail = new PerformanceIndicatorProjectTemplateDetail(); |
|
|
|
|
|
BeanUtils.copyProperties(firstTemplateDetail, newFirstTemplateDetail); |
|
|
|
|
|
newFirstTemplateDetail.setTemplateId(newTemplate.getId()); |
|
|
|
|
|
newFirstTemplateDetail.setCreateOn(LocalDateTime.now()); |
|
|
|
|
|
newFirstTemplateDetail.setCreateBy(user.getUsername()); |
|
|
|
|
|
newFirstTemplateDetail.setUpdateOn(LocalDateTime.now()); |
|
|
|
|
|
newFirstTemplateDetail.setUpdateBy(user.getUsername()); |
|
|
|
|
|
// 新的指标ID、parentId要置空 |
|
|
|
|
|
newFirstTemplateDetail.setId(null); |
|
|
|
|
|
newFirstTemplateDetail.setParentId(null); |
|
|
|
|
|
indicatorProjectTemplateDetailService.save(newFirstTemplateDetail); |
|
|
|
|
|
// 关联二级指标 |
|
|
|
|
|
newSecondTemplateDetail.setParentId(newFirstTemplateDetail.getId()); |
|
|
|
|
|
templateDetails.add(newSecondTemplateDetail); |
|
|
|
|
|
} |
|
|
|
|
|
// 批量更新 |
|
|
|
|
|
if (indicatorProjectTemplateDetailService.updateBatchById(templateDetails)) { |
|
|
|
|
|
return "模版复制成功"; |
|
|
} |
|
|
} |
|
|
return "模版复制成功"; |
|
|
|
|
|
} |
|
|
} |
|
|
return "模版复制失败"; |
|
|
return "模版复制失败"; |
|
|
} |
|
|
} |
|
|