mirror of
https://codeup.aliyun.com/64f7d6b8ce01efaafef1e678/coal/coal.git
synced 2026-01-25 07:46:40 +08:00
完善
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package cn.lihongjie.coal.deviceWorkOrder.dto;
|
||||
|
||||
import cn.lihongjie.coal.base.dto.OrgCommonDto;
|
||||
import cn.lihongjie.coal.deviceWorkOrderDetail.dto.CreateDeviceWorkOrderDetailDto;
|
||||
|
||||
import jakarta.persistence.ManyToOne;
|
||||
|
||||
@@ -39,7 +40,7 @@ public class CreateDeviceWorkOrderDto extends OrgCommonDto {
|
||||
|
||||
|
||||
|
||||
private List<CreateDeviceWorkOrderDto> details;
|
||||
private List<CreateDeviceWorkOrderDetailDto> details;
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -41,7 +41,7 @@ public class DeviceWorkOrderDto extends OrgCommonDto {
|
||||
+ "from t_dictionary d,\n"
|
||||
+ " t_dictionary_item i\n"
|
||||
+ "where d.id = i.dictionary_id\n"
|
||||
+ " and d.code = 'device.workOrder.status'\n"
|
||||
+ " and d.code = 'device.workOrder.type'\n"
|
||||
+ " and i.code = type)")
|
||||
private String typeName;
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package cn.lihongjie.coal.deviceWorkOrder.dto;
|
||||
|
||||
import cn.lihongjie.coal.base.dto.OrgCommonDto;
|
||||
import cn.lihongjie.coal.deviceWorkOrderDetail.dto.CreateDeviceWorkOrderDetailDto;
|
||||
|
||||
import jakarta.persistence.ManyToOne;
|
||||
|
||||
@@ -37,5 +38,5 @@ public class UpdateDeviceWorkOrderDto extends OrgCommonDto {
|
||||
|
||||
|
||||
|
||||
private List<CreateDeviceWorkOrderDto> details;
|
||||
private List<CreateDeviceWorkOrderDetailDto> details;
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import cn.lihongjie.coal.device.entity.DeviceEntity;
|
||||
import cn.lihongjie.coal.deviceWorkOrderDetail.entity.DeviceWorkOrderDetailEntity;
|
||||
import cn.lihongjie.coal.user.entity.UserEntity;
|
||||
|
||||
import jakarta.persistence.CascadeType;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.ManyToOne;
|
||||
import jakarta.persistence.OneToMany;
|
||||
@@ -45,7 +46,7 @@ public class DeviceWorkOrderEntity extends OrgCommonEntity {
|
||||
+ "from t_dictionary d,\n"
|
||||
+ " t_dictionary_item i\n"
|
||||
+ "where d.id = i.dictionary_id\n"
|
||||
+ " and d.code = 'device.workOrder.status'\n"
|
||||
+ " and d.code = 'device.workOrder.type'\n"
|
||||
+ " and i.code = type)")
|
||||
private String typeName;
|
||||
|
||||
@@ -63,7 +64,7 @@ public class DeviceWorkOrderEntity extends OrgCommonEntity {
|
||||
|
||||
@Comment("归档状态")
|
||||
@ColumnDefault("'0'")
|
||||
private String archiveStatus;
|
||||
private String archiveStatus = "0";
|
||||
|
||||
@Formula(
|
||||
"(select i.name\n"
|
||||
@@ -75,7 +76,7 @@ public class DeviceWorkOrderEntity extends OrgCommonEntity {
|
||||
private String archiveStatusName;
|
||||
|
||||
|
||||
@OneToMany(mappedBy = "workOrder")
|
||||
@OneToMany(mappedBy = "workOrder", cascade = {CascadeType.ALL})
|
||||
private List<DeviceWorkOrderDetailEntity> details;
|
||||
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@ import cn.lihongjie.coal.exception.BizException;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.convert.ConversionService;
|
||||
import org.springframework.data.domain.Page;
|
||||
@@ -35,8 +36,13 @@ public class DeviceWorkOrderService
|
||||
|
||||
public DeviceWorkOrderDto create(CreateDeviceWorkOrderDto request) {
|
||||
DeviceWorkOrderEntity entity = mapper.toEntity(request);
|
||||
if (CollectionUtils.isNotEmpty(entity.getDetails())) {
|
||||
|
||||
entity.getDetails().forEach(x -> x.setWorkOrder(entity));
|
||||
}
|
||||
|
||||
this.repository.save(entity);
|
||||
|
||||
return getById(entity.getId());
|
||||
}
|
||||
|
||||
@@ -51,6 +57,13 @@ public class DeviceWorkOrderService
|
||||
});
|
||||
this.mapper.updateEntity(entity, request);
|
||||
|
||||
|
||||
|
||||
if (CollectionUtils.isNotEmpty(entity.getDetails())) {
|
||||
|
||||
entity.getDetails().forEach(x -> x.setWorkOrder(entity));
|
||||
}
|
||||
|
||||
this.repository.save(entity);
|
||||
|
||||
return getById(entity.getId());
|
||||
|
||||
@@ -4,5 +4,16 @@ import cn.lihongjie.coal.base.dto.OrgCommonDto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Data
|
||||
public class CreateDeviceWorkOrderDetailDto extends OrgCommonDto {}
|
||||
public class CreateDeviceWorkOrderDetailDto extends OrgCommonDto {
|
||||
|
||||
private LocalDateTime startTime;
|
||||
|
||||
private LocalDateTime endTime;
|
||||
|
||||
|
||||
private String content;
|
||||
|
||||
}
|
||||
|
||||
@@ -4,8 +4,18 @@ import cn.lihongjie.coal.base.dto.OrgCommonDto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Data
|
||||
public class DeviceWorkOrderDetailDto extends OrgCommonDto {
|
||||
|
||||
private LocalDateTime startTime;
|
||||
|
||||
private LocalDateTime endTime;
|
||||
|
||||
|
||||
private String content;
|
||||
|
||||
private String archiveStatus;
|
||||
|
||||
private String archiveStatusName;
|
||||
|
||||
@@ -4,5 +4,16 @@ import cn.lihongjie.coal.base.dto.OrgCommonDto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Data
|
||||
public class UpdateDeviceWorkOrderDetailDto extends OrgCommonDto {}
|
||||
public class UpdateDeviceWorkOrderDetailDto extends OrgCommonDto {
|
||||
|
||||
private LocalDateTime startTime;
|
||||
|
||||
private LocalDateTime endTime;
|
||||
|
||||
|
||||
private String content;
|
||||
|
||||
}
|
||||
|
||||
@@ -14,6 +14,9 @@ public class CreateEmpSalaryItemDto extends OrgCommonDto {
|
||||
|
||||
@Comment("是否展示")
|
||||
private Boolean show;
|
||||
|
||||
@Comment("是否继承")
|
||||
private Boolean inherit;
|
||||
@Comment("上级名称")
|
||||
private String parentName;
|
||||
|
||||
|
||||
@@ -18,6 +18,10 @@ public class EmpSalaryItemDto extends OrgCommonDto {
|
||||
@Comment("是否展示")
|
||||
private Boolean show;
|
||||
|
||||
@Comment("是否继承")
|
||||
private Boolean inherit;
|
||||
|
||||
|
||||
|
||||
@Comment("工资项目类型")
|
||||
private String itemType;
|
||||
|
||||
@@ -18,6 +18,9 @@ public class UpdateEmpSalaryItemDto extends OrgCommonDto {
|
||||
|
||||
@Comment("是否展示")
|
||||
private Boolean show;
|
||||
|
||||
@Comment("是否继承")
|
||||
private Boolean inherit;
|
||||
@Comment("工资项目类型")
|
||||
private String itemType;
|
||||
|
||||
|
||||
@@ -18,6 +18,8 @@ public class EmpSalaryItemEntity extends OrgCommonEntity {
|
||||
@Comment("是否展示")
|
||||
private Boolean show;
|
||||
|
||||
@Comment("是否继承")
|
||||
private Boolean inherit;
|
||||
@Comment("上级名称")
|
||||
private String parentName;
|
||||
|
||||
|
||||
@@ -4,7 +4,6 @@ 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.common.Ctx;
|
||||
import cn.lihongjie.coal.common.GroovyScriptUtils;
|
||||
import cn.lihongjie.coal.empSalary.entity.EmpSalaryEntity;
|
||||
import cn.lihongjie.coal.empSalaryBatch.entity.EmpSalaryBatchEntity;
|
||||
import cn.lihongjie.coal.empSalaryItem.dto.CreateEmpSalaryItemDto;
|
||||
@@ -33,6 +32,10 @@ import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.lang3.RegExUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.codehaus.groovy.ast.ASTNode;
|
||||
import org.codehaus.groovy.ast.CodeVisitorSupport;
|
||||
import org.codehaus.groovy.ast.builder.AstStringCompiler;
|
||||
import org.codehaus.groovy.ast.expr.VariableExpression;
|
||||
import org.codehaus.groovy.control.CompilerConfiguration;
|
||||
import org.jgrapht.alg.cycle.CycleDetector;
|
||||
import org.jgrapht.graph.DefaultDirectedGraph;
|
||||
@@ -171,19 +174,49 @@ public class EmpSalaryItemService
|
||||
formula = tmp;
|
||||
|
||||
// 如果是工资字段
|
||||
if (StringUtils.equals(it.getItemType(), "1")){
|
||||
if (StringUtils.equals(it.getItemType(), "1")) {
|
||||
dependOn.add(it.getCode().replace("salary_", ""));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
item.setDependOn(dependOn);
|
||||
List<String> variables = new ArrayList<>();
|
||||
try {
|
||||
GroovyScriptUtils.validate(formula);
|
||||
if (!StringUtils.isEmpty(formula)) {
|
||||
AstStringCompiler compiler = new AstStringCompiler();
|
||||
List<ASTNode> astNodes = new ArrayList<>();
|
||||
|
||||
astNodes = compiler.compile(formula);
|
||||
|
||||
astNodes.stream()
|
||||
.forEach(
|
||||
x ->
|
||||
x.visit(
|
||||
new CodeVisitorSupport() {
|
||||
@Override
|
||||
public void visitVariableExpression(
|
||||
VariableExpression expression) {
|
||||
variables.add(expression.getName());
|
||||
}
|
||||
}));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
||||
throw new BizException("无效的公式: " + item.getName());
|
||||
}
|
||||
variables.removeAll(Arrays.asList("salary", "emp", "stdMap", "batch"));
|
||||
|
||||
Collection<String> unknownVariables = CollectionUtils.removeAll(variables, dependOn);
|
||||
|
||||
if (!unknownVariables.isEmpty()) {
|
||||
|
||||
throw new BizException(
|
||||
"工资项目 ["
|
||||
+ StringUtils.defaultIfBlank(item.getName(), item.getCode())
|
||||
+ "] 公式中存在未知变量: "
|
||||
+ StringUtils.join(unknownVariables, ", "));
|
||||
}
|
||||
|
||||
item.setFormula(formula);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user