From c967b5105f82bcc11c525a6dc638186fac1d3b75 Mon Sep 17 00:00:00 2001 From: tangwei Date: Fri, 14 Aug 2026 13:49:00 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BC=98=E5=8C=96=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../yfd/platform/config/SecurityConfig.java | 2 +- .../controller/SdFpssrlRController.java | 167 ++++++++++++++++-- .../qgc_base/service/ISdFpssrlRService.java | 5 +- .../service/impl/SdFpssrlRServiceImpl.java | 45 +++-- .../qgc_env/fp/entity/vo/FpFpssrlQueryVo.java | 3 + .../fp/service/impl/FpRunServiceImpl.java | 3 + 6 files changed, 192 insertions(+), 33 deletions(-) diff --git a/backend/src/main/java/com/yfd/platform/config/SecurityConfig.java b/backend/src/main/java/com/yfd/platform/config/SecurityConfig.java index 04ab7190..c7ef4999 100644 --- a/backend/src/main/java/com/yfd/platform/config/SecurityConfig.java +++ b/backend/src/main/java/com/yfd/platform/config/SecurityConfig.java @@ -85,7 +85,7 @@ public class SecurityConfig { .requestMatchers("/wq/**").permitAll() // .requestMatchers("/wte/**").permitAll() // .requestMatchers("/vd/**").permitAll() -// .requestMatchers("/vap/**").permitAll() + .requestMatchers("/vap/**").permitAll() .requestMatchers("/fp/**").permitAll() // .requestMatchers("/fpr/**").permitAll() // .requestMatchers("/fh/**").permitAll() diff --git a/backend/src/main/java/com/yfd/platform/qgc_base/controller/SdFpssrlRController.java b/backend/src/main/java/com/yfd/platform/qgc_base/controller/SdFpssrlRController.java index c48dca22..68474860 100644 --- a/backend/src/main/java/com/yfd/platform/qgc_base/controller/SdFpssrlRController.java +++ b/backend/src/main/java/com/yfd/platform/qgc_base/controller/SdFpssrlRController.java @@ -18,9 +18,7 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; +import java.util.*; import java.util.stream.Collectors; /** @@ -64,27 +62,66 @@ public class SdFpssrlRController { @Log(module = "过鱼设施自动数据管理", value = "新增过鱼自动数据") @PostMapping("/add") @Operation(summary = "新增过鱼自动数据") - public ResponseResult add(@RequestBody SdEngInfoBHOperateRequest request) { - SdFpssrlR entity = request == null || request.getEngInfo() == null ? null - : objectMapper.convertValue(request.getEngInfo(), SdFpssrlR.class); - if (entity == null) { - return ResponseResult.error("数据不能为空"); + public ResponseResult add(@RequestParam("data") String dataStr, + @RequestParam(value = "picFiles", required = false) List picFiles, + @RequestParam(value = "vdFiles", required = false) List vdFiles) { + try { + SdEngInfoBHOperateRequest request = objectMapper.readValue(dataStr, SdEngInfoBHOperateRequest.class); + SdFpssrlR entity = request == null || request.getEngInfo() == null ? null + : objectMapper.convertValue(request.getEngInfo(), SdFpssrlR.class); + if (entity == null) { + return ResponseResult.error("数据不能为空"); + } + + // 上传附件并设置到实体(图片→firstImgUrl,视频→videoUrl) + applyUploadedFiles(entity, picFiles, vdFiles); + + boolean result = sdFpssrlRService.add(entity, request.getSource()); + return result ? ResponseResult.success("新增成功") : ResponseResult.error("新增失败"); + } catch (Exception e) { + log.error("新增过鱼自动数据失败", e); + return ResponseResult.error("新增失败: " + e.getMessage()); } - boolean result = sdFpssrlRService.add(entity, request.getSource()); - return result ? ResponseResult.success("新增成功") : ResponseResult.error("新增失败"); } @Log(module = "过鱼设施自动数据管理", value = "修改过鱼自动数据") @PostMapping("/update") @Operation(summary = "修改过鱼自动数据") - public ResponseResult update(@RequestBody SdEngInfoBHOperateRequest request) { - SdFpssrlR entity = request == null || request.getEngInfo() == null ? null - : objectMapper.convertValue(request.getEngInfo(), SdFpssrlR.class); - if (entity == null || entity.getId() == null) { - return ResponseResult.error("数据或ID不能为空"); + public ResponseResult update(@RequestParam("data") String dataStr, + @RequestParam(value = "picFiles", required = false) List picFiles, + @RequestParam(value = "vdFiles", required = false) List vdFiles) { + try { + SdEngInfoBHOperateRequest request = objectMapper.readValue(dataStr, SdEngInfoBHOperateRequest.class); + Map engInfo = request == null ? null : request.getEngInfo(); + if (engInfo == null || engInfo.get("id") == null) { + return ResponseResult.error("数据或ID不能为空"); + } + + // 获取修改前的实体,用于后续清理被替换的旧附件 + SdFpssrlR before = sdFpssrlRService.getById((String) engInfo.get("id")); + List oldAttachmentIds = before != null ? collectAttachmentIds(before) : Collections.emptyList(); + + // 上传新附件并合并回 patch map(仅当本次有文件上传时才覆盖对应字段) + SdFpssrlR tempEntity = objectMapper.convertValue(engInfo, SdFpssrlR.class); + applyUploadedFiles(tempEntity, picFiles, vdFiles); + if (picFiles != null && !picFiles.isEmpty()) { + engInfo.put("firstImgUrl", tempEntity.getFirstImgUrl()); + } + if (vdFiles != null && !vdFiles.isEmpty()) { + engInfo.put("videoUrl", tempEntity.getVideoUrl()); + } + + boolean result = sdFpssrlRService.update(engInfo, request.getSource()); + if (result) { + // 清理被替换的旧附件 + SdFpssrlR after = sdFpssrlRService.getById((String) engInfo.get("id")); + deleteReplacedFiles(oldAttachmentIds, collectAttachmentIds(after)); + } + return result ? ResponseResult.success("修改成功") : ResponseResult.error("修改失败"); + } catch (Exception e) { + log.error("修改过鱼自动数据失败", e); + return ResponseResult.error("修改失败: " + e.getMessage()); } - boolean result = sdFpssrlRService.update(entity, request.getSource()); - return result ? ResponseResult.success("修改成功") : ResponseResult.error("修改失败"); } @Log(module = "过鱼设施自动数据管理", value = "删除过鱼自动数据") @@ -95,7 +132,21 @@ public class SdFpssrlRController { if (ids == null || ids.isEmpty()) { return ResponseResult.error("ID不能为空"); } + + // 删除前先收集所有需要清理的附件ID + List allAttachmentIds = new ArrayList<>(); + for (String id : ids) { + SdFpssrlR entity = sdFpssrlRService.getById(id); + if (entity != null) { + allAttachmentIds.addAll(collectAttachmentIds(entity)); + } + } + boolean result = sdFpssrlRService.delete(ids, request.getSource()); + if (result) { + // 删除关联的附件 + deleteAttachments(allAttachmentIds); + } return result ? ResponseResult.success("删除成功") : ResponseResult.error("删除失败"); } @@ -169,7 +220,6 @@ public class SdFpssrlRController { try { List result = sdFpssrlRService.processAiReportBatch(requests); -// List ids = result.stream().map(SdFpssrlR::getId).collect(Collectors.toList()); log.info("AI批量上报成功,共{}条", result.size()); return ResponseResult.success(); } catch (Exception e) { @@ -177,4 +227,85 @@ public class SdFpssrlRController { return ResponseResult.error("上报失败: " + e.getMessage()); } } + + // ==================== 附件处理辅助方法 ==================== + + /** + * 上传图片/视频附件并追加附件ID到 firstImgUrl/videoUrl 字段(与已有ID以逗号拼接) + */ + private void applyUploadedFiles(SdFpssrlR entity, List picFiles, List vdFiles) { + if (picFiles != null && !picFiles.isEmpty()) { + List ids = attachmentUploadService.uploadMultipartFiles(picFiles); + if (!ids.isEmpty()) { + entity.setFirstImgUrl(mergeIds(entity.getFirstImgUrl(), ids)); + } + } + if (vdFiles != null && !vdFiles.isEmpty()) { + List ids = attachmentUploadService.uploadMultipartFiles(vdFiles); + if (!ids.isEmpty()) { + entity.setVideoUrl(mergeIds(entity.getVideoUrl(), ids)); + } + } + } + + /** + * 将新上传的附件ID列表追加到已有ID字符串后面(逗号分隔) + */ + private String mergeIds(String existing, List ids) { + String newIds = ids.stream() + .filter(StrUtil::isNotBlank) + .collect(Collectors.joining(",")); + if (StrUtil.isBlank(newIds)) { + return existing; + } + return StrUtil.isBlank(existing) ? newIds : existing + "," + newIds; + } + + /** + * 收集实体中 firstImgUrl/videoUrl 字段的附件ID + */ + private List collectAttachmentIds(SdFpssrlR entity) { + List ids = new ArrayList<>(); + if (entity == null) { + return ids; + } + if (StrUtil.isNotBlank(entity.getFirstImgUrl())) { + Arrays.stream(entity.getFirstImgUrl().split(",")) + .map(String::trim) + .filter(StrUtil::isNotBlank) + .forEach(ids::add); + } + if (StrUtil.isNotBlank(entity.getVideoUrl())) { + Arrays.stream(entity.getVideoUrl().split(",")) + .map(String::trim) + .filter(StrUtil::isNotBlank) + .forEach(ids::add); + } + return ids; + } + + /** + * 删除被替换的旧附件(old中有但new中没有的) + */ + private void deleteReplacedFiles(List oldIds, List newIds) { + for (String oldId : oldIds) { + if (StrUtil.isBlank(oldId)) { + continue; + } + if (!newIds.contains(oldId)) { + attachmentUploadService.deleteFile(oldId); + } + } + } + + /** + * 批量删除附件 + */ + private void deleteAttachments(List attachmentIds) { + for (String id : attachmentIds) { + if (StrUtil.isNotBlank(id)) { + attachmentUploadService.deleteFile(id); + } + } + } } diff --git a/backend/src/main/java/com/yfd/platform/qgc_base/service/ISdFpssrlRService.java b/backend/src/main/java/com/yfd/platform/qgc_base/service/ISdFpssrlRService.java index 7044a673..c39c1dc5 100644 --- a/backend/src/main/java/com/yfd/platform/qgc_base/service/ISdFpssrlRService.java +++ b/backend/src/main/java/com/yfd/platform/qgc_base/service/ISdFpssrlRService.java @@ -8,6 +8,7 @@ import com.yfd.platform.qgc_base.domain.SdFpssrlR; import com.yfd.platform.qgc_base.domain.SdFpssrlRAiRequest; import java.util.List; +import java.util.Map; /** *

@@ -27,9 +28,9 @@ public interface ISdFpssrlRService extends IService { boolean add(SdFpssrlR entity, String source); /** - * 修改 + * 修改(按前端 patch 显式更新字段,含 null 置空) */ - boolean update(SdFpssrlR entity, String source); + boolean update(Map engInfoPatch, String source) throws Exception; /** * 删除(逻辑删除) diff --git a/backend/src/main/java/com/yfd/platform/qgc_base/service/impl/SdFpssrlRServiceImpl.java b/backend/src/main/java/com/yfd/platform/qgc_base/service/impl/SdFpssrlRServiceImpl.java index 1e30499f..33a75434 100644 --- a/backend/src/main/java/com/yfd/platform/qgc_base/service/impl/SdFpssrlRServiceImpl.java +++ b/backend/src/main/java/com/yfd/platform/qgc_base/service/impl/SdFpssrlRServiceImpl.java @@ -13,7 +13,9 @@ import com.yfd.platform.qgc_base.mapper.SdFpssrlAiRMapper; import com.yfd.platform.qgc_base.mapper.SdFpssrlRMapper; import com.yfd.platform.qgc_base.service.IMsOperationLogService; import com.yfd.platform.qgc_base.service.ISdFpssrlRService; +import com.yfd.platform.utils.CodeToNameMetadataBo; import com.yfd.platform.utils.DataSourceRequestUtil; +import com.yfd.platform.utils.DictCodeToNameConverter; import com.yfd.platform.utils.SecurityUtils; import jakarta.annotation.Resource; import lombok.extern.slf4j.Slf4j; @@ -23,6 +25,8 @@ import org.springframework.transaction.annotation.Transactional; import java.util.ArrayList; import java.util.Date; import java.util.List; +import java.util.Map; +import java.util.Set; /** *

@@ -40,6 +44,26 @@ public class SdFpssrlRServiceImpl extends ServiceImpl TRANSIENT_FIELDS = Set.of("stnm", "serialVersionUID"); + + /** + * 代码转名称元数据配置列表 + */ + private static final List CODE_TO_NAME_META_LIST = new ArrayList<>(); + + static { + CODE_TO_NAME_META_LIST.add(CodeToNameMetadataBo.builder().codeProperty("ftp").modifyProperty("ftpName") + .dictType("DYNAMIC").dictSource("SD_FISHDICTORY_B").codeColumn("ID").nameColumn("NAME") + .filter("NVL(IS_DELETED, 0) = 0 AND NVL(ENABLE, 1) = 1").build()); + } + + @Override public Page queryPageList(DataSourceRequest request) { return DataSourceRequestUtil.executeQuery(request, SdFpssrlR.class, this); @@ -49,21 +73,18 @@ public class SdFpssrlRServiceImpl extends ServiceImpl engInfoPatch, String source) throws Exception { + return patchUpdateHelper.execute(this, engInfoPatch, source, TABLE_NAME, SdFpssrlR.class, + TRANSIENT_FIELDS, CODE_TO_NAME_META_LIST, "id"); } @Override @@ -72,14 +93,14 @@ public class SdFpssrlRServiceImpl extends ServiceImpl wrapper = new LambdaUpdateWrapper<>(); wrapper.eq(SdFpssrlR::getId, id); wrapper.set(SdFpssrlR::getIsDeleted, 1); wrapper.set(SdFpssrlR::getDeleteUser, SecurityUtils.getCurrentUsername()); wrapper.set(SdFpssrlR::getDeleteTime, new Date()); if (this.update(wrapper)) { -// msOperationLogService.recordDeleteDetailLog(id,TABLE_NAME, entity, source); + msOperationLogService.recordDeleteDetailLog(id,TABLE_NAME, entity, source); count++; } } diff --git a/backend/src/main/java/com/yfd/platform/qgc_env/fp/entity/vo/FpFpssrlQueryVo.java b/backend/src/main/java/com/yfd/platform/qgc_env/fp/entity/vo/FpFpssrlQueryVo.java index 56bbf631..1a26a133 100644 --- a/backend/src/main/java/com/yfd/platform/qgc_env/fp/entity/vo/FpFpssrlQueryVo.java +++ b/backend/src/main/java/com/yfd/platform/qgc_env/fp/entity/vo/FpFpssrlQueryVo.java @@ -105,6 +105,9 @@ public class FpFpssrlQueryVo { @Schema(description = "站点分类编码") private String stCode; + @Schema(description = "是否鱼苗") + private Integer isfs; + @Schema(description = "站点分类名称") private String stName; } diff --git a/backend/src/main/java/com/yfd/platform/qgc_env/fp/service/impl/FpRunServiceImpl.java b/backend/src/main/java/com/yfd/platform/qgc_env/fp/service/impl/FpRunServiceImpl.java index aba8ad7f..6a716cae 100644 --- a/backend/src/main/java/com/yfd/platform/qgc_env/fp/service/impl/FpRunServiceImpl.java +++ b/backend/src/main/java/com/yfd/platform/qgc_env/fp/service/impl/FpRunServiceImpl.java @@ -1534,6 +1534,7 @@ public class FpRunServiceImpl implements FpRunService { "src.ID AS id, " + "src.STCD AS stcd, " + "src.STNM AS stnm, " + + "src.ISFS AS isfs, " + "src.BASEID AS baseId, " + "src.BASENAME AS baseName, " + "src.RSTCD AS rstcd, " + @@ -1581,6 +1582,7 @@ public class FpRunServiceImpl implements FpRunService { " COALESCE(fishRv.NAME, relRv.FISH_NAME, fishZy.NAME, relZy.FISH_NAME, fishDirect.NAME, t.FTP) AS FTP, " + " t.FTP AS FISHID, " + " t.FSZ AS FSZ, " + + " null AS ISFS, " + " TO_CHAR(t.LENGTH) AS LENGTH, " + " TO_CHAR(t.WIDTH) AS WIDTH, " + " TO_CHAR(t.FISHSPEED) AS FISHSPEED, " + @@ -1639,6 +1641,7 @@ public class FpRunServiceImpl implements FpRunService { " COALESCE(fishRv.NAME, relRv.FISH_NAME, fishZy.NAME, relZy.FISH_NAME, fishDirect.NAME, t.FTP) AS FTP, " + " t.FTP AS FISHID, " + " t.FSZ AS FSZ, " + + " t.ISFS AS ISFS, " + " CAST(NULL AS VARCHAR2(50)) AS LENGTH, " + " CAST(NULL AS VARCHAR2(50)) AS WIDTH, " + " CAST(NULL AS VARCHAR2(50)) AS FISHSPEED, " +