fix: 优化电站删除

This commit is contained in:
tangwei 2026-06-26 09:00:48 +08:00
parent 76939be1af
commit 0b673d4620
6 changed files with 81 additions and 4 deletions

View File

@ -113,8 +113,9 @@ public class SdEngInfoBHController {
@Log(module = "电站管理", value = "删除电站") @Log(module = "电站管理", value = "删除电站")
@PostMapping("/delete") @PostMapping("/delete")
@Operation(summary = "删除电站") @Operation(summary = "删除电站")
public ResponseResult delete(@RequestParam String stcd) { public ResponseResult delete(@RequestBody SdEngInfoBHOperateRequest request) {
boolean result = engInfoBHService.deleteEngInfo(stcd); boolean result = engInfoBHService.deleteEngInfo(request == null ? null : request.getIds(),
request == null ? null : request.getSource());
return result ? ResponseResult.success("删除成功") : ResponseResult.error("删除失败"); return result ? ResponseResult.success("删除成功") : ResponseResult.error("删除失败");
} }

View File

@ -2,6 +2,7 @@ package com.yfd.platform.qgc_base.domain;
import lombok.Data; import lombok.Data;
import java.util.List;
import java.util.Map; import java.util.Map;
@Data @Data
@ -9,5 +10,7 @@ public class SdEngInfoBHOperateRequest {
private Map<String, Object> engInfo; private Map<String, Object> engInfo;
private List<String> ids;
private String source; private String source;
} }

View File

@ -7,4 +7,6 @@ public interface IMsOperationLogService {
void recordEngAddLog(SdEngInfoBH engInfo, String source); void recordEngAddLog(SdEngInfoBH engInfo, String source);
void recordEngUpdateLog(SdEngInfoBH before, SdEngInfoBH changeSet, String source); void recordEngUpdateLog(SdEngInfoBH before, SdEngInfoBH changeSet, String source);
void recordEngDeleteLog(SdEngInfoBH engInfo, String source);
} }

View File

@ -70,6 +70,8 @@ public interface ISdEngInfoBHService extends IService<SdEngInfoBH> {
*/ */
boolean deleteEngInfo(String stcd); boolean deleteEngInfo(String stcd);
boolean deleteEngInfo(List<String> ids, String source);
List<SdEngInfoBH> selectRegDropdown(SdEngInfoBHRequest sdEngInfoBHRequest); List<SdEngInfoBH> selectRegDropdown(SdEngInfoBHRequest sdEngInfoBHRequest);
EngBaseInfoVo getStInfoByStcd(String stcd); EngBaseInfoVo getStInfoByStcd(String stcd);

View File

@ -343,6 +343,41 @@ public class MsOperationLogServiceImpl implements IMsOperationLogService {
batchInsertDetails(details); batchInsertDetails(details);
} }
@Override
public void recordEngDeleteLog(SdEngInfoBH engInfo, String source) {
if (engInfo == null) {
return;
}
MsOperationLog mainLog = buildMainLog("删除电站", source);
msOperationLogMapper.insert(mainLog);
List<MsOperationLogDetail> details = new ArrayList<>();
Set<String> processedColumns = new HashSet<>();
for (Field field : SdEngInfoBH.class.getDeclaredFields()) {
if (shouldSkipField(field)) {
continue;
}
field.setAccessible(true);
String columnName = resolveColumnName(field);
if (ENG_NAME_COLUMNS.contains(columnName) || processedColumns.contains(columnName)) {
continue;
}
Object oldValue = getFieldValue(field, engInfo);
if (oldValue == null) {
continue;
}
String nameColumn = ENG_CODE_NAME_FIELD_MAP.get(columnName);
Object oldNameValue = resolveNameValue(columnName, nameColumn, oldValue, engInfo);
details.add(buildDetail(mainLog.getId(), engInfo.getStcd(), columnName,
oldValue, oldNameValue, null, null, "删除字段值"));
processedColumns.add(columnName);
if (StrUtil.isNotBlank(nameColumn)) {
processedColumns.add(nameColumn);
}
}
batchInsertDetails(details);
}
private MsOperationLog buildMainLog(String remark, String source) { private MsOperationLog buildMainLog(String remark, String source) {
MsOperationLog log = new MsOperationLog(); MsOperationLog log = new MsOperationLog();
log.setOperator(resolveOperator()); log.setOperator(resolveOperator());

View File

@ -42,6 +42,7 @@ import org.springframework.util.StringUtils;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
@ -503,8 +504,41 @@ public class SdEngInfoBHServiceImpl extends ServiceImpl<SdEngInfoBHMapper, SdEng
@Override @Override
public boolean deleteEngInfo(String stcd) { public boolean deleteEngInfo(String stcd) {
return this.update( new LambdaUpdateWrapper<SdEngInfoBH>().eq(SdEngInfoBH::getStcd, stcd).set(SdEngInfoBH::getIsDeleted, 1)); if (StrUtil.isBlank(stcd)) {
// return this.removeById(stcd); return false;
}
return deleteEngInfo(java.util.Collections.singletonList(stcd), null);
}
@Override
@Transactional(rollbackFor = Exception.class)
public boolean deleteEngInfo(List<String> ids, String source) {
List<String> stcdList = ids == null ? new ArrayList<>() : ids.stream()
.filter(StrUtil::isNotBlank)
.distinct()
.collect(Collectors.toList());
if (CollUtil.isEmpty(stcdList)) {
return false;
}
List<SdEngInfoBH> beforeList = this.lambdaQuery()
.in(SdEngInfoBH::getStcd, stcdList)
.eq(SdEngInfoBH::getIsDeleted, 0)
.list();
if (CollUtil.isEmpty(beforeList)) {
return false;
}
boolean result = this.update(new LambdaUpdateWrapper<SdEngInfoBH>()
.in(SdEngInfoBH::getStcd, stcdList)
.eq(SdEngInfoBH::getIsDeleted, 0)
.set(SdEngInfoBH::getIsDeleted, 1)
.set(SdEngInfoBH::getDeleteUser, SecurityUtils.getCurrentUsername())
.set(SdEngInfoBH::getDeleteTime, new Date()));
if (result) {
for (SdEngInfoBH before : beforeList) {
msOperationLogService.recordEngDeleteLog(before, source);
}
}
return result;
} }
@Override @Override