package cn.iocoder.yudao.module.hrm.dal.redis;
|
|
import cn.hutool.core.date.DatePattern;
|
import cn.hutool.core.date.DateUtil;
|
import jakarta.annotation.Resource;
|
import org.springframework.data.redis.core.StringRedisTemplate;
|
import org.springframework.stereotype.Repository;
|
|
import java.time.Duration;
|
import java.time.LocalDateTime;
|
|
/**
|
* HRM 编号生成的 Redis DAO
|
*
|
* @author 芋道源码
|
*/
|
@Repository
|
public class HrmNoRedisDAO {
|
|
/**
|
* 员工编号前缀
|
*/
|
public static final String EMPLOYEE_NO_PREFIX = "EMP";
|
|
/**
|
* 考勤异常申请编号前缀
|
*/
|
public static final String ATTENDANCE_EXCEPTION_NO_PREFIX = "KQ";
|
|
/**
|
* 薪酬核算编号前缀
|
*/
|
public static final String SALARY_CALCULATION_NO_PREFIX = "SC";
|
|
/**
|
* 薪资发放编号前缀
|
*/
|
public static final String SALARY_PAYMENT_NO_PREFIX = "SF";
|
|
/**
|
* 请假申请编号前缀
|
*/
|
public static final String LEAVE_APPLICATION_NO_PREFIX = "LA";
|
|
/**
|
* 调岗申请编号前缀
|
*/
|
public static final String TRANSFER_APPLICATION_NO_PREFIX = "TA";
|
|
/**
|
* 离职申请编号前缀
|
*/
|
public static final String RESIGNATION_APPLICATION_NO_PREFIX = "RA";
|
|
@Resource
|
private StringRedisTemplate stringRedisTemplate;
|
|
/**
|
* 生成员工编号,格式:EMP + yyyyMMdd + 4位自增
|
* 例如:EMP202401010001
|
*
|
* @return 员工编号
|
*/
|
public String generateEmployeeNo() {
|
return generate(EMPLOYEE_NO_PREFIX, 4);
|
}
|
|
/**
|
* 生成请假申请编号,格式:LA + yyyyMMdd + 4位自增
|
* 例如:LA202401010001
|
*
|
* @return 请假申请编号
|
*/
|
public String generateLeaveApplicationNo() {
|
return generate(LEAVE_APPLICATION_NO_PREFIX, 4);
|
}
|
|
/**
|
* 生成调岗申请编号,格式:TA + yyyyMMdd + 4位自增
|
* 例如:TA202401010001
|
*
|
* @return 调岗申请编号
|
*/
|
public String generateTransferApplicationNo() {
|
return generate(TRANSFER_APPLICATION_NO_PREFIX, 4);
|
}
|
|
/**
|
* 生成离职申请编号,格式:RA + yyyyMMdd + 4位自增
|
* 例如:RA202401010001
|
*
|
* @return 离职申请编号
|
*/
|
public String generateResignationApplicationNo() {
|
return generate(RESIGNATION_APPLICATION_NO_PREFIX, 4);
|
}
|
|
/**
|
* 生成薪酬核算编号,格式:SC + yyyyMMdd + 4位自增
|
* 例如:SC202401010001
|
*
|
* @return 薪酬核算编号
|
*/
|
public String generateSalaryCalculationNo() {
|
return generate(SALARY_CALCULATION_NO_PREFIX, 4);
|
}
|
|
/**
|
* 生成薪资发放编号,格式:SF + yyyyMMdd + 4位自增
|
* 例如:SF202401010001
|
*
|
* @return 薪资发放编号
|
*/
|
public String generateSalaryPaymentNo() {
|
return generate(SALARY_PAYMENT_NO_PREFIX, 4);
|
}
|
|
/**
|
* 生成编号
|
*
|
* @param prefix 前缀
|
* @param digits 位数
|
* @return 编号
|
*/
|
public String generate(String prefix, int digits) {
|
String noPrefix = prefix + DateUtil.format(LocalDateTime.now(), DatePattern.PURE_DATE_PATTERN);
|
String key = HrmRedisKeyConstants.NO + noPrefix;
|
Long no = stringRedisTemplate.opsForValue().increment(key);
|
// 设置过期时间 1 天
|
stringRedisTemplate.expire(key, Duration.ofDays(1L));
|
return noPrefix + String.format("%0" + digits + "d", no);
|
}
|
|
}
|