添加员工月度考勤汇总表

This commit is contained in:
2024-08-02 09:05:19 +08:00
parent 0f543b804c
commit 97cc9002ce
15 changed files with 802 additions and 3 deletions

View File

@@ -0,0 +1,66 @@
package cn.lihongjie.coal.empMonthAttendance.controller;
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.empMonthAttendance.dto.CreateEmpMonthAttendanceDto;
import cn.lihongjie.coal.empMonthAttendance.dto.EmpMonthAttendanceDto;
import cn.lihongjie.coal.empMonthAttendance.dto.UpdateEmpMonthAttendanceDto;
import cn.lihongjie.coal.empMonthAttendance.service.EmpMonthAttendanceService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
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;
@RestController
@RequestMapping("/empMonthAttendance")
@SysLog(module = "员工月度考勤汇总表")
@Slf4j
@OrgScope
public class EmpMonthAttendanceController {
@Autowired private EmpMonthAttendanceService service;
@PostMapping("/create")
public EmpMonthAttendanceDto create(@RequestBody CreateEmpMonthAttendanceDto request) {
return this.service.create(request);
}
@PostMapping("/update")
public EmpMonthAttendanceDto update(@RequestBody UpdateEmpMonthAttendanceDto request) {
return this.service.update(request);
}
@PostMapping("/delete")
public Object delete(@RequestBody IdRequest request) {
this.service.delete(request);
return true;
}
@PostMapping("/getById")
public EmpMonthAttendanceDto getById(@RequestBody IdRequest request) {
return this.service.getById(request.getId());
}
@PostMapping("/list")
public Page<EmpMonthAttendanceDto> list(@RequestBody CommonQuery request) {
return this.service.list(request);
}
@PostMapping("/archive")
public Object archive(@RequestBody IdRequest request) {
this.service.archive(request);
return true;
}
@PostMapping("/unarchive")
public Object unarchive(@RequestBody IdRequest request) {
this.service.unarchive(request);
return true;
}
}

View File

@@ -0,0 +1,105 @@
package cn.lihongjie.coal.empMonthAttendance.dto;
import cn.lihongjie.coal.base.dto.OrgCommonDto;
import jakarta.persistence.ManyToOne;
import lombok.Data;
import org.hibernate.annotations.Comment;
import java.time.LocalDate;
@Data
public class CreateEmpMonthAttendanceDto extends OrgCommonDto {
@ManyToOne
private String 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;
@Comment("产假天数")
private Double maternityLeaveDays;
@Comment("陪产假天数")
private Double paternityLeaveDays;
@Comment("丧假天数")
private Double funeralLeaveDays;
@Comment("年假天数")
private Double annualLeaveDays;
@Comment("迟到次数")
private Integer lateTimes;
@Comment("迟到分钟数")
private Integer lateMinutes;
@Comment("早退次数")
private Integer earlyTimes;
@Comment("早退分钟数")
private Integer earlyMinutes;
@Comment("旷工次数")
private Integer absenteeismTimes;
}

View File

@@ -0,0 +1,114 @@
package cn.lihongjie.coal.empMonthAttendance.dto;
import cn.lihongjie.coal.base.dto.OrgCommonDto;
import cn.lihongjie.coal.common.DictCode;
import cn.lihongjie.coal.employee.dto.EmployeeDto;
import cn.lihongjie.coal.pojoProcessor.DictTranslate;
import jakarta.persistence.ManyToOne;
import lombok.Data;
import org.hibernate.annotations.Comment;
import java.time.LocalDate;
@Data
public class EmpMonthAttendanceDto extends OrgCommonDto {
@ManyToOne
private EmployeeDto 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;
@Comment("产假天数")
private Double maternityLeaveDays;
@Comment("陪产假天数")
private Double paternityLeaveDays;
@Comment("丧假天数")
private Double funeralLeaveDays;
@Comment("年假天数")
private Double annualLeaveDays;
@Comment("迟到次数")
private Integer lateTimes;
@Comment("迟到分钟数")
private Integer lateMinutes;
@Comment("早退次数")
private Integer earlyTimes;
@Comment("早退分钟数")
private Integer earlyMinutes;
@Comment("旷工次数")
private Integer absenteeismTimes;
private String archiveStatus;
@DictTranslate(dictKey = DictCode.ARCHIVESTATUS)
private String archiveStatusName;
}

View File

@@ -0,0 +1,108 @@
package cn.lihongjie.coal.empMonthAttendance.dto;
import cn.lihongjie.coal.base.dto.OrgCommonDto;
import jakarta.persistence.ManyToOne;
import lombok.Data;
import org.hibernate.annotations.Comment;
import java.time.LocalDate;
@Data
public class UpdateEmpMonthAttendanceDto extends OrgCommonDto {
@ManyToOne
private String 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;
@Comment("产假天数")
private Double maternityLeaveDays;
@Comment("陪产假天数")
private Double paternityLeaveDays;
@Comment("丧假天数")
private Double funeralLeaveDays;
@Comment("年假天数")
private Double annualLeaveDays;
@Comment("迟到次数")
private Integer lateTimes;
@Comment("迟到分钟数")
private Integer lateMinutes;
@Comment("早退次数")
private Integer earlyTimes;
@Comment("早退分钟数")
private Integer earlyMinutes;
@Comment("旷工次数")
private Integer absenteeismTimes;
}

View File

@@ -0,0 +1,122 @@
package cn.lihongjie.coal.empMonthAttendance.entity;
import cn.lihongjie.coal.base.entity.OrgCommonEntity;
import cn.lihongjie.coal.employee.entity.EmployeeEntity;
import jakarta.persistence.Entity;
import jakarta.persistence.ManyToOne;
import lombok.Data;
import org.hibernate.annotations.ColumnDefault;
import org.hibernate.annotations.Comment;
import java.time.LocalDate;
@Data
@Entity
public class EmpMonthAttendanceEntity extends OrgCommonEntity {
@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;
@Comment("产假天数")
private Double maternityLeaveDays;
@Comment("陪产假天数")
private Double paternityLeaveDays;
@Comment("丧假天数")
private Double funeralLeaveDays;
@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";
}

View File

@@ -0,0 +1,23 @@
package cn.lihongjie.coal.empMonthAttendance.mapper;
import cn.lihongjie.coal.base.mapper.BaseMapper;
import cn.lihongjie.coal.base.mapper.CommonEntityMapper;
import cn.lihongjie.coal.base.mapper.CommonMapper;
import cn.lihongjie.coal.empMonthAttendance.dto.CreateEmpMonthAttendanceDto;
import cn.lihongjie.coal.empMonthAttendance.dto.EmpMonthAttendanceDto;
import cn.lihongjie.coal.empMonthAttendance.dto.UpdateEmpMonthAttendanceDto;
import cn.lihongjie.coal.empMonthAttendance.entity.EmpMonthAttendanceEntity;
import org.mapstruct.Mapper;
import org.mapstruct.control.DeepClone;
@Mapper(
componentModel = org.mapstruct.MappingConstants.ComponentModel.SPRING,
uses = {CommonMapper.class, CommonEntityMapper.class},
mappingControl = DeepClone.class)
public interface EmpMonthAttendanceMapper
extends BaseMapper<
EmpMonthAttendanceEntity,
EmpMonthAttendanceDto,
CreateEmpMonthAttendanceDto,
UpdateEmpMonthAttendanceDto> {}

View File

@@ -0,0 +1,15 @@
package cn.lihongjie.coal.empMonthAttendance.repository;
import cn.lihongjie.coal.base.dao.BaseRepository;
import cn.lihongjie.coal.empMonthAttendance.entity.EmpMonthAttendanceEntity;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import java.util.List;
@Repository
public interface EmpMonthAttendanceRepository extends BaseRepository<EmpMonthAttendanceEntity> {
@Query("select false")
boolean isLinked(List<String> ids);
}

View File

@@ -0,0 +1,94 @@
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.dbFunctions.DbFunctionService;
import cn.lihongjie.coal.empMonthAttendance.dto.CreateEmpMonthAttendanceDto;
import cn.lihongjie.coal.empMonthAttendance.dto.EmpMonthAttendanceDto;
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.exception.BizException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.convert.ConversionService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@Service
@Slf4j
@Transactional
public class EmpMonthAttendanceService
extends BaseService<EmpMonthAttendanceEntity, EmpMonthAttendanceRepository> {
@Autowired private EmpMonthAttendanceRepository repository;
@Autowired private EmpMonthAttendanceMapper mapper;
@Autowired private ConversionService conversionService;
@Autowired private DbFunctionService dbFunctionService;
public EmpMonthAttendanceDto create(CreateEmpMonthAttendanceDto request) {
EmpMonthAttendanceEntity entity = mapper.toEntity(request);
this.repository.save(entity);
return getById(entity.getId());
}
public EmpMonthAttendanceDto update(UpdateEmpMonthAttendanceDto request) {
EmpMonthAttendanceEntity entity = this.repository.get(request.getId());
if (this.repository.containArchived(request.getId())) {
throw new BizException("部分数据已归档,无法编辑或删除");
}
this.mapper.updateEntity(entity, request);
this.repository.save(entity);
return getById(entity.getId());
}
public void delete(IdRequest request) {
if (this.repository.containArchived(request)) {
throw new BizException("部分数据已归档,无法编辑或删除");
}
boolean linked = this.repository.isLinked(request.getIds());
if (linked) {
throw new BizException("数据已被关联,无法删除");
}
this.repository.deleteAllById(request.getIds());
}
public EmpMonthAttendanceDto getById(String id) {
EmpMonthAttendanceEntity entity = repository.get(id);
return mapper.toDto(entity);
}
public Page<EmpMonthAttendanceDto> list(CommonQuery query) {
Page<EmpMonthAttendanceEntity> page =
repository.findAll(
query.specification(conversionService),
PageRequest.of(
query.getPageNo(),
query.getPageSize(),
Sort.by(query.getOrders())));
return page.map(this.mapper::toDto);
}
public void archive(IdRequest dto) {
this.repository.archive(dto);
}
public void unarchive(IdRequest dto) {
this.repository.unArchive(dto);
}
}

View File

@@ -8,6 +8,7 @@ import org.hibernate.annotations.Comment;
@Data
public class CreateEmpSalaryItemDto extends OrgCommonDto {

View File

@@ -4,6 +4,8 @@ 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.Ctx;
import cn.lihongjie.coal.common.FreeMakerUtils;
import cn.lihongjie.coal.common.JpaUtils;
import cn.lihongjie.coal.empSalary.entity.EmpSalaryEntity;
import cn.lihongjie.coal.empSalaryBatch.entity.EmpSalaryBatchEntity;
import cn.lihongjie.coal.empSalaryItem.dto.CreateEmpSalaryItemDto;
@@ -21,6 +23,8 @@ import cn.lihongjie.coal.exception.BizException;
import groovy.lang.GroovyClassLoader;
import groovy.lang.Script;
import jakarta.persistence.EntityManager;
import jakarta.persistence.PersistenceContext;
import jakarta.persistence.criteria.CriteriaBuilder;
import jakarta.persistence.criteria.CriteriaQuery;
import jakarta.persistence.criteria.Predicate;
@@ -67,6 +71,54 @@ public class EmpSalaryItemService
@Autowired private EmpSalaryStandardService empSalaryStandardService;
@PersistenceContext EntityManager em;
public List<EmpSalaryItemEntity> findAllBy(String organizationId, List<String> dependOn, List<String> dependOnSysItem) {
Map<String, Object> params = Map.of("organizationId", organizationId, "dependOn", dependOn, "dependOnSysItem", dependOnSysItem);
List<String> ids = JpaUtils.execNativeQuery(
em,
FreeMakerUtils.render(
"""
select * from t_emp_salary_item
<@where>
<#if organizationId??>
AND organization_id = :organizationId
</#if>
<#if dependOn?? && !dependOnSysItem??>
AND depend_on @> ARRAY[:dependOn]
</#if>
<#if dependOnSysItem?? && !dependOn??>
AND depend_on_sys_item @> ARRAY[:dependOnSysItem]
</#if>
<#if dependOn?? && dependOnSysItem??>
AND (depend_on @> ARRAY[:dependOn] or depend_on_sys_item @> ARRAY[:dependOnSysItem])
</#if>
</@where>
""",
params),
params,
String.class);
return findAllByIds(ids);
}
private void updatePriority(List<EmpSalaryItemEntity> enabled) {
DefaultDirectedGraph<String, DefaultEdge> graph =
new DefaultDirectedGraph<>(DefaultEdge.class);

View File

@@ -1,12 +1,21 @@
package cn.lihongjie.coal.empSalarySysItem.dto;
import cn.lihongjie.coal.base.dto.CommonDto;
import cn.lihongjie.coal.empSalarySysItem.entity.EmpSalarySysItemEntity;
import cn.lihongjie.coal.errorMsg.ErrorMsgCode;
import cn.lihongjie.coal.validator.RequireCode;
import cn.lihongjie.coal.validator.RequireName;
import cn.lihongjie.coal.validator.Uniq;
import lombok.Data;
import org.hibernate.annotations.Comment;
@Data
@RequireName
@RequireCode
@Uniq(fields = {"code"}, message = ErrorMsgCode.UNIQ_CODE, entityClass = EmpSalarySysItemEntity.class)
@Uniq(fields = {"name"}, message = ErrorMsgCode.UNIQ_NAME, entityClass = EmpSalarySysItemEntity.class)
public class CreateEmpSalarySysItemDto extends CommonDto {

View File

@@ -1,12 +1,21 @@
package cn.lihongjie.coal.empSalarySysItem.dto;
import cn.lihongjie.coal.base.dto.CommonDto;
import cn.lihongjie.coal.empSalarySysItem.entity.EmpSalarySysItemEntity;
import cn.lihongjie.coal.errorMsg.ErrorMsgCode;
import cn.lihongjie.coal.validator.RequireCode;
import cn.lihongjie.coal.validator.RequireName;
import cn.lihongjie.coal.validator.Uniq;
import lombok.Data;
import org.hibernate.annotations.Comment;
@Data
@RequireName
@RequireCode
@Uniq(fields = {"code"}, message = ErrorMsgCode.UNIQ_CODE, entityClass = EmpSalarySysItemEntity.class)
@Uniq(fields = {"name"}, message = ErrorMsgCode.UNIQ_NAME, entityClass = EmpSalarySysItemEntity.class)
public class UpdateEmpSalarySysItemDto extends CommonDto {

View File

@@ -4,6 +4,8 @@ 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.dbFunctions.DbFunctionService;
import cn.lihongjie.coal.empSalaryItem.entity.EmpSalaryItemEntity;
import cn.lihongjie.coal.empSalaryItem.service.EmpSalaryItemService;
import cn.lihongjie.coal.empSalarySysItem.dto.CreateEmpSalarySysItemDto;
import cn.lihongjie.coal.empSalarySysItem.dto.EmpSalarySysItemDto;
import cn.lihongjie.coal.empSalarySysItem.dto.UpdateEmpSalarySysItemDto;
@@ -14,6 +16,8 @@ import cn.lihongjie.coal.exception.BizException;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.convert.ConversionService;
import org.springframework.data.domain.Page;
@@ -22,6 +26,10 @@ import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
@Service
@Slf4j
@Transactional
@@ -42,8 +50,43 @@ public class EmpSalarySysItemService
return getById(entity.getId());
}
@Autowired EmpSalaryItemService empSalaryItemService;
public EmpSalarySysItemDto update(UpdateEmpSalarySysItemDto request) {
EmpSalarySysItemEntity entity = this.repository.get(request.getId());
// 发生名称变更时, 同步更新关联的工资项目
if (ObjectUtils.notEqual(request.getName(), entity.getName())) {
List<EmpSalaryItemEntity> items =
empSalaryItemService.findAllBy(null, null, Collections.singletonList(entity.getCode()));
if (CollectionUtils.isNotEmpty(items)) {
items.forEach(
x -> {
x.setFormulaShow(
x.getFormulaShow()
.replace(entity.getName(), request.getName()));
});
}
}
// 发生编码变更时, 同步更新关联的工资项目
if (ObjectUtils.notEqual(request.getCode(), entity.getCode())) {
List<EmpSalaryItemEntity> items =
empSalaryItemService.findAllBy(null, null, Collections.singletonList(entity.getCode()));
if (CollectionUtils.isNotEmpty(items)) {
items.forEach(
x -> {
if (CollectionUtils.containsAny(
x.getDependOnSysItem(), entity.getCode())) {
x.getDependOnSysItem().remove(entity.getCode());
x.getDependOnSysItem().add(request.getCode());
}
});
}
}
this.mapper.updateEntity(entity, request);
this.repository.save(entity);
@@ -58,6 +101,24 @@ public class EmpSalarySysItemService
throw new BizException("数据已被关联,无法删除");
}
List<EmpSalarySysItemEntity> toDelete = this.repository.findAllById(request.getIds());
// 如果被依赖, 无法删除
empSalaryItemService
.findAllBy(
null, null, toDelete.stream().map(EmpSalarySysItemEntity::getCode).toList())
.forEach(
x -> {
if (CollectionUtils.containsAny(
x.getDependOnSysItem(),
toDelete.stream()
.map(EmpSalarySysItemEntity::getCode)
.toList())) {
throw new BizException("数据已被关联,无法删除");
}
});
this.repository.deleteAllById(request.getIds());
}

View File

@@ -20,9 +20,7 @@ import org.hibernate.mapping.PersistentClass;
import org.hibernate.mapping.Table;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.tool.schema.spi.Exporter;
import org.hibernate.type.BasicTypeRegistry;
import org.hibernate.type.SqlTypes;
import org.hibernate.type.Type;
import org.hibernate.type.*;
import org.hibernate.type.descriptor.java.JavaType;
import org.hibernate.type.descriptor.jdbc.JdbcType;
import org.hibernate.type.descriptor.sql.DdlType;
@@ -75,6 +73,11 @@ public class MyPostgreSQLDialect extends PostgreSQLDialect {
super.initializeFunctionRegistry(functionContributions);
functionContributions.getFunctionRegistry().registerNamed("self_and_children_ids");
functionContributions.getFunctionRegistry().registerNamed("self_and_parent_ids");
BasicType<String> stringType = functionContributions.getTypeConfiguration()
.getBasicTypeRegistry().resolve(StandardBasicTypes.STRING);
functionContributions.getFunctionRegistry().registerPattern(
"anyString", "any(?1)", stringType);
}
@Override

View File

@@ -0,0 +1,17 @@
package scripts.dict
import cn.lihongjie.coal.base.dto.CommonQuery
import cn.lihongjie.coal.empMonthAttendance.controller.EmpMonthAttendanceController
import org.springframework.context.ApplicationContext
ApplicationContext ioc = ioc
def controller = ioc.getBean(EmpMonthAttendanceController.class)
return controller.list(new CommonQuery())