添加工资项目CURD

This commit is contained in:
2023-09-22 16:31:53 +08:00
parent acfc02a766
commit 587b5cee1b
9 changed files with 385 additions and 0 deletions

View File

@@ -0,0 +1,54 @@
package cn.lihongjie.coal.salaryItem.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.salaryItem.dto.CreateSalaryItemDto;
import cn.lihongjie.coal.salaryItem.dto.SalaryItemDto;
import cn.lihongjie.coal.salaryItem.dto.UpdateSalaryItemDto;
import cn.lihongjie.coal.salaryItem.service.SalaryItemService;
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("/salaryItem")
@SysLog(module = "工资项目")
@Slf4j
@OrgScope
public class SalaryItemController {
@Autowired private SalaryItemService service;
@PostMapping("/create")
public SalaryItemDto create(@RequestBody CreateSalaryItemDto request) {
return this.service.create(request);
}
@PostMapping("/update")
public SalaryItemDto update(@RequestBody UpdateSalaryItemDto request) {
return this.service.update(request);
}
@PostMapping("/delete")
public Object delete(@RequestBody IdRequest request) {
this.service.delete(request);
return true;
}
@PostMapping("/getById")
public SalaryItemDto getById(@RequestBody String request) {
return this.service.getById(request);
}
@PostMapping("/list")
public Page<SalaryItemDto> list(@RequestBody CommonQuery request) {
return this.service.list(request);
}
}

View File

@@ -0,0 +1,46 @@
package cn.lihongjie.coal.salaryItem.dto;
import cn.lihongjie.coal.base.dto.OrgCommonDto;
import lombok.Data;
import org.hibernate.annotations.Comment;
import org.hibernate.annotations.Formula;
@Data
public class CreateSalaryItemDto extends OrgCommonDto {
@Comment("上级名称")
private String parentName;
@Comment("工资项目类型")
private String itemType;
@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 = 'salaryItem.type'\n"
+ " and i.code = item_type)")
@Comment("工资项目类型-名称")
private String itemTypeName;
@Comment("工资项目录入方式")
private String inputType;
@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 = 'salaryItem.inputType'\n"
+ " and i.code = input_type)")
@Comment("工资项目录入方式-名称")
private String inputTypeName;
@Comment("公式-显示")
private String formulaShow;
@Comment("公式")
private String formula;
}

View File

@@ -0,0 +1,51 @@
package cn.lihongjie.coal.salaryItem.dto;
import cn.lihongjie.coal.base.dto.OrgCommonDto;
import lombok.Data;
import org.hibernate.annotations.Comment;
import org.hibernate.annotations.Formula;
import java.util.List;
@Data
public class SalaryItemDto extends OrgCommonDto {
@Comment("上级名称")
private String parentName;
@Comment("工资项目类型")
private String itemType;
@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 = 'salaryItem.type'\n"
+ " and i.code = item_type)")
@Comment("工资项目类型-名称")
private String itemTypeName;
@Comment("工资项目录入方式")
private String inputType;
@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 = 'salaryItem.inputType'\n"
+ " and i.code = input_type)")
@Comment("工资项目录入方式-名称")
private String inputTypeName;
@Comment("公式-显示")
private String formulaShow;
@Comment("公式")
private String formula;
@Comment("依赖项目")
private List<String> dependOn;
}

View File

@@ -0,0 +1,51 @@
package cn.lihongjie.coal.salaryItem.dto;
import cn.lihongjie.coal.base.dto.OrgCommonDto;
import lombok.Data;
import org.hibernate.annotations.Comment;
import org.hibernate.annotations.Formula;
import java.util.List;
@Data
public class UpdateSalaryItemDto extends OrgCommonDto {
@Comment("上级名称")
private String parentName;
@Comment("工资项目类型")
private String itemType;
@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 = 'salaryItem.type'\n"
+ " and i.code = item_type)")
@Comment("工资项目类型-名称")
private String itemTypeName;
@Comment("工资项目录入方式")
private String inputType;
@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 = 'salaryItem.inputType'\n"
+ " and i.code = input_type)")
@Comment("工资项目录入方式-名称")
private String inputTypeName;
@Comment("公式-显示")
private String formulaShow;
@Comment("公式")
private String formula;
@Comment("依赖项目")
private List<String> dependOn;
}

View File

@@ -0,0 +1,55 @@
package cn.lihongjie.coal.salaryItem.entity;
import cn.lihongjie.coal.base.entity.OrgCommonEntity;
import jakarta.persistence.Entity;
import lombok.Data;
import org.hibernate.annotations.Comment;
import org.hibernate.annotations.Formula;
import java.util.List;
@Data
@Entity
public class SalaryItemEntity extends OrgCommonEntity {
@Comment("上级名称")
private String parentName;
@Comment("工资项目类型")
private String itemType;
@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 = 'salaryItem.type'\n"
+ " and i.code = item_type)")
@Comment("工资项目类型-名称")
private String itemTypeName;
@Comment("工资项目录入方式")
private String inputType;
@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 = 'salaryItem.inputType'\n"
+ " and i.code = input_type)")
@Comment("工资项目录入方式-名称")
private String inputTypeName;
@Comment("公式-显示")
private String formulaShow;
@Comment("公式")
private String formula;
@Comment("依赖项目")
private List<String> dependOn;
}

View File

@@ -0,0 +1,19 @@
package cn.lihongjie.coal.salaryItem.mapper;
import cn.lihongjie.coal.base.mapper.BaseMapper;
import cn.lihongjie.coal.base.mapper.CommonMapper;
import cn.lihongjie.coal.salaryItem.dto.CreateSalaryItemDto;
import cn.lihongjie.coal.salaryItem.dto.SalaryItemDto;
import cn.lihongjie.coal.salaryItem.dto.UpdateSalaryItemDto;
import cn.lihongjie.coal.salaryItem.entity.SalaryItemEntity;
import org.mapstruct.Mapper;
import org.mapstruct.control.DeepClone;
@Mapper(
componentModel = org.mapstruct.MappingConstants.ComponentModel.SPRING,
uses = {CommonMapper.class},
mappingControl = DeepClone.class)
public interface SalaryItemMapper
extends BaseMapper<
SalaryItemEntity, SalaryItemDto, CreateSalaryItemDto, UpdateSalaryItemDto> {}

View File

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

View File

@@ -0,0 +1,68 @@
package cn.lihongjie.coal.salaryItem.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.salaryItem.dto.CreateSalaryItemDto;
import cn.lihongjie.coal.salaryItem.dto.SalaryItemDto;
import cn.lihongjie.coal.salaryItem.dto.UpdateSalaryItemDto;
import cn.lihongjie.coal.salaryItem.entity.SalaryItemEntity;
import cn.lihongjie.coal.salaryItem.mapper.SalaryItemMapper;
import cn.lihongjie.coal.salaryItem.repository.SalaryItemRepository;
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 SalaryItemService extends BaseService<SalaryItemEntity, SalaryItemRepository> {
@Autowired private SalaryItemRepository repository;
@Autowired private SalaryItemMapper mapper;
@Autowired private ConversionService conversionService;
public SalaryItemDto create(CreateSalaryItemDto request) {
SalaryItemEntity entity = mapper.toEntity(request);
this.repository.save(entity);
return getById(entity.getId());
}
public SalaryItemDto update(UpdateSalaryItemDto request) {
SalaryItemEntity 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 SalaryItemDto getById(String id) {
SalaryItemEntity entity = repository.get(id);
return mapper.toDto(entity);
}
public Page<SalaryItemDto> list(CommonQuery query) {
Page<SalaryItemEntity> page =
repository.findAll(
query.specification(conversionService),
PageRequest.of(
query.getPageNo(),
query.getPageSize(),
Sort.by(query.getOrders())));
return page.map(this.mapper::toDto);
}
}

View File

@@ -410,5 +410,37 @@
"name": "研究生"
}
]
},
{
"code": "salaryItem.type",
"name": "工资项目类型",
"item": [
{
"code": "1",
"name": "应发项"
},
{
"code": "2",
"name": "扣发项"
},
{
"code": "3",
"name": "辅助计算项"
}
]
},
{
"code": "salaryItem.inputType",
"name": "工资项目录入方式",
"item": [
{
"code": "1",
"name": "手动录入"
},
{
"code": "2",
"name": "公式计算"
}
]
}
]