|
@@ -1,7 +1,6 @@
|
|
package com.kmall.admin.service.impl;
|
|
package com.kmall.admin.service.impl;
|
|
|
|
|
|
import cn.hutool.http.HttpUtil;
|
|
import cn.hutool.http.HttpUtil;
|
|
-import com.alibaba.druid.support.json.JSONUtils;
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
import com.alibaba.fastjson.JSON;
|
|
import com.google.common.collect.ImmutableBiMap;
|
|
import com.google.common.collect.ImmutableBiMap;
|
|
import com.google.common.collect.Maps;
|
|
import com.google.common.collect.Maps;
|
|
@@ -11,10 +10,12 @@ import com.kmall.admin.dto.GoodsDto;
|
|
import com.kmall.admin.dto.GoodsPanoramaDto;
|
|
import com.kmall.admin.dto.GoodsPanoramaDto;
|
|
import com.kmall.admin.entity.*;
|
|
import com.kmall.admin.entity.*;
|
|
import com.kmall.admin.entity.mk.MkActivitiesEntity;
|
|
import com.kmall.admin.entity.mk.MkActivitiesEntity;
|
|
|
|
+import com.kmall.admin.entity.shop.ShopErrorPriceRecordEntity;
|
|
import com.kmall.admin.service.*;
|
|
import com.kmall.admin.service.*;
|
|
import com.kmall.admin.service.mk.MkActivitiesService;
|
|
import com.kmall.admin.service.mk.MkActivitiesService;
|
|
import com.kmall.admin.service.mk.MkActivityFormService;
|
|
import com.kmall.admin.service.mk.MkActivityFormService;
|
|
import com.kmall.admin.service.GoodsService;
|
|
import com.kmall.admin.service.GoodsService;
|
|
|
|
+import com.kmall.admin.service.shop.ShopErrorPriceRecordService;
|
|
import com.kmall.admin.utils.CalculateTax;
|
|
import com.kmall.admin.utils.CalculateTax;
|
|
import com.kmall.admin.utils.GoodsUtils;
|
|
import com.kmall.admin.utils.GoodsUtils;
|
|
import com.kmall.admin.utils.ShiroUtils;
|
|
import com.kmall.admin.utils.ShiroUtils;
|
|
@@ -22,8 +23,6 @@ import com.kmall.api.entity.exportpdf.PDFGoodsDto;
|
|
import com.kmall.common.constant.Dict;
|
|
import com.kmall.common.constant.Dict;
|
|
import com.kmall.admin.fromcomm.entity.SysUserEntity;
|
|
import com.kmall.admin.fromcomm.entity.SysUserEntity;
|
|
import com.kmall.common.utils.*;
|
|
import com.kmall.common.utils.*;
|
|
-import com.kmall.common.utils.print.ticket.item.Goods;
|
|
|
|
-import org.apache.poi.util.StringUtil;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
@@ -110,6 +109,8 @@ public class GoodsServiceImpl implements GoodsService {
|
|
@Autowired
|
|
@Autowired
|
|
private BrandService brandService;
|
|
private BrandService brandService;
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
+ private ShopErrorPriceRecordService shopErrorPriceRecordService;
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public GoodsEntity queryObject(Integer id) {
|
|
public GoodsEntity queryObject(Integer id) {
|
|
@@ -1903,5 +1904,144 @@ public class GoodsServiceImpl implements GoodsService {
|
|
goodsDao.update(updateGoods);
|
|
goodsDao.update(updateGoods);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @Override
|
|
|
|
+ public void checkGoodsPrice(SysUserEntity user) {
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ Map<String, BigDecimal> hsCodeMap = CalculateTax.hsCodeMap;
|
|
|
|
+ Set<String> hdCodeSet = hsCodeMap.keySet();
|
|
|
|
+
|
|
|
|
+ List<Map<String,String>> errorPriceSkuList = new LinkedList<>();
|
|
|
|
+
|
|
|
|
+ // 保存各种异常价格对象集合
|
|
|
|
+ List<ShopErrorPriceRecordEntity> shopErrorPriceRecordEntities = new LinkedList<>();
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ // 查询所有特殊化妆品的商品
|
|
|
|
+ List<GoodsEntity> queryGoodsDetails = goodsDao.querySpecialCosmetics(hdCodeSet);
|
|
|
|
+ for (GoodsEntity goodsEntity : queryGoodsDetails) {
|
|
|
|
+ calculateShopPrice(user,goodsEntity,errorPriceSkuList,shopErrorPriceRecordEntities);
|
|
|
|
+ calculateDailyPrice(user,goodsEntity,errorPriceSkuList,shopErrorPriceRecordEntities);
|
|
|
|
+ calculeatePromotion(user,goodsEntity,errorPriceSkuList,shopErrorPriceRecordEntities);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if(shopErrorPriceRecordEntities.size() != 0){
|
|
|
|
+ shopErrorPriceRecordService.saveBatch(shopErrorPriceRecordEntities);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void calculeatePromotion(SysUserEntity user, GoodsEntity goods, List<Map<String, String>> errorPriceSkuList, List<ShopErrorPriceRecordEntity> shopErrorPriceRecordEntities) {
|
|
|
|
+ String prodBarcode = goods.getProdBarcode();
|
|
|
|
+ String storeId = goods.getStoreId()+"";
|
|
|
|
+ SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
|
+ /**
|
|
|
|
+ * 2.查询当前时间,该门店是否有活动,如果有活动,查询开启了哪些营销方式
|
|
|
|
+ * 参数: 当前时间 门店id
|
|
|
|
+ */
|
|
|
|
+ MkActivitiesPromotionEntity promotionEntity = promotionService.queryByDateAndBarcode(storeId,format.format(new Date()),"lscx",prodBarcode);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ // 如果该商品存在临时促销,直接替换活动价格
|
|
|
|
+ if(promotionEntity == null){
|
|
|
|
+ return ;
|
|
|
|
+ }
|
|
|
|
+ goods.setActualPaymentAmount(promotionEntity.getActivityPrice());
|
|
|
|
+ goods.setRetailPrice(promotionEntity.getActivityPrice());
|
|
|
|
+ goods.setActivity("临时促销");
|
|
|
|
+ try {
|
|
|
|
+ CalculateTax.calculateFinalTax(goods,goods.getActualPaymentAmount(),this).setScale(3,RoundingMode.HALF_UP);
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ ShopErrorPriceRecordEntity shopErrorPriceRecordEntity = new ShopErrorPriceRecordEntity();
|
|
|
|
+ shopErrorPriceRecordEntity.setMerchSn(goods.getMerchSn());
|
|
|
|
+ shopErrorPriceRecordEntity.setThirdMerchSn(goods.getThirdPartyMerchCode());
|
|
|
|
+ shopErrorPriceRecordEntity.setShopSn(goods.getStoreId()+"");
|
|
|
|
+ shopErrorPriceRecordEntity.setPriceType(3); // 3 是临时促销
|
|
|
|
+ shopErrorPriceRecordEntity.setSku(goods.getSku());
|
|
|
|
+ shopErrorPriceRecordEntity.setBarcode(goods.getProdBarcode());
|
|
|
|
+ shopErrorPriceRecordEntity.setVerifier(user.getUserId()+"");
|
|
|
|
+ shopErrorPriceRecordEntity.setCheckTime(new Date());
|
|
|
|
+ shopErrorPriceRecordEntity.setCreaterSn(user.getUserId()+"");
|
|
|
|
+ shopErrorPriceRecordEntity.setCreateTime(new Date());
|
|
|
|
+ shopErrorPriceRecordEntity.setCurrentPrice(goods.getActualPaymentAmount().toString());
|
|
|
|
+ shopErrorPriceRecordEntity.setSuggestedPrice(e.getMessage());
|
|
|
|
+ shopErrorPriceRecordEntities.add(shopErrorPriceRecordEntity);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void calculateDailyPrice(SysUserEntity user, GoodsEntity goods, List<Map<String, String>> errorPriceSkuList, List<ShopErrorPriceRecordEntity> shopErrorPriceRecordEntities) {
|
|
|
|
+ String prodBarcode = goods.getProdBarcode();
|
|
|
|
+ String storeId = goods.getStoreId()+"";
|
|
|
|
+ /**
|
|
|
|
+ * 2.查询当前时间,该门店是否有活动,如果有活动,查询开启了哪些营销方式
|
|
|
|
+ * 参数: 当前时间 门店id
|
|
|
|
+ */
|
|
|
|
+ SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 日常活动跟着条形码走,优先级比临时促销低,但是高于正常价格
|
|
|
|
+ */
|
|
|
|
+ MkDailyActivitiesEntity dailyActivitiesEntity = dailyActivitiesService.queryByDateAndBarcode(storeId,format.format(new Date()),"rchd",prodBarcode);
|
|
|
|
+ if(dailyActivitiesEntity == null){
|
|
|
|
+ return ;
|
|
|
|
+ }
|
|
|
|
+ goods.setActualPaymentAmount(dailyActivitiesEntity.getActivityPrice());
|
|
|
|
+ goods.setRetailPrice(dailyActivitiesEntity.getActivityPrice());
|
|
|
|
+ goods.setActivity("日常活动");
|
|
|
|
+ // 计算税费
|
|
|
|
+ try {
|
|
|
|
+ CalculateTax.calculateFinalTax(goods,goods.getActualPaymentAmount(),this).setScale(3,RoundingMode.HALF_UP);
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ // 记录有异常的sku
|
|
|
|
+ ShopErrorPriceRecordEntity shopErrorPriceRecordEntity = new ShopErrorPriceRecordEntity();
|
|
|
|
+ shopErrorPriceRecordEntity.setMerchSn(goods.getMerchSn());
|
|
|
|
+ shopErrorPriceRecordEntity.setThirdMerchSn(goods.getThirdPartyMerchCode());
|
|
|
|
+ shopErrorPriceRecordEntity.setShopSn(goods.getStoreId()+"");
|
|
|
|
+ shopErrorPriceRecordEntity.setPriceType(2); // 2 是日常活动
|
|
|
|
+ shopErrorPriceRecordEntity.setSku(goods.getSku());
|
|
|
|
+ shopErrorPriceRecordEntity.setBarcode(goods.getProdBarcode());
|
|
|
|
+ shopErrorPriceRecordEntity.setVerifier(user.getUserId()+"");
|
|
|
|
+ shopErrorPriceRecordEntity.setCheckTime(new Date());
|
|
|
|
+ shopErrorPriceRecordEntity.setCreaterSn(user.getUserId()+"");
|
|
|
|
+ shopErrorPriceRecordEntity.setCreateTime(new Date());
|
|
|
|
+ shopErrorPriceRecordEntity.setCurrentPrice(goods.getActualPaymentAmount().toString());
|
|
|
|
+ shopErrorPriceRecordEntity.setSuggestedPrice(e.getMessage());
|
|
|
|
+ shopErrorPriceRecordEntities.add(shopErrorPriceRecordEntity);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void calculateShopPrice(SysUserEntity user, GoodsEntity goods, List<Map<String, String>> errorPriceSkuList, List<ShopErrorPriceRecordEntity> shopErrorPriceRecordEntities) {
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ goods.setDiscountedPrice(new BigDecimal(0));
|
|
|
|
+ BigDecimal retailPrice = goods.getRetailPrice();
|
|
|
|
+ goods.setActualPaymentAmount(retailPrice.setScale(2,RoundingMode.HALF_UP));
|
|
|
|
+
|
|
|
|
+ // 计算税费
|
|
|
|
+ try {
|
|
|
|
+ CalculateTax.calculateFinalTax(goods,goods.getActualPaymentAmount(),this).setScale(3,RoundingMode.HALF_UP);
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ // 记录有异常的sku
|
|
|
|
+ ShopErrorPriceRecordEntity shopErrorPriceRecordEntity = new ShopErrorPriceRecordEntity();
|
|
|
|
+ shopErrorPriceRecordEntity.setMerchSn(goods.getMerchSn());
|
|
|
|
+ shopErrorPriceRecordEntity.setThirdMerchSn(goods.getThirdPartyMerchCode());
|
|
|
|
+ shopErrorPriceRecordEntity.setShopSn(goods.getStoreId()+"");
|
|
|
|
+ shopErrorPriceRecordEntity.setPriceType(1); // 1 门店商品价格
|
|
|
|
+ shopErrorPriceRecordEntity.setSku(goods.getSku());
|
|
|
|
+ shopErrorPriceRecordEntity.setBarcode(goods.getProdBarcode());
|
|
|
|
+ shopErrorPriceRecordEntity.setVerifier(user.getUserId()+"");
|
|
|
|
+ shopErrorPriceRecordEntity.setCheckTime(new Date());
|
|
|
|
+ shopErrorPriceRecordEntity.setCreaterSn(user.getUserId()+"");
|
|
|
|
+ shopErrorPriceRecordEntity.setCreateTime(new Date());
|
|
|
|
+ shopErrorPriceRecordEntity.setCurrentPrice(goods.getActualPaymentAmount().toString());
|
|
|
|
+ shopErrorPriceRecordEntity.setSuggestedPrice(e.getMessage());
|
|
|
|
+ shopErrorPriceRecordEntities.add(shopErrorPriceRecordEntity);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
|
|
}
|
|
}
|