Commit 2e256bec by 张富康

feat(perfSalary): 增加绩效规则定时生效任务与打卡数据同步参数支持

- 在AutoPerformRuleMapper接口及XML中新增删除生效规则和更新待生效规则方法
- 修改clockInCompleteAnalysisStaffService,支持传入打卡日期参数以同步指定月份数据
- 修改PerfRuleRemoteService,新增绩效规则定时任务方法perfRuleSettingJob,实现将待生效规则设为生效
- 调整生效月份校验逻辑,支持当前月份及未来月份为有效生效时间
- 新建PerfRuleSettingJob定时任务,每月1号执行绩效规则生效流程
- 优化SyncQwClockInDetailDataJob定时任务,支持通过分片参数动态指定同步月份
- 更新EffectiveReferralReview模型状态定义,增加“未保存过”和“待提交(草稿)”状态描述
1 parent c9fe6bb7
...@@ -77,9 +77,9 @@ public class EffectiveReferralReview implements Serializable { ...@@ -77,9 +77,9 @@ public class EffectiveReferralReview implements Serializable {
private String remark; private String remark;
/** /**
* 状态:0-待提交,1-待复核 * 状态:0-未保存过,1-待提交(草稿),2-待复核
*/ */
@ApiModelProperty(notes = "状态:0-待提交,1-待复核") @ApiModelProperty(notes = "状态:0-未保存过,1-待提交(草稿),2-待复核")
@Column(name = "status") @Column(name = "status")
private Integer status; private Integer status;
......
package cn.com.glsx.dj.staff.job;
import cn.com.glsx.dj.staff.service.perfSalary.PerfRuleRemoteService;
import com.dangdang.ddframe.job.api.ShardingContext;
import com.dangdang.ddframe.job.api.simple.SimpleJob;
import lombok.extern.slf4j.Slf4j;
import org.oreframework.boot.autoconfigure.elasticjob.annotation.ElasticJobConf;
import javax.annotation.Resource;
@Slf4j
@ElasticJobConf(name = "PerfRuleSettingJob", cron = "0 0 1 1 * ? ", description = "绩效配置设置", overwrite = false)
public class PerfRuleSettingJob implements SimpleJob {
@Resource
private PerfRuleRemoteService perfRuleRemoteService;
@Override
public void execute(ShardingContext shardingContext) {
log.info("----------------绩效配置设置开始-----------------");
try {
perfRuleRemoteService.perfRuleSettingJob();
} catch (Exception e) {
log.error(e.getMessage(), e);
}
log.info("----------------绩效配置设置结束-----------------");
}
}
...@@ -8,7 +8,7 @@ import org.oreframework.boot.autoconfigure.elasticjob.annotation.ElasticJobConf; ...@@ -8,7 +8,7 @@ import org.oreframework.boot.autoconfigure.elasticjob.annotation.ElasticJobConf;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@Slf4j @Slf4j
@ElasticJobConf(name = "SyncQwClockInDetailDataJob", cron = "0 0 4 1 * ? ", description = "定时打卡详情同步任务-每月1号4点执行", overwrite = false) @ElasticJobConf(name = "SyncQwClockInDetailDataJob", cron = "0 0 4 1 * ? ", description = "定时打卡详情同步任务-每月1号4点执行-可配参数格式(yyyy-MM)", overwrite = false)
public class SyncQwClockInDetailDataJob implements SimpleJob { public class SyncQwClockInDetailDataJob implements SimpleJob {
@Autowired @Autowired
...@@ -19,7 +19,9 @@ public class SyncQwClockInDetailDataJob implements SimpleJob { ...@@ -19,7 +19,9 @@ public class SyncQwClockInDetailDataJob implements SimpleJob {
log.info("----------------定时打卡详情同步任务开始-----------------"); log.info("----------------定时打卡详情同步任务开始-----------------");
long l = System.currentTimeMillis(); long l = System.currentTimeMillis();
try { try {
clockInCompleteAnalysisStaffService.syncQwClockInDetailData(); String shardingParameter = shardingContext.getShardingParameter();
log.info("参数:{}", shardingParameter);
clockInCompleteAnalysisStaffService.syncQwClockInDetailData(shardingParameter);
} catch (Exception e) { } catch (Exception e) {
log.error(e.getMessage(), e); log.error(e.getMessage(), e);
} }
......
...@@ -18,4 +18,8 @@ public interface AutoPerformRuleMapper extends OreMapper<AutoPerformRule> { ...@@ -18,4 +18,8 @@ public interface AutoPerformRuleMapper extends OreMapper<AutoPerformRule> {
void deleteLatestRuleConfig(); void deleteLatestRuleConfig();
void deleteEffectiveRuleConfig();
void updatePendingRuleConfig(@Param("id") Integer id);
} }
\ No newline at end of file \ No newline at end of file
...@@ -126,7 +126,7 @@ public class PerfRuleRemoteImpl implements PerfRuleRemote { ...@@ -126,7 +126,7 @@ public class PerfRuleRemoteImpl implements PerfRuleRemote {
*/ */
@Override @Override
public RpcResponse<Boolean> clockInCompleteAnalysisStaff() { public RpcResponse<Boolean> clockInCompleteAnalysisStaff() {
clockInCompleteAnalysisStaffService.syncQwClockInDetailData(); clockInCompleteAnalysisStaffService.syncQwClockInDetailData("");
return RpcResponse.success(true); return RpcResponse.success(true);
} }
......
...@@ -13,6 +13,7 @@ import cn.hutool.core.date.DatePattern; ...@@ -13,6 +13,7 @@ import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateTime; import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil; import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.CollectionUtils;
...@@ -37,11 +38,16 @@ public class ClockInCompleteAnalysisStaffService { ...@@ -37,11 +38,16 @@ public class ClockInCompleteAnalysisStaffService {
@Resource @Resource
private StaffQwClockCleanMapper staffQwClockCleanMapper; private StaffQwClockCleanMapper staffQwClockCleanMapper;
public void syncQwClockInDetailData() { public void syncQwClockInDetailData(String clockInDateStr) {
Integer merchantId = OrePropertyConfigurer.getProperty("syncQwClockInData.build.merchantId", Integer.class, 44202977); Integer merchantId = OrePropertyConfigurer.getProperty("syncQwClockInData.build.merchantId", Integer.class, 44202977);
// 查询企微打卡表指定日期所有人员 // 查询企微打卡表指定日期所有人员
DateTime lastMonthDate = DateUtil.offsetMonth(new Date(), -1); DateTime lastMonthDate = DateUtil.offsetMonth(new Date(), -1);
String clockInDate = DateUtil.format(lastMonthDate, DatePattern.NORM_MONTH_PATTERN); String clockInDate;
if (StrUtil.isNotBlank(clockInDateStr)) {
clockInDate = clockInDateStr;
} else {
clockInDate = DateUtil.format(lastMonthDate, DatePattern.NORM_MONTH_PATTERN);
}
List<StaffQwClockInInfo> staffQwClockInInfos = staffQwClockInInfoMapper.selectByDate(clockInDate); List<StaffQwClockInInfo> staffQwClockInInfos = staffQwClockInInfoMapper.selectByDate(clockInDate);
// 判断是否有数据 // 判断是否有数据
if (ObjectUtil.isEmpty(staffQwClockInInfos)) { if (ObjectUtil.isEmpty(staffQwClockInInfos)) {
......
...@@ -11,14 +11,18 @@ import cn.com.glsx.dj.staff.model.perfSalary.PerformanceLevel; ...@@ -11,14 +11,18 @@ import cn.com.glsx.dj.staff.model.perfSalary.PerformanceLevel;
import cn.com.glsx.dj.staff.model.perfSalary.PerformanceMonthly; import cn.com.glsx.dj.staff.model.perfSalary.PerformanceMonthly;
import cn.com.glsx.framework.core.exception.RpcServiceException; import cn.com.glsx.framework.core.exception.RpcServiceException;
import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil; import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.IdUtil; import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.oreframework.boot.env.OrePropertyConfigurer; import org.oreframework.boot.env.OrePropertyConfigurer;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import tk.mybatis.mapper.entity.Example;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.Date; import java.util.Date;
...@@ -73,10 +77,10 @@ public class PerfRuleRemoteService { ...@@ -73,10 +77,10 @@ public class PerfRuleRemoteService {
// log.info("perfRuleConfigUpdate:{}", JSONUtil.toJsonPrettyStr(perfRuleConfigUpdateDTO)); // log.info("perfRuleConfigUpdate:{}", JSONUtil.toJsonPrettyStr(perfRuleConfigUpdateDTO));
AutoPerformRuleUpdateDTO autoPerformRuleUpdateDTO = perfRuleConfigUpdateDTO.getAutoPerformRuleUpdateDTO(); AutoPerformRuleUpdateDTO autoPerformRuleUpdateDTO = perfRuleConfigUpdateDTO.getAutoPerformRuleUpdateDTO();
List<PerformanceLevelUpdateDTO> performanceLevelUpdateDTOS = perfRuleConfigUpdateDTO.getPerformanceLevelUpdateDTOS(); List<PerformanceLevelUpdateDTO> performanceLevelUpdateDTOS = perfRuleConfigUpdateDTO.getPerformanceLevelUpdateDTOS();
// hutool判断生效月份是未来月份 如果不是则抛异常 // hutool判断生效月份是当月或未来月份 如果不是则抛异常
Date effectiveMonth = autoPerformRuleUpdateDTO.getEffectiveMonth(); Date effectiveMonth = autoPerformRuleUpdateDTO.getEffectiveMonth();
if (!isFutureMonth(DateUtil.formatDate(effectiveMonth))) { if (!isCurrentAndFutureMonth(DateUtil.formatDate(effectiveMonth))) {
throw new RpcServiceException("生效时间应大于当前月"); throw new RpcServiceException("生效时间应大于等于当前月");
} }
// 删除最新的配置 // 删除最新的配置
autoPerformRuleMapper.deleteLatestRuleConfig(); autoPerformRuleMapper.deleteLatestRuleConfig();
...@@ -147,12 +151,46 @@ public class PerfRuleRemoteService { ...@@ -147,12 +151,46 @@ public class PerfRuleRemoteService {
} }
/** /**
* 判断指定日期时间字符串是否属于未来月份 * 定时任务-绩效配置设置
*/
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = RpcServiceException.class)
public void perfRuleSettingJob() {
// 查询是否存在 待生效且生效时间等于上个月的配置
// 上个月
DateTime lastMonthDate = DateUtil.offsetMonth(new Date(), -1);
String lastMonth = DateUtil.format(lastMonthDate, DatePattern.NORM_MONTH_PATTERN);
String queryLastMonthPendingCondition = "(DATE_FORMAT(effective_month, '%Y-%m') = '{}')";
queryLastMonthPendingCondition = StrUtil.format(queryLastMonthPendingCondition, lastMonth);
Example queryLastMonthPendingExample = new Example(AutoPerformRule.class);
queryLastMonthPendingExample.createCriteria().andEqualTo("effectiveStatus", EffectiveStatusEnum.PENDING_EFFECTIVE.getCode())
.andCondition(queryLastMonthPendingCondition)
.andEqualTo("effectiveStartDate", lastMonth);
AutoPerformRule lastMonthPendingAutoPerformRule = autoPerformRuleMapper.selectOneByExample(queryLastMonthPendingExample);
if (ObjectUtil.isEmpty(lastMonthPendingAutoPerformRule)) {
// 使用生效中的配置
Example queryEffectiveExample = new Example(AutoPerformRule.class);
queryEffectiveExample.createCriteria().andEqualTo("effectiveStatus", EffectiveStatusEnum.EFFECTIVE.getCode())
.andEqualTo("deletedFlag", 'N');
AutoPerformRule effectiveAutoPerformRule = autoPerformRuleMapper.selectOneByExample(queryEffectiveExample);
if (ObjectUtil.isEmpty(effectiveAutoPerformRule)) {
log.error("未找到有效的绩效配置");
return;
}
}
// 存在待生效的
// 将生效中的配置逻辑删除
autoPerformRuleMapper.deleteEffectiveRuleConfig();
// 将lastMonthPendingAutoPerformRule设置为生效中
autoPerformRuleMapper.updatePendingRuleConfig(lastMonthPendingAutoPerformRule.getId());
}
/**
* 判断指定日期时间字符串是否属于当前或未来月份
* *
* @param dateTimeStr 日期时间字符串 (格式: yyyy-MM-dd hh:mm:ss) * @param dateTimeStr 日期时间字符串 (格式: yyyy-MM-dd hh:mm:ss)
* @return true 表示是未来月份,false 表示不是 * @return true 表示是当前或未来月份,false 表示不是
*/ */
public static boolean isFutureMonth(String dateTimeStr) { public static boolean isCurrentAndFutureMonth(String dateTimeStr) {
// 1. 解析传入的日期字符串 // 1. 解析传入的日期字符串
Date targetDate = DateUtil.parse(dateTimeStr); Date targetDate = DateUtil.parse(dateTimeStr);
...@@ -165,15 +203,14 @@ public class PerfRuleRemoteService { ...@@ -165,15 +203,14 @@ public class PerfRuleRemoteService {
int currentYear = DateUtil.year(now); int currentYear = DateUtil.year(now);
int currentMonth = DateUtil.month(now) + 1; int currentMonth = DateUtil.month(now) + 1;
// 4. 比较逻辑 // 4. 比较逻辑(关键修改:当前月份也返回 true)
// 同年同月或更早
if (targetYear > currentYear) { if (targetYear > currentYear) {
return true; // 目标年份更晚 return true; // 目标年份更晚
} else return targetYear == currentYear && targetMonth > currentMonth; // 同年但目标月份更晚 } else {
// 修正:目标月份 >= 当前月份(包含当前月份)
return targetYear == currentYear && targetMonth >= currentMonth;
}
} }
......
...@@ -32,7 +32,6 @@ ...@@ -32,7 +32,6 @@
LIMIT 1 LIMIT 1
</select> </select>
<!-- 2. 查询绩效等级配置(关联表) -->
<select id="getPerformanceLevels" resultType="cn.com.glsx.dj.staff.dto.perfSalary.PerformanceLevelDetailDTO"> <select id="getPerformanceLevels" resultType="cn.com.glsx.dj.staff.dto.perfSalary.PerformanceLevelDetailDTO">
SELECT SELECT
level_code AS levelCode, level_code AS levelCode,
...@@ -40,16 +39,27 @@ ...@@ -40,16 +39,27 @@
score_symbol_value AS scoreSymbolValue, score_symbol_value AS scoreSymbolValue,
reward_coefficient AS rewardCoefficient reward_coefficient AS rewardCoefficient
FROM sal_performance_level FROM sal_performance_level
WHERE uuid = #{uuid} <!-- 通过外部参数传入 --> WHERE uuid = #{uuid}
</select> </select>
<update id="deleteLatestRuleConfig"> <update id="deleteLatestRuleConfig">
UPDATE sal_auto_perform_rule UPDATE sal_auto_perform_rule
SET deleted_flag = 'D' SET deleted_flag = 'D'
WHERE effective_month > Date(now())
ORDER BY created_date DESC ORDER BY created_date DESC
LIMIT 1 LIMIT 1
</update> </update>
<update id="deleteEffectiveRuleConfig">
UPDATE sal_auto_perform_rule
SET deleted_flag = 'D'
WHERE effective_status = 1;
</update>
<update id="updatePendingRuleConfig">
UPDATE sal_auto_perform_rule
SET effective_status = 2
WHERE id = #{id};
</update>
</mapper> </mapper>
\ No newline at end of file \ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!