添加批量接口

This commit is contained in:
2024-08-03 15:59:02 +08:00
parent 82e705e339
commit b4a153afe3
12 changed files with 233 additions and 50 deletions

View File

@@ -0,0 +1,20 @@
package cn.lihongjie.coal.common;
import lombok.Data;
import java.util.*;
@Data
public class Batch<T> {
private List<T> data;
private Map<String, Object> extra;
public Object getOrDefault(String key, Object defaultValue) {
if (extra == null) {
return defaultValue;
}
return extra.getOrDefault(key, defaultValue);
}
}

View File

@@ -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";

View File

@@ -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<UpdateEmpMonthAttendanceDto> request) {
this.service.batchUpdate(request);
return true;
}
@PostMapping("/getById")
public EmpMonthAttendanceDto getById(@RequestBody IdRequest request) {
return this.service.getById(request.getId());

View File

@@ -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;
}
}
}

View File

@@ -20,4 +20,6 @@ public interface EmpMonthAttendanceMapper
EmpMonthAttendanceEntity,
EmpMonthAttendanceDto,
CreateEmpMonthAttendanceDto,
UpdateEmpMonthAttendanceDto> {}
UpdateEmpMonthAttendanceDto> {
CreateEmpMonthAttendanceDto toCreateDto(UpdateEmpMonthAttendanceDto dto);
}

View File

@@ -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<UpdateEmpMonthAttendanceDto> 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);

View File

@@ -35,5 +35,12 @@ public class CreateEmpSalaryItemDto extends OrgCommonDto {
private String formulaShow;
@Comment("保留小数位")
private Integer decimalPlaces;
@Comment("小数位处理方式 0-四舍五入 1-截断 2-进位")
private String decimalPlacesHandler;
}

View File

@@ -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;
}

View File

@@ -43,5 +43,13 @@ public class UpdateEmpSalaryItemDto extends OrgCommonDto {
private String formulaShow;
@Comment("保留小数位")
private Integer decimalPlaces;
@Comment("小数位处理方式 0-四舍五入 1-截断 2-进位")
private String decimalPlacesHandler;
}

View File

@@ -54,4 +54,13 @@ public class EmpSalaryItemEntity extends OrgCommonEntity {
private Boolean systemPreset;
@Comment("保留小数位")
private Integer decimalPlaces;
@Comment("小数位处理方式 0-四舍五入 1-截断 2-进位")
private String decimalPlacesHandler;
}

View File

@@ -12,6 +12,6 @@ import java.util.List;
@Repository
public interface EmployeeRepository extends BaseRepository<EmployeeEntity> {
@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<String> ids);
}

View File

@@ -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": "设备状态",