修复:快照合并分析图并支持导出订单对应表

快照将不良构成与柏拉图合并为一个选项,完整保留页面容器,黑片和亮片继续并排展示两张分析图;迁移旧快照选项并等待组合图的数据准备完成。

销售订单类型对应表支持下载当前生效版本的完整Excel,订单号按文本写入,保留前导零,沿用管理员角色与来源字段权限。导出开始时固定版本,使用滚动工作簿限制内存。

菜单、页面及快照标题统一改为黑片数据和亮片数据。

验证:11项前端检查、8项后端单元测试通过;157698条实际对应关系与数据库逐条一致,重新导入预览零变更;黑片完整快照和亮片单模块快照均通过视觉检查。
This commit is contained in:
2026-11-04 09:06:07 +08:00
parent 80cd9e79eb
commit 147b56d0fd
11 changed files with 133 additions and 20 deletions
@@ -3,6 +3,9 @@ package cn.yunsheng.quality.filters;
import cn.yunsheng.quality.governance.GovernanceAccessService;
import cn.yunsheng.quality.identity.AppUserPrincipal;
import java.util.Map;
import java.nio.charset.StandardCharsets;
import org.springframework.http.*;
import org.springframework.web.servlet.mvc.method.annotation.StreamingResponseBody;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.*;
@@ -20,6 +23,14 @@ public class SalesOrderTypeController {
if(!SalesOrderTypes.allowed(governance.allowedFields(actor)))throw new org.springframework.web.server.ResponseStatusException(org.springframework.http.HttpStatus.FORBIDDEN,"没有销售订单来源字段权限");
}
@GetMapping public Map<String,Object> status(@AuthenticationPrincipal AppUserPrincipal actor) { authorize(actor);return service.status(); }
@GetMapping("/export") public ResponseEntity<StreamingResponseBody> export(@AuthenticationPrincipal AppUserPrincipal actor) {
authorize(actor);
String version=service.versionForExport();
StreamingResponseBody body=output->service.writeExport(version,output);
return ResponseEntity.ok().contentType(MediaType.parseMediaType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"))
.header(HttpHeaders.CONTENT_DISPOSITION,ContentDisposition.attachment().filename("销售订单类型对应表.xlsx",StandardCharsets.UTF_8).build().toString())
.header(HttpHeaders.CACHE_CONTROL,"no-store").body(body);
}
@PostMapping("/preview") public Map<String,Object> preview(@RequestParam MultipartFile file,@RequestParam(defaultValue="MERGE") String mode,@AuthenticationPrincipal AppUserPrincipal actor) { authorize(actor);return service.preview(file,mode); }
@PostMapping("/import") public Map<String,Object> importFile(@RequestParam MultipartFile file,@RequestParam String mode,@RequestParam(defaultValue="") String expectedVersion,@RequestParam String sha256,@AuthenticationPrincipal AppUserPrincipal actor) { authorize(actor);return service.importFile(file,mode,expectedVersion,sha256,actor); }
public record Activation(String versionId,String expectedVersion) {}
@@ -5,6 +5,8 @@ import java.io.*;
import java.security.MessageDigest;
import java.util.*;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
import org.springframework.http.HttpStatus;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
@@ -66,6 +68,30 @@ public class SalesOrderTypeService {
if(version!=null&&!version.isBlank())jdbc.query("SELECT order_no,order_type FROM sales_order_type_entry WHERE version_id=? ORDER BY order_no",(org.springframework.jdbc.core.RowCallbackHandler)rs->result.put(rs.getString(1),rs.getString(2)),version);
return result;
}
public String versionForExport() {
String version=current(false);
if(version==null||version.isBlank())throw new ResponseStatusException(HttpStatus.NOT_FOUND,"尚未导入销售订单类型对应表");
return version;
}
@Transactional(readOnly=true)
public void writeExport(String version,OutputStream output) throws IOException {
try(SXSSFWorkbook workbook=new SXSSFWorkbook(200)) {
workbook.setCompressTempFiles(true);
Sheet sheet=workbook.createSheet("销售订单类型对应");
sheet.createFreezePane(0,1);sheet.setColumnWidth(0,28*256);sheet.setColumnWidth(1,28*256);
CellStyle textStyle=workbook.createCellStyle();textStyle.setDataFormat(workbook.createDataFormat().getFormat("@"));
sheet.setDefaultColumnStyle(0,textStyle);sheet.setDefaultColumnStyle(1,textStyle);
Row header=sheet.createRow(0);header.createCell(0).setCellValue("销售订单编号");header.createCell(1).setCellValue("销售订单类型");
int[] index={1};
// 导出开始时固定版本,后续更新对应表不会混入本次下载。订单号始终写成文本。
jdbc.query("SELECT order_no,order_type FROM sales_order_type_entry WHERE version_id=? ORDER BY order_no",(org.springframework.jdbc.core.RowCallbackHandler)rs->{
Row row=sheet.createRow(index[0]++);
for(int column=0;column<2;column++){Cell cell=row.createCell(column,CellType.STRING);cell.setCellValue(rs.getString(column+1));cell.setCellStyle(textStyle);}
},version);
sheet.setAutoFilter(new CellRangeAddress(0,index[0]-1,0,1));
workbook.write(output);
}
}
private static void requireMode(String mode) {
if(!Set.of("MERGE","REPLACE").contains(mode))throw QueryFilterFields.bad("请选择增量更新或整表替换");
}