系统内有普通的 1.通用指标(不分专业,默认每个班组必填),
2.专业指标(每个指标默认归属于对应专业的班组)
所以每个班组默认归属的指标:默认归属的通用指标+本班组对应专业的指标
默认不归属的指标:专业指标中和本班组专业不同的指标
指标管理员可以设置默认不归属的归属,默认归属的不归属,
并且可以设置本周期生效和下周期生效
还可以设置每个周期起始月份
数据库c_team_index表:
需求:
1、将当前归属于本班组的指标排除(上一篇)
指标管理员可以将本归属于本班组的指标排除掉,不用继续考核,并分为:
立马生效:从当前周期就开始不用考核,不归属于本班组,排除立马生效
下周期生效:当前周期不变,依然归属,需要等到下周期才不归属,排除掉
这里内部代码需要注意的点:
如果是本归属本班组的指标排除:
则需要判断在连表:肯定没有生效的排除记录,不然就是已经排除的指标(fail)
如果是本不归属本班组的指标排除:
则需要判断判断连表:肯定有生效的包含记录,不然就还没归属本班组,不需要排除
2、将当前不归属于本班组的指标添加(本篇)
指标管理员可以将本不归属于本班组的指标添加进来,不用继续考核,并分为:
立马生效:从当前周期就开始考核,归属于本班组,添加立马生效
下周期生效:当前周期不变,依然不归属,需要等到下周期才归属,添加
这里内部代码需要注意的点:
如果是本不归属本班组的指标添加:
则需要判断判断连表:肯定没有生效的包含记录,不然就已经归属本班组了,不需要再添加
如果是本归属本班组的指标添加:
则需要判断在连表:肯定有生效的排除记录,不然就是还处于归属的指标,不需要添加(fail)
注意点:填报周期不一定非是每年的年初开始,例如本项目是从上年的十二月份就开始了,所以我在全局变量表中配置了一个评分周期月偏移量参数
-1代表默认的一月往前偏移一个月,即前一年十二月开始本周期填报,以此类推
同时,全局参数表中还有评分周期年份,自增1后成为下周期,得到月偏移量后,根据正负来判定是否推到前一年下半年:
int mon = 1; if (offserMon < 0) { nextscoreCycle--; mon = 13 + offserMon; }
再得到下周期详细时间:
String nextTimes = nextscoreCycle + "-" + mon + "-01 00:00:00"; DateTimeFormatter de = DateTimeFormatter.ofPattern(FORMAT, Locale.CHINA); LocalDateTime nextTime = LocalDateTime.parse(nextTimes, de); (FORMAT是上面的常量,FORMAT = "yyyy-MM-dd HH:mm:ss")
LocalDateTime nowTime = LocalDateTime.parse(timeStr1, da); //班组创建时间 LocalDateTime beginTeamTime = oldTeam.getData().getCreateTime(); //最大失效时间 LocalDateTime maxFaulureTime = LocalDateTime.parse(FAILURE_TIME, da);
功能代码结构:
一、排除指标 接口:(把本 属于本专业的指标排除)
如果指标默认归属本班组,判断指标在c_team_index表中必须没有生效的排除记录
1、如果是立马生效,c_team_index表新增,生效时间为now 失效时间设置为2036
include_or_exclude值为1(排除) status为1
2、如果是将来生效,c_team_index表新增,生效时间为下一周期起始月
失效时间设置2036 include_or_exclude值为1(排除) status为1
如果指标默认不归属本班组,现在又需要排除不再考核,那肯定表里肯定有之前的包含记录
3、如果是立马生效,失效时间为失效时间设置为now
status为0(状态改不可用即可)
4、如果是将来生效,失效时间设置(下一周期起始月份1号0时0分0秒)
的前一秒 status为0
二、添加指标 接口(把本 不属于本专业的指标添加给本班组)
如果指标默认不归属班组,指标在c_team_index表中肯定没有生效的包含记录,
1、如果是立马生效,c_team_index新增,include_or_exclude值为0(包含),status为1, begin_time为now(), end_time 为 2036...
2、如果是将来生效,c_team_index新增,include_or_exclude值为0(包含),status为1, begin_time为下一周期起始月份1号0时0分0秒, end_time 为 2036...
如果指标默认归属班组,指标在c_team_index表中肯定有生效的排除记录,现在要重新又要考核
3、如果是立马生效,status为0, 失效end时间为now (下周期一开始排除记录就没作用了,下周期不排除,即从下周期一开始就不排除,要考核)
4、如果是将来生效,status为0, 失效(下一周期起始月份1号0时0分0秒)的前一秒
常量声明:
//指标排除 /不归属 public static final int INCLUDER_OR_EXCLUDE = 1; //包含指标 /归属 public static final int CONTION_OR_EXCLUDE = 0; public static final String FORMAT = "yyyy-MM-dd HH:mm:ss"; public static final String FAILURE_TIME = "2036-12-31 23:59:59"; //指标立马生效 public static final Integer IS_NOW_EFFECT = 1; //归属当前班组 public static final Integer INCLUDER_OR_EXCLUDER = 0; //通用指标类型 public static final Long COMMON_INDEX_TYPE = 0L;
校验:
msg = "userId和teamId不能为空"; msg = "通过班组标识获取可用的班组列表失败,请输入有效的teamId";(班组表查不到) msg = "通过指标标识获取指标失败,请输入有效的indexId";(指标表查不到) msg = "通过指标标识获取的指标不可用,请输入有效的indexId";(指标状态)
@Override
public R<String> addIndexFillTasks(IndexTeamVO indexTeamVO) {
String msg;
Long teamId = indexTeamVO.getTeamId();
Long indexId = indexTeamVO.getIndexId();
Integer isNowEffect = indexTeamVO.getIsNowEffect();
if (null == teamId || null == indexId) {
msg = "userId和teamId不能为空";
log.error(msg);
return R.fail(msg);
}
TeamInfo teamInfo = new TeamInfo();
teamInfo.setId(teamId);
R<Team> oldTeam = authorityApi.selectTeamById(teamInfo);
if (null == oldTeam || !oldTeam.getIsSuccess() ||
null == oldTeam.getData()) {
msg = "通过班组标识获取可用的班组列表失败,请输入有效的teamId";
log.error(msg);
return R.fail(msg);
}
CommonIndex oldIndex = commonIndexService.getById(indexId);
if (null == oldIndex ) {
msg = "通过指标标识获取指标失败,请输入有效的indexId";
log.error(msg);
return R.fail(msg);
}
if(!oldIndex.getStatus().equals(ON_STATUS)){
msg = "通过指标标识获取的指标不可用,请输入有效的indexId";
log.error(msg);
return R.fail(msg);
}
//当前时间
String timeStr1 = LocalDateTime.now().format(DateTimeFormatter.ofPattern(FORMAT, Locale.CHINA));
DateTimeFormatter df = DateTimeFormatter.ofPattern(FORMAT, Locale.CHINA);
LocalDateTime nowTime = LocalDateTime.parse(timeStr1, df);
//下一周期起始时间(通过全局参数年份和月偏移量获取)
ParameterDTO p = new ParameterDTO();
p.setKey(INDEX_SCORE_CYCLE);
R<List<ParameterGradeValueDTO>> cycle = authorityApi.getValueByKey(p);
if (null == cycle.getData() || cycle.getData().isEmpty()) {
msg = "系统测试获取失败:评分周期";
log.error(msg);
return R.fail(msg);
}
//先获取当前评分周期
int scoreCycle = Integer.parseInt(cycle.getData().get(0).getLeftValue());
//默认下一周期
int nextscoreCycle = ++scoreCycle;
ParameterDTO p1 = new ParameterDTO();
p1.setKey(SCORE_OFFSET_MON);
R<List<ParameterGradeValueDTO>> offser = authorityApi.getValueByKey(p1);
if (null == offser.getData() || offser.getData().isEmpty()) {
msg = "系统测试获取失败:评分周期月份偏移量";
log.error(msg);
return R.fail(msg);
}
//和月偏移量
int offserMon = Integer.parseInt(offser.getData().get(0).getLeftValue());
int mon = 1;
if (offserMon < 0) {
nextscoreCycle--;
mon = 13 + offserMon;
}
String nextTimes = nextscoreCycle + "-" + mon + "-01 00:00:00";
DateTimeFormatter de = DateTimeFormatter.ofPattern(FORMAT, Locale.CHINA);
//下一周期生效具体时间
LocalDateTime nextTime = LocalDateTime.parse(nextTimes, de);
//最大失效时间
LocalDateTime maxFaulureTime = LocalDateTime.parse(FAILURE_TIME, de);
//所有通用指标集合
List<CommonIndex> commonIndexList = commonIndexService.lambdaQuery()
.eq(CommonIndex::getStatus, ON_STATUS)
.eq(CommonIndex::getIndexType, COMMON_INDEX_TYPE)
.list();
//所有当前班组 相同专业的指标集合
List<CommonIndex> careerIndexList = commonIndexService.lambdaQuery()
.eq(CommonIndex::getStatus, ON_STATUS)
.eq(CommonIndex::getIndexType, oldTeam.getData() .getSpecialityId())
.list();
//班组创建时间
LocalDateTime beginTeamTime = oldTeam.getData() .getCreateTime();
//该班组 所有默认 指标
List<CommonIndex> allIndex = new ArrayList<>();
List<Long> allIndexId = new ArrayList<>();
if(null!=commonIndexList&&!commonIndexList.isEmpty()){
allIndex.addAll(commonIndexList);
}
if(null!=careerIndexList&&!careerIndexList.isEmpty()){
allIndex.addAll(careerIndexList);
}
if(null!=allIndex&&!allIndex.isEmpty()){
//该班组 所有默认 指标 id
for (CommonIndex indexs : allIndex) {
allIndexId.add(indexs.getId());
}
}
//根据指标id,班组id查 排除记录
TeamIndex oldTeamIndexP = teamIndexService.lambdaQuery()
.eq(TeamIndex::getIndexId, indexId)
.eq(TeamIndex::getTeamId, teamId)
.eq(TeamIndex::getIncludeOrExclude, INCLUDER_OR_EXCLUDE)
.one();
//根据指标id,班组id查 包含记录
TeamIndex oldTeamIndexB = teamIndexService.lambdaQuery()
.eq(TeamIndex::getIndexId, indexId)
.eq(TeamIndex::getTeamId, teamId)
.eq(TeamIndex::getIncludeOrExclude, CONTION_OR_EXCLUDE)
.one();
if (oldTeamIndexB != null) {
msg = "此默认不归属本班的指标已经包含了,请输入有效的indexId!!";
log.error(msg);
return R.fail(msg);
}
//不归属当前班组
if (!allIndexId.contains(indexId)) {
//立马生效
if (IS_NOW_EFFECT .equals(isNowEffect) ) {
TeamIndex t = new TeamIndex();
t.setTeamId(teamId);
t.setIndexId(indexId);
t.setStatus(ON_STATUS);
t.setIncludeOrExclude(CONTION_OR_EXCLUDE);
t.setBeginTime(nowTime);
t.setEndTime(maxFaulureTime);//2036
if (!teamIndexService.save(t)) {
msg = "当前周期新增本不归属本班的指标包含记录失败,请联系管理员或稍后重试!";
log.error(msg);
return R.fail(msg);
}
return R.success("当前周期新增本不归属本班的指标包含记录成功!");
//下周期生效
} else {
TeamIndex t = new TeamIndex();
t.setTeamId(teamId);
t.setIndexId(indexId);
t.setStatus(ON_STATUS);
t.setIncludeOrExclude(CONTION_OR_EXCLUDE);
t.setBeginTime(nextTime);
t.setEndTime(maxFaulureTime);//2036
if (!teamIndexService.save(t)) {
msg = "下一周期新增本不归属本班的指标包含记录失败,请联系管理员或稍后重试!";
log.error(msg);
return R.fail(msg);
}
return R.success("下一周期新增本不归属本班的指标包含记录成功!");
}
} else {
//归属当前班组
if (oldTeamIndexP == null) {
msg = "当前周期中默认属于本班组的此指标并没有生效的排除记录,不需要添加包含记录!";
log.error(msg);
return R.fail(msg);
}
//立马生效
if (IS_NOW_EFFECT .equals(isNowEffect) ) {
oldTeamIndexP.setStatus(NOT_ON_STATUS);
oldTeamIndexP.setEndTime(nowTime);
if (!teamIndexService.updateById(oldTeamIndexP)) {
msg = "当前周期本归属本班的此指标设置包含记录失败,请联系管理员或稍后重试!";
log.error(msg);
return R.fail(msg);
}
return R.success("当前周期本归属本班的此指标设置包含记录失败!");
//下个周期生效
} else {
oldTeamIndexP.setStatus(NOT_ON_STATUS);
oldTeamIndexP.setEndTime(nextTime);
if (!teamIndexService.updateById(oldTeamIndexP)) {
msg = "下一周期本归属本班的此指标设置包含记录失败,请联系管理员或稍后重试!";
log.error(msg);
return R.fail(msg);
}
return R.success("下一周期本归属本班的此指标设置包含记录失败!");
}
}
@Override public R<String> addIndexFillTasks(IndexTeamVO indexTeamVO) { String msg; Long teamId = indexTeamVO.getTeamId(); Long indexId = indexTeamVO.getIndexId(); Integer isNowEffect = indexTeamVO.getIsNowEffect(); if (null == teamId || null == indexId) { msg = "userId和teamId不能为空"; log.error(msg); return R.fail(msg); } TeamInfo teamInfo = new TeamInfo(); teamInfo.setId(teamId); R<Team> oldTeam = authorityApi.selectTeamById(teamInfo); if (null == oldTeam || !oldTeam.getIsSuccess() || null == oldTeam.getData()) { msg = "通过班组标识获取可用的班组列表失败,请输入有效的teamId"; log.error(msg); return R.fail(msg); } CommonIndex oldIndex = commonIndexService.getById(indexId); if (null == oldIndex ) { msg = "通过指标标识获取指标失败,请输入有效的indexId"; log.error(msg); return R.fail(msg); } if(!oldIndex.getStatus().equals(ON_STATUS)){ msg = "通过指标标识获取的指标不可用,请输入有效的indexId"; log.error(msg); return R.fail(msg); } //当前时间 String timeStr1 = LocalDateTime.now().format(DateTimeFormatter.ofPattern(FORMAT, Locale.CHINA)); DateTimeFormatter df = DateTimeFormatter.ofPattern(FORMAT, Locale.CHINA); LocalDateTime nowTime = LocalDateTime.parse(timeStr1, df); //下一周期起始时间(通过全局参数年份和月偏移量获取) ParameterDTO p = new ParameterDTO(); p.setKey(INDEX_SCORE_CYCLE); R<List<ParameterGradeValueDTO>> cycle = authorityApi.getValueByKey(p); if (null == cycle.getData() || cycle.getData().isEmpty()) { msg = "系统测试获取失败:评分周期"; log.error(msg); return R.fail(msg); } //先获取当前评分周期 int scoreCycle = Integer.parseInt(cycle.getData().get(0).getLeftValue()); //默认下一周期 int nextscoreCycle = ++scoreCycle; ParameterDTO p1 = new ParameterDTO(); p1.setKey(SCORE_OFFSET_MON); R<List<ParameterGradeValueDTO>> offser = authorityApi.getValueByKey(p1); if (null == offser.getData() || offser.getData().isEmpty()) { msg = "系统测试获取失败:评分周期月份偏移量"; log.error(msg); return R.fail(msg); } //和月偏移量 int offserMon = Integer.parseInt(offser.getData().get(0).getLeftValue()); int mon = 1; if (offserMon < 0) { nextscoreCycle--; mon = 13 + offserMon; } String nextTimes = nextscoreCycle + "-" + mon + "-01 00:00:00"; DateTimeFormatter de = DateTimeFormatter.ofPattern(FORMAT, Locale.CHINA); //下一周期生效具体时间 LocalDateTime nextTime = LocalDateTime.parse(nextTimes, de); //最大失效时间 LocalDateTime maxFaulureTime = LocalDateTime.parse(FAILURE_TIME, de); //所有通用指标集合 List<CommonIndex> commonIndexList = commonIndexService.lambdaQuery() .eq(CommonIndex::getStatus, ON_STATUS) .eq(CommonIndex::getIndexType, COMMON_INDEX_TYPE) .list(); //所有当前班组 相同专业的指标集合 List<CommonIndex> careerIndexList = commonIndexService.lambdaQuery() .eq(CommonIndex::getStatus, ON_STATUS) .eq(CommonIndex::getIndexType, oldTeam.getData() .getSpecialityId()) .list(); //班组创建时间 LocalDateTime beginTeamTime = oldTeam.getData() .getCreateTime(); //该班组 所有默认 指标 List<CommonIndex> allIndex = new ArrayList<>(); List<Long> allIndexId = new ArrayList<>(); if(null!=commonIndexList&&!commonIndexList.isEmpty()){ allIndex.addAll(commonIndexList); } if(null!=careerIndexList&&!careerIndexList.isEmpty()){ allIndex.addAll(careerIndexList); } if(null!=allIndex&&!allIndex.isEmpty()){ //该班组 所有默认 指标 id for (CommonIndex indexs : allIndex) { allIndexId.add(indexs.getId()); } } //根据指标id,班组id查 排除记录 TeamIndex oldTeamIndexP = teamIndexService.lambdaQuery() .eq(TeamIndex::getIndexId, indexId) .eq(TeamIndex::getTeamId, teamId) .eq(TeamIndex::getIncludeOrExclude, INCLUDER_OR_EXCLUDE) .one(); //根据指标id,班组id查 包含记录 TeamIndex oldTeamIndexB = teamIndexService.lambdaQuery() .eq(TeamIndex::getIndexId, indexId) .eq(TeamIndex::getTeamId, teamId) .eq(TeamIndex::getIncludeOrExclude, CONTION_OR_EXCLUDE) .one(); if (oldTeamIndexB != null) { msg = "此默认不归属本班的指标已经包含了,请输入有效的indexId!!"; log.error(msg); return R.fail(msg); } //不归属当前班组 if (!allIndexId.contains(indexId)) { //立马生效 if (IS_NOW_EFFECT .equals(isNowEffect) ) { TeamIndex t = new TeamIndex(); t.setTeamId(teamId); t.setIndexId(indexId); t.setStatus(ON_STATUS); t.setIncludeOrExclude(CONTION_OR_EXCLUDE); t.setBeginTime(nowTime); t.setEndTime(maxFaulureTime);//2036 if (!teamIndexService.save(t)) { msg = "当前周期新增本不归属本班的指标包含记录失败,请联系管理员或稍后重试!"; log.error(msg); return R.fail(msg); } return R.success("当前周期新增本不归属本班的指标包含记录成功!"); //下周期生效 } else { TeamIndex t = new TeamIndex(); t.setTeamId(teamId); t.setIndexId(indexId); t.setStatus(ON_STATUS); t.setIncludeOrExclude(CONTION_OR_EXCLUDE); t.setBeginTime(nextTime); t.setEndTime(maxFaulureTime);//2036 if (!teamIndexService.save(t)) { msg = "下一周期新增本不归属本班的指标包含记录失败,请联系管理员或稍后重试!"; log.error(msg); return R.fail(msg); } return R.success("下一周期新增本不归属本班的指标包含记录成功!"); } //归属当前班组 } else { if (oldTeamIndexP == null) { msg = "当前周期中默认属于本班组的此指标并没有生效的排除记录,不需要添加包含记录!"; log.error(msg); return R.fail(msg); } //立马生效 if (IS_NOW_EFFECT .equals(isNowEffect) ) { oldTeamIndexP.setStatus(NOT_ON_STATUS); oldTeamIndexP.setEndTime(nowTime); if (!teamIndexService.updateById(oldTeamIndexP)) { msg = "当前周期本归属本班的此指标设置包含记录失败,请联系管理员或稍后重试!"; log.error(msg); return R.fail(msg); } return R.success("当前周期本归属本班的此指标设置包含记录失败!"); //下个周期生效 } else { oldTeamIndexP.setStatus(NOT_ON_STATUS); oldTeamIndexP.setEndTime(nextTime); if (!teamIndexService.updateById(oldTeamIndexP)) { msg = "下一周期本归属本班的此指标设置包含记录失败,请联系管理员或稍后重试!"; log.error(msg); return R.fail(msg); } return R.success("下一周期本归属本班的此指标设置包含记录失败!"); } }