935090232@qq.com
2022-05-03 afe54403db87c5f04e841350c9312367e10de50f
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;
@@ -33,6 +34,8 @@
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
/**
@@ -59,16 +62,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 +76,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 +244,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);
    }