| | |
| | | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.fzzy.api.entity.*; |
| | | import com.fzzy.api.utils.RedisUtil; |
| | | import com.fzzy.api.view.repository.*; |
| | | import com.fzzy.inte.sh2023.dto.SHDN2023ReqDto; |
| | | import com.fzzy.inte.sh2023.constant.ApiRespCode; |
| | | import com.fzzy.inte.sh2023.dto.ApiResp; |
| | | import com.fzzy.inte.sh2023.dto.ResultDto; |
| | | import com.fzzy.push.sh2023.SH2023Constant; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.scheduling.annotation.Async; |
| | | import org.springframework.stereotype.Component; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | | @Slf4j |
| | | @Service |
| | | public class SHDNService { |
| | | |
| | | @Autowired |
| | | private ApiConfsRep apiConfsRep; |
| | | @Autowired |
| | | private Api9109Rep api9109Rep; |
| | | @Autowired |
| | |
| | | private Api9115Rep api9115Rep; |
| | | @Autowired |
| | | private Api9116Rep api9116Rep; |
| | | @Autowired |
| | | private RedisUtil redisUtil; |
| | | |
| | | |
| | | @Async |
| | | public void syncData(String interfaceId, String dataStr){ |
| | | public void syncData(String interfaceId, String dataStr, String deptId, String outId){ |
| | | |
| | | ApiConfs apiConfs = apiConfsRep.getDataByDeptId(deptId); |
| | | if(null == apiConfs){ |
| | | log.error("-----未获取到库区信息配置,不解析---------"); |
| | | resultRedis(outId, ApiRespCode.R_500.getCode(), "未获取到库区信息配置,不解析"); |
| | | return; |
| | | } |
| | | try { |
| | | //单位信息 |
| | | if(SH2023Constant.SH_2023_API_CODE_3101.equals(interfaceId)){ |
| | | List<Api9109> list = JSONObject.parseArray(dataStr, Api9109.class); |
| | | if(null == list || list.isEmpty()){ |
| | | log.error("-----未获取到信息,不解析---------"); |
| | | resultRedis(outId, ApiRespCode.R_500.getCode(), "未获取到信息,不解析"); |
| | | return; |
| | | } |
| | | for (Api9109 apiData : list) { |
| | | apiData.setKqdm(apiConfs.getKqdm()); |
| | | apiData.setZhgxsj(new Date()); |
| | | api9109Rep.save(apiData); |
| | | } |
| | | log.info("-----单位信息解析完成={}-----", list); |
| | | //解析结果放入缓存 |
| | | resultRedis(outId, ApiRespCode.R_200.getCode(), "单位信息解析完成"); |
| | | } |
| | | |
| | | //单位信息 |
| | | if(SH2023Constant.SH_2023_API_CODE_3101.equals(interfaceId)){ |
| | | List<Api9109> list = JSONObject.parseArray(dataStr, Api9109.class); |
| | | api9109Rep.saveAll(list); |
| | | //收纳库信息 |
| | | if(SH2023Constant.SH_2023_API_CODE_3102.equals(interfaceId)){ |
| | | List<Api9110> list = JSONObject.parseArray(dataStr, Api9110.class); |
| | | if(null == list || list.isEmpty()){ |
| | | log.error("-----未获取到库区信息,不解析---------"); |
| | | resultRedis(outId, ApiRespCode.R_500.getCode(), "未获取到库区信息,不解析"); |
| | | return; |
| | | } |
| | | for (Api9110 apiData : list) { |
| | | apiData.setZhgxsj(new Date()); |
| | | api9110Rep.save(apiData); |
| | | } |
| | | log.info("-----库区信息解析完成={}-----", list); |
| | | //解析结果放入缓存 |
| | | resultRedis(outId, ApiRespCode.R_200.getCode(), "库区信息解析完成"); |
| | | } |
| | | |
| | | //仓房信息 |
| | | if(SH2023Constant.SH_2023_API_CODE_3103.equals(interfaceId)){ |
| | | List<Api9111> list = JSONObject.parseArray(dataStr, Api9111.class); |
| | | if(null == list || list.isEmpty()){ |
| | | log.error("-----未获取到仓房信息,不解析---------"); |
| | | resultRedis(outId, ApiRespCode.R_500.getCode(), "未获取到仓房信息,不解析"); |
| | | return; |
| | | } |
| | | for (Api9111 apiData : list) { |
| | | apiData.setZhgxsj(new Date()); |
| | | api9111Rep.save(apiData); |
| | | } |
| | | log.info("-----仓房信息解析完成={}-----", list); |
| | | //解析结果放入缓存 |
| | | resultRedis(outId, ApiRespCode.R_200.getCode(), "仓房信息解析完成"); |
| | | } |
| | | |
| | | //廒间信息 |
| | | if(SH2023Constant.SH_2023_API_CODE_3104.equals(interfaceId)){ |
| | | List<Api9112> list = JSONObject.parseArray(dataStr, Api9112.class); |
| | | if(null == list || list.isEmpty()){ |
| | | log.error("-----未获取到仓房信息,不解析---------"); |
| | | resultRedis(outId, ApiRespCode.R_500.getCode(), "未获取到仓房信息,不解析"); |
| | | return; |
| | | } |
| | | for (Api9112 apiData : list) { |
| | | apiData.setKqdm(apiConfs.getKqdm()); |
| | | apiData.setZhgxsj(new Date()); |
| | | api9112Rep.save(apiData); |
| | | } |
| | | log.info("-----廒间信息解析完成={}-----", list); |
| | | //解析结果放入缓存 |
| | | resultRedis(outId, ApiRespCode.R_200.getCode(), "廒间信息解析完成"); |
| | | } |
| | | |
| | | //货位信息 |
| | | if(SH2023Constant.SH_2023_API_CODE_3105.equals(interfaceId)){ |
| | | List<Api9113> list = JSONObject.parseArray(dataStr, Api9113.class); |
| | | if(null == list || list.isEmpty()){ |
| | | log.error("-----未获取到货位信息,不解析---------"); |
| | | resultRedis(outId, ApiRespCode.R_500.getCode(), "未获取到仓房信息,不解析"); |
| | | return; |
| | | } |
| | | for (Api9113 apiData : list) { |
| | | apiData.setKqdm(apiConfs.getKqdm()); |
| | | apiData.setZhgxsj(new Date()); |
| | | api9113Rep.save(apiData); |
| | | } |
| | | log.info("-----货位信息解析完成={}-----", list); |
| | | //解析结果放入缓存 |
| | | resultRedis(outId, ApiRespCode.R_200.getCode(), "货位信息解析完成"); |
| | | } |
| | | |
| | | //粮食入库信息 |
| | | if(SH2023Constant.SH_2023_API_CODE_3201.equals(interfaceId)){ |
| | | List<Api9114> list = JSONObject.parseArray(dataStr, Api9114.class); |
| | | if(null == list || list.isEmpty()){ |
| | | log.error("-----未获取到粮食入库信息,不解析---------"); |
| | | resultRedis(outId, ApiRespCode.R_500.getCode(), "未获取到仓房信息,不解析"); |
| | | return; |
| | | } |
| | | for (Api9114 apiData : list) { |
| | | apiData.setKqdm(apiConfs.getKqdm()); |
| | | apiData.setZhgxsj(new Date()); |
| | | api9114Rep.save(apiData); |
| | | } |
| | | log.info("-----粮食入库信息解析完成={}-----", list); |
| | | //解析结果放入缓存 |
| | | resultRedis(outId, ApiRespCode.R_200.getCode(), "粮食入库信息解析完成"); |
| | | } |
| | | |
| | | //来粮检验信息 |
| | | if(SH2023Constant.SH_2023_API_CODE_3202.equals(interfaceId)){ |
| | | List<Api9115> list = JSONObject.parseArray(dataStr, Api9115.class); |
| | | if(null == list || list.isEmpty()){ |
| | | log.error("-----未获取到来粮检验信息,不解析---------"); |
| | | resultRedis(outId, ApiRespCode.R_500.getCode(), "未获取到仓房信息,不解析"); |
| | | return; |
| | | } |
| | | for (Api9115 apiData : list) { |
| | | apiData.setKqdm(apiConfs.getKqdm()); |
| | | apiData.setZhgxsj(new Date()); |
| | | api9115Rep.save(apiData); |
| | | } |
| | | log.info("-----来粮检验信息解析完成={}-----", list); |
| | | //解析结果放入缓存 |
| | | resultRedis(outId, ApiRespCode.R_200.getCode(), "来粮检验信息解析完成"); |
| | | } |
| | | |
| | | //粮食收购基础信息 |
| | | if(SH2023Constant.SH_2023_API_CODE_3203.equals(interfaceId)){ |
| | | List<Api9116> list = JSONObject.parseArray(dataStr, Api9116.class); |
| | | if(null == list || list.isEmpty()){ |
| | | log.error("-----未获取到粮食收购基础信息,不解析---------"); |
| | | resultRedis(outId, ApiRespCode.R_500.getCode(), "未获取到仓房信息,不解析"); |
| | | return; |
| | | } |
| | | for (Api9116 apiData : list) { |
| | | apiData.setKqdm(apiConfs.getKqdm()); |
| | | apiData.setZhgxsj(new Date()); |
| | | api9116Rep.save(apiData); |
| | | } |
| | | log.info("-----粮食收购基础信息解析完成={}-----", list); |
| | | //解析结果放入缓存 |
| | | resultRedis(outId, ApiRespCode.R_200.getCode(), "粮食收购基础信息解析完成"); |
| | | } |
| | | } catch (Exception e) { |
| | | log.error("-----接口{}解析报错,错误原因={}-----", interfaceId, e.toString()); |
| | | resultRedis(outId, ApiRespCode.R_500.getCode(), "-----接口"+interfaceId+"解析报错,错误原因="+e.toString()+"-----"); |
| | | } |
| | | |
| | | //收纳库信息 |
| | | if(SH2023Constant.SH_2023_API_CODE_3102.equals(interfaceId)){ |
| | | List<Api9110> list = JSONObject.parseArray(dataStr, Api9110.class); |
| | | api9110Rep.saveAll(list); |
| | | } |
| | | |
| | | /** |
| | | * 从缓存中获取解析结果 |
| | | * @param dataStr |
| | | * @return |
| | | */ |
| | | public ApiResp getResult(String dataStr){ |
| | | List<ResultDto> list = JSONObject.parseArray(dataStr, ResultDto.class); |
| | | if(null == list || list.isEmpty()){ |
| | | log.error("-----outId为空---------"); |
| | | return new ApiResp(ApiRespCode.R_500.getCode(), "outId为空,无法获取解析结果!"); |
| | | } |
| | | |
| | | //仓房信息 |
| | | if(SH2023Constant.SH_2023_API_CODE_3103.equals(interfaceId)){ |
| | | List<Api9111> list = JSONObject.parseArray(dataStr, Api9111.class); |
| | | api9111Rep.saveAll(list); |
| | | ApiResp result = (ApiResp)redisUtil.get(list.get(0).getOutId()); |
| | | if(null == result){ |
| | | log.error("-----未获取到outId对应的解析结果---------"); |
| | | return new ApiResp(ApiRespCode.R_500.getCode(), "未获取到outId对应的解析结果!"); |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | //廒间信息 |
| | | if(SH2023Constant.SH_2023_API_CODE_3104.equals(interfaceId)){ |
| | | List<Api9112> list = JSONObject.parseArray(dataStr, Api9112.class); |
| | | api9112Rep.saveAll(list); |
| | | } |
| | | |
| | | //货位信息 |
| | | if(SH2023Constant.SH_2023_API_CODE_3105.equals(interfaceId)){ |
| | | List<Api9113> list = JSONObject.parseArray(dataStr, Api9113.class); |
| | | api9113Rep.saveAll(list); |
| | | } |
| | | |
| | | //粮食入库信息 |
| | | if(SH2023Constant.SH_2023_API_CODE_3201.equals(interfaceId)){ |
| | | List<Api9114> list = JSONObject.parseArray(dataStr, Api9114.class); |
| | | api9114Rep.saveAll(list); |
| | | } |
| | | |
| | | //来粮检验信息 |
| | | if(SH2023Constant.SH_2023_API_CODE_3202.equals(interfaceId)){ |
| | | List<Api9115> list = JSONObject.parseArray(dataStr, Api9115.class); |
| | | api9115Rep.saveAll(list); |
| | | } |
| | | |
| | | //粮食收购基础信息 |
| | | if(SH2023Constant.SH_2023_API_CODE_3203.equals(interfaceId)){ |
| | | List<Api9116> list = JSONObject.parseArray(dataStr, Api9116.class); |
| | | api9116Rep.saveAll(list); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * |
| | | * 结果存入缓存 |
| | | * @param outId |
| | | * @param code |
| | | * @param msg |
| | | */ |
| | | public void resultRedis(String outId, String code, String msg){ |
| | | ApiResp result = new ApiResp(code, msg); |
| | | //结果存入缓存2小时 |
| | | redisUtil.set(outId, result, 60*60*2); |
| | | } |
| | | } |