Helius
2022-09-19 f2b9a83f75a4345cd42d008f3153c18f8f890cad
zq-erp/src/main/java/com/matrix/system/hive/service/imp/ShoppingGoodsServiceImpl.java
@@ -1,5 +1,6 @@
package com.matrix.system.hive.service.imp;
import cn.hutool.core.collection.CollUtil;
import com.matrix.core.constance.MatrixConstance;
import com.matrix.core.exception.GlobleException;
import com.matrix.core.pojo.PaginationVO;
@@ -31,6 +32,8 @@
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
/**
@@ -102,7 +105,6 @@
                Arrays.asList(SysOrderItemDto::getCount, SysOrderItemDto::getGoodsId));
    }
    @Override
    @Transactional(rollbackFor = Exception.class)
    public int add(ShoppingGoods shoppingGoods) {
@@ -110,17 +112,21 @@
        SysShopInfo shopInfo = shopInfoDao.selectById(sysUsers.getShopId());
        if (shopInfo.getShopType() == SysShopInfo.SHOP_TYPE_ZONGBU) {
        if(shopInfo.getShopType() == SysShopInfo.SHOP_TYPE_ZONGBU){
            shoppingGoods.setHeadquarters(1);
        } else {
            shoppingGoods.setHeadquarters(2);
        }
        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() + "重复");
        }
@@ -280,6 +286,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);
    }
@@ -388,9 +405,6 @@
                shoppingGoods.setIsAssemble(Dictionary.FLAG_NO);
                break;
            case Dictionary.SHOPPING_GOODS_TYPE_TC:
                shoppingGoods.setIsAssemble(Dictionary.FLAG_YES);
                break;
            case Dictionary.SHOPPING_GOODS_TYPE_ZHK:
                shoppingGoods.setIsAssemble(Dictionary.FLAG_YES);
                break;
        }