|
@@ -0,0 +1,298 @@
|
|
|
+package com.ims.eval.service.custom;
|
|
|
+
|
|
|
+import java.time.LocalDate;
|
|
|
+import java.util.*;
|
|
|
+import java.util.function.Function;
|
|
|
+import java.util.regex.Matcher;
|
|
|
+import java.util.regex.Pattern;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+import com.ims.eval.dao.EvaluateReportInfoMapper;
|
|
|
+import com.ims.eval.dao.EvaluateReportMapper;
|
|
|
+import com.ims.eval.entity.EvaluateReport;
|
|
|
+import com.ims.eval.entity.EvaluateReportInfo;
|
|
|
+import com.ims.eval.service.custom.enums.AIDateTypeEnum;
|
|
|
+import lombok.Data;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+
|
|
|
+@RestController
|
|
|
+public class AIIntelligentService {
|
|
|
+
|
|
|
+ private Map<String, EvaluateReportInfo> evaluateReportInfoMap = new HashMap<>();
|
|
|
+
|
|
|
+
|
|
|
+ @Value("${AI.scoreType}")
|
|
|
+ private String scoreType;
|
|
|
+
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private EvaluateReportInfoMapper evaluateReportInfoMapper;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private EvaluateReportMapper evaluateReportMapper;
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 智能生成结果
|
|
|
+ */
|
|
|
+ public String intelligentGeneration(String question) {
|
|
|
+ StringBuilder sb = new StringBuilder();
|
|
|
+ if (question.length() < 5 && (question.contains("你好") || question.contains("您好"))) {
|
|
|
+ sb.append("你好!请问有什么我可以帮助你的吗?");
|
|
|
+ return sb.toString();
|
|
|
+ }
|
|
|
+ Map<String, EvaluateReportInfo> erimap = new HashMap<>();
|
|
|
+ evaluateReportInfoMap = getEvaluateReportInfoMap();
|
|
|
+ erimap = evaluateReportInfoMap.values().stream().filter(eri -> question.contains(eri.getOrganizationName())).collect(Collectors.toMap(EvaluateReportInfo::getEvaluateReportId, Function.identity()));
|
|
|
+ if (erimap.isEmpty()) {
|
|
|
+ sb.append("抱歉,这个知识我还在学习中");
|
|
|
+ return sb.toString();
|
|
|
+ }
|
|
|
+ getConcrete(erimap, question, sb);
|
|
|
+ return sb.toString();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取具体时间报表
|
|
|
+ */
|
|
|
+ private void getConcrete(Map<String, EvaluateReportInfo> erimap, String question, StringBuilder sb) {
|
|
|
+ List<EvaluateReport> ler = evaluateReportMapper.selectBatchIds(erimap.keySet());
|
|
|
+ AIDateInfo ad = getDate(question);
|
|
|
+ if (ad.getInfoYear() == null && ad.getInfoQuarter() == null && ad.getInfoMonth() == null) {
|
|
|
+ ad = new AIDateInfo();
|
|
|
+ ad.setType(AIDateTypeEnum.Year);
|
|
|
+ ad.setInfoYear(LocalDate.now().getYear() + "");
|
|
|
+ }
|
|
|
+ switch (ad.getType()) {
|
|
|
+ case Year:
|
|
|
+ getYearData(ler, ad, sb, erimap, question);
|
|
|
+ break;
|
|
|
+ case YearQuarter:
|
|
|
+ getYearQuarterData(ler, ad, sb, erimap, question);
|
|
|
+ break;
|
|
|
+ case YearMonth:
|
|
|
+ getYearMonthData(ler, ad, sb, erimap, question);
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 有年和月
|
|
|
+ */
|
|
|
+ private void getYearMonthData(List<EvaluateReport> ler, AIDateInfo ad, StringBuilder sb, Map<String, EvaluateReportInfo> erimap, String question) {
|
|
|
+ int mark = 0;
|
|
|
+ for (EvaluateReport er : ler) {
|
|
|
+ if (ad.getInfoYear().equals(er.getYear()) && ad.getInfoMonth().equals(er.getMonth())) {
|
|
|
+ getInfoScore(sb, er, erimap, question);
|
|
|
+ mark++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (mark == 0) {
|
|
|
+ sb.append("抱歉,这个知识我还在学习中");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 有年和季度
|
|
|
+ */
|
|
|
+ private void getYearQuarterData(List<EvaluateReport> ler, AIDateInfo ad, StringBuilder sb, Map<String, EvaluateReportInfo> erimap, String question) {
|
|
|
+ int mark = 0;
|
|
|
+ for (EvaluateReport er : ler) {
|
|
|
+ if (ad.getInfoYear().equals(er.getYear()) && ad.getInfoQuarter().equals(er.getMonth())) {
|
|
|
+ getInfoScore(sb, er, erimap, question);
|
|
|
+ mark++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (mark == 0) {
|
|
|
+ sb.append("抱歉,这个知识我还在学习中");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 只有年份
|
|
|
+ */
|
|
|
+ private void getYearData(List<EvaluateReport> ler, AIDateInfo ad, StringBuilder sb, Map<String, EvaluateReportInfo> erimap, String question) {
|
|
|
+ int mark = 0;
|
|
|
+ for (EvaluateReport er : ler) {
|
|
|
+ if ("-".equals(er.getMonth()) && ad.getInfoYear().equals(er.getYear())) {
|
|
|
+ getInfoScore(sb, er, erimap, question);
|
|
|
+ mark++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (mark == 0) {
|
|
|
+ sb.append("抱歉,这个知识我还在学习中");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 处理接收到的时间
|
|
|
+ */
|
|
|
+ public AIDateInfo getDate(String question) {
|
|
|
+ AIDateInfo aii = new AIDateInfo();
|
|
|
+ // 匹配年份
|
|
|
+ Pattern yearPattern = Pattern.compile("(\\d{4}|今年|去年)");
|
|
|
+ Matcher yearMatcher = yearPattern.matcher(question);
|
|
|
+ if (yearMatcher.find()) {
|
|
|
+ String yearStr = yearMatcher.group();
|
|
|
+ int year = 0;
|
|
|
+ if ("今年".equals(yearStr)) {
|
|
|
+ year = LocalDate.now().getYear();
|
|
|
+ } else if ("去年".equals(yearStr)) {
|
|
|
+ year = LocalDate.now().getYear() - 1;
|
|
|
+ } else {
|
|
|
+ year = Integer.parseInt(yearStr);
|
|
|
+ }
|
|
|
+ aii.setType(AIDateTypeEnum.Year);
|
|
|
+ aii.setInfoYear(String.valueOf(year));
|
|
|
+ }
|
|
|
+
|
|
|
+ // 匹配月份
|
|
|
+ Pattern monthPattern = Pattern.compile("(\\d{1,2}月)");
|
|
|
+ Matcher monthMatcher = monthPattern.matcher(question);
|
|
|
+ if (monthMatcher.find()) {
|
|
|
+ String monthStr = monthMatcher.group().replace("月", "");
|
|
|
+ if (aii.getInfoYear() == null) {
|
|
|
+ aii.setInfoYear(LocalDate.now().getYear() + "");
|
|
|
+ }
|
|
|
+ aii.setType(AIDateTypeEnum.YearMonth);
|
|
|
+ aii.setInfoMonth(monthStr);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 匹配季度
|
|
|
+ Pattern quarterPattern = Pattern.compile("(第)?([一-四]|\\d{1,2})季度");
|
|
|
+ Matcher quarterMatcher = quarterPattern.matcher(question);
|
|
|
+ if (quarterMatcher.find()) {
|
|
|
+ String quarterStr = quarterMatcher.group(2);
|
|
|
+ int quarterNum = convertToQuarterNumber(quarterStr);
|
|
|
+ if (quarterNum > 0) {
|
|
|
+ if (aii.getInfoYear() == null) {
|
|
|
+ aii.setInfoMonth(LocalDate.now().getYear() + "");
|
|
|
+ }
|
|
|
+ aii.setType(AIDateTypeEnum.YearQuarter);
|
|
|
+ aii.setInfoQuarter(quarterNum + "");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return aii;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private void getInfoScore(StringBuilder sb, EvaluateReport er, Map<String, EvaluateReportInfo> erimap, String question) {
|
|
|
+ int mark=0;
|
|
|
+ EvaluateReportInfo e = erimap.get(er.getId());
|
|
|
+ sb.append(e.getOrganizationName()).append("的");
|
|
|
+ double s3 = 0.0;
|
|
|
+ String[] sType = scoreType.split(",");
|
|
|
+ for (String s2 : sType) {
|
|
|
+ if (question.contains(s2)) {
|
|
|
+ switch (s2) {
|
|
|
+ case "最终得分":
|
|
|
+ s3 = e.getScore();
|
|
|
+ sb.append("最终得分是:").append(s3);
|
|
|
+ break;
|
|
|
+ case "综合得分":
|
|
|
+ s3 = e.getZhScore();
|
|
|
+ sb.append("综合得分是:").append(s3);
|
|
|
+ break;
|
|
|
+ case "生产经营得分":
|
|
|
+ s3 = e.getScjyScore();
|
|
|
+ sb.append("生产经营得分是:").append(s3);
|
|
|
+ break;
|
|
|
+ case "前期得分":
|
|
|
+ s3 = e.getQqScore();
|
|
|
+ sb.append("前期得分是:").append(s3);
|
|
|
+ break;
|
|
|
+ case "基建得分":
|
|
|
+ s3 = e.getJjScore();
|
|
|
+ sb.append("基建得分是:").append(s3);
|
|
|
+ break;
|
|
|
+ case "加分项":
|
|
|
+ s3 = e.getAddScore();
|
|
|
+ sb.append("加分项是:").append(s3);
|
|
|
+ break;
|
|
|
+ case "减分项":
|
|
|
+ s3 = e.getSubScore();
|
|
|
+ sb.append("减分项是:").append(s3);
|
|
|
+ break;
|
|
|
+ case "加减分合计":
|
|
|
+ s3 = e.getAddSubScore();
|
|
|
+ sb.append("加减分合计是:").append(s3);
|
|
|
+ break;
|
|
|
+ case "经营业绩系数":
|
|
|
+ s3 = e.getJyyjXs();
|
|
|
+ sb.append("经营业绩系数是:").append(s3);
|
|
|
+ break;
|
|
|
+ case "关键业绩系数":
|
|
|
+ s3 = e.getGjyjXs();
|
|
|
+ sb.append("关键业绩系数是:").append(s3);
|
|
|
+ break;
|
|
|
+ case "党建考核乘数":
|
|
|
+ s3 = e.getDjkhCs();
|
|
|
+ sb.append("党建考核乘数是:").append(s3);
|
|
|
+ break;
|
|
|
+ case "折算分数":
|
|
|
+ s3 = e.getDiscountScore();
|
|
|
+ sb.append("折算分数是:").append(s3);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ mark++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (mark == 0) {
|
|
|
+ sb.append("最终得分是:").append(e.getScore()).append(",").append("综合得分是:").append(e.getZhScore()).append(",").append("生产经营得分是:").append(e.getScjyScore()).append(",")
|
|
|
+ .append("前期得分是:").append(e.getQqScore()).append(",").append("基建得分是:").append(e.getJjScore()).append(",").append("加分项是:").append(e.getAddScore()).append(",")
|
|
|
+ .append("减分项是:").append(e.getSubScore()).append("加减分合计是:").append(e.getAddSubScore()).append("经营业绩系数是:").append(e.getJyyjXs())
|
|
|
+ .append("关键业绩系数是:").append(e.getGjyjXs()).append(",").append("党建考核乘数是:").append(e.getDjkhCs()).append(",").append("折算分数是:").append(e.getDiscountScore());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private int convertToQuarterNumber(String quarterStr) {
|
|
|
+ switch (quarterStr) {
|
|
|
+ case "一":
|
|
|
+ case "1":
|
|
|
+ return 1;
|
|
|
+ case "二":
|
|
|
+ case "2":
|
|
|
+ return 2;
|
|
|
+ case "三":
|
|
|
+ case "3":
|
|
|
+ return 3;
|
|
|
+ case "四":
|
|
|
+ case "4":
|
|
|
+ return 4;
|
|
|
+ default:
|
|
|
+ // 如果不是有效的季度数字,则返回0或抛出异常
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 考评详情map
|
|
|
+ */
|
|
|
+ public Map<String, EvaluateReportInfo> getEvaluateReportInfoMap() {
|
|
|
+ List<EvaluateReportInfo> evaluateReportInfos = evaluateReportInfoMapper.selectList(null);
|
|
|
+ return evaluateReportInfoMap = evaluateReportInfos.stream().collect(Collectors.toMap(EvaluateReportInfo::getId, Function.identity()));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Data
|
|
|
+ public class AIDateInfo {
|
|
|
+ private String infoYear;
|
|
|
+ private String infoMonth;
|
|
|
+ private String infoQuarter;
|
|
|
+ private AIDateTypeEnum type;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+}
|