From cf4a0d9db1ac17b3a670cbf92bcec740fd038955 Mon Sep 17 00:00:00 2001 From: lihongjie0209 Date: Sun, 18 Aug 2024 14:08:42 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=8A=A5=E8=A1=A8=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/EmpSalaryReportController.java | 54 +++++++++++++ .../dto/CreateEmpSalaryReportDto.java | 11 +++ .../dto/EmpSalaryReportDto.java | 11 +++ .../dto/UpdateEmpSalaryReportDto.java | 11 +++ .../entity/EmpSalaryReportEntity.java | 14 ++++ .../mapper/EmpSalaryReportMapper.java | 23 ++++++ .../repository/EmpSalaryReportRepository.java | 15 ++++ .../service/EmpSalaryReportService.java | 81 +++++++++++++++++++ .../dict/enum/empSalaryReportDict.groovy | 17 ++++ 9 files changed, 237 insertions(+) create mode 100644 src/main/java/cn/lihongjie/coal/empSalaryReport/controller/EmpSalaryReportController.java create mode 100644 src/main/java/cn/lihongjie/coal/empSalaryReport/dto/CreateEmpSalaryReportDto.java create mode 100644 src/main/java/cn/lihongjie/coal/empSalaryReport/dto/EmpSalaryReportDto.java create mode 100644 src/main/java/cn/lihongjie/coal/empSalaryReport/dto/UpdateEmpSalaryReportDto.java create mode 100644 src/main/java/cn/lihongjie/coal/empSalaryReport/entity/EmpSalaryReportEntity.java create mode 100644 src/main/java/cn/lihongjie/coal/empSalaryReport/mapper/EmpSalaryReportMapper.java create mode 100644 src/main/java/cn/lihongjie/coal/empSalaryReport/repository/EmpSalaryReportRepository.java create mode 100644 src/main/java/cn/lihongjie/coal/empSalaryReport/service/EmpSalaryReportService.java create mode 100644 src/main/resources/scripts/dict/enum/empSalaryReportDict.groovy diff --git a/src/main/java/cn/lihongjie/coal/empSalaryReport/controller/EmpSalaryReportController.java b/src/main/java/cn/lihongjie/coal/empSalaryReport/controller/EmpSalaryReportController.java new file mode 100644 index 00000000..221c70b9 --- /dev/null +++ b/src/main/java/cn/lihongjie/coal/empSalaryReport/controller/EmpSalaryReportController.java @@ -0,0 +1,54 @@ +package cn.lihongjie.coal.empSalaryReport.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.empSalaryReport.dto.CreateEmpSalaryReportDto; +import cn.lihongjie.coal.empSalaryReport.dto.EmpSalaryReportDto; +import cn.lihongjie.coal.empSalaryReport.dto.UpdateEmpSalaryReportDto; +import cn.lihongjie.coal.empSalaryReport.service.EmpSalaryReportService; + +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("/empSalaryReport") +@SysLog(module = "") +@Slf4j +@OrgScope +public class EmpSalaryReportController { + @Autowired private EmpSalaryReportService service; + + @PostMapping("/create") + public EmpSalaryReportDto create(@RequestBody CreateEmpSalaryReportDto request) { + return this.service.create(request); + } + + @PostMapping("/update") + public EmpSalaryReportDto update(@RequestBody UpdateEmpSalaryReportDto request) { + return this.service.update(request); + } + + @PostMapping("/delete") + public Object delete(@RequestBody IdRequest request) { + this.service.delete(request); + return true; + } + + @PostMapping("/getById") + public EmpSalaryReportDto getById(@RequestBody IdRequest request) { + return this.service.getById(request.getId()); + } + + @PostMapping("/list") + public Page list(@RequestBody CommonQuery request) { + return this.service.list(request); + } +} diff --git a/src/main/java/cn/lihongjie/coal/empSalaryReport/dto/CreateEmpSalaryReportDto.java b/src/main/java/cn/lihongjie/coal/empSalaryReport/dto/CreateEmpSalaryReportDto.java new file mode 100644 index 00000000..3b04b5ae --- /dev/null +++ b/src/main/java/cn/lihongjie/coal/empSalaryReport/dto/CreateEmpSalaryReportDto.java @@ -0,0 +1,11 @@ +package cn.lihongjie.coal.empSalaryReport.dto; + +import cn.lihongjie.coal.base.dto.OrgCommonDto; + +import lombok.Data; + +@Data +public class CreateEmpSalaryReportDto extends OrgCommonDto { + private String jsonConfig; + +} diff --git a/src/main/java/cn/lihongjie/coal/empSalaryReport/dto/EmpSalaryReportDto.java b/src/main/java/cn/lihongjie/coal/empSalaryReport/dto/EmpSalaryReportDto.java new file mode 100644 index 00000000..400921d1 --- /dev/null +++ b/src/main/java/cn/lihongjie/coal/empSalaryReport/dto/EmpSalaryReportDto.java @@ -0,0 +1,11 @@ +package cn.lihongjie.coal.empSalaryReport.dto; + +import cn.lihongjie.coal.base.dto.OrgCommonDto; + +import lombok.Data; + +@Data +public class EmpSalaryReportDto extends OrgCommonDto { + private String jsonConfig; + +} diff --git a/src/main/java/cn/lihongjie/coal/empSalaryReport/dto/UpdateEmpSalaryReportDto.java b/src/main/java/cn/lihongjie/coal/empSalaryReport/dto/UpdateEmpSalaryReportDto.java new file mode 100644 index 00000000..c9e501e1 --- /dev/null +++ b/src/main/java/cn/lihongjie/coal/empSalaryReport/dto/UpdateEmpSalaryReportDto.java @@ -0,0 +1,11 @@ +package cn.lihongjie.coal.empSalaryReport.dto; + +import cn.lihongjie.coal.base.dto.OrgCommonDto; + +import lombok.Data; + +@Data +public class UpdateEmpSalaryReportDto extends OrgCommonDto { + private String jsonConfig; + +} diff --git a/src/main/java/cn/lihongjie/coal/empSalaryReport/entity/EmpSalaryReportEntity.java b/src/main/java/cn/lihongjie/coal/empSalaryReport/entity/EmpSalaryReportEntity.java new file mode 100644 index 00000000..169bb86b --- /dev/null +++ b/src/main/java/cn/lihongjie/coal/empSalaryReport/entity/EmpSalaryReportEntity.java @@ -0,0 +1,14 @@ +package cn.lihongjie.coal.empSalaryReport.entity; + +import cn.lihongjie.coal.base.entity.OrgCommonEntity; + +import jakarta.persistence.Entity; + +import lombok.Data; + +@Data +@Entity +public class EmpSalaryReportEntity extends OrgCommonEntity { + + private String jsonConfig; +} diff --git a/src/main/java/cn/lihongjie/coal/empSalaryReport/mapper/EmpSalaryReportMapper.java b/src/main/java/cn/lihongjie/coal/empSalaryReport/mapper/EmpSalaryReportMapper.java new file mode 100644 index 00000000..753668e1 --- /dev/null +++ b/src/main/java/cn/lihongjie/coal/empSalaryReport/mapper/EmpSalaryReportMapper.java @@ -0,0 +1,23 @@ +package cn.lihongjie.coal.empSalaryReport.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.empSalaryReport.dto.CreateEmpSalaryReportDto; +import cn.lihongjie.coal.empSalaryReport.dto.EmpSalaryReportDto; +import cn.lihongjie.coal.empSalaryReport.dto.UpdateEmpSalaryReportDto; +import cn.lihongjie.coal.empSalaryReport.entity.EmpSalaryReportEntity; + +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 EmpSalaryReportMapper + extends BaseMapper< + EmpSalaryReportEntity, + EmpSalaryReportDto, + CreateEmpSalaryReportDto, + UpdateEmpSalaryReportDto> {} diff --git a/src/main/java/cn/lihongjie/coal/empSalaryReport/repository/EmpSalaryReportRepository.java b/src/main/java/cn/lihongjie/coal/empSalaryReport/repository/EmpSalaryReportRepository.java new file mode 100644 index 00000000..6a6e237b --- /dev/null +++ b/src/main/java/cn/lihongjie/coal/empSalaryReport/repository/EmpSalaryReportRepository.java @@ -0,0 +1,15 @@ +package cn.lihongjie.coal.empSalaryReport.repository; + +import cn.lihongjie.coal.base.dao.BaseRepository; +import cn.lihongjie.coal.empSalaryReport.entity.EmpSalaryReportEntity; + +import org.springframework.data.jpa.repository.Query; +import org.springframework.stereotype.Repository; + +import java.util.List; + +@Repository +public interface EmpSalaryReportRepository extends BaseRepository { + @Query("select false") + boolean isLinked(List ids); +} diff --git a/src/main/java/cn/lihongjie/coal/empSalaryReport/service/EmpSalaryReportService.java b/src/main/java/cn/lihongjie/coal/empSalaryReport/service/EmpSalaryReportService.java new file mode 100644 index 00000000..4189b146 --- /dev/null +++ b/src/main/java/cn/lihongjie/coal/empSalaryReport/service/EmpSalaryReportService.java @@ -0,0 +1,81 @@ +package cn.lihongjie.coal.empSalaryReport.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.empSalaryReport.dto.CreateEmpSalaryReportDto; +import cn.lihongjie.coal.empSalaryReport.dto.EmpSalaryReportDto; +import cn.lihongjie.coal.empSalaryReport.dto.UpdateEmpSalaryReportDto; +import cn.lihongjie.coal.empSalaryReport.entity.EmpSalaryReportEntity; +import cn.lihongjie.coal.empSalaryReport.mapper.EmpSalaryReportMapper; +import cn.lihongjie.coal.empSalaryReport.repository.EmpSalaryReportRepository; +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 EmpSalaryReportService + extends BaseService { + @Autowired private EmpSalaryReportRepository repository; + + @Autowired private EmpSalaryReportMapper mapper; + + @Autowired private ConversionService conversionService; + + @Autowired private DbFunctionService dbFunctionService; + + public EmpSalaryReportDto create(CreateEmpSalaryReportDto request) { + EmpSalaryReportEntity entity = mapper.toEntity(request); + + this.repository.save(entity); + return getById(entity.getId()); + } + + public EmpSalaryReportDto update(UpdateEmpSalaryReportDto request) { + EmpSalaryReportEntity entity = this.repository.get(request.getId()); + this.mapper.updateEntity(entity, request); + + this.repository.save(entity); + + return getById(entity.getId()); + } + + public void delete(IdRequest request) { + boolean linked = this.repository.isLinked(request.getIds()); + + if (linked) { + throw new BizException("数据已被关联,无法删除"); + } + + this.repository.deleteAllById(request.getIds()); + } + + public EmpSalaryReportDto getById(String id) { + EmpSalaryReportEntity entity = repository.get(id); + + return mapper.toDto(entity); + } + + public Page list(CommonQuery query) { + Page page = + repository.findAll( + query.specification(conversionService), + PageRequest.of( + query.getPageNo(), + query.getPageSize(), + Sort.by(query.getOrders()))); + + return page.map(this.mapper::toDto); + } +} diff --git a/src/main/resources/scripts/dict/enum/empSalaryReportDict.groovy b/src/main/resources/scripts/dict/enum/empSalaryReportDict.groovy new file mode 100644 index 00000000..11733a54 --- /dev/null +++ b/src/main/resources/scripts/dict/enum/empSalaryReportDict.groovy @@ -0,0 +1,17 @@ + +package scripts.dict + +import cn.lihongjie.coal.base.dto.CommonQuery +import cn.lihongjie.coal.empSalaryReport.controller.EmpSalaryReportController +import org.springframework.context.ApplicationContext + +ApplicationContext ioc = ioc + +def controller = ioc.getBean(EmpSalaryReportController.class) + + + + +return controller.list(new CommonQuery()) + +