From aeaae1d860575e0c4097031f0274262d8df17901 Mon Sep 17 00:00:00 2001
From: Helius <wangdoubleone@gmail.com>
Date: Fri, 11 Dec 2020 14:02:44 +0800
Subject: [PATCH] modify shopping goods invalid time

---
 zq-erp/src/main/java/com/matrix/core/tools/DateUtil.java                              |    2 +-
 zq-erp/src/main/java/com/matrix/system/hive/service/imp/ShoppingGoodsServiceImpl.java |   31 +++++++++++++++++++++++++++++++
 zq-erp/src/main/java/com/matrix/system/hive/service/ShoppingGoodsService.java         |    3 +++
 zq-erp/src/main/resources/templates/views/admin/hive/products/goods-form.html         |    6 +++---
 zq-erp/src/main/java/com/matrix/system/hive/service/imp/SysOrderServiceImpl.java      |    1 -
 5 files changed, 38 insertions(+), 5 deletions(-)

diff --git a/zq-erp/src/main/java/com/matrix/core/tools/DateUtil.java b/zq-erp/src/main/java/com/matrix/core/tools/DateUtil.java
index 4fdaef7..419bddf 100644
--- a/zq-erp/src/main/java/com/matrix/core/tools/DateUtil.java
+++ b/zq-erp/src/main/java/com/matrix/core/tools/DateUtil.java
@@ -720,7 +720,7 @@
                 targetDate = calendar.getTime();
                 break;
             default:
-                targetDate = new Date();
+                targetDate = stringToDate("9999-12-31", DATE_FORMAT_DD);
 
         }
 
diff --git a/zq-erp/src/main/java/com/matrix/system/hive/service/ShoppingGoodsService.java b/zq-erp/src/main/java/com/matrix/system/hive/service/ShoppingGoodsService.java
index 61e0ace..116c7e7 100644
--- a/zq-erp/src/main/java/com/matrix/system/hive/service/ShoppingGoodsService.java
+++ b/zq-erp/src/main/java/com/matrix/system/hive/service/ShoppingGoodsService.java
@@ -4,6 +4,7 @@
 import com.matrix.system.hive.bean.ShoppingGoods;
 import com.matrix.system.hive.plugin.util.BaseServices;
 
+import java.util.Date;
 import java.util.List;
 /**
  *
@@ -98,4 +99,6 @@
 	public List<ShoppingGoods> findAll(ShoppingGoods shoppingGoods);
 
 	public  ShoppingGoods findByCode(String goodsCode);
+
+	Date calInvalidTime(ShoppingGoods shoppingGoods, Integer type);
 }
\ No newline at end of file
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 c89bc78..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
@@ -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;
@@ -421,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;
+    }
 }
diff --git a/zq-erp/src/main/java/com/matrix/system/hive/service/imp/SysOrderServiceImpl.java b/zq-erp/src/main/java/com/matrix/system/hive/service/imp/SysOrderServiceImpl.java
index b0bf857..f9d3d2e 100644
--- a/zq-erp/src/main/java/com/matrix/system/hive/service/imp/SysOrderServiceImpl.java
+++ b/zq-erp/src/main/java/com/matrix/system/hive/service/imp/SysOrderServiceImpl.java
@@ -954,7 +954,6 @@
 
     }
 
-
     public void addZongheCarUse(SysOrder order, SysOrderItem sysOrderItem) {
 
 
diff --git a/zq-erp/src/main/resources/templates/views/admin/hive/products/goods-form.html b/zq-erp/src/main/resources/templates/views/admin/hive/products/goods-form.html
index 215e098..9582b81 100644
--- a/zq-erp/src/main/resources/templates/views/admin/hive/products/goods-form.html
+++ b/zq-erp/src/main/resources/templates/views/admin/hive/products/goods-form.html
@@ -893,7 +893,7 @@
                         </el-form-item>
                     </el-col>
                 </el-row>
-                <el-row>
+                <el-row v-if="form.goodType!='家居产品'">
                     <el-form-item label="购买有效期">
                         <el-col  :span="4">
                             <el-form-item label="" prop="isNum">
@@ -917,7 +917,7 @@
                         </el-col>
                     </el-form-item>
                 </el-row>
-                <el-row>
+                <el-row v-if="form.goodType!='家居产品'">
                     <el-form-item label="消耗有效期">
                         <el-col  :span="4">
                             <el-form-item label="" prop="isNum">
@@ -939,7 +939,7 @@
                         </el-col>
                     </el-form-item>
                 </el-row>
-                <el-row>
+                <el-row v-if="form.goodType!='家居产品'">
                     <el-form-item label="统一到期时间">
                         <el-col :span="6">
                             <el-date-picker

--
Gitblit v1.9.1