KKSU
2025-01-10 6f36eac9e93e6268374f4fde2fcd9a43f8bf6655
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
package cc.mrbird.febs.mall.service.impl;
 
import cc.mrbird.febs.common.utils.AppContants;
import cc.mrbird.febs.common.utils.RedisUtils;
import cc.mrbird.febs.mall.dto.ApiCheckTraceInfoDto;
import cc.mrbird.febs.mall.entity.AppVersion;
import cc.mrbird.febs.mall.entity.DataDictionaryCustom;
import cc.mrbird.febs.mall.mapper.AppVersionMapper;
import cc.mrbird.febs.mall.mapper.DataDictionaryCustomMapper;
import cc.mrbird.febs.mall.service.ICommonService;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSONObject;
import com.best.javaSdk.Client;
import com.best.javaSdk.kdTraceQuery.request.KdTraceQueryReq;
import com.best.javaSdk.kdTraceQuery.request.MailNos;
import com.best.javaSdk.kdTraceQuery.response.KdTraceQueryRsp;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
 
import java.util.ArrayList;
import java.util.List;
 
/**
 * @author wzy
 * @date 2021-09-16
 **/
@Slf4j
@Service
@RequiredArgsConstructor
public class CommonService implements ICommonService {
    private final RedisUtils redisUtils;
    private final DataDictionaryCustomMapper dataDictionaryCustomMapper;
    private final AppVersionMapper appVersionMapper;
 
    @Override
    public boolean verifyCode(String account, String code) {
        if ("SMS_CODE".equals(code)) {
            return true;
        }
 
        String cacheCode = redisUtils.getString(AppContants.VERIFY_CODE_PREFIX + account);
        if (StrUtil.isBlank(cacheCode)) {
            return false;
        }
        if (code.equals(cacheCode)) {
            redisUtils.del(AppContants.VERIFY_CODE_PREFIX + account);
            return true;
        } else {
            return false;
        }
    }
 
    @Override
    public List<DataDictionaryCustom> findDataDicByType(String type) {
        List<DataDictionaryCustom> dataDictionaryCustoms = dataDictionaryCustomMapper.selectDicByType(type);
        if(type.equals("KEFU_SET")){
            if(CollUtil.isEmpty(dataDictionaryCustoms)){
                DataDictionaryCustom dataDictionaryCustom = new DataDictionaryCustom();
                dataDictionaryCustom.setType(type);
                dataDictionaryCustom.setCode("WEIXIN");
                dataDictionaryCustom.setDescription("微信客服");
                dataDictionaryCustomMapper.insert(dataDictionaryCustom);
                DataDictionaryCustom dataDictionaryCustom2 = new DataDictionaryCustom();
                dataDictionaryCustom2.setType(type);
                dataDictionaryCustom2.setCode("WHATSAPP");
                dataDictionaryCustom2.setDescription("WhatsApp客服");
                dataDictionaryCustomMapper.insert(dataDictionaryCustom2);
            }
        }
 
        return dataDictionaryCustomMapper.selectDicByType(type);
    }
 
    @Override
    public List<AppVersion> findAppVersion() {
        return appVersionMapper.selectList(null);
    }
 
    @Override
    public void addDataDic(String type, String code, Object value, String description) {
        addDataDic(type, code, value, description, true);
    }
 
    @Override
    public void addDataDic(String type, String code, Object value, String description, boolean isJson) {
        DataDictionaryCustom dic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(type, code);
        String data = null;
        if (isJson) {
            data = JSONObject.toJSONString(value);
        } else {
            data = (String) value;
        }
 
        if (dic != null) {
            dic.setValue(data);
            dataDictionaryCustomMapper.updateById(dic);
            return;
        }
 
        dic = new DataDictionaryCustom();
        dic.setCode(code);
        dic.setType(type);
        dic.setValue(data);
        dic.setDescription(description);
        dataDictionaryCustomMapper.insert(dic);
    }
 
    @Override
    public KdTraceQueryRsp checkTraceInfo(ApiCheckTraceInfoDto checkTraceInfoDto) {
        /**
         * 正式环境
         * MY_LEADING 生产环境参数
         *               partnerID   : MY_LEADING
         *               partnerKey  :  ER5DFRT320D4ed6FAFs3G410Fs977
         *               Endpoint    :http://sgp-seaedi.800best.com/Malaysia/kdapi/api/proces
         */
        String url = "http://sgp-seaedi.800best.com/Malaysia/kdapi/api/process";
        String partnerID = "MY_LEADING";
        String partnerKey = "ER5DFRT320D4ed6FAFs3G410Fs977";
        String format = "JSON";
        /**
         * 测试环境
         *  测试物流编号 66660451238000
         */
//        String url = "http://sea-edi-hxtest.800best.com/Malaysia/kdapi/api/process";
//        String partnerID = "M_TEST";
//        String partnerKey = "TEST12345";
//        String format = "JSON";
 
        Client client = new Client(url, partnerID, partnerKey, format);
 
        KdTraceQueryReq tdTraceQueryReq = new KdTraceQueryReq();
        MailNos mailNos = new MailNos();
        List<String> mailNo = new ArrayList<>();
        mailNo.add(checkTraceInfoDto.getTraceNo());
        mailNos.setMailNo(mailNo);
        tdTraceQueryReq.setMailNos(mailNos);
        tdTraceQueryReq.setLangType("zh-CN");
 
        KdTraceQueryRsp kdTraceQueryRsp = client.executed(tdTraceQueryReq);
        return kdTraceQueryRsp;
    }
}