diff --git a/base-buildpackage/src/main/java/com/hzya/frame/voucher/ae/push/dao/IAePushVoucherLogDao.java b/base-buildpackage/src/main/java/com/hzya/frame/voucher/ae/push/dao/IAePushVoucherLogDao.java index 07945b96..ee591603 100644 --- a/base-buildpackage/src/main/java/com/hzya/frame/voucher/ae/push/dao/IAePushVoucherLogDao.java +++ b/base-buildpackage/src/main/java/com/hzya/frame/voucher/ae/push/dao/IAePushVoucherLogDao.java @@ -11,5 +11,6 @@ import com.hzya.frame.basedao.dao.IBaseDao; */ public interface IAePushVoucherLogDao extends IBaseDao { + AePushVoucherLogEntity saveOrUpdateBymdmIdAndBillCodeAndTypeId(AePushVoucherLogEntity aePushVoucherLogEntity); } diff --git a/base-buildpackage/src/main/java/com/hzya/frame/voucher/ae/push/dao/impl/AePushVoucherLogDaoImpl.java b/base-buildpackage/src/main/java/com/hzya/frame/voucher/ae/push/dao/impl/AePushVoucherLogDaoImpl.java index 12b41112..20edb41d 100644 --- a/base-buildpackage/src/main/java/com/hzya/frame/voucher/ae/push/dao/impl/AePushVoucherLogDaoImpl.java +++ b/base-buildpackage/src/main/java/com/hzya/frame/voucher/ae/push/dao/impl/AePushVoucherLogDaoImpl.java @@ -1,9 +1,13 @@ package com.hzya.frame.voucher.ae.push.dao.impl; +import cn.hutool.core.lang.Assert; import com.hzya.frame.voucher.ae.push.entity.AePushVoucherLogEntity; import com.hzya.frame.voucher.ae.push.dao.IAePushVoucherLogDao; import org.springframework.stereotype.Repository; import com.hzya.frame.basedao.dao.MybatisGenericDao; + +import java.util.List; + /** * (AePushVoucherLog)表数据库访问层 * @@ -12,6 +16,29 @@ import com.hzya.frame.basedao.dao.MybatisGenericDao; */ @Repository public class AePushVoucherLogDaoImpl extends MybatisGenericDao implements IAePushVoucherLogDao{ - + + /** + * 根据mdmId,bill_code,typeId新增或修改日志 + * 没数据则新增,有数据判断Y/N + * N->N/Y 更新 + * Y->N/Y 返回null + */ + @Override + public AePushVoucherLogEntity saveOrUpdateBymdmIdAndBillCodeAndTypeId(AePushVoucherLogEntity aePushVoucherLogEntity) { + Assert.notNull(aePushVoucherLogEntity.getMdmId(), "根据mdmId,bill_code,typeId新增或修改日志时,mdmId不能为空"); + Assert.notNull(aePushVoucherLogEntity.getBillCode(), "根据mdmId,bill_code,billCode新增或修改日志时,mdmId不能为空"); + Assert.notNull(aePushVoucherLogEntity.getBillStatus(), "根据mdmId,bill_code,billStatus新增或修改日志时,mdmId不能为空"); + AePushVoucherLogEntity aePushVoucherLogEntity1 = new AePushVoucherLogEntity(); + aePushVoucherLogEntity1.setMdmId(aePushVoucherLogEntity.getMdmId()); + aePushVoucherLogEntity1.setBillCode(aePushVoucherLogEntity.getBillCode()); + List query = this.query(aePushVoucherLogEntity1); + if (query == null || query.size() == 0) { + AePushVoucherLogEntity save = this.save(aePushVoucherLogEntity); + return save; + }else { + this.update(aePushVoucherLogEntity); + return aePushVoucherLogEntity; + } + } } diff --git a/base-buildpackage/src/main/java/com/hzya/frame/voucher/ae/push/entity/AePushVoucherLogEntity.java b/base-buildpackage/src/main/java/com/hzya/frame/voucher/ae/push/entity/AePushVoucherLogEntity.java index ee4e328c..e4fe75a0 100644 --- a/base-buildpackage/src/main/java/com/hzya/frame/voucher/ae/push/entity/AePushVoucherLogEntity.java +++ b/base-buildpackage/src/main/java/com/hzya/frame/voucher/ae/push/entity/AePushVoucherLogEntity.java @@ -1,6 +1,7 @@ package com.hzya.frame.voucher.ae.push.entity; import java.util.Date; +import java.util.List; import com.hzya.frame.web.entity.BaseEntity; @@ -418,5 +419,16 @@ public class AePushVoucherLogEntity extends BaseEntity { public void setdBbSum(String dBbSum) { this.dBbSum = dBbSum; } + + + public List logList; + + public List getLogList() { + return logList; + } + + public void setLogList(List logList) { + this.logList = logList; + } } diff --git a/base-buildpackage/src/main/java/com/hzya/frame/voucher/ae/push/service/IAePushVoucherLogService.java b/base-buildpackage/src/main/java/com/hzya/frame/voucher/ae/push/service/IAePushVoucherLogService.java index f1976941..c450fa45 100644 --- a/base-buildpackage/src/main/java/com/hzya/frame/voucher/ae/push/service/IAePushVoucherLogService.java +++ b/base-buildpackage/src/main/java/com/hzya/frame/voucher/ae/push/service/IAePushVoucherLogService.java @@ -16,4 +16,6 @@ public interface IAePushVoucherLogService extends IBaseService queryBill(AePushVoucherLogEntity entity); List queryDetailsByBillCode(AePushVoucherLogEntity entity); + + AePushVoucherLogEntity saveOrUpdateBymdmIdAndBillCodeAndTypeId(AePushVoucherLogEntity aePushVoucherLogEntity); } diff --git a/base-buildpackage/src/main/java/com/hzya/frame/voucher/ae/push/service/impl/AePushVoucherLogServiceImpl.java b/base-buildpackage/src/main/java/com/hzya/frame/voucher/ae/push/service/impl/AePushVoucherLogServiceImpl.java index 51ed75bc..32b0d36c 100644 --- a/base-buildpackage/src/main/java/com/hzya/frame/voucher/ae/push/service/impl/AePushVoucherLogServiceImpl.java +++ b/base-buildpackage/src/main/java/com/hzya/frame/voucher/ae/push/service/impl/AePushVoucherLogServiceImpl.java @@ -52,59 +52,207 @@ public class AePushVoucherLogServiceImpl extends BaseService queryBill(AePushVoucherLogEntity entity) { Assert.notNull(entity.getMdmId(), "mdmId不能为空"); + // 1. 查询原始数据 CreateVoucherVO createVoucherVO = new CreateVoucherVO(); createVoucherVO.setMdmId(entity.getMdmId()); - if (entity.getTimeStart() != null && !"".equals(entity.getTimeStart())) { - createVoucherVO.setTimeStart(entity.getTimeStart()); - } - if (entity.getTimeEnd() != null && !"".equals(entity.getTimeEnd())) { - createVoucherVO.setTimeEnd(entity.getTimeEnd()); - } + createVoucherVO.setTimeStart(entity.getTimeStart()); + createVoucherVO.setTimeEnd(entity.getTimeEnd()); List> mapList = coreService.queryDataByMdmId(createVoucherVO); - List allList = transData(entity.getMdmId(), mapList); - AePushVoucherLogEntity aePushVoucherLogEntity1 = new AePushVoucherLogEntity(); - aePushVoucherLogEntity1.setMdmId(entity.getMdmId()); - List pushData = aePushVoucherLogDao.query(aePushVoucherLogEntity1); + // 2. 查询已推送数据,并构建 billCode -> entity 的映射 + AePushVoucherLogEntity queryEntity = new AePushVoucherLogEntity(); + queryEntity.setMdmId(entity.getMdmId()); + List pushData = aePushVoucherLogDao.query(queryEntity); + + Map pushMap = pushData.stream() + .collect(Collectors.toMap( + AePushVoucherLogEntity::getBillCode, + e -> e, + (e1, e2) -> e1 // 如果有重复 billCode,保留第一个 + )); + + // 3. 设置 billStatus 和 pushInfo for (AePushVoucherLogEntity allEntity : allList) { - for (AePushVoucherLogEntity pushEntity : pushData) { - if (allEntity.getBillCode().equals(pushEntity.getBillCode())) { - allEntity.setBillStatus("Y"); - allEntity.setPushInfo(pushEntity.getPushInfo()); - } else { - allEntity.setBillStatus("N"); -// allEntity.setPushInfo(pushEntity.getPushInfo()); - } + AePushVoucherLogEntity pushEntity = pushMap.get(allEntity.getBillCode()); + if (pushEntity != null) { + allEntity.setBillStatus("Y"); + allEntity.setPushInfo(pushEntity.getPushInfo()); + } else { + allEntity.setBillStatus("N"); + // pushInfo 保持 null 或设为默认值 } - - } - System.out.println(allList); - String status = entity.getBillStatus(); - if (entity.getBillStatus() != null && !"".equals(entity.getBillStatus())) { - List statusList = new ArrayList<>(); - for (AePushVoucherLogEntity aePushVoucherLogEntity : allList) { - if (status.equals(aePushVoucherLogEntity.getBillStatus())) { - statusList.add(aePushVoucherLogEntity); - } - } - - for (AePushVoucherLogEntity aePushVoucherLogEntity : statusList) { - queryByBillCodeAndStatueY(aePushVoucherLogEntity); - } - - return statusList; } - for (AePushVoucherLogEntity aePushVoucherLogEntity : allList) { - queryByBillCodeAndStatueY(aePushVoucherLogEntity); - } - return allList; + // 4. 过滤数据 + List filteredList = filterByConditions(allList, entity.getBillCode(), entity.getBillStatus()); + // 5. 增强数据:调用 Y 状态专用查询和模板类型查询 + enhanceData(filteredList); + // 6. 返回结果 + return filteredList; } + // 过滤逻辑抽离 + private List filterByConditions(List list, String billCode, String billStatus) { + return list.stream().filter(entity -> { + // 单据号匹配 + if (billCode != null && !billCode.isEmpty()) { + if (entity.getBillCode() == null || !entity.getBillCode().contains(billCode)) { + return false; + } + } + // 状态匹配 + if (billStatus != null && !billStatus.isEmpty()) { + if (!billStatus.equals(entity.getBillStatus())) { + return false; + } + } + return true; + }).collect(Collectors.toList()); + } + + // 数据增强逻辑抽离 + private void enhanceData(List list) { + list.forEach(entity -> { + if ("Y".equals(entity.getBillStatus())) { + queryByBillCodeAndStatueY(entity); + } + }); + queryTempType(list); + } + + +// @Override +// public List queryBill(AePushVoucherLogEntity entity) { +// Assert.notNull(entity.getMdmId(), "mdmId不能为空"); +// +// CreateVoucherVO createVoucherVO = new CreateVoucherVO(); +// createVoucherVO.setMdmId(entity.getMdmId()); +// if (entity.getTimeStart() != null && !"".equals(entity.getTimeStart())) { +// createVoucherVO.setTimeStart(entity.getTimeStart()); +// } +// if (entity.getTimeEnd() != null && !"".equals(entity.getTimeEnd())) { +// createVoucherVO.setTimeEnd(entity.getTimeEnd()); +// } +// +// List> mapList = coreService.queryDataByMdmId(createVoucherVO);//已被去重 +// +// List allList = transData(entity.getMdmId(), mapList); +// AePushVoucherLogEntity aePushVoucherLogEntity1 = new AePushVoucherLogEntity(); +// aePushVoucherLogEntity1.setMdmId(entity.getMdmId()); +// List pushData = aePushVoucherLogDao.query(aePushVoucherLogEntity1); +// +// for (AePushVoucherLogEntity allEntity : allList) { +// for (AePushVoucherLogEntity pushEntity : pushData) { +// if (allEntity.getBillCode().equals(pushEntity.getBillCode())) { +// allEntity.setBillStatus("Y"); +// allEntity.setPushInfo(pushEntity.getPushInfo()); +// break; +// } else { +// allEntity.setBillStatus("N"); +//// allEntity.setPushInfo(pushEntity.getPushInfo()); +// } +// } +// +// } +// +// List resList = new ArrayList<>(); +// +// String billCode = entity.getBillCode(); +// String status = entity.getBillStatus(); +// +// //单据号 +// if (billCode != null && status == null) { +// for (AePushVoucherLogEntity aePushVoucherLogEntity : allList) { +// if (aePushVoucherLogEntity.getBillCode().contains(billCode)) { +// resList.add(aePushVoucherLogEntity); +// } +// } +// if (entity.getBillStatus() != null && !"".equals(entity.getBillStatus())) { +// List statusList = new ArrayList<>(); +// for (AePushVoucherLogEntity aePushVoucherLogEntity : resList) { +// if (status.equals(aePushVoucherLogEntity.getBillStatus())) { +// statusList.add(aePushVoucherLogEntity); +// } +// } +// +// for (AePushVoucherLogEntity aePushVoucherLogEntity : statusList) { +// queryByBillCodeAndStatueY(aePushVoucherLogEntity); +// } +// queryTempType(statusList); +// return statusList; +// } +// +// for (AePushVoucherLogEntity aePushVoucherLogEntity : resList) { +// queryByBillCodeAndStatueY(aePushVoucherLogEntity); +// } +// +// +// queryTempType(resList); +// return resList; +// +// } +// //状态 +// if (billCode == null && status != null) { +// if (entity.getBillStatus() != null && !"".equals(entity.getBillStatus())) { +// List statusList = new ArrayList<>(); +// for (AePushVoucherLogEntity aePushVoucherLogEntity : allList) { +// if (status.equals(aePushVoucherLogEntity.getBillStatus())) { +// statusList.add(aePushVoucherLogEntity); +// } +// } +// +// for (AePushVoucherLogEntity aePushVoucherLogEntity : statusList) { +// queryByBillCodeAndStatueY(aePushVoucherLogEntity); +// } +// queryTempType(statusList); +// return statusList; +// } +// +// for (AePushVoucherLogEntity aePushVoucherLogEntity : allList) { +// queryByBillCodeAndStatueY(aePushVoucherLogEntity); +// } +// +// +// queryTempType(allList); +// return allList; +// +// } +// //单据号+状态 +// if (billCode != null && status != null) { +// for (AePushVoucherLogEntity aePushVoucherLogEntity : allList) { +// if (aePushVoucherLogEntity.getBillCode().contains(billCode)) { +// resList.add(aePushVoucherLogEntity); +// } +// } +// +// if (entity.getBillStatus() != null && !"".equals(entity.getBillStatus())) { +// List statusList = new ArrayList<>(); +// for (AePushVoucherLogEntity aePushVoucherLogEntity : resList) { +// if (status.equals(aePushVoucherLogEntity.getBillStatus())) { +// statusList.add(aePushVoucherLogEntity); +// } +// } +// for (AePushVoucherLogEntity aePushVoucherLogEntity : statusList) { +// queryByBillCodeAndStatueY(aePushVoucherLogEntity); +// } +// queryTempType(statusList); +// return statusList; +// } +// } +// +// +// for (AePushVoucherLogEntity aePushVoucherLogEntity : allList) { +// queryByBillCodeAndStatueY(aePushVoucherLogEntity); +// } +// +// queryTempType(allList); +// return allList; +// } + @Override public List queryDetailsByBillCode(AePushVoucherLogEntity entity) { Assert.notNull(entity.getId(), "id不能为空"); @@ -119,12 +267,12 @@ public class AePushVoucherLogServiceImpl extends BaseService transData(String mdmId, List> mapList) { - System.out.println(mapList); List all = new ArrayList<>(); for (Map stringObjectMap : mapList) { if (stringObjectMap != null) { @@ -141,7 +289,6 @@ public class AePushVoucherLogServiceImpl extends BaseService voucherLogEntityList) { + for (AePushVoucherLogEntity aePushVoucherLogEntity : voucherLogEntityList) { + AePushVoucherLogEntity aePushVoucherLogEntity1 = new AePushVoucherLogEntity(); + aePushVoucherLogEntity1.setBillCode(aePushVoucherLogEntity.getBillCode()); + List query = aePushVoucherLogDao.query(aePushVoucherLogEntity1); + aePushVoucherLogEntity.setLogList(query); + } + } + + + /** + * 根据mdmId,bill_code,typeId新增或修改日志 + * 没数据则新增,有数据判断Y/N + * N->N/Y 更新 + * Y->N/Y 返回null + */ + @Override + public AePushVoucherLogEntity saveOrUpdateBymdmIdAndBillCodeAndTypeId(AePushVoucherLogEntity aePushVoucherLogEntity) { + Assert.notNull(aePushVoucherLogEntity.getMdmId(), "根据mdmId,bill_code,typeId新增或修改日志时,mdmId不能为空"); + Assert.notNull(aePushVoucherLogEntity.getBillCode(), "根据mdmId,bill_code,billCode新增或修改日志时,mdmId不能为空"); + Assert.notNull(aePushVoucherLogEntity.getBillStatus(), "根据mdmId,bill_code,billStatus新增或修改日志时,mdmId不能为空"); + AePushVoucherLogEntity aePushVoucherLogEntity1 = new AePushVoucherLogEntity(); + aePushVoucherLogEntity1.setMdmId(aePushVoucherLogEntity.getMdmId()); + aePushVoucherLogEntity1.setBillCode(aePushVoucherLogEntity.getBillCode()); + List query = aePushVoucherLogDao.query(aePushVoucherLogEntity1); + if (query == null || query.size() == 0) { + AePushVoucherLogEntity save = aePushVoucherLogDao.save(aePushVoucherLogEntity); + return save; + } else { + aePushVoucherLogDao.update(aePushVoucherLogEntity); + return aePushVoucherLogEntity; + } + } + + }