liukangdong
2024-10-10 76ac3375a039432db9e44b70350cb49e1786db1d
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
package com.doumee.service.business.impl.thrid;
 
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.doumee.biz.system.SystemDictDataBiz;
import com.doumee.core.tms.model.request.TmsLockStatusQueryRequest;
import com.doumee.core.tms.model.request.TmsOrderListRequest;
import com.doumee.core.tms.model.response.TmsBaseResponse;
import com.doumee.core.tms.model.response.TmsLockStatusQueryResponse;
import com.doumee.core.tms.model.response.TmsOrderListResponse;
import com.doumee.core.utils.Constants;
import com.doumee.core.utils.HttpsUtil;
import com.doumee.core.wms.model.request.*;
import com.doumee.core.wms.model.response.WmsBaseDataResponse;
import com.doumee.core.wms.model.response.WmsBaseResponse;
import com.doumee.core.wms.model.response.WmsInventoryDataResponse;
import com.doumee.dao.business.*;
import com.doumee.dao.business.model.*;
import com.doumee.service.business.third.TmsService;
import com.doumee.service.business.third.WmsService;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import java.util.*;
 
/**
 * TMS平台对接Service实现
 * @author 江蹄蹄
 * @date 2023/11/30 15:33
 */
@Service
@Slf4j
public class TmsServiceImpl implements TmsService {
    @Autowired
    private PlatformWmsJobMapper platformWmsJobMapper;
    @Autowired
    private PlatformGroupMapper platformGroupMapper;
    @Autowired
    private CarsMapper carsMapper;
    @Autowired
    private MemberMapper memberMapper;
    @Autowired
    private PlatformJobMapper platformJobMapper;
    @Autowired
    private PlatformWmsDetailMapper platformWmsDetailMapper;
    @Autowired
    private SystemDictDataBiz systemDictDataBiz;
    @Autowired
    private WmsInterfaceLogMapper wmsInterfaceLogMapper;
 
    /**
     * 电子锁上锁时间接口
     * 根据合同号,查询电子锁上锁情况;存在批量查询的情况;
     * @param param 参数
     * @return WmsBaseResponse
     */
    @Override
    public TmsBaseResponse<List<TmsLockStatusQueryResponse>> lockStatusQuery(TmsLockStatusQueryRequest param){
        String url = systemDictDataBiz.queryByCode(Constants.TSM_PARAM,Constants.TMS_INTERFACE_URL_PREFIX).getCode()
                +systemDictDataBiz.queryByCode(Constants.TSM_PARAM,Constants.TMS_LOCK_STATUS_URL).getCode();
 
        TmsBaseResponse<List<TmsLockStatusQueryResponse>> response = sendHttpRequest(url,"电子锁上锁时间接口",JSONObject.toJSONString(param)
                ,new TypeReference< TmsBaseResponse<List<TmsLockStatusQueryResponse>>>(){});
        return  new TmsBaseResponse<>();
    }
 
    /**
     * 合同列表接口
     * 根据区域ID集合+筛选条件(合同号、制单开始日期、制单结束日期、发货地、到货地、省份,非需要),返回合同列表信息,按照时间倒序展示;
     * @param param 参数
     * @return WmsBaseResponse
     */
    @Override
    public  TmsBaseResponse<List<TmsOrderListResponse>> orderList(TmsOrderListRequest param){
        String url = systemDictDataBiz.queryByCode(Constants.TSM_PARAM,Constants.TMS_INTERFACE_URL_PREFIX).getCode()
                    +systemDictDataBiz.queryByCode(Constants.TSM_PARAM,Constants.TMS_ORDER_LIST_URL).getCode();
        TmsBaseResponse<List<TmsOrderListResponse>> response = sendHttpRequest(url,"合同列表接口",JSONObject.toJSONString(param)
                ,new TypeReference< TmsBaseResponse<List<TmsOrderListResponse>>>(){});
        return  new TmsBaseResponse<>();
    }
 
    /**
     * 发起 tms接口请求
     * @param url
     * @param name
     * @param param
     * @param typeReference
     * @return
     * @param <T>
     */
    public  <T> TmsBaseResponse<T> sendHttpRequest(String url, String name, String param,TypeReference<TmsBaseResponse<T>> typeReference){
        log.info("【"+name+"】================开始===="+ JSONObject.toJSONString(param));
        if ( StringUtils.isNotBlank(url)) {
            String res = null;
            int success = 0;
            try {
                Map<String,String> headers = new HashMap<>();
                res = HttpsUtil.postJson(url,param);
                TmsBaseResponse result = JSONObject.parseObject(res, typeReference.getType());
                logResult(result,name);
                if(result!=null && result.getData() !=null ){
 
                }else{
                    success =1;
                }
                return  result;
            }catch (Exception e){
                success = 1;
                log.error("【"+name+"】================失败===="+ JSONObject.toJSONString(param));
            }finally {
            }
        }
        return  null;
    }
    private static void logResult(TmsBaseResponse res,String name) {
        if(StringUtils.equals(res.getCode(), TmsBaseResponse.CODE_SUCCESS)){
            log.info("【TMS接口:"+name+"】================成功====\n"+res);
        }else{
            log.error("【TMS接口:"+name+"】================失败====:\n"+ res);
        }
    }
 
}