修改:对标报告保存功能和模板顺序调整 v2.0

This commit is contained in:
zjh 2025-12-18 15:57:58 +08:00
parent f7e5813d5b
commit 282924dd85
7 changed files with 33 additions and 123 deletions

View File

@ -23,7 +23,6 @@ public class SheetDataListener implements ReadListener<Parameter> {
private List<Parameter> cachedDataList;
private String currentSheetName;
MyResponse problems;
Integer maxOrder;
// 用于存储表头
private Set<String> actualHeaders = new HashSet<>();
@ -35,14 +34,13 @@ public class SheetDataListener implements ReadListener<Parameter> {
private boolean validSheet = false;
public SheetDataListener(TemplateService templateService,
String templateRowId, String createBy, MyResponse problems, Integer maxOrder) {
String templateRowId, String createBy, MyResponse problems) {
this.templateService = templateService;
this.templateRowId = templateRowId;
this.createBy = createBy;
this.cachedDataList = new ArrayList<>(BATCH_SIZE);
this.problems = problems;
this.requiredHeaders = getIncludeColumnFieldNames();
this.maxOrder = maxOrder;
}
@Override
@ -104,8 +102,7 @@ public class SheetDataListener implements ReadListener<Parameter> {
currentSheetName,
templateRowId,
createBy,
problems,
maxOrder
problems
);
cachedDataList.clear();
}
@ -147,7 +144,6 @@ public class SheetDataListener implements ReadListener<Parameter> {
headerChecked = false;
validSheet = false;
actualHeaders.clear();
maxOrder += 1;
}
private static Set<String> getIncludeColumnFieldNames() {

View File

@ -35,14 +35,14 @@ public class Template extends MpaasBasePojo {
private Timestamp createdTime;
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Timestamp publishedTime;
private Integer orderNum;
private Long orderNum;
private String createBy;
@Column(type = ColumnType.CALCULATE)
private Integer maxOrder;
public Template(String templateName, Integer version, String status, Timestamp createdTime, Timestamp publishedTime, String createBy, Integer orderNum) {
public Template(String templateName, Integer version, String status, Timestamp createdTime, Timestamp publishedTime, String createBy, Long orderNum) {
this.templateName = templateName;
this.version = version;
this.status = status;

View File

@ -10,11 +10,11 @@ import java.util.List;
@SQLQuery(value = {
@SQL(view = "getAllReportApproval",
sql = "SELECT br.id AS \"reportId\", af.id AS \"flowId\", br.* FROM yfsjglpt_model_approval_flow af JOIN yfsjglpt_model_benchmarking_report br ON af.template_id = br.id WHERE br.is_delete = 0 and br.title like CONCAT('%', #title, '%') and br.manufacturer_name like CONCAT('%', #manufacturerName, '%') and br.model_name like CONCAT('%', #modelName, '%') and br.product_number like CONCAT('%', #productNumber, '%') and br.module like CONCAT('%', #module, '%') and br.plate like CONCAT('%', #plate, '%') and br.platform like CONCAT('%', #platform, '%') and br.series like CONCAT('%', #series, '%') and br.market_segment like CONCAT('%', #marketSegment, '%') and br.project_name like CONCAT('%', #projectName, '%') and br.project_number like CONCAT('%', #projectNumber, '%') and br.status like CONCAT('%', #status, '%') and af.flow_type = 2 ORDER BY CASE br.status WHEN 'COMPLETE' THEN 1 WHEN 'APPROVING' THEN 2 WHEN 'REJECTED' THEN 3 ELSE 4 END ASC"),
sql = "SELECT br.id AS \"reportId\", af.id AS \"flowId\", br.* FROM yfsjglpt_model_approval_flow af RIGHT JOIN yfsjglpt_model_benchmarking_report br ON af.template_id = br.id AND af.flow_type = 2 WHERE br.is_delete = 0 and br.title like CONCAT('%', #title, '%') and br.manufacturer_name like CONCAT('%', #manufacturerName, '%') and br.model_name like CONCAT('%', #modelName, '%') and br.product_number like CONCAT('%', #productNumber, '%') and br.module like CONCAT('%', #module, '%') and br.plate like CONCAT('%', #plate, '%') and br.platform like CONCAT('%', #platform, '%') and br.series like CONCAT('%', #series, '%') and br.market_segment like CONCAT('%', #marketSegment, '%') and br.project_name like CONCAT('%', #projectName, '%') and br.project_number like CONCAT('%', #projectNumber, '%') and br.status like CONCAT('%', #status, '%') ORDER BY CASE br.status WHEN 'COMPLETE' THEN 1 WHEN 'APPROVING' THEN 2 WHEN 'REJECTED' THEN 3 ELSE 4 END ASC"),
@SQL(view = "getReportByUserIdAndIds",
sql = "SELECT br.id AS \"reportId\", af.id AS \"flowId\", br.* FROM yfsjglpt_model_approval_flow af JOIN yfsjglpt_model_benchmarking_report br ON af.template_id = br.id WHERE br.title like CONCAT('%', #title, '%') and br.manufacturer_name like CONCAT('%', #manufacturerName, '%') and br.model_name like CONCAT('%', #modelName, '%') and br.product_number like CONCAT('%', #productNumber, '%') and br.module like CONCAT('%', #module, '%') and br.plate like CONCAT('%', #plate, '%') and br.platform like CONCAT('%', #platform, '%') and br.series like CONCAT('%', #series, '%') and br.market_segment like CONCAT('%', #marketSegment, '%') and br.project_name like CONCAT('%', #projectName, '%') and br.project_number like CONCAT('%', #projectNumber, '%') and br.status like CONCAT('%', #status, '%') and af.flow_type = 2 AND af.id NOT IN (#ids) AND af.create_by = #createBy"),
sql = "SELECT br.id AS \"reportId\", af.id AS \"flowId\", br.* FROM yfsjglpt_model_approval_flow af LEFT JOIN yfsjglpt_model_benchmarking_report br ON af.template_id = br.id WHERE br.title like CONCAT('%', #title, '%') and br.manufacturer_name like CONCAT('%', #manufacturerName, '%') and br.model_name like CONCAT('%', #modelName, '%') and br.product_number like CONCAT('%', #productNumber, '%') and br.module like CONCAT('%', #module, '%') and br.plate like CONCAT('%', #plate, '%') and br.platform like CONCAT('%', #platform, '%') and br.series like CONCAT('%', #series, '%') and br.market_segment like CONCAT('%', #marketSegment, '%') and br.project_name like CONCAT('%', #projectName, '%') and br.project_number like CONCAT('%', #projectNumber, '%') and br.status like CONCAT('%', #status, '%') and af.flow_type = 2 AND af.id NOT IN (#ids) AND af.create_by = #createBy"),
@SQL(view = "getTodoAndReport",
sql = "SELECT br.id AS \"reportId\", af.id AS \"flowId\", br.* FROM yfsjglpt_model_approval_flow af JOIN yfsjglpt_model_benchmarking_report br ON af.template_id = br.id WHERE br.title like CONCAT('%', #title, '%') and br.manufacturer_name like CONCAT('%', #manufacturerName, '%') and br.model_name like CONCAT('%', #modelName, '%') and br.product_number like CONCAT('%', #productNumber, '%') and br.module like CONCAT('%', #module, '%') and br.plate like CONCAT('%', #plate, '%') and br.platform like CONCAT('%', #platform, '%') and br.series like CONCAT('%', #series, '%') and br.market_segment like CONCAT('%', #marketSegment, '%') and br.project_name like CONCAT('%', #projectName, '%') and br.project_number like CONCAT('%', #projectNumber, '%') and br.status like CONCAT('%', #status, '%') and af.flow_type = 2 AND (af.id IN (#ids) OR af.create_by = #createBy) ORDER BY CASE br.status WHEN 'COMPLETE' THEN 1 WHEN 'APPROVING' THEN 2 WHEN 'REJECTED' THEN 3 ELSE 4 END ASC")
sql = "SELECT br.id AS \"reportId\", af.id AS \"flowId\", br.* FROM yfsjglpt_model_approval_flow af LEFT JOIN yfsjglpt_model_benchmarking_report br ON af.template_id = br.id WHERE br.title like CONCAT('%', #title, '%') and br.manufacturer_name like CONCAT('%', #manufacturerName, '%') and br.model_name like CONCAT('%', #modelName, '%') and br.product_number like CONCAT('%', #productNumber, '%') and br.module like CONCAT('%', #module, '%') and br.plate like CONCAT('%', #plate, '%') and br.platform like CONCAT('%', #platform, '%') and br.series like CONCAT('%', #series, '%') and br.market_segment like CONCAT('%', #marketSegment, '%') and br.project_name like CONCAT('%', #projectName, '%') and br.project_number like CONCAT('%', #projectNumber, '%') and br.status like CONCAT('%', #status, '%') and af.flow_type = 2 AND (af.id IN (#ids) OR af.create_by = #createBy) ORDER BY CASE br.status WHEN 'COMPLETE' THEN 1 WHEN 'APPROVING' THEN 2 WHEN 'REJECTED' THEN 3 ELSE 4 END ASC")
})
@Data
public class TodoAndReportView {

View File

@ -1,99 +0,0 @@
package com.xdap.self_development.schedule;
import com.alibaba.fastjson2.JSON;
import com.xdap.self_development.config.BusinessDatabase;
import com.xdap.self_development.exception.CommonException;
import com.xdap.self_development.pojo.ApprovalFlow;
import com.xdap.self_development.pojo.ApprovalRecord;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
@Service
@Slf4j
@Transactional(rollbackFor = CommonException.class)
public class ModifiedTodoTimer {
@Resource
private BusinessDatabase bd;
@Autowired
private StringRedisTemplate redisTemplate;
private static final String TODO_PREFIX = "approval:todo:";
private static final String TODO_PREFIX_2 = "report:todo:";
private static final String NODE_PROCESSED_PREFIX = "approval:node:processed:";
private static final String NODE_PROCESSED_PREFIX_2 = "report:node:processed:";
// @Scheduled(cron = "0 */1 * * * *")
public void modifiedTodo() {
// 获取审批中的所有流程
List<ApprovalFlow> flows1 = bd.getBusinessDatabase()
.eq("flow_status", "APPROVING")
.eq("flow_type", 1)
.doQuery(ApprovalFlow.class);
checkFlows(flows1, TODO_PREFIX, NODE_PROCESSED_PREFIX);
List<ApprovalFlow> flows2 = bd.getBusinessDatabase()
.eq("flow_status", "APPROVING")
.eq("flow_type", 2)
.doQuery(ApprovalFlow.class);
checkFlows(flows2, TODO_PREFIX_2, NODE_PROCESSED_PREFIX_2);
}
// 检查流程
private void checkFlows(List<ApprovalFlow> flows, String todoFlag, String prefixFlag) {
// 遍历每一个流程
flows.forEach(flow -> {
List<String> nodeUsers = getNodeUsers(flow, flow.getCurrentNode());
List<String> records = bd.getBusinessDatabase()
.eq("flow_id", flow.getId())
.eq("node", flow.getCurrentNode())
.doQuery(ApprovalRecord.class)
.stream().map(ApprovalRecord::getUserId)
.collect(Collectors.toList());
if (Objects.equals(flow.getCurrentNode(), "COUNTERSIGN")) {
log.info("{}审批流的COUNTERSIGN的已完成的人{}", flow.getId(), records);
records.forEach(record -> {
Boolean isMember = redisTemplate.opsForSet()
.isMember(prefixFlag + flow.getId() + ":" + flow.getCurrentNode(), record);
if (Boolean.FALSE.equals(isMember)) {
redisTemplate.opsForSet().add(prefixFlag + flow.getId() + ":" + flow.getCurrentNode(), record);
}
});
}
// 未完成当前节点审批任务的人
List<String> collected = nodeUsers.stream()
.filter(element -> !records.contains(element))
.collect(Collectors.toList());
collected.forEach(element -> {
// 检查redis是否存在该待办节点
Boolean isMember = redisTemplate.opsForSet().isMember(todoFlag + element, flow.getId());
log.info("{}{} is member: {}", todoFlag + element, flow.getId(), isMember);
if (Boolean.FALSE.equals(isMember)) {
redisTemplate.opsForSet().add(todoFlag + element, flow.getId());
log.info("{}{} is added", todoFlag, element);
}
});
});
}
private List<String> getNodeUsers(ApprovalFlow flow, String node) {
switch (node) {
case "PROOFREAD": return JSON.parseArray(flow.getProofreadUsers()).toJavaList(String.class);
case "REVIEW": return JSON.parseArray(flow.getReviewUsers()).toJavaList(String.class);
case "COUNTERSIGN": return JSON.parseArray(flow.getCountersignUsers()).toJavaList(String.class);
case "APPROVE": return JSON.parseArray(flow.getApproveUsers()).toJavaList(String.class);
default: return Collections.emptyList();
}
}
}

View File

@ -17,7 +17,7 @@ public interface TemplateService {
MyResponse importTemplate(MultipartFile file, String templateRowId, String userId);
void processSheetData(List<Parameter> dataList, String sheetName,
String templateRowId, String createBy, MyResponse problems,Integer maxOrder);
String templateRowId, String createBy, MyResponse problems);
void insertTemplate(InsertTemplateForm form);

View File

@ -94,7 +94,7 @@ public class EngineParamDetailServiceImpl implements EngineParamDetailService {
)
));
ArrayList<Template> templatesMax = new ArrayList<>(latestTemplateMap.values());
Map<String, Integer> systemOrderMap = templatesMax.stream()
Map<String, Long> systemOrderMap = templatesMax.stream()
.collect(Collectors.toMap(
Template::getTemplateName, // key: 子系统编码
Template::getOrderNum, // value: 排序号
@ -109,7 +109,7 @@ public class EngineParamDetailServiceImpl implements EngineParamDetailService {
)
));
if (ObjectUtils.isNotEmpty(modelID)) {
systemOrderMap.put("整车参数", 0);
systemOrderMap.put("整车参数", (long) 0);
DataEntryEngineModelPojo dataEntryEngineModelPojo = dataEntryEngineModelService.selectBymodelId(modelID);
//状态代号
String productNumber = dataEntryEngineModelPojo.getProductNumber();
@ -153,7 +153,7 @@ public class EngineParamDetailServiceImpl implements EngineParamDetailService {
}
HashMap<String, List<String>> sortedCollect2 = collect.entrySet().stream()
.sorted(Comparator.comparing(entry ->
systemOrderMap.getOrDefault(entry.getKey(), Integer.MAX_VALUE)
systemOrderMap.getOrDefault(entry.getKey(), Long.MAX_VALUE)
))
.collect(Collectors.toMap(
Map.Entry::getKey,

View File

@ -28,6 +28,7 @@ import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@Service
@Slf4j
@ -62,7 +63,7 @@ public class TemplateServiceImpl implements TemplateService {
// 创建新模板
Template newTemplate = new Template(
form.getTemplateName(), 1, "DRAFT", Timestamp.valueOf(LocalDateTime.now()),
null, form.getUserId(), getMaxOrder()
null, form.getUserId(), System.currentTimeMillis()
);
bd.getBusinessDatabase().doInsert(newTemplate);
@ -79,24 +80,36 @@ public class TemplateServiceImpl implements TemplateService {
if (template != null) {
if (Objects.equals(form.getTemplateName(), template.getTemplateName()) && form.getOrderNum() != null) {
List<Long> sorted = bd.getBusinessDatabase()
.groupBy("order_num")
.orderBy("order_num", "asc")
.doQuery(Template.class)
.stream().map(Template::getOrderNum)
.collect(Collectors.toList());
Long num = sorted.get(form.getOrderNum());
if (num == null) {
num = sorted.get(sorted.size() - 1);
}
List<String> originalTemplateId = bd.getBusinessDatabase()
.eq("order_num", template.getOrderNum())
.doQuery(Template.class).stream().map(Template::getId)
.collect(Collectors.toList());
List<String> updateTemplateId = bd.getBusinessDatabase()
.eq("order_num", form.getOrderNum())
.eq("order_num", num)
.doQuery(Template.class).stream().map(Template::getId)
.collect(Collectors.toList());
if (updateTemplateId.isEmpty()) {
bd.getBusinessDatabase()
.in("id", updateTemplateId)
.update("order_num", getMaxOrder())
.update("order_num", template.getOrderNum())
.doUpdate(Template.class);
} else {
bd.getBusinessDatabase()
.in("id", updateTemplateId)
.update("order_num", template.getOrderNum())
.update("order_num", num)
.doUpdate(Template.class);
bd.getBusinessDatabase()
.in("id", originalTemplateId)
@ -110,7 +123,7 @@ public class TemplateServiceImpl implements TemplateService {
Template newTemplate = new Template(
form.getTemplateName(), 1, "DRAFT", Timestamp.valueOf(LocalDateTime.now()),
null, form.getUserId(), 1
null, form.getUserId(), System.currentTimeMillis()
);
bd.getBusinessDatabase()
@ -140,7 +153,7 @@ public class TemplateServiceImpl implements TemplateService {
EasyExcel.read(
inputStream,
Parameter.class,
new SheetDataListener(this, templateRowId, userId, problems, maxOrder)
new SheetDataListener(this, templateRowId, userId, problems)
).doReadAll();
} catch (IOException e) {
@ -226,7 +239,7 @@ public class TemplateServiceImpl implements TemplateService {
@Override
public void processSheetData(List<Parameter> dataList, String sheetName,
String templateRowId, String createBy, MyResponse problems, Integer maxOrder) {
String templateRowId, String createBy, MyResponse problems) {
if (dataList.isEmpty()) {
log.warn("Sheet {} 没有数据", sheetName);
return;
@ -297,7 +310,7 @@ public class TemplateServiceImpl implements TemplateService {
default:
lastTemplate = new Template(
templateName, lastTemplate.getVersion()+1, "DRAFT",
Timestamp.valueOf(LocalDateTime.now()), null, createBy, maxOrder
Timestamp.valueOf(LocalDateTime.now()), null, createBy, System.currentTimeMillis()
);
bd.getBusinessDatabase()
.doInsert(lastTemplate);
@ -305,7 +318,7 @@ public class TemplateServiceImpl implements TemplateService {
} else {
lastTemplate = new Template(
templateName, 1, "DRAFT", Timestamp.valueOf(LocalDateTime.now()),
null, createBy, maxOrder
null, createBy, System.currentTimeMillis()
);
bd.getBusinessDatabase()
.doInsert(lastTemplate);