| | |
| | | import com.fzzy.api.data.ApiParam; |
| | | import com.fzzy.api.data.PushProtocol; |
| | | import com.fzzy.api.dto.ResponseDto; |
| | | import com.fzzy.api.entity.Api1102; |
| | | import com.fzzy.api.entity.ApiConfs; |
| | | import com.fzzy.api.entity.ApiLog; |
| | | import com.fzzy.api.entity.*; |
| | | import com.fzzy.api.service.ApiCommonService; |
| | | import com.fzzy.api.service.ApiRemoteService; |
| | | import com.fzzy.api.service.ApiTriggerService; |
| | | import com.fzzy.api.utils.*; |
| | | import com.fzzy.api.view.repository.Api1102Rep; |
| | | import com.fzzy.api.view.repository.Api1104Rep; |
| | | import com.fzzy.api.view.repository.ApiLogRep; |
| | | import com.fzzy.push.sh2023.dto.SH2023ReqDto; |
| | | import com.fzzy.push.sh2023.dto.SH2023RespDto; |
| | | import com.fzzy.push.sh2023.dto.*; |
| | | import lombok.Data; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.lang.StringUtils; |
| | | import org.apache.commons.lang.time.DateFormatUtils; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | |
| | | private ApiLogRep apiLogRep; |
| | | @Autowired |
| | | private Api1102Rep api1102Rep; |
| | | @Autowired |
| | | private Api1104Rep api1104Rep; |
| | | |
| | | @Override |
| | | public String getProtocol() { |
| | |
| | | public ResponseDto pushData(ApiParam param, ApiConfs conf, Object data) { |
| | | String inteId = param.getInteId(); |
| | | String kqdm = param.getKqdm(); |
| | | |
| | | //查询库区信息行政区划码 |
| | | List<Api1102> api1102List = api1102Rep.findPushData(conf.getKqdm()); |
| | | try { |
| | | if (null == conf) { |
| | | conf = apiCommonService.getConf(kqdm); |
| | |
| | | ApiLog apiLog = new ApiLog(); |
| | | apiLog.setId(ContextUtil.getUUID()); |
| | | apiLog.setInteId(inteId); |
| | | String jsonData = getJsonData(inteId, data); |
| | | String jsonData = getJsonData(inteId, data, api1102List.get(0).getXzqhdm()); |
| | | log.info("接口数据信息=" + jsonData); |
| | | |
| | | if (StringUtils.isEmpty(inteId)) { |
| | |
| | | SH2023ReqDto reqData = new SH2023ReqDto(); |
| | | reqData.setId(ContextUtil.getUUID()); |
| | | //获取身份ID,即行政区划码 |
| | | List<Api1102> api1102List = api1102Rep.findPushData(conf.getKqdm()); |
| | | if(null == api1102List || api1102List.isEmpty()){ |
| | | if (null == api1102List || api1102List.isEmpty()) { |
| | | ResponseDto responseDto = new ResponseDto(99, "没有获取到身份ID"); |
| | | apiLog.setStatus(99); |
| | | apiLog.setResult("没有获取到身份ID"); |
| | |
| | | //指令id |
| | | reqData.setOrderid(param.getOrderid()); |
| | | //身份签名,对地区行政区划代码_当天日期进行MD5算法签名 |
| | | reqData.setAccess_token(RSAUtils.encryptData(reqData.getUid() + "_" + DateFormatUtils.format(new Date(), "yyyy-MM-dd"),conf.getPublicKey())); |
| | | reqData.setAccess_token(RSAUtils.encryptData(reqData.getUid() + "_" + DateFormatUtils.format(new Date(), "yyyy-MM-dd"), conf.getPublicKey())); |
| | | //数据总条数 |
| | | List<Object> list = (List<Object>)data; |
| | | List<Object> list = (List<Object>) data; |
| | | reqData.setDatalength(list.size()); |
| | | //数据进行SM4加密 |
| | | reqData.setData(jsonData); |
| | |
| | | * @return |
| | | * @throws Exception |
| | | */ |
| | | private String getJsonData(String inteId, Object data) { |
| | | private String getJsonData(String inteId, Object data, String code) { |
| | | //具体根据接口进行封装 |
| | | if (SH2023Constant.SH_2023_API_CODE_1101.equals(inteId)) { |
| | | return JSON.toJSONString(data); |
| | | SH2023Api1101 api1101; |
| | | //最后转换为json |
| | | List<SH2023Api1101> list = new ArrayList<>(); |
| | | //把data转化成list集合 |
| | | List<Api1101> api1101List = castList(data, Api1101.class); |
| | | //查询廒间数 |
| | | List<Api1104> api1104List = api1104Rep.findPushData(api1101List.get(0).getKqdm()); |
| | | for (Api1101 apiData : api1101List) { |
| | | api1101 = new SH2023Api1101(); |
| | | BeanUtils.copyProperties(apiData, api1101); |
| | | api1101.setAjs(api1104List.size()); |
| | | api1101.setBjw(ShAreaBjw.getBjw(code)); |
| | | list.add(api1101); |
| | | } |
| | | return JSON.toJSONString(list); |
| | | } else if (SH2023Constant.SH_2023_API_CODE_1102.equals(inteId)) { |
| | | SH2023Api1102 api1102; |
| | | //最后转换为json |
| | | List<SH2023Api1102> list = new ArrayList<>(); |
| | | //把data转化成list集合 |
| | | List<Api1102> api1101List = castList(data, Api1102.class); |
| | | //查询廒间数 |
| | | List<Api1104> api1104List = api1104Rep.findPushData(api1101List.get(0).getKqdm()); |
| | | //计算储备仓容 |
| | | Double count = 0.0; |
| | | for (Api1104 api1104 : api1104List) { |
| | | count = count + api1104.getAjsjcrong(); |
| | | } |
| | | for (Api1102 apiData : api1101List) { |
| | | api1102 = new SH2023Api1102(); |
| | | BeanUtils.copyProperties(apiData, api1102); |
| | | api1102.setAjs(api1104List.size()); |
| | | api1102.setBjw(ShAreaBjw.getBjw(code)); |
| | | api1102.setCbcr(count); |
| | | list.add(api1102); |
| | | } |
| | | return JSON.toJSONString(list); |
| | | } else if (SH2023Constant.SH_2023_API_CODE_1103.equals(inteId)) { |
| | | SH2023Api1103 api1103; |
| | | //最后转换为json |
| | | List<SH2023Api1103> list = new ArrayList<>(); |
| | | //把data转化成list集合 |
| | | List<Api1103> api1103List = castList(data, Api1103.class); |
| | | //查询廒间数 |
| | | List<Api1104> api1104List = api1104Rep.findPushData(api1103List.get(0).getKqdm()); |
| | | for (Api1103 apiData : api1103List) { |
| | | api1103 = new SH2023Api1103(); |
| | | BeanUtils.copyProperties(apiData, api1103); |
| | | api1103.setAjs(api1104List.size()); |
| | | api1103.setBjw(ShAreaBjw.getBjw(code)); |
| | | list.add(api1103); |
| | | } |
| | | return JSON.toJSONString(list); |
| | | } else { |
| | | return JSON.toJSONString(data); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * Object类型转变为List |
| | | * |
| | | * @param obj |
| | | * @param clazz |
| | | * @param <T> |
| | | * @return |
| | | */ |
| | | public static <T> List<T> castList(Object obj, Class<T> clazz) { |
| | | List<T> result = new ArrayList<T>(); |
| | | if (obj instanceof List<?>) { |
| | | for (Object o : (List<?>) obj) { |
| | | result.add(clazz.cast(o)); |
| | | } |
| | | return result; |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | |
| | | } |