DriverTask.java 30.3 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031
package com.trash.quartz.task;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;

import javax.swing.Spring;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import com.google.gson.reflect.TypeToken;
import com.trash.activiti.service.IActTaskService;
import com.trash.business.domain.CompanyCredit;
import com.trash.business.domain.DriverCredit;
import com.trash.business.domain.SupervisionTrack;
import com.trash.business.domain.TruckCredit;
import com.trash.business.mapper.CompanyCreditMapper;
import com.trash.business.service.ICompanyCreditService;
import com.trash.business.service.IDriverCreditService;
import com.trash.business.service.ISupervisionThreestepService;
import com.trash.business.service.ISupervisionTrackService;
import com.trash.business.service.ITruckActivateService;
import com.trash.business.service.ITruckCreditService;
import com.trash.caseOffline.domain.CaseOffline;
import com.trash.caseOffline.mapper.CaseOfflineMapper;
import com.trash.casefile.domain.KafkaCompensation;
import com.trash.casefile.domain.ReplyApprovalProcess;
import com.trash.casefile.domain.ViolationCaseFile;
import com.trash.casefile.kafka.Consumer;
import com.trash.casefile.mapper.KafkaCompensationMapper;
import com.trash.casefile.mapper.ReplyApprovalProcessMapper;
import com.trash.casefile.mapper.ViolationCaseFileMapper;
import com.trash.casefile.service.IViolationCaseFileService;
import com.trash.common.config.trashConfig;
import com.trash.common.core.redis.RedisCache;
import com.trash.common.utils.LogUtils;
import com.trash.common.utils.RemoteServerUtils;
import com.trash.common.utils.SecurityUtils;
import com.trash.common.utils.file.FileUploadUtils;
import com.trash.common.utils.spring.SpringUtils;
import com.trash.common.utils.util.PostSms;
import com.trash.common.utils.vo.mt.JsonSmsSend;
import com.trash.common.utils.vo.mt.Mobile;
import com.trash.office.domain.LogisticsManagement;
import com.trash.office.domain.UploadFile;
import com.trash.office.mapper.LogisticsManagementMapper;
import com.trash.office.mapper.UploadFileMapper;
import com.trash.workflow.service.IWorkflowService;

/**
 * 定时任务调度测试
 * 
 * @author trash
 */
@Component("DriverTask")
public class DriverTask {

	String TOKEN;

	SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
	/** 系统基础配置 */
	@Autowired
	private trashConfig trashConfig;

	@Autowired
	private RedisCache redisCache;

	public void getUpCase() {
		JSONArray array = RemoteServerUtils.getCaseList();
		Map map = new HashMap<>();
		List<String> ids = new ArrayList<String>();

		if (array != null && array.size() > 0) {
			for (Object object : array) {
				JSONObject json = (JSONObject) object;
				try {
					ViolationCaseFile caseFile = new ViolationCaseFile(json);

					for (Object fileObj : json.getJSONArray("attchList")) {

						JSONObject fileJSON = (JSONObject) fileObj;
						UploadFile uploadFile = new UploadFile();
						uploadFile.setTableName("violation_case_file");
						uploadFile.setTableNumber(caseFile.getId().toString());
						uploadFile.setFileName(fileJSON.getString("attchFileName"));
						uploadFile.setFilePath(fileJSON.getString("attchFilePath"));

						SpringUtils.getBean(UploadFileMapper.class).insertUploadFile(uploadFile);
					}

					SpringUtils.getBean(ViolationCaseFileMapper.class).insertViolationCaseFile(caseFile);

					ids.add(caseFile.getId());

				} catch (BeansException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}

			}

			map.put("taskIds", ids);
			map.put("taskType", "Q2");
			RemoteServerUtils.updateUpCase(map);
		}

	}

	public void getUpCaseState() {

		getCaseStateIntoDB("/api/thirdApi/query/urgeList", "urgeUser", "urgeDesc", "urgeTime", "Q5");

		getCaseStateIntoDB("/api/thirdApi/query/superviseList", "supUser", "supDesc", "supTime", "Q4");

		JSONArray array = RemoteServerUtils.getUpCaseResult();
		Map map = new HashMap<>();
		List<String> ids = new ArrayList<String>();

		if (array != null && array.size() > 0) {
			for (Object object : array) {
				JSONObject json = (JSONObject) object;

				ViolationCaseFile casefile = SpringUtils.getBean(ViolationCaseFileMapper.class)
						.selectViolationCaseFileById(json.getString("thirdCaseId"));

				if (casefile == null) {
					continue;
				} else {

					Date d = new Date(json.getString("reportTime"));

					ids.add(json.getString("acceptId"));

					ReplyApprovalProcess rap = new ReplyApprovalProcess();
					rap.setTableName("workflow_casefile:" + json.getString("thirdCaseId"));
					rap.setReplyPeople("综管服");
					rap.setReply(json.getString("replyContent"));
					rap.setReplyTime(new Date(json.getString("handleTime")));

					JSONArray images = json.getJSONArray("attchList");
					String path = "";
					try {
						for (Object obj : images) {
							JSONObject img = (JSONObject) obj;
							path += img.getString("attchFilePath") + ",";
						}
					} catch (Exception e) {
						e.printStackTrace();
					}
					rap.setReplyImg(path.substring(0, path.length() - 1));
				}
			}

			map.put("taskIds", ids);
			map.put("taskType", "Q1");
			RemoteServerUtils.updateUpCase(map);
		}

	}

	private void getCaseStateIntoDB(String url, String arg0, String arg1, String arg2, String type) {
		try {

			JSONArray array = RemoteServerUtils.getUpCaseState(url);
			Map map = new HashMap<>();
			List<String> ids = new ArrayList<String>();

			if (array != null && array.size() > 0) {
				SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
				for (Object object : array) {
					JSONObject json = (JSONObject) object;

					ViolationCaseFile caseFile = new ViolationCaseFile();

					caseFile.setNumber(json.getString("evtId"));

					List<ViolationCaseFile> list = SpringUtils.getBean(ViolationCaseFileMapper.class)
							.selectViolationCaseFileList(caseFile);

					if (list.size() == 0) {
						continue;
					}

					ReplyApprovalProcess rap = new ReplyApprovalProcess();
					rap.setTableName("workflow_casefile:" + list.get(0).getId());
					rap.setReplyPeople(json.getString(arg0));
					rap.setReply(json.getString(arg1));
					try {
						rap.setReplyTime(sdf.parse(json.getString(arg2)));
					} catch (ParseException e) {

						rap.setReplyTime(new Date());

						e.printStackTrace();
					}

					SpringUtils.getBean(ReplyApprovalProcessMapper.class).insertReplyApprovalProcess(rap);

					ids.add(json.getString("taskId"));
				}

				map.put("taskIds", ids);
				map.put("taskType", type);
				RemoteServerUtils.updateUpCase(map);
			}

		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	Map<String, String> paramsMap = new HashMap<String, String>();

	public void createTrackData() {

		File file = new File("./settings.txt");

		String params = "2 1 10 2 1 10 2 1 10 2 1 10 2 1 10 2 1 10 2 1 10 2 1 10";

		if (!file.exists()) {
			try {
				file.createNewFile();

				FileOutputStream fos = new FileOutputStream(file);

				fos.write(params.getBytes());
				fos.flush();

				fos.close();

			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		} else {
			try {
				FileInputStream fis = new FileInputStream(file);

				byte[] bs = new byte[fis.available()];

				fis.read(bs);

				params = new String(bs);

			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}

		}

		String[] arr = params.split(" ");

		for (int i = 0; i < 8; i++) {
			paramsMap.put("type_" + i + "_timeout", arr[i * 3]);
			paramsMap.put("type_" + i + "_season", arr[i * 3 + 1]);
			paramsMap.put("type_" + i + "_pect", arr[i * 3 + 2]);
		}

		JSONArray areas = redisCache.getCacheObject("areaList");
		Map<String, String> area = new HashMap<>();

		for (Object object : areas) {
			JSONObject json = (JSONObject) object;
			area.put(json.getString("code"), json.getString("name"));
		}

		try {

			int type = 5;
			LogisticsManagement logisticsManagement = new LogisticsManagement();

			Date d = new Date();

			d.setMonth(d.getMonth() - (Integer.parseInt(paramsMap.get("type_" + type + "_season")) * 3));
			d.setDate(0);
			d.setHours(23);
			d.setMinutes(59);
			d.setSeconds(59);

			logisticsManagement.setCreateTime(d);

			List<LogisticsManagement> logs = SpringUtils.getBean(LogisticsManagementMapper.class)
					.selectLogisticsManagementList(logisticsManagement);

			Collections.shuffle(logs);

			double pect = Double.parseDouble(paramsMap.get("type_" + type + "_pect")) / 100;

			logs = logs.subList(0, (int) (logs.size() * pect));

			for (LogisticsManagement l : logs) {

				String title = (l.getType().equals("0") ? "用章申请" : l.getType().equals("1") ? "物品申请" : "采购申请");

				insertData(l.getId() + "", title, type, "综合管理部", l.getDeptName());
			}

		} catch (Exception e) {
			e.printStackTrace();
		}

		try {

			int type = 6;
			CaseOffline caseOffline = new CaseOffline();

			Date d = new Date();

			d.setMonth(d.getMonth() - (Integer.parseInt(paramsMap.get("type_" + type + "_season")) * 3));
			d.setDate(0);
			d.setHours(23);
			d.setMinutes(59);
			d.setSeconds(59);

			caseOffline.setCreateTime(d);

			List<CaseOffline> logs = SpringUtils.getBean(CaseOfflineMapper.class).selectCaseOfflineList(caseOffline);

			Collections.shuffle(logs);

			double pect = Double.parseDouble(paramsMap.get("type_" + type + "_pect")) / 100;

			logs = logs.subList(0, (int) (logs.size() * pect));

			for (CaseOffline l : logs) {
				insertData(l.getId() + "", "电子交办案卷:" + l.getSiteName(), type, "治理事务部", area.get(l.getPlace()));
			}

		} catch (Exception e) {
			e.printStackTrace();
		}

		try {

			int type = 7;
			ViolationCaseFile caseOffline = new ViolationCaseFile();

			Date d = new Date();

			d.setMonth(d.getMonth() - (Integer.parseInt(paramsMap.get("type_" + type + "_season")) * 3));
			d.setDate(0);
			d.setHours(23);
			d.setMinutes(59);
			d.setSeconds(59);

			caseOffline.setCreateTime(d);

			List<ViolationCaseFile> logs = SpringUtils.getBean(ViolationCaseFileMapper.class)
					.selectViolationCaseFileList(caseOffline);

			Collections.shuffle(logs);

			double pect = Double.parseDouble(paramsMap.get("type_" + type + "_pect")) / 100;

			logs = logs.subList(0, (int) (logs.size() * pect));

			for (ViolationCaseFile l : logs) {
				insertData(l.getId() + "", "违规案卷:" + l.getProjectName(), type, "科技信息部", l.getOwningRegion());
			}

		} catch (Exception e) {
			e.printStackTrace();
		}

		Gson g = new Gson();

		JSONArray array;

		array = redisCache.getCacheObject("truckList");// 车辆
		if (array != null && array.size() > 0) {

			int type = 4;

			List<JSONObject> list = ShuffleData(g, array, type);

			for (JSONObject json : list) {
				try {
					insertData(json.getString("id"), json.getString("licenseplateNo"), type, "行业事务部",
							json.getString("areaName"));
				} catch (Exception e) {
					e.printStackTrace();
				}
			}

		}

		array = redisCache.getCacheObject("contractList");// 合同
		if (array != null && array.size() > 0) {

			int type = 3;

			List<JSONObject> list = ShuffleData(g, array, type);

			for (JSONObject json : list) {

				try {
					insertData(json.getString("id"), json.getString("constructionSiteName"), type, "综合管理部",
							area.get(json.getString("earthSiteAreaCode")));
				} catch (Exception e) {
					e.printStackTrace();
				}
			}

		}

		array = redisCache.getCacheObject("companyList");// 公司
		if (array != null && array.size() > 0) {
			int type = 2;

			List<JSONObject> list = ShuffleData(g, array, type);

			for (JSONObject json : list) {
				try {
					insertData(json.getString("id"), json.getString("name"), type, "行业事务部",
							area.get(json.getString("areaCode")));
				} catch (Exception e) {
					e.printStackTrace();
				}
			}

		}

		array = redisCache.getCacheObject("constructionList");// 工地

		if (array != null && array.size() > 0) {

			int type = 0;

			List<JSONObject> list = ShuffleData(g, array, type);

			for (JSONObject json : list) {
				try {
					insertData(json.getString("id"), json.getString("name"), type, "勘察事务部",
							area.get(json.getString("areaCode").split("\\.")[0]));
				} catch (Exception e) {
					e.printStackTrace();
				}

			}
		}

		array = redisCache.getCacheObject("earthSitesList"); // 消纳场

		if (array != null && array.size() > 0) {

			int type = 1;

			List<JSONObject> list = ShuffleData(g, array, type);

			for (JSONObject json : list) {
				try {
					insertData(json.getString("id"), json.getString("name"), type, "消纳事务部",
							area.get(json.getString("areaCode")));
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		}

	}

	public List ShuffleData(Gson g, JSONArray array, int type) {
		List<JSONObject> list = g.fromJson(array.toJSONString(), new TypeToken<List<JSONObject>>() {
		}.getType());

		Date d = new Date();

		d.setMonth(d.getMonth() - (Integer.parseInt(paramsMap.get("type_" + type + "_season")) * 3));
		d.setDate(0);
		d.setHours(23);
		d.setMinutes(59);
		d.setSeconds(59);

		try {
			list = list.parallelStream().filter(p -> {

				SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
				String editTime = p.getString("editedAt");
				String createdTime = p.getString("createdAt");
				long newTime = 0;
				try {
					if (editTime == null) {
						if (createdTime == null) {
							return false;
						} else {
							newTime = simpleDateFormat.parse(p.getString("createdAt")).getTime();
						}
					} else {
						newTime = simpleDateFormat.parse(p.getString("editedAt")).getTime();
					}
				} catch (Exception e) {
					e.printStackTrace();
				}
				return d.getTime() < newTime;

			}).collect(Collectors.toList());
		} catch (Exception e) {
			e.printStackTrace();
		}

		Collections.shuffle(list);

		double pect = Double.parseDouble(paramsMap.get("type_" + type + "_pect")) / 100;

		list = list.subList(0, (int) (list.size() * pect));

		return list;
	}

	public void insertData(String id, String name, int type, String dept, String place) {
		try {
			SupervisionTrack track = new SupervisionTrack();
			track.setObjectId(id);
			track.setTitle(name);
			track.setType(type);
			track.setCreateTime(new Date());
			track.setCreateBy("长沙市建筑垃圾智慧监管平台");
			track.setDept(dept);
			track.setPlace(place);
			SpringUtils.getBean(ISupervisionTrackService.class).insertSupervisionTrack(track);

		} catch (Exception e) {
			e.printStackTrace();
		}

	}

	public void checkCredit() {

		if (RemoteServerUtils.remote == null) {
			RemoteServerUtils.remote = trashConfig.getRemotePath();
		}
		if (TOKEN == null) {
			TOKEN = trashConfig.getToken();
		}

		LogUtils.getBlock("=================== checkCredit 定时器执行 当前时间:      " + simpleDateFormat.format(new Date()));

		try {
			checkTruckActive();
		} catch (Exception e) {
			e.printStackTrace();
		}

	}

	@SuppressWarnings("deprecation")
	private void checkTruckActive() {
		if (TOKEN == null) {
			TOKEN = trashConfig.getToken();
		}
		try {
			SpringUtils.getBean(ISupervisionThreestepService.class).checkDataToActiveTruck(TOKEN);
		} catch (Exception e) {
			// TODO: handle exception
		}

	}

	private void checkDriverCredit() {

		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		if (RemoteServerUtils.remote == null) {
			RemoteServerUtils.remote = trashConfig.getRemotePath();
		}
		if (TOKEN == null) {
			TOKEN = trashConfig.getToken();
		}

		JSONArray drivers = RemoteServerUtils.getDriverList(TOKEN);

		for (Object object : drivers) {

			JSONObject json = (JSONObject) object;

			try {
				if (sdf.parse(json.getString("endAt")).getTime() < sdf.parse(sdf.format(new Date())).getTime()
						|| sdf.parse(json.getString("qualificationCertValidEndAt")).getTime() < sdf
								.parse(sdf.format(new Date())).getTime()) {
					DriverCredit driver = new DriverCredit();

					driver.setIdNumber(json.getString("identityNo"));
					driver.setName(json.getString("name"));
					driver.setCreateBy("长沙市建筑垃圾智慧监管平台");
					driver.setReason("证件过期");
					driver.setTime(new Date());
					driver.setStatus(0L);
					driver.setObjectId(json.getString("id"));

					SpringUtils.getBean(IDriverCreditService.class).insertDriverCredit(driver);
				}
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}

		}

	}

	@SuppressWarnings({ "unchecked", "rawtypes" })
	private void checkTruckCredit() {

		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		Map map = new HashMap<>();
		map.put("size", 9999);
		map.put("valid", 0);
		map.put("page", 1);

		JSONArray trucks = RemoteServerUtils.getTruckList(map, TOKEN);

		List<Map> listParam = new ArrayList<Map>();

		if (trucks != null) {
			for (Object jsonObject : trucks) {
				JSONObject truck = (JSONObject) jsonObject;

				try {
					if (sdf.parse(truck.getString("transportCertValid")).getTime() < sdf.parse(sdf.format(new Date()))
							.getTime()
							|| sdf.parse(truck.getString("licenseValid")).getTime() < sdf.parse(sdf.format(new Date()))
									.getTime()) {

						TruckCredit truckCredit = new TruckCredit();
						truckCredit.setTime(new Date());
						truckCredit.setCreateBy("长沙市建筑垃圾智慧监管平台");
						truckCredit.setReason("道路运输证有效期:" + truck.getString("transportCertValid") + " 行驶证有效期:"
								+ truck.getString("licenseValid") + ",证件过期");
						truckCredit.setLostCredit(1L);
						truckCredit.setObjectId(truck.getString("id"));
						truckCredit.setLicensePlate(truck.getString("licenseplateNo"));
						truckCredit.setCompanyId(truck.getString("companyName"));
						truckCredit.setStatus(0L);

						Map param = new HashMap<>();

						param.put("id", truck.getString("id"));
						param.put("creditStatus", 1);

						listParam.add(param);

						SpringUtils.getBean(ITruckCreditService.class).insertTruckCredit(truckCredit, 0);
					}
				} catch (BeansException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} catch (ParseException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} catch (Exception e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}

			if (listParam.size() > 0)
				RemoteServerUtils.updateTruckList(listParam, TOKEN);

		}

	}

	public void checkCompanyCredit() {
		try {
			checkTruckCredit();
		} catch (Exception e) {
			e.printStackTrace();
		}

		try {
			checkDriverCredit(); // 检查驾驶员信用
		} catch (Exception e) {
			e.printStackTrace();
		}

		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

		Map map = new HashMap<>();
		map.put("size", 9999);
		map.put("page", 1);

		JSONArray companys = RemoteServerUtils.getCompanyList(map, TOKEN);
		if (companys != null) {
			for (Object jsonObject : companys) {
				JSONObject company = (JSONObject) jsonObject;
				try {
					if (sdf.parse(company.getString("registrationValidTime")).getTime() < sdf
							.parse(sdf.format(new Date())).getTime()
							|| sdf.parse(company.getString("businessLicenseValidTime")).getTime() < sdf
									.parse(sdf.format(new Date())).getTime()) {
						CompanyCredit companyCredit = new CompanyCredit();
						companyCredit.setTime(new Date());
						companyCredit.setCreateBy("长沙市建筑垃圾智慧监管平台");
						companyCredit.setReason("企业道路运输经营许可证有效期:" + company.getString("businessLicenseValidTime")
								+ " 企业营业执照有效期:" + company.getString("registrationValidTime") + ",证件过期");
						companyCredit.setLostCredit(1L);
						companyCredit.setObjectId(company.getString("id"));
						companyCredit.setName(company.getString("name"));
						companyCredit.setPlace(company.getString("areaName"));
						companyCredit.setStatus(0L);
						SpringUtils.getBean(ICompanyCreditService.class).insertCompanyCredit(companyCredit, TOKEN);
					}
				} catch (Exception e) {
					e.printStackTrace();
				}

			}
		}

		CompanyCredit companyCredit = new CompanyCredit();
		companyCredit.setLostCredit(1L);
		companyCredit.setStatus(0L);

		List<CompanyCredit> companyList = SpringUtils.getBean(CompanyCreditMapper.class)
				.selectCompanyCreditList(companyCredit);

		for (CompanyCredit c : companyList) {
			SpringUtils.getBean(ICompanyCreditService.class).updateRemoteCompanyAndTruck(c, TOKEN);
		}

		try {
			checkToSendSMS(); // 检查驾驶员信用
		} catch (Exception e) {
			e.printStackTrace();
		}

	}

	private void checkToSendSMS() {
		if (RemoteServerUtils.remote == null) {
			RemoteServerUtils.remote = trashConfig.getRemotePath();
		}
		
		
		Map<String, Object> map = new HashMap<>();
		map.put("size", 99999);
		map.put("page", 1);
		JSONArray cList = redisCache.getCacheObject("constructionList");
		if(cList == null){
			cList = RemoteServerUtils.getConstructionList(map, trashConfig.getToken());
			redisCache.setCacheObject("constructionList", cList,60,TimeUnit.MINUTES);
		}
		
		JSONArray eList = redisCache.getCacheObject("earthSitesList");
		if(eList == null){
			eList = RemoteServerUtils.getEarthSitesList(map, trashConfig.getToken());
			redisCache.setCacheObject("earthSitesList", cList,60,TimeUnit.MINUTES);
		}

		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		long now = 0;
		try {
			now = sdf.parse(sdf.format(new Date())).getTime();
		} catch (ParseException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		
		if(cList != null){
			for(Object obj:cList){
				try{
					
				JSONObject json = (JSONObject) obj;
				long endTime = 0;
				try {
					now = sdf.parse(sdf.format(new Date())).getTime();
					endTime = sdf.parse(json.getString("effectiveEnd")).getTime();
				} catch (ParseException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				
				// 1 * 60 分 60  时 24
				
				if((endTime - now) == 15*1000*60*60*24){
					List<Mobile> mobileList = new ArrayList<>();
						

//						String p = json.getString("constructionCompanyPhone");
//			            if(p != null){
//							Mobile mobile=new Mobile();
//				            mobile.setMobile(p);
//				            mobileList.add(mobile);
//			            }
//					
//						String p1 = json.getString("projectnCompanyPhone");
//			            if(p1 != null){
//			            	Mobile mobile2=new Mobile();
//				            mobile2.setMobile(p1);
//				            mobileList.add(mobile2);
//			            }

	            	Mobile mobile2=new Mobile();
		            mobile2.setMobile("19520553054");
		            mobileList.add(mobile2);
					
			            String smsString = "【长沙渣管】到期提醒:"+json.getString("name")+"将于"+json.getString("effectiveEnd")+"到期(截止日),请在到期日前及时办理相关手续。";
							
							JsonSmsSend jsonSmsSend= PostSms.sendSms(mobileList,smsString);
				            if(jsonSmsSend!=null){
				                if(jsonSmsSend.getState()==0){
				                	System.out.println("发送成功");
				                }else{
				                	System.out.println(jsonSmsSend.getMessage());
				                }
				            }else{
				            	System.out.println("发送返回空");
				            }
				}
				
				
				} catch (Exception e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
			
		}

		if(eList != null){
			for(Object obj:eList){
				try{
					
				
				JSONObject json = (JSONObject) obj;
				long endTime = 0;
				try {
					endTime = sdf.parse(json.getString("effectiveEnd")).getTime();
				} catch (ParseException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				if((endTime - now) == 15*1000*60*60*24){
					List<Mobile> mobileList = new ArrayList<>();
						String p = json.getString("principalPhoneNo");
			            if(p != null){
//							Mobile mobile=new Mobile();
//				            mobile.setMobile(p);
//				            mobileList.add(mobile);
				            
			            	Mobile mobile2=new Mobile();
				            mobile2.setMobile("19520553054");
				            mobileList.add(mobile2);
				            
				            String smsString = "【长沙渣管】到期提醒:"+json.getString("name")+"将于"+json.getString("effectiveEnd")+"到期(截止日),请在到期日前及时办理相关手续。";
							
							JsonSmsSend jsonSmsSend= PostSms.sendSms(mobileList,smsString);
				            if(jsonSmsSend!=null){
				                if(jsonSmsSend.getState()==0){
				                	System.out.println("发送成功");
				                }else{
				                	System.out.println(jsonSmsSend.getMessage());
				                }
				            }else{
				            	System.out.println("发送返回空");
				            }
			            }
				}
				
				
				
			}catch(Exception e){
				e.printStackTrace();
			}
			}
		}
		
		
		
	}

	public void checkAllTask() {
		LogUtils.getBlock("===================  删除超时报工数据     定时器执行 当前时间:      " + simpleDateFormat.format(new Date()));

		if (TOKEN == null) {
			TOKEN = trashConfig.getToken();
		}
		try {
			SpringUtils.getBean(ISupervisionThreestepService.class).updateTodayData(TOKEN);
		} catch (Exception e) {
			e.printStackTrace();
		}
		try {
			SpringUtils.getBean(IActTaskService.class).endAllThreesteptask("workflow_threestep");
		} catch (Exception e) {
			e.printStackTrace();
		}
		try {
			SpringUtils.getBean(IWorkflowService.class).deleteWorkflowByName("workflow_threestep");
		} catch (Exception e) {
			e.printStackTrace();
		}
		try {
			SpringUtils.getBean(ITruckActivateService.class).endAllTruckUnActive();
		} catch (Exception e) {
			e.printStackTrace();
		}

	}

	/**
	 * kafka补偿机制,每半小时一次
	 * 
	 * @throws InterruptedException
	 */
	public void kafkaCompensation() throws InterruptedException, IOException {
		KafkaCompensation kafkaCompensation = new KafkaCompensation();
		kafkaCompensation.setStatus(0);
		List<KafkaCompensation> kafkaCompensationList = SpringUtils.getBean(KafkaCompensationMapper.class)
				.selectKafkaCompensationList(kafkaCompensation);
		for (KafkaCompensation k : kafkaCompensationList) {
			SpringUtils.getBean(Consumer.class).autoViolationWarning(k.getData(), k.getId().toString());
		}
	}

	/**
	 * 每分钟更新一次公司列表
	 */
	public void getCompanyList() {
		if (RemoteServerUtils.remote == null) {
			RemoteServerUtils.remote = trashConfig.getRemotePath();
		}
		Map<String, Object> map = new HashMap<>();
		map.put("size", 99999);
		map.put("page", 1);
		JSONArray jsonArray = RemoteServerUtils.getCompanyList(map, trashConfig.getToken());
		if (jsonArray != null) {
			redisCache.setCacheObject("companyList", jsonArray, 60, TimeUnit.MINUTES);
		}
	}

	public void getContractList() {
		if (RemoteServerUtils.remote == null) {
			RemoteServerUtils.remote = trashConfig.getRemotePath();
		}
		Map<String, Object> map = new HashMap<>();
		map.put("size", 99999);
		map.put("page", 1);
		map.put("contractStatus", 1);
		map.put("auditStatus", 1);
		JSONArray jsonArray = RemoteServerUtils.getContractList(map, trashConfig.getToken());
		if (jsonArray != null) {
			redisCache.setCacheObject("contractList", jsonArray, 60, TimeUnit.MINUTES);
		}
	}

	/**
	 * 每分钟更新一次工地列表
	 */
	public void getConstructionList() {
		if (RemoteServerUtils.remote == null) {
			RemoteServerUtils.remote = trashConfig.getRemotePath();
		}
		Map<String, Object> map = new HashMap<>();
		map.put("size", 99999);
		map.put("page", 1);
		JSONArray jsonArray = RemoteServerUtils.getConstructionList(map, trashConfig.getToken());
		if (jsonArray != null) {
			redisCache.setCacheObject("constructionList", jsonArray, 60, TimeUnit.MINUTES);
		}
	}

	/**
	 * 每分钟更新一次消纳场列表
	 */
	public void getEarthSitesList() {
		if (RemoteServerUtils.remote == null) {
			RemoteServerUtils.remote = trashConfig.getRemotePath();
		}
		Map<String, Object> map = new HashMap<>();
		map.put("size", 99999);
		map.put("page", 1);
		JSONArray jsonArray = RemoteServerUtils.getEarthSitesList(map, trashConfig.getToken());
		if (jsonArray != null) {
			redisCache.setCacheObject("earthSitesList", jsonArray, 60, TimeUnit.MINUTES);
		}
	}

	/**
	 * 每分钟更新一次区域列表
	 */
	public void getTruckList() {
		if (RemoteServerUtils.remote == null) {
			RemoteServerUtils.remote = trashConfig.getRemotePath();
		}
		Map<String, Object> map = new HashMap<>();
		map.put("size", 99999);
		map.put("valid", 0);
		map.put("page", 1);

		JSONArray jsonArray = RemoteServerUtils.getTruckList(map, trashConfig.getToken());
		if (jsonArray != null) {
			redisCache.setCacheObject("truckList", jsonArray, 60, TimeUnit.MINUTES);
		}
	}

	/**
	 * 每分钟更新一次区域列表
	 */
	public void getAreaList() {
		if (RemoteServerUtils.remote == null) {
			RemoteServerUtils.remote = trashConfig.getRemotePath();
		}
		Map<String, Object> map = new HashMap<>();
		map.put("size", 99999);
		map.put("page", 1);
		JSONArray jsonArray = RemoteServerUtils.getAreas(trashConfig.getToken());
		if (jsonArray != null) {
			redisCache.setCacheObject("areaList", jsonArray, 60, TimeUnit.MINUTES);
		}
	}
}