Commit 156aa5ea by 章家宝

fixbug(store audit):我已办从审批日志中查询我的动作

1 parent 0ef2aa64
......@@ -41,6 +41,8 @@ import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;
/**
* 门店审批服务实现。
......@@ -72,21 +74,25 @@ public class StoreApprovalServiceImpl implements StoreApprovalService {
@Override
public PageResult<StoreApprovalTaskVO> pageDone(StoreApprovalTaskQueryDTO query) {
// 从审批日志反查当前用户参与过审批(PASS / REJECT)的 listingId,
// 从审批日志反查当前用户参与过审批(PASS / REJECT)的记录,
// 避免多级审批时 approveUserId 被末级覆盖导致前级审批人查不到已办记录
List<Long> doneListingIds = storeApprovalLogMapper
List<StoreApprovalLog> myLogs = storeApprovalLogMapper
.selectList(new LambdaQueryWrapper<StoreApprovalLog>()
.eq(StoreApprovalLog::getOperatorId, CurrentUserHolder.getUserId())
.in(StoreApprovalLog::getAction,
List.of(ApprovalActionEnum.PASS.name(), ApprovalActionEnum.REJECT.name()))
.select(StoreApprovalLog::getListingId)
.groupBy(StoreApprovalLog::getListingId))
.stream().map(StoreApprovalLog::getListingId).distinct().toList();
.orderByDesc(StoreApprovalLog::getOperateTime));
// 每个 listingId 取最新一条日志,用于填充「我已办」的动作 / 意见
Map<Long, StoreApprovalLog> latestLogByListing = myLogs.stream()
.collect(Collectors.toMap(StoreApprovalLog::getListingId, Function.identity(), (a, b) -> a));
List<Long> doneListingIds = latestLogByListing.keySet().stream().toList();
LambdaQueryWrapper<StoreListing> wrapper = buildWrapper(query)
.in(StoreListing::getListingId, doneListingIds.isEmpty() ? List.of(-1L) : doneListingIds)
.orderByDesc(StoreListing::getApproveTime);
return pageTask(query, wrapper);
return pageTask(query, wrapper, latestLogByListing);
}
@Override
......@@ -283,10 +289,28 @@ public class StoreApprovalServiceImpl implements StoreApprovalService {
private PageResult<StoreApprovalTaskVO> pageTask(StoreApprovalTaskQueryDTO query,
LambdaQueryWrapper<StoreListing> wrapper) {
return pageTask(query, wrapper, Map.of());
}
private PageResult<StoreApprovalTaskVO> pageTask(StoreApprovalTaskQueryDTO query,
LambdaQueryWrapper<StoreListing> wrapper,
Map<Long, StoreApprovalLog> logByListing) {
Page<StoreListing> page = storeListingMapper.selectPage(
new Page<>(query.getCurrent(), query.getSize()), wrapper);
List<StoreApprovalTaskVO> records = page.getRecords().stream()
.map(storeListingAssembler::toTaskVO).toList();
if (!logByListing.isEmpty()) {
for (StoreApprovalTaskVO vo : records) {
StoreApprovalLog log = logByListing.get(vo.getListingId());
if (log == null) {
continue;
}
vo.setMyAction(log.getAction());
vo.setMyActionLabel(ApprovalActionEnum.valueOf(log.getAction()).getLabel());
vo.setHandleOpinion(log.getReason());
vo.setHandleTime(log.getOperateTime());
}
}
return PageResult.of(records, page.getTotal(), page.getCurrent(), page.getSize());
}
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!