| | |
| | | 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.Api1202Rep; |
| | | 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; |
| | | @Autowired |
| | | private Api1202Rep api1202Rep; |
| | | |
| | | @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 if (SH2023Constant.SH_2023_API_CODE_1104.equals(inteId)) { |
| | | SH2023Api1104 api1104; |
| | | //最后转换为json |
| | | List<SH2023Api1104> list = new ArrayList<>(); |
| | | //把data转化成list集合 |
| | | List<Api1104> api1104List = castList(data, Api1104.class); |
| | | for (Api1104 apiData : api1104List) { |
| | | api1104 = new SH2023Api1104(); |
| | | BeanUtils.copyProperties(apiData, api1104); |
| | | api1104.setAjdm(apiData.getAjdh()); |
| | | api1104.setCfdm(apiData.getCfbh()); |
| | | api1104.setSykqdm(apiData.getKqdm()); |
| | | api1104.setBjw(ShAreaBjw.getBjw(code)); |
| | | list.add(api1104); |
| | | } |
| | | return JSON.toJSONString(list); |
| | | } else if (SH2023Constant.SH_2023_API_CODE_1105.equals(inteId)) { |
| | | SH2023Api1105 api1105; |
| | | //最后转换为json |
| | | List<SH2023Api1105> list = new ArrayList<>(); |
| | | //把data转化成list集合 |
| | | List<Api1105> api1105List = castList(data, Api1105.class); |
| | | for (Api1105 apiData : api1105List) { |
| | | api1105 = new SH2023Api1105(); |
| | | BeanUtils.copyProperties(apiData, api1105); |
| | | api1105.setBjw(ShAreaBjw.getBjw(code)); |
| | | list.add(api1105); |
| | | } |
| | | return JSON.toJSONString(list); |
| | | } else if (SH2023Constant.SH_2023_API_CODE_1106.equals(inteId)) { |
| | | SH2023Api1106 api1106; |
| | | //最后转换为json |
| | | List<SH2023Api1106> list = new ArrayList<>(); |
| | | //把data转化成list集合 |
| | | List<Api1106> api1106List = castList(data, Api1106.class); |
| | | for (Api1106 apiData : api1106List) { |
| | | api1106 = new SH2023Api1106(); |
| | | BeanUtils.copyProperties(apiData, api1106); |
| | | api1106.setBjw(ShAreaBjw.getBjw(code)); |
| | | list.add(api1106); |
| | | } |
| | | return JSON.toJSONString(list); |
| | | } else if (SH2023Constant.SH_2023_API_CODE_1201.equals(inteId)) { |
| | | SH2023Api1201 api1201; |
| | | //最后转换为json |
| | | List<SH2023Api1201> list = new ArrayList<>(); |
| | | //把data转化成list集合 |
| | | List<Api1201> api1201List = castList(data, Api1201.class); |
| | | for (Api1201 apiData : api1201List) { |
| | | api1201 = new SH2023Api1201(); |
| | | BeanUtils.copyProperties(apiData, api1201); |
| | | api1201.setBjw(ShAreaBjw.getBjw(code)); |
| | | api1201.setHtsfzz("0"); |
| | | list.add(api1201); |
| | | } |
| | | return JSON.toJSONString(list); |
| | | } else if (SH2023Constant.SH_2023_API_CODE_1202.equals(inteId)) { |
| | | SH2023Api1202 api1202; |
| | | //最后转换为json |
| | | List<SH2023Api1202> list = new ArrayList<>(); |
| | | //把data转化成list集合 |
| | | List<Api1202> api1202List = castList(data, Api1202.class); |
| | | for (Api1202 apiData : api1202List) { |
| | | api1202 = new SH2023Api1202(); |
| | | BeanUtils.copyProperties(apiData, api1202); |
| | | api1202.setBjw(ShAreaBjw.getBjw(code)); |
| | | api1202.setPch(apiData.getHwdm() + apiData.getShnd()); |
| | | //todo 驳运单号(2104) 检斤单号(2101) 均为非必填 |
| | | api1202.setJzrq(apiData.getCmsj()); |
| | | list.add(api1202); |
| | | } |
| | | return JSON.toJSONString(list); |
| | | } else if (SH2023Constant.SH_2023_API_CODE_1203.equals(inteId)) { |
| | | SH2023Api1203 api1203; |
| | | //最后转换为json |
| | | List<SH2023Api1203> list = new ArrayList<>(); |
| | | //把data转化成list集合 |
| | | List<Api1203> api1203List = castList(data, Api1203.class); |
| | | for (Api1203 apiData : api1203List) { |
| | | api1203 = new SH2023Api1203(); |
| | | BeanUtils.copyProperties(apiData, api1203); |
| | | api1203.setBjw(ShAreaBjw.getBjw(code)); |
| | | //查询收获年份 |
| | | List<Api1202> api1202List = api1202Rep.getDataById(apiData.getRkywdh()); |
| | | api1203.setPch(apiData.getHwdm() + api1202List.get(0).getShnd()); |
| | | list.add(api1203); |
| | | } |
| | | return JSON.toJSONString(list); |
| | | } else if (SH2023Constant.SH_2023_API_CODE_1204.equals(inteId)) { |
| | | SH2023Api1204 api1204; |
| | | //最后转换为json |
| | | List<SH2023Api1204> list = new ArrayList<>(); |
| | | //把data转化成list集合 |
| | | List<Api1204> api1204List = castList(data, Api1204.class); |
| | | for (Api1204 apiData : api1204List) { |
| | | api1204 = new SH2023Api1204(); |
| | | BeanUtils.copyProperties(apiData, api1204); |
| | | api1204.setBjw(ShAreaBjw.getBjw(code)); |
| | | api1204.setPch(apiData.getHwdm() + DateFormatUtils.format(apiData.getJssj(), "yyyy")); |
| | | list.add(api1204); |
| | | } |
| | | return JSON.toJSONString(list); |
| | | } else if (SH2023Constant.SH_2023_API_CODE_1205.equals(inteId)) { |
| | | SH2023Api1205 api1205; |
| | | //最后转换为json |
| | | List<SH2023Api1205> list = new ArrayList<>(); |
| | | //把data转化成list集合 |
| | | List<Api1205> api1205List = castList(data, Api1205.class); |
| | | for (Api1205 apiData : api1205List) { |
| | | api1205 = new SH2023Api1205(); |
| | | BeanUtils.copyProperties(apiData, api1205); |
| | | api1205.setBjw(ShAreaBjw.getBjw(code)); |
| | | api1205.setPch(apiData.getHwdm() + DateFormatUtils.format(apiData.getCmsj(), "yyyy")); |
| | | api1205.setJzrq(apiData.getCmsj()); |
| | | list.add(api1205); |
| | | } |
| | | 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; |
| | | } |
| | | |
| | | |
| | | } |