Browse Source

fix: 修复id为主键的bug;

test-20240527
龚宝雄 7 months ago
parent
commit
39bcf1df0f
  1. 10
      nlsso-server/src/main/java/org/nl/wms/database/eas/dao/EasOutInBill.java
  2. 8
      nlsso-server/src/main/java/org/nl/wms/database/eas/dao/xml/EasOutInBillDetailMapper.xml
  3. 45
      nlsso-server/src/main/java/org/nl/wms/database/eas/service/impl/EasOutInBillServiceImpl.java
  4. 5
      nlsso-server/src/main/java/org/nl/wms/schedule/EasBillSchedule.java

10
nlsso-server/src/main/java/org/nl/wms/database/eas/dao/EasOutInBill.java

@ -25,15 +25,17 @@ public class EasOutInBill extends Model<EasOutInBill> {
private static final long serialVersionUID = -7739291296662381393L; private static final long serialVersionUID = -7739291296662381393L;
/** /**
* eas单据id * eas单据id
*/ */
@TableId(value = "id", type = IdType.NONE) @TableId(value = "djid", type = IdType.NONE)
private String id; private String djid;
private String djid; /**
* id
*/
private String id;
/** /**

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

@ -7,7 +7,7 @@
FROM FROM
EAS_NOBLE.V_UC_OUTINBILL EAS_NOBLE.V_UC_OUTINBILL
WHERE DJZT = '提交' WHERE DJZT = '提交'
AND TO_DATE(cjsj, 'YYYY-MM-DD') >= TRUNC(SYSDATE) - INTERVAL '15' DAY(3) AND TO_DATE(cjsj, 'YYYY-MM-DD') >= TRUNC(SYSDATE) - INTERVAL '91' DAY(3)
</select> </select>
<select id="selectSrmPageWithInventory" resultType="org.nl.wms.database.eas.dao.EasOutInBillDetail"> <select id="selectSrmPageWithInventory" resultType="org.nl.wms.database.eas.dao.EasOutInBillDetail">
SELECT SELECT
@ -19,7 +19,7 @@
DJZT = '未入库' DJZT = '未入库'
AND CJSJ >= DATE_SUB( AND CJSJ >= DATE_SUB(
CURDATE(), CURDATE(),
INTERVAL 15 DAY) INTERVAL 91 DAY)
</select> </select>
<select id="selectEasIds" resultType="org.nl.wms.database.eas.dao.EasOutInBillDetail"> <select id="selectEasIds" resultType="org.nl.wms.database.eas.dao.EasOutInBillDetail">
SELECT SELECT
@ -27,13 +27,13 @@
FROM FROM
EAS_NOBLE.V_UC_OUTINBILL EAS_NOBLE.V_UC_OUTINBILL
WHERE DJZT = '提交' WHERE DJZT = '提交'
AND TO_DATE(cjsj, 'YYYY-MM-DD') >= TRUNC(SYSDATE) - INTERVAL '15' DAY(3) AND TO_DATE(cjsj, 'YYYY-MM-DD') >= TRUNC(SYSDATE) - INTERVAL '91' DAY(3)
</select> </select>
<select id="selectSrmIds" resultType="org.nl.wms.database.eas.dao.EasOutInBillDetail"> <select id="selectSrmIds" resultType="org.nl.wms.database.eas.dao.EasOutInBillDetail">
SELECT SELECT
FLID,DJID FLID,DJID
FROM V_WMS_INBILL_THIRD FROM V_WMS_INBILL_THIRD
WHERE DJZT='未入库' AND CJSJ >= DATE_SUB(CURDATE(), INTERVAL 15 DAY) WHERE DJZT='未入库' AND CJSJ >= DATE_SUB(CURDATE(), INTERVAL 91 DAY)
</select> </select>
<select id="selectByConditions" resultType="org.nl.wms.database.eas.dao.InventoryInfo"> <select id="selectByConditions" resultType="org.nl.wms.database.eas.dao.InventoryInfo">
SELECT SELECT

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

@ -177,20 +177,20 @@ public class EasOutInBillServiceImpl extends ServiceImpl<EasOutInBillMapper, Eas
try { try {
insertBills(easOutInBillDetails, existingIds); insertBills(easOutInBillDetails, existingIds);
} catch (Exception e) { } catch (Exception e) {
log.error("异常信息:" + e.toString()); log.error("异常信息:" + e);
} }
}, pool); }, pool);
CompletableFuture.runAsync(() -> { CompletableFuture.runAsync(() -> {
try { try {
updateBills(easOutInBillDetails, existingIds); updateBills(easOutInBillDetails, existingIds);
} catch (Exception e) { } catch (Exception e) {
log.error("异常信息:" + e.toString()); log.error("异常信息:" + e);
} }
}, pool); }, pool);
// CompletableFuture.runAsync(() -> { CompletableFuture.runAsync(() -> {
// //todo 检查事务是否会失效 //todo 检查事务是否会失效
// autoDeleteBill(easOutInBillDetails, existingIds); autoDeleteBill(easOutInBillDetails, existingIds);
// }, pool); }, pool);
} }
@ -254,10 +254,6 @@ public class EasOutInBillServiceImpl extends ServiceImpl<EasOutInBillMapper, Eas
return bill; return bill;
}) })
.collect(Collectors.toList()); .collect(Collectors.toList());
//主表
//easOutInBillMapper.insertBatch(billList);
//明细表
//easOutInBillDetailMapper.insertBatch(detailList);
CompletableFuture.runAsync(() -> { CompletableFuture.runAsync(() -> {
//主表 //主表
for (EasOutInBill entity : billList) { for (EasOutInBill entity : billList) {
@ -284,18 +280,24 @@ public class EasOutInBillServiceImpl extends ServiceImpl<EasOutInBillMapper, Eas
Set<String> ids = existingIds.stream().map(EasOutInBillDetail::getFlid).collect(Collectors.toSet()); Set<String> ids = existingIds.stream().map(EasOutInBillDetail::getFlid).collect(Collectors.toSet());
// 过滤出需要插入的新单据,并根据来源设置 ID // 过滤出需要插入的新单据,并根据来源设置 ID
List<EasOutInBillDetail> insertEasBills = easOutInBillDetails.stream() List<EasOutInBillDetail> insertEasBills = easOutInBillDetails.stream()
.filter(bill -> ids.contains(bill.getDjid())) .filter(r -> r.getXgsj() != null)
.collect(Collectors.toList()); .collect(Collectors.toList());
if (CollectionUtils.isNotEmpty(insertEasBills)) { if (CollectionUtils.isNotEmpty(insertEasBills)) {
//比较insertEasBills与existingIds的修改时间进行按需更新 //比较insertEasBills与existingIds的修改时间进行按需更新
for (EasOutInBillDetail entity : insertEasBills) { for (EasOutInBillDetail entity : insertEasBills) {
EasOutInBillDetail existing = existingIds.stream() EasOutInBillDetail existing = existingIds.stream()
.filter(e -> { .filter(e -> {
boolean isUpdate = false;
try { try {
return e.getFlid().equals(entity.getFlid()) && org.nl.common.utils.DateUtil.getDate(e.getXgsj()).after(org.nl.common.utils.DateUtil.getDate(entity.getXgsj())); if (e.getFlid().equals(entity.getFlid())) {
if (e.getXgsj() == null || org.nl.common.utils.DateUtil.getDate(entity.getXgsj()).after(org.nl.common.utils.DateUtil.getDate(e.getXgsj()))) {
isUpdate = true;
}
}
} catch (ParseException ex) { } catch (ParseException ex) {
throw new RuntimeException(ex); throw new RuntimeException(ex);
} }
return isUpdate;
}) })
.findFirst() .findFirst()
.orElse(null); .orElse(null);
@ -349,13 +351,19 @@ public class EasOutInBillServiceImpl extends ServiceImpl<EasOutInBillMapper, Eas
.filter(e -> !easFlidSet.contains(e.getFlid())) .filter(e -> !easFlidSet.contains(e.getFlid()))
.collect(Collectors.toList()); .collect(Collectors.toList());
if (CollectionUtils.isNotEmpty(idsToDelete)) { if (CollectionUtils.isNotEmpty(idsToDelete)) {
//找出idsToDelete中DJID相同且元素只有一个的集合,说明是最后一个明细行要被删除,那么主单据也要被删除 Map<String, Long> idCount1 = idsToDelete.stream()
Map<String, Long> idCounts = idsToDelete.stream() .collect(Collectors.groupingBy(EasOutInBillDetail::getDjid, Collectors.counting()));
Map<String, Long> idCount2 = existingIds.stream()
.collect(Collectors.groupingBy(EasOutInBillDetail::getDjid, Collectors.counting())); .collect(Collectors.groupingBy(EasOutInBillDetail::getDjid, Collectors.counting()));
Set<String> billIds = idCounts.entrySet().stream() Set<String> billIds = new HashSet<>();
.filter(entry -> entry.getValue() == 1) idCount1.forEach((k, v) -> {
.map(Map.Entry::getKey) //遍历idCount1中的djid,与idCount2的比较,如果相等,判断value的个等于idCount2,则记录key到一个新的set集合中
.collect(Collectors.toSet()); if (idCount2.containsKey(k)) {
if (idCount2.get(k).equals(v)) {
billIds.add(k);
}
}
});
if (CollectionUtils.isNotEmpty(billIds)) { if (CollectionUtils.isNotEmpty(billIds)) {
//删除主数据 //删除主数据
deleteAll(billIds); deleteAll(billIds);
@ -365,7 +373,6 @@ public class EasOutInBillServiceImpl extends ServiceImpl<EasOutInBillMapper, Eas
Set<String> filds = idsToDelete.stream().map(EasOutInBillDetail::getFlid).collect(Collectors.toSet()); Set<String> filds = idsToDelete.stream().map(EasOutInBillDetail::getFlid).collect(Collectors.toSet());
queryWrapper.in(EasOutInBillDetail::getFlid, filds); queryWrapper.in(EasOutInBillDetail::getFlid, filds);
easOutInBillDetailMapper.delete(queryWrapper); easOutInBillDetailMapper.delete(queryWrapper);
} }
} catch (Exception e) { } catch (Exception e) {
log.error("定时删除源头已删除单据-autoDeleteBill接口回滚,出现异常: {}", e); log.error("定时删除源头已删除单据-autoDeleteBill接口回滚,出现异常: {}", e);

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

@ -59,7 +59,7 @@ public class EasBillSchedule {
* eas单据数据同步 * eas单据数据同步
*/ */
@Async("taskExecutor") @Async("taskExecutor")
@Scheduled(cron = "0/120 * * * * *") @Scheduled(cron = "0/60 * * * * *")
public void getEasOutInBills() { public void getEasOutInBills() {
// 获取eas视图查询未提交的单据 // 获取eas视图查询未提交的单据
List<EasOutInBillDetail> easOutInBillDetails = easOutInBillDetailMapper.selectPageWithInventory(); List<EasOutInBillDetail> easOutInBillDetails = easOutInBillDetailMapper.selectPageWithInventory();
@ -136,7 +136,7 @@ public class EasBillSchedule {
* 定时清空单据 * 定时清空单据
*/ */
@Async("taskExecutor") @Async("taskExecutor")
//@Scheduled(cron = "0/86400 * * * * *") @Scheduled(cron = "0/86400 * * * * *")
public void autoDeleteTask() { public void autoDeleteTask() {
LocalDate threeMonthsAgo = LocalDate.now().minusMonths(3); LocalDate threeMonthsAgo = LocalDate.now().minusMonths(3);
String days = threeMonthsAgo.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")); String days = threeMonthsAgo.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
@ -206,7 +206,6 @@ public class EasBillSchedule {
queryWrapper.in(EasOutInBillDetail::getFlid, filds); queryWrapper.in(EasOutInBillDetail::getFlid, filds);
easOutInBillDetailMapper.delete(queryWrapper); easOutInBillDetailMapper.delete(queryWrapper);
} }
} }

Loading…
Cancel
Save