From 1386a8657ec42cd3baf6bde8b1506f52c910f0e1 Mon Sep 17 00:00:00 2001
From: xiaoyong931011 <15274802129@163.com>
Date: Fri, 17 Mar 2023 12:29:45 +0800
Subject: [PATCH] 20220516

---
 zq-erp/src/main/java/com/matrix/system/hive/service/imp/ShoppingGoodsServiceImpl.java |   64 ++++++++++++++++++++++----------
 1 files changed, 44 insertions(+), 20 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 e13f1f9..73b7c72 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
@@ -1,5 +1,7 @@
 package com.matrix.system.hive.service.imp;
 
+import cn.hutool.core.collection.CollUtil;
+import cn.hutool.core.util.StrUtil;
 import com.matrix.core.constance.MatrixConstance;
 import com.matrix.core.exception.GlobleException;
 import com.matrix.core.pojo.PaginationVO;
@@ -33,6 +35,8 @@
 import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
+import java.util.Objects;
+import java.util.stream.Collectors;
 
 
 /**
@@ -59,16 +63,11 @@
 
 
 
-
-
-
-
     @Override
     @Transactional(rollbackFor = Exception.class)
     public int add(ShoppingGoods shoppingGoods) {
         SysUsers sysUsers = WebUtil.getSessionAttribute(MatrixConstance.LOGIN_KEY);
         SysShopInfo shopInfo = shopInfoDao.selectById(sysUsers.getShopId());
-
 
 
         if(shopInfo.getShopType()==SysShopInfo.SHOP_TYPE_ZONGBU){
@@ -78,10 +77,14 @@
         }
 
         shoppingGoods.setShopId(sysUsers.getShopId());
-        // 校验去重
-        if (serviceUtil.addCheckRepeatTowColumn("shopping_goods",
-                "code", shoppingGoods.getCode(),
-                "company_id", shoppingGoods.getCompanyId())) {
+
+        //去重查询
+        ShoppingGoods queryGoods=new ShoppingGoods();
+        queryGoods.setCompanyId(shoppingGoods.getCompanyId());
+        queryGoods.setCode(shoppingGoods.getCode());
+        queryGoods.setIsDel(ShoppingGoods.NORMAL);
+        List<ShoppingGoods>  oldGoods=shoppingGoodsDao.selectByModel(queryGoods);
+        if(CollUtil.isNotEmpty(oldGoods)){
             throw new GlobleException("编号" + shoppingGoods.getCode() + "重复");
         }
 
@@ -242,6 +245,17 @@
     @Override
     @Transactional(rollbackFor = Exception.class)
     public int remove(List<Long> list) {
+        SysUsers user = WebUtil.getSessionAttribute(MatrixConstance.LOGIN_KEY);
+        SysShopInfo zbShop = shopInfoDao.selectZbShop(user.getCompanyId());
+        //非总部员工只能删除自己门店的产品
+        if(user.getShopId()!=zbShop.getId()){
+            //校验是否可以删除
+            List<ShoppingGoods> dataList = shoppingGoodsDao.selectByIds(list);
+            List<ShoppingGoods> collect = dataList.stream().filter(goods -> !Objects.equals(user.getShopId(), goods.getShopId())).collect(Collectors.toList());
+            if(CollUtil.isNotEmpty(collect)){
+                throw new GlobleException("非总部员工只能删除自己门店的产品");
+            }
+        }
         return shoppingGoodsDao.deleteByIds(list);
 
     }
@@ -442,31 +456,41 @@
             return DateUtil.stringToDate("2099-12-31", DateUtil.DATE_FORMAT_DD);
         }
 
-        if (type == 2 && buyDate == null) {
-            throw new GlobleException("购买日期不能为空");
-        }
+//        if (type == 2 && buyDate == null) {
+//            throw new GlobleException("购买日期不能为空");
+//        }
 
         Date target = null;
-        Date buyValidDate = null;
+        Date buyValidDate = DateUtil.stringToDate("2099-12-31", DateUtil.DATE_FORMAT_DD);;
         if (type == 1) {
-            buyValidDate = DateUtil.calDate(shoppingGoods.getBuyDateNum(), shoppingGoods.getBuyDateUnit());
+            if (shoppingGoods.getBuyDateNum() != null && StrUtil.isNotBlank(shoppingGoods.getBuyDateUnit())) {
+                buyValidDate = DateUtil.calDate(shoppingGoods.getBuyDateNum(), shoppingGoods.getBuyDateUnit());
+            }
         } else {
             buyValidDate = buyDate;
         }
 
         Date useValidDate = DateUtil.stringToDate("2099-12-31", DateUtil.DATE_FORMAT_DD);
         if (type == 2) {
-            useValidDate = DateUtil.calDate(shoppingGoods.getUseDateNum(), shoppingGoods.getUseDateUnit());
+            if (shoppingGoods.getUseDateNum() != null && StrUtil.isNotBlank(shoppingGoods.getUseDateUnit())) {
+                useValidDate = DateUtil.calDate(shoppingGoods.getUseDateNum(), shoppingGoods.getUseDateUnit());
+            }
         }
 
-        if (buyValidDate.after(useValidDate)) {
-            target = useValidDate;
-        } else {
-            target = buyValidDate;
+        if (buyValidDate != null) {
+            if (buyValidDate.after(useValidDate)) {
+                target = useValidDate;
+            } else {
+                target = buyValidDate;
+            }
         }
 
         if (shoppingGoods.getInvalidTime() != null) {
-            if (target.after(shoppingGoods.getInvalidTime())) {
+            if (target != null) {
+                if (target.after(shoppingGoods.getInvalidTime())) {
+                    target = shoppingGoods.getInvalidTime();
+                }
+            } else {
                 target = shoppingGoods.getInvalidTime();
             }
         }

--
Gitblit v1.9.1