diff --git a/src/main/java/com/xdap/self_development/controller/CommonParameterController.java b/src/main/java/com/xdap/self_development/controller/CommonParameterController.java index 2d05d08..4862813 100644 --- a/src/main/java/com/xdap/self_development/controller/CommonParameterController.java +++ b/src/main/java/com/xdap/self_development/controller/CommonParameterController.java @@ -1,9 +1,11 @@ package com.xdap.self_development.controller; import com.definesys.mpaas.common.http.Response; -import com.xdap.self_development.controller.form.ModelCommon; -import com.xdap.self_development.controller.form.ModelCommonParameterInsertForm; +import com.xdap.self_development.controller.form.*; +import com.xdap.self_development.exception.CommonException; +import com.xdap.self_development.pojo.AnalysisCommonParameters; import com.xdap.self_development.service.CommonParameterService; +import org.springframework.validation.BindingResult; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; @@ -17,6 +19,13 @@ public class CommonParameterController { @Resource private CommonParameterService commonParameterService; + // 全部子系统和参数 + @GetMapping("/getSystemAndPara") + public Response getSystemAndPara() { + List list = commonParameterService.getSystemAndPara(); + return Response.ok().data(list); + } + // 查询机型参数常用 @GetMapping("/getModelCommon") public Response getModelCommonParameter( @@ -28,24 +37,69 @@ public class CommonParameterController { // 新增机型参数常用 @PostMapping("/insertModelCommon") public Response insertModelCommonParameter( - @Valid @RequestBody ModelCommonParameterInsertForm form + @Valid @RequestBody ModelCommonParameterInsertForm form, + BindingResult bindingResult ) { + if (bindingResult.hasErrors()) { + bindingResult.getFieldErrors().forEach(error -> { + throw new CommonException(error.getDefaultMessage()); + }); + } commonParameterService.insertModelCommonParameter(form); return Response.ok().setMessage("新增成功"); } // 修改机型参数常用 @PostMapping("/updateModelCommon") public Response updateModelCommonParameter( - @Valid @RequestBody ModelCommonParameterInsertForm form + @Valid @RequestBody ModelCommonParameterUpdateForm form, + BindingResult bindingResult ) { + if (bindingResult.hasErrors()) { + bindingResult.getFieldErrors().forEach(error -> { + throw new CommonException(error.getDefaultMessage()); + }); + } commonParameterService.updateModelCommonParameter(form); return Response.ok().setMessage("修改成功"); } // 查询数据分析常用 + @GetMapping("/getAnalysisCommonParameter") + public Response getAnalysisCommonParameter( + @NotBlank @RequestParam String userId + ) { + List list = commonParameterService.getAnalysisCommonParameter(userId); + return Response.ok().data(list); + } // 新增数据分析常用 + @PostMapping("/insertAnalysisCommon") + public Response insertAnalysisCommonParameter( + @Valid @RequestBody AnalysisCommonParameterInsertForm form, + BindingResult bindingResult + ) { + if (bindingResult.hasErrors()) { + bindingResult.getFieldErrors().forEach(error -> { + throw new CommonException(error.getDefaultMessage()); + }); + } + commonParameterService.insertAnalysisCommonParameter(form); + return Response.ok().setMessage("新增成功"); + } // 修改数据分析常用 + @PostMapping("/updateAnalysisCommon") + public Response updateAnalysisCommonParameter( + @Valid @RequestBody AnalysisCommonParameterUpdateForm form, + BindingResult bindingResult + ) { + if (bindingResult.hasErrors()) { + bindingResult.getFieldErrors().forEach(error -> { + throw new CommonException(error.getDefaultMessage()); + }); + } + commonParameterService.updateAnalysisCommonParameter(form); + return Response.ok().setMessage("修改成功"); + } } diff --git a/src/main/java/com/xdap/self_development/controller/PermissionController.java b/src/main/java/com/xdap/self_development/controller/PermissionController.java index baae52f..e96a898 100644 --- a/src/main/java/com/xdap/self_development/controller/PermissionController.java +++ b/src/main/java/com/xdap/self_development/controller/PermissionController.java @@ -78,7 +78,7 @@ public class PermissionController { } } - //参数查询 + // 根据子系统获取参数 @GetMapping("/getAllParameters") public Response getAllParameters( @NotBlank String subsystem diff --git a/src/main/java/com/xdap/self_development/controller/form/AnalysisCommonParameterInsertForm.java b/src/main/java/com/xdap/self_development/controller/form/AnalysisCommonParameterInsertForm.java new file mode 100644 index 0000000..a256e82 --- /dev/null +++ b/src/main/java/com/xdap/self_development/controller/form/AnalysisCommonParameterInsertForm.java @@ -0,0 +1,24 @@ +package com.xdap.self_development.controller.form; + +import lombok.Data; + +import javax.validation.constraints.NotBlank; + +@Data +public class AnalysisCommonParameterInsertForm { + private String modelName; + private String plate; + private String platform; + private String series; + private String projectName; + private String projectNumber; + private Long emission; + private Long displacementMin; + private Long displacementMax; + private String combustionType; + + @NotBlank(message = "创建者不能为空") + private String userId; + @NotBlank(message = "常用名不能为空") + private String commonName; +} diff --git a/src/main/java/com/xdap/self_development/controller/form/AnalysisCommonParameterUpdateForm.java b/src/main/java/com/xdap/self_development/controller/form/AnalysisCommonParameterUpdateForm.java new file mode 100644 index 0000000..d5846fb --- /dev/null +++ b/src/main/java/com/xdap/self_development/controller/form/AnalysisCommonParameterUpdateForm.java @@ -0,0 +1,26 @@ +package com.xdap.self_development.controller.form; + +import lombok.Data; + +import javax.validation.constraints.NotBlank; + +@Data +public class AnalysisCommonParameterUpdateForm { + private String modelName; + private String plate; + private String platform; + private String series; + private String projectName; + private String projectNumber; + private Long emission; + private Long displacementMin; + private Long displacementMax; + private String combustionType; + + @NotBlank(message = "创建者不能为空") + private String userId; + @NotBlank(message = "常用名不能为空") + private String commonName; + @NotBlank(message = "常用不能为空") + private String commonId; +} diff --git a/src/main/java/com/xdap/self_development/controller/form/ModelCommon.java b/src/main/java/com/xdap/self_development/controller/form/ModelCommon.java index 817c0b4..58bafcf 100644 --- a/src/main/java/com/xdap/self_development/controller/form/ModelCommon.java +++ b/src/main/java/com/xdap/self_development/controller/form/ModelCommon.java @@ -7,5 +7,6 @@ import java.util.List; @Data public class ModelCommon { private String commonName; - private List subsystems; + private String commonId; + List subsystems; } diff --git a/src/main/java/com/xdap/self_development/controller/form/ModelCommonParameterInsertForm.java b/src/main/java/com/xdap/self_development/controller/form/ModelCommonParameterInsertForm.java index 426edbf..d78c34c 100644 --- a/src/main/java/com/xdap/self_development/controller/form/ModelCommonParameterInsertForm.java +++ b/src/main/java/com/xdap/self_development/controller/form/ModelCommonParameterInsertForm.java @@ -3,12 +3,16 @@ package com.xdap.self_development.controller.form; import lombok.Data; import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotEmpty; import javax.validation.constraints.NotNull; +import java.util.List; @Data public class ModelCommonParameterInsertForm { @NotBlank(message = "创建者不能为空") private String userId; - @NotNull(message = "常用不能为空") - private ModelCommon common; + @NotBlank(message = "常用名不能为空") + private String commonName; + @NotEmpty(message = "参数不能为空") + private List subsystems; } diff --git a/src/main/java/com/xdap/self_development/controller/form/ModelCommonParameterUpdateForm.java b/src/main/java/com/xdap/self_development/controller/form/ModelCommonParameterUpdateForm.java new file mode 100644 index 0000000..a6391ab --- /dev/null +++ b/src/main/java/com/xdap/self_development/controller/form/ModelCommonParameterUpdateForm.java @@ -0,0 +1,18 @@ +package com.xdap.self_development.controller.form; + +import lombok.Data; + +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotEmpty; +import javax.validation.constraints.NotNull; +import java.util.List; + +@Data +public class ModelCommonParameterUpdateForm { + @NotBlank(message = "创建者不能为空") + private String userId; + @NotBlank(message = "常用不能为空") + private String commonId; + @NotEmpty(message = "参数不能为空") + private List subsystems; +} diff --git a/src/main/java/com/xdap/self_development/pojo/AnalysisCommonParameters.java b/src/main/java/com/xdap/self_development/pojo/AnalysisCommonParameters.java index e088706..3d78cec 100644 --- a/src/main/java/com/xdap/self_development/pojo/AnalysisCommonParameters.java +++ b/src/main/java/com/xdap/self_development/pojo/AnalysisCommonParameters.java @@ -13,15 +13,17 @@ import lombok.EqualsAndHashCode; public class AnalysisCommonParameters extends MpaasBasePojo { @RowID(sequence = "analysis_common_parameters_s", type = RowIDType.UUID) private String id; + private String modelName; private String plate; private String platform; private String series; private String projectName; private String projectNumber; - private String emission; - private String displacementMin; - private String displacementMax; + private Long emission; + private Long displacementMin; + private Long displacementMax; private String combustionType; - private String userId; + + private String commonId; } diff --git a/src/main/java/com/xdap/self_development/pojo/ApprovalFlow.java b/src/main/java/com/xdap/self_development/pojo/ApprovalFlow.java index a8c8d51..72399e9 100644 --- a/src/main/java/com/xdap/self_development/pojo/ApprovalFlow.java +++ b/src/main/java/com/xdap/self_development/pojo/ApprovalFlow.java @@ -18,7 +18,7 @@ public class ApprovalFlow extends MpaasBasePojo { private String id; private String templateId; private String currentNode; // 节点:PROOFREAD, REVIEW, COUNTERSIGN, APPROVE - private String flowStatus; + private String flowStatus; //DRAFT(草稿)、APPROVING(审批中)、COMPLETE(已完成)、RETURNED(已撤回)、REJECTED(已拒绝) private String proofreadUsers; // 校对人员 private String reviewUsers; // 审核人员 diff --git a/src/main/java/com/xdap/self_development/pojo/CommonParameter.java b/src/main/java/com/xdap/self_development/pojo/CommonParameter.java new file mode 100644 index 0000000..2296b66 --- /dev/null +++ b/src/main/java/com/xdap/self_development/pojo/CommonParameter.java @@ -0,0 +1,19 @@ +package com.xdap.self_development.pojo; + +import com.definesys.mpaas.query.annotation.RowID; +import com.definesys.mpaas.query.annotation.RowIDType; +import com.definesys.mpaas.query.annotation.Table; +import com.definesys.mpaas.query.model.MpaasBasePojo; +import lombok.Data; +import lombok.EqualsAndHashCode; + +@EqualsAndHashCode(callSuper = true) +@Data +@Table("yfsjglpt_common_parameter") +public class CommonParameter extends MpaasBasePojo { + @RowID(sequence = "common_parameters_s", type = RowIDType.UUID) + private String id; + private String commonName; + private Integer commonType; + private String createBy; +} diff --git a/src/main/java/com/xdap/self_development/pojo/ModelCommonParameters.java b/src/main/java/com/xdap/self_development/pojo/ModelCommonParameters.java index 362b44d..0e9c891 100644 --- a/src/main/java/com/xdap/self_development/pojo/ModelCommonParameters.java +++ b/src/main/java/com/xdap/self_development/pojo/ModelCommonParameters.java @@ -17,9 +17,8 @@ public class ModelCommonParameters extends MpaasBasePojo { private String id; private String subsystem; private String parameterId; - private String userId; - // 唯一性 - private String commonName; + + private String commonId; @Column(type = ColumnType.CALCULATE) private String parameterName; diff --git a/src/main/java/com/xdap/self_development/pojo/Parameter.java b/src/main/java/com/xdap/self_development/pojo/Parameter.java index 2acbb47..3df8706 100644 --- a/src/main/java/com/xdap/self_development/pojo/Parameter.java +++ b/src/main/java/com/xdap/self_development/pojo/Parameter.java @@ -9,12 +9,14 @@ import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; @SQLQuery(value = { + @SQL(view = "getAllSubsystemAndPara", + sql = "SELECT DISTINCT mp.subsystem_name, mp.parameter_name, mp.id FROM yfsjglpt_model_parameter mp INNER JOIN yfsjglpt_model_parameter_and_template mpat ON mp.id = mpat.parameter_id INNER JOIN yfsjglpt_model_template mt ON mpat.template_id = mt.id INNER JOIN ( SELECT template_name, MAX(version) AS max_version FROM yfsjglpt_model_template WHERE status = 'COMPLETE' GROUP BY template_name ) latest ON mt.template_name = latest.template_name AND mt.version = latest.max_version WHERE mt.status = 'COMPLETE' ORDER BY mp.subsystem_name, mp.parameter_name, mp.id"), @SQL(view = "getAllSubsystem", sql = "SELECT DISTINCT mp.subsystem_name FROM yfsjglpt_model_parameter mp INNER JOIN yfsjglpt_model_parameter_and_template mpat ON mp.id = mpat.parameter_id INNER JOIN yfsjglpt_model_template mt ON mpat.template_id = mt.id INNER JOIN ( SELECT template_name, MAX(version) AS max_version FROM yfsjglpt_model_template WHERE status = 'COMPLETE' GROUP BY template_name ) latest ON mt.template_name = latest.template_name AND mt.version = latest.max_version WHERE mt.status = 'COMPLETE' ORDER BY mp.subsystem_name"), - @SQL(view = "selectParametersByTemplateId", sql = - "select p.* from yfsjglpt_model_parameter p left join yfsjglpt_model_parameter_and_template tap on p.id = tap.parameter_id where tap.template_id = #templateId"), - @SQL(view = "selectMaxNumber", sql = - "SELECT max(parameter_number) AS max_number FROM yfsjglpt_model_parameter p LEFT JOIN yfsjglpt_model_parameter_and_template tap ON p.id = tap.parameter_id WHERE tap.template_id = #templateId") + @SQL(view = "selectParametersByTemplateId", + sql = "select p.* from yfsjglpt_model_parameter p left join yfsjglpt_model_parameter_and_template tap on p.id = tap.parameter_id where tap.template_id = #templateId"), + @SQL(view = "selectMaxNumber", + sql = "SELECT max(parameter_number) AS max_number FROM yfsjglpt_model_parameter p LEFT JOIN yfsjglpt_model_parameter_and_template tap ON p.id = tap.parameter_id WHERE tap.template_id = #templateId") }) @EqualsAndHashCode(callSuper = true) @Data diff --git a/src/main/java/com/xdap/self_development/pojo/Template.java b/src/main/java/com/xdap/self_development/pojo/Template.java index 30fb39c..be5e199 100644 --- a/src/main/java/com/xdap/self_development/pojo/Template.java +++ b/src/main/java/com/xdap/self_development/pojo/Template.java @@ -27,7 +27,7 @@ public class Template extends MpaasBasePojo { private String id; private String templateName; private Integer version; - //DRAFT(草稿)、APPROVING(审批中)、COMPLETE(已完成)、RETURNED(已撤回)、REJECTED(已拒绝) + //DRAFT(草稿)、APPROVING(审批中)、COMPLETE(已完成) private String status; @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") private Timestamp createdTime; diff --git a/src/main/java/com/xdap/self_development/pojo/view/TodoAndTemplateView.java b/src/main/java/com/xdap/self_development/pojo/view/TodoAndTemplateView.java index f1d416b..53c0aaf 100644 --- a/src/main/java/com/xdap/self_development/pojo/view/TodoAndTemplateView.java +++ b/src/main/java/com/xdap/self_development/pojo/view/TodoAndTemplateView.java @@ -13,7 +13,7 @@ import java.util.List; @SQL(view = "getApprovalByUserIdAndIds", sql = "SELECT af.id AS \"flowId\", t.id AS \"templateId\", t.template_name AS \"templateName\", t.version AS \"version\", t.status AS \"status\" , af.create_by AS \"createBy\", af.created_time AS \"createdTime\" , CASE WHEN current_node = 'PROOFREAD' THEN proofread_users WHEN current_node = 'REVIEW' THEN review_users WHEN current_node = 'COUNTERSIGN' THEN countersign_users WHEN current_node = 'APPROVE' THEN approve_users END AS current_users FROM yfsjglpt_model_approval_flow af JOIN yfsjglpt_model_template t ON af.template_id = t.id WHERE t.template_name like CONCAT('%',#templateName, '%') and t.status like CONCAT('%',#status, '%') and af.flow_type = 1 and af.id NOT IN (#ids) AND af.create_by = #createBy"), @SQL(view = "getTodoAndTemplate", - sql = "SELECT af.id AS \"flowId\", t.id AS \"templateId\", t.template_name AS \"templateName\", t.version AS \"version\", t.status AS \"status\" , af.create_by AS \"createBy\" , xu.username AS \"username\", af.created_time AS \"createdTime\" , CASE WHEN current_node = 'PROOFREAD' THEN proofread_users WHEN current_node = 'REVIEW' THEN review_users WHEN current_node = 'COUNTERSIGN' THEN countersign_users WHEN current_node = 'APPROVE' THEN approve_users END AS current_users FROM yfsjglpt_model_approval_flow af JOIN yfsjglpt_model_template t ON af.template_id = t.id LEFT JOIN xdap_users xu ON xu.id = af.create_by WHERE t.template_name LIKE CONCAT('%', #templateName, '%') AND t.status LIKE CONCAT('%', #status, '%') AND t.created_time LIKE CONCAT('%', #createdTime, '%') AND xu.username LIKE CONCAT('%', #username, '%') AND af.flow_type = 1 AND (af.id IN (#ids) OR af.create_by = #createBy) ORDER BY CASE t.status WHEN 'COMPLETE' THEN 1 WHEN 'APPROVING' THEN 2 WHEN 'DRAFT' THEN 3 WHEN 'REJECTED' THEN 4 ELSE 5 END ASC") + sql = "SELECT af.id AS \"flowId\", t.id AS \"templateId\", t.template_name AS \"templateName\", t.version AS \"version\", af.flow_status AS \"status\" , af.create_by AS \"createBy\" , xu.username AS \"username\", af.created_time AS \"createdTime\" , CASE WHEN current_node = 'PROOFREAD' THEN proofread_users WHEN current_node = 'REVIEW' THEN review_users WHEN current_node = 'COUNTERSIGN' THEN countersign_users WHEN current_node = 'APPROVE' THEN approve_users END AS current_users FROM yfsjglpt_model_approval_flow af JOIN yfsjglpt_model_template t ON af.template_id = t.id LEFT JOIN xdap_users xu ON xu.id = af.create_by WHERE t.template_name LIKE CONCAT('%', #templateName, '%') AND t.status LIKE CONCAT('%', #status, '%') AND t.created_time LIKE CONCAT('%', #createdTime, '%') AND xu.username LIKE CONCAT('%', #username, '%') AND af.flow_type = 1 AND (af.id IN (#ids) OR af.create_by = #createBy) ORDER BY CASE af.flow_status WHEN 'COMPLETE' THEN 1 WHEN 'APPROVING' THEN 2 WHEN 'DRAFT' THEN 3 WHEN 'REJECTED' THEN 4 ELSE 5 END ASC") }) @Data public class TodoAndTemplateView { diff --git a/src/main/java/com/xdap/self_development/service/CommonParameterService.java b/src/main/java/com/xdap/self_development/service/CommonParameterService.java index cf0006f..325bd27 100644 --- a/src/main/java/com/xdap/self_development/service/CommonParameterService.java +++ b/src/main/java/com/xdap/self_development/service/CommonParameterService.java @@ -1,16 +1,24 @@ package com.xdap.self_development.service; -import com.xdap.self_development.controller.form.ModelCommon; -import com.xdap.self_development.controller.form.ModelCommonParameterInsertForm; +import com.xdap.self_development.controller.form.*; +import com.xdap.self_development.pojo.AnalysisCommonParameters; import javax.validation.Valid; import javax.validation.constraints.NotBlank; import java.util.List; public interface CommonParameterService { + List getSystemAndPara(); + List getModelCommonParameter(@NotBlank String userId); void insertModelCommonParameter(@Valid ModelCommonParameterInsertForm form); - void updateModelCommonParameter(@Valid ModelCommonParameterInsertForm form); + void updateModelCommonParameter(@Valid ModelCommonParameterUpdateForm form); + + List getAnalysisCommonParameter(@NotBlank String userId); + + void insertAnalysisCommonParameter(@Valid AnalysisCommonParameterInsertForm form); + + void updateAnalysisCommonParameter(AnalysisCommonParameterUpdateForm form); } diff --git a/src/main/java/com/xdap/self_development/service/impl/CommonParameterServiceImpl.java b/src/main/java/com/xdap/self_development/service/impl/CommonParameterServiceImpl.java index bd48157..56bcfe3 100644 --- a/src/main/java/com/xdap/self_development/service/impl/CommonParameterServiceImpl.java +++ b/src/main/java/com/xdap/self_development/service/impl/CommonParameterServiceImpl.java @@ -1,18 +1,21 @@ package com.xdap.self_development.service.impl; import com.xdap.self_development.config.BusinessDatabase; -import com.xdap.self_development.controller.form.ModelCommon; -import com.xdap.self_development.controller.form.ModelCommonItem; -import com.xdap.self_development.controller.form.ModelCommonParameterInsertForm; +import com.xdap.self_development.controller.form.*; import com.xdap.self_development.exception.CommonException; +import com.xdap.self_development.pojo.AnalysisCommonParameters; +import com.xdap.self_development.pojo.CommonParameter; import com.xdap.self_development.pojo.ModelCommonParameters; +import com.xdap.self_development.pojo.Parameter; import com.xdap.self_development.pojo.view.ParametersView; import com.xdap.self_development.service.CommonParameterService; +import org.springframework.beans.BeanUtils; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import java.util.Map; import java.util.stream.Collectors; @@ -23,44 +26,165 @@ public class CommonParameterServiceImpl implements CommonParameterService { private BusinessDatabase bd; @Override - public List getModelCommonParameter(String userId) { - List modelCommonParameters = bd.getBusinessDatabase() + public List getSystemAndPara() { + List parameters = bd.getBusinessDatabase() .viewQueryMode(true) - .view("getCommonById") - .setVar("userId", userId) - .doQuery(ModelCommonParameters.class); - return convertToModelCommonList(modelCommonParameters); + .view("getAllSubsystemAndPara") + .doQuery(Parameter.class); + + return convertToModelCommonItemList(parameters); + } + + @Override + public List getModelCommonParameter(String userId) { + List commonParameters = bd.getBusinessDatabase() + .eq("create_by", userId) + .eq("common_type", 1) + .doQuery(CommonParameter.class); + List ids = commonParameters.stream().map(CommonParameter::getId).collect(Collectors.toList()); + if (ids.isEmpty()) { + return Collections.emptyList(); + } + + // 数据处理 + List modelCommonParameters = bd.getBusinessDatabase() + .in("common_id", ids).doQuery(ModelCommonParameters.class); + return convertToModelCommonList(modelCommonParameters, commonParameters); } @Override @Transactional(rollbackFor = CommonException.class) public void insertModelCommonParameter(ModelCommonParameterInsertForm form) { // 检查名字是否重复 - List modelCommonParameters = convertToModelCommonParameters(form.getCommon(), form.getUserId()); + List modelCommonParameters1 = bd.getBusinessDatabase() + .eq("common_name", form.getCommonName()).doQuery(CommonParameter.class); + if (!modelCommonParameters1.isEmpty()) { + throw new CommonException("常用名重复,请重新命名"); + } + // 新增常用 + CommonParameter commonParameter = new CommonParameter(); + commonParameter.setCommonName(form.getCommonName()); + commonParameter.setCommonType(1); + commonParameter.setCreateBy(form.getUserId()); + bd.getBusinessDatabase().doInsert(commonParameter); + + // 关联常用参数 + List modelCommonParameters = + convertToModelCommonParameters(form.getSubsystems(), commonParameter.getId()); bd.getBusinessDatabase().doBatchInsert(modelCommonParameters); } @Override @Transactional(rollbackFor = CommonException.class) - public void updateModelCommonParameter(ModelCommonParameterInsertForm form) { - bd.getBusinessDatabase().eq("common_name", form.getCommon().getCommonName()).doDelete(ModelCommonParameters.class); - insertModelCommonParameter(form); + public void updateModelCommonParameter(ModelCommonParameterUpdateForm form) { + CommonParameter commonParameter = bd.getBusinessDatabase() + .eq("id", form.getCommonId()).doQueryFirst(CommonParameter.class); + if (commonParameter == null) { + throw new CommonException("无该常用"); + } + bd.getBusinessDatabase().eq("common_id", form.getCommonId()) + .doDelete(ModelCommonParameters.class); + List modelCommonParameters = + convertToModelCommonParameters(form.getSubsystems(), form.getCommonId()); + bd.getBusinessDatabase().doBatchInsert(modelCommonParameters); + } + + @Override + public List getAnalysisCommonParameter(String userId) { + List commonParameters = bd.getBusinessDatabase() + .eq("create_by", userId) + .eq("common_type", 2) + .doQuery(CommonParameter.class); + List ids = commonParameters.stream().map(CommonParameter::getId).collect(Collectors.toList()); + if (ids.isEmpty()) { + return Collections.emptyList(); + } + + // 数据处理 + List modelCommonParameters = bd.getBusinessDatabase() + .in("common_id", ids).doQuery(AnalysisCommonParameters.class); + return modelCommonParameters; + } + + @Override + @Transactional(rollbackFor = CommonException.class) + public void insertAnalysisCommonParameter(AnalysisCommonParameterInsertForm form) { + // 检查名字是否重复 + List modelCommonParameters1 = bd.getBusinessDatabase() + .eq("common_name", form.getCommonName()).doQuery(CommonParameter.class); + if (!modelCommonParameters1.isEmpty()) { + throw new CommonException("常用名重复,请重新命名"); + } + // 新增常用 + CommonParameter commonParameter = new CommonParameter(); + commonParameter.setCommonName(form.getCommonName()); + commonParameter.setCommonType(2); + commonParameter.setCreateBy(form.getUserId()); + bd.getBusinessDatabase().doInsert(commonParameter); + + // 关联常用参数 + AnalysisCommonParameters analysisCommonParameter = new AnalysisCommonParameters(); + BeanUtils.copyProperties(form, analysisCommonParameter); + analysisCommonParameter.setCommonId(commonParameter.getId()); + bd.getBusinessDatabase().doInsert(analysisCommonParameter); + } + + @Override + @Transactional(rollbackFor = CommonException.class) + public void updateAnalysisCommonParameter(AnalysisCommonParameterUpdateForm form) { + CommonParameter commonParameter = bd.getBusinessDatabase() + .eq("id", form.getCommonId()).doQueryFirst(CommonParameter.class); + if (commonParameter == null) { + throw new CommonException("无该常用"); + } + AnalysisCommonParameters commonParameters = bd.getBusinessDatabase() + .eq("common_id", form.getCommonId()) + .doQueryFirst(AnalysisCommonParameters.class); + BeanUtils.copyProperties(form, commonParameters); + bd.getBusinessDatabase().rowid("id", commonParameter.getRowId()).doUpdate(commonParameter); + } + + /** + * Parameter 列表转换为 ModelCommonItem 列表 + */ + public static List convertToModelCommonItemList(List parameterList) { + if (parameterList == null || parameterList.isEmpty()) { + return new ArrayList<>(); + } + Map> groupedBySubsystem = parameterList.stream() + .collect(Collectors.groupingBy(Parameter::getSubsystemName)); + List result = new ArrayList<>(); + for (Map.Entry> entry : groupedBySubsystem.entrySet()) { + ModelCommonItem item = new ModelCommonItem(); + item.setSubsystem(entry.getKey()); + List parameters = entry.getValue().stream() + .map(param -> new ParametersView(param.getId(), param.getParameterName())) + .collect(Collectors.toList()); + item.setParameters(parameters); + result.add(item); + } + return result; } /** * 将 ModelCommonParameters 列表转换为 ModelCommon 列表 */ - private List convertToModelCommonList(List paramsList) { + private List convertToModelCommonList( + List paramsList, List commonParameters + ) { if (paramsList == null || paramsList.isEmpty()) { return new ArrayList<>(); } - Map> groupedByCommonName = paramsList.stream() - .collect(Collectors.groupingBy(ModelCommonParameters::getCommonName)); + Map> groupedByCommonId = paramsList.stream() + .collect(Collectors.groupingBy(ModelCommonParameters::getCommonId)); List result = new ArrayList<>(); - for (Map.Entry> commonNameEntry : groupedByCommonName.entrySet()) { + for (CommonParameter commonParameter : commonParameters) { ModelCommon modelCommon = new ModelCommon(); - modelCommon.setCommonName(commonNameEntry.getKey()); - Map> groupedBySubsystem = commonNameEntry.getValue().stream() + modelCommon.setCommonName(commonParameter.getCommonName()); + modelCommon.setCommonId(commonParameter.getId()); + + Map> groupedBySubsystem = + groupedByCommonId.get(modelCommon.getCommonId()).stream() .collect(Collectors.groupingBy(ModelCommonParameters::getSubsystem)); List items = new ArrayList<>(); for (Map.Entry> subsystemEntry : groupedBySubsystem.entrySet()) { @@ -82,23 +206,17 @@ public class CommonParameterServiceImpl implements CommonParameterService { * 将ModelCommon 转换为 ModelCommonParameters 列表 */ private List convertToModelCommonParameters( - ModelCommon modelCommon, String userId) { - if (modelCommon == null) { - return new ArrayList<>(); - } + List commonItems, String commonId) { List result = new ArrayList<>(); - String commonName = modelCommon.getCommonName(); - if (modelCommon.getSubsystems() != null) { - for (ModelCommonItem item : modelCommon.getSubsystems()) { + if (commonItems != null) { + for (ModelCommonItem item : commonItems) { String subsystem = item.getSubsystem(); if (item.getParameters() != null) { for (ParametersView paramView : item.getParameters()) { ModelCommonParameters param = new ModelCommonParameters(); param.setSubsystem(subsystem); param.setParameterId(paramView.getParameterId()); - param.setUserId(userId); - param.setCommonName(commonName); - param.setParameterName(paramView.getParameterName()); + param.setCommonId(commonId); result.add(param); } } diff --git a/src/main/java/com/xdap/self_development/service/impl/ModelMenuPermissionServiceImpl.java b/src/main/java/com/xdap/self_development/service/impl/ModelMenuPermissionServiceImpl.java index fa4ce64..6de0d4e 100644 --- a/src/main/java/com/xdap/self_development/service/impl/ModelMenuPermissionServiceImpl.java +++ b/src/main/java/com/xdap/self_development/service/impl/ModelMenuPermissionServiceImpl.java @@ -3,7 +3,7 @@ package com.xdap.self_development.service.impl; import com.xdap.self_development.config.BusinessDatabase; import com.xdap.self_development.controller.request.ModelRolesRequest; -import com.xdap.self_development.pojo.ModelMenuPermissionPojo; +import com.xdap.self_development.pojo.ModelMenuDictionaryPojo; import com.xdap.self_development.pojo.ModelRolesPojo; import com.xdap.self_development.pojo.view.MenuListView; import com.xdap.self_development.service.ModelMenuPermissionService; @@ -31,10 +31,10 @@ public class ModelMenuPermissionServiceImpl implements ModelMenuPermissionServic Map nodeMap = new HashMap<>(); List views = new ArrayList<>(); - List permissionPojos = businessDatabase.getBusinessDatabase() - .doQuery(ModelMenuPermissionPojo.class); + List permissionPojos = businessDatabase.getBusinessDatabase() + .doQuery(ModelMenuDictionaryPojo.class); - for (ModelMenuPermissionPojo pojo : permissionPojos) { + for (ModelMenuDictionaryPojo pojo : permissionPojos) { MenuListView node = new MenuListView(); node.setId(pojo.getId()); node.setMenu(pojo.getMenuName()); @@ -42,7 +42,7 @@ public class ModelMenuPermissionServiceImpl implements ModelMenuPermissionServic nodeMap.put(pojo.getId(), node); } - for (ModelMenuPermissionPojo pojo : permissionPojos) { + for (ModelMenuDictionaryPojo pojo : permissionPojos) { String parentId = pojo.getParentId(); MenuListView currentNode = nodeMap.get(pojo.getId()); diff --git a/src/main/java/com/xdap/self_development/service/impl/ParameterServiceImpl.java b/src/main/java/com/xdap/self_development/service/impl/ParameterServiceImpl.java index 3b598c4..d71d9df 100644 --- a/src/main/java/com/xdap/self_development/service/impl/ParameterServiceImpl.java +++ b/src/main/java/com/xdap/self_development/service/impl/ParameterServiceImpl.java @@ -71,8 +71,6 @@ public class ParameterServiceImpl implements ParameterService { // 获取基准模板和最新模板 TemplateBenchmark benchmark = getTemplateBenchmark(form.getTemplateRowId()); - // todo 根据上传的部分参数更新模板 - // todo 部分维护的参数同步到最新的草稿中 Template newVersionTemplate; // 如果当前修改的模板为最新版并且为草稿状态,就不需要新建版本 if (Objects.equals(benchmark.getLastTemplate().getId(), benchmark.getBaseTemplate().getId()) @@ -82,12 +80,23 @@ public class ParameterServiceImpl implements ParameterService { } // 否则创建新版本 else { - newVersionTemplate = new Template( - benchmark.getLastTemplate().getTemplateName(), calculateNextVersion(benchmark.getLastTemplate().getVersion()), - "DRAFT", Timestamp.valueOf(LocalDateTime.now()), null, form.getCreateBy() - ); - // 保存新模板 - bd.getBusinessDatabase().doInsert(newVersionTemplate); + switch (benchmark.getLastTemplate().getStatus()) { + // 如果最新版本为草稿状态,沿用该版本 + case "DRAFT": + newVersionTemplate = benchmark.getLastTemplate(); + break; + // 如果最新版本为审核中,则不允许新建版本 + case "APPROVING": + throw new CommonException("最新模板审核中,暂时无法新建版本"); + // 如果最新版本为已完成,创建新版本 + default: + newVersionTemplate = new Template( + benchmark.getLastTemplate().getTemplateName(), calculateNextVersion(benchmark.getLastTemplate().getVersion()), + "DRAFT", Timestamp.valueOf(LocalDateTime.now()), null, form.getCreateBy() + ); + // 保存新模板 + bd.getBusinessDatabase().doInsert(newVersionTemplate); + } } // 4. 处理参数变更 diff --git a/src/main/java/com/xdap/self_development/service/impl/TemplateApprovalServiceImpl.java b/src/main/java/com/xdap/self_development/service/impl/TemplateApprovalServiceImpl.java index 5d919ae..a6bcf2c 100644 --- a/src/main/java/com/xdap/self_development/service/impl/TemplateApprovalServiceImpl.java +++ b/src/main/java/com/xdap/self_development/service/impl/TemplateApprovalServiceImpl.java @@ -269,7 +269,22 @@ public class TemplateApprovalServiceImpl implements TemplateApprovalService { if (!Objects.equals(flow.getCreateBy(), request.getUserId())) { throw new CommonException("不是申请人无法撤回"); } + if (!Objects.equals(flow.getCurrentNode(), "PROOFREAD")) { + throw new CommonException("已进入流程无法撤回"); + } + if (!Objects.equals(flow.getFlowStatus(), "APPROVING")) { + throw new CommonException("不在流程无法撤回"); + } if ("RETURN".equals(request.getResult())) { + ApprovalRecord record = new ApprovalRecord(); + record.setFlowId(flow.getId()); + record.setNode(flow.getCurrentNode()); + record.setUserId(request.getUserId()); + record.setOpinion(request.getOpinion()); + record.setResult(request.getResult()); + record.setApprovalTime(Timestamp.valueOf(LocalDateTime.now())); + bd.getBusinessDatabase().doInsert(record); + // 申请人撤回 cancelProcess(flow, "RETURNED"); } { @@ -371,7 +386,7 @@ public class TemplateApprovalServiceImpl implements TemplateApprovalService { flow.setFlowStatus(status); bd.getBusinessDatabase() .rowid("id", flow.getRowId()) - .update("status", flow.getFlowStatus()) + .update("flow_status", flow.getFlowStatus()) .doUpdate(ApprovalFlow.class); // 更新模板状态(重新打回草稿状态) Template template = bd.getBusinessDatabase() diff --git a/src/main/java/com/xdap/self_development/service/impl/TemplateServiceImpl.java b/src/main/java/com/xdap/self_development/service/impl/TemplateServiceImpl.java index d488544..1b93406 100644 --- a/src/main/java/com/xdap/self_development/service/impl/TemplateServiceImpl.java +++ b/src/main/java/com/xdap/self_development/service/impl/TemplateServiceImpl.java @@ -54,17 +54,17 @@ public class TemplateServiceImpl implements TemplateService { .eq("template_name", form.getTemplateName()) .doQueryFirst(Template.class); + // 如果有同名称模板 + if (template != null) { + throw new CommonException("已有同名版本,不允许新建模板"); + } + // 创建新模板 Template newTemplate = new Template( form.getTemplateName(), 1, "DRAFT", Timestamp.valueOf(LocalDateTime.now()), null, form.getCreateBy() ); - // 如果有同名称模板 - if (template != null) { - throw new CommonException("已有同名版本,导入失败"); - } - bd.getBusinessDatabase().doInsert(newTemplate); } @@ -248,11 +248,7 @@ public class TemplateServiceImpl implements TemplateService { problems.setFlag(true); problems.getErrors().add("模板‘"+templateName+"‘的最新版本正在审核中,无法导入"); return; - case "RETURNED": - problems.setFlag(true); - problems.getErrors().add("模板‘"+templateName+"’的最新版本已被退回,无法导入"); - return; - // 最新版本已发布或已退回,增加版本号新增 + // 最新版本已发布,增加版本号新增 default: lastTemplate = new Template( templateName, lastTemplate.getVersion()+1, "DRAFT", diff --git a/src/main/resources/sql.sql b/src/main/resources/sql.sql index 59223ef..4f13412 100644 --- a/src/main/resources/sql.sql +++ b/src/main/resources/sql.sql @@ -1,14 +1,23 @@ +DROP TABLE IF EXISTS yfsjglpt_common_parameter; +CREATE TABLE yfsjglpt_common_parameter ( + `id` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT 'ID', + `common_name` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '常用名称', + `common_type` int COLLATE utf8mb4_general_ci NOT NULL COMMENT '常用类型', + `create_by` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '用户ID', + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='常用参数表'; + +DROP TABLE IF EXISTS yfsjglpt_model_common_parameters; -- 新增机型参数常用参数表 CREATE TABLE yfsjglpt_model_common_parameters ( `id` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT 'ID', `subsystem` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '子系统', `parameter_id` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '参数ID', - `user_id` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '用户ID', - `common_name` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '常用名称', + `common_id` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '常用id', PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='机型参数常用参数表'; - +DROP TABLE IF EXISTS yfsjglpt_analysis_common_parameters; -- 新增分析常用参数表 CREATE TABLE yfsjglpt_analysis_common_parameters ( `id` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT 'ID', @@ -18,11 +27,11 @@ CREATE TABLE yfsjglpt_analysis_common_parameters ( `series` varchar(100) COLLATE utf8mb4_general_ci NOT NULL COMMENT '系列', `project_name` varchar(100) COLLATE utf8mb4_general_ci NOT NULL COMMENT '项目名称', `project_number` varchar(100) COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '项目编号', - `emission` varchar(100) COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '排放', - `displacement_min` varchar(100) COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '排放下限', - `displacement_max` varchar(100) COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '排放上限', + `emission` bigint COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '排放', + `displacement_min` bigint COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '排放下限', + `displacement_max` bigint COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '排放上限', `combustion_type` varchar(100) COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '燃烧类型', - `user_id` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '用户ID', + `common_id` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '常用id', PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='统计分析常用参数表';