|
@@ -1,10 +1,13 @@
|
|
|
package com.caimei365.commodity.service.impl;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
import com.aliyun.opensearch.sdk.dependencies.com.google.common.collect.Lists;
|
|
|
import com.caimei365.commodity.components.PriceUtilService;
|
|
|
import com.caimei365.commodity.mapper.PriceMapper;
|
|
|
-import com.caimei365.commodity.mapper.PromotionsMapper;
|
|
|
+import com.caimei365.commodity.mapper.ShopMapper;
|
|
|
import com.caimei365.commodity.model.ResponseJson;
|
|
|
+import com.caimei365.commodity.model.vo.ProductSalesVo;
|
|
|
import com.caimei365.commodity.model.vo.LadderPriceVo;
|
|
|
import com.caimei365.commodity.model.vo.PriceVo;
|
|
|
import com.caimei365.commodity.model.vo.TaxVo;
|
|
@@ -13,10 +16,14 @@ import com.caimei365.commodity.service.PriceService;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
+import org.springframework.util.ObjectUtils;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import java.util.List;
|
|
|
|
|
|
+import static com.alibaba.fastjson.JSON.parseArray;
|
|
|
+import static com.alibaba.fastjson.JSON.parseObject;
|
|
|
+
|
|
|
/**
|
|
|
* Description
|
|
|
*
|
|
@@ -29,7 +36,7 @@ public class PriceServiceImpl implements PriceService {
|
|
|
@Resource
|
|
|
private PriceMapper priceMapper;
|
|
|
@Resource
|
|
|
- private PromotionsMapper promotionsMapper;
|
|
|
+ private ShopMapper shopMapper;
|
|
|
@Resource
|
|
|
private PriceUtilService priceUtilService;
|
|
|
@Resource
|
|
@@ -100,4 +107,58 @@ public class PriceServiceImpl implements PriceService {
|
|
|
}
|
|
|
return ResponseJson.success(ladderPrices);
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 更新商品销量
|
|
|
+ *
|
|
|
+ * @param productInfo [ // 商品id,数量
|
|
|
+ * {"productId": 2789, "productCount": 1},
|
|
|
+ * {"productId": 2790, "productCount": 2}
|
|
|
+ * ]
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public ResponseJson<Void> productSaleUpdate(String productInfo) {
|
|
|
+ JSONArray infoArr = null;
|
|
|
+ try {
|
|
|
+ infoArr = parseArray(productInfo);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("【更新商品销量】商品信息解析异常try-catch:", e);
|
|
|
+ return ResponseJson.error("商品信息解析异常!", null);
|
|
|
+ }
|
|
|
+ if (null == infoArr) {
|
|
|
+ return ResponseJson.error("商品数据异常!", null);
|
|
|
+ }
|
|
|
+ // 遍历所有商品
|
|
|
+ for (Object productObject : infoArr) {
|
|
|
+ JSONObject productTemp = (JSONObject) productObject;
|
|
|
+ Integer productId = (Integer) productTemp.get("productId");
|
|
|
+ Integer productCount = (Integer) productTemp.get("productCount");
|
|
|
+ // 获取商品销量信息
|
|
|
+ ProductSalesVo salesVo = priceMapper.getProductSalesInfo(productId);
|
|
|
+ if (null == salesVo || ObjectUtils.isEmpty(salesVo)){
|
|
|
+ return ResponseJson.error("商品数据异常!", null);
|
|
|
+ }
|
|
|
+ int dbCount = (null == salesVo.getProductCount()) ? 0 : salesVo.getProductCount();
|
|
|
+ salesVo.setProductCount(dbCount + productCount);
|
|
|
+ // 获取供应商名称
|
|
|
+ String shopName = shopMapper.getShopNameByShopId(salesVo.getShopId());
|
|
|
+ salesVo.setShopName(shopName);
|
|
|
+ // 分类名称
|
|
|
+ String typeName = shopMapper.getTypeName(salesVo.getBigTypeId(), salesVo.getSmallTypeId(), salesVo.getTinyTypeId());
|
|
|
+ if (null != salesVo.getCommodityType() && 2 == salesVo.getCommodityType()){
|
|
|
+ salesVo.setProperty("仪器-"+typeName);
|
|
|
+ } else {
|
|
|
+ salesVo.setProperty("产品-"+typeName);
|
|
|
+ }
|
|
|
+ if (null == salesVo.getId()) {
|
|
|
+ // 新商品
|
|
|
+ priceMapper.insertProductSales(salesVo);
|
|
|
+ } else {
|
|
|
+ // 更新销量
|
|
|
+ priceMapper.updateProductSales(salesVo);
|
|
|
+ }
|
|
|
+ log.info("【更新商品销量】:"+salesVo.toString());
|
|
|
+ }
|
|
|
+ return ResponseJson.success(null);
|
|
|
+ }
|
|
|
}
|