添加员工档案记录

This commit is contained in:
2024-02-25 10:11:21 +08:00
parent 5c428e419f
commit ca6ff5c060
12 changed files with 498 additions and 0 deletions

View File

@@ -10,6 +10,7 @@ import jakarta.persistence.OneToMany;
import lombok.Data;
import org.hibernate.annotations.Comment;
import org.hibernate.annotations.Formula;
import java.time.LocalDate;
import java.util.List;
@@ -80,4 +81,24 @@ public class EmployeeDto extends OrgCommonDto {
@Comment("收款人姓名")
private String bankCardName;
@Comment("离职时间")
private LocalDate resignDate;
@Comment("离职原因")
private String resignReason;
@Comment("员工状态")
private String empStatus;
@Formula(
"(select i.name\n"
+ "from t_dictionary d,\n"
+ " t_dictionary_item i\n"
+ "where d.id = i.dictionary_id\n"
+ " and d.code = 'emp.status'\n"
+ " and i.code = emp_status)")
private String empStatusName;
}

View File

@@ -59,6 +59,14 @@ public class EmployeeEntity extends OrgCommonEntity {
@Comment("入职时间")
private LocalDate entryDate;
@Comment("离职时间")
private LocalDate resignDate;
@Comment("离职原因")
private String resignReason;
@Comment("身份证号")
private String idCard;
@@ -115,4 +123,16 @@ public class EmployeeEntity extends OrgCommonEntity {
@Comment("收款人姓名")
private String bankCardName;
@Comment("员工状态")
private String empStatus;
@Formula(
"(select i.name\n"
+ "from t_dictionary d,\n"
+ " t_dictionary_item i\n"
+ "where d.id = i.dictionary_id\n"
+ " and d.code = 'emp.status'\n"
+ " and i.code = emp_status)")
private String empStatusName;
}

View File

@@ -0,0 +1,66 @@
package cn.lihongjie.coal.employeeRecord.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.employeeRecord.dto.CreateEmployeeRecordDto;
import cn.lihongjie.coal.employeeRecord.dto.EmployeeRecordDto;
import cn.lihongjie.coal.employeeRecord.dto.UpdateEmployeeRecordDto;
import cn.lihongjie.coal.employeeRecord.service.EmployeeRecordService;
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("/employeeRecord")
@SysLog(module = "员工档案记录")
@Slf4j
@OrgScope
public class EmployeeRecordController {
@Autowired private EmployeeRecordService service;
@PostMapping("/create")
public EmployeeRecordDto create(@RequestBody CreateEmployeeRecordDto request) {
return this.service.create(request);
}
@PostMapping("/update")
public EmployeeRecordDto update(@RequestBody UpdateEmployeeRecordDto request) {
return this.service.update(request);
}
@PostMapping("/delete")
public Object delete(@RequestBody IdRequest request) {
this.service.delete(request);
return true;
}
@PostMapping("/getById")
public EmployeeRecordDto getById(@RequestBody IdRequest request) {
return this.service.getById(request.getId());
}
@PostMapping("/list")
public Page<EmployeeRecordDto> 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,41 @@
package cn.lihongjie.coal.employeeRecord.dto;
import cn.lihongjie.coal.base.dto.OrgCommonDto;
import jakarta.persistence.ManyToOne;
import lombok.Data;
import org.hibernate.annotations.Comment;
import org.hibernate.annotations.Formula;
@Data
public class CreateEmployeeRecordDto extends OrgCommonDto {
@ManyToOne
private String employee;
@Comment("记录时间")
private java.time.LocalDateTime recordTime;
@Comment("记录类型")
private String recordType;
@Formula(
"(select i.name\n"
+ "from t_dictionary d,\n"
+ " t_dictionary_item i\n"
+ "where d.id = i.dictionary_id\n"
+ " and d.code = 'emp.record.type'\n"
+ " and i.code = record_type)")
private String recordTypeName;
@Comment("记录内容")
private String recordContent;
@Comment("分数")
private Double score;
}

View File

@@ -0,0 +1,42 @@
package cn.lihongjie.coal.employeeRecord.dto;
import cn.lihongjie.coal.base.dto.OrgCommonDto;
import lombok.Data;
import org.hibernate.annotations.Comment;
import org.hibernate.annotations.Formula;
@Data
public class EmployeeRecordDto extends OrgCommonDto {
@Comment("记录时间")
private java.time.LocalDateTime recordTime;
@Comment("记录类型")
private String recordType;
@Formula(
"(select i.name\n"
+ "from t_dictionary d,\n"
+ " t_dictionary_item i\n"
+ "where d.id = i.dictionary_id\n"
+ " and d.code = 'emp.record.type'\n"
+ " and i.code = record_type)")
private String recordTypeName;
@Comment("记录内容")
private String recordContent;
@Comment("分数")
private Double score;
private String archiveStatus;
private String archiveStatusName;
}

View File

@@ -0,0 +1,41 @@
package cn.lihongjie.coal.employeeRecord.dto;
import cn.lihongjie.coal.base.dto.OrgCommonDto;
import jakarta.persistence.ManyToOne;
import lombok.Data;
import org.hibernate.annotations.Comment;
import org.hibernate.annotations.Formula;
@Data
public class UpdateEmployeeRecordDto extends OrgCommonDto {
@ManyToOne
private String employee;
@Comment("记录时间")
private java.time.LocalDateTime recordTime;
@Comment("记录类型")
private String recordType;
@Formula(
"(select i.name\n"
+ "from t_dictionary d,\n"
+ " t_dictionary_item i\n"
+ "where d.id = i.dictionary_id\n"
+ " and d.code = 'emp.record.type'\n"
+ " and i.code = record_type)")
private String recordTypeName;
@Comment("记录内容")
private String recordContent;
@Comment("分数")
private Double score;
}

View File

@@ -0,0 +1,61 @@
package cn.lihongjie.coal.employeeRecord.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 org.hibernate.annotations.Formula;
@Data
@Entity
public class EmployeeRecordEntity extends OrgCommonEntity {
@ManyToOne
private EmployeeEntity employee;
@Comment("记录时间")
private java.time.LocalDateTime recordTime;
@Comment("记录类型")
private String recordType;
@Formula(
"(select i.name\n"
+ "from t_dictionary d,\n"
+ " t_dictionary_item i\n"
+ "where d.id = i.dictionary_id\n"
+ " and d.code = 'emp.record.type'\n"
+ " and i.code = record_type)")
private String recordTypeName;
@Comment("记录内容")
private String recordContent;
@Comment("分数")
private Double score;
@Comment("归档状态")
@ColumnDefault("'0'")
private String archiveStatus;
@Formula(
"(select i.name\n"
+ "from t_dictionary d,\n"
+ " t_dictionary_item i\n"
+ "where d.id = i.dictionary_id\n"
+ " and d.code = 'archiveStatus'\n"
+ " and i.code = archive_status)")
private String archiveStatusName;
}

View File

@@ -0,0 +1,23 @@
package cn.lihongjie.coal.employeeRecord.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.employeeRecord.dto.CreateEmployeeRecordDto;
import cn.lihongjie.coal.employeeRecord.dto.EmployeeRecordDto;
import cn.lihongjie.coal.employeeRecord.dto.UpdateEmployeeRecordDto;
import cn.lihongjie.coal.employeeRecord.entity.EmployeeRecordEntity;
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 EmployeeRecordMapper
extends BaseMapper<
EmployeeRecordEntity,
EmployeeRecordDto,
CreateEmployeeRecordDto,
UpdateEmployeeRecordDto> {}

View File

@@ -0,0 +1,9 @@
package cn.lihongjie.coal.employeeRecord.repository;
import cn.lihongjie.coal.base.dao.BaseRepository;
import cn.lihongjie.coal.employeeRecord.entity.EmployeeRecordEntity;
import org.springframework.stereotype.Repository;
@Repository
public interface EmployeeRecordRepository extends BaseRepository<EmployeeRecordEntity> {}

View File

@@ -0,0 +1,118 @@
package cn.lihongjie.coal.employeeRecord.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.ArchiveUtils;
import cn.lihongjie.coal.employeeRecord.dto.CreateEmployeeRecordDto;
import cn.lihongjie.coal.employeeRecord.dto.EmployeeRecordDto;
import cn.lihongjie.coal.employeeRecord.dto.UpdateEmployeeRecordDto;
import cn.lihongjie.coal.employeeRecord.entity.EmployeeRecordEntity;
import cn.lihongjie.coal.employeeRecord.mapper.EmployeeRecordMapper;
import cn.lihongjie.coal.employeeRecord.repository.EmployeeRecordRepository;
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 EmployeeRecordService
extends BaseService<EmployeeRecordEntity, EmployeeRecordRepository> {
@Autowired private EmployeeRecordRepository repository;
@Autowired private EmployeeRecordMapper mapper;
@Autowired private ConversionService conversionService;
public EmployeeRecordDto create(CreateEmployeeRecordDto request) {
EmployeeRecordEntity entity = mapper.toEntity(request);
this.repository.save(entity);
return getById(entity.getId());
}
public EmployeeRecordDto update(UpdateEmployeeRecordDto request) {
EmployeeRecordEntity entity = this.repository.get(request.getId());
ArchiveUtils.checkArchiveStatus(
entity,
EmployeeRecordEntity::getArchiveStatus,
x -> "0",
(e, actual, expected) -> {
throw new BizException("数据 " + "已归档,无法编辑");
});
this.mapper.updateEntity(entity, request);
this.repository.save(entity);
return getById(entity.getId());
}
public void delete(IdRequest request) {
ArchiveUtils.checkArchiveStatus(
this.repository::findAllById,
request.getIds(),
EmployeeRecordEntity::getArchiveStatus,
x -> "0",
(e, actual, expected) -> {
throw new BizException("数据 " + "已归档,无法删除");
});
this.repository.deleteAllById(request.getIds());
}
public EmployeeRecordDto getById(String id) {
EmployeeRecordEntity entity = repository.get(id);
return mapper.toDto(entity);
}
public Page<EmployeeRecordDto> list(CommonQuery query) {
Page<EmployeeRecordEntity> 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.findAllById(dto.getIds()).stream()
.peek(
x ->
ArchiveUtils.checkArchiveStatus(
x,
EmployeeRecordEntity::getArchiveStatus,
y -> "0",
(e, actual, expected) -> {
throw new BizException("数据 " + "已归档,无法再次归档");
}))
.peek(x -> x.setArchiveStatus("1"))
.forEach(this.repository::save);
}
public void unarchive(IdRequest dto) {
this.repository.findAllById(dto.getIds()).stream()
.peek(
x ->
ArchiveUtils.checkArchiveStatus(
x,
EmployeeRecordEntity::getArchiveStatus,
y -> "1",
(e, actual, expected) -> {
throw new BizException("数据" + "未归档,无法取消归档");
}))
.peek(x -> x.setArchiveStatus("0"))
.forEach(this.repository::save);
}
}

View File

@@ -1965,6 +1965,45 @@
]
},
{
"code": "emp.status",
"name": "员工状态",
"item": [
{
"code": "0",
"name": "未入职"
},
{
"code": "1",
"name": "在职"
},
{
"code": "2",
"name": "离职"
}
]
},
{
"code": "emp.record.type",
"name": "员工档案记录类型",
"item": [
{
"code": "0",
"name": "表扬"
},
{
"code": "1",
"name": "惩罚"
},
{
"code": "2",
"name": "日常"
}
]
},
{
"code": "coalBlend.coalType",
"name": "配煤-煤类型",

View File

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