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;
/**
* eas单据id
*/
@TableId(value = "id", type = IdType.NONE)
private String id;
@TableId(value = "djid", type = IdType.NONE)
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
EAS_NOBLE.V_UC_OUTINBILL
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 id="selectSrmPageWithInventory" resultType="org.nl.wms.database.eas.dao.EasOutInBillDetail">
SELECT
@ -19,7 +19,7 @@
DJZT = '未入库'
AND CJSJ >= DATE_SUB(
CURDATE(),
INTERVAL 15 DAY)
INTERVAL 91 DAY)
</select>
<select id="selectEasIds" resultType="org.nl.wms.database.eas.dao.EasOutInBillDetail">
SELECT
@ -27,13 +27,13 @@
FROM
EAS_NOBLE.V_UC_OUTINBILL
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 id="selectSrmIds" resultType="org.nl.wms.database.eas.dao.EasOutInBillDetail">
SELECT
FLID,DJID
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 id="selectByConditions" resultType="org.nl.wms.database.eas.dao.InventoryInfo">
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 {
insertBills(easOutInBillDetails, existingIds);
} catch (Exception e) {
log.error("异常信息:" + e.toString());
log.error("异常信息:" + e);
}
}, pool);
CompletableFuture.runAsync(() -> {
try {
updateBills(easOutInBillDetails, existingIds);
} catch (Exception e) {
log.error("异常信息:" + e.toString());
log.error("异常信息:" + e);
}
}, pool);
// CompletableFuture.runAsync(() -> {
// //todo 检查事务是否会失效
// autoDeleteBill(easOutInBillDetails, existingIds);
// }, pool);
CompletableFuture.runAsync(() -> {
//todo 检查事务是否会失效
autoDeleteBill(easOutInBillDetails, existingIds);
}, pool);
}
@ -254,10 +254,6 @@ public class EasOutInBillServiceImpl extends ServiceImpl<EasOutInBillMapper, Eas
return bill;
})
.collect(Collectors.toList());
//主表
//easOutInBillMapper.insertBatch(billList);
//明细表
//easOutInBillDetailMapper.insertBatch(detailList);
CompletableFuture.runAsync(() -> {
//主表
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());
// 过滤出需要插入的新单据,并根据来源设置 ID
List<EasOutInBillDetail> insertEasBills = easOutInBillDetails.stream()
.filter(bill -> ids.contains(bill.getDjid()))
.filter(r -> r.getXgsj() != null)
.collect(Collectors.toList());
if (CollectionUtils.isNotEmpty(insertEasBills)) {
//比较insertEasBills与existingIds的修改时间进行按需更新
for (EasOutInBillDetail entity : insertEasBills) {
EasOutInBillDetail existing = existingIds.stream()
.filter(e -> {
boolean isUpdate = false;
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) {
throw new RuntimeException(ex);
}
return isUpdate;
})
.findFirst()
.orElse(null);
@ -349,13 +351,19 @@ public class EasOutInBillServiceImpl extends ServiceImpl<EasOutInBillMapper, Eas
.filter(e -> !easFlidSet.contains(e.getFlid()))
.collect(Collectors.toList());
if (CollectionUtils.isNotEmpty(idsToDelete)) {
//找出idsToDelete中DJID相同且元素只有一个的集合,说明是最后一个明细行要被删除,那么主单据也要被删除
Map<String, Long> idCounts = idsToDelete.stream()
Map<String, Long> idCount1 = idsToDelete.stream()
.collect(Collectors.groupingBy(EasOutInBillDetail::getDjid, Collectors.counting()));
Map<String, Long> idCount2 = existingIds.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());
Set<String> billIds = new HashSet<>();
idCount1.forEach((k, v) -> {
//遍历idCount1中的djid,与idCount2的比较,如果相等,判断value的个等于idCount2,则记录key到一个新的set集合中
if (idCount2.containsKey(k)) {
if (idCount2.get(k).equals(v)) {
billIds.add(k);
}
}
});
if (CollectionUtils.isNotEmpty(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());
queryWrapper.in(EasOutInBillDetail::getFlid, filds);
easOutInBillDetailMapper.delete(queryWrapper);
}
} catch (Exception 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单据数据同步
*/
@Async("taskExecutor")
@Scheduled(cron = "0/120 * * * * *")
@Scheduled(cron = "0/60 * * * * *")
public void getEasOutInBills() {
// 获取eas视图查询未提交的单据
List<EasOutInBillDetail> easOutInBillDetails = easOutInBillDetailMapper.selectPageWithInventory();
@ -136,7 +136,7 @@ public class EasBillSchedule {
* 定时清空单据
*/
@Async("taskExecutor")
//@Scheduled(cron = "0/86400 * * * * *")
@Scheduled(cron = "0/86400 * * * * *")
public void autoDeleteTask() {
LocalDate threeMonthsAgo = LocalDate.now().minusMonths(3);
String days = threeMonthsAgo.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
@ -206,7 +206,6 @@ public class EasBillSchedule {
queryWrapper.in(EasOutInBillDetail::getFlid, filds);
easOutInBillDetailMapper.delete(queryWrapper);
}
}

Loading…
Cancel
Save