Browse Source

opt: 单据批量自动审核;

test-20240527
龚宝雄 7 months ago
parent
commit
fbe2337cd2
  1. 4
      nlsso-server/src/main/java/org/nl/wms/database/eas/dao/xml/EasOutInBillDetailMapper.xml
  2. 2
      nlsso-server/src/main/java/org/nl/wms/database/eas/service/impl/EasOutInBillDetailServiceImpl.java
  3. 66
      nlsso-server/src/main/java/org/nl/wms/database/eas/service/impl/EasOutInBillServiceImpl.java
  4. 171
      nlsso-server/src/main/java/org/nl/wms/schedule/EasBillSchedule.java

4
nlsso-server/src/main/java/org/nl/wms/database/eas/dao/xml/EasOutInBillDetailMapper.xml

@ -7,7 +7,7 @@
FROM
EAS_NOBLE.V_UC_OUTINBILL
WHERE DJZT = '提交'
AND TO_DATE(cjsj, 'YYYY-MM-DD') >= TRUNC(SYSDATE) - INTERVAL '7' DAY(3)
AND TO_DATE(cjsj, 'YYYY-MM-DD') >= TRUNC(SYSDATE) - INTERVAL '15' DAY(3)
</select>
<select id="selectSrmPageWithInventory" resultType="org.nl.wms.database.eas.dao.EasOutInBillDetail">
SELECT
@ -27,7 +27,7 @@
FROM
EAS_NOBLE.V_UC_OUTINBILL
WHERE DJZT = '提交'
AND TO_DATE(cjsj, 'YYYY-MM-DD') >= TRUNC(SYSDATE) - INTERVAL '7' DAY(3)
AND TO_DATE(cjsj, 'YYYY-MM-DD') >= TRUNC(SYSDATE) - INTERVAL '15' DAY(3)
</select>
<select id="selectSrmIds" resultType="org.nl.wms.database.eas.dao.EasOutInBillDetail">
SELECT

2
nlsso-server/src/main/java/org/nl/wms/database/eas/service/impl/EasOutInBillDetailServiceImpl.java

@ -209,7 +209,7 @@ public class EasOutInBillDetailServiceImpl extends ServiceImpl<EasOutInBillDetai
updateWrapper.set("update_name", SecurityUtils.getCurrentNickName());
updateWrapper.set("update_time", DateUtil.format(DateUtil.beginOfDay(DateUtil.date()), "yyyy-MM-dd"));
easOutInBillDetailMapper.update(null, updateWrapper);
ieasOutInBillService.audit(ids,false);
//ieasOutInBillService.audit(ids,false);
});
} else {
boolean isValid = entityList.stream()

66
nlsso-server/src/main/java/org/nl/wms/database/eas/service/impl/EasOutInBillServiceImpl.java

@ -186,12 +186,8 @@ public class EasOutInBillServiceImpl extends ServiceImpl<EasOutInBillMapper, Eas
}
}, pool);
CompletableFuture.runAsync(() -> {
try {
//todo 检查事务是否会失效
autoDeleteBill(easOutInBillDetails, existingIds);
} catch (Exception e) {
log.error("异常信息:" + e.toString());
}
}, pool);
}
@ -337,35 +333,39 @@ public class EasOutInBillServiceImpl extends ServiceImpl<EasOutInBillMapper, Eas
* 定时删除源头已删除单据
*/
@Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Exception.class)
@Transactional(rollbackFor = Exception.class)
public void autoDeleteBill(List<EasOutInBillDetail> easOutInBillDetails, List<EasOutInBillDetail> existingIds) {
// 获取easOutInBillDetails中flid字段的集合
Set<String> easFlidSet = easOutInBillDetails.stream()
.map(EasOutInBillDetail::getFlid)
.collect(Collectors.toSet());
// 找出existingIds中flid字段集合不在easOutInBillDetails中flid字段集合中的记录
List<EasOutInBillDetail> idsToDelete = existingIds.stream()
.filter(e -> !easFlidSet.contains(e.getFlid()))
.collect(Collectors.toList());
if (CollectionUtils.isNotEmpty(idsToDelete)) {
//找出idsToDelete中DJID相同且元素只有一个的集合,说明是最后一个明细行要被删除,那么主单据也要被删除
Map<String, Long> idCounts = idsToDelete.stream()
.collect(Collectors.groupingBy(EasOutInBillDetail::getDjid, Collectors.counting()));
Set<String> billIds = idCounts.entrySet().stream()
.filter(entry -> entry.getValue() == 1)
.map(Map.Entry::getKey)
try {
// 获取easOutInBillDetails中flid字段的集合
Set<String> easFlidSet = easOutInBillDetails.stream()
.map(EasOutInBillDetail::getFlid)
.collect(Collectors.toSet());
if (CollectionUtils.isNotEmpty(billIds)) {
//删除主数据
deleteAll(billIds);
// 找出existingIds中flid字段集合不在easOutInBillDetails中flid字段集合中的记录
List<EasOutInBillDetail> idsToDelete = existingIds.stream()
.filter(e -> !easFlidSet.contains(e.getFlid()))
.collect(Collectors.toList());
if (CollectionUtils.isNotEmpty(idsToDelete)) {
//找出idsToDelete中DJID相同且元素只有一个的集合,说明是最后一个明细行要被删除,那么主单据也要被删除
Map<String, Long> idCounts = idsToDelete.stream()
.collect(Collectors.groupingBy(EasOutInBillDetail::getDjid, Collectors.counting()));
Set<String> billIds = idCounts.entrySet().stream()
.filter(entry -> entry.getValue() == 1)
.map(Map.Entry::getKey)
.collect(Collectors.toSet());
if (CollectionUtils.isNotEmpty(billIds)) {
//删除主数据
deleteAll(billIds);
}
//删除明细单据
LambdaQueryWrapper<EasOutInBillDetail> queryWrapper = new LambdaQueryWrapper<>();
Set<String> filds = idsToDelete.stream().map(EasOutInBillDetail::getFlid).collect(Collectors.toSet());
queryWrapper.in(EasOutInBillDetail::getFlid, filds);
easOutInBillDetailMapper.delete(queryWrapper);
}
//删除明细单据
LambdaQueryWrapper<EasOutInBillDetail> queryWrapper = new LambdaQueryWrapper<>();
Set<String> filds = idsToDelete.stream().map(EasOutInBillDetail::getFlid).collect(Collectors.toSet());
queryWrapper.in(EasOutInBillDetail::getFlid, filds);
easOutInBillDetailMapper.delete(queryWrapper);
} catch (Exception e) {
log.error("定时删除源头已删除单据-autoDeleteBill接口回滚,出现异常: {}", e);
}
}
@ -429,10 +429,10 @@ public class EasOutInBillServiceImpl extends ServiceImpl<EasOutInBillMapper, Eas
List<EasOutInBillDto> easOutInBillList = easOutInBillMapper.queryBillList(ids);
//所有明细表
List<EasOutInBillDetailDto> easOutInBillDetailList = easOutInBillDetailMapper.queryBillDetailList(ids);
long count = easOutInBillDetailList.stream().filter(r -> r.getQty().compareTo(BigDecimal.ZERO) == 0).count();
if (count == easOutInBillDetailList.size()) {
throw new BadRequestException("该单据无任何出入库操作,请检查");
}
long count = easOutInBillDetailList.stream().filter(r -> r.getQty().compareTo(BigDecimal.ZERO) == 0).count();
if (count == easOutInBillDetailList.size()) {
throw new BadRequestException("该单据无任何出入库操作,请检查");
}
//报文组合
if (CollectionUtils.isNotEmpty(easOutInBillList)) {
easOutInBillList.forEach(b -> {

171
nlsso-server/src/main/java/org/nl/wms/schedule/EasBillSchedule.java

@ -59,7 +59,7 @@ public class EasBillSchedule {
* eas单据数据同步
*/
@Async("taskExecutor")
@Scheduled(cron = "0/30 * * * * *")
@Scheduled(cron = "0/60 * * * * *")
public void getEasOutInBills() {
// 获取eas视图查询未提交的单据
List<EasOutInBillDetail> easOutInBillDetails = easOutInBillDetailMapper.selectPageWithInventory();
@ -81,30 +81,41 @@ public class EasBillSchedule {
* eas单据自动审核
*/
@Async("taskExecutor")
@Scheduled(cron = "0/30 * * * * *")
@Scheduled(cron = "0/60 * * * * *")
@Transactional(rollbackFor = Exception.class)
public void automaticAuditBills() {
// 单据明细批量出入库单
List<EasOutInBillDetail> easOutInBillDetailList1 = easOutInBillDetailMapper
.selectList(new LambdaQueryWrapper<EasOutInBillDetail>().eq(EasOutInBillDetail::getDjzt, "1"));
List<String> djIdList1 = easOutInBillDetailList1.stream()
.map(EasOutInBillDetail::getDjid)
.distinct()
.collect(Collectors.toList());
//单个明细出入库单
List<EasOutInBillDetail> easOutInBillDetailList2 = easOutInBillDetailMapper
.selectList(new LambdaQueryWrapper<EasOutInBillDetail>().eq(EasOutInBillDetail::getDjzt, "2"));
Map<String, Long> groupSizeMap = easOutInBillDetailList2.stream()
.collect(Collectors.groupingBy(EasOutInBillDetail::getDjid, Collectors.counting()));
List<String> djIdList2 = new ArrayList<>();
groupSizeMap.forEach((id, count) -> {
List<EasOutInBill> billList = easOutInBillService
.list(new LambdaQueryWrapper<EasOutInBill>().eq(EasOutInBill::getDjid, id));
if (billList.size() == count) {
djIdList2.add(id);
try {
// 单据明细批量出入库单
List<EasOutInBillDetail> easOutInBillDetailList1 = easOutInBillDetailMapper
.selectList(new LambdaQueryWrapper<EasOutInBillDetail>().eq(EasOutInBillDetail::getDjzt, "2"));
List<String> djIdList1 = new ArrayList<>();
if (!easOutInBillDetailList1.isEmpty()) {
List<String> distinctList = easOutInBillDetailList1.stream()
.map(EasOutInBillDetail::getDjid)
.distinct()
.collect(Collectors.toList());
djIdList1.addAll(distinctList);
}
List<String> djIdList2 = new ArrayList<>();
//单个明细出入库单
List<EasOutInBillDetail> easOutInBillDetailList2 = easOutInBillDetailMapper
.selectList(new LambdaQueryWrapper<EasOutInBillDetail>().eq(EasOutInBillDetail::getDjzt, "1"));
if (!easOutInBillDetailList2.isEmpty()) {
Map<String, Long> groupSizeMap = easOutInBillDetailList2.stream()
.collect(Collectors.groupingBy(EasOutInBillDetail::getDjid, Collectors.counting()));
groupSizeMap.forEach((id, count) -> {
//有多少笔明细行,如果被标记待审核的明细行数量=该单据所有明细行数量,则表示单据满足自动审核条件
List<EasOutInBillDetail> billList = easOutInBillDetailMapper
.selectList(new LambdaQueryWrapper<EasOutInBillDetail>().eq(EasOutInBillDetail::getDjid, id));
if (billList.size() == count) {
djIdList2.add(id);
}
});
}
});
updateBillInBatch(djIdList1, djIdList2);
updateBillInBatch(djIdList1, djIdList2);
} catch (Exception e) {
log.error("eas单据自动审核-automaticAuditBills接口回滚,出现异常:", e);
}
}
@ -123,6 +134,47 @@ public class EasBillSchedule {
}
}
/**
* 定时清空单据
*/
@Async("taskExecutor")
@Scheduled(cron = "0/86400 * * * * *")
public void autoDeleteTask() {
LocalDate threeMonthsAgo = LocalDate.now().minusMonths(3);
String days = threeMonthsAgo.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
//查询三个月前的数据
LambdaQueryWrapper<EasOutInBill> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.lt(EasOutInBill::getCjsj, days);
List<EasOutInBill> oldBills = easOutInBillService.list(queryWrapper);
if (CollectionUtils.isNotEmpty(oldBills)) {
Set<String> ids = oldBills.stream().map(EasOutInBill::getDjid).collect(Collectors.toSet());
if (CollectionUtils.isNotEmpty(ids)) {
easOutInBillDetailMapper.deleteDetail(ids);
}
easOutInBillDetailMapper.deleteInfo(days);
}
}
/**
* 首页信息推送
*/
@Async("taskExecutor")
@Scheduled(cron = "0/4 * * * * *")
public void sendHomeInfoTask() {
//StopWatch stopWatch = new StopWatch();
//stopWatch.start();
CopyOnWriteArraySet<SendHomeWebSocketServer> webSocketSet =
SendHomeWebSocketServer.getWebSocketSet();
if (webSocketSet.size() > 0) {
webSocketSet.forEach(c -> {
c.sendDataToClient(easOutInBillService.getBillsCount());
});
}
//stopWatch.stop();
//System.out.println("1task-首页及头部信息推送-sendHomeInfoTask-花费时间----------------------------------------------------------------****************************************************************= totalTime = " + stopWatch.getTotalTimeMillis());
}
/**
* 定时删除源头已删除单据
@ -160,79 +212,4 @@ public class EasBillSchedule {
}
/**
* 定时删除源头已删除单据
*/
@Async("taskExecutor")
@Transactional(rollbackFor = Exception.class)
public void autoDeleteBills(List<EasOutInBillDetail> easOutInBillDetails, List<EasOutInBillDetail> existingIds) {
// 获取easOutInBillDetails中flid字段的集合
Set<String> easFlidSet = easOutInBillDetails.stream()
.map(EasOutInBillDetail::getFlid)
.collect(Collectors.toSet());
// 找出existingIds中flid字段集合不在easOutInBillDetails中flid字段集合中的记录
List<EasOutInBillDetail> idsToDelete = existingIds.stream()
.filter(e -> !easFlidSet.contains(e.getFlid()))
.collect(Collectors.toList());
// 找出idsToDelete中DJID相同且元素只有一个的集合,说明是最后一个明细行要被删除,那么主单据也要被删除
Set<String> billIds = idsToDelete.stream()
.collect(Collectors.groupingBy(EasOutInBillDetail::getDjid, Collectors.counting()))
.entrySet().stream()
.filter(entry -> entry.getValue() == 1)
.map(Map.Entry::getKey)
.collect(Collectors.toSet());
if (CollectionUtils.isNotEmpty(billIds)) {
// 删除主数据
easOutInBillService.deleteAll(billIds);
}
// 删除明细单据
if (CollectionUtils.isNotEmpty(idsToDelete)) {
LambdaQueryWrapper<EasOutInBillDetail> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.in(EasOutInBillDetail::getFlid, idsToDelete);
easOutInBillDetailMapper.delete(queryWrapper);
}
}
/**
* 首页信息推送
*/
@Async("taskExecutor")
@Scheduled(cron = "0/4 * * * * *")
public void sendHomeInfoTask() {
//StopWatch stopWatch = new StopWatch();
//stopWatch.start();
CopyOnWriteArraySet<SendHomeWebSocketServer> webSocketSet =
SendHomeWebSocketServer.getWebSocketSet();
if (webSocketSet.size() > 0) {
webSocketSet.forEach(c -> {
c.sendDataToClient(easOutInBillService.getBillsCount());
});
}
//stopWatch.stop();
//System.out.println("1task-首页及头部信息推送-sendHomeInfoTask-花费时间----------------------------------------------------------------****************************************************************= totalTime = " + stopWatch.getTotalTimeMillis());
}
/**
* 定时清空单据
*/
@Async("taskExecutor")
@Scheduled(cron = "0/86400 * * * * *")
public void autoDeleteTask() {
LocalDate threeMonthsAgo = LocalDate.now().minusMonths(3);
String days = threeMonthsAgo.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
//查询三个月前的数据
LambdaQueryWrapper<EasOutInBill> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.lt(EasOutInBill::getCjsj, days);
List<EasOutInBill> oldBills = easOutInBillService.list(queryWrapper);
if (CollectionUtils.isNotEmpty(oldBills)) {
Set<String> ids = oldBills.stream().map(EasOutInBill::getDjid).collect(Collectors.toSet());
if (CollectionUtils.isNotEmpty(ids)) {
easOutInBillDetailMapper.deleteDetail(ids);
}
easOutInBillDetailMapper.deleteInfo(days);
}
}
}

Loading…
Cancel
Save