| | |
| | | package com.fzzy.push.whhpjl; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.fzzy.api.data.ApiParam; |
| | | import com.fzzy.api.data.PushProtocol; |
| | | import com.fzzy.api.dto.ResponseDto; |
| | |
| | | import com.fzzy.api.service.ApiCommonService; |
| | | import com.fzzy.api.service.ApiRemoteService; |
| | | import com.fzzy.api.service.ApiTriggerService; |
| | | import com.fzzy.api.utils.ContextUtil; |
| | | import com.fzzy.api.utils.RedisUtil; |
| | | import com.fzzy.api.utils.*; |
| | | import com.fzzy.api.view.repository.*; |
| | | import com.fzzy.push.whhpjl.dto.WhjlReqDto; |
| | | import com.fzzy.push.whhpjl.dto.WhjlRespDto; |
| | | import com.fzzy.whjl.WhjlConstant; |
| | | import com.fzzy.otherview.whhpjl.WhjlConstant; |
| | | 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.Date; |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | | import java.util.*; |
| | | |
| | | /** |
| | | * 武汉军粮省平台-上传数据服务类 |
| | |
| | | private ApiTriggerService apiTriggerService; |
| | | @Autowired |
| | | private ApiLogRep apiLogRep; |
| | | @Autowired |
| | | private Whjl2023HttpClientUtil whjl2023HttpClientUtil; |
| | | |
| | | @Override |
| | | public String getProtocol() { |
| | |
| | | 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); |
| | | } |
| | | |
| | | //添加LOGO |
| | | //添加日志 |
| | | ApiLog apiLog = new ApiLog(); |
| | | apiLog.setId(ContextUtil.getUUID()); |
| | | apiLog.setInteId(inteId); |
| | | String jsonData = getJsonData(inteId, data, conf.getApiUrl()); |
| | | log.info("报文信息=" + jsonData); |
| | | String jsonData = getJsonData(data); |
| | | log.info("接口数据信息=" + jsonData); |
| | | inteId = getInteId(inteId); |
| | | if (StringUtils.isEmpty(inteId)) { |
| | | ResponseDto responseDto = new ResponseDto(99, "没有获取到接口", bizId); |
| | | ResponseDto responseDto = new ResponseDto(99, "没有获取到接口"); |
| | | apiLog.setStatus(99); |
| | | apiLog.setResult("没有获取到接口"); |
| | | apiLogRep.save(apiLog); |
| | |
| | | apiLog.setUploadTime(new Date()); |
| | | |
| | | if (conf == null) { |
| | | ResponseDto responseDto = new ResponseDto(99, "没有获取到上传配置", bizId); |
| | | ResponseDto responseDto = new ResponseDto(99, "没有获取到上传配置"); |
| | | apiLog.setStatus(99); |
| | | apiLog.setResult("没有获取到上传配置"); |
| | | apiLogRep.save(apiLog); |
| | | return responseDto; |
| | | } |
| | | |
| | | Map<String, Object> map = new HashMap<>(); |
| | | WhjlRespDto responseDto = Whjl2023HttpClientUtil.postPushData(conf.getApiUrl() + inteId, jsonData, conf, null); |
| | | //封装推送数据 |
| | | WhjlReqDto reqData = new WhjlReqDto(); |
| | | //报文标识ID |
| | | reqData.setId(ContextUtil.getUUID()); |
| | | //身份ID |
| | | reqData.setUid(conf.getUserName()); |
| | | //获取指令id |
| | | String key = RedisConst.buildKey(RedisConst.KYE_ORDER, conf.getKqdm()); |
| | | String orderId = (String)redisUtil.get(key); |
| | | if(StringUtils.isEmpty(orderId)){ |
| | | orderId = reqData.getId(); |
| | | } |
| | | reqData.setOrderid(orderId); |
| | | //应用码 |
| | | reqData.setAppcode(conf.getAppCode()); |
| | | //时间戳 |
| | | reqData.setTimestamp(Long.valueOf(ContextUtil.getCurTimeMillis())); |
| | | //身份签名,对应用码_授权码_站点编码_报文ID_时间戳进行MD5算法签名 |
| | | String accessToken = reqData.getAppcode() +"_" + conf.getPassword() +"_" + reqData.getUid() + "_" + reqData.getId() + "_" + reqData.getTimestamp(); |
| | | log.info("身份签名:" + accessToken); |
| | | reqData.setAccesstoken(MyMD5Util.encrypt(accessToken)); |
| | | //数据总条数 |
| | | reqData.setDatalength(1); |
| | | //数据主体,进行SM4加密 |
| | | reqData.setData(SM4Util.encryptEcb(conf.getPublicKey(), jsonData)); |
| | | //摘要,数据主体的MD5值 |
| | | reqData.setDigest(MyMD5Util.encrypt(jsonData)); |
| | | //操作类型 |
| | | JSONObject jsonObject = JSONObject.parseObject(JSON.toJSONString(data)); |
| | | String czbz = jsonObject.getString("czbz"); |
| | | if("u".equals(czbz)){ |
| | | czbz = "update"; |
| | | }else if("d".equals(czbz)){ |
| | | czbz = "delete"; |
| | | }else { |
| | | czbz = "insert"; |
| | | } |
| | | reqData.setOperator(czbz); |
| | | |
| | | WhjlRespDto responseDto = whjl2023HttpClientUtil.postPushData(conf.getApiUrl() + inteId, reqData); |
| | | apiLog.setStatus(responseDto.getCode() == 200 ? 0 : responseDto.getCode()); |
| | | apiLog.setResult(responseDto.getResult()); |
| | | apiLogRep.save(apiLog); |
| | | ResponseDto resd = new ResponseDto(); |
| | | resd.setSuccess(responseDto.getCode() == 200 ? 0 : responseDto.getCode()); |
| | | resd.setMsg(responseDto.getResult()); |
| | | //updateGD2022AuthToken(responseDto,conf, token); |
| | | |
| | | return resd; |
| | | } catch (Exception e) { |
| | | log.error(e.getMessage(), e); |
| | |
| | | } |
| | | |
| | | /** |
| | | * 调整数据封装,获取json数据 |
| | | * 调整数据封装成list,获取json数据 |
| | | * |
| | | * @param inteId |
| | | * @param data |
| | | * @return |
| | | * @throws Exception |
| | | */ |
| | | private String getJsonData(String inteId, Object data, String url) { |
| | | return JSON.toJSONString(data); |
| | | private String getJsonData(Object data) { |
| | | List<Object> list = new ArrayList<>(); |
| | | list.add(data); |
| | | return JSON.toJSONString(list); |
| | | } |
| | | |
| | | private String getInteId(String inteId) { |
| | |
| | | case "1105": |
| | | return WhjlConstant.API_CODE_CFXX; |
| | | case "1106": |
| | | return WhjlConstant.API_CODE_AJXX; |
| | | return WhjlConstant.API_CODE_YGXX; |
| | | case "1107": |
| | | return WhjlConstant.API_CODE_HWXX; |
| | | return WhjlConstant.API_CODE_AJXX; |
| | | case "1108": |
| | | return WhjlConstant.API_CODE_CCSSDZDA; |
| | | return WhjlConstant.API_CODE_HWXX; |
| | | case "1109": |
| | | return WhjlConstant.API_CODE_CCSSWHJL; |
| | | return WhjlConstant.API_CODE_CCSSDZDA; |
| | | case "1110": |
| | | return WhjlConstant.API_CODE_CCSSBFJL; |
| | | return WhjlConstant.API_CODE_CCSSWHJL; |
| | | case "1111": |
| | | return WhjlConstant.API_CODE_CCSBXX; |
| | | return WhjlConstant.API_CODE_CCSSBFJL; |
| | | case "1112": |
| | | return WhjlConstant.API_CODE_CCSBWHJL; |
| | | return WhjlConstant.API_CODE_CCSBXX; |
| | | case "1113": |
| | | return WhjlConstant.API_CODE_CCSBWXJL; |
| | | return WhjlConstant.API_CODE_CCSBWHJL; |
| | | case "1114": |
| | | return WhjlConstant.API_CODE_CCSBWXJL; |
| | | case "11145": |
| | | return WhjlConstant.API_CODE_CCSBBFJL; |
| | | case "1201": |
| | | return WhjlConstant.API_CODE_FSGYSXX; |