From cccbfadcb6e96c23a33c40c0687a27c2f6efa1db Mon Sep 17 00:00:00 2001
From: 云 <2163098428@qq.com>
Date: 星期一, 09 十一月 2026 13:16:42 +0800
Subject: [PATCH] feat(seal): 添加印章详情及图片预览功能

---
 yudao-module-mes/src/test/java/cn/iocoder/yudao/module/mes/service/pd/seal/PdSealServiceTest.java         |   16 ++++++++++++++++
 yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/pd/seal/PdSealService.java             |    5 +++++
 yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/pd/seal/PdSealController.java |    8 ++++++++
 3 files changed, 29 insertions(+), 0 deletions(-)

diff --git a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/pd/seal/PdSealController.java b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/pd/seal/PdSealController.java
index 4ad968d..4291a36 100644
--- a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/pd/seal/PdSealController.java
+++ b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/pd/seal/PdSealController.java
@@ -20,6 +20,14 @@
     @Resource private MesPdProjectController projectController;
     @GetMapping("/list") @PreAuthorize("@ss.hasPermission('mes:pd-seal:manage')")
     public CommonResult<List<Map<String,Object>>> list(){ return success(service.seals(false)); }
+    @GetMapping("/image") @PreAuthorize("@ss.hasPermission('mes:pd-seal:manage')")
+    public void image(@RequestParam long id, HttpServletResponse response) throws java.io.IOException {
+        byte[] image = service.getImage(id);
+        response.setContentType("image/png");
+        response.setHeader("Cache-Control", "no-store, private");
+        response.setHeader("X-Content-Type-Options", "nosniff");
+        response.getOutputStream().write(image);
+    }
     @GetMapping("/available") @PreAuthorize("@ss.hasPermission('mes:pd-project:export')")
     public CommonResult<List<Map<String,Object>>> available(){ return success(service.seals(true)); }
     @PostMapping("/upload") @PreAuthorize("@ss.hasPermission('mes:pd-seal:manage')")
diff --git a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/pd/seal/PdSealService.java b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/pd/seal/PdSealService.java
index 74f35b1..ec17cb6 100644
--- a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/pd/seal/PdSealService.java
+++ b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/pd/seal/PdSealService.java
@@ -30,6 +30,11 @@
     public List<Map<String,Object>> seals(boolean activeOnly) {
         return jdbc.queryForList("SELECT id,name,enabled,create_time FROM pd_seal WHERE tenant_id=? AND deleted=0" + (activeOnly ? " AND enabled=1" : "") + " ORDER BY id DESC", tenant());
     }
+    public byte[] getImage(long id) {
+        var rows = jdbc.queryForList("SELECT image_data FROM pd_seal WHERE id=? AND tenant_id=? AND deleted=0", id, tenant());
+        if (rows.isEmpty()) throw fail("鍗扮珷涓嶅瓨鍦�");
+        return (byte[]) rows.get(0).get("image_data");
+    }
     public long upload(String name, MultipartFile file, Long userId) throws Exception {
         if (name == null || name.isBlank() || name.length() > 100) throw fail("鍗扮珷鍚嶇О涓嶈兘涓虹┖涓斾笉鑳借秴杩�100瀛�");
         if (file == null || file.isEmpty() || file.getSize() > 2 * 1024 * 1024) throw fail("璇蜂笂浼犱笉瓒呰繃2MB鐨凱NG鍗扮珷鍥剧墖");
diff --git a/yudao-module-mes/src/test/java/cn/iocoder/yudao/module/mes/service/pd/seal/PdSealServiceTest.java b/yudao-module-mes/src/test/java/cn/iocoder/yudao/module/mes/service/pd/seal/PdSealServiceTest.java
index 388383d..27d149a 100644
--- a/yudao-module-mes/src/test/java/cn/iocoder/yudao/module/mes/service/pd/seal/PdSealServiceTest.java
+++ b/yudao-module-mes/src/test/java/cn/iocoder/yudao/module/mes/service/pd/seal/PdSealServiceTest.java
@@ -21,6 +21,22 @@
     @InjectMocks PdSealService service;
     @Mock JdbcTemplate jdbc;
     @Mock BpmTaskService tasks;
+    @Test void imageLookupIsScopedToCurrentTenant() {
+        cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder.setTenantId(42L);
+        try {
+            byte[] image = {1, 2};
+            when(jdbc.queryForList(anyString(), any(Object[].class)))
+                    .thenReturn(List.of(Map.of("image_data", image)));
+            assertArrayEquals(image, service.getImage(7));
+            verify(jdbc).queryForList(contains("tenant_id=? AND deleted=0"), eq(7L), eq(42L));
+        } finally {
+            cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder.clear();
+        }
+    }
+    @Test void refusesImageWhenSealIsNotFound() {
+        when(jdbc.queryForList(anyString(), any(Object[].class))).thenReturn(List.of());
+        assertThrows(ServiceException.class, () -> service.getImage(7));
+    }
     @Test void refusesDownloadWithoutApprovedApplication() {
         when(jdbc.queryForList(anyString(), any(Object[].class))).thenReturn(List.of());
         assertThrows(ServiceException.class, () -> service.download(1, 7));

--
Gitblit v1.9.3