添加工资公式

This commit is contained in:
2024-07-29 20:38:23 +08:00
parent 106a801d4a
commit 2871bfee1e
9 changed files with 240 additions and 0 deletions

View File

@@ -0,0 +1,52 @@
package cn.lihongjie.coal.empSalaryFunction.controller;
import cn.lihongjie.coal.annotation.SysLog;
import cn.lihongjie.coal.base.dto.CommonQuery;
import cn.lihongjie.coal.base.dto.IdRequest;
import cn.lihongjie.coal.empSalaryFunction.dto.CreateEmpSalaryFunctionDto;
import cn.lihongjie.coal.empSalaryFunction.dto.EmpSalaryFunctionDto;
import cn.lihongjie.coal.empSalaryFunction.dto.UpdateEmpSalaryFunctionDto;
import cn.lihongjie.coal.empSalaryFunction.service.EmpSalaryFunctionService;
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("/empSalaryFunction")
@SysLog(module = "工资函数")
@Slf4j
public class EmpSalaryFunctionController {
@Autowired private EmpSalaryFunctionService service;
@PostMapping("/create")
public EmpSalaryFunctionDto create(@RequestBody CreateEmpSalaryFunctionDto request) {
return this.service.create(request);
}
@PostMapping("/update")
public EmpSalaryFunctionDto update(@RequestBody UpdateEmpSalaryFunctionDto request) {
return this.service.update(request);
}
@PostMapping("/delete")
public Object delete(@RequestBody IdRequest request) {
this.service.delete(request);
return true;
}
@PostMapping("/getById")
public EmpSalaryFunctionDto getById(@RequestBody IdRequest request) {
return this.service.getById(request.getId());
}
@PostMapping("/list")
public Page<EmpSalaryFunctionDto> list(@RequestBody CommonQuery request) {
return this.service.list(request);
}
}

View File

@@ -0,0 +1,8 @@
package cn.lihongjie.coal.empSalaryFunction.dto;
import cn.lihongjie.coal.base.dto.CommonDto;
import lombok.Data;
@Data
public class CreateEmpSalaryFunctionDto extends CommonDto {}

View File

@@ -0,0 +1,8 @@
package cn.lihongjie.coal.empSalaryFunction.dto;
import cn.lihongjie.coal.base.dto.CommonDto;
import lombok.Data;
@Data
public class EmpSalaryFunctionDto extends CommonDto {}

View File

@@ -0,0 +1,8 @@
package cn.lihongjie.coal.empSalaryFunction.dto;
import cn.lihongjie.coal.base.dto.CommonDto;
import lombok.Data;
@Data
public class UpdateEmpSalaryFunctionDto extends CommonDto {}

View File

@@ -0,0 +1,28 @@
package cn.lihongjie.coal.empSalaryFunction.entity;
import cn.lihongjie.coal.base.entity.CommonEntity;
import jakarta.persistence.Entity;
import lombok.Data;
import org.hibernate.annotations.Comment;
@Data
@Entity
public class EmpSalaryFunctionEntity extends CommonEntity {
@Comment("使用说明")
private String description;
@Comment("函数内容")
private String content;
}

View File

@@ -0,0 +1,23 @@
package cn.lihongjie.coal.empSalaryFunction.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.empSalaryFunction.dto.CreateEmpSalaryFunctionDto;
import cn.lihongjie.coal.empSalaryFunction.dto.EmpSalaryFunctionDto;
import cn.lihongjie.coal.empSalaryFunction.dto.UpdateEmpSalaryFunctionDto;
import cn.lihongjie.coal.empSalaryFunction.entity.EmpSalaryFunctionEntity;
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 EmpSalaryFunctionMapper
extends BaseMapper<
EmpSalaryFunctionEntity,
EmpSalaryFunctionDto,
CreateEmpSalaryFunctionDto,
UpdateEmpSalaryFunctionDto> {}

View File

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

View File

@@ -0,0 +1,81 @@
package cn.lihongjie.coal.empSalaryFunction.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.empSalaryFunction.dto.CreateEmpSalaryFunctionDto;
import cn.lihongjie.coal.empSalaryFunction.dto.EmpSalaryFunctionDto;
import cn.lihongjie.coal.empSalaryFunction.dto.UpdateEmpSalaryFunctionDto;
import cn.lihongjie.coal.empSalaryFunction.entity.EmpSalaryFunctionEntity;
import cn.lihongjie.coal.empSalaryFunction.mapper.EmpSalaryFunctionMapper;
import cn.lihongjie.coal.empSalaryFunction.repository.EmpSalaryFunctionRepository;
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 EmpSalaryFunctionService
extends BaseService<EmpSalaryFunctionEntity, EmpSalaryFunctionRepository> {
@Autowired private EmpSalaryFunctionRepository repository;
@Autowired private EmpSalaryFunctionMapper mapper;
@Autowired private ConversionService conversionService;
@Autowired private DbFunctionService dbFunctionService;
public EmpSalaryFunctionDto create(CreateEmpSalaryFunctionDto request) {
EmpSalaryFunctionEntity entity = mapper.toEntity(request);
this.repository.save(entity);
return getById(entity.getId());
}
public EmpSalaryFunctionDto update(UpdateEmpSalaryFunctionDto request) {
EmpSalaryFunctionEntity 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 EmpSalaryFunctionDto getById(String id) {
EmpSalaryFunctionEntity entity = repository.get(id);
return mapper.toDto(entity);
}
public Page<EmpSalaryFunctionDto> list(CommonQuery query) {
Page<EmpSalaryFunctionEntity> page =
repository.findAll(
query.specification(conversionService),
PageRequest.of(
query.getPageNo(),
query.getPageSize(),
Sort.by(query.getOrders())));
return page.map(this.mapper::toDto);
}
}

View File

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