From c554c7ad5405bafa149dbb6429e8245f78b33ffc Mon Sep 17 00:00:00 2001
From: Helius <wangdoubleone@gmail.com>
Date: Wed, 23 Dec 2020 15:59:53 +0800
Subject: [PATCH] modify

---
 zq-erp/src/main/java/com/matrix/system/hive/service/imp/ShoppingGoodsServiceImpl.java |   70 ++++++++++++++++++++++++++++++++++
 1 files changed, 69 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 c89bc78..4977b14 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
@@ -6,6 +6,8 @@
 import com.matrix.core.tools.DateUtil;
 import com.matrix.core.tools.StringUtils;
 import com.matrix.core.tools.WebUtil;
+import com.matrix.system.app.dto.ShoppingGoodsListDto;
+import com.matrix.system.app.vo.ShoppingGoodsListVo;
 import com.matrix.system.common.bean.SysUsers;
 import com.matrix.system.common.dao.UtilDao;
 import com.matrix.system.common.tools.ServiceUtil;
@@ -26,6 +28,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 +101,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);
             }
@@ -421,4 +424,69 @@
 
         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;
+    }
+
+
+    @Override
+    public List<ShoppingGoodsListVo> findShoppingGoodsListForApi(ShoppingGoodsListDto shoppingGoodsListDto) {
+        SysUsers user = WebUtil.getSessionAttribute(MatrixConstance.LOGIN_KEY);
+        shoppingGoodsListDto.setShopId(user.getShopId());
+        PaginationVO pageVo = new PaginationVO();
+        int offset = (shoppingGoodsListDto.getPageNum() - 1) + shoppingGoodsListDto.getPageSize();
+        int limit = shoppingGoodsListDto.getPageSize();
+        pageVo.setOffset(offset);
+        pageVo.setLimit(limit);
+        return shoppingGoodsDao.selectShoppingGoodsApiInPage(shoppingGoodsListDto, pageVo);
+    }
+
+    @Override
+    public int findShoppingGoodsListTotalForApi(ShoppingGoodsListDto shoppingGoodsListDto) {
+        SysUsers user = WebUtil.getSessionAttribute(MatrixConstance.LOGIN_KEY);
+        shoppingGoodsListDto.setShopId(user.getShopId());
+        return shoppingGoodsDao.selectShopppingGoodsAipTotal(shoppingGoodsListDto);
+    }
 }

--
Gitblit v1.9.1