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;
|
}
|
|
}
|
}
|