Task.java 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  1. package platform.modules.sys.task;
  2. import com.alibaba.fastjson.JSON;
  3. import com.alibaba.fastjson.JSONArray;
  4. import com.alibaba.fastjson.JSONObject;
  5. import com.alibaba.fastjson.parser.Feature;
  6. import com.alibaba.fastjson.serializer.SerializerFeature;
  7. import com.alibaba.fastjson.support.config.FastJsonConfig;
  8. import com.google.gson.GsonBuilder;
  9. import org.apache.commons.lang3.StringUtils;
  10. import org.springframework.beans.BeanUtils;
  11. import org.springframework.beans.factory.annotation.Autowired;
  12. import org.springframework.beans.factory.annotation.Configurable;
  13. import org.springframework.core.env.Environment;
  14. import org.springframework.scheduling.annotation.EnableScheduling;
  15. import org.springframework.scheduling.annotation.Scheduled;
  16. import org.springframework.stereotype.Component;
  17. import platform.common.Constant;
  18. import platform.common.base.model.Dict;
  19. import platform.common.util.CommonUtils;
  20. import platform.common.util.DateUtil;
  21. import platform.common.util.HttpClientUtil;
  22. import platform.modules.area.MapAreaService;
  23. import platform.modules.build.entity.BuildingInfo;
  24. import platform.modules.build.entity.Company;
  25. import platform.modules.build.service.*;
  26. import platform.modules.company.entity.ProjectApplication;
  27. import platform.modules.company.service.ProjectApplicationService;
  28. import platform.modules.government.dao.PolicyDao;
  29. import platform.modules.government.dto.PolicyDetailDto;
  30. import platform.modules.government.dto.PolicyDto;
  31. import platform.modules.government.entity.CompanyReport;
  32. import platform.modules.government.entity.Policy;
  33. import platform.modules.government.entity.Project;
  34. import platform.modules.government.service.CompanyReportService;
  35. import platform.modules.government.service.PolicyService;
  36. import platform.modules.government.service.ProjectService;
  37. import platform.modules.sys.entity.SysConfig;
  38. import platform.modules.sys.service.SysConfigService;
  39. import scriptella.execution.EtlExecutor;
  40. import scriptella.execution.EtlExecutorException;
  41. import tk.mybatis.mapper.entity.Example;
  42. import javax.annotation.Resource;
  43. import java.io.File;
  44. import java.sql.Connection;
  45. import java.sql.DriverManager;
  46. import java.sql.PreparedStatement;
  47. import java.sql.Statement;
  48. import java.util.*;
  49. import java.util.concurrent.*;
  50. /**
  51. * Created by luohaifeng on 2017/11/4.
  52. */
  53. @Component
  54. @Configurable
  55. @EnableScheduling
  56. public class Task {
  57. @Autowired
  58. private ContractService contractService;
  59. @Autowired
  60. private BuildingInfoService buildingInfoService;
  61. @Autowired
  62. private FloorService floorService;
  63. @Autowired
  64. private CompanyReportService companyReportService;
  65. @Autowired
  66. private CompanyService companyService;
  67. @Autowired
  68. private FloorContractRelateService floorContractRelateService;
  69. @Autowired
  70. private MapAreaService mapAreaService;
  71. @Autowired
  72. private Environment environment;
  73. @Autowired
  74. private SysConfigService sysConfigService;
  75. @Scheduled(cron = "0 0/1 * * * ?") // 每分钟执行一次
  76. public void generateMap() throws Exception {
  77. //内网
  78. if (environment.getProperty("spring.profiles").equals(Constant.Environment.PROD_IN)) {
  79. System.out.println("执行Quartz生成地图定时器任务:" + new Date());
  80. mapAreaService.addIndustryPointByAttr(floorContractRelateService.findBuildLivesNotGenerateMap());
  81. }
  82. }
  83. @Scheduled(cron = "0 0/1 * * * ?") // 每分钟执行一次
  84. public void deleteMap() throws Exception {
  85. //内网
  86. if (environment.getProperty("spring.profiles").equals(Constant.Environment.PROD_IN)) {
  87. System.out.println("执行Quartz删除地图定时器任务:" + new Date());
  88. mapAreaService.deleteIndustryPointByUUID(floorContractRelateService.findBuildLivesGenerateMapAndDelete());
  89. }
  90. }
  91. /*@Scheduled(cron = "0 0/1 * * * ?") // 每分钟执行一次
  92. public void play() throws Exception {
  93. //外网
  94. if (environment.getProperty("spring.profiles").equals(Constant.Environment.PROD_OUT)||environment.getProperty("spring.profiles").equals(Constant.Environment.TEST)) {
  95. contractService.insertTenancy();
  96. System.out.println("执行Quartz定时器任务:" + new Date());
  97. }
  98. }*/
  99. @Scheduled(cron = "0 0/1 * * * ?") // 每分钟执行一次
  100. public void updateBuild() throws Exception {
  101. //外网
  102. if (environment.getProperty("spring.profiles").equals(Constant.Environment.PROD_OUT) || environment.getProperty("spring.profiles").equals(Constant.Environment.TEST)) {
  103. List<BuildingInfo> buildingInfoList = buildingInfoService.findListByIsUse();
  104. for (BuildingInfo buildingInfo : buildingInfoList) {
  105. if (floorService.sumIsUse(buildingInfo.getId()) == 0) {
  106. buildingInfo.setIs_use(false);
  107. buildingInfoService.updateIsUse(buildingInfo.getId());
  108. }
  109. }
  110. System.out.println("更新楼层是否可用:" + new Date());
  111. }
  112. }
  113. /*@Scheduled(cron = "0 0/1 * * * ?") // 每分钟执行一次
  114. public void checkEndContract() throws Exception {
  115. //外网
  116. if (environment.getProperty("spring.profiles").equals(Constant.Environment.PROD_OUT)||environment.getProperty("spring.profiles").equals(Constant.Environment.TEST)) {
  117. contractService.checkEndContract();
  118. System.out.println("更新合同到期信息:" + new Date());
  119. }
  120. }*/
  121. /*@Scheduled(cron = "0 0/1 * * * ?") // 每分钟执行一次
  122. public void checkStartContract() throws Exception {
  123. //外网
  124. if (environment.getProperty("spring.profiles").equals(Constant.Environment.PROD_OUT)) {
  125. contractService.checkStartContract();
  126. System.out.println("检查合同生效信息:" + new Date());
  127. }
  128. }*/
  129. @Scheduled(cron = "0 0 18 * * ?") // 每分钟执行一次
  130. public void insertCompanyReport() throws Exception {
  131. //外网
  132. if (environment.getProperty("spring.profiles").equals(Constant.Environment.PROD_OUT)) {
  133. ExecutorService threadPool = new ThreadPoolExecutor(
  134. 10,
  135. 20,
  136. 1L,
  137. TimeUnit.SECONDS,
  138. new LinkedBlockingDeque<>(),
  139. Executors.defaultThreadFactory(),
  140. new ThreadPoolExecutor.AbortPolicy());
  141. List<Company> companies = companyService.findCompanies();
  142. for (Company company : companies) {
  143. CompanyReport companyReport = new CompanyReport();
  144. companyReport.setStatus(Constant.CompanyReportStatus.NOT);
  145. companyReport.setReport_month(DateUtil.getCurrentMonth());
  146. companyReport.setReport_year(DateUtil.getCurrentYear());
  147. companyReport.setCompany_id(company.getId());
  148. companyReport.setCompany_name(company.getCompany_name());
  149. companyReport.setBuild_id(company.getBuild_id());
  150. threadPool.execute(() -> companyReportService.generateInsertReport(companyReport));
  151. }
  152. System.out.println("检查合同生效信息:" + new Date());
  153. }
  154. }
  155. public void work() throws Exception {
  156. System.out.println("执行调度任务:" + new Date());
  157. }
  158. @Scheduled(cron = "0/15 0 0 * * ?")
  159. public void getHoliday() {
  160. System.out.println("测试定时");
  161. String year = DateUtil.getCurrentDateString("yyyy");
  162. sysConfigService.addYearWorkDay(year);
  163. }
  164. @Autowired
  165. public HttpClientUtil httpClientUtil;
  166. @Resource
  167. private PolicyService policyService;
  168. @Scheduled(cron = "0 0 22 * * ?")
  169. public void SyncPolicyTask() throws Exception {
  170. //内网
  171. if (environment.getProperty("spring.profiles").equals(Constant.Environment.PROD_IN)) {
  172. String url1 = "http://snd.ideatob.com/mp/api/?apikey=snd_apis&at=2&page=1&pagesize=99999&lb=";
  173. String url2 = "http://snd.ideatob.com/mp/api/?apikey=snd_apis&at=6&bno=";
  174. String[] typeArr = {"1", "2", "3", "4"};
  175. policyService.deleteByWhere(null);
  176. List<Policy> list1 = new ArrayList<>();
  177. for (String type : typeArr) {
  178. String result = httpClientUtil.sendHttpGet(url1 + type);
  179. JSONObject obj = JSONObject.parseObject(result);
  180. String j = obj.getString("list");
  181. List<PolicyDto> list = JSONArray.parseArray(j, PolicyDto.class);
  182. for (PolicyDto policyDto : list) {
  183. if ("1".equals(type)) {
  184. policyDto.setType("country");
  185. }
  186. if ("2".equals(type)) {
  187. policyDto.setType("province");
  188. }
  189. if ("3".equals(type)) {
  190. policyDto.setType("city");
  191. }
  192. if ("4".equals(type)) {
  193. policyDto.setType("district");
  194. }
  195. String results = httpClientUtil.sendHttpGet(url2 + policyDto.getBno());
  196. JSONObject objs = JSONObject.parseObject(results);
  197. String rs = objs.getString("list");
  198. PolicyDetailDto policyDetailDto = JSONObject.parseObject(rs, PolicyDetailDto.class);
  199. policyDto.setMessage(policyDetailDto.getMessage());
  200. Policy policy = new Policy();
  201. BeanUtils.copyProperties(policyDto, policy);
  202. list1.add(policy);
  203. }
  204. }
  205. policyService.saveList(list1);
  206. }
  207. }
  208. @Scheduled(cron = "0 0 23 * * ?") // 每分钟执行一次
  209. public void EtlTask() throws Exception {
  210. //内网
  211. if (environment.getProperty("spring.profiles").equals(Constant.Environment.PROD_IN)) {
  212. System.out.println("执行Quartz定时器任务ETL:" + new Date());
  213. String classesPath = Thread.currentThread().getContextClassLoader().getResource("").getPath();
  214. String templateUrl = classesPath + "etl.xml";
  215. try {
  216. EtlExecutor.newExecutor(new File(templateUrl)).execute();
  217. } catch (EtlExecutorException e) {
  218. // TODO Auto-generated catch block
  219. e.printStackTrace();
  220. } //Execute etl.xml file
  221. }
  222. }
  223. @Autowired
  224. private ProjectApplicationService projectApplicationService;
  225. @Autowired
  226. private ProjectService projectService;
  227. @Scheduled(cron = "0 0 22 * * ?")
  228. public void CorrectApplicationType() throws Exception {
  229. String year = DateUtil.getCurrentDateString("yyyy");
  230. Example example = new Example(ProjectApplication.class);
  231. Example.Criteria criteria = example.createCriteria();
  232. criteria.andLike("apply_no", "%GY" + year + "%");
  233. List<ProjectApplication> projectApplicationList = projectApplicationService.selectByExample(example);
  234. example = new Example(Project.class);
  235. criteria = example.createCriteria();
  236. criteria.andEqualTo("project_year", year);
  237. List<Project> projectList = projectService.selectByExample(example);
  238. if (CommonUtils.isNotNull(projectApplicationList) && CommonUtils.isNotNull(projectList)) {
  239. for (ProjectApplication projectApplication : projectApplicationList) {
  240. for (Project project : projectList) {
  241. if (
  242. Objects.equals(projectApplication.getProject_name(), project.getProject_name())
  243. && projectApplication.getProject_id() != project.getId()
  244. ) {
  245. // System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
  246. // System.out.println(projectApplication.toString());
  247. // System.out.println("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<");
  248. projectApplication.setProject_id(project.getId());
  249. projectApplicationService.updateSelective(projectApplication);
  250. break;
  251. }
  252. }
  253. }
  254. }
  255. }
  256. }