fix: 优化电站删除
This commit is contained in:
parent
76939be1af
commit
0b673d4620
@ -113,8 +113,9 @@ public class SdEngInfoBHController {
|
||||
@Log(module = "电站管理", value = "删除电站")
|
||||
@PostMapping("/delete")
|
||||
@Operation(summary = "删除电站")
|
||||
public ResponseResult delete(@RequestParam String stcd) {
|
||||
boolean result = engInfoBHService.deleteEngInfo(stcd);
|
||||
public ResponseResult delete(@RequestBody SdEngInfoBHOperateRequest request) {
|
||||
boolean result = engInfoBHService.deleteEngInfo(request == null ? null : request.getIds(),
|
||||
request == null ? null : request.getSource());
|
||||
return result ? ResponseResult.success("删除成功") : ResponseResult.error("删除失败");
|
||||
}
|
||||
|
||||
|
||||
@ -2,6 +2,7 @@ package com.yfd.platform.qgc_base.domain;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Data
|
||||
@ -9,5 +10,7 @@ public class SdEngInfoBHOperateRequest {
|
||||
|
||||
private Map<String, Object> engInfo;
|
||||
|
||||
private List<String> ids;
|
||||
|
||||
private String source;
|
||||
}
|
||||
|
||||
@ -7,4 +7,6 @@ public interface IMsOperationLogService {
|
||||
void recordEngAddLog(SdEngInfoBH engInfo, String source);
|
||||
|
||||
void recordEngUpdateLog(SdEngInfoBH before, SdEngInfoBH changeSet, String source);
|
||||
|
||||
void recordEngDeleteLog(SdEngInfoBH engInfo, String source);
|
||||
}
|
||||
|
||||
@ -70,6 +70,8 @@ public interface ISdEngInfoBHService extends IService<SdEngInfoBH> {
|
||||
*/
|
||||
boolean deleteEngInfo(String stcd);
|
||||
|
||||
boolean deleteEngInfo(List<String> ids, String source);
|
||||
|
||||
List<SdEngInfoBH> selectRegDropdown(SdEngInfoBHRequest sdEngInfoBHRequest);
|
||||
|
||||
EngBaseInfoVo getStInfoByStcd(String stcd);
|
||||
|
||||
@ -343,6 +343,41 @@ public class MsOperationLogServiceImpl implements IMsOperationLogService {
|
||||
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) {
|
||||
MsOperationLog log = new MsOperationLog();
|
||||
log.setOperator(resolveOperator());
|
||||
|
||||
@ -42,6 +42,7 @@ import org.springframework.util.StringUtils;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashMap;
|
||||
@ -503,8 +504,41 @@ public class SdEngInfoBHServiceImpl extends ServiceImpl<SdEngInfoBHMapper, SdEng
|
||||
|
||||
@Override
|
||||
public boolean deleteEngInfo(String stcd) {
|
||||
return this.update( new LambdaUpdateWrapper<SdEngInfoBH>().eq(SdEngInfoBH::getStcd, stcd).set(SdEngInfoBH::getIsDeleted, 1));
|
||||
// return this.removeById(stcd);
|
||||
if (StrUtil.isBlank(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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user