WS
2023-05-09 96836ce842d05686c04e82373553310cdb0f8eda
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
146
147
148
149
150
151
152
153
154
155
package com.fzzy.push.shjdjw2023;
 
import com.alibaba.fastjson.JSON;
import com.fzzy.api.Constant;
import com.fzzy.api.data.ApiParam;
import com.fzzy.api.data.PushProtocol;
import com.fzzy.api.dto.ResponseDto;
import com.fzzy.api.entity.ApiConfs;
import com.fzzy.api.entity.ApiLog;
import com.fzzy.api.service.ApiCommonService;
import com.fzzy.api.service.ApiRemoteService;
import com.fzzy.api.utils.ContextUtil;
import com.fzzy.api.utils.RedisUtil;
import com.fzzy.api.view.repository.ApiLogRep;
import com.fzzy.push.gd2022.dto.*;
import com.fzzy.push.shjdjw2023.dto.ShjdjwReqDto;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import java.util.*;
 
/**
 * 上海嘉定纪委监管平台-上传数据服务类
 *
 * @author czt
 * @date 2023/5/9  14:09
 */
@Slf4j
@Data
@Service
public class ShjdjwApiRemoteService2023 implements ApiRemoteService {
 
    @Autowired
    private RedisUtil redisUtil;
 
    @Autowired
    private ApiCommonService apiCommonService;
 
    @Autowired
    private ApiLogRep apiLogRep;
 
 
    @Override
    public String getProtocol() {
        return PushProtocol.SB_SHJdJW_2023.getCode();
    }
 
    @Override
    public ResponseDto pushData(ApiParam param, Object data) {
        return pushData(param, null, data);
    }
 
    @Override
    public ResponseDto pushData(ApiParam param, ApiConfs conf, Object data) {
        String inteId = param.getInteId();
        String kqdm = param.getKqdm();
        String bizId = param.getBizId();
 
        try {
            if (null == conf) {
                conf = apiCommonService.getConf(kqdm);
            }
            //添加日志
            ApiLog apiLog = new ApiLog();
            apiLog.setId(ContextUtil.getUUID());
            apiLog.setInteId(param.getInteId());
 
            //获取接口编码
            String interfaceId = getDataId(inteId);
 
            //获取json数据
            String jsonData = getJsonData(inteId, data, interfaceId);
 
            if (StringUtils.isEmpty(interfaceId)) {
                ResponseDto responseDto = new ResponseDto(99, "没有获取到接口", bizId);
                apiLog.setStatus(99);
                apiLog.setResult("没有获取到接口");
                apiLogRep.save(apiLog);
                return responseDto;
            }
            apiLog.setData(jsonData);
            apiLog.setKqdm(kqdm);
            apiLog.setUploadTime(new Date());
 
            if (conf == null) {
                ResponseDto responseDto = new ResponseDto(99, "没有获取到上传配置", bizId);
                apiLog.setStatus(99);
                apiLog.setResult("没有获取到上传配置");
                apiLogRep.save(apiLog);
                return responseDto;
            }
 
            Map<String, Object> map = new HashMap<>();
            GD2022ResponseDto responseDto = Shjdjw2023HttpClientUtil.postPushData(conf.getApiUrl() + inteId, jsonData, conf);
            responseDto.setBizId(bizId);
            apiLog.setStatus(responseDto.getCode() == 200 ? 0 : responseDto.getCode());
            apiLog.setResult(responseDto.getMsg());
            apiLogRep.save(apiLog);
            ResponseDto resd = new ResponseDto();
            resd.setSuccess(responseDto.getCode() == 200 ? 0 : responseDto.getCode());
            resd.setMsg(responseDto.getMsg());
            //updateGD2022AuthToken(responseDto,conf, token);
            return resd;
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return new ResponseDto(99, e.getMessage());
        }
    }
 
    /**
     * 调整数据封装,获取json数据
     *
     * @param inteId
     * @param data
     * @return
     * @throws Exception
     */
    private String getJsonData(String inteId, Object data, String interfaceId) {
        ShjdjwReqDto<Object> dto = new ShjdjwReqDto<>();
        dto.setId(getDataId(interfaceId));
        //转换封装
        if (Constant.API_CODE_1101.equals(inteId)) {
            dto.setData(data);
        } else if (Constant.API_CODE_1202.equals(inteId)) {
 
 
            dto.setData(data);
        } else {
            dto.setData(data);
        }
 
        return JSON.toJSONString(dto);
    }
 
    /**
     * 获取接口编码
     *
     * @param inteId
     * @return
     */
    private String getDataId(String inteId) {
        switch (inteId) {
            case "1101":
                return ShjdjwApiCodeConstant.API_CODE_LS1101;
            case "1202":
                return ShjdjwApiCodeConstant.API_CODE_LS1302;
            default:
                return inteId;
        }
 
    }
}