This commit is contained in:
启航 2024-03-13 19:21:50 +08:45
parent 4563cd9df3
commit fd5f786c58
6 changed files with 121 additions and 25 deletions

View File

@ -35,7 +35,7 @@ public class ApiCommon {
}
if (shop.getType() != EnumShopType.JD.getIndex()) {
return ApiResult.build(HttpStatus.PARAMS_ERROR, "参数错误,店铺不是淘系店铺");
return ApiResult.build(HttpStatus.PARAMS_ERROR, "参数错误,店铺不是JD店铺");
}
SysPlatform platform = platformService.selectById(EnumShopType.JD.getIndex());

View File

@ -6,7 +6,12 @@ import com.pdd.pop.sdk.http.PopHttpClient;
import com.pdd.pop.sdk.http.api.pop.request.PddOrderListGetRequest;
import com.pdd.pop.sdk.http.api.pop.response.PddOrderListGetResponse;
import com.qihang.common.common.ApiResult;
import com.qihang.common.enums.EnumShopType;
import com.qihang.common.enums.HttpStatus;
import com.qihang.pdd.domain.SysPlatform;
import com.qihang.pdd.service.SysPlatformService;
import com.qihang.pdd.service.SysShopService;
import lombok.AllArgsConstructor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@ -15,14 +20,16 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
@AllArgsConstructor
@RequestMapping("/pdd_api")
@RestController
public class AjaxOrderPddController {
private static Logger log = LoggerFactory.getLogger(AjaxOrderPddController.class);
// @Autowired
// private ServerConfig serverConfig;
@Autowired
private SysShopService shopService;
private final SysShopService shopService;
private final SysPlatformService platformService;
// @Autowired
// private IPddOrderService pddOrderService;
@ -42,31 +49,53 @@ public class AjaxOrderPddController {
String endDate = reqData.getEndDate();//reqData.getString("endTime");
var shop = shopService.selectShopById(reqData.getShopId());
if(shop == null) return new ApiResult<>(EnumResultVo.Fail.getIndex(), "店铺不存在!");
String appKey = shop.getAppKey();
String appSercet = shop.getAppSercet();
if(!StringUtils.hasText(appKey) || !StringUtils.hasText(appSercet)) return new ApiResult<>(EnumResultVo.Fail.getIndex(), "参数错误请设置appkey和serecet");
if(shop == null) return ApiResult.build(HttpStatus.PARAMS_ERROR, "店铺不存在!");
if (shop.getType() != EnumShopType.PDD.getIndex()) {
return ApiResult.build(HttpStatus.PARAMS_ERROR, "参数错误店铺不是PDD店铺");
}
SysPlatform platform = platformService.selectById(EnumShopType.JD.getIndex());
if(!StringUtils.hasText(platform.getAppKey())) {
return ApiResult.build(HttpStatus.PARAMS_ERROR, "平台配置错误没有找到AppKey");
}
if(!StringUtils.hasText(platform.getAppSecret())) {
return ApiResult.build(HttpStatus.PARAMS_ERROR, "第三方平台配置错误没有找到AppSercet");
}
// if(!StringUtils.hasText(platform.getRedirectUri())) {
// return ApiResult.build(HttpStatus.PARAMS_ERROR, "第三方平台配置错误没有找到RedirectUri");
// }
// if(!StringUtils.hasText(platform.getServerUrl())) {
// return ApiResult.build(HttpStatus.PARAMS_ERROR, "第三方平台配置错误没有找到ServerUrl");
// }
// String appKey = shop.getAppKey();
// String appSercet = shop.getAppSercet();
// if(!StringUtils.hasText(appKey) || !StringUtils.hasText(appSercet)) return new ApiResult<>(EnumResultVo.Fail.getIndex(), "参数错误请设置appkey和serecet");
// String clientId = DataConfigObject.getInstance().getPddClientId();
// String clientSecret = DataConfigObject.getInstance().getPddClientSecret();
// var shop = shopService.getShop(shopId);
// var settingEntity = thirdSettingService.getEntity(shop.getType());
ShopApiParams params = new ShopApiParams();
params.setAppKey(shop.getAppkey());
params.setAppSecret(shop.getAppSercet());
params.setAccessToken(shop.getSessionKey());
params.setTokenRequestUrl(serverConfig.getUrl()+"/pdd_api2/oauth");
params.setAppKey(platform.getAppKey());
params.setAppSecret(platform.getAppSecret());
params.setAccessToken(shop.getAccessToken());
params.setTokenRequestUrl("http://localhost:3000/pdd_api2/oauth");
params.setApiRequestUrl(shop.getApiRequestUrl());
String accessToken = shop.getSessionKey();
if(!StringUtils.hasText(accessToken)) return new ApiResult<>(EnumResultVo.TokenFail.getIndex(), "参数错误accessToken为空",params);
String accessToken = params.getAccessToken();
if(!StringUtils.hasText(accessToken)) {
return ApiResult.build(HttpStatus.PARAMS_ERROR, "参数错误accessToken为空");
}
// if(!StringUtils.hasText(accessToken)) return new ApiResult<>(EnumResultVo.TokenFail.getIndex(), "参数错误accessToken为空",params);
// 获取店铺信息判断店铺是否一致
var shopResult = PddApiUtils.getShopInfo(appKey, appSercet, accessToken);
if (shopResult.getCode() != EnumResultVo.SUCCESS.getIndex())
return new ApiResult<>(shopResult.getCode(), shopResult.getMsg(),params);
var shopResult = PddApiUtils.getShopInfo(params.getAppKey(), params.getAppSecret(), accessToken);
if (shopResult.getCode() != HttpStatus.SUCCESS)
return ApiResult.build(shopResult.getCode(), shopResult.getMsg(),params);
if (shopResult.getData().getMallId().longValue() != shop.getSellerUserId().longValue()) {
return new ApiResult<>(EnumResultVo.TokenFail.getIndex(), "该店铺不是授权店铺",params);
if (shopResult.getData().getMallId().longValue() != shop.getSellerId().longValue()) {
return ApiResult.build(HttpStatus.UNAUTHORIZED, "该店铺不是授权店铺",params);
}
ApiResult<ErpSalesPullCountResp> result = null;// 返回结果

View File

@ -0,0 +1,61 @@
package com.qihang.pdd.controller;
/**
* 更新erp销售订单数据统计
*/
public class ErpSalesPullCountResp {
private int addCount;//新增
private int failCount;//失败
private int updCount;//更新
private Integer totalRecords;//总记录数
private String startTime;
private String endTime;
public String getStartTime() {
return startTime;
}
public void setStartTime(String startTime) {
this.startTime = startTime;
}
public String getEndTime() {
return endTime;
}
public void setEndTime(String endTime) {
this.endTime = endTime;
}
public int getAddCount() {
return addCount;
}
public void setAddCount(int addCount) {
this.addCount = addCount;
}
public int getFailCount() {
return failCount;
}
public void setFailCount(int failCount) {
this.failCount = failCount;
}
public int getUpdCount() {
return updCount;
}
public void setUpdCount(int updCount) {
this.updCount = updCount;
}
public Integer getTotalRecords() {
return totalRecords;
}
public void setTotalRecords(Integer totalRecords) {
this.totalRecords = totalRecords;
}
}

View File

@ -5,8 +5,8 @@ import com.pdd.pop.sdk.http.PopClient;
import com.pdd.pop.sdk.http.PopHttpClient;
import com.pdd.pop.sdk.http.api.pop.request.PddMallInfoGetRequest;
import com.pdd.pop.sdk.http.api.pop.response.PddMallInfoGetResponse;
import com.qihang.erp.api.common.ApiResult;
import com.qihang.erp.api.common.EnumResultVo;
import com.qihang.common.common.ApiResult;
import com.qihang.common.enums.HttpStatus;
public class PddApiUtils {
/**
@ -24,11 +24,11 @@ public class PddApiUtils {
PddMallInfoGetRequest request = new PddMallInfoGetRequest();
PddMallInfoGetResponse response = client.syncInvoke(request, accessToken);
if (response.getErrorResponse() == null) {
return new ApiResult<>(EnumResultVo.SUCCESS.getIndex(), "SUCCESS", response.getMallInfoGetResponse());
return ApiResult.build(HttpStatus.SUCCESS, "SUCCESS", response.getMallInfoGetResponse());
} else if (response.getErrorResponse().getErrorCode().intValue() == 10019) {
return new ApiResult<>(EnumResultVo.TokenFail.getIndex(), "Token过期");
return ApiResult.build(HttpStatus.UNAUTHORIZED, "Token过期");
}else
return new ApiResult<>(EnumResultVo.Fail.getIndex(), "接口调用失败:"+response.getErrorResponse().getErrorMsg());
return ApiResult.build(HttpStatus.ERROR, "接口调用失败:"+response.getErrorResponse().getErrorMsg());
}
}

View File

@ -9,5 +9,5 @@ import com.baomidou.mybatisplus.extension.service.IService;
* @createDate 2024-03-13 17:43:42
*/
public interface SysPlatformService extends IService<SysPlatform> {
SysPlatform selectById(Integer id);
}

View File

@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qihang.pdd.domain.SysPlatform;
import com.qihang.pdd.service.SysPlatformService;
import com.qihang.pdd.mapper.SysPlatformMapper;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
/**
@ -11,10 +12,15 @@ import org.springframework.stereotype.Service;
* @description 针对表sys_platform的数据库操作Service实现
* @createDate 2024-03-13 17:43:42
*/
@AllArgsConstructor
@Service
public class SysPlatformServiceImpl extends ServiceImpl<SysPlatformMapper, SysPlatform>
implements SysPlatformService{
private final SysPlatformMapper mapper;
@Override
public SysPlatform selectById(Integer id) {
return mapper.selectById(id);
}
}