|  | @@ -1555,7 +1555,7 @@ public class GoodsServiceImpl implements GoodsService {
 | 
	
		
			
				|  |  |       */
 | 
	
		
			
				|  |  |      @Override
 | 
	
		
			
				|  |  |      @Transactional
 | 
	
		
			
				|  |  | -    public synchronized Map<String,Object> calculateGoodsDetail(String prodBarcode, String storeId, String sku) {
 | 
	
		
			
				|  |  | +    public synchronized Map<String,Object> calculateGoodsDetail(String prodBarcode, String storeId, String sku, Integer sellVolume) {
 | 
	
		
			
				|  |  |          /**
 | 
	
		
			
				|  |  |           * 1.首先根据商品条码跟门店id查询是否有库存,没库存直接返回
 | 
	
		
			
				|  |  |           */
 | 
	
	
		
			
				|  | @@ -1563,101 +1563,17 @@ public class GoodsServiceImpl implements GoodsService {
 | 
	
		
			
				|  |  |          if(goods == null) {
 | 
	
		
			
				|  |  |              return null;
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -        String env = environment.getProperty("haikong.env");
 | 
	
		
			
				|  |  | +        goods.setSellVolume(sellVolume);
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          /*
 | 
	
		
			
				|  |  |          * 2. 查询海仓仓库系统,判断库存是否足够
 | 
	
		
			
				|  |  |          * */
 | 
	
		
			
				|  |  | -        sku = org.springframework.util.StringUtils.isEmpty(sku) ? goods.getSku() : sku;
 | 
	
		
			
				|  |  | +        /*sku = org.springframework.util.StringUtils.isEmpty(sku) ? goods.getSku() : sku;
 | 
	
		
			
				|  |  |          String wareStockNumberKey = storeId + sku + prodBarcode;
 | 
	
		
			
				|  |  |          String warehouseStockMapKey = Constants.WAREHOUSE_STOCK_MAP_KEY + "_" + storeId;
 | 
	
		
			
				|  |  | -        String redisCacheWareQuantity = JedisUtil.hget(warehouseStockMapKey, wareStockNumberKey);
 | 
	
		
			
				|  |  | -        // 保税仓或缓存中的保税仓库存
 | 
	
		
			
				|  |  | -        Integer wareQuantity = 0;
 | 
	
		
			
				|  |  | -        // 保税仓库存
 | 
	
		
			
				|  |  | -        Integer realWareQuantity = 0;
 | 
	
		
			
				|  |  | -        Integer exitRegionNumber = goods.getExitRegionNumber();
 | 
	
		
			
				|  |  | -        String stockNum = goods.getStockNum();
 | 
	
		
			
				|  |  | -        Integer sellVolume = Objects.isNull(goods.getSellVolume()) ? 1 : goods.getSellVolume();
 | 
	
		
			
				|  |  | -        if (org.springframework.util.StringUtils.isEmpty(redisCacheWareQuantity)) {
 | 
	
		
			
				|  |  | -            WareQueryStockResponseDTO wareQueryStockResponseDTO = null;
 | 
	
		
			
				|  |  | -            String queryWarehouseStockResponse = null;
 | 
	
		
			
				|  |  | -            // 环境配置
 | 
	
		
			
				|  |  | -            if (!org.springframework.util.StringUtils.isEmpty(env) && Constants.PROD.equals(env)) {
 | 
	
		
			
				|  |  | -                WareQueryStockParamDTO wareQueryStockParamDTO = new WareQueryStockParamDTO();
 | 
	
		
			
				|  |  | -                List<Criteria> criteriaList = new ArrayList<>();
 | 
	
		
			
				|  |  | -                Criteria criteria = new Criteria();
 | 
	
		
			
				|  |  | -                criteria.setItemId(goods.getWarehouseSysGoodId());
 | 
	
		
			
				|  |  | -                criteria.setItemCode(goods.getSku());
 | 
	
		
			
				|  |  | -                criteria.setOwnerCode(haiKongProperties.getWareCompanyCode());
 | 
	
		
			
				|  |  | -                criteria.setInventoryType(Constants.InventoryType.ZP.getType());
 | 
	
		
			
				|  |  | -                criteria.setWarehouseCode(goods.getWarehouseSn());
 | 
	
		
			
				|  |  | -                criteriaList.add(criteria);
 | 
	
		
			
				|  |  | -                wareQueryStockParamDTO.setCriteriaList(criteriaList);
 | 
	
		
			
				|  |  | -                try {
 | 
	
		
			
				|  |  | -                    queryWarehouseStockResponse = haiKongWarehouseTemplate.queryWarehouseStock(wareQueryStockParamDTO);
 | 
	
		
			
				|  |  | -                } catch (Exception e) {
 | 
	
		
			
				|  |  | -                    log.error("sku:【{}】,调用海控仓库系统查询库存出现异常!", sku, e);
 | 
	
		
			
				|  |  | -                    throw new ServiceException(String.format("sku:【%s】,调用海控仓库系统查询库存出现异常!", sku));
 | 
	
		
			
				|  |  | -                }
 | 
	
		
			
				|  |  | -                log.info("调用海控仓库系统,请求参数,门店:{}、商品条码:{}、商品编码:{},响应数据:{}", storeId, prodBarcode, sku, queryWarehouseStockResponse);
 | 
	
		
			
				|  |  | -                if (org.springframework.util.StringUtils.isEmpty(queryWarehouseStockResponse)) {
 | 
	
		
			
				|  |  | -                    log.error("调用库存系统接口出现错误!返回结果为空!");
 | 
	
		
			
				|  |  | -                    throw new ServiceException("调用库存系统接口出现错误!");
 | 
	
		
			
				|  |  | -                }
 | 
	
		
			
				|  |  | -                try {
 | 
	
		
			
				|  |  | -                    wareQueryStockResponseDTO = (WareQueryStockResponseDTO) XmlUtils.toObject(queryWarehouseStockResponse, WareQueryStockResponseDTO.class);
 | 
	
		
			
				|  |  | -                } catch (Exception e) {
 | 
	
		
			
				|  |  | -                    log.error("解析一步达库存系统响应数据出现错误!出现异常:", e);
 | 
	
		
			
				|  |  | -                }
 | 
	
		
			
				|  |  | -                if (Objects.isNull(wareQueryStockResponseDTO)) {
 | 
	
		
			
				|  |  | -                    log.error("解析一步达库存系统响应数据出现错误!请求响应结果:{}", queryWarehouseStockResponse);
 | 
	
		
			
				|  |  | -                    throw new ServiceException("解析一步达库存系统响应数据出现错误!");
 | 
	
		
			
				|  |  | -                }
 | 
	
		
			
				|  |  | -                if ("failure".equals(wareQueryStockResponseDTO.getFlag())) {
 | 
	
		
			
				|  |  | -                    log.error("请求一步达库存系统返回错误响应!响应数据:{}", queryWarehouseStockResponse);
 | 
	
		
			
				|  |  | -                    throw new ServiceException(String.format("请求一步达库存系统查询库存错误!响应数据:%s", wareQueryStockResponseDTO.getMessage()));
 | 
	
		
			
				|  |  | -                }
 | 
	
		
			
				|  |  | -            } else {
 | 
	
		
			
				|  |  | -                wareQueryStockResponseDTO = new WareQueryStockResponseDTO();
 | 
	
		
			
				|  |  | -                wareQueryStockResponseDTO.setCode("0");
 | 
	
		
			
				|  |  | -                wareQueryStockResponseDTO.setFlag("success");
 | 
	
		
			
				|  |  | -                wareQueryStockResponseDTO.setMessage("");
 | 
	
		
			
				|  |  | -                WareQueryStockResponseDTO.WareQueryStockResponseItemDTO wareQueryStockResponseItemDTO = new WareQueryStockResponseDTO.WareQueryStockResponseItemDTO();
 | 
	
		
			
				|  |  | -                wareQueryStockResponseItemDTO.setQuantity(3);
 | 
	
		
			
				|  |  | -                wareQueryStockResponseItemDTO.setItemCode(sku);
 | 
	
		
			
				|  |  | -                wareQueryStockResponseItemDTO.setProduceCode(prodBarcode);
 | 
	
		
			
				|  |  | -                List<WareQueryStockResponseDTO.WareQueryStockResponseItemDTO> wareQueryStockResponseItemDTOS = new ArrayList<>();
 | 
	
		
			
				|  |  | -                wareQueryStockResponseItemDTOS.add(wareQueryStockResponseItemDTO);
 | 
	
		
			
				|  |  | -                wareQueryStockResponseDTO.setItems(wareQueryStockResponseItemDTOS);
 | 
	
		
			
				|  |  | -            }
 | 
	
		
			
				|  |  | +        String redisCacheWareQuantity = JedisUtil.hget(warehouseStockMapKey, wareStockNumberKey);*/
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -            // 校验库存
 | 
	
		
			
				|  |  | -            List<WareQueryStockResponseDTO.WareQueryStockResponseItemDTO> items = wareQueryStockResponseDTO.getItems();
 | 
	
		
			
				|  |  | -            if (CollectionUtils.isEmpty(items)) {
 | 
	
		
			
				|  |  | -                log.error("查询商品时:【{}】,仓库不存在该商品!", prodBarcode);
 | 
	
		
			
				|  |  | -                throw new ServiceException(String.format("查询商品时:【%s】,仓库不存在该商品!", prodBarcode));
 | 
	
		
			
				|  |  | -            }
 | 
	
		
			
				|  |  | -            WareQueryStockResponseDTO.WareQueryStockResponseItemDTO itemDTO = items.get(0);
 | 
	
		
			
				|  |  | -            // 仓库可用库存
 | 
	
		
			
				|  |  | -            wareQuantity = itemDTO.getQuantity();
 | 
	
		
			
				|  |  | -            realWareQuantity = wareQuantity;
 | 
	
		
			
				|  |  | -            JedisUtil.hset(warehouseStockMapKey, wareStockNumberKey, String.valueOf(wareQuantity));
 | 
	
		
			
				|  |  | -        } else {
 | 
	
		
			
				|  |  | -            wareQuantity = Integer.parseInt(redisCacheWareQuantity);
 | 
	
		
			
				|  |  | -            // 如果是缓存中有该商品保税仓的库存可用数缓存,因为这个可用数已经是经过计算的,所以这里需要加上购买数
 | 
	
		
			
				|  |  | -            // 避免下面提示的是计算过后的库存可用数,以致于出现误解
 | 
	
		
			
				|  |  | -            realWareQuantity = wareQuantity + sellVolume;
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  | -        // 保税仓库存 + 展销店库存 - 出区数 >= 购买数
 | 
	
		
			
				|  |  | -        if (!((wareQuantity + Integer.parseInt(stockNum) - exitRegionNumber) > sellVolume)) {
 | 
	
		
			
				|  |  | -            // 库存不足
 | 
	
		
			
				|  |  | -            log.error("商品条码:【{}】,sku:【{}】,门店库存:【{}】,保税仓库存:【{}】,出区数:【{}】,该商品仓库库存不足!", prodBarcode, sku, stockNum, realWareQuantity, exitRegionNumber);
 | 
	
		
			
				|  |  | -            throw new ServiceException(String.format("商品条码:【%s】,sku:【%s】,门店库存:【%s】,保税仓库存:【%s】,出区数:【%s】,该商品仓库库存不足!", prodBarcode, sku, stockNum, realWareQuantity, exitRegionNumber));
 | 
	
		
			
				|  |  | -        } else {
 | 
	
		
			
				|  |  | -            JedisUtil.hset(warehouseStockMapKey, wareStockNumberKey, String.valueOf(wareQuantity - sellVolume));
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  | +        validateWarehouseStock(goods, prodBarcode, sku, storeId);
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          goods.setDiscountedPrice(new BigDecimal(0));
 | 
	
		
			
				|  |  |          BigDecimal retailPrice = goods.getRetailPrice();
 | 
	
	
		
			
				|  | @@ -1677,6 +1593,85 @@ public class GoodsServiceImpl implements GoodsService {
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      @Override
 | 
	
		
			
				|  |  | +    public void validateWarehouseStock(GoodsDetailsDto goods, String prodBarcode, String sku, String storeId) {
 | 
	
		
			
				|  |  | +        // 保税仓库存
 | 
	
		
			
				|  |  | +        Integer wareQuantity = 0;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        String env = environment.getProperty("haikong.env");
 | 
	
		
			
				|  |  | +        // 保税仓库存
 | 
	
		
			
				|  |  | +        Integer exitRegionNumber = goods.getExitRegionNumber();
 | 
	
		
			
				|  |  | +        String stockNum = goods.getStockNum();
 | 
	
		
			
				|  |  | +        Integer sellVolume = Objects.isNull(goods.getSellVolume()) ? 1 : goods.getSellVolume();
 | 
	
		
			
				|  |  | +        WareQueryStockResponseDTO wareQueryStockResponseDTO = null;
 | 
	
		
			
				|  |  | +        String queryWarehouseStockResponse = null;
 | 
	
		
			
				|  |  | +        // 环境配置
 | 
	
		
			
				|  |  | +        if (!org.springframework.util.StringUtils.isEmpty(env) && Constants.PROD.equals(env)) {
 | 
	
		
			
				|  |  | +            WareQueryStockParamDTO wareQueryStockParamDTO = new WareQueryStockParamDTO();
 | 
	
		
			
				|  |  | +            List<Criteria> criteriaList = new ArrayList<>();
 | 
	
		
			
				|  |  | +            Criteria criteria = new Criteria();
 | 
	
		
			
				|  |  | +            criteria.setItemId(goods.getWarehouseSysGoodId());
 | 
	
		
			
				|  |  | +            criteria.setItemCode(goods.getSku());
 | 
	
		
			
				|  |  | +            criteria.setOwnerCode(haiKongProperties.getWareCompanyCode());
 | 
	
		
			
				|  |  | +            criteria.setInventoryType(Constants.InventoryType.ZP.getType());
 | 
	
		
			
				|  |  | +            criteria.setWarehouseCode(goods.getWarehouseSn());
 | 
	
		
			
				|  |  | +            criteriaList.add(criteria);
 | 
	
		
			
				|  |  | +            wareQueryStockParamDTO.setCriteriaList(criteriaList);
 | 
	
		
			
				|  |  | +            try {
 | 
	
		
			
				|  |  | +                queryWarehouseStockResponse = haiKongWarehouseTemplate.queryWarehouseStock(wareQueryStockParamDTO);
 | 
	
		
			
				|  |  | +            } catch (Exception e) {
 | 
	
		
			
				|  |  | +                log.error("sku:【{}】,调用海控仓库系统查询库存出现异常!", sku, e);
 | 
	
		
			
				|  |  | +                throw new ServiceException(String.format("sku:【%s】,调用海控仓库系统查询库存出现异常!", sku));
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            log.info("调用海控仓库系统,请求参数,门店:{}、商品条码:{}、商品编码:{},响应数据:{}", storeId, prodBarcode, sku, queryWarehouseStockResponse);
 | 
	
		
			
				|  |  | +            if (org.springframework.util.StringUtils.isEmpty(queryWarehouseStockResponse)) {
 | 
	
		
			
				|  |  | +                log.error("调用库存系统接口出现错误!返回结果为空!");
 | 
	
		
			
				|  |  | +                throw new ServiceException("调用库存系统接口出现错误!");
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            try {
 | 
	
		
			
				|  |  | +                wareQueryStockResponseDTO = (WareQueryStockResponseDTO) XmlUtils.toObject(queryWarehouseStockResponse, WareQueryStockResponseDTO.class);
 | 
	
		
			
				|  |  | +            } catch (Exception e) {
 | 
	
		
			
				|  |  | +                log.error("解析一步达库存系统响应数据出现错误!出现异常:", e);
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            if (Objects.isNull(wareQueryStockResponseDTO)) {
 | 
	
		
			
				|  |  | +                log.error("解析一步达库存系统响应数据出现错误!请求响应结果:{}", queryWarehouseStockResponse);
 | 
	
		
			
				|  |  | +                throw new ServiceException("解析一步达库存系统响应数据出现错误!");
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            if ("failure".equals(wareQueryStockResponseDTO.getFlag())) {
 | 
	
		
			
				|  |  | +                log.error("请求一步达库存系统返回错误响应!响应数据:{}", queryWarehouseStockResponse);
 | 
	
		
			
				|  |  | +                throw new ServiceException(String.format("请求一步达库存系统查询库存错误!响应数据:%s", wareQueryStockResponseDTO.getMessage()));
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +        } else {
 | 
	
		
			
				|  |  | +            wareQueryStockResponseDTO = new WareQueryStockResponseDTO();
 | 
	
		
			
				|  |  | +            wareQueryStockResponseDTO.setCode("0");
 | 
	
		
			
				|  |  | +            wareQueryStockResponseDTO.setFlag("success");
 | 
	
		
			
				|  |  | +            wareQueryStockResponseDTO.setMessage("");
 | 
	
		
			
				|  |  | +            WareQueryStockResponseDTO.WareQueryStockResponseItemDTO wareQueryStockResponseItemDTO = new WareQueryStockResponseDTO.WareQueryStockResponseItemDTO();
 | 
	
		
			
				|  |  | +            wareQueryStockResponseItemDTO.setQuantity(3);
 | 
	
		
			
				|  |  | +            wareQueryStockResponseItemDTO.setItemCode(sku);
 | 
	
		
			
				|  |  | +            wareQueryStockResponseItemDTO.setProduceCode(prodBarcode);
 | 
	
		
			
				|  |  | +            List<WareQueryStockResponseDTO.WareQueryStockResponseItemDTO> wareQueryStockResponseItemDTOS = new ArrayList<>();
 | 
	
		
			
				|  |  | +            wareQueryStockResponseItemDTOS.add(wareQueryStockResponseItemDTO);
 | 
	
		
			
				|  |  | +            wareQueryStockResponseDTO.setItems(wareQueryStockResponseItemDTOS);
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        // 校验库存
 | 
	
		
			
				|  |  | +        List<WareQueryStockResponseDTO.WareQueryStockResponseItemDTO> items = wareQueryStockResponseDTO.getItems();
 | 
	
		
			
				|  |  | +        if (CollectionUtils.isEmpty(items)) {
 | 
	
		
			
				|  |  | +            log.error("查询商品时:【{}】,仓库不存在该商品!", prodBarcode);
 | 
	
		
			
				|  |  | +            throw new ServiceException(String.format("查询商品时:【%s】,仓库不存在该商品!", prodBarcode));
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        WareQueryStockResponseDTO.WareQueryStockResponseItemDTO itemDTO = items.get(0);
 | 
	
		
			
				|  |  | +        // 仓库可用库存
 | 
	
		
			
				|  |  | +        wareQuantity = itemDTO.getQuantity();
 | 
	
		
			
				|  |  | +        // 保税仓库存 + 展销店库存 - 出区数 >= 购买数
 | 
	
		
			
				|  |  | +        if (!((wareQuantity + Integer.parseInt(stockNum) - exitRegionNumber) > sellVolume)) {
 | 
	
		
			
				|  |  | +            // 库存不足
 | 
	
		
			
				|  |  | +            log.error("商品条码:【{}】,sku:【{}】,门店库存:【{}】,保税仓库存:【{}】,出区数:【{}】,该商品仓库库存不足!", prodBarcode, sku, stockNum, wareQuantity, exitRegionNumber);
 | 
	
		
			
				|  |  | +            throw new ServiceException(String.format("商品条码:【%s】,sku:【%s】,门店库存:【%s】,保税仓库存:【%s】,出区数:【%s】,该商品仓库库存不足!", prodBarcode, sku, stockNum, wareQuantity, exitRegionNumber));
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    @Override
 | 
	
		
			
				|  |  |      public List<Map<String,Object>> selectSkuDetails(String prodBarcode, String storeId) {
 | 
	
		
			
				|  |  |          /**
 | 
	
		
			
				|  |  |           * 1.首先根据商品条码跟门店id查询是否有库存,没库存直接返回
 |