Commit 0dc559e3a8bd6c4e48f5b2c5f92e80a60ce80d66

Authored by 廖磊
2 parents 9c2e8731 5d90b218

Merge branch 'pudong' of http://222.66.0.204:8090/panzhaov5/bsth_control

into pudong

Too many changes to show.

To preserve performance only 15 of 29 files are displayed.

src/main/java/com/bsth/controller/realcontrol/AdminUtilsController.java
1   -package com.bsth.controller.realcontrol;
2   -
3   -import com.bsth.data.directive.DayOfDirectives;
4   -import com.bsth.data.directive.DirectivesPstThread;
5   -import com.bsth.data.gpsdata_v2.cache.GeoCacheData;
6   -import com.bsth.data.gpsdata_v2.handlers.overspeed.OverspeedProcess;
7   -import com.bsth.data.gpsdata_v2.thread.GpsDataLoaderThread;
8   -import com.bsth.data.msg_queue.DirectivePushQueue;
9   -import com.bsth.data.msg_queue.WebSocketPushQueue;
10   -import com.bsth.data.pilot80.PilotReport;
11   -import com.bsth.data.schedule.DayOfSchedule;
12   -import com.bsth.entity.realcontrol.ScheduleRealInfo;
13   -import com.bsth.websocket.handler.SendUtils;
14   -import org.slf4j.Logger;
15   -import org.slf4j.LoggerFactory;
16   -import org.springframework.beans.factory.annotation.Autowired;
17   -import org.springframework.web.bind.annotation.RequestMapping;
18   -import org.springframework.web.bind.annotation.RequestParam;
19   -import org.springframework.web.bind.annotation.RestController;
20   -
21   -import java.util.HashMap;
22   -import java.util.List;
23   -import java.util.Map;
24   -
25   -/**
26   - * Created by panzhao on 2017/4/14.
27   - */
28   -@RestController
29   -@RequestMapping("adminUtils")
30   -public class AdminUtilsController {
31   -
32   -
33   - Logger logger = LoggerFactory.getLogger(this.getClass());
34   -
35   - @Autowired
36   - DayOfSchedule dayOfSchedule;
37   -
38   - @Autowired
39   - GeoCacheData geoCacheData;
40   -
41   - @Autowired
42   - DayOfDirectives dayOfDirectives;
43   -
44   - @Autowired
45   - SendUtils sendUtils;
46   -
47   - @Autowired
48   - PilotReport pilotReport;
49   -
50   - /**
51   - * 出现重复班次的车辆
52   - * @param
53   -
54   - @RequestMapping(value = "/schRepeat", method = RequestMethod.POST)
55   - public void schRepeat(@RequestParam String nbbm){
56   - logger.info("前端通知,车辆 " + nbbm + "出现重复班次,开始检测...");
57   - List<ScheduleRealInfo> list = dayOfSchedule.findByNbbm(nbbm);
58   - logger.info("检测前,车辆班次数量:" + list.size());
59   -
60   - Map<Long, ScheduleRealInfo> map = new HashMap<>();
61   - for(ScheduleRealInfo sch : list){
62   - if(map.containsKey(sch.getId())){
63   - logger.info("检测到重复ID: " + sch.getId());
64   - }
65   - map.put(sch.getId(), sch);
66   - }
67   -
68   - logger.info("检测后,车辆班次数量:" + list.size());
69   - if(map.values().size() > 0){
70   - dayOfSchedule.replaceByNbbm(nbbm, map.values());
71   - }
72   - }*/
73   -
74   -/* @RequestMapping(value = "/directivePushQueue")
75   - public void directivePushQueue(){
76   - DirectivePushQueue.start();
77   - }*/
78   -
79   - @RequestMapping(value = "/directiveQueueSize")
80   - public void directiveQueueSize(){
81   - DirectivePushQueue.size();
82   - }
83   -
84   - /*@RequestMapping(value = "/webSocketPushQueue")
85   - public void webSocketPushQueue(){
86   - WebSocketPushQueue.start();
87   - }*/
88   -
89   - @RequestMapping(value = "/webSocketQueueSize")
90   - public void webSocketQueueSize(){
91   - WebSocketPushQueue.size();
92   - }
93   -
94   - @RequestMapping(value = "/setHttpFlag")
95   - public void setHttpFlag(@RequestParam int flag){
96   - if(flag != 0 && flag != -1)
97   - return;
98   - GpsDataLoaderThread.setFlag(flag);
99   - }
100   -
101   - @RequestMapping(value = "/updateCacheBuff")
102   - public void updateCacheBuff(){
103   - geoCacheData.loadData();
104   - }
105   -
106   - @RequestMapping(value = "/reCalcLpSch")
107   - public void reCalcLpSch(){
108   - dayOfSchedule._test_reCalcLpSch();
109   - }
110   -
111   - @RequestMapping(value = "/findSchByLpName")
112   - public List<ScheduleRealInfo> findSchByLpName(@RequestParam String lpName){
113   - return dayOfSchedule.getLpScheduleMap().get(lpName);
114   - }
115   -
116   - @RequestMapping(value = "/findSchByNbbm")
117   - public List<ScheduleRealInfo> findSchByNbbm(@RequestParam String nbbm){
118   - return dayOfSchedule.findByNbbm(nbbm);
119   - }
120   -
121   - @RequestMapping(value = "/removeExecPlan")
122   - public int removeExecPlan(@RequestParam String nbbm){
123   - dayOfSchedule.removeExecPlan(nbbm);
124   - return 1;
125   - }
126   -
127   - @RequestMapping(value = "/sch_re_calc_id_maps")
128   - public int reCalcIdMaps(){
129   - return dayOfSchedule.reCalcIdMaps();
130   - }
131   -
132   - @RequestMapping(value = "/sch_size_string")
133   - public String schSizeString(){
134   - return dayOfSchedule.sizeString();
135   - }
136   -
137   - @RequestMapping(value = "/containerSize")
138   - public Map<String, Integer> containerSize(){
139   - Map<String, Integer> rs = new HashMap<>();
140   - rs.put("60_size", dayOfDirectives.all60().size());
141   - rs.put("80_size", pilotReport.findAll().size());
142   - rs.put("nbbm_sch_size", dayOfSchedule.findAll().size());
143   - rs.put("lp_sch_size", dayOfSchedule.findAllByLpContainer().size());
144   - rs.put("id_sch_size", dayOfSchedule.findAllByIdContainer().size());
145   - rs.put("pst_sch_size", dayOfSchedule.getPstSize());
146   - rs.put("speeds_size", OverspeedProcess.size());
147   - return rs;
148   - }
149   -
150   - @RequestMapping(value = "/websocketRadioText")
151   - public int radioText(String t, String lineCode){
152   - sendUtils.sendRadioText(t, lineCode);
153   - return 0;
154   - }
155   -
156   - @Autowired
157   - DirectivesPstThread directivesPstThread;
158   -
159   - @RequestMapping(value = "/_sd_60_pst")
160   - public void sd_60_pst(){
161   - logger.info("手动入库指令....");
162   - directivesPstThread.run();
163   - }
  1 +package com.bsth.controller.realcontrol;
  2 +
  3 +import com.bsth.data.directive.DayOfDirectives;
  4 +import com.bsth.data.directive.DirectivesPstThread;
  5 +import com.bsth.data.gpsdata_v2.cache.GeoCacheData;
  6 +import com.bsth.data.gpsdata_v2.handlers.overspeed.OverspeedProcess;
  7 +import com.bsth.data.gpsdata_v2.thread.GpsDataLoaderThread;
  8 +import com.bsth.data.msg_queue.DirectivePushQueue;
  9 +import com.bsth.data.msg_queue.WebSocketPushQueue;
  10 +import com.bsth.data.pilot80.PilotReport;
  11 +import com.bsth.data.schedule.DayOfSchedule;
  12 +import com.bsth.entity.realcontrol.ScheduleRealInfo;
  13 +import com.bsth.websocket.handler.SendUtils;
  14 +import org.slf4j.Logger;
  15 +import org.slf4j.LoggerFactory;
  16 +import org.springframework.beans.factory.annotation.Autowired;
  17 +import org.springframework.web.bind.annotation.RequestMapping;
  18 +import org.springframework.web.bind.annotation.RequestParam;
  19 +import org.springframework.web.bind.annotation.RestController;
  20 +
  21 +import java.util.HashMap;
  22 +import java.util.List;
  23 +import java.util.Map;
  24 +
  25 +/**
  26 + * Created by panzhao on 2017/4/14.
  27 + */
  28 +@RestController
  29 +@RequestMapping("adminUtils")
  30 +public class AdminUtilsController {
  31 +
  32 +
  33 + Logger logger = LoggerFactory.getLogger(this.getClass());
  34 +
  35 + @Autowired
  36 + DayOfSchedule dayOfSchedule;
  37 +
  38 + @Autowired
  39 + GeoCacheData geoCacheData;
  40 +
  41 + @Autowired
  42 + DayOfDirectives dayOfDirectives;
  43 +
  44 + @Autowired
  45 + SendUtils sendUtils;
  46 +
  47 + @Autowired
  48 + PilotReport pilotReport;
  49 +
  50 + /**
  51 + * 出现重复班次的车辆
  52 + * @param
  53 +
  54 + @RequestMapping(value = "/schRepeat", method = RequestMethod.POST)
  55 + public void schRepeat(@RequestParam String nbbm){
  56 + logger.info("前端通知,车辆 " + nbbm + "出现重复班次,开始检测...");
  57 + List<ScheduleRealInfo> list = dayOfSchedule.findByNbbm(nbbm);
  58 + logger.info("检测前,车辆班次数量:" + list.size());
  59 +
  60 + Map<Long, ScheduleRealInfo> map = new HashMap<>();
  61 + for(ScheduleRealInfo sch : list){
  62 + if(map.containsKey(sch.getId())){
  63 + logger.info("检测到重复ID: " + sch.getId());
  64 + }
  65 + map.put(sch.getId(), sch);
  66 + }
  67 +
  68 + logger.info("检测后,车辆班次数量:" + list.size());
  69 + if(map.values().size() > 0){
  70 + dayOfSchedule.replaceByNbbm(nbbm, map.values());
  71 + }
  72 + }*/
  73 +
  74 +/* @RequestMapping(value = "/directivePushQueue")
  75 + public void directivePushQueue(){
  76 + DirectivePushQueue.start();
  77 + }*/
  78 +
  79 + @RequestMapping(value = "/directiveQueueSize")
  80 + public void directiveQueueSize(){
  81 + DirectivePushQueue.size();
  82 + }
  83 +
  84 + /*@RequestMapping(value = "/webSocketPushQueue")
  85 + public void webSocketPushQueue(){
  86 + WebSocketPushQueue.start();
  87 + }*/
  88 +
  89 + @RequestMapping(value = "/webSocketQueueSize")
  90 + public void webSocketQueueSize(){
  91 + WebSocketPushQueue.size();
  92 + }
  93 +
  94 + @RequestMapping(value = "/setHttpFlag")
  95 + public void setHttpFlag(@RequestParam int flag){
  96 + if(flag != 0 && flag != -1)
  97 + return;
  98 + GpsDataLoaderThread.setFlag(flag);
  99 + }
  100 +
  101 + @RequestMapping(value = "/updateCacheBuff")
  102 + public void updateCacheBuff(){
  103 + geoCacheData.loadData();
  104 + }
  105 +
  106 + @RequestMapping(value = "/reCalcLpSch")
  107 + public void reCalcLpSch(){
  108 + dayOfSchedule._test_reCalcLpSch();
  109 + }
  110 +
  111 + @RequestMapping(value = "/findSchByLpName")
  112 + public List<ScheduleRealInfo> findSchByLpName(@RequestParam String lpName){
  113 + return dayOfSchedule.getLpScheduleMap().get(lpName);
  114 + }
  115 +
  116 + @RequestMapping(value = "/findSchByNbbm")
  117 + public List<ScheduleRealInfo> findSchByNbbm(@RequestParam String nbbm){
  118 + return dayOfSchedule.findByNbbm(nbbm);
  119 + }
  120 +
  121 + @RequestMapping(value = "/removeExecPlan")
  122 + public int removeExecPlan(@RequestParam String nbbm){
  123 + dayOfSchedule.removeExecPlan(nbbm);
  124 + return 1;
  125 + }
  126 +
  127 + @RequestMapping(value = "/sch_re_calc_id_maps")
  128 + public int reCalcIdMaps(){
  129 + return dayOfSchedule.reCalcIdMaps();
  130 + }
  131 +
  132 + @RequestMapping(value = "/sch_size_string")
  133 + public String schSizeString(){
  134 + return dayOfSchedule.sizeString();
  135 + }
  136 +
  137 + @RequestMapping(value = "/containerSize")
  138 + public Map<String, Integer> containerSize(){
  139 + Map<String, Integer> rs = new HashMap<>();
  140 + rs.put("60_size", dayOfDirectives.all60().size());
  141 + rs.put("80_size", pilotReport.findAll().size());
  142 + rs.put("nbbm_sch_size", dayOfSchedule.findAll().size());
  143 + rs.put("lp_sch_size", dayOfSchedule.findAllByLpContainer().size());
  144 + rs.put("id_sch_size", dayOfSchedule.findAllByIdContainer().size());
  145 + rs.put("pst_sch_size", dayOfSchedule.getPstSize());
  146 + rs.put("speeds_size", OverspeedProcess.size());
  147 + return rs;
  148 + }
  149 +
  150 + @RequestMapping(value = "/websocketRadioText")
  151 + public int radioText(String t, String lineCode){
  152 + sendUtils.sendRadioText(t, lineCode);
  153 + return 0;
  154 + }
  155 +
  156 + @Autowired
  157 + DirectivesPstThread directivesPstThread;
  158 +
  159 + @RequestMapping(value = "/_sd_60_pst")
  160 + public void sd_60_pst(){
  161 + logger.info("手动入库指令....");
  162 + directivesPstThread.run();
  163 + }
164 164 }
165 165 \ No newline at end of file
... ...
src/main/java/com/bsth/controller/realcontrol/dto/DftzAndDestroy.java
1   -package com.bsth.controller.realcontrol.dto;
2   -
3   -/**
4   - * Created by panzhao on 2018/3/22.
5   - */
6   -public class DftzAndDestroy {
7   -
8   - /**
9   - * 要调整待发的出场班次ID
10   - */
11   - private Long dftzId;
12   -
13   - /**
14   - * 要设置的待发时间
15   - */
16   - private String newTimeStr;
17   -
18   - /**
19   - * 要烂掉的班次的 班次id ,号分割多个
20   - */
21   - private String destroyIdx;
22   -
23   - /**
24   - * 备注
25   - */
26   - private String remarks;
27   -
28   - private String reason;
29   -
30   - /**
31   - * 调派工号
32   - */
33   - private String userId;
34   -
35   - public String getNewTimeStr() {
36   - return newTimeStr;
37   - }
38   -
39   - public void setNewTimeStr(String newTimeStr) {
40   - this.newTimeStr = newTimeStr;
41   - }
42   -
43   - public String getDestroyIdx() {
44   - return destroyIdx;
45   - }
46   -
47   - public void setDestroyIdx(String destroyIdx) {
48   - this.destroyIdx = destroyIdx;
49   - }
50   -
51   - public String getRemarks() {
52   - return remarks;
53   - }
54   -
55   - public void setRemarks(String remarks) {
56   - this.remarks = remarks;
57   - }
58   -
59   - public Long getDftzId() {
60   - return dftzId;
61   - }
62   -
63   - public void setDftzId(Long dftzId) {
64   - this.dftzId = dftzId;
65   - }
66   -
67   - public String getReason() {
68   - return reason;
69   - }
70   -
71   - public void setReason(String reason) {
72   - this.reason = reason;
73   - }
74   -
75   - public String getUserId() {
76   - return userId;
77   - }
78   -
79   - public void setUserId(String userId) {
80   - this.userId = userId;
81   - }
82   -}
  1 +package com.bsth.controller.realcontrol.dto;
  2 +
  3 +/**
  4 + * Created by panzhao on 2018/3/22.
  5 + */
  6 +public class DftzAndDestroy {
  7 +
  8 + /**
  9 + * 要调整待发的出场班次ID
  10 + */
  11 + private Long dftzId;
  12 +
  13 + /**
  14 + * 要设置的待发时间
  15 + */
  16 + private String newTimeStr;
  17 +
  18 + /**
  19 + * 要烂掉的班次的 班次id ,号分割多个
  20 + */
  21 + private String destroyIdx;
  22 +
  23 + /**
  24 + * 备注
  25 + */
  26 + private String remarks;
  27 +
  28 + private String reason;
  29 +
  30 + /**
  31 + * 调派工号
  32 + */
  33 + private String userId;
  34 +
  35 + public String getNewTimeStr() {
  36 + return newTimeStr;
  37 + }
  38 +
  39 + public void setNewTimeStr(String newTimeStr) {
  40 + this.newTimeStr = newTimeStr;
  41 + }
  42 +
  43 + public String getDestroyIdx() {
  44 + return destroyIdx;
  45 + }
  46 +
  47 + public void setDestroyIdx(String destroyIdx) {
  48 + this.destroyIdx = destroyIdx;
  49 + }
  50 +
  51 + public String getRemarks() {
  52 + return remarks;
  53 + }
  54 +
  55 + public void setRemarks(String remarks) {
  56 + this.remarks = remarks;
  57 + }
  58 +
  59 + public Long getDftzId() {
  60 + return dftzId;
  61 + }
  62 +
  63 + public void setDftzId(Long dftzId) {
  64 + this.dftzId = dftzId;
  65 + }
  66 +
  67 + public String getReason() {
  68 + return reason;
  69 + }
  70 +
  71 + public void setReason(String reason) {
  72 + this.reason = reason;
  73 + }
  74 +
  75 + public String getUserId() {
  76 + return userId;
  77 + }
  78 +
  79 + public void setUserId(String userId) {
  80 + this.userId = userId;
  81 + }
  82 +}
... ...
src/main/java/com/bsth/data/schedule/e_state_check/ScheduleStationCodeChecker.java
1   -package com.bsth.data.schedule.e_state_check;
2   -
3   -import com.bsth.data.schedule.DayOfSchedule;
4   -import com.bsth.data.schedule.e_state_check.entity.SCodeInfo;
5   -import com.bsth.entity.realcontrol.ScheduleRealInfo;
6   -import com.google.common.collect.ArrayListMultimap;
7   -import org.slf4j.Logger;
8   -import org.slf4j.LoggerFactory;
9   -import org.springframework.beans.factory.annotation.Autowired;
10   -import org.springframework.jdbc.core.BeanPropertyRowMapper;
11   -import org.springframework.jdbc.core.JdbcTemplate;
12   -import org.springframework.stereotype.Component;
13   -
14   -import java.util.*;
15   -
16   -/**
17   - * 检查班次站点编码和路由编码是否相符合
18   - * Created by panzhao on 2018/4/2.
19   - */
20   -@Component
21   -public class ScheduleStationCodeChecker {
22   -
23   - @Autowired
24   - DayOfSchedule dayOfSchedule;
25   -
26   - private static ArrayListMultimap<String, SCodeInfo> multimap;
27   -
28   - static {
29   - multimap = ArrayListMultimap.create();
30   - }
31   -
32   - @Autowired
33   - JdbcTemplate jdbcTemplate;
34   -
35   - static Logger logger = LoggerFactory.getLogger(ScheduleStationCodeChecker.class);
36   -
37   - public static List<SCodeInfo> findByLineIdx(List<String> lineArray){
38   - List<SCodeInfo> rs = new ArrayList<>();
39   -
40   - try{
41   - for(String coed : lineArray){
42   - rs.addAll(multimap.get(coed));
43   - }
44   - }catch (Exception e){
45   - logger.error("", e);
46   - }
47   - return rs;
48   - }
49   -
50   - public void checkAll() {
51   - try {
52   - logger.info("start....");
53   - List<ScheduleRealInfo> all = new ArrayList(dayOfSchedule.findAll());
54   -
55   - //按线路站点分组数据(上行)
56   - Map<String, ScheduleRealInfo> ups = new HashMap<>();
57   - //按线路站点分组数据(下行)
58   - Map<String, ScheduleRealInfo> downs = new HashMap();
59   -
60   - String key;
61   - for (ScheduleRealInfo sch : all) {
62   - if (sch.getBcType().equals("out")
63   - || sch.getBcType().equals("in"))
64   - continue;
65   - key = sch.getXlBm() + "_" + sch.getXlDir() + "_";
66   -
67   - ups.put(key + sch.getQdzCode(), sch);
68   - downs.put(key + sch.getZdzCode(), sch);
69   - }
70   -
71   - //获取全部实际的站点编码
72   - Map<String, SCodeInfo> realMap = allRealCodeInfo();
73   -
74   - List<SCodeInfo> rs = new ArrayList<>();
75   - rs.addAll(checkCode(ups.values(), realMap, "qd"));
76   - rs.addAll(checkCode(downs.values(), realMap, "zd"));
77   -
78   - //按线路分组
79   - ArrayListMultimap<String, SCodeInfo> mList = ArrayListMultimap.create();
80   - for (SCodeInfo sci : rs) {
81   - mList.put(sci.getLineCode(), sci);
82   - }
83   -
84   - multimap = mList;
85   - logger.info("end....");
86   - } catch (Exception e) {
87   - logger.error("", e);
88   - }
89   - }
90   -
91   - private List<SCodeInfo> checkCode(Collection<ScheduleRealInfo> list, Map<String, SCodeInfo> realMap, String qdOrZd) {
92   - List<SCodeInfo> rs = new ArrayList<>();
93   - String k;
94   - SCodeInfo sci;
95   - for(ScheduleRealInfo sch : list){
96   - k = sch.getXlBm() + "_" + sch.getXlDir() + "_";
97   -
98   - sci = realMap.get(k + getName(sch, qdOrZd));//名称和编码都不存在
99   - if(null == sci && !realMap.containsKey(k + getCode(sch, qdOrZd))){
100   - sci = SCodeInfo.getInstance(sch, qdOrZd);
101   - rs.add(sci);
102   - continue;
103   - }
104   - else if(null != sci && !sci.getRealStationCode().equals(getCode(sch, qdOrZd))){//名称一致的站点,编码不一致
105   - sci.setStationCode(getCode(sch, qdOrZd));
106   - rs.add(sci);
107   - continue;
108   - }
109   - }
110   - return rs;
111   - }
112   -
113   - private String getName(ScheduleRealInfo sch, String qdOrZd) {
114   - return qdOrZd.equals("qd")?sch.getQdzName():sch.getZdzName();
115   - }
116   -
117   - private String getCode(ScheduleRealInfo sch, String qdOrZd) {
118   - return qdOrZd.equals("qd")?sch.getQdzCode():sch.getZdzCode();
119   - }
120   -
121   -
122   - private Map<String, SCodeInfo> allRealCodeInfo() {
123   - String sql = "select line_code,directions as up_down,station_code as real_station_code,station_name from bsth_c_stationroute where line in (select id from bsth_c_line where destroy=0) and destroy=0";
124   - List<SCodeInfo> realList = jdbcTemplate.query(sql, BeanPropertyRowMapper.newInstance(SCodeInfo.class));
125   - Map<String, SCodeInfo> realMap = new HashMap<>();
126   -
127   - for (SCodeInfo sci : realList) {
128   - realMap.put(sci.getLineCode() + "_" + sci.getUpDown() + "_" + sci.getStationName(), sci);
129   - realMap.put(sci.getLineCode() + "_" + sci.getUpDown() + "_" + sci.getRealStationCode(), sci);
130   - }
131   -
132   - return realMap;
133   - }
134   -}
  1 +package com.bsth.data.schedule.e_state_check;
  2 +
  3 +import com.alibaba.fastjson.JSON;
  4 +import com.bsth.data.schedule.DayOfSchedule;
  5 +import com.bsth.data.schedule.e_state_check.entity.SCodeInfo;
  6 +import com.bsth.entity.realcontrol.ScheduleRealInfo;
  7 +import com.google.common.collect.ArrayListMultimap;
  8 +import org.slf4j.Logger;
  9 +import org.slf4j.LoggerFactory;
  10 +import org.springframework.beans.factory.annotation.Autowired;
  11 +import org.springframework.jdbc.core.BeanPropertyRowMapper;
  12 +import org.springframework.jdbc.core.JdbcTemplate;
  13 +import org.springframework.stereotype.Component;
  14 +
  15 +import java.util.*;
  16 +
  17 +/**
  18 + * 检查班次站点编码和路由编码是否相符合
  19 + * Created by panzhao on 2018/4/2.
  20 + */
  21 +@Component
  22 +public class ScheduleStationCodeChecker {
  23 +
  24 + @Autowired
  25 + DayOfSchedule dayOfSchedule;
  26 +
  27 + private static ArrayListMultimap<String, SCodeInfo> multimap;
  28 +
  29 + static {
  30 + multimap = ArrayListMultimap.create();
  31 + }
  32 +
  33 + @Autowired
  34 + JdbcTemplate jdbcTemplate;
  35 +
  36 + static Logger logger = LoggerFactory.getLogger(ScheduleStationCodeChecker.class);
  37 +
  38 + public static List<SCodeInfo> findByLineIdx(List<String> lineArray){
  39 + List<SCodeInfo> rs = new ArrayList<>();
  40 +
  41 + try{
  42 + for(String coed : lineArray){
  43 + rs.addAll(multimap.get(coed));
  44 + }
  45 + }catch (Exception e){
  46 + logger.error("", e);
  47 + }
  48 + return rs;
  49 + }
  50 +
  51 + public void checkAll() {
  52 + try {
  53 + logger.info("start....");
  54 + List<ScheduleRealInfo> all = new ArrayList(dayOfSchedule.findAll());
  55 +
  56 + //按线路站点分组数据(上行)
  57 + Map<String, ScheduleRealInfo> ups = new HashMap<>();
  58 + //按线路站点分组数据(下行)
  59 + Map<String, ScheduleRealInfo> downs = new HashMap();
  60 +
  61 + String key;
  62 + for (ScheduleRealInfo sch : all) {
  63 + if (sch.getBcType().equals("out")
  64 + || sch.getBcType().equals("in"))
  65 + continue;
  66 +
  67 + key = sch.getXlBm() + "_" + sch.getXlDir() + "_";
  68 +
  69 + ups.put(key + sch.getQdzCode(), sch);
  70 + downs.put(key + sch.getZdzCode(), sch);
  71 + }
  72 +
  73 + //获取全部实际的站点编码
  74 + Map<String, SCodeInfo> realMap = allRealCodeInfo();
  75 +
  76 + List<SCodeInfo> rs = new ArrayList<>();
  77 + rs.addAll(checkCode(ups.values(), realMap, "qd"));
  78 + rs.addAll(checkCode(downs.values(), realMap, "zd"));
  79 +
  80 + //按线路分组
  81 + ArrayListMultimap<String, SCodeInfo> mList = ArrayListMultimap.create();
  82 + for (SCodeInfo sci : rs) {
  83 + mList.put(sci.getLineCode(), sci);
  84 + }
  85 +
  86 + multimap = mList;
  87 + logger.info("站点检查 end.... idx: " + (multimap.keySet().size() > 0 ? JSON.toJSONString(multimap.keySet()):"无"));
  88 + } catch (Exception e) {
  89 + logger.error("", e);
  90 + }
  91 + }
  92 +
  93 + private List<SCodeInfo> checkCode(Collection<ScheduleRealInfo> list, Map<String, SCodeInfo> realMap, String qdOrZd) {
  94 + List<SCodeInfo> rs = new ArrayList<>();
  95 + String k;
  96 + SCodeInfo sci;
  97 + for(ScheduleRealInfo sch : list){
  98 + k = sch.getXlBm() + "_" + sch.getXlDir() + "_";
  99 +
  100 + sci = realMap.get(k + getName(sch, qdOrZd));//名称和编码都不存在
  101 + if(null == sci && !realMap.containsKey(k + getCode(sch, qdOrZd))){
  102 + sci = SCodeInfo.getInstance(sch, qdOrZd);
  103 + rs.add(sci);
  104 + continue;
  105 + }
  106 + else if(null != sci && !sci.getRealStationCode().equals(getCode(sch, qdOrZd))){//名称一致的站点,编码不一致
  107 + sci.setStationCode(getCode(sch, qdOrZd));
  108 + rs.add(sci);
  109 + continue;
  110 + }
  111 + }
  112 + return rs;
  113 + }
  114 +
  115 + private String getName(ScheduleRealInfo sch, String qdOrZd) {
  116 + return qdOrZd.equals("qd")?sch.getQdzName():sch.getZdzName();
  117 + }
  118 +
  119 + private String getCode(ScheduleRealInfo sch, String qdOrZd) {
  120 + return qdOrZd.equals("qd")?sch.getQdzCode():sch.getZdzCode();
  121 + }
  122 +
  123 +
  124 + private Map<String, SCodeInfo> allRealCodeInfo() {
  125 + String sql = "select line_code,directions as up_down,station_code as real_station_code,station_name from bsth_c_stationroute where line in (select id from bsth_c_line where destroy=0) and destroy=0";
  126 + List<SCodeInfo> realList = jdbcTemplate.query(sql, BeanPropertyRowMapper.newInstance(SCodeInfo.class));
  127 + Map<String, SCodeInfo> realMap = new HashMap<>();
  128 +
  129 + for (SCodeInfo sci : realList) {
  130 + realMap.put(sci.getLineCode() + "_" + sci.getUpDown() + "_" + sci.getStationName(), sci);
  131 + realMap.put(sci.getLineCode() + "_" + sci.getUpDown() + "_" + sci.getRealStationCode(), sci);
  132 + }
  133 +
  134 + return realMap;
  135 + }
  136 +}
... ...
src/main/java/com/bsth/data/schedule/e_state_check/entity/SCodeInfo.java
1   -package com.bsth.data.schedule.e_state_check.entity;
2   -
3   -import com.bsth.entity.realcontrol.ScheduleRealInfo;
4   -
5   -/**
6   - * Created by panzhao on 2018/4/2.
7   - */
8   -public class SCodeInfo {
9   -
10   - /**
11   - * 线路编码
12   - */
13   - private String lineCode;
14   -
15   - /**
16   - * 上下行
17   - */
18   - private int upDown;
19   -
20   - /**
21   - * 站点编码
22   - */
23   - private String stationCode;
24   -
25   - /**
26   - * 站点名称
27   - */
28   - private String stationName;
29   -
30   - /**
31   - * 实际站点编码
32   - */
33   - private String realStationCode;
34   -
35   - public String getLineCode() {
36   - return lineCode;
37   - }
38   -
39   - public void setLineCode(String lineCode) {
40   - this.lineCode = lineCode;
41   - }
42   -
43   - public int getUpDown() {
44   - return upDown;
45   - }
46   -
47   - public void setUpDown(int upDown) {
48   - this.upDown = upDown;
49   - }
50   -
51   - public String getStationCode() {
52   - return stationCode;
53   - }
54   -
55   - public void setStationCode(String stationCode) {
56   - this.stationCode = stationCode;
57   - }
58   -
59   - public String getStationName() {
60   - return stationName;
61   - }
62   -
63   - public void setStationName(String stationName) {
64   - this.stationName = stationName;
65   - }
66   -
67   - public String getRealStationCode() {
68   - return realStationCode;
69   - }
70   -
71   - public void setRealStationCode(String realStationCode) {
72   - this.realStationCode = realStationCode;
73   - }
74   -
75   - public static SCodeInfo getUpInstance(ScheduleRealInfo sch) {
76   - SCodeInfo sci = new SCodeInfo();
77   - sci.setLineCode(sch.getXlBm());
78   - sci.setUpDown(Integer.parseInt(sch.getXlDir()));
79   - sci.setStationName(sch.getQdzName());
80   - sci.setStationCode(sch.getQdzCode());
81   - return sci;
82   - }
83   -
84   - public static SCodeInfo geDownInstance(ScheduleRealInfo sch) {
85   - SCodeInfo sci = new SCodeInfo();
86   - sci.setLineCode(sch.getXlBm());
87   - sci.setUpDown(Integer.parseInt(sch.getXlDir()));
88   - sci.setStationName(sch.getZdzName());
89   - sci.setStationCode(sch.getZdzCode());
90   - return sci;
91   - }
92   -
93   - public static SCodeInfo getInstance(ScheduleRealInfo sch, String qdOrZd) {
94   - return qdOrZd.equals("qd")?getUpInstance(sch):geDownInstance(sch);
95   - }
96   -}
  1 +package com.bsth.data.schedule.e_state_check.entity;
  2 +
  3 +import com.bsth.entity.realcontrol.ScheduleRealInfo;
  4 +
  5 +/**
  6 + * Created by panzhao on 2018/4/2.
  7 + */
  8 +public class SCodeInfo {
  9 +
  10 + /**
  11 + * 线路编码
  12 + */
  13 + private String lineCode;
  14 +
  15 + /**
  16 + * 上下行
  17 + */
  18 + private int upDown;
  19 +
  20 + /**
  21 + * 站点编码
  22 + */
  23 + private String stationCode;
  24 +
  25 + /**
  26 + * 站点名称
  27 + */
  28 + private String stationName;
  29 +
  30 + /**
  31 + * 实际站点编码
  32 + */
  33 + private String realStationCode;
  34 +
  35 + public String getLineCode() {
  36 + return lineCode;
  37 + }
  38 +
  39 + public void setLineCode(String lineCode) {
  40 + this.lineCode = lineCode;
  41 + }
  42 +
  43 + public int getUpDown() {
  44 + return upDown;
  45 + }
  46 +
  47 + public void setUpDown(int upDown) {
  48 + this.upDown = upDown;
  49 + }
  50 +
  51 + public String getStationCode() {
  52 + return stationCode;
  53 + }
  54 +
  55 + public void setStationCode(String stationCode) {
  56 + this.stationCode = stationCode;
  57 + }
  58 +
  59 + public String getStationName() {
  60 + return stationName;
  61 + }
  62 +
  63 + public void setStationName(String stationName) {
  64 + this.stationName = stationName;
  65 + }
  66 +
  67 + public String getRealStationCode() {
  68 + return realStationCode;
  69 + }
  70 +
  71 + public void setRealStationCode(String realStationCode) {
  72 + this.realStationCode = realStationCode;
  73 + }
  74 +
  75 + public static SCodeInfo getUpInstance(ScheduleRealInfo sch) {
  76 + SCodeInfo sci = new SCodeInfo();
  77 + sci.setLineCode(sch.getXlBm());
  78 + sci.setUpDown(Integer.parseInt(sch.getXlDir()));
  79 + sci.setStationName(sch.getQdzName());
  80 + sci.setStationCode(sch.getQdzCode());
  81 + return sci;
  82 + }
  83 +
  84 + public static SCodeInfo geDownInstance(ScheduleRealInfo sch) {
  85 + SCodeInfo sci = new SCodeInfo();
  86 + sci.setLineCode(sch.getXlBm());
  87 + sci.setUpDown(Integer.parseInt(sch.getXlDir()));
  88 + sci.setStationName(sch.getZdzName());
  89 + sci.setStationCode(sch.getZdzCode());
  90 + return sci;
  91 + }
  92 +
  93 + public static SCodeInfo getInstance(ScheduleRealInfo sch, String qdOrZd) {
  94 + return qdOrZd.equals("qd")?getUpInstance(sch):geDownInstance(sch);
  95 + }
  96 +}
... ...
src/main/java/com/bsth/data/schedule/e_state_check/thread/FixedCheckStationCodeThread.java
1   -package com.bsth.data.schedule.e_state_check.thread;
2   -
3   -import com.bsth.data.schedule.e_state_check.ScheduleStationCodeChecker;
4   -import org.slf4j.Logger;
5   -import org.slf4j.LoggerFactory;
6   -import org.springframework.beans.factory.annotation.Autowired;
7   -import org.springframework.stereotype.Component;
8   -
9   -/**
10   - * 定时检查班次站点编码线程
11   - * Created by panzhao on 2018/4/2.
12   - */
13   -@Component
14   -public class FixedCheckStationCodeThread extends Thread {
15   -
16   - @Autowired
17   - ScheduleStationCodeChecker scheduleStationCodeChecker;
18   -
19   - Logger logger = LoggerFactory.getLogger(this.getClass());
20   -
21   - @Override
22   - public void run() {
23   - try {
24   - scheduleStationCodeChecker.checkAll();
25   - } catch (Exception e) {
26   - logger.error("", e);
27   - }
28   - }
29   -}
  1 +package com.bsth.data.schedule.e_state_check.thread;
  2 +
  3 +import com.bsth.data.schedule.e_state_check.ScheduleStationCodeChecker;
  4 +import org.slf4j.Logger;
  5 +import org.slf4j.LoggerFactory;
  6 +import org.springframework.beans.factory.annotation.Autowired;
  7 +import org.springframework.stereotype.Component;
  8 +
  9 +/**
  10 + * 定时检查班次站点编码线程
  11 + * Created by panzhao on 2018/4/2.
  12 + */
  13 +@Component
  14 +public class FixedCheckStationCodeThread extends Thread {
  15 +
  16 + @Autowired
  17 + ScheduleStationCodeChecker scheduleStationCodeChecker;
  18 +
  19 + Logger logger = LoggerFactory.getLogger(this.getClass());
  20 +
  21 + @Override
  22 + public void run() {
  23 + try {
  24 + scheduleStationCodeChecker.checkAll();
  25 + } catch (Exception e) {
  26 + logger.error("", e);
  27 + }
  28 + }
  29 +}
... ...
src/main/java/com/bsth/data/schedule/external/TccExternalService.java
1   -package com.bsth.data.schedule.external;
2   -
3   -import com.bsth.common.ResponseCode;
4   -import com.bsth.controller.realcontrol.dto.ChangePersonCar;
5   -import com.bsth.controller.realcontrol.dto.DftzAndDestroy;
6   -import com.bsth.data.schedule.DayOfSchedule;
7   -import com.bsth.entity.realcontrol.ScheduleRealInfo;
8   -import com.bsth.service.realcontrol.ScheduleRealInfoService;
9   -import com.bsth.websocket.handler.SendUtils;
10   -import org.apache.commons.lang3.StringUtils;
11   -import org.slf4j.Logger;
12   -import org.slf4j.LoggerFactory;
13   -import org.springframework.beans.factory.annotation.Autowired;
14   -import org.springframework.stereotype.Component;
15   -
16   -import java.util.*;
17   -
18   -/**
19   - * 对停车场开放的班次调度服务
20   - * Created by panzhao on 2018/3/22.
21   - */
22   -@Component
23   -public class TccExternalService {
24   -
25   - Logger logger = LoggerFactory.getLogger(TccExternalService.class);
26   -
27   - @Autowired
28   - DayOfSchedule dayOfSchedule;
29   -
30   - @Autowired
31   - ScheduleRealInfoService scheduleRealInfoService;
32   -
33   - @Autowired
34   - SendUtils sendUtils;
35   -
36   - /**
37   - * 待发调整
38   - *
39   - * @param dad
40   - * @return
41   - */
42   - public Map<String, Object> dftz(DftzAndDestroy dad) {
43   - Map<String, Object> rs = new HashMap();
44   - rs.put("status", ResponseCode.ERROR);
45   - try {
46   - List<ScheduleRealInfo> updateList = new ArrayList<>();//要刷新的班次
47   - ScheduleRealInfo sch = dayOfSchedule.get(dad.getDftzId());
48   - if (null == sch) {
49   - rs.put("msg", "班次已经不存在了!");
50   - return rs;
51   - }
52   -
53   - if (!sch.getBcType().equals("out")) {
54   - rs.put("msg", "只能操作出场班次!");
55   - return rs;
56   - }
57   -
58   - //调整待发时间
59   - scheduleRealInfoService.outgoAdjust(sch.getId(), dad.getRemarks(), dad.getNewTimeStr(), sch.getBcType(), "4", dad.getUserId());
60   - updateList.add(sch);
61   -
62   - //需要烂班的班次
63   - if (StringUtils.isNotEmpty(dad.getDestroyIdx())) {
64   - Map<String, Object> dMap =
65   - scheduleRealInfoService.destroy(dad.getDestroyIdx(), dad.getRemarks(), dad.getReason(), dad.getUserId());
66   -
67   -
68   - updateList.addAll((Collection<? extends ScheduleRealInfo>) dMap.get("ts"));
69   - }
70   -
71   - //通知调度客户端更新班次信息
72   - sendUpdate2Page(updateList);
73   -
74   - rs.put("status", ResponseCode.SUCCESS);
75   - rs.put("t", sch);
76   - } catch (Exception e) {
77   - rs.put("msg", "内部调度服务接口出现异常!");
78   - logger.error("", e);
79   - }
80   - return rs;
81   - }
82   -
83   - /**
84   - * 换人换车
85   - *
86   - * @param cpcs
87   - * @return
88   - */
89   - public Map<String, Object> hrhc(List<ChangePersonCar> cpcs,String tccCode, String userId) {
90   - Map<String, Object> rs = new HashMap();
91   - rs.put("status", ResponseCode.ERROR);
92   - try {
93   - rs = scheduleRealInfoService.multi_tzrc(cpcs, userId);
94   -
95   - //通知调度客户端更新班次信息
96   - sendUpdate2Page(new ArrayList<ScheduleRealInfo>((Set)rs.get("ts")));
97   -
98   - //返回更新结果集中指定停车场的进出场班次
99   - Set<ScheduleRealInfo> ts = (Set<ScheduleRealInfo>) rs.get("ts");
100   - List<ScheduleRealInfo> list = new ArrayList<>();
101   - for(ScheduleRealInfo sch : ts){
102   - if((sch.getBcType().equals("out") && sch.getQdzCode().equals(tccCode))
103   - || (sch.getBcType().equals("in") && sch.getZdzCode().equals(tccCode)))
104   - list.add(sch);
105   - }
106   - rs.put("list", list);
107   - rs.remove("ts");
108   - } catch (Exception e) {
109   - rs.put("msg", "服务器出现异常!");
110   - logger.error("", e);
111   - }
112   - return rs;
113   - }
114   -
115   -
116   - public void sendUpdate2Page(List<ScheduleRealInfo> list) {
117   - sendUtils.refreshSch(list);
118   - }
119   -}
  1 +package com.bsth.data.schedule.external;
  2 +
  3 +import com.bsth.common.ResponseCode;
  4 +import com.bsth.controller.realcontrol.dto.ChangePersonCar;
  5 +import com.bsth.controller.realcontrol.dto.DftzAndDestroy;
  6 +import com.bsth.data.schedule.DayOfSchedule;
  7 +import com.bsth.entity.realcontrol.ScheduleRealInfo;
  8 +import com.bsth.service.realcontrol.ScheduleRealInfoService;
  9 +import com.bsth.websocket.handler.SendUtils;
  10 +import org.apache.commons.lang3.StringUtils;
  11 +import org.slf4j.Logger;
  12 +import org.slf4j.LoggerFactory;
  13 +import org.springframework.beans.factory.annotation.Autowired;
  14 +import org.springframework.stereotype.Component;
  15 +
  16 +import java.util.*;
  17 +
  18 +/**
  19 + * 对停车场开放的班次调度服务
  20 + * Created by panzhao on 2018/3/22.
  21 + */
  22 +@Component
  23 +public class TccExternalService {
  24 +
  25 + Logger logger = LoggerFactory.getLogger(TccExternalService.class);
  26 +
  27 + @Autowired
  28 + DayOfSchedule dayOfSchedule;
  29 +
  30 + @Autowired
  31 + ScheduleRealInfoService scheduleRealInfoService;
  32 +
  33 + @Autowired
  34 + SendUtils sendUtils;
  35 +
  36 + /**
  37 + * 待发调整
  38 + *
  39 + * @param dad
  40 + * @return
  41 + */
  42 + public Map<String, Object> dftz(DftzAndDestroy dad) {
  43 + Map<String, Object> rs = new HashMap();
  44 + rs.put("status", ResponseCode.ERROR);
  45 + try {
  46 + List<ScheduleRealInfo> updateList = new ArrayList<>();//要刷新的班次
  47 + ScheduleRealInfo sch = dayOfSchedule.get(dad.getDftzId());
  48 + if (null == sch) {
  49 + rs.put("msg", "班次已经不存在了!");
  50 + return rs;
  51 + }
  52 +
  53 + if (!sch.getBcType().equals("out")) {
  54 + rs.put("msg", "只能操作出场班次!");
  55 + return rs;
  56 + }
  57 +
  58 + //调整待发时间
  59 + scheduleRealInfoService.outgoAdjust(sch.getId(), dad.getRemarks(), dad.getNewTimeStr(), sch.getBcType(), "4", dad.getUserId());
  60 + updateList.add(sch);
  61 +
  62 + //需要烂班的班次
  63 + if (StringUtils.isNotEmpty(dad.getDestroyIdx())) {
  64 + Map<String, Object> dMap =
  65 + scheduleRealInfoService.destroy(dad.getDestroyIdx(), dad.getRemarks(), dad.getReason(), dad.getUserId());
  66 +
  67 +
  68 + updateList.addAll((Collection<? extends ScheduleRealInfo>) dMap.get("ts"));
  69 + }
  70 +
  71 + //通知调度客户端更新班次信息
  72 + sendUpdate2Page(updateList);
  73 +
  74 + rs.put("status", ResponseCode.SUCCESS);
  75 + rs.put("t", sch);
  76 + } catch (Exception e) {
  77 + rs.put("msg", "内部调度服务接口出现异常!");
  78 + logger.error("", e);
  79 + }
  80 + return rs;
  81 + }
  82 +
  83 + /**
  84 + * 换人换车
  85 + *
  86 + * @param cpcs
  87 + * @return
  88 + */
  89 + public Map<String, Object> hrhc(List<ChangePersonCar> cpcs,String tccCode, String userId) {
  90 + Map<String, Object> rs = new HashMap();
  91 + rs.put("status", ResponseCode.ERROR);
  92 + try {
  93 + rs = scheduleRealInfoService.multi_tzrc(cpcs, userId);
  94 +
  95 + //通知调度客户端更新班次信息
  96 + sendUpdate2Page(new ArrayList<ScheduleRealInfo>((Set)rs.get("ts")));
  97 +
  98 + //返回更新结果集中指定停车场的进出场班次
  99 + Set<ScheduleRealInfo> ts = (Set<ScheduleRealInfo>) rs.get("ts");
  100 + List<ScheduleRealInfo> list = new ArrayList<>();
  101 + for(ScheduleRealInfo sch : ts){
  102 + if((sch.getBcType().equals("out") && sch.getQdzCode().equals(tccCode))
  103 + || (sch.getBcType().equals("in") && sch.getZdzCode().equals(tccCode)))
  104 + list.add(sch);
  105 + }
  106 + rs.put("list", list);
  107 + rs.remove("ts");
  108 + } catch (Exception e) {
  109 + rs.put("msg", "服务器出现异常!");
  110 + logger.error("", e);
  111 + }
  112 + return rs;
  113 + }
  114 +
  115 +
  116 + public void sendUpdate2Page(List<ScheduleRealInfo> list) {
  117 + sendUtils.refreshSch(list);
  118 + }
  119 +}
... ...
src/main/java/com/bsth/repository/LineVersionsRepository.java
... ... @@ -43,7 +43,7 @@ public interface LineVersionsRepository extends BaseRepository&lt;LineVersions, Int
43 43 /**
44 44 * 查询待更新线路的线路版本
45 45 */
46   - @Query(value = "SELECT lv FROM LineVersions lv where lv.status = 2 and lv.startDate<sysdate() and lv.endDate > sysdate()")
  46 + @Query(value = "SELECT lv FROM LineVersions lv where lv.status = 2 and lv.startDate<sysdate() and lv.endDate > sysdate() and lv.isupdate != 1")
47 47 public List<LineVersions> findupdated();
48 48  
49 49 /**
... ...
src/main/java/com/bsth/repository/LsSectionRouteRepository.java
... ... @@ -28,7 +28,7 @@ public interface LsSectionRouteRepository extends BaseRepository&lt;LsSectionRoute,
28 28 /**
29 29 * 查询待更新线路的路段路由
30 30 */
31   - @Query(value = "SELECT sr FROM LsSectionRoute sr where sr.line.id =?1 and sr.lineCode=?2 and sr.versions=?3")
  31 + @Query(value = "SELECT sr FROM LsSectionRoute sr where sr.line.id =?1 and sr.lineCode=?2 and sr.versions=?3 and sr.destroy=0")
32 32 public List<LsSectionRoute> findupdated(Integer lineId,String lineCode,Integer versions);
33 33  
34 34 /**
... ...
src/main/java/com/bsth/repository/LsStationRouteRepository.java
... ... @@ -30,7 +30,7 @@ public interface LsStationRouteRepository extends BaseRepository&lt;LsStationRoute,
30 30 * 查询待更新线路的站点路由
31 31 */
32 32 @EntityGraph(value = "ls_stationRoute_station", type = EntityGraph.EntityGraphType.FETCH)
33   - @Query(value = "SELECT DISTINCT sr FROM LsStationRoute sr where sr.line.id =?1 and sr.lineCode=?2 and sr.versions=?3")
  33 + @Query(value = "SELECT DISTINCT sr FROM LsStationRoute sr where sr.line.id =?1 and sr.lineCode=?2 and sr.versions=?3 and sr.destroy=0")
34 34 List<LsStationRoute> findupdated(Integer lineId, String lineCode, Integer versions);
35 35  
36 36 /**
... ...
src/main/java/com/bsth/service/realcontrol/impl/ScheduleRealInfoServiceImpl.java
... ... @@ -190,6 +190,11 @@ public class ScheduleRealInfoServiceImpl extends BaseServiceImpl&lt;ScheduleRealInf
190 190 ScheduleRealInfo sch = dayOfSchedule.get(schId);
191 191 String gsbm = sch.getGsBm(), fgsbm = sch.getFgsBm();
192 192  
  193 + if(StringUtils.isBlank(jGh) || "/".equals(StringUtils.trim(jGh))){
  194 + rs.put("msg", "无效的参数【驾驶员】");
  195 + rs.put("status", ResponseCode.ERROR);
  196 + return rs;
  197 + }
193 198 //校验运营公司
194 199 Personnel jsy = BasicData.perMap.get(gsbm + "-" + jGh);
195 200 if (null == jsy) {
... ... @@ -197,6 +202,7 @@ public class ScheduleRealInfoServiceImpl extends BaseServiceImpl&lt;ScheduleRealInf
197 202 rs.put("msg", msg);
198 203 return rs;
199 204 }
  205 +
200 206 if (!carExist(gsbm, nbbm)) {
201 207 msg = sch.getGsName() + "没有自编号为" + "[" + nbbm + "]的车辆";
202 208 rs.put("msg", msg);
... ... @@ -1508,10 +1514,16 @@ public class ScheduleRealInfoServiceImpl extends BaseServiceImpl&lt;ScheduleRealInf
1508 1514 }
1509 1515 }
1510 1516  
  1517 + if(StringUtils.isBlank(jsy) || "/".equals(StringUtils.trim(jsy))){
  1518 + rs.put("status", ResponseCode.ERROR);
  1519 + rs.put("msg", "无效的参数【驾驶员】");
  1520 + return rs;
  1521 + }
  1522 +
1511 1523 /**
1512 1524 * 换驾驶员
1513 1525 */
1514   - if (StringUtils.isNotEmpty(jsy) && jsy.indexOf("/") != -1) {
  1526 + if (StringUtils.isNotEmpty(jsy)) {
1515 1527 String jGh = jsy.split("/")[0];
1516 1528 String jName = getPersonName(sch.getGsBm(), jGh);
1517 1529 if (StringUtils.isEmpty(jName)) {
... ... @@ -1528,8 +1540,9 @@ public class ScheduleRealInfoServiceImpl extends BaseServiceImpl&lt;ScheduleRealInf
1528 1540 * 换售票员
1529 1541 */
1530 1542 String spy = map.get("spy");
1531   - if (StringUtils.isNotEmpty(spy) && spy.indexOf("/") != -1 && !spy.equals("/")) {
  1543 + if (StringUtils.isNotEmpty(spy) && !StringUtils.trim(spy).equals("/")) {
1532 1544 String sGh = spy.split("/")[0];
  1545 +
1533 1546 String sName = getPersonName(sch.getGsBm(), sGh);
1534 1547 if (StringUtils.isEmpty(sName)) {
1535 1548 rs.put("msg", sch.getXlName() + "所属的公司编码下找不到工号为【" + sGh + "】的售票员");
... ... @@ -3480,6 +3493,7 @@ public class ScheduleRealInfoServiceImpl extends BaseServiceImpl&lt;ScheduleRealInf
3480 3493 }
3481 3494 }
3482 3495  
  3496 +
3483 3497 //为换人换车情况表写入数据
3484 3498 schModifyLog.saveChangetochange(sch, cpc, userId);
3485 3499 //日志记录
... ... @@ -3487,8 +3501,6 @@ public class ScheduleRealInfoServiceImpl extends BaseServiceImpl&lt;ScheduleRealInf
3487 3501  
3488 3502 //换驾驶员
3489 3503 if (StringUtils.isNotEmpty(cpc.getJsy())) {
3490   - /*if(!jGh.equals(sch.getjGh()))
3491   - sb.append(sch.getjGh() + " 换 " + jGh + ";");*/
3492 3504 //换驾驶员
3493 3505 if (persoChange(sch, jGh))
3494 3506 set.add(sch);
... ... @@ -3496,8 +3508,8 @@ public class ScheduleRealInfoServiceImpl extends BaseServiceImpl&lt;ScheduleRealInf
3496 3508  
3497 3509 //换售票员
3498 3510 if (StringUtils.isNotEmpty(cpc.getSpy())
3499   - && cpc.getSpy().indexOf("/") != -1
3500   - && cpc.getSpy().length() > 1) {
  3511 + && !"/".equals(StringUtils.trim(cpc.getSpy()))) {
  3512 +
3501 3513 sGh = cpc.getSpy().split("/")[0];
3502 3514 sName = getPersonName(sch.getGsBm(), sGh);
3503 3515 if (StringUtils.isEmpty(sName)) {
... ...
src/main/java/com/bsth/service/schedule/datatools/Excel2003PoiOperator.java
1   -package com.bsth.service.schedule.datatools;
2   -
3   -import org.apache.poi.hssf.usermodel.*;
4   -import org.apache.poi.ss.usermodel.*;
5   -import org.apache.poi.ss.util.WorkbookUtil;
6   -import org.apache.poi.xssf.usermodel.XSSFColor;
7   -
8   -import java.awt.Color;
9   -import java.io.File;
10   -import java.io.FileOutputStream;
11   -import java.util.Date;
12   -
13   -/**
14   - * Excel2003表格Poi操作类。
15   - * TODO:2003里面还有很多和2007不通的样式设定方式,以后再改
16   - */
17   -public class Excel2003PoiOperator implements ExcelPoiOperator {
18   - @Override
19   - public Cell createCell(
20   - Workbook workbook, Row row, short columnIndex,
21   - Object value, int valueType,
22   - HorizontalAlignment horizontalAlignment, VerticalAlignment verticalAlignment,
23   - BorderStyle borderStyle, Color borderColor,
24   - short fontSize, Color fontColor, String fontName,
25   - Color backgroudColor, FillPatternType fillPatternType) {
26   - HSSFWorkbook hssfWorkbook = (HSSFWorkbook) workbook;
27   - HSSFRow hssfRow = (HSSFRow) row;
28   -
29   - CreationHelper creationHelper = hssfWorkbook.getCreationHelper();
30   -
31   - // 1、创建单元格对象
32   - HSSFCell hssfCell = hssfRow.createCell((int) columnIndex);
33   -
34   - // 2、设定样式
35   - HSSFCellStyle hssfCellStyle = hssfWorkbook.createCellStyle();
36   -
37   - // 设定值及数据格式
38   - DataFormat dataFormat = hssfWorkbook.createDataFormat();
39   - if (valueType == HSSFCell.CELL_TYPE_STRING) {
40   - hssfCellStyle.setDataFormat(dataFormat.getFormat("@"));
41   - hssfCell.setCellValue(creationHelper.createRichTextString(String.valueOf(value)));
42   - } else if (valueType == HSSFCell.CELL_TYPE_NUMERIC) {
43   - if (value instanceof Date) { // 日期
44   - hssfCellStyle.setDataFormat(dataFormat.getFormat("yyyy-mm-dd"));
45   - hssfCell.setCellValue((Date) value);
46   - } else if (value instanceof Double) {
47   - hssfCellStyle.setDataFormat(dataFormat.getFormat("0.00"));
48   - hssfCell.setCellValue((Double) value);
49   - } else if (value instanceof Integer) {
50   - hssfCellStyle.setDataFormat(dataFormat.getFormat("0"));
51   - hssfCell.setCellValue(Double.valueOf(value.toString()));
52   - } else {
53   - throw new RuntimeException("Excel2003 只支持 String Date Double Integer 单元格类型");
54   - }
55   - } else if (valueType == HSSFCell.CELL_TYPE_BLANK) {
56   - hssfCell.setCellType(HSSFCell.CELL_TYPE_BLANK);
57   - } else {
58   - throw new RuntimeException("暂时不支持字符串、日期、数字以外的类型");
59   - }
60   -
61   - // 对齐方式
62   - hssfCellStyle.setAlignment((short) horizontalAlignment.ordinal());
63   - hssfCellStyle.setVerticalAlignment((short) verticalAlignment.ordinal());
64   -
65   - // 边框样式
66   - hssfCellStyle.setBorderTop((short) borderStyle.ordinal());
67   - hssfCellStyle.setTopBorderColor(new XSSFColor(borderColor).getIndexed());
68   - hssfCellStyle.setBorderBottom((short) borderStyle.ordinal());
69   - hssfCellStyle.setBottomBorderColor(new XSSFColor(borderColor).getIndexed());
70   - hssfCellStyle.setBorderLeft((short) borderStyle.ordinal());
71   - hssfCellStyle.setLeftBorderColor(new XSSFColor(borderColor).getIndexed());
72   - hssfCellStyle.setBorderRight((short) borderStyle.ordinal());
73   - hssfCellStyle.setRightBorderColor(new XSSFColor(borderColor).getIndexed());
74   -
75   - // 字体颜色
76   -// HSSFFont font = hssfWorkbook.createFont();
77   -// font.setColor(new XSSFColor(fontColor).getIndexed());
78   -// font.setFontHeightInPoints(fontSize);
79   -// font.setFontName(fontName);
80   -// hssfCellStyle.setFont(font);
81   -
82   -
83   - // 单元背景色
84   - hssfCellStyle.setFillForegroundColor(new XSSFColor(backgroudColor).getIndexed());
85   -// hssfCellStyle.setFillPattern((short) fillPatternType.ordinal());
86   -
87   - // TODO
88   -
89   - hssfCell.setCellStyle(hssfCellStyle);
90   - return hssfCell;
91   - }
92   -
93   - @Override
94   - public Cell createStringCell(
95   - Workbook workbook, Row row, short columnIndex,
96   - String value) {
97   - HSSFWorkbook hssfWorkbook = (HSSFWorkbook) workbook;
98   - HSSFRow hssfRow = (HSSFRow) row;
99   -
100   - HSSFCell hssfCell = (HSSFCell) createCell(
101   - hssfWorkbook, hssfRow, columnIndex,
102   - value, HSSFCell.CELL_TYPE_STRING,
103   - HorizontalAlignment.CENTER, VerticalAlignment.CENTER,
104   - BorderStyle.MEDIUM, new java.awt.Color(0xdedede),
105   - (short) 13, new java.awt.Color(0x2765A7), "宋体",
106   - new Color(0xffffff), FillPatternType.SOLID_FOREGROUND
107   - );
108   - DataFormat dataFormat = hssfWorkbook.createDataFormat();
109   - hssfCell.getCellStyle().setDataFormat(dataFormat.getFormat("@"));
110   - return hssfCell;
111   - }
112   -
113   - @Override
114   - public Cell createStringCell(
115   - Workbook workbook, Row row, short columnIndex,
116   - String value,
117   - Color backgroudColor) {
118   - HSSFWorkbook hssfWorkbook = (HSSFWorkbook) workbook;
119   - HSSFRow hssfRow = (HSSFRow) row;
120   -
121   - HSSFCell hssfCell = (HSSFCell) createCell(
122   - hssfWorkbook, hssfRow, columnIndex,
123   - value, HSSFCell.CELL_TYPE_STRING,
124   - HorizontalAlignment.CENTER, VerticalAlignment.CENTER,
125   - BorderStyle.MEDIUM, new java.awt.Color(0xdedede),
126   - (short) 13, new java.awt.Color(0x2765A7), "宋体",
127   - backgroudColor, FillPatternType.SOLID_FOREGROUND
128   - );
129   - DataFormat dataFormat = hssfWorkbook.createDataFormat();
130   - hssfCell.getCellStyle().setDataFormat(dataFormat.getFormat("@"));
131   - return hssfCell;
132   - }
133   -
134   - @Override
135   - public Cell createIntegerCell(
136   - Workbook workbook, Row row, short columnIndex,
137   - Integer value) {
138   - HSSFWorkbook hssfWorkbook = (HSSFWorkbook) workbook;
139   - HSSFRow hssfRow = (HSSFRow) row;
140   -
141   - HSSFCell hssfCell = (HSSFCell) createCell(
142   - hssfWorkbook, hssfRow, columnIndex,
143   - value, HSSFCell.CELL_TYPE_NUMERIC,
144   - HorizontalAlignment.CENTER, VerticalAlignment.CENTER,
145   - BorderStyle.MEDIUM, new Color(0xdedede),
146   - (short) 13, new Color(0x2765A7), "宋体",
147   - new Color(0xffffff), FillPatternType.SOLID_FOREGROUND
148   - );
149   -
150   - DataFormat dataFormat = hssfWorkbook.createDataFormat();
151   - hssfCell.getCellStyle().setDataFormat(dataFormat.getFormat("0"));
152   - return hssfCell;
153   - }
154   -
155   - @Override
156   - public Cell createIntegerCell(
157   - Workbook workbook, Row row, short columnIndex,
158   - Integer value,
159   - Color backgroudColor) {
160   - HSSFWorkbook hssfWorkbook = (HSSFWorkbook) workbook;
161   - HSSFRow hssfRow = (HSSFRow) row;
162   -
163   - HSSFCell hssfCell = (HSSFCell) createCell(
164   - hssfWorkbook, hssfRow, columnIndex,
165   - value, HSSFCell.CELL_TYPE_NUMERIC,
166   - HorizontalAlignment.CENTER, VerticalAlignment.CENTER,
167   - BorderStyle.MEDIUM, new Color(0xdedede),
168   - (short) 13, new Color(0x2765A7), "宋体",
169   - backgroudColor, FillPatternType.SOLID_FOREGROUND
170   - );
171   -
172   - DataFormat dataFormat = hssfWorkbook.createDataFormat();
173   - hssfCell.getCellStyle().setDataFormat(dataFormat.getFormat("0"));
174   - return hssfCell;
175   - }
176   -
177   - @Override
178   - public Cell createDoubleCell(
179   - Workbook workbook, Row row, short columnIndex,
180   - Double value) {
181   - HSSFWorkbook hssfWorkbook = (HSSFWorkbook) workbook;
182   - HSSFRow hssfRow = (HSSFRow) row;
183   -
184   - HSSFCell hssfCell = (HSSFCell) createCell(
185   - hssfWorkbook, hssfRow, columnIndex,
186   - value, HSSFCell.CELL_TYPE_NUMERIC,
187   - HorizontalAlignment.CENTER, VerticalAlignment.CENTER,
188   - BorderStyle.MEDIUM, new Color(0xdedede),
189   - (short) 13, new Color(0x2765A7), "宋体",
190   - new Color(0xffffff), FillPatternType.SOLID_FOREGROUND
191   - );
192   -
193   - DataFormat dataFormat = hssfWorkbook.createDataFormat();
194   - hssfCell.getCellStyle().setDataFormat(dataFormat.getFormat("0.00"));
195   - return hssfCell;
196   - }
197   -
198   - @Override
199   - public Cell createDoubleCell(
200   - Workbook workbook, Row row, short columnIndex,
201   - Double value,
202   - Color backgroudColor) {
203   - HSSFWorkbook hssfWorkbook = (HSSFWorkbook) workbook;
204   - HSSFRow hssfRow = (HSSFRow) row;
205   -
206   - HSSFCell hssfCell = (HSSFCell) createCell(
207   - hssfWorkbook, hssfRow, columnIndex,
208   - value, HSSFCell.CELL_TYPE_NUMERIC,
209   - HorizontalAlignment.CENTER, VerticalAlignment.CENTER,
210   - BorderStyle.MEDIUM, new Color(0xdedede),
211   - (short) 13, new Color(0x2765A7), "宋体",
212   - backgroudColor, FillPatternType.SOLID_FOREGROUND
213   - );
214   -
215   - DataFormat dataFormat = hssfWorkbook.createDataFormat();
216   - hssfCell.getCellStyle().setDataFormat(dataFormat.getFormat("0.00"));
217   - return hssfCell;
218   - }
219   -
220   - @Override
221   - public Cell createBlankCell(Workbook workbook, Row row, short columnIndex) {
222   - return createCell(
223   - workbook, row, columnIndex,
224   - null, HSSFCell.CELL_TYPE_BLANK,
225   - HorizontalAlignment.CENTER, VerticalAlignment.CENTER,
226   - BorderStyle.MEDIUM, new Color(0xdedede),
227   - (short) 13, new Color(0x2765A7), "宋体",
228   - new Color(0xffffff), FillPatternType.SOLID_FOREGROUND
229   - );
230   - }
231   -
232   - @Override
233   - public Cell setCellDataFormat(Workbook workbook, Cell cell, String fmt) {
234   - HSSFWorkbook hssfWorkbook = (HSSFWorkbook) workbook;
235   - DataFormat dataFormat = hssfWorkbook.createDataFormat();
236   - cell.getCellStyle().setDataFormat(dataFormat.getFormat("fmt"));
237   - return cell;
238   - }
239   -
240   - @Override
241   - public Cell setCellBackground(Cell cell, Color color) {
242   - HSSFCell hssfCell = (HSSFCell) cell;
243   - hssfCell.getCellStyle().setFillForegroundColor(new XSSFColor(color).getIndexed());
244   - return cell;
245   - }
246   -
247   - @Override
248   - public Workbook createWorkBook() {
249   - return new HSSFWorkbook();
250   - }
251   -
252   - @Override
253   - public Sheet createWorkBookSheet(Workbook workbook, String sheetName) {
254   - HSSFWorkbook hssfWorkbook = (HSSFWorkbook) workbook;
255   - return hssfWorkbook.createSheet(WorkbookUtil.createSafeSheetName(sheetName));
256   - }
257   -
258   - @Override
259   - public Row createSheetRow(Sheet sheet, int rowIndex) {
260   - HSSFSheet hssfSheet = (HSSFSheet) sheet;
261   - return hssfSheet.createRow(rowIndex);
262   - }
263   -
264   - @Override
265   - public void writeExcel(File excelFile, Workbook workbook) {
266   - try {
267   - HSSFWorkbook hssfWorkbook = (HSSFWorkbook) workbook;
268   - FileOutputStream fileOutputStream = new FileOutputStream(excelFile);
269   - hssfWorkbook.write(fileOutputStream);
270   - } catch (Exception exp) {
271   - throw new RuntimeException(exp);
272   - }
273   - }
274   -}
  1 +package com.bsth.service.schedule.datatools;
  2 +
  3 +import org.apache.poi.hssf.usermodel.*;
  4 +import org.apache.poi.ss.usermodel.*;
  5 +import org.apache.poi.ss.util.WorkbookUtil;
  6 +import org.apache.poi.xssf.usermodel.XSSFColor;
  7 +
  8 +import java.awt.Color;
  9 +import java.io.File;
  10 +import java.io.FileOutputStream;
  11 +import java.util.Date;
  12 +
  13 +/**
  14 + * Excel2003表格Poi操作类。
  15 + * TODO:2003里面还有很多和2007不通的样式设定方式,以后再改
  16 + */
  17 +public class Excel2003PoiOperator implements ExcelPoiOperator {
  18 + @Override
  19 + public Cell createCell(
  20 + Workbook workbook, Row row, short columnIndex,
  21 + Object value, int valueType,
  22 + HorizontalAlignment horizontalAlignment, VerticalAlignment verticalAlignment,
  23 + BorderStyle borderStyle, Color borderColor,
  24 + short fontSize, Color fontColor, String fontName,
  25 + Color backgroudColor, FillPatternType fillPatternType) {
  26 + HSSFWorkbook hssfWorkbook = (HSSFWorkbook) workbook;
  27 + HSSFRow hssfRow = (HSSFRow) row;
  28 +
  29 + CreationHelper creationHelper = hssfWorkbook.getCreationHelper();
  30 +
  31 + // 1、创建单元格对象
  32 + HSSFCell hssfCell = hssfRow.createCell((int) columnIndex);
  33 +
  34 + // 2、设定样式
  35 + HSSFCellStyle hssfCellStyle = hssfWorkbook.createCellStyle();
  36 +
  37 + // 设定值及数据格式
  38 + DataFormat dataFormat = hssfWorkbook.createDataFormat();
  39 + if (valueType == HSSFCell.CELL_TYPE_STRING) {
  40 + hssfCellStyle.setDataFormat(dataFormat.getFormat("@"));
  41 + hssfCell.setCellValue(creationHelper.createRichTextString(String.valueOf(value)));
  42 + } else if (valueType == HSSFCell.CELL_TYPE_NUMERIC) {
  43 + if (value instanceof Date) { // 日期
  44 + hssfCellStyle.setDataFormat(dataFormat.getFormat("yyyy-mm-dd"));
  45 + hssfCell.setCellValue((Date) value);
  46 + } else if (value instanceof Double) {
  47 + hssfCellStyle.setDataFormat(dataFormat.getFormat("0.00"));
  48 + hssfCell.setCellValue((Double) value);
  49 + } else if (value instanceof Integer) {
  50 + hssfCellStyle.setDataFormat(dataFormat.getFormat("0"));
  51 + hssfCell.setCellValue(Double.valueOf(value.toString()));
  52 + } else {
  53 + throw new RuntimeException("Excel2003 只支持 String Date Double Integer 单元格类型");
  54 + }
  55 + } else if (valueType == HSSFCell.CELL_TYPE_BLANK) {
  56 + hssfCell.setCellType(HSSFCell.CELL_TYPE_BLANK);
  57 + } else {
  58 + throw new RuntimeException("暂时不支持字符串、日期、数字以外的类型");
  59 + }
  60 +
  61 + // 对齐方式
  62 + hssfCellStyle.setAlignment((short) horizontalAlignment.ordinal());
  63 + hssfCellStyle.setVerticalAlignment((short) verticalAlignment.ordinal());
  64 +
  65 + // 边框样式
  66 + hssfCellStyle.setBorderTop((short) borderStyle.ordinal());
  67 + hssfCellStyle.setTopBorderColor(new XSSFColor(borderColor).getIndexed());
  68 + hssfCellStyle.setBorderBottom((short) borderStyle.ordinal());
  69 + hssfCellStyle.setBottomBorderColor(new XSSFColor(borderColor).getIndexed());
  70 + hssfCellStyle.setBorderLeft((short) borderStyle.ordinal());
  71 + hssfCellStyle.setLeftBorderColor(new XSSFColor(borderColor).getIndexed());
  72 + hssfCellStyle.setBorderRight((short) borderStyle.ordinal());
  73 + hssfCellStyle.setRightBorderColor(new XSSFColor(borderColor).getIndexed());
  74 +
  75 + // 字体颜色
  76 +// HSSFFont font = hssfWorkbook.createFont();
  77 +// font.setColor(new XSSFColor(fontColor).getIndexed());
  78 +// font.setFontHeightInPoints(fontSize);
  79 +// font.setFontName(fontName);
  80 +// hssfCellStyle.setFont(font);
  81 +
  82 +
  83 + // 单元背景色
  84 + hssfCellStyle.setFillForegroundColor(new XSSFColor(backgroudColor).getIndexed());
  85 +// hssfCellStyle.setFillPattern((short) fillPatternType.ordinal());
  86 +
  87 + // TODO
  88 +
  89 + hssfCell.setCellStyle(hssfCellStyle);
  90 + return hssfCell;
  91 + }
  92 +
  93 + @Override
  94 + public Cell createStringCell(
  95 + Workbook workbook, Row row, short columnIndex,
  96 + String value) {
  97 + HSSFWorkbook hssfWorkbook = (HSSFWorkbook) workbook;
  98 + HSSFRow hssfRow = (HSSFRow) row;
  99 +
  100 + HSSFCell hssfCell = (HSSFCell) createCell(
  101 + hssfWorkbook, hssfRow, columnIndex,
  102 + value, HSSFCell.CELL_TYPE_STRING,
  103 + HorizontalAlignment.CENTER, VerticalAlignment.CENTER,
  104 + BorderStyle.MEDIUM, new java.awt.Color(0xdedede),
  105 + (short) 13, new java.awt.Color(0x2765A7), "宋体",
  106 + new Color(0xffffff), FillPatternType.SOLID_FOREGROUND
  107 + );
  108 + DataFormat dataFormat = hssfWorkbook.createDataFormat();
  109 + hssfCell.getCellStyle().setDataFormat(dataFormat.getFormat("@"));
  110 + return hssfCell;
  111 + }
  112 +
  113 + @Override
  114 + public Cell createStringCell(
  115 + Workbook workbook, Row row, short columnIndex,
  116 + String value,
  117 + Color backgroudColor) {
  118 + HSSFWorkbook hssfWorkbook = (HSSFWorkbook) workbook;
  119 + HSSFRow hssfRow = (HSSFRow) row;
  120 +
  121 + HSSFCell hssfCell = (HSSFCell) createCell(
  122 + hssfWorkbook, hssfRow, columnIndex,
  123 + value, HSSFCell.CELL_TYPE_STRING,
  124 + HorizontalAlignment.CENTER, VerticalAlignment.CENTER,
  125 + BorderStyle.MEDIUM, new java.awt.Color(0xdedede),
  126 + (short) 13, new java.awt.Color(0x2765A7), "宋体",
  127 + backgroudColor, FillPatternType.SOLID_FOREGROUND
  128 + );
  129 + DataFormat dataFormat = hssfWorkbook.createDataFormat();
  130 + hssfCell.getCellStyle().setDataFormat(dataFormat.getFormat("@"));
  131 + return hssfCell;
  132 + }
  133 +
  134 + @Override
  135 + public Cell createIntegerCell(
  136 + Workbook workbook, Row row, short columnIndex,
  137 + Integer value) {
  138 + HSSFWorkbook hssfWorkbook = (HSSFWorkbook) workbook;
  139 + HSSFRow hssfRow = (HSSFRow) row;
  140 +
  141 + HSSFCell hssfCell = (HSSFCell) createCell(
  142 + hssfWorkbook, hssfRow, columnIndex,
  143 + value, HSSFCell.CELL_TYPE_NUMERIC,
  144 + HorizontalAlignment.CENTER, VerticalAlignment.CENTER,
  145 + BorderStyle.MEDIUM, new Color(0xdedede),
  146 + (short) 13, new Color(0x2765A7), "宋体",
  147 + new Color(0xffffff), FillPatternType.SOLID_FOREGROUND
  148 + );
  149 +
  150 + DataFormat dataFormat = hssfWorkbook.createDataFormat();
  151 + hssfCell.getCellStyle().setDataFormat(dataFormat.getFormat("0"));
  152 + return hssfCell;
  153 + }
  154 +
  155 + @Override
  156 + public Cell createIntegerCell(
  157 + Workbook workbook, Row row, short columnIndex,
  158 + Integer value,
  159 + Color backgroudColor) {
  160 + HSSFWorkbook hssfWorkbook = (HSSFWorkbook) workbook;
  161 + HSSFRow hssfRow = (HSSFRow) row;
  162 +
  163 + HSSFCell hssfCell = (HSSFCell) createCell(
  164 + hssfWorkbook, hssfRow, columnIndex,
  165 + value, HSSFCell.CELL_TYPE_NUMERIC,
  166 + HorizontalAlignment.CENTER, VerticalAlignment.CENTER,
  167 + BorderStyle.MEDIUM, new Color(0xdedede),
  168 + (short) 13, new Color(0x2765A7), "宋体",
  169 + backgroudColor, FillPatternType.SOLID_FOREGROUND
  170 + );
  171 +
  172 + DataFormat dataFormat = hssfWorkbook.createDataFormat();
  173 + hssfCell.getCellStyle().setDataFormat(dataFormat.getFormat("0"));
  174 + return hssfCell;
  175 + }
  176 +
  177 + @Override
  178 + public Cell createDoubleCell(
  179 + Workbook workbook, Row row, short columnIndex,
  180 + Double value) {
  181 + HSSFWorkbook hssfWorkbook = (HSSFWorkbook) workbook;
  182 + HSSFRow hssfRow = (HSSFRow) row;
  183 +
  184 + HSSFCell hssfCell = (HSSFCell) createCell(
  185 + hssfWorkbook, hssfRow, columnIndex,
  186 + value, HSSFCell.CELL_TYPE_NUMERIC,
  187 + HorizontalAlignment.CENTER, VerticalAlignment.CENTER,
  188 + BorderStyle.MEDIUM, new Color(0xdedede),
  189 + (short) 13, new Color(0x2765A7), "宋体",
  190 + new Color(0xffffff), FillPatternType.SOLID_FOREGROUND
  191 + );
  192 +
  193 + DataFormat dataFormat = hssfWorkbook.createDataFormat();
  194 + hssfCell.getCellStyle().setDataFormat(dataFormat.getFormat("0.00"));
  195 + return hssfCell;
  196 + }
  197 +
  198 + @Override
  199 + public Cell createDoubleCell(
  200 + Workbook workbook, Row row, short columnIndex,
  201 + Double value,
  202 + Color backgroudColor) {
  203 + HSSFWorkbook hssfWorkbook = (HSSFWorkbook) workbook;
  204 + HSSFRow hssfRow = (HSSFRow) row;
  205 +
  206 + HSSFCell hssfCell = (HSSFCell) createCell(
  207 + hssfWorkbook, hssfRow, columnIndex,
  208 + value, HSSFCell.CELL_TYPE_NUMERIC,
  209 + HorizontalAlignment.CENTER, VerticalAlignment.CENTER,
  210 + BorderStyle.MEDIUM, new Color(0xdedede),
  211 + (short) 13, new Color(0x2765A7), "宋体",
  212 + backgroudColor, FillPatternType.SOLID_FOREGROUND
  213 + );
  214 +
  215 + DataFormat dataFormat = hssfWorkbook.createDataFormat();
  216 + hssfCell.getCellStyle().setDataFormat(dataFormat.getFormat("0.00"));
  217 + return hssfCell;
  218 + }
  219 +
  220 + @Override
  221 + public Cell createBlankCell(Workbook workbook, Row row, short columnIndex) {
  222 + return createCell(
  223 + workbook, row, columnIndex,
  224 + null, HSSFCell.CELL_TYPE_BLANK,
  225 + HorizontalAlignment.CENTER, VerticalAlignment.CENTER,
  226 + BorderStyle.MEDIUM, new Color(0xdedede),
  227 + (short) 13, new Color(0x2765A7), "宋体",
  228 + new Color(0xffffff), FillPatternType.SOLID_FOREGROUND
  229 + );
  230 + }
  231 +
  232 + @Override
  233 + public Cell setCellDataFormat(Workbook workbook, Cell cell, String fmt) {
  234 + HSSFWorkbook hssfWorkbook = (HSSFWorkbook) workbook;
  235 + DataFormat dataFormat = hssfWorkbook.createDataFormat();
  236 + cell.getCellStyle().setDataFormat(dataFormat.getFormat("fmt"));
  237 + return cell;
  238 + }
  239 +
  240 + @Override
  241 + public Cell setCellBackground(Cell cell, Color color) {
  242 + HSSFCell hssfCell = (HSSFCell) cell;
  243 + hssfCell.getCellStyle().setFillForegroundColor(new XSSFColor(color).getIndexed());
  244 + return cell;
  245 + }
  246 +
  247 + @Override
  248 + public Workbook createWorkBook() {
  249 + return new HSSFWorkbook();
  250 + }
  251 +
  252 + @Override
  253 + public Sheet createWorkBookSheet(Workbook workbook, String sheetName) {
  254 + HSSFWorkbook hssfWorkbook = (HSSFWorkbook) workbook;
  255 + return hssfWorkbook.createSheet(WorkbookUtil.createSafeSheetName(sheetName));
  256 + }
  257 +
  258 + @Override
  259 + public Row createSheetRow(Sheet sheet, int rowIndex) {
  260 + HSSFSheet hssfSheet = (HSSFSheet) sheet;
  261 + return hssfSheet.createRow(rowIndex);
  262 + }
  263 +
  264 + @Override
  265 + public void writeExcel(File excelFile, Workbook workbook) {
  266 + try {
  267 + HSSFWorkbook hssfWorkbook = (HSSFWorkbook) workbook;
  268 + FileOutputStream fileOutputStream = new FileOutputStream(excelFile);
  269 + hssfWorkbook.write(fileOutputStream);
  270 + } catch (Exception exp) {
  271 + throw new RuntimeException(exp);
  272 + }
  273 + }
  274 +}
... ...
src/main/java/com/bsth/service/schedule/datatools/Excel2007PoiOperator.java
1   -package com.bsth.service.schedule.datatools;
2   -
3   -import org.apache.poi.ss.usermodel.*;
4   -import org.apache.poi.ss.util.WorkbookUtil;
5   -import org.apache.poi.xssf.usermodel.*;
6   -
7   -import java.awt.Color;
8   -import java.io.File;
9   -import java.io.FileOutputStream;
10   -import java.util.Date;
11   -
12   -/**
13   - * Excel2007表格Poi操作类。
14   - * TODO:以后测style需要重用
15   - */
16   -public class Excel2007PoiOperator implements ExcelPoiOperator {
17   - @Override
18   - public Cell createCell(
19   - Workbook workbook, Row row, short columnIndex,
20   - Object value, int valueType,
21   - HorizontalAlignment horizontalAlignment, VerticalAlignment verticalAlignment,
22   - BorderStyle borderStyle, java.awt.Color borderColor,
23   - short fontSize, java.awt.Color fontColor, String fontName,
24   - java.awt.Color backgroudColor, FillPatternType fillPatternType) {
25   -
26   - XSSFWorkbook xssfWorkbook = (XSSFWorkbook) workbook;
27   - XSSFRow xssfRow = (XSSFRow) row;
28   -
29   - CreationHelper creationHelper = xssfWorkbook.getCreationHelper();
30   -
31   - // 1、创建单元格对象
32   - XSSFCell xssfCell = xssfRow.createCell(columnIndex);
33   -
34   - // 2、设定样式
35   - XSSFCellStyle xssfCellStyle = xssfWorkbook.createCellStyle();
36   -
37   - // 设定值及数据格式
38   - DataFormat dataFormat = xssfWorkbook.createDataFormat();
39   - if (valueType == XSSFCell.CELL_TYPE_STRING) {
40   - xssfCellStyle.setDataFormat(dataFormat.getFormat("@"));
41   - xssfCell.setCellValue(creationHelper.createRichTextString(String.valueOf(value)));
42   - } else if (valueType == XSSFCell.CELL_TYPE_NUMERIC) {
43   - if (value instanceof Date) { // 日期
44   - xssfCellStyle.setDataFormat(dataFormat.getFormat("yyyy-mm-dd"));
45   - xssfCell.setCellValue((Date) value);
46   - } else if (value instanceof Double) {
47   - xssfCellStyle.setDataFormat(dataFormat.getFormat("0.00"));
48   - xssfCell.setCellValue((Double) value);
49   - } else if (value instanceof Integer) {
50   - xssfCellStyle.setDataFormat(dataFormat.getFormat("0"));
51   - xssfCell.setCellValue(Double.valueOf(value.toString()));
52   - } else {
53   - throw new RuntimeException("Excel2007 只支持 String Date Double Integer 单元格类型");
54   - }
55   - } else if (valueType == XSSFCell.CELL_TYPE_BLANK) {
56   - xssfCell.setCellType(Cell.CELL_TYPE_BLANK);
57   - } else {
58   - throw new RuntimeException("暂时不支持字符串、日期、数字以外的类型");
59   - }
60   -
61   - // 对齐方式
62   - xssfCellStyle.setAlignment(horizontalAlignment);
63   - xssfCellStyle.setVerticalAlignment(verticalAlignment);
64   -
65   - // 边框样式
66   - xssfCellStyle.setBorderTop(borderStyle);
67   - xssfCellStyle.setTopBorderColor(new XSSFColor(borderColor));
68   - xssfCellStyle.setBorderBottom(borderStyle);
69   - xssfCellStyle.setBottomBorderColor(new XSSFColor(borderColor));
70   - xssfCellStyle.setBorderLeft(borderStyle);
71   - xssfCellStyle.setLeftBorderColor(new XSSFColor(borderColor));
72   - xssfCellStyle.setBorderRight(borderStyle);
73   - xssfCellStyle.setRightBorderColor(new XSSFColor(borderColor));
74   -
75   - // 字体颜色
76   - XSSFFont font = xssfWorkbook.createFont();
77   - font.setColor(new XSSFColor(fontColor));
78   - font.setFontHeightInPoints(fontSize);
79   - font.setFontName(fontName);
80   - xssfCellStyle.setFont(font);
81   -
82   -
83   - // 单元背景色
84   - xssfCellStyle.setFillForegroundColor(new XSSFColor(backgroudColor));
85   - xssfCellStyle.setFillPattern(fillPatternType);
86   -
87   - // TODO
88   -
89   - xssfCell.setCellStyle(xssfCellStyle);
90   - return xssfCell;
91   - }
92   -
93   - @Override
94   - public Cell createStringCell(
95   - Workbook workbook, Row row, short columnIndex,
96   - String value) {
97   - XSSFWorkbook xssfWorkbook = (XSSFWorkbook) workbook;
98   - XSSFRow xssfRow = (XSSFRow) row;
99   -
100   - XSSFCell xssfCell = (XSSFCell) createCell(
101   - xssfWorkbook, xssfRow, columnIndex,
102   - value, XSSFCell.CELL_TYPE_STRING,
103   - HorizontalAlignment.CENTER, VerticalAlignment.CENTER,
104   - BorderStyle.MEDIUM, new java.awt.Color(0xdedede),
105   - (short) 13, new java.awt.Color(0x2765A7), "宋体",
106   - new Color(0xffffff), FillPatternType.SOLID_FOREGROUND
107   - );
108   - DataFormat dataFormat = xssfWorkbook.createDataFormat();
109   - xssfCell.getCellStyle().setDataFormat(dataFormat.getFormat("@"));
110   - return xssfCell;
111   - }
112   -
113   - @Override
114   - public Cell createStringCell(
115   - Workbook workbook, Row row, short columnIndex,
116   - String value,
117   - Color backgroudColor) {
118   - XSSFWorkbook xssfWorkbook = (XSSFWorkbook) workbook;
119   - XSSFRow xssfRow = (XSSFRow) row;
120   -
121   - XSSFCell xssfCell = (XSSFCell) createCell(
122   - xssfWorkbook, xssfRow, columnIndex,
123   - value, XSSFCell.CELL_TYPE_STRING,
124   - HorizontalAlignment.CENTER, VerticalAlignment.CENTER,
125   - BorderStyle.MEDIUM, new java.awt.Color(0xdedede),
126   - (short) 13, new java.awt.Color(0x2765A7), "宋体",
127   - backgroudColor, FillPatternType.SOLID_FOREGROUND
128   - );
129   - DataFormat dataFormat = xssfWorkbook.createDataFormat();
130   - xssfCell.getCellStyle().setDataFormat(dataFormat.getFormat("@"));
131   - return xssfCell;
132   - }
133   -
134   - @Override
135   - public Cell createIntegerCell(
136   - Workbook workbook, Row row, short columnIndex,
137   - Integer value) {
138   - XSSFWorkbook xssfWorkbook = (XSSFWorkbook) workbook;
139   - XSSFRow xssfRow = (XSSFRow) row;
140   -
141   - XSSFCell xssfCell = (XSSFCell) createCell(
142   - xssfWorkbook, xssfRow, columnIndex,
143   - value, XSSFCell.CELL_TYPE_NUMERIC,
144   - HorizontalAlignment.CENTER, VerticalAlignment.CENTER,
145   - BorderStyle.MEDIUM, new Color(0xdedede),
146   - (short) 13, new Color(0x2765A7), "宋体",
147   - new Color(0xffffff), FillPatternType.SOLID_FOREGROUND
148   - );
149   -
150   - DataFormat dataFormat = xssfWorkbook.createDataFormat();
151   - xssfCell.getCellStyle().setDataFormat(dataFormat.getFormat("0"));
152   - return xssfCell;
153   - }
154   -
155   - @Override
156   - public Cell createIntegerCell(
157   - Workbook workbook, Row row, short columnIndex,
158   - Integer value,
159   - Color backgroudColor) {
160   - XSSFWorkbook xssfWorkbook = (XSSFWorkbook) workbook;
161   - XSSFRow xssfRow = (XSSFRow) row;
162   -
163   - XSSFCell xssfCell = (XSSFCell) createCell(
164   - xssfWorkbook, xssfRow, columnIndex,
165   - value, XSSFCell.CELL_TYPE_NUMERIC,
166   - HorizontalAlignment.CENTER, VerticalAlignment.CENTER,
167   - BorderStyle.MEDIUM, new Color(0xdedede),
168   - (short) 13, new Color(0x2765A7), "宋体",
169   - backgroudColor, FillPatternType.SOLID_FOREGROUND
170   - );
171   -
172   - DataFormat dataFormat = xssfWorkbook.createDataFormat();
173   - xssfCell.getCellStyle().setDataFormat(dataFormat.getFormat("0"));
174   - return xssfCell;
175   - }
176   -
177   - @Override
178   - public Cell createDoubleCell(
179   - Workbook workbook, Row row, short columnIndex,
180   - Double value) {
181   - XSSFWorkbook xssfWorkbook = (XSSFWorkbook) workbook;
182   - XSSFRow xssfRow = (XSSFRow) row;
183   -
184   - XSSFCell xssfCell = (XSSFCell) createCell(
185   - xssfWorkbook, xssfRow, columnIndex,
186   - value, XSSFCell.CELL_TYPE_NUMERIC,
187   - HorizontalAlignment.CENTER, VerticalAlignment.CENTER,
188   - BorderStyle.MEDIUM, new Color(0xdedede),
189   - (short) 13, new Color(0x2765A7), "宋体",
190   - new Color(0xffffff), FillPatternType.SOLID_FOREGROUND
191   - );
192   -
193   - DataFormat dataFormat = xssfWorkbook.createDataFormat();
194   - xssfCell.getCellStyle().setDataFormat(dataFormat.getFormat("0.00"));
195   - return xssfCell;
196   - }
197   -
198   - @Override
199   - public Cell createDoubleCell(
200   - Workbook workbook, Row row, short columnIndex,
201   - Double value,
202   - Color backgroudColor) {
203   - XSSFWorkbook xssfWorkbook = (XSSFWorkbook) workbook;
204   - XSSFRow xssfRow = (XSSFRow) row;
205   -
206   - XSSFCell xssfCell = (XSSFCell) createCell(
207   - xssfWorkbook, xssfRow, columnIndex,
208   - value, XSSFCell.CELL_TYPE_NUMERIC,
209   - HorizontalAlignment.CENTER, VerticalAlignment.CENTER,
210   - BorderStyle.MEDIUM, new Color(0xdedede),
211   - (short) 13, new Color(0x2765A7), "宋体",
212   - backgroudColor, FillPatternType.SOLID_FOREGROUND
213   - );
214   -
215   - DataFormat dataFormat = xssfWorkbook.createDataFormat();
216   - xssfCell.getCellStyle().setDataFormat(dataFormat.getFormat("0.00"));
217   - return xssfCell;
218   - }
219   -
220   - @Override
221   - public Cell createBlankCell(
222   - Workbook workbook, Row row, short columnIndex) {
223   - return createCell(
224   - workbook, row, columnIndex,
225   - null, XSSFCell.CELL_TYPE_BLANK,
226   - HorizontalAlignment.CENTER, VerticalAlignment.CENTER,
227   - BorderStyle.MEDIUM, new Color(0xdedede),
228   - (short) 13, new Color(0x2765A7), "宋体",
229   - new Color(0xffffff), FillPatternType.SOLID_FOREGROUND
230   - );
231   - }
232   -
233   - @Override
234   - public Cell setCellDataFormat(Workbook workbook, Cell cell, String fmt) {
235   - XSSFWorkbook xssfWorkbook = (XSSFWorkbook) workbook;
236   - DataFormat dataFormat = xssfWorkbook.createDataFormat();
237   - cell.getCellStyle().setDataFormat(dataFormat.getFormat(fmt));
238   - return cell;
239   - }
240   -
241   - @Override
242   - public Cell setCellBackground(Cell cell, Color color) {
243   - XSSFCell xssfCell = (XSSFCell) cell;
244   - xssfCell.getCellStyle().setFillForegroundColor(new XSSFColor(color));
245   - return cell;
246   - }
247   -
248   - @Override
249   - public Workbook createWorkBook() {
250   - return new XSSFWorkbook();
251   - }
252   -
253   - @Override
254   - public Sheet createWorkBookSheet(Workbook workbook, String sheetName) {
255   - return workbook.createSheet(WorkbookUtil.createSafeSheetName(sheetName));
256   - }
257   -
258   - @Override
259   - public Row createSheetRow(Sheet sheet, int rowIndex) {
260   - XSSFSheet xssfSheet = (XSSFSheet) sheet;
261   - return xssfSheet.createRow(rowIndex);
262   - }
263   -
264   - @Override
265   - public void writeExcel(File excelFile, Workbook workbook) {
266   - try {
267   - XSSFWorkbook xssfWorkbook = (XSSFWorkbook) workbook;
268   - FileOutputStream fileOutputStream = new FileOutputStream(excelFile);
269   - xssfWorkbook.write(fileOutputStream);
270   - } catch (Exception exp) {
271   - throw new RuntimeException(exp);
272   - }
273   -
274   - }
275   -}
  1 +package com.bsth.service.schedule.datatools;
  2 +
  3 +import org.apache.poi.ss.usermodel.*;
  4 +import org.apache.poi.ss.util.WorkbookUtil;
  5 +import org.apache.poi.xssf.usermodel.*;
  6 +
  7 +import java.awt.Color;
  8 +import java.io.File;
  9 +import java.io.FileOutputStream;
  10 +import java.util.Date;
  11 +
  12 +/**
  13 + * Excel2007表格Poi操作类。
  14 + * TODO:以后测style需要重用
  15 + */
  16 +public class Excel2007PoiOperator implements ExcelPoiOperator {
  17 + @Override
  18 + public Cell createCell(
  19 + Workbook workbook, Row row, short columnIndex,
  20 + Object value, int valueType,
  21 + HorizontalAlignment horizontalAlignment, VerticalAlignment verticalAlignment,
  22 + BorderStyle borderStyle, java.awt.Color borderColor,
  23 + short fontSize, java.awt.Color fontColor, String fontName,
  24 + java.awt.Color backgroudColor, FillPatternType fillPatternType) {
  25 +
  26 + XSSFWorkbook xssfWorkbook = (XSSFWorkbook) workbook;
  27 + XSSFRow xssfRow = (XSSFRow) row;
  28 +
  29 + CreationHelper creationHelper = xssfWorkbook.getCreationHelper();
  30 +
  31 + // 1、创建单元格对象
  32 + XSSFCell xssfCell = xssfRow.createCell(columnIndex);
  33 +
  34 + // 2、设定样式
  35 + XSSFCellStyle xssfCellStyle = xssfWorkbook.createCellStyle();
  36 +
  37 + // 设定值及数据格式
  38 + DataFormat dataFormat = xssfWorkbook.createDataFormat();
  39 + if (valueType == XSSFCell.CELL_TYPE_STRING) {
  40 + xssfCellStyle.setDataFormat(dataFormat.getFormat("@"));
  41 + xssfCell.setCellValue(creationHelper.createRichTextString(String.valueOf(value)));
  42 + } else if (valueType == XSSFCell.CELL_TYPE_NUMERIC) {
  43 + if (value instanceof Date) { // 日期
  44 + xssfCellStyle.setDataFormat(dataFormat.getFormat("yyyy-mm-dd"));
  45 + xssfCell.setCellValue((Date) value);
  46 + } else if (value instanceof Double) {
  47 + xssfCellStyle.setDataFormat(dataFormat.getFormat("0.00"));
  48 + xssfCell.setCellValue((Double) value);
  49 + } else if (value instanceof Integer) {
  50 + xssfCellStyle.setDataFormat(dataFormat.getFormat("0"));
  51 + xssfCell.setCellValue(Double.valueOf(value.toString()));
  52 + } else {
  53 + throw new RuntimeException("Excel2007 只支持 String Date Double Integer 单元格类型");
  54 + }
  55 + } else if (valueType == XSSFCell.CELL_TYPE_BLANK) {
  56 + xssfCell.setCellType(Cell.CELL_TYPE_BLANK);
  57 + } else {
  58 + throw new RuntimeException("暂时不支持字符串、日期、数字以外的类型");
  59 + }
  60 +
  61 + // 对齐方式
  62 + xssfCellStyle.setAlignment(horizontalAlignment);
  63 + xssfCellStyle.setVerticalAlignment(verticalAlignment);
  64 +
  65 + // 边框样式
  66 + xssfCellStyle.setBorderTop(borderStyle);
  67 + xssfCellStyle.setTopBorderColor(new XSSFColor(borderColor));
  68 + xssfCellStyle.setBorderBottom(borderStyle);
  69 + xssfCellStyle.setBottomBorderColor(new XSSFColor(borderColor));
  70 + xssfCellStyle.setBorderLeft(borderStyle);
  71 + xssfCellStyle.setLeftBorderColor(new XSSFColor(borderColor));
  72 + xssfCellStyle.setBorderRight(borderStyle);
  73 + xssfCellStyle.setRightBorderColor(new XSSFColor(borderColor));
  74 +
  75 + // 字体颜色
  76 + XSSFFont font = xssfWorkbook.createFont();
  77 + font.setColor(new XSSFColor(fontColor));
  78 + font.setFontHeightInPoints(fontSize);
  79 + font.setFontName(fontName);
  80 + xssfCellStyle.setFont(font);
  81 +
  82 +
  83 + // 单元背景色
  84 + xssfCellStyle.setFillForegroundColor(new XSSFColor(backgroudColor));
  85 + xssfCellStyle.setFillPattern(fillPatternType);
  86 +
  87 + // TODO
  88 +
  89 + xssfCell.setCellStyle(xssfCellStyle);
  90 + return xssfCell;
  91 + }
  92 +
  93 + @Override
  94 + public Cell createStringCell(
  95 + Workbook workbook, Row row, short columnIndex,
  96 + String value) {
  97 + XSSFWorkbook xssfWorkbook = (XSSFWorkbook) workbook;
  98 + XSSFRow xssfRow = (XSSFRow) row;
  99 +
  100 + XSSFCell xssfCell = (XSSFCell) createCell(
  101 + xssfWorkbook, xssfRow, columnIndex,
  102 + value, XSSFCell.CELL_TYPE_STRING,
  103 + HorizontalAlignment.CENTER, VerticalAlignment.CENTER,
  104 + BorderStyle.MEDIUM, new java.awt.Color(0xdedede),
  105 + (short) 13, new java.awt.Color(0x2765A7), "宋体",
  106 + new Color(0xffffff), FillPatternType.SOLID_FOREGROUND
  107 + );
  108 + DataFormat dataFormat = xssfWorkbook.createDataFormat();
  109 + xssfCell.getCellStyle().setDataFormat(dataFormat.getFormat("@"));
  110 + return xssfCell;
  111 + }
  112 +
  113 + @Override
  114 + public Cell createStringCell(
  115 + Workbook workbook, Row row, short columnIndex,
  116 + String value,
  117 + Color backgroudColor) {
  118 + XSSFWorkbook xssfWorkbook = (XSSFWorkbook) workbook;
  119 + XSSFRow xssfRow = (XSSFRow) row;
  120 +
  121 + XSSFCell xssfCell = (XSSFCell) createCell(
  122 + xssfWorkbook, xssfRow, columnIndex,
  123 + value, XSSFCell.CELL_TYPE_STRING,
  124 + HorizontalAlignment.CENTER, VerticalAlignment.CENTER,
  125 + BorderStyle.MEDIUM, new java.awt.Color(0xdedede),
  126 + (short) 13, new java.awt.Color(0x2765A7), "宋体",
  127 + backgroudColor, FillPatternType.SOLID_FOREGROUND
  128 + );
  129 + DataFormat dataFormat = xssfWorkbook.createDataFormat();
  130 + xssfCell.getCellStyle().setDataFormat(dataFormat.getFormat("@"));
  131 + return xssfCell;
  132 + }
  133 +
  134 + @Override
  135 + public Cell createIntegerCell(
  136 + Workbook workbook, Row row, short columnIndex,
  137 + Integer value) {
  138 + XSSFWorkbook xssfWorkbook = (XSSFWorkbook) workbook;
  139 + XSSFRow xssfRow = (XSSFRow) row;
  140 +
  141 + XSSFCell xssfCell = (XSSFCell) createCell(
  142 + xssfWorkbook, xssfRow, columnIndex,
  143 + value, XSSFCell.CELL_TYPE_NUMERIC,
  144 + HorizontalAlignment.CENTER, VerticalAlignment.CENTER,
  145 + BorderStyle.MEDIUM, new Color(0xdedede),
  146 + (short) 13, new Color(0x2765A7), "宋体",
  147 + new Color(0xffffff), FillPatternType.SOLID_FOREGROUND
  148 + );
  149 +
  150 + DataFormat dataFormat = xssfWorkbook.createDataFormat();
  151 + xssfCell.getCellStyle().setDataFormat(dataFormat.getFormat("0"));
  152 + return xssfCell;
  153 + }
  154 +
  155 + @Override
  156 + public Cell createIntegerCell(
  157 + Workbook workbook, Row row, short columnIndex,
  158 + Integer value,
  159 + Color backgroudColor) {
  160 + XSSFWorkbook xssfWorkbook = (XSSFWorkbook) workbook;
  161 + XSSFRow xssfRow = (XSSFRow) row;
  162 +
  163 + XSSFCell xssfCell = (XSSFCell) createCell(
  164 + xssfWorkbook, xssfRow, columnIndex,
  165 + value, XSSFCell.CELL_TYPE_NUMERIC,
  166 + HorizontalAlignment.CENTER, VerticalAlignment.CENTER,
  167 + BorderStyle.MEDIUM, new Color(0xdedede),
  168 + (short) 13, new Color(0x2765A7), "宋体",
  169 + backgroudColor, FillPatternType.SOLID_FOREGROUND
  170 + );
  171 +
  172 + DataFormat dataFormat = xssfWorkbook.createDataFormat();
  173 + xssfCell.getCellStyle().setDataFormat(dataFormat.getFormat("0"));
  174 + return xssfCell;
  175 + }
  176 +
  177 + @Override
  178 + public Cell createDoubleCell(
  179 + Workbook workbook, Row row, short columnIndex,
  180 + Double value) {
  181 + XSSFWorkbook xssfWorkbook = (XSSFWorkbook) workbook;
  182 + XSSFRow xssfRow = (XSSFRow) row;
  183 +
  184 + XSSFCell xssfCell = (XSSFCell) createCell(
  185 + xssfWorkbook, xssfRow, columnIndex,
  186 + value, XSSFCell.CELL_TYPE_NUMERIC,
  187 + HorizontalAlignment.CENTER, VerticalAlignment.CENTER,
  188 + BorderStyle.MEDIUM, new Color(0xdedede),
  189 + (short) 13, new Color(0x2765A7), "宋体",
  190 + new Color(0xffffff), FillPatternType.SOLID_FOREGROUND
  191 + );
  192 +
  193 + DataFormat dataFormat = xssfWorkbook.createDataFormat();
  194 + xssfCell.getCellStyle().setDataFormat(dataFormat.getFormat("0.00"));
  195 + return xssfCell;
  196 + }
  197 +
  198 + @Override
  199 + public Cell createDoubleCell(
  200 + Workbook workbook, Row row, short columnIndex,
  201 + Double value,
  202 + Color backgroudColor) {
  203 + XSSFWorkbook xssfWorkbook = (XSSFWorkbook) workbook;
  204 + XSSFRow xssfRow = (XSSFRow) row;
  205 +
  206 + XSSFCell xssfCell = (XSSFCell) createCell(
  207 + xssfWorkbook, xssfRow, columnIndex,
  208 + value, XSSFCell.CELL_TYPE_NUMERIC,
  209 + HorizontalAlignment.CENTER, VerticalAlignment.CENTER,
  210 + BorderStyle.MEDIUM, new Color(0xdedede),
  211 + (short) 13, new Color(0x2765A7), "宋体",
  212 + backgroudColor, FillPatternType.SOLID_FOREGROUND
  213 + );
  214 +
  215 + DataFormat dataFormat = xssfWorkbook.createDataFormat();
  216 + xssfCell.getCellStyle().setDataFormat(dataFormat.getFormat("0.00"));
  217 + return xssfCell;
  218 + }
  219 +
  220 + @Override
  221 + public Cell createBlankCell(
  222 + Workbook workbook, Row row, short columnIndex) {
  223 + return createCell(
  224 + workbook, row, columnIndex,
  225 + null, XSSFCell.CELL_TYPE_BLANK,
  226 + HorizontalAlignment.CENTER, VerticalAlignment.CENTER,
  227 + BorderStyle.MEDIUM, new Color(0xdedede),
  228 + (short) 13, new Color(0x2765A7), "宋体",
  229 + new Color(0xffffff), FillPatternType.SOLID_FOREGROUND
  230 + );
  231 + }
  232 +
  233 + @Override
  234 + public Cell setCellDataFormat(Workbook workbook, Cell cell, String fmt) {
  235 + XSSFWorkbook xssfWorkbook = (XSSFWorkbook) workbook;
  236 + DataFormat dataFormat = xssfWorkbook.createDataFormat();
  237 + cell.getCellStyle().setDataFormat(dataFormat.getFormat(fmt));
  238 + return cell;
  239 + }
  240 +
  241 + @Override
  242 + public Cell setCellBackground(Cell cell, Color color) {
  243 + XSSFCell xssfCell = (XSSFCell) cell;
  244 + xssfCell.getCellStyle().setFillForegroundColor(new XSSFColor(color));
  245 + return cell;
  246 + }
  247 +
  248 + @Override
  249 + public Workbook createWorkBook() {
  250 + return new XSSFWorkbook();
  251 + }
  252 +
  253 + @Override
  254 + public Sheet createWorkBookSheet(Workbook workbook, String sheetName) {
  255 + return workbook.createSheet(WorkbookUtil.createSafeSheetName(sheetName));
  256 + }
  257 +
  258 + @Override
  259 + public Row createSheetRow(Sheet sheet, int rowIndex) {
  260 + XSSFSheet xssfSheet = (XSSFSheet) sheet;
  261 + return xssfSheet.createRow(rowIndex);
  262 + }
  263 +
  264 + @Override
  265 + public void writeExcel(File excelFile, Workbook workbook) {
  266 + try {
  267 + XSSFWorkbook xssfWorkbook = (XSSFWorkbook) workbook;
  268 + FileOutputStream fileOutputStream = new FileOutputStream(excelFile);
  269 + xssfWorkbook.write(fileOutputStream);
  270 + } catch (Exception exp) {
  271 + throw new RuntimeException(exp);
  272 + }
  273 +
  274 + }
  275 +}
... ...
src/main/java/com/bsth/service/schedule/datatools/ExcelPoiOperator.java
1   -package com.bsth.service.schedule.datatools;
2   -
3   -import org.apache.poi.ss.usermodel.*;
4   -
5   -import java.awt.Color;
6   -import java.io.File;
7   -
8   -/**
9   - * Excel表格Poi操作接口。
10   - */
11   -public interface ExcelPoiOperator {
12   -
13   -
14   - //---------------- 创建单元格 ---------------//
15   -
16   - Cell createCell(
17   - Workbook workbook, Row row, short columnIndex,
18   - Object value, int valueType,
19   - HorizontalAlignment horizontalAlignment, VerticalAlignment verticalAlignment,
20   - BorderStyle borderStyle, java.awt.Color borderColor,
21   - short fontSize, java.awt.Color fontColor, String fontName,
22   - java.awt.Color backgroudColor, FillPatternType fillPatternType
23   - );
24   -
25   - Cell createStringCell(
26   - Workbook workbook, Row row, short columnIndex,
27   - String value
28   - );
29   -
30   - Cell createStringCell(
31   - Workbook workbook, Row row, short columnIndex,
32   - String value,
33   - java.awt.Color backgroudColor
34   - );
35   -
36   - Cell createIntegerCell(
37   - Workbook workbook, Row row, short columnIndex,
38   - Integer value
39   - );
40   -
41   - Cell createIntegerCell(
42   - Workbook workbook, Row row, short columnIndex,
43   - Integer value,
44   - java.awt.Color backgroudColor
45   - );
46   -
47   - Cell createDoubleCell(
48   - Workbook workbook, Row row, short columnIndex,
49   - Double value
50   - );
51   -
52   - Cell createDoubleCell(
53   - Workbook workbook, Row row, short columnIndex,
54   - Double value,
55   - java.awt.Color backgroudColor
56   - );
57   -
58   - Cell createBlankCell(
59   - Workbook workbook, Row row, short columnIndex
60   - );
61   -
62   - //---------------- 创建单元格数据格式 ---------------//
63   -
64   - Cell setCellDataFormat(Workbook workbook, Cell cell, String fmt);
65   -
66   - Cell setCellBackground(Cell cell, Color color);
67   -
68   - //---------------- 创建workbook,sheet,row ---------------//
69   - Workbook createWorkBook();
70   - Sheet createWorkBookSheet(Workbook workbook, String sheetName);
71   - Row createSheetRow(Sheet sheet, int rowIndex);
72   -
73   - //---------------- 生成文件 ---------------//
74   - void writeExcel(File excelFile, Workbook workbook);
75   -}
  1 +package com.bsth.service.schedule.datatools;
  2 +
  3 +import org.apache.poi.ss.usermodel.*;
  4 +
  5 +import java.awt.Color;
  6 +import java.io.File;
  7 +
  8 +/**
  9 + * Excel表格Poi操作接口。
  10 + */
  11 +public interface ExcelPoiOperator {
  12 +
  13 +
  14 + //---------------- 创建单元格 ---------------//
  15 +
  16 + Cell createCell(
  17 + Workbook workbook, Row row, short columnIndex,
  18 + Object value, int valueType,
  19 + HorizontalAlignment horizontalAlignment, VerticalAlignment verticalAlignment,
  20 + BorderStyle borderStyle, java.awt.Color borderColor,
  21 + short fontSize, java.awt.Color fontColor, String fontName,
  22 + java.awt.Color backgroudColor, FillPatternType fillPatternType
  23 + );
  24 +
  25 + Cell createStringCell(
  26 + Workbook workbook, Row row, short columnIndex,
  27 + String value
  28 + );
  29 +
  30 + Cell createStringCell(
  31 + Workbook workbook, Row row, short columnIndex,
  32 + String value,
  33 + java.awt.Color backgroudColor
  34 + );
  35 +
  36 + Cell createIntegerCell(
  37 + Workbook workbook, Row row, short columnIndex,
  38 + Integer value
  39 + );
  40 +
  41 + Cell createIntegerCell(
  42 + Workbook workbook, Row row, short columnIndex,
  43 + Integer value,
  44 + java.awt.Color backgroudColor
  45 + );
  46 +
  47 + Cell createDoubleCell(
  48 + Workbook workbook, Row row, short columnIndex,
  49 + Double value
  50 + );
  51 +
  52 + Cell createDoubleCell(
  53 + Workbook workbook, Row row, short columnIndex,
  54 + Double value,
  55 + java.awt.Color backgroudColor
  56 + );
  57 +
  58 + Cell createBlankCell(
  59 + Workbook workbook, Row row, short columnIndex
  60 + );
  61 +
  62 + //---------------- 创建单元格数据格式 ---------------//
  63 +
  64 + Cell setCellDataFormat(Workbook workbook, Cell cell, String fmt);
  65 +
  66 + Cell setCellBackground(Cell cell, Color color);
  67 +
  68 + //---------------- 创建workbook,sheet,row ---------------//
  69 + Workbook createWorkBook();
  70 + Sheet createWorkBookSheet(Workbook workbook, String sheetName);
  71 + Row createSheetRow(Sheet sheet, int rowIndex);
  72 +
  73 + //---------------- 生成文件 ---------------//
  74 + void writeExcel(File excelFile, Workbook workbook);
  75 +}
... ...
src/main/java/com/bsth/service/schedule/datatools/TTinfoDetailDynamicData.java
1   -package com.bsth.service.schedule.datatools;
2   -
3   -import com.bsth.service.schedule.exception.ScheduleException;
4   -import com.bsth.service.schedule.utils.DataToolsFile;
5   -import com.bsth.service.schedule.utils.DataToolsFileType;
6   -import com.fasterxml.jackson.annotation.JsonCreator;
7   -import com.fasterxml.jackson.annotation.JsonValue;
8   -
9   -import java.util.List;
10   -
11   -/**
12   - * 动态时刻表数据。
13   - */
14   -public interface TTinfoDetailDynamicData {
15   -
16   - //---------------------- 生成时刻表用对象(以下) ---------------------//
17   - public static enum BcType { // 班次类型枚举
18   - IN("in"), // 进场
19   - OUT("out"), // 出场
20   - BD("bd"), // 早例保
21   - LC("lc"), // 晚例保
22   - NORMAL("normal"); // 正常
23   - private String flag;
24   -
25   - @JsonCreator
26   - private BcType(String flag) {
27   - this.flag = flag;
28   - }
29   -
30   - @JsonValue
31   - public String getFlag() {
32   - return flag;
33   - }
34   -
35   - public void setFlag(String flag) {
36   - this.flag = flag;
37   - }
38   - }
39   -
40   - public static class BcObj { // 班次对象
41   - /** 班次时间 */
42   - private Integer bcsj;
43   - /** 停站时间 */
44   - private Integer ssj;
45   - /** 吃饭时间 */
46   - private Integer eatsj;
47   -
48   - /** 停车场id */
49   - private Integer tccid;
50   - /** 起点站id */
51   - private Integer qdzid;
52   - /** 终点站id */
53   - private Integer zdzid;
54   -
55   - /** 是否上行 */
56   - private Boolean isUp;
57   -
58   - /** 是否分班 */
59   - private Boolean isFb;
60   -
61   - /** 班次类型 */
62   - private BcType bcType;
63   - /** 发车时刻 */
64   - private String fcsj;
65   - /** 用于统计的发车时间描述(把进出场,保养,吃饭时间写在一起) */
66   - private String fcsjDesc;
67   -
68   - /** 第几圈(从1开始) */
69   - private Integer groupNo;
70   - /** 圈里第几个班次(1或者2) */
71   - private Integer groupBcNo;
72   -
73   - public Integer getBcsj() {
74   - return bcsj;
75   - }
76   -
77   - public void setBcsj(Integer bcsj) {
78   - this.bcsj = bcsj;
79   - }
80   -
81   - public Integer getSsj() {
82   - return ssj;
83   - }
84   -
85   - public void setSsj(Integer ssj) {
86   - this.ssj = ssj;
87   - }
88   -
89   - public Integer getEatsj() {
90   - return eatsj;
91   - }
92   -
93   - public void setEatsj(Integer eatsj) {
94   - this.eatsj = eatsj;
95   - }
96   -
97   - public Integer getTccid() {
98   - return tccid;
99   - }
100   -
101   - public void setTccid(Integer tccid) {
102   - this.tccid = tccid;
103   - }
104   -
105   - public Integer getQdzid() {
106   - return qdzid;
107   - }
108   -
109   - public void setQdzid(Integer qdzid) {
110   - this.qdzid = qdzid;
111   - }
112   -
113   - public Integer getZdzid() {
114   - return zdzid;
115   - }
116   -
117   - public void setZdzid(Integer zdzid) {
118   - this.zdzid = zdzid;
119   - }
120   -
121   - public BcType getBcType() {
122   - return bcType;
123   - }
124   -
125   - public void setBcType(BcType bcType) {
126   - this.bcType = bcType;
127   - }
128   -
129   - public String getFcsj() {
130   - return fcsj;
131   - }
132   -
133   - public void setFcsj(String fcsj) {
134   - this.fcsj = fcsj;
135   - }
136   -
137   - public Boolean getIsUp() {
138   - return isUp;
139   - }
140   -
141   - public void setIsUp(Boolean isUp) {
142   - this.isUp = isUp;
143   - }
144   -
145   - public Integer getGroupNo() {
146   - return groupNo;
147   - }
148   -
149   - public void setGroupNo(Integer groupNo) {
150   - this.groupNo = groupNo;
151   - }
152   -
153   - public Integer getGroupBcNo() {
154   - return groupBcNo;
155   - }
156   -
157   - public void setGroupBcNo(Integer groupBcNo) {
158   - this.groupBcNo = groupBcNo;
159   - }
160   -
161   - public String getFcsjDesc() {
162   - return fcsjDesc;
163   - }
164   -
165   - public void setFcsjDesc(String fcsjDesc) {
166   - this.fcsjDesc = fcsjDesc;
167   - }
168   -
169   - public Boolean getIsFb() {
170   - return isFb;
171   - }
172   -
173   - public void setIsFb(Boolean fb) {
174   - isFb = fb;
175   - }
176   - }
177   -
178   - public static class LpObj { // 路牌对象
179   - /** 路牌名字 */
180   - private String lpname;
181   - /** 每圈的第一个班次是否上行 */
182   - private Boolean isUp;
183   -
184   - /** 第一个班次起点站路由id */
185   - private Integer stationRouteId1;
186   - /** 第二个班次起点站路由id */
187   - private Integer stationRouteId2;
188   -
189   - /** 班次列表 */
190   - private List<BcObj> bcObjList;
191   - /** 总圈数 */
192   - private Integer groupCount;
193   -
194   - //---------------- 路牌统计 ---------------//
195   - /** 总里程 */
196   - private Double zlc;
197   - /** 营运里程 */
198   - private Double yylc;
199   - /** 空驶里程 */
200   - private Double kslc;
201   - /** 总工时 */
202   - private Double zgs;
203   - /** 总班次 */
204   - private Integer zbc;
205   - /** 营运工时 */
206   - private Double yygs;
207   - /** 营运班次 */
208   - private Integer yybc;
209   -
210   - public String getLpname() {
211   - return lpname;
212   - }
213   -
214   - public void setLpname(String lpname) {
215   - this.lpname = lpname;
216   - }
217   -
218   - public Boolean getIsUp() {
219   - return isUp;
220   - }
221   -
222   - public void setIsUp(Boolean isUp) {
223   - this.isUp = isUp;
224   - }
225   -
226   - public List<BcObj> getBcObjList() {
227   - return bcObjList;
228   - }
229   -
230   - public void setBcObjList(List<BcObj> bcObjList) {
231   - this.bcObjList = bcObjList;
232   - }
233   -
234   - public Integer getGroupCount() {
235   - return groupCount;
236   - }
237   -
238   - public void setGroupCount(Integer groupCount) {
239   - this.groupCount = groupCount;
240   - }
241   -
242   - public Integer getStationRouteId1() {
243   - return stationRouteId1;
244   - }
245   -
246   - public void setStationRouteId1(Integer stationRouteId1) {
247   - this.stationRouteId1 = stationRouteId1;
248   - }
249   -
250   - public Integer getStationRouteId2() {
251   - return stationRouteId2;
252   - }
253   -
254   - public void setStationRouteId2(Integer stationRouteId2) {
255   - this.stationRouteId2 = stationRouteId2;
256   - }
257   -
258   - public Boolean getUp() {
259   - return isUp;
260   - }
261   -
262   - public void setUp(Boolean up) {
263   - isUp = up;
264   - }
265   -
266   - public Double getZlc() {
267   - return zlc;
268   - }
269   -
270   - public void setZlc(Double zlc) {
271   - this.zlc = zlc;
272   - }
273   -
274   - public Double getYylc() {
275   - return yylc;
276   - }
277   -
278   - public void setYylc(Double yylc) {
279   - this.yylc = yylc;
280   - }
281   -
282   - public Double getKslc() {
283   - return kslc;
284   - }
285   -
286   - public void setKslc(Double kslc) {
287   - this.kslc = kslc;
288   - }
289   -
290   - public Double getZgs() {
291   - return zgs;
292   - }
293   -
294   - public void setZgs(Double zgs) {
295   - this.zgs = zgs;
296   - }
297   -
298   - public Integer getZbc() {
299   - return zbc;
300   - }
301   -
302   - public void setZbc(Integer zbc) {
303   - this.zbc = zbc;
304   - }
305   -
306   - public Double getYygs() {
307   - return yygs;
308   - }
309   -
310   - public void setYygs(Double yygs) {
311   - this.yygs = yygs;
312   - }
313   -
314   - public Integer getYybc() {
315   - return yybc;
316   - }
317   -
318   - public void setYybc(Integer yybc) {
319   - this.yybc = yybc;
320   - }
321   -
322   - }
323   -
324   - public static class StatInfo { // 统计数据对象
325   - /** 统计项目 */
326   - private String statItem;
327   - /** 统计值 */
328   - private Double statValue;
329   -
330   - public String getStatItem() {
331   - return statItem;
332   - }
333   -
334   - public void setStatItem(String statItem) {
335   - this.statItem = statItem;
336   - }
337   -
338   - public Double getStatValue() {
339   - return statValue;
340   - }
341   -
342   - public void setStatValue(Double statValue) {
343   - this.statValue = statValue;
344   - }
345   - }
346   -
347   - public static class DTInfos { // 所有数据信息
348   - /** 路牌班次数据列表 */
349   - private List<LpObj> lpObjList;
350   - /** 统计数据列表 */
351   - private List<StatInfo> statInfoList;
352   -
353   - public List<LpObj> getLpObjList() {
354   - return lpObjList;
355   - }
356   -
357   - public void setLpObjList(List<LpObj> lpObjList) {
358   - this.lpObjList = lpObjList;
359   - }
360   -
361   - public List<StatInfo> getStatInfoList() {
362   - return statInfoList;
363   - }
364   -
365   - public void setStatInfoList(List<StatInfo> statInfoList) {
366   - this.statInfoList = statInfoList;
367   - }
368   - }
369   -
370   - //---------------------- 生成时刻表用对象(以上) ---------------------//
371   -
372   - /**
373   - * 导出动态时刻表数据。
374   - * @param dtInfos
375   - * @return
376   - * @throws ScheduleException
377   - */
378   - public DataToolsFile exportDynamicTTinfo(DTInfos dtInfos, DataToolsFileType type) throws ScheduleException;
379   -}
  1 +package com.bsth.service.schedule.datatools;
  2 +
  3 +import com.bsth.service.schedule.exception.ScheduleException;
  4 +import com.bsth.service.schedule.utils.DataToolsFile;
  5 +import com.bsth.service.schedule.utils.DataToolsFileType;
  6 +import com.fasterxml.jackson.annotation.JsonCreator;
  7 +import com.fasterxml.jackson.annotation.JsonValue;
  8 +
  9 +import java.util.List;
  10 +
  11 +/**
  12 + * 动态时刻表数据。
  13 + */
  14 +public interface TTinfoDetailDynamicData {
  15 +
  16 + //---------------------- 生成时刻表用对象(以下) ---------------------//
  17 + public static enum BcType { // 班次类型枚举
  18 + IN("in"), // 进场
  19 + OUT("out"), // 出场
  20 + BD("bd"), // 早例保
  21 + LC("lc"), // 晚例保
  22 + NORMAL("normal"); // 正常
  23 + private String flag;
  24 +
  25 + @JsonCreator
  26 + private BcType(String flag) {
  27 + this.flag = flag;
  28 + }
  29 +
  30 + @JsonValue
  31 + public String getFlag() {
  32 + return flag;
  33 + }
  34 +
  35 + public void setFlag(String flag) {
  36 + this.flag = flag;
  37 + }
  38 + }
  39 +
  40 + public static class BcObj { // 班次对象
  41 + /** 班次时间 */
  42 + private Integer bcsj;
  43 + /** 停站时间 */
  44 + private Integer ssj;
  45 + /** 吃饭时间 */
  46 + private Integer eatsj;
  47 +
  48 + /** 停车场id */
  49 + private Integer tccid;
  50 + /** 起点站id */
  51 + private Integer qdzid;
  52 + /** 终点站id */
  53 + private Integer zdzid;
  54 +
  55 + /** 是否上行 */
  56 + private Boolean isUp;
  57 +
  58 + /** 是否分班 */
  59 + private Boolean isFb;
  60 +
  61 + /** 班次类型 */
  62 + private BcType bcType;
  63 + /** 发车时刻 */
  64 + private String fcsj;
  65 + /** 用于统计的发车时间描述(把进出场,保养,吃饭时间写在一起) */
  66 + private String fcsjDesc;
  67 +
  68 + /** 第几圈(从1开始) */
  69 + private Integer groupNo;
  70 + /** 圈里第几个班次(1或者2) */
  71 + private Integer groupBcNo;
  72 +
  73 + public Integer getBcsj() {
  74 + return bcsj;
  75 + }
  76 +
  77 + public void setBcsj(Integer bcsj) {
  78 + this.bcsj = bcsj;
  79 + }
  80 +
  81 + public Integer getSsj() {
  82 + return ssj;
  83 + }
  84 +
  85 + public void setSsj(Integer ssj) {
  86 + this.ssj = ssj;
  87 + }
  88 +
  89 + public Integer getEatsj() {
  90 + return eatsj;
  91 + }
  92 +
  93 + public void setEatsj(Integer eatsj) {
  94 + this.eatsj = eatsj;
  95 + }
  96 +
  97 + public Integer getTccid() {
  98 + return tccid;
  99 + }
  100 +
  101 + public void setTccid(Integer tccid) {
  102 + this.tccid = tccid;
  103 + }
  104 +
  105 + public Integer getQdzid() {
  106 + return qdzid;
  107 + }
  108 +
  109 + public void setQdzid(Integer qdzid) {
  110 + this.qdzid = qdzid;
  111 + }
  112 +
  113 + public Integer getZdzid() {
  114 + return zdzid;
  115 + }
  116 +
  117 + public void setZdzid(Integer zdzid) {
  118 + this.zdzid = zdzid;
  119 + }
  120 +
  121 + public BcType getBcType() {
  122 + return bcType;
  123 + }
  124 +
  125 + public void setBcType(BcType bcType) {
  126 + this.bcType = bcType;
  127 + }
  128 +
  129 + public String getFcsj() {
  130 + return fcsj;
  131 + }
  132 +
  133 + public void setFcsj(String fcsj) {
  134 + this.fcsj = fcsj;
  135 + }
  136 +
  137 + public Boolean getIsUp() {
  138 + return isUp;
  139 + }
  140 +
  141 + public void setIsUp(Boolean isUp) {
  142 + this.isUp = isUp;
  143 + }
  144 +
  145 + public Integer getGroupNo() {
  146 + return groupNo;
  147 + }
  148 +
  149 + public void setGroupNo(Integer groupNo) {
  150 + this.groupNo = groupNo;
  151 + }
  152 +
  153 + public Integer getGroupBcNo() {
  154 + return groupBcNo;
  155 + }
  156 +
  157 + public void setGroupBcNo(Integer groupBcNo) {
  158 + this.groupBcNo = groupBcNo;
  159 + }
  160 +
  161 + public String getFcsjDesc() {
  162 + return fcsjDesc;
  163 + }
  164 +
  165 + public void setFcsjDesc(String fcsjDesc) {
  166 + this.fcsjDesc = fcsjDesc;
  167 + }
  168 +
  169 + public Boolean getIsFb() {
  170 + return isFb;
  171 + }
  172 +
  173 + public void setIsFb(Boolean fb) {
  174 + isFb = fb;
  175 + }
  176 + }
  177 +
  178 + public static class LpObj { // 路牌对象
  179 + /** 路牌名字 */
  180 + private String lpname;
  181 + /** 每圈的第一个班次是否上行 */
  182 + private Boolean isUp;
  183 +
  184 + /** 第一个班次起点站路由id */
  185 + private Integer stationRouteId1;
  186 + /** 第二个班次起点站路由id */
  187 + private Integer stationRouteId2;
  188 +
  189 + /** 班次列表 */
  190 + private List<BcObj> bcObjList;
  191 + /** 总圈数 */
  192 + private Integer groupCount;
  193 +
  194 + //---------------- 路牌统计 ---------------//
  195 + /** 总里程 */
  196 + private Double zlc;
  197 + /** 营运里程 */
  198 + private Double yylc;
  199 + /** 空驶里程 */
  200 + private Double kslc;
  201 + /** 总工时 */
  202 + private Double zgs;
  203 + /** 总班次 */
  204 + private Integer zbc;
  205 + /** 营运工时 */
  206 + private Double yygs;
  207 + /** 营运班次 */
  208 + private Integer yybc;
  209 +
  210 + public String getLpname() {
  211 + return lpname;
  212 + }
  213 +
  214 + public void setLpname(String lpname) {
  215 + this.lpname = lpname;
  216 + }
  217 +
  218 + public Boolean getIsUp() {
  219 + return isUp;
  220 + }
  221 +
  222 + public void setIsUp(Boolean isUp) {
  223 + this.isUp = isUp;
  224 + }
  225 +
  226 + public List<BcObj> getBcObjList() {
  227 + return bcObjList;
  228 + }
  229 +
  230 + public void setBcObjList(List<BcObj> bcObjList) {
  231 + this.bcObjList = bcObjList;
  232 + }
  233 +
  234 + public Integer getGroupCount() {
  235 + return groupCount;
  236 + }
  237 +
  238 + public void setGroupCount(Integer groupCount) {
  239 + this.groupCount = groupCount;
  240 + }
  241 +
  242 + public Integer getStationRouteId1() {
  243 + return stationRouteId1;
  244 + }
  245 +
  246 + public void setStationRouteId1(Integer stationRouteId1) {
  247 + this.stationRouteId1 = stationRouteId1;
  248 + }
  249 +
  250 + public Integer getStationRouteId2() {
  251 + return stationRouteId2;
  252 + }
  253 +
  254 + public void setStationRouteId2(Integer stationRouteId2) {
  255 + this.stationRouteId2 = stationRouteId2;
  256 + }
  257 +
  258 + public Boolean getUp() {
  259 + return isUp;
  260 + }
  261 +
  262 + public void setUp(Boolean up) {
  263 + isUp = up;
  264 + }
  265 +
  266 + public Double getZlc() {
  267 + return zlc;
  268 + }
  269 +
  270 + public void setZlc(Double zlc) {
  271 + this.zlc = zlc;
  272 + }
  273 +
  274 + public Double getYylc() {
  275 + return yylc;
  276 + }
  277 +
  278 + public void setYylc(Double yylc) {
  279 + this.yylc = yylc;
  280 + }
  281 +
  282 + public Double getKslc() {
  283 + return kslc;
  284 + }
  285 +
  286 + public void setKslc(Double kslc) {
  287 + this.kslc = kslc;
  288 + }
  289 +
  290 + public Double getZgs() {
  291 + return zgs;
  292 + }
  293 +
  294 + public void setZgs(Double zgs) {
  295 + this.zgs = zgs;
  296 + }
  297 +
  298 + public Integer getZbc() {
  299 + return zbc;
  300 + }
  301 +
  302 + public void setZbc(Integer zbc) {
  303 + this.zbc = zbc;
  304 + }
  305 +
  306 + public Double getYygs() {
  307 + return yygs;
  308 + }
  309 +
  310 + public void setYygs(Double yygs) {
  311 + this.yygs = yygs;
  312 + }
  313 +
  314 + public Integer getYybc() {
  315 + return yybc;
  316 + }
  317 +
  318 + public void setYybc(Integer yybc) {
  319 + this.yybc = yybc;
  320 + }
  321 +
  322 + }
  323 +
  324 + public static class StatInfo { // 统计数据对象
  325 + /** 统计项目 */
  326 + private String statItem;
  327 + /** 统计值 */
  328 + private Double statValue;
  329 +
  330 + public String getStatItem() {
  331 + return statItem;
  332 + }
  333 +
  334 + public void setStatItem(String statItem) {
  335 + this.statItem = statItem;
  336 + }
  337 +
  338 + public Double getStatValue() {
  339 + return statValue;
  340 + }
  341 +
  342 + public void setStatValue(Double statValue) {
  343 + this.statValue = statValue;
  344 + }
  345 + }
  346 +
  347 + public static class DTInfos { // 所有数据信息
  348 + /** 路牌班次数据列表 */
  349 + private List<LpObj> lpObjList;
  350 + /** 统计数据列表 */
  351 + private List<StatInfo> statInfoList;
  352 +
  353 + public List<LpObj> getLpObjList() {
  354 + return lpObjList;
  355 + }
  356 +
  357 + public void setLpObjList(List<LpObj> lpObjList) {
  358 + this.lpObjList = lpObjList;
  359 + }
  360 +
  361 + public List<StatInfo> getStatInfoList() {
  362 + return statInfoList;
  363 + }
  364 +
  365 + public void setStatInfoList(List<StatInfo> statInfoList) {
  366 + this.statInfoList = statInfoList;
  367 + }
  368 + }
  369 +
  370 + //---------------------- 生成时刻表用对象(以上) ---------------------//
  371 +
  372 + /**
  373 + * 导出动态时刻表数据。
  374 + * @param dtInfos
  375 + * @return
  376 + * @throws ScheduleException
  377 + */
  378 + public DataToolsFile exportDynamicTTinfo(DTInfos dtInfos, DataToolsFileType type) throws ScheduleException;
  379 +}
... ...
src/main/java/com/bsth/service/schedule/plan/DroolsSchedulePlan.java
1   -package com.bsth.service.schedule.plan;
2   -
3   -import com.bsth.entity.Line;
4   -import com.bsth.entity.schedule.SchedulePlan;
5   -import com.bsth.entity.schedule.SchedulePlanInfo;
6   -import com.bsth.entity.schedule.TTInfo;
7   -import com.bsth.entity.schedule.rule.ScheduleRule1Flat;
8   -import com.bsth.repository.BusinessRepository;
9   -import com.bsth.repository.LineRepository;
10   -import com.bsth.repository.schedule.*;
11   -import com.bsth.service.schedule.rules.ScheduleRuleService;
12   -import com.bsth.service.schedule.rules.plan.PlanCalcuParam_input;
13   -import com.bsth.service.schedule.rules.plan.PlanResult;
14   -import com.bsth.service.schedule.rules.rerun.RerunRule_input;
15   -import com.bsth.service.schedule.rules.rerun.RerunRule_param;
16   -import com.bsth.service.schedule.rules.shiftloop.ScheduleCalcuParam_input;
17   -import com.bsth.service.schedule.rules.shiftloop.ScheduleResults_output;
18   -import com.bsth.service.schedule.rules.shiftloop.ScheduleRule_input;
19   -import com.bsth.service.schedule.rules.ttinfo.*;
20   -import com.bsth.service.schedule.rules.validate.ValidateParam;
21   -import com.bsth.service.schedule.rules.validate.ValidateResults_output;
22   -import org.apache.commons.lang3.StringUtils;
23   -import org.joda.time.DateTime;
24   -import org.kie.api.KieBase;
25   -import org.kie.api.runtime.KieSession;
26   -import org.slf4j.Logger;
27   -
28   -import java.util.*;
29   -
30   -/**
31   - * 排班计划(使用Drools)。
32   - */
33   -public class DroolsSchedulePlan {
34   - /** 主线路 */
35   - private Line mainLine;
36   - /** 套跑辅线路规则 */
37   - private List<RerunRule_input> rerunRule_inputs;
38   -
39   - /** 开始排班时间 */
40   - private Date from;
41   - /** 结束排班时间 */
42   - private Date to;
43   - /** 排班计划entity */
44   - private SchedulePlan schedulePlan;
45   -
46   - //-------------------- 相关的Repo,service服务 --------------------//
47   - /** 线路Repo */
48   - private LineRepository lineRepository;
49   - /** 排班规则Repo */
50   - private ScheduleRule1FlatRepository scheduleRule1FlatRepository;
51   - /** 时刻表Repo */
52   - private TTInfoRepository ttInfoRepository;
53   - /** 时刻表明细Repo */
54   - private TTInfoDetailRepository ttInfoDetailRepository;
55   - /** 车辆配置Repo */
56   - private CarConfigInfoRepository carConfigInfoRepository;
57   - /** 人员配置Repo */
58   - private EmployeeConfigInfoRepository employeeConfigInfoRepository;
59   - /** 套跑规则Repo */
60   - private RerunRuleRepository rerunRuleRepository;
61   - /** 营运状态Repo */
62   - private BusinessRepository businessRepository;
63   -
64   - /** 排班规则service */
65   - private ScheduleRuleService scheduleRuleService;
66   -
67   - //-------------------- Drools KBase实例 ------------------//
68   - /** 排班预处理KBase */
69   - private KieBase preKBase;
70   - /** 排班核心KBase */
71   - private KieBase coreKBase;
72   -
73   - //-------------------- 日志记录器 ---------------------//
74   - private Logger logger;
75   -
76   - public DroolsSchedulePlan(
77   - SchedulePlan schedulePlan,
78   - LineRepository lineRepository, ScheduleRule1FlatRepository scheduleRule1FlatRepository,
79   - TTInfoRepository ttInfoRepository, TTInfoDetailRepository ttInfoDetailRepository,
80   - CarConfigInfoRepository carConfigInfoRepository,
81   - EmployeeConfigInfoRepository employeeConfigInfoRepository,
82   - RerunRuleRepository rerunRuleRepository,
83   - BusinessRepository businessRepository,
84   - ScheduleRuleService scheduleRuleService,
85   - KieBase preKBase, KieBase coreKBase,
86   - Logger logger) {
87   -
88   - // 验证SchedulePlan实体
89   - if (schedulePlan == null) {
90   - throw new RuntimeException("排班用SchedulePlan为空!");
91   - }
92   - if (schedulePlan.getXl() == null) {
93   - throw new RuntimeException("排班线路为空!");
94   - } else {
95   - // 获取主线路
96   - this.mainLine = lineRepository.findOne(schedulePlan.getXl().getId());
97   - if (this.mainLine == null) {
98   - throw new RuntimeException("线路id=" + schedulePlan.getXl().getId() + "不存在!");
99   - }
100   - // 获取主线路套跑信息
101   - this.rerunRule_inputs = scheduleRuleService.findRerunrule(this.mainLine.getId());
102   - }
103   - if (schedulePlan.getScheduleFromTime() == null) {
104   - throw new RuntimeException("排班开始时间为空!");
105   - }
106   - if (schedulePlan.getScheduleToTime() == null) {
107   - throw new RuntimeException("排班结束时间为空!");
108   - }
109   - this.from = schedulePlan.getScheduleFromTime();
110   - this.to = schedulePlan.getScheduleToTime();
111   - if (schedulePlan.getTtInfoIds() == null) {
112   - throw new RuntimeException("排班关联的时刻表ids为空!");
113   - }
114   - if (schedulePlan.getTtInfoNames() == null) {
115   - throw new RuntimeException("排班关联的时刻表名字s为空!");
116   - }
117   - this.schedulePlan = schedulePlan;
118   -
119   - this.lineRepository = lineRepository;
120   - this.scheduleRule1FlatRepository = scheduleRule1FlatRepository;
121   - this.ttInfoRepository = ttInfoRepository;
122   - this.ttInfoDetailRepository = ttInfoDetailRepository;
123   - this.carConfigInfoRepository = carConfigInfoRepository;
124   - this.employeeConfigInfoRepository = employeeConfigInfoRepository;
125   - this.rerunRuleRepository = rerunRuleRepository;
126   - this.businessRepository = businessRepository;
127   - this.scheduleRuleService = scheduleRuleService;
128   - this.preKBase = preKBase;
129   - this.coreKBase = coreKBase;
130   -
131   - this.logger = logger;
132   -
133   - }
134   -
135   - public void generatePlan() {
136   - logger.info("<--- 排班master线路 id={}, name={}, 开始排班",
137   - this.mainLine.getId(), this.mainLine.getName());
138   -
139   - // 1、确定主线路排班(包含完全套跑路牌规则,所谓完全套跑路牌规则指整个路牌的班次都是套跑规则指定的)
140   - PlanResult planResult = this.schedulePlanWithOutRerun();
141   -
142   - // 2、确定套跑规则
143   - this.rerunPlanResult(planResult);
144   -
145   - // TODO:3-1、验证排班结果
146   - this.validPlanResult(planResult);
147   -
148   - // TODO:3-2、去除完全套跑遗漏班次(以后放到规则中执行)
149   - Iterator<SchedulePlanInfo> infoIterator = planResult.getSchedulePlanInfos().iterator();
150   - while (infoIterator.hasNext()) {
151   - SchedulePlanInfo schedulePlanInfo = infoIterator.next();
152   - if (schedulePlanInfo.getCl() == null) {
153   - infoIterator.remove();
154   - }
155   - }
156   -
157   - // 4、保存数据(jdbcTemplate 批量插入)
158   - Date start4 = new Date();
159   - this.scheduleRuleService.generateSchedulePlan(
160   - this.schedulePlan, planResult.getSchedulePlanInfos());
161   - Date end4 = new Date();
162   -
163   - this.logger.info("保存主线路数据 {} 条 耗时 {} ms --->",
164   - planResult.getSchedulePlanInfos().size(),
165   - end4.getTime() - start4.getTime());
166   - }
167   -
168   - /**
169   - * 计算规则输入。
170   - * @return
171   - */
172   - private List<ScheduleRule_input> calcuSrfList(Line line) {
173   - // 1-1、构造drools规则输入数据,输出数据
174   - // 全局计算参数
175   - SchedulePlan schedulePlan = new SchedulePlan();
176   - schedulePlan.setXl(line);
177   - schedulePlan.setScheduleFromTime(this.from);
178   - schedulePlan.setScheduleToTime(this.to);
179   - ScheduleCalcuParam_input scheduleCalcuParam_input = new ScheduleCalcuParam_input(schedulePlan);
180   -
181   - // 规则输出数据
182   - List<ScheduleRule_input> scheduleRule_inputs = new ArrayList<>();
183   -
184   - // 1-2、构造drools session->载入数据->启动规则->计算->销毁session
185   - // 创建session,内部配置的是stateful
186   - KieSession session = preKBase.newKieSession();
187   - // 设置gloable对象,在drl中通过别名使用
188   - session.setGlobal("sriList", scheduleRule_inputs);
189   - session.setGlobal("log", logger); // 设置日志
190   -
191   - session.setGlobal("srf", scheduleRule1FlatRepository);
192   - session.setGlobal("rrr", rerunRuleRepository);
193   - session.setGlobal("srservice", scheduleRuleService);
194   -
195   - // 载入数据
196   - session.insert(scheduleCalcuParam_input);
197   -
198   - // 执行rule
199   - session.fireAllRules();
200   -
201   - // 执行完毕销毁,有日志的也要关闭
202   - session.dispose();
203   -
204   - return scheduleRule_inputs;
205   - }
206   -
207   - /**
208   - * 时刻表选择(判定每天使用的时刻表,以及路牌数据输出)。
209   - * @return [TTInfoResults_output, LpInfoResults_output]
210   - */
211   - private Object[] ttInfoOutput(Line line) {
212   - // 获取线路的所有未作废的时刻表
213   - List<TTInfo> ttInfos = ttInfoRepository.findInCanceledByXl(line);
214   -
215   - // 1-1、构造drools规则输入数据,输出数据
216   - // 全局计算参数
217   - TTInfoCalcuParam_input ttInfoCalcuParam_input =
218   - new TTInfoCalcuParam_input(
219   - new DateTime(this.from),
220   - new DateTime(this.to),
221   - String.valueOf(line.getId())
222   - );
223   - // 规则输出数据
224   - TTInfoResults_output ttInfoResults_output = new TTInfoResults_output();
225   - LpInfoResults_output lpInfoResults_output = new LpInfoResults_output();
226   -
227   - // 1-2、构造drools session->载入数据->启动规则->计算->销毁session
228   - // 创建session,内部配置的是stateful
229   - KieSession session = coreKBase.newKieSession();
230   -
231   - // 设置gloable对象,在drl中通过别名使用
232   - session.setGlobal("results", ttInfoResults_output);
233   - session.setGlobal("lpInfoResults_output", lpInfoResults_output);
234   - session.setGlobal("log", logger); // 设置日志
235   - session.setGlobal("tTInfoDetailRepository", ttInfoDetailRepository);
236   -
237   - // 载入数据
238   - session.insert(ttInfoCalcuParam_input);
239   - for (TTInfo ttInfo : ttInfos) {
240   - TTInfo_input ttInfo_input = new TTInfo_input(ttInfo);
241   - session.insert(ttInfo_input);
242   - }
243   -
244   - // 载入数据2(计算规则最早启用时间)
245   - List<ScheduleRule1Flat> scheduleRule1Flats = scheduleRule1FlatRepository.findByXl(line);
246   -
247   - for (ScheduleRule1Flat scheduleRule1Flat: scheduleRule1Flats) {
248   - ScheduleRule_input scheduleRule_input = new ScheduleRule_input(scheduleRule1Flat);
249   - session.insert(scheduleRule_input);
250   - }
251   -
252   - // 执行rule
253   - session.fireAllRules();
254   -
255   - // 执行完毕销毁,有日志的也要关闭
256   - session.dispose();
257   -
258   - return new Object[] {ttInfoResults_output, lpInfoResults_output};
259   -
260   - }
261   -
262   - /**
263   - * 循环规则输出。
264   - * @param lpInfoResults_output 时刻表每日路牌的情况
265   - */
266   - private ScheduleResults_output loopRuleOutput(Line line, LpInfoResults_output lpInfoResults_output) {
267   - // 1-1、构造drools规则输入数据,输出数据
268   - // 全局计算参数
269   - SchedulePlan schedulePlan = new SchedulePlan();
270   - schedulePlan.setXl(line);
271   - schedulePlan.setScheduleFromTime(this.from);
272   - schedulePlan.setScheduleToTime(this.to);
273   - schedulePlan.setIsHistoryPlanFirst(this.schedulePlan.getIsHistoryPlanFirst());
274   - schedulePlan.setCreateBy(this.schedulePlan.getCreateBy());
275   - ScheduleCalcuParam_input scheduleCalcuParam_input = new ScheduleCalcuParam_input(schedulePlan);
276   - // 每个规则对应的输入参数
277   - List<ScheduleRule_input> scheduleRule_inputs = this.calcuSrfList(line);
278   -
279   - // 规则输出数据
280   - ScheduleResults_output scheduleResults_output = new ScheduleResults_output();
281   -
282   - // 1-2、构造drools session->载入数据->启动规则->计算->销毁session
283   - // 创建session,内部配置的是stateful
284   - KieSession session = coreKBase.newKieSession();
285   - // 设置gloable对象,在drl中通过别名使用
286   - session.setGlobal("scheduleResult", scheduleResults_output);
287   - session.setGlobal("log", logger); // 设置日志
288   - session.setGlobal("scheduleRuleService", scheduleRuleService);
289   -
290   - // 载入数据
291   - session.insert(scheduleCalcuParam_input);
292   - for (ScheduleRule_input scheduleRule_input : scheduleRule_inputs) {
293   - session.insert(scheduleRule_input);
294   - }
295   - // 每日时刻表路牌数据
296   - for (LpInfoResult_output lpInfoResult_output: lpInfoResults_output.getLpInfoResult_outputs()) {
297   - session.insert(lpInfoResult_output);
298   - }
299   - // 执行rule
300   - session.fireAllRules();
301   -
302   - // 执行完毕销毁,有日志的也要关闭
303   - session.dispose();
304   -
305   - // 保存循环规则结果数据
306   - scheduleRuleService.generateRuleResult(scheduleResults_output.getSchedulePlanRuleResults());
307   -
308   -// logger.info("循环规则输出={}", scheduleResults_output.showGuideboardDesc1());
309   -
310   - return scheduleResults_output;
311   - }
312   -
313   - /**
314   - * 排班生成。
315   - * @param scheduleResults_output loopRuleOutput方法规则输出
316   - * @param ttInfoResults_output ttInfoOutput方法规则输出
317   - * @return PlanResult
318   - */
319   - private PlanResult planResultOutput(
320   - Line line,
321   - ScheduleResults_output scheduleResults_output,
322   - TTInfoResults_output ttInfoResults_output) {
323   -
324   - SchedulePlan schedulePlan = new SchedulePlan();
325   - schedulePlan.setXl(line);
326   - schedulePlan.setScheduleFromTime(this.from);
327   - schedulePlan.setScheduleToTime(this.to);
328   - schedulePlan.setCreateBy(this.schedulePlan.getCreateBy());
329   - schedulePlan.setUpdateBy(this.schedulePlan.getUpdateBy());
330   -
331   - // 1-1、构造drools规则输入数据,输出数据
332   - PlanCalcuParam_input planCalcuParam_input = new PlanCalcuParam_input(
333   - schedulePlan,
334   - scheduleResults_output,
335   - ttInfoResults_output
336   - );
337   - // 规则输出数据
338   - PlanResult planResult = new PlanResult();
339   - planResult.setXlId(schedulePlan.getXl().getId().toString());
340   -
341   - // 1-2、构造drools session->载入数据->启动规则->计算->销毁session
342   - // 创建session,内部配置的是stateful
343   - KieSession session = this.coreKBase.newKieSession();
344   -
345   - // 设置gloable对象,在drl中通过别名使用
346   - session.setGlobal("planResult", planResult);
347   - session.setGlobal("log", this.logger); // 设置日志
348   -
349   - session.setGlobal("tTInfoDetailRepository", this.ttInfoDetailRepository);
350   - session.setGlobal("carConfigInfoRepository", this.carConfigInfoRepository);
351   - session.setGlobal("employeeConfigInfoRepository", this.employeeConfigInfoRepository);
352   - session.setGlobal("lineRepository", this.lineRepository);
353   - session.setGlobal("businessRepository", this.businessRepository);
354   -
355   - // 载入数据
356   - session.insert(planCalcuParam_input);
357   -
358   - // 执行rule
359   - session.fireAllRules();
360   -
361   - // 执行完毕销毁,有日志的也要关闭
362   - session.dispose();
363   -
364   - return planResult;
365   -
366   - }
367   -
368   - /**
369   - * 生成线路排班(不含套跑规则)。
370   - * @param schedulePlan
371   - * @return
372   - */
373   - private PlanResult schedulePlanWithOutRerun() {
374   - // 1、时刻表数据及每日路牌数据计算
375   - Date start1 = new Date();
376   - Object[] ttInfoRets = this.ttInfoOutput(this.mainLine);
377   - TTInfoResults_output ttInfoResults_output = (TTInfoResults_output) ttInfoRets[0];
378   - LpInfoResults_output lpInfoResults_output = (LpInfoResults_output) ttInfoRets[1];
379   - Date end1 = new Date();
380   - // 2、循环规则计算输出
381   - Date start2 = new Date();
382   - ScheduleResults_output scheduleResults_output = this.loopRuleOutput(
383   - this.mainLine, lpInfoResults_output);
384   - Date end2 = new Date();
385   -
386   - logger.info("规则计算结果={}", scheduleResults_output.showGuideboardDesc1());
387   -
388   - // 3、计划输出
389   - Date start3 = new Date();
390   - PlanResult planResult = planResultOutput(
391   - this.mainLine, scheduleResults_output, ttInfoResults_output);
392   - Date end3 = new Date();
393   -
394   - logger.info("drool时刻表每日路牌计算 {} ms,drool循环规则计算 {} ms,drool计划数据 {} ms",
395   - end1.getTime() - start1.getTime(),
396   - end2.getTime() - start2.getTime(),
397   - end3.getTime() - start3.getTime());
398   -
399   - // TODO:将lpInfoResults_output 也要返回
400   -
401   - return planResult;
402   - }
403   -
404   - /**
405   - * 套跑计划排班数据。
406   - * @param planResult
407   - */
408   - private void rerunPlanResult(PlanResult planResult) {
409   - logger.info("套跑数量 {} 组", this.rerunRule_inputs.size());
410   -
411   - if (this.rerunRule_inputs.size() > 0) {
412   - // 找出是对应路牌类型的线路,计算循环规则输出
413   - Set<String> dylpxlids = new HashSet<>();
414   - for (RerunRule_input rerunRule_input: rerunRule_inputs) {
415   - if ("dylp".equals(rerunRule_input.getType())) {
416   - dylpxlids.add(rerunRule_input.getS_xl()); // 参与套跑的线路
417   - }
418   - }
419   -
420   - List<ScheduleResults_output> scheduleResults_outputs = new ArrayList<>();
421   - Date start1 = new Date();
422   - for (String xlid: dylpxlids) {
423   - Line dylpline = new Line(); // 套跑的线路默认跟着主线路设定走
424   - dylpline.setId(Integer.parseInt(xlid));
425   - // 获取套跑线路的循环规则计算输出
426   - Object[] ttInfoRets = this.ttInfoOutput(dylpline);
427   - LpInfoResults_output lpInfoResults_output = (LpInfoResults_output) ttInfoRets[1];
428   - ScheduleResults_output scheduleResults_output = this.loopRuleOutput(
429   - dylpline, lpInfoResults_output);
430   - scheduleResults_outputs.add(scheduleResults_output);
431   - }
432   -
433   - // 1-2、构造drools session->载入数据->启动规则->计算->销毁session
434   - // 创建session,内部配置的是stateful
435   - KieSession session = this.coreKBase.newKieSession();
436   -
437   - // 设置gloable对象,在drl中通过别名使用
438   - session.setGlobal("planResult", planResult);
439   - session.setGlobal("log", this.logger); // 设置日志
440   -
441   - session.setGlobal("carConfigInfoRepository", this.carConfigInfoRepository);
442   - session.setGlobal("employeeConfigInfoRepository", this.employeeConfigInfoRepository);
443   -
444   - // 载入数据
445   - RerunRule_param rerunRule_param = new RerunRule_param();
446   - rerunRule_param.setMxlid(planResult.getXlId());
447   - rerunRule_param.setXlIds_dylp(dylpxlids);
448   - session.insert(rerunRule_param);
449   - for (RerunRule_input rri: this.rerunRule_inputs) {
450   - session.insert(rri);
451   - }
452   - for (SchedulePlanInfo spi: planResult.getSchedulePlanInfos()) {
453   - session.insert(spi);
454   - }
455   - for (ScheduleResults_output sro: scheduleResults_outputs) {
456   - session.insert(sro);
457   - }
458   -
459   - // 执行rule
460   - session.fireAllRules();
461   -
462   - // 执行完毕销毁,有日志的也要关闭
463   - session.dispose();
464   -
465   - Date end1 = new Date();
466   - logger.info("套跑规则计算,耗时 {} ms", end1.getTime() - start1.getTime());
467   -
468   - }
469   -
470   - }
471   -
472   - /**
473   - * 验证排班结果。
474   - * @param planResult
475   - * @param schedulePlan
476   - */
477   - public void validPlanResult(PlanResult planResult) {
478   - // 1-1、构造drools规则输入数据,输出数据
479   - ValidateParam validateParam = new ValidateParam(
480   - new DateTime(this.from), new DateTime(this.to));
481   - // 规则输出数据
482   - ValidateResults_output result = new ValidateResults_output();
483   -
484   - // 1-2、构造drools session->载入数据->启动规则->计算->销毁session
485   - // 创建session,内部配置的是stateful
486   - KieSession session = this.coreKBase.newKieSession();
487   -
488   - // 设置gloable对象,在drl中通过别名使用
489   - session.setGlobal("validResult", result);
490   - session.setGlobal("log", this.logger); // 设置日志
491   -
492   - // 载入数据
493   - session.insert(validateParam);
494   - for (SchedulePlanInfo schedulePlanInfo: planResult.getSchedulePlanInfos()) {
495   - session.insert(schedulePlanInfo);
496   - }
497   -
498   - // 执行rule
499   - session.fireAllRules();
500   -
501   - // 执行完毕销毁,有日志的也要关闭
502   - session.dispose();
503   -
504   -// logger.info("错误总数={}", result.getInfos().size());
505   -// for (ValidateResults_output.ValidInfo validInfo: result.getInfos()) {
506   -// logger.info(validInfo.getDesc());
507   -// }
508   -
509   - // 取10条错误
510   - int size = result.getInfos().size() > 10 ? 10: result.getInfos().size();
511   - List<String> desclist = new ArrayList<>();
512   - for (int i = 0; i < size; i++) {
513   - desclist.add(result.getInfos().get(i).getDesc());
514   - }
515   - if (desclist.size() > 0) {
516   - this.schedulePlan.setPlanResult(StringUtils.join(desclist, "</br>"));
517   - } else {
518   - this.schedulePlan.setPlanResult("ok");
519   - }
520   -
521   - // TODO:设定错误信息
522   - }
523   -
524   -}
  1 +package com.bsth.service.schedule.plan;
  2 +
  3 +import com.bsth.entity.Line;
  4 +import com.bsth.entity.schedule.SchedulePlan;
  5 +import com.bsth.entity.schedule.SchedulePlanInfo;
  6 +import com.bsth.entity.schedule.TTInfo;
  7 +import com.bsth.entity.schedule.rule.ScheduleRule1Flat;
  8 +import com.bsth.repository.BusinessRepository;
  9 +import com.bsth.repository.LineRepository;
  10 +import com.bsth.repository.schedule.*;
  11 +import com.bsth.service.schedule.rules.ScheduleRuleService;
  12 +import com.bsth.service.schedule.rules.plan.PlanCalcuParam_input;
  13 +import com.bsth.service.schedule.rules.plan.PlanResult;
  14 +import com.bsth.service.schedule.rules.rerun.RerunRule_input;
  15 +import com.bsth.service.schedule.rules.rerun.RerunRule_param;
  16 +import com.bsth.service.schedule.rules.shiftloop.ScheduleCalcuParam_input;
  17 +import com.bsth.service.schedule.rules.shiftloop.ScheduleResults_output;
  18 +import com.bsth.service.schedule.rules.shiftloop.ScheduleRule_input;
  19 +import com.bsth.service.schedule.rules.ttinfo.*;
  20 +import com.bsth.service.schedule.rules.validate.ValidateParam;
  21 +import com.bsth.service.schedule.rules.validate.ValidateResults_output;
  22 +import org.apache.commons.lang3.StringUtils;
  23 +import org.joda.time.DateTime;
  24 +import org.kie.api.KieBase;
  25 +import org.kie.api.runtime.KieSession;
  26 +import org.slf4j.Logger;
  27 +
  28 +import java.util.*;
  29 +
  30 +/**
  31 + * 排班计划(使用Drools)。
  32 + */
  33 +public class DroolsSchedulePlan {
  34 + /** 主线路 */
  35 + private Line mainLine;
  36 + /** 套跑辅线路规则 */
  37 + private List<RerunRule_input> rerunRule_inputs;
  38 +
  39 + /** 开始排班时间 */
  40 + private Date from;
  41 + /** 结束排班时间 */
  42 + private Date to;
  43 + /** 排班计划entity */
  44 + private SchedulePlan schedulePlan;
  45 +
  46 + //-------------------- 相关的Repo,service服务 --------------------//
  47 + /** 线路Repo */
  48 + private LineRepository lineRepository;
  49 + /** 排班规则Repo */
  50 + private ScheduleRule1FlatRepository scheduleRule1FlatRepository;
  51 + /** 时刻表Repo */
  52 + private TTInfoRepository ttInfoRepository;
  53 + /** 时刻表明细Repo */
  54 + private TTInfoDetailRepository ttInfoDetailRepository;
  55 + /** 车辆配置Repo */
  56 + private CarConfigInfoRepository carConfigInfoRepository;
  57 + /** 人员配置Repo */
  58 + private EmployeeConfigInfoRepository employeeConfigInfoRepository;
  59 + /** 套跑规则Repo */
  60 + private RerunRuleRepository rerunRuleRepository;
  61 + /** 营运状态Repo */
  62 + private BusinessRepository businessRepository;
  63 +
  64 + /** 排班规则service */
  65 + private ScheduleRuleService scheduleRuleService;
  66 +
  67 + //-------------------- Drools KBase实例 ------------------//
  68 + /** 排班预处理KBase */
  69 + private KieBase preKBase;
  70 + /** 排班核心KBase */
  71 + private KieBase coreKBase;
  72 +
  73 + //-------------------- 日志记录器 ---------------------//
  74 + private Logger logger;
  75 +
  76 + public DroolsSchedulePlan(
  77 + SchedulePlan schedulePlan,
  78 + LineRepository lineRepository, ScheduleRule1FlatRepository scheduleRule1FlatRepository,
  79 + TTInfoRepository ttInfoRepository, TTInfoDetailRepository ttInfoDetailRepository,
  80 + CarConfigInfoRepository carConfigInfoRepository,
  81 + EmployeeConfigInfoRepository employeeConfigInfoRepository,
  82 + RerunRuleRepository rerunRuleRepository,
  83 + BusinessRepository businessRepository,
  84 + ScheduleRuleService scheduleRuleService,
  85 + KieBase preKBase, KieBase coreKBase,
  86 + Logger logger) {
  87 +
  88 + // 验证SchedulePlan实体
  89 + if (schedulePlan == null) {
  90 + throw new RuntimeException("排班用SchedulePlan为空!");
  91 + }
  92 + if (schedulePlan.getXl() == null) {
  93 + throw new RuntimeException("排班线路为空!");
  94 + } else {
  95 + // 获取主线路
  96 + this.mainLine = lineRepository.findOne(schedulePlan.getXl().getId());
  97 + if (this.mainLine == null) {
  98 + throw new RuntimeException("线路id=" + schedulePlan.getXl().getId() + "不存在!");
  99 + }
  100 + // 获取主线路套跑信息
  101 + this.rerunRule_inputs = scheduleRuleService.findRerunrule(this.mainLine.getId());
  102 + }
  103 + if (schedulePlan.getScheduleFromTime() == null) {
  104 + throw new RuntimeException("排班开始时间为空!");
  105 + }
  106 + if (schedulePlan.getScheduleToTime() == null) {
  107 + throw new RuntimeException("排班结束时间为空!");
  108 + }
  109 + this.from = schedulePlan.getScheduleFromTime();
  110 + this.to = schedulePlan.getScheduleToTime();
  111 + if (schedulePlan.getTtInfoIds() == null) {
  112 + throw new RuntimeException("排班关联的时刻表ids为空!");
  113 + }
  114 + if (schedulePlan.getTtInfoNames() == null) {
  115 + throw new RuntimeException("排班关联的时刻表名字s为空!");
  116 + }
  117 + this.schedulePlan = schedulePlan;
  118 +
  119 + this.lineRepository = lineRepository;
  120 + this.scheduleRule1FlatRepository = scheduleRule1FlatRepository;
  121 + this.ttInfoRepository = ttInfoRepository;
  122 + this.ttInfoDetailRepository = ttInfoDetailRepository;
  123 + this.carConfigInfoRepository = carConfigInfoRepository;
  124 + this.employeeConfigInfoRepository = employeeConfigInfoRepository;
  125 + this.rerunRuleRepository = rerunRuleRepository;
  126 + this.businessRepository = businessRepository;
  127 + this.scheduleRuleService = scheduleRuleService;
  128 + this.preKBase = preKBase;
  129 + this.coreKBase = coreKBase;
  130 +
  131 + this.logger = logger;
  132 +
  133 + }
  134 +
  135 + public void generatePlan() {
  136 + logger.info("<--- 排班master线路 id={}, name={}, 开始排班",
  137 + this.mainLine.getId(), this.mainLine.getName());
  138 +
  139 + // 1、确定主线路排班(包含完全套跑路牌规则,所谓完全套跑路牌规则指整个路牌的班次都是套跑规则指定的)
  140 + PlanResult planResult = this.schedulePlanWithOutRerun();
  141 +
  142 + // 2、确定套跑规则
  143 + this.rerunPlanResult(planResult);
  144 +
  145 + // TODO:3-1、验证排班结果
  146 + this.validPlanResult(planResult);
  147 +
  148 + // TODO:3-2、去除完全套跑遗漏班次(以后放到规则中执行)
  149 + Iterator<SchedulePlanInfo> infoIterator = planResult.getSchedulePlanInfos().iterator();
  150 + while (infoIterator.hasNext()) {
  151 + SchedulePlanInfo schedulePlanInfo = infoIterator.next();
  152 + if (schedulePlanInfo.getCl() == null) {
  153 + infoIterator.remove();
  154 + }
  155 + }
  156 +
  157 + // 4、保存数据(jdbcTemplate 批量插入)
  158 + Date start4 = new Date();
  159 + this.scheduleRuleService.generateSchedulePlan(
  160 + this.schedulePlan, planResult.getSchedulePlanInfos());
  161 + Date end4 = new Date();
  162 +
  163 + this.logger.info("保存主线路数据 {} 条 耗时 {} ms --->",
  164 + planResult.getSchedulePlanInfos().size(),
  165 + end4.getTime() - start4.getTime());
  166 + }
  167 +
  168 + /**
  169 + * 计算规则输入。
  170 + * @return
  171 + */
  172 + private List<ScheduleRule_input> calcuSrfList(Line line) {
  173 + // 1-1、构造drools规则输入数据,输出数据
  174 + // 全局计算参数
  175 + SchedulePlan schedulePlan = new SchedulePlan();
  176 + schedulePlan.setXl(line);
  177 + schedulePlan.setScheduleFromTime(this.from);
  178 + schedulePlan.setScheduleToTime(this.to);
  179 + ScheduleCalcuParam_input scheduleCalcuParam_input = new ScheduleCalcuParam_input(schedulePlan);
  180 +
  181 + // 规则输出数据
  182 + List<ScheduleRule_input> scheduleRule_inputs = new ArrayList<>();
  183 +
  184 + // 1-2、构造drools session->载入数据->启动规则->计算->销毁session
  185 + // 创建session,内部配置的是stateful
  186 + KieSession session = preKBase.newKieSession();
  187 + // 设置gloable对象,在drl中通过别名使用
  188 + session.setGlobal("sriList", scheduleRule_inputs);
  189 + session.setGlobal("log", logger); // 设置日志
  190 +
  191 + session.setGlobal("srf", scheduleRule1FlatRepository);
  192 + session.setGlobal("rrr", rerunRuleRepository);
  193 + session.setGlobal("srservice", scheduleRuleService);
  194 +
  195 + // 载入数据
  196 + session.insert(scheduleCalcuParam_input);
  197 +
  198 + // 执行rule
  199 + session.fireAllRules();
  200 +
  201 + // 执行完毕销毁,有日志的也要关闭
  202 + session.dispose();
  203 +
  204 + return scheduleRule_inputs;
  205 + }
  206 +
  207 + /**
  208 + * 时刻表选择(判定每天使用的时刻表,以及路牌数据输出)。
  209 + * @return [TTInfoResults_output, LpInfoResults_output]
  210 + */
  211 + private Object[] ttInfoOutput(Line line) {
  212 + // 获取线路的所有未作废的时刻表
  213 + List<TTInfo> ttInfos = ttInfoRepository.findInCanceledByXl(line);
  214 +
  215 + // 1-1、构造drools规则输入数据,输出数据
  216 + // 全局计算参数
  217 + TTInfoCalcuParam_input ttInfoCalcuParam_input =
  218 + new TTInfoCalcuParam_input(
  219 + new DateTime(this.from),
  220 + new DateTime(this.to),
  221 + String.valueOf(line.getId())
  222 + );
  223 + // 规则输出数据
  224 + TTInfoResults_output ttInfoResults_output = new TTInfoResults_output();
  225 + LpInfoResults_output lpInfoResults_output = new LpInfoResults_output();
  226 +
  227 + // 1-2、构造drools session->载入数据->启动规则->计算->销毁session
  228 + // 创建session,内部配置的是stateful
  229 + KieSession session = coreKBase.newKieSession();
  230 +
  231 + // 设置gloable对象,在drl中通过别名使用
  232 + session.setGlobal("results", ttInfoResults_output);
  233 + session.setGlobal("lpInfoResults_output", lpInfoResults_output);
  234 + session.setGlobal("log", logger); // 设置日志
  235 + session.setGlobal("tTInfoDetailRepository", ttInfoDetailRepository);
  236 +
  237 + // 载入数据
  238 + session.insert(ttInfoCalcuParam_input);
  239 + for (TTInfo ttInfo : ttInfos) {
  240 + TTInfo_input ttInfo_input = new TTInfo_input(ttInfo);
  241 + session.insert(ttInfo_input);
  242 + }
  243 +
  244 + // 载入数据2(计算规则最早启用时间)
  245 + List<ScheduleRule1Flat> scheduleRule1Flats = scheduleRule1FlatRepository.findByXl(line);
  246 +
  247 + for (ScheduleRule1Flat scheduleRule1Flat: scheduleRule1Flats) {
  248 + ScheduleRule_input scheduleRule_input = new ScheduleRule_input(scheduleRule1Flat);
  249 + session.insert(scheduleRule_input);
  250 + }
  251 +
  252 + // 执行rule
  253 + session.fireAllRules();
  254 +
  255 + // 执行完毕销毁,有日志的也要关闭
  256 + session.dispose();
  257 +
  258 + return new Object[] {ttInfoResults_output, lpInfoResults_output};
  259 +
  260 + }
  261 +
  262 + /**
  263 + * 循环规则输出。
  264 + * @param lpInfoResults_output 时刻表每日路牌的情况
  265 + */
  266 + private ScheduleResults_output loopRuleOutput(Line line, LpInfoResults_output lpInfoResults_output) {
  267 + // 1-1、构造drools规则输入数据,输出数据
  268 + // 全局计算参数
  269 + SchedulePlan schedulePlan = new SchedulePlan();
  270 + schedulePlan.setXl(line);
  271 + schedulePlan.setScheduleFromTime(this.from);
  272 + schedulePlan.setScheduleToTime(this.to);
  273 + schedulePlan.setIsHistoryPlanFirst(this.schedulePlan.getIsHistoryPlanFirst());
  274 + schedulePlan.setCreateBy(this.schedulePlan.getCreateBy());
  275 + ScheduleCalcuParam_input scheduleCalcuParam_input = new ScheduleCalcuParam_input(schedulePlan);
  276 + // 每个规则对应的输入参数
  277 + List<ScheduleRule_input> scheduleRule_inputs = this.calcuSrfList(line);
  278 +
  279 + // 规则输出数据
  280 + ScheduleResults_output scheduleResults_output = new ScheduleResults_output();
  281 +
  282 + // 1-2、构造drools session->载入数据->启动规则->计算->销毁session
  283 + // 创建session,内部配置的是stateful
  284 + KieSession session = coreKBase.newKieSession();
  285 + // 设置gloable对象,在drl中通过别名使用
  286 + session.setGlobal("scheduleResult", scheduleResults_output);
  287 + session.setGlobal("log", logger); // 设置日志
  288 + session.setGlobal("scheduleRuleService", scheduleRuleService);
  289 +
  290 + // 载入数据
  291 + session.insert(scheduleCalcuParam_input);
  292 + for (ScheduleRule_input scheduleRule_input : scheduleRule_inputs) {
  293 + session.insert(scheduleRule_input);
  294 + }
  295 + // 每日时刻表路牌数据
  296 + for (LpInfoResult_output lpInfoResult_output: lpInfoResults_output.getLpInfoResult_outputs()) {
  297 + session.insert(lpInfoResult_output);
  298 + }
  299 + // 执行rule
  300 + session.fireAllRules();
  301 +
  302 + // 执行完毕销毁,有日志的也要关闭
  303 + session.dispose();
  304 +
  305 + // 保存循环规则结果数据
  306 + scheduleRuleService.generateRuleResult(scheduleResults_output.getSchedulePlanRuleResults());
  307 +
  308 +// logger.info("循环规则输出={}", scheduleResults_output.showGuideboardDesc1());
  309 +
  310 + return scheduleResults_output;
  311 + }
  312 +
  313 + /**
  314 + * 排班生成。
  315 + * @param scheduleResults_output loopRuleOutput方法规则输出
  316 + * @param ttInfoResults_output ttInfoOutput方法规则输出
  317 + * @return PlanResult
  318 + */
  319 + private PlanResult planResultOutput(
  320 + Line line,
  321 + ScheduleResults_output scheduleResults_output,
  322 + TTInfoResults_output ttInfoResults_output) {
  323 +
  324 + SchedulePlan schedulePlan = new SchedulePlan();
  325 + schedulePlan.setXl(line);
  326 + schedulePlan.setScheduleFromTime(this.from);
  327 + schedulePlan.setScheduleToTime(this.to);
  328 + schedulePlan.setCreateBy(this.schedulePlan.getCreateBy());
  329 + schedulePlan.setUpdateBy(this.schedulePlan.getUpdateBy());
  330 +
  331 + // 1-1、构造drools规则输入数据,输出数据
  332 + PlanCalcuParam_input planCalcuParam_input = new PlanCalcuParam_input(
  333 + schedulePlan,
  334 + scheduleResults_output,
  335 + ttInfoResults_output
  336 + );
  337 + // 规则输出数据
  338 + PlanResult planResult = new PlanResult();
  339 + planResult.setXlId(schedulePlan.getXl().getId().toString());
  340 +
  341 + // 1-2、构造drools session->载入数据->启动规则->计算->销毁session
  342 + // 创建session,内部配置的是stateful
  343 + KieSession session = this.coreKBase.newKieSession();
  344 +
  345 + // 设置gloable对象,在drl中通过别名使用
  346 + session.setGlobal("planResult", planResult);
  347 + session.setGlobal("log", this.logger); // 设置日志
  348 +
  349 + session.setGlobal("tTInfoDetailRepository", this.ttInfoDetailRepository);
  350 + session.setGlobal("carConfigInfoRepository", this.carConfigInfoRepository);
  351 + session.setGlobal("employeeConfigInfoRepository", this.employeeConfigInfoRepository);
  352 + session.setGlobal("lineRepository", this.lineRepository);
  353 + session.setGlobal("businessRepository", this.businessRepository);
  354 +
  355 + // 载入数据
  356 + session.insert(planCalcuParam_input);
  357 +
  358 + // 执行rule
  359 + session.fireAllRules();
  360 +
  361 + // 执行完毕销毁,有日志的也要关闭
  362 + session.dispose();
  363 +
  364 + return planResult;
  365 +
  366 + }
  367 +
  368 + /**
  369 + * 生成线路排班(不含套跑规则)。
  370 + * @param schedulePlan
  371 + * @return
  372 + */
  373 + private PlanResult schedulePlanWithOutRerun() {
  374 + // 1、时刻表数据及每日路牌数据计算
  375 + Date start1 = new Date();
  376 + Object[] ttInfoRets = this.ttInfoOutput(this.mainLine);
  377 + TTInfoResults_output ttInfoResults_output = (TTInfoResults_output) ttInfoRets[0];
  378 + LpInfoResults_output lpInfoResults_output = (LpInfoResults_output) ttInfoRets[1];
  379 + Date end1 = new Date();
  380 + // 2、循环规则计算输出
  381 + Date start2 = new Date();
  382 + ScheduleResults_output scheduleResults_output = this.loopRuleOutput(
  383 + this.mainLine, lpInfoResults_output);
  384 + Date end2 = new Date();
  385 +
  386 + logger.info("规则计算结果={}", scheduleResults_output.showGuideboardDesc1());
  387 +
  388 + // 3、计划输出
  389 + Date start3 = new Date();
  390 + PlanResult planResult = planResultOutput(
  391 + this.mainLine, scheduleResults_output, ttInfoResults_output);
  392 + Date end3 = new Date();
  393 +
  394 + logger.info("drool时刻表每日路牌计算 {} ms,drool循环规则计算 {} ms,drool计划数据 {} ms",
  395 + end1.getTime() - start1.getTime(),
  396 + end2.getTime() - start2.getTime(),
  397 + end3.getTime() - start3.getTime());
  398 +
  399 + // TODO:将lpInfoResults_output 也要返回
  400 +
  401 + return planResult;
  402 + }
  403 +
  404 + /**
  405 + * 套跑计划排班数据。
  406 + * @param planResult
  407 + */
  408 + private void rerunPlanResult(PlanResult planResult) {
  409 + logger.info("套跑数量 {} 组", this.rerunRule_inputs.size());
  410 +
  411 + if (this.rerunRule_inputs.size() > 0) {
  412 + // 找出是对应路牌类型的线路,计算循环规则输出
  413 + Set<String> dylpxlids = new HashSet<>();
  414 + for (RerunRule_input rerunRule_input: rerunRule_inputs) {
  415 + if ("dylp".equals(rerunRule_input.getType())) {
  416 + dylpxlids.add(rerunRule_input.getS_xl()); // 参与套跑的线路
  417 + }
  418 + }
  419 +
  420 + List<ScheduleResults_output> scheduleResults_outputs = new ArrayList<>();
  421 + Date start1 = new Date();
  422 + for (String xlid: dylpxlids) {
  423 + Line dylpline = new Line(); // 套跑的线路默认跟着主线路设定走
  424 + dylpline.setId(Integer.parseInt(xlid));
  425 + // 获取套跑线路的循环规则计算输出
  426 + Object[] ttInfoRets = this.ttInfoOutput(dylpline);
  427 + LpInfoResults_output lpInfoResults_output = (LpInfoResults_output) ttInfoRets[1];
  428 + ScheduleResults_output scheduleResults_output = this.loopRuleOutput(
  429 + dylpline, lpInfoResults_output);
  430 + scheduleResults_outputs.add(scheduleResults_output);
  431 + }
  432 +
  433 + // 1-2、构造drools session->载入数据->启动规则->计算->销毁session
  434 + // 创建session,内部配置的是stateful
  435 + KieSession session = this.coreKBase.newKieSession();
  436 +
  437 + // 设置gloable对象,在drl中通过别名使用
  438 + session.setGlobal("planResult", planResult);
  439 + session.setGlobal("log", this.logger); // 设置日志
  440 +
  441 + session.setGlobal("carConfigInfoRepository", this.carConfigInfoRepository);
  442 + session.setGlobal("employeeConfigInfoRepository", this.employeeConfigInfoRepository);
  443 +
  444 + // 载入数据
  445 + RerunRule_param rerunRule_param = new RerunRule_param();
  446 + rerunRule_param.setMxlid(planResult.getXlId());
  447 + rerunRule_param.setXlIds_dylp(dylpxlids);
  448 + session.insert(rerunRule_param);
  449 + for (RerunRule_input rri: this.rerunRule_inputs) {
  450 + session.insert(rri);
  451 + }
  452 + for (SchedulePlanInfo spi: planResult.getSchedulePlanInfos()) {
  453 + session.insert(spi);
  454 + }
  455 + for (ScheduleResults_output sro: scheduleResults_outputs) {
  456 + session.insert(sro);
  457 + }
  458 +
  459 + // 执行rule
  460 + session.fireAllRules();
  461 +
  462 + // 执行完毕销毁,有日志的也要关闭
  463 + session.dispose();
  464 +
  465 + Date end1 = new Date();
  466 + logger.info("套跑规则计算,耗时 {} ms", end1.getTime() - start1.getTime());
  467 +
  468 + }
  469 +
  470 + }
  471 +
  472 + /**
  473 + * 验证排班结果。
  474 + * @param planResult
  475 + * @param schedulePlan
  476 + */
  477 + public void validPlanResult(PlanResult planResult) {
  478 + // 1-1、构造drools规则输入数据,输出数据
  479 + ValidateParam validateParam = new ValidateParam(
  480 + new DateTime(this.from), new DateTime(this.to));
  481 + // 规则输出数据
  482 + ValidateResults_output result = new ValidateResults_output();
  483 +
  484 + // 1-2、构造drools session->载入数据->启动规则->计算->销毁session
  485 + // 创建session,内部配置的是stateful
  486 + KieSession session = this.coreKBase.newKieSession();
  487 +
  488 + // 设置gloable对象,在drl中通过别名使用
  489 + session.setGlobal("validResult", result);
  490 + session.setGlobal("log", this.logger); // 设置日志
  491 +
  492 + // 载入数据
  493 + session.insert(validateParam);
  494 + for (SchedulePlanInfo schedulePlanInfo: planResult.getSchedulePlanInfos()) {
  495 + session.insert(schedulePlanInfo);
  496 + }
  497 +
  498 + // 执行rule
  499 + session.fireAllRules();
  500 +
  501 + // 执行完毕销毁,有日志的也要关闭
  502 + session.dispose();
  503 +
  504 +// logger.info("错误总数={}", result.getInfos().size());
  505 +// for (ValidateResults_output.ValidInfo validInfo: result.getInfos()) {
  506 +// logger.info(validInfo.getDesc());
  507 +// }
  508 +
  509 + // 取10条错误
  510 + int size = result.getInfos().size() > 10 ? 10: result.getInfos().size();
  511 + List<String> desclist = new ArrayList<>();
  512 + for (int i = 0; i < size; i++) {
  513 + desclist.add(result.getInfos().get(i).getDesc());
  514 + }
  515 + if (desclist.size() > 0) {
  516 + this.schedulePlan.setPlanResult(StringUtils.join(desclist, "</br>"));
  517 + } else {
  518 + this.schedulePlan.setPlanResult("ok");
  519 + }
  520 +
  521 + // TODO:设定错误信息
  522 + }
  523 +
  524 +}
... ...