Browse Source

业绩对标管理功能开发

hlf 9 months ago
parent
commit
841060c05c

+ 6 - 0
ims-service/ims-eval/src/main/java/com/ims/eval/dao/PerformanceBenchmarkInfoMapper.java

@@ -29,4 +29,10 @@ public interface PerformanceBenchmarkInfoMapper extends BaseMapper<PerformanceBe
 											  @Param("degreeYear") Integer degreeYear,
 											  @Param("quarterlyMonth") Integer quarterlyMonth);
 
+	List<PerformanceBenchmarkInfo> selectListByIndexName(@Param("manageCategory") String manageCategory,
+														 @Param("checkCycle") String checkCycle,
+														 @Param("degreeYear") Integer degreeYear,
+														 @Param("quarterlyMonth") Integer quarterlyMonth,
+														 @Param("indexName") String indexName);
+
 }

+ 103 - 17
ims-service/ims-eval/src/main/java/com/ims/eval/service/impl/PerformanceBenchmarkInfoServiceImpl.java

@@ -8,12 +8,15 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.ims.eval.dao.PerformanceBenchmarkInfoMapper;
 import com.ims.eval.entity.*;
 import com.ims.eval.service.*;
+import lombok.Data;
 import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
 import java.util.ArrayList;
 import java.util.Comparator;
 import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
 
 /**
  * @author hlf
@@ -120,7 +123,9 @@ public class PerformanceBenchmarkInfoServiceImpl extends ServiceImpl<Performance
 				}
 			}
 			super.saveBatch(performanceBenchmarkInfoList);
-			addRecord(manageCategory, checkCycle, degreeYear, quarterlyMonth, "寻标");
+			if (performanceBenchmarkInfoList.size() > 0) {
+				addRecord(manageCategory, checkCycle, degreeYear, quarterlyMonth, "寻标");
+			}
 		}
 	}
 
@@ -133,25 +138,89 @@ public class PerformanceBenchmarkInfoServiceImpl extends ServiceImpl<Performance
 	 * @param quarterlyMonth 季/月度
 	 */
 	private void lb(String manageCategory, String checkCycle, Integer degreeYear, Integer quarterlyMonth) {
+		List<PerformanceBenchmarkInfo> updateList = new ArrayList<>();
 		List<BenchmarkingRecord> benchmarkingRecordList = benchmarkingRecordService.selectList(manageCategory, checkCycle, degreeYear, quarterlyMonth, "立标");
 		if (benchmarkingRecordList.size() == 0) {
 			if ("NDKP".equals(checkCycle)) {
 				List<PerformanceBenchmarkInfo> performanceBenchmarkInfoList = baseMapper.selectList(manageCategory, checkCycle, degreeYear, null);
-				double completeValueSum = performanceBenchmarkInfoList.stream().mapToDouble(PerformanceBenchmarkInfo::getCompleteValue).sum();
-				double installCapacitySum = performanceBenchmarkInfoList.stream().mapToDouble(PerformanceBenchmarkInfo::getInstallCapacity).sum();
-				List<PerformanceBenchmarkInfo> updateList = new ArrayList<>();
-				performanceBenchmarkInfoList.forEach(PerformanceBenchmarkInfo -> {
-					PerformanceBenchmarkInfo.setRecommendedValue(yearIndexRecommendedValueA(completeValueSum, installCapacitySum, PerformanceBenchmarkInfo.getInstallCapacity()));
-					updateList.add(PerformanceBenchmarkInfo);
-				});
-				super.updateBatchById(updateList);
+				//Map分组
+				Map<String, List<PerformanceBenchmarkInfo>> grouped = performanceBenchmarkInfoList.stream().collect(Collectors.groupingBy(PerformanceBenchmarkInfo::getIndexName));
+				//Map转List
+				List<PbiGroup> pbiGroupList = grouped.entrySet().stream().map(entry -> new PbiGroup(entry.getKey(), entry.getValue())).collect(Collectors.toList());
+				for (PbiGroup pbiGroup : pbiGroupList) {
+					//指标完成值求和
+					double completeValueSum = pbiGroup.getPbis().stream().mapToDouble(PerformanceBenchmarkInfo::getCompleteValue).sum();
+					//装机容量求和
+					double installCapacitySum = pbiGroup.getPbis().stream().mapToDouble(PerformanceBenchmarkInfo::getInstallCapacity).sum();
+					//往年全年pbiGroup.getIndexName()指标数据
+					List<PerformanceBenchmarkInfo> wnData = baseMapper.selectListByIndexName(manageCategory, checkCycle, degreeYear - 1, null, pbiGroup.getIndexName());
+					//前年全年pbiGroup.getIndexName()指标数据
+					List<PerformanceBenchmarkInfo> qnData = baseMapper.selectListByIndexName(manageCategory, checkCycle, degreeYear - 2, null, pbiGroup.getIndexName());
+					double plannedValueWnSum;
+					double plannedValueQnSum;
+					double completeValueWnSum;
+					if (qnData.size() > 0 && wnData.size() > 0) {
+						//往年计划值
+						plannedValueWnSum = wnData.stream().mapToDouble(PerformanceBenchmarkInfo::getPlannedValue).sum();
+						//往年实际完成值
+						completeValueWnSum = wnData.stream().mapToDouble(PerformanceBenchmarkInfo::getCompleteValue).sum();
+						//前年计划值
+						plannedValueQnSum = qnData.stream().mapToDouble(PerformanceBenchmarkInfo::getPlannedValue).sum();
+					} else if (wnData.size() > 0) {
+						//往年计划值
+						plannedValueWnSum = wnData.stream().mapToDouble(PerformanceBenchmarkInfo::getPlannedValue).sum();
+						plannedValueQnSum = 0;
+						completeValueWnSum = 0;
+					} else {
+						plannedValueWnSum = 0;
+						plannedValueQnSum = 0;
+						completeValueWnSum = 0;
+					}
+					pbiGroup.getPbis().forEach(PerformanceBenchmarkInfo -> {
+						double A = yearIndexRecommendedValueA(completeValueSum, installCapacitySum, PerformanceBenchmarkInfo.getInstallCapacity());
+						double B = yearIndexRecommendedValueB(plannedValueWnSum, plannedValueQnSum, completeValueWnSum);
+						PerformanceBenchmarkInfo.setRecommendedValue(Math.max(A, B));
+						updateList.add(PerformanceBenchmarkInfo);
+					});
+				}
 			} else if ("JDKP".equals(checkCycle) || "YDKP".equals(checkCycle)) {
 				List<PerformanceBenchmarkInfo> performanceBenchmarkInfoList = baseMapper.selectList(manageCategory, checkCycle, degreeYear, quarterlyMonth);
-				List<PerformanceBenchmarkInfo> updateList = new ArrayList<>();
-
-
+				//Map分组
+				Map<String, List<PerformanceBenchmarkInfo>> grouped = performanceBenchmarkInfoList.stream().collect(Collectors.groupingBy(PerformanceBenchmarkInfo::getIndexName));
+				//Map转List
+				List<PbiGroup> pbiGroupList = grouped.entrySet().stream().map(entry -> new PbiGroup(entry.getKey(), entry.getValue())).collect(Collectors.toList());
+				for (PbiGroup pbiGroup : pbiGroupList) {
+					//往年当前季/月pbiGroup.getIndexName()指标数据
+					List<PerformanceBenchmarkInfo> wnfData = baseMapper.selectListByIndexName(manageCategory, checkCycle, degreeYear - 1, quarterlyMonth, pbiGroup.getIndexName());
+					double zb;
+					if (wnfData.size() > 0) {
+						//往年全年pbiGroup.getIndexName()指标数据
+						List<PerformanceBenchmarkInfo> wnhData = baseMapper.selectListByIndexName(manageCategory, checkCycle, degreeYear - 1, null, pbiGroup.getIndexName());
+						//往年全年计划值总和
+						double wnhPlannedValueSum = wnhData.stream().mapToDouble(PerformanceBenchmarkInfo::getPlannedValue).sum();
+						//往年当前季/月计划值总和
+						double wnfPlannedValueSum = wnfData.stream().mapToDouble(PerformanceBenchmarkInfo::getPlannedValue).sum();
+						zb = wnfPlannedValueSum / wnhPlannedValueSum;
+					} else {
+						//当前年pbiGroup.getIndexName()指标全数据
+						double dnPlannedValueSum = pbiGroup.getPbis().stream().mapToDouble(PerformanceBenchmarkInfo::getPlannedValue).sum();
+						if ("JDKP".equals(checkCycle)) {
+							zb = (dnPlannedValueSum / 3) / dnPlannedValueSum;
+						} else {
+							zb = (dnPlannedValueSum / 12) / dnPlannedValueSum;
+						}
+					}
+					double finalZb = zb;
+					performanceBenchmarkInfoList.forEach(PerformanceBenchmarkInfo -> {
+						PerformanceBenchmarkInfo.setRecommendedValue(quarterlyMonthIndexRecommendedValue(PerformanceBenchmarkInfo.getPlannedValue(), finalZb));
+						updateList.add(PerformanceBenchmarkInfo);
+					});
+				}
+			}
+			super.updateBatchById(updateList);
+			if (updateList.size() > 0) {
+				addRecord(manageCategory, checkCycle, degreeYear, quarterlyMonth, "立标");
 			}
-			addRecord(manageCategory, checkCycle, degreeYear, quarterlyMonth, "立标");
 		}
 	}
 
@@ -175,7 +244,9 @@ public class PerformanceBenchmarkInfoServiceImpl extends ServiceImpl<Performance
 				performanceBenchmarkInfoList.get(0).setIsBg(1);
 			}
 			super.updateBatchById(performanceBenchmarkInfoList);
-			addRecord(manageCategory, checkCycle, degreeYear, quarterlyMonth, "标杆");
+			if (performanceBenchmarkInfoList.size() > 0) {
+				addRecord(manageCategory, checkCycle, degreeYear, quarterlyMonth, "标杆");
+			}
 		}
 	}
 
@@ -198,7 +269,9 @@ public class PerformanceBenchmarkInfoServiceImpl extends ServiceImpl<Performance
 				}
 			}
 			super.updateBatchById(performanceBenchmarkInfoList);
-			addRecord(manageCategory, checkCycle, degreeYear, quarterlyMonth, "达标");
+			if (performanceBenchmarkInfoList.size() > 0) {
+				addRecord(manageCategory, checkCycle, degreeYear, quarterlyMonth, "达标");
+			}
 		}
 	}
 
@@ -221,7 +294,9 @@ public class PerformanceBenchmarkInfoServiceImpl extends ServiceImpl<Performance
 				}
 			}));
 			super.updateBatchById(performanceBenchmarkInfoList);
-			addRecord(manageCategory, checkCycle, degreeYear, quarterlyMonth, "超标");
+			if (performanceBenchmarkInfoList.size() > 0) {
+				addRecord(manageCategory, checkCycle, degreeYear, quarterlyMonth, "超标");
+			}
 		}
 	}
 
@@ -238,7 +313,7 @@ public class PerformanceBenchmarkInfoServiceImpl extends ServiceImpl<Performance
 	private Double yearIndexRecommendedValueB(double a, double b, double c) {
 		double B;
 		if (b == 0) {
-			B = a * 0.02;
+			B = a + (a * 0.02);
 		} else {
 			B = (a / b) * c;
 		}
@@ -262,4 +337,15 @@ public class PerformanceBenchmarkInfoServiceImpl extends ServiceImpl<Performance
 		benchmarkingRecord.setTagType(toolCategory);
 		benchmarkingRecordService.save(benchmarkingRecord);
 	}
+
+	@Data
+	private static class PbiGroup {
+		private String indexName;
+		private List<PerformanceBenchmarkInfo> pbis;
+
+		public PbiGroup(String indexName, List<PerformanceBenchmarkInfo> pbis) {
+			this.indexName = indexName;
+			this.pbis = pbis;
+		}
+	}
 }

+ 21 - 0
ims-service/ims-eval/src/main/resources/mappers/PerformanceBenchmarkInfoMapper.xml

@@ -96,4 +96,25 @@
         </where>
     </select>
 
+    <select id="selectListByIndexName" resultType="com.ims.eval.entity.PerformanceBenchmarkInfo">
+        select * from performance_benchmark_info
+        <where>
+            <if test="manageCategory != null and manageCategory != ''">
+                AND manage_category = #{manageCategory}
+            </if>
+            <if test="checkCycle != null and checkCycle != ''">
+                AND check_cycle = #{checkCycle}
+            </if>
+            <if test="degreeYear != null and degreeYear != ''">
+                AND degree_year = #{degreeYear}
+            </if>
+            <if test="quarterlyMonth != null and quarterlyMonth != ''">
+                AND quarterly_month = #{quarterlyMonth}
+            </if>
+            <if test="indexName != null and indexName != ''">
+                AND index_name = #{indexName}
+            </if>
+        </where>
+    </select>
+
 </mapper>