Commit f412c8afa419e4f8feabea47bfbe7fd8ee87e42c

Authored by 陈强
1 parent 0f81ab5b

方针展开相关接口新增、优化修改

  1 +package com.qgutech.qgyun.apaas.sync.cpsfzzk.controller;
  2 +
  3 +import com.qgutech.qgyun.apaas.sync.cpsfzzk.model.ScoreCard;
  4 +import com.qgutech.qgyun.apaas.sync.cpsfzzk.model.ScoreCardReviewRecord;
  5 +import com.qgutech.qgyun.apaas.sync.cpsfzzk.service.ScoreCardReviewRecordService;
  6 +import com.qgutech.qgyun.framework.common.result.JsonResult;
  7 +import lombok.extern.slf4j.Slf4j;
  8 +import org.springframework.web.bind.annotation.*;
  9 +
  10 +import javax.annotation.Resource;
  11 +import java.util.List;
  12 +
  13 +/**
  14 + * 公司级记分卡回顾记录接口
  15 + */
  16 +@Slf4j
  17 +@RestController
  18 +@RequestMapping("/scoreCardReviewRecord")
  19 +public class ScoreCardReviewRecordController {
  20 +
  21 + @Resource
  22 + private ScoreCardReviewRecordService scoreCardReviewRecordService;
  23 +
  24 + /**
  25 + * 获取所有公司级记分卡回顾记录列表
  26 + *
  27 + * @return
  28 + */
  29 + @GetMapping("/list/all")
  30 + public JsonResult listAll() {
  31 + List<ScoreCardReviewRecord> scoreCardReviewRecordList = scoreCardReviewRecordService.listAll();
  32 + return new JsonResult<>(true, "成功", scoreCardReviewRecordList);
  33 + }
  34 +
  35 + /**
  36 + * 根据入参 id 获取并回填公司级记分卡回顾记录详情
  37 + * <p>
  38 + * 根据入参 id 获取回顾记录详情,再根据记录中的记分卡信息获取记分卡详情,
  39 + * 根据回顾记录的月份取对应记分卡对应月份的目标值回填到回顾记录,是否达标
  40 + * 暂默认为达标,最后更新对应回顾记录信息并返回
  41 + *
  42 + * @param reviewRecord 回顾记录ID
  43 + * @return 更新后的回顾记录详情
  44 + */
  45 + @PostMapping("/review")
  46 + public JsonResult review(@RequestBody ScoreCardReviewRecord reviewRecord) {
  47 + ScoreCardReviewRecord scoreCardReviewRecord = scoreCardReviewRecordService.reviewById(reviewRecord.getId());
  48 + return new JsonResult<>(true, "成功", scoreCardReviewRecord);
  49 + }
  50 +
  51 + /**
  52 + * 根据入参 id 将回顾记录回写到对应记分卡
  53 + * <p>
  54 + * 根据入参 id 获取回顾记录详情,根据回顾记录的月份、月份实际值、是否达标,
  55 + * 更新对应记分卡记录对应月份的实际值和是否达标信息,并返回更新后的记分卡
  56 + *
  57 + * @param reviewRecord 回顾记录ID
  58 + * @return 更新后的记分卡详情
  59 + */
  60 + @PostMapping("/syncScoreCard")
  61 + public JsonResult syncScoreCard(@RequestBody ScoreCardReviewRecord reviewRecord) {
  62 + ScoreCard scoreCard = scoreCardReviewRecordService.syncToScoreCardById(reviewRecord.getId());
  63 + return new JsonResult<>(true, "成功", scoreCard);
  64 + }
  65 +}
@@ -5,6 +5,8 @@ import com.qgutech.qgyun.apaas.sync.cpsfzzk.service.ThreeYearPlanService; @@ -5,6 +5,8 @@ import com.qgutech.qgyun.apaas.sync.cpsfzzk.service.ThreeYearPlanService;
5 import com.qgutech.qgyun.framework.common.result.JsonResult; 5 import com.qgutech.qgyun.framework.common.result.JsonResult;
6 import lombok.extern.slf4j.Slf4j; 6 import lombok.extern.slf4j.Slf4j;
7 import org.springframework.web.bind.annotation.GetMapping; 7 import org.springframework.web.bind.annotation.GetMapping;
  8 +import org.springframework.web.bind.annotation.PostMapping;
  9 +import org.springframework.web.bind.annotation.RequestBody;
8 import org.springframework.web.bind.annotation.RequestMapping; 10 import org.springframework.web.bind.annotation.RequestMapping;
9 import org.springframework.web.bind.annotation.RestController; 11 import org.springframework.web.bind.annotation.RestController;
10 12
@@ -32,4 +34,21 @@ public class ThreeYearPlanController { @@ -32,4 +34,21 @@ public class ThreeYearPlanController {
32 List<ThreeYearPlan> threeYearPlanList = threeYearPlanService.listAll(); 34 List<ThreeYearPlan> threeYearPlanList = threeYearPlanService.listAll();
33 return new JsonResult<>(true, "成功", threeYearPlanList); 35 return new JsonResult<>(true, "成功", threeYearPlanList);
34 } 36 }
  37 +
  38 + /**
  39 + * 根据入参 id 列表批量生成下一年度三年规划记录
  40 + * <p>
  41 + * 逐条处理:按指标 id 查出指标信息并复制一条年份 +1 的新指标(以所属板块 + 年份 +
  42 + * 名称判断唯一性,已存在则复用);复制生成新三年规划记录(板块不变,基准年度及
  43 + * jznda/jzndb/jzndc1 等全部年度 Date 字段整体 +1 年,其余字段原样复制,指标更新为新指标 id);
  44 + * 以板块 + 基准年度 + 指标判断三年规划唯一性,不存在时才新增。
  45 + *
  46 + * @param ids 三年规划记录 id 列表
  47 + * @return 处理结果(仅成功标识)
  48 + */
  49 + @PostMapping("/generate/nextYear")
  50 + public JsonResult generateNextYear(@RequestBody List<String> ids) {
  51 + threeYearPlanService.generateNextYearPlans(ids);
  52 + return new JsonResult<>(true, "成功", null);
  53 + }
35 } 54 }
  1 +package com.qgutech.qgyun.apaas.sync.cpsfzzk.enums;
  2 +
  3 +import lombok.Getter;
  4 +
  5 +/**
  6 + * 月份枚举
  7 + * <p>
  8 + * 数据库字段 month_em 存储编号:#1#-1月,#2#-2月 ... #12#-12月
  9 + */
  10 +@Getter
  11 +public enum MonthEnum {
  12 +
  13 + /**
  14 + * 1月
  15 + */
  16 + JANUARY("#1#", "1月"),
  17 +
  18 + /**
  19 + * 2月
  20 + */
  21 + FEBRUARY("#2#", "2月"),
  22 +
  23 + /**
  24 + * 3月
  25 + */
  26 + MARCH("#3#", "3月"),
  27 +
  28 + /**
  29 + * 4月
  30 + */
  31 + APRIL("#4#", "4月"),
  32 +
  33 + /**
  34 + * 5月
  35 + */
  36 + MAY("#5#", "5月"),
  37 +
  38 + /**
  39 + * 6月
  40 + */
  41 + JUNE("#6#", "6月"),
  42 +
  43 + /**
  44 + * 7月
  45 + */
  46 + JULY("#7#", "7月"),
  47 +
  48 + /**
  49 + * 8月
  50 + */
  51 + AUGUST("#8#", "8月"),
  52 +
  53 + /**
  54 + * 9月
  55 + */
  56 + SEPTEMBER("#9#", "9月"),
  57 +
  58 + /**
  59 + * 10月
  60 + */
  61 + OCTOBER("#10#", "10月"),
  62 +
  63 + /**
  64 + * 11月
  65 + */
  66 + NOVEMBER("#11#", "11月"),
  67 +
  68 + /**
  69 + * 12月
  70 + */
  71 + DECEMBER("#12#", "12月");
  72 +
  73 + /**
  74 + * 数据库中存储的编号
  75 + */
  76 + private final String code;
  77 +
  78 + /**
  79 + * 中文描述
  80 + */
  81 + private final String desc;
  82 +
  83 + MonthEnum(String code, String desc) {
  84 + this.code = code;
  85 + this.desc = desc;
  86 + }
  87 +
  88 + /**
  89 + * 根据编号获取枚举
  90 + *
  91 + * @param code 编号
  92 + * @return 枚举实例,未找到返回 null
  93 + */
  94 + public static MonthEnum fromCode(String code) {
  95 + if (code == null) {
  96 + return null;
  97 + }
  98 + for (MonthEnum month : values()) {
  99 + if (month.code.equals(code)) {
  100 + return month;
  101 + }
  102 + }
  103 + if (!code.startsWith("#")) {
  104 + String wrapped = "#" + code + "#";
  105 + for (MonthEnum month : values()) {
  106 + if (month.code.equals(wrapped)) {
  107 + return month;
  108 + }
  109 + }
  110 + }
  111 + return null;
  112 + }
  113 +
  114 + /**
  115 + * 根据编号获取中文描述
  116 + *
  117 + * @param code 编号
  118 + * @return 中文描述,未找到返回原编号
  119 + */
  120 + public static String getDescByCode(String code) {
  121 + MonthEnum month = fromCode(code);
  122 + return month != null ? month.getDesc() : code;
  123 + }
  124 +
  125 + /**
  126 + * 根据编号获取月份数字(1-12)
  127 + *
  128 + * @param code 编号
  129 + * @return 月份数字(1-12),未找到返回 null
  130 + */
  131 + public static Integer getMonthByCode(String code) {
  132 + MonthEnum month = fromCode(code);
  133 + return month != null ? month.ordinal() + 1 : null;
  134 + }
  135 +}
  1 +package com.qgutech.qgyun.apaas.sync.cpsfzzk.mapper;
  2 +
  3 +import com.qgutech.qgyun.framework.database.mybatis.registermapper.QguBaseMapper;
  4 +import com.qgutech.qgyun.apaas.sync.cpsfzzk.model.ScoreCardReviewRecord;
  5 +
  6 +public interface ScoreCardReviewRecordMapper extends QguBaseMapper<ScoreCardReviewRecord> {
  7 +}
@@ -19,6 +19,7 @@ public class CompanyIndicator extends BaseCorpModel { @@ -19,6 +19,7 @@ public class CompanyIndicator extends BaseCorpModel {
19 19
20 public static final String SSBK = "ssbk"; 20 public static final String SSBK = "ssbk";
21 public static final String BKXH = "bkxh"; 21 public static final String BKXH = "bkxh";
  22 + public static final String MC = "mc";
22 public static final String ZBXH = "zbxh"; 23 public static final String ZBXH = "zbxh";
23 public static final String NF = "nf"; 24 public static final String NF = "nf";
24 public static final String ZT = "zt"; 25 public static final String ZT = "zt";
@@ -24,7 +24,6 @@ public class ScoreCard extends BaseCorpModel { @@ -24,7 +24,6 @@ public class ScoreCard extends BaseCorpModel {
24 public static final String JZND = "jznd"; 24 public static final String JZND = "jznd";
25 public static final String SFPP = "sfpp"; 25 public static final String SFPP = "sfpp";
26 public static final String QTDW = "qtdw"; 26 public static final String QTDW = "qtdw";
27 - public static final String ZT = "zt";  
28 public static final String HGRY = "hgry"; 27 public static final String HGRY = "hgry";
29 28
30 /* 29 /*
@@ -283,11 +282,6 @@ public class ScoreCard extends BaseCorpModel { @@ -283,11 +282,6 @@ public class ScoreCard extends BaseCorpModel {
283 private String mbytdmbz; 282 private String mbytdmbz;
284 283
285 /* 284 /*
286 - * 状态  
287 - */  
288 - private String zt;  
289 -  
290 - /*  
291 * 合格人员 285 * 合格人员
292 */ 286 */
293 private String hgry; 287 private String hgry;
  1 +package com.qgutech.qgyun.apaas.sync.cpsfzzk.model;
  2 +
  3 +import com.qgutech.qgyun.apaas.sync.cpsfzzk.enums.MonthEnum;
  4 +import com.qgutech.qgyun.framework.database.model.BaseCorpModel;
  5 +import lombok.Getter;
  6 +import lombok.Setter;
  7 +import lombok.ToString;
  8 +
  9 +import javax.persistence.Table;
  10 +import javax.persistence.Transient;
  11 +
  12 +/**
  13 + * 公司级记分卡回顾记录
  14 + */
  15 +@Getter
  16 +@Setter
  17 +@ToString
  18 +@Table(name = "t_auto_hfca_dnxpkp_ujnpkh")
  19 +public class ScoreCardReviewRecord extends BaseCorpModel {
  20 +
  21 + public static final String GSJJFKXX = "gsjjfkxx";
  22 + public static final String YEAR_STR = "yearStr";
  23 + public static final String BKXX = "bkxx";
  24 + public static final String GSJZBXX = "gsjzbxx";
  25 + public static final String MONTH_EM = "monthEm";
  26 + public static final String APPROVAL_STATUS = "approvalStatus";
  27 +
  28 + /*
  29 + * 记分卡(关联 ScoreCard)
  30 + */
  31 + private String gsjjfkxx;
  32 +
  33 + /*
  34 + * 年份
  35 + */
  36 + private String yearStr;
  37 +
  38 + /*
  39 + * 板块信息(关联 BlockInfo)
  40 + */
  41 + private String bkxx;
  42 +
  43 + /*
  44 + * 公司级指标信息(关联 CompanyIndicator)
  45 + */
  46 + private String gsjzbxx;
  47 +
  48 + /*
  49 + * 目标值
  50 + */
  51 + private String mbVal;
  52 +
  53 + /*
  54 + * 月份:#1#-1月;#2#-2月;...;#12#-12月
  55 + */
  56 + private String monthEm;
  57 +
  58 + /*
  59 + * 月份实际值
  60 + */
  61 + private String monthRealVal;
  62 +
  63 + /*
  64 + * 月份目标值
  65 + */
  66 + private String monthTargetVal;
  67 +
  68 + /*
  69 + * 月份是否达标
  70 + */
  71 + private Boolean monthFinishFlag;
  72 +
  73 + /*
  74 + * 审批记录信息
  75 + */
  76 + private String spjlxx;
  77 +
  78 + /*
  79 + * 流程实例ID
  80 + */
  81 + private String processInstanceId;
  82 +
  83 + /*
  84 + * 审批状态
  85 + */
  86 + private String approvalStatus;
  87 +
  88 + /**********非持久化字段*********/
  89 + /*
  90 + * 月份中文描述(非数据库字段,由 monthEm 计算得出)
  91 + */
  92 + @Transient
  93 + private String monthEmDesc;
  94 +
  95 + /**
  96 + * 月份中文描述
  97 + *
  98 + * @return 月份中文名称
  99 + */
  100 + public String getMonthEmDesc() {
  101 + return MonthEnum.getDescByCode(this.monthEm);
  102 + }
  103 +}
@@ -84,16 +84,6 @@ public class WorkPlan extends BaseCorpModel { @@ -84,16 +84,6 @@ public class WorkPlan extends BaseCorpModel {
84 private String wchfj; 84 private String wchfj;
85 85
86 /* 86 /*
87 - * 项目是否有延期申请  
88 - */  
89 - private Boolean xmsfyqsq;  
90 -  
91 - /*  
92 - * 延期后时间  
93 - */  
94 - private Date yqhsj;  
95 -  
96 - /*  
97 * 经理审批 87 * 经理审批
98 */ 88 */
99 private String jlsp; 89 private String jlsp;
@@ -114,7 +104,7 @@ public class WorkPlan extends BaseCorpModel { @@ -114,7 +104,7 @@ public class WorkPlan extends BaseCorpModel {
114 private String gzjhzrr; 104 private String gzjhzrr;
115 105
116 /* 106 /*
117 - * 相关责任人经理 107 + * 回顾责任主管/经理
118 */ 108 */
119 private String hgzrzgjl; 109 private String hgzrzgjl;
120 110
@@ -5,7 +5,9 @@ import com.qgutech.qgyun.apaas.sync.base.BoErrorCode; @@ -5,7 +5,9 @@ import com.qgutech.qgyun.apaas.sync.base.BoErrorCode;
5 import com.qgutech.qgyun.apaas.sync.base.BoException; 5 import com.qgutech.qgyun.apaas.sync.base.BoException;
6 import com.qgutech.qgyun.apaas.sync.cpsfzzk.mapper.CompanyIndicatorMapper; 6 import com.qgutech.qgyun.apaas.sync.cpsfzzk.mapper.CompanyIndicatorMapper;
7 import com.qgutech.qgyun.apaas.sync.cpsfzzk.model.CompanyIndicator; 7 import com.qgutech.qgyun.apaas.sync.cpsfzzk.model.CompanyIndicator;
  8 +import com.qgutech.qgyun.apaas.sync.utils.DateDealUtils;
8 import org.apache.commons.collections4.CollectionUtils; 9 import org.apache.commons.collections4.CollectionUtils;
  10 +import org.apache.commons.lang3.StringUtils;
9 import org.springframework.stereotype.Service; 11 import org.springframework.stereotype.Service;
10 import org.springframework.transaction.annotation.Transactional; 12 import org.springframework.transaction.annotation.Transactional;
11 import org.springframework.util.Assert; 13 import org.springframework.util.Assert;
@@ -69,4 +71,44 @@ public class CompanyIndicatorService extends BaseServiceImpl<CompanyIndicator> { @@ -69,4 +71,44 @@ public class CompanyIndicatorService extends BaseServiceImpl<CompanyIndicator> {
69 Example example = CorpExample.ofCorp(entityClass); 71 Example example = CorpExample.ofCorp(entityClass);
70 return companyIndicatorMapper.selectByExample(example); 72 return companyIndicatorMapper.selectByExample(example);
71 } 73 }
  74 +
  75 + /**
  76 + * 根据 id 查询指标信息,不存在时返回 null(不抛异常)
  77 + *
  78 + * @param id 指标信息 id
  79 + * @return 指标信息,id 为空或不存在时返回 null
  80 + */
  81 + @Transactional(readOnly = true)
  82 + public CompanyIndicator getByIdOrNull(String id) {
  83 + if (StringUtils.isBlank(id)) {
  84 + return null;
  85 + }
  86 +
  87 + Example example = new Example(entityClass);
  88 + CorpExample.criteria(example).andEqualTo(CompanyIndicator.ID, id);
  89 + return companyIndicatorMapper.selectOneByExample(example);
  90 + }
  91 +
  92 + /**
  93 + * 按所属板块、年份、名称查询唯一指标信息
  94 + * <p>
  95 + * 年份以区间方式匹配(当年 1 月 1 日至 12 月 31 日),用于指标信息唯一性判断。
  96 + *
  97 + * @param ssbk 所属板块
  98 + * @param year 年份(如 2027)
  99 + * @param mc 名称
  100 + * @return 匹配的指标信息,不存在时返回 null
  101 + */
  102 + @Transactional(readOnly = true)
  103 + public CompanyIndicator getBySsbkAndYearAndMc(String ssbk, String year, String mc) {
  104 + Example example = new Example(entityClass);
  105 + CorpExample.criteria(example)
  106 + .andEqualTo(CompanyIndicator.SSBK, ssbk)
  107 + .andBetween(CompanyIndicator.NF,
  108 + DateDealUtils.parseYearStartTime(year),
  109 + DateDealUtils.parseYearEndTime(year))
  110 + .andEqualTo(CompanyIndicator.MC, mc);
  111 + List<CompanyIndicator> list = companyIndicatorMapper.selectByExample(example);
  112 + return CollectionUtils.isEmpty(list) ? null : list.get(0);
  113 + }
72 } 114 }
  1 +package com.qgutech.qgyun.apaas.sync.cpsfzzk.service;
  2 +
  3 +import com.qgutech.qgyun.framework.database.mybatis.service.BaseServiceImpl;
  4 +import com.qgutech.qgyun.apaas.sync.base.BoErrorCode;
  5 +import com.qgutech.qgyun.apaas.sync.base.BoException;
  6 +import com.qgutech.qgyun.apaas.sync.cpsfzzk.enums.MonthEnum;
  7 +import com.qgutech.qgyun.apaas.sync.cpsfzzk.mapper.ScoreCardReviewRecordMapper;
  8 +import com.qgutech.qgyun.apaas.sync.cpsfzzk.model.ScoreCard;
  9 +import com.qgutech.qgyun.apaas.sync.cpsfzzk.model.ScoreCardReviewRecord;
  10 +import org.apache.commons.collections4.CollectionUtils;
  11 +import org.springframework.stereotype.Service;
  12 +import org.springframework.transaction.annotation.Transactional;
  13 +import org.springframework.util.Assert;
  14 +import com.qgutech.qgyun.apaas.sync.utils.CorpExample;
  15 +import tk.mybatis.mapper.entity.Example;
  16 +
  17 +import javax.annotation.Resource;
  18 +import java.util.*;
  19 +import java.util.stream.Collectors;
  20 +
  21 +/**
  22 + * ScoreCardReviewRecord 服务
  23 + */
  24 +@Service
  25 +public class ScoreCardReviewRecordService extends BaseServiceImpl<ScoreCardReviewRecord> {
  26 +
  27 + @Resource
  28 + private ScoreCardReviewRecordMapper scoreCardReviewRecordMapper;
  29 +
  30 + @Resource
  31 + private ScoreCardService scoreCardService;
  32 +
  33 + @Transactional(readOnly = true)
  34 + public ScoreCardReviewRecord getById(String id) {
  35 + Assert.hasLength(id, "id is empty!");
  36 +
  37 + Example example = new Example(entityClass);
  38 + CorpExample.criteria(example).andEqualTo(ScoreCardReviewRecord.ID, id);
  39 + ScoreCardReviewRecord scoreCardReviewRecord = scoreCardReviewRecordMapper.selectOneByExample(example);
  40 + if (null == scoreCardReviewRecord) {
  41 + throw new BoException(BoErrorCode.DATA_ERROR);
  42 + }
  43 + return scoreCardReviewRecord;
  44 + }
  45 +
  46 + @Transactional(readOnly = true)
  47 + public List<ScoreCardReviewRecord> listByIds(Collection<String> ids) {
  48 + Assert.notEmpty(ids, "ids is empty!");
  49 +
  50 + Example example = new Example(entityClass);
  51 + CorpExample.criteria(example).andIn(ScoreCardReviewRecord.ID, ids);
  52 + List<ScoreCardReviewRecord> scoreCardReviewRecordList = scoreCardReviewRecordMapper.selectByExample(example);
  53 + if (CollectionUtils.isEmpty(scoreCardReviewRecordList)) {
  54 + return new ArrayList<>(0);
  55 + }
  56 + return scoreCardReviewRecordList;
  57 + }
  58 +
  59 + @Transactional(readOnly = true)
  60 + public Map<String, ScoreCardReviewRecord> mapByIds(Collection<String> ids) {
  61 + Assert.notEmpty(ids, "ids is empty!");
  62 +
  63 + List<ScoreCardReviewRecord> scoreCardReviewRecordList = listByIds(ids);
  64 + if (CollectionUtils.isEmpty(scoreCardReviewRecordList)) {
  65 + return new HashMap<>(0);
  66 + }
  67 +
  68 + return scoreCardReviewRecordList.stream().collect(Collectors.toMap(ScoreCardReviewRecord::getId, scoreCardReviewRecord -> scoreCardReviewRecord));
  69 + }
  70 +
  71 + @Transactional(readOnly = true)
  72 + public List<ScoreCardReviewRecord> listAll() {
  73 +
  74 + Example example = CorpExample.ofCorp(entityClass);
  75 + return scoreCardReviewRecordMapper.selectByExample(example);
  76 + }
  77 +
  78 + /**
  79 + * 根据 ID 处理并回填记分卡回顾记录
  80 + * <p>
  81 + * 处理流程:根据入参 id 获取回顾记录详情 -> 根据记录中的记分卡信息获取记分卡详情 ->
  82 + * 根据回顾记录的月份取对应记分卡对应月份的目标值回填到回顾记录 ->
  83 + * 回顾记录的是否达标暂默认为达标 -> 最后更新对应回顾记录信息
  84 + *
  85 + * @param id 回顾记录ID
  86 + * @return 更新后的回顾记录
  87 + */
  88 + @Transactional(rollbackFor = Exception.class)
  89 + public ScoreCardReviewRecord reviewById(String id) {
  90 + Assert.hasLength(id, "id is empty!");
  91 + // 1. 根据入参 id 获取回顾记录详情
  92 + ScoreCardReviewRecord record = getById(id);
  93 +
  94 + // 2. 根据回顾记录中的记分卡信息获取记分卡详情
  95 + Assert.hasLength(record.getGsjjfkxx(), "gsjjfkxx is empty!");
  96 + ScoreCard scoreCard = scoreCardService.getById(record.getGsjjfkxx());
  97 +
  98 + // 3. 根据回顾记录的月份获取对应记分卡对应月份的目标值,回填到回顾记录
  99 + Integer month = MonthEnum.getMonthByCode(record.getMonthEm());
  100 + Assert.notNull(month, "monthEm is invalid!");
  101 + record.setMonthTargetVal(scoreCardService.getMonthTargetValue(scoreCard, month));
  102 +
  103 + // 4. 回顾记录的是否达标暂默认为达标
  104 + // TODO 后续补充根据月份目标值与实际值计算是否达标的逻辑
  105 + record.setMonthFinishFlag(Boolean.TRUE);
  106 +
  107 + // 5. 最后更新对应回顾记录信息
  108 + scoreCardReviewRecordMapper.updateByPrimaryKeySelective(record);
  109 + return record;
  110 + }
  111 +
  112 + /**
  113 + * 根据 ID 将回顾记录回写到对应记分卡
  114 + * <p>
  115 + * 处理流程:根据入参 id 获取回顾记录详情 -> 根据记录中的记分卡信息获取记分卡详情 ->
  116 + * 根据回顾记录的月份,将月份实际值、是否达标写回记分卡对应月份 -> 最后更新对应记分卡记录
  117 + *
  118 + * @param id 回顾记录ID
  119 + * @return 更新后的记分卡记录
  120 + */
  121 + @Transactional(rollbackFor = Exception.class)
  122 + public ScoreCard syncToScoreCardById(String id) {
  123 + Assert.hasLength(id, "id is empty!");
  124 + // 1. 根据入参 id 获取回顾记录详情
  125 + ScoreCardReviewRecord record = getById(id);
  126 +
  127 + // 2. 根据回顾记录中的记分卡信息获取记分卡详情
  128 + Assert.hasLength(record.getGsjjfkxx(), "gsjjfkxx is empty!");
  129 + ScoreCard scoreCard = scoreCardService.getById(record.getGsjjfkxx());
  130 +
  131 + // 3. 根据回顾记录的月份,将月份实际值、是否达标写回记分卡对应月份
  132 + Integer month = MonthEnum.getMonthByCode(record.getMonthEm());
  133 + Assert.notNull(month, "monthEm is invalid!");
  134 + scoreCardService.setMonthRealAndReached(scoreCard, month, record.getMonthRealVal(), record.getMonthFinishFlag());
  135 +
  136 + // 4. 最后更新对应记分卡记录
  137 + scoreCardService.updateById(scoreCard);
  138 + return scoreCard;
  139 + }
  140 +}
@@ -332,6 +332,93 @@ public class ScoreCardService extends BaseServiceImpl<ScoreCard> { @@ -332,6 +332,93 @@ public class ScoreCardService extends BaseServiceImpl<ScoreCard> {
332 } 332 }
333 333
334 /** 334 /**
  335 + * 获取记分卡指定月份的目标值
  336 + *
  337 + * @param scoreCard 记分卡记录
  338 + * @param month 月份(1-12)
  339 + * @return 对应月份的目标值
  340 + */
  341 + public String getMonthTargetValue(ScoreCard scoreCard, int month) {
  342 + fillQueryMonthValue(scoreCard, month);
  343 + return scoreCard.getQueryMonthTarget();
  344 + }
  345 +
  346 + /**
  347 + * 设置记分卡指定月份的实际值与是否达标
  348 + *
  349 + * @param scoreCard 记分卡记录
  350 + * @param month 月份(1-12)
  351 + * @param realVal 月份实际值
  352 + * @param reached 月份是否达标
  353 + */
  354 + public void setMonthRealAndReached(ScoreCard scoreCard, int month, String realVal, Boolean reached) {
  355 + switch (month) {
  356 + case 1:
  357 + scoreCard.setYsjz(realVal);
  358 + scoreCard.setYsfdb(reached);
  359 + break;
  360 + case 2:
  361 + scoreCard.setYsjza(realVal);
  362 + scoreCard.setYsfdba(reached);
  363 + break;
  364 + case 3:
  365 + scoreCard.setYsjzb(realVal);
  366 + scoreCard.setYsfdbb(reached);
  367 + break;
  368 + case 4:
  369 + scoreCard.setYsjzc(realVal);
  370 + scoreCard.setYsfdbc(reached);
  371 + break;
  372 + case 5:
  373 + scoreCard.setYsjzd(realVal);
  374 + scoreCard.setYsfdbd(reached);
  375 + break;
  376 + case 6:
  377 + scoreCard.setYsjze(realVal);
  378 + scoreCard.setYsfdbe(reached);
  379 + break;
  380 + case 7:
  381 + scoreCard.setYsjzf(realVal);
  382 + scoreCard.setYsfdbf(reached);
  383 + break;
  384 + case 8:
  385 + scoreCard.setYsjzg(realVal);
  386 + scoreCard.setYsfdbg(reached);
  387 + break;
  388 + case 9:
  389 + scoreCard.setYsjzh(realVal);
  390 + scoreCard.setYsfdbh(reached);
  391 + break;
  392 + case 10:
  393 + scoreCard.setYsjzi(realVal);
  394 + scoreCard.setYsfdbi(reached);
  395 + break;
  396 + case 11:
  397 + scoreCard.setYsjzj(realVal);
  398 + scoreCard.setYsfdbj(reached);
  399 + break;
  400 + case 12:
  401 + scoreCard.setYsjzk(realVal);
  402 + scoreCard.setYsfdbk(reached);
  403 + break;
  404 + default:
  405 + throw new IllegalArgumentException("month must be in 1-12!");
  406 + }
  407 + }
  408 +
  409 + /**
  410 + * 根据主键选择性更新记分卡
  411 + *
  412 + * @param scoreCard 待更新的记分卡记录
  413 + */
  414 + @Transactional(rollbackFor = Exception.class)
  415 + public void updateById(ScoreCard scoreCard) {
  416 + Assert.notNull(scoreCard, "scoreCard is null!");
  417 + Assert.hasLength(scoreCard.getId(), "id is empty!");
  418 + scoreCardMapper.updateByPrimaryKeySelective(scoreCard);
  419 + }
  420 +
  421 + /**
335 * 获取记分卡指定月份的“是否达标”字段值 422 * 获取记分卡指定月份的“是否达标”字段值
336 * 423 *
337 * @param scoreCard 记分卡记录 424 * @param scoreCard 记分卡记录
@@ -4,8 +4,12 @@ import com.qgutech.qgyun.framework.database.mybatis.service.BaseServiceImpl; @@ -4,8 +4,12 @@ import com.qgutech.qgyun.framework.database.mybatis.service.BaseServiceImpl;
4 import com.qgutech.qgyun.apaas.sync.base.BoErrorCode; 4 import com.qgutech.qgyun.apaas.sync.base.BoErrorCode;
5 import com.qgutech.qgyun.apaas.sync.base.BoException; 5 import com.qgutech.qgyun.apaas.sync.base.BoException;
6 import com.qgutech.qgyun.apaas.sync.cpsfzzk.mapper.ThreeYearPlanMapper; 6 import com.qgutech.qgyun.apaas.sync.cpsfzzk.mapper.ThreeYearPlanMapper;
  7 +import com.qgutech.qgyun.apaas.sync.cpsfzzk.model.CompanyIndicator;
7 import com.qgutech.qgyun.apaas.sync.cpsfzzk.model.ThreeYearPlan; 8 import com.qgutech.qgyun.apaas.sync.cpsfzzk.model.ThreeYearPlan;
  9 +import com.qgutech.qgyun.apaas.sync.utils.DateDealUtils;
  10 +import lombok.extern.slf4j.Slf4j;
8 import org.apache.commons.collections4.CollectionUtils; 11 import org.apache.commons.collections4.CollectionUtils;
  12 +import org.apache.commons.lang3.StringUtils;
9 import org.springframework.stereotype.Service; 13 import org.springframework.stereotype.Service;
10 import org.springframework.transaction.annotation.Transactional; 14 import org.springframework.transaction.annotation.Transactional;
11 import org.springframework.util.Assert; 15 import org.springframework.util.Assert;
@@ -19,12 +23,16 @@ import java.util.stream.Collectors; @@ -19,12 +23,16 @@ import java.util.stream.Collectors;
19 /** 23 /**
20 * ThreeYearPlan 服务 24 * ThreeYearPlan 服务
21 */ 25 */
  26 +@Slf4j
22 @Service 27 @Service
23 public class ThreeYearPlanService extends BaseServiceImpl<ThreeYearPlan> { 28 public class ThreeYearPlanService extends BaseServiceImpl<ThreeYearPlan> {
24 29
25 @Resource 30 @Resource
26 private ThreeYearPlanMapper threeYearPlanMapper; 31 private ThreeYearPlanMapper threeYearPlanMapper;
27 32
  33 + @Resource
  34 + private CompanyIndicatorService companyIndicatorService;
  35 +
28 @Transactional(readOnly = true) 36 @Transactional(readOnly = true)
29 public ThreeYearPlan getById(String id) { 37 public ThreeYearPlan getById(String id) {
30 Assert.hasLength(id, "id is empty!"); 38 Assert.hasLength(id, "id is empty!");
@@ -69,4 +77,185 @@ public class ThreeYearPlanService extends BaseServiceImpl<ThreeYearPlan> { @@ -69,4 +77,185 @@ public class ThreeYearPlanService extends BaseServiceImpl<ThreeYearPlan> {
69 Example example = CorpExample.ofCorp(entityClass); 77 Example example = CorpExample.ofCorp(entityClass);
70 return threeYearPlanMapper.selectByExample(example); 78 return threeYearPlanMapper.selectByExample(example);
71 } 79 }
  80 +
  81 + /**
  82 + * 根据入参 id 列表批量生成下一年度三年规划记录
  83 + * <p>
  84 + * 处理流程(逐条):
  85 + * <ol>
  86 + * <li>按指标 id 查出指标信息,复制一条新指标:年份(nf)+1 年、其余字段原样复制;
  87 + * 以所属板块(ssbk)+ 年份 + 名称(mc)判断唯一性,已存在则复用,否则新增;</li>
  88 + * <li>复制生成新三年规划记录:板块(bk)不变,基准年度及 jznda/jzndb/jzndc1 等
  89 + * 全部年度 Date 字段整体 +1 年,其余字段原样复制,指标(zb)更新为新指标 id;</li>
  90 + * <li>以板块 + 基准年度 + 指标判断三年规划唯一性,不存在时才新增。</li>
  91 + * </ol>
  92 + * 指标无法解析(zb 为空、指标不存在或年份为空)的记录将被跳过。
  93 + *
  94 + * @param ids 三年规划记录 id 列表
  95 + */
  96 + @Transactional(rollbackFor = Exception.class)
  97 + public void generateNextYearPlans(Collection<String> ids) {
  98 + Assert.notEmpty(ids, "ids is empty!");
  99 +
  100 + List<ThreeYearPlan> sourceList = listByIds(ids);
  101 + if (CollectionUtils.isEmpty(sourceList)) {
  102 + return;
  103 + }
  104 +
  105 + // 批次内指标唯一键(所属板块|年份|名称)-> 新指标 id 缓存,避免重复新增
  106 + Map<String, String> indicatorIdCache = new HashMap<>();
  107 + for (ThreeYearPlan source : sourceList) {
  108 + // 1. 解析并生成/复用下一年度指标
  109 + String newZbId = resolveNextYearIndicator(source.getZb(), indicatorIdCache);
  110 + if (StringUtils.isBlank(newZbId)) {
  111 + log.warn("三年规划[{}]的指标[{}]无法解析下一年度指标,已跳过", source.getId(), source.getZb());
  112 + continue;
  113 + }
  114 +
  115 + // 2. 复制生成下一年度三年规划记录
  116 + ThreeYearPlan target = copyForNextYear(source, newZbId);
  117 + if (target.getJznd() == null) {
  118 + log.warn("三年规划[{}]基准年度为空,无法生成下一年度记录,已跳过", source.getId());
  119 + continue;
  120 + }
  121 +
  122 + // 3. 唯一性校验:板块 + 基准年度 + 指标,已存在则跳过
  123 + if (existsByBkAndJzndYearAndZb(target.getBk(), String.valueOf(yearOf(target.getJznd())), target.getZb())) {
  124 + continue;
  125 + }
  126 + insert(target);
  127 + }
  128 + }
  129 +
  130 + /**
  131 + * 按板块、基准年度(年份)、指标判断三年规划记录是否已存在
  132 + *
  133 + * @param bk 板块
  134 + * @param year 基准年度年份(如 2027)
  135 + * @param zb 指标 id
  136 + * @return 存在返回 true
  137 + */
  138 + @Transactional(readOnly = true)
  139 + public boolean existsByBkAndJzndYearAndZb(String bk, String year, String zb) {
  140 + Example example = new Example(entityClass);
  141 + CorpExample.criteria(example)
  142 + .andEqualTo(ThreeYearPlan.BK, bk)
  143 + .andBetween(ThreeYearPlan.JZND,
  144 + DateDealUtils.parseYearStartTime(year),
  145 + DateDealUtils.parseYearEndTime(year))
  146 + .andEqualTo(ThreeYearPlan.ZB, zb);
  147 + return threeYearPlanMapper.selectCountByExample(example) > 0;
  148 + }
  149 +
  150 + /**
  151 + * 解析源指标对应的下一年度指标 id:复制指标(年份 +1)并按唯一性复用或新增。
  152 + *
  153 + * @param sourceIndicatorId 源指标 id
  154 + * @param cache 批次内指标唯一键 -> 新指标 id 缓存
  155 + * @return 下一年度指标 id;无法解析时返回 null
  156 + */
  157 + private String resolveNextYearIndicator(String sourceIndicatorId, Map<String, String> cache) {
  158 + if (StringUtils.isBlank(sourceIndicatorId)) {
  159 + return null;
  160 + }
  161 + CompanyIndicator sourceIndicator = companyIndicatorService.getByIdOrNull(sourceIndicatorId);
  162 + if (sourceIndicator == null || sourceIndicator.getNf() == null) {
  163 + return null;
  164 + }
  165 +
  166 + Date newNf = plusOneYear(sourceIndicator.getNf());
  167 + int newYear = yearOf(newNf);
  168 + // 唯一键:所属板块 + 年份 + 名称
  169 + String uniqueKey = sourceIndicator.getSsbk() + "|" + newYear + "|" + sourceIndicator.getMc();
  170 + String cachedId = cache.get(uniqueKey);
  171 + if (StringUtils.isNotBlank(cachedId)) {
  172 + return cachedId;
  173 + }
  174 +
  175 + // 查库判断是否已存在同板块、同年份、同名称的指标
  176 + CompanyIndicator existing = companyIndicatorService.getBySsbkAndYearAndMc(
  177 + sourceIndicator.getSsbk(), String.valueOf(newYear), sourceIndicator.getMc());
  178 + String resultId;
  179 + if (existing != null) {
  180 + resultId = existing.getId();
  181 + } else {
  182 + resultId = companyIndicatorService.insert(copyIndicatorForNextYear(sourceIndicator, newNf));
  183 + }
  184 + cache.put(uniqueKey, resultId);
  185 + return resultId;
  186 + }
  187 +
  188 + /**
  189 + * 复制指标信息为下一年度新记录:年份(nf)取 newNf,其余业务字段原样复制。
  190 + * <p>不复制 id / corpCode / 审计字段,由框架 insert 时自动填充。
  191 + */
  192 + private CompanyIndicator copyIndicatorForNextYear(CompanyIndicator source, Date newNf) {
  193 + CompanyIndicator target = new CompanyIndicator();
  194 + target.setSsbk(source.getSsbk());
  195 + target.setBkxh(source.getBkxh());
  196 + target.setMc(source.getMc());
  197 + target.setZbxh(source.getZbxh());
  198 + target.setQdyxya(source.getQdyxya());
  199 + target.setNf(newNf);
  200 + target.setZt(source.getZt());
  201 + return target;
  202 + }
  203 +
  204 + /**
  205 + * 复制三年规划记录为下一年度新记录:板块不变,全部年度 Date 字段整体 +1 年,
  206 + * 指标更新为新指标 id,其余字段原样复制。
  207 + * <p>不复制 id / corpCode / 审计字段,由框架 insert 时自动填充。
  208 + */
  209 + private ThreeYearPlan copyForNextYear(ThreeYearPlan source, String newZbId) {
  210 + ThreeYearPlan target = new ThreeYearPlan();
  211 + // 板块不变
  212 + target.setBk(source.getBk());
  213 + // 指标更新为下一年度指标
  214 + target.setZb(newZbId);
  215 + target.setZbxh(source.getZbxh());
  216 + // 年度字段整体 +1 年
  217 + target.setJznd(plusOneYear(source.getJznd()));
  218 + target.setJznda(plusOneYear(source.getJznda()));
  219 + target.setJzndb(plusOneYear(source.getJzndb()));
  220 + target.setJzndc1(plusOneYear(source.getJzndc1()));
  221 + // 其余字段原样复制
  222 + target.setJzndz(source.getJzndz());
  223 + target.setJzytd(source.getJzytd());
  224 + target.setNdmbz(source.getNdmbz());
  225 + target.setNdmbza(source.getNdmbza());
  226 + target.setJzndc(source.getJzndc());
  227 + target.setNdmbzb(source.getNdmbzb());
  228 + target.setSfsd(source.getSfsd());
  229 + target.setWhlb(source.getWhlb());
  230 + target.setXzyy(source.getXzyy());
  231 + target.setXzsj(source.getXzsj());
  232 + target.setQtdw(source.getQtdw());
  233 + target.setQtdwfz(source.getQtdwfz());
  234 + target.setCx(source.getCx());
  235 + target.setBz(source.getBz());
  236 + target.setQtdwfzr(source.getQtdwfzr());
  237 + return target;
  238 + }
  239 +
  240 + /**
  241 + * 将日期加一年(保留月、日、时间),为空时返回 null。
  242 + */
  243 + private static Date plusOneYear(Date date) {
  244 + if (date == null) {
  245 + return null;
  246 + }
  247 + Calendar cal = Calendar.getInstance();
  248 + cal.setTime(date);
  249 + cal.add(Calendar.YEAR, 1);
  250 + return cal.getTime();
  251 + }
  252 +
  253 + /**
  254 + * 获取日期所处年份。
  255 + */
  256 + private static int yearOf(Date date) {
  257 + Calendar cal = Calendar.getInstance();
  258 + cal.setTime(date);
  259 + return cal.get(Calendar.YEAR);
  260 + }
72 } 261 }
@@ -269,3 +269,28 @@ CREATE TABLE `t_auto_hfca_dnxpkp_jfxxxx` @@ -269,3 +269,28 @@ CREATE TABLE `t_auto_hfca_dnxpkp_jfxxxx`
269 `glgskpi` varchar(50) COLLATE utf8mb4_general_ci DEFAULT NULL, 269 `glgskpi` varchar(50) COLLATE utf8mb4_general_ci DEFAULT NULL,
270 PRIMARY KEY (`id`) 270 PRIMARY KEY (`id`)
271 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; 271 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
  272 +
  273 +
  274 +--公司级记分卡回顾记录
  275 +CREATE TABLE `t_auto_hfca_dnxpkp_ujnpkh`
  276 +(
  277 + `id` varchar(32) COLLATE utf8mb4_general_ci NOT NULL COMMENT 'ID',
  278 + `corp_code` varchar(50) COLLATE utf8mb4_general_ci NOT NULL COMMENT '公司编号',
  279 + `created_at` datetime(3) NOT NULL COMMENT '创建时间',
  280 + `created_by` varchar(32) COLLATE utf8mb4_general_ci NOT NULL COMMENT '创建人ID',
  281 + `updated_at` datetime(3) NOT NULL COMMENT '最后更新时间',
  282 + `updated_by` varchar(32) COLLATE utf8mb4_general_ci NOT NULL COMMENT '最后更新人',
  283 + `gsjjfkxx` varchar(32) COLLATE utf8mb4_general_ci DEFAULT NULL,
  284 + `year_str` varchar(50) COLLATE utf8mb4_general_ci DEFAULT NULL,
  285 + `bkxx` varchar(32) COLLATE utf8mb4_general_ci DEFAULT NULL,
  286 + `gsjzbxx` varchar(32) COLLATE utf8mb4_general_ci DEFAULT NULL,
  287 + `mb_val` varchar(50) COLLATE utf8mb4_general_ci DEFAULT NULL,
  288 + `month_em` varchar(50) COLLATE utf8mb4_general_ci DEFAULT NULL,
  289 + `month_real_val` varchar(50) COLLATE utf8mb4_general_ci DEFAULT NULL,
  290 + `month_target_val` varchar(50) COLLATE utf8mb4_general_ci DEFAULT NULL,
  291 + `month_finish_flag` tinyint(1) DEFAULT NULL,
  292 + `spjlxx` varchar(32) COLLATE utf8mb4_general_ci DEFAULT NULL,
  293 + `process_instance_id` varchar(50) COLLATE utf8mb4_general_ci DEFAULT NULL,
  294 + `approval_status` varchar(50) COLLATE utf8mb4_general_ci DEFAULT NULL,
  295 + PRIMARY KEY (`id`)
  296 +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;