From 8a99ea72de8c40d0c9871a0d6559920fcc929a54 Mon Sep 17 00:00:00 2001
From: Helius <wangdoubleone@gmail.com>
Date: Wed, 23 Dec 2020 20:48:35 +0800
Subject: [PATCH] modify
---
zq-erp/src/main/java/com/matrix/system/hive/service/imp/ShoppingGoodsServiceImpl.java | 82 +++++++++++++++++++++++++++++++++++------
1 files changed, 70 insertions(+), 12 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 dc8cba5..d415e72 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
@@ -26,6 +26,7 @@
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;
@@ -98,7 +99,7 @@
shoppingGoods.setReferencePice(0D);
}
// 验证套餐卡卡必须填写最大使用次数
- if (Dictionary.FLAG_YES_Y.equals(shoppingGoods.getIsCourse())) {
+ if (Dictionary.FLAG_YES_Y.equals(shoppingGoods.getIsCourse()) && Dictionary.FLAG_NO_N.equals(shoppingGoods.getIsInfinite())) {
if (shoppingGoods.getCarUseCount() == null) {
shoppingGoods.setCarUseCount(0);
}
@@ -125,19 +126,31 @@
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);
- }
+// 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);
}
}
@@ -409,4 +422,49 @@
return shoppingGoodsDao.selectByModelData(shoppingGoods);
}
+
+ /**
+ * 计算失效时间
+ *
+ * @param shoppingGoods
+ * @param type 1 - 购买时 2 - 消耗时
+ * @param buyDate 购买日期, 当计算消耗日期时,不能为空
+ * @return
+ */
+ @Override
+ public Date calInvalidTime(ShoppingGoods shoppingGoods, @NotNull Integer type, Date buyDate) {
+ if (StringUtils.isBlank(shoppingGoods.getBuyValid()) && StringUtils.isBlank(shoppingGoods.getUseValid()) && shoppingGoods.getInvalidTime() == null) {
+ return DateUtil.stringToDate("9999-12-31", DateUtil.DATE_FORMAT_DD);
+ }
+
+ if (type == 2 && buyDate == null) {
+ throw new GlobleException("购买日期不能为空");
+ }
+
+ Date target = null;
+ Date buyValidDate = null;
+ if (type == 1) {
+ buyValidDate = DateUtil.calDate(shoppingGoods.getBuyDateNum(), shoppingGoods.getBuyDateUnit());
+ } else {
+ buyValidDate = buyDate;
+ }
+
+ Date useValidDate = DateUtil.stringToDate("9999-12-31", DateUtil.DATE_FORMAT_DD);
+ if (type == 2) {
+ 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