完善jd商品拉取、关联
This commit is contained in:
parent
ec5e4281ea
commit
c48b8c9a25
|
|
@ -6,5 +6,5 @@ import lombok.Data;
|
|||
public class LinkErpGoodsSkuBo {
|
||||
private String id;//主键ID
|
||||
private String erpGoodsSkuId;//ERP商品SkuId
|
||||
private String erpSkuId;//ERP商品SkuId
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -51,6 +51,7 @@ public class HttpStatus
|
|||
* 未授权
|
||||
*/
|
||||
public static final int UNAUTHORIZED = 401;
|
||||
public static final int UNAUTHORIZED1 = 1401;
|
||||
|
||||
/**
|
||||
* 访问受限,授权过期
|
||||
|
|
|
|||
|
|
@ -0,0 +1,79 @@
|
|||
package com.qihang.jd.controller;
|
||||
|
||||
|
||||
import cn.qihangerp.open.jd.GoodsApiHelper;
|
||||
import cn.qihangerp.open.jd.common.ApiResultVo;
|
||||
import cn.qihangerp.open.jd.model.GoodsSku;
|
||||
import cn.qihangerp.open.jd.utils.DateUtil;
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.qihang.common.common.AjaxResult;
|
||||
import com.qihang.common.enums.HttpStatus;
|
||||
import com.qihang.jd.domain.OmsJdGoodsSku;
|
||||
import com.qihang.jd.openApi.ApiCommon;
|
||||
import com.qihang.jd.openApi.PullRequest;
|
||||
import com.qihang.jd.service.OmsJdGoodsSkuService;
|
||||
import com.qihang.security.common.BaseController;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
@AllArgsConstructor
|
||||
@RestController
|
||||
@RequestMapping("/goods")
|
||||
public class GoodsApiController extends BaseController {
|
||||
private final ApiCommon apiCommon;
|
||||
private final OmsJdGoodsSkuService goodsSkuService;
|
||||
|
||||
@RequestMapping(value = "/pull_goods", method = RequestMethod.POST)
|
||||
public AjaxResult pullList(@RequestBody PullRequest params) throws Exception {
|
||||
if (params.getShopId() == null || params.getShopId() <= 0) {
|
||||
return AjaxResult.error(HttpStatus.PARAMS_ERROR, "参数错误,没有店铺Id");
|
||||
}
|
||||
var checkResult = apiCommon.checkBefore(params.getShopId());
|
||||
if (checkResult.getCode() != HttpStatus.SUCCESS) {
|
||||
return AjaxResult.error(checkResult.getCode(), checkResult.getMsg(),checkResult.getData());
|
||||
}
|
||||
String accessToken = checkResult.getData().getAccessToken();
|
||||
String appKey = checkResult.getData().getAppKey();
|
||||
String appSecret = checkResult.getData().getAppSecret();
|
||||
|
||||
|
||||
//获取接口
|
||||
ApiResultVo<GoodsSku> upResult = GoodsApiHelper.pullGoods(appKey,appSecret,accessToken);
|
||||
if(upResult.getCode() == 19) return AjaxResult.error(HttpStatus.UNAUTHORIZED1,"Token已过期");
|
||||
if(upResult.getCode()!=0) return AjaxResult.error(upResult.getCode(),upResult.getMsg());
|
||||
|
||||
int successTotal = 0;//新增成功的订单
|
||||
int totalError = 0;
|
||||
int hasExistOrder = 0;//已存在的订单数
|
||||
for (GoodsSku sku: upResult.getList()) {
|
||||
OmsJdGoodsSku goodsSku = new OmsJdGoodsSku();
|
||||
BeanUtils.copyProperties(sku, goodsSku);
|
||||
goodsSku.setJdPrice(BigDecimal.valueOf(sku.getJdPrice()/100));
|
||||
goodsSku.setCreated( DateUtil.unixTimeToDate(sku.getCreated()/1000));
|
||||
goodsSku.setModified(DateUtil.unixTimeToDate(sku.getModified()/1000));
|
||||
goodsSku.setShopId(params.getShopId());
|
||||
if(sku.getSaleAttrs()!=null){
|
||||
goodsSku.setSaleAttrs(JSON.toJSONString(sku.getSaleAttrs()));
|
||||
String attrs = "";
|
||||
for(GoodsSku.SaleAttrsDTO dto:sku.getSaleAttrs()){
|
||||
for(String s: dto.getAttrValueAlias()) {
|
||||
attrs += s +";";
|
||||
}
|
||||
}
|
||||
goodsSku.setAttrs(attrs);
|
||||
}
|
||||
|
||||
goodsSkuService.saveGoodsSku(params.getShopId(), goodsSku);
|
||||
successTotal++;
|
||||
logger.info("添加商品:"+successTotal);
|
||||
|
||||
}
|
||||
return AjaxResult.success();
|
||||
}
|
||||
}
|
||||
|
|
@ -50,7 +50,7 @@ public class GoodsController extends BaseController {
|
|||
{
|
||||
OmsJdGoodsSku sku = new OmsJdGoodsSku();
|
||||
sku.setId(bo.getId());
|
||||
sku.setErpGoodsSkuId(Long.parseLong(bo.getErpSkuId()));
|
||||
sku.setErpGoodsSkuId(Long.parseLong(bo.getErpGoodsSkuId()));
|
||||
skuService.updateById(sku);
|
||||
return success();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -56,7 +56,6 @@ public class OrderApiController {
|
|||
return AjaxResult.error(checkResult.getCode(), checkResult.getMsg(),checkResult.getData());
|
||||
}
|
||||
String accessToken = checkResult.getData().getAccessToken();
|
||||
String serverUrl = checkResult.getData().getServerUrl();
|
||||
String appKey = checkResult.getData().getAppKey();
|
||||
String appSecret = checkResult.getData().getAppSecret();
|
||||
|
||||
|
|
|
|||
|
|
@ -74,7 +74,7 @@
|
|||
<!-- </el-table-column>-->
|
||||
<el-table-column label="商家编码" align="center" prop="outerId" />
|
||||
<el-table-column label="京东价" align="center" prop="jdPrice" />
|
||||
<el-table-column label="ERP SKU ID" align="center" prop="erpSkuId" />
|
||||
<el-table-column label="ERP SKU ID" align="center" prop="erpGoodsSkuId" />
|
||||
<el-table-column label="状态" align="center" prop="status" >
|
||||
<template slot-scope="scope">
|
||||
<el-tag size="small" v-if="scope.row.status === 1">销售中</el-tag>
|
||||
|
|
@ -106,8 +106,8 @@
|
|||
<!-- 添加或修改商品管理对话框 -->
|
||||
<el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
|
||||
<el-form ref="form" :model="form" :rules="rules" label-width="120px">
|
||||
<el-form-item label="ERP商品SkuId" prop="erpSkuId">
|
||||
<el-input v-model.number="form.erpSkuId" placeholder="请输入ERP商品SkuId" />
|
||||
<el-form-item label="ERP商品SkuId" prop="erpGoodsSkuId">
|
||||
<el-input v-model.number="form.erpGoodsSkuId" placeholder="请输入ERP商品SkuId" />
|
||||
</el-form-item>
|
||||
|
||||
</el-form>
|
||||
|
|
@ -171,7 +171,7 @@ export default {
|
|||
id: [
|
||||
{ required: true, message: "不能为空", trigger: "change" }
|
||||
],
|
||||
erpSkuId: [
|
||||
erpGoodsSkuId: [
|
||||
{ required: true, message: "不能为空", trigger: "blur" }
|
||||
],
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue