fix: 优化过鱼设施草稿数据日志联动
This commit is contained in:
parent
3156eda07f
commit
d28b75ec84
@ -0,0 +1,19 @@
|
||||
package com.yfd.platform.config;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.SerializationFeature;
|
||||
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
public class JacksonConfig {
|
||||
|
||||
@Bean
|
||||
public ObjectMapper objectMapper() {
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
mapper.registerModule(new JavaTimeModule());
|
||||
mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
|
||||
return mapper;
|
||||
}
|
||||
}
|
||||
@ -1,8 +1,12 @@
|
||||
package com.yfd.platform.data.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.yfd.platform.common.DataSourceRequest;
|
||||
import com.yfd.platform.config.ResponseResult;
|
||||
import com.yfd.platform.data.domain.ApprovalChangeLog;
|
||||
import com.yfd.platform.data.domain.ApprovalLog;
|
||||
import com.yfd.platform.data.service.IApprovalChangeLogService;
|
||||
import com.yfd.platform.utils.DataSourceRequestUtil;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.annotation.Resource;
|
||||
@ -31,6 +35,13 @@ public class ApprovalChangeLogController {
|
||||
return ResponseResult.successData(list);
|
||||
}
|
||||
|
||||
@PostMapping("/queryPageList")
|
||||
@Operation(summary = "分页查询变更记录列表(通用)")
|
||||
public ResponseResult queryPageList(@RequestBody DataSourceRequest request) {
|
||||
Page<ApprovalChangeLog> approvalChangeLogPage = DataSourceRequestUtil.executeQuery(request, ApprovalChangeLog.class, approvalChangeLogService);
|
||||
return ResponseResult.successData(approvalChangeLogPage);
|
||||
}
|
||||
|
||||
@GetMapping("/getByApprovalId")
|
||||
@Operation(summary = "根据审批批次ID查询变更记录")
|
||||
public ResponseResult getByApprovalId(@RequestParam String approvalId) {
|
||||
|
||||
@ -1,8 +1,12 @@
|
||||
package com.yfd.platform.data.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.yfd.platform.common.DataSourceRequest;
|
||||
import com.yfd.platform.config.ResponseResult;
|
||||
import com.yfd.platform.data.domain.ApprovalLog;
|
||||
import com.yfd.platform.data.domain.ApprovalMain;
|
||||
import com.yfd.platform.data.service.IApprovalLogService;
|
||||
import com.yfd.platform.utils.DataSourceRequestUtil;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.annotation.Resource;
|
||||
@ -31,6 +35,14 @@ public class ApprovalLogController {
|
||||
return ResponseResult.successData(list);
|
||||
}
|
||||
|
||||
@PostMapping("/queryPageList")
|
||||
@Operation(summary = "分页查询审批日志列表(通用)")
|
||||
public ResponseResult queryPageList(@RequestBody DataSourceRequest request) {
|
||||
Page<ApprovalLog> approvalLogPage = DataSourceRequestUtil.executeQuery(request, ApprovalLog.class, approvalLogService);
|
||||
return ResponseResult.successData(approvalLogPage);
|
||||
}
|
||||
|
||||
|
||||
@GetMapping("/getByApprovalId")
|
||||
@Operation(summary = "根据审批批次ID查询日志")
|
||||
public ResponseResult getByApprovalId(@RequestParam String approvalId) {
|
||||
|
||||
@ -1,9 +1,11 @@
|
||||
package com.yfd.platform.data.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.yfd.platform.common.DataSourceRequest;
|
||||
import com.yfd.platform.config.ResponseResult;
|
||||
import com.yfd.platform.data.domain.ApprovalMain;
|
||||
import com.yfd.platform.data.service.IApprovalMainService;
|
||||
import com.yfd.platform.utils.DataSourceRequestUtil;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.annotation.Resource;
|
||||
@ -36,6 +38,15 @@ public class ApprovalMainController {
|
||||
return ResponseResult.successData(result);
|
||||
}
|
||||
|
||||
@PostMapping("/queryPageList")
|
||||
@Operation(summary = "分页查询审批列表(通用)")
|
||||
public ResponseResult queryPageList(@RequestBody DataSourceRequest request) {
|
||||
Page<ApprovalMain> approvalMainPage = DataSourceRequestUtil.executeQuery(request, ApprovalMain.class, approvalMainService);
|
||||
return ResponseResult.successData(approvalMainPage);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@GetMapping("/getById")
|
||||
@Operation(summary = "根据ID查询审批")
|
||||
public ResponseResult getById(@RequestParam Long id) {
|
||||
|
||||
@ -7,11 +7,14 @@ import com.yfd.platform.data.domain.FishDraftData;
|
||||
import com.yfd.platform.data.domain.FishImportRequest;
|
||||
import com.yfd.platform.data.domain.FishImportResult;
|
||||
import com.yfd.platform.data.domain.ImportTask;
|
||||
import com.yfd.platform.data.domain.BatchApproveRequest;
|
||||
import com.yfd.platform.data.domain.BatchRejectRequest;
|
||||
import com.yfd.platform.data.domain.vo.FishDraftDataVO;
|
||||
import com.yfd.platform.data.service.IFishDraftDataService;
|
||||
import com.yfd.platform.data.service.IFishImportService;
|
||||
import com.yfd.platform.data.service.IImportTaskService;
|
||||
import com.yfd.platform.utils.KendoUtil;
|
||||
import com.yfd.platform.utils.SecurityUtils;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.annotation.Resource;
|
||||
@ -91,6 +94,19 @@ public class FishDraftDataController {
|
||||
return result ? ResponseResult.success("保存成功") : ResponseResult.error("保存失败");
|
||||
}
|
||||
|
||||
@PostMapping("/batchSaveDraft")
|
||||
@Operation(summary = "批量保存草稿")
|
||||
public ResponseResult saveDraft(@RequestBody List<FishDraftData> fishDraftDataList) {
|
||||
|
||||
fishDraftDataList.forEach(fishDraftData -> {
|
||||
fishDraftData.setStatus("DRAFT");
|
||||
fishDraftData.setDeletedFlag(0);
|
||||
fishDraftData.setLockFlag(0);
|
||||
});
|
||||
boolean result = fishDraftDataService.saveBatch(fishDraftDataList);
|
||||
return result ? ResponseResult.success("保存成功") : ResponseResult.error("保存失败");
|
||||
}
|
||||
|
||||
@PostMapping("/updateDraft")
|
||||
@Operation(summary = "更新草稿")
|
||||
public ResponseResult updateDraft(@RequestBody FishDraftData fishDraftData) {
|
||||
@ -130,17 +146,15 @@ public class FishDraftDataController {
|
||||
|
||||
@PostMapping("/batchApprove")
|
||||
@Operation(summary = "批量审批通过")
|
||||
public ResponseResult batchApprove(@RequestBody List<String> ids,
|
||||
@RequestParam(required = false) String approveComment) {
|
||||
boolean result = fishDraftDataService.batchApprove(ids, approveComment);
|
||||
public ResponseResult batchApprove(@RequestBody BatchApproveRequest request) {
|
||||
boolean result = fishDraftDataService.batchApprove(request.getIds(), request.getApproveComment());
|
||||
return result ? ResponseResult.success("审批通过") : ResponseResult.error("审批失败");
|
||||
}
|
||||
|
||||
@PostMapping("/reject")
|
||||
@Operation(summary = "审批驳回")
|
||||
public ResponseResult batchReject(@RequestParam String id,
|
||||
@RequestParam String rejectReason) {
|
||||
boolean result = fishDraftDataService.batchReject(id, rejectReason);
|
||||
public ResponseResult batchReject(@RequestBody BatchRejectRequest request) {
|
||||
boolean result = fishDraftDataService.batchReject(request.getId(), request.getRejectReason());
|
||||
return result ? ResponseResult.success("驳回成功") : ResponseResult.error("驳回失败");
|
||||
}
|
||||
|
||||
@ -168,9 +182,9 @@ public class FishDraftDataController {
|
||||
}
|
||||
|
||||
@PostMapping("/update")
|
||||
@Operation(summary = "修改过鱼数据")
|
||||
@Operation(summary = "审批人修改过鱼数据(记录变更日志)")
|
||||
public ResponseResult update(@RequestBody FishDraftData fishDraftData) {
|
||||
boolean result = fishDraftDataService.updateById(fishDraftData);
|
||||
boolean result = fishDraftDataService.updateByIdWithLog(fishDraftData);
|
||||
return result ? ResponseResult.success("修改成功") : ResponseResult.error("修改失败");
|
||||
}
|
||||
|
||||
@ -190,8 +204,7 @@ public class FishDraftDataController {
|
||||
|
||||
@PostMapping("/importZip")
|
||||
@Operation(summary = "导入ZIP过鱼数据(每个用户同时只能进行一次导入)")
|
||||
public ResponseResult importZip(@RequestParam("file") MultipartFile file,
|
||||
@RequestParam String uploadUserId) {
|
||||
public ResponseResult importZip(@RequestParam("file") MultipartFile file) {
|
||||
if (file == null || file.isEmpty()) {
|
||||
return ResponseResult.error("请上传文件");
|
||||
}
|
||||
@ -199,7 +212,7 @@ public class FishDraftDataController {
|
||||
if (fileName == null || (!fileName.endsWith(".zip"))) {
|
||||
return ResponseResult.error("请上传ZIP文件(.zip)");
|
||||
}
|
||||
|
||||
String uploadUserId = SecurityUtils.getUserId();
|
||||
if (importTaskService.hasImportingTask(uploadUserId)) {
|
||||
return ResponseResult.error("您有正在进行的导入任务,请等待完成后重试");
|
||||
}
|
||||
|
||||
@ -0,0 +1,20 @@
|
||||
package com.yfd.platform.data.domain;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 批量审批请求参数
|
||||
*/
|
||||
@Data
|
||||
@Schema(description = "批量审批请求参数")
|
||||
public class BatchApproveRequest {
|
||||
|
||||
@Schema(description = "草稿数据ID列表")
|
||||
private List<String> ids;
|
||||
|
||||
@Schema(description = "审批意见")
|
||||
private String approveComment;
|
||||
}
|
||||
@ -0,0 +1,18 @@
|
||||
package com.yfd.platform.data.domain;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 审批驳回请求参数
|
||||
*/
|
||||
@Data
|
||||
@Schema(description = "审批驳回请求参数")
|
||||
public class BatchRejectRequest {
|
||||
|
||||
@Schema(description = "草稿数据ID")
|
||||
private String id;
|
||||
|
||||
@Schema(description = "驳回原因")
|
||||
private String rejectReason;
|
||||
}
|
||||
@ -106,7 +106,7 @@ public class FishDraftData implements Serializable {
|
||||
/**
|
||||
* 审批批次ID
|
||||
*/
|
||||
private Long approvalId;
|
||||
private String approvalId;
|
||||
|
||||
/**
|
||||
* 状态(DRAFT未提交 / SUBMITTED已提交 / APPROVED已通过 / REJECTED已驳回)
|
||||
|
||||
@ -110,7 +110,7 @@ public class FishDraftDataVO implements Serializable {
|
||||
/**
|
||||
* 审批批次ID
|
||||
*/
|
||||
private Long approvalId;
|
||||
private String approvalId;
|
||||
|
||||
/**
|
||||
* 状态(DRAFT未提交 / SUBMITTED已提交 / APPROVED已通过 / REJECTED已驳回)
|
||||
|
||||
@ -86,4 +86,9 @@ public interface IFishDraftDataService extends IService<FishDraftData> {
|
||||
boolean unlockDraft(String id);
|
||||
|
||||
boolean batchRemoveDraft(List<String> ids);
|
||||
|
||||
/**
|
||||
* 审批人修改数据并记录变更日志
|
||||
*/
|
||||
boolean updateByIdWithLog(FishDraftData fishDraftData);
|
||||
}
|
||||
@ -7,22 +7,24 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.yfd.platform.common.DataSourceLoadOptionsBase;
|
||||
import com.yfd.platform.common.DataSourceRequest;
|
||||
import com.yfd.platform.data.domain.ApprovalMain;
|
||||
import com.yfd.platform.data.domain.FishDraftData;
|
||||
import com.yfd.platform.data.domain.vo.FishDraftDataVO;
|
||||
import com.yfd.platform.data.mapper.FishDraftDataMapper;
|
||||
import com.yfd.platform.data.service.IApprovalChangeLogService;
|
||||
import com.yfd.platform.data.service.IApprovalLogService;
|
||||
import com.yfd.platform.data.service.IApprovalMainService;
|
||||
import com.yfd.platform.data.service.IFishDraftDataService;
|
||||
import com.yfd.platform.utils.KendoUtil;
|
||||
import com.yfd.platform.utils.QgcQueryWrapperUtil;
|
||||
import com.yfd.platform.utils.SecurityUtils;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@ -41,6 +43,12 @@ public class FishDraftDataServiceImpl extends ServiceImpl<FishDraftDataMapper, F
|
||||
@Resource
|
||||
private IApprovalChangeLogService approvalChangeLogService;
|
||||
|
||||
@Resource
|
||||
private IApprovalLogService approvalLogService;
|
||||
|
||||
@Resource
|
||||
private ObjectMapper objectMapper;
|
||||
|
||||
@Override
|
||||
public Page<FishDraftDataVO> queryPageList(DataSourceRequest dataSourceRequest) {
|
||||
Page<FishDraftDataVO> page = KendoUtil.getPage(dataSourceRequest);
|
||||
@ -110,8 +118,28 @@ public class FishDraftDataServiceImpl extends ServiceImpl<FishDraftDataMapper, F
|
||||
if (existing == null || existing.getLockFlag() == 1) {
|
||||
return false;
|
||||
}
|
||||
fishDraftData.setStatus("DRAFT");
|
||||
return this.updateById(fishDraftData);
|
||||
boolean isSubmitted = existing.getApprovalId() != null && StrUtil.isNotBlank(existing.getApprovalId());
|
||||
try {
|
||||
String beforeJson = objectMapper.writeValueAsString(existing);
|
||||
fishDraftData.setStatus(existing.getStatus());
|
||||
boolean result = this.updateById(fishDraftData);
|
||||
if (result && isSubmitted) {
|
||||
FishDraftData after = this.getById(fishDraftData.getId());
|
||||
String afterJson = objectMapper.writeValueAsString(after);
|
||||
String changeJson = buildChangeJson(beforeJson, afterJson, existing, after);
|
||||
approvalChangeLogService.logChange(
|
||||
existing.getApprovalId(),
|
||||
fishDraftData.getId(),
|
||||
"FISH",
|
||||
"UPDATE",
|
||||
changeJson,
|
||||
SecurityUtils.getUserId()
|
||||
);
|
||||
}
|
||||
return result;
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("记录变更日志失败", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -147,22 +175,53 @@ public class FishDraftDataServiceImpl extends ServiceImpl<FishDraftDataMapper, F
|
||||
if (fishDraftData == null || fishDraftData.getLockFlag() == 1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ApprovalMain approvalMain = new ApprovalMain();
|
||||
approvalMain.setApprovalNo("APR" + System.currentTimeMillis());
|
||||
approvalMain.setBizType("FISH");
|
||||
approvalMain.setDataCount(1);
|
||||
approvalMain.setApplyUserId(operatorId);
|
||||
approvalMain.setApplyTime(new Date());
|
||||
approvalMain.setStatus("PENDING");
|
||||
approvalMainService.save(approvalMain);
|
||||
|
||||
fishDraftData.setApprovalId(approvalMain.getId());
|
||||
fishDraftData.setStatus("SUBMITTED");
|
||||
fishDraftData.setSubmitTime(new Date());
|
||||
return this.updateById(fishDraftData);
|
||||
boolean result = this.updateById(fishDraftData);
|
||||
if (result) {
|
||||
approvalLogService.logSubmit(approvalMain.getId(), operatorId, "提交草稿");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean submitDrafts(List<String> ids) {
|
||||
for (String id : ids) {
|
||||
FishDraftData fishDraftData = this.getById(id);
|
||||
if (fishDraftData != null && fishDraftData.getLockFlag() == 0) {
|
||||
fishDraftData.setStatus("SUBMITTED");
|
||||
fishDraftData.setSubmitTime(new Date());
|
||||
this.updateById(fishDraftData);
|
||||
}
|
||||
if (ids == null || ids.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
String operatorId = SecurityUtils.getUserId();
|
||||
|
||||
ApprovalMain approvalMain = new ApprovalMain();
|
||||
approvalMain.setApprovalNo("APR" + System.currentTimeMillis());
|
||||
approvalMain.setBizType("FISH");
|
||||
approvalMain.setDataCount(ids.size());
|
||||
approvalMain.setApplyUserId(operatorId);
|
||||
approvalMain.setApplyTime(new Date());
|
||||
approvalMain.setStatus("PENDING");
|
||||
approvalMainService.save(approvalMain);
|
||||
|
||||
LambdaUpdateWrapper<FishDraftData> updateWrapper = new LambdaUpdateWrapper<>();
|
||||
updateWrapper.in(FishDraftData::getId, ids);
|
||||
updateWrapper.eq(FishDraftData::getLockFlag, 0);
|
||||
updateWrapper.set(FishDraftData::getApprovalId, approvalMain.getId());
|
||||
updateWrapper.set(FishDraftData::getStatus, "SUBMITTED");
|
||||
updateWrapper.set(FishDraftData::getSubmitTime, new Date());
|
||||
this.update(updateWrapper);
|
||||
|
||||
|
||||
approvalLogService.logSubmit(approvalMain.getId(), operatorId, "批量提交草稿,共" + ids.size() + "条");
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -174,34 +233,73 @@ public class FishDraftDataServiceImpl extends ServiceImpl<FishDraftDataMapper, F
|
||||
return false;
|
||||
}
|
||||
Date now = new Date();
|
||||
for (String id : ids) {
|
||||
FishDraftData fishDraftData = this.getById(id);
|
||||
if (fishDraftData != null && "SUBMITTED".equals(fishDraftData.getStatus())) {
|
||||
fishDraftData.setStatus("APPROVED");
|
||||
fishDraftData.setApproveTime(now);
|
||||
fishDraftData.setUpdatedBy(SecurityUtils.getUserId());
|
||||
this.updateById(fishDraftData);
|
||||
String operatorId = SecurityUtils.getUserId();
|
||||
|
||||
List<FishDraftData> dataList = this.listByIds(ids);
|
||||
Set<String> processedApprovalIds = new HashSet<>();
|
||||
List<String> validIds = new ArrayList<>();
|
||||
|
||||
for (FishDraftData fishDraftData : dataList) {
|
||||
if ("SUBMITTED".equals(fishDraftData.getStatus())) {
|
||||
validIds.add(fishDraftData.getId());
|
||||
if (fishDraftData.getApprovalId() != null) {
|
||||
processedApprovalIds.add(fishDraftData.getApprovalId());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!validIds.isEmpty()) {
|
||||
LambdaUpdateWrapper<FishDraftData> updateWrapper = new LambdaUpdateWrapper<>();
|
||||
updateWrapper.in(FishDraftData::getId, validIds);
|
||||
updateWrapper.set(FishDraftData::getStatus, "APPROVED");
|
||||
updateWrapper.set(FishDraftData::getApproveTime, now);
|
||||
updateWrapper.set(FishDraftData::getUpdatedBy, operatorId);
|
||||
this.update(updateWrapper);
|
||||
for (String approvalId : processedApprovalIds) {
|
||||
ApprovalMain approvalMain = approvalMainService.getById(approvalId);
|
||||
approvalLogService.logApprove(approvalId, SecurityUtils.getUserId(), approveComment);
|
||||
if (approvalMain != null) {
|
||||
approvalMain.setStatus("APPROVED");
|
||||
approvalMain.setApproverId(operatorId);
|
||||
approvalMain.setApproveTime(now);
|
||||
approvalMain.setRemark(approveComment);
|
||||
approvalMainService.updateById(approvalMain);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean batchReject(String id, String rejectReason) {
|
||||
if (StrUtil.isBlank( id)) {
|
||||
if (StrUtil.isBlank(id)) {
|
||||
return false;
|
||||
}
|
||||
if (StrUtil.isBlank(rejectReason)) {
|
||||
throw new IllegalArgumentException("驳回原因不能为空");
|
||||
}
|
||||
Date now = new Date();
|
||||
String operatorId = SecurityUtils.getUserId();
|
||||
FishDraftData fishDraftData = this.getById(id);
|
||||
if (fishDraftData != null && "SUBMITTED".equals(fishDraftData.getStatus())) {
|
||||
fishDraftData.setStatus("REJECTED");
|
||||
fishDraftData.setApproveTime(now);
|
||||
fishDraftData.setUpdatedBy(SecurityUtils.getUserId());
|
||||
this.updateById(fishDraftData);
|
||||
fishDraftData.setUpdatedBy(operatorId);
|
||||
boolean result = this.updateById(fishDraftData);
|
||||
if (result && fishDraftData.getApprovalId() != null) {
|
||||
approvalLogService.logReject(fishDraftData.getApprovalId(), operatorId, rejectReason);
|
||||
ApprovalMain approvalMain = approvalMainService.getById(fishDraftData.getApprovalId());
|
||||
if (approvalMain != null) {
|
||||
approvalMain.setStatus("REJECTED");
|
||||
approvalMain.setApproverId(operatorId);
|
||||
approvalMain.setApproveTime(now);
|
||||
approvalMain.setRemark(rejectReason);
|
||||
approvalMainService.updateById(approvalMain);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@ -228,5 +326,66 @@ public class FishDraftDataServiceImpl extends ServiceImpl<FishDraftDataMapper, F
|
||||
return this.updateById(fishDraftData);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean updateByIdWithLog(FishDraftData fishDraftData) {
|
||||
FishDraftData existing = this.getById(fishDraftData.getId());
|
||||
if (existing == null) {
|
||||
return false;
|
||||
}
|
||||
if (existing.getApprovalId() == null || StrUtil.isBlank(existing.getApprovalId())) {
|
||||
return this.updateById(fishDraftData);
|
||||
}
|
||||
try {
|
||||
String beforeJson = objectMapper.writeValueAsString(existing);
|
||||
boolean result = this.updateById(fishDraftData);
|
||||
if (result) {
|
||||
FishDraftData after = this.getById(fishDraftData.getId());
|
||||
String afterJson = objectMapper.writeValueAsString(after);
|
||||
String changeJson = buildChangeJson(beforeJson, afterJson, existing, after);
|
||||
approvalChangeLogService.logChange(
|
||||
existing.getApprovalId(),
|
||||
fishDraftData.getId(),
|
||||
"FISH",
|
||||
"UPDATE",
|
||||
changeJson,
|
||||
SecurityUtils.getUserId()
|
||||
);
|
||||
}
|
||||
return result;
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("记录变更日志失败", e);
|
||||
}
|
||||
}
|
||||
|
||||
private String buildChangeJson(String beforeJson, String afterJson, FishDraftData before, FishDraftData after) {
|
||||
try {
|
||||
Map<String, Object> changeInfo = new LinkedHashMap<>();
|
||||
changeInfo.put("before", objectMapper.readTree(beforeJson));
|
||||
changeInfo.put("after", objectMapper.readTree(afterJson));
|
||||
List<String> changedFields = new ArrayList<>();
|
||||
if (!Objects.equals(before.getStcd(), after.getStcd())) changedFields.add("stcd");
|
||||
if (!Objects.equals(before.getTm(), after.getTm())) changedFields.add("tm");
|
||||
if (!Objects.equals(before.getFtp(), after.getFtp())) changedFields.add("ftp");
|
||||
if (!Objects.equals(before.getFsz(), after.getFsz())) changedFields.add("fsz");
|
||||
if (!Objects.equals(before.getFcnt(), after.getFcnt())) changedFields.add("fcnt");
|
||||
if (!Objects.equals(before.getFwet(), after.getFwet())) changedFields.add("fwet");
|
||||
if (!Objects.equals(before.getStrdt(), after.getStrdt())) changedFields.add("strdt");
|
||||
if (!Objects.equals(before.getEnddt(), after.getEnddt())) changedFields.add("enddt");
|
||||
if (!Objects.equals(before.getDirection(), after.getDirection())) changedFields.add("direction");
|
||||
if (!Objects.equals(before.getYr(), after.getYr())) changedFields.add("yr");
|
||||
if (!Objects.equals(before.getMouth(), after.getMouth())) changedFields.add("mouth");
|
||||
if (!Objects.equals(before.getVdpth(), after.getVdpth())) changedFields.add("vdpth");
|
||||
if (!Objects.equals(before.getPicpth(), after.getPicpth())) changedFields.add("picpth");
|
||||
if (!Objects.equals(before.getIsfs(), after.getIsfs())) changedFields.add("isfs");
|
||||
if (!Objects.equals(before.getSourceType(), after.getSourceType())) changedFields.add("sourceType");
|
||||
if (!Objects.equals(before.getStatus(), after.getStatus())) changedFields.add("status");
|
||||
changeInfo.put("changed_fields", changedFields);
|
||||
return objectMapper.writeValueAsString(changeInfo);
|
||||
} catch (Exception e) {
|
||||
return "{}";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user