Commit cca5d02726e5f892e25ca05521a4b86af0f0c0e5
1 parent
831ec122
智能时刻表发车间隔报表
Showing
11 changed files
with
303 additions
and
12 deletions
src/main/java/com/bsth/controller/schedule/core/TTInfoDetailController.java
| ... | ... | @@ -128,6 +128,32 @@ public class TTInfoDetailController extends BController<TTInfoDetail, Long> { |
| 128 | 128 | return ttInfoDetailService.skbDetailMxSave(entities); |
| 129 | 129 | } |
| 130 | 130 | |
| 131 | + @RequestMapping(value = "/exportDTDFile2", method = RequestMethod.POST) | |
| 132 | + public void exportFile2(@RequestBody TTinfoDetailDynamicData.LineHeadWayInfo lineHeadWayInfo, | |
| 133 | + HttpServletResponse response) throws Exception { | |
| 134 | + DataToolsFile dataToolsFile = ttInfoDetailService.exportHeadwayTTinfo(lineHeadWayInfo); | |
| 135 | + | |
| 136 | + // 流输出导出文件 | |
| 137 | + response.setHeader("content-type", "application/octet-stream"); | |
| 138 | + response.setHeader("Content-Disposition", "attachment; filename=" + dataToolsFile.getFile().getName()); | |
| 139 | + response.setContentType("application/octet-stream"); | |
| 140 | + | |
| 141 | + OutputStream os = response.getOutputStream(); | |
| 142 | + BufferedOutputStream bos = new BufferedOutputStream(os); | |
| 143 | + | |
| 144 | + InputStream is = new FileInputStream(dataToolsFile.getFile()); | |
| 145 | + BufferedInputStream bis = new BufferedInputStream(is); | |
| 146 | + | |
| 147 | + int length = 0; | |
| 148 | + byte[] temp = new byte[1 * 1024 * 10]; | |
| 149 | + while ((length = bis.read(temp)) != -1) { | |
| 150 | + bos.write(temp, 0, length); | |
| 151 | + } | |
| 152 | + bos.flush(); | |
| 153 | + bis.close(); | |
| 154 | + bos.close(); | |
| 155 | + is.close(); | |
| 156 | + } | |
| 131 | 157 | |
| 132 | 158 | @RequestMapping(value = "/exportDTDFile/{type}", method = RequestMethod.POST) |
| 133 | 159 | public void exportFile( | ... | ... |
src/main/java/com/bsth/service/schedule/TTInfoDetailService.java
| ... | ... | @@ -34,6 +34,14 @@ public interface TTInfoDetailService extends BService<TTInfoDetail, Long> { |
| 34 | 34 | DataToolsFile exportDynamicTTinfo(TTinfoDetailDynamicData.DTInfos dtInfos, DataToolsFileType type) throws ScheduleException; |
| 35 | 35 | |
| 36 | 36 | /** |
| 37 | + * 导出班次发车间隔信息。 | |
| 38 | + * @param lineHeadWayInfo | |
| 39 | + * @return | |
| 40 | + * @throws ScheduleException | |
| 41 | + */ | |
| 42 | + DataToolsFile exportHeadwayTTinfo(TTinfoDetailDynamicData.LineHeadWayInfo lineHeadWayInfo) throws ScheduleException; | |
| 43 | + | |
| 44 | + /** | |
| 37 | 45 | * 获取时刻表最大发车顺序号 |
| 38 | 46 | * @param xlid 线路id |
| 39 | 47 | * @param ttinfoid 时刻表id | ... | ... |
src/main/java/com/bsth/service/schedule/datatools/TTInfoDetailDataToolsImpl.java
| ... | ... | @@ -800,4 +800,82 @@ public class TTInfoDetailDataToolsImpl implements DataToolsService, TTInfoDetail |
| 800 | 800 | } |
| 801 | 801 | |
| 802 | 802 | } |
| 803 | + | |
| 804 | + @Override | |
| 805 | + public DataToolsFile exportHeadwayTTinfo(LineHeadWayInfo lineHeadWayInfo) throws ScheduleException { | |
| 806 | + try { | |
| 807 | + // 输出2007版本 | |
| 808 | + ExcelPoiOperator excelPoiOperator = new Excel2007PoiOperator(); | |
| 809 | + | |
| 810 | + // 使用POI,创建xlsx文件 | |
| 811 | + org.apache.poi.ss.usermodel.Workbook wb = excelPoiOperator.createWorkBook(); | |
| 812 | + // 一个sheet写上下行间隔信息 | |
| 813 | + org.apache.poi.ss.usermodel.Sheet sheet = excelPoiOperator.createWorkBookSheet(wb, "时刻表发车间隔信息_统计"); | |
| 814 | + | |
| 815 | + // 构建第一行数据 | |
| 816 | + Row lpHeadRow = excelPoiOperator.createSheetRow(sheet, 0); | |
| 817 | + // 构建上行发车间隔表头 | |
| 818 | + excelPoiOperator.createStringCell(wb, lpHeadRow, (short) 0, "路牌", new Color(0x96b9d7)); | |
| 819 | + excelPoiOperator.createStringCell(wb, lpHeadRow, (short) 1, "发车时间", new Color(0x96b9d7)); | |
| 820 | + excelPoiOperator.createStringCell(wb, lpHeadRow, (short) 2, "发车间隔", new Color(0x96b9d7)); | |
| 821 | + // 构造下行发车间隔表头 | |
| 822 | + excelPoiOperator.createStringCell(wb, lpHeadRow, (short) 6, "路牌", new Color(0x96b9d7)); | |
| 823 | + excelPoiOperator.createStringCell(wb, lpHeadRow, (short) 7, "发车时间", new Color(0x96b9d7)); | |
| 824 | + excelPoiOperator.createStringCell(wb, lpHeadRow, (short) 8, "发车间隔", new Color(0x96b9d7)); | |
| 825 | + | |
| 826 | + // 构造行 | |
| 827 | + int maxRow = Math.max(lineHeadWayInfo.getUpBcList().size(), lineHeadWayInfo.getDownBcList().size()); | |
| 828 | + List<Row> rowList = new ArrayList<>(); | |
| 829 | + for (int i = 1; i <= maxRow; i++) { | |
| 830 | + Row row = excelPoiOperator.createSheetRow(sheet, i); | |
| 831 | + rowList.add(row); | |
| 832 | + } | |
| 833 | + | |
| 834 | + // 构造上行发车间隔信息 | |
| 835 | + for (int i = 0; i < lineHeadWayInfo.getUpBcList().size(); i++) { | |
| 836 | + BcHeadWayInfo bcHeadWayInfo = lineHeadWayInfo.getUpBcList().get(i); | |
| 837 | + excelPoiOperator.createStringCell(wb, rowList.get(i), (short) 0, bcHeadWayInfo.getLpName()); | |
| 838 | + excelPoiOperator.createStringCell(wb, rowList.get(i), (short) 1, bcHeadWayInfo.getFcsj()); | |
| 839 | + excelPoiOperator.createStringCell(wb, rowList.get(i), (short) 2, bcHeadWayInfo.getHeadway()); | |
| 840 | + } | |
| 841 | + // 构造下行发车间隔信息 | |
| 842 | + for (int i = 0; i < lineHeadWayInfo.getDownBcList().size(); i++) { | |
| 843 | + BcHeadWayInfo bcHeadWayInfo = lineHeadWayInfo.getDownBcList().get(i); | |
| 844 | + excelPoiOperator.createStringCell(wb, rowList.get(i), (short) 6, bcHeadWayInfo.getLpName()); | |
| 845 | + excelPoiOperator.createStringCell(wb, rowList.get(i), (short) 7, bcHeadWayInfo.getFcsj()); | |
| 846 | + excelPoiOperator.createStringCell(wb, rowList.get(i), (short) 8, bcHeadWayInfo.getHeadway()); | |
| 847 | + } | |
| 848 | + | |
| 849 | + // 自适应单元格长宽 | |
| 850 | + sheet.autoSizeColumn(0); | |
| 851 | + sheet.autoSizeColumn(1); | |
| 852 | + sheet.autoSizeColumn(2); | |
| 853 | + sheet.autoSizeColumn(6); | |
| 854 | + sheet.autoSizeColumn(7); | |
| 855 | + sheet.autoSizeColumn(8); | |
| 856 | + | |
| 857 | + // wb内存写入文件 | |
| 858 | + String filepath = dataToolsProperties.getFileoutputDir() + | |
| 859 | + File.separator + | |
| 860 | + "动态时刻表发车间隔信息-" + | |
| 861 | + new DateTime().toString("yyyyMMddHHmmss") + ".xlsx"; | |
| 862 | + File file = new File(filepath); | |
| 863 | + excelPoiOperator.writeExcel(file, wb); | |
| 864 | + | |
| 865 | + DataToolsFile dataToolsFile = new DataToolsFile(); | |
| 866 | + dataToolsFile.setFileType(DataToolsFileType.XLSX); | |
| 867 | + dataToolsFile.setFile(file); | |
| 868 | + | |
| 869 | + return dataToolsFile; | |
| 870 | + | |
| 871 | + } catch (Exception exp) { | |
| 872 | + LOGGER.info("//---------------- 动态时刻表发车间隔信息输出 failed... ----------------//"); | |
| 873 | + | |
| 874 | + StringWriter sw = new StringWriter(); | |
| 875 | + exp.printStackTrace(new PrintWriter(sw)); | |
| 876 | + LOGGER.info(sw.toString()); | |
| 877 | + | |
| 878 | + throw new ScheduleException(exp); | |
| 879 | + } | |
| 880 | + } | |
| 803 | 881 | } | ... | ... |
src/main/java/com/bsth/service/schedule/datatools/TTinfoDetailDynamicData.java
| ... | ... | @@ -400,6 +400,62 @@ public interface TTinfoDetailDynamicData { |
| 400 | 400 | } |
| 401 | 401 | } |
| 402 | 402 | |
| 403 | + class BcHeadWayInfo { // 班次发车间隔信息 | |
| 404 | + /** 路牌名字 */ | |
| 405 | + private String lpName; | |
| 406 | + /** 发车时间 */ | |
| 407 | + private String fcsj; | |
| 408 | + /** 发车间隔 */ | |
| 409 | + private String headway; | |
| 410 | + | |
| 411 | + public String getLpName() { | |
| 412 | + return lpName; | |
| 413 | + } | |
| 414 | + | |
| 415 | + public void setLpName(String lpName) { | |
| 416 | + this.lpName = lpName; | |
| 417 | + } | |
| 418 | + | |
| 419 | + public String getFcsj() { | |
| 420 | + return fcsj; | |
| 421 | + } | |
| 422 | + | |
| 423 | + public void setFcsj(String fcsj) { | |
| 424 | + this.fcsj = fcsj; | |
| 425 | + } | |
| 426 | + | |
| 427 | + public String getHeadway() { | |
| 428 | + return headway; | |
| 429 | + } | |
| 430 | + | |
| 431 | + public void setHeadway(String headway) { | |
| 432 | + this.headway = headway; | |
| 433 | + } | |
| 434 | + } | |
| 435 | + | |
| 436 | + class LineHeadWayInfo { // 线路发车间隔信息 | |
| 437 | + /** 上行班次发车间隔信息 */ | |
| 438 | + private List<BcHeadWayInfo> upBcList; | |
| 439 | + /** 下行班次发车间隔信息 */ | |
| 440 | + private List<BcHeadWayInfo> downBcList; | |
| 441 | + | |
| 442 | + public List<BcHeadWayInfo> getUpBcList() { | |
| 443 | + return upBcList; | |
| 444 | + } | |
| 445 | + | |
| 446 | + public void setUpBcList(List<BcHeadWayInfo> upBcList) { | |
| 447 | + this.upBcList = upBcList; | |
| 448 | + } | |
| 449 | + | |
| 450 | + public List<BcHeadWayInfo> getDownBcList() { | |
| 451 | + return downBcList; | |
| 452 | + } | |
| 453 | + | |
| 454 | + public void setDownBcList(List<BcHeadWayInfo> downBcList) { | |
| 455 | + this.downBcList = downBcList; | |
| 456 | + } | |
| 457 | + } | |
| 458 | + | |
| 403 | 459 | //---------------------- 生成时刻表用对象(以上) ---------------------// |
| 404 | 460 | |
| 405 | 461 | /** |
| ... | ... | @@ -409,4 +465,12 @@ public interface TTinfoDetailDynamicData { |
| 409 | 465 | * @throws ScheduleException |
| 410 | 466 | */ |
| 411 | 467 | DataToolsFile exportDynamicTTinfo(DTInfos dtInfos, DataToolsFileType type) throws ScheduleException; |
| 468 | + | |
| 469 | + /** | |
| 470 | + * 导出班次发车间隔信息。 | |
| 471 | + * @param lineHeadWayInfo | |
| 472 | + * @return | |
| 473 | + * @throws ScheduleException | |
| 474 | + */ | |
| 475 | + DataToolsFile exportHeadwayTTinfo(LineHeadWayInfo lineHeadWayInfo) throws ScheduleException; | |
| 412 | 476 | } | ... | ... |
src/main/java/com/bsth/service/schedule/impl/SchedulePlanServiceImpl.java
| ... | ... | @@ -8,18 +8,17 @@ import com.bsth.repository.LineRepository; |
| 8 | 8 | import com.bsth.repository.schedule.*; |
| 9 | 9 | import com.bsth.service.schedule.SchedulePlanService; |
| 10 | 10 | import com.bsth.service.schedule.exception.ScheduleException; |
| 11 | +import com.bsth.service.schedule.impl.plan.DroolsSchedulePlan; | |
| 12 | +import com.bsth.service.schedule.impl.plan.ScheduleRuleService; | |
| 11 | 13 | import com.bsth.service.schedule.impl.plan.kBase3.validate.rule.ValidateRuleResult; |
| 12 | 14 | import com.bsth.service.schedule.impl.plan.kBase3.validate.timetable.CalcuParam; |
| 13 | 15 | import com.bsth.service.schedule.impl.plan.kBase3.validate.timetable.Result; |
| 14 | -import com.bsth.service.schedule.impl.plan.DroolsSchedulePlan; | |
| 15 | -import com.bsth.service.schedule.impl.plan.ScheduleRuleService; | |
| 16 | 16 | import org.joda.time.DateTime; |
| 17 | 17 | import org.kie.api.KieBase; |
| 18 | 18 | import org.kie.api.runtime.KieSession; |
| 19 | 19 | import org.slf4j.Logger; |
| 20 | 20 | import org.slf4j.LoggerFactory; |
| 21 | 21 | import org.springframework.beans.factory.annotation.Autowired; |
| 22 | -import org.springframework.beans.factory.annotation.Qualifier; | |
| 23 | 22 | import org.springframework.stereotype.Service; |
| 24 | 23 | import org.springframework.transaction.annotation.Isolation; |
| 25 | 24 | import org.springframework.transaction.annotation.Propagation; |
| ... | ... | @@ -35,16 +34,16 @@ import java.util.concurrent.locks.ReentrantLock; |
| 35 | 34 | */ |
| 36 | 35 | @Service |
| 37 | 36 | public class SchedulePlanServiceImpl extends BServiceImpl<SchedulePlan, Long> implements SchedulePlanService { |
| 38 | - @Autowired | |
| 39 | - @Qualifier("coreKBase") | |
| 37 | +// @Autowired | |
| 38 | +// @Qualifier("coreKBase") | |
| 40 | 39 | private KieBase coreKBase; |
| 41 | 40 | |
| 42 | - @Autowired | |
| 43 | - @Qualifier("preKBase") | |
| 41 | +// @Autowired | |
| 42 | +// @Qualifier("preKBase") | |
| 44 | 43 | private KieBase preKBase; |
| 45 | 44 | |
| 46 | - @Autowired | |
| 47 | - @Qualifier("KBase3") | |
| 45 | +// @Autowired | |
| 46 | +// @Qualifier("KBase3") | |
| 48 | 47 | private KieBase validateKBase; |
| 49 | 48 | |
| 50 | 49 | @Autowired | ... | ... |
src/main/java/com/bsth/service/schedule/impl/TTInfoDetailServiceImpl.java
| ... | ... | @@ -145,6 +145,11 @@ public class TTInfoDetailServiceImpl extends BServiceImpl<TTInfoDetail, Long> im |
| 145 | 145 | } |
| 146 | 146 | |
| 147 | 147 | @Override |
| 148 | + public DataToolsFile exportHeadwayTTinfo(TTinfoDetailDynamicData.LineHeadWayInfo lineHeadWayInfo) throws ScheduleException { | |
| 149 | + return tTinfoDetailDynamicData.exportHeadwayTTinfo(lineHeadWayInfo); | |
| 150 | + } | |
| 151 | + | |
| 152 | + @Override | |
| 148 | 153 | public DataToolsFile exportDynamicTTinfo(TTinfoDetailDynamicData.DTInfos dtInfos, DataToolsFileType type) throws ScheduleException { |
| 149 | 154 | return tTinfoDetailDynamicData.exportDynamicTTinfo(dtInfos, type); |
| 150 | 155 | } | ... | ... |
src/main/java/com/bsth/service/schedule/impl/plan/MyDroolsConfiguration.java
| ... | ... | @@ -14,12 +14,11 @@ import org.kie.api.runtime.conf.ClockTypeOption; |
| 14 | 14 | import org.slf4j.Logger; |
| 15 | 15 | import org.slf4j.LoggerFactory; |
| 16 | 16 | import org.springframework.context.annotation.Bean; |
| 17 | -import org.springframework.context.annotation.Configuration; | |
| 18 | 17 | |
| 19 | 18 | /** |
| 20 | 19 | * Drools 6配置类。 |
| 21 | 20 | */ |
| 22 | -@Configuration | |
| 21 | +//@Configuration | |
| 23 | 22 | public class MyDroolsConfiguration { |
| 24 | 23 | /** 日志记录器 */ |
| 25 | 24 | private static final Logger logger = LoggerFactory.getLogger(MyDroolsConfiguration.class); | ... | ... |
src/main/resources/static/pages/base/timesmodel/gantt.html
src/main/resources/static/pages/base/timesmodel/js/gantt.js
src/main/resources/static/pages/base/timesmodel/js/v2_2/Main_v2_2_ExcelObj.js
| ... | ... | @@ -966,6 +966,76 @@ var Main_v2_2_ExcelObj = (function() { |
| 966 | 966 | return _celb.fnGenerateExcelLpBcList(); |
| 967 | 967 | }; |
| 968 | 968 | |
| 969 | + /** | |
| 970 | + * 获取班次发车间隔数据。 | |
| 971 | + * @return {*} | |
| 972 | + */ | |
| 973 | + InternalExcelObj.prototype.fnGetBcHeadWayInfoList = function() { | |
| 974 | + // 甘特图班次数据 | |
| 975 | + var aGanttBc = this._fnBc(); | |
| 976 | + | |
| 977 | + var i; | |
| 978 | + var oHeadWayBc = {}; | |
| 979 | + // 构造上行班次间隔数据,normal班次,时间排序 | |
| 980 | + var upBcList = []; | |
| 981 | + for (i = 0; i < aGanttBc.length; i++) { | |
| 982 | + oHeadWayBc = {}; | |
| 983 | + if (aGanttBc[i].xlDir == 'relationshipGraph-up' && aGanttBc[i].bcType == 'normal') { | |
| 984 | + oHeadWayBc.lpName = aGanttBc[i].lpName; // 路牌 | |
| 985 | + oHeadWayBc.fcsj = aGanttBc[i].fcsj; // 发车时间 | |
| 986 | + oHeadWayBc.fcsj_time = aGanttBc[i].fcsj_time; // 发车时间(毫秒) | |
| 987 | + upBcList.push(oHeadWayBc); | |
| 988 | + } | |
| 989 | + } | |
| 990 | + upBcList.sort(function(t1, t2) { | |
| 991 | + return t1.fcsj_time - t2.fcsj_time; | |
| 992 | + }); | |
| 993 | + // 计算发车间隔时间 | |
| 994 | + for (i = 0; i < upBcList.length; i++) { | |
| 995 | + if (i == 0) { | |
| 996 | + upBcList[i].headway = 0; | |
| 997 | + } else { | |
| 998 | + upBcList[i].headway = (upBcList[i].fcsj_time - upBcList[i - 1].fcsj_time) / 1000 / 60 | |
| 999 | + } | |
| 1000 | + } | |
| 1001 | + | |
| 1002 | + // 构造下行班次间隔数据,normal班次,时间排序 | |
| 1003 | + var downBcList = []; | |
| 1004 | + for (i = 0; i < aGanttBc.length; i++) { | |
| 1005 | + oHeadWayBc = {}; | |
| 1006 | + if (aGanttBc[i].xlDir == 'relationshipGraph-down' && aGanttBc[i].bcType == 'normal') { | |
| 1007 | + oHeadWayBc.lpName = aGanttBc[i].lpName; // 路牌 | |
| 1008 | + oHeadWayBc.fcsj = aGanttBc[i].fcsj; // 发车时间 | |
| 1009 | + oHeadWayBc.fcsj_time = aGanttBc[i].fcsj_time; // 发车时间(毫秒) | |
| 1010 | + downBcList.push(oHeadWayBc); | |
| 1011 | + } | |
| 1012 | + } | |
| 1013 | + downBcList.sort(function(t1, t2) { | |
| 1014 | + return t1.fcsj_time - t2.fcsj_time; | |
| 1015 | + }); | |
| 1016 | + // 计算发车间隔时间 | |
| 1017 | + for (i = 0; i < downBcList.length; i++) { | |
| 1018 | + if (i == 0) { | |
| 1019 | + downBcList[i].headway = 0; | |
| 1020 | + } else { | |
| 1021 | + downBcList[i].headway = (downBcList[i].fcsj_time - downBcList[i - 1].fcsj_time) / 1000 / 60 | |
| 1022 | + } | |
| 1023 | + } | |
| 1024 | + | |
| 1025 | + // 删除 fcsj_time 属性 | |
| 1026 | + for (i = 0; i < upBcList.length; i++) { | |
| 1027 | + delete upBcList[i].fcsj_time; | |
| 1028 | + } | |
| 1029 | + for (i = 0; i < downBcList.length; i++) { | |
| 1030 | + delete downBcList[i].fcsj_time; | |
| 1031 | + } | |
| 1032 | + | |
| 1033 | + return { | |
| 1034 | + upBcList : upBcList, | |
| 1035 | + downBcList : downBcList | |
| 1036 | + }; | |
| 1037 | + }; | |
| 1038 | + | |
| 969 | 1039 | return InternalExcelObj; |
| 970 | 1040 | |
| 971 | 1041 | } ()); |
| 972 | 1042 | \ No newline at end of file | ... | ... |
src/main/resources/static/pages/base/timesmodel/js/v2_2/main_v2_2.js
| ... | ... | @@ -69,6 +69,39 @@ var Main_v2_2 = function() { |
| 69 | 69 | |
| 70 | 70 | $('.exportAddXls').off('click'); |
| 71 | 71 | $('.exportAddXlsx').off('click'); |
| 72 | + $('.exportHeadWayXlsx').off('click'); | |
| 73 | + | |
| 74 | + $('.exportHeadWayXlsx').on('click', function() { | |
| 75 | + // TOD:获取发车间隔信息 | |
| 76 | + var lineHeadWayInfo = oExcel.fnGetBcHeadWayInfoList(); | |
| 77 | + | |
| 78 | + console.log(lineHeadWayInfo); | |
| 79 | + | |
| 80 | + $(".exportAdd").addClass("disabled"); | |
| 81 | + $(".exportAddSpan").html("正在导出..."); | |
| 82 | + | |
| 83 | + // 提交 | |
| 84 | + $.ajax({ | |
| 85 | + type: 'POST', | |
| 86 | + url: "/tidc/exportDTDFile2", | |
| 87 | + dataType: 'binary', | |
| 88 | + contentType: "application/json", | |
| 89 | + data: JSON.stringify(lineHeadWayInfo), | |
| 90 | + success: function(data){ | |
| 91 | + oExcel.downloadFile(data, "application/octet-stream", "时刻表发车间隔信息.xls"); | |
| 92 | + | |
| 93 | + $(".exportAdd").removeClass("disabled"); | |
| 94 | + $(".exportAddSpan").html(" 导出数据"); | |
| 95 | + }, | |
| 96 | + error: function(xhr, type){ | |
| 97 | + alert('错误:TODO'); | |
| 98 | + | |
| 99 | + $(".exportAdd").removeClass("disabled"); | |
| 100 | + $(".exportAddSpan").html(" 导出数据"); | |
| 101 | + } | |
| 102 | + }); | |
| 103 | + }); | |
| 104 | + | |
| 72 | 105 | |
| 73 | 106 | $('.exportAddXls').on('click', function() { |
| 74 | 107 | ... | ... |