| | |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.lang.StringUtils; |
| | | import org.apache.commons.lang.time.DateFormatUtils; |
| | | import com.fzzy.api.utils.NumberUtil; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | |
| | | @Autowired |
| | | private Api1208Rep api1208Rep; |
| | | @Autowired |
| | | private Api1210Rep api1210Rep; |
| | | @Autowired |
| | | private Api1109Rep api1109Rep; |
| | | @Autowired |
| | | private Api1202Rep api1202Rep; |
| | | @Autowired |
| | | private Api1205Rep api1205Rep; |
| | | @Autowired |
| | | private Api1403Rep api1403Rep; |
| | | @Autowired |
| | | private Api1404Rep api1404Rep; |
| | | |
| | |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public ResponseDto pullData(ApiParam param, ApiConfs conf) { |
| | | String inteId = param.getInteId(); |
| | | String kqdm = param.getKqdm(); |
| | | |
| | | try { |
| | | if (null == conf) { |
| | | conf = apiCommonService.getConf(kqdm); |
| | | } |
| | | |
| | | //添加日志 |
| | | ApiLog apiLog = new ApiLog(); |
| | | apiLog.setId(ContextUtil.getUUID()); |
| | | apiLog.setInteId(inteId); |
| | | |
| | | if (StringUtils.isEmpty(inteId)) { |
| | | ResponseDto responseDto = new ResponseDto(99, "没有获取到接口"); |
| | | apiLog.setStatus(99); |
| | | apiLog.setResult("没有获取到接口"); |
| | | apiLogRep.save(apiLog); |
| | | return responseDto; |
| | | } |
| | | |
| | | if (conf == null) { |
| | | ResponseDto responseDto = new ResponseDto(99, "没有获取到上传配置"); |
| | | apiLog.setStatus(99); |
| | | apiLog.setResult("没有获取到上传配置"); |
| | | apiLogRep.save(apiLog); |
| | | return responseDto; |
| | | } |
| | | |
| | | //封装数据 |
| | | SH2023PullReqDto reqData = new SH2023PullReqDto();; |
| | | |
| | | reqData.setName(conf.getUserName()); |
| | | reqData.setPwd(conf.getAppCode()); |
| | | log.info("拉取共享数据请求信息=" + JSON.toJSONString(reqData)); |
| | | |
| | | String url = conf.getApiUrl().replace("UPLOAD", "Shared"); |
| | | SH2023PullRespDto responseDto = SH2023HttpClientUtil.postPullData(url + inteId, JSON.toJSONString(reqData)); |
| | | |
| | | apiLog.setStatus(responseDto.getRetcode() == 200 ? 0 : responseDto.getRetcode()); |
| | | apiLog.setResult(responseDto.getRetMsg()); |
| | | apiLogRep.save(apiLog); |
| | | ResponseDto resd = new ResponseDto(); |
| | | resd.setSuccess(responseDto.getRetcode() == 200 ? 0 : responseDto.getRetcode()); |
| | | resd.setMsg(responseDto.getRetMsg()); |
| | | resd.setData(responseDto.getData()); |
| | | return resd; |
| | | } catch (Exception e) { |
| | | log.error(e.getMessage(), e); |
| | | return new ResponseDto(99, e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 转为JSON |
| | | * |
| | |
| | | list.add(object); |
| | | return JSON.toJSONString(list); |
| | | } |
| | | |
| | | } |
| | | |
| | | /** |
| | |
| | | * @return |
| | | */ |
| | | private Object getJsonApiData(String inteId, Object data, String code) { |
| | | List<Object> list = new ArrayList<>(); |
| | | //具体根据接口进行封装 |
| | | if (SH2023Constant.SH_2023_API_CODE_1101.equals(inteId)) { |
| | | SH2023Api1101 api1101 = new SH2023Api1101(); |
| | |
| | | BeanUtils.copyProperties(apiData, api1104); |
| | | api1104.setAjdm(apiData.getAjdh()); |
| | | api1104.setCfdm(apiData.getCfbh()); |
| | | |
| | | //设置粮食性质代码(查看廒间对应的最新库存进行赋值) |
| | | List<Api1208> api1208List = api1208Rep.findDataByHwdm(api1104.getAjdm() + "01"); |
| | | if (null != api1208List && api1208List.size() > 0) { |
| | | api1104.setLsxzdm(api1208List.get(0).getLsxzdm()); |
| | | } |
| | | |
| | | //设置空属性为默认值 |
| | | changeObject(api1104); |
| | |
| | | api1109.setWjl(JSON.toJSONString(map)); |
| | | //上海市平台文件名称规则:库区编码_业务流水号_分类码_顺序码.jpg,例如:91310114703439394M001_142211080101_GL_00.jpg |
| | | api1109.setWjmc(getWjmc(api1109.getWjlx(), api1109.getWjmc())); |
| | | //业务类型 |
| | | api1109.setYwdh(getYwdh(api1109.getWjlx(), api1109.getWjmc(), api1109.getYwdh())); |
| | | //设置空属性为默认值 |
| | | changeObject(api1109); |
| | | return api1109; |
| | |
| | | BeanUtils.copyProperties(data, api1112); |
| | | api1112.setHdrychsj(api1112.getQdzgzchzyzgsj()); |
| | | api1112.setBjw(ShAreaBjw.getBjw(code)); |
| | | api1112.setZy("01"); |
| | | |
| | | //设置空属性为默认值 |
| | | changeObject(api1112); |
| | |
| | | if (StringUtils.isEmpty(api1201.getShr())) { |
| | | api1201.setShr("审批人"); |
| | | } |
| | | //设置购销方式,默认客户统一信用码为空,则为产销,反之为竞价;(1-定向;2-竞价;3-产销) |
| | | api1201.setGxfs("2"); |
| | | if(StringUtils.isEmpty(api1201.getKhtyshxydm())){ |
| | | api1201.setGxfs("3"); |
| | | } |
| | | //设置空属性为默认值 |
| | | changeObject(api1201); |
| | | return api1201; |
| | |
| | | if (StringUtils.isEmpty(api1202.getRkjsdh())) { |
| | | api1202.setRkjsdh("0"); |
| | | } |
| | | |
| | | //设置粮食轮换年度 |
| | | //设置粮食轮换年度,根据计划明细号查询计划明细,再根据计划明细查询轮换计划 |
| | | List<Api1404> api1404List = api1404Rep.getDataByJhmxdh(apiData.getJhmxh()); |
| | | if (null != api1404List && api1404List.size() > 0) { |
| | | api1202.setLhnd(api1404List.get(0).getShnd()); |
| | | List<Api1403> api1403List = api1403Rep.getDataByLhjhdh(api1404List.get(0).getLhjhdh()); |
| | | if(null != api1403List && api1403List.size() > 0){ |
| | | if(StringUtils.isNotEmpty(api1403List.get(0).getJhnd())){ |
| | | api1202.setLhnd(api1403List.get(0).getJhnd()); |
| | | } |
| | | } |
| | | } |
| | | |
| | | //查询粮食性质转变单号(根据入库时间和货位代码查询粮食性质转变单) |
| | | List<Api1210> api1210List = api1210Rep.findDataByHwdmAndTime(api1202.getHwdm(), api1202.getCmsj()); |
| | | if (null != api1210List && api1210List.size() > 0) { |
| | | api1202.setLsxzzbdh(api1210List.get(0).getLsxzzbdh()); |
| | | } |
| | | //设置批次号 |
| | | List<Api1208> api1208List = api1208Rep.findDataByHwdm(api1202.getHwdm()); |
| | | if (null != api1208List && api1208List.size() > 0) { |
| | | api1202.setPch(apiData.getHwdm() + api1208List.get(0).getShnd()); |
| | | } |
| | | //粮食性质 |
| | | api1202.setLsxzdm("200"); |
| | | |
| | | //设置空属性为默认值 |
| | | changeObject(api1202); |
| | | return api1202; |
| | |
| | | if (null != api1208List && api1208List.size() > 0) { |
| | | api1203.setPch(apiData.getHwdm() + api1208List.get(0).getShnd()); |
| | | } |
| | | |
| | | //设置质检编码(默认等同于入库质检单号),若为船运,则设置为系统内船运的单号 |
| | | api1203.setZjbh(api1203.getRkjydh()); |
| | | List<Api1202> api1202List = api1202Rep.getDataById(api1203.getRkywdh()); |
| | | if (null != api1202List && api1202List.size() > 0) { |
| | | if(api1202List.get(0).getYsgj().equals("3")){ |
| | | api1203.setZjbh(api1202List.get(0).getBizId().substring(2)); |
| | | } |
| | | } |
| | | //设置空属性为默认值 |
| | | changeObject(api1203); |
| | | return api1203; |
| | |
| | | //设置粮食轮换年度 |
| | | List<Api1404> api1404List = api1404Rep.getDataByJhmxdh(apiData.getJhmxh()); |
| | | if (null != api1404List && api1404List.size() > 0) { |
| | | api1205.setLhnd(api1404List.get(0).getShnd()); |
| | | List<Api1403> api1403List = api1403Rep.getDataByLhjhdh(api1404List.get(0).getLhjhdh()); |
| | | if(null != api1403List && api1403List.size() > 0){ |
| | | if(StringUtils.isNotEmpty(api1403List.get(0).getJhnd())){ |
| | | api1205.setLhnd(api1403List.get(0).getJhnd()); |
| | | } |
| | | } |
| | | } |
| | | |
| | | //设置批次号 |
| | |
| | | api1205.setPch(apiData.getHwdm() + api1208List.get(0).getShnd()); |
| | | } |
| | | |
| | | //粮食性质 |
| | | api1205.setLsxzdm("200"); |
| | | //设置空属性为默认值 |
| | | changeObject(api1205); |
| | | return api1205; |
| | |
| | | api1209.setPch(api1209.getHwdm() + api1208List.get(0).getShnd()); |
| | | } |
| | | |
| | | //粮食性质,暂时默认区级储备 |
| | | api1209.setLsxzdm("122"); |
| | | |
| | | //设置空属性为默认值 |
| | | changeObject(api1209); |
| | | return api1209; |
| | |
| | | if (null != api1208List && api1208List.size() > 0) { |
| | | api1211.setPch(apiData.getHwdm() + api1208List.get(0).getShnd()); |
| | | } |
| | | |
| | | //主管粮库代码 |
| | | api1211.setZglkdm(apiData.getKqdm()); |
| | | //设置空属性为默认值 |
| | | changeObject(api1211); |
| | | return api1211; |
| | |
| | | Api1302 apiData = (Api1302) data; |
| | | BeanUtils.copyProperties(apiData, api1302); |
| | | api1302.setBjw(ShAreaBjw.getBjw(code)); |
| | | api1302.setCpjw(String.valueOf(apiData.getLspjw())); |
| | | api1302.setCzgw(String.valueOf(apiData.getLspjw())); |
| | | api1302.setCzdw(String.valueOf(apiData.getLspjw())); |
| | | api1302.setGfwjw(String.valueOf(apiData.getLspjw())); |
| | | api1302.setLwmx(apiData.getLswdzjh()); |
| | | |
| | | api1302.setLqjs("1"); |
| | | //批次号 |
| | | List<Api1208> api1208List = api1208Rep.findDataByHwdm(api1302.getHwdm()); |
| | | if (null != api1208List && api1208List.size() > 0) { |
| | | api1302.setPch(apiData.getHwdm() + api1208List.get(0).getShnd()); |
| | | } |
| | | //统计层高、层低、层均温等信息 |
| | | api1302 = packageData1302(api1302); |
| | | |
| | | //设置空属性为默认值 |
| | | changeObject(api1302); |
| | |
| | | api1403.setJhzxdwmc(api1101List.get(0).getDwmc()); |
| | | api1403.setBjw(ShAreaBjw.getBjw(code)); |
| | | |
| | | //查询轮换计划的轮入数量和轮出数量 |
| | | List<Api1404> list = api1404Rep.getDataByLhjhdh(api1403.getLhjhdh()); |
| | | Double lrsl = 0.0, lcsl = 0.0; //用于统计轮入数量和轮出数量 |
| | | if(null != list && list.size() > 0){ |
| | | for (Api1404 api1404 : list) { |
| | | if(null!= api1404.getLhlx() && "2".equals(api1404.getLhlx())){ |
| | | lrsl += api1404.getLhsl(); |
| | | } |
| | | if(null!= api1404.getLhlx() && "1".equals(api1404.getLhlx())){ |
| | | lcsl += api1404.getLhsl(); |
| | | } |
| | | } |
| | | } |
| | | api1403.setLrsl(lrsl/1000 + ""); |
| | | api1403.setLcsl(lcsl/1000 + ""); |
| | | |
| | | //设置空属性为默认值 |
| | | changeObject(api1403); |
| | | return api1403; |
| | |
| | | return data; |
| | | } |
| | | |
| | | private String getWjmc(String wjlx, String wjmc) { |
| | | if ("2".equals(wjlx) || "3".equals(wjlx) || "4".equals(wjlx) || "5".equals(wjlx)) { |
| | | if (wjmc.endsWith(".jpg")) { |
| | | wjmc = wjmc.replaceAll(".jpg", "_00.jpg"); |
| | | /** |
| | | * 根据上海数据格式进行封装 |
| | | * 层均温: |
| | | * 层高温: |
| | | * 层低温: |
| | | * 各范围均温: |
| | | * 粮温明细: |
| | | * 粮温状态: |
| | | * 异常点个数: |
| | | * |
| | | * @param data |
| | | * @return |
| | | */ |
| | | private SH2023Api1302 packageData1302(SH2023Api1302 data) { |
| | | if (StringUtils.isEmpty(data.getLswdzjh())) { |
| | | return data; |
| | | } |
| | | String lswdzjh = data.getLswdzjh(); |
| | | String[] split = lswdzjh.split("\\|"); |
| | | Map<Integer, List<Double>> map = new HashMap<>(); |
| | | Integer ceng; |
| | | Integer errorNum = 0; //异常点个数 |
| | | String lwmx = ""; //粮温明细 |
| | | String lwzt = "0"; //粮温状态 |
| | | String gfwjw = ""; //各范围均温 |
| | | for (String s : split) { |
| | | String[] grain = s.split(","); |
| | | ceng = Integer.valueOf(grain[1]); |
| | | if (null == map.get(ceng)) { |
| | | map.put(ceng, new ArrayList<>()); |
| | | } |
| | | if (wjmc.endsWith(".png")) { |
| | | wjmc = wjmc.replaceAll(".png", "_00.png"); |
| | | map.get(ceng).add(Double.valueOf(grain[0])); |
| | | lwmx += grain[2] + ":" + grain[3] +":" + grain[1] + "$" + grain[0]; |
| | | if (Double.valueOf(grain[0]) <= -100) { |
| | | lwmx += "$" + "1" + "#"; |
| | | errorNum++; |
| | | } else { |
| | | lwmx += "$" + "5" + "#"; |
| | | } |
| | | } |
| | | return wjmc; |
| | | String cpjw = ""; //层平均温 |
| | | String czgw = ""; //层最高温 |
| | | String czdw = ""; //层最低温 |
| | | |
| | | List<Double> payPoints; |
| | | Double sum; |
| | | int num; |
| | | Double tempH; |
| | | Double tempL; |
| | | Double tempA; |
| | | Double tempValue1 = 0.0; //范围均温1 |
| | | Double tempValue2 = 0.0; //范围均温2 |
| | | Double tempValue3 = 0.0; //范围均温3 |
| | | Integer numValue = 0; //计算范围均温 |
| | | for (Integer cengNum : map.keySet()) { |
| | | payPoints = map.get(cengNum); |
| | | sum = 0.0; |
| | | num = 0; |
| | | tempH = null; |
| | | tempL = null; |
| | | tempA = 0.0; |
| | | for (Double point : payPoints) { |
| | | if(point > -100){ |
| | | sum += point; |
| | | num++; |
| | | if (tempH == null) { |
| | | tempH = point; |
| | | } |
| | | if (tempL == null) { |
| | | tempL = point; |
| | | } |
| | | if (tempH < point) { |
| | | tempH = point; |
| | | } |
| | | if (tempL > point) { |
| | | tempL = point; |
| | | } |
| | | } |
| | | } |
| | | if (num > 0) { |
| | | tempA = sum / num; |
| | | } |
| | | cpjw += cengNum + "$" + NumberUtil.keepPrecision(tempA, 1) + "#"; |
| | | czgw += cengNum + "$" + tempH + "#"; |
| | | czdw += cengNum + "$" + tempL + "#"; |
| | | //范围均温封装 |
| | | if (cengNum == 1) { |
| | | tempValue1 = NumberUtil.keepPrecision(tempA, 1); |
| | | } else if (cengNum == map.keySet().size()) { |
| | | tempValue3 = NumberUtil.keepPrecision(tempA, 1); |
| | | } else { |
| | | tempValue2 += tempA; |
| | | numValue++; |
| | | } |
| | | } |
| | | |
| | | if (errorNum > 0) { |
| | | lwzt = "2"; |
| | | } |
| | | if (numValue > 0) { |
| | | tempValue2 = NumberUtil.keepPrecision(tempValue2 / numValue, 1); |
| | | } |
| | | gfwjw += tempValue1 + "#"; |
| | | if (map.keySet().size() == 2) { |
| | | gfwjw += tempValue3 + "#"; |
| | | } |
| | | if (map.keySet().size() > 3) { |
| | | gfwjw += tempValue2 + "#" + tempValue3 + "#"; |
| | | } |
| | | data.setCpjw(cpjw); |
| | | data.setCzgw(czgw); |
| | | data.setCzdw(czdw); |
| | | data.setGfwjw(gfwjw); |
| | | data.setLwmx(lwmx); |
| | | data.setLwzt(lwzt); |
| | | data.setYcdgs(errorNum); |
| | | |
| | | return 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; |
| | | } |
| | | |
| | | |
| | | private List<SHFinanceDto> copyApi1503(Api1503 data) { |
| | | Api1503 api1503 = data; |
| | | private List<SHFinanceDto> copyApi1503(Api1503 api1503) { |
| | | List<SHFinanceDto> list = new ArrayList<>(); |
| | | SHFinanceDto shFinanceDto = new SHFinanceDto(); |
| | | shFinanceDto.setDwdm(api1503.getDwdm()); |
| | |
| | | return list; |
| | | } |
| | | |
| | | private List<SHFinanceDto> copyApi1502(Api1502 data) { |
| | | Api1502 api1502 = data; |
| | | private List<SHFinanceDto> copyApi1502(Api1502 api1502) { |
| | | List<SHFinanceDto> list = new ArrayList<>(); |
| | | SHFinanceDto shFinanceDto = new SHFinanceDto(); |
| | | shFinanceDto.setDwdm(api1502.getDwdm()); |
| | |
| | | return list; |
| | | } |
| | | |
| | | private List<SHFinanceDto> copyApi1501(Api1501 data) { |
| | | Api1501 api1501 = data; |
| | | private List<SHFinanceDto> copyApi1501(Api1501 api1501) { |
| | | List<SHFinanceDto> list = new ArrayList<>(); |
| | | SHFinanceDto shFinanceDto = new SHFinanceDto(); |
| | | shFinanceDto.setDwdm(api1501.getDwdm()); |
| | |
| | | list.add(shFinanceDto); |
| | | } |
| | | |
| | | private String getWjmc(String wjlx, String wjmc) { |
| | | if ("2".equals(wjlx) || "3".equals(wjlx) || "4".equals(wjlx) || "5".equals(wjlx)) { |
| | | if (wjmc.endsWith(".jpg")) { |
| | | wjmc = wjmc.replaceAll(".jpg", "_00.jpg"); |
| | | } |
| | | if (wjmc.endsWith(".png")) { |
| | | wjmc = wjmc.replaceAll(".png", "_00.png"); |
| | | } |
| | | } |
| | | return wjmc; |
| | | } |
| | | private String getYwdh(String wjlx, String wjmc, String ywdh) { |
| | | String[] s = wjmc.split("_"); |
| | | if ("2".equals(wjlx) || "3".equals(wjlx)) { |
| | | ywdh = s[1]; |
| | | } |
| | | return ywdh; |
| | | } |
| | | |
| | | private Object changeObject(Object object) { |
| | | // 使用反射获取属性列表 vo为实体对象名 |
| | | Field[] fields = object.getClass().getDeclaredFields(); |
| | |
| | | } |
| | | return object; |
| | | } |
| | | |
| | | } |