ZttKSchedule.java 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. package com.onemap.analyse.task;
  2. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  3. import com.onemap.analyse.domain.Ztzt.ZttMbkDTO;
  4. import com.onemap.analyse.domain.Ztzt.ZttkDTO;
  5. import com.onemap.analyse.mapper.ztzt.ZttKMapper;
  6. import com.onemap.analyse.mapper.ztzt.ZttMbKMapper;
  7. import com.onemap.common.core.utils.StringUtils;
  8. import org.springframework.beans.factory.annotation.Value;
  9. import org.springframework.scheduling.annotation.Async;
  10. import org.springframework.scheduling.annotation.Scheduled;
  11. import org.springframework.stereotype.Component;
  12. import javax.annotation.Resource;
  13. import java.io.File;
  14. import java.net.URLEncoder;
  15. import java.text.SimpleDateFormat;
  16. import java.util.Date;
  17. import java.util.HashMap;
  18. import java.util.List;
  19. import java.util.Map;
  20. /**
  21. * @ClassName ZttKSchedule
  22. * @Description TODO
  23. * @Author 北京四维空间数码科技有限公司
  24. * @Date 2025/10/9 8:30
  25. * @Version 1.0
  26. */
  27. @Component
  28. public class ZttKSchedule
  29. {
  30. //间隔时间 单位ms
  31. public static final long TIME_INTERVAL = 1 * 20000;
  32. //制图图片拼接时间戳格式
  33. private SimpleDateFormat timeFormat = new SimpleDateFormat("yyyyMMddHHmmss");
  34. @Resource
  35. private ZttKMapper zttKMapper;
  36. @Resource
  37. private ZttMbKMapper zttmbkmapper;
  38. // @Value("${yzt.ztzt}")
  39. // private String ztztUrl;
  40. //专题图出图文件夹 需要已创建好的 后面会拼接编制时间文件夹加主标题文件名
  41. @Value("${Ztt.exportLocation}")
  42. private String exportLocation;
  43. @Value("${Ztt.functionId}")
  44. private String functionId;
  45. @Value("${Hgxfx.temp}")
  46. private String temp;
  47. /**
  48. * Scheduled 定时器参数
  49. * cron表达式:指定任务在特定时间执行
  50. * fixedDelay:表示上一次任务执行完成后多久再执行,参数类型long,单位:ms
  51. * fixedDelayString:与fixedDelay一样,只是参数类型是String
  52. * fixedRate:表示按一定的频率执行任务,参数类型long,单位:ms 如: fixedRate(5000),表示这个定时器任务每5秒执行一次
  53. * fixedRateString:与fixedRate一样,只是参数类型变为String
  54. * initialDelay:表示延迟多久再第一次执行任务,参数类型为long ,单位:ms
  55. * initialDelayString:与initialDelay一样,只是参数类型String
  56. */
  57. @Async("taskExecutor")
  58. @Scheduled(fixedDelay = TIME_INTERVAL)
  59. public void ZtztStatus()
  60. {
  61. try {
  62. QueryWrapper<ZttkDTO> wrapper = new QueryWrapper<ZttkDTO>();
  63. wrapper.eq("ztzt", "0"); //查找没做的专题图
  64. wrapper.orderByAsc("cjsj");
  65. //每次只操作一条记录,按照时间正序排列
  66. List<ZttkDTO> ress = zttKMapper.selectList(wrapper);
  67. if (ress.size() > 0)
  68. {
  69. ZttkDTO res = ress.get(0);
  70. //更新数据库信息 开始时间 制图状态
  71. res.setKssj(new Date());
  72. res.setZtzt(1);
  73. QueryWrapper<ZttkDTO> update = new QueryWrapper<ZttkDTO>();
  74. update.eq("bsm", res.getBsm());
  75. zttKMapper.update(res, update);
  76. //查询模板位置
  77. QueryWrapper<ZttMbkDTO> mb = new QueryWrapper<ZttMbkDTO>();
  78. mb.eq("bsm", res.getMbbsm());
  79. ZttMbkDTO mbDto = zttmbkmapper.selectOne(mb);
  80. String mbposition = mbDto.getMbwj();
  81. //判断目标文件夹是否存在,不存在则创建
  82. String curTime = timeFormat.format(new Date());
  83. String newfile = res.getZzsj() + "\\" + res.getName() + curTime + ".jpg";
  84. String jpgpath = exportLocation + "\\" + newfile;
  85. File file = new File(jpgpath);
  86. if (!file.getParentFile().exists()) {
  87. file.getParentFile().mkdirs();
  88. }
  89. //执行python脚本 封装参数
  90. Map<String, String> params = new HashMap<>();
  91. params.put("bsm", res.getBsm());
  92. params.put("mbposition", mbposition);
  93. params.put("jpgpath", jpgpath);
  94. try{
  95. String result = PythonExecute.Run(functionId, params);
  96. Date now = new Date();
  97. if (!StringUtils.isEmpty(result) && result.contains("OK")) {//成功
  98. res.setZtzt(2);
  99. res.setBz(result);
  100. res.setJssj(now);
  101. res.setZttwj(StringUtils.getFileStaticPath(jpgpath, temp));
  102. zttKMapper.update(res, update);
  103. }else{
  104. res.setJssj(now);
  105. res.setZtzt(3);
  106. res.setBz(result);
  107. QueryWrapper<ZttkDTO> update2 = new QueryWrapper<ZttkDTO>();
  108. update2.eq("bsm", res.getBsm());
  109. zttKMapper.update(res, update2);
  110. }
  111. //调用地址出图
  112. // String getUrl = ztztUrl + "" + res.getBsm()+"&mbposition="+ URLEncoder.encode(mbposition,"UTF-8")+"&jpgpath="+ URLEncoder.encode(jpgpath,"UTF-8")+"&newfile="+URLEncoder.encode(newfile,"UTF-8");
  113. // System.out.println("开始进行专题制图,调用地址" + getUrl);
  114. // String msg = HttpClientUtil.doGet(getUrl);
  115. // System.out.println("专题制图检查结果" + msg);
  116. // System.out.println("专题制图检查结果:" + res.getBsm() + "制图任务调用成果!!!!!!!! " + new Date().toString());
  117. }catch (Exception e){
  118. e.printStackTrace();
  119. res.setZtzt(3);
  120. res.setBz(e.getMessage());
  121. QueryWrapper<ZttkDTO> update2 = new QueryWrapper<ZttkDTO>();
  122. update2.eq("bsm", res.getBsm());
  123. zttKMapper.update(res, update2);
  124. }
  125. }
  126. } catch (Exception e) {
  127. e.printStackTrace();
  128. }
  129. }
  130. }