liujie
2026-06-09 c96fbe6b0aeb413a17c429133ee6d81d138144b9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package com.xiaopeng.operation.utils;
 
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson2.JSON;
import com.xiaopeng.api.dto.account.UcUserInfo;
import com.xiaopeng.api.feignClient.account.UserResourcesClient;
import com.xiaopeng.api.model.operation.XpOfficialPartner;
import com.xiaopeng.api.model.order.XpOrder;
import com.xiaopeng.api.vo.operation.OfficialPartnerResult;
import com.xiaopeng.common.core.domain.R;
import com.xiaopeng.common.core.exception.ServiceException;
import com.xiaopeng.operation.service.IXpOfficialPartnerService;
import com.xiaopeng.operation.vo.PushNewOrderVo;
import org.springframework.stereotype.Component;
 
import javax.annotation.Resource;
import java.time.format.DateTimeFormatter;
 
/**
 * 合作商工具类
 */
@Component
public class OfficialPartnerUtil {
 
    @Resource
    private IXpOfficialPartnerService xpOfficialPartnerService;
 
    @Resource
    private UserResourcesClient userResourcesClient;
 
 
 
 
    /**
     * 推送新的订单给合作商
     * @param officialPartnerId
     * @return
     */
    public R<?> pushNewOrder(Integer officialPartnerId, XpOrder xpOrder) {
        XpOfficialPartner xpOfficialPartner = xpOfficialPartnerService.getById(officialPartnerId);
        String createOrderUrl = xpOfficialPartner.getCreateOrderUrl();
        PushNewOrderVo pushNewOrderVo = buildNewOrder(xpOrder);
        HttpRequest post = HttpUtil.createPost(createOrderUrl);
        post.body(JSON.toJSONString(pushNewOrderVo));
        HttpResponse execute = post.execute();
        if(!execute.isOk()){
            throw new ServiceException("[" + xpOfficialPartner.getName() + "]调用合作商接口失败-通知新订单接口");
        }
        OfficialPartnerResult officialPartnerResult = JSON.parseObject(execute.body(), OfficialPartnerResult.class);
        if(0 == officialPartnerResult.getCode()){
            return R.ok();
        }
        throw new ServiceException("[" + xpOfficialPartner.getName() + "]" + officialPartnerResult.getMsg());
    }
 
 
    /**
     * 构建推送订单数据
     * @param xpOrder
     * @return
     */
    private PushNewOrderVo buildNewOrder(XpOrder xpOrder){
        PushNewOrderVo vo = new PushNewOrderVo();
        vo.setOrderNum(xpOrder.getOrderNumber());
        vo.setVehicleModelId(null);
        vo.setVehicleModelName("");
        vo.setPlacementLongitude(xpOrder.getPlacementLon());
        vo.setPlacementLatitude(xpOrder.getPlacementLat());
        vo.setPlacementAddress(xpOrder.getPlacementAddress());
        vo.setStartLongitude(xpOrder.getStartLon());
        vo.setStartLatitude(xpOrder.getStartLat());
        vo.setStartAddress(xpOrder.getStartAddress());
        vo.setEndLongitude(xpOrder.getEndLon());
        vo.setEndLatitude(xpOrder.getEndLat());
        vo.setEndAddress(xpOrder.getEndAddress());
        vo.setUserId(xpOrder.getAppUserId());
        UcUserInfo ucUserInfo = userResourcesClient.getBaseUserByUid(xpOrder.getAppUserId().toString());
        if(ucUserInfo != null){
            vo.setUserPhone(ucUserInfo.getMobile());
        }
        vo.setCreateTime(xpOrder.getCreateTime().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
        return vo;
 
    }
 
}