diff --git a/src/main/java/cn/lihongjie/coal/common/Batch.java b/src/main/java/cn/lihongjie/coal/common/Batch.java new file mode 100644 index 00000000..d9de4b6e --- /dev/null +++ b/src/main/java/cn/lihongjie/coal/common/Batch.java @@ -0,0 +1,20 @@ +package cn.lihongjie.coal.common; + +import lombok.Data; + +import java.util.*; + +@Data +public class Batch { + + private List data; + + private Map extra; + + public Object getOrDefault(String key, Object defaultValue) { + if (extra == null) { + return defaultValue; + } + return extra.getOrDefault(key, defaultValue); + } +} diff --git a/src/main/java/cn/lihongjie/coal/common/DictCode.java b/src/main/java/cn/lihongjie/coal/common/DictCode.java index d15e12f2..3c9ca615 100644 --- a/src/main/java/cn/lihongjie/coal/common/DictCode.java +++ b/src/main/java/cn/lihongjie/coal/common/DictCode.java @@ -12,6 +12,9 @@ public class DictCode { public static final String APPOINTMENT_STATUS = "appointment.status"; + public static final String EMP_SALARY_ITEM_DECIMALPLACESHANDLER = + "emp.salary.item.decimalPlacesHandler"; + public static final String EMP_SALARY_SYSITEM_TYPE = "emp.salary.sysItem.type"; public static final String PURCHASEORDER_STATUS = "purchaseOrder.status"; diff --git a/src/main/java/cn/lihongjie/coal/empMonthAttendance/controller/EmpMonthAttendanceController.java b/src/main/java/cn/lihongjie/coal/empMonthAttendance/controller/EmpMonthAttendanceController.java index db35c0dd..4fc296fe 100644 --- a/src/main/java/cn/lihongjie/coal/empMonthAttendance/controller/EmpMonthAttendanceController.java +++ b/src/main/java/cn/lihongjie/coal/empMonthAttendance/controller/EmpMonthAttendanceController.java @@ -4,6 +4,7 @@ import cn.lihongjie.coal.annotation.OrgScope; import cn.lihongjie.coal.annotation.SysLog; import cn.lihongjie.coal.base.dto.CommonQuery; import cn.lihongjie.coal.base.dto.IdRequest; +import cn.lihongjie.coal.common.Batch; import cn.lihongjie.coal.empMonthAttendance.dto.CreateEmpMonthAttendanceDto; import cn.lihongjie.coal.empMonthAttendance.dto.EmpMonthAttendanceDto; import cn.lihongjie.coal.empMonthAttendance.dto.UpdateEmpMonthAttendanceDto; @@ -42,6 +43,12 @@ public class EmpMonthAttendanceController { return true; } + @PostMapping("/batchUpdate") + public Object batchUpdate(@RequestBody Batch request) { + this.service.batchUpdate(request); + return true; + } + @PostMapping("/getById") public EmpMonthAttendanceDto getById(@RequestBody IdRequest request) { return this.service.getById(request.getId()); diff --git a/src/main/java/cn/lihongjie/coal/empMonthAttendance/entity/EmpMonthAttendanceEntity.java b/src/main/java/cn/lihongjie/coal/empMonthAttendance/entity/EmpMonthAttendanceEntity.java index e36736bd..523296cb 100644 --- a/src/main/java/cn/lihongjie/coal/empMonthAttendance/entity/EmpMonthAttendanceEntity.java +++ b/src/main/java/cn/lihongjie/coal/empMonthAttendance/entity/EmpMonthAttendanceEntity.java @@ -17,59 +17,36 @@ import java.time.LocalDate; @Entity public class EmpMonthAttendanceEntity extends OrgCommonEntity { - - @ManyToOne - private EmployeeEntity employee; - - + @ManyToOne private EmployeeEntity employee; @Comment("年月") private LocalDate yearMonth; - - @Comment("是否全勤") private Boolean fullAttendance; - @Comment("是否满勤") private Boolean fullWork; - - @Comment("应出勤天数") private Double shouldAttendanceDays; - @Comment("实际出勤天数") private Double actualAttendanceDays; - @Comment("加班天数") private Double overtimeDays; - @Comment("请假天数") private Double leaveDays; - - - - /** - * 后面这些不重要,放到最后 - */ - - - - + /** 后面这些不重要,放到最后 */ @Comment("事假天数") private Double personalLeaveDays; - @Comment("病假天数") private Double sickLeaveDays; - @Comment("婚假天数") private Double marriageLeaveDays; @@ -85,38 +62,113 @@ public class EmpMonthAttendanceEntity extends OrgCommonEntity { @Comment("年假天数") private Double annualLeaveDays; - - - - - - @Comment("迟到次数") private Integer lateTimes; @Comment("迟到分钟数") private Integer lateMinutes; - @Comment("早退次数") private Integer earlyTimes; @Comment("早退分钟数") private Integer earlyMinutes; - @Comment("旷工次数") private Integer absenteeismTimes; - - - - - - - - @Comment("归档状态") @ColumnDefault("'0'") private String archiveStatus = "0"; + + @Override + public void prePersist() { + super.prePersist(); + this.setDefaultVal(); + } + + @Override + public void preUpdate() { + super.preUpdate(); + this.setDefaultVal(); + } + + public void setDefaultVal() { + + if (this.yearMonth != null) { + this.yearMonth = LocalDate.of(this.yearMonth.getYear(), this.yearMonth.getMonth(), 1); + } + + if (this.fullAttendance == null) { + this.fullAttendance = false; + } + + if (this.fullWork == null) { + this.fullWork = false; + } + + if (this.shouldAttendanceDays == null) { + this.shouldAttendanceDays = 0.0; + } + + if (this.actualAttendanceDays == null) { + this.actualAttendanceDays = 0.0; + } + + if (this.overtimeDays == null) { + this.overtimeDays = 0.0; + } + + if (this.leaveDays == null) { + this.leaveDays = 0.0; + } + + if (this.personalLeaveDays == null) { + this.personalLeaveDays = 0.0; + } + + if (this.sickLeaveDays == null) { + this.sickLeaveDays = 0.0; + } + + if (this.marriageLeaveDays == null) { + this.marriageLeaveDays = 0.0; + } + + if (this.maternityLeaveDays == null) { + this.maternityLeaveDays = 0.0; + } + + if (this.paternityLeaveDays == null) { + this.paternityLeaveDays = 0.0; + } + + if (this.funeralLeaveDays == null) { + this.funeralLeaveDays = 0.0; + } + + if (this.annualLeaveDays == null) { + this.annualLeaveDays = 0.0; + } + + if (this.lateTimes == null) { + this.lateTimes = 0; + } + + if (this.lateMinutes == null) { + this.lateMinutes = 0; + } + + if (this.earlyTimes == null) { + this.earlyTimes = 0; + } + + if (this.earlyMinutes == null) { + this.earlyMinutes = 0; + } + + if (this.absenteeismTimes == null) { + this.absenteeismTimes = 0; + } + } } diff --git a/src/main/java/cn/lihongjie/coal/empMonthAttendance/mapper/EmpMonthAttendanceMapper.java b/src/main/java/cn/lihongjie/coal/empMonthAttendance/mapper/EmpMonthAttendanceMapper.java index 77b9c035..4198b4a6 100644 --- a/src/main/java/cn/lihongjie/coal/empMonthAttendance/mapper/EmpMonthAttendanceMapper.java +++ b/src/main/java/cn/lihongjie/coal/empMonthAttendance/mapper/EmpMonthAttendanceMapper.java @@ -20,4 +20,6 @@ public interface EmpMonthAttendanceMapper EmpMonthAttendanceEntity, EmpMonthAttendanceDto, CreateEmpMonthAttendanceDto, - UpdateEmpMonthAttendanceDto> {} + UpdateEmpMonthAttendanceDto> { + CreateEmpMonthAttendanceDto toCreateDto(UpdateEmpMonthAttendanceDto dto); +} diff --git a/src/main/java/cn/lihongjie/coal/empMonthAttendance/service/EmpMonthAttendanceService.java b/src/main/java/cn/lihongjie/coal/empMonthAttendance/service/EmpMonthAttendanceService.java index ad21a56d..d4ccc214 100644 --- a/src/main/java/cn/lihongjie/coal/empMonthAttendance/service/EmpMonthAttendanceService.java +++ b/src/main/java/cn/lihongjie/coal/empMonthAttendance/service/EmpMonthAttendanceService.java @@ -3,6 +3,7 @@ package cn.lihongjie.coal.empMonthAttendance.service; import cn.lihongjie.coal.base.dto.CommonQuery; import cn.lihongjie.coal.base.dto.IdRequest; import cn.lihongjie.coal.base.service.BaseService; +import cn.lihongjie.coal.common.Batch; import cn.lihongjie.coal.dbFunctions.DbFunctionService; import cn.lihongjie.coal.empMonthAttendance.dto.CreateEmpMonthAttendanceDto; import cn.lihongjie.coal.empMonthAttendance.dto.EmpMonthAttendanceDto; @@ -10,10 +11,15 @@ import cn.lihongjie.coal.empMonthAttendance.dto.UpdateEmpMonthAttendanceDto; import cn.lihongjie.coal.empMonthAttendance.entity.EmpMonthAttendanceEntity; import cn.lihongjie.coal.empMonthAttendance.mapper.EmpMonthAttendanceMapper; import cn.lihongjie.coal.empMonthAttendance.repository.EmpMonthAttendanceRepository; +import cn.lihongjie.coal.employee.service.EmployeeService; import cn.lihongjie.coal.exception.BizException; +import jakarta.persistence.EntityManager; +import jakarta.persistence.PersistenceContext; + import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.convert.ConversionService; import org.springframework.data.domain.Page; @@ -35,18 +41,62 @@ public class EmpMonthAttendanceService @Autowired private DbFunctionService dbFunctionService; + @PersistenceContext EntityManager em; + @Autowired + private EmployeeService employeeService; + public EmpMonthAttendanceDto create(CreateEmpMonthAttendanceDto request) { EmpMonthAttendanceEntity entity = mapper.toEntity(request); + Long cnt = + em.createQuery( + "select count(*) from EmpMonthAttendanceEntity where employee.id = :employeeId and yearMonth = :yearMonth", + Long.class) + .setParameter("employeeId", entity.getEmployee().getId()) + .setParameter("yearMonth", entity.getYearMonth()) + .getSingleResult(); + + if (cnt > 0) { + throw new BizException(String.format("员工 %s %s月 考勤数据已存在", employeeService.get(request.getEmployee()).getName(), request.getYearMonth().getMonth())); + } + this.repository.save(entity); + return getById(entity.getId()); } + public void batchUpdate(Batch request) { + + for (UpdateEmpMonthAttendanceDto dto : request.getData()) { + + if (StringUtils.isNotEmpty(dto.getId())) { + update(dto); + } else { + + create(this.mapper.toCreateDto(dto)); + } + } + } + public EmpMonthAttendanceDto update(UpdateEmpMonthAttendanceDto request) { EmpMonthAttendanceEntity entity = this.repository.get(request.getId()); if (this.repository.containArchived(request.getId())) { throw new BizException("部分数据已归档,无法编辑或删除"); } + + Long cnt = + em.createQuery( + "select count(*) from EmpMonthAttendanceEntity where employee.id = :employeeId and yearMonth = :yearMonth and id != :id", + Long.class) + .setParameter("employeeId", request.getEmployee()) + .setParameter("yearMonth", request.getYearMonth()) + .setParameter("id", request.getId()) + .getSingleResult(); + + if (cnt > 0) { + throw new BizException(String.format("员工 %s %s月 考勤数据已存在", employeeService.get(request.getEmployee()).getName(), request.getYearMonth().getMonth())); + } + this.mapper.updateEntity(entity, request); this.repository.save(entity); diff --git a/src/main/java/cn/lihongjie/coal/empSalaryItem/dto/CreateEmpSalaryItemDto.java b/src/main/java/cn/lihongjie/coal/empSalaryItem/dto/CreateEmpSalaryItemDto.java index a6274346..87d03d91 100644 --- a/src/main/java/cn/lihongjie/coal/empSalaryItem/dto/CreateEmpSalaryItemDto.java +++ b/src/main/java/cn/lihongjie/coal/empSalaryItem/dto/CreateEmpSalaryItemDto.java @@ -35,5 +35,12 @@ public class CreateEmpSalaryItemDto extends OrgCommonDto { private String formulaShow; + @Comment("保留小数位") + private Integer decimalPlaces; + + + @Comment("小数位处理方式 0-四舍五入 1-截断 2-进位") + private String decimalPlacesHandler; + } diff --git a/src/main/java/cn/lihongjie/coal/empSalaryItem/dto/EmpSalaryItemDto.java b/src/main/java/cn/lihongjie/coal/empSalaryItem/dto/EmpSalaryItemDto.java index 80efe8b9..a8e908c8 100644 --- a/src/main/java/cn/lihongjie/coal/empSalaryItem/dto/EmpSalaryItemDto.java +++ b/src/main/java/cn/lihongjie/coal/empSalaryItem/dto/EmpSalaryItemDto.java @@ -48,4 +48,18 @@ public class EmpSalaryItemDto extends OrgCommonDto { @Comment("优先级") private Integer priority; + + + + @Comment("保留小数位") + private Integer decimalPlaces; + + + @Comment("小数位处理方式 0-四舍五入 1-截断 2-进位") + private String decimalPlacesHandler; + + @DictTranslate(dictKey = DictCode.EMP_SALARY_ITEM_DECIMALPLACESHANDLER) + private String decimalPlacesHandlerName; + + } diff --git a/src/main/java/cn/lihongjie/coal/empSalaryItem/dto/UpdateEmpSalaryItemDto.java b/src/main/java/cn/lihongjie/coal/empSalaryItem/dto/UpdateEmpSalaryItemDto.java index 383e00b3..58c07d62 100644 --- a/src/main/java/cn/lihongjie/coal/empSalaryItem/dto/UpdateEmpSalaryItemDto.java +++ b/src/main/java/cn/lihongjie/coal/empSalaryItem/dto/UpdateEmpSalaryItemDto.java @@ -43,5 +43,13 @@ public class UpdateEmpSalaryItemDto extends OrgCommonDto { private String formulaShow; + @Comment("保留小数位") + private Integer decimalPlaces; + + + @Comment("小数位处理方式 0-四舍五入 1-截断 2-进位") + private String decimalPlacesHandler; + + } diff --git a/src/main/java/cn/lihongjie/coal/empSalaryItem/entity/EmpSalaryItemEntity.java b/src/main/java/cn/lihongjie/coal/empSalaryItem/entity/EmpSalaryItemEntity.java index 206a8aee..c55573e9 100644 --- a/src/main/java/cn/lihongjie/coal/empSalaryItem/entity/EmpSalaryItemEntity.java +++ b/src/main/java/cn/lihongjie/coal/empSalaryItem/entity/EmpSalaryItemEntity.java @@ -54,4 +54,13 @@ public class EmpSalaryItemEntity extends OrgCommonEntity { private Boolean systemPreset; + + + + @Comment("保留小数位") + private Integer decimalPlaces; + + + @Comment("小数位处理方式 0-四舍五入 1-截断 2-进位") + private String decimalPlacesHandler; } diff --git a/src/main/java/cn/lihongjie/coal/employee/repository/EmployeeRepository.java b/src/main/java/cn/lihongjie/coal/employee/repository/EmployeeRepository.java index dbf3d393..838c4796 100644 --- a/src/main/java/cn/lihongjie/coal/employee/repository/EmployeeRepository.java +++ b/src/main/java/cn/lihongjie/coal/employee/repository/EmployeeRepository.java @@ -12,6 +12,6 @@ import java.util.List; @Repository public interface EmployeeRepository extends BaseRepository { - @Query("select exists(select 1 from EmployeeRecordEntity e where e.employee.id in :ids)") + @Query("select exists(select 1 from EmployeeRecordEntity e where e.employee.id in :ids union all select 1 from EmpMonthAttendanceEntity e where e.employee.id in :ids union all select 1 from EmpSalaryEntity e where e.employee.id in :ids)") boolean isLinked(@Param("ids") List ids); } diff --git a/src/main/resources/config/dictionary.json b/src/main/resources/config/dictionary.json index b3439f89..79046e25 100644 --- a/src/main/resources/config/dictionary.json +++ b/src/main/resources/config/dictionary.json @@ -1713,11 +1713,26 @@ "code": "2", "name": "已过期" } - ] }, - - + { + "code": "emp.salary.item.decimalPlacesHandler", + "name": "工资项目小数位处理方式", + "item": [ + { + "code": "0", + "name": "四舍五入" + }, + { + "code": "1", + "name": "截断" + }, + { + "code": "2", + "name": "进位" + } + ] + }, { "code": "emp.salary.sysItem.type", "name": "工资系统项目类型", @@ -1734,10 +1749,8 @@ "code": "2", "name": "函数" } - ] }, - { "code": "purchaseOrder.status", "name": "采购订单状态", @@ -2134,7 +2147,6 @@ } ] }, - { "code": "device.category.deviceCodeGenRule", "name": "设备编码生成规则", @@ -2157,7 +2169,6 @@ } ] }, - { "code": "device.status", "name": "设备状态",