修改:批量发起流程
This commit is contained in:
parent
dd0fa6017b
commit
5c795ebde6
@ -2,6 +2,8 @@ package com.xdap.self_development.config;
|
|||||||
|
|
||||||
import com.definesys.mpaas.query.MpaasQuery;
|
import com.definesys.mpaas.query.MpaasQuery;
|
||||||
import com.definesys.mpaas.query.MpaasQueryFactory;
|
import com.definesys.mpaas.query.MpaasQueryFactory;
|
||||||
|
import com.xdap.common.constant.DatasourceConstant;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
@ -12,8 +14,11 @@ public class BusinessDatabase {
|
|||||||
@Resource
|
@Resource
|
||||||
private MpaasQueryFactory queryFactory;
|
private MpaasQueryFactory queryFactory;
|
||||||
|
|
||||||
|
@Value("${apaas.single.tenantId}")
|
||||||
|
private String tenantId;
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public MpaasQuery getBusinessDatabase() {
|
public MpaasQuery getBusinessDatabase() {
|
||||||
return queryFactory.buildFromDatasource("xdap_app_223770822127386625");
|
return queryFactory.buildFromDatasource(DatasourceConstant.XDAP_MYSQL_PREFIX + tenantId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,22 +2,26 @@ package com.xdap.self_development.controller;
|
|||||||
|
|
||||||
import com.definesys.mpaas.common.http.Response;
|
import com.definesys.mpaas.common.http.Response;
|
||||||
import com.definesys.mpaas.query.MpaasQueryFactory;
|
import com.definesys.mpaas.query.MpaasQueryFactory;
|
||||||
|
import com.xdap.motor.entity.SnowflakeIdWorker;
|
||||||
|
import com.xdap.runtime.service.RuntimeAppContextService;
|
||||||
import com.xdap.self_development.common.UserPermissionGetter;
|
import com.xdap.self_development.common.UserPermissionGetter;
|
||||||
import com.xdap.self_development.config.BusinessDatabase;
|
import com.xdap.self_development.config.BusinessDatabase;
|
||||||
import com.xdap.self_development.pojo.*;
|
import com.xdap.self_development.feign.ApaasMyTokenFeign;
|
||||||
|
import com.xdap.self_development.feign.dto.AppTokenDTO;
|
||||||
|
import com.xdap.self_development.feign.dto.ProcessLaunchRequest;
|
||||||
|
import com.xdap.self_development.feign.dto.ProcessLaunchResponse;
|
||||||
|
import com.xdap.self_development.feign.dto.UserTokenDT0;
|
||||||
|
import com.xdap.self_development.pojo.ApprovalParameterChangeDetails;
|
||||||
|
import com.xdap.self_development.pojo.ApprovalPerson;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.util.HashMap;
|
import java.util.*;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@RestController
|
@RestController
|
||||||
@ -29,156 +33,123 @@ public class DeleteController {
|
|||||||
private UserPermissionGetter getter;
|
private UserPermissionGetter getter;
|
||||||
@Resource
|
@Resource
|
||||||
private MpaasQueryFactory queryFactory;
|
private MpaasQueryFactory queryFactory;
|
||||||
|
@Autowired
|
||||||
|
private ApaasMyTokenFeign apaasMyTokenFeign;
|
||||||
|
@Resource
|
||||||
|
private RuntimeAppContextService runtimeAppContextService;
|
||||||
|
@Resource
|
||||||
|
private SnowflakeIdWorker snowflakeIdWorker;
|
||||||
|
|
||||||
|
@Value("${apaas.token.clientId}")
|
||||||
|
private String clientId;
|
||||||
|
@Value("${apaas.token.clientSecred}")
|
||||||
|
private String clientSecret;
|
||||||
|
|
||||||
@GetMapping("/getTables")
|
@GetMapping("submitApproval")
|
||||||
public Response getTables(String ztj, String z_wlms) {
|
public Response submitApproval() {
|
||||||
Map<String, Object> map = new HashMap<>();
|
String currentTenantId = runtimeAppContextService.getCurrentTenantId();
|
||||||
List<Map<String, Object>> list = queryFactory
|
String currentUserId = getter.getCurrentUserId();
|
||||||
.buildFromDatasource("yc_lrs_test_relsult")
|
AppTokenDTO token = apaasMyTokenFeign.getAppToken(
|
||||||
.eq("ztj", ztj)
|
"client_credentials",
|
||||||
.eq("z_wlms", z_wlms)
|
clientId,
|
||||||
.table("ads_prd_f_yfsjglpt_fdjlbjcjb")
|
clientSecret
|
||||||
.doQuery();
|
);
|
||||||
List<Map<String, Object>> list1 = queryFactory
|
|
||||||
.buildFromDatasource("yc_lrs_test_relsult")
|
UserTokenDT0 userToken = apaasMyTokenFeign.getUserToken(
|
||||||
.table("ads_prd_f_tc_flsxb")
|
token.getAccess_token(),
|
||||||
.doQuery();
|
currentUserId
|
||||||
map.put("ads_prd_f_yfsjglpt_fdjlbjcjb", list);
|
);
|
||||||
map.put("ads_prd_f_tc_flsxb", list1);
|
String formId = "693cce312153aa5a1ac8599b";
|
||||||
return Response.ok().data(map);
|
String documentId = snowflakeIdWorker.nextId();
|
||||||
|
ApprovalPerson approvalPerson = new ApprovalPerson();
|
||||||
|
approvalPerson.getDetails().setParameterName("测试参数名11");
|
||||||
|
approvalPerson.setPz(Collections.singletonList("100771325212057665536"));
|
||||||
|
approvalPerson.setSh(Collections.singletonList("100771325212057665536"));
|
||||||
|
approvalPerson.setJd(Collections.singletonList("100771325212057665536"));
|
||||||
|
approvalPerson.setDocumentId(documentId);
|
||||||
|
bd.getBusinessDatabase().doInsert(approvalPerson);
|
||||||
|
List<String> documentIds = Collections.singletonList(documentId);
|
||||||
|
|
||||||
|
// 调用接口
|
||||||
|
ProcessLaunchResponse response = batchLaunch(userToken.getAccess_token(), formId, documentIds);
|
||||||
|
|
||||||
|
// 处理响应
|
||||||
|
if (response.isSuccess()) {
|
||||||
|
return Response.ok().data("流程批量发起成功:" + response.getMessage());
|
||||||
|
} else {
|
||||||
|
return Response.error("流程批量发起失败:" + response.getMessage());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("getAll")
|
public ProcessLaunchResponse batchLaunch(String userToken, String formId, List<String> documentIds) {
|
||||||
public Response getAll() {
|
// 1. 构造请求头参数
|
||||||
List<Template> templates = bd.getBusinessDatabase().doQuery(Template.class);
|
// 毫秒级时间戳(必填,来源:系统当前时间戳,Java8通过System.currentTimeMillis()获取)
|
||||||
List<Parameter> parameters = bd.getBusinessDatabase().doQuery(Parameter.class);
|
String xdapTimestamp = String.valueOf(System.currentTimeMillis());
|
||||||
List<TemplateAndParameter> templateAndParameters = bd.getBusinessDatabase().doQuery(TemplateAndParameter.class);
|
// 构造Authorization(格式:bearer + 空格 + token)
|
||||||
List<RevisionRecord> revisionRecords = bd.getBusinessDatabase().doQuery(RevisionRecord.class);
|
String authorization = "Bearer " + userToken;
|
||||||
|
|
||||||
Map<String, Object> result = new HashMap<>();
|
// 2. 构造请求体参数
|
||||||
result.put("templates", templates);
|
ProcessLaunchRequest request =
|
||||||
result.put("parameters", parameters);
|
new ProcessLaunchRequest(formId, documentIds);
|
||||||
result.put("templateAndParameters", templateAndParameters);
|
|
||||||
result.put("revisionRecords", revisionRecords);
|
|
||||||
|
|
||||||
return Response.ok().data(result);
|
// 3. 调用Feign接口
|
||||||
|
return apaasMyTokenFeign.batchLaunchProcess(
|
||||||
|
"application/json;charset=UTF-8",
|
||||||
|
authorization,
|
||||||
|
xdapTimestamp,
|
||||||
|
request
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/deleteAll")
|
@GetMapping("/submitPro")
|
||||||
@Transactional
|
public Response submitPro() {
|
||||||
public Response deleteAll(@RequestParam String version) {
|
List<String> tableNames = getTablesWithFormId();
|
||||||
List<Template> templates = bd.getBusinessDatabase()
|
|
||||||
.eq("version", version)
|
|
||||||
.doQuery(Template.class);
|
|
||||||
|
|
||||||
for (Template template : templates) {
|
Map<String, List<String>> params = new HashMap<>();
|
||||||
List<TemplateAndParameter> templateAndParameters = bd.getBusinessDatabase()
|
params.put("tableNames", new ArrayList<>());
|
||||||
.eq("template_id", template.getId())
|
tableNames.forEach(tableName -> {
|
||||||
.doQuery(TemplateAndParameter.class);
|
String table = countFormIdInTable(tableName, "693cce312153aa5a1ac8599b");
|
||||||
|
if (table != null) {
|
||||||
List<String> ids = templateAndParameters.stream()
|
params.get("tableNames").add(table);
|
||||||
.map(TemplateAndParameter::getId)
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
|
|
||||||
List<String> parameterIds = templateAndParameters.stream()
|
|
||||||
.map(TemplateAndParameter::getParameterId)
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
|
|
||||||
List<RevisionRecord> revisionRecords = bd.getBusinessDatabase()
|
|
||||||
.eq("template_id", template.getId())
|
|
||||||
.doQuery(RevisionRecord.class);
|
|
||||||
|
|
||||||
List<String> rIds = revisionRecords.stream()
|
|
||||||
.map(RevisionRecord::getId)
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
|
|
||||||
if (!parameterIds.isEmpty()) {
|
|
||||||
bd.getBusinessDatabase()
|
|
||||||
.in("id", parameterIds)
|
|
||||||
.doDelete(Parameter.class);
|
|
||||||
}
|
}
|
||||||
if (!ids.isEmpty()) {
|
});
|
||||||
bd.getBusinessDatabase()
|
return Response.ok().data(params);
|
||||||
.in("id", ids)
|
}
|
||||||
.doDelete(TemplateAndParameter.class);
|
|
||||||
|
public List<String> getTablesWithFormId() {
|
||||||
|
// 查询所有包含 form_id 字段的表
|
||||||
|
String sql = "SELECT TABLE_NAME FROM INFORMATION_SCHEMA.COLUMNS " +
|
||||||
|
"WHERE COLUMN_NAME = 'form_id' " +
|
||||||
|
"AND TABLE_SCHEMA = DATABASE()";
|
||||||
|
|
||||||
|
List<Map<String, Object>> tables = bd.getBusinessDatabase().sql(sql).doQuery();
|
||||||
|
System.out.println(tables);
|
||||||
|
List<String> tableNames = new ArrayList<>();
|
||||||
|
for (Map<String, Object> table : tables) {
|
||||||
|
tableNames.add((String) table.get("TABLE_NAME"));
|
||||||
|
}
|
||||||
|
|
||||||
|
return tableNames;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String countFormIdInTable(String tableName, String formIdValue) {
|
||||||
|
// 构建查询语句
|
||||||
|
String sql = "SELECT form_id FROM "+tableName+" WHERE form_id = '" + formIdValue +"'";
|
||||||
|
|
||||||
|
try {
|
||||||
|
System.out.println(sql);
|
||||||
|
List<Map<String, Object>> result = bd.getBusinessDatabase()
|
||||||
|
.sql(sql)
|
||||||
|
.doQuery();
|
||||||
|
|
||||||
|
if (!result.isEmpty()) {
|
||||||
|
return tableName;
|
||||||
}
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
// 记录日志,表可能不存在或没有form_id字段
|
||||||
|
System.err.println("查询表 " + tableName + " 时出错: " + e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
if (template.getId() != null) {
|
return null;
|
||||||
bd.getBusinessDatabase()
|
|
||||||
.eq("id", template.getId())
|
|
||||||
.doDelete(Template.class);
|
|
||||||
}
|
|
||||||
if (!rIds.isEmpty()) {
|
|
||||||
bd.getBusinessDatabase()
|
|
||||||
.in("id", rIds)
|
|
||||||
.doDelete(RevisionRecord.class);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return Response.ok();
|
|
||||||
}
|
|
||||||
|
|
||||||
@GetMapping("/deleteOne")
|
|
||||||
public Response deleteOne(
|
|
||||||
@RequestParam String rowId,
|
|
||||||
@RequestParam String parameterRowId,
|
|
||||||
@RequestParam String templateRowId,
|
|
||||||
@RequestParam String revisionRowId
|
|
||||||
) {
|
|
||||||
if (parameterRowId != null && !parameterRowId.isEmpty()) {
|
|
||||||
bd.getBusinessDatabase()
|
|
||||||
.rowid("id", parameterRowId)
|
|
||||||
.doDelete(Parameter.class);
|
|
||||||
}
|
|
||||||
if (rowId != null && !rowId.isEmpty()) {
|
|
||||||
bd.getBusinessDatabase()
|
|
||||||
.rowid("id", rowId)
|
|
||||||
.doDelete(TemplateAndParameter.class);
|
|
||||||
}
|
|
||||||
if (templateRowId != null && !templateRowId.isEmpty()) {
|
|
||||||
bd.getBusinessDatabase()
|
|
||||||
.rowid("id", templateRowId)
|
|
||||||
.doDelete(Template.class);
|
|
||||||
}
|
|
||||||
if (revisionRowId != null && !revisionRowId.isEmpty()) {
|
|
||||||
bd.getBusinessDatabase()
|
|
||||||
.rowid("id", revisionRowId)
|
|
||||||
.doDelete(RevisionRecord.class);
|
|
||||||
}
|
|
||||||
return Response.ok();
|
|
||||||
}
|
|
||||||
|
|
||||||
@GetMapping("/getAllFlow")
|
|
||||||
public Response getAllFlow() {
|
|
||||||
List<ApprovalFlow> flows = bd.getBusinessDatabase().doQuery(ApprovalFlow.class);
|
|
||||||
List<ApprovalRecord> records = bd.getBusinessDatabase().doQuery(ApprovalRecord.class);
|
|
||||||
|
|
||||||
Map<String, Object> result = new HashMap<>();
|
|
||||||
result.put("flows", flows);
|
|
||||||
result.put("records", records);
|
|
||||||
return Response.ok().data(result);
|
|
||||||
}
|
|
||||||
|
|
||||||
@GetMapping("/deleteAllFlow")
|
|
||||||
public Response deleteAllFlow(
|
|
||||||
@RequestParam String flowId
|
|
||||||
) {
|
|
||||||
bd.getBusinessDatabase().eq("flow_id", flowId).doDelete(ApprovalRecord.class);
|
|
||||||
bd.getBusinessDatabase().eq("id", flowId).doDelete(ApprovalFlow.class);
|
|
||||||
return Response.ok().setMessage("删除成功");
|
|
||||||
}
|
|
||||||
|
|
||||||
@GetMapping("/deleteOneFlow")
|
|
||||||
public Response deleteOneFlow(
|
|
||||||
@RequestParam String flowId,
|
|
||||||
@RequestParam String id
|
|
||||||
) {
|
|
||||||
if (flowId != null && !flowId.isEmpty()) {
|
|
||||||
bd.getBusinessDatabase().eq("id", flowId).doDelete(ApprovalFlow.class);
|
|
||||||
}
|
|
||||||
if (id != null && !id.isEmpty()) {
|
|
||||||
bd.getBusinessDatabase().eq("id", id).doDelete(ApprovalRecord.class);
|
|
||||||
}
|
|
||||||
return Response.ok();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -5,6 +5,7 @@ import com.definesys.mpaas.query.db.PageQueryResult;
|
|||||||
import com.xdap.runtime.service.RuntimeDatasourceService;
|
import com.xdap.runtime.service.RuntimeDatasourceService;
|
||||||
import com.xdap.self_development.controller.form.*;
|
import com.xdap.self_development.controller.form.*;
|
||||||
import com.xdap.self_development.exception.CommonException;
|
import com.xdap.self_development.exception.CommonException;
|
||||||
|
import com.xdap.self_development.pojo.ApprovalFlow;
|
||||||
import com.xdap.self_development.pojo.view.ApprovalFlowView;
|
import com.xdap.self_development.pojo.view.ApprovalFlowView;
|
||||||
import com.xdap.self_development.pojo.view.DepartmentUserView;
|
import com.xdap.self_development.pojo.view.DepartmentUserView;
|
||||||
import com.xdap.self_development.pojo.view.TemplateChangeView;
|
import com.xdap.self_development.pojo.view.TemplateChangeView;
|
||||||
@ -14,6 +15,7 @@ import org.springframework.web.bind.annotation.*;
|
|||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import javax.validation.Valid;
|
import javax.validation.Valid;
|
||||||
|
import javax.validation.constraints.NotBlank;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@ -24,6 +26,15 @@ public class TemplateApprovalController {
|
|||||||
@Resource
|
@Resource
|
||||||
private RuntimeDatasourceService runtimeDatasourceService;
|
private RuntimeDatasourceService runtimeDatasourceService;
|
||||||
|
|
||||||
|
@GetMapping("/saveApprovalId")
|
||||||
|
public Response saveApprovalId(
|
||||||
|
@NotBlank String documentId
|
||||||
|
) {
|
||||||
|
ApprovalFlow approvalFlow = new ApprovalFlow();
|
||||||
|
approvalFlow.setId(documentId);
|
||||||
|
return Response.ok();
|
||||||
|
}
|
||||||
|
|
||||||
@GetMapping("/getUsersByCondition")
|
@GetMapping("/getUsersByCondition")
|
||||||
public Response getUsersByCondition(
|
public Response getUsersByCondition(
|
||||||
@RequestParam String name
|
@RequestParam String name
|
||||||
|
|||||||
@ -3,10 +3,12 @@ package com.xdap.self_development.controller;
|
|||||||
import com.definesys.mpaas.common.http.Response;
|
import com.definesys.mpaas.common.http.Response;
|
||||||
import com.definesys.mpaas.query.db.PageQueryResult;
|
import com.definesys.mpaas.query.db.PageQueryResult;
|
||||||
import com.xdap.self_development.common.MyResponse;
|
import com.xdap.self_development.common.MyResponse;
|
||||||
|
import com.xdap.self_development.config.BusinessDatabase;
|
||||||
import com.xdap.self_development.controller.form.*;
|
import com.xdap.self_development.controller.form.*;
|
||||||
import com.xdap.self_development.exception.CommonException;
|
import com.xdap.self_development.exception.CommonException;
|
||||||
import com.xdap.self_development.pojo.Template;
|
import com.xdap.self_development.pojo.Template;
|
||||||
import com.xdap.self_development.service.TemplateService;
|
import com.xdap.self_development.service.TemplateService;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.validation.BindingResult;
|
import org.springframework.validation.BindingResult;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
@ -14,13 +16,41 @@ import org.springframework.web.multipart.MultipartFile;
|
|||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import javax.validation.Valid;
|
import javax.validation.Valid;
|
||||||
|
import javax.validation.constraints.NotBlank;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/custom/template")
|
@RequestMapping("/custom/template")
|
||||||
public class TemplateController {
|
public class TemplateController {
|
||||||
@Resource
|
@Resource
|
||||||
private TemplateService templateService;
|
private TemplateService templateService;
|
||||||
|
@Resource
|
||||||
|
private BusinessDatabase bd;
|
||||||
|
|
||||||
|
// 更新模板状态
|
||||||
|
@GetMapping("/updateTemplateStatus")
|
||||||
|
public Response updateTemplateStatus(
|
||||||
|
@NotBlank String templateId,
|
||||||
|
@NotBlank String status
|
||||||
|
) {
|
||||||
|
if (Objects.equals(status, "COMPLETE")) {
|
||||||
|
Template template = bd.getBusinessDatabase().eq("id", templateId).doQueryFirst(Template.class);
|
||||||
|
bd.getBusinessDatabase()
|
||||||
|
.eq("template_name", template.getTemplateName())
|
||||||
|
.update("status", "HISTORY")
|
||||||
|
.doUpdate(Template.class);
|
||||||
|
|
||||||
|
}
|
||||||
|
bd.getBusinessDatabase()
|
||||||
|
.eq("id", templateId)
|
||||||
|
.update("status", status)
|
||||||
|
.doUpdate(Template.class);
|
||||||
|
return Response.ok();
|
||||||
|
}
|
||||||
|
// ------------------------------------------
|
||||||
|
|
||||||
// 模板名的模糊搜索
|
// 模板名的模糊搜索
|
||||||
@GetMapping("/getTemplateByCondition")
|
@GetMapping("/getTemplateByCondition")
|
||||||
|
|||||||
@ -8,8 +8,8 @@ import javax.validation.constraints.NotNull;
|
|||||||
|
|
||||||
@Data
|
@Data
|
||||||
public class ApprovalAndParameterForm {
|
public class ApprovalAndParameterForm {
|
||||||
@NotBlank(message = "流程不能为空")
|
// @NotBlank(message = "流程不能为空")
|
||||||
private String flowId;
|
// private String flowId;
|
||||||
@NotBlank(message = "模板不能为空")
|
@NotBlank(message = "模板不能为空")
|
||||||
private String templateId;
|
private String templateId;
|
||||||
|
|
||||||
|
|||||||
@ -6,6 +6,8 @@ import javax.validation.constraints.NotBlank;
|
|||||||
|
|
||||||
@Data
|
@Data
|
||||||
public class ParameterForm {
|
public class ParameterForm {
|
||||||
|
private String id;
|
||||||
|
|
||||||
private Integer parameterNumber;
|
private Integer parameterNumber;
|
||||||
|
|
||||||
@NotBlank(message = "子系统不能为空")
|
@NotBlank(message = "子系统不能为空")
|
||||||
|
|||||||
@ -1,10 +1,9 @@
|
|||||||
package com.xdap.self_development.feign;
|
package com.xdap.self_development.feign;
|
||||||
|
|
||||||
import com.xdap.common.config.FeignConfig;
|
import com.xdap.common.config.FeignConfig;
|
||||||
import com.xdap.self_development.feign.dto.AppTokenDTO;
|
import com.xdap.self_development.feign.dto.*;
|
||||||
import com.xdap.self_development.feign.dto.FileUploadDTO;
|
|
||||||
import com.xdap.self_development.feign.dto.UserTokenDT0;
|
|
||||||
import org.springframework.cloud.openfeign.FeignClient;
|
import org.springframework.cloud.openfeign.FeignClient;
|
||||||
|
import org.springframework.http.HttpHeaders;
|
||||||
import org.springframework.http.MediaType;
|
import org.springframework.http.MediaType;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
@ -44,4 +43,21 @@ public interface ApaasMyTokenFeign {
|
|||||||
@RequestPart("tenantId") String tenantId,
|
@RequestPart("tenantId") String tenantId,
|
||||||
@RequestPart("userId") String userId
|
@RequestPart("userId") String userId
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量发起流程(无流程实例的单据)
|
||||||
|
* @param contentType 请求体格式(固定application/json;charset=UTF-8)
|
||||||
|
* @param access_token 用户token(非必填,格式:bearer + 空格 + token值)
|
||||||
|
* @param xdapTimestamp 毫秒级时间戳(必填,如:1744238901000)
|
||||||
|
* @param requestParam 请求体参数
|
||||||
|
* @return 响应结果
|
||||||
|
*/
|
||||||
|
@PostMapping(value = "/xdap-open/open/process/v1/batch/pureLaunchProcess",
|
||||||
|
consumes = "application/json;charset=UTF-8")
|
||||||
|
ProcessLaunchResponse batchLaunchProcess(
|
||||||
|
@RequestHeader("Content-Type") String contentType,
|
||||||
|
@RequestHeader(value = "Authorization") String access_token,
|
||||||
|
@RequestHeader("xdaptimestamp") String xdapTimestamp,
|
||||||
|
@RequestBody ProcessLaunchRequest requestParam
|
||||||
|
);
|
||||||
}
|
}
|
||||||
@ -0,0 +1,15 @@
|
|||||||
|
package com.xdap.self_development.feign.dto;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class ProcessLaunchRequest {
|
||||||
|
private String formId;
|
||||||
|
private List<String> documentIds;
|
||||||
|
}
|
||||||
@ -0,0 +1,24 @@
|
|||||||
|
package com.xdap.self_development.feign.dto;
|
||||||
|
|
||||||
|
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.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import org.checkerframework.checker.units.qual.A;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class ProcessLaunchResponse {
|
||||||
|
private String code;
|
||||||
|
private String message;
|
||||||
|
|
||||||
|
// 快捷判断是否成功
|
||||||
|
public boolean isSuccess() {
|
||||||
|
return "ok".equals(this.code);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -33,7 +33,6 @@ public class SheetDataListener implements ReadListener<Parameter> {
|
|||||||
private final Set<String> requiredHeaders;
|
private final Set<String> requiredHeaders;
|
||||||
// 标记当前sheet是否有效
|
// 标记当前sheet是否有效
|
||||||
private boolean validSheet = false;
|
private boolean validSheet = false;
|
||||||
private Set<Integer> someNumber = new HashSet<>();
|
|
||||||
|
|
||||||
public SheetDataListener(TemplateService templateService,
|
public SheetDataListener(TemplateService templateService,
|
||||||
String templateRowId, String createBy, MyResponse problems, Integer maxOrder) {
|
String templateRowId, String createBy, MyResponse problems, Integer maxOrder) {
|
||||||
@ -54,7 +53,6 @@ public class SheetDataListener implements ReadListener<Parameter> {
|
|||||||
.filter(Objects::nonNull)
|
.filter(Objects::nonNull)
|
||||||
.collect(Collectors.toSet());
|
.collect(Collectors.toSet());
|
||||||
currentSheetName = context.readSheetHolder().getSheetName();
|
currentSheetName = context.readSheetHolder().getSheetName();
|
||||||
someNumber = new HashSet<>();
|
|
||||||
log.info("开始解析Sheet: {}", currentSheetName);
|
log.info("开始解析Sheet: {}", currentSheetName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -87,12 +85,6 @@ public class SheetDataListener implements ReadListener<Parameter> {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!someNumber.add(data.getParameterNumber())) {
|
|
||||||
problems.setFlag(true);
|
|
||||||
problems.getErrors().add(currentSheetName +"模板的参数"+data.getParameterName()+"的序号字段重复");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (currentSheetName == null) {
|
if (currentSheetName == null) {
|
||||||
currentSheetName = context.readSheetHolder().getSheetName();
|
currentSheetName = context.readSheetHolder().getSheetName();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,18 @@
|
|||||||
|
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("approval_parameter_change_details")
|
||||||
|
public class ApprovalParameterChangeDetails extends MpaasBasePojo {
|
||||||
|
@RowID(sequence = "pp_s", type = RowIDType.UUID)
|
||||||
|
private String id;
|
||||||
|
private String documentId;
|
||||||
|
private String parameterName;
|
||||||
|
}
|
||||||
@ -0,0 +1,24 @@
|
|||||||
|
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;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
@Data
|
||||||
|
@Table("approval_persons")
|
||||||
|
public class ApprovalPerson extends MpaasBasePojo {
|
||||||
|
@RowID(sequence = "ap_s", type = RowIDType.UUID)
|
||||||
|
private String id;
|
||||||
|
private List<String> jd;
|
||||||
|
private List<String> sh;
|
||||||
|
private List<String> hq;
|
||||||
|
private List<String> pz;
|
||||||
|
private String documentId;
|
||||||
|
ApprovalParameterChangeDetails details = new ApprovalParameterChangeDetails();
|
||||||
|
}
|
||||||
@ -0,0 +1,15 @@
|
|||||||
|
package com.xdap.self_development.pojo;
|
||||||
|
|
||||||
|
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("ads_prd_f_tc_flsxb")
|
||||||
|
public class ClassificationAttribute extends MpaasBasePojo {
|
||||||
|
private String pitemId;
|
||||||
|
private String idattrtbutehame;
|
||||||
|
private String fieldvalue;
|
||||||
|
}
|
||||||
@ -0,0 +1,18 @@
|
|||||||
|
package com.xdap.self_development.pojo;
|
||||||
|
|
||||||
|
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("ads_prd_f_yfsjglpt_fdjlbjcjb")
|
||||||
|
public class EnginePartsCollection extends MpaasBasePojo {
|
||||||
|
// 状态机 -> 状态代号
|
||||||
|
private String ztj;
|
||||||
|
// 零部件名称
|
||||||
|
private String lbjmc;
|
||||||
|
// 零部件图号
|
||||||
|
private String lbjth;
|
||||||
|
}
|
||||||
@ -11,10 +11,10 @@ import java.sql.Timestamp;
|
|||||||
|
|
||||||
@SQLQuery(value = {
|
@SQLQuery(value = {
|
||||||
@SQL(view = "getMaxOrder",
|
@SQL(view = "getMaxOrder",
|
||||||
sql = "SELECT * FROM ( SELECT *, MAX(order_num) OVER (PARTITION BY template_name ) AS maxOrder , ROW_NUMBER() OVER (PARTITION BY template_name ORDER BY order_num DESC) AS rn FROM yfsjglpt_model_template ) tmp WHERE rn = 1"),
|
sql = "SELECT order_num as maxOrder FROM yfsjglpt_model_template ORDER BY order_num desc"),
|
||||||
// 查找每个模板的最新版本并且优先级按照已发布、审核中、草稿状态转变(只有这三种状态)
|
// 查找每个模板的最新版本并且优先级按照已发布、审核中、草稿状态转变(只有这三种状态)
|
||||||
@SQL(view = "getLatestTemplate",
|
@SQL(view = "getLatestTemplate",
|
||||||
sql = "SELECT ranked.order_num, ranked.id, ranked.template_name, ranked.version, ranked.status, ranked.created_time , ranked.published_time, xu.username AS 'createBy' FROM ( SELECT t.*, ROW_NUMBER() OVER (PARTITION BY template_name ORDER BY CASE WHEN status = 'COMPLETE' THEN 1 WHEN status = 'APPROVING' THEN 2 ELSE 3 END, version DESC) AS rn FROM yfsjglpt_model_template t WHERE status IN ('COMPLETE', 'DRAFT', 'APPROVING') ) ranked LEFT JOIN xdap_users xu ON xu.id = ranked.create_by WHERE rn = 1 ORDER BY CASE status WHEN 'COMPLETE' THEN 1 WHEN 'APPROVING' THEN 2 WHEN 'DRAFT' THEN 3 WHEN 'RETURNED' THEN 4 WHEN 'REJECTED' THEN 5 ELSE 6 END ASC"
|
sql = "SELECT ranked.order_num, ranked.id, ranked.template_name, ranked.version, ranked.status, ranked.created_time , ranked.published_time, xu.username AS 'createBy' FROM ( SELECT t.*, ROW_NUMBER() OVER (PARTITION BY template_name ORDER BY CASE WHEN status = 'COMPLETE' THEN 1 WHEN status = 'APPROVING' THEN 2 ELSE 3 END, version DESC) AS rn FROM yfsjglpt_model_template t WHERE status IN ('COMPLETE', 'DRAFT', 'APPROVING') ) ranked LEFT JOIN xdap_users xu ON xu.id = ranked.create_by WHERE rn = 1 ORDER BY CASE status WHEN 'COMPLETE' THEN 1 WHEN 'APPROVING' THEN 2 WHEN 'DRAFT' THEN 3 WHEN 'RETURNED' THEN 4 WHEN 'REJECTED' THEN 5 ELSE 6 END ASC, ranked.order_num desc"
|
||||||
),
|
),
|
||||||
// 获取所有模板的最新版本号(包括所有状态)
|
// 获取所有模板的最新版本号(包括所有状态)
|
||||||
@SQL(view = "getNewTemplate",
|
@SQL(view = "getNewTemplate",
|
||||||
|
|||||||
@ -6,15 +6,28 @@ import lombok.Data;
|
|||||||
|
|
||||||
@SQLQuery(value = {
|
@SQLQuery(value = {
|
||||||
@SQL(view = "getModelParameterValue",
|
@SQL(view = "getModelParameterValue",
|
||||||
sql = "SELECT epd.id AS \"id\", deem.id AS \"modelId\", ymp.parameter_name AS \"parameterName\", ymp.id AS \"parameterId\", epd.parameter_value AS \"parameterValue\" , ymp.parameter_source AS \"parameterSource\", ymp.number_or_formula AS \"numberOrFormula\", epd.major_version FROM data_entry_engine_model deem JOIN engine_param_detail epd ON epd.engine_model_id = deem.id AND deem.version_number = epd.major_version JOIN yfsjglpt_model_parameter ymp ON ymp.id = epd.parameter_id")
|
sql = "SELECT epd.id AS \"id\", deem.id AS \"modelId\", deem.product_number AS \"productNumber\", ymp.parameter_name AS \"parameterName\", ymp.id AS \"parameterId\" , epd.parameter_value AS \"parameterValue\", ymp.parts_name AS \"partsName\", ymp.parameter_type AS \"parameterType\", ymp.parameter_source AS \"parameterSource\", ymp.number_or_formula AS \"numberOrFormula\" , epd.major_version FROM data_entry_engine_model deem JOIN engine_param_detail epd ON epd.engine_model_id = deem.id AND deem.version_number = epd.major_version JOIN yfsjglpt_model_parameter ymp ON ymp.id = epd.parameter_id")
|
||||||
})
|
})
|
||||||
@Data
|
@Data
|
||||||
public class CalculationParameterView {
|
public class CalculationParameterView {
|
||||||
|
// 参数详情id
|
||||||
private String id;
|
private String id;
|
||||||
|
// 机型id
|
||||||
private String modelId;
|
private String modelId;
|
||||||
|
// 参数id
|
||||||
private String parameterId;
|
private String parameterId;
|
||||||
|
// 产品编号(状态代号)
|
||||||
|
private String productNumber;
|
||||||
|
// 参数名称
|
||||||
private String parameterName;
|
private String parameterName;
|
||||||
|
// 部件名称
|
||||||
|
private String partsName;
|
||||||
|
// 参数类型
|
||||||
|
private String parameterType;
|
||||||
|
// 参数值
|
||||||
private String parameterValue;
|
private String parameterValue;
|
||||||
|
// 参数来源
|
||||||
private String parameterSource;
|
private String parameterSource;
|
||||||
|
// 编号或者公式
|
||||||
private String numberOrFormula;
|
private String numberOrFormula;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,5 @@
|
|||||||
|
package com.xdap.self_development.pojo.view;
|
||||||
|
|
||||||
|
|
||||||
|
public class TCParameterValueView {
|
||||||
|
}
|
||||||
@ -6,7 +6,7 @@ import lombok.Data;
|
|||||||
|
|
||||||
@SQLQuery(value = {
|
@SQLQuery(value = {
|
||||||
@SQL(view = "getParameterAndChange",
|
@SQL(view = "getParameterAndChange",
|
||||||
sql = "SELECT p.*, r.modify_details FROM ( SELECT *, ROW_NUMBER() OVER (PARTITION BY parameter_id ORDER BY create_time DESC) AS rn FROM yfsjglpt_model_revision_record ) r LEFT JOIN yfsjglpt_model_parameter p ON r.parameter_id = p.id WHERE r.rn = 1 and r.template_id = #templateId order by r.create_time desc ")
|
sql = "SELECT p.*, r.pre_template_id, r.modify_details FROM ( SELECT *, ROW_NUMBER() OVER (PARTITION BY parameter_id ORDER BY create_time DESC) AS rn FROM yfsjglpt_model_revision_record ) r LEFT JOIN yfsjglpt_model_parameter p ON r.parameter_id = p.id WHERE r.rn = 1 and r.template_id = #templateId order by r.create_time desc ")
|
||||||
})
|
})
|
||||||
@Data
|
@Data
|
||||||
public class TemplateChangeView {
|
public class TemplateChangeView {
|
||||||
|
|||||||
@ -2,6 +2,8 @@ package com.xdap.self_development.schedule;
|
|||||||
|
|
||||||
import com.xdap.self_development.config.BusinessDatabase;
|
import com.xdap.self_development.config.BusinessDatabase;
|
||||||
import com.xdap.self_development.exception.CommonException;
|
import com.xdap.self_development.exception.CommonException;
|
||||||
|
import com.xdap.self_development.pojo.ClassificationAttribute;
|
||||||
|
import com.xdap.self_development.pojo.EnginePartsCollection;
|
||||||
import com.xdap.self_development.pojo.view.CalculationParameterView;
|
import com.xdap.self_development.pojo.view.CalculationParameterView;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
@ -26,7 +28,9 @@ public class ParameterValueCalculationTimer {
|
|||||||
public void dailyCalculate() {
|
public void dailyCalculate() {
|
||||||
LocalDate today = LocalDate.now();
|
LocalDate today = LocalDate.now();
|
||||||
log.info("开始执行{}参数计算任务", today);
|
log.info("开始执行{}参数计算任务", today);
|
||||||
// 查询所有参数配置
|
List<CalculationParameterView> toUpdate = new ArrayList<>();
|
||||||
|
|
||||||
|
// 1.查询所有参数配置
|
||||||
List<CalculationParameterView> parameterValues = bd.getBusinessDatabase()
|
List<CalculationParameterView> parameterValues = bd.getBusinessDatabase()
|
||||||
.viewQueryMode(true)
|
.viewQueryMode(true)
|
||||||
.view("getModelParameterValue")
|
.view("getModelParameterValue")
|
||||||
@ -35,23 +39,43 @@ public class ParameterValueCalculationTimer {
|
|||||||
log.info("无参数配置,跳过计算");
|
log.info("无参数配置,跳过计算");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// 维护所有参数的原始值
|
|
||||||
|
// 2.从中台更新参数值
|
||||||
|
for (CalculationParameterView parameter : parameterValues) {
|
||||||
|
if (Objects.equals(parameter.getParameterSource(), "TC分类表")) {
|
||||||
|
EnginePartsCollection enginePartsCollection = bd.getBusinessDatabase()
|
||||||
|
.eq("ztj", parameter.getProductNumber())
|
||||||
|
.eq("lbjmc", parameter.getPartsName())
|
||||||
|
.doQueryFirst(EnginePartsCollection.class);
|
||||||
|
if (enginePartsCollection == null || enginePartsCollection.getLbjth() == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
ClassificationAttribute classificationAttribute = bd.getBusinessDatabase()
|
||||||
|
.eq("pitemId", enginePartsCollection.getLbjth())
|
||||||
|
.eq("idattrtbutehame", parameter.getParameterName())
|
||||||
|
.doQueryFirst(ClassificationAttribute.class);
|
||||||
|
if (classificationAttribute != null && classificationAttribute.getFieldvalue() != null) {
|
||||||
|
parameter.setParameterValue(classificationAttribute.getFieldvalue());
|
||||||
|
toUpdate.add(parameter);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3.维护所有参数的原始值
|
||||||
Map<String, Map<String, String>> originalValueMap = convertMap(parameterValues);
|
Map<String, Map<String, String>> originalValueMap = convertMap(parameterValues);
|
||||||
// 构建参数名列表,按长度降序排列
|
|
||||||
|
// 4.构建参数名列表,按长度降序排列
|
||||||
List<String> parameterNames = originalValueMap.keySet().stream()
|
List<String> parameterNames = originalValueMap.keySet().stream()
|
||||||
.sorted((a, b) -> Integer.compare(b.length(), a.length()))
|
.sorted((a, b) -> Integer.compare(b.length(), a.length()))
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
// 遍历参数,计算需运算的参数值
|
|
||||||
List<CalculationParameterView> toUpdate = new ArrayList<>();
|
// 5.遍历参数,计算需运算的参数值
|
||||||
for (CalculationParameterView parameterValue : parameterValues) {
|
for (CalculationParameterView parameterValue : parameterValues) {
|
||||||
if (Objects.equals(parameterValue.getParameterSource(), "公式计算")) {
|
if (Objects.equals(parameterValue.getParameterSource(), "公式计算")) {
|
||||||
String formula = parameterValue.getNumberOrFormula();
|
String formula = parameterValue.getNumberOrFormula();
|
||||||
String modelId = parameterValue.getModelId();
|
String modelId = parameterValue.getModelId();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
log.info("原始公式:{}", formula);
|
|
||||||
String replacedFormula = replaceParametersInFormula(formula, parameterNames, originalValueMap, modelId);
|
String replacedFormula = replaceParametersInFormula(formula, parameterNames, originalValueMap, modelId);
|
||||||
log.info("替换后公式:{}", replacedFormula);
|
|
||||||
Double result = calculateExpression(replacedFormula);
|
Double result = calculateExpression(replacedFormula);
|
||||||
String formattedResult = String.format("%.6f", result);
|
String formattedResult = String.format("%.6f", result);
|
||||||
log.info("计算结果:{}", formattedResult);
|
log.info("计算结果:{}", formattedResult);
|
||||||
@ -105,7 +129,7 @@ public class ParameterValueCalculationTimer {
|
|||||||
return "0";
|
return "0";
|
||||||
}
|
}
|
||||||
|
|
||||||
private Double calculateExpression(String expression) {
|
private Double calculateExpression(String expression) throws RuntimeException {
|
||||||
|
|
||||||
Double result = calculateWithScriptEngine(expression);
|
Double result = calculateWithScriptEngine(expression);
|
||||||
if (result != null) {
|
if (result != null) {
|
||||||
@ -149,11 +173,15 @@ public class ParameterValueCalculationTimer {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Map<String, Map<String, String>> convertMap(List<CalculationParameterView> list) {
|
public static Map<String, Map<String, String>> convertMap(
|
||||||
|
List<CalculationParameterView> list
|
||||||
|
) {
|
||||||
if (list == null) {
|
if (list == null) {
|
||||||
return new HashMap<>();
|
return new HashMap<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 参数名在所有子系统都唯一
|
||||||
|
// 转为以参数名为key,(机型代号为key,参数值为值)为值的形式
|
||||||
return list.stream()
|
return list.stream()
|
||||||
.filter(Objects::nonNull)
|
.filter(Objects::nonNull)
|
||||||
.filter(item -> item.getParameterName() != null)
|
.filter(item -> item.getParameterName() != null)
|
||||||
|
|||||||
@ -76,7 +76,7 @@ public class ParameterServiceImpl implements ParameterService {
|
|||||||
@Transactional(rollbackFor = CommonException.class)
|
@Transactional(rollbackFor = CommonException.class)
|
||||||
public TemplateInfoView maintenanceParameters(UpdateParameterForm form) {
|
public TemplateInfoView maintenanceParameters(UpdateParameterForm form) {
|
||||||
// 公式格式检查
|
// 公式格式检查
|
||||||
form.getParameterForms().forEach(parameter -> {
|
for (ParameterForm parameter : form.getParameterForms()) {
|
||||||
if (Objects.equals(parameter.getParameterSource(), "公式计算")) {
|
if (Objects.equals(parameter.getParameterSource(), "公式计算")) {
|
||||||
Map<String, Object> validationResult = FormulaValidator.validateFormulaDetailed(
|
Map<String, Object> validationResult = FormulaValidator.validateFormulaDetailed(
|
||||||
parameter.getNumberOrFormula());
|
parameter.getNumberOrFormula());
|
||||||
@ -87,36 +87,14 @@ public class ParameterServiceImpl implements ParameterService {
|
|||||||
throw new CommonException(errorMsg);
|
throw new CommonException(errorMsg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
|
||||||
// 获取基准模板和最新模板
|
// 获取基准模板和最新模板
|
||||||
TemplateBenchmark benchmark = getTemplateBenchmark(form.getTemplateRowId());
|
TemplateBenchmark benchmark = getTemplateBenchmark(form.getTemplateRowId());
|
||||||
Template newVersionTemplate;
|
// 校验模板状态
|
||||||
|
validateTemplateStatus(benchmark);
|
||||||
// 当前修改的模板不为最新版
|
// 创建/复用新版本模板
|
||||||
if (!Objects.equals(benchmark.getLastTemplate().getId(), benchmark.getBaseTemplate().getId())) {
|
Template newVersionTemplate = createOrReuseNewTemplate(benchmark);
|
||||||
throw new CommonException("该状态的模板不可修改");
|
// 处理参数变更
|
||||||
}
|
|
||||||
|
|
||||||
// 当前模板为草稿状态
|
|
||||||
if (Objects.equals(benchmark.getBaseTemplate().getStatus(), "DRAFT")) {
|
|
||||||
newVersionTemplate = benchmark.getBaseTemplate();
|
|
||||||
}
|
|
||||||
// 当前模板为已发布状态
|
|
||||||
else if (Objects.equals(benchmark.getBaseTemplate().getStatus(), "COMPLETE")) {
|
|
||||||
newVersionTemplate = new Template(
|
|
||||||
benchmark.getLastTemplate().getTemplateName(), calculateNextVersion(benchmark.getLastTemplate().getVersion()),
|
|
||||||
"DRAFT", Timestamp.valueOf(LocalDateTime.now()), null, permissionGetter.getCurrentUserId(),getMaxOrder()
|
|
||||||
);
|
|
||||||
// 保存新模板
|
|
||||||
bd.getBusinessDatabase().doInsert(newVersionTemplate);
|
|
||||||
}
|
|
||||||
// 其他状态
|
|
||||||
else {
|
|
||||||
throw new CommonException("该状态的模板不可修改");
|
|
||||||
}
|
|
||||||
|
|
||||||
// 4. 处理参数变更
|
|
||||||
ParameterProcessingResult processingResult = processParameters(
|
ParameterProcessingResult processingResult = processParameters(
|
||||||
form.getParameterForms(),
|
form.getParameterForms(),
|
||||||
benchmark.getParameters(),
|
benchmark.getParameters(),
|
||||||
@ -124,15 +102,54 @@ public class ParameterServiceImpl implements ParameterService {
|
|||||||
newVersionTemplate
|
newVersionTemplate
|
||||||
);
|
);
|
||||||
|
|
||||||
// 5. 保存所有数据
|
// 保存所有数据
|
||||||
saveAllData(benchmark.getBaseTemplate(), newVersionTemplate, processingResult);
|
saveAllData(benchmark.getBaseTemplate(), newVersionTemplate, processingResult);
|
||||||
TemplateInfoView result = new TemplateInfoView();
|
|
||||||
|
|
||||||
|
TemplateInfoView result = new TemplateInfoView();
|
||||||
result.setTemplateRowId(newVersionTemplate.getRowId());
|
result.setTemplateRowId(newVersionTemplate.getRowId());
|
||||||
result.setVersion(newVersionTemplate.getVersion());
|
result.setVersion(newVersionTemplate.getVersion());
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 校验模板状态
|
||||||
|
*/
|
||||||
|
private void validateTemplateStatus(TemplateBenchmark benchmark) {
|
||||||
|
// 当前修改的模板不为最新版
|
||||||
|
if (!Objects.equals(benchmark.getLastTemplate().getId(), benchmark.getBaseTemplate().getId())) {
|
||||||
|
throw new CommonException("该状态的模板不可修改");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 校验模板状态(仅允许草稿/已发布)
|
||||||
|
String status = benchmark.getBaseTemplate().getStatus();
|
||||||
|
if (!"DRAFT".equals(status) && !"COMPLETE".equals(status)) {
|
||||||
|
throw new CommonException("该状态的模板不可修改,仅支持草稿/已发布状态");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建/复用新版本模板
|
||||||
|
*/
|
||||||
|
private Template createOrReuseNewTemplate(TemplateBenchmark benchmark) {
|
||||||
|
Template baseTemplate = benchmark.getBaseTemplate();
|
||||||
|
// 草稿状态复用原模板,已发布创建新版本
|
||||||
|
if ("DRAFT".equals(baseTemplate.getStatus())) {
|
||||||
|
return baseTemplate;
|
||||||
|
} else {
|
||||||
|
Template newTemplate = new Template(
|
||||||
|
benchmark.getLastTemplate().getTemplateName(),
|
||||||
|
calculateNextVersion(benchmark.getLastTemplate().getVersion()),
|
||||||
|
"DRAFT",
|
||||||
|
Timestamp.valueOf(LocalDateTime.now()),
|
||||||
|
null,
|
||||||
|
permissionGetter.getCurrentUserId(),
|
||||||
|
getMaxOrder()
|
||||||
|
);
|
||||||
|
bd.getBusinessDatabase().doInsert(newTemplate);
|
||||||
|
return newTemplate;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private Integer getMaxOrder() {
|
private Integer getMaxOrder() {
|
||||||
Template template = bd.getBusinessDatabase()
|
Template template = bd.getBusinessDatabase()
|
||||||
.viewQueryMode(true)
|
.viewQueryMode(true)
|
||||||
@ -213,14 +230,16 @@ public class ParameterServiceImpl implements ParameterService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional(rollbackFor = CommonException.class)
|
private ParameterProcessingResult processParameters(
|
||||||
public ParameterProcessingResult processParameters(
|
|
||||||
List<ParameterForm> parameterForms,
|
List<ParameterForm> parameterForms,
|
||||||
List<Parameter> existingParameters,
|
List<Parameter> existingParameters,
|
||||||
Template baseTemplate,
|
Template baseTemplate,
|
||||||
Template newTemplate)
|
Template newTemplate)
|
||||||
{
|
{
|
||||||
Map<Integer, Parameter> parameterMap = createParameterMap(existingParameters);
|
Map<String, Parameter> parameterMap = existingParameters.stream()
|
||||||
|
.collect(Collectors.toMap(Parameter::getId, param -> param, (k1, k2) -> {
|
||||||
|
throw new IllegalStateException("发现重复的参数ID: " + k1);
|
||||||
|
}));
|
||||||
|
|
||||||
List<Parameter> newParameters = new ArrayList<>();
|
List<Parameter> newParameters = new ArrayList<>();
|
||||||
List<RevisionRecord> revisionRecords = new ArrayList<>();
|
List<RevisionRecord> revisionRecords = new ArrayList<>();
|
||||||
@ -253,27 +272,10 @@ public class ParameterServiceImpl implements ParameterService {
|
|||||||
return new ParameterProcessingResult(newParameters, revisionRecords);
|
return new ParameterProcessingResult(newParameters, revisionRecords);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Map<Integer, Parameter> createParameterMap(List<Parameter> parameters) {
|
|
||||||
Map<Integer, Parameter> map = new HashMap<>();
|
|
||||||
Set<Integer> duplicateNumbers = new HashSet<>();
|
|
||||||
for (Parameter parameter : parameters) {
|
|
||||||
if (map.containsKey(parameter.getParameterNumber())) {
|
|
||||||
duplicateNumbers.add(parameter.getParameterNumber());
|
|
||||||
} else {
|
|
||||||
map.put(parameter.getParameterNumber(), parameter);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!duplicateNumbers.isEmpty()) {
|
|
||||||
throw new IllegalStateException("发现重复的参数编号: " + duplicateNumbers);
|
|
||||||
}
|
|
||||||
return map;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 处理新增参数
|
* 处理新增参数
|
||||||
*/
|
*/
|
||||||
@Transactional(rollbackFor = CommonException.class)
|
private void handleInsertOperation(
|
||||||
public void handleInsertOperation(
|
|
||||||
ParameterForm form, Template newTemplate,
|
ParameterForm form, Template newTemplate,
|
||||||
List<Parameter> newParameters, List<RevisionRecord> revisionRecords,
|
List<Parameter> newParameters, List<RevisionRecord> revisionRecords,
|
||||||
Template baseTemplate
|
Template baseTemplate
|
||||||
@ -281,6 +283,7 @@ public class ParameterServiceImpl implements ParameterService {
|
|||||||
Parameter newParameter = new Parameter();
|
Parameter newParameter = new Parameter();
|
||||||
BeanUtils.copyProperties(form, newParameter);
|
BeanUtils.copyProperties(form, newParameter);
|
||||||
newParameter.setCreatedBy(permissionGetter.getCurrentUserId());
|
newParameter.setCreatedBy(permissionGetter.getCurrentUserId());
|
||||||
|
newParameter.setId(null);
|
||||||
|
|
||||||
Parameter parameter = bd.getBusinessDatabase()
|
Parameter parameter = bd.getBusinessDatabase()
|
||||||
.viewQueryMode(true)
|
.viewQueryMode(true)
|
||||||
@ -317,13 +320,12 @@ public class ParameterServiceImpl implements ParameterService {
|
|||||||
/**
|
/**
|
||||||
* 处理更新参数
|
* 处理更新参数
|
||||||
*/
|
*/
|
||||||
@Transactional(rollbackFor = CommonException.class)
|
private void handleUpdateOperation(
|
||||||
public void handleUpdateOperation(
|
ParameterForm form, Map<String, Parameter> parameterMap,
|
||||||
ParameterForm form, Map<Integer, Parameter> parameterMap,
|
|
||||||
Template newTemplate, List<Parameter> newParameters,
|
Template newTemplate, List<Parameter> newParameters,
|
||||||
List<RevisionRecord> revisionRecords, Template baseTemplate
|
List<RevisionRecord> revisionRecords, Template baseTemplate
|
||||||
) {
|
) {
|
||||||
Parameter originalParameter = parameterMap.get(form.getParameterNumber());
|
Parameter originalParameter = parameterMap.get(form.getId());
|
||||||
|
|
||||||
if (originalParameter == null) {
|
if (originalParameter == null) {
|
||||||
throw new IllegalArgumentException("未找到要更新的参数,编号: " + form.getParameterNumber());
|
throw new IllegalArgumentException("未找到要更新的参数,编号: " + form.getParameterNumber());
|
||||||
@ -394,11 +396,11 @@ public class ParameterServiceImpl implements ParameterService {
|
|||||||
* 处理删除参数
|
* 处理删除参数
|
||||||
*/
|
*/
|
||||||
private void handleDeleteOperation(
|
private void handleDeleteOperation(
|
||||||
ParameterForm form, Map<Integer, Parameter> parameterMap,
|
ParameterForm form, Map<String, Parameter> parameterMap,
|
||||||
Template newTemplate, List<RevisionRecord> revisionRecords,
|
Template newTemplate, List<RevisionRecord> revisionRecords,
|
||||||
Template baseTemplate
|
Template baseTemplate
|
||||||
) {
|
) {
|
||||||
Parameter deletedParameter = parameterMap.get(form.getParameterNumber());
|
Parameter deletedParameter = parameterMap.get(form.getId());
|
||||||
|
|
||||||
if (deletedParameter != null) {
|
if (deletedParameter != null) {
|
||||||
revisionRecords.add(new RevisionRecord(
|
revisionRecords.add(new RevisionRecord(
|
||||||
@ -418,10 +420,10 @@ public class ParameterServiceImpl implements ParameterService {
|
|||||||
* 处理未修改参数
|
* 处理未修改参数
|
||||||
*/
|
*/
|
||||||
private void handleUnchangedOperation(
|
private void handleUnchangedOperation(
|
||||||
ParameterForm form, Map<Integer, Parameter> parameterMap,
|
ParameterForm form, Map<String, Parameter> parameterMap,
|
||||||
List<Parameter> newParameters
|
List<Parameter> newParameters
|
||||||
) {
|
) {
|
||||||
Parameter unchangedParameter = parameterMap.get(form.getParameterNumber());
|
Parameter unchangedParameter = parameterMap.get(form.getId());
|
||||||
|
|
||||||
if (unchangedParameter != null) {
|
if (unchangedParameter != null) {
|
||||||
newParameters.add(unchangedParameter);
|
newParameters.add(unchangedParameter);
|
||||||
@ -429,14 +431,14 @@ public class ParameterServiceImpl implements ParameterService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public List<Parameter> findUnmatchedParameters(
|
public List<Parameter> findUnmatchedParameters(
|
||||||
Map<Integer, Parameter> parameterMap,
|
Map<String, Parameter> parameterMap,
|
||||||
List<ParameterForm> parameterForms) {
|
List<ParameterForm> parameterForms) {
|
||||||
Set<Integer> formNumbers = parameterForms.parallelStream()
|
Set<String> formIds = parameterForms.stream()
|
||||||
.map(ParameterForm::getParameterNumber)
|
.map(ParameterForm::getId)
|
||||||
.filter(Objects::nonNull)
|
.filter(Objects::nonNull)
|
||||||
.collect(Collectors.toCollection(HashSet::new));
|
.collect(Collectors.toSet());
|
||||||
return parameterMap.entrySet().parallelStream()
|
return parameterMap.entrySet().stream()
|
||||||
.filter(entry -> !formNumbers.contains(entry.getKey()))
|
.filter(entry -> !formIds.contains(entry.getKey()))
|
||||||
.map(Map.Entry::getValue)
|
.map(Map.Entry::getValue)
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|||||||
@ -338,10 +338,13 @@ public class TemplateApprovalServiceImpl implements TemplateApprovalService {
|
|||||||
flow.setFlowStatus("COMPLETE");
|
flow.setFlowStatus("COMPLETE");
|
||||||
flow.setCurrentNode(null);
|
flow.setCurrentNode(null);
|
||||||
template.setStatus("COMPLETE");
|
template.setStatus("COMPLETE");
|
||||||
|
// 将同名的上一个版本的状态改为历史
|
||||||
bd.getBusinessDatabase()
|
bd.getBusinessDatabase()
|
||||||
.eq("template_name", template.getTemplateName())
|
.eq("template_name", template.getTemplateName())
|
||||||
|
.eq("version", template.getVersion()-1)
|
||||||
.update("status", "HISTORY")
|
.update("status", "HISTORY")
|
||||||
.doUpdate(Template.class);
|
.doUpdate(Template.class);
|
||||||
|
// 将当前版本状态改为已发布
|
||||||
bd.getBusinessDatabase()
|
bd.getBusinessDatabase()
|
||||||
.rowid("id", template.getRowId())
|
.rowid("id", template.getRowId())
|
||||||
.update("status", template.getStatus())
|
.update("status", template.getStatus())
|
||||||
@ -395,8 +398,7 @@ public class TemplateApprovalServiceImpl implements TemplateApprovalService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional(rollbackFor = CommonException.class)
|
private void cancelProcess(ApprovalFlow flow, String status) {
|
||||||
public void cancelProcess(ApprovalFlow flow, String status) {
|
|
||||||
// 更新流程状态
|
// 更新流程状态
|
||||||
flow.setFlowStatus(status);
|
flow.setFlowStatus(status);
|
||||||
bd.getBusinessDatabase()
|
bd.getBusinessDatabase()
|
||||||
|
|||||||
@ -176,7 +176,7 @@ public class TemplateServiceImpl implements TemplateService {
|
|||||||
if (form.isTemplateEmpty()) {
|
if (form.isTemplateEmpty()) {
|
||||||
list = bd.getBusinessDatabase()
|
list = bd.getBusinessDatabase()
|
||||||
.viewQueryMode(true)
|
.viewQueryMode(true)
|
||||||
.view("selectParametersByTemplateId")
|
.view("selectParametersByTId")
|
||||||
.setVar("templateId", templateDB.getId())
|
.setVar("templateId", templateDB.getId())
|
||||||
.select("parameterName", "parameterNumber")
|
.select("parameterName", "parameterNumber")
|
||||||
.orderBy("parameterNumber", "asc")
|
.orderBy("parameterNumber", "asc")
|
||||||
@ -184,7 +184,7 @@ public class TemplateServiceImpl implements TemplateService {
|
|||||||
} else {
|
} else {
|
||||||
list = bd.getBusinessDatabase()
|
list = bd.getBusinessDatabase()
|
||||||
.viewQueryMode(true)
|
.viewQueryMode(true)
|
||||||
.view("selectParametersByTemplateId")
|
.view("selectParametersByTId")
|
||||||
.setVar("templateId", templateDB.getId())
|
.setVar("templateId", templateDB.getId())
|
||||||
.orderBy("parameterNumber", "asc")
|
.orderBy("parameterNumber", "asc")
|
||||||
.doQuery(Parameter.class);
|
.doQuery(Parameter.class);
|
||||||
|
|||||||
@ -121,3 +121,11 @@ DELETE FROM yfsjglpt_model_approval_record;
|
|||||||
DELETE FROM yfsjglpt_model_responsible_person;
|
DELETE FROM yfsjglpt_model_responsible_person;
|
||||||
DELETE FROM yfsjglpt_model_benchmarking_report;
|
DELETE FROM yfsjglpt_model_benchmarking_report;
|
||||||
DELETE FROM yfsjglpt_model_revision_record;
|
DELETE FROM yfsjglpt_model_revision_record;
|
||||||
|
|
||||||
|
delete from data_entry_engine_model;
|
||||||
|
delete from engine_param_detail;
|
||||||
|
delete from todo_task;
|
||||||
|
delete from data_change_comment;
|
||||||
|
delete from approval_config ;
|
||||||
|
delete from engine_review_list;
|
||||||
|
delete from param_approval_record;
|
||||||
Loading…
x
Reference in New Issue
Block a user