|
|
@ -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); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|