mirror of
https://codeup.aliyun.com/64f7d6b8ce01efaafef1e678/coal/coal.git
synced 2026-01-25 15:55:18 +08:00
添加人员管理
This commit is contained in:
@@ -3,8 +3,10 @@ package cn.lihongjie.coal.base.mapper;
|
||||
import cn.lihongjie.coal.base.dto.BaseDto;
|
||||
import cn.lihongjie.coal.base.entity.BaseEntity;
|
||||
import cn.lihongjie.coal.coalInfo.entity.CoalInfoEntity;
|
||||
import cn.lihongjie.coal.department.entity.DepartmentEntity;
|
||||
import cn.lihongjie.coal.dictionary.entity.DictionaryEntity;
|
||||
import cn.lihongjie.coal.dictionary.entity.DictionaryItemEntity;
|
||||
import cn.lihongjie.coal.file.entity.FileEntity;
|
||||
import cn.lihongjie.coal.organization.entity.OrganizationEntity;
|
||||
import cn.lihongjie.coal.permission.entity.PermissionEntity;
|
||||
import cn.lihongjie.coal.resource.entity.ResourceEntity;
|
||||
@@ -145,6 +147,28 @@ public interface CommonMapper {
|
||||
return e;
|
||||
}
|
||||
|
||||
default FileEntity createFile(String id) {
|
||||
|
||||
if (StringUtils.isEmpty(id)) {
|
||||
|
||||
return null;
|
||||
}
|
||||
FileEntity e = new FileEntity();
|
||||
e.setId(id);
|
||||
return e;
|
||||
}
|
||||
|
||||
default DepartmentEntity createDepartment(String id) {
|
||||
|
||||
if (StringUtils.isEmpty(id)) {
|
||||
|
||||
return null;
|
||||
}
|
||||
DepartmentEntity e = new DepartmentEntity();
|
||||
e.setId(id);
|
||||
return e;
|
||||
}
|
||||
|
||||
default String toString(Object o) {
|
||||
|
||||
if (o == null) {
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
package cn.lihongjie.coal.employee.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.employee.dto.CreateEmployeeDto;
|
||||
import cn.lihongjie.coal.employee.dto.EmployeeDto;
|
||||
import cn.lihongjie.coal.employee.dto.UpdateEmployeeDto;
|
||||
import cn.lihongjie.coal.employee.service.EmployeeService;
|
||||
|
||||
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("/employee")
|
||||
@SysLog(module = "员工信息")
|
||||
@Slf4j
|
||||
@OrgScope
|
||||
public class EmployeeController {
|
||||
@Autowired private EmployeeService service;
|
||||
|
||||
@PostMapping("/create")
|
||||
public EmployeeDto create(@RequestBody CreateEmployeeDto request) {
|
||||
return this.service.create(request);
|
||||
}
|
||||
|
||||
@PostMapping("/update")
|
||||
public EmployeeDto update(@RequestBody UpdateEmployeeDto request) {
|
||||
return this.service.update(request);
|
||||
}
|
||||
|
||||
@PostMapping("/delete")
|
||||
public Object delete(@RequestBody IdRequest request) {
|
||||
this.service.delete(request);
|
||||
return true;
|
||||
}
|
||||
|
||||
@PostMapping("/getById")
|
||||
public EmployeeDto getById(@RequestBody String request) {
|
||||
return this.service.getById(request);
|
||||
}
|
||||
|
||||
@PostMapping("/list")
|
||||
public Page<EmployeeDto> list(@RequestBody CommonQuery request) {
|
||||
return this.service.list(request);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package cn.lihongjie.coal.employee.dto;
|
||||
|
||||
import cn.lihongjie.coal.base.dto.OrgCommonDto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import org.hibernate.annotations.Comment;
|
||||
|
||||
import java.time.LocalDate;
|
||||
|
||||
@Data
|
||||
public class CreateEmployeeDto extends OrgCommonDto {
|
||||
@Comment("性别")
|
||||
private String sex;
|
||||
|
||||
@Comment("民族")
|
||||
private String nation;
|
||||
|
||||
@Comment("婚姻状况")
|
||||
private String marriage;
|
||||
|
||||
@Comment("入职时间")
|
||||
private LocalDate entryDate;
|
||||
|
||||
@Comment("身份证号")
|
||||
private String idCard;
|
||||
|
||||
@Comment("学历")
|
||||
private String education;
|
||||
|
||||
@Comment("毕业学校")
|
||||
private String school;
|
||||
|
||||
@Comment("籍贯")
|
||||
private String nativePlace;
|
||||
|
||||
@Comment("住址")
|
||||
private String address;
|
||||
|
||||
@Comment("手机号")
|
||||
private String phone;
|
||||
|
||||
@Comment("照片")
|
||||
private String image;
|
||||
|
||||
@Comment("部门")
|
||||
private String department;
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
package cn.lihongjie.coal.employee.dto;
|
||||
|
||||
import cn.lihongjie.coal.base.dto.OrgCommonDto;
|
||||
import cn.lihongjie.coal.department.entity.DepartmentEntity;
|
||||
import cn.lihongjie.coal.file.entity.FileEntity;
|
||||
|
||||
import jakarta.persistence.ManyToOne;
|
||||
import jakarta.persistence.OneToOne;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import org.hibernate.annotations.Comment;
|
||||
|
||||
import java.time.LocalDate;
|
||||
|
||||
@Data
|
||||
public class EmployeeDto extends OrgCommonDto {
|
||||
@Comment("性别")
|
||||
private String sex;
|
||||
|
||||
@Comment("性别-名称")
|
||||
private String sexName;
|
||||
|
||||
@Comment("民族")
|
||||
private String nation;
|
||||
|
||||
@Comment("民族-名称")
|
||||
private String nationName;
|
||||
|
||||
@Comment("婚姻状况")
|
||||
private String marriage;
|
||||
|
||||
@Comment("婚姻状况-名称")
|
||||
private String marriageName;
|
||||
|
||||
@Comment("入职时间")
|
||||
private LocalDate entryDate;
|
||||
|
||||
@Comment("身份证号")
|
||||
private String idCard;
|
||||
|
||||
@Comment("学历")
|
||||
private String education;
|
||||
|
||||
@Comment("学历-名称")
|
||||
private String educationName;
|
||||
|
||||
@Comment("毕业学校")
|
||||
private String school;
|
||||
|
||||
@Comment("籍贯")
|
||||
private String nativePlace;
|
||||
|
||||
@Comment("住址")
|
||||
private String address;
|
||||
|
||||
@Comment("手机号")
|
||||
private String phone;
|
||||
|
||||
@Comment("照片")
|
||||
@OneToOne
|
||||
private FileEntity image;
|
||||
|
||||
@Comment("部门")
|
||||
@ManyToOne
|
||||
private DepartmentEntity department;
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package cn.lihongjie.coal.employee.dto;
|
||||
|
||||
import cn.lihongjie.coal.base.dto.OrgCommonDto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import org.hibernate.annotations.Comment;
|
||||
|
||||
import java.time.LocalDate;
|
||||
|
||||
@Data
|
||||
public class UpdateEmployeeDto extends OrgCommonDto {
|
||||
@Comment("性别")
|
||||
private String sex;
|
||||
|
||||
@Comment("民族")
|
||||
private String nation;
|
||||
|
||||
@Comment("婚姻状况")
|
||||
private String marriage;
|
||||
|
||||
@Comment("入职时间")
|
||||
private LocalDate entryDate;
|
||||
|
||||
@Comment("身份证号")
|
||||
private String idCard;
|
||||
|
||||
@Comment("学历")
|
||||
private String education;
|
||||
|
||||
@Comment("毕业学校")
|
||||
private String school;
|
||||
|
||||
@Comment("籍贯")
|
||||
private String nativePlace;
|
||||
|
||||
@Comment("住址")
|
||||
private String address;
|
||||
|
||||
@Comment("手机号")
|
||||
private String phone;
|
||||
|
||||
@Comment("照片")
|
||||
private String image;
|
||||
|
||||
@Comment("部门")
|
||||
private String department;
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
package cn.lihongjie.coal.employee.entity;
|
||||
|
||||
import cn.lihongjie.coal.base.entity.OrgCommonEntity;
|
||||
import cn.lihongjie.coal.department.entity.DepartmentEntity;
|
||||
import cn.lihongjie.coal.file.entity.FileEntity;
|
||||
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.ManyToOne;
|
||||
import jakarta.persistence.OneToOne;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import org.hibernate.annotations.Comment;
|
||||
import org.hibernate.annotations.Formula;
|
||||
|
||||
import java.time.LocalDate;
|
||||
|
||||
@Data
|
||||
@Entity
|
||||
public class EmployeeEntity extends OrgCommonEntity {
|
||||
|
||||
@Comment("性别")
|
||||
private String sex;
|
||||
|
||||
@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 = 'sex'\n"
|
||||
+ " and i.code = sex)")
|
||||
@Comment("性别-名称")
|
||||
private String sexName;
|
||||
|
||||
@Comment("民族")
|
||||
private String nation;
|
||||
|
||||
@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 = 'nation'\n"
|
||||
+ " and i.code = nation)")
|
||||
@Comment("民族-名称")
|
||||
private String nationName;
|
||||
|
||||
@Comment("婚姻状况")
|
||||
private String marriage;
|
||||
|
||||
@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 = 'marriage'\n"
|
||||
+ " and i.code = marriage)")
|
||||
@Comment("婚姻状况-名称")
|
||||
private String marriageName;
|
||||
|
||||
@Comment("入职时间")
|
||||
private LocalDate entryDate;
|
||||
|
||||
@Comment("身份证号")
|
||||
private String idCard;
|
||||
|
||||
@Comment("学历")
|
||||
private String education;
|
||||
|
||||
@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 = 'education'\n"
|
||||
+ " and i.code = education)")
|
||||
@Comment("学历-名称")
|
||||
private String educationName;
|
||||
|
||||
@Comment("毕业学校")
|
||||
private String school;
|
||||
|
||||
@Comment("籍贯")
|
||||
private String nativePlace;
|
||||
|
||||
@Comment("住址")
|
||||
private String address;
|
||||
|
||||
@Comment("手机号")
|
||||
private String phone;
|
||||
|
||||
@Comment("照片")
|
||||
@OneToOne
|
||||
private FileEntity image;
|
||||
|
||||
@Comment("部门")
|
||||
@ManyToOne
|
||||
private DepartmentEntity department;
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package cn.lihongjie.coal.employee.mapper;
|
||||
|
||||
import cn.lihongjie.coal.base.mapper.BaseMapper;
|
||||
import cn.lihongjie.coal.base.mapper.CommonMapper;
|
||||
import cn.lihongjie.coal.employee.dto.CreateEmployeeDto;
|
||||
import cn.lihongjie.coal.employee.dto.EmployeeDto;
|
||||
import cn.lihongjie.coal.employee.dto.UpdateEmployeeDto;
|
||||
import cn.lihongjie.coal.employee.entity.EmployeeEntity;
|
||||
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.control.DeepClone;
|
||||
|
||||
@Mapper(
|
||||
componentModel = org.mapstruct.MappingConstants.ComponentModel.SPRING,
|
||||
uses = {CommonMapper.class},
|
||||
mappingControl = DeepClone.class)
|
||||
public interface EmployeeMapper
|
||||
extends BaseMapper<EmployeeEntity, EmployeeDto, CreateEmployeeDto, UpdateEmployeeDto> {}
|
||||
@@ -0,0 +1,9 @@
|
||||
package cn.lihongjie.coal.employee.repository;
|
||||
|
||||
import cn.lihongjie.coal.base.dao.BaseRepository;
|
||||
import cn.lihongjie.coal.employee.entity.EmployeeEntity;
|
||||
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public interface EmployeeRepository extends BaseRepository<EmployeeEntity> {}
|
||||
@@ -0,0 +1,68 @@
|
||||
package cn.lihongjie.coal.employee.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.employee.dto.CreateEmployeeDto;
|
||||
import cn.lihongjie.coal.employee.dto.EmployeeDto;
|
||||
import cn.lihongjie.coal.employee.dto.UpdateEmployeeDto;
|
||||
import cn.lihongjie.coal.employee.entity.EmployeeEntity;
|
||||
import cn.lihongjie.coal.employee.mapper.EmployeeMapper;
|
||||
import cn.lihongjie.coal.employee.repository.EmployeeRepository;
|
||||
|
||||
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;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
public class EmployeeService extends BaseService<EmployeeEntity, EmployeeRepository> {
|
||||
@Autowired private EmployeeRepository repository;
|
||||
|
||||
@Autowired private EmployeeMapper mapper;
|
||||
|
||||
@Autowired private ConversionService conversionService;
|
||||
|
||||
public EmployeeDto create(CreateEmployeeDto request) {
|
||||
EmployeeEntity entity = mapper.toEntity(request);
|
||||
|
||||
this.repository.save(entity);
|
||||
return getById(entity.getId());
|
||||
}
|
||||
|
||||
public EmployeeDto update(UpdateEmployeeDto request) {
|
||||
EmployeeEntity entity = this.repository.get(request.getId());
|
||||
this.mapper.updateEntity(entity, request);
|
||||
|
||||
this.repository.save(entity);
|
||||
|
||||
return getById(entity.getId());
|
||||
}
|
||||
|
||||
public void delete(IdRequest request) {
|
||||
this.repository.deleteAllById(request.getIds());
|
||||
}
|
||||
|
||||
public EmployeeDto getById(String id) {
|
||||
EmployeeEntity entity = repository.get(id);
|
||||
|
||||
return mapper.toDto(entity);
|
||||
}
|
||||
|
||||
public Page<EmployeeDto> list(CommonQuery query) {
|
||||
Page<EmployeeEntity> page =
|
||||
repository.findAll(
|
||||
query.specification(conversionService),
|
||||
PageRequest.of(
|
||||
query.getPageNo(),
|
||||
query.getPageSize(),
|
||||
Sort.by(query.getOrders())));
|
||||
|
||||
return page.map(this.mapper::toDto);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user