fix(quartz): 1.增加超时重试机制2.数据条数不统一时删除拉取到的数据
| | |
| | | import com.integrated.zyyt.enetity.business.Zyyt; |
| | | import com.integrated.zyyt.util.ZyytUtil; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.jdbc.core.BatchPreparedStatementSetter; |
| | | import org.springframework.jdbc.core.JdbcTemplate; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.transaction.interceptor.TransactionAspectSupport; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.sql.Date; |
| | |
| | | |
| | | @Service |
| | | @Slf4j |
| | | @Transactional(rollbackFor = Exception.class) |
| | | //@Transactional(rollbackFor = Exception.class) |
| | | public class ZyytService { |
| | | @Resource |
| | | private JdbcTemplate jdbcTemplate; |
| | |
| | | |
| | | Zyyt<StationInfo> stationInfoService = ZyytUtil.getBusinessEntity("STATIONINFO", yestDay); |
| | | // String exeSql = "merge into STATIONINFO A USING" + " (select ? V_JGBH from dual ) C " + "ON(A.V_JGBH=C.V_JGBH) " + "when matched then " + "update SET A.V_SFMC=?,A.V_SFDM=?,A.V_DSDM=?,A.V_DSMC=?,A.V_QXDM=?,A.V_XSMC=?,A.V_TDJGBH=?,A.V_TDJGMC=?,A.V_JGMC=?,A.V_LXRXM=?,A.V_LXDH=?,A.V_SJHM=?,A.V_LXDZ=?,A.ISCOUNTRY=?,A.C_WDLX =?,A.C_YZBM=?,A.V_YYWDBH=?,A.V_YYWDMC=?,A.V_GPSJD=?,A.V_GPSWD=?,A.YLGZDID =?,A.YLGZDMC=?,A.V_STATUS=?,A.D_SQRQ=?,A.D_SPRQ=?" + "when not matched then " + "insert(A.V_SFMC,A.V_SFDM,A.V_DSDM,A.V_DSMC,A.V_QXDM,A.V_XSMC,A.V_TDJGBH,A.V_TDJGMC,A.V_JGBH,A.V_JGMC,A.V_LXRXM,A.V_LXDH,A.V_SJHM,A.V_LXDZ,A.ISCOUNTRY,A.C_WDLX ,A.C_YZBM,A.V_YYWDBH,A.V_YYWDMC,A.V_GPSJD,A.V_GPSWD,A.YLGZDID ,A.YLGZDMC,A.V_STATUS,A.D_SQRQ,A.D_SPRQ) values " + "(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"; |
| | | String exeSql = "merge into STATIONINFO A USING" + " (select ? V_JGBH, ? CPBD_LOAD_DT from dual ) C " + "ON(A.V_JGBH=C.V_JGBH) " + "when matched then " + "update SET A.CPBD_LOAD_DT=?, A.V_SFMC=?,A.V_SFDM=?,A.V_DSDM=?,A.V_DSMC=?,A.V_QXDM=?,A.V_XSMC=?,A.V_TDJGBH=?,A.V_TDJGMC=?,A.V_JGMC=?,A.V_LXRXM=?,A.V_LXDH=?,A.V_SJHM=?,A.V_LXDZ=?,A.ISCOUNTRY=?,A.C_WDLX =?,A.C_YZBM=?,A.V_YYWDBH=?,A.V_YYWDMC=?,A.V_GPSJD=?,A.V_GPSWD=?,A.YLGZDID =?,A.YLGZDMC=?,A.V_STATUS=?,A.D_SQRQ=?,A.D_SPRQ=? where A.CPBD_LOAD_DT < C.CPBD_LOAD_DT " + "when not matched then " + "insert(A.V_SFMC,A.V_SFDM,A.V_DSDM,A.V_DSMC,A.V_QXDM,A.V_XSMC,A.V_TDJGBH,A.V_TDJGMC,A.V_JGBH,A.V_JGMC,A.V_LXRXM,A.V_LXDH,A.V_SJHM,A.V_LXDZ,A.ISCOUNTRY,A.C_WDLX ,A.C_YZBM,A.V_YYWDBH,A.V_YYWDMC,A.V_GPSJD,A.V_GPSWD,A.YLGZDID ,A.YLGZDMC,A.V_STATUS,A.D_SQRQ,A.D_SPRQ,A.CPBD_LOAD_DT) values " + "(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"; |
| | | |
| | | Long recordId = stationInfoService.insertRecord("STATIONINFO", batchNo); |
| | | String exeSql = "merge into STATIONINFO A USING" + " (select ? V_JGBH, ? CPBD_LOAD_DT from dual ) C " + "ON(A.V_JGBH=C.V_JGBH) " + "when matched then " + "update SET A.CPBD_LOAD_DT=?, A.V_SFMC=?,A.V_SFDM=?,A.V_DSDM=?,A.V_DSMC=?,A.V_QXDM=?,A.V_XSMC=?,A.V_TDJGBH=?,A.V_TDJGMC=?,A.V_JGMC=?,A.V_LXRXM=?,A.V_LXDH=?,A.V_SJHM=?,A.V_LXDZ=?,A.ISCOUNTRY=?,A.C_WDLX =?,A.C_YZBM=?,A.V_YYWDBH=?,A.V_YYWDMC=?,A.V_GPSJD=?,A.V_GPSWD=?,A.YLGZDID =?,A.YLGZDMC=?,A.V_STATUS=?,A.D_SQRQ=?,A.D_SPRQ=? where A.CPBD_LOAD_DT < C.CPBD_LOAD_DT " + "when not matched then " + "insert(A.V_SFMC,A.V_SFDM,A.V_DSDM,A.V_DSMC,A.V_QXDM,A.V_XSMC,A.V_TDJGBH,A.V_TDJGMC,A.V_JGBH,A.V_JGMC,A.V_LXRXM,A.V_LXDH,A.V_SJHM,A.V_LXDZ,A.ISCOUNTRY,A.C_WDLX ,A.C_YZBM,A.V_YYWDBH,A.V_YYWDMC,A.V_GPSJD,A.V_GPSWD,A.YLGZDID ,A.YLGZDMC,A.V_STATUS,A.D_SQRQ,A.D_SPRQ,A.CPBD_LOAD_DT) values " + "(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"; |
| | | Long totalSize = 0L; |
| | | |
| | | int pageNum = 0; |
| | | int pageSize = 1000; |
| | | // int pageSize = 1000; |
| | | |
| | | //设置回滚点 |
| | | Object savePoint = TransactionAspectSupport.currentTransactionStatus().createSavepoint(); |
| | | // Object savePoint = TransactionAspectSupport.currentTransactionStatus().createSavepoint(); |
| | | |
| | | try { |
| | | // 查询总数 |
| | | Long totalElements = ZyytUtil.getApiTotalElements("STATIONINFO", yestDay); |
| | | Long totalPages = ZyytUtil.calcPages(totalElements, pageSize); |
| | | log.info("共{}条数据,每页{}条,可分{}页,", totalElements, pageSize, totalPages); |
| | | if (totalElements == null || totalElements == 0) { |
| | | log.info("共0条数据"); |
| | | stationInfoService.updateRecord(recordId, 0, totalSize, "未拉取到数据"); |
| | | return; |
| | | } |
| | | Long totalPages = ZyytUtil.calcPages(totalElements, PAGESIZE); |
| | | log.info("共{}条数据,每页{}条,可分{}页,", totalElements, PAGESIZE, totalPages); |
| | | for (pageNum = 0; pageNum <= totalPages - 1; pageNum++) { |
| | | ZyytDataResult<StationInfo> zyytDataResult = stationInfoService.getData(pageNum, pageSize); |
| | | ZyytDataResult<StationInfo> zyytDataResult = stationInfoService.getData(pageNum, PAGESIZE); |
| | | |
| | | List<StationInfo> stationInfoList = zyytDataResult.getContent(); |
| | | log.info("第{}次获取,本次获取到{}条数据", pageNum + 1, zyytDataResult.getContentSize()); |
| | |
| | | }); |
| | | } catch (Exception e) { |
| | | log.error("设置参数值报错了"); |
| | | e.printStackTrace(); |
| | | // e.printStackTrace(); |
| | | log.error(e.getMessage()); |
| | | //手工回滚异常 |
| | | TransactionAspectSupport.currentTransactionStatus().rollbackToSavepoint(savePoint); |
| | | // TransactionAspectSupport.currentTransactionStatus().rollbackToSavepoint(savePoint); |
| | | stationInfoService.updateRecord(recordId, 1, 0L, e.getMessage()); |
| | | return; |
| | | } |
| | |
| | | log.info("···········中邮易通 {}站点信息 任务执行完毕···········", yestDay); |
| | | } |
| | | |
| | | private int PAGESIZE = 1000; |
| | | |
| | | @Value("${pullData.pageSize}") |
| | | public void setTRYNUM(Integer pageSize) { |
| | | pageSize = pageSize <= 0 ? 1000 : pageSize; |
| | | this.PAGESIZE = pageSize; |
| | | } |
| | | |
| | | //社会快递日报表 |
| | | |
| | |
| | | log.info("YYZT_T_SHKDRB 的 批次{}正在运行", batchNo); |
| | | return; |
| | | } |
| | | Zyyt<YyztTShkdrb> stationInfoService = ZyytUtil.getBusinessEntity("YYZT_T_SHKDRB", date); |
| | | Long recordId = stationInfoService.insertRecord("YYZT_T_SHKDRB", batchNo); |
| | | |
| | | // 删除已有批次数据 |
| | | String delSql = "delete from YYZT_T_SHKDRB where BATCH_NO='" + batchNo + "'"; |
| | | jdbcTemplate.update(delSql); |
| | | |
| | | Zyyt<YyztTShkdrb> stationInfoService = ZyytUtil.getBusinessEntity("YYZT_T_SHKDRB", date); |
| | | Long recordId = stationInfoService.insertRecord("YYZT_T_SHKDRB", batchNo); |
| | | Long totalSize = 0L; |
| | | Long totalElements = 0L; |
| | | |
| | | //设置回滚点 |
| | | Object savePoint = TransactionAspectSupport.currentTransactionStatus().createSavepoint(); |
| | | // Object savePoint = TransactionAspectSupport.currentTransactionStatus().createSavepoint(); |
| | | try { |
| | | int pageNum = 0; |
| | | int pageSize = 1000; |
| | | // int pageSize = 1000; |
| | | |
| | | String batchInsertSql = "INSERT INTO YYZT_T_SHKDRB (\"V_SFDM\",\"V_SFMC\",\"V_DSDM\",\"V_DSMC\",\"V_QXDM\",\"V_XSMC\",\"V_TDJGBH\",\"V_TDJGMC\",\"V_JGBH\",\"V_JGMC\",\"D_RBRQ\",\"N_ZGYZLJS\",\"N_ZGYZQJS\",\"N_SHKDLJS\",\"N_SHKDQJS\",\"N_ZTLJS\",\"N_ZTQJS\",\"N_YTLJS\",\"N_YTQJS\",\"N_STLJS\",\"N_STQJS\",\"N_BSLJS\",\"N_BSQJS\",\"N_YDLJS\",\"N_YDQJS\",\"N_YFLJS\",\"N_YFQJS\",\"N_JDLJS\",\"N_JDQJS\",\"N_JTLJS\",\"N_JTQJS\",\"N_TTLJS\",\"N_TTQJS\",\"N_DBLJS\",\"N_DBQJS\",\"N_DNLJS\",\"N_DNQJS\",\"N_FWLJS\",\"N_FWQJS\",\"N_YSLJS\",\"N_YSQJS\",\"N_QTLJS\",\"N_QTQJS\",\"RESERVED1\",\"RESERVED2\",\"RESERVED3\",\"RESERVED4\",\"BATCH_NO\") VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"; |
| | | |
| | | // 查询总数 |
| | | Long totalElements = ZyytUtil.getApiTotalElements("YYZT_T_SHKDRB", date); |
| | | Long totalPages = ZyytUtil.calcPages(totalElements, pageSize); |
| | | log.info("社会快递日报表(YYZT_T_SHKDRB) 共{}条数据,每页{}条,可分{}页,", totalElements, pageSize, totalPages); |
| | | totalElements = ZyytUtil.getApiTotalElements("YYZT_T_SHKDRB", date); |
| | | if (totalElements == null || totalElements == 0) { |
| | | log.info("共0条数据"); |
| | | stationInfoService.updateRecord(recordId, 0, totalSize, "未拉取到数据"); |
| | | return; |
| | | } |
| | | Long totalPages = ZyytUtil.calcPages(totalElements, PAGESIZE); |
| | | log.info("社会快递日报表(YYZT_T_SHKDRB) 共{}条数据,每页{}条,可分{}页,", totalElements, PAGESIZE, totalPages); |
| | | |
| | | for (pageNum = 0; pageNum <= totalPages - 1; pageNum++) { |
| | | ZyytDataResult<YyztTShkdrb> zyytDataResult = stationInfoService.getData(pageNum, pageSize); |
| | | ZyytDataResult<YyztTShkdrb> zyytDataResult = stationInfoService.getData(pageNum, PAGESIZE); |
| | | |
| | | List<YyztTShkdrb> stationInfoList = zyytDataResult.getContent(); |
| | | totalSize += zyytDataResult.getContentSize(); |
| | |
| | | } catch (Exception e) { |
| | | log.error(e.getMessage()); |
| | | //手工回滚异常 |
| | | TransactionAspectSupport.currentTransactionStatus().rollbackToSavepoint(savePoint); |
| | | // TransactionAspectSupport.currentTransactionStatus().rollbackToSavepoint(savePoint); |
| | | stationInfoService.updateRecord(recordId, 1, 0L, e.getMessage()); |
| | | return; |
| | | } |
| | | } |
| | | } |
| | | } catch ( |
| | | Exception e) { |
| | | } catch (Exception e) { |
| | | log.error(e.getMessage()); |
| | | stationInfoService.updateRecord(recordId, 1, 0L, e.getMessage()); |
| | | return; |
| | | } |
| | | if (totalSize != totalElements) { |
| | | log.error("拉取到的总条数:{}与接口显示的总条数:{}不一致,删除拉取到数据! ", totalSize, totalElements); |
| | | jdbcTemplate.update(delSql); |
| | | stationInfoService.updateRecord(recordId, 1, 0L, "拉取到的总条数与接口显示的总条数不一致!"); |
| | | return; |
| | | } |
| | | stationInfoService.updateRecord(recordId, 0, totalSize, null); |
| | |
| | | log.info("YYZT_T_DJTJB 的 批次{}正在运行", batchNo); |
| | | return; |
| | | } |
| | | Zyyt<YyztTDjtjb> stationInfoService = ZyytUtil.getBusinessEntity("YYZT_T_DJTJB", date); |
| | | Long recordId = stationInfoService.insertRecord("YYZT_T_DJTJB", batchNo); |
| | | |
| | | // 删除已有批次数据 |
| | | String delSql = "delete from YYZT_T_DJTJB where BATCH_NO='" + batchNo + "'"; |
| | | jdbcTemplate.update(delSql); |
| | | |
| | | Zyyt<YyztTDjtjb> stationInfoService = ZyytUtil.getBusinessEntity("YYZT_T_DJTJB", date); |
| | | Long recordId = stationInfoService.insertRecord("YYZT_T_DJTJB", batchNo); |
| | | |
| | | Long totalSize = 0L; |
| | | Long totalElements = 0L; |
| | | //设置回滚点 |
| | | Object savePoint = TransactionAspectSupport.currentTransactionStatus().createSavepoint(); |
| | | // Object savePoint = TransactionAspectSupport.currentTransactionStatus().createSavepoint(); |
| | | |
| | | try { |
| | | int pageNum = 0; |
| | | int pageSize = 1000; |
| | | // int pageSize = 1000; |
| | | |
| | | String batchInsertSql = "INSERT INTO YYZT_T_DJTJB (\"V_SFDM\", \"V_SFMC\", \"V_DSDM\", \"V_DSMC\", \"V_QXDM\", \"V_XSMC\", \"V_TDJGBH\", \"V_JGBH\", \"V_JGMC\", \"D_RBRQ\", \"V_YLGZDID\", \"V_YLGZDMC\", \"N_SJYWL\", \"N_TKYWL\", \"N_BKYEL\", \"N_SJZJE\", \"N_TKSR\", \"N_BKSR\", \"BATCH_NO\") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; |
| | | // 查询总数 |
| | | Long totalElements = ZyytUtil.getApiTotalElements("YYZT_T_DJTJB", date); |
| | | Long totalPages = ZyytUtil.calcPages(totalElements, pageSize); |
| | | log.info("共{}条数据,每页{}条,可分{}页,", totalElements, pageSize, totalPages); |
| | | totalElements = ZyytUtil.getApiTotalElements("YYZT_T_DJTJB", date); |
| | | if (totalElements == null || totalElements == 0) { |
| | | log.info("共0条数据"); |
| | | stationInfoService.updateRecord(recordId, 0, totalSize, "未拉取到数据"); |
| | | return; |
| | | } |
| | | Long totalPages = ZyytUtil.calcPages(totalElements, PAGESIZE); |
| | | log.info("共{}条数据,每页{}条,可分{}页,", totalElements, PAGESIZE, totalPages); |
| | | |
| | | for (pageNum = 0; pageNum <= totalPages - 1; pageNum++) { |
| | | ZyytDataResult<YyztTDjtjb> zyytDataResult = stationInfoService.getData(pageNum, pageSize); |
| | | ZyytDataResult<YyztTDjtjb> zyytDataResult = stationInfoService.getData(pageNum, PAGESIZE); |
| | | List<YyztTDjtjb> djtjbList = zyytDataResult.getContent(); |
| | | totalSize += zyytDataResult.getContentSize(); |
| | | log.info("第{}次获取,本次获取到{}条数据", pageNum + 1, zyytDataResult.getContentSize()); |
| | |
| | | } catch (Exception e) { |
| | | log.error(e.getMessage()); |
| | | //手工回滚异常 |
| | | TransactionAspectSupport.currentTransactionStatus().rollbackToSavepoint(savePoint); |
| | | // TransactionAspectSupport.currentTransactionStatus().rollbackToSavepoint(savePoint); |
| | | stationInfoService.updateRecord(recordId, 1, 0L, e.getMessage()); |
| | | return; |
| | | } |
| | |
| | | stationInfoService.updateRecord(recordId, 1, 0L, e.getMessage()); |
| | | return; |
| | | } |
| | | |
| | | if (totalSize != totalElements) { |
| | | log.error("拉取到的总条数:{}与接口显示的总条数:{}不一致,删除拉取到数据! ", totalSize, totalElements); |
| | | jdbcTemplate.update(delSql); |
| | | stationInfoService.updateRecord(recordId, 1, 0L, "拉取到的总条数与接口显示的总条数不一致!"); |
| | | return; |
| | | } |
| | | stationInfoService.updateRecord(recordId, 0, totalSize, null); |
| | | log.info("···········中邮易通 代寄统计表 -- [{}] 任务执行完毕···········", date); |
| | | } |
| | |
| | | package com.integrated.zyyt.util; |
| | | |
| | | import cn.hutool.core.convert.Convert; |
| | | import cn.hutool.core.io.IORuntimeException; |
| | | import cn.hutool.http.HttpRequest; |
| | | import cn.hutool.http.HttpResponse; |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.integrated.zyyt.ZyytConstant; |
| | |
| | | import com.integrated.zyyt.enetity.business.ZyytTShkdrb; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.http.HttpStatus; |
| | | import org.springframework.jdbc.core.JdbcTemplate; |
| | | import org.springframework.stereotype.Component; |
| | | import org.springframework.util.CollectionUtils; |
| | | import org.springframework.util.StringUtils; |
| | | |
| | | import java.time.LocalDate; |
| | | import java.util.HashMap; |
| | |
| | | @Component |
| | | @Slf4j |
| | | public class ZyytUtil { |
| | | /** |
| | | * 超时重试次数 |
| | | */ |
| | | private static int TRYNUM = 3; |
| | | |
| | | @Value("${pullData.tryNum}") |
| | | public void setTRYNUM(Integer tryNum) { |
| | | tryNum = tryNum <= 0 ? 3 : tryNum; |
| | | this.TRYNUM = tryNum; |
| | | } |
| | | |
| | | /** |
| | | * http超时时间设置 |
| | | */ |
| | | private static int TRYTIMEOUT = 3 * 1000; |
| | | |
| | | @Value("${pullData.tryTimeOut}") |
| | | public void setTRYTIMEOUT(Integer tryTimeOut) { |
| | | this.TRYTIMEOUT = tryTimeOut * 1000; |
| | | } |
| | | |
| | | private static JdbcTemplate jdbcTemplate; |
| | | |
| | | @Autowired |
| | |
| | | params.put("ciphertext", eciphrtext); |
| | | params.put("client", client); |
| | | params.put("secret", secret); |
| | | |
| | | String httpResult = HttpRequest.post(url) |
| | | HttpRequest httpRequest = HttpRequest.post(url) |
| | | .form(params) |
| | | .header("X-EOS-SourceSysKey", sourceSysKey) |
| | | .execute() |
| | | .body(); |
| | | .timeout(TRYTIMEOUT); |
| | | log.info("超时时间为{}毫秒", TRYTIMEOUT); |
| | | log.info("url =》》{}", url); |
| | | log.info("params =》》{}", params); |
| | | HttpResponse httpResponse = null; |
| | | int tryNumTemp = 1; |
| | | boolean isTimeOut = false; |
| | | try { |
| | | httpResponse = httpRequest.execute(); |
| | | } catch (IORuntimeException e) { |
| | | // e.printStackTrace(); |
| | | // 超时重试 |
| | | isTimeOut = true; |
| | | log.error(e.getMessage()); |
| | | } |
| | | while (tryNumTemp <= TRYNUM && isTimeOut) { |
| | | log.error("请求接口超时,进行第{}次重试!", tryNumTemp); |
| | | try { |
| | | httpResponse = httpRequest.execute(); |
| | | isTimeOut = false; |
| | | } catch (IORuntimeException e) { |
| | | // e.printStackTrace(); |
| | | // 超时重试 |
| | | log.error(e.getMessage()); |
| | | } |
| | | tryNumTemp++; |
| | | } |
| | | if (httpResponse == null) { |
| | | log.error("请求接口超时,请联系接口提供方!"); |
| | | return null; |
| | | } |
| | | int responseStatus = httpResponse.getStatus(); |
| | | if (HttpStatus.NOT_FOUND.value() == responseStatus) { |
| | | log.error("接口API异常,请联系接口提供方!HttpStatus:{}", responseStatus); |
| | | return null; |
| | | } else if (HttpStatus.OK.value() != responseStatus) { |
| | | log.error("请求接口状态有误!HttpStatus:{}", responseStatus); |
| | | return null; |
| | | } |
| | | String httpResult = httpResponse.body(); |
| | | log.info("result =》》{}", httpResult); |
| | | try { |
| | | return JSONObject.parseObject(httpResult, TokenResult.class); |
| | | } catch (Exception e) { |
| | | log.error(e.getMessage()); |
| | | log.error("Token解析失败!", e.getMessage()); |
| | | return null; |
| | | } |
| | | } |
| | |
| | | * @return |
| | | */ |
| | | public static <T> ZyytDataResult<T> getData(String url, String bearToken, String sourceSysKey, JSONObject params, int pageNum, int pageSize, Class<T> tClass) { |
| | | if (StringUtils.isEmpty(bearToken)) { |
| | | log.error("bearToken不能为null!"); |
| | | return null; |
| | | } |
| | | HashMap header = new HashMap(); |
| | | header.put("Authorization", "Bearer " + bearToken); |
| | | header.put("X-EOS-SourceSysKey", sourceSysKey); |
| | |
| | | log.info("url =》》{}", trueUrl); |
| | | log.info("header=>>bearToken》》{}\r\nSourceSysKey=>>{}", bearToken, sourceSysKey); |
| | | log.info("params =》》{}", params); |
| | | String httpResult = HttpRequest.post(trueUrl) |
| | | HttpRequest httpRequest = HttpRequest.post(trueUrl) |
| | | .addHeaders(header) |
| | | .contentType("application/json") |
| | | .body(params.toJSONString()) |
| | | .timeout(1000 * 50) |
| | | .execute() |
| | | .body(); |
| | | .timeout(TRYTIMEOUT); |
| | | log.info("超时时间为{}毫秒", TRYTIMEOUT); |
| | | HttpResponse httpResponse = null; |
| | | |
| | | int tryNumTemp = 1; |
| | | boolean isTimeOut = false; |
| | | try { |
| | | httpResponse = httpRequest.execute(); |
| | | } catch (IORuntimeException e) { |
| | | // 超时重试 |
| | | isTimeOut = true; |
| | | log.error(e.getMessage()); |
| | | } |
| | | while (tryNumTemp <= TRYNUM && isTimeOut) { |
| | | log.error("请求接口超时,进行第{}次重试!", tryNumTemp); |
| | | try { |
| | | httpResponse = httpRequest.execute(); |
| | | isTimeOut = false; |
| | | } catch (IORuntimeException e) { |
| | | // e.printStackTrace(); |
| | | // 超时重试 |
| | | log.error(e.getMessage()); |
| | | } |
| | | tryNumTemp++; |
| | | } |
| | | if (httpResponse == null) { |
| | | log.error("请求接口超时,请联系接口提供方!"); |
| | | return null; |
| | | } |
| | | int responseStatus = httpResponse.getStatus(); |
| | | if (HttpStatus.NOT_FOUND.value() != responseStatus) { |
| | | log.error("接口API异常,请联系接口提供方!HttpStatus:{}", responseStatus); |
| | | return null; |
| | | } else if (HttpStatus.OK.value() != responseStatus) { |
| | | log.error("请求接口状态有误!HttpStatus:{}", responseStatus); |
| | | return null; |
| | | } |
| | | String httpResult = httpResponse.body(); |
| | | try { |
| | | JSONObject respJson = JSONObject.parseObject(httpResult); |
| | | log.info("开始解析结果4"); |
| | | Long contentSize = respJson.getLong("contentSize"); |
| | | if (contentSize != null && contentSize.compareTo(0L) > 0) { |
| | | JSONArray dataArray = respJson.getJSONArray("content"); |
| | | log.info("开始解析结果5"); |
| | | List<T> content = dataArray.toJavaList(tClass); |
| | | respJson.remove("content"); |
| | | log.info("开始解析结果6"); |
| | | ZyytDataResult<T> zyytDataResult = respJson.toJavaObject(ZyytDataResult.class); |
| | | zyytDataResult.setContent(content); |
| | | return zyytDataResult; |
| | |
| | | } |
| | | } catch (Exception e) { |
| | | log.error("getData 异常"); |
| | | e.printStackTrace(); |
| | | // e.printStackTrace(); |
| | | return null; |
| | | } |
| | | } |
| | |
| | | String sql = "SELECT*FROM (SELECT*FROM ZYYT_RECORD WHERE BATCH_NO='" + getBatchNo(date) + "' AND TABLE_NAME='" + tableName + "' ORDER BY START_TIME DESC) tmp WHERE ROWNUM<=1"; |
| | | Map<String, Object> map = null; |
| | | try { |
| | | map = jdbcTemplate.queryForMap(sql); |
| | | // map = jdbcTemplate.queryForMap(sql); |
| | | List<Map<String, Object>> maps = jdbcTemplate.queryForList(sql); |
| | | if (CollectionUtils.isEmpty(maps)) { |
| | | return map; |
| | | } |
| | | map = maps.get(0); |
| | | } catch (Exception e) { |
| | | log.error("sql=={} 查询发生了异常,可能因为没有查询到数据", sql); |
| | | log.error(e.getMessage()); |
| | |
| | | public static Long getApiTotalElements(String tableName, LocalDate date) { |
| | | Zyyt businessEntity = getBusinessEntity(tableName, date); |
| | | ZyytDataResult zyytDataResult = businessEntity.getData(0, 1); |
| | | if (zyytDataResult == null) { |
| | | log.info("拉取数据失败,拉取返回值为null"); |
| | | return 0l; |
| | | } |
| | | log.info("总共拉取到数据{}条", zyytDataResult.getTotalElements()); |
| | | return zyytDataResult.getTotalElements(); |
| | | } |
| | |
| | | driver-class-name: oracle.jdbc.driver.OracleDriver |
| | | #url: jdbc:oracle:thin:@127.0.0.1:1521/helowin |
| | | # url: jdbc:oracle:thin:@121.36.40.27:11521/helowin |
| | | url: jdbc:oracle:thin:@1.14.252.104:7101/ORCL |
| | | url: jdbc:oracle:thin:@1.14.252.33:7101/ORCL |
| | | username: zhfwpt |
| | | password: Zhfwpt_2021 |
| | | hikari: |
| | |
| | | #站点信息表 |
| | | station: https://10.225.71.10:9092 |
| | | |
| | | pullData: |
| | | tryNum: 3 |
| | | # 单位秒 |
| | | tryTimeOut: 5 |
| | | pageSize: 1000 |
| | | |
| | |
| | | djtjb: http://10.225.71.10:9090 |
| | | #站点信息表 |
| | | station: https://10.225.71.10:9092 |
| | | |
| | | pullData: |
| | | tryNum: 5 |
| | | # 单位秒 |
| | | tryTimeOut: 5 |
| | | pageSize: 1000 |