| | |
| | | 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; |
| | |
| | | import com.matrix.system.hive.bean.SysShopInfo; |
| | | import com.matrix.system.hive.dao.*; |
| | | import com.matrix.system.hive.dto.GoodsSealLimitDto; |
| | | import com.matrix.system.hive.dto.OrderItemDto; |
| | | import com.matrix.system.hive.dto.SysOrderItemDto; |
| | | import com.matrix.system.hive.service.ShoppingGoodsService; |
| | | import org.apache.commons.collections.CollectionUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | |
| | | import java.util.Arrays; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.Objects; |
| | | import java.util.stream.Collectors; |
| | | |
| | | |
| | | /** |
| | |
| | | //校验参数不能为空 |
| | | checkGoodsSelLimtParam(goodsSealLimitDto); |
| | | |
| | | goodsSealLimitDto.getOrderItemDtoList().forEach(item -> { |
| | | goodsSealLimitDto.getSysOrderItemDtoList().forEach(item -> { |
| | | ShoppingGoods shopGoods = shoppingGoodsDao.selectById(item.getGoodsId()); |
| | | //最大销售次数检测 |
| | | Integer maxNum = shopGoods.getCarMaxSaleCount(); |
| | | if (maxNum != null && maxNum != 0) { |
| | | Integer buyNum = orderItemDao.selectByGoodsId(shopGoods.getId(), null); |
| | | if ((buyNum + item.getCount()) == maxNum) { |
| | | if (buyNum.equals(maxNum)) { |
| | | if (!shopGoods.getStaus().equals(Dictionary.BUSINESS_STATE_DOWN)) { |
| | | shopGoods.setStaus(Dictionary.BUSINESS_STATE_DOWN); |
| | | shoppingGoodsDao.update(shopGoods); |
| | | LogUtil.info("{}商品达到最大销售数量自动下架",shopGoods.getName()); |
| | | LogUtil.info("商品达到最大销售数量自动下架:{}", shopGoods.getName()); |
| | | } |
| | | } else if ((buyNum + item.getCount()) > maxNum) { |
| | | throw new GlobleException(shopGoods.getName() + "已超过最大销售数量"); |
| | |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | private void checkGoodsSelLimtParam(GoodsSealLimitDto goodsSealLimitDto) { |
| | | ParamCheckUtil.requireNonNulls(goodsSealLimitDto, |
| | | goodsSealLimitDto.getVipId(), |
| | | goodsSealLimitDto.getOrderItemDtoList()); |
| | | goodsSealLimitDto.getSysOrderItemDtoList()); |
| | | |
| | | |
| | | ParamCheckUtil.requireListElementNonNull(goodsSealLimitDto.getOrderItemDtoList(), |
| | | Arrays.asList(OrderItemDto::getCount, OrderItemDto::getGoodsId)); |
| | | ParamCheckUtil.requireListElementNonNull(goodsSealLimitDto.getSysOrderItemDtoList(), |
| | | Arrays.asList(SysOrderItemDto::getCount, SysOrderItemDto::getGoodsId)); |
| | | } |
| | | |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | |
| | | 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() + "重复"); |
| | | } |
| | | |
| | |
| | | @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); |
| | | |
| | | } |
| | |
| | | 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; |
| | | } |