From 84dfc91ffe5a049f54759219cecdd5e909384665 Mon Sep 17 00:00:00 2001 From: tangwei Date: Fri, 21 Aug 2026 09:04:30 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E6=94=B9=E5=85=A8=E8=BF=87?= =?UTF-8?q?=E7=A8=8B=E9=B1=BC=E7=B1=BB=E6=94=BE=E9=B1=BC=E6=98=8E=E7=BB=86?= =?UTF-8?q?=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../entity/vo/BatchDeleteByIdsAo.java | 23 +++ .../impl/MsOperationLogServiceImpl.java | 2 +- .../fb/controller/FbStationController.java | 17 ++- .../entity/vo/FbFishRunQgcOperateRequest.java | 24 ++++ .../qgc_env/fb/service/FbStationService.java | 13 +- .../fb/service/impl/FbStationServiceImpl.java | 132 +++++++++++++++++- 6 files changed, 202 insertions(+), 9 deletions(-) create mode 100644 backend/src/main/java/com/yfd/platform/qgc_base/entity/vo/BatchDeleteByIdsAo.java create mode 100644 backend/src/main/java/com/yfd/platform/qgc_env/fb/entity/vo/FbFishRunQgcOperateRequest.java diff --git a/backend/src/main/java/com/yfd/platform/qgc_base/entity/vo/BatchDeleteByIdsAo.java b/backend/src/main/java/com/yfd/platform/qgc_base/entity/vo/BatchDeleteByIdsAo.java new file mode 100644 index 00000000..5f87ad38 --- /dev/null +++ b/backend/src/main/java/com/yfd/platform/qgc_base/entity/vo/BatchDeleteByIdsAo.java @@ -0,0 +1,23 @@ +package com.yfd.platform.qgc_base.entity.vo; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +import java.io.Serializable; +import java.util.List; + +@Data +@Schema(description = "批量删除参数") +public class BatchDeleteByIdsAo implements Serializable { + + private static final long serialVersionUID = 1L; + + @Schema(description = "数据来源") + private String source; + + @Schema(description = "数据类型") + private String dataType; + + @Schema(description = "删除数据列表") + private List ids; +} diff --git a/backend/src/main/java/com/yfd/platform/qgc_base/service/impl/MsOperationLogServiceImpl.java b/backend/src/main/java/com/yfd/platform/qgc_base/service/impl/MsOperationLogServiceImpl.java index 20ead32a..4dc418a3 100644 --- a/backend/src/main/java/com/yfd/platform/qgc_base/service/impl/MsOperationLogServiceImpl.java +++ b/backend/src/main/java/com/yfd/platform/qgc_base/service/impl/MsOperationLogServiceImpl.java @@ -85,7 +85,7 @@ public class MsOperationLogServiceImpl extends ServiceImpl ids) { - fbStationService.removeFishRunQgcDetailData(ids); + public ResponseResult removeFishRunQgcDetailData(@RequestBody BatchDeleteByIdsAo batchDeleteByIdsAo) { + fbStationService.removeFishRunQgcDetailData(batchDeleteByIdsAo); + return ResponseResult.success(); + } + + @Log(module = "鱼类增殖站模块", value = "修改全过程鱼类放鱼明细数据") + @PostMapping("/fishrun/qgc/updateFishRunQgcDetailData") + @Operation(summary = "修改全过程鱼类放鱼明细数据(按明细ID)") + public ResponseResult updateFishRunQgcDetailData(@RequestBody FbFishRunQgcOperateRequest operateRequest) { + fbStationService.updateFishRunQgcDetailData( + operateRequest == null ? null : operateRequest.getUpdateData(), + operateRequest == null ? null : operateRequest.getSource() + ); return ResponseResult.success(); } diff --git a/backend/src/main/java/com/yfd/platform/qgc_env/fb/entity/vo/FbFishRunQgcOperateRequest.java b/backend/src/main/java/com/yfd/platform/qgc_env/fb/entity/vo/FbFishRunQgcOperateRequest.java new file mode 100644 index 00000000..004f2a35 --- /dev/null +++ b/backend/src/main/java/com/yfd/platform/qgc_env/fb/entity/vo/FbFishRunQgcOperateRequest.java @@ -0,0 +1,24 @@ +package com.yfd.platform.qgc_env.fb.entity.vo; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +import java.io.Serializable; +import java.util.Map; + +/** + * 全过程鱼类放鱼明细数据操作请求 + *

updateData: 修改数据,其中 id 为定位条件,其余 key 对应明细表可修改字段

+ */ +@Data +@Schema(description = "全过程鱼类放鱼明细数据操作请求") +public class FbFishRunQgcOperateRequest implements Serializable { + + private static final long serialVersionUID = 1L; + + @Schema(description = "数据来源") + private String source; + + @Schema(description = "修改数据") + private Map updateData; +} diff --git a/backend/src/main/java/com/yfd/platform/qgc_env/fb/service/FbStationService.java b/backend/src/main/java/com/yfd/platform/qgc_env/fb/service/FbStationService.java index 93aaf507..8896c6ed 100644 --- a/backend/src/main/java/com/yfd/platform/qgc_env/fb/service/FbStationService.java +++ b/backend/src/main/java/com/yfd/platform/qgc_env/fb/service/FbStationService.java @@ -2,6 +2,7 @@ package com.yfd.platform.qgc_env.fb.service; import com.yfd.platform.common.DataSourceRequest; import com.yfd.platform.common.DataSourceResult; +import com.yfd.platform.qgc_base.entity.vo.BatchDeleteByIdsAo; import com.yfd.platform.qgc_env.fb.entity.vo.*; import java.util.List; @@ -38,9 +39,17 @@ public interface FbStationService { /** * 按明细ID批量逻辑删除全过程鱼类放鱼数据,并记录操作日志。 * - * @param ids 明细ID列表(SD_RPIMNFISH_R.ID) + * @param batchDeleteByIdsAo 删除参数(ids + source) */ - boolean removeFishRunQgcDetailData(List ids); + boolean removeFishRunQgcDetailData(BatchDeleteByIdsAo batchDeleteByIdsAo); + + /** + * 修改全过程鱼类放鱼明细数据(按明细ID定位),并记录操作日志。 + * + * @param updateData 修改数据,id 为定位条件,其余 key 为可修改字段 + * @param source 数据来源 + */ + boolean updateFishRunQgcDetailData(Map updateData, String source); DataSourceResult getFishTypeKendoListCust(DataSourceRequest dataSourceRequest); diff --git a/backend/src/main/java/com/yfd/platform/qgc_env/fb/service/impl/FbStationServiceImpl.java b/backend/src/main/java/com/yfd/platform/qgc_env/fb/service/impl/FbStationServiceImpl.java index 1e9a6304..5309b35d 100644 --- a/backend/src/main/java/com/yfd/platform/qgc_env/fb/service/impl/FbStationServiceImpl.java +++ b/backend/src/main/java/com/yfd/platform/qgc_env/fb/service/impl/FbStationServiceImpl.java @@ -11,6 +11,8 @@ import com.yfd.platform.common.Group; import com.yfd.platform.common.GroupHelper; import com.yfd.platform.common.GroupingInfo; import com.yfd.platform.common.MicroservicDynamicSQLMapper; +import com.yfd.platform.common.exception.BizException; +import com.yfd.platform.qgc_base.entity.vo.BatchDeleteByIdsAo; import com.yfd.platform.qgc_env.fb.entity.vo.*; import com.yfd.platform.qgc_env.fb.service.FbStationService; import com.yfd.platform.qgc_env.wt.utils.SiteAvoidanceUtils; @@ -18,6 +20,7 @@ import com.yfd.platform.qgc_base.domain.MsOperationLog; import com.yfd.platform.qgc_base.domain.MsOperationLogDetail; import com.yfd.platform.qgc_base.mapper.MsOperationLogDetailMapper; import com.yfd.platform.qgc_base.mapper.MsOperationLogMapper; +import com.yfd.platform.utils.LogValueUtils; import com.yfd.platform.utils.QgcQueryWrapperUtil; import com.yfd.platform.utils.SecurityUtils; import jakarta.annotation.Resource; @@ -63,6 +66,25 @@ public class FbStationServiceImpl implements FbStationService { FISH_RUN_FIELD_MEANING_MAP.put("REMARK", "备注"); } + /** + * 全过程鱼类放鱼明细可修改字段映射(前端入参 key -> 数据库列) + */ + private static final LinkedHashMap FISH_RUN_UPDATE_COLUMN_MAP = new LinkedHashMap<>(); + + static { + FISH_RUN_UPDATE_COLUMN_MAP.put("ftp", "FTP"); + FISH_RUN_UPDATE_COLUMN_MAP.put("fsZ", "FSZ"); + FISH_RUN_UPDATE_COLUMN_MAP.put("fwet", "FWET"); + FISH_RUN_UPDATE_COLUMN_MAP.put("fcnt", "FCNT"); + FISH_RUN_UPDATE_COLUMN_MAP.put("tagte", "TAGTE"); + FISH_RUN_UPDATE_COLUMN_MAP.put("tagcnt", "TAGCNT"); + FISH_RUN_UPDATE_COLUMN_MAP.put("fage", "FAGE"); + FISH_RUN_UPDATE_COLUMN_MAP.put("fid", "FID"); + FISH_RUN_UPDATE_COLUMN_MAP.put("protectlvl", "PROTECTLVL"); + FISH_RUN_UPDATE_COLUMN_MAP.put("fa", "FA"); + FISH_RUN_UPDATE_COLUMN_MAP.put("remark", "REMARK"); + } + @Override public List getYearRpStatistics(String year) { Map paramMap = new HashMap<>(); @@ -293,14 +315,15 @@ public class FbStationServiceImpl implements FbStationService { resolveLogOperator(), param.getFtp(), param.getStcd(), param.getFlyr() ); recordFishRunDeleteLog(beforeRows, String.format("删除全过程鱼类放鱼数据(站点:%s,年份:%s,删除条数:%d)", - param.getStcd(), param.getFlyr(), deleteCount), deleteCount); + param.getStcd(), param.getFlyr(), deleteCount),null, deleteCount); } return true; } @Override @Transactional(rollbackFor = Exception.class) - public boolean removeFishRunQgcDetailData(List ids) { + public boolean removeFishRunQgcDetailData(BatchDeleteByIdsAo batchDeleteByIdsAo) { + List ids = batchDeleteByIdsAo.getIds(); if (CollUtil.isEmpty(ids)) { return true; } @@ -319,10 +342,109 @@ public class FbStationServiceImpl implements FbStationService { deleteCount += batchSoftDeleteFishRunDetail(part); } // 3. 记录删除日志(每条明细一条主日志, 子日志挂对应主日志) - recordFishRunDeleteLog(beforeRows, String.format("删除全过程鱼类放鱼数据(明细删除,删除条数:%d)", deleteCount), deleteCount); + recordFishRunDeleteLog(beforeRows, String.format("删除全过程鱼类放鱼数据(明细删除,删除条数:%d)", deleteCount),batchDeleteByIdsAo.getSource(), deleteCount); return true; } + @Override + @Transactional(rollbackFor = Exception.class) + public boolean updateFishRunQgcDetailData(Map updateData, String source) { + if (updateData == null || updateData.isEmpty()) { + return true; + } + String id = asString(updateData.get("id")); + if (StrUtil.isBlank(id)) { + throw new BizException("明细ID不能为空"); + } + // 1. 查询修改前的明细行(用于记录日志) + Map beforeRow = querySingleFishRunDetailRow(id); + if (beforeRow == null || beforeRow.isEmpty()) { + throw new BizException("放鱼明细不存在或已被删除"); + } + // 2. 更新允许修改的字段 + updateFishRunDetailData(updateData, id); + // 3. 记录修改日志(只记录真正发生变化的字段) + recordFishRunUpdateLog(beforeRow, updateData, source); + return true; + } + + private Map querySingleFishRunDetailRow(String id) { + List> rows = queryFishRunDetailRowsByIds(Collections.singletonList(id)); + return rows.isEmpty() ? new HashMap<>() : rows.get(0); + } + + private void updateFishRunDetailData(Map updateData, String id) { + List setClauses = new ArrayList<>(); + List params = new ArrayList<>(); + for (Map.Entry entry : FISH_RUN_UPDATE_COLUMN_MAP.entrySet()) { + if (!updateData.containsKey(entry.getKey())) { + continue; + } + setClauses.add(entry.getValue() + " = ?"); + params.add(updateData.get(entry.getKey())); + } + if (setClauses.isEmpty()) { + return; + } + String sql = "UPDATE SD_RPIMNFISH_R SET " + String.join(", ", setClauses) + + " WHERE ID = ? AND NVL(IS_DELETED, 0) = 0"; + params.add(id); + int updated = jdbcTemplate.update(sql, params.toArray()); + if (updated == 0) { + throw new BizException("放鱼明细不存在或已被删除"); + } + } + + private void recordFishRunUpdateLog(Map beforeRow, + Map updateData, + String source) { + if (updateData == null || updateData.isEmpty()) { + return; + } + String recordId = asString(beforeRow.get("ID")); + String stcd = asString(beforeRow.get("STCD")); + List details = new ArrayList<>(); + for (Map.Entry entry : FISH_RUN_UPDATE_COLUMN_MAP.entrySet()) { + if (!updateData.containsKey(entry.getKey())) { + continue; + } + String column = entry.getValue(); + Object oldValue = beforeRow.get(column); + Object newValue = updateData.get(entry.getKey()); + // 数值类型按数值大小比较,忽略精度差异(133.0000 == 133.00) + if (LogValueUtils.sameLogValue(oldValue, newValue)) { + continue; + } + MsOperationLogDetail detail = new MsOperationLogDetail(); + detail.setTableName(FISH_RUN_DETAIL_TABLE_NAME); + detail.setStationCode(stcd); + detail.setFieldCode(column); + detail.setFieldMeaning(FISH_RUN_FIELD_MEANING_MAP.getOrDefault(column, column)); + detail.setOldValueCode(formatFishRunLogValue(oldValue)); + detail.setOldValueName(formatFishRunLogValue(oldValue)); + detail.setNewValueCode(formatFishRunLogValue(newValue)); + detail.setNewValueName(formatFishRunLogValue(newValue)); + detail.setRemark("修改字段值"); + details.add(detail); + } + if (details.isEmpty()) { + return; + } + MsOperationLog mainLog = new MsOperationLog(); + mainLog.setOperator(resolveLogOperator()); + mainLog.setOperationType("02"); + mainLog.setRecordId(recordId); + mainLog.setOperateTime(new Date()); + mainLog.setTableName(FISH_RUN_DETAIL_TABLE_NAME); + mainLog.setSource(StrUtil.trimToNull(source)); + mainLog.setRemark("修改全过程鱼类放鱼数据(明细ID:" + recordId + ")"); + msOperationLogMapper.insert(mainLog); + for (MsOperationLogDetail detail : details) { + detail.setMainId(mainLog.getId()); + msOperationLogDetailMapper.insert(detail); + } + } + private List> queryFishRunDetailRows(FbFishRunQgcDeleteParam param) { String sql = "SELECT det.ID, det.RPIMN_ID, run.STCD, det.FTP, det.FSZ, det.FWET, det.FCNT, " + "det.TAGTE, det.TAGCNT, det.FAGE, det.FID, det.PROTECTLVL, det.FA, det.REMARK " + @@ -393,7 +515,7 @@ public class FbStationServiceImpl implements FbStationService { return normalized; } - private void recordFishRunDeleteLog(List> rows, String remark, int deleteCount) { + private void recordFishRunDeleteLog(List> rows, String remark,String source, int deleteCount) { if (CollUtil.isEmpty(rows)) { return; } @@ -405,6 +527,8 @@ public class FbStationServiceImpl implements FbStationService { mainLog.setOperator(resolveLogOperator()); mainLog.setRecordId(recordId); mainLog.setOperateTime(new Date()); + mainLog.setSource(source); + mainLog.setOperationType("03"); mainLog.setTableName(FISH_RUN_DETAIL_TABLE_NAME); mainLog.setRemark(remark); msOperationLogMapper.insert(mainLog);