删除无用的代码

This commit is contained in:
2024-03-21 11:04:48 +08:00
parent 0a50307570
commit 340248439f
8 changed files with 0 additions and 503 deletions

View File

@@ -1,54 +0,0 @@
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 IdRequest request) {
return this.service.getById(request.getId());
}
@PostMapping("/list")
public Page<SalaryItemDto> list(@RequestBody CommonQuery request) {
return this.service.list(request);
}
}

View File

@@ -1,46 +0,0 @@
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

@@ -1,53 +0,0 @@
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;
private String fullName;
@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

@@ -1,51 +0,0 @@
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

@@ -1,61 +0,0 @@
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;
@Formula("(CONCAT(parentName,'-' ,name))")
private String fullName;
@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;
@Comment("优先级")
private Integer priority;
}

View File

@@ -1,18 +0,0 @@
package cn.lihongjie.coal.salaryItem.mapper;
import cn.lihongjie.coal.base.mapper.BaseMapper;
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 = {cn.lihongjie.coal.base.mapper.CommonMapper.class, cn.lihongjie.coal.base.mapper.CommonEntityMapper.class},
mappingControl = DeepClone.class)
public interface SalaryItemMapper
extends BaseMapper<
SalaryItemEntity, SalaryItemDto, CreateSalaryItemDto, UpdateSalaryItemDto> {}

View File

@@ -1,13 +0,0 @@
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;
import java.util.List;
@Repository
public interface SalaryItemRepository extends BaseRepository<SalaryItemEntity> {
List<SalaryItemEntity> findByOrganizationIdAndStatus(String organizationId, Integer status);
}

View File

@@ -1,207 +0,0 @@
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.entity.CommonEntity;
import cn.lihongjie.coal.base.service.BaseService;
import cn.lihongjie.coal.common.GroovyScriptUtils;
import cn.lihongjie.coal.exception.BizException;
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.apache.commons.lang3.StringUtils;
import org.jgrapht.graph.DefaultDirectedGraph;
import org.jgrapht.graph.DefaultEdge;
import org.jgrapht.traverse.TopologicalOrderIterator;
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;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.function.Function;
import java.util.stream.Collectors;
@Service
@Slf4j
@Transactional
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);
updateField(entity);
// 校验公式
this.repository.save(entity);
syncFormula(entity);
return getById(entity.getId());
}
private void updateField(SalaryItemEntity entity) {
List<SalaryItemEntity> allItems =
repository.findByOrganizationIdAndStatus(entity.getOrganizationId(), 1);
Map<String, SalaryItemEntity> nameMap =
allItems.stream()
.collect(
Collectors.toMap(
e -> String.format("【%s】", e.getFullName()), e -> e));
Set<String> dependsOn = new HashSet<>();
Function<String, String> mapper =
(String s) -> {
if (nameMap.containsKey(s)) {
String code = nameMap.get(s).getCode();
dependsOn.add(code);
return code;
}
throw new BizException("公式中的依赖项 {} 不存在", s);
};
// 生成公式
String formula =
GroovyScriptUtils.replaceVariable("【(.*?)】", entity.getFormulaShow(), mapper);
entity.setDependOn(dependsOn.stream().toList());
entity.setFormula(formula);
try {
GroovyScriptUtils.variables(formula);
} catch (Exception e) {
throw new BizException("无效的公式");
}
}
private void syncFormula(SalaryItemEntity entity) {
DefaultDirectedGraph<Object, DefaultEdge> graph =
new DefaultDirectedGraph<>(DefaultEdge.class);
List<SalaryItemEntity> all =
repository.findByOrganizationIdAndStatus(entity.getOrganizationId(), 1);
Set<String> enabledCode =
all.stream().map(sie -> sie.getCode()).collect(Collectors.toSet());
for (SalaryItemEntity def : all) {
if (StringUtils.equalsIgnoreCase(def.getInputType(), "1")) {
Iterable<String> dependents = def.getDependOn();
for (String d : dependents) {
if (!enabledCode.contains(d)) {
throw new BizException("公式中的依赖项 {} 不存在", d);
}
graph.addVertex(def.getCode());
graph.addVertex(d);
graph.addEdge(d, def.getCode());
}
}
}
Map<String, SalaryItemEntity> codeMap =
all.stream().collect(Collectors.toMap(CommonEntity::getCode, e -> e));
Function<String, String> mapper =
(String s) -> {
if (codeMap.containsKey(s)) {
return "" + codeMap.get(s).getFullName() + "";
}
throw new BizException("公式中的依赖项 {} 不存在", s);
};
// 生成公式
TopologicalOrderIterator<Object, DefaultEdge> iterator =
new TopologicalOrderIterator<>(graph);
int order = 0;
while (iterator.hasNext()) {
Object next = iterator.next();
for (var item : all) {
if (StringUtils.equalsIgnoreCase(item.getCode(), next + "")) {
item.setPriority(order++);
item.setFormulaShow(
GroovyScriptUtils.replaceVariable(
"item\\d+", entity.getFormula(), mapper));
break;
}
}
}
this.repository.saveAll(all);
}
public SalaryItemDto update(UpdateSalaryItemDto request) {
SalaryItemEntity entity = this.repository.get(request.getId());
this.mapper.updateEntity(entity, request);
updateField(entity);
this.repository.save(entity);
syncFormula(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);
}
public void initOrgDefault(String organizationId) {
for (int i = 0; i < 50; i++) {
SalaryItemEntity item = new SalaryItemEntity();
item.setCode("item" + i);
item.setInputType("1");
item.setItemType("1");
item.setStatus(0);
item.setOrganizationId(organizationId);
this.repository.save(item);
}
}
}