|
@@ -0,0 +1,209 @@
|
|
|
+package com.ims.eval.service.impl;
|
|
|
+
|
|
|
+import com.ims.common.utils.StringUtils;
|
|
|
+import com.ims.eval.cache.CacheContext;
|
|
|
+import com.ims.eval.config.CustomException;
|
|
|
+import com.ims.eval.entity.*;
|
|
|
+import com.ims.eval.dao.OrganizationEvaluationCommonInfoMapper;
|
|
|
+import com.ims.eval.entity.dto.request.AddEvaluationInfoDTO;
|
|
|
+import com.ims.eval.entity.dto.response.IndicatorResDTO;
|
|
|
+import com.ims.eval.service.*;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.ims.eval.util.MathCalculatorUtil;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+
|
|
|
+import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * <p>
|
|
|
+ * 服务实现类
|
|
|
+ * </p>
|
|
|
+ *
|
|
|
+ * @author wang
|
|
|
+ * @since 2023-09-11
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class OrganizationEvaluationCommonInfoServiceImpl extends ServiceImpl<OrganizationEvaluationCommonInfoMapper, OrganizationEvaluationCommonInfo> implements IOrganizationEvaluationCommonInfoService {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IOrganizationEvaluationService organizationEvaluationService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IOrganizationEvaluationRuleService organizationEvaluationRuleService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IIndicatorService indicatorService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IIndicatorDictionaryService indicatorDictionaryService;
|
|
|
+
|
|
|
+
|
|
|
+ @Transactional
|
|
|
+ @Override
|
|
|
+ public boolean addEvaluationCommonInfo(List<AddEvaluationInfoDTO> addEvaluationInfoDTOs) {
|
|
|
+ for (AddEvaluationInfoDTO addEvaluationInfoDTO : addEvaluationInfoDTOs) {
|
|
|
+
|
|
|
+ List<OrganizationEvaluationCommonInfo> infoResDTOList = baseMapper.selectListAll(addEvaluationInfoDTO.getOrganizationEvaluationId(),addEvaluationInfoDTO.getIndicatorId(),addEvaluationInfoDTO.getOrganizationId(),addEvaluationInfoDTO.getDeptName());
|
|
|
+ //判断是否已存在记录
|
|
|
+ if(null != infoResDTOList && infoResDTOList.size()>0){
|
|
|
+ //当前部门存在记录;移除保存
|
|
|
+ List<String> commonIds = infoResDTOList.stream().map(OrganizationEvaluationCommonInfo::getId).collect(Collectors.toList());
|
|
|
+ boolean b = this.removeByIds(commonIds);
|
|
|
+ if(!b){
|
|
|
+ throw new CustomException("保存失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //1.获取考评id(获取此考评记录)
|
|
|
+ String organizationEvaluationId = addEvaluationInfoDTO.getOrganizationEvaluationId();
|
|
|
+
|
|
|
+ if (StringUtils.isEmpty(organizationEvaluationId)) {
|
|
|
+ throw new CustomException("保存失败");
|
|
|
+ }
|
|
|
+ OrganizationEvaluation organizationEvaluation = organizationEvaluationService.getById(organizationEvaluationId);
|
|
|
+
|
|
|
+ if (null == organizationEvaluation) {
|
|
|
+ throw new CustomException("保存失败");
|
|
|
+ }
|
|
|
+ organizationEvaluation.getCheckCycle();
|
|
|
+
|
|
|
+ //2.获取组织id 和所属板块(判断该板块下是否有此组织的考核)
|
|
|
+ String organizationType = organizationEvaluation.getOrganizationType();//考评类型 DWKP
|
|
|
+ String checkCycle = organizationEvaluation.getCheckCycle();//考评周期-月度、季度
|
|
|
+ String year = organizationEvaluation.getYear();//年份
|
|
|
+
|
|
|
+ //3.查询当前对应的考评权重(需要考评的单位)
|
|
|
+ List<OrganizationEvaluationRule> evaluationRules = organizationEvaluationRuleService.getOrganizationEvaluationRuleByYearAndCycle(organizationType, checkCycle, year, addEvaluationInfoDTO.getOrganizationId());
|
|
|
+ if (null == evaluationRules || evaluationRules.size() <= 0) {
|
|
|
+ throw new CustomException("当前组织没有参与考评");
|
|
|
+ }
|
|
|
+ OrganizationEvaluationRule evaluationRule = evaluationRules.get(0);
|
|
|
+
|
|
|
+ //4.获取指标信息
|
|
|
+ List<String> indicatorIds = Arrays.asList(addEvaluationInfoDTO.getIndicatorId().split(","));
|
|
|
+ List<IndicatorResDTO> dictionaryList = indicatorService.listByIds(indicatorIds);
|
|
|
+ Map<String, List<IndicatorResDTO>> groupedChildCode = dictionaryList.stream()
|
|
|
+ .collect(Collectors.groupingBy(d -> d.getChildCode() + "," + d.getChildName()));
|
|
|
+ Map<String, Object> optionMap = addEvaluationInfoDTO.getOptionMap();
|
|
|
+
|
|
|
+ //5.保存指标
|
|
|
+ for (Map.Entry<String, List<IndicatorResDTO>> childCodeEntry : groupedChildCode.entrySet()) {
|
|
|
+
|
|
|
+ for (IndicatorResDTO d : childCodeEntry.getValue()) {
|
|
|
+ OrganizationEvaluationCommonInfo info = new OrganizationEvaluationCommonInfo();
|
|
|
+ info.setOrganizationEvaluationId(addEvaluationInfoDTO.getOrganizationEvaluationId());
|
|
|
+ info.setOrganizationId(evaluationRule.getOrganizationId());
|
|
|
+ info.setIndicatorId(addEvaluationInfoDTO.getIndicatorId());
|
|
|
+ info.setIndicatorDictionaryId(d.getId());
|
|
|
+ info.setOptionCode(d.getOptionCode());
|
|
|
+ info.setIsQuantified(d.getIsQuantified());
|
|
|
+ if (null != optionMap.get(d.getChildCode() + "_" + d.getOptionCode())) {
|
|
|
+ Object value = optionMap.get(d.getChildCode() + "_" +d.getOptionCode());
|
|
|
+ if (null != value) {
|
|
|
+ info.setNonQuantifiedValue(String.valueOf(value));
|
|
|
+ if (d.getIsQuantified()) {
|
|
|
+
|
|
|
+ if (MathCalculatorUtil.isNumber(value.toString())) {
|
|
|
+ info.setQuantifiedValue(Double.valueOf(value.toString()));
|
|
|
+ } else {
|
|
|
+ info.setQuantifiedValue(0);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ info.setChildCode(d.getChildCode());
|
|
|
+ CacheContext.ddSuperKeyMap.containsKey("BM0001");
|
|
|
+
|
|
|
+ if (StringUtils.isNotEmpty(addEvaluationInfoDTO.getDeptName()) && CacheContext.ddSuperKeyMap.containsKey("BM0001")){
|
|
|
+ Optional<DataDictionary> any = CacheContext.ddSuperKeyMap.get("BM0001").stream().filter(t -> t.getKeyName().equals(addEvaluationInfoDTO.getDeptName())).findAny();
|
|
|
+ DataDictionary di = any.isPresent() ? any.get() : null;
|
|
|
+ info.setDeptId(di.getDataKey());
|
|
|
+ info.setDeptName(addEvaluationInfoDTO.getDeptName());
|
|
|
+ }
|
|
|
+
|
|
|
+ saveOrUpdate(info);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Map getListAll(String organizationEvaluationId, String indicatorId, String organizationId, String deptId) {
|
|
|
+
|
|
|
+ //生成标题
|
|
|
+ List<IndicatorDictionary> dictionaryList = indicatorDictionaryService.list("", indicatorId, "", "");
|
|
|
+ Map<String, List<IndicatorDictionary>> groupedChildCode = dictionaryList.stream()
|
|
|
+ .collect(Collectors.groupingBy(d -> d.getChildCode() + "," + d.getChildName()));
|
|
|
+ Map data = new HashMap();
|
|
|
+ Map title = new LinkedHashMap();
|
|
|
+ for (Map.Entry<String, List<IndicatorDictionary>> childCodeEntry : groupedChildCode.entrySet()) {
|
|
|
+ List<Map> titleArray = new ArrayList<>();
|
|
|
+ for (IndicatorDictionary d : childCodeEntry.getValue()) {
|
|
|
+ Map titlemap = new LinkedHashMap();
|
|
|
+ if (!d.getIsShow()) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ titlemap.put("key", d.getOptionName());//名称
|
|
|
+ titlemap.put("code",d.getChildCode()+"_"+d.getOptionCode());//名称
|
|
|
+ titlemap.put("flag", d.getIsQuantified()?"1":"2");//是否量化
|
|
|
+ titleArray.add(titlemap);
|
|
|
+ }
|
|
|
+ title.put(childCodeEntry.getKey().split(",")[1], titleArray);
|
|
|
+ }
|
|
|
+ data.put("title", title);
|
|
|
+ //获取数据
|
|
|
+
|
|
|
+ List<OrganizationEvaluationCommonInfo> list = baseMapper.selectListAll(organizationEvaluationId,indicatorId,organizationId,deptId);
|
|
|
+
|
|
|
+ //根据部门id分组
|
|
|
+ Map<String, List<OrganizationEvaluationCommonInfo>> groupedData = list.stream()
|
|
|
+ .collect(Collectors.groupingBy(OrganizationEvaluationCommonInfo::getDeptId));
|
|
|
+ List<Map> mapList = new ArrayList<>();
|
|
|
+ //遍历按照部门分组的数据
|
|
|
+ for (Map.Entry<String, List<OrganizationEvaluationCommonInfo>> entry : groupedData.entrySet()) {
|
|
|
+
|
|
|
+ Map indicatormap = new HashMap();
|
|
|
+ List<OrganizationEvaluationCommonInfo> dtoList = entry.getValue();
|
|
|
+ Map<String, OrganizationEvaluationCommonInfo> resultMap = dtoList.stream()
|
|
|
+ .collect(Collectors.toMap(
|
|
|
+ dto -> dto.getChildCode() + "_" + dto.getOptionCode(),
|
|
|
+ dto -> dto,
|
|
|
+ (oldValue, newValue) -> oldValue));
|
|
|
+
|
|
|
+ boolean mark = true;//标记给单位
|
|
|
+ for (IndicatorDictionary d : dictionaryList) {
|
|
|
+ if (!d.getIsShow()) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (mark) {
|
|
|
+ indicatormap.put("deptName", resultMap.get(d.getChildCode()+"_"+d.getOptionCode()).getDeptName());//公司名
|
|
|
+ indicatormap.put("organizationId", resultMap.get(d.getChildCode()+"_"+d.getOptionCode()).getOrganizationId());//公司id
|
|
|
+ mark = false;
|
|
|
+ }
|
|
|
+
|
|
|
+ //指标属性
|
|
|
+ indicatormap.put(d.getChildCode() + "_" + d.getOptionCode(), null == resultMap.get(d.getChildCode()+"_"+d.getOptionCode()).getNonQuantifiedValue() ? "" : resultMap.get(d.getChildCode()+"_"+d.getOptionCode()).getNonQuantifiedValue());
|
|
|
+ //指标id
|
|
|
+ indicatormap.put("ID_" + d.getChildCode() + "_" + d.getOptionCode(), resultMap.get(d.getChildCode()+"_"+d.getOptionCode()).getId());
|
|
|
+ //是否量化
|
|
|
+ indicatormap.put("IS_LH_" +d.getChildCode() + "_" + d.getOptionCode(),resultMap.get(d.getChildCode()+"_"+d.getOptionCode()).getIsQuantified()?"1":"2");
|
|
|
+
|
|
|
+ mapList.add(indicatormap);
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ data.put("value", mapList);
|
|
|
+
|
|
|
+ return data;
|
|
|
+ }
|
|
|
+}
|