Commit 1b4276e63647227926e303e2445bd145de599524

Authored by 徐烜
2 parents 1073409b b650a337

Merge branch 'minhang' of http://222.66.0.204:8090//panzhaov5/bsth_control into minhang

Too many changes to show.

To preserve performance only 14 of 18 files are displayed.

src/main/java/com/bsth/XDApplication.java
1   -package com.bsth;
2   -
3   -import com.bsth.data.BasicData;
4   -import com.bsth.data.ThreadMonotor;
5   -import com.bsth.data.car_out_info.UpdateDBThread;
6   -import com.bsth.data.directive.DirectivesPstThread;
7   -import com.bsth.data.gpsdata.thread.GpsDataLoaderThread;
8   -import com.bsth.data.gpsdata.thread.OfflineMonitorThread;
9   -import com.bsth.data.schedule.late_adjust.ScheduleLateThread;
10   -import com.bsth.data.schedule.thread.CalcOilThread;
11   -import com.bsth.data.schedule.thread.SchedulePstThread;
12   -import com.bsth.data.schedule.thread.ScheduleRefreshThread;
13   -import com.bsth.data.schedule.thread.SubmitToTrafficManage;
14   -import com.bsth.util.DateUtils;
15   -import com.bsth.util.Tools;
16   -import org.slf4j.Logger;
17   -import org.slf4j.LoggerFactory;
18   -import org.springframework.beans.factory.annotation.Autowired;
19   -import org.springframework.boot.CommandLineRunner;
20   -import org.springframework.stereotype.Component;
21   -
22   -import java.util.concurrent.ScheduledExecutorService;
23   -import java.util.concurrent.TimeUnit;
24   -
25   -/**
26   - * 线调大部分服务都在这里启动
27   - * Created by panzhao on 2017/5/14.
28   - */
29   -@Component
30   -public class XDApplication implements CommandLineRunner {
31   -
32   - Logger log = LoggerFactory.getLogger(this.getClass());
33   -
34   - @Autowired
35   - BasicData.BasicDataLoader basicDataLoader;
36   - @Autowired
37   - UpdateDBThread fcxxUpdateThread;
38   - @Autowired
39   - GpsDataLoaderThread gpsDataLoader;
40   - @Autowired
41   - OfflineMonitorThread offlineMonitorThread;
42   - @Autowired
43   - ScheduleRefreshThread scheduleRefreshThread;
44   - @Autowired
45   - SchedulePstThread schedulePstThread;
46   - @Autowired
47   - ScheduleLateThread scheduleLateThread;
48   - @Autowired
49   - SubmitToTrafficManage submitToTrafficManage;
50   - @Autowired
51   - CalcOilThread calcOilThread;
52   - @Autowired
53   - DirectivesPstThread directivesPstThread;
54   - @Autowired
55   - ThreadMonotor threadMonotor;
56   -
57   - private static long timeDiff;
58   -
59   - static {
60   - timeDiff = (DateUtils.getTimestamp() + 1000 * 60 * 140) - System.currentTimeMillis();
61   - if (timeDiff < 0)
62   - timeDiff += (1000 * 60 * 60 * 24);
63   - }
64   -
65   - @Override
66   - public void run(String... strings) throws Exception {
67   - try {
68   - Tools tools = new Tools("application.properties");
69   - String environment = tools.getValue("spring.profiles.active");
70   - //预先加载基础的对照数据
71   - basicDataLoader.loadAllData();
72   - switch (environment){
73   - case "dev":
74   - devInit();
75   - break;
76   - case "prod":
77   - prodInit();
78   - break;
79   - }
80   - }catch (Exception e){
81   - log.error("线调后台启动出现异常!!", e);
82   - System.exit(1);
83   - }
84   - }
85   -
86   - public void devInit(){
87   - ScheduledExecutorService sexec = Application.mainServices;
88   - //抓取GPS数据
89   - gpsDataLoader.setFlag(-1);
90   - sexec.scheduleWithFixedDelay(gpsDataLoader, 30, 2, TimeUnit.SECONDS);
91   - //实际排班更新线程
92   - sexec.scheduleWithFixedDelay(scheduleRefreshThread, 15, 240, TimeUnit.SECONDS);
93   - //实际排班延迟入库线程
94   - sexec.scheduleWithFixedDelay(schedulePstThread, 60, 30, TimeUnit.SECONDS);
95   -
96   - //线程监听(防止重要的线程阻塞、异常结束。以及部分主备切换工作)
97   - sexec.scheduleWithFixedDelay(threadMonotor, 240, 60, TimeUnit.SECONDS);
98   - }
99   -
100   - public void prodInit(){
101   - ScheduledExecutorService sexec = Application.mainServices;
102   - //发车信息
103   - sexec.scheduleWithFixedDelay(fcxxUpdateThread, 60, 40, TimeUnit.SECONDS);
104   - //抓取GPS数据
105   - sexec.scheduleWithFixedDelay(gpsDataLoader, 30, 2, TimeUnit.SECONDS);
106   - //检查设备掉离线
107   - sexec.scheduleWithFixedDelay(offlineMonitorThread, 120, 60, TimeUnit.SECONDS);
108   - //实际排班更新线程
109   - sexec.scheduleWithFixedDelay(scheduleRefreshThread, 15, 240, TimeUnit.SECONDS);
110   - //实际排班延迟入库线程
111   - sexec.scheduleWithFixedDelay(schedulePstThread, 60, 30, TimeUnit.SECONDS);
112   - //检查班次误点
113   - sexec.scheduleWithFixedDelay(scheduleLateThread, 60, 30, TimeUnit.SECONDS);
114   - //调度指令延迟入库
115   - sexec.scheduleWithFixedDelay(directivesPstThread, 180, 180, TimeUnit.SECONDS);
116   -
117   - //运管处静态数据提交
118   - log.info(timeDiff / 1000 / 60 + "分钟之后提交到运管处");
119   - sexec.scheduleAtFixedRate(submitToTrafficManage, timeDiff / 1000, 60 * 60 * 24, TimeUnit.SECONDS);
120   - //计算油、公里加注
121   - sexec.scheduleAtFixedRate(calcOilThread, timeDiff / 1000, 60 * 60 * 24, TimeUnit.SECONDS);
122   -
123   - //线程监听(防止重要的线程阻塞、异常结束。以及部分主备切换工作)
124   - sexec.scheduleWithFixedDelay(threadMonotor, 240, 60, TimeUnit.SECONDS);
125   - }
126   -}
  1 +package com.bsth;
  2 +
  3 +import com.bsth.data.BasicData;
  4 +import com.bsth.data.ThreadMonotor;
  5 +import com.bsth.data.car_out_info.UpdateDBThread;
  6 +import com.bsth.data.directive.DirectivesPstThread;
  7 +import com.bsth.data.gpsdata.thread.GpsDataLoaderThread;
  8 +import com.bsth.data.gpsdata.thread.OfflineMonitorThread;
  9 +import com.bsth.data.schedule.late_adjust.ScheduleLateThread;
  10 +import com.bsth.data.schedule.thread.CalcOilThread;
  11 +import com.bsth.data.schedule.thread.SchedulePstThread;
  12 +import com.bsth.data.schedule.thread.ScheduleRefreshThread;
  13 +import com.bsth.data.schedule.thread.SubmitToTrafficManage;
  14 +import com.bsth.util.DateUtils;
  15 +import com.bsth.util.Tools;
  16 +import org.slf4j.Logger;
  17 +import org.slf4j.LoggerFactory;
  18 +import org.springframework.beans.factory.annotation.Autowired;
  19 +import org.springframework.boot.CommandLineRunner;
  20 +import org.springframework.stereotype.Component;
  21 +
  22 +import java.util.concurrent.ScheduledExecutorService;
  23 +import java.util.concurrent.TimeUnit;
  24 +
  25 +/**
  26 + * 线调大部分服务都在这里启动
  27 + * Created by panzhao on 2017/5/14.
  28 + */
  29 +@Component
  30 +public class XDApplication implements CommandLineRunner {
  31 +
  32 + Logger log = LoggerFactory.getLogger(this.getClass());
  33 +
  34 + @Autowired
  35 + BasicData.BasicDataLoader basicDataLoader;
  36 + @Autowired
  37 + UpdateDBThread fcxxUpdateThread;
  38 + @Autowired
  39 + GpsDataLoaderThread gpsDataLoader;
  40 + @Autowired
  41 + OfflineMonitorThread offlineMonitorThread;
  42 + @Autowired
  43 + ScheduleRefreshThread scheduleRefreshThread;
  44 + @Autowired
  45 + SchedulePstThread schedulePstThread;
  46 + @Autowired
  47 + ScheduleLateThread scheduleLateThread;
  48 + @Autowired
  49 + SubmitToTrafficManage submitToTrafficManage;
  50 + @Autowired
  51 + CalcOilThread calcOilThread;
  52 + @Autowired
  53 + DirectivesPstThread directivesPstThread;
  54 + @Autowired
  55 + ThreadMonotor threadMonotor;
  56 +
  57 + private static long timeDiff;
  58 +
  59 + static {
  60 + timeDiff = (DateUtils.getTimestamp() + 1000 * 60 * 140) - System.currentTimeMillis();
  61 + if (timeDiff < 0)
  62 + timeDiff += (1000 * 60 * 60 * 24);
  63 + }
  64 +
  65 + @Override
  66 + public void run(String... strings) throws Exception {
  67 + try {
  68 + Tools tools = new Tools("application.properties");
  69 + String environment = tools.getValue("spring.profiles.active");
  70 + //预先加载基础的对照数据
  71 + basicDataLoader.loadAllData();
  72 + switch (environment){
  73 + case "dev":
  74 + devInit();
  75 + break;
  76 + case "prod":
  77 + prodInit();
  78 + break;
  79 + }
  80 + }catch (Exception e){
  81 + log.error("线调后台启动出现异常!!", e);
  82 + System.exit(1);
  83 + }
  84 + }
  85 +
  86 + public void devInit(){
  87 + ScheduledExecutorService sexec = Application.mainServices;
  88 + //抓取GPS数据
  89 + gpsDataLoader.setFlag(-1);
  90 + sexec.scheduleWithFixedDelay(gpsDataLoader, 30, 2, TimeUnit.SECONDS);
  91 + //实际排班更新线程
  92 + sexec.scheduleWithFixedDelay(scheduleRefreshThread, 15, 240, TimeUnit.SECONDS);
  93 + //实际排班延迟入库线程
  94 + sexec.scheduleWithFixedDelay(schedulePstThread, 60, 30, TimeUnit.SECONDS);
  95 +
  96 + //线程监听(防止重要的线程阻塞、异常结束。以及部分主备切换工作)
  97 + sexec.scheduleWithFixedDelay(threadMonotor, 240, 60, TimeUnit.SECONDS);
  98 + }
  99 +
  100 + public void prodInit(){
  101 + ScheduledExecutorService sexec = Application.mainServices;
  102 + //发车信息
  103 + sexec.scheduleWithFixedDelay(fcxxUpdateThread, 60, 40, TimeUnit.SECONDS);
  104 + //抓取GPS数据
  105 + sexec.scheduleWithFixedDelay(gpsDataLoader, 30, 2, TimeUnit.SECONDS);
  106 + //检查设备掉离线
  107 + sexec.scheduleWithFixedDelay(offlineMonitorThread, 120, 60, TimeUnit.SECONDS);
  108 + //实际排班更新线程
  109 + sexec.scheduleWithFixedDelay(scheduleRefreshThread, 15, 240, TimeUnit.SECONDS);
  110 + //实际排班延迟入库线程
  111 + sexec.scheduleWithFixedDelay(schedulePstThread, 60, 30, TimeUnit.SECONDS);
  112 + //检查班次误点
  113 + sexec.scheduleWithFixedDelay(scheduleLateThread, 60, 30, TimeUnit.SECONDS);
  114 + //调度指令延迟入库
  115 + sexec.scheduleWithFixedDelay(directivesPstThread, 180, 180, TimeUnit.SECONDS);
  116 +
  117 + //运管处静态数据提交
  118 + log.info(timeDiff / 1000 / 60 + "分钟之后提交到运管处");
  119 + sexec.scheduleAtFixedRate(submitToTrafficManage, timeDiff / 1000, 60 * 60 * 24, TimeUnit.SECONDS);
  120 + //计算油、公里加注
  121 + sexec.scheduleAtFixedRate(calcOilThread, timeDiff / 1000, 60 * 60 * 24, TimeUnit.SECONDS);
  122 +
  123 + //线程监听(防止重要的线程阻塞、异常结束。以及部分主备切换工作)
  124 + sexec.scheduleWithFixedDelay(threadMonotor, 240, 60, TimeUnit.SECONDS);
  125 + }
  126 +}
... ...
src/main/java/com/bsth/data/ThreadMonotor.java
1   -package com.bsth.data;
2   -
3   -import com.bsth.data.gpsdata.arrival.GpsRealAnalyse;
4   -import com.bsth.data.gpsdata.thread.GpsDataLoaderThread;
5   -import com.bsth.data.msg_queue.DirectivePushQueue;
6   -import com.bsth.data.msg_queue.WebSocketPushQueue;
7   -import org.slf4j.Logger;
8   -import org.slf4j.LoggerFactory;
9   -import org.springframework.stereotype.Component;
10   -
11   -/**
12   - * Created by panzhao on 2017/5/11.
13   - */
14   -@Component
15   -public class ThreadMonotor extends Thread{
16   -
17   - Logger log = LoggerFactory.getLogger(this.getClass());
18   -
19   - @Override
20   - public void run() {
21   -
22   - //线调GPS分析主线程
23   - if(GpsRealAnalyse.isBlock()){
24   - log.warn("GpsRealAnalyse isBlock true !!!!");
25   - GpsRealAnalyse.shutdown();
26   - }
27   -
28   - if(GpsRealAnalyse.isIdle()){
29   - //尝试使用网关的GPS实时对照数据
30   - GpsDataLoaderThread.setFlag(-1);
31   - }
32   -
33   - //webSocket 消息推送队列
34   - if(WebSocketPushQueue.isIdle()){
35   - log.warn("WebSocketPushQueue isIdle true !!!!");
36   - WebSocketPushQueue.start();
37   - }
38   -
39   - //网关指令推送队列(系统自动发送的)
40   - if(DirectivePushQueue.isIdle()){
41   - log.warn("DirectivePushQueue isIdle true !!!!");
42   - DirectivePushQueue.start();
43   - }
44   - }
45   -}
  1 +package com.bsth.data;
  2 +
  3 +import com.bsth.data.gpsdata.arrival.GpsRealAnalyse;
  4 +import com.bsth.data.gpsdata.thread.GpsDataLoaderThread;
  5 +import com.bsth.data.msg_queue.DirectivePushQueue;
  6 +import com.bsth.data.msg_queue.WebSocketPushQueue;
  7 +import org.slf4j.Logger;
  8 +import org.slf4j.LoggerFactory;
  9 +import org.springframework.stereotype.Component;
  10 +
  11 +/**
  12 + * Created by panzhao on 2017/5/11.
  13 + */
  14 +@Component
  15 +public class ThreadMonotor extends Thread{
  16 +
  17 + Logger log = LoggerFactory.getLogger(this.getClass());
  18 +
  19 + @Override
  20 + public void run() {
  21 +
  22 + //线调GPS分析主线程
  23 + if(GpsRealAnalyse.isBlock()){
  24 + log.warn("GpsRealAnalyse isBlock true !!!!");
  25 + GpsRealAnalyse.shutdown();
  26 + }
  27 +
  28 + if(GpsRealAnalyse.isIdle()){
  29 + //尝试使用网关的GPS实时对照数据
  30 + GpsDataLoaderThread.setFlag(-1);
  31 + }
  32 +
  33 + //webSocket 消息推送队列
  34 + if(WebSocketPushQueue.isIdle()){
  35 + log.warn("WebSocketPushQueue isIdle true !!!!");
  36 + WebSocketPushQueue.start();
  37 + }
  38 +
  39 + //网关指令推送队列(系统自动发送的)
  40 + if(DirectivePushQueue.isIdle()){
  41 + log.warn("DirectivePushQueue isIdle true !!!!");
  42 + DirectivePushQueue.start();
  43 + }
  44 + }
  45 +}
... ...
src/main/java/com/bsth/data/car_out_info/UpdateDBThread.java
1   -package com.bsth.data.car_out_info;
2   -
3   -import org.springframework.beans.factory.annotation.Autowired;
4   -import org.springframework.stereotype.Component;
5   -
6   -/**
7   - * 数据库发车信息表更新线程
8   - * Created by panzhao on 2017/5/14.
9   - */
10   -@Component
11   -public class UpdateDBThread extends Thread{
12   -
13   - @Autowired
14   - CarOutInfoHandler carOutInfoHandler;
15   -
16   - @Override
17   - public void run() {
18   - carOutInfoHandler.updateAll();
19   - }
20   -}
  1 +package com.bsth.data.car_out_info;
  2 +
  3 +import org.springframework.beans.factory.annotation.Autowired;
  4 +import org.springframework.stereotype.Component;
  5 +
  6 +/**
  7 + * 数据库发车信息表更新线程
  8 + * Created by panzhao on 2017/5/14.
  9 + */
  10 +@Component
  11 +public class UpdateDBThread extends Thread{
  12 +
  13 + @Autowired
  14 + CarOutInfoHandler carOutInfoHandler;
  15 +
  16 + @Override
  17 + public void run() {
  18 + carOutInfoHandler.updateAll();
  19 + }
  20 +}
... ...
src/main/java/com/bsth/data/msg_queue/DirectivePushQueue.java
1   -package com.bsth.data.msg_queue;
2   -
3   -import com.bsth.entity.realcontrol.ScheduleRealInfo;
4   -import com.bsth.service.directive.DirectiveService;
5   -import org.slf4j.Logger;
6   -import org.slf4j.LoggerFactory;
7   -import org.springframework.beans.BeansException;
8   -import org.springframework.boot.CommandLineRunner;
9   -import org.springframework.context.ApplicationContext;
10   -import org.springframework.context.ApplicationContextAware;
11   -import org.springframework.stereotype.Component;
12   -
13   -import java.util.LinkedList;
14   -
15   -/**
16   - * 到网关的指令推送队列 (系统发送的队列, 用户手动发送的不走这里)
17   - * Created by panzhao on 2017/5/11.
18   - */
19   -@Component
20   -public class DirectivePushQueue implements CommandLineRunner, ApplicationContextAware {
21   -
22   - static LinkedList<QueueData_Directive> linkedList;
23   - static DataPushThread thread;
24   - static DirectiveService directiveService;
25   - static long t;
26   - static final int IDLE_TIME = 1000 * 30;
27   -
28   - static {
29   - linkedList = new LinkedList<>();
30   - }
31   -
32   - public static void put6002(ScheduleRealInfo sch, int finish, String sender){
33   - QueueData_Directive qd6002 = new QueueData_Directive();
34   - qd6002.setSch(sch);
35   - qd6002.setFinish(finish);
36   - qd6002.setSender(sender);
37   - qd6002.setCode("60_02");
38   -
39   - linkedList.add(qd6002);
40   - }
41   -
42   - public static void put6003(String nbbm, int state, int upDown, ScheduleRealInfo sch, String sender){
43   - QueueData_Directive qd6003 = new QueueData_Directive();
44   - qd6003.setNbbm(nbbm);
45   - qd6003.setState(state);
46   - qd6003.setUpDown(upDown);
47   - qd6003.setSch(sch);
48   - qd6003.setSender(sender);
49   -
50   - qd6003.setCode("60_03");
51   -
52   - linkedList.add(qd6003);
53   - }
54   -
55   - public static void put64(String nbbm, String lineCode, String sender){
56   - QueueData_Directive qd64 = new QueueData_Directive();
57   - qd64.setNbbm(nbbm);
58   - qd64.setLineCode(lineCode);
59   - qd64.setSender(sender);
60   -
61   - qd64.setCode("64");
62   -
63   - linkedList.add(qd64);
64   - }
65   -
66   - public static boolean isIdle(){
67   - return System.currentTimeMillis() - t > IDLE_TIME;
68   - }
69   -
70   - public static void start(){
71   - if(thread != null){
72   - thread.interrupt();
73   - }
74   - thread = new DataPushThread();
75   - thread.start();
76   - }
77   -
78   - @Override
79   - public void run(String... strings) throws Exception {
80   - start();
81   - }
82   -
83   - @Override
84   - public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
85   - directiveService = applicationContext.getBean(DirectiveService.class);
86   - }
87   -
88   - public static class DataPushThread extends Thread {
89   -
90   - Logger log = LoggerFactory.getLogger(this.getClass());
91   -
92   - @Override
93   - public void run() {
94   - boolean sleepFlag = false;
95   - QueueData_Directive qd;
96   - String code;
97   - while (true) {
98   - try {
99   - qd = linkedList.pollFirst();
100   - if (qd != null) {
101   - sleepFlag = false;
102   - code = qd.getCode();
103   -
104   - if(code.equals("60_02")){
105   - directiveService.send60Dispatch(qd.getSch(), qd.getFinish(), qd.getSender());
106   - log.info("directive 60_02 sch id: " + qd.getSch().getId());
107   - }
108   - else if(code.equals("60_03")){
109   - directiveService.send60Operation(qd.getNbbm(), qd.getState(), qd.getUpDown(), null, qd.getSender());
110   - log.info("directive 60_03 nbbm: " + qd.getNbbm());
111   - }
112   - else if(code.equals("64")){
113   - directiveService.lineChange(qd.getNbbm(), qd.getLineCode(), qd.getSender());
114   - log.info("directive 64 nbbm: " + qd.getNbbm() + " lineCode: " + qd.getLineCode());
115   - }
116   -
117   - } else{
118   - Thread.sleep(500);
119   - if(!sleepFlag){
120   - log.info("sleep...");
121   - sleepFlag = true;
122   - }
123   - }
124   - t = System.currentTimeMillis();
125   - }
126   - catch(InterruptedException e){
127   - break;
128   - }
129   - catch (Exception e) {
130   - log.error("", e);
131   - }
132   -
133   - }
134   - }
135   - }
136   -}
  1 +package com.bsth.data.msg_queue;
  2 +
  3 +import com.bsth.entity.realcontrol.ScheduleRealInfo;
  4 +import com.bsth.service.directive.DirectiveService;
  5 +import org.slf4j.Logger;
  6 +import org.slf4j.LoggerFactory;
  7 +import org.springframework.beans.BeansException;
  8 +import org.springframework.boot.CommandLineRunner;
  9 +import org.springframework.context.ApplicationContext;
  10 +import org.springframework.context.ApplicationContextAware;
  11 +import org.springframework.stereotype.Component;
  12 +
  13 +import java.util.LinkedList;
  14 +
  15 +/**
  16 + * 到网关的指令推送队列 (系统发送的队列, 用户手动发送的不走这里)
  17 + * Created by panzhao on 2017/5/11.
  18 + */
  19 +@Component
  20 +public class DirectivePushQueue implements CommandLineRunner, ApplicationContextAware {
  21 +
  22 + static LinkedList<QueueData_Directive> linkedList;
  23 + static DataPushThread thread;
  24 + static DirectiveService directiveService;
  25 + static long t;
  26 + static final int IDLE_TIME = 1000 * 30;
  27 +
  28 + static {
  29 + linkedList = new LinkedList<>();
  30 + }
  31 +
  32 + public static void put6002(ScheduleRealInfo sch, int finish, String sender){
  33 + QueueData_Directive qd6002 = new QueueData_Directive();
  34 + qd6002.setSch(sch);
  35 + qd6002.setFinish(finish);
  36 + qd6002.setSender(sender);
  37 + qd6002.setCode("60_02");
  38 +
  39 + linkedList.add(qd6002);
  40 + }
  41 +
  42 + public static void put6003(String nbbm, int state, int upDown, ScheduleRealInfo sch, String sender){
  43 + QueueData_Directive qd6003 = new QueueData_Directive();
  44 + qd6003.setNbbm(nbbm);
  45 + qd6003.setState(state);
  46 + qd6003.setUpDown(upDown);
  47 + qd6003.setSch(sch);
  48 + qd6003.setSender(sender);
  49 +
  50 + qd6003.setCode("60_03");
  51 +
  52 + linkedList.add(qd6003);
  53 + }
  54 +
  55 + public static void put64(String nbbm, String lineCode, String sender){
  56 + QueueData_Directive qd64 = new QueueData_Directive();
  57 + qd64.setNbbm(nbbm);
  58 + qd64.setLineCode(lineCode);
  59 + qd64.setSender(sender);
  60 +
  61 + qd64.setCode("64");
  62 +
  63 + linkedList.add(qd64);
  64 + }
  65 +
  66 + public static boolean isIdle(){
  67 + return System.currentTimeMillis() - t > IDLE_TIME;
  68 + }
  69 +
  70 + public static void start(){
  71 + if(thread != null){
  72 + thread.interrupt();
  73 + }
  74 + thread = new DataPushThread();
  75 + thread.start();
  76 + }
  77 +
  78 + @Override
  79 + public void run(String... strings) throws Exception {
  80 + start();
  81 + }
  82 +
  83 + @Override
  84 + public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
  85 + directiveService = applicationContext.getBean(DirectiveService.class);
  86 + }
  87 +
  88 + public static class DataPushThread extends Thread {
  89 +
  90 + Logger log = LoggerFactory.getLogger(this.getClass());
  91 +
  92 + @Override
  93 + public void run() {
  94 + boolean sleepFlag = false;
  95 + QueueData_Directive qd;
  96 + String code;
  97 + while (true) {
  98 + try {
  99 + qd = linkedList.pollFirst();
  100 + if (qd != null) {
  101 + sleepFlag = false;
  102 + code = qd.getCode();
  103 +
  104 + if(code.equals("60_02")){
  105 + directiveService.send60Dispatch(qd.getSch(), qd.getFinish(), qd.getSender());
  106 + log.info("directive 60_02 sch id: " + qd.getSch().getId());
  107 + }
  108 + else if(code.equals("60_03")){
  109 + directiveService.send60Operation(qd.getNbbm(), qd.getState(), qd.getUpDown(), null, qd.getSender());
  110 + log.info("directive 60_03 nbbm: " + qd.getNbbm());
  111 + }
  112 + else if(code.equals("64")){
  113 + directiveService.lineChange(qd.getNbbm(), qd.getLineCode(), qd.getSender());
  114 + log.info("directive 64 nbbm: " + qd.getNbbm() + " lineCode: " + qd.getLineCode());
  115 + }
  116 +
  117 + } else{
  118 + Thread.sleep(500);
  119 + if(!sleepFlag){
  120 + log.info("sleep...");
  121 + sleepFlag = true;
  122 + }
  123 + }
  124 + t = System.currentTimeMillis();
  125 + }
  126 + catch(InterruptedException e){
  127 + break;
  128 + }
  129 + catch (Exception e) {
  130 + log.error("", e);
  131 + }
  132 +
  133 + }
  134 + }
  135 + }
  136 +}
... ...
src/main/java/com/bsth/data/msg_queue/QueueData.java
1   -package com.bsth.data.msg_queue;
2   -
3   -import org.springframework.web.socket.TextMessage;
4   -import org.springframework.web.socket.WebSocketSession;
5   -
6   -/**
7   - * Created by panzhao on 2017/5/11.
8   - */
9   -public class QueueData {
10   -
11   - private TextMessage message;
12   -
13   - private WebSocketSession session;
14   -
15   -
16   - public WebSocketSession getSession() {
17   - return session;
18   - }
19   -
20   - public void setSession(WebSocketSession session) {
21   - this.session = session;
22   - }
23   -
24   - public TextMessage getMessage() {
25   - return message;
26   - }
27   -
28   - public void setMessage(TextMessage message) {
29   - this.message = message;
30   - }
31   -}
  1 +package com.bsth.data.msg_queue;
  2 +
  3 +import org.springframework.web.socket.TextMessage;
  4 +import org.springframework.web.socket.WebSocketSession;
  5 +
  6 +/**
  7 + * Created by panzhao on 2017/5/11.
  8 + */
  9 +public class QueueData {
  10 +
  11 + private TextMessage message;
  12 +
  13 + private WebSocketSession session;
  14 +
  15 +
  16 + public WebSocketSession getSession() {
  17 + return session;
  18 + }
  19 +
  20 + public void setSession(WebSocketSession session) {
  21 + this.session = session;
  22 + }
  23 +
  24 + public TextMessage getMessage() {
  25 + return message;
  26 + }
  27 +
  28 + public void setMessage(TextMessage message) {
  29 + this.message = message;
  30 + }
  31 +}
... ...
src/main/java/com/bsth/data/msg_queue/QueueData_Directive.java
1   -package com.bsth.data.msg_queue;
2   -
3   -import com.bsth.entity.realcontrol.ScheduleRealInfo;
4   -
5   -/**
6   - * Created by panzhao on 2017/5/11.
7   - */
8   -public class QueueData_Directive {
9   -
10   - /**
11   - * 指令类型
12   - * 60_02
13   - * 60_03
14   - * 64
15   - */
16   - private String code;
17   -
18   - /** 60调度指令内容 60_02*/
19   - private ScheduleRealInfo sch;
20   - private int finish;
21   -
22   - /** 60 营运指令 60_03*/
23   - private String nbbm;
24   - private int state;
25   - private int upDown;
26   -
27   - /** 64指令内容 */
28   - private String lineCode;
29   -
30   - private String sender;
31   -
32   -
33   - public ScheduleRealInfo getSch() {
34   - return sch;
35   - }
36   -
37   - public void setSch(ScheduleRealInfo sch) {
38   - this.sch = sch;
39   - }
40   -
41   - public int getFinish() {
42   - return finish;
43   - }
44   -
45   - public void setFinish(int finish) {
46   - this.finish = finish;
47   - }
48   -
49   - public String getSender() {
50   - return sender;
51   - }
52   -
53   - public void setSender(String sender) {
54   - this.sender = sender;
55   - }
56   -
57   - public String getNbbm() {
58   - return nbbm;
59   - }
60   -
61   - public void setNbbm(String nbbm) {
62   - this.nbbm = nbbm;
63   - }
64   -
65   - public int getState() {
66   - return state;
67   - }
68   -
69   - public void setState(int state) {
70   - this.state = state;
71   - }
72   -
73   - public int getUpDown() {
74   - return upDown;
75   - }
76   -
77   - public void setUpDown(int upDown) {
78   - this.upDown = upDown;
79   - }
80   -
81   - public String getCode() {
82   - return code;
83   - }
84   -
85   - public void setCode(String code) {
86   - this.code = code;
87   - }
88   -
89   - public String getLineCode() {
90   - return lineCode;
91   - }
92   -
93   - public void setLineCode(String lineCode) {
94   - this.lineCode = lineCode;
95   - }
96   -}
  1 +package com.bsth.data.msg_queue;
  2 +
  3 +import com.bsth.entity.realcontrol.ScheduleRealInfo;
  4 +
  5 +/**
  6 + * Created by panzhao on 2017/5/11.
  7 + */
  8 +public class QueueData_Directive {
  9 +
  10 + /**
  11 + * 指令类型
  12 + * 60_02
  13 + * 60_03
  14 + * 64
  15 + */
  16 + private String code;
  17 +
  18 + /** 60调度指令内容 60_02*/
  19 + private ScheduleRealInfo sch;
  20 + private int finish;
  21 +
  22 + /** 60 营运指令 60_03*/
  23 + private String nbbm;
  24 + private int state;
  25 + private int upDown;
  26 +
  27 + /** 64指令内容 */
  28 + private String lineCode;
  29 +
  30 + private String sender;
  31 +
  32 +
  33 + public ScheduleRealInfo getSch() {
  34 + return sch;
  35 + }
  36 +
  37 + public void setSch(ScheduleRealInfo sch) {
  38 + this.sch = sch;
  39 + }
  40 +
  41 + public int getFinish() {
  42 + return finish;
  43 + }
  44 +
  45 + public void setFinish(int finish) {
  46 + this.finish = finish;
  47 + }
  48 +
  49 + public String getSender() {
  50 + return sender;
  51 + }
  52 +
  53 + public void setSender(String sender) {
  54 + this.sender = sender;
  55 + }
  56 +
  57 + public String getNbbm() {
  58 + return nbbm;
  59 + }
  60 +
  61 + public void setNbbm(String nbbm) {
  62 + this.nbbm = nbbm;
  63 + }
  64 +
  65 + public int getState() {
  66 + return state;
  67 + }
  68 +
  69 + public void setState(int state) {
  70 + this.state = state;
  71 + }
  72 +
  73 + public int getUpDown() {
  74 + return upDown;
  75 + }
  76 +
  77 + public void setUpDown(int upDown) {
  78 + this.upDown = upDown;
  79 + }
  80 +
  81 + public String getCode() {
  82 + return code;
  83 + }
  84 +
  85 + public void setCode(String code) {
  86 + this.code = code;
  87 + }
  88 +
  89 + public String getLineCode() {
  90 + return lineCode;
  91 + }
  92 +
  93 + public void setLineCode(String lineCode) {
  94 + this.lineCode = lineCode;
  95 + }
  96 +}
... ...
src/main/java/com/bsth/data/msg_queue/WebSocketPushQueue.java
1   -package com.bsth.data.msg_queue;
2   -
3   -import com.bsth.common.Constants;
4   -import org.slf4j.Logger;
5   -import org.slf4j.LoggerFactory;
6   -import org.springframework.boot.CommandLineRunner;
7   -import org.springframework.stereotype.Component;
8   -import org.springframework.web.socket.TextMessage;
9   -import org.springframework.web.socket.WebSocketSession;
10   -
11   -import java.util.LinkedList;
12   -
13   -/**
14   - * 线调web socket 推送队列
15   - * Created by panzhao on 2017/5/11.
16   - */
17   -@Component
18   -public class WebSocketPushQueue implements CommandLineRunner {
19   -
20   - static LinkedList<QueueData> linkedList;
21   - static DataPushThread thread;
22   - static Logger log = LoggerFactory.getLogger(WebSocketPushQueue.class);
23   - static long t;
24   - static final int IDLE_TIME = 1000 * 30;
25   -
26   - static {
27   - linkedList = new LinkedList();
28   - }
29   -
30   - public static boolean isIdle() {
31   - return System.currentTimeMillis() - t > IDLE_TIME;
32   - }
33   -
34   - public static void put(WebSocketSession session, TextMessage msg) {
35   - QueueData qd = new QueueData();
36   - qd.setMessage(msg);
37   - qd.setSession(session);
38   -
39   - log.info("put、[" + session.getAttributes().get(Constants.SESSION_USERNAME) + "] 、" + msg.getPayload());
40   - linkedList.add(qd);
41   - }
42   -
43   - public static void start() {
44   - if (thread != null) {
45   - thread.interrupt();
46   - }
47   - thread = new DataPushThread();
48   - thread.start();
49   - }
50   -
51   - @Override
52   - public void run(String... strings) throws Exception {
53   - start();
54   - }
55   -
56   - public static class DataPushThread extends Thread {
57   -
58   - Logger log = LoggerFactory.getLogger(this.getClass());
59   -
60   - @Override
61   - public void run() {
62   - QueueData qd;
63   - WebSocketSession session;
64   -
65   - boolean sleepFlag = false;
66   - while (true) {
67   - try {
68   - qd = linkedList.pollFirst();
69   - if (qd != null) {
70   - sleepFlag = false;
71   - session = qd.getSession();
72   - if (session.isOpen()) {
73   - log.info("push start、[" + session.getAttributes().get(Constants.SESSION_USERNAME) + "] 、" + qd.getMessage().getPayload());
74   - session.sendMessage(qd.getMessage());
75   - log.info("push end..");
76   - }
77   - } else {
78   - Thread.sleep(500);
79   - if (!sleepFlag) {
80   - log.info("sleep...");
81   - sleepFlag = true;
82   - }
83   - }
84   - t = System.currentTimeMillis();
85   - } catch (InterruptedException e) {
86   - break;
87   - } catch (Exception e) {
88   - log.error("", e);
89   - }
90   - }
91   - }
92   - }
93   -}
  1 +package com.bsth.data.msg_queue;
  2 +
  3 +import com.bsth.common.Constants;
  4 +import org.slf4j.Logger;
  5 +import org.slf4j.LoggerFactory;
  6 +import org.springframework.boot.CommandLineRunner;
  7 +import org.springframework.stereotype.Component;
  8 +import org.springframework.web.socket.TextMessage;
  9 +import org.springframework.web.socket.WebSocketSession;
  10 +
  11 +import java.util.LinkedList;
  12 +
  13 +/**
  14 + * 线调web socket 推送队列
  15 + * Created by panzhao on 2017/5/11.
  16 + */
  17 +@Component
  18 +public class WebSocketPushQueue implements CommandLineRunner {
  19 +
  20 + static LinkedList<QueueData> linkedList;
  21 + static DataPushThread thread;
  22 + static Logger log = LoggerFactory.getLogger(WebSocketPushQueue.class);
  23 + static long t;
  24 + static final int IDLE_TIME = 1000 * 30;
  25 +
  26 + static {
  27 + linkedList = new LinkedList();
  28 + }
  29 +
  30 + public static boolean isIdle() {
  31 + return System.currentTimeMillis() - t > IDLE_TIME;
  32 + }
  33 +
  34 + public static void put(WebSocketSession session, TextMessage msg) {
  35 + QueueData qd = new QueueData();
  36 + qd.setMessage(msg);
  37 + qd.setSession(session);
  38 +
  39 + log.info("put、[" + session.getAttributes().get(Constants.SESSION_USERNAME) + "] 、" + msg.getPayload());
  40 + linkedList.add(qd);
  41 + }
  42 +
  43 + public static void start() {
  44 + if (thread != null) {
  45 + thread.interrupt();
  46 + }
  47 + thread = new DataPushThread();
  48 + thread.start();
  49 + }
  50 +
  51 + @Override
  52 + public void run(String... strings) throws Exception {
  53 + start();
  54 + }
  55 +
  56 + public static class DataPushThread extends Thread {
  57 +
  58 + Logger log = LoggerFactory.getLogger(this.getClass());
  59 +
  60 + @Override
  61 + public void run() {
  62 + QueueData qd;
  63 + WebSocketSession session;
  64 +
  65 + boolean sleepFlag = false;
  66 + while (true) {
  67 + try {
  68 + qd = linkedList.pollFirst();
  69 + if (qd != null) {
  70 + sleepFlag = false;
  71 + session = qd.getSession();
  72 + if (session.isOpen()) {
  73 + log.info("push start、[" + session.getAttributes().get(Constants.SESSION_USERNAME) + "] 、" + qd.getMessage().getPayload());
  74 + session.sendMessage(qd.getMessage());
  75 + log.info("push end..");
  76 + }
  77 + } else {
  78 + Thread.sleep(500);
  79 + if (!sleepFlag) {
  80 + log.info("sleep...");
  81 + sleepFlag = true;
  82 + }
  83 + }
  84 + t = System.currentTimeMillis();
  85 + } catch (InterruptedException e) {
  86 + break;
  87 + } catch (Exception e) {
  88 + log.error("", e);
  89 + }
  90 + }
  91 + }
  92 + }
  93 +}
... ...
src/main/java/com/bsth/service/oil/impl/YlbServiceImpl.java
... ... @@ -198,7 +198,16 @@ public class YlbServiceImpl extends BaseServiceImpl&lt;Ylb,Integer&gt; implements YlbS
198 198  
199 199 }
200 200 if(addList.size()>0){
201   - new BatchSaveUtils<Ylb>().saveList(addList, Ylb.class);
  201 + try {
  202 + new BatchSaveUtils<Ylb>().saveList2(addList, Ylb.class);
  203 + } catch (Exception e) {
  204 + // TODO: handle exception
  205 + if(e.getMessage().indexOf("PK_YLB_UK")>0){
  206 + newMap.put("fage", "存在相同数据,数据已经过滤");
  207 + logger.info("定时器:存在相同数据,数据已经过滤");
  208 + }
  209 + }
  210 +// new BatchSaveUtils<Ylb>().saveList(addList, Ylb.class);
202 211 }
203 212 result = "success";
204 213 }catch (Exception e) {
... ... @@ -363,7 +372,16 @@ public class YlbServiceImpl extends BaseServiceImpl&lt;Ylb,Integer&gt; implements YlbS
363 372 }
364 373 }
365 374 if(addList.size()>0){
366   - new BatchSaveUtils<Ylb>().saveList(addList, Ylb.class);
  375 + try {
  376 + new BatchSaveUtils<Ylb>().saveList2(addList, Ylb.class);
  377 + } catch (Exception e) {
  378 + // TODO: handle exception
  379 + if(e.getMessage().indexOf("PK_YLB_UK")>0){
  380 + newMap.put("fage", "存在相同数据,数据已经过滤");
  381 + logger.info("获取:存在相同数据,数据已经过滤");
  382 + }
  383 + }
  384 +
367 385 }
368 386  
369 387 if(updateList.size()>0){
... ... @@ -372,7 +390,7 @@ public class YlbServiceImpl extends BaseServiceImpl&lt;Ylb,Integer&gt; implements YlbS
372 390 }
373 391 }
374 392 newMap.put("status", ResponseCode.SUCCESS);
375   - } catch (ParseException e) {
  393 + } catch (Exception e) {
376 394 // TODO Auto-generated catch block
377 395 newMap.put("status", ResponseCode.ERROR);
378 396 throw e;
... ... @@ -778,7 +796,16 @@ public class YlbServiceImpl extends BaseServiceImpl&lt;Ylb,Integer&gt; implements YlbS
778 796 t.setYh(0.0);
779 797 if(!(t.getSsgsdm().equals("") || t.getFgsdm().equals(""))){
780 798 t.setCreatetime(new Date());
781   - repository.save(t);
  799 + try {
  800 + repository.save(t);
  801 + } catch (Exception e) {
  802 + // TODO: handle exception
  803 + if(e.getMessage().indexOf("PK_YLB_UK")>0){
  804 + newMap.put("fage", "存在相同数据,数据已经过滤");
  805 + logger.info("核对有存油没里程:存在相同数据,数据已经过滤");
  806 + }
  807 + }
  808 +
782 809 /*if(null!=cyl){
783 810 cyl.setCyl(Arith.add(t.getJzl(), t.getCzyl()));
784 811 cyl.setUpdatetime(y1.getYyrq());
... ...
src/main/java/com/bsth/service/report/impl/CulateMileageServiceImpl.java
... ... @@ -222,7 +222,21 @@ public class CulateMileageServiceImpl implements CulateMileageService{
222 222 if (!isInOut(scheduleRealInfo)) {
223 223 if(!scheduleRealInfo.isDestroy()){
224 224 if(scheduleRealInfo.isSflj()){
225   - ljgl=Arith.add(ljgl,scheduleRealInfo.getJhlc()==null?0:scheduleRealInfo.getJhlc());
  225 + Set<ChildTaskPlan> childTaskPlans = scheduleRealInfo.getcTasks();
  226 + if(childTaskPlans.isEmpty()){
  227 + ljgl=Arith.add(ljgl,scheduleRealInfo.getJhlc()==null?0:scheduleRealInfo.getJhlc());
  228 + }else{
  229 + Iterator<ChildTaskPlan> it = childTaskPlans.iterator();
  230 + while (it.hasNext()) {
  231 + ChildTaskPlan childTaskPlan = it.next();
  232 + if(childTaskPlan.getMileageType().equals("service")){
  233 + if (!childTaskPlan.isDestroy()) {
  234 + Float jhgl=childTaskPlan.getMileage()==null?0:childTaskPlan.getMileage();
  235 + ljgl=Arith.add(ljgl,jhgl);
  236 + }
  237 + }
  238 + }
  239 + }
226 240 }else{
227 241 Set<ChildTaskPlan> childTaskPlans = scheduleRealInfo.getcTasks();
228 242 if(!childTaskPlans.isEmpty()){
... ...
src/main/java/com/bsth/service/schedule/impl/PeopleCarPlanServiceImpl.java
... ... @@ -869,50 +869,50 @@ public class PeopleCarPlanServiceImpl implements PeopleCarPlanService {
869 869 Map<String, Object> m0 = new HashMap<String, Object>();
870 870 m0.put("time", "首~6:30");
871 871 m0.put("upbc", "0"); m0.put("dnbc", "0");
872   - m0.put("upys", "--"); m0.put("dnys", "--");
873   - m0.put("pjys", "--");
  872 + m0.put("upys", "/"); m0.put("dnys", "/");
  873 + m0.put("pjys", "/");
874 874 tempList.add(m0);
875 875 Map<String, Object> m1 = new HashMap<String, Object>();
876 876 m1.put("time", "6:31~8:30");
877 877 m1.put("upbc", "0"); m1.put("dnbc", "0");
878   - m1.put("upys", "--"); m1.put("dnys", "--");
879   - m1.put("pjys", "--");
  878 + m1.put("upys", "/"); m1.put("dnys", "/");
  879 + m1.put("pjys", "/");
880 880 tempList.add(m1);
881 881 Map<String, Object> m2 = new HashMap<String, Object>();
882 882 m2.put("time", "8:31~11:00");
883 883 m2.put("upbc", "0"); m2.put("dnbc", "0");
884   - m2.put("upys", "--"); m2.put("dnys", "--");
885   - m2.put("pjys", "--");
  884 + m2.put("upys", "/"); m2.put("dnys", "/");
  885 + m2.put("pjys", "/");
886 886 tempList.add(m2);
887 887 Map<String, Object> m3 = new HashMap<String, Object>();
888 888 m3.put("time", "11:01~13:30");
889 889 m3.put("upbc", "0"); m3.put("dnbc", "0");
890   - m3.put("upys", "--"); m3.put("dnys", "--");
891   - m3.put("pjys", "--");
  890 + m3.put("upys", "/"); m3.put("dnys", "/");
  891 + m3.put("pjys", "/");
892 892 tempList.add(m3);
893 893 Map<String, Object> m4 = new HashMap<String, Object>();
894 894 m4.put("time", "13:31~16:00");
895 895 m4.put("upbc", "0"); m4.put("dnbc", "0");
896   - m4.put("upys", "--"); m4.put("dnys", "--");
897   - m4.put("pjys", "--");
  896 + m4.put("upys", "/"); m4.put("dnys", "/");
  897 + m4.put("pjys", "/");
898 898 tempList.add(m4);
899 899 Map<String, Object> m5 = new HashMap<String, Object>();
900 900 m5.put("time", "16:01~18:00");
901 901 m5.put("upbc", "0"); m5.put("dnbc", "0");
902   - m5.put("upys", "--"); m5.put("dnys", "--");
903   - m5.put("pjys", "--");
  902 + m5.put("upys", "/"); m5.put("dnys", "/");
  903 + m5.put("pjys", "/");
904 904 tempList.add(m5);
905 905 Map<String, Object> m6 = new HashMap<String, Object>();
906 906 m6.put("time", "18:01~20:30");
907 907 m6.put("upbc", "0"); m6.put("dnbc", "0");
908   - m6.put("upys", "--"); m6.put("dnys", "--");
909   - m6.put("pjys", "--");
  908 + m6.put("upys", "/"); m6.put("dnys", "/");
  909 + m6.put("pjys", "/");
910 910 tempList.add(m6);
911 911 Map<String, Object> m7 = new HashMap<String, Object>();
912 912 m7.put("time", "20:31~末");
913 913 m7.put("upbc", "0"); m7.put("dnbc", "0");
914   - m7.put("upys", "--"); m7.put("dnys", "--");
915   - m7.put("pjys", "--");
  914 + m7.put("upys", "/"); m7.put("dnys", "/");
  915 + m7.put("pjys", "/");
916 916 tempList.add(m7);
917 917 }
918 918  
... ... @@ -1367,6 +1367,7 @@ public class PeopleCarPlanServiceImpl implements PeopleCarPlanService {
1367 1367 }
1368 1368 for(String key : keyMap.keySet()){
1369 1369 Map<String, Object> tempMap = new HashMap<String, Object>();
  1370 + Map<String, Object> m = new HashMap<String, Object>();
1370 1371 Map<Long, ScheduleRealInfo> temp0 = new HashMap<Long, ScheduleRealInfo>();
1371 1372 List<Long> longList0 = new ArrayList<Long>();
1372 1373 Map<Long, ScheduleRealInfo> temp1 = new HashMap<Long, ScheduleRealInfo>();
... ... @@ -1410,6 +1411,10 @@ public class PeopleCarPlanServiceImpl implements PeopleCarPlanService {
1410 1411 if(delay >= -3 && delay <= 1){
1411 1412 sjbc++;
1412 1413 }
  1414 + m.put("qdzFirst0", shouban0.getQdzName());
  1415 + m.put("jhfcFirst0", shouban0.getFcsj());
  1416 + m.put("sjfcFirst0", shouban0.getFcsjActual());
  1417 + m.put("delayFirst0", delay>0?"+"+delay:delay);
1413 1418 }
1414 1419  
1415 1420 if(moban0.getFcsjActual() != null){
... ... @@ -1420,7 +1425,20 @@ public class PeopleCarPlanServiceImpl implements PeopleCarPlanService {
1420 1425 if(delay >= -3 && delay <= 1){
1421 1426 sjbc++;
1422 1427 }
  1428 + m.put("qdzLast0", moban0.getQdzName());
  1429 + m.put("jhfcLast0", moban0.getFcsj());
  1430 + m.put("sjfcLast0", moban0.getFcsjActual());
  1431 + m.put("delayLast0", delay>0?"+"+delay:delay);
1423 1432 }
  1433 + } else {
  1434 + m.put("qdzFirst0", "--");
  1435 + m.put("jhfcFirst0", "/");
  1436 + m.put("sjfcFirst0", "/");
  1437 + m.put("delayFirst0", "/");
  1438 + m.put("qdzLast0", "--");
  1439 + m.put("jhfcLast0", "/");
  1440 + m.put("sjfcLast0", "/");
  1441 + m.put("delayLast0", "/");
1424 1442 }
1425 1443  
1426 1444 if(longList1.size() != 0){
... ... @@ -1435,7 +1453,12 @@ public class PeopleCarPlanServiceImpl implements PeopleCarPlanService {
1435 1453 if(delay >= -3 && delay <= 1){
1436 1454 sjbc++;
1437 1455 }
  1456 + m.put("qdzFirst1", shouban1.getQdzName());
  1457 + m.put("jhfcFirst1", shouban1.getFcsj());
  1458 + m.put("sjfcFirst1", shouban1.getFcsjActual());
  1459 + m.put("delayFirst1", delay>0?"+"+delay:delay);
1438 1460 }
  1461 +
1439 1462 if(moban1.getFcsjActual() != null){
1440 1463 jhbc++;
1441 1464 String[] split = moban1.getFcsjActual().split(":");
... ... @@ -1444,9 +1467,24 @@ public class PeopleCarPlanServiceImpl implements PeopleCarPlanService {
1444 1467 if(delay >= -3 && delay <= 1){
1445 1468 sjbc++;
1446 1469 }
  1470 + m.put("qdzLast1", moban1.getQdzName());
  1471 + m.put("jhfcLast1", moban1.getFcsj());
  1472 + m.put("sjfcLast1", moban1.getFcsjActual());
  1473 + m.put("delayLast1", delay>0?"+"+delay:delay);
1447 1474 }
  1475 + } else {
  1476 + m.put("qdzFirst1", "--");
  1477 + m.put("jhfcFirst1", "/");
  1478 + m.put("sjfcFirst1", "/");
  1479 + m.put("delayFirst1", "/");
  1480 + m.put("qdzLast1", "--");
  1481 + m.put("jhfcLast1", "/");
  1482 + m.put("sjfcLast1", "/");
  1483 + m.put("delayLast1", "/");
1448 1484 }
1449   -
  1485 +
  1486 + m.put("line", key);
  1487 + tempMap.put("map", m);
1450 1488 tempMap.put("jhbc", jhbc);
1451 1489 tempMap.put("sjbc", sjbc);
1452 1490 tempMap.put("zdl", nf.format((float) sjbc / jhbc *100) + "%");
... ...
src/main/java/com/bsth/service/schedule/rules/validate/ValidRepeatBcFunction.java
1   -package com.bsth.service.schedule.rules.validate;
2   -
3   -import com.bsth.entity.schedule.SchedulePlanInfo;
4   -import org.kie.api.runtime.rule.AccumulateFunction;
5   -
6   -import java.io.*;
7   -import java.text.SimpleDateFormat;
8   -import java.util.ArrayList;
9   -import java.util.HashMap;
10   -import java.util.List;
11   -import java.util.Map;
12   -
13   -/**
14   - * 计算班次重复错误。
15   - * 同一个路牌下,相同发车时间的班次数。
16   - * 注意:使用这个函数时,要一天计算一次,多天计算无意义。
17   - */
18   -public class ValidRepeatBcFunction implements AccumulateFunction {
19   - @Override
20   - public void writeExternal(ObjectOutput out) throws IOException {
21   - }
22   -
23   - @Override
24   - public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
25   -
26   - }
27   -
28   - protected static class RepeatBcInfo implements Externalizable {
29   - /** 错误描述 */
30   - public List<ValidateResults_output.ValidInfo> validInfoList = new ArrayList<>();
31   - /** 内部计数Map,key:{路牌Id}_{发车时间},value:个数 */
32   - public Map<String, Integer> lpBcFcsjCount = new HashMap<>();
33   -
34   - public RepeatBcInfo() {
35   - }
36   -
37   - @Override
38   - public void writeExternal(ObjectOutput out) throws IOException {
39   - out.writeObject(validInfoList);
40   - }
41   -
42   - @Override
43   - public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
44   - validInfoList = (List<ValidateResults_output.ValidInfo>) in.readObject();
45   - }
46   - }
47   -
48   - @Override
49   - public Serializable createContext() {
50   - System.out.println("create");
51   - return new RepeatBcInfo();
52   - }
53   -
54   - @Override
55   - public void init(Serializable serializable) throws Exception {
56   - // TODO:
57   - System.out.println("init");
58   - }
59   -
60   - @Override
61   - public void accumulate(Serializable context, Object o) {
62   - RepeatBcInfo repeatBcInfo = (RepeatBcInfo) context;
63   - SchedulePlanInfo schedulePlanInfo = (SchedulePlanInfo) o;
64   -
65   - String key = schedulePlanInfo.getLp() + "_" + schedulePlanInfo.getFcsj();
66   - SimpleDateFormat sf = new SimpleDateFormat("yyyy年MM月dd日");
67   - String infoformat = "日期(%s),路牌(%s),班次(%s),重复(%d)次";
68   - if (repeatBcInfo.lpBcFcsjCount.get(key) == null) {
69   - repeatBcInfo.lpBcFcsjCount.put(key, 1);
70   - } else {
71   - int count = repeatBcInfo.lpBcFcsjCount.get(key) + 1;
72   - ValidateResults_output.ValidInfo validInfo = new ValidateResults_output.ValidInfo();
73   - validInfo.setSd(schedulePlanInfo.getScheduleDate());
74   - validInfo.setDesc(String.format(
75   - infoformat,
76   - sf.format(schedulePlanInfo.getScheduleDate()),
77   - schedulePlanInfo.getLpName(),
78   - schedulePlanInfo.getFcsj(),
79   - count));
80   - repeatBcInfo.validInfoList.add(validInfo);
81   - repeatBcInfo.lpBcFcsjCount.put(key, count);
82   - }
83   - }
84   -
85   - @Override
86   - public boolean supportsReverse() {
87   - return true;
88   - }
89   -
90   - @Override
91   - public void reverse(Serializable context, Object o) throws Exception {
92   - RepeatBcInfo repeatBcInfo = (RepeatBcInfo) context;
93   - SchedulePlanInfo schedulePlanInfo = (SchedulePlanInfo) o;
94   -
95   - String key = schedulePlanInfo.getLp() + "_" + schedulePlanInfo.getFcsj();
96   - repeatBcInfo.lpBcFcsjCount.remove(key);
97   -
98   - if (!repeatBcInfo.validInfoList.isEmpty()) { // 全部清空
99   - repeatBcInfo.validInfoList.clear();
100   - }
101   - }
102   -
103   - @Override
104   - public Class<?> getResultType() {
105   - return List.class;
106   - }
107   -
108   - @Override
109   - public Object getResult(Serializable context) throws Exception {
110   - RepeatBcInfo repeatBcInfo = (RepeatBcInfo) context;
111   - return repeatBcInfo.validInfoList;
112   - }
113   -}
  1 +package com.bsth.service.schedule.rules.validate;
  2 +
  3 +import com.bsth.entity.schedule.SchedulePlanInfo;
  4 +import org.kie.api.runtime.rule.AccumulateFunction;
  5 +
  6 +import java.io.*;
  7 +import java.text.SimpleDateFormat;
  8 +import java.util.ArrayList;
  9 +import java.util.HashMap;
  10 +import java.util.List;
  11 +import java.util.Map;
  12 +
  13 +/**
  14 + * 计算班次重复错误。
  15 + * 同一个路牌下,相同发车时间的班次数。
  16 + * 注意:使用这个函数时,要一天计算一次,多天计算无意义。
  17 + */
  18 +public class ValidRepeatBcFunction implements AccumulateFunction {
  19 + @Override
  20 + public void writeExternal(ObjectOutput out) throws IOException {
  21 + }
  22 +
  23 + @Override
  24 + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
  25 +
  26 + }
  27 +
  28 + protected static class RepeatBcInfo implements Externalizable {
  29 + /** 错误描述 */
  30 + public List<ValidateResults_output.ValidInfo> validInfoList = new ArrayList<>();
  31 + /** 内部计数Map,key:{路牌Id}_{发车时间},value:个数 */
  32 + public Map<String, Integer> lpBcFcsjCount = new HashMap<>();
  33 +
  34 + public RepeatBcInfo() {
  35 + }
  36 +
  37 + @Override
  38 + public void writeExternal(ObjectOutput out) throws IOException {
  39 + out.writeObject(validInfoList);
  40 + }
  41 +
  42 + @Override
  43 + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
  44 + validInfoList = (List<ValidateResults_output.ValidInfo>) in.readObject();
  45 + }
  46 + }
  47 +
  48 + @Override
  49 + public Serializable createContext() {
  50 + System.out.println("create");
  51 + return new RepeatBcInfo();
  52 + }
  53 +
  54 + @Override
  55 + public void init(Serializable serializable) throws Exception {
  56 + // TODO:
  57 + System.out.println("init");
  58 + }
  59 +
  60 + @Override
  61 + public void accumulate(Serializable context, Object o) {
  62 + RepeatBcInfo repeatBcInfo = (RepeatBcInfo) context;
  63 + SchedulePlanInfo schedulePlanInfo = (SchedulePlanInfo) o;
  64 +
  65 + String key = schedulePlanInfo.getLp() + "_" + schedulePlanInfo.getFcsj();
  66 + SimpleDateFormat sf = new SimpleDateFormat("yyyy年MM月dd日");
  67 + String infoformat = "日期(%s),路牌(%s),班次(%s),重复(%d)次";
  68 + if (repeatBcInfo.lpBcFcsjCount.get(key) == null) {
  69 + repeatBcInfo.lpBcFcsjCount.put(key, 1);
  70 + } else {
  71 + int count = repeatBcInfo.lpBcFcsjCount.get(key) + 1;
  72 + ValidateResults_output.ValidInfo validInfo = new ValidateResults_output.ValidInfo();
  73 + validInfo.setSd(schedulePlanInfo.getScheduleDate());
  74 + validInfo.setDesc(String.format(
  75 + infoformat,
  76 + sf.format(schedulePlanInfo.getScheduleDate()),
  77 + schedulePlanInfo.getLpName(),
  78 + schedulePlanInfo.getFcsj(),
  79 + count));
  80 + repeatBcInfo.validInfoList.add(validInfo);
  81 + repeatBcInfo.lpBcFcsjCount.put(key, count);
  82 + }
  83 + }
  84 +
  85 + @Override
  86 + public boolean supportsReverse() {
  87 + return true;
  88 + }
  89 +
  90 + @Override
  91 + public void reverse(Serializable context, Object o) throws Exception {
  92 + RepeatBcInfo repeatBcInfo = (RepeatBcInfo) context;
  93 + SchedulePlanInfo schedulePlanInfo = (SchedulePlanInfo) o;
  94 +
  95 + String key = schedulePlanInfo.getLp() + "_" + schedulePlanInfo.getFcsj();
  96 + repeatBcInfo.lpBcFcsjCount.remove(key);
  97 +
  98 + if (!repeatBcInfo.validInfoList.isEmpty()) { // 全部清空
  99 + repeatBcInfo.validInfoList.clear();
  100 + }
  101 + }
  102 +
  103 + @Override
  104 + public Class<?> getResultType() {
  105 + return List.class;
  106 + }
  107 +
  108 + @Override
  109 + public Object getResult(Serializable context) throws Exception {
  110 + RepeatBcInfo repeatBcInfo = (RepeatBcInfo) context;
  111 + return repeatBcInfo.validInfoList;
  112 + }
  113 +}
... ...
src/main/java/com/bsth/service/schedule/rules/validate/ValidateParam.java
1   -package com.bsth.service.schedule.rules.validate;
2   -
3   -import org.joda.time.DateTime;
4   -import org.joda.time.Period;
5   -import org.joda.time.PeriodType;
6   -
7   -/**
8   - * Created by xu on 17/5/11.
9   - */
10   -public class ValidateParam {
11   - /** 开始计算日期 */
12   - private DateTime fromDate;
13   - /** 结束计算日期 */
14   - private DateTime toDate;
15   -
16   - /** 间隔天数 */
17   - private Integer days;
18   -
19   - public ValidateParam(DateTime f, DateTime t) {
20   - this.fromDate = f;
21   - this.toDate = t;
22   - Period period = new Period(fromDate, toDate, PeriodType.days());
23   - days = period.getDays() + 1;
24   - }
25   -
26   - public DateTime getFromDate() {
27   - return fromDate;
28   - }
29   -
30   - public void setFromDate(DateTime fromDate) {
31   - this.fromDate = fromDate;
32   - }
33   -
34   - public DateTime getToDate() {
35   - return toDate;
36   - }
37   -
38   - public void setToDate(DateTime toDate) {
39   - this.toDate = toDate;
40   - }
41   -
42   - public Integer getDays() {
43   - return days;
44   - }
45   -
46   - public void setDays(Integer days) {
47   - this.days = days;
48   - }
49   -}
  1 +package com.bsth.service.schedule.rules.validate;
  2 +
  3 +import org.joda.time.DateTime;
  4 +import org.joda.time.Period;
  5 +import org.joda.time.PeriodType;
  6 +
  7 +/**
  8 + * Created by xu on 17/5/11.
  9 + */
  10 +public class ValidateParam {
  11 + /** 开始计算日期 */
  12 + private DateTime fromDate;
  13 + /** 结束计算日期 */
  14 + private DateTime toDate;
  15 +
  16 + /** 间隔天数 */
  17 + private Integer days;
  18 +
  19 + public ValidateParam(DateTime f, DateTime t) {
  20 + this.fromDate = f;
  21 + this.toDate = t;
  22 + Period period = new Period(fromDate, toDate, PeriodType.days());
  23 + days = period.getDays() + 1;
  24 + }
  25 +
  26 + public DateTime getFromDate() {
  27 + return fromDate;
  28 + }
  29 +
  30 + public void setFromDate(DateTime fromDate) {
  31 + this.fromDate = fromDate;
  32 + }
  33 +
  34 + public DateTime getToDate() {
  35 + return toDate;
  36 + }
  37 +
  38 + public void setToDate(DateTime toDate) {
  39 + this.toDate = toDate;
  40 + }
  41 +
  42 + public Integer getDays() {
  43 + return days;
  44 + }
  45 +
  46 + public void setDays(Integer days) {
  47 + this.days = days;
  48 + }
  49 +}
... ...
src/main/java/com/bsth/service/schedule/rules/validate/ValidateResults_output.java
1   -package com.bsth.service.schedule.rules.validate;
2   -
3   -import java.util.ArrayList;
4   -import java.util.Date;
5   -import java.util.List;
6   -
7   -/**
8   - * 验证输出。
9   - */
10   -public class ValidateResults_output {
11   - private List<ValidInfo> infos = new ArrayList<>();
12   -
13   - public static class ValidInfo {
14   - /** 日期 */
15   - private Date sd;
16   - /** 描述 */
17   - private String desc;
18   -
19   - public Date getSd() {
20   - return sd;
21   - }
22   -
23   - public void setSd(Date sd) {
24   - this.sd = sd;
25   - }
26   -
27   - public String getDesc() {
28   - return desc;
29   - }
30   -
31   - public void setDesc(String desc) {
32   - this.desc = desc;
33   - }
34   - }
35   -
36   - public List<ValidInfo> getInfos() {
37   - return infos;
38   - }
39   -
40   - public void setInfos(List<ValidInfo> infos) {
41   - this.infos = infos;
42   - }
43   -}
  1 +package com.bsth.service.schedule.rules.validate;
  2 +
  3 +import java.util.ArrayList;
  4 +import java.util.Date;
  5 +import java.util.List;
  6 +
  7 +/**
  8 + * 验证输出。
  9 + */
  10 +public class ValidateResults_output {
  11 + private List<ValidInfo> infos = new ArrayList<>();
  12 +
  13 + public static class ValidInfo {
  14 + /** 日期 */
  15 + private Date sd;
  16 + /** 描述 */
  17 + private String desc;
  18 +
  19 + public Date getSd() {
  20 + return sd;
  21 + }
  22 +
  23 + public void setSd(Date sd) {
  24 + this.sd = sd;
  25 + }
  26 +
  27 + public String getDesc() {
  28 + return desc;
  29 + }
  30 +
  31 + public void setDesc(String desc) {
  32 + this.desc = desc;
  33 + }
  34 + }
  35 +
  36 + public List<ValidInfo> getInfos() {
  37 + return infos;
  38 + }
  39 +
  40 + public void setInfos(List<ValidInfo> infos) {
  41 + this.infos = infos;
  42 + }
  43 +}
... ...
src/main/java/com/bsth/util/BatchSaveUtils.java
... ... @@ -99,6 +99,47 @@ public class BatchSaveUtils&lt;T&gt; {
99 99 return 0;
100 100 }
101 101  
  102 + public int saveList2(List<T> list, Class<T> clazz) throws Exception{
  103 + //获取泛型 T 的字节码
  104 + Table table = clazz.getAnnotation(Table.class);
  105 + if(null == table){
  106 + logger.error("找不到" + clazz.getSimpleName() + "类的表映射");
  107 + return -1;
  108 + }
  109 + List<Field> fs = fieldFilter(clazz.getDeclaredFields());
  110 + String sql = createSql(table, fs);
  111 + logger.info(sql);
  112 +
  113 + //每5000条批量入库一次
  114 + Connection conn = null;
  115 + PreparedStatement ps = null;
  116 + try{
  117 + conn = getConn();
  118 + conn.setAutoCommit(false);
  119 + ps = conn.prepareStatement(sql);
  120 +
  121 + int fsize = fs.size(), count = 0;
  122 + for(T t : list){
  123 + count ++;
  124 + for(int i = 0; i < fsize; i ++){
  125 + ps.setObject(i + 1, fs.get(i).get(t));
  126 + }
  127 +
  128 + ps.addBatch();
  129 + if(count % batchSize == 0){
  130 + ps.executeBatch();
  131 + conn.commit();
  132 + ps.clearBatch();
  133 + }
  134 + }
  135 + ps.executeBatch();
  136 + conn.commit();
  137 + }finally {
  138 + closeAll(conn, ps, null);
  139 + }
  140 +
  141 + return 0;
  142 + }
102 143 public String createSql(Table table, List<Field> fs){
103 144 String sqlBefore = "insert into " + table.name() + "("
104 145 ,sqlValues = " values(";
... ...