fix: 优化逻辑
This commit is contained in:
parent
d9e15f9736
commit
645b97435c
@ -60,6 +60,8 @@ import java.util.*;
|
|||||||
@Slf4j
|
@Slf4j
|
||||||
public class FishDraftDataController {
|
public class FishDraftDataController {
|
||||||
|
|
||||||
|
private static final int IN_QUERY_BATCH_SIZE = 900;
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private IFishDraftDataService fishDraftDataService;
|
private IFishDraftDataService fishDraftDataService;
|
||||||
|
|
||||||
@ -368,11 +370,10 @@ public class FishDraftDataController {
|
|||||||
@PostMapping("/batchApproveByApprovalId")
|
@PostMapping("/batchApproveByApprovalId")
|
||||||
@Operation(summary = "根据审批批次全部审批通过")
|
@Operation(summary = "根据审批批次全部审批通过")
|
||||||
public ResponseResult batchApproveByApprovalId(@RequestBody BatchApproveRequest request) {
|
public ResponseResult batchApproveByApprovalId(@RequestBody BatchApproveRequest request) {
|
||||||
if (request.getApprovalIds().isEmpty()) {
|
if (request.getApprovalIds() == null || request.getApprovalIds().isEmpty()) {
|
||||||
return ResponseResult.error("请选择审批批次");
|
return ResponseResult.error("请选择审批批次");
|
||||||
}
|
}
|
||||||
List<FishDraftData> draft = fishDraftDataService.list(new LambdaQueryWrapper<FishDraftData>().eq(FishDraftData::getDeletedFlag, 0).in(FishDraftData::getApprovalId, request.getApprovalIds()).eq(FishDraftData::getStatus, "PENDING").select(FishDraftData::getId));
|
List<String> ids = listDraftIdsByApprovalIdsAndStatus(request.getApprovalIds(), "PENDING");
|
||||||
List<String> ids = draft.stream().map(FishDraftData::getId).toList();
|
|
||||||
boolean result = fishDraftDataService.batchApprove(ids, request.getApproveComment());
|
boolean result = fishDraftDataService.batchApprove(ids, request.getApproveComment());
|
||||||
return result ? ResponseResult.success("审批通过") : ResponseResult.error("审批失败");
|
return result ? ResponseResult.success("审批通过") : ResponseResult.error("审批失败");
|
||||||
}
|
}
|
||||||
@ -388,8 +389,7 @@ public class FishDraftDataController {
|
|||||||
@Operation(summary = "批量驳回")
|
@Operation(summary = "批量驳回")
|
||||||
public ResponseResult batchRejectFull(@RequestBody BatchRejectRequest request) {
|
public ResponseResult batchRejectFull(@RequestBody BatchRejectRequest request) {
|
||||||
if (request.getApprovalIds() != null && !request.getApprovalIds().isEmpty()) {
|
if (request.getApprovalIds() != null && !request.getApprovalIds().isEmpty()) {
|
||||||
List<FishDraftData> draft = fishDraftDataService.list(new LambdaQueryWrapper<FishDraftData>().eq(FishDraftData::getDeletedFlag, 0).in(FishDraftData::getApprovalId, request.getApprovalIds()).eq(FishDraftData::getStatus, "PENDING").select(FishDraftData::getId));
|
List<String> ids = listDraftIdsByApprovalIdsAndStatus(request.getApprovalIds(), "PENDING");
|
||||||
List<String> ids = draft.stream().map(FishDraftData::getId).toList();
|
|
||||||
boolean result = fishDraftDataService.rejectBatch(ids, request.getRejectReason());
|
boolean result = fishDraftDataService.rejectBatch(ids, request.getRejectReason());
|
||||||
return result ? ResponseResult.success("驳回成功") : ResponseResult.error("驳回失败");
|
return result ? ResponseResult.success("驳回成功") : ResponseResult.error("驳回失败");
|
||||||
}
|
}
|
||||||
@ -429,6 +429,47 @@ public class FishDraftDataController {
|
|||||||
return result ? ResponseResult.success("修改成功") : ResponseResult.error("修改失败");
|
return result ? ResponseResult.success("修改成功") : ResponseResult.error("修改失败");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private List<String> listDraftIdsByApprovalIdsAndStatus(List<String> approvalIds, String status) {
|
||||||
|
List<String> normalizedApprovalIds = normalizeBatchValues(approvalIds);
|
||||||
|
if (normalizedApprovalIds.isEmpty()) {
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
List<String> ids = new ArrayList<>();
|
||||||
|
for (List<String> batchApprovalIds : splitList(normalizedApprovalIds, IN_QUERY_BATCH_SIZE)) {
|
||||||
|
List<FishDraftData> draft = fishDraftDataService.list(new LambdaQueryWrapper<FishDraftData>()
|
||||||
|
.eq(FishDraftData::getDeletedFlag, 0)
|
||||||
|
.in(FishDraftData::getApprovalId, batchApprovalIds)
|
||||||
|
.eq(FishDraftData::getStatus, status)
|
||||||
|
.select(FishDraftData::getId));
|
||||||
|
ids.addAll(draft.stream().map(FishDraftData::getId).filter(StrUtil::isNotBlank).toList());
|
||||||
|
}
|
||||||
|
return ids;
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<String> normalizeBatchValues(List<String> values) {
|
||||||
|
if (values == null || values.isEmpty()) {
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
LinkedHashSet<String> normalized = new LinkedHashSet<>();
|
||||||
|
for (String value : values) {
|
||||||
|
if (StrUtil.isNotBlank(value)) {
|
||||||
|
normalized.add(value.trim());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new ArrayList<>(normalized);
|
||||||
|
}
|
||||||
|
|
||||||
|
private <T> List<List<T>> splitList(List<T> source, int batchSize) {
|
||||||
|
if (source == null || source.isEmpty()) {
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
List<List<T>> result = new ArrayList<>();
|
||||||
|
for (int i = 0; i < source.size(); i += batchSize) {
|
||||||
|
result.add(source.subList(i, Math.min(source.size(), i + batchSize)));
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
@PostMapping("/delete")
|
@PostMapping("/delete")
|
||||||
@Operation(summary = "删除过鱼数据")
|
@Operation(summary = "删除过鱼数据")
|
||||||
public ResponseResult delete(@RequestParam String id) {
|
public ResponseResult delete(@RequestParam String id) {
|
||||||
|
|||||||
@ -2,7 +2,6 @@ package com.yfd.platform.qgc_data.service.impl;
|
|||||||
|
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import com.yfd.platform.common.DataSourceLoadOptionsBase;
|
import com.yfd.platform.common.DataSourceLoadOptionsBase;
|
||||||
@ -48,6 +47,8 @@ import java.util.*;
|
|||||||
@Slf4j
|
@Slf4j
|
||||||
public class FishDraftDataServiceImpl extends ServiceImpl<FishDraftDataMapper, FishDraftData> implements IFishDraftDataService {
|
public class FishDraftDataServiceImpl extends ServiceImpl<FishDraftDataMapper, FishDraftData> implements IFishDraftDataService {
|
||||||
|
|
||||||
|
private static final int IN_QUERY_BATCH_SIZE = 200;
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private FishDraftDataMapper fishDraftDataMapper;
|
private FishDraftDataMapper fishDraftDataMapper;
|
||||||
|
|
||||||
@ -254,16 +255,15 @@ public class FishDraftDataServiceImpl extends ServiceImpl<FishDraftDataMapper, F
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean batchRemoveDraft(List<String> ids) {
|
public boolean batchRemoveDraft(List<String> ids) {
|
||||||
long count = this.count(new LambdaQueryWrapper<FishDraftData>().in(FishDraftData::getId, ids).eq(FishDraftData::getLockFlag, 1));
|
long count = countByIdsAndLockFlag(ids, 1);
|
||||||
if(count > 0){
|
if(count > 0){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
LambdaUpdateWrapper<FishDraftData> updateWrapper = new LambdaUpdateWrapper<>();
|
|
||||||
updateWrapper.in(FishDraftData::getId, ids);
|
|
||||||
updateWrapper.set(FishDraftData::getDeletedFlag, 1);
|
|
||||||
String userId = SecurityUtils.getUserId();
|
String userId = SecurityUtils.getUserId();
|
||||||
updateWrapper.set(FishDraftData::getDeletedBy,userId );
|
return updateByIdsInBatches(ids, entity -> {
|
||||||
return this.update(updateWrapper);
|
entity.setDeletedFlag(1);
|
||||||
|
entity.setDeletedBy(userId);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -313,13 +313,13 @@ public class FishDraftDataServiceImpl extends ServiceImpl<FishDraftDataMapper, F
|
|||||||
setUserDataScope(approvalMain);
|
setUserDataScope(approvalMain);
|
||||||
approvalMainService.save(approvalMain);
|
approvalMainService.save(approvalMain);
|
||||||
|
|
||||||
LambdaUpdateWrapper<FishDraftData> updateWrapper = new LambdaUpdateWrapper<>();
|
List<String> unlockedIds = listIdsByLockFlag(ids, 0);
|
||||||
updateWrapper.in(FishDraftData::getId, ids);
|
Date submitTime = new Date();
|
||||||
updateWrapper.eq(FishDraftData::getLockFlag, 0);
|
updateByIdsInBatches(unlockedIds, entity -> {
|
||||||
updateWrapper.set(FishDraftData::getApprovalId, approvalMain.getId());
|
entity.setApprovalId(approvalMain.getId());
|
||||||
updateWrapper.set(FishDraftData::getStatus, "PENDING");
|
entity.setStatus("PENDING");
|
||||||
updateWrapper.set(FishDraftData::getSubmitTime, new Date());
|
entity.setSubmitTime(submitTime);
|
||||||
this.update(updateWrapper);
|
});
|
||||||
|
|
||||||
|
|
||||||
approvalLogService.logSubmit(approvalMain.getId(), operatorId, "批量提交草稿,共" + ids.size() + "条");
|
approvalLogService.logSubmit(approvalMain.getId(), operatorId, "批量提交草稿,共" + ids.size() + "条");
|
||||||
@ -421,7 +421,7 @@ public class FishDraftDataServiceImpl extends ServiceImpl<FishDraftDataMapper, F
|
|||||||
Date now = new Date();
|
Date now = new Date();
|
||||||
String operatorId = SecurityUtils.getUserId();
|
String operatorId = SecurityUtils.getUserId();
|
||||||
|
|
||||||
List<FishDraftData> dataList = this.listByIds(ids);
|
List<FishDraftData> dataList = listByIdsInBatches(ids);
|
||||||
Set<String> processedApprovalIds = new HashSet<>();
|
Set<String> processedApprovalIds = new HashSet<>();
|
||||||
List<String> validIds = new ArrayList<>();
|
List<String> validIds = new ArrayList<>();
|
||||||
List<SdFpssR> fpssRList = new ArrayList<>();
|
List<SdFpssR> fpssRList = new ArrayList<>();
|
||||||
@ -438,12 +438,11 @@ public class FishDraftDataServiceImpl extends ServiceImpl<FishDraftDataMapper, F
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!validIds.isEmpty()) {
|
if (!validIds.isEmpty()) {
|
||||||
LambdaUpdateWrapper<FishDraftData> updateWrapper = new LambdaUpdateWrapper<>();
|
updateByIdsInBatches(validIds, entity -> {
|
||||||
updateWrapper.in(FishDraftData::getId, validIds);
|
entity.setStatus("APPROVED");
|
||||||
updateWrapper.set(FishDraftData::getStatus, "APPROVED");
|
entity.setApproveTime(now);
|
||||||
updateWrapper.set(FishDraftData::getApproveTime, now);
|
entity.setUpdatedBy(operatorId);
|
||||||
updateWrapper.set(FishDraftData::getUpdatedBy, operatorId);
|
});
|
||||||
this.update(updateWrapper);
|
|
||||||
boolean b = sdFpssRService.saveOrUpdateBatch(fpssRList);
|
boolean b = sdFpssRService.saveOrUpdateBatch(fpssRList);
|
||||||
log.info("=======================插入数据条数======================="+fpssRList.size());
|
log.info("=======================插入数据条数======================="+fpssRList.size());
|
||||||
for (String approvalId : processedApprovalIds) {
|
for (String approvalId : processedApprovalIds) {
|
||||||
@ -548,7 +547,7 @@ public class FishDraftDataServiceImpl extends ServiceImpl<FishDraftDataMapper, F
|
|||||||
Date now = new Date();
|
Date now = new Date();
|
||||||
String operatorId = SecurityUtils.getUserId();
|
String operatorId = SecurityUtils.getUserId();
|
||||||
|
|
||||||
List<FishDraftData> dataList = this.listByIds(ids);
|
List<FishDraftData> dataList = listByIdsInBatches(ids);
|
||||||
Set<String> processedApprovalIds = new HashSet<>();
|
Set<String> processedApprovalIds = new HashSet<>();
|
||||||
List<String> validIds = new ArrayList<>();
|
List<String> validIds = new ArrayList<>();
|
||||||
|
|
||||||
@ -562,12 +561,11 @@ public class FishDraftDataServiceImpl extends ServiceImpl<FishDraftDataMapper, F
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!validIds.isEmpty()) {
|
if (!validIds.isEmpty()) {
|
||||||
LambdaUpdateWrapper<FishDraftData> updateWrapper = new LambdaUpdateWrapper<>();
|
updateByIdsInBatches(validIds, entity -> {
|
||||||
updateWrapper.in(FishDraftData::getId, validIds);
|
entity.setStatus("REJECTED");
|
||||||
updateWrapper.set(FishDraftData::getStatus, "REJECTED");
|
entity.setApproveTime(now);
|
||||||
updateWrapper.set(FishDraftData::getApproveTime, now);
|
entity.setUpdatedBy(operatorId);
|
||||||
updateWrapper.set(FishDraftData::getUpdatedBy, operatorId);
|
});
|
||||||
this.update(updateWrapper);
|
|
||||||
|
|
||||||
for (String approvalId : processedApprovalIds) {
|
for (String approvalId : processedApprovalIds) {
|
||||||
approvalLogService.logReject(approvalId, operatorId, rejectReason);
|
approvalLogService.logReject(approvalId, operatorId, rejectReason);
|
||||||
@ -679,4 +677,90 @@ public class FishDraftDataServiceImpl extends ServiceImpl<FishDraftDataMapper, F
|
|||||||
log.info("批量保存草稿完成, 共{}条, 耗时{}ms", fishDraftDataList.size(), System.currentTimeMillis() - start);
|
log.info("批量保存草稿完成, 共{}条, 耗时{}ms", fishDraftDataList.size(), System.currentTimeMillis() - start);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private List<FishDraftData> listByIdsInBatches(List<String> ids) {
|
||||||
|
List<String> normalizedIds = normalizeBatchValues(ids);
|
||||||
|
if (normalizedIds.isEmpty()) {
|
||||||
|
return new ArrayList<>();
|
||||||
|
}
|
||||||
|
List<FishDraftData> result = new ArrayList<>();
|
||||||
|
for (List<String> batchIds : splitList(normalizedIds, IN_QUERY_BATCH_SIZE)) {
|
||||||
|
result.addAll(this.list(new LambdaQueryWrapper<FishDraftData>().in(FishDraftData::getId, batchIds)));
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private long countByIdsAndLockFlag(List<String> ids, Integer lockFlag) {
|
||||||
|
List<String> normalizedIds = normalizeBatchValues(ids);
|
||||||
|
if (normalizedIds.isEmpty()) {
|
||||||
|
return 0L;
|
||||||
|
}
|
||||||
|
long total = 0L;
|
||||||
|
for (List<String> batchIds : splitList(normalizedIds, IN_QUERY_BATCH_SIZE)) {
|
||||||
|
total += this.count(new LambdaQueryWrapper<FishDraftData>()
|
||||||
|
.in(FishDraftData::getId, batchIds)
|
||||||
|
.eq(FishDraftData::getLockFlag, lockFlag));
|
||||||
|
}
|
||||||
|
return total;
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<String> listIdsByLockFlag(List<String> ids, Integer lockFlag) {
|
||||||
|
List<String> normalizedIds = normalizeBatchValues(ids);
|
||||||
|
if (normalizedIds.isEmpty()) {
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
List<String> result = new ArrayList<>();
|
||||||
|
for (List<String> batchIds : splitList(normalizedIds, IN_QUERY_BATCH_SIZE)) {
|
||||||
|
List<FishDraftData> records = this.list(new LambdaQueryWrapper<FishDraftData>()
|
||||||
|
.select(FishDraftData::getId)
|
||||||
|
.in(FishDraftData::getId, batchIds)
|
||||||
|
.eq(FishDraftData::getLockFlag, lockFlag));
|
||||||
|
result.addAll(records.stream().map(FishDraftData::getId).filter(StrUtil::isNotBlank).toList());
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean updateByIdsInBatches(List<String> ids,
|
||||||
|
java.util.function.Consumer<FishDraftData> entityCustomizer) {
|
||||||
|
List<String> normalizedIds = normalizeBatchValues(ids);
|
||||||
|
if (normalizedIds.isEmpty()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
boolean updated = false;
|
||||||
|
for (List<String> batchIds : splitList(normalizedIds, IN_QUERY_BATCH_SIZE)) {
|
||||||
|
List<FishDraftData> batchEntities = new ArrayList<>(batchIds.size());
|
||||||
|
for (String batchId : batchIds) {
|
||||||
|
FishDraftData entity = new FishDraftData();
|
||||||
|
entity.setId(batchId);
|
||||||
|
entityCustomizer.accept(entity);
|
||||||
|
batchEntities.add(entity);
|
||||||
|
}
|
||||||
|
updated = this.updateBatchById(batchEntities, IN_QUERY_BATCH_SIZE) || updated;
|
||||||
|
}
|
||||||
|
return updated;
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<String> normalizeBatchValues(List<String> values) {
|
||||||
|
if (values == null || values.isEmpty()) {
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
LinkedHashSet<String> normalized = new LinkedHashSet<>();
|
||||||
|
for (String value : values) {
|
||||||
|
if (StrUtil.isNotBlank(value)) {
|
||||||
|
normalized.add(value.trim());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new ArrayList<>(normalized);
|
||||||
|
}
|
||||||
|
|
||||||
|
private <T> List<List<T>> splitList(List<T> source, int batchSize) {
|
||||||
|
if (source == null || source.isEmpty()) {
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
List<List<T>> result = new ArrayList<>();
|
||||||
|
for (int i = 0; i < source.size(); i += batchSize) {
|
||||||
|
result.add(source.subList(i, Math.min(source.size(), i + batchSize)));
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user