|
|
@@ -9,6 +9,8 @@ import com.google.common.collect.Lists; |
|
|
|
import com.ningdatech.basic.exception.BizException; |
|
|
|
import com.ningdatech.basic.function.VUtils; |
|
|
|
import com.ningdatech.basic.model.PageVo; |
|
|
|
import com.ningdatech.pmapi.common.enumeration.CommonEnum; |
|
|
|
import com.ningdatech.pmapi.performance.enumration.PerformanceTemplateStageNameEnum; |
|
|
|
import com.ningdatech.pmapi.performance.enumration.PerformanceTemplateTypeEnum; |
|
|
|
import com.ningdatech.pmapi.performance.model.dto.PerformanceIndicatorProjectTemplateSaveDTO; |
|
|
|
import com.ningdatech.pmapi.performance.model.dto.ProjectTemplateDetailDTO; |
|
|
@@ -25,9 +27,9 @@ import lombok.AllArgsConstructor; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
import org.springframework.stereotype.Component; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
|
|
|
import java.time.LocalDateTime; |
|
|
|
import java.util.Collections; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Objects; |
|
|
|
import java.util.stream.Collectors; |
|
|
@@ -42,7 +44,7 @@ import java.util.stream.Collectors; |
|
|
|
@Component |
|
|
|
@AllArgsConstructor |
|
|
|
public class IndicatorTemplateManage { |
|
|
|
private final IPerformanceIndicatorProjectTemplateService indicatorTemplateService; |
|
|
|
private final IPerformanceIndicatorProjectTemplateService indicatorProjectTemplateService; |
|
|
|
|
|
|
|
private final IPerformanceIndicatorProjectTemplateDetailService indicatorProjectTemplateDetailService; |
|
|
|
|
|
|
@@ -56,7 +58,7 @@ public class IndicatorTemplateManage { |
|
|
|
LambdaQueryWrapper<PerformanceIndicatorProjectTemplate> wrapper = Wrappers.lambdaQuery(PerformanceIndicatorProjectTemplate.class) |
|
|
|
.like(StringUtils.isNotBlank(req.getTemplateName()), PerformanceIndicatorProjectTemplate::getName, req.getTemplateName()) |
|
|
|
.eq(StringUtils.isNotBlank(req.getRegionCode()), PerformanceIndicatorProjectTemplate::getRegionCode,req.getRegionCode()); |
|
|
|
indicatorTemplateService.page(page,wrapper); |
|
|
|
indicatorProjectTemplateService.page(page,wrapper); |
|
|
|
|
|
|
|
if(0L == page.getTotal()){ |
|
|
|
return PageVo.empty(); |
|
|
@@ -75,7 +77,7 @@ public class IndicatorTemplateManage { |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
public PerformanceIndicatorProjectTemplateVO projectDetail(Long id) { |
|
|
|
PerformanceIndicatorProjectTemplate template = indicatorTemplateService.getById(id); |
|
|
|
PerformanceIndicatorProjectTemplate template = indicatorProjectTemplateService.getById(id); |
|
|
|
if(Objects.isNull(template)){ |
|
|
|
return null; |
|
|
|
} |
|
|
@@ -94,11 +96,12 @@ public class IndicatorTemplateManage { |
|
|
|
* @param dto |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
@Transactional |
|
|
|
public String projectTemplateSave(PerformanceIndicatorProjectTemplateSaveDTO dto) { |
|
|
|
UserInfoDetails user = LoginUserUtil.loginUserDetail(); |
|
|
|
PerformanceIndicatorProjectTemplate template = BeanUtil.copyProperties(dto, PerformanceIndicatorProjectTemplate.class); |
|
|
|
if(Objects.nonNull(dto.getId())){ |
|
|
|
PerformanceIndicatorProjectTemplate old = indicatorTemplateService.getById(dto.getId()); |
|
|
|
PerformanceIndicatorProjectTemplate old = indicatorProjectTemplateService.getById(dto.getId()); |
|
|
|
VUtils.isTrue(Objects.isNull(old)).throwMessage("该模板不存在!"); |
|
|
|
template.setId(old.getId()); |
|
|
|
}else{ |
|
|
@@ -108,13 +111,24 @@ public class IndicatorTemplateManage { |
|
|
|
} |
|
|
|
template.setUpdateOn(LocalDateTime.now()); |
|
|
|
template.setUpdateBy(user.getUsername()); |
|
|
|
if(indicatorTemplateService.saveOrUpdate(template)){ |
|
|
|
if(indicatorProjectTemplateService.saveOrUpdate(template)){ |
|
|
|
//保存 模板的详情 |
|
|
|
if(CollUtil.isNotEmpty(dto.getTemplateDetails())){ |
|
|
|
//先删除 |
|
|
|
indicatorProjectTemplateDetailService.remove(Wrappers.lambdaQuery(PerformanceIndicatorProjectTemplateDetail.class) |
|
|
|
.eq(PerformanceIndicatorProjectTemplateDetail::getTemplateId,dto.getId())); |
|
|
|
analysisTemplateDetails(dto.getTemplateDetails(),template.getId()); |
|
|
|
|
|
|
|
//校检 3个阶段 总分是不是100 |
|
|
|
List<PerformanceIndicatorProjectTemplateDetail> stages = indicatorProjectTemplateDetailService.list(Wrappers.lambdaQuery(PerformanceIndicatorProjectTemplateDetail.class) |
|
|
|
.eq(PerformanceIndicatorProjectTemplateDetail::getType, PerformanceTemplateTypeEnum.STAGE.getCode()) |
|
|
|
.eq(PerformanceIndicatorProjectTemplateDetail::getTemplateId, template.getId()) |
|
|
|
.in(PerformanceIndicatorProjectTemplateDetail::getName, Lists.newArrayList(PerformanceTemplateStageNameEnum.STAGE_1.getDesc(), |
|
|
|
PerformanceTemplateStageNameEnum.STAGE_2.getDesc(), PerformanceTemplateStageNameEnum.STAGE_3.getDesc()))); |
|
|
|
if(CollUtil.isNotEmpty(stages)){ |
|
|
|
int sum = stages.stream().filter(p -> Objects.nonNull(p.getScore())).mapToInt(PerformanceIndicatorProjectTemplateDetail::getScore).sum(); |
|
|
|
VUtils.isTrue(sum != 100).throwMessage("总分不是100 操作失败!"); |
|
|
|
} |
|
|
|
} |
|
|
|
return "保存成功"; |
|
|
|
} |
|
|
@@ -126,23 +140,22 @@ public class IndicatorTemplateManage { |
|
|
|
* @param templateDetails |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
private void analysisTemplateDetails( |
|
|
|
public void analysisTemplateDetails( |
|
|
|
List<ProjectTemplateDetailDTO> templateDetails,Long templateId) { |
|
|
|
List<PerformanceIndicatorProjectTemplateDetail> details = Lists.newArrayList(); |
|
|
|
if(CollUtil.isEmpty(templateDetails)){ |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
analysisTemplateDetailsInner(templateDetails,templateId,null); |
|
|
|
analysisTemplateDetailsInner(templateDetails,templateId,null,null); |
|
|
|
} |
|
|
|
|
|
|
|
private void analysisTemplateDetailsInner(List<ProjectTemplateDetailDTO> templateDetails, |
|
|
|
Long templateId,Long parentId) { |
|
|
|
public void analysisTemplateDetailsInner(List<ProjectTemplateDetailDTO> templateDetails, |
|
|
|
Long templateId,Long parentId,Long stageId) { |
|
|
|
if(CollUtil.isEmpty(templateDetails)){ |
|
|
|
return; |
|
|
|
} |
|
|
|
UserInfoDetails user = LoginUserUtil.loginUserDetail(); |
|
|
|
for(ProjectTemplateDetailDTO detail : templateDetails){ |
|
|
|
//计算阶段的 |
|
|
|
PerformanceIndicatorProjectTemplateDetail templateDetail = BeanUtil.copyProperties(detail, PerformanceIndicatorProjectTemplateDetail.class); |
|
|
|
templateDetail.setCreateBy(user.getUsername()); |
|
|
|
templateDetail.setCreateOn(LocalDateTime.now()); |
|
|
@@ -150,12 +163,46 @@ public class IndicatorTemplateManage { |
|
|
|
templateDetail.setUpdateOn(LocalDateTime.now()); |
|
|
|
templateDetail.setTemplateId(templateId); |
|
|
|
templateDetail.setParentId(parentId); |
|
|
|
//如果是阶段的计算下 总分 |
|
|
|
if(!PerformanceTemplateTypeEnum.STAGE.getCode().equals(templateDetail.getType())){ |
|
|
|
templateDetail.setStageId(stageId); |
|
|
|
} |
|
|
|
indicatorProjectTemplateDetailService.save(templateDetail); |
|
|
|
//如果是阶段的话 阶段Id 就是自己的id |
|
|
|
if(PerformanceTemplateTypeEnum.STAGE.getCode().equals(templateDetail.getType())){ |
|
|
|
templateDetail.setScore(computeTotalScore(templateDetail)); |
|
|
|
templateDetail.setStageId(templateDetail.getId()); |
|
|
|
indicatorProjectTemplateDetailService.updateById(templateDetail); |
|
|
|
stageId = templateDetail.getId(); |
|
|
|
} |
|
|
|
|
|
|
|
if(CollUtil.isNotEmpty(detail.getChildren())){ |
|
|
|
analysisTemplateDetailsInner(detail.getChildren(),templateId,templateDetail.getId()); |
|
|
|
analysisTemplateDetailsInner(detail.getChildren(),templateId,templateDetail.getId(),stageId); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 计算 此阶段下的 总分 |
|
|
|
* @param templateDetail |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
private Integer computeTotalScore(PerformanceIndicatorProjectTemplateDetail templateDetail) { |
|
|
|
Integer total = 0; |
|
|
|
if(Objects.isNull(templateDetail) || Objects.isNull(templateDetail.getId())){ |
|
|
|
return total; |
|
|
|
} |
|
|
|
|
|
|
|
if(PerformanceTemplateTypeEnum.STAGE.getCode().equals(templateDetail.getType())){ |
|
|
|
List<PerformanceIndicatorProjectTemplateDetail> thirds = indicatorProjectTemplateDetailService.list(Wrappers.lambdaQuery(PerformanceIndicatorProjectTemplateDetail.class) |
|
|
|
.eq(PerformanceIndicatorProjectTemplateDetail::getTemplateId, templateDetail.getTemplateId()) |
|
|
|
.eq(PerformanceIndicatorProjectTemplateDetail::getStageId, templateDetail.getId()) |
|
|
|
.eq(PerformanceIndicatorProjectTemplateDetail::getType,PerformanceTemplateTypeEnum.THIRD_INDEX.getCode())); |
|
|
|
if(CollUtil.isNotEmpty(thirds)){ |
|
|
|
total = thirds.stream().mapToInt(PerformanceIndicatorProjectTemplateDetail::getScore).sum(); |
|
|
|
} |
|
|
|
} |
|
|
|
return total; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
@@ -199,7 +246,27 @@ public class IndicatorTemplateManage { |
|
|
|
res.add(detailVo); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return res; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 删除项目模板 |
|
|
|
* @param id |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
public String projectTemplateDelete(Long id) { |
|
|
|
PerformanceIndicatorProjectTemplate projectTemplate = indicatorProjectTemplateService.getById(id); |
|
|
|
VUtils.isTrue(Objects.isNull(projectTemplate)).throwMessage("该模板不存在!"); |
|
|
|
|
|
|
|
if(CommonEnum.YES.getCode().equals(projectTemplate.getStatus())){ |
|
|
|
throw new BizException("操作失败 该模板 是启用状态!"); |
|
|
|
} |
|
|
|
|
|
|
|
if(indicatorProjectTemplateService.removeById(id)){ |
|
|
|
indicatorProjectTemplateDetailService.remove(Wrappers.lambdaQuery(PerformanceIndicatorProjectTemplateDetail.class) |
|
|
|
.eq(PerformanceIndicatorProjectTemplateDetail::getTemplateId,id)); |
|
|
|
return "删除成功"; |
|
|
|
} |
|
|
|
return "操作失败"; |
|
|
|
} |
|
|
|
} |