Commit 2e4c58cc by 张富康

feat(perfSalary): 优化自动绩效计算及考勤数据处理逻辑

- 自动绩效计算支持试用期和转正期间薪资按天数比例计算
- 新增判断试用期和转正存在性方法,精确评估考勤月份状态
- 基于出勤天数和产值阈值设置不同绩效等级及奖励系数
- 实现单条绩效数据插入独立事务,保证失败回滚并记录错误日志
- 考勤打卡处理逻辑新增离职日期判断,过滤离职后打卡数据
- PerformanceEvaluation模型调整日期字段类型为字符串,并新增离职日期字段
- 扩展数据库操作,支持性能评估记录的插入或更新(单条及批量)
- 代码格式及日志记录优化,提升代码可读性和稳定性
1 parent 361fdac8
...@@ -41,6 +41,8 @@ public class AutoPerformRule implements Serializable { ...@@ -41,6 +41,8 @@ public class AutoPerformRule implements Serializable {
@Column(name = "month_onboard_output_threshold") @Column(name = "month_onboard_output_threshold")
private Integer monthOnboardOutputThreshold; private Integer monthOnboardOutputThreshold;
/** /**
* 当月入职新员工-触发规则后的等级编码 * 当月入职新员工-触发规则后的等级编码
*/ */
...@@ -63,6 +65,7 @@ public class AutoPerformRule implements Serializable { ...@@ -63,6 +65,7 @@ public class AutoPerformRule implements Serializable {
private BigDecimal monthOnboardTriggerRewardCoefficient; private BigDecimal monthOnboardTriggerRewardCoefficient;
/** /**
* 当月入职新员工-规则外的默认等级编码 * 当月入职新员工-规则外的默认等级编码
*/ */
...@@ -84,6 +87,8 @@ public class AutoPerformRule implements Serializable { ...@@ -84,6 +87,8 @@ public class AutoPerformRule implements Serializable {
@Column(name = "month_onboard_default_reward_coefficient") @Column(name = "month_onboard_default_reward_coefficient")
private BigDecimal monthOnboardDefaultRewardCoefficient; private BigDecimal monthOnboardDefaultRewardCoefficient;
/** /**
* 非月入职员工-产值阈值(5000-20000)<此值 * 非月入职员工-产值阈值(5000-20000)<此值
*/ */
...@@ -91,6 +96,8 @@ public class AutoPerformRule implements Serializable { ...@@ -91,6 +96,8 @@ public class AutoPerformRule implements Serializable {
@Column(name = "no_month_onboard_output_threshold") @Column(name = "no_month_onboard_output_threshold")
private Integer noMonthOnboardOutputThreshold; private Integer noMonthOnboardOutputThreshold;
/** /**
* 非月入职员工-触发规则后的等级编码 * 非月入职员工-触发规则后的等级编码
*/ */
...@@ -98,7 +105,6 @@ public class AutoPerformRule implements Serializable { ...@@ -98,7 +105,6 @@ public class AutoPerformRule implements Serializable {
@Column(name = "no_month_onboard_trigger_level_code") @Column(name = "no_month_onboard_trigger_level_code")
private String noMonthOnboardTriggerLevelCode; private String noMonthOnboardTriggerLevelCode;
/** /**
* 非月入职员工-触发规则后的等级编码-分数范围 * 非月入职员工-触发规则后的等级编码-分数范围
*/ */
...@@ -113,6 +119,8 @@ public class AutoPerformRule implements Serializable { ...@@ -113,6 +119,8 @@ public class AutoPerformRule implements Serializable {
@Column(name = "no_month_onboard_trigger_reward_coefficient") @Column(name = "no_month_onboard_trigger_reward_coefficient")
private BigDecimal noMonthOnboardTriggerRewardCoefficient; private BigDecimal noMonthOnboardTriggerRewardCoefficient;
/** /**
* 非月入职员工-规则外的默认等级编码 * 非月入职员工-规则外的默认等级编码
*/ */
...@@ -134,6 +142,8 @@ public class AutoPerformRule implements Serializable { ...@@ -134,6 +142,8 @@ public class AutoPerformRule implements Serializable {
@Column(name = "no_month_onboard_default_reward_coefficient") @Column(name = "no_month_onboard_default_reward_coefficient")
private BigDecimal noMonthOnboardDefaultRewardCoefficient; private BigDecimal noMonthOnboardDefaultRewardCoefficient;
/** /**
* 生效月份(yyyy-mm格式) * 生效月份(yyyy-mm格式)
*/ */
......
...@@ -45,9 +45,8 @@ public class PerformanceEvaluation implements Serializable { ...@@ -45,9 +45,8 @@ public class PerformanceEvaluation implements Serializable {
* 评分月份(yyyy-mm) * 评分月份(yyyy-mm)
*/ */
@ApiModelProperty(notes = "评分月份(yyyy-mm)") @ApiModelProperty(notes = "评分月份(yyyy-mm)")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
@Column(name = "evaluation_month") @Column(name = "evaluation_month")
private Date evaluationMonth; private String evaluationMonth;
/** /**
* 绩效等级-系统自动设置 * 绩效等级-系统自动设置
...@@ -57,18 +56,19 @@ public class PerformanceEvaluation implements Serializable { ...@@ -57,18 +56,19 @@ public class PerformanceEvaluation implements Serializable {
private String autoGradeCode; private String autoGradeCode;
/** /**
* 分数范围-系统自动设置
*/
@ApiModelProperty(notes = "分数范围-系统自动设置")
@Column(name = "auto_score_symbol_value")
private String autoScoreSymbolValue;
/**
* 奖励系数-系统自动设置 * 奖励系数-系统自动设置
*/ */
@ApiModelProperty(notes = "奖励系数-系统自动设置") @ApiModelProperty(notes = "奖励系数-系统自动设置")
@Column(name = "auto_reward_coefficient") @Column(name = "auto_reward_coefficient")
private BigDecimal autoRewardCoefficient; private BigDecimal autoRewardCoefficient;
/**
* 分数范围-系统自动设置
*/
@ApiModelProperty(notes = "分数范围-系统自动设置")
@Column(name = "auto_score_symbol_value")
private String autoScoreSymbolValue;
/** /**
* 绩效等级-手动设置 * 绩效等级-手动设置
...@@ -106,50 +106,67 @@ public class PerformanceEvaluation implements Serializable { ...@@ -106,50 +106,67 @@ public class PerformanceEvaluation implements Serializable {
private Integer isAutoPerformance; private Integer isAutoPerformance;
/**
* 绩效工资
*/
@ApiModelProperty(notes = "绩效工资")
@Column(name = "performance_salary")
private BigDecimal performanceSalary;
/** /**
* 转正前底薪 * 转正前工资
*/ */
@ApiModelProperty(notes = "转正前底薪") @ApiModelProperty(notes = "转正前工资")
@Column(name = "before_correction_basic_salary") @Column(name = "before_correction_basic_salary")
private BigDecimal beforeCorrectionBasicSalary; private BigDecimal beforeCorrectionBasicSalary;
/** /**
* 转正后底薪 * 转正后工资
*/ */
@ApiModelProperty(notes = "转正后底薪") @ApiModelProperty(notes = "转正后工资")
@Column(name = "after_correction_basic_salary") @Column(name = "after_correction_basic_salary")
private BigDecimal afterCorrectionBasicSalary; private BigDecimal afterCorrectionBasicSalary;
/** /**
* 考勤计算后-试用期阶段底薪 (已乘70%) * 底薪占工资占比 默认0.7
*/ */
@ApiModelProperty(notes = "考勤计算后-试用期阶段底薪") @ApiModelProperty(notes = "底薪占工资占比 默认0.7")
@Column(name = "basic_salary_ratio")
private BigDecimal basicSalaryRatio;
/**
* 考勤计算后-试用期阶段工资
*/
@ApiModelProperty(notes = "考勤计算后-试用期阶段工资")
@Column(name = "after_attendance_probation_basic_salary") @Column(name = "after_attendance_probation_basic_salary")
private BigDecimal afterAttendanceProbationBasicSalary; private BigDecimal afterAttendanceProbationBasicSalary;
/** /**
* 考勤计算后-转正后阶段底薪 (已乘70%) * 考勤计算后-转正后阶段工资
*/ */
@ApiModelProperty(notes = "考勤计算后-转正后阶段底薪") @ApiModelProperty(notes = "考勤计算后-转正后阶段工资")
@Column(name = "after_attendance_regular_basic_salary") @Column(name = "after_attendance_regular_basic_salary")
private BigDecimal afterAttendanceRegularBasicSalary; private BigDecimal afterAttendanceRegularBasicSalary;
/** /**
* 考勤计算后-合计底薪 (已乘70%) * 考勤计算后-合计工资
*/ */
@ApiModelProperty(notes = "考勤计算后-合计底薪") @ApiModelProperty(notes = "考勤计算后-合计工资")
@Column(name = "after_attendance_total_basic_salary") @Column(name = "after_attendance_total_basic_salary")
private BigDecimal afterAttendanceTotalBasicSalary; private BigDecimal afterAttendanceTotalBasicSalary;
/** /**
* 基本工资(底薪+绩效工资) * 底薪 = 考勤计算后-合计工资 x basic_salary_ratio
*/
@ApiModelProperty(notes = "底薪")
@Column(name = "base_salary")
private BigDecimal baseSalary;
/**
* 绩效工资 = 考勤计算后-合计工资 x (1 - basic_salary_ratio) x 评分系数
*/
@ApiModelProperty(notes = "绩效工资")
@Column(name = "performance_salary")
private BigDecimal performanceSalary;
/**
* 基本工资 = (底薪 + 绩效工资)
*/ */
@ApiModelProperty(notes = "基本工资(底薪+绩效工资)") @ApiModelProperty(notes = "基本工资(底薪+绩效工资)")
@Column(name = "basic_salary") @Column(name = "basic_salary")
...@@ -173,17 +190,22 @@ public class PerformanceEvaluation implements Serializable { ...@@ -173,17 +190,22 @@ public class PerformanceEvaluation implements Serializable {
* 入职日期 * 入职日期
*/ */
@ApiModelProperty(notes = "入职日期") @ApiModelProperty(notes = "入职日期")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
@Column(name = "entry_date") @Column(name = "entry_date")
private Date entryDate; private String entryDate;
/** /**
* 转正日期 * 转正日期
*/ */
@ApiModelProperty(notes = "转正日期") @ApiModelProperty(notes = "转正日期")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
@Column(name = "correction_date") @Column(name = "correction_date")
private Date correctionDate; private String correctionDate;
/**
* 离职日期
*/
@ApiModelProperty(notes = "离职日期")
@Column(name = "leave_date")
private String leaveDate;
/** /**
* 是否该月入职:1-是,0-否 * 是否该月入职:1-是,0-否
...@@ -193,9 +215,9 @@ public class PerformanceEvaluation implements Serializable { ...@@ -193,9 +215,9 @@ public class PerformanceEvaluation implements Serializable {
private Integer isEntry; private Integer isEntry;
/** /**
* 是否试用期:1-是,0-否 * 该月是否试用期:1-是,0-否
*/ */
@ApiModelProperty(notes = "是否试用期:1-是,0-否") @ApiModelProperty(notes = "该月是否试用期:1-是,0-否")
@Column(name = "is_probation") @Column(name = "is_probation")
private Integer isProbation; private Integer isProbation;
...@@ -206,19 +228,13 @@ public class PerformanceEvaluation implements Serializable { ...@@ -206,19 +228,13 @@ public class PerformanceEvaluation implements Serializable {
@Column(name = "is_correction") @Column(name = "is_correction")
private Integer isCorrection; private Integer isCorrection;
/**
* 该月是否离职 1-是,0-否
*/
@ApiModelProperty(notes = "该月是否离职 1-是,0-否")
@Column(name = "is_leaving")
private Integer isLeaving;
/** /**
* 门店名称 * 门店名称
*/ */
@ApiModelProperty(notes = "门店名称") @ApiModelProperty(notes = "门店名称")
@Column(name = "merchant_name") @Column(name = "merchant_name")
private Integer merchantName; private String merchantName;
/** /**
......
...@@ -2,9 +2,15 @@ package cn.com.glsx.dj.staff.mapper.perfSalary; ...@@ -2,9 +2,15 @@ package cn.com.glsx.dj.staff.mapper.perfSalary;
import cn.com.glsx.dj.staff.model.perfSalary.PerformanceEvaluation; import cn.com.glsx.dj.staff.model.perfSalary.PerformanceEvaluation;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.oreframework.datasource.mybatis.mapper.OreMapper; import org.oreframework.datasource.mybatis.mapper.OreMapper;
import java.util.List;
@Mapper @Mapper
public interface PerformanceEvaluationMapper extends OreMapper<PerformanceEvaluation> { public interface PerformanceEvaluationMapper extends OreMapper<PerformanceEvaluation> {
void insertOrUpdate(PerformanceEvaluation performanceEvaluation);
void insertOrUpdateBatch(@Param("list") List<PerformanceEvaluation> performanceEvaluationList);
} }
\ No newline at end of file \ No newline at end of file
...@@ -283,6 +283,13 @@ public class AttendanceDataCleansingService { ...@@ -283,6 +283,13 @@ public class AttendanceDataCleansingService {
for (StaffQwClockClean clockInfo : staffQwClockCleans) { for (StaffQwClockClean clockInfo : staffQwClockCleans) {
try { try {
// 2. 处理每条考勤记录 // 2. 处理每条考勤记录
// 判断该打卡日期是否在离职直接之后,如果在离职日期之后则不计算
if (StrUtil.isNotBlank(employee.getLastWorkDate())) {
if(DateUtil.compare(DateUtil.parse(clockInfo.getClockInDate(), "yyyy-MM-dd"), DateUtil.parse(employee.getLastWorkDate(), "yyyy-MM-dd")) > 0){
log.info("{} 打卡日期:{},离职日期:{} 打卡日期在离职日期之后,不处理", employee.getStaffName(), clockInfo.getClockInDate(), employee.getLastWorkDate());
continue;
}
}
ClockInResult result = processClockIn(clockInfo, lastMonthYMD, employee); ClockInResult result = processClockIn(clockInfo, lastMonthYMD, employee);
workHours = NumberUtil.add(workHours, result.getTotalWorkHours()); workHours = NumberUtil.add(workHours, result.getTotalWorkHours());
lateEarlyMinutes = NumberUtil.add(lateEarlyMinutes, result.getLateEarlyMinutes()); lateEarlyMinutes = NumberUtil.add(lateEarlyMinutes, result.getLateEarlyMinutes());
...@@ -739,7 +746,8 @@ public class AttendanceDataCleansingService { ...@@ -739,7 +746,8 @@ public class AttendanceDataCleansingService {
String clockInDate = clockInfo.getClockInDate(); String clockInDate = clockInfo.getClockInDate();
String officialDate = employee.getOfficialDate(); String officialDate = employee.getOfficialDate();
// yyyy-MM-dd 比较clockInDate officialDate 日期大小 该打卡日期是否转正后 // yyyy-MM-dd 比较clockInDate officialDate 日期大小 该打卡日期是否转正后
boolean isAfterOfficialDate = StrUtil.isNotBlank(officialDate) && DateUtil.compare(DateUtil.parse(clockInDate, "yyyy-MM-dd"), DateUtil.parse(officialDate, "yyyy-MM-dd")) >= 0; boolean isAfterOfficialDate = StrUtil.isNotBlank(officialDate)
&& DateUtil.compare(DateUtil.parse(clockInDate, "yyyy-MM-dd"), DateUtil.parse(officialDate, "yyyy-MM-dd")) >= 0;
BigDecimal totalWorkHours = BigDecimal.ZERO; BigDecimal totalWorkHours = BigDecimal.ZERO;
BigDecimal lateEarlyMinutes = BigDecimal.ZERO; BigDecimal lateEarlyMinutes = BigDecimal.ZERO;
// todz // todz
...@@ -785,6 +793,7 @@ public class AttendanceDataCleansingService { ...@@ -785,6 +793,7 @@ public class AttendanceDataCleansingService {
} }
} }
// 4. 处理下班打卡 // 4. 处理下班打卡
if (ObjectUtil.isNotEmpty(clockInfo.getClockOutTimeEnd())) { if (ObjectUtil.isNotEmpty(clockInfo.getClockOutTimeEnd())) {
// 判断经纬度是否在商户打卡地址100米范围内 // 判断经纬度是否在商户打卡地址100米范围内
......
...@@ -14,6 +14,7 @@ import cn.hutool.core.collection.CollUtil; ...@@ -14,6 +14,7 @@ import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DatePattern; 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.NumberUtil;
import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONUtil; import cn.hutool.json.JSONUtil;
...@@ -21,10 +22,14 @@ import lombok.extern.slf4j.Slf4j; ...@@ -21,10 +22,14 @@ 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.PlatformTransactionManager; import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.TransactionDefinition;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.support.DefaultTransactionDefinition;
import tk.mybatis.mapper.entity.Example; import tk.mybatis.mapper.entity.Example;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.*; import java.util.*;
import java.util.concurrent.Executor; import java.util.concurrent.Executor;
import java.util.stream.Collectors; import java.util.stream.Collectors;
...@@ -53,6 +58,9 @@ public class AutoPerfEvaluationService { ...@@ -53,6 +58,9 @@ public class AutoPerfEvaluationService {
private GetDataStatsService getDataStatsService; private GetDataStatsService getDataStatsService;
@Resource @Resource
private PerformanceEvaluationMapper performanceEvaluationMapper; private PerformanceEvaluationMapper performanceEvaluationMapper;
Double basicSalaryRatio = OrePropertyConfigurer.getProperty("basic.salary.ratio", Double.class, 0.7);
/** /**
* 每月自动评绩效 * 每月自动评绩效
*/ */
...@@ -95,7 +103,7 @@ public class AutoPerfEvaluationService { ...@@ -95,7 +103,7 @@ public class AutoPerfEvaluationService {
attendanceSummaryMap = attendanceSummaries.stream().collect(Collectors.toMap(AttendanceSummary::getMobilePhone, v -> v)); attendanceSummaryMap = attendanceSummaries.stream().collect(Collectors.toMap(AttendanceSummary::getMobilePhone, v -> v));
} }
log.info("获取到 {} 条考勤数据", attendanceSummaries.size()); log.info("获取到 {} 条考勤数据", attendanceSummaries.size());
// 调用查询指标系统 获取所有员工产值 todz // 调用查询指标系统 获取所有员工产值
// { // {
// "itemCodes": "A036", // "itemCodes": "A036",
// "startDate": "2025-12-01", // "startDate": "2025-12-01",
...@@ -116,7 +124,7 @@ public class AutoPerfEvaluationService { ...@@ -116,7 +124,7 @@ public class AutoPerfEvaluationService {
String jsonBody = JSONUtil.toJsonStr(dataBizQueryParamsDTO); String jsonBody = JSONUtil.toJsonStr(dataBizQueryParamsDTO);
DataResp<List<DataBusinessDTO>> listDataResp = getDataStatsService.getListDataResp(jsonBody); DataResp<List<DataBusinessDTO>> listDataResp = getDataStatsService.getListDataResp(jsonBody);
List<DataBusinessDTO> content = listDataResp.getContent(); List<DataBusinessDTO> content = listDataResp.getContent();
// 给每个手机号设置0产值 map // 给每个手机号设置 0 产值 map
Map<String, BigDecimal> phoneOutValueMap = staffBeiSenBaseInfos.stream().collect( Map<String, BigDecimal> phoneOutValueMap = staffBeiSenBaseInfos.stream().collect(
Collectors.toMap(StaffBeisenBaseInfo::getStaffPhone, employee -> BigDecimal.ZERO)); Collectors.toMap(StaffBeisenBaseInfo::getStaffPhone, employee -> BigDecimal.ZERO));
// 判空 // 判空
...@@ -136,13 +144,275 @@ public class AutoPerfEvaluationService { ...@@ -136,13 +144,275 @@ public class AutoPerfEvaluationService {
List<PerformanceEvaluation> performanceEvaluations = new ArrayList<>(); List<PerformanceEvaluation> performanceEvaluations = new ArrayList<>();
for (StaffBeisenBaseInfo employee : staffBeiSenBaseInfos) { for (StaffBeisenBaseInfo employee : staffBeiSenBaseInfos) {
log.info("开始处理员工 {} 的数据", employee.getStaffName()); log.info("开始处理员工 {} 的数据", employee.getStaffName());
AttendanceSummary attendanceSummary = attendanceSummaryMap.get(employee.getStaffPhone()); // 判断是否该月入职
// 判断该员工该月是否转正 boolean isEntryBoolean = ObjectUtil.equals(DateUtil.format(DateUtil.parse(employee.getEntryDate()), DatePattern.NORM_MONTH_PATTERN), lastMonth);
// 判断该月是否存在试用期
boolean isProbationBoolean = hasProbationDays(employee.getEntryDate(), employee.getOfficialDate(), lastMonthFirstYMD, lastMonthLastYMD);
// 判断是否当月转正
boolean isCorrectionBoolean = hasOfficialDays(employee.getOfficialDate(), lastMonthLastYMD);
PerformanceEvaluation performanceEvaluation = new PerformanceEvaluation();
performanceEvaluation.setMobilePhone(employee.getStaffPhone());
performanceEvaluation.setName(employee.getStaffName());
performanceEvaluation.setEvaluationMonth(lastMonth);
BigDecimal trialBasicSalary = ObjectUtil.isNotEmpty(employee.getTrialBasicSalary()) ? employee.getTrialBasicSalary() : BigDecimal.ZERO;
BigDecimal formalBasicSalary = ObjectUtil.isNotEmpty(employee.getFormalBasicSalary()) ? employee.getFormalBasicSalary() : BigDecimal.ZERO;
performanceEvaluation.setBeforeCorrectionBasicSalary(trialBasicSalary);
performanceEvaluation.setAfterCorrectionBasicSalary(formalBasicSalary);
performanceEvaluation.setBasicSalaryRatio(BigDecimal.valueOf(basicSalaryRatio));
performanceEvaluation.setEntryDate(employee.getEntryDate());
performanceEvaluation.setCorrectionDate(employee.getOfficialDate());
performanceEvaluation.setLeaveDate(employee.getLastWorkDate());
performanceEvaluation.setIsEntry(isEntryBoolean ? 1 : 0);
performanceEvaluation.setIsProbation(isProbationBoolean ? 1 : 0);
performanceEvaluation.setIsCorrection(isCorrectionBoolean ? 1 : 0);
performanceEvaluation.setMerchantName(employee.getMerchantName());
performanceEvaluation.setSubmitCount(0);
performanceEvaluation.setHandleStatus(0);
performanceEvaluation.setSuperiorLeaderMobilePhone(employee.getDirectLeaderPhone());
// 考勤数据为空 底薪为0 BigDecimal staffOutValue = phoneOutValueMap.get(employee.getStaffPhone());
if (ObjectUtil.isEmpty(attendanceSummary)) { AttendanceSummary attendanceSummary = attendanceSummaryMap.get(employee.getStaffPhone());
// 试用期出勤天数
BigDecimal probationDays = attendanceSummary.getProbationDays();
// 转正出勤天数
BigDecimal correctionDays = attendanceSummary.getCorrectionDays();
// 计算考勤数据后的工资
Integer expectedAttendanceDays = attendanceSummary.getExpectedAttendanceDays();
BigDecimal actualAttendanceDays = attendanceSummary.getActualAttendanceDays();
// 计算-试用期期间工资
BigDecimal afterAttendanceProbationBasicSalary = BigDecimal.ZERO;
// 计算-转正期间工资
BigDecimal afterAttendanceRegularBasicSalary = BigDecimal.ZERO;
// 计算-完整工资
BigDecimal afterAttendanceTotalBasicSalary = BigDecimal.ZERO;
// 考勤数据为空 工资为0
if (ObjectUtil.isNotEmpty(attendanceSummary)) {
// 判断实际出勤天数是否大于等于考勤数据中的应出勤天数
if (actualAttendanceDays.compareTo(new BigDecimal(expectedAttendanceDays)) >= 0) {
// 满勤 完整工资
// 是否有存在试用
if (isProbationBoolean) {
// 判断是否存在月中转正
if (isCorrectionBoolean) {
// 试用期阶段:(转正前天数 - 试用期段休息天数)/应出勤天数 × 试用期工资
// (转正前天数 - 试用期段休息天数) = 试用期出勤天数 probationDays
// 试用期出勤天数 × 试用期工资 / 应出勤天数
afterAttendanceProbationBasicSalary = NumberUtil.div(NumberUtil.mul(probationDays, trialBasicSalary), expectedAttendanceDays)
.setScale(2, RoundingMode.HALF_UP);
// 转正后阶段:(转正后天数 - 转正后休息天数)/应出勤天数 × 转正后工资
// (转正后天数 - 转正后休息天数) = 转正出勤天数 correctionDays
// 转正出勤天数 × 转正后工资 / 应出勤天数
afterAttendanceRegularBasicSalary = NumberUtil.div(NumberUtil.mul(correctionDays, formalBasicSalary), expectedAttendanceDays)
.setScale(2, RoundingMode.HALF_UP);
// 底薪 = (试用期阶段工资 + 转正后阶段)
afterAttendanceTotalBasicSalary = afterAttendanceProbationBasicSalary.add(afterAttendanceRegularBasicSalary);
} else {
afterAttendanceProbationBasicSalary = trialBasicSalary;
afterAttendanceRegularBasicSalary = BigDecimal.ZERO;
afterAttendanceTotalBasicSalary = trialBasicSalary;
}
} else {
performanceEvaluation.setAfterAttendanceProbationBasicSalary(BigDecimal.ZERO);
performanceEvaluation.setAfterAttendanceRegularBasicSalary(formalBasicSalary);
performanceEvaluation.setAfterAttendanceTotalBasicSalary(formalBasicSalary);
}
} else {
// 不满勤
// 是否有存在试用
if (isProbationBoolean) {
// 判断是否存在月中转正
if (isCorrectionBoolean) {
// 试用期阶段:(转正前天数 - 试用期段休息天数)/应出勤天数 × 试用期工资
// (转正前天数 - 试用期段休息天数) = 试用期出勤天数 probationDays
// 试用期出勤天数 × 试用期工资 / 应出勤天数
afterAttendanceProbationBasicSalary = NumberUtil.div(NumberUtil.mul(probationDays, trialBasicSalary), expectedAttendanceDays)
.setScale(2, RoundingMode.HALF_UP);
// 转正后阶段:(转正后天数 - 转正后休息天数)/应出勤天数 × 转正后工资
// (转正后天数 - 转正后休息天数) = 转正出勤天数 correctionDays
// 转正出勤天数 × 转正后工资 / 应出勤天数
afterAttendanceRegularBasicSalary = NumberUtil.div(NumberUtil.mul(correctionDays, formalBasicSalary), expectedAttendanceDays)
.setScale(2, RoundingMode.HALF_UP);
// 底薪 = (试用期阶段工资 + 转正后阶段)
afterAttendanceTotalBasicSalary = afterAttendanceProbationBasicSalary.add(afterAttendanceRegularBasicSalary);
} else {
// 考勤全在试用期
// (自然月总天数 − 未出勤天数)/应出勤天数 × 工资
// 试用期出勤天数 × 试用期工资 / 应出勤天数
afterAttendanceProbationBasicSalary = NumberUtil.div(NumberUtil.mul(probationDays, trialBasicSalary), expectedAttendanceDays)
.setScale(2, RoundingMode.HALF_UP);
afterAttendanceRegularBasicSalary = BigDecimal.ZERO;
afterAttendanceTotalBasicSalary = NumberUtil.div(NumberUtil.mul(probationDays, trialBasicSalary), expectedAttendanceDays)
.setScale(2, RoundingMode.HALF_UP);
}
} else {
// 考勤全在已转正
// (自然月总天数 − 未出勤天数)/应出勤天数 × 工资
// 转正出勤天数 × 转正后工资 / 应出勤天数
afterAttendanceProbationBasicSalary = BigDecimal.ZERO;
afterAttendanceRegularBasicSalary = NumberUtil.div(NumberUtil.mul(correctionDays, formalBasicSalary), expectedAttendanceDays)
.setScale(2, RoundingMode.HALF_UP);
afterAttendanceTotalBasicSalary = BigDecimal.ZERO;
}
}
} else {
log.info("员工 {} 的考勤数据为空 底薪为0", employee.getStaffName()); log.info("员工 {} 的考勤数据为空 底薪为0", employee.getStaffName());
} }
performanceEvaluation.setAfterAttendanceProbationBasicSalary(afterAttendanceProbationBasicSalary);
performanceEvaluation.setAfterAttendanceRegularBasicSalary(afterAttendanceRegularBasicSalary);
performanceEvaluation.setAfterAttendanceTotalBasicSalary(afterAttendanceTotalBasicSalary);
// 通过判断产值 判断绩效评级
// 计算的评级
String calculatorLevel;
String calculatorMonthOnboardTriggerScore;
BigDecimal calculatorMonthOnboardTriggerRewardCoefficient;
int autoGradeType;
// 是否当月入职
if (isEntryBoolean) {
calculatorLevel = autoPerformRule.getMonthOnboardDefaultLevelCode();
calculatorMonthOnboardTriggerScore = autoPerformRule.getMonthOnboardDefaultScore();
calculatorMonthOnboardTriggerRewardCoefficient = autoPerformRule.getMonthOnboardDefaultRewardCoefficient();
Integer monthOnboardAttendanceDays = autoPerformRule.getMonthOnboardAttendanceDays();
// 自动打绩效类型 1-当月入职新员工-规则内 2-当月入职新员工-规则外 3-非当月入职员工-规则内 4-非当月入职员工-规则外
autoGradeType = 1;
// 判断出勤天数是否满足 monthOnboardAttendanceDays 标准 >=该天数
if (actualAttendanceDays.compareTo(new BigDecimal(monthOnboardAttendanceDays)) >= 0) {
// 判断产值是否满足产值阈值 < 该产值阈值
Integer monthOnboardOutputThreshold = autoPerformRule.getMonthOnboardOutputThreshold();
if (staffOutValue.compareTo(BigDecimal.valueOf(monthOnboardOutputThreshold)) < 0) {
// 触发规则
autoGradeType = 2;
calculatorLevel = autoPerformRule.getMonthOnboardTriggerLevelCode();
calculatorMonthOnboardTriggerScore = autoPerformRule.getMonthOnboardTriggerScore();
calculatorMonthOnboardTriggerRewardCoefficient = autoPerformRule.getMonthOnboardTriggerRewardCoefficient();
} }
} }
} else {
autoGradeType = 3;
calculatorLevel = autoPerformRule.getNoMonthOnboardTriggerLevelCode();
calculatorMonthOnboardTriggerScore = autoPerformRule.getNoMonthOnboardTriggerScore();
calculatorMonthOnboardTriggerRewardCoefficient = autoPerformRule.getNoMonthOnboardTriggerRewardCoefficient();
Integer noMonthOnboardOutputThreshold = autoPerformRule.getNoMonthOnboardOutputThreshold();
// 判断产值是否满足产值阈值 < 该产值阈值
if (staffOutValue.compareTo(BigDecimal.valueOf(noMonthOnboardOutputThreshold)) < 0) {
// 触发规则
autoGradeType = 4;
calculatorLevel = autoPerformRule.getNoMonthOnboardTriggerLevelCode();
calculatorMonthOnboardTriggerScore = autoPerformRule.getNoMonthOnboardDefaultScore();
calculatorMonthOnboardTriggerRewardCoefficient = autoPerformRule.getNoMonthOnboardDefaultRewardCoefficient();
}
}
performanceEvaluation.setAutoGradeCode(calculatorLevel);
performanceEvaluation.setAutoRewardCoefficient(calculatorMonthOnboardTriggerRewardCoefficient);
performanceEvaluation.setAutoScoreSymbolValue(calculatorMonthOnboardTriggerScore);
performanceEvaluation.setIsAutoPerformance(1);
// 底薪
BigDecimal baseSalary = NumberUtil.mul(afterAttendanceTotalBasicSalary, basicSalaryRatio).setScale(2, RoundingMode.HALF_UP);
// 绩效工资 = 合计工资 × (1 - 0.7) × 绩效工资系数
BigDecimal performanceSalary = NumberUtil.mul(NumberUtil.mul(afterAttendanceTotalBasicSalary, 1 - basicSalaryRatio), calculatorMonthOnboardTriggerRewardCoefficient)
.setScale(2, RoundingMode.HALF_UP);
// 基本工资 = (底薪 + 绩效工资)
BigDecimal basicSalary = NumberUtil.add(baseSalary, performanceSalary);
performanceEvaluation.setBaseSalary(baseSalary);
performanceEvaluation.setPerformanceSalary(performanceSalary);
performanceEvaluation.setBasicSalary(basicSalary);
performanceEvaluation.setTotalGrossSalary(null);
performanceEvaluation.setOutputValue(staffOutValue);
performanceEvaluation.setAutoPerformanceConfigId(autoPerformRule.getId());
performanceEvaluation.setPerformanceGradeUuid(autoPerformRule.getPerformanceLevelUuid());
performanceEvaluation.setAutoGradeType(autoGradeType);
performanceEvaluation.setAdoptType(1);
performanceEvaluation.setAmountCalculationType(1);
performanceEvaluations.add(performanceEvaluation);
}
// 保存插入数据
for (PerformanceEvaluation performanceEvaluation : performanceEvaluations) {
insertPerformanceEvaluations(performanceEvaluation);
}
}
/**
* 优化后的单条插入
* 1. 确保每个单条插入在独立事务中执行
* 2. 失败时回滚事务
* 3. 详细记录失败信息
*/
private void insertPerformanceEvaluations(PerformanceEvaluation performanceEvaluation) {
TransactionDefinition def = new DefaultTransactionDefinition();
TransactionStatus status = transactionManager.getTransaction(def);
try {
// 1. 执行插入操作
performanceEvaluationMapper.insertOrUpdate(performanceEvaluation);
// 2. 提交事务
transactionManager.commit(status);
} catch (Exception e) {
// 3. 失败时回滚事务
transactionManager.rollback(status);
log.error("自动打绩效插入失败:{},数据:{}", e.getMessage(), JSONUtil.toJsonStr(performanceEvaluation), e);
throw e;
}
}
/**
* 判断指定月份是否存在试用
*
* @param entryDateStr 入职时间(必填)
* @param officialDateStr 转正时间(为空说明在试用期)
* @param monthFirstYMD 该月第一天
* @param monthLastYMD 该月最后一天
* @return 是否存在试用
*/
public static boolean hasProbationDays(String entryDateStr, String officialDateStr,
DateTime monthFirstYMD, DateTime monthLastYMD) {
DateTime entryDate = DateUtil.parse(entryDateStr, DatePattern.NORM_DATE_PATTERN);
// 如果入职时间晚于当月最后一天,则当月无试用天数
if (entryDate.compareTo(monthLastYMD) > 0) {
return false;
}
if (StrUtil.isNotBlank(officialDateStr)) {
DateTime officialDate = DateUtil.parse(officialDateStr, DatePattern.NORM_DATE_PATTERN);
// 如果转正时间不为空且早于当月第一天,则当月无试用天数(已转正)
if (officialDate.compareTo(monthFirstYMD) <= 0) {
return false;
}
}
// 其他情况存在试用天数
return true;
}
/**
* 判断指定月份是否存在转正
*
* @param officialDateStr 转正时间(为空说明在试用期)
* @param monthLastYMD 该月最后一天
* @return 是否存在转正
*/
public static boolean hasOfficialDays(String officialDateStr, DateTime monthLastYMD) {
if (StrUtil.isNotBlank(officialDateStr)) {
DateTime officialDate = DateUtil.parse(officialDateStr, DatePattern.NORM_DATE_PATTERN);
// 如果转正时间晚于当月最后一天,则当月无转正
if (officialDate.compareTo(monthLastYMD) > 0) {
return false;
} else {
return true;
}
} else {
return false;
}
}
// public static void main(String[] args) {
// // 入职日期
//// DateTime entryDate = DateUtil.parseDate("2024-01-15");
// String entryDate = "2024-01-15";
// // 转正日期
//// DateTime officialDate = DateUtil.parseDate("2024-04-01");
// String officialDate = "2024-03-01";
// DateTime lastMonthFirstYMD = DateUtil.parseDate("2024-03-01");
// DateTime lastMonthLastYMD = DateUtil.parseDate("2024-03-31");
//
// System.out.println("是否存在试用天数: " + hasProbationDays(entryDate, officialDate, lastMonthFirstYMD, lastMonthLastYMD));
// System.out.println("是否存在转正天数: " + hasOfficialDays(officialDate, lastMonthLastYMD));
// }
} }
...@@ -3,6 +3,259 @@ ...@@ -3,6 +3,259 @@
<mapper namespace="cn.com.glsx.dj.staff.mapper.perfSalary.PerformanceEvaluationMapper"> <mapper namespace="cn.com.glsx.dj.staff.mapper.perfSalary.PerformanceEvaluationMapper">
<!-- 单条插入/更新 -->
<insert id="insertOrUpdate" parameterType="cn.com.glsx.dj.staff.model.perfSalary.PerformanceEvaluation">
INSERT INTO sal_performance_evaluation (
mobile_phone,
name,
evaluation_month,
auto_grade_code,
auto_reward_coefficient,
auto_score_symbol_value,
manual_grade_code,
manual_reward_coefficient,
manual_score_symbol_value,
manual_final_performance_amount,
is_auto_performance,
before_correction_basic_salary,
after_correction_basic_salary,
basic_salary_ratio,
after_attendance_probation_basic_salary,
after_attendance_regular_basic_salary,
after_attendance_total_basic_salary,
base_salary,
performance_salary,
basic_salary,
total_gross_salary,
output_value,
entry_date,
correction_date,
leave_date,
is_entry,
is_probation,
is_correction,
merchant_name,
auto_performance_config_id,
performance_grade_uuid,
auto_grade_type,
submit_count,
handle_status,
adopt_type,
amount_calculation_type,
superior_leader_mobile_phone,
created_by,
updated_by,
deleted_flag
)
VALUES (
#{mobilePhone},
#{name},
#{evaluationMonth},
#{autoGradeCode},
#{autoRewardCoefficient},
#{autoScoreSymbolValue},
#{manualGradeCode},
#{manualRewardCoefficient},
#{manualScoreSymbolValue},
#{manualFinalPerformanceAmount},
#{isAutoPerformance},
#{beforeCorrectionBasicSalary},
#{afterCorrectionBasicSalary},
#{basicSalaryRatio},
#{afterAttendanceProbationBasicSalary},
#{afterAttendanceRegularBasicSalary},
#{afterAttendanceTotalBasicSalary},
#{baseSalary},
#{performanceSalary},
#{basicSalary},
#{totalGrossSalary},
#{outputValue},
#{entryDate},
#{correctionDate},
#{leaveDate},
#{isEntry},
#{isProbation},
#{isCorrection},
#{merchantName},
#{autoPerformanceConfigId},
#{performanceGradeUuid},
#{autoGradeType},
#{submitCount},
#{handleStatus},
#{adoptType},
#{amountCalculationType},
#{superiorLeaderMobilePhone},
#{createdBy},
#{updatedBy},
#{deletedFlag}
)
ON DUPLICATE KEY UPDATE
name = VALUES(name),
auto_grade_code = VALUES(auto_grade_code),
auto_reward_coefficient = VALUES(auto_reward_coefficient),
auto_score_symbol_value = VALUES(auto_score_symbol_value),
manual_grade_code = VALUES(manual_grade_code),
manual_reward_coefficient = VALUES(manual_reward_coefficient),
manual_score_symbol_value = VALUES(manual_score_symbol_value),
manual_final_performance_amount = VALUES(manual_final_performance_amount),
is_auto_performance = VALUES(is_auto_performance),
before_correction_basic_salary = VALUES(before_correction_basic_salary),
after_correction_basic_salary = VALUES(after_correction_basic_salary),
basic_salary_ratio = VALUES(basic_salary_ratio),
after_attendance_probation_basic_salary = VALUES(after_attendance_probation_basic_salary),
after_attendance_regular_basic_salary = VALUES(after_attendance_regular_basic_salary),
after_attendance_total_basic_salary = VALUES(after_attendance_total_basic_salary),
base_salary = VALUES(base_salary),
performance_salary = VALUES(performance_salary),
basic_salary = VALUES(basic_salary),
total_gross_salary = VALUES(total_gross_salary),
output_value = VALUES(output_value),
entry_date = VALUES(entry_date),
correction_date = VALUES(correction_date),
leave_date = VALUES(leave_date),
is_entry = VALUES(is_entry),
is_probation = VALUES(is_probation),
is_correction = VALUES(is_correction),
merchant_name = VALUES(merchant_name),
auto_performance_config_id = VALUES(auto_performance_config_id),
performance_grade_uuid = VALUES(performance_grade_uuid),
auto_grade_type = VALUES(auto_grade_type),
submit_count = VALUES(submit_count),
handle_status = VALUES(handle_status),
adopt_type = VALUES(adopt_type),
amount_calculation_type = VALUES(amount_calculation_type),
superior_leader_mobile_phone = VALUES(superior_leader_mobile_phone),
updated_by = VALUES(updated_by),
updated_date = current_timestamp
</insert>
<!-- 批量插入/更新 -->
<insert id="insertOrUpdateBatch" parameterType="java.util.List">
INSERT INTO sal_performance_evaluation (
mobile_phone,
name,
evaluation_month,
auto_grade_code,
auto_reward_coefficient,
auto_score_symbol_value,
manual_grade_code,
manual_reward_coefficient,
manual_score_symbol_value,
manual_final_performance_amount,
is_auto_performance,
before_correction_basic_salary,
after_correction_basic_salary,
basic_salary_ratio,
after_attendance_probation_basic_salary,
after_attendance_regular_basic_salary,
after_attendance_total_basic_salary,
base_salary,
performance_salary,
basic_salary,
total_gross_salary,
output_value,
entry_date,
correction_date,
leave_date,
is_entry,
is_probation,
is_correction,
merchant_name,
auto_performance_config_id,
performance_grade_uuid,
auto_grade_type,
submit_count,
handle_status,
adopt_type,
amount_calculation_type,
superior_leader_mobile_phone,
created_by,
updated_by,
deleted_flag
)
VALUES
<foreach collection="list" item="item" separator=",">
(
#{item.mobilePhone},
#{item.name},
#{item.evaluationMonth},
#{item.autoGradeCode},
#{item.autoRewardCoefficient},
#{item.autoScoreSymbolValue},
#{item.manualGradeCode},
#{item.manualRewardCoefficient},
#{item.manualScoreSymbolValue},
#{item.manualFinalPerformanceAmount},
#{item.isAutoPerformance},
#{item.beforeCorrectionBasicSalary},
#{item.afterCorrectionBasicSalary},
#{item.basicSalaryRatio},
#{item.afterAttendanceProbationBasicSalary},
#{item.afterAttendanceRegularBasicSalary},
#{item.afterAttendanceTotalBasicSalary},
#{item.baseSalary},
#{item.performanceSalary},
#{item.basicSalary},
#{item.totalGrossSalary},
#{item.outputValue},
#{item.entryDate},
#{item.correctionDate},
#{item.leaveDate},
#{item.isEntry},
#{item.isProbation},
#{item.isCorrection},
#{item.merchantName},
#{item.autoPerformanceConfigId},
#{item.performanceGradeUuid},
#{item.autoGradeType},
#{item.submitCount},
#{item.handleStatus},
#{item.adoptType},
#{item.amountCalculationType},
#{item.superiorLeaderMobilePhone},
#{item.createdBy},
#{item.updatedBy},
#{item.deletedFlag}
)
</foreach>
ON DUPLICATE KEY UPDATE
name = VALUES(name),
auto_grade_code = VALUES(auto_grade_code),
auto_reward_coefficient = VALUES(auto_reward_coefficient),
auto_score_symbol_value = VALUES(auto_score_symbol_value),
manual_grade_code = VALUES(manual_grade_code),
manual_reward_coefficient = VALUES(manual_reward_coefficient),
manual_score_symbol_value = VALUES(manual_score_symbol_value),
manual_final_performance_amount = VALUES(manual_final_performance_amount),
is_auto_performance = VALUES(is_auto_performance),
before_correction_basic_salary = VALUES(before_correction_basic_salary),
after_correction_basic_salary = VALUES(after_correction_basic_salary),
basic_salary_ratio = VALUES(basic_salary_ratio),
after_attendance_probation_basic_salary = VALUES(after_attendance_probation_basic_salary),
after_attendance_regular_basic_salary = VALUES(after_attendance_regular_basic_salary),
after_attendance_total_basic_salary = VALUES(after_attendance_total_basic_salary),
base_salary = VALUES(base_salary),
performance_salary = VALUES(performance_salary),
basic_salary = VALUES(basic_salary),
total_gross_salary = VALUES(total_gross_salary),
output_value = VALUES(output_value),
entry_date = VALUES(entry_date),
correction_date = VALUES(correction_date),
leave_date = VALUES(leave_date),
is_entry = VALUES(is_entry),
is_probation = VALUES(is_probation),
is_correction = VALUES(is_correction),
merchant_name = VALUES(merchant_name),
auto_performance_config_id = VALUES(auto_performance_config_id),
performance_grade_uuid = VALUES(performance_grade_uuid),
auto_grade_type = VALUES(auto_grade_type),
submit_count = VALUES(submit_count),
handle_status = VALUES(handle_status),
adopt_type = VALUES(adopt_type),
amount_calculation_type = VALUES(amount_calculation_type),
superior_leader_mobile_phone = VALUES(superior_leader_mobile_phone),
updated_by = VALUES(updated_by),
updated_date = current_timestamp
</insert>
</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!