From c712995e79c5527fd2b8fac12b64e9893a22b984 Mon Sep 17 00:00:00 2001 From: zjh <15615273395@163.com> Date: Fri, 26 Dec 2025 15:28:17 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9:=E6=A8=A1=E6=9D=BF=E5=BA=8F?= =?UTF-8?q?=E5=8F=B7=E5=B0=8F=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../xdap/self_development/pojo/Template.java | 3 +- .../pojo/view/TodoAndReportView.java | 3 +- .../impl/BenchmarkingReportServiceImpl.java | 5 +- .../service/impl/TemplateServiceImpl.java | 133 ++++++++++-------- 4 files changed, 82 insertions(+), 62 deletions(-) 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 4ad6126..11c6dc5 100644 --- a/src/main/java/com/xdap/self_development/pojo/Template.java +++ b/src/main/java/com/xdap/self_development/pojo/Template.java @@ -15,7 +15,8 @@ import java.sql.Timestamp; // 查找每个模板的最新版本并且优先级按照已发布、审核中、草稿状态转变(只有这三种状态) // CASE ranked.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(view = "getLatestTemplate", - sql = "SELECT ROW_NUMBER() OVER (ORDER BY CASE ranked.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) AS 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 ranked.order_num DESC" + sql = "SELECT ROW_NUMBER() OVER (ORDER BY ranked.order_num DESC) AS display_order_num, ranked.id, ranked.template_name, ranked.version , ranked.status, ranked.created_time, ranked.published_time, ROW_NUMBER() OVER (ORDER BY ranked.order_num DESC) AS order_num , 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 ranked.order_num DESC" +// sql = "SELECT ROW_NUMBER() OVER (ORDER BY CASE ranked.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) AS 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 ranked.order_num DESC" ), // 获取所有模板的最新版本号(包括所有状态) @SQL(view = "getNewTemplate", diff --git a/src/main/java/com/xdap/self_development/pojo/view/TodoAndReportView.java b/src/main/java/com/xdap/self_development/pojo/view/TodoAndReportView.java index b679336..e6b3732 100644 --- a/src/main/java/com/xdap/self_development/pojo/view/TodoAndReportView.java +++ b/src/main/java/com/xdap/self_development/pojo/view/TodoAndReportView.java @@ -10,11 +10,12 @@ import java.sql.Timestamp; @SQLQuery(value = { // CASE br.status WHEN 'COMPLETE' THEN 1 WHEN 'APPROVING' THEN 2 WHEN 'REJECTED' THEN 3 ELSE 4 END ASC , @SQL(view = "getAllReport", - sql = "SELECT br.id AS \"reportId\", br.* FROM yfsjglpt_model_benchmarking_report br 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 br.upload_time DESC") + sql = "SELECT br.id AS \"reportId\", br.*, af.id AS \"flowId\" FROM yfsjglpt_model_benchmarking_report br LEFT JOIN yfsjglpt_model_approval_flow af 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, '%') ORDER BY br.upload_time DESC") }) @Data public class TodoAndReportView { private String reportId; + private String flowId; private String title; private String manufacturerName; diff --git a/src/main/java/com/xdap/self_development/service/impl/BenchmarkingReportServiceImpl.java b/src/main/java/com/xdap/self_development/service/impl/BenchmarkingReportServiceImpl.java index c72b5d5..a63d13d 100644 --- a/src/main/java/com/xdap/self_development/service/impl/BenchmarkingReportServiceImpl.java +++ b/src/main/java/com/xdap/self_development/service/impl/BenchmarkingReportServiceImpl.java @@ -246,8 +246,8 @@ public class BenchmarkingReportServiceImpl implements BenchmarkingReportService BenchmarkingReport report = bd.getBusinessDatabase() .eq("id", form.getReportId()) .doQueryFirst(BenchmarkingReport.class); - if (!Objects.equals(report.getStatus(), "DRAFT")) { - throw new CommonException("报告非草稿状态不可修改"); + if (!"DRAFT".equals(report.getStatus()) && !"REJECT".equals(report.getStatus())) { + throw new CommonException("报告非草稿或拒绝状态不可修改"); } if (!Objects.equals(report.getCreateBy(), form.getUserId())) { throw new CommonException("非创建者不能修改"); @@ -255,6 +255,7 @@ public class BenchmarkingReportServiceImpl implements BenchmarkingReportService BeanUtils.copyProperties(form, report); report.setFilePath(form.getFileUrl() == null ? "" : form.getFileUrl()); report.setUploadTime(Timestamp.valueOf(LocalDateTime.now())); + report.setStatus("DRAFT"); bd.getBusinessDatabase() .eq("id", report.getId()) .doUpdate(report); 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 655a508..85cffe8 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 @@ -83,56 +83,56 @@ public class TemplateServiceImpl implements TemplateService { .doQueryFirst(Template.class); if (template != null) { -// if (Objects.equals(form.getTemplateName(), template.getTemplateName()) && form.getOrderNum() != null) { -// List sorted = bd.getBusinessDatabase() -// .groupBy("order_num") -// .orderBy("order_num", "desc") -// .doQuery(Template.class) -// .stream().map(Template::getOrderNum) -// .collect(Collectors.toList()); -// -// Long num = sorted.get(form.getOrderNum() - 1); -// if (num == null) { -// num = sorted.get(sorted.size() - 1); -// } -// -// List originalTemplateId = bd.getBusinessDatabase() -// .eq("order_num", template.getOrderNum()) -// .doQuery(Template.class).stream().map(Template::getId) -// .collect(Collectors.toList()); -// List updateTemplateId = bd.getBusinessDatabase() -// .eq("order_num", num) -// .doQuery(Template.class).stream().map(Template::getId) -// .collect(Collectors.toList()); -// -// if (updateTemplateId.isEmpty()) { -// bd.getBusinessDatabase() -// .in("id", originalTemplateId) -// .update("order_num", System.currentTimeMillis()) -// .doUpdate(Template.class); -// } else { -// bd.getBusinessDatabase() -// .in("id", updateTemplateId) -// .update("order_num", template.getOrderNum()) -// .doUpdate(Template.class); -// bd.getBusinessDatabase() -// .in("id", originalTemplateId) -// .update("order_num", num) -// .doUpdate(Template.class); -// } -// return; -// } + if (Objects.equals(form.getTemplateName(), template.getTemplateName()) && form.getOrderNum() != null) { + List sorted = bd.getBusinessDatabase() + .groupBy("order_num") + .orderBy("order_num", "desc") + .doQuery(Template.class) + .stream().map(Template::getOrderNum) + .collect(Collectors.toList()); + + Long num = sorted.get(form.getOrderNum() - 1); + if (num == null) { + num = sorted.get(sorted.size() - 1); + } + + List originalTemplateId = bd.getBusinessDatabase() + .eq("order_num", template.getOrderNum()) + .doQuery(Template.class).stream().map(Template::getId) + .collect(Collectors.toList()); + List updateTemplateId = bd.getBusinessDatabase() + .eq("order_num", num) + .doQuery(Template.class).stream().map(Template::getId) + .collect(Collectors.toList()); + + if (updateTemplateId.isEmpty()) { + bd.getBusinessDatabase() + .in("id", originalTemplateId) + .update("order_num", System.currentTimeMillis()) + .doUpdate(Template.class); + } else { + bd.getBusinessDatabase() + .in("id", updateTemplateId) + .update("order_num", template.getOrderNum()) + .doUpdate(Template.class); + bd.getBusinessDatabase() + .in("id", originalTemplateId) + .update("order_num", num) + .doUpdate(Template.class); + } + return; + } throw new CommonException("不可修改为已有模板"); } - - Template newTemplate = new Template( - form.getTemplateName(), 1, "DRAFT", Timestamp.valueOf(LocalDateTime.now()), - null, form.getUserId(), System.currentTimeMillis(), 0 - ); + String templateName = bd.getBusinessDatabase() + .rowid("id", form.getTemplateRowId()) + .doQueryFirst(Template.class) + .getTemplateName(); bd.getBusinessDatabase() - .rowid("id", form.getTemplateRowId()) - .doUpdate(newTemplate); + .eq("template_name", templateName) + .update("template_name", form.getTemplateName()) + .doUpdate(Template.class); } @Override @@ -604,21 +604,38 @@ public class TemplateServiceImpl implements TemplateService { .eq("status", "COMPLETE") .doQuery(Template.class); - try (ExcelWriter excelWriter = EasyExcel.write(response.getOutputStream(), Parameter.class) - .registerWriteHandler(new LongestMatchColumnWidthStyleStrategy()) - .includeColumnFieldNames(getIncludeColumnFieldNames()) - .build()) { + if (templates.isEmpty()) { + try { + List list = new ArrayList<>(); + list.add(new Parameter()); - for (Template template : templates) { - List parameters = new ArrayList<>(); - parameters.add(new Parameter()); + EasyExcel.write(response.getOutputStream(), Parameter.class) + .registerWriteHandler(new LongestMatchColumnWidthStyleStrategy()) + .includeColumnFieldNames(getIncludeColumnFieldNames()) + .sheet("xxx") + .doWrite(list); + } catch (Exception e) { + throw new CommonException("导出Excel失败: " + e.getMessage()); + } + } else { + try (ExcelWriter excelWriter = EasyExcel.write(response.getOutputStream(), Parameter.class) + .registerWriteHandler(new LongestMatchColumnWidthStyleStrategy()) + .includeColumnFieldNames(getIncludeColumnFieldNames()) + .build()) { - WriteSheet writeSheet = EasyExcel - .writerSheet(template.getTemplateName()) - .build(); + for (Template template : templates) { + List parameters = new ArrayList<>(); + parameters.add(new Parameter()); - // 写入数据到对应的sheet - excelWriter.write(parameters, writeSheet); + WriteSheet writeSheet = EasyExcel + .writerSheet(template.getTemplateName()) + .build(); + + // 写入数据到对应的sheet + excelWriter.write(parameters, writeSheet); + } + } catch (Exception e) { + throw new CommonException("导出Excel失败: " + e.getMessage()); } } } catch (Exception e) {