Commit 707496419c57f2293d2a91c27cd277503ebc3589

Authored by panzhaov5
2 parents 469daeb5 81ddfc23

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

# Conflicts:
#	src/main/java/com/bsth/data/schedule/e_state_check/ScheduleStationCodeChecker.java

Too many changes to show.

To preserve performance only 16 of 31 files are displayed.

src/main/java/com/bsth/controller/calc/CalcWaybillController.java
@@ -151,6 +151,39 @@ public class CalcWaybillController extends BaseController<CalcWaybill, Integer> @@ -151,6 +151,39 @@ public class CalcWaybillController extends BaseController<CalcWaybill, Integer>
151 return calcWaybillService.calcStatisticsDaily(gsdm,fgsdm,line,date,date2,xlName,type); 151 return calcWaybillService.calcStatisticsDaily(gsdm,fgsdm,line,date,date2,xlName,type);
152 } 152 }
153 153
  154 + @RequestMapping(value="/calcStatisticsDaily2")
  155 + public List<Map<String, Object>> calcStatisticsDaily2(@RequestParam Map<String, Object> map){
  156 + String gsdm="";
  157 + if(map.get("gsdm")!=null){
  158 + gsdm=map.get("gsdm").toString().trim();
  159 + }
  160 + String fgsdm="";
  161 + if(map.get("fgsdm")!=null){
  162 + fgsdm=map.get("fgsdm").toString().trim();
  163 + }
  164 + String line="";
  165 + if(map.get("line")!=null){
  166 + line=map.get("line").toString().trim();
  167 + }
  168 + String date="";
  169 + if(map.get("date")!=null){
  170 + date=map.get("date").toString().trim();
  171 + }
  172 + String date2="";
  173 + if(map.get("date2")!=null){
  174 + date2=map.get("date2").toString().trim();
  175 + }
  176 + String xlName="";
  177 + if(map.get("xlName")!=null){
  178 + xlName=map.get("xlName").toString().trim();
  179 + }
  180 + String type="";
  181 + if(map.get("type")!=null){
  182 + type=map.get("type").toString().trim();
  183 + }
  184 + return calcWaybillService.calcStatisticsDaily2(gsdm,fgsdm,line,date,date2,xlName,type);
  185 + }
  186 +
154 @RequestMapping(value="/generateLineMileage") 187 @RequestMapping(value="/generateLineMileage")
155 public Map<String, Object> generateLineMileage(@RequestParam Map<String, Object> map) throws Exception{ 188 public Map<String, Object> generateLineMileage(@RequestParam Map<String, Object> map) throws Exception{
156 Map<String, Object> m = new HashMap<String, Object>(); 189 Map<String, Object> m = new HashMap<String, Object>();
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 \ No newline at end of file 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
@@ -148,4 +148,4 @@ public class ScheduleStationCodeChecker { @@ -148,4 +148,4 @@ public class ScheduleStationCodeChecker {
148 148
149 return realMap; 149 return realMap;
150 } 150 }
151 -} 151 -}
  152 +}
152 \ No newline at end of file 153 \ No newline at end of file
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/service/calc/CalcWaybillService.java
@@ -32,6 +32,8 @@ public interface CalcWaybillService extends BaseService&lt;CalcWaybill, Integer&gt; { @@ -32,6 +32,8 @@ public interface CalcWaybillService extends BaseService&lt;CalcWaybill, Integer&gt; {
32 32
33 List<CalcStatistics> calcStatisticsDaily(String gsdm,String fgsdm, String line, String date, String date2, String xlName, String type); 33 List<CalcStatistics> calcStatisticsDaily(String gsdm,String fgsdm, String line, String date, String date2, String xlName, String type);
34 34
  35 + List<Map<String, Object>> calcStatisticsDaily2(String gsdm,String fgsdm, String line, String date, String date2, String xlName, String type);
  36 +
35 Map<String, Object> calcLineMileage(String date, String line); 37 Map<String, Object> calcLineMileage(String date, String line);
36 38
37 Map<String, Object> calcBusMileage(String date, String line); 39 Map<String, Object> calcBusMileage(String date, String line);
src/main/java/com/bsth/service/calc/impl/CalcWaybillServiceImpl.java
@@ -2,6 +2,7 @@ package com.bsth.service.calc.impl; @@ -2,6 +2,7 @@ package com.bsth.service.calc.impl;
2 2
3 import java.sql.ResultSet; 3 import java.sql.ResultSet;
4 import java.sql.SQLException; 4 import java.sql.SQLException;
  5 +import java.text.ParseException;
5 import java.text.SimpleDateFormat; 6 import java.text.SimpleDateFormat;
6 import java.util.ArrayList; 7 import java.util.ArrayList;
7 import java.util.Calendar; 8 import java.util.Calendar;
@@ -37,6 +38,7 @@ import com.bsth.repository.realcontrol.ScheduleRealInfoRepository; @@ -37,6 +38,7 @@ import com.bsth.repository.realcontrol.ScheduleRealInfoRepository;
37 import com.bsth.service.calc.CalcToolService; 38 import com.bsth.service.calc.CalcToolService;
38 import com.bsth.service.calc.CalcWaybillService; 39 import com.bsth.service.calc.CalcWaybillService;
39 import com.bsth.service.impl.BaseServiceImpl; 40 import com.bsth.service.impl.BaseServiceImpl;
  41 +import com.bsth.service.realcontrol.ScheduleRealInfoService;
40 import com.bsth.service.report.CulateMileageService; 42 import com.bsth.service.report.CulateMileageService;
41 import com.bsth.service.report.ReportService; 43 import com.bsth.service.report.ReportService;
42 import com.bsth.util.Arith; 44 import com.bsth.util.Arith;
@@ -81,6 +83,9 @@ public class CalcWaybillServiceImpl extends BaseServiceImpl&lt;CalcWaybill, Integer @@ -81,6 +83,9 @@ public class CalcWaybillServiceImpl extends BaseServiceImpl&lt;CalcWaybill, Integer
81 private CulateMileageService culateService; 83 private CulateMileageService culateService;
82 84
83 @Autowired 85 @Autowired
  86 + private ScheduleRealInfoService scheduleRealInfoService;
  87 +
  88 + @Autowired
84 private ScheduleRealInfoRepository scheduleRealInfoRepository; 89 private ScheduleRealInfoRepository scheduleRealInfoRepository;
85 90
86 @Autowired 91 @Autowired
@@ -850,6 +855,360 @@ public class CalcWaybillServiceImpl extends BaseServiceImpl&lt;CalcWaybill, Integer @@ -850,6 +855,360 @@ public class CalcWaybillServiceImpl extends BaseServiceImpl&lt;CalcWaybill, Integer
850 855
851 return resList; 856 return resList;
852 } 857 }
  858 +
  859 + @Override
  860 + public List<Map<String, Object>> calcStatisticsDaily2(String gsdm, String fgsdm,
  861 + String line, String date, String date2, String xlName, String type) {
  862 + // TODO Auto-generated method stub
  863 + SimpleDateFormat dft = new SimpleDateFormat("yyyy-MM-dd");
  864 + Date beginDate = new Date();
  865 + Calendar calendar = Calendar.getInstance();
  866 + calendar.setTime(beginDate);
  867 + calendar.set(Calendar.DATE, calendar.get(Calendar.DATE) - 4);
  868 + String d2 = dft.format(calendar.getTime()); //当前日期前4天
  869 + calendar.set(Calendar.DATE, calendar.get(Calendar.DATE) +1);
  870 + String d3= dft.format(calendar.getTime()); //当前日期前3天
  871 +
  872 + String d1="";
  873 + String d4="";
  874 + try {
  875 + long t3 = dft.parse(d2).getTime();
  876 + long t1=dft.parse(date).getTime();
  877 + long t2=dft.parse(date2).getTime();
  878 +
  879 + if(t1<=t3 && t2>t3){
  880 + //所选日期区间区间既有实时数据也有历史数据
  881 + d1=date;
  882 + d4=date2;
  883 + } else if (t1>t3&&t2>t3){
  884 + d1=date;
  885 + d2=date2;
  886 + d3=date;
  887 + d4=date2;
  888 + }else{
  889 + d1=date;
  890 + d2=date2;
  891 + //实时数据无需
  892 + d3="";
  893 + d4="";
  894 + }
  895 + } catch (ParseException e1) {
  896 + // TODO Auto-generated catch block
  897 + e1.printStackTrace();
  898 + }
  899 +
  900 +
  901 + List<CalcStatistics> list = new ArrayList<CalcStatistics>();
  902 + if(line.length() > 0){
  903 + list = calcStatisticsRepository.selectByDateAndLineTj2(line, d1, d2);
  904 + } else {
  905 + list = calcStatisticsRepository.selectByDateAndLineTj(line, d1, d2, gsdm, fgsdm);
  906 + }
  907 +
  908 + List<CalcStatistics> resList = new ArrayList<CalcStatistics>();
  909 + Map<String, List<CalcStatistics>> keyMap = new HashMap<String, List<CalcStatistics>>();
  910 + List<String> keyList = new ArrayList<String>();
  911 +
  912 + for(CalcStatistics s : list){
  913 + try {
  914 + String key = PinyinHelper.convertToPinyinString(s.getXlName(), "" , PinyinFormat.WITHOUT_TONE);
  915 + if(!keyMap.containsKey(key)){
  916 + keyMap.put(key, new ArrayList<CalcStatistics>());
  917 + keyList.add(key);
  918 + }
  919 + keyMap.get(key).add(s);
  920 + } catch (PinyinException e) {
  921 + // TODO Auto-generated catch block
  922 + e.printStackTrace();
  923 + }
  924 + }
  925 + Collections.sort(keyList, new AccountXlbmStr());
  926 +
  927 + for(String key : keyList){
  928 + if(keyMap.get(key).size() > 0){
  929 + CalcStatistics s = keyMap.get(key).get(0);
  930 + if(keyMap.get(key).size() > 1)
  931 + for(int i = 1; i < keyMap.get(key).size(); i++){
  932 + CalcStatistics s_ = keyMap.get(key).get(i);
  933 + s = addStatistics(s, s_);
  934 + }
  935 + resList.add(s);
  936 + }
  937 + }
  938 +
  939 + if(resList.size() > 0){
  940 + CalcStatistics temp = new CalcStatistics();
  941 + temp.setXlName("合计");
  942 + temp.setXl("hj");
  943 + for(CalcStatistics s : resList){
  944 + temp = addStatistics(temp, s);
  945 + }
  946 + resList.add(temp);
  947 + }
  948 + List<Map<String, Object>> mapList = new ArrayList<Map<String, Object>>();
  949 + for(CalcStatistics c : resList){
  950 + Map<String, Object> m = new HashMap<String, Object>();
  951 + m.put("xlBm", c.getXl());
  952 + m.put("xlName", c.getXlName());
  953 + m.put("jhzlc", c.getJhzlc());
  954 + m.put("jhlc", c.getJhyylc());
  955 + m.put("jcclc", c.getJhkslc());
  956 + m.put("sjzgl", c.getSjzlc());
  957 + m.put("sjgl", c.getSjyylc());
  958 + m.put("sjksgl", c.getSjkslc());
  959 + m.put("ssgl", c.getSslc());
  960 + m.put("ssbc", c.getSsbc());
  961 + m.put("ssgl_lz", c.getLzlc());
  962 + m.put("ssgl_dm", c.getDmlc());
  963 + m.put("ssgl_gz", c.getGzlc());
  964 + m.put("ssgl_jf", c.getJflc());
  965 + m.put("ssgl_zs", c.getZslc());
  966 + m.put("ssgl_qr", c.getQrlc());
  967 + m.put("ssgl_qc", c.getQclc());
  968 + m.put("ssgl_kx", c.getKxlc());
  969 + m.put("ssgl_qh", c.getQhlc());
  970 + m.put("ssgl_yw", c.getYwlc());
  971 + m.put("ssgl_other", c.getQtlc());
  972 + m.put("ljgl", c.getLjlc());
  973 + m.put("jhbc", c.getJhbcq());
  974 + m.put("jhbc_m", c.getJhbcz());
  975 + m.put("jhbc_a", c.getJhbcw());
  976 + m.put("sjbc", c.getSjbcq());
  977 + m.put("sjbc_m", c.getSjbcz());
  978 + m.put("sjbc_a", c.getSjbcw());
  979 + m.put("ljbc", c.getLjbcq());
  980 + m.put("ljbc_m", c.getLjbcz());
  981 + m.put("ljbc_a", c.getLjbcw());
  982 + m.put("fzbc", c.getFzbcq());
  983 + m.put("fzbc_m", c.getFzbcz());
  984 + m.put("fzbc_a", c.getFzbcw());
  985 + m.put("dtbc", c.getDtbcq());
  986 + m.put("dtbc_m", c.getDtbcz());
  987 + m.put("dtbc_a", c.getDtbcw());
  988 + m.put("djg", c.getDjgq());
  989 + m.put("djg_m", c.getDjgz());
  990 + m.put("djg_a", c.getDjgw());
  991 + m.put("djg_time", c.getDjgsj());
  992 + double jl = Arith.sub(Arith.add(m.get("jhlc"), m.get("ljgl")), m.get("ssgl"));
  993 + if (jl == Double.parseDouble(m.get("sjgl").toString())) {
  994 + m.put("zt", 0);
  995 + } else {
  996 + m.put("zt", 1);
  997 + }
  998 + mapList.add(m);
  999 + }
  1000 +
  1001 + List<Map<String, Object>> tjlist=new ArrayList<Map<String, Object>>();
  1002 + if(!d4.equals("")){
  1003 + tjlist= scheduleRealInfoService.statisticsDailyTjHb(gsdm, fgsdm, line, d3, d4, xlName, type);
  1004 + }
  1005 + List<Map<String, Object>> mapListHj = new ArrayList<Map<String, Object>>();
  1006 +
  1007 + if(mapList.size()>0){
  1008 + if(tjlist.size()>0){
  1009 + for ( int i=0;i<tjlist.size();i++) {
  1010 + Map<String, Object> tjMap =tjlist.get(i);
  1011 + boolean fage=true;
  1012 + for(int j=0;j<mapList.size();j++){
  1013 + Map<String, Object> lsMap=mapList.get(j);
  1014 + if(lsMap.get("xlBm").toString().equals(tjMap.get("xlBm").toString())){
  1015 + Map<String, Object> hjMap=new HashMap<String,Object>();
  1016 + hjMap.put("xlBm", tjMap.get("xlBm"));
  1017 + hjMap.put("xlName", tjMap.get("xlName"));
  1018 + hjMap.put("jhzlc", Arith.add(lsMap.get("jhzlc"), tjMap.get("jhzlc")));
  1019 + hjMap.put("jhlc", Arith.add(lsMap.get("jhlc"), tjMap.get("jhlc")));
  1020 + hjMap.put("jcclc",Arith.add(lsMap.get("jcclc"), tjMap.get("jcclc")));
  1021 + hjMap.put("sjzgl",Arith.add(lsMap.get("sjzgl"), tjMap.get("sjzgl")));
  1022 + hjMap.put("sjgl", Arith.add(lsMap.get("sjgl"), tjMap.get("sjgl")));
  1023 + hjMap.put("sjksgl", Arith.add(lsMap.get("sjksgl"), tjMap.get("sjksgl")));
  1024 + hjMap.put("ssgl", Arith.add(lsMap.get("ssgl"), tjMap.get("ssgl")));
  1025 + hjMap.put("ssbc", Integer.parseInt(lsMap.get("ssbc").toString())+Integer.parseInt(tjMap.get("ssbc").toString()));
  1026 + hjMap.put("ssgl_lz", Arith.add(lsMap.get("ssgl_lz"), tjMap.get("ssgl_lz")));
  1027 + hjMap.put("ssgl_dm", Arith.add(lsMap.get("ssgl_dm"), tjMap.get("ssgl_dm")));
  1028 + hjMap.put("ssgl_gz", Arith.add(lsMap.get("ssgl_gz"), tjMap.get("ssgl_gz")));
  1029 + hjMap.put("ssgl_jf", Arith.add(lsMap.get("ssgl_jf"), tjMap.get("ssgl_jf")));
  1030 + hjMap.put("ssgl_zs", Arith.add(lsMap.get("ssgl_zs"), tjMap.get("ssgl_zs")));
  1031 + hjMap.put("ssgl_qr", Arith.add(lsMap.get("ssgl_qr"), tjMap.get("ssgl_qr")));
  1032 + hjMap.put("ssgl_qc", Arith.add(lsMap.get("ssgl_qc"), tjMap.get("ssgl_qc")));
  1033 + hjMap.put("ssgl_kx", Arith.add(lsMap.get("ssgl_kx"), tjMap.get("ssgl_kx")));
  1034 + hjMap.put("ssgl_qh", Arith.add(lsMap.get("ssgl_qh"), tjMap.get("ssgl_qh")));
  1035 + hjMap.put("ssgl_yw", Arith.add(lsMap.get("ssgl_yw"), tjMap.get("ssgl_yw")));
  1036 + hjMap.put("ssgl_other", Arith.add(lsMap.get("ssgl_other"), tjMap.get("ssgl_other")));
  1037 + hjMap.put("ljgl", Arith.add(lsMap.get("ljgl"), tjMap.get("ljgl")));
  1038 + hjMap.put("jhbc", Integer.parseInt(lsMap.get("jhbc").toString())+ Integer.parseInt(tjMap.get("jhbc").toString()));
  1039 + hjMap.put("jhbc_m", Integer.parseInt(lsMap.get("jhbc_m").toString())+Integer.parseInt(tjMap.get("jhbc_m").toString()));
  1040 + hjMap.put("jhbc_a", Integer.parseInt(lsMap.get("jhbc_a").toString())+ Integer.parseInt(tjMap.get("jhbc_a").toString()));
  1041 + hjMap.put("sjbc", Integer.parseInt(lsMap.get("sjbc").toString())+ Integer.parseInt(tjMap.get("sjbc").toString()));
  1042 + hjMap.put("sjbc_m",Integer.parseInt(lsMap.get("sjbc_m").toString())+ Integer.parseInt(tjMap.get("sjbc_m").toString()));
  1043 + hjMap.put("sjbc_a", Integer.parseInt(lsMap.get("sjbc_a").toString())+ Integer.parseInt(tjMap.get("sjbc_a").toString()));
  1044 + hjMap.put("ljbc", Integer.parseInt(lsMap.get("ljbc").toString())+ Integer.parseInt(tjMap.get("ljbc").toString()));
  1045 + hjMap.put("ljbc_m", Integer.parseInt(lsMap.get("ljbc_m").toString())+ Integer.parseInt(tjMap.get("ljbc_m").toString()));
  1046 + hjMap.put("ljbc_a", Integer.parseInt(lsMap.get("ljbc_a").toString())+Integer.parseInt( tjMap.get("ljbc_a").toString()));
  1047 + hjMap.put("fzbc", Integer.parseInt(lsMap.get("fzbc").toString())+ Integer.parseInt(tjMap.get("fzbc").toString()));
  1048 + hjMap.put("fzbc_m",Integer.parseInt(lsMap.get("fzbc_m").toString())+ Integer.parseInt(tjMap.get("fzbc_m").toString()));
  1049 + hjMap.put("fzbc_a",Integer.parseInt(lsMap.get("fzbc_a").toString())+ Integer.parseInt(tjMap.get("fzbc_a").toString()));
  1050 + hjMap.put("dtbc", Integer.parseInt(lsMap.get("dtbc").toString())+ Integer.parseInt(tjMap.get("dtbc").toString()));
  1051 + hjMap.put("dtbc_m", Integer.parseInt(lsMap.get("dtbc_m").toString())+ Integer.parseInt(tjMap.get("dtbc_m").toString()));
  1052 + hjMap.put("dtbc_a", Integer.parseInt(lsMap.get("dtbc_a").toString())+ Integer.parseInt(tjMap.get("dtbc_a").toString()));
  1053 + hjMap.put("djg", Integer.parseInt(lsMap.get("djg").toString())+ Integer.parseInt(tjMap.get("djg").toString()));
  1054 + hjMap.put("djg_m", Integer.parseInt(lsMap.get("djg_m").toString())+ Integer.parseInt(tjMap.get("djg_m").toString()));
  1055 + hjMap.put("djg_a", Integer.parseInt(lsMap.get("djg_a").toString())+ Integer.parseInt(tjMap.get("djg_a").toString()));
  1056 + if(Arith.add(lsMap.get("djg_time"),0)>Arith.add(tjMap.get("djg_time"), 0)){
  1057 + hjMap.put("djg_time", lsMap.get("djg_time"));
  1058 + }else{
  1059 + hjMap.put("djg_time",tjMap.get("djg_time"));
  1060 + }
  1061 +
  1062 + double jl = Arith.sub(Arith.add(hjMap.get("jhlc"), hjMap.get("ljgl")), hjMap.get("ssgl"));
  1063 + if (jl == Double.parseDouble(hjMap.get("sjgl").toString())) {
  1064 + hjMap.put("zt", 0);
  1065 + } else {
  1066 + hjMap.put("zt", 1);
  1067 + }
  1068 + mapListHj.add(hjMap);
  1069 + fage=false;
  1070 + }
  1071 + }
  1072 +
  1073 + if(fage){
  1074 + Map<String, Object> m = new HashMap<String, Object>();
  1075 + m.put("xlBm", tjMap.get("xlBm"));
  1076 + m.put("xlName", tjMap.get("xlName"));
  1077 + m.put("jhzlc", tjMap.get("jhzlc"));
  1078 + m.put("jhlc", tjMap.get("jhlc"));
  1079 + m.put("jcclc", tjMap.get("jcclc"));
  1080 + m.put("sjzgl",tjMap.get("sjzgl"));
  1081 + m.put("sjgl", tjMap.get("sjgl"));
  1082 + m.put("sjksgl", tjMap.get("sjksgl"));
  1083 + m.put("ssgl", tjMap.get("ssgl"));
  1084 + m.put("ssbc", tjMap.get("ssbc"));
  1085 + m.put("ssgl_lz", tjMap.get("ssgl_lz"));
  1086 + m.put("ssgl_dm", tjMap.get("ssgl_dm"));
  1087 + m.put("ssgl_gz", tjMap.get("ssgl_gz"));
  1088 + m.put("ssgl_jf", tjMap.get("ssgl_jf"));
  1089 + m.put("ssgl_zs", tjMap.get("ssgl_zs"));
  1090 + m.put("ssgl_qr", tjMap.get("ssgl_qr"));
  1091 + m.put("ssgl_qc", tjMap.get("ssgl_qc"));
  1092 + m.put("ssgl_kx", tjMap.get("ssgl_kx"));
  1093 + m.put("ssgl_qh", tjMap.get("ssgl_qh"));
  1094 + m.put("ssgl_yw", tjMap.get("ssgl_yw"));
  1095 + m.put("ssgl_other", tjMap.get("ssgl_other"));
  1096 + m.put("ljgl", tjMap.get("ljgl"));
  1097 + m.put("jhbc", tjMap.get("jhbc"));
  1098 + m.put("jhbc_m", tjMap.get("jhbc_m"));
  1099 + m.put("jhbc_a", tjMap.get("jhbc_a"));
  1100 + m.put("sjbc", tjMap.get("sjbc"));
  1101 + m.put("sjbc_m",tjMap.get("sjbc_m"));
  1102 + m.put("sjbc_a", tjMap.get("sjbc_a"));
  1103 + m.put("ljbc", tjMap.get("ljbc"));
  1104 + m.put("ljbc_m", tjMap.get("ljbc_m"));
  1105 + m.put("ljbc_a",tjMap.get("ljbc_a"));
  1106 + m.put("fzbc", tjMap.get("fzbc"));
  1107 + m.put("fzbc_m", tjMap.get("fzbc_m"));
  1108 + m.put("fzbc_a",tjMap.get("fzbc_a"));
  1109 + m.put("dtbc", tjMap.get("dtbc"));
  1110 + m.put("dtbc_m", tjMap.get("dtbc_m"));
  1111 + m.put("dtbc_a", tjMap.get("dtbc_a"));
  1112 + m.put("djg", tjMap.get("djg"));
  1113 + m.put("djg_m", tjMap.get("djg_m"));
  1114 + m.put("djg_a", tjMap.get("djg_a"));
  1115 + m.put("djg_time", tjMap.get("djg_time"));
  1116 + double jl = Arith.sub(Arith.add(m.get("jhlc"), m.get("ljgl")), m.get("ssgl"));
  1117 + if (jl == Double.parseDouble(m.get("sjgl").toString())) {
  1118 + m.put("zt", 0);
  1119 + } else {
  1120 + m.put("zt", 1);
  1121 + }
  1122 + mapListHj.add(m);
  1123 + }
  1124 + }
  1125 + }else{
  1126 + mapListHj.addAll(mapList);
  1127 + }
  1128 + }else{
  1129 + for (int i=0;i<tjlist.size();i++) {
  1130 + Map<String, Object> tjMap =tjlist.get(i);
  1131 + Map<String, Object> m = new HashMap<String, Object>();
  1132 + m.put("xlBm", tjMap.get("xlBm"));
  1133 + m.put("xlName", tjMap.get("xlName"));
  1134 + m.put("jhzlc", tjMap.get("jhzlc"));
  1135 + m.put("jhlc", tjMap.get("jhlc"));
  1136 + m.put("jcclc", tjMap.get("jcclc"));
  1137 + m.put("sjzgl",tjMap.get("sjzgl"));
  1138 + m.put("sjgl", tjMap.get("sjgl"));
  1139 + m.put("sjksgl", tjMap.get("sjksgl"));
  1140 + m.put("ssgl", tjMap.get("ssgl"));
  1141 + m.put("ssbc", tjMap.get("ssbc"));
  1142 + m.put("ssgl_lz", tjMap.get("ssgl_lz"));
  1143 + m.put("ssgl_dm", tjMap.get("ssgl_dm"));
  1144 + m.put("ssgl_gz", tjMap.get("ssgl_gz"));
  1145 + m.put("ssgl_jf", tjMap.get("ssgl_jf"));
  1146 + m.put("ssgl_zs", tjMap.get("ssgl_zs"));
  1147 + m.put("ssgl_qr", tjMap.get("ssgl_qr"));
  1148 + m.put("ssgl_qc", tjMap.get("ssgl_qc"));
  1149 + m.put("ssgl_kx", tjMap.get("ssgl_kx"));
  1150 + m.put("ssgl_qh", tjMap.get("ssgl_qh"));
  1151 + m.put("ssgl_yw", tjMap.get("ssgl_yw"));
  1152 + m.put("ssgl_other", tjMap.get("ssgl_other"));
  1153 + m.put("ljgl", tjMap.get("ljgl"));
  1154 + m.put("jhbc", tjMap.get("jhbc"));
  1155 + m.put("jhbc_m", tjMap.get("jhbc_m"));
  1156 + m.put("jhbc_a", tjMap.get("jhbc_a"));
  1157 + m.put("sjbc", tjMap.get("sjbc"));
  1158 + m.put("sjbc_m",tjMap.get("sjbc_m"));
  1159 + m.put("sjbc_a", tjMap.get("sjbc_a"));
  1160 + m.put("ljbc", tjMap.get("ljbc"));
  1161 + m.put("ljbc_m", tjMap.get("ljbc_m"));
  1162 + m.put("ljbc_a",tjMap.get("ljbc_a"));
  1163 + m.put("fzbc", tjMap.get("fzbc"));
  1164 + m.put("fzbc_m", tjMap.get("fzbc_m"));
  1165 + m.put("fzbc_a",tjMap.get("fzbc_a"));
  1166 + m.put("dtbc", tjMap.get("dtbc"));
  1167 + m.put("dtbc_m", tjMap.get("dtbc_m"));
  1168 + m.put("dtbc_a", tjMap.get("dtbc_a"));
  1169 + m.put("djg", tjMap.get("djg"));
  1170 + m.put("djg_m", tjMap.get("djg_m"));
  1171 + m.put("djg_a", tjMap.get("djg_a"));
  1172 + m.put("djg_time", tjMap.get("djg_time"));
  1173 + double jl = Arith.sub(Arith.add(m.get("jhlc"), m.get("ljgl")), m.get("ssgl"));
  1174 + if (jl == Double.parseDouble(m.get("sjgl").toString())) {
  1175 + m.put("zt", 0);
  1176 + } else {
  1177 + m.put("zt", 1);
  1178 + }
  1179 + mapListHj.add(m);
  1180 +
  1181 + }
  1182 + }
  1183 +
  1184 + if (type != null && type.length() != 0 && type.equals("export")) {
  1185 + SimpleDateFormat sdfMonth = new SimpleDateFormat("yyyy-MM-dd"),
  1186 + sdfSimple = new SimpleDateFormat("yyyyMMdd");
  1187 + List<Iterator<?>> listI = new ArrayList<Iterator<?>>();
  1188 + Map<String, Object> m = new HashMap<String, Object>();
  1189 + m.put("date", date+"至"+date2);
  1190 + ReportUtils ee = new ReportUtils();
  1191 + try {
  1192 + String dateTime = "";
  1193 + if(date.equals(date2)){
  1194 + dateTime = sdfSimple.format(sdfMonth.parse(date));
  1195 + } else {
  1196 + dateTime = sdfSimple.format(sdfMonth.parse(date))
  1197 + +"-"+sdfSimple.format(sdfMonth.parse(date2));
  1198 + }
  1199 + listI.add(mapListHj.iterator());
  1200 + String path = this.getClass().getResource("/").getPath() + "static/pages/forms/";
  1201 + ee.excelReplace(listI, new Object[]{m}, path + "mould/statisticsDaily_.xls",
  1202 + path + "export/" + dateTime + "-" + xlName + "-统计日报.xls");
  1203 + } catch (Exception e) {
  1204 + // TODO: handle exception
  1205 + //e.printStackTrace();
  1206 + logger.info("" , e);
  1207 + }
  1208 + }
  1209 +
  1210 + return mapListHj;
  1211 + }
853 1212
854 public CalcStatistics addStatistics(CalcStatistics s, CalcStatistics s_){ 1213 public CalcStatistics addStatistics(CalcStatistics s, CalcStatistics s_){
855 s.setJhzlc(Arith.add(s.getJhzlc()!=null?s.getJhzlc():0, s_.getJhzlc())); 1214 s.setJhzlc(Arith.add(s.getJhzlc()!=null?s.getJhzlc():0, s_.getJhzlc()));
src/main/java/com/bsth/service/realcontrol/ScheduleRealInfoService.java
@@ -119,6 +119,9 @@ public interface ScheduleRealInfoService extends BaseService&lt;ScheduleRealInfo, L @@ -119,6 +119,9 @@ public interface ScheduleRealInfoService extends BaseService&lt;ScheduleRealInfo, L
119 119
120 List<Map<String,Object>> statisticsDailyTj(String gsdm,String fgsdm,String line, String date,String date2, String xlName, String type); 120 List<Map<String,Object>> statisticsDailyTj(String gsdm,String fgsdm,String line, String date,String date2, String xlName, String type);
121 121
  122 + //用于实时数据与统计数据合并查询
  123 + List<Map<String,Object>> statisticsDailyTjHb(String gsdm,String fgsdm,String line, String date,String date2, String xlName, String type);
  124 +
122 //List<Object> scheduleDaily(String line,String date); 125 //List<Object> scheduleDaily(String line,String date);
123 126
124 int countByLineCodeAndDate(String xlBm, String schDate); 127 int countByLineCodeAndDate(String xlBm, String schDate);
src/main/java/com/bsth/service/realcontrol/impl/ScheduleRealInfoServiceImpl.java
@@ -2666,6 +2666,7 @@ public class ScheduleRealInfoServiceImpl extends BaseServiceImpl&lt;ScheduleRealInf @@ -2666,6 +2666,7 @@ public class ScheduleRealInfoServiceImpl extends BaseServiceImpl&lt;ScheduleRealInf
2666 } 2666 }
2667 Map<String, Object> map = new HashMap<String, Object>(); 2667 Map<String, Object> map = new HashMap<String, Object>();
2668 if (list.size() > 0) { 2668 if (list.size() > 0) {
  2669 + map.put("xlBm", list.get(0).getXlBm());
2669 map.put("xlName", list.get(0).getXlName()); 2670 map.put("xlName", list.get(0).getXlName());
2670 try { 2671 try {
2671 map.put("xlNamePy", PinyinHelper.convertToPinyinString(list.get(0).getXlName(), "", PinyinFormat.WITHOUT_TONE)); 2672 map.put("xlNamePy", PinyinHelper.convertToPinyinString(list.get(0).getXlName(), "", PinyinFormat.WITHOUT_TONE));
@@ -2914,6 +2915,148 @@ public class ScheduleRealInfoServiceImpl extends BaseServiceImpl&lt;ScheduleRealInf @@ -2914,6 +2915,148 @@ public class ScheduleRealInfoServiceImpl extends BaseServiceImpl&lt;ScheduleRealInf
2914 } 2915 }
2915 2916
2916 @Override 2917 @Override
  2918 + public List<Map<String, Object>> statisticsDailyTjHb(String gsdm, String fgsdm, String line, String date, String date2,
  2919 + String xlName, String type) {
  2920 + List<ScheduleRealInfo> list = new ArrayList<ScheduleRealInfo>();
  2921 + List<ScheduleRealInfo> list_s = new ArrayList<ScheduleRealInfo>();
  2922 + List<ScheduleRealInfo> lists = new ArrayList<ScheduleRealInfo>();
  2923 + line = line.trim();
  2924 + if (line.equals("")) {
  2925 + //查询所有线路
  2926 + list = scheduleRealInfoRepository.scheduleByDateAndLineTj(line, date, date2, gsdm, fgsdm);
  2927 + } else {
  2928 + //查询单条线路
  2929 + list = scheduleRealInfoRepository.scheduleByDateAndLineTj2(line, date, date2);
  2930 + }
  2931 + for (int i = 0; i < list.size(); i++) {
  2932 + ScheduleRealInfo s = list.get(i);
  2933 + Set<ChildTaskPlan> cts = s.getcTasks();
  2934 + if (cts != null && cts.size() > 0) {
  2935 + list_s.add(s);
  2936 + } else {
  2937 + if (s.getZdsjActual() != null && s.getFcsjActual() != null) {
  2938 + list_s.add(s);
  2939 + }
  2940 + }
  2941 + }
  2942 + List<Map<String, Object>> lMap = new ArrayList<Map<String, Object>>();
  2943 + for (int i = 0; i < list.size(); i++) {
  2944 + if (i < list.size() - 1) {
  2945 + if (list.get(i + 1).getXlBm().equals(list.get(i).getXlBm())) {
  2946 + lists.add(list.get(i));
  2947 + } else {
  2948 + lists.add(list.get(i));
  2949 + Map<String, Object> map = staticTj(lists);
  2950 + lMap.add(map);
  2951 + lists = new ArrayList<ScheduleRealInfo>();
  2952 + }
  2953 + } else {
  2954 + if (list.get(i).getXlBm().equals(list.get(i - 1).getXlBm())) {
  2955 + lists.add(list.get(i));
  2956 + Map<String, Object> map = staticTj(lists);
  2957 + lMap.add(map);
  2958 + } else {
  2959 + lists = new ArrayList<ScheduleRealInfo>();
  2960 + lists.add(list.get(i));
  2961 + Map<String, Object> map = staticTj(lists);
  2962 + lMap.add(map);
  2963 + }
  2964 + }
  2965 + }
  2966 +
  2967 + Collections.sort(lMap, new AccountXlbm());
  2968 + Map<String, Object> map = new HashMap<String, Object>();
  2969 + map.put("xlBm", "hj");
  2970 + map.put("xlName", "合计");
  2971 + double jhyygl = culateService.culateJhgl(list);//计划营运公里
  2972 + double jhjcclc = culateService.culateJhJccgl(list);//计划进出场公里(计划空驶公里)
  2973 + map.put("jhlc", jhyygl);
  2974 + map.put("jcclc", jhjcclc);
  2975 + map.put("jhzlc", Arith.add(jhyygl, jhjcclc));
  2976 +
  2977 + double ljgl = culateService.culateLjgl(list_s);
  2978 + double sjyygl = culateService.culateSjgl(list_s);
  2979 + double zyygl = Arith.add(sjyygl, ljgl);
  2980 +
  2981 + double sjjccgl = culateService.culateJccgl(list_s);
  2982 + double sjksgl = culateService.culateKsgl(list_s);
  2983 + double zksgl = Arith.add(sjjccgl, sjksgl);
  2984 + map.put("sjzgl", Arith.add(zyygl, zksgl));
  2985 + map.put("sjgl", zyygl);
  2986 + map.put("sjksgl", zksgl);
  2987 +
  2988 + double ssgl = culateService.culateLbgl(list);
  2989 + map.put("ssgl", ssgl);
  2990 + //计划+临加-少驶=实驶
  2991 + double jl = Arith.sub(Arith.add(jhyygl, ljgl), ssgl);
  2992 + if (jl == zyygl) {
  2993 + map.put("zt", 0);
  2994 + } else {
  2995 + map.put("zt", 1);
  2996 + }
  2997 + map.put("ssgl_lz", culateService.culateCJLC(list, "路阻"));
  2998 + map.put("ssgl_dm", culateService.culateCJLC(list, "吊慢"));
  2999 + map.put("ssgl_gz", culateService.culateCJLC(list, "故障"));
  3000 + map.put("ssgl_jf", culateService.culateCJLC(list, "纠纷"));
  3001 + map.put("ssgl_zs", culateService.culateCJLC(list, "肇事"));
  3002 + map.put("ssgl_qr", culateService.culateCJLC(list, "缺人"));
  3003 + map.put("ssgl_qc", culateService.culateCJLC(list, "缺车"));
  3004 + map.put("ssgl_kx", culateService.culateCJLC(list, "客稀"));
  3005 + map.put("ssgl_qh", culateService.culateCJLC(list, "气候"));
  3006 + map.put("ssgl_yw", culateService.culateCJLC(list, "援外"));
  3007 + double ssgl_pc = culateService.culateCJLC(list, "配车");
  3008 + double ssgl_by = culateService.culateCJLC(list, "保养");
  3009 + double ssgl_cj = culateService.culateCJLC(list, "抽减");
  3010 + double ssgl_qt = culateService.culateCJLC(list, "其他");
  3011 + map.put("ssgl_other", Arith.add(Arith.add(ssgl_pc, ssgl_by), Arith.add(ssgl_cj, ssgl_qt)));
  3012 +
  3013 + map.put("ssbc", culateService.culateLbbc(list));
  3014 + map.put("ljgl", ljgl);
  3015 + map.put("jhbc", culateService.culateJhbc(list, ""));
  3016 + map.put("jhbc_m", culateService.culateJhbc(list, "zgf"));
  3017 + map.put("jhbc_a", culateService.culateJhbc(list, "wgf"));
  3018 + map.put("sjbc", culateService.culateSjbc(list_s, ""));
  3019 + map.put("sjbc_m", culateService.culateSjbc(list_s, "zgf"));
  3020 + map.put("sjbc_a", culateService.culateSjbc(list_s, "wgf"));
  3021 + map.put("ljbc", culateService.culateLjbc(list_s, ""));
  3022 + map.put("ljbc_m", culateService.culateLjbc(list_s, "zgf"));
  3023 + map.put("ljbc_a", culateService.culateLjbc(list_s, "wgf"));
  3024 + map.put("fzbc", culateService.culateFzbc(list_s, ""));
  3025 + map.put("fzbc_m", culateService.culateFzbc(list_s, "zgf"));
  3026 + map.put("fzbc_a", culateService.culateFzbc(list_s, "wgf"));
  3027 + map.put("dtbc", 0);
  3028 + map.put("dtbc_m", 0);
  3029 + map.put("dtbc_a", 0);
  3030 + if (list.size() > 0) {
  3031 + int djg = 0, djg_m = 0, djg_a = 0, djg_time = 0;
  3032 + for (Map<String, Object> m : lMap) {
  3033 + if (m.containsKey("djg") && m.get("djg") != null)
  3034 + djg += Integer.valueOf(m.get("djg").toString());
  3035 + if (m.containsKey("djg_m") && m.get("djg_m") != null)
  3036 + djg_m += Integer.valueOf(m.get("djg_m").toString());
  3037 + if (m.containsKey("djg_a") && m.get("djg_a") != null)
  3038 + djg_a += Integer.valueOf(m.get("djg_a").toString());
  3039 + if (m.containsKey("djg_time") && m.get("djg_time") != null) {
  3040 + int t = Integer.valueOf(m.get("djg_time").toString());
  3041 + if (t > djg_time)
  3042 + djg_time = t;
  3043 + }
  3044 + }
  3045 + map.put("djg", djg);
  3046 + map.put("djg_m", djg_m);
  3047 + map.put("djg_a", djg_a);
  3048 + map.put("djg_time", djg_time);
  3049 + } else {
  3050 + map.put("djg", "0");
  3051 + map.put("djg_m", "0");
  3052 + map.put("djg_a", "0");
  3053 + map.put("djg_time", "0");
  3054 + }
  3055 + lMap.add(map);
  3056 + return lMap;
  3057 + }
  3058 +
  3059 + @Override
2917 public Map<String, Object> scheduleDaily(String line, String date) { 3060 public Map<String, Object> scheduleDaily(String line, String date) {
2918 Map<String, String> tempMap = null; 3061 Map<String, String> tempMap = null;
2919 List<ScheduleRealInfo> scheduleRealInfos = scheduleRealInfoRepository.scheduleByDateAndLine(line, date); 3062 List<ScheduleRealInfo> scheduleRealInfos = scheduleRealInfoRepository.scheduleByDateAndLine(line, date);
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 +}