Commit 834bbdb29ffc75322ed6d7344936f3b1dfe10a67
1 parent
c81af188
Update
Showing
8 changed files
with
298 additions
and
283 deletions
src/main/java/com/bsth/controller/schedule/core/TTInfoDetailController.java
| @@ -4,6 +4,7 @@ import com.bsth.common.ResponseCode; | @@ -4,6 +4,7 @@ import com.bsth.common.ResponseCode; | ||
| 4 | import com.bsth.controller.schedule.BController; | 4 | import com.bsth.controller.schedule.BController; |
| 5 | import com.bsth.entity.schedule.TTInfoDetail; | 5 | import com.bsth.entity.schedule.TTInfoDetail; |
| 6 | import com.bsth.service.schedule.TTInfoDetailService; | 6 | import com.bsth.service.schedule.TTInfoDetailService; |
| 7 | +import com.bsth.service.schedule.datatools.TTInfoDetailForEdit; | ||
| 7 | import org.springframework.beans.factory.annotation.Autowired; | 8 | import org.springframework.beans.factory.annotation.Autowired; |
| 8 | import org.springframework.web.bind.annotation.*; | 9 | import org.springframework.web.bind.annotation.*; |
| 9 | 10 | ||
| @@ -73,9 +74,13 @@ public class TTInfoDetailController extends BController<TTInfoDetail, Long> { | @@ -73,9 +74,13 @@ public class TTInfoDetailController extends BController<TTInfoDetail, Long> { | ||
| 73 | @RequestMapping(value = "/edit/{xlid}/{ttid}", method = RequestMethod.GET) | 74 | @RequestMapping(value = "/edit/{xlid}/{ttid}", method = RequestMethod.GET) |
| 74 | public Map<String, Object> getEditInfo(@PathVariable("xlid") Integer xlid, | 75 | public Map<String, Object> getEditInfo(@PathVariable("xlid") Integer xlid, |
| 75 | @PathVariable("ttid") Long ttid) { | 76 | @PathVariable("ttid") Long ttid) { |
| 77 | + | ||
| 78 | + // 获取最大的发车数,用于输出数据的数量 | ||
| 79 | + Long maxfcno = ttInfoDetailService.findMaxFcno(xlid, ttid); | ||
| 80 | + | ||
| 76 | Map<String, Object> rtn = new HashMap<>(); | 81 | Map<String, Object> rtn = new HashMap<>(); |
| 77 | try { | 82 | try { |
| 78 | - TTInfoDetailService.EditInfo editInfo = ttInfoDetailService.getEditInfo(xlid, ttid); | 83 | + TTInfoDetailForEdit.EditInfo editInfo = ttInfoDetailService.getEditInfo(xlid, ttid, maxfcno); |
| 79 | rtn.put("status", ResponseCode.SUCCESS); | 84 | rtn.put("status", ResponseCode.SUCCESS); |
| 80 | rtn.put("data", editInfo); | 85 | rtn.put("data", editInfo); |
| 81 | } catch (Exception exp) { | 86 | } catch (Exception exp) { |
src/main/java/com/bsth/service/schedule/TTInfoDetailService.java
| 1 | package com.bsth.service.schedule; | 1 | package com.bsth.service.schedule; |
| 2 | 2 | ||
| 3 | import com.bsth.entity.schedule.TTInfoDetail; | 3 | import com.bsth.entity.schedule.TTInfoDetail; |
| 4 | +import com.bsth.service.schedule.datatools.TTInfoDetailForEdit; | ||
| 4 | import com.bsth.service.schedule.exception.ScheduleException; | 5 | import com.bsth.service.schedule.exception.ScheduleException; |
| 5 | -import org.apache.commons.lang3.StringUtils; | ||
| 6 | 6 | ||
| 7 | -import java.util.ArrayList; | ||
| 8 | import java.util.List; | 7 | import java.util.List; |
| 9 | import java.util.Map; | 8 | import java.util.Map; |
| 10 | 9 | ||
| @@ -14,157 +13,21 @@ import java.util.Map; | @@ -14,157 +13,21 @@ import java.util.Map; | ||
| 14 | public interface TTInfoDetailService extends BService<TTInfoDetail, Long> { | 13 | public interface TTInfoDetailService extends BService<TTInfoDetail, Long> { |
| 15 | 14 | ||
| 16 | /** | 15 | /** |
| 17 | - * 发车信息内部类。 | ||
| 18 | - */ | ||
| 19 | - public static class FcInfo { | ||
| 20 | - /** 时刻明细id */ | ||
| 21 | - private Long ttdid; | ||
| 22 | - /** 发车时间 */ | ||
| 23 | - private String fcsj; | ||
| 24 | - /** 班次类型 */ | ||
| 25 | - private String bc_type; | ||
| 26 | - /** 线路上下行 */ | ||
| 27 | - private String xldir; | ||
| 28 | - /** 是偶分班 */ | ||
| 29 | - private Boolean isfb; | ||
| 30 | - | ||
| 31 | - /** 起点站code */ | ||
| 32 | - private String qdzCode; | ||
| 33 | - /** 终点站code */ | ||
| 34 | - private String zdzCode; | ||
| 35 | - | ||
| 36 | - public FcInfo() { | ||
| 37 | - } | ||
| 38 | - | ||
| 39 | - public FcInfo( | ||
| 40 | - String ttdid_str, | ||
| 41 | - String bc_type, | ||
| 42 | - String fcsj, | ||
| 43 | - String xldir, | ||
| 44 | - String isfb, | ||
| 45 | - String qdzCode, | ||
| 46 | - String zdzCode) { | ||
| 47 | - this.ttdid = StringUtils.isEmpty(ttdid_str) ? null : Long.valueOf(ttdid_str); | ||
| 48 | - this.bc_type = bc_type; | ||
| 49 | - this.fcsj = fcsj; | ||
| 50 | - this.xldir = xldir; | ||
| 51 | - if ("N".equals(isfb)) | ||
| 52 | - this.isfb = false; | ||
| 53 | - else if ("Y".equals(isfb) || "true".equals(isfb)) | ||
| 54 | - this.isfb = true; | ||
| 55 | - else | ||
| 56 | - this.isfb = false; | ||
| 57 | - | ||
| 58 | - if (StringUtils.isNotEmpty(qdzCode) && !"null".equals(qdzCode)) { | ||
| 59 | - this.qdzCode = qdzCode; | ||
| 60 | - } | ||
| 61 | - if (StringUtils.isNotEmpty(zdzCode) && !"null".equals(zdzCode)) { | ||
| 62 | - this.zdzCode = zdzCode; | ||
| 63 | - } | ||
| 64 | - | ||
| 65 | - } | ||
| 66 | - | ||
| 67 | - public Long getTtdid() { | ||
| 68 | - return ttdid; | ||
| 69 | - } | ||
| 70 | - | ||
| 71 | - public void setTtdid(Long ttdid) { | ||
| 72 | - this.ttdid = ttdid; | ||
| 73 | - } | ||
| 74 | - | ||
| 75 | - public String getFcsj() { | ||
| 76 | - return fcsj; | ||
| 77 | - } | ||
| 78 | - | ||
| 79 | - public void setFcsj(String fcsj) { | ||
| 80 | - this.fcsj = fcsj; | ||
| 81 | - } | ||
| 82 | - | ||
| 83 | - public String getBc_type() { | ||
| 84 | - return bc_type; | ||
| 85 | - } | ||
| 86 | - | ||
| 87 | - public void setBc_type(String bc_type) { | ||
| 88 | - this.bc_type = bc_type; | ||
| 89 | - } | ||
| 90 | - | ||
| 91 | - public String getXldir() { | ||
| 92 | - return xldir; | ||
| 93 | - } | ||
| 94 | - | ||
| 95 | - public void setXldir(String xldir) { | ||
| 96 | - this.xldir = xldir; | ||
| 97 | - } | ||
| 98 | - | ||
| 99 | - public Boolean getIsfb() { | ||
| 100 | - return isfb; | ||
| 101 | - } | ||
| 102 | - | ||
| 103 | - public void setIsfb(Boolean isfb) { | ||
| 104 | - this.isfb = isfb; | ||
| 105 | - } | ||
| 106 | - | ||
| 107 | - public String getQdzCode() { | ||
| 108 | - return qdzCode; | ||
| 109 | - } | ||
| 110 | - | ||
| 111 | - public void setQdzCode(String qdzCode) { | ||
| 112 | - this.qdzCode = qdzCode; | ||
| 113 | - } | ||
| 114 | - | ||
| 115 | - public String getZdzCode() { | ||
| 116 | - return zdzCode; | ||
| 117 | - } | ||
| 118 | - | ||
| 119 | - public void setZdzCode(String zdzCode) { | ||
| 120 | - this.zdzCode = zdzCode; | ||
| 121 | - } | ||
| 122 | - } | ||
| 123 | - | ||
| 124 | - /** | ||
| 125 | - * 时刻表编辑用的返回数据。 | 16 | + * 获取待编辑的数据。 |
| 17 | + * @param xlid 线路id | ||
| 18 | + * @param ttid 时刻表id | ||
| 19 | + * @param maxfcno 最大发车顺序号 | ||
| 20 | + * @return | ||
| 126 | */ | 21 | */ |
| 127 | - public static class EditInfo { | ||
| 128 | - /** 标题数据 */ | ||
| 129 | - private List<String> header = new ArrayList<>(); | ||
| 130 | - /** 内容数据 */ | ||
| 131 | - private List<List<FcInfo>> contents = new ArrayList<>(); | ||
| 132 | - | ||
| 133 | - /** 营运描述 */ | ||
| 134 | - private String yy_desc; | ||
| 135 | - | ||
| 136 | - public List<String> getHeader() { | ||
| 137 | - return header; | ||
| 138 | - } | ||
| 139 | - | ||
| 140 | - public void setHeader(List<String> header) { | ||
| 141 | - this.header = header; | ||
| 142 | - } | ||
| 143 | - | ||
| 144 | - public List<List<FcInfo>> getContents() { | ||
| 145 | - return contents; | ||
| 146 | - } | ||
| 147 | - | ||
| 148 | - public void setContents(List<List<FcInfo>> contents) { | ||
| 149 | - this.contents = contents; | ||
| 150 | - } | ||
| 151 | - | ||
| 152 | - public String getYy_desc() { | ||
| 153 | - return yy_desc; | ||
| 154 | - } | ||
| 155 | - | ||
| 156 | - public void setYy_desc(String yy_desc) { | ||
| 157 | - this.yy_desc = yy_desc; | ||
| 158 | - } | ||
| 159 | - } | 22 | + TTInfoDetailForEdit.EditInfo getEditInfo(Integer xlid, Long ttid, Long maxfcno) throws ScheduleException; |
| 160 | 23 | ||
| 161 | /** | 24 | /** |
| 162 | - * 获取待编辑的数据。 | 25 | + * 获取时刻表最大发车顺序号 |
| 163 | * @param xlid 线路id | 26 | * @param xlid 线路id |
| 164 | - * @param ttid 时刻表id | 27 | + * @param ttinfoid 时刻表id |
| 165 | * @return | 28 | * @return |
| 166 | */ | 29 | */ |
| 167 | - EditInfo getEditInfo(Integer xlid, Long ttid) throws ScheduleException; | 30 | + Long findMaxFcno(Integer xlid, Long ttinfoid); |
| 168 | 31 | ||
| 169 | /** | 32 | /** |
| 170 | * 验证sheet(以后放到规则引擎里去做)。 | 33 | * 验证sheet(以后放到规则引擎里去做)。 |
src/main/java/com/bsth/service/schedule/datatools/TTInfoDetailDataToolsImpl.java
| @@ -21,10 +21,7 @@ import org.springframework.stereotype.Service; | @@ -21,10 +21,7 @@ import org.springframework.stereotype.Service; | ||
| 21 | import java.io.File; | 21 | import java.io.File; |
| 22 | import java.io.PrintWriter; | 22 | import java.io.PrintWriter; |
| 23 | import java.io.StringWriter; | 23 | import java.io.StringWriter; |
| 24 | -import java.util.ArrayList; | ||
| 25 | -import java.util.HashMap; | ||
| 26 | -import java.util.List; | ||
| 27 | -import java.util.Map; | 24 | +import java.util.*; |
| 28 | 25 | ||
| 29 | /** | 26 | /** |
| 30 | * Created by xu on 17/5/16. | 27 | * Created by xu on 17/5/16. |
| @@ -206,8 +203,10 @@ public class TTInfoDetailDataToolsImpl implements DataToolsService, TTInfoDetail | @@ -206,8 +203,10 @@ public class TTInfoDetailDataToolsImpl implements DataToolsService, TTInfoDetail | ||
| 206 | } | 203 | } |
| 207 | 204 | ||
| 208 | @Override | 205 | @Override |
| 209 | - public File exportDataForEdit(Integer xlid, Long ttid) throws ScheduleException { | 206 | + public EditInfo getEditInfo(Integer xlid, Long ttid, Long maxfcno) throws ScheduleException { |
| 210 | try { | 207 | try { |
| 208 | + LOGGER.info("//---------------- 时刻表编辑用数据输出 start... ----------------//"); | ||
| 209 | + | ||
| 211 | // 创建ktr转换所需参数 | 210 | // 创建ktr转换所需参数 |
| 212 | Map<String, Object> ktrParms = new HashMap<>(); | 211 | Map<String, Object> ktrParms = new HashMap<>(); |
| 213 | File ktrFile = new File(this.getClass().getResource( | 212 | File ktrFile = new File(this.getClass().getResource( |
| @@ -225,9 +224,115 @@ public class TTInfoDetailDataToolsImpl implements DataToolsService, TTInfoDetail | @@ -225,9 +224,115 @@ public class TTInfoDetailDataToolsImpl implements DataToolsService, TTInfoDetail | ||
| 225 | ktrParms.put("xlid", String.valueOf(xlid)); | 224 | ktrParms.put("xlid", String.valueOf(xlid)); |
| 226 | ktrParms.put("ttid", String.valueOf(ttid)); | 225 | ktrParms.put("ttid", String.valueOf(ttid)); |
| 227 | 226 | ||
| 228 | - return dataToolsService.exportData(ktrParms); | 227 | + dataToolsService.exportData(ktrParms); |
| 228 | + | ||
| 229 | + EditInfo editInfo = new EditInfo(); // 输出数据 | ||
| 230 | + | ||
| 231 | + | ||
| 232 | + // 1.6、获取最大的发车数,用于输出数据的数量 | ||
| 233 | + LOGGER.info("最大发车顺序号={}", maxfcno); | ||
| 234 | + if (maxfcno != null) { | ||
| 235 | + // 2、读取ktr生成的excel数据,组织编辑用数据返回 | ||
| 236 | + // 2-1、读取Excel文件 | ||
| 237 | + Workbook book = Workbook.getWorkbook(new File(dataToolsProperties.getTransTempdir() + | ||
| 238 | + File.separator + outputFilePath + ".xls")); | ||
| 239 | + Sheet sheet = book.getSheet(0); | ||
| 240 | + | ||
| 241 | + // 2-2、处理数据 | ||
| 242 | + int all_bc_ks = 0; // 总空驶班次 | ||
| 243 | + int all_bc_yy = 0; // 总营运班次 | ||
| 244 | + double all_lc_ks = 0; // 总空驶里程 | ||
| 245 | + double all_lc_yy = 0; // 总营运里程 | ||
| 246 | + | ||
| 247 | + String[] headarrays = new String[maxfcno.intValue() + 3]; | ||
| 248 | + headarrays[0] = "路牌"; | ||
| 249 | + headarrays[maxfcno.intValue() + 1] = "空驶班次/空驶里程"; | ||
| 250 | + headarrays[maxfcno.intValue() + 2] = "运营班次/运营里程"; | ||
| 251 | + | ||
| 252 | + for (int r = 1; r < sheet.getRows(); r++) { | ||
| 253 | + List<FcInfo> fcInfos = new ArrayList<>(); | ||
| 254 | + // 每行第一列都是路牌 | ||
| 255 | + fcInfos.add(new FcInfo(null, null, sheet.getCell(0, r).getContents(), null, null, null, null)); // 用fcsj放置路牌显示 | ||
| 256 | + | ||
| 257 | + int bc_ks = 0; // 空驶班次 | ||
| 258 | + int bc_yy = 0; // 营运班次 | ||
| 259 | + double lc_ks = 0; // 空驶里程 | ||
| 260 | + double lc_yy = 0; // 营运里程 | ||
| 261 | + | ||
| 262 | + for (int c = 1; c <= maxfcno; c++) { | ||
| 263 | + String content_str = sheet.getCell(c, r).getContents(); | ||
| 264 | + try { | ||
| 265 | + String[] content = StringUtils.isEmpty(content_str) ? null : content_str.split(","); // 总的内容 | ||
| 266 | + | ||
| 267 | + String ttdid_str = content == null ? "" : content[0]; // 时刻表明细id | ||
| 268 | + String fcsj = content == null ? "" : content[1]; // 发车时间 | ||
| 269 | + String jhlc = content == null ? "" : content[2]; // 计划里程 | ||
| 270 | + String fzdname = content == null ? "" : content[3]; // 发车站点名称 | ||
| 271 | + String bctype = content == null ? "" : content[4]; // 班次类型 | ||
| 272 | + String xldir = content == null ? "" : content[5]; // 线路上下行 | ||
| 273 | + String isfb = content == null ? "" : content[6]; // 是否分班 | ||
| 274 | + | ||
| 275 | + String qdzCode = content == null ? "" : content[7]; // 起点站编码 | ||
| 276 | + String zdzCode = content == null ? "" : content[8]; // 终点站编码 | ||
| 277 | + | ||
| 278 | + FcInfo fcInfo = new FcInfo(ttdid_str, bctype, fcsj, xldir, isfb, qdzCode, zdzCode); | ||
| 279 | + | ||
| 280 | + if (StringUtils.isNotEmpty(fzdname)) | ||
| 281 | + headarrays[c] = fzdname; | ||
| 282 | + fcInfos.add(fcInfo); | ||
| 283 | + | ||
| 284 | + | ||
| 285 | + // 计算班次里程 | ||
| 286 | + if (StringUtils.isNotEmpty(jhlc)) { | ||
| 287 | + if ("in".equals(bctype) || "out".equals(bctype) || "ldks".equals(bctype)) { | ||
| 288 | + bc_ks += 1; | ||
| 289 | + lc_ks += Double.valueOf(jhlc); | ||
| 290 | + | ||
| 291 | + all_bc_ks += 1; | ||
| 292 | + all_lc_ks += Double.valueOf(jhlc); | ||
| 293 | + | ||
| 294 | + } else { | ||
| 295 | + bc_yy += 1; | ||
| 296 | + lc_yy += Double.valueOf(jhlc); | ||
| 297 | + | ||
| 298 | + all_bc_yy += 1; | ||
| 299 | + all_lc_yy += Double.valueOf(jhlc); | ||
| 300 | + } | ||
| 301 | + } | ||
| 302 | + | ||
| 303 | + } catch (Exception exp) { | ||
| 304 | + exp.printStackTrace(); | ||
| 305 | + LOGGER.info("第{}行,第{}列数据有问题,数据={},异常message={}", r, c, content_str, exp.getCause()); | ||
| 306 | + break; | ||
| 307 | + } | ||
| 308 | + | ||
| 309 | + } | ||
| 310 | + | ||
| 311 | + // 添加一列 空驶班次/空驶里程,fcsj放置数据 | ||
| 312 | + fcInfos.add(new FcInfo(null, null, String.format("%d/%.3f", bc_ks, lc_ks), null, null, null, null)); | ||
| 313 | + | ||
| 314 | + // 添加一列 营运班次/营运里程,fcsj放置数据 | ||
| 315 | + fcInfos.add(new FcInfo(null, null, String.format("%d/%.3f", bc_yy, lc_yy), null, null, null, null)); | ||
| 316 | + | ||
| 317 | + editInfo.getContents().add(fcInfos); | ||
| 318 | + } | ||
| 319 | + editInfo.getHeader().addAll(Arrays.asList(headarrays)); | ||
| 320 | + | ||
| 321 | + editInfo.setYy_desc(String.format("空驶班次=%d,营运班次=%d,空驶里程=%.3f,营运里程=%.3f,总里程=%.3f", all_bc_ks, all_bc_yy, all_lc_ks, all_lc_yy, all_lc_ks + all_lc_yy)); | ||
| 322 | + } | ||
| 323 | + | ||
| 324 | + LOGGER.info("//---------------- 时刻表编辑用数据输出 success... ----------------//"); | ||
| 325 | + | ||
| 326 | + return editInfo; | ||
| 229 | } catch (Exception exp) { | 327 | } catch (Exception exp) { |
| 230 | - throw new ScheduleException(exp); | 328 | + LOGGER.info("//---------------- 时刻表编辑用数据输出 failed... ----------------//"); |
| 329 | + | ||
| 330 | + StringWriter sw = new StringWriter(); | ||
| 331 | + exp.printStackTrace(new PrintWriter(sw)); | ||
| 332 | + LOGGER.info(sw.toString()); | ||
| 333 | + | ||
| 334 | + throw new ScheduleException(exp.getMessage()); | ||
| 231 | } | 335 | } |
| 232 | } | 336 | } |
| 337 | + | ||
| 233 | } | 338 | } |
src/main/java/com/bsth/service/schedule/datatools/TTInfoDetailForEdit.java
| 1 | package com.bsth.service.schedule.datatools; | 1 | package com.bsth.service.schedule.datatools; |
| 2 | 2 | ||
| 3 | import com.bsth.service.schedule.exception.ScheduleException; | 3 | import com.bsth.service.schedule.exception.ScheduleException; |
| 4 | +import org.apache.commons.lang3.StringUtils; | ||
| 4 | 5 | ||
| 5 | -import java.io.File; | 6 | +import java.util.ArrayList; |
| 7 | +import java.util.List; | ||
| 6 | 8 | ||
| 7 | /** | 9 | /** |
| 8 | * Created by xu on 17/5/16. | 10 | * Created by xu on 17/5/16. |
| 9 | */ | 11 | */ |
| 10 | public interface TTInfoDetailForEdit { | 12 | public interface TTInfoDetailForEdit { |
| 11 | - File exportDataForEdit(Integer xlid, Long ttid) throws ScheduleException; | 13 | + /** |
| 14 | + * 发车信息内部类。 | ||
| 15 | + */ | ||
| 16 | + public static class FcInfo { | ||
| 17 | + /** 时刻明细id */ | ||
| 18 | + private Long ttdid; | ||
| 19 | + /** 发车时间 */ | ||
| 20 | + private String fcsj; | ||
| 21 | + /** 班次类型 */ | ||
| 22 | + private String bc_type; | ||
| 23 | + /** 线路上下行 */ | ||
| 24 | + private String xldir; | ||
| 25 | + /** 是偶分班 */ | ||
| 26 | + private Boolean isfb; | ||
| 27 | + | ||
| 28 | + /** 起点站code */ | ||
| 29 | + private String qdzCode; | ||
| 30 | + /** 终点站code */ | ||
| 31 | + private String zdzCode; | ||
| 32 | + | ||
| 33 | + public FcInfo() { | ||
| 34 | + } | ||
| 35 | + | ||
| 36 | + public FcInfo( | ||
| 37 | + String ttdid_str, | ||
| 38 | + String bc_type, | ||
| 39 | + String fcsj, | ||
| 40 | + String xldir, | ||
| 41 | + String isfb, | ||
| 42 | + String qdzCode, | ||
| 43 | + String zdzCode) { | ||
| 44 | + this.ttdid = StringUtils.isEmpty(ttdid_str) ? null : Long.valueOf(ttdid_str); | ||
| 45 | + this.bc_type = bc_type; | ||
| 46 | + this.fcsj = fcsj; | ||
| 47 | + this.xldir = xldir; | ||
| 48 | + if ("N".equals(isfb)) | ||
| 49 | + this.isfb = false; | ||
| 50 | + else if ("Y".equals(isfb) || "true".equals(isfb)) | ||
| 51 | + this.isfb = true; | ||
| 52 | + else | ||
| 53 | + this.isfb = false; | ||
| 54 | + | ||
| 55 | + if (StringUtils.isNotEmpty(qdzCode) && !"null".equals(qdzCode)) { | ||
| 56 | + this.qdzCode = qdzCode; | ||
| 57 | + } | ||
| 58 | + if (StringUtils.isNotEmpty(zdzCode) && !"null".equals(zdzCode)) { | ||
| 59 | + this.zdzCode = zdzCode; | ||
| 60 | + } | ||
| 61 | + | ||
| 62 | + } | ||
| 63 | + | ||
| 64 | + public Long getTtdid() { | ||
| 65 | + return ttdid; | ||
| 66 | + } | ||
| 67 | + | ||
| 68 | + public void setTtdid(Long ttdid) { | ||
| 69 | + this.ttdid = ttdid; | ||
| 70 | + } | ||
| 71 | + | ||
| 72 | + public String getFcsj() { | ||
| 73 | + return fcsj; | ||
| 74 | + } | ||
| 75 | + | ||
| 76 | + public void setFcsj(String fcsj) { | ||
| 77 | + this.fcsj = fcsj; | ||
| 78 | + } | ||
| 79 | + | ||
| 80 | + public String getBc_type() { | ||
| 81 | + return bc_type; | ||
| 82 | + } | ||
| 83 | + | ||
| 84 | + public void setBc_type(String bc_type) { | ||
| 85 | + this.bc_type = bc_type; | ||
| 86 | + } | ||
| 87 | + | ||
| 88 | + public String getXldir() { | ||
| 89 | + return xldir; | ||
| 90 | + } | ||
| 91 | + | ||
| 92 | + public void setXldir(String xldir) { | ||
| 93 | + this.xldir = xldir; | ||
| 94 | + } | ||
| 95 | + | ||
| 96 | + public Boolean getIsfb() { | ||
| 97 | + return isfb; | ||
| 98 | + } | ||
| 99 | + | ||
| 100 | + public void setIsfb(Boolean isfb) { | ||
| 101 | + this.isfb = isfb; | ||
| 102 | + } | ||
| 103 | + | ||
| 104 | + public String getQdzCode() { | ||
| 105 | + return qdzCode; | ||
| 106 | + } | ||
| 107 | + | ||
| 108 | + public void setQdzCode(String qdzCode) { | ||
| 109 | + this.qdzCode = qdzCode; | ||
| 110 | + } | ||
| 111 | + | ||
| 112 | + public String getZdzCode() { | ||
| 113 | + return zdzCode; | ||
| 114 | + } | ||
| 115 | + | ||
| 116 | + public void setZdzCode(String zdzCode) { | ||
| 117 | + this.zdzCode = zdzCode; | ||
| 118 | + } | ||
| 119 | + } | ||
| 120 | + | ||
| 121 | + /** | ||
| 122 | + * 时刻表编辑用的返回数据。 | ||
| 123 | + */ | ||
| 124 | + public static class EditInfo { | ||
| 125 | + /** 标题数据 */ | ||
| 126 | + private List<String> header = new ArrayList<>(); | ||
| 127 | + /** 内容数据 */ | ||
| 128 | + private List<List<FcInfo>> contents = new ArrayList<>(); | ||
| 129 | + | ||
| 130 | + /** 营运描述 */ | ||
| 131 | + private String yy_desc; | ||
| 132 | + | ||
| 133 | + public List<String> getHeader() { | ||
| 134 | + return header; | ||
| 135 | + } | ||
| 136 | + | ||
| 137 | + public void setHeader(List<String> header) { | ||
| 138 | + this.header = header; | ||
| 139 | + } | ||
| 140 | + | ||
| 141 | + public List<List<FcInfo>> getContents() { | ||
| 142 | + return contents; | ||
| 143 | + } | ||
| 144 | + | ||
| 145 | + public void setContents(List<List<FcInfo>> contents) { | ||
| 146 | + this.contents = contents; | ||
| 147 | + } | ||
| 148 | + | ||
| 149 | + public String getYy_desc() { | ||
| 150 | + return yy_desc; | ||
| 151 | + } | ||
| 152 | + | ||
| 153 | + public void setYy_desc(String yy_desc) { | ||
| 154 | + this.yy_desc = yy_desc; | ||
| 155 | + } | ||
| 156 | + } | ||
| 157 | + | ||
| 158 | + /** | ||
| 159 | + * 获取待编辑的数据。 | ||
| 160 | + * @param xlid 线路id | ||
| 161 | + * @param ttid 时刻表id | ||
| 162 | + * @param maxfcno 最大发车顺序号 | ||
| 163 | + * @return | ||
| 164 | + */ | ||
| 165 | + EditInfo getEditInfo(Integer xlid, Long ttid, Long maxfcno) throws ScheduleException; | ||
| 166 | + | ||
| 12 | } | 167 | } |
src/main/java/com/bsth/service/schedule/impl/TTInfoDetailServiceImpl.java
| @@ -69,8 +69,6 @@ public class TTInfoDetailServiceImpl extends BServiceImpl<TTInfoDetail, Long> im | @@ -69,8 +69,6 @@ public class TTInfoDetailServiceImpl extends BServiceImpl<TTInfoDetail, Long> im | ||
| 69 | @Autowired | 69 | @Autowired |
| 70 | private TTInfoDetailRepository ttInfoDetailRepository; | 70 | private TTInfoDetailRepository ttInfoDetailRepository; |
| 71 | @Autowired | 71 | @Autowired |
| 72 | - private DataToolsProperties dataToolsProperties; | ||
| 73 | - @Autowired | ||
| 74 | private LineRepository lineRepository; | 72 | private LineRepository lineRepository; |
| 75 | @Autowired | 73 | @Autowired |
| 76 | private TTInfoRepository infoRepository; | 74 | private TTInfoRepository infoRepository; |
| @@ -114,6 +112,11 @@ public class TTInfoDetailServiceImpl extends BServiceImpl<TTInfoDetail, Long> im | @@ -114,6 +112,11 @@ public class TTInfoDetailServiceImpl extends BServiceImpl<TTInfoDetail, Long> im | ||
| 114 | } | 112 | } |
| 115 | 113 | ||
| 116 | @Override | 114 | @Override |
| 115 | + public Long findMaxFcno(Integer xlid, Long ttinfoid) { | ||
| 116 | + return ttInfoDetailRepository.findMaxFcno(xlid, ttinfoid); | ||
| 117 | + } | ||
| 118 | + | ||
| 119 | + @Override | ||
| 117 | public TTInfoDetail findById(Long aLong) { | 120 | public TTInfoDetail findById(Long aLong) { |
| 118 | return ttInfoDetailRepository.findOneExtend(aLong); | 121 | return ttInfoDetailRepository.findOneExtend(aLong); |
| 119 | } | 122 | } |
| @@ -135,128 +138,12 @@ public class TTInfoDetailServiceImpl extends BServiceImpl<TTInfoDetail, Long> im | @@ -135,128 +138,12 @@ public class TTInfoDetailServiceImpl extends BServiceImpl<TTInfoDetail, Long> im | ||
| 135 | return dataToolsService.exportData(params); | 138 | return dataToolsService.exportData(params); |
| 136 | } | 139 | } |
| 137 | 140 | ||
| 138 | - @Override | ||
| 139 | - public TTInfoDetailService.EditInfo getEditInfo(Integer xlid, Long ttid) throws ScheduleException { | ||
| 140 | - try { | ||
| 141 | - LOGGER.info("//---------------- 时刻表编辑用数据输出 start... ----------------//"); | ||
| 142 | - | ||
| 143 | - // 附加参数 | ||
| 144 | - String outputFilePath = String.format("ttinfodetail_(id=%s)_foredit-%s", | ||
| 145 | - String.valueOf(ttid), new DateTime().toString("yyyyMMddHHmmss")); | ||
| 146 | - | ||
| 147 | - ttInfoDetailForEdit.exportDataForEdit(xlid, ttid); | ||
| 148 | - | ||
| 149 | - TTInfoDetailService.EditInfo editInfo = new TTInfoDetailService.EditInfo(); // 输出数据 | ||
| 150 | - | ||
| 151 | - // 1.6、获取最大的发车数,用于输出数据的数量 | ||
| 152 | - Long maxfcno = ttInfoDetailRepository.findMaxFcno(xlid, ttid); | ||
| 153 | - LOGGER.info("最大发车顺序号={}", maxfcno); | ||
| 154 | - if (maxfcno != null) { | ||
| 155 | - // 2、读取ktr生成的excel数据,组织编辑用数据返回 | ||
| 156 | - // 2-1、读取Excel文件 | ||
| 157 | - Workbook book = Workbook.getWorkbook(new File(dataToolsProperties.getTransTempdir() + | ||
| 158 | - File.separator + outputFilePath + ".xls")); | ||
| 159 | - Sheet sheet = book.getSheet(0); | ||
| 160 | - | ||
| 161 | - // 2-2、处理数据 | ||
| 162 | - int all_bc_ks = 0; // 总空驶班次 | ||
| 163 | - int all_bc_yy = 0; // 总营运班次 | ||
| 164 | - double all_lc_ks = 0; // 总空驶里程 | ||
| 165 | - double all_lc_yy = 0; // 总营运里程 | ||
| 166 | - | ||
| 167 | - String[] headarrays = new String[maxfcno.intValue() + 3]; | ||
| 168 | - headarrays[0] = "路牌"; | ||
| 169 | - headarrays[maxfcno.intValue() + 1] = "空驶班次/空驶里程"; | ||
| 170 | - headarrays[maxfcno.intValue() + 2] = "运营班次/运营里程"; | ||
| 171 | - | ||
| 172 | - for (int r = 1; r < sheet.getRows(); r++) { | ||
| 173 | - List<TTInfoDetailService.FcInfo> fcInfos = new ArrayList<>(); | ||
| 174 | - // 每行第一列都是路牌 | ||
| 175 | - fcInfos.add(new TTInfoDetailService.FcInfo(null, null, sheet.getCell(0, r).getContents(), null, null, null, null)); // 用fcsj放置路牌显示 | ||
| 176 | - | ||
| 177 | - int bc_ks = 0; // 空驶班次 | ||
| 178 | - int bc_yy = 0; // 营运班次 | ||
| 179 | - double lc_ks = 0; // 空驶里程 | ||
| 180 | - double lc_yy = 0; // 营运里程 | ||
| 181 | - | ||
| 182 | - for (int c = 1; c <= maxfcno; c++) { | ||
| 183 | - String content_str = sheet.getCell(c, r).getContents(); | ||
| 184 | - try { | ||
| 185 | - String[] content = StringUtils.isEmpty(content_str) ? null : content_str.split(","); // 总的内容 | ||
| 186 | - | ||
| 187 | - String ttdid_str = content == null ? "" : content[0]; // 时刻表明细id | ||
| 188 | - String fcsj = content == null ? "" : content[1]; // 发车时间 | ||
| 189 | - String jhlc = content == null ? "" : content[2]; // 计划里程 | ||
| 190 | - String fzdname = content == null ? "" : content[3]; // 发车站点名称 | ||
| 191 | - String bctype = content == null ? "" : content[4]; // 班次类型 | ||
| 192 | - String xldir = content == null ? "" : content[5]; // 线路上下行 | ||
| 193 | - String isfb = content == null ? "" : content[6]; // 是否分班 | ||
| 194 | - | ||
| 195 | - String qdzCode = content == null ? "" : content[7]; // 起点站编码 | ||
| 196 | - String zdzCode = content == null ? "" : content[8]; // 终点站编码 | ||
| 197 | - | ||
| 198 | - TTInfoDetailService.FcInfo fcInfo = new TTInfoDetailService.FcInfo(ttdid_str, bctype, fcsj, xldir, isfb, qdzCode, zdzCode); | ||
| 199 | - | ||
| 200 | - if (StringUtils.isNotEmpty(fzdname)) | ||
| 201 | - headarrays[c] = fzdname; | ||
| 202 | - fcInfos.add(fcInfo); | ||
| 203 | - | ||
| 204 | - | ||
| 205 | - // 计算班次里程 | ||
| 206 | - if (StringUtils.isNotEmpty(jhlc)) { | ||
| 207 | - if ("in".equals(bctype) || "out".equals(bctype) || "ldks".equals(bctype)) { | ||
| 208 | - bc_ks += 1; | ||
| 209 | - lc_ks += Double.valueOf(jhlc); | ||
| 210 | - | ||
| 211 | - all_bc_ks += 1; | ||
| 212 | - all_lc_ks += Double.valueOf(jhlc); | ||
| 213 | - | ||
| 214 | - } else { | ||
| 215 | - bc_yy += 1; | ||
| 216 | - lc_yy += Double.valueOf(jhlc); | ||
| 217 | - | ||
| 218 | - all_bc_yy += 1; | ||
| 219 | - all_lc_yy += Double.valueOf(jhlc); | ||
| 220 | - } | ||
| 221 | - } | ||
| 222 | - | ||
| 223 | - } catch (Exception exp) { | ||
| 224 | - exp.printStackTrace(); | ||
| 225 | - LOGGER.info("第{}行,第{}列数据有问题,数据={},异常message={}", r, c, content_str, exp.getCause()); | ||
| 226 | - break; | ||
| 227 | - } | ||
| 228 | - | ||
| 229 | - } | ||
| 230 | - | ||
| 231 | - // 添加一列 空驶班次/空驶里程,fcsj放置数据 | ||
| 232 | - fcInfos.add(new TTInfoDetailService.FcInfo(null, null, String.format("%d/%.3f", bc_ks, lc_ks), null, null, null, null)); | ||
| 233 | - | ||
| 234 | - // 添加一列 营运班次/营运里程,fcsj放置数据 | ||
| 235 | - fcInfos.add(new TTInfoDetailService.FcInfo(null, null, String.format("%d/%.3f", bc_yy, lc_yy), null, null, null, null)); | ||
| 236 | 141 | ||
| 237 | - editInfo.getContents().add(fcInfos); | ||
| 238 | - } | ||
| 239 | - editInfo.getHeader().addAll(Arrays.asList(headarrays)); | ||
| 240 | - | ||
| 241 | - editInfo.setYy_desc(String.format("空驶班次=%d,营运班次=%d,空驶里程=%.3f,营运里程=%.3f,总里程=%.3f", all_bc_ks, all_bc_yy, all_lc_ks, all_lc_yy, all_lc_ks + all_lc_yy)); | ||
| 242 | - } | ||
| 243 | - | ||
| 244 | - LOGGER.info("//---------------- 时刻表编辑用数据输出 success... ----------------//"); | ||
| 245 | - | ||
| 246 | - return editInfo; | ||
| 247 | - } catch (Exception exp) { | ||
| 248 | - LOGGER.info("//---------------- 时刻表编辑用数据输出 failed... ----------------//"); | ||
| 249 | - | ||
| 250 | - StringWriter sw = new StringWriter(); | ||
| 251 | - exp.printStackTrace(new PrintWriter(sw)); | ||
| 252 | - LOGGER.info(sw.toString()); | ||
| 253 | - | ||
| 254 | - throw new ScheduleException(exp.getMessage()); | ||
| 255 | - } | 142 | + @Override |
| 143 | + public TTInfoDetailForEdit.EditInfo getEditInfo(Integer xlid, Long ttid, Long maxfcno) throws ScheduleException { | ||
| 144 | + return ttInfoDetailForEdit.getEditInfo(xlid, ttid, maxfcno); | ||
| 256 | } | 145 | } |
| 257 | 146 | ||
| 258 | - | ||
| 259 | - | ||
| 260 | @Override | 147 | @Override |
| 261 | public void validateExcelSheet(String filename, String sheetname, Integer lineid, String linename) throws ScheduleException { | 148 | public void validateExcelSheet(String filename, String sheetname, Integer lineid, String linename) throws ScheduleException { |
| 262 | try { | 149 | try { |
src/main/java/com/bsth/service/schedule/utils/DataToolsServiceImpl.java
| @@ -125,7 +125,7 @@ public class DataToolsServiceImpl implements DataToolsService { | @@ -125,7 +125,7 @@ public class DataToolsServiceImpl implements DataToolsService { | ||
| 125 | exp.printStackTrace(new PrintWriter(sw)); | 125 | exp.printStackTrace(new PrintWriter(sw)); |
| 126 | LOGGER.info(sw.toString()); | 126 | LOGGER.info(sw.toString()); |
| 127 | 127 | ||
| 128 | - throw new ScheduleException("上传文件错误!"); | 128 | + throw new ScheduleException(exp); |
| 129 | } | 129 | } |
| 130 | } | 130 | } |
| 131 | 131 | ||
| @@ -184,7 +184,7 @@ public class DataToolsServiceImpl implements DataToolsService { | @@ -184,7 +184,7 @@ public class DataToolsServiceImpl implements DataToolsService { | ||
| 184 | exp.printStackTrace(new PrintWriter(sw)); | 184 | exp.printStackTrace(new PrintWriter(sw)); |
| 185 | LOGGER.info(sw.toString()); | 185 | LOGGER.info(sw.toString()); |
| 186 | 186 | ||
| 187 | - throw new ScheduleException("导入数据错误!"); | 187 | + throw new ScheduleException(exp); |
| 188 | } finally { | 188 | } finally { |
| 189 | // 清除日志操作 | 189 | // 清除日志操作 |
| 190 | KettleLogStore.discardLines(transLogId, true); | 190 | KettleLogStore.discardLines(transLogId, true); |
| @@ -259,7 +259,7 @@ public class DataToolsServiceImpl implements DataToolsService { | @@ -259,7 +259,7 @@ public class DataToolsServiceImpl implements DataToolsService { | ||
| 259 | exp.printStackTrace(new PrintWriter(sw)); | 259 | exp.printStackTrace(new PrintWriter(sw)); |
| 260 | LOGGER.info(sw.toString()); | 260 | LOGGER.info(sw.toString()); |
| 261 | 261 | ||
| 262 | - throw new ScheduleException("导出数据错误!"); | 262 | + throw new ScheduleException(exp); |
| 263 | } finally { | 263 | } finally { |
| 264 | // 清除日志操作 | 264 | // 清除日志操作 |
| 265 | KettleLogStore.discardLines(transLogId, true); | 265 | KettleLogStore.discardLines(transLogId, true); |
src/main/resources/application-dev.properties
| @@ -6,7 +6,7 @@ spring.jpa.hibernate.ddl-auto= update | @@ -6,7 +6,7 @@ spring.jpa.hibernate.ddl-auto= update | ||
| 6 | spring.jpa.hibernate.naming_strategy= org.hibernate.cfg.ImprovedNamingStrategy | 6 | spring.jpa.hibernate.naming_strategy= org.hibernate.cfg.ImprovedNamingStrategy |
| 7 | #DATABASE | 7 | #DATABASE |
| 8 | spring.jpa.database= MYSQL | 8 | spring.jpa.database= MYSQL |
| 9 | -spring.jpa.show-sql= true | 9 | +spring.jpa.show-sql= false |
| 10 | spring.datasource.driver-class-name= com.mysql.jdbc.Driver | 10 | spring.datasource.driver-class-name= com.mysql.jdbc.Driver |
| 11 | spring.datasource.url= jdbc:mysql://127.0.0.1/control?useUnicode=true&characterEncoding=utf-8&useSSL=false | 11 | spring.datasource.url= jdbc:mysql://127.0.0.1/control?useUnicode=true&characterEncoding=utf-8&useSSL=false |
| 12 | spring.datasource.username= root | 12 | spring.datasource.username= root |
src/test/resources/testdata/problem.properties
| @@ -20,7 +20,7 @@ | @@ -20,7 +20,7 @@ | ||
| 20 | 20=排班规则备注 | 20 | 20=排班规则备注 |
| 21 | ##21=时刻表,两点间空驶,算空驶 | 21 | ##21=时刻表,两点间空驶,算空驶 |
| 22 | 22=搭班编码自动生成 | 22 | 22=搭班编码自动生成 |
| 23 | -23=时刻表明细修改终点站停驶(停止1个半小时以上) | 23 | +##23=时刻表明细修改终点站停驶(停止1个半小时以上) |
| 24 | ##24=线路标准里如果里程是0,用标准里程 | 24 | ##24=线路标准里如果里程是0,用标准里程 |
| 25 | ##25=规则导出的日期格式修正 | 25 | ##25=规则导出的日期格式修正 |
| 26 | ##26=人员录入,工号规则前加 "{公司编码}-" | 26 | ##26=人员录入,工号规则前加 "{公司编码}-" |