| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301 |
- package platform.modules.sys.task;
- import com.alibaba.fastjson.JSON;
- import com.alibaba.fastjson.JSONArray;
- import com.alibaba.fastjson.JSONObject;
- import com.alibaba.fastjson.parser.Feature;
- import com.alibaba.fastjson.serializer.SerializerFeature;
- import com.alibaba.fastjson.support.config.FastJsonConfig;
- import com.google.gson.GsonBuilder;
- import org.apache.commons.lang3.StringUtils;
- import org.springframework.beans.BeanUtils;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.beans.factory.annotation.Configurable;
- import org.springframework.core.env.Environment;
- import org.springframework.scheduling.annotation.EnableScheduling;
- import org.springframework.scheduling.annotation.Scheduled;
- import org.springframework.stereotype.Component;
- import platform.common.Constant;
- import platform.common.base.model.Dict;
- import platform.common.util.CommonUtils;
- import platform.common.util.DateUtil;
- import platform.common.util.HttpClientUtil;
- import platform.modules.area.MapAreaService;
- import platform.modules.build.entity.BuildingInfo;
- import platform.modules.build.entity.Company;
- import platform.modules.build.service.*;
- import platform.modules.company.entity.ProjectApplication;
- import platform.modules.company.service.ProjectApplicationService;
- import platform.modules.government.dao.PolicyDao;
- import platform.modules.government.dto.PolicyDetailDto;
- import platform.modules.government.dto.PolicyDto;
- import platform.modules.government.entity.CompanyReport;
- import platform.modules.government.entity.Policy;
- import platform.modules.government.entity.Project;
- import platform.modules.government.service.CompanyReportService;
- import platform.modules.government.service.PolicyService;
- import platform.modules.government.service.ProjectService;
- import platform.modules.sys.entity.SysConfig;
- import platform.modules.sys.service.SysConfigService;
- import scriptella.execution.EtlExecutor;
- import scriptella.execution.EtlExecutorException;
- import tk.mybatis.mapper.entity.Example;
- import javax.annotation.Resource;
- import java.io.File;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.PreparedStatement;
- import java.sql.Statement;
- import java.util.*;
- import java.util.concurrent.*;
- /**
- * Created by luohaifeng on 2017/11/4.
- */
- @Component
- @Configurable
- @EnableScheduling
- public class Task {
- @Autowired
- private ContractService contractService;
- @Autowired
- private BuildingInfoService buildingInfoService;
- @Autowired
- private FloorService floorService;
- @Autowired
- private CompanyReportService companyReportService;
- @Autowired
- private CompanyService companyService;
- @Autowired
- private FloorContractRelateService floorContractRelateService;
- @Autowired
- private MapAreaService mapAreaService;
- @Autowired
- private Environment environment;
- @Autowired
- private SysConfigService sysConfigService;
- @Scheduled(cron = "0 0/1 * * * ?") // 每分钟执行一次
- public void generateMap() throws Exception {
- //内网
- if (environment.getProperty("spring.profiles").equals(Constant.Environment.PROD_IN)) {
- System.out.println("执行Quartz生成地图定时器任务:" + new Date());
- mapAreaService.addIndustryPointByAttr(floorContractRelateService.findBuildLivesNotGenerateMap());
- }
- }
- @Scheduled(cron = "0 0/1 * * * ?") // 每分钟执行一次
- public void deleteMap() throws Exception {
- //内网
- if (environment.getProperty("spring.profiles").equals(Constant.Environment.PROD_IN)) {
- System.out.println("执行Quartz删除地图定时器任务:" + new Date());
- mapAreaService.deleteIndustryPointByUUID(floorContractRelateService.findBuildLivesGenerateMapAndDelete());
- }
- }
- /*@Scheduled(cron = "0 0/1 * * * ?") // 每分钟执行一次
- public void play() throws Exception {
- //外网
- if (environment.getProperty("spring.profiles").equals(Constant.Environment.PROD_OUT)||environment.getProperty("spring.profiles").equals(Constant.Environment.TEST)) {
- contractService.insertTenancy();
- System.out.println("执行Quartz定时器任务:" + new Date());
- }
- }*/
- @Scheduled(cron = "0 0/1 * * * ?") // 每分钟执行一次
- public void updateBuild() throws Exception {
- //外网
- if (environment.getProperty("spring.profiles").equals(Constant.Environment.PROD_OUT) || environment.getProperty("spring.profiles").equals(Constant.Environment.TEST)) {
- List<BuildingInfo> buildingInfoList = buildingInfoService.findListByIsUse();
- for (BuildingInfo buildingInfo : buildingInfoList) {
- if (floorService.sumIsUse(buildingInfo.getId()) == 0) {
- buildingInfo.setIs_use(false);
- buildingInfoService.updateIsUse(buildingInfo.getId());
- }
- }
- System.out.println("更新楼层是否可用:" + new Date());
- }
- }
- /*@Scheduled(cron = "0 0/1 * * * ?") // 每分钟执行一次
- public void checkEndContract() throws Exception {
- //外网
- if (environment.getProperty("spring.profiles").equals(Constant.Environment.PROD_OUT)||environment.getProperty("spring.profiles").equals(Constant.Environment.TEST)) {
- contractService.checkEndContract();
- System.out.println("更新合同到期信息:" + new Date());
- }
- }*/
- /*@Scheduled(cron = "0 0/1 * * * ?") // 每分钟执行一次
- public void checkStartContract() throws Exception {
- //外网
- if (environment.getProperty("spring.profiles").equals(Constant.Environment.PROD_OUT)) {
- contractService.checkStartContract();
- System.out.println("检查合同生效信息:" + new Date());
- }
- }*/
- @Scheduled(cron = "0 0 18 * * ?") // 每分钟执行一次
- public void insertCompanyReport() throws Exception {
- //外网
- if (environment.getProperty("spring.profiles").equals(Constant.Environment.PROD_OUT)) {
- ExecutorService threadPool = new ThreadPoolExecutor(
- 10,
- 20,
- 1L,
- TimeUnit.SECONDS,
- new LinkedBlockingDeque<>(),
- Executors.defaultThreadFactory(),
- new ThreadPoolExecutor.AbortPolicy());
- List<Company> companies = companyService.findCompanies();
- for (Company company : companies) {
- CompanyReport companyReport = new CompanyReport();
- companyReport.setStatus(Constant.CompanyReportStatus.NOT);
- companyReport.setReport_month(DateUtil.getCurrentMonth());
- companyReport.setReport_year(DateUtil.getCurrentYear());
- companyReport.setCompany_id(company.getId());
- companyReport.setCompany_name(company.getCompany_name());
- companyReport.setBuild_id(company.getBuild_id());
- threadPool.execute(() -> companyReportService.generateInsertReport(companyReport));
- }
- System.out.println("检查合同生效信息:" + new Date());
- }
- }
- public void work() throws Exception {
- System.out.println("执行调度任务:" + new Date());
- }
- @Scheduled(cron = "0/15 0 0 * * ?")
- public void getHoliday() {
- System.out.println("测试定时");
- String year = DateUtil.getCurrentDateString("yyyy");
- sysConfigService.addYearWorkDay(year);
- }
- @Autowired
- public HttpClientUtil httpClientUtil;
- @Resource
- private PolicyService policyService;
- @Scheduled(cron = "0 0 22 * * ?")
- public void SyncPolicyTask() throws Exception {
- //内网
- if (environment.getProperty("spring.profiles").equals(Constant.Environment.PROD_IN)) {
- String url1 = "http://snd.ideatob.com/mp/api/?apikey=snd_apis&at=2&page=1&pagesize=99999&lb=";
- String url2 = "http://snd.ideatob.com/mp/api/?apikey=snd_apis&at=6&bno=";
- String[] typeArr = {"1", "2", "3", "4"};
- policyService.deleteByWhere(null);
- List<Policy> list1 = new ArrayList<>();
- for (String type : typeArr) {
- String result = httpClientUtil.sendHttpGet(url1 + type);
- JSONObject obj = JSONObject.parseObject(result);
- String j = obj.getString("list");
- List<PolicyDto> list = JSONArray.parseArray(j, PolicyDto.class);
- for (PolicyDto policyDto : list) {
- if ("1".equals(type)) {
- policyDto.setType("country");
- }
- if ("2".equals(type)) {
- policyDto.setType("province");
- }
- if ("3".equals(type)) {
- policyDto.setType("city");
- }
- if ("4".equals(type)) {
- policyDto.setType("district");
- }
- String results = httpClientUtil.sendHttpGet(url2 + policyDto.getBno());
- JSONObject objs = JSONObject.parseObject(results);
- String rs = objs.getString("list");
- PolicyDetailDto policyDetailDto = JSONObject.parseObject(rs, PolicyDetailDto.class);
- policyDto.setMessage(policyDetailDto.getMessage());
- Policy policy = new Policy();
- BeanUtils.copyProperties(policyDto, policy);
- list1.add(policy);
- }
- }
- policyService.saveList(list1);
- }
- }
- @Scheduled(cron = "0 0 23 * * ?") // 每分钟执行一次
- public void EtlTask() throws Exception {
- //内网
- if (environment.getProperty("spring.profiles").equals(Constant.Environment.PROD_IN)) {
- System.out.println("执行Quartz定时器任务ETL:" + new Date());
- String classesPath = Thread.currentThread().getContextClassLoader().getResource("").getPath();
- String templateUrl = classesPath + "etl.xml";
- try {
- EtlExecutor.newExecutor(new File(templateUrl)).execute();
- } catch (EtlExecutorException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } //Execute etl.xml file
- }
- }
- @Autowired
- private ProjectApplicationService projectApplicationService;
- @Autowired
- private ProjectService projectService;
- @Scheduled(cron = "0 0 22 * * ?")
- public void CorrectApplicationType() throws Exception {
- String year = DateUtil.getCurrentDateString("yyyy");
- Example example = new Example(ProjectApplication.class);
- Example.Criteria criteria = example.createCriteria();
- criteria.andLike("apply_no", "%GY" + year + "%");
- List<ProjectApplication> projectApplicationList = projectApplicationService.selectByExample(example);
- example = new Example(Project.class);
- criteria = example.createCriteria();
- criteria.andEqualTo("project_year", year);
- List<Project> projectList = projectService.selectByExample(example);
- if (CommonUtils.isNotNull(projectApplicationList) && CommonUtils.isNotNull(projectList)) {
- for (ProjectApplication projectApplication : projectApplicationList) {
- for (Project project : projectList) {
- if (
- Objects.equals(projectApplication.getProject_name(), project.getProject_name())
- && projectApplication.getProject_id() != project.getId()
- ) {
- // System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
- // System.out.println(projectApplication.toString());
- // System.out.println("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<");
- projectApplication.setProject_id(project.getId());
- projectApplicationService.updateSelective(projectApplication);
- break;
- }
- }
- }
- }
- }
- }
|