From aaeaded75d418e6582c16ebd983fe6b052b889b8 Mon Sep 17 00:00:00 2001 From: Helius <wangdoubleone@gmail.com> Date: Fri, 11 Dec 2020 14:27:59 +0800 Subject: [PATCH] Merge branch 'master' into ty_urgent --- zq-erp/src/main/java/com/matrix/system/hive/service/imp/ShoppingGoodsServiceImpl.java | 68 +++++++++++++++++++++++++++++++++ 1 files changed, 67 insertions(+), 1 deletions(-) diff --git a/zq-erp/src/main/java/com/matrix/system/hive/service/imp/ShoppingGoodsServiceImpl.java b/zq-erp/src/main/java/com/matrix/system/hive/service/imp/ShoppingGoodsServiceImpl.java index fc8b5d5..1966a30 100644 --- a/zq-erp/src/main/java/com/matrix/system/hive/service/imp/ShoppingGoodsServiceImpl.java +++ b/zq-erp/src/main/java/com/matrix/system/hive/service/imp/ShoppingGoodsServiceImpl.java @@ -3,6 +3,7 @@ import com.matrix.core.constance.MatrixConstance; import com.matrix.core.exception.GlobleException; import com.matrix.core.pojo.PaginationVO; +import com.matrix.core.tools.DateUtil; import com.matrix.core.tools.StringUtils; import com.matrix.core.tools.WebUtil; import com.matrix.system.common.bean.SysUsers; @@ -25,7 +26,9 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import javax.validation.constraints.NotNull; import java.awt.event.WindowStateListener; +import java.time.LocalDate; import java.util.ArrayList; import java.util.Date; import java.util.List; @@ -88,6 +91,9 @@ shoppingGoods.setCreateTime(new Date()); setPublicAttr(shoppingGoods); + + setShoppingGoodsInvalidTime(shoppingGoods); + if (shoppingGoods.getReferencePice() == null) { //赠送金额 shoppingGoods.setReferencePice(0D); @@ -116,6 +122,36 @@ return i; + } + + private void setShoppingGoodsInvalidTime(ShoppingGoods shoppingGoods) { + // 若未设置购买有效期和消耗有效期,则默认永久有效 +// if (shoppingGoods.getBuyDateNum() == null && shoppingGoods.getUseDateNum() == null) { +// shoppingGoods.setInvalidTime(DateUtil.stringToDate("9999-12-31", DateUtil.DATE_FORMAT_DD)); +// } else { +// // 计算失效日期,判断购买有效期和消耗有效期哪个先失效,则为失效日期 +// Date buyValidDate = DateUtil.calDate(shoppingGoods.getBuyDateNum(), shoppingGoods.getBuyDateUnit()); +// Date useValidDate = DateUtil.calDate(shoppingGoods.getUseDateNum(), shoppingGoods.getUseDateUnit()); +// if (buyValidDate.after(useValidDate)) { +// shoppingGoods.setInvalidTime(useValidDate); +// } else { +// shoppingGoods.setInvalidTime(buyValidDate); +// } +// shoppingGoods.setBuyValid(shoppingGoods.getBuyDateNum() + shoppingGoods.getBuyDateUnit()); +// shoppingGoods.setUseValid(shoppingGoods.getUseDateNum() + shoppingGoods.getUseDateUnit()); +// } + + if (shoppingGoods.getBuyDateNum() != null && StringUtils.isNotBlank(shoppingGoods.getBuyDateUnit())) { + shoppingGoods.setBuyValid(shoppingGoods.getBuyDateNum() + shoppingGoods.getBuyDateUnit()); + } else { + shoppingGoods.setBuyValid(null); + } + + if (shoppingGoods.getUseDateNum() != null && StringUtils.isNotBlank(shoppingGoods.getUseDateUnit())) { + shoppingGoods.setUseValid(shoppingGoods.getUseDateNum() + shoppingGoods.getUseDateUnit()); + } else { + shoppingGoods.setUseValid(null); + } } private void setGoodsAssembles(ShoppingGoods shoppingGoods) { @@ -190,7 +226,7 @@ } } - + setShoppingGoodsInvalidTime(shoppingGoods); return shoppingGoodsDao.update(shoppingGoods); @@ -386,4 +422,34 @@ return shoppingGoodsDao.selectByModelData(shoppingGoods); } + + /** + * 计算失效时间 + * + * @param shoppingGoods + * @param type 1 - 购买时 2 - 消耗时 + * @return + */ + @Override + public Date calInvalidTime(ShoppingGoods shoppingGoods, @NotNull Integer type) { + if (StringUtils.isBlank(shoppingGoods.getBuyValid()) && StringUtils.isBlank(shoppingGoods.getUseValid()) && shoppingGoods.getInvalidTime() == null) { + return null; + } + Date target = null; + Date buyValidDate = DateUtil.calDate(shoppingGoods.getBuyDateNum(), shoppingGoods.getBuyDateUnit()); + Date useValidDate = DateUtil.calDate(shoppingGoods.getUseDateNum(), shoppingGoods.getUseDateUnit()); + + if (buyValidDate.after(useValidDate)) { + target = useValidDate; + } else { + target = buyValidDate; + } + + if (shoppingGoods.getInvalidTime() != null) { + if (target.after(shoppingGoods.getInvalidTime())) { + target = shoppingGoods.getInvalidTime(); + } + } + return target; + } } -- Gitblit v1.9.1