Commit c6ba991f authored by 刘斌's avatar 刘斌

feat: 增加H5表单保存

parent 4553770c
package com.anplus.hr.config;
import cn.hutool.core.date.LocalDateTimeUtil;
import com.anplus.hr.constant.HrAgeGroupEnum;
import com.anplus.hr.constant.HrEmployeeConstants;
import com.anplus.hr.constant.HrYearsOfServiceSegmentEnum;
import com.anplus.hr.domain.EmployeeInfo;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.Period;
/**
* @author 刘斌
* @date 2025/11/25 21:16
*/
public class EmployeeInfoCalcUtils {
/**
* 计算预计转正时间
*/
public static boolean calcExpectedRegularDate(EmployeeInfo employeeInfo) {
boolean isUpdate = false;
if (HrEmployeeConstants.EMPLOYEE_TYPE_REGULAR.equals(employeeInfo.getEmployeeType())) {
return false;
}
if (employeeInfo.getEntryDate() != null && employeeInfo.getProbationPeriod() != null) {
employeeInfo.setExpectedRegularDate(employeeInfo.getEntryDate().plusMonths(employeeInfo.getProbationPeriod()));
isUpdate = true;
}
return isUpdate;
}
/**
* 计算员工年龄组
*/
public static boolean calcAgeGroup(EmployeeInfo employeeInfo) {
boolean isUpdate = false;
if (employeeInfo.getBirthDate() == null) {
return false;
}
Period period = LocalDateTimeUtil.betweenPeriod(employeeInfo.getBirthDate(), LocalDate.from(LocalDateTime.now()));
int years = period.getYears();
// 更新员工年龄组
if (employeeInfo.getAge() == null || employeeInfo.getAge() != years) {
isUpdate = true;
employeeInfo.setAge(years);
HrAgeGroupEnum ageGroupEnum = HrAgeGroupEnum.getByAge(employeeInfo.getAge());
if (ageGroupEnum != null) {
employeeInfo.setAgeGroup(ageGroupEnum.getCode());
}
} else if (employeeInfo.getAgeGroup() == null) {
HrAgeGroupEnum ageGroupEnum = HrAgeGroupEnum.getByAge(employeeInfo.getAge());
if (ageGroupEnum != null) {
employeeInfo.setAgeGroup(ageGroupEnum.getCode());
isUpdate = true;
}
}
return isUpdate;
}
/**
* 计算员工工龄
*/
public static boolean calcYearsOfService(EmployeeInfo employeeInfo) {
boolean isUpdate = false;
if (employeeInfo.getEntryDate() != null) {
int newTotalMonths = SeniorityUtils.calculateTotalMonths(employeeInfo.getEntryDate());
if (employeeInfo.getYearsOfServiceMonths() == null || employeeInfo.getYearsOfServiceMonths() != newTotalMonths) {
employeeInfo.setYearsOfServiceMonths(newTotalMonths);
employeeInfo.setYearsOfService(SeniorityUtils.formatMonthsToSeniority(newTotalMonths));
// 更新员工工龄组
HrYearsOfServiceSegmentEnum yearsOfServiceSegmentEnum = HrYearsOfServiceSegmentEnum.getByTotalMonths(newTotalMonths);
if (yearsOfServiceSegmentEnum != null) {
employeeInfo.setYearsOfServiceSegment(yearsOfServiceSegmentEnum.getCode());
}
isUpdate = true;
}
}
return isUpdate;
}
}
package com.anplus.hr.controller;
import cn.dev33.satoken.annotation.SaIgnore;
import com.alibaba.cola.dto.Response;
import com.anplus.hr.domain.params.EmployeeBaseInfoParam;
import com.anplus.hr.service.EmployeeInfoServ;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import top.binfast.common.core.constant.BusinessType;
import top.binfast.common.core.util.ResponseUtils;
import top.binfast.common.idempotent.annotation.NoRepeatSubmit;
import top.binfast.common.log.annotation.PinSysLog;
/**
* @author 刘斌
* @date 2025/11/25 21:03
*/
@RestController
@RequestMapping("/employee/baseInfo")
public class EmployeeBaseInfoForH5Ctrl {
@Resource
private EmployeeInfoServ employeeInfoServ;
/**
* 新增基础员工信息
*/
@SaIgnore
@NoRepeatSubmit
// @SaCheckPermission("employee:info:add")
@PinSysLog(value = "基础员工信息", businessType = BusinessType.INSERT)
@PostMapping()
public Response addBaseInfo(@RequestBody EmployeeBaseInfoParam param) {
return ResponseUtils.ofResult(employeeInfoServ.insertBaseInfoForH5(param));
}
}
package com.anplus.hr.domain.params;
import com.anplus.hr.domain.EmployeeInfo;
import io.github.linpeilie.annotations.AutoMapper;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
import java.time.LocalDate;
/**
* @author 刘斌
* @date 2025/11/25 20:56
*/
@Data
@AutoMapper(target = EmployeeInfo.class, reverseConvertGenerate = false)
public class EmployeeBaseInfoParam {
/**
* 姓名
*/
@NotBlank(message = "姓名不能为空")
private String name;
/**
* 手机号码
*/
@NotBlank(message = "手机号码不能为空")
private String phoneNumber;
/**
* 性别
*/
@NotBlank(message = "性别不能为空")
private String gender;
/**
* 身份证号码
*/
@NotBlank(message = "身份证号码不能为空")
private String idCardNumber;
/**
* 出生日期
*/
@NotNull(message = "出生日期不能为空")
private LocalDate birthDate;
/**
* 年龄
*/
@NotNull(message = "年龄不能为空")
private Integer age;
/**
* 照片
*/
@NotBlank(message = "照片不能为空")
private String photo;
/**
* 籍贯
*/
@NotBlank(message = "籍贯不能为空")
private String nativePlace;
/**
* 民族
*/
@NotBlank(message = "民族不能为空")
private String ethnicity;
/**
* 婚姻状况
*/
@NotBlank(message = "婚姻状况不能为空")
private String maritalStatus;
/**
* 政治面貌
*/
@NotBlank(message = "政治面貌不能为空")
private String politicalStatus;
/**
* 紧急联系人
*/
@NotBlank(message = "紧急联系人不能为空")
private String emergencyContact;
/**
* 紧急联系人电话
*/
@NotBlank(message = "紧急联系人电话不能为空")
private String emergencyContactPhone;
/**
* 家庭地址
*/
@NotBlank(message = "家庭地址不能为空")
private String homeAddress;
/**
* 户口所在地
*/
@NotBlank(message = "户口所在地不能为空")
private String householdRegistrationAddress;
}
......@@ -91,6 +91,14 @@ public interface EmployeeInfoServ extends IService<EmployeeInfo> {
*/
Boolean insertByParam(EmployeeInfoParam param);
/**
* 新增基础员工信息
*
* @param param 员工信息
* @return 是否新增成功
*/
Boolean insertBaseInfoForH5(EmployeeBaseInfoParam param);
/**
* 修改员工信息
*
......
......@@ -7,6 +7,7 @@ import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.cola.dto.PageResponse;
import com.anplus.hr.config.EmployeeInfoCalcUtils;
import com.anplus.hr.constant.EmployeeChangeLogTypeConstant;
import com.anplus.hr.constant.HrFlowEnum;
import com.anplus.hr.constant.HrFlowTypeConstant;
......@@ -294,6 +295,7 @@ public class EmployeeFlowServImpl extends ServiceImpl<EmployeeFlowMapper, Employ
// 入职流程结束
employeeInfo.setEntryApplyStatus(HrFlowEnum.FINISH.getStatus());
employeeInfo.setStatus(HrStatusEnum.ENTRY.getStatus());
EmployeeInfoCalcUtils.calcExpectedRegularDate(employeeInfo);
for (SysAuditLog auditLog : auditLogs) {
if ("entryDate".equals(auditLog.getAuditField())) {
employeeInfo.setEntryDate(LocalDateTimeUtil.parseDate(auditLog.getAfterVal(), DatePattern.NORM_DATE_PATTERN));
......
......@@ -8,8 +8,11 @@ import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.cola.dto.PageResponse;
import com.alibaba.cola.dto.Response;
import com.anplus.hr.config.SeniorityUtils;
import com.anplus.hr.constant.*;
import com.anplus.hr.config.EmployeeInfoCalcUtils;
import com.anplus.hr.constant.HrEmployeeConstants;
import com.anplus.hr.constant.HrFlowEnum;
import com.anplus.hr.constant.HrFlowTypeConstant;
import com.anplus.hr.constant.HrStatusEnum;
import com.anplus.hr.domain.EmployeeInfo;
import com.anplus.hr.domain.params.*;
import com.anplus.hr.domain.vo.EmployeeInfoImportVo;
......@@ -29,12 +32,9 @@ import com.baomidou.mybatisplus.extension.toolkit.SqlHelper;
import lombok.RequiredArgsConstructor;
import org.dromara.trans.service.impl.TransService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
import top.binfast.app.biz.sysapi.bean.model.auth.SysDept;
import top.binfast.app.biz.sysapi.bean.model.oss.SysOss;
import top.binfast.app.biz.sysapi.dao.system.SysOssMapper;
import top.binfast.common.core.constant.NormalStatus;
import top.binfast.common.core.enums.ResultCode;
import top.binfast.common.core.exception.PlatformException;
import top.binfast.common.core.util.LambdaUtil;
......@@ -271,7 +271,7 @@ public class EmployeeInfoServImpl extends ServiceImpl<EmployeeInfoMapper, Employ
employeeInfo.setPartDeptId(partDeptId);
employeeInfo.setStatus(HrEmployeeConstants.EMPLOYEE_TYPE_REGULAR.equals(employeeInfo.getEmployeeType())
? HrStatusEnum.REGULARIZATION.getStatus() : HrStatusEnum.ENTRY.getStatus());
calcExpectedRegularDate(employeeInfo);
EmployeeInfoCalcUtils.calcExpectedRegularDate(employeeInfo);
if (sysOss != null) {
ossList.add(sysOss);
ossEmployeeInfoMap.put(sysOss.getFileName(), employeeInfo);
......@@ -401,36 +401,12 @@ public class EmployeeInfoServImpl extends ServiceImpl<EmployeeInfoMapper, Employ
}
private void initDefaultEmployeeInfo(EmployeeInfo employeeInfo) {
calcExpectedRegularDate(employeeInfo);
// 计算预计转正时间
EmployeeInfoCalcUtils.calcExpectedRegularDate(employeeInfo);
// 更新员工年龄组
if (employeeInfo.getAge() != null) {
HrAgeGroupEnum ageGroupEnum = HrAgeGroupEnum.getByAge(employeeInfo.getAge());
if (ageGroupEnum != null) {
employeeInfo.setAgeGroup(ageGroupEnum.getCode());
}
}
if (employeeInfo.getEntryDate() != null) {
int newTotalMonths = SeniorityUtils.calculateTotalMonths(employeeInfo.getEntryDate());
employeeInfo.setYearsOfServiceMonths(newTotalMonths);
employeeInfo.setYearsOfService(SeniorityUtils.formatMonthsToSeniority(newTotalMonths));
// 更新员工工龄组
HrYearsOfServiceSegmentEnum yearsOfServiceSegmentEnum = HrYearsOfServiceSegmentEnum.getByTotalMonths(newTotalMonths);
if (yearsOfServiceSegmentEnum != null) {
employeeInfo.setYearsOfServiceSegment(yearsOfServiceSegmentEnum.getCode());
}
}
}
/**
* 计算预计转正时间
*/
private void calcExpectedRegularDate(EmployeeInfo employeeInfo) {
if (HrEmployeeConstants.EMPLOYEE_TYPE_REGULAR.equals(employeeInfo.getEmployeeType())) {
return;
}
if (employeeInfo.getEntryDate() != null && employeeInfo.getProbationPeriod() != null) {
employeeInfo.setExpectedRegularDate(employeeInfo.getEntryDate().plusMonths(employeeInfo.getProbationPeriod()));
}
EmployeeInfoCalcUtils.calcAgeGroup(employeeInfo);
// 计算员工工龄
EmployeeInfoCalcUtils.calcYearsOfService(employeeInfo);
}
/**
......@@ -442,9 +418,20 @@ public class EmployeeInfoServImpl extends ServiceImpl<EmployeeInfoMapper, Employ
@Override
public Boolean updateByParam(EmployeeInfoParam param) {
EmployeeInfo employeeInfo = MapstructUtils.convert(param, EmployeeInfo.class);
EmployeeInfoCalcUtils.calcYearsOfService(employeeInfo);
return this.updateById(employeeInfo);
}
@Override
public Boolean insertBaseInfoForH5(EmployeeBaseInfoParam param) {
EmployeeInfo employeeInfo = MapstructUtils.convert(param, EmployeeInfo.class);
// 更新员工年龄组
EmployeeInfoCalcUtils.calcAgeGroup(employeeInfo);
employeeInfo.setEntryApplyStatus(HrFlowEnum.DRAFT.getStatus());
employeeInfo.setStatus(HrStatusEnum.DRAFT.getStatus());
return this.save(employeeInfo);
}
/**
* 保存前的数据校验
*/
......
package com.anplus.hr.service.impl;
import cn.hutool.core.date.LocalDateTimeUtil;
import com.anplus.hr.config.SeniorityUtils;
import com.anplus.hr.constant.HrAgeGroupEnum;
import com.anplus.hr.config.EmployeeInfoCalcUtils;
import com.anplus.hr.constant.HrFlowEnum;
import com.anplus.hr.constant.HrStatusEnum;
import com.anplus.hr.constant.HrYearsOfServiceSegmentEnum;
import com.anplus.hr.domain.EmployeeInfo;
import com.anplus.hr.mapper.EmployeeInfoMapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
......@@ -16,8 +13,6 @@ import top.binfast.common.sse.dto.SseMessageDto;
import top.binfast.common.sse.utils.SseMessageUtils;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.Period;
import java.util.ArrayList;
import java.util.List;
......@@ -48,7 +43,14 @@ public class EmployeeScheduleService {
*/
// @Scheduled(cron = "0 10 8 15,16,17,18,19,20 * ?")
public void monthlyTask() {
// TODO: 实现每月任务逻辑
executeSafely("每月检查提醒", this::remindPerMonth);
}
/**
* 每月15到20号号8点10分执行
*/
private void remindPerMonth() {
// 实现每月任务逻辑
boolean existNewRegularReminders = employeeInfoMapper.exists(new LambdaUpdateWrapper<EmployeeInfo>()
.eq(EmployeeInfo::getStatus, HrStatusEnum.ENTRY.getStatus())
.between(EmployeeInfo::getExpectedRegularDate, LocalDate.now(), LocalDate.now().plusMonths(1))
......@@ -56,7 +58,7 @@ public class EmployeeScheduleService {
if (existNewRegularReminders) {
SseMessageDto dto = new SseMessageDto();
dto.setMessage("有新的转正提醒!请检查!");
dto.setUserIds(List.of(1L));
dto.setUserIds(List.of(6L));
SseMessageUtils.publishMessage(dto);
}
boolean existContractRenewalReminders = employeeInfoMapper.exists(new LambdaUpdateWrapper<EmployeeInfo>()
......@@ -66,7 +68,7 @@ public class EmployeeScheduleService {
if (existContractRenewalReminders) {
SseMessageDto dto = new SseMessageDto();
dto.setMessage("有新的合同续约提醒!请检查!");
dto.setUserIds(List.of(1L));
dto.setUserIds(List.of(6L));
SseMessageUtils.publishMessage(dto);
}
}
......@@ -80,21 +82,8 @@ public class EmployeeScheduleService {
.ne(EmployeeInfo::getResignationApplyStatus, HrFlowEnum.FINISH.getStatus()));
List<EmployeeInfo> updateList = new ArrayList<>();
for (EmployeeInfo employeeInfo : employeeInfos) {
boolean isUpdate = false;
if (employeeInfo.getEntryDate() != null) {
int newTotalMonths = SeniorityUtils.calculateTotalMonths(employeeInfo.getEntryDate());
if (employeeInfo.getYearsOfServiceMonths() == null || employeeInfo.getYearsOfServiceMonths() != newTotalMonths) {
isUpdate = true;
employeeInfo.setYearsOfServiceMonths(newTotalMonths);
employeeInfo.setYearsOfService(SeniorityUtils.formatMonthsToSeniority(newTotalMonths));
// 更新员工工龄组
HrYearsOfServiceSegmentEnum yearsOfServiceSegmentEnum = HrYearsOfServiceSegmentEnum.getByTotalMonths(newTotalMonths);
if (yearsOfServiceSegmentEnum != null) {
employeeInfo.setYearsOfServiceSegment(yearsOfServiceSegmentEnum.getCode());
}
}
}
isUpdate = isUpdate || precessRefreshAge(employeeInfo);
boolean isUpdate = EmployeeInfoCalcUtils.calcYearsOfService(employeeInfo);
isUpdate = isUpdate || EmployeeInfoCalcUtils.calcAgeGroup(employeeInfo);
if (isUpdate) {
updateList.add(employeeInfo);
}
......@@ -102,24 +91,6 @@ public class EmployeeScheduleService {
employeeInfoMapper.updateById(updateList);
}
private boolean precessRefreshAge(EmployeeInfo employeeInfo) {
boolean isUpdate = false;
if (employeeInfo.getBirthDate() == null) {
return false;
}
Period period = LocalDateTimeUtil.betweenPeriod(employeeInfo.getBirthDate(), LocalDate.from(LocalDateTime.now()));
int years = period.getYears();
if (employeeInfo.getAge() == null || employeeInfo.getAge() != years) {
isUpdate = true;
employeeInfo.setAge(years);
// 更新员工年龄组
HrAgeGroupEnum ageGroupEnum = HrAgeGroupEnum.getByAge(years);
if (ageGroupEnum != null) {
employeeInfo.setAgeGroup(ageGroupEnum.getCode());
}
}
return isUpdate;
}
/**
* 安全执行方法,包含异常处理
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment