| | |
| | | import com.fzzy.push.gd2022.dto.Gd2022Api1208; |
| | | import com.fzzy.push.gd2022.dto.Gd2022Api1307; |
| | | import com.fzzy.push.gd2022.dto.Gd2022Api1308; |
| | | import com.fzzy.push.sh2023.SH2023Constant; |
| | | 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.lang.reflect.Field; |
| | | import java.util.*; |
| | | |
| | | /** |
| | |
| | | @Override |
| | | public String getProtocol() { |
| | | return PushProtocol.SB_GD_2022.getCode(); |
| | | } |
| | | |
| | | @Override |
| | | public ResponseDto pushData(ApiParam param, Object data) { |
| | | return pushData(param, null, data); |
| | | } |
| | | |
| | | @Override |
| | |
| | | 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()); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public ResponseDto pushData(ApiParam param, Object data) { |
| | | return pushData(param, null, data); |
| | | } |
| | | |
| | | // @Override |
| | | // public ResponseDto pushFile(ApiParam param, ApiConfs conf, Object data) { |
| | | // |
| | | // String inteId = param.getInteId(); |
| | | // String kqdm = param.getKqdm(); |
| | | // |
| | | // try { |
| | | // |
| | | // if (null == conf) { |
| | | // conf = apiCommonService.getConf(kqdm); |
| | | // } |
| | | // //获取TOKEN |
| | | // GD2022AuthToken token = getGD2022AuthToken(conf); |
| | | // |
| | | // ApiLog apiLog = new ApiLog(); |
| | | // apiLog.setId(ContextUtil.getUUID()); |
| | | // apiLog.setInteId(inteId); |
| | | // apiLog.setData(JSON.toJSONString(data)); |
| | | // apiLog.setKqdm(kqdm); |
| | | // apiLog.setUploadTime(new Date()); |
| | | // |
| | | // String wjdz = ""; |
| | | // if (Constant.API_CODE_1109.equals(inteId)) { |
| | | // //封装数据,获取文件地址 |
| | | // Gd2022Api1109 api1109 = new Gd2022Api1109(); |
| | | // BeanUtils.copyProperties(data, api1109); |
| | | // wjdz = api1109.getWjdz(); |
| | | // } else if (Constant.API_CODE_1307.equals(inteId)) { |
| | | // //封装数据,获取文件地址 |
| | | // Gd2022Api1307 api1307 = new Gd2022Api1307(); |
| | | // BeanUtils.copyProperties(data, api1307); |
| | | // wjdz = api1307.getWjdz(); |
| | | // } else if (Constant.API_CODE_1308.equals(inteId)) { |
| | | // //封装数据,获取文件地址 |
| | | // Gd2022Api1308 api1308 = new Gd2022Api1308(); |
| | | // BeanUtils.copyProperties(data, api1308); |
| | | // wjdz = api1308.getWjdz(); |
| | | // } |
| | | // if (StringUtils.isEmpty(wjdz)) { |
| | | // ResponseDto responseDto = new ResponseDto(99, "没有获取到文件地址", wjdz); |
| | | // apiLog.setStatus(99); |
| | | // apiLog.setResult("没有获取到文件地址"); |
| | | // apiLogRep.save(apiLog); |
| | | // return responseDto; |
| | | // } |
| | | // //先上传文件,获取文件id |
| | | // GD2022ResponseDto responseDto = GD2022HttpClientUtil.postUploadData(conf.getApiUrl(), token, wjdz); |
| | | // ResponseDto resd = new ResponseDto(); |
| | | // resd.setSuccess(responseDto.getCode() == 200 ? 0 : responseDto.getCode()); |
| | | // resd.setBizId((String) responseDto.getData()); |
| | | // resd.setMsg(responseDto.getMsg()); |
| | | // return resd; |
| | | // } catch (Exception e) { |
| | | // log.error(e.getMessage(), e); |
| | | // return new ResponseDto(99, e.getMessage()); |
| | | // } |
| | | // } |
| | | |
| | | /** |
| | | * 推送财务数据接口 |
| | |
| | | } |
| | | } |
| | | |
| | | private Object changeObject(Object object) { |
| | | // 使用反射获取属性列表 object为实体对象名 |
| | | Field[] fields = object.getClass().getDeclaredFields(); |
| | | for (Field field : fields) { |
| | | field.setAccessible(true); |
| | | try { |
| | | // 判断属性值是否为null |
| | | if (field.get(object) == null || field.get(object) == "") { |
| | | //根据类型设置默认值 |
| | | if (field.getType() == String.class) { |
| | | field.set(object, "0"); |
| | | } |
| | | if (field.getType() == Integer.class) { |
| | | field.set(object, 0); |
| | | } |
| | | if (field.getType() == Double.class) { |
| | | field.set(object, 0.0); |
| | | } |
| | | if (field.getType() == Date.class) { |
| | | field.set(object, new Date()); |
| | | } |
| | | } |
| | | } catch (IllegalAccessException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | return object; |
| | | } |
| | | |
| | | private String getJsonData(String inteId, Object data, String url, GD2022AuthToken authToken) throws Exception { |
| | | if (Constant.API_CODE_1101.equals(inteId)) { |
| | | Gd2022Api1101 api1101 = new Gd2022Api1101(); |
| | | BeanUtils.copyProperties(data, api1101); |
| | | return JSON.toJSONString(api1101); |
| | | } else if (Constant.API_CODE_1109.equals(inteId)) { |
| | | } else if (Constant.API_CODE_1102.equals(inteId)) { |
| | | Gd2022Api1102 api1102 = new Gd2022Api1102(); |
| | | BeanUtils.copyProperties(data, api1102); |
| | | return JSON.toJSONString(api1102); |
| | | } else if (Constant.API_CODE_1103.equals(inteId)) { |
| | | Gd2022Api1103 api1103 = new Gd2022Api1103(); |
| | | BeanUtils.copyProperties(data, api1103); |
| | | changeObject(api1103); |
| | | return JSON.toJSONString(api1103); |
| | | } else if (Constant.API_CODE_1104.equals(inteId)) { |
| | | Gd2022Api1104 api1104 = new Gd2022Api1104(); |
| | | BeanUtils.copyProperties(data, api1104); |
| | | changeObject(api1104); |
| | | return JSON.toJSONString(api1104); |
| | | } else if (Constant.API_CODE_1105.equals(inteId)) { |
| | | Gd2022Api1105 api1105 = new Gd2022Api1105(); |
| | | BeanUtils.copyProperties(data, api1105); |
| | | return JSON.toJSONString(api1105); |
| | | }else if (Constant.API_CODE_1109.equals(inteId)) { |
| | | //封装数据 |
| | | Gd2022Api1109 api1109 = new Gd2022Api1109(); |
| | | BeanUtils.copyProperties(data, api1109); |
| | |
| | | } |
| | | //先上传文件,获取文件id |
| | | GD2022ResponseDto responseDto = GD2022HttpClientUtil.postUploadData(url, authToken, api1109.getWjdz()); |
| | | System.out.println((String) responseDto.getData()); |
| | | //设置上传文件id |
| | | api1109.setFileStorageId((String) responseDto.getData()); |
| | | return JSON.toJSONString(api1109); |
| | |
| | | api1308.setFileStorageId((String) responseDto.getData()); |
| | | return JSON.toJSONString(api1308); |
| | | } else { |
| | | // changeObject(data); |
| | | return JSON.toJSONString(data); |
| | | } |
| | | } |