refundapi
This commit is contained in:
parent
6f0ab5f950
commit
a2d4e766cb
|
|
@ -0,0 +1,92 @@
|
|||
package com.qihang.tao.api;
|
||||
|
||||
import com.qihang.common.enums.HttpStatus;
|
||||
import com.qihang.tao.common.EnumShopType;
|
||||
import com.qihang.tao.common.ServerConfig;
|
||||
import com.qihang.tao.controller.ShopApiParams;
|
||||
import com.qihang.tao.domain.SysPlatform;
|
||||
import com.qihang.tao.service.SysPlatformService;
|
||||
import com.qihang.tao.service.SysShopService;
|
||||
import com.taobao.api.ApiException;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.StringUtils;
|
||||
@AllArgsConstructor
|
||||
@Component
|
||||
public class ApiCommon {
|
||||
private final SysShopService shopService;
|
||||
private final SysPlatformService platformService;
|
||||
private final ServerConfig serverConfig;
|
||||
/**
|
||||
* 更新前的检查
|
||||
*
|
||||
* @param shopId
|
||||
* @return
|
||||
* @throws ApiException
|
||||
*/
|
||||
public com.qihang.tao.common.ApiResult<ShopApiParams> checkBefore(Integer shopId) throws ApiException {
|
||||
var shop = shopService.selectShopById(shopId);
|
||||
if (shop == null) {
|
||||
// return new ApiResult<>(EnumResultVo.ParamsError.getIndex(), "参数错误,没有找到店铺");
|
||||
return com.qihang.tao.common.ApiResult.build(HttpStatus.PARAMS_ERROR,"参数错误,没有找到店铺");
|
||||
}
|
||||
|
||||
if (shop.getType() != EnumShopType.TAO.getIndex()) {
|
||||
return com.qihang.tao.common.ApiResult.build(HttpStatus.PARAMS_ERROR, "参数错误,店铺不是淘系店铺");
|
||||
}
|
||||
SysPlatform platform = platformService.selectById(EnumShopType.TAO.getIndex());
|
||||
|
||||
if(!StringUtils.hasText(platform.getAppKey())) {
|
||||
return com.qihang.tao.common.ApiResult.build(HttpStatus.PARAMS_ERROR, "平台配置错误,没有找到AppKey");
|
||||
}
|
||||
if(!StringUtils.hasText(platform.getAppSecret())) {
|
||||
return com.qihang.tao.common.ApiResult.build(HttpStatus.PARAMS_ERROR, "第三方平台配置错误,没有找到AppSercet");
|
||||
}
|
||||
if(!StringUtils.hasText(shop.getApiRequestUrl())) {
|
||||
return com.qihang.tao.common.ApiResult.build(HttpStatus.PARAMS_ERROR, "第三方平台配置错误,没有找到ApiRequestUrl");
|
||||
}
|
||||
if(shop.getSellerId() == null || shop.getSellerId() <= 0) {
|
||||
return com.qihang.tao.common.ApiResult.build(HttpStatus.PARAMS_ERROR, "第三方平台配置错误,没有找到SellerUserId");
|
||||
}
|
||||
|
||||
ShopApiParams params = new ShopApiParams();
|
||||
params.setAppKey(platform.getAppKey());
|
||||
params.setAppSecret(platform.getAppSecret());
|
||||
params.setAccessToken(shop.getAccessToken());
|
||||
params.setTokenRequestUrl(serverConfig.getUrl()+"/taoapi2/tao_oauth");
|
||||
params.setApiRequestUrl(shop.getApiRequestUrl());
|
||||
|
||||
if (!StringUtils.hasText(shop.getAccessToken())) {
|
||||
|
||||
return com.qihang.tao.common.ApiResult.build(HttpStatus.UNAUTHORIZED, "Token已过期,请重新授权", params);
|
||||
}
|
||||
|
||||
/****************先查询卖家对不对***************/
|
||||
// TaobaoClient client = new DefaultTaobaoClient(url, appkey, secret);
|
||||
// UserSellerGetRequest reqSeller = new UserSellerGetRequest();
|
||||
// reqSeller.setFields("nick,user_id");
|
||||
// UserSellerGetResponse rsp = client.execute(reqSeller, sessionKey);
|
||||
// if(StringUtils.hasText(rsp.getErrorCode())){
|
||||
// if(rsp.getErrorCode().equals("27")){
|
||||
// return new ApiResult<>(EnumResultVo.TokenFail.getIndex(), "Token已过期,请重新授权",params);
|
||||
// }
|
||||
// else if(rsp.getErrorCode().equals("11")){
|
||||
// if(rsp.getSubCode().equals("isv.permission-api-package-limit"))
|
||||
// return new ApiResult<>(EnumResultVo.ParamsError.getIndex(), "请检查淘宝用户API:taobao.user.seller.get是否具有访问权限",params);
|
||||
// return new ApiResult<>(EnumResultVo.ParamsError.getIndex(), rsp.getSubCode(),params);
|
||||
// }
|
||||
// else if(rsp.getErrorCode().equals("25")){
|
||||
// return new ApiResult<>(EnumResultVo.ParamsError.getIndex(), "无效签名!请检查SessionKey、appKey、appSecret是否匹配",params);
|
||||
// } else
|
||||
// return new ApiResult<>(EnumResultVo.ParamsError.getIndex(), "参数错误!"+(StringUtils.hasText(rsp.getSubMsg()) ? rsp.getSubMsg(): rsp.getMsg()));
|
||||
// }
|
||||
// if(rsp.getUser() == null || rsp.getUser().getUserId() == null){
|
||||
// return new ApiResult<>(EnumResultVo.ParamsError.getIndex(), "参数错误!请设置店铺SellerUserId值!",params);
|
||||
// }
|
||||
// else if (shop.getSellerUserId().longValue() != rsp.getUser().getUserId().longValue()) {
|
||||
// return new ApiResult<>(EnumResultVo.TokenFail.getIndex(), "当前用户是:" + rsp.getUser().getNick() + ",请重新授权",params);
|
||||
// }
|
||||
return com.qihang.tao.common.ApiResult.build(HttpStatus.SUCCESS,"",params);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,18 +1,31 @@
|
|||
package com.qihang.tao.api;
|
||||
|
||||
import com.qihang.common.utils.DateUtils;
|
||||
import com.qihang.common.utils.StringUtils;
|
||||
import com.qihang.tao.domain.TaoRefund;
|
||||
import com.taobao.api.ApiException;
|
||||
import com.taobao.api.DefaultTaobaoClient;
|
||||
import com.taobao.api.TaobaoClient;
|
||||
import com.taobao.api.domain.Refund;
|
||||
import com.taobao.api.request.RefundGetRequest;
|
||||
import com.taobao.api.request.RefundsApplyGetRequest;
|
||||
import com.taobao.api.request.RefundsReceiveGetRequest;
|
||||
import com.taobao.api.response.RefundGetResponse;
|
||||
import com.taobao.api.response.RefundsReceiveGetResponse;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneOffset;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
public class RefundApiHelper {
|
||||
private static Logger log = LoggerFactory.getLogger(RefundApiHelper.class);
|
||||
|
||||
private static final String REFUND_FIELDS = "refund_id, tid, title, buyer_nick, seller_nick, total_fee, status, created,num, refund_fee, oid, good_status," +
|
||||
" company_name, sid, payment, reason, desc, has_good_return, modified, order_status,refund_phase,sku";
|
||||
/**
|
||||
|
|
@ -29,23 +42,15 @@ public class RefundApiHelper {
|
|||
public static ApiResult<TaoRefund> pullRefund(Long pageNo, Long pageSize, String url, String appKey, String appSecret, String sessionKey) throws ApiException {
|
||||
TaobaoClient client = new DefaultTaobaoClient(url, appKey, appSecret);
|
||||
List<TaoRefund> list = new ArrayList<>();
|
||||
|
||||
// TaobaoClient client = new DefaultTaobaoClient(url, appkey, secret);
|
||||
// RefundGetRequest req1 = new RefundGetRequest();
|
||||
// req1.setFields("title,address,good_return_time,created");
|
||||
// req1.setRefundId(44929186648087305L);
|
||||
// RefundGetResponse rsp1 = client.execute(req1, sessionKey);
|
||||
// System.out.println(rsp1.getBody());
|
||||
// RefundsApplyGetRequest raReq = new RefundsApplyGetRequest();
|
||||
// raReq.setFields("refund_id, tid, title, buyer_nick, seller_nick, total_fee, status, created, refund_fee");
|
||||
// raReq.setPageNo(1L);
|
||||
// raReq.setPageSize(10L);
|
||||
////// raReq.setStatus("SUCCESS");
|
||||
////
|
||||
// RefundsApplyGetResponse raRsp = client.execute(raReq,sessionKey);
|
||||
// 取当前时间30分钟前
|
||||
LocalDateTime endTime = LocalDateTime.now();
|
||||
LocalDateTime startTime = endTime.minus(60 * 24, ChronoUnit.MINUTES);
|
||||
|
||||
RefundsReceiveGetRequest req = new RefundsReceiveGetRequest();
|
||||
req.setFields(REFUND_FIELDS);
|
||||
req.setStartModified(Date.from(startTime.toInstant(ZoneOffset.UTC)));
|
||||
req.setEndModified(Date.from(endTime.toInstant(ZoneOffset.UTC)));
|
||||
req.setUseHasNext(true);
|
||||
// req.setStatus("WAIT_SELLER_AGREE");
|
||||
// req.setSellerNick("hz0799");
|
||||
// req.setBuyerNick("juan20108810");
|
||||
|
|
@ -54,35 +59,93 @@ public class RefundApiHelper {
|
|||
req.setPageNo(pageNo);
|
||||
req.setPageSize(pageSize);
|
||||
RefundsReceiveGetResponse rsp = client.execute(req, sessionKey);
|
||||
if (rsp.getTotalResults() > 0) {
|
||||
//查到了数据
|
||||
if (rsp.getRefunds() == null) {
|
||||
if (!org.springframework.util.StringUtils.isEmpty(rsp.getErrorCode())) {
|
||||
//接口查询错误
|
||||
return new ApiResult(500, "接口调用错误:" + rsp.getMsg() + rsp.getSubMsg());
|
||||
}
|
||||
log.info("========增量拉取退款:无退款,{}==========", LocalDateTime.now());
|
||||
return new ApiResult(0, new ArrayList());
|
||||
}
|
||||
|
||||
//查到了数据
|
||||
for (var item : rsp.getRefunds()) {
|
||||
TaoRefund refund = assembleRefund(item);
|
||||
Refund detail = pullRefundDetail(client,sessionKey,Long.parseLong(item.getRefundId()));
|
||||
if(detail!=null) {
|
||||
refund.setDisputeType(detail.getDisputeType());
|
||||
refund.setNumIid(detail.getNumIid());
|
||||
refund.setNum(detail.getNum());
|
||||
}
|
||||
//循环插入退货数据
|
||||
list.add(refund);
|
||||
}
|
||||
|
||||
// 有分页,继续拉取
|
||||
while (rsp.getHasNext()) {
|
||||
pageNo++;
|
||||
req.setPageNo(pageNo);
|
||||
rsp = client.execute(req, sessionKey);
|
||||
//有数据
|
||||
for (var item : rsp.getRefunds()) {
|
||||
TaoRefund refund = assembleRefund(item);
|
||||
Refund detail = pullRefundDetail(client,sessionKey,Long.parseLong(item.getRefundId()));
|
||||
if(detail!=null) {
|
||||
refund.setDisputeType(detail.getDisputeType());
|
||||
refund.setNumIid(detail.getNumIid());
|
||||
refund.setNum(detail.getNum());
|
||||
}
|
||||
//循环插入退货数据
|
||||
TaoRefund refund = new TaoRefund();
|
||||
refund.setRefundId(item.getRefundId());
|
||||
refund.setTid(item.getTid());
|
||||
refund.setOid(item.getOid());
|
||||
refund.setSellerNick(item.getSellerNick());
|
||||
refund.setTotalFee(Double.parseDouble(item.getTotalFee()));
|
||||
refund.setRefundFee(Double.parseDouble(item.getRefundFee()));
|
||||
refund.setCreated(item.getCreated());
|
||||
refund.setStatus(item.getStatus());
|
||||
refund.setTitle(item.getTitle());
|
||||
refund.setDesc(item.getDesc());
|
||||
refund.setBuyerNick(item.getBuyerNick());
|
||||
refund.setBuyerOpenUid(item.getBuyerOpenUid());
|
||||
refund.setGoodStatus(item.getGoodStatus());
|
||||
refund.setHasGoodReturn(item.getHasGoodReturn() == true ? 1 : 0);
|
||||
// refund.setLogisticsCode(item.getSid());
|
||||
// refund.setLogisticsCompany(item.getCompanyName());
|
||||
refund.setModified(item.getModified());
|
||||
refund.setReason(item.getReason());
|
||||
refund.setNum(item.getNum());
|
||||
refund.setRefundPhase(item.getRefundPhase());
|
||||
list.add(refund);
|
||||
}
|
||||
}
|
||||
return new ApiResult(rsp.getTotalResults().intValue(), list);
|
||||
return new ApiResult(list.size(), list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取退款详情
|
||||
* @param client
|
||||
* @param sessionKey
|
||||
* @param refundId
|
||||
* @return
|
||||
*/
|
||||
public static Refund pullRefundDetail(TaobaoClient client,String sessionKey,Long refundId){
|
||||
try {
|
||||
RefundGetRequest req1 = new RefundGetRequest();
|
||||
req1.setFields("refund_id, alipay_no, tid, oid, buyer_nick, seller_nick, total_fee, status, created, refund_fee, good_status, has_good_return, payment, reason, desc, num_iid, title, price, num, good_return_time, company_name, sid, address, shipping_type, refund_remind_timeout, refund_phase, refund_version, operation_contraint, attribute, outer_id,dispute_type,sku,end_time,combine_item_info");
|
||||
req1.setRefundId(refundId);
|
||||
RefundGetResponse rsp1 = client.execute(req1, sessionKey);
|
||||
return rsp1.getRefund();
|
||||
}catch (ApiException e){
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static TaoRefund assembleRefund(Refund item){
|
||||
TaoRefund refund = new TaoRefund();
|
||||
refund.setRefundId(item.getRefundId());
|
||||
refund.setTid(item.getTid());
|
||||
refund.setOid(item.getOid());
|
||||
refund.setSellerNick(item.getSellerNick());
|
||||
refund.setPayment(StringUtils.isEmpty(item.getPayment()) ?0.0:Double.parseDouble(item.getPayment()));
|
||||
refund.setTotalFee(Double.parseDouble(item.getTotalFee()));
|
||||
refund.setRefundFee(Double.parseDouble(item.getRefundFee()));
|
||||
refund.setCreated(item.getCreated());
|
||||
refund.setStatus(item.getStatus());
|
||||
refund.setTitle(item.getTitle());
|
||||
refund.setDesc1(item.getDesc());
|
||||
refund.setBuyerNick(item.getBuyerNick());
|
||||
refund.setBuyerOpenUid(item.getBuyerOpenUid());
|
||||
refund.setGoodStatus(item.getGoodStatus());
|
||||
refund.setHasGoodReturn(item.getHasGoodReturn() == true ? 1 : 0);
|
||||
refund.setOrderStatus(item.getOrderStatus());
|
||||
refund.setModified(item.getModified());
|
||||
refund.setReason(item.getReason());
|
||||
refund.setNum(item.getNum());
|
||||
refund.setRefundPhase(item.getRefundPhase());
|
||||
refund.setSid(item.getSid());
|
||||
refund.setSku(item.getSku());
|
||||
return refund;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package com.qihang.tao.controller;
|
|||
|
||||
import com.qihang.common.common.EnumResultVo;
|
||||
import com.qihang.common.enums.HttpStatus;
|
||||
import com.qihang.tao.api.ApiCommon;
|
||||
import com.qihang.tao.api.ApiResult;
|
||||
import com.qihang.tao.api.OrderApiHelper;
|
||||
import com.qihang.tao.common.EnumShopType;
|
||||
|
|
@ -29,91 +30,23 @@ public class OrderApiController {
|
|||
private static Logger log = LoggerFactory.getLogger(OrderApiController.class);
|
||||
|
||||
private final TaoOrderService orderService;
|
||||
private final SysShopService shopService;
|
||||
private final SysPlatformService platformService;
|
||||
private final ServerConfig serverConfig;
|
||||
private final ApiCommon apiCommon;
|
||||
|
||||
|
||||
/**
|
||||
* 更新前的检查
|
||||
*
|
||||
* @param shopId
|
||||
* 增量更新订单
|
||||
* @param req
|
||||
* @return
|
||||
* @throws ApiException
|
||||
*/
|
||||
public com.qihang.tao.common.ApiResult<ShopApiParams> checkBefore(Integer shopId) throws ApiException {
|
||||
log.info("/**************主动更新tao 参数检查****************/");
|
||||
var shop = shopService.selectShopById(shopId);
|
||||
|
||||
if (shop == null) {
|
||||
// return new ApiResult<>(EnumResultVo.ParamsError.getIndex(), "参数错误,没有找到店铺");
|
||||
return com.qihang.tao.common.ApiResult.build(HttpStatus.PARAMS_ERROR,"参数错误,没有找到店铺");
|
||||
}
|
||||
|
||||
if (shop.getType() != EnumShopType.TAO.getIndex()) {
|
||||
return com.qihang.tao.common.ApiResult.build(HttpStatus.PARAMS_ERROR, "参数错误,店铺不是淘系店铺");
|
||||
}
|
||||
SysPlatform platform = platformService.selectById(EnumShopType.TAO.getIndex());
|
||||
|
||||
if(!StringUtils.hasText(platform.getAppKey())) {
|
||||
return com.qihang.tao.common.ApiResult.build(HttpStatus.PARAMS_ERROR, "平台配置错误,没有找到AppKey");
|
||||
}
|
||||
if(!StringUtils.hasText(platform.getAppSecret())) {
|
||||
return com.qihang.tao.common.ApiResult.build(HttpStatus.PARAMS_ERROR, "第三方平台配置错误,没有找到AppSercet");
|
||||
}
|
||||
if(!StringUtils.hasText(shop.getApiRequestUrl())) {
|
||||
return com.qihang.tao.common.ApiResult.build(HttpStatus.PARAMS_ERROR, "第三方平台配置错误,没有找到ApiRequestUrl");
|
||||
}
|
||||
if(shop.getSellerId() == null || shop.getSellerId() <= 0) {
|
||||
return com.qihang.tao.common.ApiResult.build(HttpStatus.PARAMS_ERROR, "第三方平台配置错误,没有找到SellerUserId");
|
||||
}
|
||||
|
||||
ShopApiParams params = new ShopApiParams();
|
||||
params.setAppKey(platform.getAppKey());
|
||||
params.setAppSecret(platform.getAppSecret());
|
||||
params.setAccessToken(shop.getAccessToken());
|
||||
params.setTokenRequestUrl(serverConfig.getUrl()+"/taoapi2/tao_oauth");
|
||||
params.setApiRequestUrl(shop.getApiRequestUrl());
|
||||
|
||||
if (!StringUtils.hasText(shop.getAccessToken())) {
|
||||
|
||||
return com.qihang.tao.common.ApiResult.build(HttpStatus.UNAUTHORIZED, "Token已过期,请重新授权", params);
|
||||
}
|
||||
|
||||
/****************先查询卖家对不对***************/
|
||||
// TaobaoClient client = new DefaultTaobaoClient(url, appkey, secret);
|
||||
// UserSellerGetRequest reqSeller = new UserSellerGetRequest();
|
||||
// reqSeller.setFields("nick,user_id");
|
||||
// UserSellerGetResponse rsp = client.execute(reqSeller, sessionKey);
|
||||
// if(StringUtils.hasText(rsp.getErrorCode())){
|
||||
// if(rsp.getErrorCode().equals("27")){
|
||||
// return new ApiResult<>(EnumResultVo.TokenFail.getIndex(), "Token已过期,请重新授权",params);
|
||||
// }
|
||||
// else if(rsp.getErrorCode().equals("11")){
|
||||
// if(rsp.getSubCode().equals("isv.permission-api-package-limit"))
|
||||
// return new ApiResult<>(EnumResultVo.ParamsError.getIndex(), "请检查淘宝用户API:taobao.user.seller.get是否具有访问权限",params);
|
||||
// return new ApiResult<>(EnumResultVo.ParamsError.getIndex(), rsp.getSubCode(),params);
|
||||
// }
|
||||
// else if(rsp.getErrorCode().equals("25")){
|
||||
// return new ApiResult<>(EnumResultVo.ParamsError.getIndex(), "无效签名!请检查SessionKey、appKey、appSecret是否匹配",params);
|
||||
// } else
|
||||
// return new ApiResult<>(EnumResultVo.ParamsError.getIndex(), "参数错误!"+(StringUtils.hasText(rsp.getSubMsg()) ? rsp.getSubMsg(): rsp.getMsg()));
|
||||
// }
|
||||
// if(rsp.getUser() == null || rsp.getUser().getUserId() == null){
|
||||
// return new ApiResult<>(EnumResultVo.ParamsError.getIndex(), "参数错误!请设置店铺SellerUserId值!",params);
|
||||
// }
|
||||
// else if (shop.getSellerUserId().longValue() != rsp.getUser().getUserId().longValue()) {
|
||||
// return new ApiResult<>(EnumResultVo.TokenFail.getIndex(), "当前用户是:" + rsp.getUser().getNick() + ",请重新授权",params);
|
||||
// }
|
||||
return com.qihang.tao.common.ApiResult.build(HttpStatus.SUCCESS,"",params);
|
||||
}
|
||||
|
||||
@GetMapping("/pull_order_tao")
|
||||
@ResponseBody
|
||||
public com.qihang.tao.common.ApiResult<Object> pullIncrementOrder(TaoRequest req) throws ApiException {
|
||||
log.info("/**************主动更新tao订单****************/");
|
||||
log.info("/**************增量拉取tao订单****************/");
|
||||
if (req.getShopId() == null || req.getShopId() <= 0) {
|
||||
return com.qihang.tao.common.ApiResult.build(HttpStatus.PARAMS_ERROR, "参数错误,没有店铺Id");
|
||||
}
|
||||
var checkResult = this.checkBefore(req.getShopId());
|
||||
var checkResult = apiCommon.checkBefore(req.getShopId());
|
||||
if (checkResult.getCode() != HttpStatus.SUCCESS) {
|
||||
return com.qihang.tao.common.ApiResult.build(checkResult.getCode(), checkResult.getMsg(),checkResult.getData());
|
||||
}
|
||||
|
|
@ -178,7 +111,7 @@ public class OrderApiController {
|
|||
if (req.getShopId() == null || req.getShopId() <= 0) {
|
||||
return com.qihang.tao.common.ApiResult.build(HttpStatus.PARAMS_ERROR, "参数错误,没有店铺Id");
|
||||
}
|
||||
var checkResult = this.checkBefore(req.getShopId());
|
||||
var checkResult = apiCommon.checkBefore(req.getShopId());
|
||||
if (checkResult.getCode() != HttpStatus.SUCCESS) {
|
||||
return com.qihang.tao.common.ApiResult.build(checkResult.getCode(), checkResult.getMsg(),checkResult.getData());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,127 +1,112 @@
|
|||
package com.qihang.tao.controller;
|
||||
|
||||
import com.qihang.common.common.EnumResultVo;
|
||||
import com.qihang.common.enums.HttpStatus;
|
||||
import com.qihang.tao.api.ApiCommon;
|
||||
import com.qihang.tao.api.ApiResult;
|
||||
import com.qihang.tao.api.RefundApiHelper;
|
||||
import com.qihang.tao.common.TaoRequest;
|
||||
import com.qihang.tao.domain.TaoRefund;
|
||||
import com.qihang.tao.service.TaoRefundService;
|
||||
import com.taobao.api.ApiException;
|
||||
import com.taobao.api.DefaultTaobaoClient;
|
||||
import com.taobao.api.TaobaoClient;
|
||||
import com.taobao.api.request.RefundGetRequest;
|
||||
import com.taobao.api.response.RefundGetResponse;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
@AllArgsConstructor
|
||||
@RestController
|
||||
@RequestMapping("/refund")
|
||||
public class RefundApiController {
|
||||
private static Logger log = LoggerFactory.getLogger(RefundApiController.class);
|
||||
private final ApiCommon apiCommon;
|
||||
private final TaoRefundService refundService;
|
||||
/**
|
||||
* 更新退货订单
|
||||
*
|
||||
* @return
|
||||
* @throws ApiException
|
||||
*/
|
||||
@RequestMapping("/pull_refund")
|
||||
@ResponseBody
|
||||
public ApiResult<String> refundOrderPull(@RequestBody TaoRequest taoRequest) throws ApiException {
|
||||
log.info("/**************主动更新tao退货订单****************/");
|
||||
if (taoRequest.getShopId() == null || taoRequest.getShopId() <= 0) {
|
||||
return new ApiResult<>(EnumResultVo.ParamsError.getIndex(), "参数错误,没有店铺Id");
|
||||
}
|
||||
Integer shopId = taoRequest.getShopId();
|
||||
var checkResult = apiCommon.checkBefore(shopId);
|
||||
|
||||
if (checkResult.getCode() != HttpStatus.SUCCESS) {
|
||||
return new ApiResult<>(checkResult.getCode(), checkResult.getMsg());
|
||||
}
|
||||
|
||||
String sessionKey = checkResult.getData().getAccessToken();
|
||||
String url = checkResult.getData().getApiRequestUrl();
|
||||
String appKey = checkResult.getData().getAppKey();
|
||||
String appSecret = checkResult.getData().getAppSecret();
|
||||
|
||||
|
||||
Long pageSize = 50l;
|
||||
Long pageIndex = 1l;
|
||||
|
||||
//第一次获取
|
||||
ApiResult<TaoRefund> upResult = RefundApiHelper.pullRefund(pageIndex, pageSize, url, appKey, appSecret, sessionKey);
|
||||
|
||||
if (upResult.getCode().intValue() != 0) {
|
||||
log.info("/**************主动更新tao退货订单:第一次获取结果失败:" + upResult.getMsg() + "****************/");
|
||||
return new ApiResult<>(EnumResultVo.SystemException.getIndex(), upResult.getMsg());
|
||||
}
|
||||
|
||||
log.info("/**************主动更新tao退货订单:第一次获取结果:总记录数" + upResult.getTotalRecords() + "****************/");
|
||||
int insertSuccess = 0;//新增成功的订单
|
||||
int totalError = 0;
|
||||
int hasExistOrder = 0;//已存在的订单数
|
||||
|
||||
//循环插入订单数据到数据库
|
||||
for (var refund : upResult.getList()) {
|
||||
|
||||
//插入订单数据
|
||||
var result = refundService.saveAndUpdateRefund(shopId, refund);
|
||||
if (result == EnumResultVo.DataExist.getIndex()) {
|
||||
//已经存在
|
||||
log.info("/**************主动更新tao退货订单:开始更新数据库:" + refund.getRefundId() + "存在、更新****************/");
|
||||
hasExistOrder++;
|
||||
} else if (result == EnumResultVo.SUCCESS.getIndex()) {
|
||||
log.info("/**************主动更新tao退货订单:开始插入数据库:" + refund.getRefundId() + "不存在、新增****************/");
|
||||
insertSuccess++;
|
||||
} else {
|
||||
log.info("/**************主动更新tao退货订单:开始更新数据库:" + refund.getRefundId() + "报错****************/");
|
||||
totalError++;
|
||||
}
|
||||
}
|
||||
|
||||
String msg = "成功,总共找到:" + upResult.getTotalRecords() + "条订单,新增:" + insertSuccess + "条,添加错误:" + totalError + "条,更新:" + hasExistOrder + "条";
|
||||
log.info("/**************主动更新tao订单:END:" + msg + "****************/");
|
||||
return new ApiResult<>(EnumResultVo.SUCCESS.getIndex(), msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新单条退货单
|
||||
*
|
||||
* @param taoRequest
|
||||
* @param model
|
||||
* @param request
|
||||
* @return
|
||||
* @throws ApiException
|
||||
*/
|
||||
// @RequestMapping("/refund/pull_refund_order")
|
||||
// @ResponseBody
|
||||
// public com.qihang.tao.common.ApiResult<String> refundOrderPull(@RequestBody TaoRequest taoRequest) throws ApiException {
|
||||
// log.info("/**************主动更新tao退货订单****************/");
|
||||
// if (taoRequest.getShopId() == null || taoRequest.getShopId() <= 0) {
|
||||
// return new com.qihang.tao.common.ApiResult<>(EnumResultVo.ParamsError.getIndex(), "参数错误,没有店铺Id");
|
||||
// }
|
||||
// Integer shopId = taoRequest.getShopId();
|
||||
// var checkResult = this.checkBefore(shopId);
|
||||
//
|
||||
// if (checkResult.getCode() != EnumResultVo.SUCCESS.getIndex()) {
|
||||
// return new com.qihang.tao.common.ApiResult<>(checkResult.getCode(), checkResult.getMsg());
|
||||
// }
|
||||
//
|
||||
// String sessionKey = checkResult.getData().getAccessToken();
|
||||
// String url = checkResult.getData().getApiRequestUrl();
|
||||
// String appKey = checkResult.getData().getAppKey();
|
||||
// String appSecret = checkResult.getData().getAppSecret();
|
||||
//
|
||||
//
|
||||
// Long pageSize = 50l;
|
||||
// Long pageIndex = 1l;
|
||||
//
|
||||
// //第一次获取
|
||||
// ApiResult<TaoRefund> upResult = RefundApiHelper.pullRefund(pageIndex, pageSize, url, appKey, appSecret, sessionKey);
|
||||
//
|
||||
// if (upResult.getCode().intValue() != 0) {
|
||||
// log.info("/**************主动更新tao退货订单:第一次获取结果失败:" + upResult.getMsg() + "****************/");
|
||||
// return new com.qihang.tao.common.ApiResult<>(EnumResultVo.SystemException.getIndex(), upResult.getMsg());
|
||||
// }
|
||||
//
|
||||
// log.info("/**************主动更新tao退货订单:第一次获取结果:总记录数" + upResult.getTotalRecords() + "****************/");
|
||||
// int insertSuccess = 0;//新增成功的订单
|
||||
// int totalError = 0;
|
||||
// int hasExistOrder = 0;//已存在的订单数
|
||||
//
|
||||
// //循环插入订单数据到数据库
|
||||
// for (var order : upResult.getList()) {
|
||||
//
|
||||
// //插入订单数据
|
||||
// var result = tmallOrderReturnService.updOrderRefund(shopId, order);
|
||||
// if (result == EnumResultVo.DataExist.getIndex()) {
|
||||
// //已经存在
|
||||
// log.info("/**************主动更新tao退货订单:开始更新数据库:" + order.getRefundId() + "存在、更新****************/");
|
||||
// hasExistOrder++;
|
||||
// } else if (result == EnumResultVo.SUCCESS.getIndex()) {
|
||||
// log.info("/**************主动更新tao退货订单:开始更新数据库:" + order.getRefundId() + "不存在、新增****************/");
|
||||
// insertSuccess++;
|
||||
// } else {
|
||||
// log.info("/**************主动更新tao退货订单:开始更新数据库:" + order.getRefundId() + "报错****************/");
|
||||
// totalError++;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
//
|
||||
// //计算总页数
|
||||
// int totalPage = (upResult.getTotalRecords() % pageSize == 0) ? upResult.getTotalRecords() / pageSize.intValue() : (upResult.getTotalRecords() / pageSize.intValue()) + 1;
|
||||
// pageIndex++;
|
||||
//
|
||||
// while (pageIndex <= totalPage) {
|
||||
// ApiResult<TaoOrderRefund> upResult1 = RefundApiHelper.pullRefund(pageIndex, pageSize, url, appKey, appSecret, sessionKey);
|
||||
// //循环插入订单数据到数据库
|
||||
// for (var order : upResult1.getList()) {
|
||||
//
|
||||
// //插入订单数据
|
||||
// var result1 = tmallOrderReturnService.updOrderRefund(shopId, order);
|
||||
// if (result1 == EnumResultVo.DataExist.getIndex()) {
|
||||
// //已经存在
|
||||
// log.info("/**************主动更新tao退货订单:开始更新数据库:" + order.getRefundId() + "存在、更新****************/");
|
||||
// hasExistOrder++;
|
||||
// } else if (result1 == EnumResultVo.SUCCESS.getIndex()) {
|
||||
// log.info("/**************主动更新tao退货订单:开始更新数据库:" + order.getRefundId() + "不存在、新增****************/");
|
||||
// insertSuccess++;
|
||||
// } else {
|
||||
// log.info("/**************主动更新tao退货订单:开始更新数据库:" + order.getRefundId() + "报错****************/");
|
||||
// totalError++;
|
||||
// }
|
||||
// }
|
||||
// pageIndex++;
|
||||
// }
|
||||
//
|
||||
// String msg = "成功,总共找到:" + upResult.getTotalRecords() + "条订单,新增:" + insertSuccess + "条,添加错误:" + totalError + "条,更新:" + hasExistOrder + "条";
|
||||
// log.info("/**************主动更新tao订单:END:" + msg + "****************/");
|
||||
// return new com.qihang.tao.common.ApiResult<>(EnumResultVo.SUCCESS.getIndex(), msg);
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 更新单条退货单
|
||||
// *
|
||||
// * @param taoRequest
|
||||
// * @param model
|
||||
// * @param request
|
||||
// * @return
|
||||
// * @throws ApiException
|
||||
// */
|
||||
// @RequestMapping("/refund/pull_refund_order_by_num")
|
||||
// @ResponseBody
|
||||
// public com.qihang.tao.common.ApiResult<String> refundOrderPullByNum(@RequestBody TaoRequest taoRequest, Model model, HttpServletRequest request) throws ApiException {
|
||||
|
|
|
|||
|
|
@ -161,7 +161,7 @@ public class TaoRefund implements Serializable {
|
|||
/**
|
||||
* 退款说明
|
||||
*/
|
||||
private String desc;
|
||||
private String desc1;
|
||||
|
||||
/**
|
||||
* 物流公司
|
||||
|
|
@ -659,15 +659,15 @@ outer_sku_id String 123 123
|
|||
/**
|
||||
* 退款说明
|
||||
*/
|
||||
public String getDesc() {
|
||||
return desc;
|
||||
public String getDesc1() {
|
||||
return desc1;
|
||||
}
|
||||
|
||||
/**
|
||||
* 退款说明
|
||||
*/
|
||||
public void setDesc(String desc) {
|
||||
this.desc = desc;
|
||||
public void setDesc1(String desc) {
|
||||
this.desc1 = desc;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -906,7 +906,7 @@ outer_sku_id String 123 123
|
|||
&& (this.getReason() == null ? other.getReason() == null : this.getReason().equals(other.getReason()))
|
||||
&& (this.getRefundPhase() == null ? other.getRefundPhase() == null : this.getRefundPhase().equals(other.getRefundPhase()))
|
||||
&& (this.getShippingType() == null ? other.getShippingType() == null : this.getShippingType().equals(other.getShippingType()))
|
||||
&& (this.getDesc() == null ? other.getDesc() == null : this.getDesc().equals(other.getDesc()))
|
||||
&& (this.getDesc1() == null ? other.getDesc1() == null : this.getDesc1().equals(other.getDesc1()))
|
||||
&& (this.getCompanyName() == null ? other.getCompanyName() == null : this.getCompanyName().equals(other.getCompanyName()))
|
||||
&& (this.getSid() == null ? other.getSid() == null : this.getSid().equals(other.getSid()))
|
||||
&& (this.getSendTime() == null ? other.getSendTime() == null : this.getSendTime().equals(other.getSendTime()))
|
||||
|
|
@ -956,7 +956,7 @@ outer_sku_id String 123 123
|
|||
result = prime * result + ((getReason() == null) ? 0 : getReason().hashCode());
|
||||
result = prime * result + ((getRefundPhase() == null) ? 0 : getRefundPhase().hashCode());
|
||||
result = prime * result + ((getShippingType() == null) ? 0 : getShippingType().hashCode());
|
||||
result = prime * result + ((getDesc() == null) ? 0 : getDesc().hashCode());
|
||||
result = prime * result + ((getDesc1() == null) ? 0 : getDesc1().hashCode());
|
||||
result = prime * result + ((getCompanyName() == null) ? 0 : getCompanyName().hashCode());
|
||||
result = prime * result + ((getSid() == null) ? 0 : getSid().hashCode());
|
||||
result = prime * result + ((getSendTime() == null) ? 0 : getSendTime().hashCode());
|
||||
|
|
@ -1009,7 +1009,7 @@ outer_sku_id String 123 123
|
|||
sb.append(", reason=").append(reason);
|
||||
sb.append(", refundPhase=").append(refundPhase);
|
||||
sb.append(", shippingType=").append(shippingType);
|
||||
sb.append(", desc=").append(desc);
|
||||
sb.append(", desc1=").append(desc1);
|
||||
sb.append(", companyName=").append(companyName);
|
||||
sb.append(", sid=").append(sid);
|
||||
sb.append(", sendTime=").append(sendTime);
|
||||
|
|
|
|||
|
|
@ -9,5 +9,5 @@ import com.baomidou.mybatisplus.extension.service.IService;
|
|||
* @createDate 2024-02-29 19:01:45
|
||||
*/
|
||||
public interface TaoRefundService extends IService<TaoRefund> {
|
||||
|
||||
int saveAndUpdateRefund(Integer shopId,TaoRefund refund);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,8 +32,6 @@ public class TaoOrderServiceImpl extends ServiceImpl<TaoOrderMapper, TaoOrder>
|
|||
@Override
|
||||
public ResultVo<Integer> saveOrder(Integer shopId, TaoOrder order) {
|
||||
try {
|
||||
|
||||
|
||||
List<TaoOrder> taoOrders = mapper.selectList(new LambdaQueryWrapper<TaoOrder>().eq(TaoOrder::getTid, order.getTid()));
|
||||
if (taoOrders != null && taoOrders.size() > 0) {
|
||||
// 存在,修改
|
||||
|
|
@ -74,6 +72,7 @@ public class TaoOrderServiceImpl extends ServiceImpl<TaoOrderMapper, TaoOrder>
|
|||
return new ResultVo<>(EnumResultVo.DataExist, "订单已经存在,更新成功");
|
||||
} else {
|
||||
// 不存在,新增
|
||||
order.setShopId(shopId);
|
||||
order.setCreateTime(new Date());
|
||||
mapper.insert(order);
|
||||
// 添加item
|
||||
|
|
|
|||
|
|
@ -1,20 +1,50 @@
|
|||
package com.qihang.tao.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.qihang.common.common.EnumResultVo;
|
||||
import com.qihang.tao.domain.TaoRefund;
|
||||
import com.qihang.tao.service.TaoRefundService;
|
||||
import com.qihang.tao.mapper.TaoRefundMapper;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.crypto.Mac;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author TW
|
||||
* @description 针对表【tao_refund(淘宝退款订单表)】的数据库操作Service实现
|
||||
* @createDate 2024-02-29 19:01:45
|
||||
*/
|
||||
@AllArgsConstructor
|
||||
@Service
|
||||
public class TaoRefundServiceImpl extends ServiceImpl<TaoRefundMapper, TaoRefund>
|
||||
implements TaoRefundService{
|
||||
|
||||
private final TaoRefundMapper mapper;
|
||||
@Override
|
||||
public int saveAndUpdateRefund(Integer shopId, TaoRefund refund) {
|
||||
List<TaoRefund> taoRefunds = mapper.selectList(new LambdaQueryWrapper<TaoRefund>().eq(TaoRefund::getRefundId, refund.getRefundId()));
|
||||
if(taoRefunds!=null && taoRefunds.size()>0){
|
||||
// 存在,修改
|
||||
TaoRefund update = new TaoRefund();
|
||||
update.setId(taoRefunds.get(0).getId());
|
||||
update.setModified(refund.getModified());
|
||||
update.setStatus(refund.getStatus());
|
||||
update.setEndTime(refund.getEndTime());
|
||||
update.setUpdateTime(new Date());
|
||||
mapper.updateById(update);
|
||||
return EnumResultVo.DataExist.getIndex();
|
||||
}else{
|
||||
refund.setShopId(shopId);
|
||||
refund.setCreateTime(new Date());
|
||||
mapper.insert(refund);
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@
|
|||
<result property="reason" column="reason" jdbcType="VARCHAR"/>
|
||||
<result property="refundPhase" column="refund_phase" jdbcType="VARCHAR"/>
|
||||
<result property="shippingType" column="shipping_type" jdbcType="VARCHAR"/>
|
||||
<result property="desc" column="desc" jdbcType="VARCHAR"/>
|
||||
<result property="desc1" column="desc1" jdbcType="VARCHAR"/>
|
||||
<result property="companyName" column="company_name" jdbcType="VARCHAR"/>
|
||||
<result property="sid" column="sid" jdbcType="VARCHAR"/>
|
||||
<result property="sendTime" column="send_time" jdbcType="VARCHAR"/>
|
||||
|
|
@ -62,7 +62,7 @@
|
|||
good_return_time,good_status,has_good_return,
|
||||
num_iid,num,outer_id,
|
||||
reason,refund_phase,shipping_type,
|
||||
desc,company_name,sid,
|
||||
desc1,company_name,sid,
|
||||
send_time,end_time,title,
|
||||
sku,buyer_open_uid,buyer_nick,
|
||||
combine_item_info,create_time,create_by,
|
||||
|
|
|
|||
Loading…
Reference in New Issue