wzy
2022-10-12 691de9aeed2c79374c38a5493e3bf14277a52253
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);
    }
@@ -448,25 +462,31 @@
        Date target = null;
        Date buyValidDate = null;
        if (type == 1) {
            buyValidDate = DateUtil.calDate(shoppingGoods.getBuyDateNum(), shoppingGoods.getBuyDateUnit());
        if (type == 1 && StrUtil.isNotBlank(shoppingGoods.getBuyValid())) {
            buyValidDate = DateUtil.stringToDate(shoppingGoods.getBuyValid(), "yyyy-MM-dd");
        } 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 (type == 2 && StrUtil.isNotBlank(shoppingGoods.getUseValid())) {
            useValidDate = DateUtil.stringToDate(shoppingGoods.getUseValid(), "yyyy-MM-dd");
        }
        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();
            }
        }