|
@@ -39,6 +39,7 @@ import com.kmall.manager.manager.redis.JedisUtil;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.core.env.Environment;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
@@ -135,6 +136,8 @@ public class GoodsServiceImpl implements GoodsService {
|
|
|
|
|
|
@Autowired
|
|
|
private HaiKongWarehouseTemplate haiKongWarehouseTemplate;
|
|
|
+ @Autowired
|
|
|
+ private Environment environment;
|
|
|
|
|
|
@Override
|
|
|
public GoodsEntity queryObject(Integer id) {
|
|
@@ -1554,6 +1557,8 @@ public class GoodsServiceImpl implements GoodsService {
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
+ String env = environment.getProperty("haikong.env");
|
|
|
+
|
|
|
/*
|
|
|
* 2. 查询海仓仓库系统,判断库存是否足够
|
|
|
* */
|
|
@@ -1566,50 +1571,49 @@ public class GoodsServiceImpl implements GoodsService {
|
|
|
String stockNum = goods.getStockNum();
|
|
|
Integer sellVolume = Objects.isNull(goods.getSellVolume()) ? 1 : goods.getSellVolume();
|
|
|
if (org.springframework.util.StringUtils.isEmpty(redisCacheWareQuantity)) {
|
|
|
-
|
|
|
- /* -----------------↓--------------生产请打开注释-------------------↓------------ */
|
|
|
-// WareQueryStockParamDTO wareQueryStockParamDTO = new WareQueryStockParamDTO();
|
|
|
-// List<Criteria> criteriaList = new ArrayList<>();
|
|
|
-// Criteria criteria = new Criteria();
|
|
|
-// criteria.setItemId(goods.getWarehouseSysGoodId());
|
|
|
-// criteria.setItemCode(goods.getSku());
|
|
|
-// criteria.setOwnerCode(goods.getConsignorSn());
|
|
|
-// criteria.setInventoryType(Constants.InventoryType.ZP.getType());
|
|
|
-// criteria.setWarehouseCode(goods.getWarehouseSn());
|
|
|
-// criteriaList.add(criteria);
|
|
|
-// wareQueryStockParamDTO.setCriteriaList(criteriaList);
|
|
|
-// String queryWarehouseStockResponse = null;
|
|
|
-// 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("调用库存系统接口出现错误!");
|
|
|
-// }
|
|
|
-// WareQueryStockResponseDTO wareQueryStockResponseDTO = JacksonUtil.fromStringJson(queryWarehouseStockResponse, WareQueryStockResponseDTO.class);
|
|
|
- /* -----------------↑--------------生产请打开注释------------------↑------------- */
|
|
|
-
|
|
|
- /* -----------------↓--------------测试数据,生产请注释-------------------↓------------ */
|
|
|
- WareQueryStockResponseDTO 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);
|
|
|
- /* -----------------↑--------------测试数据,生产请注释------------------↑------------- */
|
|
|
+ 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(goods.getConsignorSn());
|
|
|
+ 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("调用库存系统接口出现错误!");
|
|
|
+ }
|
|
|
+ wareQueryStockResponseDTO = JacksonUtil.fromStringJson(queryWarehouseStockResponse, WareQueryStockResponseDTO.class);
|
|
|
+ } 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);
|
|
|
+ }
|
|
|
|
|
|
|
|
|
if (Objects.isNull(wareQueryStockResponseDTO)) {
|
|
|
-// log.error("解析一步达库存系统响应数据出现错误!请求响应结果:{}", queryWarehouseStockResponse);
|
|
|
+ log.error("解析一步达库存系统响应数据出现错误!请求响应结果:{}", queryWarehouseStockResponse);
|
|
|
throw new ServiceException("解析一步达库存系统响应数据出现错误!");
|
|
|
}
|
|
|
|
|
@@ -1668,260 +1672,12 @@ public class GoodsServiceImpl implements GoodsService {
|
|
|
/**
|
|
|
* 1.首先根据商品条码跟门店id查询是否有库存,没库存直接返回
|
|
|
*/
|
|
|
-
|
|
|
goods.setDiscountedPrice(new BigDecimal(0));
|
|
|
BigDecimal retailPrice = goods.getRetailPrice();
|
|
|
|
|
|
-
|
|
|
goods.setActualPaymentAmount(retailPrice.setScale(2,RoundingMode.HALF_UP));
|
|
|
|
|
|
Map<String,Object> skuActivitiesMap = new HashMap<>();
|
|
|
-
|
|
|
- SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
-
|
|
|
- /**
|
|
|
- * 2.查询当前时间,该门店是否有活动,如果有活动,查询开启了哪些营销方式
|
|
|
- * 参数: 当前时间 门店id
|
|
|
- */
|
|
|
- List<MkActivitiesEntity> mkActivitiesEntityList = mkActivitiesService.queryByNow(storeId,format.format(new Date()));
|
|
|
-
|
|
|
- if(mkActivitiesEntityList == null || mkActivitiesEntityList.size() == 0){
|
|
|
- // 计算税费
|
|
|
- GoodsEntity goodsEntity = goodsDao.queryByBarcodeAndSku(prodBarcode, goods.getGoodsSn());
|
|
|
- BigDecimal tax = CalculateTax.calculateFinalTax(goodsEntity,goods.getActualPaymentAmount(),this).setScale(3,RoundingMode.HALF_UP);
|
|
|
- goods.setGoodstaxes(tax.toString());
|
|
|
- skuActivitiesMap.put("goods",goods);
|
|
|
- return skuActivitiesMap;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- // 遍历活动集合,查询有哪些活动是开启的
|
|
|
- boolean daily = false,coupon = false,combinationPrice = false
|
|
|
- ,discount = false,fullGift = false,fullReduction = false
|
|
|
- ,getOneFree = false,promotion = false,halfPrice = false;
|
|
|
-
|
|
|
- List<String> topicList = new ArrayList<>(); // 记录有哪些营销活动的topic
|
|
|
- Map<String,String> mkaIdMap = new HashMap<>(); // 记录topic跟mkaId的关系
|
|
|
- // 将所有的营销活动新增到list中
|
|
|
- for(MkActivitiesEntity mkActivitiesEntity : mkActivitiesEntityList){
|
|
|
- topicList.add(mkActivitiesEntity.getMkaTopic());
|
|
|
- String mkaId = mkaIdMap.putIfAbsent(mkActivitiesEntity.getMkaTopic(), mkActivitiesEntity.getMkaId()+"");
|
|
|
- if(StringUtils.isNotEmpty(mkaId)){
|
|
|
-// mkaId = "'"+mkaId + "','" + mkActivitiesEntity.getMkaId()+"'";
|
|
|
- mkaId += String.format(",%s",mkActivitiesEntity.getMkaId());
|
|
|
- mkaIdMap.put(mkActivitiesEntity.getMkaTopic(),mkaId);
|
|
|
- }
|
|
|
- }
|
|
|
- // 判断有哪些营销活动
|
|
|
- if(topicList.contains("zhjsp")) // 组合价
|
|
|
- combinationPrice = true;
|
|
|
- if(topicList.contains("dz")) // 打折
|
|
|
- discount = true;
|
|
|
- if(topicList.contains("mz")) //满赠
|
|
|
- fullGift = true;
|
|
|
- if(topicList.contains("mj")) // 满减
|
|
|
- fullReduction = true;
|
|
|
- if(topicList.contains("mysy")) // 买一送一
|
|
|
- getOneFree = true;
|
|
|
- if(topicList.contains("rchd")) // 日常活动
|
|
|
- daily = true;
|
|
|
- if(topicList.contains("yhq")) // 优惠券
|
|
|
- coupon = true;
|
|
|
- if(topicList.contains("lscx")) // 临时促销
|
|
|
- promotion = true;
|
|
|
- if(topicList.contains("drjbj"))
|
|
|
- halfPrice = true;
|
|
|
-
|
|
|
-
|
|
|
- // 获取未优惠前的商品价格
|
|
|
- retailPrice = goods.getRetailPrice();
|
|
|
-
|
|
|
-
|
|
|
- // 根据条码查询商品品牌名称 mall_brand mall_product_store_rela mall_goods
|
|
|
- String brandName = goods.getBrand();
|
|
|
-
|
|
|
- /**
|
|
|
- * 优先级:临时促销 》买一送一=满赠 》 组合价=日常活动 》 打折=满减 》 优惠券
|
|
|
- */
|
|
|
-
|
|
|
- /**
|
|
|
- * 组合价的做法就是将参与组合的条码带到收银端
|
|
|
- * 现根据营销活动id跟条形码,查询有哪些参与该条码组合的商品
|
|
|
- *
|
|
|
- *
|
|
|
- * TODO
|
|
|
- */
|
|
|
- if(combinationPrice){
|
|
|
- String mkaId = mkaIdMap.get("zhjsp");
|
|
|
- Map<String,Object> param = new HashMap<>();
|
|
|
- param.put("mkaId",mkaId);
|
|
|
- param.put("prodBarcode",prodBarcode);
|
|
|
- List<MkActivitiesCombinationPriceEntity> combinationPriceList = combinationPriceService.queryList(param);
|
|
|
- if(combinationPriceList != null && combinationPriceList.size() > 0) {
|
|
|
- Map<String, List<MkActivitiesCombinationPriceEntity>> collect =
|
|
|
- combinationPriceList.stream().collect(Collectors.groupingBy(MkActivitiesCombinationPriceEntity::getCombinationType));
|
|
|
-
|
|
|
- skuActivitiesMap.put("zhjsp",collect);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- format = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
- String nowTime = format.format(new Date());
|
|
|
- /**
|
|
|
- * 满减可能是跟着条码,也可能跟着品牌
|
|
|
- * 根据商品品牌跟商品条码去查询是否有优惠金额
|
|
|
- *
|
|
|
- * 满足金额 购买商品条码 赠品条码
|
|
|
- *
|
|
|
- */
|
|
|
- Map<String,Object> fullReductionMap = new HashMap<>();
|
|
|
- if(fullReduction){
|
|
|
- String mkaId = mkaIdMap.get("mj");
|
|
|
- MkActivitiesFullReductionEntity fullReductionEntity = fullReductionService.queryByCodeOrBrand(mkaId,prodBarcode,brandName,nowTime);
|
|
|
- if(fullReductionEntity != null) {
|
|
|
- if(!StringUtils.isNullOrEmpty(fullReductionEntity.getProductBrand())){
|
|
|
- // 跟着品牌走
|
|
|
- fullReductionMap.put(brandName,fullReductionEntity);
|
|
|
- }else{
|
|
|
- // 跟着条码走
|
|
|
- fullReductionMap.put(fullReductionEntity.getBarcode(), fullReductionEntity);
|
|
|
- }
|
|
|
- skuActivitiesMap.put("mj",fullReductionMap);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 满赠可能是跟着条码,也可能跟着品牌
|
|
|
- * 根据商品品牌跟商品条码去查询是否有满赠
|
|
|
- * 1.先扫买的商品,然后查询出赠送的商品条码
|
|
|
- * 2.先扫赠的商品,然后查询出符合条件的商品条码或者品牌
|
|
|
- * 满足的金额 购买的商品条码或者品牌 赠送的商品条码
|
|
|
- * TODO
|
|
|
- */
|
|
|
- Map<String,Object> fullGiftMap = new HashMap<>();
|
|
|
- if(fullGift){
|
|
|
- String mkaId = mkaIdMap.get("mz");
|
|
|
- MkActivitiesFullGiftEntity giftEntity = fullGiftService.queryByCodeOrBrand(mkaId,prodBarcode,brandName,nowTime);
|
|
|
- if(giftEntity != null) {
|
|
|
- if(giftEntity.getProductBrand() != null){
|
|
|
- // 跟着品牌走
|
|
|
- fullGiftMap.put(brandName,giftEntity);
|
|
|
- }else{
|
|
|
- // 跟着条码走
|
|
|
- fullGiftMap.put(giftEntity.getBarcode(), giftEntity);
|
|
|
- }
|
|
|
- skuActivitiesMap.put("mz",fullGiftMap);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 买一送一可能是跟着条码,也可能跟着品牌
|
|
|
- * 根据商品品牌跟商品条码去查询是否有送的商品
|
|
|
- * 有两个场景
|
|
|
- * 1.先扫买的商品,然后查询出赠送的商品条码
|
|
|
- * 2.先扫赠的商品,然后查询出符合条件的商品条码或者品牌
|
|
|
- * 所以就需要一个map
|
|
|
- * key为购买的商品条码或者商品品牌 value为赠送的商品条码
|
|
|
- * 但是品牌是根据条码查询的,所以最终map里面的结构是
|
|
|
- * key 商品条码 value 赠品条码
|
|
|
- */
|
|
|
- if(getOneFree){
|
|
|
- String mkaId = mkaIdMap.get("mysy");
|
|
|
- MkActivitiesGetOneFreeGoodsEntity getOneFreeGoodsEntity = getOneFreeGoodsService.queryByCodeOrBrand(mkaId,prodBarcode,brandName);
|
|
|
- if(getOneFreeGoodsEntity != null){
|
|
|
- if("无".equals(getOneFreeGoodsEntity.getProductBrand())){
|
|
|
- getOneFreeGoodsEntity.setBrand(false);
|
|
|
- skuActivitiesMap.put("mysy",getOneFreeGoodsEntity);
|
|
|
- }else{
|
|
|
- getOneFreeGoodsEntity.setBrand(true);
|
|
|
- skuActivitiesMap.put("mysy",getOneFreeGoodsEntity);
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- // 第二份半价
|
|
|
- if(halfPrice){
|
|
|
- String mkaId = mkaIdMap.get("drjbj");
|
|
|
- MkActivitiesHalfPriceEntity activitiesHalfPriceEntity = halfPriceService.queryByCodeOrBrand(mkaId,prodBarcode);
|
|
|
- if(activitiesHalfPriceEntity != null){
|
|
|
- skuActivitiesMap.put("drjbj",activitiesHalfPriceEntity);
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- // --------------------------------------------------------------------------------------
|
|
|
-
|
|
|
- /**
|
|
|
- * 优惠券跟着条形码走,一般是设置一个标识,然后最后输入优惠券码后,减扣对应的标识,所以返回一个map数组
|
|
|
- */
|
|
|
-
|
|
|
- if(coupon){
|
|
|
- String mkaId = mkaIdMap.get("yhq");
|
|
|
- MkActivitiesCouponEntity couponEntity = couponService.queryByBarCode(mkaId,prodBarcode,nowTime);
|
|
|
- if(couponEntity != null){ // 优惠券码,优惠金额
|
|
|
- Map<String,Object> returnMap = new HashMap<>();
|
|
|
- returnMap.put(couponEntity.getCouponSn() , couponEntity.getCouponPrice());
|
|
|
- skuActivitiesMap.put("yhq",returnMap);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- /**
|
|
|
- * 打折的价格是与条形码对应的,所以需要根据条形码和营销方式id去查询活动价格
|
|
|
- */
|
|
|
-
|
|
|
- if(discount){
|
|
|
- String mkaId = mkaIdMap.get("dz");
|
|
|
- MkActivitiesDiscountEntity discountEntity = discountService.queryByBarCode(mkaId,prodBarcode);
|
|
|
- // TODO 可能会直接替代产品价格
|
|
|
- if (discountEntity != null) {
|
|
|
- goods.setActualPaymentAmount(discountEntity.getActivityPrice());
|
|
|
- goods.setRetailPrice(discountEntity.getActivityPrice());
|
|
|
-
|
|
|
- goods.setActivity("打折");
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- /**
|
|
|
- * 日常活动跟着条形码走,优先级比临时促销低,但是高于正常价格
|
|
|
- */
|
|
|
- if(daily){
|
|
|
- String mkaId = mkaIdMap.get("rchd");
|
|
|
- MkDailyActivitiesEntity dailyActivitiesEntity = dailyActivitiesService.queryByBarCode(mkaId,prodBarcode);
|
|
|
- if(dailyActivitiesEntity != null){
|
|
|
- goods.setActualPaymentAmount(dailyActivitiesEntity.getActivityPrice());
|
|
|
- goods.setRetailPrice(dailyActivitiesEntity.getActivityPrice());
|
|
|
-
|
|
|
- goods.setActivity("日常活动");
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- /**
|
|
|
- * 临时促销跟着条形码走,优先级应该最高,所以排到了最下面
|
|
|
- */
|
|
|
- if(promotion){
|
|
|
- String mkaId = mkaIdMap.get("lscx");
|
|
|
- MkActivitiesPromotionEntity promotionEntity = promotionService.queryByBarCode(mkaId,prodBarcode);
|
|
|
- // 如果该商品存在临时促销,直接替换活动价格
|
|
|
- if(promotionEntity != null){
|
|
|
- goods.setActualPaymentAmount(promotionEntity.getActivityPrice());
|
|
|
- goods.setRetailPrice(promotionEntity.getActivityPrice());
|
|
|
-
|
|
|
- goods.setActivity("临时促销");
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
// 计算税费
|
|
|
GoodsEntity goodsEntity = goodsDao.queryByBarcodeAndSku(prodBarcode, goods.getGoodsSn());
|
|
|
BigDecimal tax = CalculateTax.calculateFinalTax(goodsEntity,goods.getActualPaymentAmount(),this).setScale(3,RoundingMode.HALF_UP);
|