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 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 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 list1 = new ArrayList<>(); for (String type : typeArr) { String result = httpClientUtil.sendHttpGet(url1 + type); JSONObject obj = JSONObject.parseObject(result); String j = obj.getString("list"); List 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 projectApplicationList = projectApplicationService.selectByExample(example); example = new Example(Project.class); criteria = example.createCriteria(); criteria.andEqualTo("project_year", year); List 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; } } } } } }