fix: 修改全过程鱼类放鱼明细数据

This commit is contained in:
tangwei 2026-08-21 09:04:30 +08:00
parent 4c500b1fd8
commit 84dfc91ffe
6 changed files with 202 additions and 9 deletions

View File

@ -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<String> ids;
}

View File

@ -85,7 +85,7 @@ public class MsOperationLogServiceImpl extends ServiceImpl<MsOperationLogMapper,
TABLE_NAME_CONFIG_MAP.put("SD_WTRV_R", TableNameConfig.join("ID", "STCD", "V_MS_STBPRP_T", "STNM")); TABLE_NAME_CONFIG_MAP.put("SD_WTRV_R", TableNameConfig.join("ID", "STCD", "V_MS_STBPRP_T", "STNM"));
TABLE_NAME_CONFIG_MAP.put("SD_WTVT_R", TableNameConfig.join("STCD", "STCD", "V_MS_STBPRP_T", "STNM")); TABLE_NAME_CONFIG_MAP.put("SD_WTVT_R", TableNameConfig.join("STCD", "STCD", "V_MS_STBPRP_T", "STNM"));
TABLE_NAME_CONFIG_MAP.put("SD_WQ_R", TableNameConfig.join("ID", "STCD", "V_MS_STBPRP_T", "STNM")); TABLE_NAME_CONFIG_MAP.put("SD_WQ_R", TableNameConfig.join("ID", "STCD", "V_MS_STBPRP_T", "STNM"));
TABLE_NAME_CONFIG_MAP.put("SD_RPIMNFISH_R", TableNameConfig.join("ID", "STCD", "V_MS_STBPRP_T", "STNM")); TABLE_NAME_CONFIG_MAP.put("SD_RPIMNFISH_R", TableNameConfig.self("ID", "ID" ));
} }

View File

@ -4,8 +4,10 @@ import com.yfd.platform.annotation.Log;
import com.yfd.platform.common.DataSourceRequest; import com.yfd.platform.common.DataSourceRequest;
import com.yfd.platform.common.DataSourceResult; import com.yfd.platform.common.DataSourceResult;
import com.yfd.platform.config.ResponseResult; import com.yfd.platform.config.ResponseResult;
import com.yfd.platform.qgc_base.entity.vo.BatchDeleteByIdsAo;
import com.yfd.platform.qgc_env.fb.entity.vo.BreedStageVO; import com.yfd.platform.qgc_env.fb.entity.vo.BreedStageVO;
import com.yfd.platform.qgc_env.fb.entity.vo.FbFishRunQgcDeleteParam; import com.yfd.platform.qgc_env.fb.entity.vo.FbFishRunQgcDeleteParam;
import com.yfd.platform.qgc_env.fb.entity.vo.FbFishRunQgcOperateRequest;
import com.yfd.platform.qgc_env.fb.service.FbStationService; import com.yfd.platform.qgc_env.fb.service.FbStationService;
import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Operation;
@ -231,8 +233,19 @@ public class FbStationController {
@Log(module = "鱼类增殖站模块", value = "删除全过程鱼类放鱼明细数据") @Log(module = "鱼类增殖站模块", value = "删除全过程鱼类放鱼明细数据")
@PostMapping("/fishrun/qgc/removeFishRunQgcDetailData") @PostMapping("/fishrun/qgc/removeFishRunQgcDetailData")
@Operation(summary = "删除全过程鱼类放鱼明细数据(按明细ID批量)") @Operation(summary = "删除全过程鱼类放鱼明细数据(按明细ID批量)")
public ResponseResult removeFishRunQgcDetailData(@RequestBody List<String> ids) { public ResponseResult removeFishRunQgcDetailData(@RequestBody BatchDeleteByIdsAo batchDeleteByIdsAo) {
fbStationService.removeFishRunQgcDetailData(ids); 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(); return ResponseResult.success();
} }

View File

@ -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;
/**
* 全过程鱼类放鱼明细数据操作请求
* <p>updateData: 修改数据其中 id 为定位条件其余 key 对应明细表可修改字段</p>
*/
@Data
@Schema(description = "全过程鱼类放鱼明细数据操作请求")
public class FbFishRunQgcOperateRequest implements Serializable {
private static final long serialVersionUID = 1L;
@Schema(description = "数据来源")
private String source;
@Schema(description = "修改数据")
private Map<String, Object> updateData;
}

View File

@ -2,6 +2,7 @@ package com.yfd.platform.qgc_env.fb.service;
import com.yfd.platform.common.DataSourceRequest; import com.yfd.platform.common.DataSourceRequest;
import com.yfd.platform.common.DataSourceResult; 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 com.yfd.platform.qgc_env.fb.entity.vo.*;
import java.util.List; import java.util.List;
@ -38,9 +39,17 @@ public interface FbStationService {
/** /**
* 按明细ID批量逻辑删除全过程鱼类放鱼数据并记录操作日志 * 按明细ID批量逻辑删除全过程鱼类放鱼数据并记录操作日志
* *
* @param ids 明细ID列表SD_RPIMNFISH_R.ID * @param batchDeleteByIdsAo 删除参数ids + source
*/ */
boolean removeFishRunQgcDetailData(List<String> ids); boolean removeFishRunQgcDetailData(BatchDeleteByIdsAo batchDeleteByIdsAo);
/**
* 修改全过程鱼类放鱼明细数据按明细ID定位并记录操作日志
*
* @param updateData 修改数据id 为定位条件其余 key 为可修改字段
* @param source 数据来源
*/
boolean updateFishRunQgcDetailData(Map<String, Object> updateData, String source);
DataSourceResult<FbFishTypeFinishVo> getFishTypeKendoListCust(DataSourceRequest dataSourceRequest); DataSourceResult<FbFishTypeFinishVo> getFishTypeKendoListCust(DataSourceRequest dataSourceRequest);

View File

@ -11,6 +11,8 @@ import com.yfd.platform.common.Group;
import com.yfd.platform.common.GroupHelper; import com.yfd.platform.common.GroupHelper;
import com.yfd.platform.common.GroupingInfo; import com.yfd.platform.common.GroupingInfo;
import com.yfd.platform.common.MicroservicDynamicSQLMapper; 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.entity.vo.*;
import com.yfd.platform.qgc_env.fb.service.FbStationService; import com.yfd.platform.qgc_env.fb.service.FbStationService;
import com.yfd.platform.qgc_env.wt.utils.SiteAvoidanceUtils; 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.domain.MsOperationLogDetail;
import com.yfd.platform.qgc_base.mapper.MsOperationLogDetailMapper; import com.yfd.platform.qgc_base.mapper.MsOperationLogDetailMapper;
import com.yfd.platform.qgc_base.mapper.MsOperationLogMapper; 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.QgcQueryWrapperUtil;
import com.yfd.platform.utils.SecurityUtils; import com.yfd.platform.utils.SecurityUtils;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
@ -63,6 +66,25 @@ public class FbStationServiceImpl implements FbStationService {
FISH_RUN_FIELD_MEANING_MAP.put("REMARK", "备注"); FISH_RUN_FIELD_MEANING_MAP.put("REMARK", "备注");
} }
/**
* 全过程鱼类放鱼明细可修改字段映射前端入参 key -> 数据库列
*/
private static final LinkedHashMap<String, String> 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 @Override
public List<YearRpStatisticsVo> getYearRpStatistics(String year) { public List<YearRpStatisticsVo> getYearRpStatistics(String year) {
Map<String, Object> paramMap = new HashMap<>(); Map<String, Object> paramMap = new HashMap<>();
@ -293,14 +315,15 @@ public class FbStationServiceImpl implements FbStationService {
resolveLogOperator(), param.getFtp(), param.getStcd(), param.getFlyr() resolveLogOperator(), param.getFtp(), param.getStcd(), param.getFlyr()
); );
recordFishRunDeleteLog(beforeRows, String.format("删除全过程鱼类放鱼数据(站点:%s,年份:%s,删除条数:%d)", recordFishRunDeleteLog(beforeRows, String.format("删除全过程鱼类放鱼数据(站点:%s,年份:%s,删除条数:%d)",
param.getStcd(), param.getFlyr(), deleteCount), deleteCount); param.getStcd(), param.getFlyr(), deleteCount),null, deleteCount);
} }
return true; return true;
} }
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public boolean removeFishRunQgcDetailData(List<String> ids) { public boolean removeFishRunQgcDetailData(BatchDeleteByIdsAo batchDeleteByIdsAo) {
List<String> ids = batchDeleteByIdsAo.getIds();
if (CollUtil.isEmpty(ids)) { if (CollUtil.isEmpty(ids)) {
return true; return true;
} }
@ -319,10 +342,109 @@ public class FbStationServiceImpl implements FbStationService {
deleteCount += batchSoftDeleteFishRunDetail(part); deleteCount += batchSoftDeleteFishRunDetail(part);
} }
// 3. 记录删除日志(每条明细一条主日志, 子日志挂对应主日志) // 3. 记录删除日志(每条明细一条主日志, 子日志挂对应主日志)
recordFishRunDeleteLog(beforeRows, String.format("删除全过程鱼类放鱼数据(明细删除,删除条数:%d)", deleteCount), deleteCount); recordFishRunDeleteLog(beforeRows, String.format("删除全过程鱼类放鱼数据(明细删除,删除条数:%d)", deleteCount),batchDeleteByIdsAo.getSource(), deleteCount);
return true; return true;
} }
@Override
@Transactional(rollbackFor = Exception.class)
public boolean updateFishRunQgcDetailData(Map<String, Object> 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<String, Object> beforeRow = querySingleFishRunDetailRow(id);
if (beforeRow == null || beforeRow.isEmpty()) {
throw new BizException("放鱼明细不存在或已被删除");
}
// 2. 更新允许修改的字段
updateFishRunDetailData(updateData, id);
// 3. 记录修改日志(只记录真正发生变化的字段)
recordFishRunUpdateLog(beforeRow, updateData, source);
return true;
}
private Map<String, Object> querySingleFishRunDetailRow(String id) {
List<Map<String, Object>> rows = queryFishRunDetailRowsByIds(Collections.singletonList(id));
return rows.isEmpty() ? new HashMap<>() : rows.get(0);
}
private void updateFishRunDetailData(Map<String, Object> updateData, String id) {
List<String> setClauses = new ArrayList<>();
List<Object> params = new ArrayList<>();
for (Map.Entry<String, String> 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<String, Object> beforeRow,
Map<String, Object> updateData,
String source) {
if (updateData == null || updateData.isEmpty()) {
return;
}
String recordId = asString(beforeRow.get("ID"));
String stcd = asString(beforeRow.get("STCD"));
List<MsOperationLogDetail> details = new ArrayList<>();
for (Map.Entry<String, String> 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<Map<String, Object>> queryFishRunDetailRows(FbFishRunQgcDeleteParam param) { private List<Map<String, Object>> queryFishRunDetailRows(FbFishRunQgcDeleteParam param) {
String sql = "SELECT det.ID, det.RPIMN_ID, run.STCD, det.FTP, det.FSZ, det.FWET, det.FCNT, " + 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 " + "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; return normalized;
} }
private void recordFishRunDeleteLog(List<Map<String, Object>> rows, String remark, int deleteCount) { private void recordFishRunDeleteLog(List<Map<String, Object>> rows, String remark,String source, int deleteCount) {
if (CollUtil.isEmpty(rows)) { if (CollUtil.isEmpty(rows)) {
return; return;
} }
@ -405,6 +527,8 @@ public class FbStationServiceImpl implements FbStationService {
mainLog.setOperator(resolveLogOperator()); mainLog.setOperator(resolveLogOperator());
mainLog.setRecordId(recordId); mainLog.setRecordId(recordId);
mainLog.setOperateTime(new Date()); mainLog.setOperateTime(new Date());
mainLog.setSource(source);
mainLog.setOperationType("03");
mainLog.setTableName(FISH_RUN_DETAIL_TABLE_NAME); mainLog.setTableName(FISH_RUN_DETAIL_TABLE_NAME);
mainLog.setRemark(remark); mainLog.setRemark(remark);
msOperationLogMapper.insert(mainLog); msOperationLogMapper.insert(mainLog);