|
|
@@ -5,6 +5,7 @@ import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
import com.yami.shop.bean.dto.hb.HBBaseReq;
|
|
|
import com.yami.shop.bean.model.*;
|
|
|
import com.yami.shop.common.util.hb.HBR;
|
|
|
@@ -41,6 +42,9 @@ public class HBGoodsService implements IHBGoodsService {
|
|
|
private final SkuMapper skuMapper;
|
|
|
private final ShopSkuMapper shopSkuMapper;
|
|
|
private final ShopDetailMapper shopDetailMapper;
|
|
|
+
|
|
|
+ private final FrontCategoryMapper frontCategoryMapper;
|
|
|
+ private final ShopCategoryMapper shopCategoryMapper;
|
|
|
private final CategoryProdMapper categoryProdMapper;
|
|
|
|
|
|
@Override
|
|
|
@@ -177,18 +181,42 @@ public class HBGoodsService implements IHBGoodsService {
|
|
|
@Override
|
|
|
public HBR updateGoodsStatus(JSONObject hbRequest) {
|
|
|
try {
|
|
|
- String bodyStr = hbRequest.getString("body");
|
|
|
+ JSONObject bodyStr = hbRequest.getJSONObject("body");
|
|
|
log.info("商品,body:{}", bodyStr);
|
|
|
- JSONObject bodyJson = JSON.parseObject(bodyStr); // 使用Fastjson的解析方法
|
|
|
-// String outStationNo = bodyJson.getString("outStationNo");
|
|
|
- String skuId = bodyJson.getString("skuId");
|
|
|
- String stationId = bodyJson.getString("stationId");
|
|
|
|
|
|
- String selfSkuStatus = getSelfSkuStatus(skuId, stationId);
|
|
|
- log.info("商品状态变更查询:{}", selfSkuStatus);
|
|
|
- //处理商品状态
|
|
|
+ JSONArray data = bodyStr.getJSONArray("data");// 使用Fastjson的解析方法
|
|
|
+ String selfSkuStatus = getSelfSkuStatus(data);
|
|
|
+ JSONObject skuInfo = JSON.parseObject(selfSkuStatus);
|
|
|
+ JSONArray jsonArray = skuInfo.getJSONObject("result").getJSONObject("result").getJSONArray("stationProductList");
|
|
|
+ for (Object datum : jsonArray) {
|
|
|
+ JSONObject jsonObject = JSON.parseObject(datum.toString());
|
|
|
+ String skuId = jsonObject.getString("skuId");
|
|
|
+ String stationId = jsonObject.getString("stationId");
|
|
|
+ Integer saleStatus = jsonObject.getInteger("saleStatus");//1 可售,0不可售
|
|
|
+
|
|
|
+ log.info("商品状态变更查询:{}", selfSkuStatus);
|
|
|
+
|
|
|
+ //处理商品状态
|
|
|
+ ShopDetail shopDetail = shopDetailMapper.selectOne(new LambdaUpdateWrapper<ShopDetail>()
|
|
|
+ .eq(ShopDetail::getHbStationId, stationId));
|
|
|
+ Sku sku = skuMapper.selectByHbSkuId(skuId);
|
|
|
+ shopSkuMapper.update(new ShopSku(), new LambdaUpdateWrapper<ShopSku>()
|
|
|
+ .set(ShopSku::getSaleStatus, saleStatus)
|
|
|
+ .eq(ShopSku::getSkuId, sku.getSkuId())
|
|
|
+ .eq(ShopSku::getShopId, shopDetail.getShopId()));
|
|
|
+
|
|
|
+ //处理门店-分类管理
|
|
|
+ List<CategoryProd> categoryProds = categoryProdMapper.selectList(new LambdaQueryWrapper<CategoryProd>()
|
|
|
+ .eq(CategoryProd::getProdId, sku.getProdId())
|
|
|
+ .eq(CategoryProd::getIsDelete, 0));
|
|
|
+ for (CategoryProd categoryProd : categoryProds) {
|
|
|
+ FrontCategory frontCategory = frontCategoryMapper.selectOne(new LambdaQueryWrapper<FrontCategory>()
|
|
|
+ .eq(FrontCategory::getCode, categoryProd.getCode()));
|
|
|
+ addShopCategory(frontCategory, shopDetail.getShopId(), shopDetail.getHbStationId());
|
|
|
+ }
|
|
|
|
|
|
|
|
|
+ }
|
|
|
} catch (Exception e) {
|
|
|
log.error("商品失败:{}", e.getMessage(), e);
|
|
|
return HBR.error("未知异常");
|
|
|
@@ -197,6 +225,65 @@ public class HBGoodsService implements IHBGoodsService {
|
|
|
return HBR.success();
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 添加门店分类
|
|
|
+ *
|
|
|
+ * @param frontCategory 前台分类
|
|
|
+ * @param shopId 门店id
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public void addShopCategory(FrontCategory frontCategory, Long shopId, String hbShopId) {
|
|
|
+ ShopCategory shopCategoryByCode = shopCategoryMapper.selectOne(new LambdaQueryWrapper<ShopCategory>()
|
|
|
+ .eq(ShopCategory::getCode, frontCategory.getCode())
|
|
|
+ .eq(ShopCategory::getShopId, shopId)
|
|
|
+ .eq(ShopCategory::getIsDelete, 0));
|
|
|
+
|
|
|
+ if (shopCategoryByCode != null) {
|
|
|
+ log.info("门店分类已存在,无需添加");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ ShopCategory shopCategory = new ShopCategory();
|
|
|
+ shopCategory.setCode(frontCategory.getCode());
|
|
|
+ shopCategory.setName(frontCategory.getName());
|
|
|
+ if (frontCategory.getParentCode() == null || frontCategory.getParentCode().equals("0")) {
|
|
|
+ shopCategory.setPid(0L);
|
|
|
+ shopCategory.setParentCode("0");
|
|
|
+ } else {
|
|
|
+ ShopCategory shopCategoryByCode1 = shopCategoryMapper.selectOne(new LambdaQueryWrapper<ShopCategory>()
|
|
|
+ .eq(ShopCategory::getCode, frontCategory.getParentCode())
|
|
|
+ .eq(ShopCategory::getShopId, shopId)
|
|
|
+ .eq(ShopCategory::getIsDelete, 0));
|
|
|
+ if (shopCategoryByCode1 == null) {
|
|
|
+ //不存在门店分类父类目添加
|
|
|
+ FrontCategory frontCategoryParent = frontCategoryMapper.selectOne(new LambdaQueryWrapper<FrontCategory>()
|
|
|
+ .eq(FrontCategory::getCode, frontCategory.getParentCode())
|
|
|
+ .eq(FrontCategory::getIsDelete, 0));
|
|
|
+ addShopCategory(frontCategoryParent, shopId, hbShopId);
|
|
|
+
|
|
|
+ shopCategoryByCode1 = shopCategoryMapper.selectOne(new LambdaQueryWrapper<ShopCategory>()
|
|
|
+ .eq(ShopCategory::getCode, frontCategory.getParentCode())
|
|
|
+ .eq(ShopCategory::getShopId, shopId)
|
|
|
+ .eq(ShopCategory::getIsDelete, 0));
|
|
|
+ }
|
|
|
+ shopCategory.setPid(shopCategoryByCode1.getId());
|
|
|
+ shopCategory.setParentCode(shopCategoryByCode1.getCode());
|
|
|
+ }
|
|
|
+
|
|
|
+ shopCategory.setShopId(shopId);
|
|
|
+ shopCategory.setHbShopId(hbShopId);
|
|
|
+ shopCategory.setLabel(frontCategory.getLabel());
|
|
|
+ shopCategory.setIcon(frontCategory.getIcon());
|
|
|
+ shopCategory.setPic(frontCategory.getPic());
|
|
|
+ shopCategory.setLevel(frontCategory.getLevel());
|
|
|
+ shopCategory.setIsDelete(0);
|
|
|
+ shopCategory.setOperateUser("admin");
|
|
|
+ shopCategory.setNum(frontCategory.getNum());
|
|
|
+ shopCategory.setIsLeaves(frontCategory.getIsLeaves());
|
|
|
+
|
|
|
+ shopCategoryMapper.insert(shopCategory);
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public HBR updateGoodsPrice(JSONObject hbRequest) {
|
|
|
@@ -393,18 +480,19 @@ public class HBGoodsService implements IHBGoodsService {
|
|
|
*
|
|
|
* @return 门店品售卖状态信息
|
|
|
*/
|
|
|
- public String getSelfSkuStatus(String skuId, String stationId) {
|
|
|
+ public String getSelfSkuStatus(JSONArray data) {
|
|
|
HBBaseReq<Object> build = HBBaseReq.create();
|
|
|
build.setAppId(hbSignUtil.getAppId());
|
|
|
JSONObject jsonObject = new JSONObject();
|
|
|
- List<JSONObject> onlineProductDTO = new ArrayList();
|
|
|
- jsonObject.put("skuId", skuId);//海博商品编码
|
|
|
- jsonObject.put("stationId", stationId);//海博门店编码
|
|
|
- onlineProductDTO.add(jsonObject);
|
|
|
- build.setBody(JSON.toJSONString(onlineProductDTO));
|
|
|
+ jsonObject.put("data", data);
|
|
|
+// List<JSONObject> onlineProductDTO = new ArrayList();
|
|
|
+// jsonObject.put("skuId", skuId);//海博商品编码
|
|
|
+// jsonObject.put("stationId", stationId);//海博门店编码
|
|
|
+// onlineProductDTO.add(jsonObject);
|
|
|
+ build.setBody(JSON.toJSONString(jsonObject));
|
|
|
build.setSign(hbSignUtil.signMd5(build));
|
|
|
- String post = post(hbSignUtil.getHBHost() + "/api/productStation/getSelfSkuStatus", build);
|
|
|
log.info("post 商品查询请求参数:{}", JSON.toJSONString(build));
|
|
|
+ String post = post(hbSignUtil.getHBHost() + "/api/productStation/getSelfSkuStatus", build);
|
|
|
log.info("post 商品查询结果:{}", post);
|
|
|
return post;
|
|
|
}
|
|
|
@@ -551,7 +639,21 @@ public class HBGoodsService implements IHBGoodsService {
|
|
|
.eq(CategoryProd::getCode, ztFrontCategoryCodeLevel));
|
|
|
if (integer == null) {
|
|
|
categoryProdMapper.insert(categoryProd);
|
|
|
+
|
|
|
+ }
|
|
|
+ //门店分类处理
|
|
|
+ List<ShopSku> shopCategoryList = shopSkuMapper.selectList(new LambdaQueryWrapper<ShopSku>()
|
|
|
+ .eq(ShopSku::getSpuId, spuId)
|
|
|
+ .eq(ShopSku::getIsDelete, 0));
|
|
|
+
|
|
|
+ for (ShopSku shopSku : shopCategoryList) {
|
|
|
+ FrontCategory frontCategory = frontCategoryMapper.selectOne(new LambdaQueryWrapper<FrontCategory>()
|
|
|
+ .eq(FrontCategory::getCode, ztFrontCategoryCodeLevel));
|
|
|
+ ShopDetail shopDetail = shopDetailMapper.selectById(shopSku.getShopId());
|
|
|
+
|
|
|
+ addShopCategory(frontCategory, shopSku.getShopId(), shopDetail.getHbStationId());
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
|
|
|
|