Commit 1a88dad558560c8cf24895fd6f15b00f5bfcf9fa
Merge branch 'minhang' into qingpu
Showing
64 changed files
with
1483 additions
and
894 deletions
Too many changes to show.
To preserve performance only 64 of 95 files are displayed.
pom.xml
| ... | ... | @@ -155,6 +155,12 @@ |
| 155 | 155 | <version>2.1.8</version> |
| 156 | 156 | </dependency> |
| 157 | 157 | |
| 158 | + <dependency> | |
| 159 | + <groupId>org.apache.tika</groupId> | |
| 160 | + <artifactId>tika-core</artifactId> | |
| 161 | + <version>1.7</version> | |
| 162 | + </dependency> | |
| 163 | + | |
| 158 | 164 | <!-- pentaho kettle 依赖 --> |
| 159 | 165 | <dependency> |
| 160 | 166 | <groupId>com.pentaho.kettle</groupId> | ... | ... |
src/main/java/com/bsth/controller/DownloadController.java
| ... | ... | @@ -2,6 +2,7 @@ package com.bsth.controller; |
| 2 | 2 | |
| 3 | 3 | import java.io.File; |
| 4 | 4 | import java.io.IOException; |
| 5 | +import java.net.URLDecoder; | |
| 5 | 6 | |
| 6 | 7 | import org.apache.commons.io.FileUtils; |
| 7 | 8 | import org.springframework.context.annotation.Scope; |
| ... | ... | @@ -35,7 +36,7 @@ public class DownloadController |
| 35 | 36 | File file=new File(moudelPath); |
| 36 | 37 | HttpHeaders headers = new HttpHeaders(); |
| 37 | 38 | String realFileName=new String(fileName.getBytes("UTF-8"),"iso-8859-1");//为了解决中文名称乱码问题 |
| 38 | - headers.setContentDispositionFormData("attachment", realFileName); | |
| 39 | + headers.setContentDispositionFormData("attachment", URLDecoder.decode(realFileName,"utf-8")); | |
| 39 | 40 | headers.setContentType(MediaType.APPLICATION_OCTET_STREAM); |
| 40 | 41 | return new ResponseEntity<byte[]>(FileUtils.readFileToByteArray(file), |
| 41 | 42 | headers, HttpStatus.CREATED); | ... | ... |
src/main/java/com/bsth/controller/realcontrol/RealMapController.java
| ... | ... | @@ -59,4 +59,14 @@ public class RealMapController { |
| 59 | 59 | public Map<String, Object> findRouteAndStationByLine(@RequestParam String lineCode){ |
| 60 | 60 | return realMapService.findRouteAndStationByLine(lineCode); |
| 61 | 61 | } |
| 62 | + | |
| 63 | + /** | |
| 64 | + * 获取多个线路的路段信息(为前端越界计算提供数据) | |
| 65 | + * @param codeIdx | |
| 66 | + * @return | |
| 67 | + */ | |
| 68 | + @RequestMapping(value = "/multiSectionRoute") | |
| 69 | + public Map<String, Object> multiSectionRoute(@RequestParam String codeIdx){ | |
| 70 | + return realMapService.multiSectionRoute(codeIdx); | |
| 71 | + } | |
| 62 | 72 | } | ... | ... |
src/main/java/com/bsth/controller/realcontrol/ScheduleRealInfoController.java
| ... | ... | @@ -338,8 +338,8 @@ public class ScheduleRealInfoController extends BaseController<ScheduleRealInfo, |
| 338 | 338 | |
| 339 | 339 | @RequestMapping(value = "/correctForm") |
| 340 | 340 | public List<ScheduleRealInfo> correctForm(@RequestParam String line, @RequestParam String startDate, |
| 341 | - @RequestParam String endDate,@RequestParam String lpName,@RequestParam String code) { | |
| 342 | - return scheduleRealInfoService.correctForm(line, startDate, endDate, lpName, code); | |
| 341 | + @RequestParam String endDate, @RequestParam String lpName, @RequestParam String code, @RequestParam String type) { | |
| 342 | + return scheduleRealInfoService.correctForm(line, startDate, endDate, lpName, code, type); | |
| 343 | 343 | } |
| 344 | 344 | /** |
| 345 | 345 | * @Title queryListWaybill | ... | ... |
src/main/java/com/bsth/controller/schedule/BController.java
| ... | ... | @@ -5,16 +5,21 @@ import com.bsth.common.ResponseCode; |
| 5 | 5 | import com.bsth.entity.schedule.BEntity; |
| 6 | 6 | import com.bsth.entity.sys.SysUser; |
| 7 | 7 | import com.bsth.service.schedule.BService; |
| 8 | -import com.bsth.service.schedule.ScheduleException; | |
| 8 | +import com.bsth.service.schedule.exception.ScheduleException; | |
| 9 | 9 | import com.bsth.service.sys.SysUserService; |
| 10 | 10 | import com.google.common.base.Splitter; |
| 11 | +import jxl.Sheet; | |
| 12 | +import jxl.Workbook; | |
| 13 | +import org.apache.commons.lang3.StringUtils; | |
| 11 | 14 | import org.springframework.beans.factory.annotation.Autowired; |
| 12 | 15 | import org.springframework.data.domain.PageRequest; |
| 13 | 16 | import org.springframework.data.domain.Sort; |
| 14 | 17 | import org.springframework.web.bind.annotation.*; |
| 18 | +import org.springframework.web.multipart.MultipartFile; | |
| 15 | 19 | |
| 20 | +import javax.servlet.http.HttpServletResponse; | |
| 16 | 21 | import javax.servlet.http.HttpSession; |
| 17 | -import java.io.Serializable; | |
| 22 | +import java.io.*; | |
| 18 | 23 | import java.util.*; |
| 19 | 24 | |
| 20 | 25 | /** |
| ... | ... | @@ -26,7 +31,7 @@ public class BController<T, ID extends Serializable> { |
| 26 | 31 | @Autowired |
| 27 | 32 | private SysUserService sysUserService; |
| 28 | 33 | |
| 29 | - // CRUD 操作 | |
| 34 | + //---------------- CRUD 操作 ----------------// | |
| 30 | 35 | // Create操作 |
| 31 | 36 | @RequestMapping(method = RequestMethod.POST) |
| 32 | 37 | public Map<String, Object> save(@RequestBody T t, HttpSession httpSession) { |
| ... | ... | @@ -73,6 +78,7 @@ public class BController<T, ID extends Serializable> { |
| 73 | 78 | rtn.put("data", t); |
| 74 | 79 | return rtn; |
| 75 | 80 | } |
| 81 | + // 查询所有操作 | |
| 76 | 82 | @RequestMapping(value = "/all", method = RequestMethod.GET) |
| 77 | 83 | public Map<String, Object> list(@RequestParam Map<String, Object> param) { |
| 78 | 84 | List<T> tList = bService.list(param); |
| ... | ... | @@ -81,6 +87,7 @@ public class BController<T, ID extends Serializable> { |
| 81 | 87 | rtn.put("data", tList); |
| 82 | 88 | return rtn; |
| 83 | 89 | } |
| 90 | + // 分页查询操作 | |
| 84 | 91 | @RequestMapping(method = RequestMethod.GET) |
| 85 | 92 | public Map<String, Object> list( |
| 86 | 93 | @RequestParam Map<String, Object> map, |
| ... | ... | @@ -138,4 +145,99 @@ public class BController<T, ID extends Serializable> { |
| 138 | 145 | return rtn; |
| 139 | 146 | } |
| 140 | 147 | |
| 148 | + //---------------- 数据服务操作 ----------------// | |
| 149 | + // 上传excel文件 | |
| 150 | + @RequestMapping(value = "/uploadFile", method = RequestMethod.POST) | |
| 151 | + public Map<String, Object> uploadFile(MultipartFile file) { | |
| 152 | + Map<String, Object> rtn = new HashMap<>(); | |
| 153 | + try { | |
| 154 | + File file1 = bService.uploadFile(file.getOriginalFilename(), file.getBytes()); | |
| 155 | + // excel文件名 | |
| 156 | + String fileName = file1.getAbsolutePath(); | |
| 157 | + // excel文件sheet | |
| 158 | + List<String> sheetnames = new ArrayList<>(); | |
| 159 | + Workbook book = Workbook.getWorkbook(file1); | |
| 160 | + for (Sheet sheet : book.getSheets()) { | |
| 161 | + sheetnames.add(sheet.getName()); | |
| 162 | + } | |
| 163 | + | |
| 164 | + rtn.put("status", ResponseCode.SUCCESS); | |
| 165 | + rtn.put("filename", fileName); | |
| 166 | + rtn.put("sheetnames", StringUtils.join(sheetnames, ",")); | |
| 167 | + } catch (Exception exp) { | |
| 168 | + rtn.put("status", ResponseCode.ERROR); | |
| 169 | + rtn.put("msg", exp.getMessage()); | |
| 170 | + } | |
| 171 | + return rtn; | |
| 172 | + } | |
| 173 | + | |
| 174 | + // 导入excel文件 | |
| 175 | + @RequestMapping(value = "/importFile", method = RequestMethod.POST) | |
| 176 | + public Map<String, Object> importFile(@RequestParam Map<String, Object> params) { | |
| 177 | + Map<String, Object> rtn = new HashMap<>(); | |
| 178 | + | |
| 179 | + try { | |
| 180 | + File file = new File(String.valueOf(params.get("filename"))); | |
| 181 | + if (!file.exists()) { | |
| 182 | + throw new Exception("导入文件不存在!"); | |
| 183 | + } | |
| 184 | + bService.importData(file, params); | |
| 185 | + | |
| 186 | + rtn.put("status", ResponseCode.SUCCESS); | |
| 187 | + rtn.put("msg", "导入文件成功"); | |
| 188 | + } catch (Exception exp) { | |
| 189 | + rtn.put("status", ResponseCode.ERROR); | |
| 190 | + rtn.put("msg", exp.getMessage()); | |
| 191 | + } | |
| 192 | + | |
| 193 | + return rtn; | |
| 194 | + } | |
| 195 | + | |
| 196 | + // 上传并导入excel文件 | |
| 197 | + @RequestMapping(value = "/uploadAndImportFile", method = RequestMethod.POST) | |
| 198 | + public Map<String, Object> uploadAndImportFile(MultipartFile file) { | |
| 199 | + Map<String, Object> rtn = new HashMap<>(); | |
| 200 | + | |
| 201 | + try { | |
| 202 | + File file1 = bService.uploadFile(file.getOriginalFilename(), file.getBytes()); | |
| 203 | + Map<String, Object> params = new HashMap<>(); | |
| 204 | + bService.importData(file1, params); | |
| 205 | + | |
| 206 | + rtn.put("status", ResponseCode.SUCCESS); | |
| 207 | + rtn.put("msg", "上传&导入文件成功"); | |
| 208 | + } catch (Exception exp) { | |
| 209 | + rtn.put("status", ResponseCode.ERROR); | |
| 210 | + rtn.put("msg", exp.getMessage()); | |
| 211 | + } | |
| 212 | + | |
| 213 | + return rtn; | |
| 214 | + } | |
| 215 | + | |
| 216 | + // 导出数据到xls文件 | |
| 217 | + @RequestMapping(value = "/exportFile", method = RequestMethod.GET) | |
| 218 | + public void exportFile(HttpServletResponse response, | |
| 219 | + @RequestParam Map<String, Object> params) throws Exception { | |
| 220 | + File file = bService.exportData(params); | |
| 221 | + // 流输出导出文件 | |
| 222 | + response.setHeader("content-type", "application/octet-stream"); | |
| 223 | + response.setHeader("Content-Disposition", "attachment; filename=" + file.getName()); | |
| 224 | + response.setContentType("application/octet-stream"); | |
| 225 | + | |
| 226 | + OutputStream os = response.getOutputStream(); | |
| 227 | + BufferedOutputStream bos = new BufferedOutputStream(os); | |
| 228 | + | |
| 229 | + InputStream is = new FileInputStream(file); | |
| 230 | + BufferedInputStream bis = new BufferedInputStream(is); | |
| 231 | + | |
| 232 | + int length = 0; | |
| 233 | + byte[] temp = new byte[1 * 1024 * 10]; | |
| 234 | + while ((length = bis.read(temp)) != -1) { | |
| 235 | + bos.write(temp, 0, length); | |
| 236 | + } | |
| 237 | + bos.flush(); | |
| 238 | + bis.close(); | |
| 239 | + bos.close(); | |
| 240 | + is.close(); | |
| 241 | + } | |
| 242 | + | |
| 141 | 243 | } | ... | ... |
src/main/java/com/bsth/controller/schedule/TTInfoDetailController.java deleted
100644 → 0
| 1 | -package com.bsth.controller.schedule; | |
| 2 | - | |
| 3 | -import com.bsth.common.ResponseCode; | |
| 4 | -import com.bsth.controller.BaseController2; | |
| 5 | -import com.bsth.entity.CarPark; | |
| 6 | -import com.bsth.entity.LineInformation; | |
| 7 | -import com.bsth.entity.StationRoute; | |
| 8 | -import com.bsth.entity.schedule.GuideboardInfo; | |
| 9 | -import com.bsth.entity.schedule.TTInfoDetail; | |
| 10 | -import com.bsth.repository.schedule.TTInfoDetailRepository; | |
| 11 | -import com.bsth.service.CarParkService; | |
| 12 | -import com.bsth.service.LineInformationService; | |
| 13 | -import com.bsth.service.StationRouteService; | |
| 14 | -import com.bsth.service.schedule.GuideboardInfoService; | |
| 15 | -import com.bsth.service.schedule.TTInfoDetailService; | |
| 16 | -import com.bsth.service.schedule.utils.DataImportExportService; | |
| 17 | -import com.bsth.service.schedule.utils.DataToolsProperties; | |
| 18 | -import jxl.Cell; | |
| 19 | -import jxl.Sheet; | |
| 20 | -import jxl.Workbook; | |
| 21 | -import jxl.write.Label; | |
| 22 | -import jxl.write.WritableSheet; | |
| 23 | -import jxl.write.WritableWorkbook; | |
| 24 | -import org.apache.commons.lang3.StringUtils; | |
| 25 | -import org.springframework.beans.factory.annotation.Autowired; | |
| 26 | -import org.springframework.util.CollectionUtils; | |
| 27 | -import org.springframework.web.bind.annotation.*; | |
| 28 | -import org.springframework.web.multipart.MultipartFile; | |
| 29 | - | |
| 30 | -import javax.servlet.http.HttpServletResponse; | |
| 31 | -import java.io.File; | |
| 32 | -import java.util.*; | |
| 33 | -import java.util.regex.Matcher; | |
| 34 | -import java.util.regex.Pattern; | |
| 35 | - | |
| 36 | -/** | |
| 37 | - * Created by xu on 16/7/2. | |
| 38 | - */ | |
| 39 | -@RestController | |
| 40 | -@RequestMapping("tidc") | |
| 41 | -public class TTInfoDetailController extends BaseController2<TTInfoDetail, Long> { | |
| 42 | - @Autowired | |
| 43 | - private TTInfoDetailService ttInfoDetailService; | |
| 44 | - @Autowired | |
| 45 | - private CarParkService carParkService; | |
| 46 | - @Autowired | |
| 47 | - private LineInformationService lineInformationService; | |
| 48 | - @Autowired | |
| 49 | - private TTInfoDetailRepository ttInfoDetailRepository; | |
| 50 | - @Autowired | |
| 51 | - private DataImportExportService dataImportExportService; | |
| 52 | - @Autowired | |
| 53 | - private StationRouteService stationRouteService; | |
| 54 | - @Autowired | |
| 55 | - private GuideboardInfoService guideboardInfoService; | |
| 56 | - @Autowired | |
| 57 | - private DataToolsProperties dataToolsProperties; | |
| 58 | - | |
| 59 | - /** | |
| 60 | - * 1、上传Excel文件,返回文件全路径名,工作区名称列表。 | |
| 61 | - * @param file | |
| 62 | - * @return | |
| 63 | - * @throws Exception | |
| 64 | - */ | |
| 65 | - | |
| 66 | - | |
| 67 | - /** | |
| 68 | - * 2、验证sheet(以后放到规则引擎里去做)。 | |
| 69 | - * @param filename excel文件全路径名 | |
| 70 | - * @param sheetname sheet名字 | |
| 71 | - * @param lineid 线路id | |
| 72 | - * @param linename 线路名称 | |
| 73 | - * @return | |
| 74 | - */ | |
| 75 | - @RequestMapping(value = "/validate/sheet", method = RequestMethod.POST) | |
| 76 | - public Map<String, Object> validateSheet(String filename, String sheetname, Integer lineid, String linename) throws Exception { | |
| 77 | - Map<String, Object> rtn = new HashMap<>(); | |
| 78 | - Workbook book = Workbook.getWorkbook(new File(filename)); | |
| 79 | - Sheet sheet = book.getSheet(sheetname); | |
| 80 | - if (sheet.getRows() == 0 || sheet.getColumns() == 0) { // 工作区是否为空 | |
| 81 | - rtn.put("status", ResponseCode.ERROR); | |
| 82 | - rtn.put("msg", String.format("%s 工作区没有数据!", sheetname)); | |
| 83 | - return rtn; | |
| 84 | - } else { | |
| 85 | - if (sheet.getRows() <= 1 || sheet.getColumns() <= 1) { | |
| 86 | - rtn.put("status", ResponseCode.ERROR); | |
| 87 | - rtn.put("msg", String.format("工作区至少包含2行2列的数据")); | |
| 88 | - return rtn; | |
| 89 | - } else { | |
| 90 | - Cell[] cells = sheet.getRow(0); // 获取第一行数据列 | |
| 91 | - for (int i = 0; i < cells.length; i++) { | |
| 92 | - String cell_con = cells[i].getContents(); | |
| 93 | - | |
| 94 | - if (StringUtils.isEmpty(cell_con)) { | |
| 95 | - rtn.put("status", ResponseCode.ERROR); | |
| 96 | - rtn.put("msg", String.format("第1行,第%d列数据不能为空", i + 1)); | |
| 97 | - return rtn; | |
| 98 | - } else { | |
| 99 | - // 正则表达式去除数字 | |
| 100 | - cell_con = cell_con.replaceAll("[\\d+]", ""); | |
| 101 | - | |
| 102 | - if (i == 0) { // 第一列必须是路牌2个字 | |
| 103 | - if (!"路牌".equals(cell_con.trim())) { | |
| 104 | - rtn.put("status", ResponseCode.ERROR); | |
| 105 | - rtn.put("msg", "第1行,第1列数据必须是路牌2个字"); | |
| 106 | - return rtn; | |
| 107 | - } | |
| 108 | - } else { // 排除出场,进场,其余内容到站点路由里查询,以各个方向的起点站为查询依据 | |
| 109 | - if ((!"出场".equals(cell_con.trim())) && | |
| 110 | - (!"进场".equals(cell_con.trim()))) { | |
| 111 | - Map<String, Object> p1 = new HashMap<>(); | |
| 112 | - p1.put("line.id_eq", lineid); | |
| 113 | - p1.put("stationName_eq", cell_con.trim()); | |
| 114 | - p1.put("stationMark_eq", "B"); | |
| 115 | - | |
| 116 | - | |
| 117 | - // TODO:这里要修改(起点站有启用撤销的标志的) | |
| 118 | - | |
| 119 | - List<StationRoute> stationRouteList = (List<StationRoute>) stationRouteService.list(p1); | |
| 120 | - if (CollectionUtils.isEmpty(stationRouteList)) { | |
| 121 | - rtn.put("status", ResponseCode.ERROR); | |
| 122 | - rtn.put("msg", String.format("第1行,第%d列数据%s在%s站点路由中不是起点站", i + 1, cell_con.trim(), linename)); | |
| 123 | - return rtn; | |
| 124 | - } else if (stationRouteList.size() > 1) { | |
| 125 | - rtn.put("status", ResponseCode.ERROR); | |
| 126 | - rtn.put("msg", String.format("第1行,第%d列数据%s在%s站点路由中上下行都是起点站", i + 1, cell_con.trim(), linename)); | |
| 127 | - return rtn; | |
| 128 | - } | |
| 129 | - } | |
| 130 | - | |
| 131 | - } | |
| 132 | - } | |
| 133 | - } | |
| 134 | - | |
| 135 | - // 验证路牌内容 | |
| 136 | - Map<String, Integer> gbindexmap = new HashMap<>(); // 记录每个路牌在第几行 | |
| 137 | - for (int i = 1; i < sheet.getRows(); i++) { // 从第2行开始验证数据 | |
| 138 | - Cell bcell = sheet.getRow(i)[0]; // 获取第1列 | |
| 139 | - String bcell_con = bcell.getContents(); | |
| 140 | - if (StringUtils.isEmpty(bcell_con)) { | |
| 141 | - rtn.put("status", ResponseCode.ERROR); | |
| 142 | - rtn.put("msg", String.format("第%d行,第1列路牌无数据", i + 1)); | |
| 143 | - return rtn; | |
| 144 | - } else if (gbindexmap.get(bcell_con.trim()) != null) { | |
| 145 | - rtn.put("status", ResponseCode.ERROR); | |
| 146 | - rtn.put("msg", String.format("第%d行,第1列的路牌数据与第%d行,第1列数据重复", | |
| 147 | - i + 1, | |
| 148 | - gbindexmap.get(bcell_con.trim()))); | |
| 149 | - return rtn; | |
| 150 | - } else { | |
| 151 | - Map<String, Object> p2 = new HashMap<>(); | |
| 152 | - p2.put("xl.id_eq", lineid); | |
| 153 | - p2.put("lpName_eq", bcell_con.trim()); | |
| 154 | - List<GuideboardInfo> guideboardInfoList = (List<GuideboardInfo>) guideboardInfoService.list(p2); | |
| 155 | - if (CollectionUtils.isEmpty(guideboardInfoList)) { | |
| 156 | - rtn.put("status", ResponseCode.ERROR); | |
| 157 | - rtn.put("msg", String.format("第%d行,第1列的路牌在%s中不存在", i + 1, linename)); | |
| 158 | - return rtn; | |
| 159 | - } else if (guideboardInfoList.size() > 1) { | |
| 160 | - rtn.put("status", ResponseCode.ERROR); | |
| 161 | - rtn.put("msg", String.format("第%d行,第1列的路牌在%s中重复", i + 1, linename)); | |
| 162 | - return rtn; | |
| 163 | - } else { | |
| 164 | - gbindexmap.put(bcell_con.trim(), i + 1); | |
| 165 | - } | |
| 166 | - } | |
| 167 | - } | |
| 168 | - | |
| 169 | - // 班次时间验证,正则表达式,格式hh:mm或者hhmm | |
| 170 | - String el = "^(([0-1]\\d)|(2[0-4])):[0-5]\\d$"; // hh:mm格式 | |
| 171 | - String el2 = "^(([0-1]\\d)|(2[0-4]))[0-5]\\d$"; // hhmm格式 | |
| 172 | - Pattern p = Pattern.compile(el); | |
| 173 | - Pattern p2 = Pattern.compile(el2); | |
| 174 | - | |
| 175 | - for (int i = 1; i < sheet.getRows(); i++) { // 从第2行开始验证数据 | |
| 176 | - Cell[] bcells = sheet.getRow(i); | |
| 177 | - for (int j = 1; j < bcells.length; j++) { // 从第2列开始 | |
| 178 | - String bcell_con = bcells[j].getContents(); | |
| 179 | - if (StringUtils.isNotEmpty(bcell_con)) { | |
| 180 | - Matcher m = p.matcher(bcell_con.trim()); | |
| 181 | - Matcher m2 = p2.matcher(bcell_con.trim()); | |
| 182 | - if ((!m.matches()) && (!m2.matches())) { | |
| 183 | - rtn.put("status", ResponseCode.ERROR); | |
| 184 | - rtn.put("msg", String.format("第%d行,第%d列的发车时间格式不正确,格式应为hh:mm或hhmm", i + 1, j + 1)); | |
| 185 | - return rtn; | |
| 186 | - } | |
| 187 | - } | |
| 188 | - } | |
| 189 | - } | |
| 190 | - } | |
| 191 | - | |
| 192 | - } | |
| 193 | - | |
| 194 | - rtn.put("status", ResponseCode.SUCCESS); | |
| 195 | - return rtn; | |
| 196 | - } | |
| 197 | - | |
| 198 | - /** | |
| 199 | - * 3、验证关联的线路标准信息(以后放到规则引擎里去做)。 | |
| 200 | - * @param lineinfoid | |
| 201 | - * @return | |
| 202 | - */ | |
| 203 | - @RequestMapping(value = "/validate/lineinfo", method = RequestMethod.GET) | |
| 204 | - public Map<String, Object> validateAssoLineInfo(Integer lineinfoid) { | |
| 205 | - Map<String, Object> rtn = new HashMap<>(); | |
| 206 | - LineInformation lineInformation = lineInformationService.findById(lineinfoid); | |
| 207 | - if (lineInformation.getUpInMileage() == null) { | |
| 208 | - rtn.put("status", ResponseCode.ERROR); | |
| 209 | - rtn.put("msg", "上行进场里程为空"); | |
| 210 | - return rtn; | |
| 211 | - } else if (lineInformation.getUpInTimer() == null) { | |
| 212 | - rtn.put("status", ResponseCode.ERROR); | |
| 213 | - rtn.put("msg", "上行进场时间为空"); | |
| 214 | - return rtn; | |
| 215 | - } else if (lineInformation.getUpOutMileage() == null) { | |
| 216 | - rtn.put("status", ResponseCode.ERROR); | |
| 217 | - rtn.put("msg", "上行出场里程为空"); | |
| 218 | - return rtn; | |
| 219 | - } else if (lineInformation.getUpOutTimer() == null) { | |
| 220 | - rtn.put("status", ResponseCode.ERROR); | |
| 221 | - rtn.put("msg", "上行出场时间为空"); | |
| 222 | - return rtn; | |
| 223 | - } else if (lineInformation.getUpMileage() == null) { | |
| 224 | - rtn.put("status", ResponseCode.ERROR); | |
| 225 | - rtn.put("msg", "上行班次里程为空"); | |
| 226 | - return rtn; | |
| 227 | - } else if (lineInformation.getUpTravelTime() == null) { | |
| 228 | - rtn.put("status", ResponseCode.ERROR); | |
| 229 | - rtn.put("msg", "上行班次时间为空"); | |
| 230 | - return rtn; | |
| 231 | - } else if (lineInformation.getDownInMileage() == null) { | |
| 232 | - rtn.put("status", ResponseCode.ERROR); | |
| 233 | - rtn.put("msg", "下行进场里程为空"); | |
| 234 | - return rtn; | |
| 235 | - } else if (lineInformation.getDownInTimer() == null) { | |
| 236 | - rtn.put("status", ResponseCode.ERROR); | |
| 237 | - rtn.put("msg", "下行进场时间为空"); | |
| 238 | - return rtn; | |
| 239 | - } else if (lineInformation.getDownOutMileage() == null) { | |
| 240 | - rtn.put("status", ResponseCode.ERROR); | |
| 241 | - rtn.put("msg", "下行出场里程为空"); | |
| 242 | - return rtn; | |
| 243 | - } else if (lineInformation.getDownOutTimer() == null) { | |
| 244 | - rtn.put("status", ResponseCode.ERROR); | |
| 245 | - rtn.put("msg", "下行出场时间为空"); | |
| 246 | - return rtn; | |
| 247 | - } else if (lineInformation.getDownMileage() == null) { | |
| 248 | - rtn.put("status", ResponseCode.ERROR); | |
| 249 | - rtn.put("msg", "下行班次里程为空"); | |
| 250 | - return rtn; | |
| 251 | - } else if (lineInformation.getDownTravelTime() == null) { | |
| 252 | - rtn.put("status", ResponseCode.ERROR); | |
| 253 | - rtn.put("msg", "下行班次时间为空"); | |
| 254 | - return rtn; | |
| 255 | - } else if (StringUtils.isEmpty(lineInformation.getCarPark())) { | |
| 256 | - rtn.put("status", ResponseCode.ERROR); | |
| 257 | - rtn.put("msg", "停车场必须选择"); | |
| 258 | - return rtn; | |
| 259 | - } | |
| 260 | - | |
| 261 | - // 单独验证停车场信息 | |
| 262 | - String tcccode = lineInformation.getCarPark(); | |
| 263 | - Map<String, Object> p1 = new HashMap<>(); | |
| 264 | - p1.put("parkCode_eq", tcccode); | |
| 265 | - List<CarPark> carParkList = (List<CarPark>) carParkService.list(p1); | |
| 266 | - if (CollectionUtils.isEmpty(carParkList)) { | |
| 267 | - rtn.put("status", ResponseCode.ERROR); | |
| 268 | - rtn.put("msg", String.format("线路标准里的停车场code=%s,在停车场信息中未找到", tcccode)); | |
| 269 | - return rtn; | |
| 270 | - } else if (carParkList.size() > 1) { | |
| 271 | - rtn.put("status", ResponseCode.ERROR); | |
| 272 | - rtn.put("msg", String.format("线路标准里的停车场code=%s,在停车场信息中有重复数据", tcccode)); | |
| 273 | - return rtn; | |
| 274 | - } else { | |
| 275 | - CarPark carPark = carParkList.get(0); | |
| 276 | - if (StringUtils.isEmpty(carPark.getParkName())) { | |
| 277 | - rtn.put("status", ResponseCode.ERROR); | |
| 278 | - rtn.put("msg", String.format("线路标准里的停车场code=%s,在停车场信息中没有停车场名字", tcccode)); | |
| 279 | - return rtn; | |
| 280 | - } | |
| 281 | - } | |
| 282 | - | |
| 283 | - rtn.put("status", ResponseCode.SUCCESS); | |
| 284 | - return rtn; | |
| 285 | - } | |
| 286 | - | |
| 287 | - /** | |
| 288 | - * 4、导入时刻表明细数据。 | |
| 289 | - * @param form | |
| 290 | - * @return | |
| 291 | - */ | |
| 292 | - @RequestMapping(value = "/importfile", method = RequestMethod.POST) | |
| 293 | - public Map<String, Object> importTTinfo(@RequestParam Map<String, Object> form) throws Exception { | |
| 294 | - Map<String, Object> rtn = new HashMap<>(); | |
| 295 | - | |
| 296 | - // 1、修改已经上传的excel文件,在每个起点站后标示数字,表示第几个班次 | |
| 297 | - // 2、由于格式问题,需要把内容都转换成字符串 | |
| 298 | - String filename = (String) form.get("filename"); | |
| 299 | - List<String> colList = new ArrayList<>(); | |
| 300 | - Workbook workbook = Workbook.getWorkbook(new File(filename)); | |
| 301 | - Sheet sheet = workbook.getSheet((String) form.get("sheetname")); | |
| 302 | - Cell[] cells = sheet.getRow(0); | |
| 303 | - for (int i = 0; i < cells.length; i++) { | |
| 304 | - if (i == 0) { | |
| 305 | - colList.add(cells[i].getContents().trim()); | |
| 306 | - } else { | |
| 307 | - colList.add(cells[i].getContents() + i); | |
| 308 | - } | |
| 309 | - } | |
| 310 | - | |
| 311 | - WritableWorkbook writableWorkbook = Workbook.createWorkbook(new File(filename + "_temp.xls"), workbook); | |
| 312 | - WritableSheet sheet1 = writableWorkbook.getSheet((String) form.get("sheetname")); | |
| 313 | - for (int i = 0; i < sheet1.getColumns(); i++) { // 第一行数据 | |
| 314 | - sheet1.addCell(new Label(i, 0, colList.get(i))); | |
| 315 | - } | |
| 316 | - for (int i = 1; i < sheet1.getRows(); i++) { // 第二行开始 | |
| 317 | - Cell[] cells1 = sheet.getRow(i); | |
| 318 | - for (int j = 0; j < cells1.length; j++) { | |
| 319 | - sheet1.addCell(new Label(j, i, cells1[j].getContents())); | |
| 320 | - } | |
| 321 | - } | |
| 322 | - writableWorkbook.write(); | |
| 323 | - writableWorkbook.close(); | |
| 324 | - | |
| 325 | - // 2、删除原有数据 | |
| 326 | - ttInfoDetailService.deleteByTtinfo(Long.valueOf(form.get("ttid").toString())); | |
| 327 | - | |
| 328 | - // 3、导入时刻表 | |
| 329 | - // 获取停车场名字 | |
| 330 | - LineInformation lineInformation = lineInformationService.findById(Integer.valueOf(form.get("lineinfo").toString())); | |
| 331 | - Map<String, Object> p1 = new HashMap<>(); | |
| 332 | - p1.put("parkCode_eq", lineInformation.getCarPark()); | |
| 333 | - List<CarPark> carParkList = (List<CarPark>) carParkService.list(p1); | |
| 334 | - String tccname = carParkList.get(0).getParkName(); | |
| 335 | - | |
| 336 | - ttInfoDetailService.fileDataImport( | |
| 337 | - new File(filename + "_temp.xls"), | |
| 338 | - (String) form.get("sheetname"), | |
| 339 | - (String) form.get("xlname"), | |
| 340 | - (String) form.get("ttname"), | |
| 341 | - tccname | |
| 342 | - ); | |
| 343 | - | |
| 344 | - return rtn; | |
| 345 | - } | |
| 346 | - | |
| 347 | - //------------- 旧版本 --------------// | |
| 348 | - @RequestMapping(value = "/dataImportExtend", method = RequestMethod.POST) | |
| 349 | - public Map<String, Object> uploadDataAndImport( | |
| 350 | - MultipartFile file, String xlmc, String ttinfoname) throws Exception { | |
| 351 | - Map<String, Object> resultMap = new HashMap<>(); | |
| 352 | - | |
| 353 | - try { | |
| 354 | - // 查找lineinformation对象,没有报错 | |
| 355 | - Map<String, Object> param = new HashMap<>(); | |
| 356 | - param.put("line.name_eq", xlmc); | |
| 357 | - Iterator<LineInformation> lineInformationIterator = lineInformationService.list(param).iterator(); | |
| 358 | - if (!lineInformationIterator.hasNext()) { | |
| 359 | - // 没有lineinformation,报错 | |
| 360 | - resultMap.put("status", ResponseCode.ERROR); | |
| 361 | - resultMap.put("msg", "没有lineinfomation,线路名称=" + xlmc); | |
| 362 | - } else { | |
| 363 | - String tcccode = lineInformationIterator.next().getCarPark(); | |
| 364 | - if (StringUtils.isEmpty(tcccode)) { | |
| 365 | - // 没有停车场code,报错 | |
| 366 | - resultMap.put("status", ResponseCode.ERROR); | |
| 367 | - resultMap.put("msg", "线路lineinfomation没有停车场code信息,线路名称=" + xlmc); | |
| 368 | - } else { | |
| 369 | - // 使用停车场code查找停车场 | |
| 370 | - param.clear();; | |
| 371 | - param.put("parkCode_eq", tcccode); | |
| 372 | - Iterator<CarPark> carParkIterator = carParkService.list(param).iterator(); | |
| 373 | - if (!carParkIterator.hasNext()) { | |
| 374 | - // 指定的停车场code没有找到停车场信息,报错 | |
| 375 | - resultMap.put("status", ResponseCode.ERROR); | |
| 376 | - resultMap.put("msg", "没有找到停车场信息,停车场code=" + tcccode); | |
| 377 | - } else { | |
| 378 | - String tccname = carParkIterator.next().getParkName(); | |
| 379 | - if (StringUtils.isEmpty(tccname)) { | |
| 380 | - // 没有停车场名字,报错 | |
| 381 | - resultMap.put("status", ResponseCode.ERROR); | |
| 382 | - resultMap.put("msg", "停车场信息没有停车场名字,停车场code=" + tcccode); | |
| 383 | - } else { | |
| 384 | - ttInfoDetailService.fileDataImport(file, xlmc, ttinfoname, tccname); | |
| 385 | - resultMap.put("status", ResponseCode.SUCCESS); | |
| 386 | - resultMap.put("msg", "导入成功"); | |
| 387 | - } | |
| 388 | - } | |
| 389 | - } | |
| 390 | - } | |
| 391 | - } catch (Exception exp) { | |
| 392 | - exp.printStackTrace(); | |
| 393 | - throw exp; | |
| 394 | - } | |
| 395 | - | |
| 396 | - return resultMap; | |
| 397 | - } | |
| 398 | - | |
| 399 | - @RequestMapping(value = "/edit/{xlid}/{ttid}", method = RequestMethod.GET) | |
| 400 | - public Object getEditInfo( | |
| 401 | - @PathVariable("xlid") Integer xlid, | |
| 402 | - @PathVariable("ttid") Long ttid) throws Exception { | |
| 403 | - // TODO:返回类型需要修正 | |
| 404 | - return ttInfoDetailService.getEditInfo(xlid, ttid); | |
| 405 | - } | |
| 406 | - | |
| 407 | - @Override | |
| 408 | - public TTInfoDetail findById(@PathVariable("id") Long aLong) { | |
| 409 | - return ttInfoDetailRepository.findOneExtend(aLong); | |
| 410 | - } | |
| 411 | - | |
| 412 | - @RequestMapping(value = "/bcdetail", method = RequestMethod.GET) | |
| 413 | - public List<TTInfoDetail> findBcdetails(Integer xlId, Long ttinfoId, Long lpId) { | |
| 414 | - return ttInfoDetailRepository.findBcdetails(xlId, ttinfoId, lpId); | |
| 415 | - } | |
| 416 | - | |
| 417 | - @Override | |
| 418 | - public void dataExport(HttpServletResponse response, @RequestParam Map<String, Object> param) throws Exception { | |
| 419 | - // 获取injectktr | |
| 420 | - File ktrFile2 = new File(this.getClass().getResource( | |
| 421 | - dataToolsProperties.getTtinfodetailOutput()).toURI()); | |
| 422 | - param.put("injectktrfile", ktrFile2.getAbsolutePath()); | |
| 423 | - param.put("ttinfoid", param.get("ttinfoid")); | |
| 424 | - | |
| 425 | - super.dataExport(response, param); | |
| 426 | - } | |
| 427 | - | |
| 428 | - @Override | |
| 429 | - protected String getDataExportKtrClasspath() { | |
| 430 | - return dataToolsProperties.getTtinfodetailMetaoutput(); | |
| 431 | - } | |
| 432 | - | |
| 433 | - @Override | |
| 434 | - protected String getDataExportFilename() { | |
| 435 | - return "时刻表"; | |
| 436 | - } | |
| 437 | -} |
src/main/java/com/bsth/controller/schedule/basicinfo/CarDeviceController.java
| ... | ... | @@ -4,7 +4,7 @@ import com.bsth.common.ResponseCode; |
| 4 | 4 | import com.bsth.controller.schedule.BController; |
| 5 | 5 | import com.bsth.entity.CarDevice; |
| 6 | 6 | import com.bsth.service.schedule.CarDeviceService; |
| 7 | -import com.bsth.service.schedule.ScheduleException; | |
| 7 | +import com.bsth.service.schedule.exception.ScheduleException; | |
| 8 | 8 | import org.springframework.beans.factory.annotation.Autowired; |
| 9 | 9 | import org.springframework.web.bind.annotation.RequestMapping; |
| 10 | 10 | import org.springframework.web.bind.annotation.RequestMethod; | ... | ... |
src/main/java/com/bsth/controller/schedule/basicinfo/CarsController.java
| ... | ... | @@ -4,7 +4,7 @@ import com.bsth.common.ResponseCode; |
| 4 | 4 | import com.bsth.controller.schedule.BController; |
| 5 | 5 | import com.bsth.entity.Cars; |
| 6 | 6 | import com.bsth.service.schedule.CarsService; |
| 7 | -import com.bsth.service.schedule.ScheduleException; | |
| 7 | +import com.bsth.service.schedule.exception.ScheduleException; | |
| 8 | 8 | import org.springframework.beans.factory.annotation.Autowired; |
| 9 | 9 | import org.springframework.web.bind.annotation.RequestMapping; |
| 10 | 10 | import org.springframework.web.bind.annotation.RequestMethod; | ... | ... |
src/main/java/com/bsth/controller/schedule/basicinfo/EmployeeController.java
| ... | ... | @@ -4,7 +4,7 @@ import com.bsth.common.ResponseCode; |
| 4 | 4 | import com.bsth.controller.schedule.BController; |
| 5 | 5 | import com.bsth.entity.Personnel; |
| 6 | 6 | import com.bsth.service.schedule.EmployeeService; |
| 7 | -import com.bsth.service.schedule.ScheduleException; | |
| 7 | +import com.bsth.service.schedule.exception.ScheduleException; | |
| 8 | 8 | import org.springframework.beans.factory.annotation.Autowired; |
| 9 | 9 | import org.springframework.web.bind.annotation.RequestMapping; |
| 10 | 10 | import org.springframework.web.bind.annotation.RequestMethod; | ... | ... |
src/main/java/com/bsth/controller/schedule/core/CarConfigInfoController.java
| ... | ... | @@ -5,7 +5,7 @@ import com.bsth.controller.schedule.BController; |
| 5 | 5 | import com.bsth.entity.schedule.CarConfigInfo; |
| 6 | 6 | import com.bsth.repository.schedule.CarConfigInfoRepository; |
| 7 | 7 | import com.bsth.service.schedule.CarConfigInfoService; |
| 8 | -import com.bsth.service.schedule.ScheduleException; | |
| 8 | +import com.bsth.service.schedule.exception.ScheduleException; | |
| 9 | 9 | import org.springframework.beans.factory.annotation.Autowired; |
| 10 | 10 | import org.springframework.web.bind.annotation.RequestMapping; |
| 11 | 11 | import org.springframework.web.bind.annotation.RequestMethod; | ... | ... |
src/main/java/com/bsth/controller/schedule/core/EmployeeConfigInfoController.java
| ... | ... | @@ -5,7 +5,7 @@ import com.bsth.controller.schedule.BController; |
| 5 | 5 | import com.bsth.entity.schedule.EmployeeConfigInfo; |
| 6 | 6 | import com.bsth.repository.schedule.EmployeeConfigInfoRepository; |
| 7 | 7 | import com.bsth.service.schedule.EmployeeConfigInfoService; |
| 8 | -import com.bsth.service.schedule.ScheduleException; | |
| 8 | +import com.bsth.service.schedule.exception.ScheduleException; | |
| 9 | 9 | import org.springframework.beans.factory.annotation.Autowired; |
| 10 | 10 | import org.springframework.web.bind.annotation.RequestMapping; |
| 11 | 11 | import org.springframework.web.bind.annotation.RequestMethod; | ... | ... |
src/main/java/com/bsth/controller/schedule/core/GuideboardInfoController.java
| ... | ... | @@ -5,7 +5,7 @@ import com.bsth.controller.schedule.BController; |
| 5 | 5 | import com.bsth.entity.schedule.GuideboardInfo; |
| 6 | 6 | import com.bsth.repository.schedule.GuideboardInfoRepository; |
| 7 | 7 | import com.bsth.service.schedule.GuideboardInfoService; |
| 8 | -import com.bsth.service.schedule.ScheduleException; | |
| 8 | +import com.bsth.service.schedule.exception.ScheduleException; | |
| 9 | 9 | import com.bsth.service.schedule.utils.DataToolsProperties; |
| 10 | 10 | import org.springframework.beans.factory.annotation.Autowired; |
| 11 | 11 | import org.springframework.boot.context.properties.EnableConfigurationProperties; | ... | ... |
src/main/java/com/bsth/controller/schedule/core/TTInfoController.java
| ... | ... | @@ -3,7 +3,7 @@ package com.bsth.controller.schedule.core; |
| 3 | 3 | import com.bsth.common.ResponseCode; |
| 4 | 4 | import com.bsth.controller.schedule.BController; |
| 5 | 5 | import com.bsth.entity.schedule.TTInfo; |
| 6 | -import com.bsth.service.schedule.ScheduleException; | |
| 6 | +import com.bsth.service.schedule.exception.ScheduleException; | |
| 7 | 7 | import com.bsth.service.schedule.TTInfoService; |
| 8 | 8 | import org.springframework.beans.factory.annotation.Autowired; |
| 9 | 9 | import org.springframework.web.bind.annotation.RequestMapping; | ... | ... |
src/main/java/com/bsth/controller/schedule/core/TTInfoDetailController.java
0 → 100644
| 1 | +package com.bsth.controller.schedule.core; | |
| 2 | + | |
| 3 | +import com.bsth.common.ResponseCode; | |
| 4 | +import com.bsth.controller.schedule.BController; | |
| 5 | +import com.bsth.entity.schedule.TTInfoDetail; | |
| 6 | +import com.bsth.service.schedule.TTInfoDetailService; | |
| 7 | +import org.springframework.beans.factory.annotation.Autowired; | |
| 8 | +import org.springframework.web.bind.annotation.PathVariable; | |
| 9 | +import org.springframework.web.bind.annotation.RequestMapping; | |
| 10 | +import org.springframework.web.bind.annotation.RequestMethod; | |
| 11 | +import org.springframework.web.bind.annotation.RestController; | |
| 12 | + | |
| 13 | +import java.util.HashMap; | |
| 14 | +import java.util.List; | |
| 15 | +import java.util.Map; | |
| 16 | + | |
| 17 | +/** | |
| 18 | + * Created by xu on 17/1/4. | |
| 19 | + */ | |
| 20 | +@RestController | |
| 21 | +@RequestMapping("tidc") | |
| 22 | +public class TTInfoDetailController extends BController<TTInfoDetail, Long> { | |
| 23 | + @Autowired | |
| 24 | + private TTInfoDetailService ttInfoDetailService; | |
| 25 | + | |
| 26 | + @RequestMapping(value = "/bcdetail", method = RequestMethod.GET) | |
| 27 | + public List<TTInfoDetail> findBcdetails(Integer xlId, Long ttinfoId, Long lpId) { | |
| 28 | + return ttInfoDetailService.findBcdetails(xlId, ttinfoId, lpId); | |
| 29 | + } | |
| 30 | + | |
| 31 | + /** | |
| 32 | + * 验证sheet(以后放到规则引擎里去做)。 | |
| 33 | + * @param filename excel文件全路径名 | |
| 34 | + * @param sheetname sheet名字 | |
| 35 | + * @param lineid 线路id | |
| 36 | + * @param linename 线路名称 | |
| 37 | + * @return | |
| 38 | + */ | |
| 39 | + @RequestMapping(value = "/validate/sheet", method = RequestMethod.POST) | |
| 40 | + public Map<String, Object> validate_sheet(String filename, String sheetname, Integer lineid, String linename) { | |
| 41 | + Map<String, Object> rtn = new HashMap<>(); | |
| 42 | + try { | |
| 43 | + ttInfoDetailService.validateExcelSheet(filename, sheetname, lineid, linename); | |
| 44 | + rtn.put("status", ResponseCode.SUCCESS); | |
| 45 | + } catch (Exception exp) { | |
| 46 | + rtn.put("status", ResponseCode.ERROR); | |
| 47 | + rtn.put("msg", exp.getMessage()); | |
| 48 | + } | |
| 49 | + return rtn; | |
| 50 | + } | |
| 51 | + | |
| 52 | + /** | |
| 53 | + * 验证关联的线路标准信息(以后放到规则引擎里去做)。 | |
| 54 | + * @param lineinfoid | |
| 55 | + * @return | |
| 56 | + */ | |
| 57 | + @RequestMapping(value = "/validate/lineinfo", method = RequestMethod.GET) | |
| 58 | + public Map<String, Object> validate_lineInfo(Integer lineinfoid) { | |
| 59 | + Map<String, Object> rtn = new HashMap<>(); | |
| 60 | + try { | |
| 61 | + ttInfoDetailService.validateAssoLineInfo(lineinfoid); | |
| 62 | + rtn.put("status", ResponseCode.SUCCESS); | |
| 63 | + } catch (Exception exp) { | |
| 64 | + rtn.put("status", ResponseCode.ERROR); | |
| 65 | + rtn.put("msg", exp.getMessage()); | |
| 66 | + } | |
| 67 | + return rtn; | |
| 68 | + } | |
| 69 | + | |
| 70 | + /** | |
| 71 | + * 获取时刻表明细编辑信息。 | |
| 72 | + * @param xlid 线路id | |
| 73 | + * @param ttid 时刻表id | |
| 74 | + * @return | |
| 75 | + */ | |
| 76 | + @RequestMapping(value = "/edit/{xlid}/{ttid}", method = RequestMethod.GET) | |
| 77 | + public Map<String, Object> getEditInfo(@PathVariable("xlid") Integer xlid, | |
| 78 | + @PathVariable("ttid") Long ttid) { | |
| 79 | + Map<String, Object> rtn = new HashMap<>(); | |
| 80 | + try { | |
| 81 | + TTInfoDetailService.EditInfo editInfo = ttInfoDetailService.getEditInfo(xlid, ttid); | |
| 82 | + rtn.put("status", ResponseCode.SUCCESS); | |
| 83 | + rtn.put("data", editInfo); | |
| 84 | + } catch (Exception exp) { | |
| 85 | + rtn.put("status", ResponseCode.ERROR); | |
| 86 | + rtn.put("msg", exp.getMessage()); | |
| 87 | + } | |
| 88 | + return rtn; | |
| 89 | + } | |
| 90 | + | |
| 91 | +} | ... | ... |
src/main/java/com/bsth/controller/sys/DutyEmployeeController.java
0 → 100644
| 1 | +package com.bsth.controller.sys; | |
| 2 | + | |
| 3 | +import com.bsth.controller.BaseController; | |
| 4 | +import com.bsth.entity.sys.DutyEmployee; | |
| 5 | +import com.bsth.service.sys.DutyEmployeeService; | |
| 6 | +import org.springframework.beans.factory.annotation.Autowired; | |
| 7 | +import org.springframework.web.bind.annotation.RequestMapping; | |
| 8 | +import org.springframework.web.bind.annotation.RequestParam; | |
| 9 | +import org.springframework.web.bind.annotation.RestController; | |
| 10 | + | |
| 11 | +import java.util.List; | |
| 12 | + | |
| 13 | +/** | |
| 14 | + * Created by panzhao on 2017/1/5. | |
| 15 | + */ | |
| 16 | +@RestController | |
| 17 | +@RequestMapping("dutyEmployee") | |
| 18 | +public class DutyEmployeeController extends BaseController<DutyEmployee, Long> { | |
| 19 | + | |
| 20 | + @Autowired | |
| 21 | + DutyEmployeeService dutyEmployeeService; | |
| 22 | + | |
| 23 | + @RequestMapping(value = "queryByLineAndTime") | |
| 24 | + public List<DutyEmployee> getDutyEmployee(@RequestParam String lineCode, @RequestParam String startTime, @RequestParam String endTime) { | |
| 25 | + return dutyEmployeeService.getDutyEmployee(lineCode, startTime, endTime); | |
| 26 | + } | |
| 27 | +} | ... | ... |
src/main/java/com/bsth/data/gpsdata/arrival/handlers/InOutStationSignalHandle.java
| ... | ... | @@ -154,6 +154,7 @@ public class InOutStationSignalHandle extends SignalHandle{ |
| 154 | 154 | schPrev.setZdsjActualAll(sch.getFcsjActualTime()); |
| 155 | 155 | |
| 156 | 156 | sendUtils.refreshSch(schPrev); |
| 157 | + dayOfSchedule.save(schPrev); | |
| 157 | 158 | } |
| 158 | 159 | } |
| 159 | 160 | } |
| ... | ... | @@ -211,6 +212,7 @@ public class InOutStationSignalHandle extends SignalHandle{ |
| 211 | 212 | next.setZdsjActualAll(sch.getZdsjActualTime()); |
| 212 | 213 | |
| 213 | 214 | sendUtils.refreshSch(next); |
| 215 | + dayOfSchedule.save(next); | |
| 214 | 216 | } |
| 215 | 217 | } |
| 216 | 218 | ... | ... |
src/main/java/com/bsth/data/pilot80/PilotReport.java
| ... | ... | @@ -84,6 +84,8 @@ public class PilotReport { |
| 84 | 84 | |
| 85 | 85 | //下发调度指令 |
| 86 | 86 | directiveService.send60Dispatch(outSch, dayOfSchedule.doneSum(nbbm), "请出@系统"); |
| 87 | + //下发线路切换指令 | |
| 88 | + directiveService.lineChange(outSch.getClZbh(), outSch.getXlBm(), "请出@系统"); | |
| 87 | 89 | /* d80.setRemarks("计划出场时间:" + outSch.getDfsj()); |
| 88 | 90 | //当前GPS位置 |
| 89 | 91 | GpsEntity gps = gpsRealData.get(d80.getDeviceId()); | ... | ... |
src/main/java/com/bsth/entity/CarPark.java
| 1 | 1 | package com.bsth.entity; |
| 2 | 2 | |
| 3 | -import java.util.Date; | |
| 3 | +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; | |
| 4 | 4 | |
| 5 | -import javax.persistence.Column; | |
| 6 | -import javax.persistence.Entity; | |
| 7 | -import javax.persistence.GeneratedValue; | |
| 8 | -import javax.persistence.Id; | |
| 9 | -import javax.persistence.Table; | |
| 5 | +import javax.persistence.*; | |
| 6 | +import java.util.Date; | |
| 10 | 7 | |
| 11 | 8 | |
| 12 | 9 | /** |
| ... | ... | @@ -25,6 +22,7 @@ import javax.persistence.Table; |
| 25 | 22 | |
| 26 | 23 | @Entity |
| 27 | 24 | @Table(name = "bsth_c_car_park") |
| 25 | +@JsonIgnoreProperties(value={"hibernateLazyInitializer","handler","fieldHandler"}) | |
| 28 | 26 | public class CarPark { |
| 29 | 27 | |
| 30 | 28 | @Id | ... | ... |
src/main/java/com/bsth/entity/Cars.java
| ... | ... | @@ -23,7 +23,7 @@ import java.util.Date; |
| 23 | 23 | |
| 24 | 24 | @Entity |
| 25 | 25 | @Table(name = "bsth_c_cars") |
| 26 | -@JsonIgnoreProperties(value={"hibernateLazyInitializer","handlers","fieldHandler"}) | |
| 26 | +@JsonIgnoreProperties(value={"hibernateLazyInitializer","handler","fieldHandler"}) | |
| 27 | 27 | public class Cars extends BEntity implements Serializable { |
| 28 | 28 | |
| 29 | 29 | /** 主键Id */ | ... | ... |
src/main/java/com/bsth/entity/Line.java
| ... | ... | @@ -24,7 +24,7 @@ import java.util.Date; |
| 24 | 24 | |
| 25 | 25 | @Entity |
| 26 | 26 | @Table(name = "bsth_c_line") |
| 27 | -@JsonIgnoreProperties(value={"hibernateLazyInitializer","handlers","fieldHandler"}) | |
| 27 | +@JsonIgnoreProperties(value={"hibernateLazyInitializer","handler","fieldHandler"}) | |
| 28 | 28 | public class Line implements Serializable { |
| 29 | 29 | |
| 30 | 30 | @Id | ... | ... |
src/main/java/com/bsth/entity/Personnel.java
| ... | ... | @@ -21,7 +21,7 @@ import javax.persistence.*; |
| 21 | 21 | |
| 22 | 22 | @Entity |
| 23 | 23 | @Table(name = "bsth_c_personnel") |
| 24 | -@JsonIgnoreProperties(value={"hibernateLazyInitializer","handlers","fieldHandler"}) | |
| 24 | +@JsonIgnoreProperties(value={"hibernateLazyInitializer","handler","fieldHandler"}) | |
| 25 | 25 | public class Personnel extends BEntity { |
| 26 | 26 | |
| 27 | 27 | /** 主键Id */ | ... | ... |
src/main/java/com/bsth/entity/Station.java
| 1 | 1 | package com.bsth.entity; |
| 2 | 2 | |
| 3 | -import java.util.Date; | |
| 3 | +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; | |
| 4 | 4 | |
| 5 | 5 | import javax.persistence.Column; |
| 6 | 6 | import javax.persistence.Entity; |
| 7 | -import javax.persistence.GeneratedValue; | |
| 8 | -import javax.persistence.GenerationType; | |
| 9 | 7 | import javax.persistence.Id; |
| 10 | 8 | import javax.persistence.Table; |
| 9 | +import java.util.Date; | |
| 11 | 10 | |
| 12 | 11 | |
| 13 | 12 | /** |
| ... | ... | @@ -26,6 +25,7 @@ import javax.persistence.Table; |
| 26 | 25 | |
| 27 | 26 | @Entity |
| 28 | 27 | @Table(name = "bsth_c_station") |
| 28 | +@JsonIgnoreProperties(value={"hibernateLazyInitializer","handler","fieldHandler"}) | |
| 29 | 29 | public class Station { |
| 30 | 30 | |
| 31 | 31 | @Id | ... | ... |
src/main/java/com/bsth/entity/schedule/CarConfigInfo.java
| ... | ... | @@ -19,7 +19,7 @@ import java.util.Date; |
| 19 | 19 | @NamedAttributeNode("cl") |
| 20 | 20 | }) |
| 21 | 21 | }) |
| 22 | -@JsonIgnoreProperties(value={"hibernateLazyInitializer","handlers","fieldHandler"}) | |
| 22 | +@JsonIgnoreProperties(value={"hibernateLazyInitializer","handler","fieldHandler"}) | |
| 23 | 23 | public class CarConfigInfo extends BEntity implements Serializable { |
| 24 | 24 | |
| 25 | 25 | /** 主健Id */ | ... | ... |
src/main/java/com/bsth/entity/schedule/EmployeeConfigInfo.java
| ... | ... | @@ -22,7 +22,7 @@ import java.io.Serializable; |
| 22 | 22 | @NamedAttributeNode("xl") |
| 23 | 23 | }) |
| 24 | 24 | }) |
| 25 | -@JsonIgnoreProperties(value={"hibernateLazyInitializer","handlers","fieldHandler"}) | |
| 25 | +@JsonIgnoreProperties(value={"hibernateLazyInitializer","handler","fieldHandler"}) | |
| 26 | 26 | public class EmployeeConfigInfo extends BEntity implements Serializable { |
| 27 | 27 | |
| 28 | 28 | /** 主键Id */ | ... | ... |
src/main/java/com/bsth/entity/schedule/GuideboardInfo.java
| ... | ... | @@ -15,7 +15,7 @@ import javax.persistence.*; |
| 15 | 15 | @NamedAttributeNode("xl") |
| 16 | 16 | }) |
| 17 | 17 | }) |
| 18 | -@JsonIgnoreProperties(value={"hibernateLazyInitializer","handlers","fieldHandler"}) | |
| 18 | +@JsonIgnoreProperties(value={"hibernateLazyInitializer","handler","fieldHandler"}) | |
| 19 | 19 | public class GuideboardInfo extends BEntity { |
| 20 | 20 | |
| 21 | 21 | /** 主键Id */ | ... | ... |
src/main/java/com/bsth/entity/schedule/TTInfo.java
| 1 | 1 | package com.bsth.entity.schedule; |
| 2 | 2 | |
| 3 | 3 | import com.bsth.entity.Line; |
| 4 | +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; | |
| 4 | 5 | |
| 5 | 6 | import javax.persistence.*; |
| 6 | 7 | import java.util.Date; |
| ... | ... | @@ -17,6 +18,7 @@ import java.util.Date; |
| 17 | 18 | @NamedAttributeNode("updateBy") |
| 18 | 19 | }) |
| 19 | 20 | }) |
| 21 | +@JsonIgnoreProperties(value={"hibernateLazyInitializer","handler","fieldHandler"}) | |
| 20 | 22 | public class TTInfo extends BEntity { |
| 21 | 23 | |
| 22 | 24 | /** 主键Id */ | ... | ... |
src/main/java/com/bsth/entity/schedule/TTInfoDetail.java
| ... | ... | @@ -3,6 +3,7 @@ package com.bsth.entity.schedule; |
| 3 | 3 | import com.bsth.entity.CarPark; |
| 4 | 4 | import com.bsth.entity.Line; |
| 5 | 5 | import com.bsth.entity.Station; |
| 6 | +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; | |
| 6 | 7 | |
| 7 | 8 | import javax.persistence.*; |
| 8 | 9 | |
| ... | ... | @@ -21,6 +22,7 @@ import javax.persistence.*; |
| 21 | 22 | @NamedAttributeNode("tcc") |
| 22 | 23 | }) |
| 23 | 24 | }) |
| 25 | +@JsonIgnoreProperties(value={"hibernateLazyInitializer","handler","fieldHandler"}) | |
| 24 | 26 | public class TTInfoDetail extends BEntity { |
| 25 | 27 | |
| 26 | 28 | /** 主健Id */ | ... | ... |
src/main/java/com/bsth/entity/sys/DutyEmployee.java
0 → 100644
| 1 | +package com.bsth.entity.sys; | |
| 2 | + | |
| 3 | +import javax.persistence.*; | |
| 4 | + | |
| 5 | +/** | |
| 6 | + * 当班调度员 | |
| 7 | + * Created by panzhao on 2017/1/5. | |
| 8 | + */ | |
| 9 | +@Entity | |
| 10 | +@Table(name = "bsth_c_sys_duty_employee") | |
| 11 | +public class DutyEmployee { | |
| 12 | + | |
| 13 | + @Id | |
| 14 | + @GeneratedValue | |
| 15 | + private Long id; | |
| 16 | + | |
| 17 | + /** | |
| 18 | + * 员工ID | |
| 19 | + */ | |
| 20 | + private Integer uId; | |
| 21 | + | |
| 22 | + /** | |
| 23 | + * 员工姓名 | |
| 24 | + */ | |
| 25 | + private String uName; | |
| 26 | + | |
| 27 | + /** | |
| 28 | + * 线路编码 ,号分割多个 | |
| 29 | + */ | |
| 30 | + private String codeIdx; | |
| 31 | + | |
| 32 | + /** | |
| 33 | + * 登入线调时间 | |
| 34 | + */ | |
| 35 | + private Long ts; | |
| 36 | + | |
| 37 | + /** | |
| 38 | + * 是否主调模式进入 | |
| 39 | + */ | |
| 40 | + private boolean main; | |
| 41 | + | |
| 42 | + public Integer getuId() { | |
| 43 | + return uId; | |
| 44 | + } | |
| 45 | + | |
| 46 | + public void setuId(Integer uId) { | |
| 47 | + this.uId = uId; | |
| 48 | + } | |
| 49 | + | |
| 50 | + public String getuName() { | |
| 51 | + return uName; | |
| 52 | + } | |
| 53 | + | |
| 54 | + public void setuName(String uName) { | |
| 55 | + this.uName = uName; | |
| 56 | + } | |
| 57 | + | |
| 58 | + public String getCodeIdx() { | |
| 59 | + return codeIdx; | |
| 60 | + } | |
| 61 | + | |
| 62 | + public void setCodeIdx(String codeIdx) { | |
| 63 | + this.codeIdx = codeIdx; | |
| 64 | + } | |
| 65 | + | |
| 66 | + public Long getTs() { | |
| 67 | + return ts; | |
| 68 | + } | |
| 69 | + | |
| 70 | + public void setTs(Long ts) { | |
| 71 | + this.ts = ts; | |
| 72 | + } | |
| 73 | + | |
| 74 | + public boolean isMain() { | |
| 75 | + return main; | |
| 76 | + } | |
| 77 | + | |
| 78 | + public void setMain(boolean main) { | |
| 79 | + this.main = main; | |
| 80 | + } | |
| 81 | + | |
| 82 | + public Long getId() { | |
| 83 | + return id; | |
| 84 | + } | |
| 85 | + | |
| 86 | + public void setId(Long id) { | |
| 87 | + this.id = id; | |
| 88 | + } | |
| 89 | +} | ... | ... |
src/main/java/com/bsth/entity/sys/SessionLog.java deleted
100644 → 0
| 1 | -package com.bsth.entity.sys; | |
| 2 | - | |
| 3 | -import java.util.Date; | |
| 4 | - | |
| 5 | -import javax.persistence.Column; | |
| 6 | -import javax.persistence.Entity; | |
| 7 | -import javax.persistence.GeneratedValue; | |
| 8 | -import javax.persistence.GenerationType; | |
| 9 | -import javax.persistence.Id; | |
| 10 | -import javax.persistence.ManyToOne; | |
| 11 | -import javax.persistence.Table; | |
| 12 | - | |
| 13 | -/** | |
| 14 | - * | |
| 15 | - * @ClassName: SessionLog | |
| 16 | - * @Description: TODO(session日志) | |
| 17 | - * @author PanZhao | |
| 18 | - * @date 2016年7月20日 下午4:46:27 | |
| 19 | - * | |
| 20 | - */ | |
| 21 | -@Entity | |
| 22 | -@Table(name = "bsth_c_sys_sessionlog") | |
| 23 | -public class SessionLog { | |
| 24 | - | |
| 25 | - @Id | |
| 26 | - @GeneratedValue(strategy = GenerationType.IDENTITY) | |
| 27 | - private Integer id; | |
| 28 | - | |
| 29 | - @ManyToOne | |
| 30 | - private SysUser user; | |
| 31 | - | |
| 32 | - /** 登录时间 */ | |
| 33 | - private Date loginDate; | |
| 34 | - | |
| 35 | - @Column(updatable = false, name = "create_date", columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP") | |
| 36 | - private Date createDate; | |
| 37 | - | |
| 38 | - /** 登出时间 */ | |
| 39 | - private Date logoutDate; | |
| 40 | - | |
| 41 | - /** 登出方式 0:主动登出, -1:其他 */ | |
| 42 | - private int logoutType; | |
| 43 | - | |
| 44 | - /** 登录IP */ | |
| 45 | - private String ip; | |
| 46 | - | |
| 47 | - public Integer getId() { | |
| 48 | - return id; | |
| 49 | - } | |
| 50 | - | |
| 51 | - public void setId(Integer id) { | |
| 52 | - this.id = id; | |
| 53 | - } | |
| 54 | - | |
| 55 | - public SysUser getUser() { | |
| 56 | - return user; | |
| 57 | - } | |
| 58 | - | |
| 59 | - public void setUser(SysUser user) { | |
| 60 | - this.user = user; | |
| 61 | - } | |
| 62 | - | |
| 63 | - public Date getLoginDate() { | |
| 64 | - return loginDate; | |
| 65 | - } | |
| 66 | - | |
| 67 | - public void setLoginDate(Date loginDate) { | |
| 68 | - this.loginDate = loginDate; | |
| 69 | - } | |
| 70 | - | |
| 71 | - public Date getCreateDate() { | |
| 72 | - return createDate; | |
| 73 | - } | |
| 74 | - | |
| 75 | - public void setCreateDate(Date createDate) { | |
| 76 | - this.createDate = createDate; | |
| 77 | - } | |
| 78 | - | |
| 79 | - public Date getLogoutDate() { | |
| 80 | - return logoutDate; | |
| 81 | - } | |
| 82 | - | |
| 83 | - public void setLogoutDate(Date logoutDate) { | |
| 84 | - this.logoutDate = logoutDate; | |
| 85 | - } | |
| 86 | - | |
| 87 | - public int getLogoutType() { | |
| 88 | - return logoutType; | |
| 89 | - } | |
| 90 | - | |
| 91 | - public void setLogoutType(int logoutType) { | |
| 92 | - this.logoutType = logoutType; | |
| 93 | - } | |
| 94 | - | |
| 95 | - public String getIp() { | |
| 96 | - return ip; | |
| 97 | - } | |
| 98 | - | |
| 99 | - public void setIp(String ip) { | |
| 100 | - this.ip = ip; | |
| 101 | - } | |
| 102 | -} |
src/main/java/com/bsth/entity/sys/SignControl.java deleted
100644 → 0
| 1 | -package com.bsth.entity.sys; | |
| 2 | - | |
| 3 | -import java.util.Date; | |
| 4 | - | |
| 5 | -import javax.persistence.Entity; | |
| 6 | -import javax.persistence.GeneratedValue; | |
| 7 | -import javax.persistence.GenerationType; | |
| 8 | -import javax.persistence.Id; | |
| 9 | -import javax.persistence.ManyToOne; | |
| 10 | -import javax.persistence.Table; | |
| 11 | - | |
| 12 | -/** | |
| 13 | - * | |
| 14 | - * @ClassName: SignControl | |
| 15 | - * @Description: TODO(进出线调记录) | |
| 16 | - * @author PanZhao | |
| 17 | - * @date 2016年7月20日 下午4:50:50 | |
| 18 | - * | |
| 19 | - */ | |
| 20 | -@Entity | |
| 21 | -@Table(name = "bsth_c_sys_sign") | |
| 22 | -public class SignControl { | |
| 23 | - | |
| 24 | - @Id | |
| 25 | - @GeneratedValue(strategy = GenerationType.IDENTITY) | |
| 26 | - private Integer id; | |
| 27 | - | |
| 28 | - @ManyToOne | |
| 29 | - private SessionLog session; | |
| 30 | - | |
| 31 | - /** 登出线调时间 */ | |
| 32 | - private Date outDate; | |
| 33 | - | |
| 34 | - /** 在线时长 */ | |
| 35 | - private Long onLineTimel; | |
| 36 | - | |
| 37 | - /** 0: 主调模式, 1:监控模式 */ | |
| 38 | - private int signType; | |
| 39 | - | |
| 40 | - /** 用户名 */ | |
| 41 | - private String userName; | |
| 42 | - | |
| 43 | - public Integer getId() { | |
| 44 | - return id; | |
| 45 | - } | |
| 46 | - | |
| 47 | - public void setId(Integer id) { | |
| 48 | - this.id = id; | |
| 49 | - } | |
| 50 | - | |
| 51 | - public SessionLog getSession() { | |
| 52 | - return session; | |
| 53 | - } | |
| 54 | - | |
| 55 | - public void setSession(SessionLog session) { | |
| 56 | - this.session = session; | |
| 57 | - } | |
| 58 | - | |
| 59 | - public Date getOutDate() { | |
| 60 | - return outDate; | |
| 61 | - } | |
| 62 | - | |
| 63 | - public void setOutDate(Date outDate) { | |
| 64 | - this.outDate = outDate; | |
| 65 | - } | |
| 66 | - | |
| 67 | - public Long getOnLineTimel() { | |
| 68 | - return onLineTimel; | |
| 69 | - } | |
| 70 | - | |
| 71 | - public void setOnLineTimel(Long onLineTimel) { | |
| 72 | - this.onLineTimel = onLineTimel; | |
| 73 | - } | |
| 74 | - | |
| 75 | - public int getSignType() { | |
| 76 | - return signType; | |
| 77 | - } | |
| 78 | - | |
| 79 | - public void setSignType(int signType) { | |
| 80 | - this.signType = signType; | |
| 81 | - } | |
| 82 | - | |
| 83 | - public String getUserName() { | |
| 84 | - return userName; | |
| 85 | - } | |
| 86 | - | |
| 87 | - public void setUserName(String userName) { | |
| 88 | - this.userName = userName; | |
| 89 | - } | |
| 90 | -} |
src/main/java/com/bsth/entity/sys/SysUser.java
| ... | ... | @@ -9,7 +9,8 @@ import java.util.Set; |
| 9 | 9 | |
| 10 | 10 | @Entity |
| 11 | 11 | @Table(name = "bsth_c_sys_user") |
| 12 | -@JsonIgnoreProperties(value={"hibernateLazyInitializer","handlers","fieldHandler"}) | |
| 12 | +//@JsonIgnoreProperties(value={"hibernateLazyInitializer","handlers","fieldHandler"}) | |
| 13 | +@JsonIgnoreProperties(ignoreUnknown = true) | |
| 13 | 14 | public class SysUser { |
| 14 | 15 | |
| 15 | 16 | @Id | ... | ... |
src/main/java/com/bsth/repository/schedule/TTInfoDetailRepository.java
| ... | ... | @@ -34,7 +34,10 @@ public interface TTInfoDetailRepository extends BaseRepository<TTInfoDetail, Lon |
| 34 | 34 | @Query("select cc from TTInfoDetail cc where cc.id=?1") |
| 35 | 35 | TTInfoDetail findOneExtend(Long aLong); |
| 36 | 36 | |
| 37 | - void deleteByTtinfoId(Long ttid); | |
| 37 | +// TODO:在findOne中 @EntityGraph 无效 | |
| 38 | +// @EntityGraph(value = "tTInfoDetail_xl_lp_qdz_zdz_tcc", type = EntityGraph.EntityGraphType.FETCH) | |
| 39 | +// @Override | |
| 40 | +// TTInfoDetail findOne(Long aLong); | |
| 38 | 41 | |
| 39 | 42 | @Query(value = "select max(tt.fcno) as mx from bsth_c_s_ttinfo_detail tt where tt.xl =?1 and tt.ttinfo =?2", nativeQuery = true) |
| 40 | 43 | Long findMaxFcno(Integer xlid, Long ttinfoid); |
| ... | ... | @@ -44,6 +47,6 @@ public interface TTInfoDetailRepository extends BaseRepository<TTInfoDetail, Lon |
| 44 | 47 | |
| 45 | 48 | @Modifying |
| 46 | 49 | @Query(value = "delete from TTInfoDetail t where t.ttinfo.id = ?1") |
| 47 | - void deleteByTtinfo(Long ttinfoid); | |
| 50 | + void deleteByTtinfoIdWithModify(Long ttinfoid); | |
| 48 | 51 | |
| 49 | 52 | } | ... | ... |
src/main/java/com/bsth/repository/sys/DutyEmployeeRepository.java
0 → 100644
| 1 | +package com.bsth.repository.sys; | |
| 2 | + | |
| 3 | +import com.bsth.entity.sys.DutyEmployee; | |
| 4 | +import com.bsth.repository.BaseRepository; | |
| 5 | +import org.springframework.data.jpa.repository.Query; | |
| 6 | +import org.springframework.stereotype.Repository; | |
| 7 | + | |
| 8 | +import java.util.List; | |
| 9 | + | |
| 10 | +/** | |
| 11 | + * Created by panzhao on 2017/1/5. | |
| 12 | + */ | |
| 13 | +@Repository | |
| 14 | +public interface DutyEmployeeRepository extends BaseRepository<DutyEmployee, Long>{ | |
| 15 | + | |
| 16 | + @Query("select t from DutyEmployee t where t.codeIdx like %?1% and t.ts > ?2 and t.ts < ?3") | |
| 17 | + List<DutyEmployee> findByLineAndTime(String lineCode, long st, long et); | |
| 18 | +} | ... | ... |
src/main/java/com/bsth/repository/sys/SessionLogRepository.java deleted
100644 → 0
| 1 | -package com.bsth.repository.sys; | |
| 2 | - | |
| 3 | -import org.springframework.stereotype.Repository; | |
| 4 | - | |
| 5 | -import com.bsth.entity.sys.SessionLog; | |
| 6 | -import com.bsth.repository.BaseRepository; | |
| 7 | - | |
| 8 | -@Repository | |
| 9 | -public interface SessionLogRepository extends BaseRepository<SessionLog, Integer>{ | |
| 10 | - | |
| 11 | -} |
src/main/java/com/bsth/service/realcontrol/RealMapService.java
src/main/java/com/bsth/service/realcontrol/ScheduleRealInfoService.java
| ... | ... | @@ -95,7 +95,7 @@ public interface ScheduleRealInfoService extends BaseService<ScheduleRealInfo, L |
| 95 | 95 | |
| 96 | 96 | List<Map<String,Object>> account(String line,String date,String code,String xlName, String type); |
| 97 | 97 | |
| 98 | - List<ScheduleRealInfo> correctForm(String line,String startDate,String endDate,String lpName,String code); | |
| 98 | + List<ScheduleRealInfo> correctForm(String line,String startDate,String endDate,String lpName,String code, String type); | |
| 99 | 99 | |
| 100 | 100 | List<ScheduleRealInfo> queryListWaybill(String jName,String clZbh,String lpName,String date,String type); |
| 101 | 101 | ... | ... |
src/main/java/com/bsth/service/realcontrol/impl/RealMapServiceImpl.java
| ... | ... | @@ -122,7 +122,7 @@ public class RealMapServiceImpl implements RealMapService { |
| 122 | 122 | rs.put("section", secList); |
| 123 | 123 | |
| 124 | 124 | //查询站点信息 |
| 125 | - sql="select r.STATION_NAME,r.STATION_ROUTE_CODE,r.LINE_CODE,r.STATION_CODE,r.STATION_MARK,s.G_LONX,s.G_LATY, r.DIRECTIONS from bsth_c_stationroute r INNER JOIN bsth_c_station s on r.station=s.id and r.line_code=? and r.destroy=0"; | |
| 125 | + sql = "select r.STATION_NAME,r.STATION_ROUTE_CODE,r.LINE_CODE,r.STATION_CODE,r.STATION_MARK,s.G_LONX,s.G_LATY, r.DIRECTIONS from bsth_c_stationroute r INNER JOIN bsth_c_station s on r.station=s.id and r.line_code=? and r.destroy=0"; | |
| 126 | 126 | List<Map<String, Object>> stationList = jdbcTemplate.queryForList(sql, lineCode); |
| 127 | 127 | rs.put("station", stationList); |
| 128 | 128 | |
| ... | ... | @@ -134,6 +134,31 @@ public class RealMapServiceImpl implements RealMapService { |
| 134 | 134 | return rs; |
| 135 | 135 | } |
| 136 | 136 | |
| 137 | + @Override | |
| 138 | + public Map<String, Object> multiSectionRoute(String codeIdx) { | |
| 139 | + Map<String, Object> rs = new HashMap<>(); | |
| 140 | + try { | |
| 141 | + List<String> idArray = Splitter.on(",").splitToList(codeIdx); | |
| 142 | + //拼接in语句 | |
| 143 | + String inStr = ""; | |
| 144 | + for (String code : idArray) { | |
| 145 | + inStr += (",'" + code + "'"); | |
| 146 | + } | |
| 147 | + inStr = " (" + inStr.substring(1) + ")"; | |
| 148 | + | |
| 149 | + String sql = "SELECT r.LINE_CODE,r.SECTION_CODE,r.SECTIONROUTE_CODE,s.SECTION_NAME,ST_AsText (s.GSECTION_VECTOR) AS GSECTION_VECTOR,r.DIRECTIONS FROM bsth_c_sectionroute r INNER JOIN bsth_c_section s ON r.section = s.id WHERE r.line_code in " + inStr + " AND r.destroy = 0 order by r.line_code, r.directions,r.sectionroute_code"; | |
| 150 | + | |
| 151 | + List<Map<String, Object>> secList = jdbcTemplate.queryForList(sql); | |
| 152 | + rs.put("section", secList); | |
| 153 | + rs.put("status", ResponseCode.SUCCESS); | |
| 154 | + } catch (DataAccessException e) { | |
| 155 | + logger.error("", e); | |
| 156 | + rs.put("status", ResponseCode.ERROR); | |
| 157 | + } | |
| 158 | + | |
| 159 | + return rs; | |
| 160 | + } | |
| 161 | + | |
| 137 | 162 | /** |
| 138 | 163 | * wgs 坐标数组转 百度 |
| 139 | 164 | * | ... | ... |
src/main/java/com/bsth/service/realcontrol/impl/ScheduleRealInfoServiceImpl.java
| ... | ... | @@ -46,6 +46,7 @@ import org.slf4j.LoggerFactory; |
| 46 | 46 | import org.springframework.beans.factory.annotation.Autowired; |
| 47 | 47 | import org.springframework.stereotype.Service; |
| 48 | 48 | |
| 49 | +import java.net.URLEncoder; | |
| 49 | 50 | import java.text.DecimalFormat; |
| 50 | 51 | import java.text.ParseException; |
| 51 | 52 | import java.text.SimpleDateFormat; |
| ... | ... | @@ -1304,8 +1305,28 @@ public class ScheduleRealInfoServiceImpl extends BaseServiceImpl<ScheduleRealInf |
| 1304 | 1305 | |
| 1305 | 1306 | @Override |
| 1306 | 1307 | public List<ScheduleRealInfo> correctForm(String line, String startDate, |
| 1307 | - String endDate, String lpName, String code) { | |
| 1308 | + String endDate, String lpName, String code, String type) { | |
| 1308 | 1309 | List<ScheduleRealInfo> list = scheduleRealInfoRepository.correctForm(line,startDate,endDate,lpName,code); |
| 1310 | + | |
| 1311 | + if(type != null && type.length() != 0 && type.equals("export")){ | |
| 1312 | + SimpleDateFormat sdfMonth = new SimpleDateFormat("yyyy-MM-dd"), | |
| 1313 | + sdfSimple = new SimpleDateFormat("yyyyMMdd"); | |
| 1314 | + List<Iterator<?>> listI = new ArrayList<Iterator<?>>(); | |
| 1315 | + Map<String,Object> m = new HashMap<String, Object>(); | |
| 1316 | + ReportUtils ee = new ReportUtils(); | |
| 1317 | + m.put("startDate", startDate); | |
| 1318 | + m.put("endDate", endDate); | |
| 1319 | + try { | |
| 1320 | + listI.add(list.iterator()); | |
| 1321 | + String path = this.getClass().getResource("/").getPath()+"static\\pages\\forms\\"; | |
| 1322 | + ee.excelReplace(listI, new Object[] { m }, path+"mould\\correctForm.xls", | |
| 1323 | + path+"export\\" + URLEncoder.encode("修正报表", "UTF-8") + sdfSimple.format(sdfMonth.parse(startDate)) + "-" + sdfSimple.format(sdfMonth.parse(endDate)) + ".xls"); | |
| 1324 | + } catch (Exception e) { | |
| 1325 | + // TODO: handle exception | |
| 1326 | + e.printStackTrace(); | |
| 1327 | + } | |
| 1328 | + } | |
| 1329 | + | |
| 1309 | 1330 | return list; |
| 1310 | 1331 | } |
| 1311 | 1332 | ... | ... |
src/main/java/com/bsth/service/schedule/BService.java
| 1 | 1 | package com.bsth.service.schedule; |
| 2 | 2 | |
| 3 | +import com.bsth.service.schedule.exception.ScheduleException; | |
| 4 | +import com.bsth.service.schedule.utils.DataToolsService; | |
| 3 | 5 | import org.springframework.data.domain.Page; |
| 4 | 6 | import org.springframework.data.domain.Pageable; |
| 5 | 7 | |
| ... | ... | @@ -10,8 +12,8 @@ import java.util.Map; |
| 10 | 12 | /** |
| 11 | 13 | * 基础service接口。 |
| 12 | 14 | */ |
| 13 | -public interface BService<T, ID extends Serializable> { | |
| 14 | - // CRUD 操作 | |
| 15 | +public interface BService<T, ID extends Serializable> extends DataToolsService { | |
| 16 | + //---------------- CRUD 操作 ----------------// | |
| 15 | 17 | // Create,Update操作 |
| 16 | 18 | T save(T t); |
| 17 | 19 | <S extends T> List<S> bulkSave(List<S> entities); // 批量保存(TODO:待测试) |
| ... | ... | @@ -22,4 +24,5 @@ public interface BService<T, ID extends Serializable> { |
| 22 | 24 | List<T> list(Map<String, Object> param); |
| 23 | 25 | // Delete操作 |
| 24 | 26 | void delete(ID id) throws ScheduleException; |
| 27 | + | |
| 25 | 28 | } | ... | ... |
src/main/java/com/bsth/service/schedule/CarConfigInfoService.java
src/main/java/com/bsth/service/schedule/CarDeviceService.java
src/main/java/com/bsth/service/schedule/CarsService.java
src/main/java/com/bsth/service/schedule/EmployeeConfigInfoService.java
src/main/java/com/bsth/service/schedule/EmployeeService.java
src/main/java/com/bsth/service/schedule/GuideboardInfoService.java
src/main/java/com/bsth/service/schedule/PeopleCarPlanServiceImpl.java
| 1 | 1 | package com.bsth.service.schedule; |
| 2 | 2 | |
| 3 | 3 | import java.math.BigDecimal; |
| 4 | +import java.net.URLEncoder; | |
| 4 | 5 | import java.sql.ResultSet; |
| 5 | 6 | import java.sql.SQLException; |
| 6 | 7 | import java.text.DecimalFormat; |
| ... | ... | @@ -463,7 +464,7 @@ public class PeopleCarPlanServiceImpl implements PeopleCarPlanService { |
| 463 | 464 | listI.add(resList.iterator()); |
| 464 | 465 | String path = this.getClass().getResource("/").getPath()+"static\\pages\\forms\\"; |
| 465 | 466 | ee.excelReplace(listI, new Object[] { m }, path+"mould\\workDaily.xls", |
| 466 | - path+"export\\营运服务日报表" + sdfSimple.format(sdfMonth.parse(date)) + ".xls"); | |
| 467 | + path+"export\\营运服务日报表"+ sdfSimple.format(sdfMonth.parse(date))+".xls"); | |
| 467 | 468 | } catch (Exception e) { |
| 468 | 469 | // TODO: handle exception |
| 469 | 470 | e.printStackTrace(); |
| ... | ... | @@ -937,7 +938,7 @@ public class PeopleCarPlanServiceImpl implements PeopleCarPlanService { |
| 937 | 938 | tempMap.put("sjfcFirst0", "/"); |
| 938 | 939 | tempMap.put("delayFirst0", "/"); |
| 939 | 940 | } |
| 940 | - if(moban0.getZdsjActual() != null){ | |
| 941 | + if(moban0.getFcsjActual() != null){ | |
| 941 | 942 | String[] split = moban0.getFcsjActual().split(":"); |
| 942 | 943 | long min = Integer.valueOf(split[0])*60 + Integer.valueOf(split[1]); |
| 943 | 944 | long delay = moban0.getFcsjT() - min; |
| ... | ... | @@ -963,7 +964,7 @@ public class PeopleCarPlanServiceImpl implements PeopleCarPlanService { |
| 963 | 964 | tempMap.put("sjfcFirst1", "/"); |
| 964 | 965 | tempMap.put("delayFirst1", "/"); |
| 965 | 966 | } |
| 966 | - if(moban1.getZdsjActual() != null){ | |
| 967 | + if(moban1.getFcsjActual() != null){ | |
| 967 | 968 | String[] split = moban1.getFcsjActual().split(":"); |
| 968 | 969 | long min = Integer.valueOf(split[0])*60 + Integer.valueOf(split[1]); |
| 969 | 970 | long delay = moban1.getFcsjT() - min; | ... | ... |
src/main/java/com/bsth/service/schedule/TTInfoDetailService.java
| 1 | 1 | package com.bsth.service.schedule; |
| 2 | 2 | |
| 3 | 3 | import com.bsth.entity.schedule.TTInfoDetail; |
| 4 | -import com.bsth.service.BaseService; | |
| 4 | +import com.bsth.service.schedule.exception.ScheduleException; | |
| 5 | 5 | import org.apache.commons.lang3.StringUtils; |
| 6 | -import org.springframework.web.multipart.MultipartFile; | |
| 7 | 6 | |
| 8 | -import java.io.File; | |
| 9 | 7 | import java.util.ArrayList; |
| 10 | 8 | import java.util.List; |
| 11 | 9 | |
| 12 | 10 | /** |
| 13 | 11 | * Created by xu on 16/7/2. |
| 14 | 12 | */ |
| 15 | -public interface TTInfoDetailService extends BaseService<TTInfoDetail, Long> { | |
| 16 | - | |
| 17 | - void deleteByTtinfo(Long ttinfoid); | |
| 13 | +public interface TTInfoDetailService extends BService<TTInfoDetail, Long> { | |
| 18 | 14 | |
| 19 | 15 | /** |
| 20 | 16 | * 发车信息内部类。 |
| ... | ... | @@ -34,7 +30,12 @@ public interface TTInfoDetailService extends BaseService<TTInfoDetail, Long> { |
| 34 | 30 | public FcInfo() { |
| 35 | 31 | } |
| 36 | 32 | |
| 37 | - public FcInfo(String ttdid_str, String bc_type, String fcsj, String xldir, String isfb) { | |
| 33 | + public FcInfo( | |
| 34 | + String ttdid_str, | |
| 35 | + String bc_type, | |
| 36 | + String fcsj, | |
| 37 | + String xldir, | |
| 38 | + String isfb) { | |
| 38 | 39 | this.ttdid = StringUtils.isEmpty(ttdid_str) ? null : Long.valueOf(ttdid_str); |
| 39 | 40 | this.bc_type = bc_type; |
| 40 | 41 | this.fcsj = fcsj; |
| ... | ... | @@ -98,6 +99,9 @@ public interface TTInfoDetailService extends BaseService<TTInfoDetail, Long> { |
| 98 | 99 | /** 内容数据 */ |
| 99 | 100 | private List<List<FcInfo>> contents = new ArrayList<>(); |
| 100 | 101 | |
| 102 | + /** 营运描述 */ | |
| 103 | + private String yy_desc; | |
| 104 | + | |
| 101 | 105 | public List<String> getHeader() { |
| 102 | 106 | return header; |
| 103 | 107 | } |
| ... | ... | @@ -113,6 +117,14 @@ public interface TTInfoDetailService extends BaseService<TTInfoDetail, Long> { |
| 113 | 117 | public void setContents(List<List<FcInfo>> contents) { |
| 114 | 118 | this.contents = contents; |
| 115 | 119 | } |
| 120 | + | |
| 121 | + public String getYy_desc() { | |
| 122 | + return yy_desc; | |
| 123 | + } | |
| 124 | + | |
| 125 | + public void setYy_desc(String yy_desc) { | |
| 126 | + this.yy_desc = yy_desc; | |
| 127 | + } | |
| 116 | 128 | } |
| 117 | 129 | |
| 118 | 130 | /** |
| ... | ... | @@ -121,22 +133,28 @@ public interface TTInfoDetailService extends BaseService<TTInfoDetail, Long> { |
| 121 | 133 | * @param ttid 时刻表id |
| 122 | 134 | * @return |
| 123 | 135 | */ |
| 124 | - EditInfo getEditInfo(Integer xlid, Long ttid) throws Exception; | |
| 136 | + EditInfo getEditInfo(Integer xlid, Long ttid) throws ScheduleException; | |
| 137 | + | |
| 138 | + /** | |
| 139 | + * 验证sheet(以后放到规则引擎里去做)。 | |
| 140 | + * @param filename excel文件全路径名 | |
| 141 | + * @param sheetname sheet名字 | |
| 142 | + * @param lineid 线路id | |
| 143 | + */ | |
| 144 | + void validateExcelSheet( | |
| 145 | + String filename, | |
| 146 | + String sheetname, | |
| 147 | + Integer lineid, | |
| 148 | + String linename) throws ScheduleException; | |
| 125 | 149 | |
| 126 | 150 | /** |
| 127 | - * 上传并导入数据,和DataImportExportService的同名方法有差别。 | |
| 128 | - * @param datafile form上传文件 | |
| 129 | - * @param xlmc 线路名称 | |
| 130 | - * @param ttinfoname 时刻表名字 | |
| 131 | - * @param tccname 停车场名字 | |
| 132 | - * @throws Exception | |
| 151 | + * 验证关联的线路标准信息(以后放到规则引擎里去做)。 | |
| 152 | + * @param lineinfoid 线路id | |
| 133 | 153 | */ |
| 134 | - void fileDataImport(MultipartFile datafile, | |
| 135 | - String xlmc, | |
| 136 | - String ttinfoname, | |
| 137 | - String tccname) throws Exception; | |
| 154 | + void validateAssoLineInfo(Integer lineinfoid) throws ScheduleException; | |
| 138 | 155 | |
| 139 | - void fileDataImport(File file, String sheetname, String xlmc, String ttinfoname, String tccname) throws Exception; | |
| 156 | + // TODO:这个方法可以用通用方法解决,以后改 | |
| 157 | + List<TTInfoDetail> findBcdetails(Integer xlId, Long ttinfoId, Long lpId); | |
| 140 | 158 | |
| 141 | 159 | |
| 142 | 160 | } | ... | ... |
src/main/java/com/bsth/service/schedule/TTInfoDetailServiceImpl.java deleted
100644 → 0
| 1 | -package com.bsth.service.schedule; | |
| 2 | - | |
| 3 | -import com.bsth.entity.schedule.TTInfoDetail; | |
| 4 | -import com.bsth.repository.schedule.TTInfoDetailRepository; | |
| 5 | -import com.bsth.service.impl.BaseServiceImpl; | |
| 6 | -import com.bsth.service.schedule.utils.DataImportExportService; | |
| 7 | -import com.bsth.service.schedule.utils.DataToolsProperties; | |
| 8 | -import jxl.Sheet; | |
| 9 | -import jxl.Workbook; | |
| 10 | -import org.apache.commons.lang3.StringUtils; | |
| 11 | -import org.joda.time.DateTime; | |
| 12 | -import org.pentaho.di.trans.Trans; | |
| 13 | -import org.pentaho.di.trans.TransMeta; | |
| 14 | -import org.springframework.beans.factory.annotation.Autowired; | |
| 15 | -import org.springframework.boot.context.properties.EnableConfigurationProperties; | |
| 16 | -import org.springframework.stereotype.Service; | |
| 17 | -import org.springframework.transaction.annotation.Isolation; | |
| 18 | -import org.springframework.transaction.annotation.Propagation; | |
| 19 | -import org.springframework.transaction.annotation.Transactional; | |
| 20 | -import org.springframework.web.multipart.MultipartFile; | |
| 21 | - | |
| 22 | -import java.io.File; | |
| 23 | -import java.util.ArrayList; | |
| 24 | -import java.util.Arrays; | |
| 25 | -import java.util.List; | |
| 26 | - | |
| 27 | -/** | |
| 28 | - * Created by xu on 16/7/2. | |
| 29 | - */ | |
| 30 | -@Service | |
| 31 | -@EnableConfigurationProperties(DataToolsProperties.class) | |
| 32 | -public class TTInfoDetailServiceImpl extends BaseServiceImpl<TTInfoDetail, Long> implements TTInfoDetailService { | |
| 33 | - @Autowired | |
| 34 | - private DataImportExportService dataImportExportService; | |
| 35 | - @Autowired | |
| 36 | - private DataToolsProperties dataToolsProperties; | |
| 37 | - @Autowired | |
| 38 | - private TTInfoDetailRepository ttInfoDetailRepository; | |
| 39 | - | |
| 40 | - @Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.READ_COMMITTED) | |
| 41 | - @Override | |
| 42 | - public void deleteByTtinfo(Long ttinfoid) { | |
| 43 | - ttInfoDetailRepository.deleteByTtinfo(ttinfoid); | |
| 44 | - } | |
| 45 | - | |
| 46 | - /** | |
| 47 | - * 获取待编辑的数据。 | |
| 48 | - * @param xlid 线路id | |
| 49 | - * @param ttid 时刻表id | |
| 50 | - * @return | |
| 51 | - */ | |
| 52 | - @Override | |
| 53 | - public EditInfo getEditInfo(Integer xlid, Long ttid) throws Exception { | |
| 54 | - // 1、使用ktr转换获取输出文件 | |
| 55 | - // 1.1、获取转换用ktr | |
| 56 | - File ktrFile = new File(this.getClass().getResource( | |
| 57 | - dataToolsProperties.getTtinfodetailForeditktr()).toURI()); | |
| 58 | - TransMeta transMeta = new TransMeta(ktrFile.getAbsolutePath()); | |
| 59 | - Trans trans = new Trans(transMeta); | |
| 60 | -// trans.setLogLevel(LogLevel.DEBUG); | |
| 61 | - // 1.2、设定命名参数,TODO:之后还要添加其他命名参数 | |
| 62 | - String outputFilePath = "ttinfodetail_" + new DateTime().toString("yyyy-MM-dd_HH-mm-ss"); | |
| 63 | - trans.setParameterValue("tempfilepath", dataToolsProperties.getTransTempdir() + File.separator + outputFilePath); // 数据输出文件路径 | |
| 64 | - trans.setParameterValue("xlid", String.valueOf(xlid)); | |
| 65 | - trans.setParameterValue("ttid", String.valueOf(ttid)); | |
| 66 | - // 1.3、执行转换 | |
| 67 | - trans.execute(null); | |
| 68 | - // 1.4、等待转换结束 | |
| 69 | - trans.waitUntilFinished(); | |
| 70 | - | |
| 71 | - // 1.5、判定ktr错误数,注意这种错误代表部分数据错误,不会终止转换执行,一般设计ktr的时候,会有错误输出文件,TODO:以后考虑使用日志实时输出 | |
| 72 | - if (trans.getErrors() > 0) { | |
| 73 | - throw new Exception("转换数据部分错误,请查看相关错误输出文件!"); | |
| 74 | - } | |
| 75 | - | |
| 76 | - // 1.6、获取最大的发车数,用于输出数据的数量 | |
| 77 | - Long maxfcno = ttInfoDetailRepository.findMaxFcno(xlid, ttid); | |
| 78 | - if (maxfcno == null) | |
| 79 | - return new EditInfo(); | |
| 80 | - | |
| 81 | - // 2、读取ktr生成的excel数据,组织编辑用数据返回 | |
| 82 | - // 2-1、读取Excel文件 | |
| 83 | - Workbook book = Workbook.getWorkbook(new File(dataToolsProperties.getTransTempdir() + | |
| 84 | - File.separator + outputFilePath + ".xls")); | |
| 85 | - Sheet sheet = book.getSheet(0); | |
| 86 | - EditInfo editInfo = new EditInfo(); | |
| 87 | - // 2-2、处理数据 | |
| 88 | - String[] headarrays = new String[maxfcno.intValue() + 1]; | |
| 89 | - headarrays[0] = "路牌"; | |
| 90 | - for (int r = 1; r < sheet.getRows(); r++) { | |
| 91 | - List<FcInfo> fcInfos = new ArrayList<>(); | |
| 92 | - // 每行第一列都是路牌 | |
| 93 | - fcInfos.add(new FcInfo(null, null, sheet.getCell(0, r).getContents(), null, null)); // 用fcsj放置路牌显示 | |
| 94 | - for (int c = 1; c <= maxfcno * 6; ) { | |
| 95 | - String ttdid_str = sheet.getCell(c, r).getContents(); // 时刻表明细id | |
| 96 | - String fcsj = sheet.getCell(c + 1, r).getContents(); // 发车时间 | |
| 97 | - String fzdname = sheet.getCell(c + 2, r).getContents(); // 发车站点名称 | |
| 98 | - String bctype = sheet.getCell(c + 3, r).getContents(); // 班次类型 | |
| 99 | - String xldir = sheet.getCell(c + 4, r).getContents(); // 线路上下行 | |
| 100 | - String isfb = sheet.getCell(c + 5, r).getContents(); // 是否分班 | |
| 101 | - | |
| 102 | - FcInfo fcInfo = new FcInfo(ttdid_str, bctype, fcsj, xldir, isfb); | |
| 103 | - | |
| 104 | - if (StringUtils.isNotEmpty(fzdname)) | |
| 105 | - headarrays[(int)(c / 6) + 1] = fzdname; | |
| 106 | - fcInfos.add(fcInfo); | |
| 107 | - | |
| 108 | - c += 6; | |
| 109 | - } | |
| 110 | - editInfo.getContents().add(fcInfos); | |
| 111 | - } | |
| 112 | - editInfo.getHeader().addAll(Arrays.asList(headarrays)); | |
| 113 | - | |
| 114 | - return editInfo; | |
| 115 | - } | |
| 116 | - | |
| 117 | - @Override | |
| 118 | - /** | |
| 119 | - * 上传并导入数据,和DataImportExportService的同名方法有差别。 | |
| 120 | - * @param datafile form上传文件 | |
| 121 | - * @param xlmc 线路名称 | |
| 122 | - * @param ttinfoname 时刻表名字 | |
| 123 | - * @param tccname 停车场名字 | |
| 124 | - * @throws Exception | |
| 125 | - */ | |
| 126 | - public void fileDataImport(MultipartFile datafile, | |
| 127 | - String xlmc, | |
| 128 | - String ttinfoname, | |
| 129 | - String tccname) throws Exception { | |
| 130 | - // 上传数据文件 | |
| 131 | - File uploadFile = dataImportExportService.uploadFile(datafile); | |
| 132 | - fileDataImport(uploadFile, "工作表1", xlmc, ttinfoname, tccname); | |
| 133 | - | |
| 134 | - } | |
| 135 | - | |
| 136 | - @Override | |
| 137 | - public void fileDataImport(File uploadFile, String sheetname, String xlmc, String ttinfoname, String tccname) throws Exception { | |
| 138 | - // 1、上传数据文件 | |
| 139 | - System.out.println("线路名称:" + xlmc); | |
| 140 | - System.out.println("时刻表名称:" + ttinfoname); | |
| 141 | - System.out.println("停车场名字:" + tccname); | |
| 142 | - System.out.println("时刻表明细上传文件:" + uploadFile); | |
| 143 | - | |
| 144 | - // 2、jexcelapi读取excel文件 | |
| 145 | - Workbook book = Workbook.getWorkbook(uploadFile); | |
| 146 | - Sheet sheet = book.getSheet(0); | |
| 147 | - List<String> columnames = new ArrayList<>(); | |
| 148 | - for (int i = 0; i < sheet.getColumns(); i++) { // 获取第一行,数据,作为列名 | |
| 149 | - columnames.add(sheet.getCell(i, 0).getContents()); | |
| 150 | - } | |
| 151 | - | |
| 152 | - System.out.println("表头1:" + StringUtils.join(columnames.toArray(), ",")); | |
| 153 | - | |
| 154 | - // 2、使用kettle运行封装数据导入逻辑的ktr转换文件 | |
| 155 | - // 2.1、初始化kettle(组件初始化已经做了) | |
| 156 | - // 2.2、创建转换元数据,转换 | |
| 157 | - File ktrFile = new File(this.getClass().getResource( | |
| 158 | - dataToolsProperties.getTtinfodetailMetadatainputktr()).toURI()); | |
| 159 | - File ktrFile2 = new File(this.getClass().getResource( | |
| 160 | - dataToolsProperties.getTtinfodetailDatainputktr()).toURI()); | |
| 161 | - TransMeta transMeta = new TransMeta(ktrFile.getAbsolutePath()); | |
| 162 | - Trans trans = new Trans(transMeta); | |
| 163 | - // 2.3、设定命名参数,用于指定数据文件,注意每个ktr必须都有以下指定的命名参数 | |
| 164 | - trans.setParameterValue("injectktrfile", ktrFile2.getAbsolutePath()); // 注入元数据的ktr文件 | |
| 165 | - trans.setParameterValue("filepath", uploadFile.getAbsolutePath()); // 指定导入数据文件的位置 | |
| 166 | - trans.setParameterValue("sheetname", sheetname); // sheet工作区的名字 | |
| 167 | - trans.setParameterValue("erroroutputdir", dataToolsProperties.getTransErrordir()); // ktr转换错误输出目录 | |
| 168 | - trans.setParameterValue("xlname", xlmc); // 线路名称 | |
| 169 | - trans.setParameterValue("ttinfoname", ttinfoname); // 时刻表名称 | |
| 170 | - trans.setParameterValue("tccname", tccname); // 停车场名字 | |
| 171 | - trans.setParameterValue("excelfieldnames", StringUtils.join(columnames.toArray(), ",")); // 时刻表excel输入字段名,以逗号连接 | |
| 172 | - columnames.remove(0); | |
| 173 | - trans.setParameterValue("normalizefieldnames", StringUtils.join(columnames.toArray(), ",")); // 数据范式化字段名,以逗号连接 | |
| 174 | - | |
| 175 | - // TODO:可以考虑设定日志输出 | |
| 176 | - // 2.4、执行转换 | |
| 177 | - trans.execute(null); | |
| 178 | - // 2.5、等待转换结束 | |
| 179 | - trans.waitUntilFinished(); | |
| 180 | - | |
| 181 | - // 3、判定ktr错误数,注意这种错误代表部分数据错误,不会终止转换执行,一般设计ktr的时候,会有错误输出文件,TODO:以后考虑使用日志实时输出 | |
| 182 | - if (trans.getErrors() > 0) { | |
| 183 | - throw new Exception("转换数据部分错误,请查看相关错误输出文件!"); | |
| 184 | - } | |
| 185 | - } | |
| 186 | -} |
src/main/java/com/bsth/service/schedule/TTInfoService.java
src/main/java/com/bsth/service/schedule/ScheduleException.java renamed to src/main/java/com/bsth/service/schedule/exception/ScheduleException.java
src/main/java/com/bsth/service/schedule/impl/BServiceImpl.java
| ... | ... | @@ -3,16 +3,19 @@ package com.bsth.service.schedule.impl; |
| 3 | 3 | import com.bsth.entity.search.CustomerSpecs; |
| 4 | 4 | import com.bsth.repository.BaseRepository; |
| 5 | 5 | import com.bsth.service.schedule.BService; |
| 6 | -import com.bsth.service.schedule.ScheduleException; | |
| 6 | +import com.bsth.service.schedule.exception.ScheduleException; | |
| 7 | +import com.bsth.service.schedule.utils.DataToolsService; | |
| 7 | 8 | import org.slf4j.Logger; |
| 8 | 9 | import org.slf4j.LoggerFactory; |
| 9 | 10 | import org.springframework.beans.factory.annotation.Autowired; |
| 11 | +import org.springframework.beans.factory.annotation.Qualifier; | |
| 10 | 12 | import org.springframework.beans.factory.annotation.Value; |
| 11 | 13 | import org.springframework.data.domain.Page; |
| 12 | 14 | import org.springframework.data.domain.Pageable; |
| 13 | 15 | import org.springframework.data.jpa.domain.Specification; |
| 14 | 16 | |
| 15 | 17 | import javax.persistence.EntityManager; |
| 18 | +import java.io.File; | |
| 16 | 19 | import java.io.Serializable; |
| 17 | 20 | import java.util.ArrayList; |
| 18 | 21 | import java.util.List; |
| ... | ... | @@ -29,6 +32,10 @@ public class BServiceImpl<T, ID extends Serializable> implements BService<T, ID> |
| 29 | 32 | @Value("${hibernate.jdbc.batch_size}") |
| 30 | 33 | private int batchSize; |
| 31 | 34 | |
| 35 | + @Autowired | |
| 36 | + @Qualifier(value = "dataToolsServiceImpl") | |
| 37 | + private DataToolsService dataToolsService; | |
| 38 | + | |
| 32 | 39 | /** 日志记录器 */ |
| 33 | 40 | protected Logger logger = LoggerFactory.getLogger(this.getClass()); |
| 34 | 41 | |
| ... | ... | @@ -108,4 +115,19 @@ public class BServiceImpl<T, ID extends Serializable> implements BService<T, ID> |
| 108 | 115 | |
| 109 | 116 | baseRepository.delete(id); |
| 110 | 117 | } |
| 118 | + | |
| 119 | + @Override | |
| 120 | + public File uploadFile(String filename, byte[] filedata) throws ScheduleException { | |
| 121 | + return dataToolsService.uploadFile(filename, filedata); | |
| 122 | + } | |
| 123 | + | |
| 124 | + @Override | |
| 125 | + public void importData(File file, Map<String, Object> params) throws ScheduleException { | |
| 126 | + dataToolsService.importData(file, params); | |
| 127 | + } | |
| 128 | + | |
| 129 | + @Override | |
| 130 | + public File exportData(Map<String, Object> params) throws ScheduleException { | |
| 131 | + return dataToolsService.exportData(params); | |
| 132 | + } | |
| 111 | 133 | } | ... | ... |
src/main/java/com/bsth/service/schedule/impl/CarConfigInfoServiceImpl.java
| ... | ... | @@ -3,7 +3,7 @@ package com.bsth.service.schedule.impl; |
| 3 | 3 | import com.bsth.entity.schedule.CarConfigInfo; |
| 4 | 4 | import com.bsth.entity.schedule.rule.ScheduleRule1Flat; |
| 5 | 5 | import com.bsth.service.schedule.CarConfigInfoService; |
| 6 | -import com.bsth.service.schedule.ScheduleException; | |
| 6 | +import com.bsth.service.schedule.exception.ScheduleException; | |
| 7 | 7 | import com.bsth.service.schedule.ScheduleRule1FlatService; |
| 8 | 8 | import org.springframework.beans.factory.annotation.Autowired; |
| 9 | 9 | import org.springframework.stereotype.Service; | ... | ... |
src/main/java/com/bsth/service/schedule/impl/CarDeviceServiceImpl.java
| ... | ... | @@ -4,7 +4,7 @@ import com.bsth.entity.CarDevice; |
| 4 | 4 | import com.bsth.entity.Cars; |
| 5 | 5 | import com.bsth.service.CarsService; |
| 6 | 6 | import com.bsth.service.schedule.CarDeviceService; |
| 7 | -import com.bsth.service.schedule.ScheduleException; | |
| 7 | +import com.bsth.service.schedule.exception.ScheduleException; | |
| 8 | 8 | import org.springframework.beans.factory.annotation.Autowired; |
| 9 | 9 | import org.springframework.stereotype.Service; |
| 10 | 10 | import org.springframework.transaction.annotation.Transactional; | ... | ... |
src/main/java/com/bsth/service/schedule/impl/CarsServiceImpl.java
| ... | ... | @@ -2,19 +2,91 @@ package com.bsth.service.schedule.impl; |
| 2 | 2 | |
| 3 | 3 | import com.bsth.entity.Cars; |
| 4 | 4 | import com.bsth.service.schedule.CarsService; |
| 5 | -import com.bsth.service.schedule.ScheduleException; | |
| 5 | +import com.bsth.service.schedule.exception.ScheduleException; | |
| 6 | +import com.bsth.service.schedule.utils.DataToolsProperties; | |
| 7 | +import org.slf4j.Logger; | |
| 8 | +import org.slf4j.LoggerFactory; | |
| 9 | +import org.springframework.beans.factory.annotation.Autowired; | |
| 10 | +import org.springframework.boot.context.properties.EnableConfigurationProperties; | |
| 6 | 11 | import org.springframework.stereotype.Service; |
| 7 | 12 | import org.springframework.transaction.annotation.Transactional; |
| 8 | 13 | import org.springframework.util.CollectionUtils; |
| 9 | 14 | |
| 15 | +import java.io.File; | |
| 16 | +import java.io.PrintWriter; | |
| 17 | +import java.io.StringWriter; | |
| 10 | 18 | import java.util.HashMap; |
| 11 | 19 | import java.util.Map; |
| 12 | 20 | |
| 13 | 21 | /** |
| 14 | 22 | * Created by xu on 16/12/8. |
| 15 | 23 | */ |
| 24 | +@EnableConfigurationProperties(DataToolsProperties.class) | |
| 16 | 25 | @Service(value = "carsServiceImpl_sc") |
| 17 | 26 | public class CarsServiceImpl extends BServiceImpl<Cars, Integer> implements CarsService { |
| 27 | + /** 日志记录器 */ | |
| 28 | + private static final Logger LOGGER = LoggerFactory.getLogger(CarsServiceImpl.class); | |
| 29 | + | |
| 30 | + @Autowired | |
| 31 | + private DataToolsProperties dataToolsProperties; | |
| 32 | + | |
| 33 | + @Override | |
| 34 | + public void importData(File file, Map<String, Object> params) throws ScheduleException { | |
| 35 | + try { | |
| 36 | + LOGGER.info("//---------------- 导入车辆基础信息 start... ----------------//"); | |
| 37 | + // 创建ktr转换所需参数 | |
| 38 | + Map<String, Object> ktrParms = new HashMap<>(); | |
| 39 | + File ktrFile = new File(this.getClass().getResource( | |
| 40 | + dataToolsProperties.getCarsDatainputktr()).toURI()); | |
| 41 | + | |
| 42 | + // 通用参数,转换文件路径,excel输入文件路径,错误输出文件路径 | |
| 43 | + ktrParms.put("transpath", ktrFile.getAbsolutePath()); | |
| 44 | + ktrParms.put("filepath", file.getAbsolutePath()); | |
| 45 | + ktrParms.put("erroroutputdir", dataToolsProperties.getTransErrordir()); | |
| 46 | + | |
| 47 | + super.importData(file, ktrParms); | |
| 48 | + | |
| 49 | + LOGGER.info("//---------------- 导入车辆基础信息 success... ----------------//"); | |
| 50 | + } catch (Exception exp) { | |
| 51 | + LOGGER.info("//---------------- 导入车辆基础信息 failed... ----------------//"); | |
| 52 | + | |
| 53 | + StringWriter sw = new StringWriter(); | |
| 54 | + exp.printStackTrace(new PrintWriter(sw)); | |
| 55 | + LOGGER.info(sw.toString()); | |
| 56 | + | |
| 57 | + throw new ScheduleException(exp.getMessage()); | |
| 58 | + } | |
| 59 | + } | |
| 60 | + | |
| 61 | + @Override | |
| 62 | + public File exportData(Map<String, Object> params) throws ScheduleException { | |
| 63 | + try { | |
| 64 | + LOGGER.info("//---------------- 导出车辆基础信息 start... ----------------//"); | |
| 65 | + // 创建ktr转换所需参数 | |
| 66 | + Map<String, Object> ktrParms = new HashMap<>(); | |
| 67 | + File ktrFile = new File(this.getClass().getResource( | |
| 68 | + dataToolsProperties.getCarsDataoutputktr()).toURI()); | |
| 69 | + | |
| 70 | + // 通用参数,转换文件路径,excel输出文件名 | |
| 71 | + ktrParms.put("transpath", ktrFile.getAbsolutePath()); | |
| 72 | + ktrParms.put("filename", "车辆基础信息_download-"); | |
| 73 | + | |
| 74 | + File file = super.exportData(ktrParms); | |
| 75 | + | |
| 76 | + LOGGER.info("//---------------- 导出车辆基础信息 success... ----------------//"); | |
| 77 | + | |
| 78 | + return file; | |
| 79 | + | |
| 80 | + } catch (Exception exp) { | |
| 81 | + LOGGER.info("//---------------- 导出车辆基础信息 failed... ----------------//"); | |
| 82 | + | |
| 83 | + StringWriter sw = new StringWriter(); | |
| 84 | + exp.printStackTrace(new PrintWriter(sw)); | |
| 85 | + LOGGER.info(sw.toString()); | |
| 86 | + | |
| 87 | + throw new ScheduleException(exp.getMessage()); | |
| 88 | + } | |
| 89 | + } | |
| 18 | 90 | |
| 19 | 91 | @Override |
| 20 | 92 | @Transactional | ... | ... |
src/main/java/com/bsth/service/schedule/impl/EmployeeConfigInfoServiceImpl.java
| ... | ... | @@ -3,7 +3,7 @@ package com.bsth.service.schedule.impl; |
| 3 | 3 | import com.bsth.entity.schedule.EmployeeConfigInfo; |
| 4 | 4 | import com.bsth.entity.schedule.rule.ScheduleRule1Flat; |
| 5 | 5 | import com.bsth.service.schedule.EmployeeConfigInfoService; |
| 6 | -import com.bsth.service.schedule.ScheduleException; | |
| 6 | +import com.bsth.service.schedule.exception.ScheduleException; | |
| 7 | 7 | import com.bsth.service.schedule.ScheduleRule1FlatService; |
| 8 | 8 | import org.springframework.beans.factory.annotation.Autowired; |
| 9 | 9 | import org.springframework.stereotype.Service; | ... | ... |
src/main/java/com/bsth/service/schedule/impl/EmployeeServiceImpl.java
| ... | ... | @@ -2,19 +2,92 @@ package com.bsth.service.schedule.impl; |
| 2 | 2 | |
| 3 | 3 | import com.bsth.entity.Personnel; |
| 4 | 4 | import com.bsth.service.schedule.EmployeeService; |
| 5 | -import com.bsth.service.schedule.ScheduleException; | |
| 5 | +import com.bsth.service.schedule.exception.ScheduleException; | |
| 6 | +import com.bsth.service.schedule.utils.DataToolsProperties; | |
| 7 | +import org.slf4j.Logger; | |
| 8 | +import org.slf4j.LoggerFactory; | |
| 9 | +import org.springframework.beans.factory.annotation.Autowired; | |
| 10 | +import org.springframework.boot.context.properties.EnableConfigurationProperties; | |
| 6 | 11 | import org.springframework.stereotype.Service; |
| 7 | 12 | import org.springframework.transaction.annotation.Transactional; |
| 8 | 13 | import org.springframework.util.CollectionUtils; |
| 9 | 14 | |
| 15 | +import java.io.File; | |
| 16 | +import java.io.PrintWriter; | |
| 17 | +import java.io.StringWriter; | |
| 10 | 18 | import java.util.HashMap; |
| 11 | 19 | import java.util.Map; |
| 12 | 20 | |
| 13 | 21 | /** |
| 14 | 22 | * Created by xu on 16/12/15. |
| 15 | 23 | */ |
| 24 | +@EnableConfigurationProperties(DataToolsProperties.class) | |
| 16 | 25 | @Service |
| 17 | 26 | public class EmployeeServiceImpl extends BServiceImpl<Personnel, Integer> implements EmployeeService { |
| 27 | + /** 日志记录器 */ | |
| 28 | + private static final Logger LOGGER = LoggerFactory.getLogger(EmployeeServiceImpl.class); | |
| 29 | + | |
| 30 | + @Autowired | |
| 31 | + private DataToolsProperties dataToolsProperties; | |
| 32 | + | |
| 33 | + @Override | |
| 34 | + public void importData(File file, Map<String, Object> params) throws ScheduleException { | |
| 35 | + try { | |
| 36 | + LOGGER.info("//---------------- 导入人员基础信息 start... ----------------//"); | |
| 37 | + // 创建ktr转换所需参数 | |
| 38 | + Map<String, Object> ktrParms = new HashMap<>(); | |
| 39 | + File ktrFile = new File(this.getClass().getResource( | |
| 40 | + dataToolsProperties.getEmployeesDatainputktr()).toURI()); | |
| 41 | + | |
| 42 | + // 通用参数,转换文件路径,excel输入文件路径,错误输出文件路径 | |
| 43 | + ktrParms.put("transpath", ktrFile.getAbsolutePath()); | |
| 44 | + ktrParms.put("filepath", file.getAbsolutePath()); | |
| 45 | + ktrParms.put("erroroutputdir", dataToolsProperties.getTransErrordir()); | |
| 46 | + | |
| 47 | + super.importData(file, ktrParms); | |
| 48 | + | |
| 49 | + LOGGER.info("//---------------- 导入人员基础信息 success... ----------------//"); | |
| 50 | + } catch (Exception exp) { | |
| 51 | + LOGGER.info("//---------------- 导入人员基础信息 failed... ----------------//"); | |
| 52 | + | |
| 53 | + StringWriter sw = new StringWriter(); | |
| 54 | + exp.printStackTrace(new PrintWriter(sw)); | |
| 55 | + LOGGER.info(sw.toString()); | |
| 56 | + | |
| 57 | + throw new ScheduleException(exp.getMessage()); | |
| 58 | + } | |
| 59 | + } | |
| 60 | + | |
| 61 | + @Override | |
| 62 | + public File exportData(Map<String, Object> params) throws ScheduleException { | |
| 63 | + try { | |
| 64 | + LOGGER.info("//---------------- 导出人员基础信息 start... ----------------//"); | |
| 65 | + // 创建ktr转换所需参数 | |
| 66 | + Map<String, Object> ktrParms = new HashMap<>(); | |
| 67 | + File ktrFile = new File(this.getClass().getResource( | |
| 68 | + dataToolsProperties.getEmployeesDataoutputktr()).toURI()); | |
| 69 | + | |
| 70 | + // 通用参数,转换文件路径,excel输出文件名 | |
| 71 | + ktrParms.put("transpath", ktrFile.getAbsolutePath()); | |
| 72 | + ktrParms.put("filename", "人员基础信息_download-"); | |
| 73 | + | |
| 74 | + File file = super.exportData(ktrParms); | |
| 75 | + | |
| 76 | + LOGGER.info("//---------------- 导出人员基础信息 success... ----------------//"); | |
| 77 | + | |
| 78 | + return file; | |
| 79 | + | |
| 80 | + } catch (Exception exp) { | |
| 81 | + LOGGER.info("//---------------- 导出人员基础信息 failed... ----------------//"); | |
| 82 | + | |
| 83 | + StringWriter sw = new StringWriter(); | |
| 84 | + exp.printStackTrace(new PrintWriter(sw)); | |
| 85 | + LOGGER.info(sw.toString()); | |
| 86 | + | |
| 87 | + throw new ScheduleException(exp.getMessage()); | |
| 88 | + } | |
| 89 | + } | |
| 90 | + | |
| 18 | 91 | @Override |
| 19 | 92 | @Transactional |
| 20 | 93 | public void validate_gh(Personnel personnel) throws ScheduleException { | ... | ... |
src/main/java/com/bsth/service/schedule/impl/GuideboardInfoServiceImpl.java
| ... | ... | @@ -3,7 +3,7 @@ package com.bsth.service.schedule.impl; |
| 3 | 3 | import com.bsth.entity.schedule.GuideboardInfo; |
| 4 | 4 | import com.bsth.entity.schedule.TTInfoDetail; |
| 5 | 5 | import com.bsth.service.schedule.GuideboardInfoService; |
| 6 | -import com.bsth.service.schedule.ScheduleException; | |
| 6 | +import com.bsth.service.schedule.exception.ScheduleException; | |
| 7 | 7 | import com.bsth.service.schedule.TTInfoDetailService; |
| 8 | 8 | import org.springframework.beans.factory.annotation.Autowired; |
| 9 | 9 | import org.springframework.stereotype.Service; | ... | ... |
src/main/java/com/bsth/service/schedule/impl/RerunServiceImpl.java
| ... | ... | @@ -2,7 +2,7 @@ package com.bsth.service.schedule.impl; |
| 2 | 2 | |
| 3 | 3 | import com.bsth.entity.schedule.rule.RerunRule; |
| 4 | 4 | import com.bsth.service.schedule.RerunService; |
| 5 | -import com.bsth.service.schedule.ScheduleException; | |
| 5 | +import com.bsth.service.schedule.exception.ScheduleException; | |
| 6 | 6 | import org.springframework.stereotype.Service; |
| 7 | 7 | import org.springframework.transaction.annotation.Transactional; |
| 8 | 8 | ... | ... |
src/main/java/com/bsth/service/schedule/impl/TTInfoDetailServiceImpl.java
0 → 100644
| 1 | +package com.bsth.service.schedule.impl; | |
| 2 | + | |
| 3 | +import com.bsth.entity.CarPark; | |
| 4 | +import com.bsth.entity.LineInformation; | |
| 5 | +import com.bsth.entity.StationRoute; | |
| 6 | +import com.bsth.entity.schedule.GuideboardInfo; | |
| 7 | +import com.bsth.entity.schedule.TTInfoDetail; | |
| 8 | +import com.bsth.repository.schedule.TTInfoDetailRepository; | |
| 9 | +import com.bsth.service.CarParkService; | |
| 10 | +import com.bsth.service.LineInformationService; | |
| 11 | +import com.bsth.service.StationRouteService; | |
| 12 | +import com.bsth.service.schedule.GuideboardInfoService; | |
| 13 | +import com.bsth.service.schedule.TTInfoDetailService; | |
| 14 | +import com.bsth.service.schedule.exception.ScheduleException; | |
| 15 | +import com.bsth.service.schedule.utils.DataToolsProperties; | |
| 16 | +import jxl.Cell; | |
| 17 | +import jxl.Sheet; | |
| 18 | +import jxl.Workbook; | |
| 19 | +import jxl.write.Label; | |
| 20 | +import jxl.write.WritableSheet; | |
| 21 | +import jxl.write.WritableWorkbook; | |
| 22 | +import org.apache.commons.lang3.StringUtils; | |
| 23 | +import org.joda.time.DateTime; | |
| 24 | +import org.slf4j.Logger; | |
| 25 | +import org.slf4j.LoggerFactory; | |
| 26 | +import org.springframework.beans.factory.annotation.Autowired; | |
| 27 | +import org.springframework.boot.context.properties.EnableConfigurationProperties; | |
| 28 | +import org.springframework.stereotype.Service; | |
| 29 | +import org.springframework.util.CollectionUtils; | |
| 30 | + | |
| 31 | +import java.io.File; | |
| 32 | +import java.io.PrintWriter; | |
| 33 | +import java.io.StringWriter; | |
| 34 | +import java.util.*; | |
| 35 | +import java.util.regex.Matcher; | |
| 36 | +import java.util.regex.Pattern; | |
| 37 | + | |
| 38 | +/** | |
| 39 | + * Created by xu on 17/1/3. | |
| 40 | + */ | |
| 41 | +@Service | |
| 42 | +@EnableConfigurationProperties(DataToolsProperties.class) | |
| 43 | +public class TTInfoDetailServiceImpl extends BServiceImpl<TTInfoDetail, Long> implements TTInfoDetailService { | |
| 44 | + /** 日志记录器 */ | |
| 45 | + private static final Logger LOGGER = LoggerFactory.getLogger(TTInfoDetailServiceImpl.class); | |
| 46 | + | |
| 47 | + @Autowired | |
| 48 | + private GuideboardInfoService guideboardInfoService; | |
| 49 | + @Autowired | |
| 50 | + private StationRouteService stationRouteService; | |
| 51 | + @Autowired | |
| 52 | + private LineInformationService lineInformationService; | |
| 53 | + @Autowired | |
| 54 | + private CarParkService carParkService; | |
| 55 | + @Autowired | |
| 56 | + private TTInfoDetailRepository ttInfoDetailRepository; | |
| 57 | + @Autowired | |
| 58 | + private DataToolsProperties dataToolsProperties; | |
| 59 | + | |
| 60 | + @Override | |
| 61 | + public TTInfoDetail findById(Long aLong) { | |
| 62 | + return ttInfoDetailRepository.findOneExtend(aLong); | |
| 63 | + } | |
| 64 | + | |
| 65 | + @Override | |
| 66 | + public void importData( | |
| 67 | + File file, | |
| 68 | + Map<String, Object> params) throws ScheduleException { | |
| 69 | + | |
| 70 | + try { | |
| 71 | + LOGGER.info("//---------------- 导入时刻表明细 start... ----------------//"); | |
| 72 | + | |
| 73 | + String filename = file.getAbsolutePath(); // xls文件名 | |
| 74 | + String sheetname = String.valueOf(params.get("sheetname")); // sheet名字 | |
| 75 | + Long ttid = Long.valueOf(String.valueOf(params.get("ttid"))); // 时刻表id | |
| 76 | + Long xlid = Long.valueOf(String.valueOf(params.get("xlid"))); // 线路id | |
| 77 | + Integer lineid = Integer.valueOf(String.valueOf(params.get("lineinfo"))); // 线路标准id | |
| 78 | + String xlname = String.valueOf(params.get("xlname")); // 线路名字 | |
| 79 | + String ttname = String.valueOf(params.get("ttname")); // 时刻表名字 | |
| 80 | + | |
| 81 | + LOGGER.info("参数1, xls文件名={},sheet名字={}", filename, sheetname); | |
| 82 | + LOGGER.info("参数2, 线路id={},线路名字={}", xlid, xlname); | |
| 83 | + LOGGER.info("参数3, 时刻表id={},时刻表名字={}", ttid, ttname); | |
| 84 | + | |
| 85 | + LOGGER.info("转换xls文件格式成文本格式..."); | |
| 86 | + // 1、修改已经上传的excel文件,在每个起点站后标示数字,表示第几个班次 | |
| 87 | + // 2、由于格式问题,需要把内容都转换成字符串 | |
| 88 | + List<String> colList = new ArrayList<>(); | |
| 89 | + Workbook workbook = Workbook.getWorkbook(new File(filename)); | |
| 90 | + Sheet sheet = workbook.getSheet(sheetname); | |
| 91 | + Cell[] cells = sheet.getRow(0); | |
| 92 | + for (int i = 0; i < cells.length; i++) { | |
| 93 | + if (i == 0) { | |
| 94 | + colList.add(cells[i].getContents().trim()); | |
| 95 | + } else { | |
| 96 | + colList.add(cells[i].getContents() + i); | |
| 97 | + } | |
| 98 | + } | |
| 99 | + | |
| 100 | + File fileCal = new File(filename + "_stringType.xls"); | |
| 101 | + WritableWorkbook writableWorkbook = Workbook.createWorkbook(fileCal, workbook); | |
| 102 | + WritableSheet sheet1 = writableWorkbook.getSheet(sheetname); | |
| 103 | + for (int i = 0; i < sheet1.getColumns(); i++) { // 第一行数据 | |
| 104 | + sheet1.addCell(new Label(i, 0, colList.get(i))); | |
| 105 | + } | |
| 106 | + for (int i = 1; i < sheet1.getRows(); i++) { // 第二行开始 | |
| 107 | + Cell[] cells1 = sheet.getRow(i); | |
| 108 | + for (int j = 0; j < cells1.length; j++) { | |
| 109 | + sheet1.addCell(new Label(j, i, cells1[j].getContents())); | |
| 110 | + } | |
| 111 | + } | |
| 112 | + writableWorkbook.write(); | |
| 113 | + writableWorkbook.close(); | |
| 114 | + | |
| 115 | + // 2、删除原有数据 | |
| 116 | + // 操作在ktr内部执行 | |
| 117 | + | |
| 118 | + // 3、导入时刻表 | |
| 119 | + // 获取停车场名字 | |
| 120 | + LOGGER.info("获取停车场名字..."); | |
| 121 | + LineInformation lineInformation = lineInformationService.findById(lineid); | |
| 122 | + Map<String, Object> p1 = new HashMap<>(); | |
| 123 | + p1.put("parkCode_eq", lineInformation.getCarPark()); | |
| 124 | + List<CarPark> carParkList = (List<CarPark>) carParkService.list(p1); | |
| 125 | + String tccname = carParkList.get(0).getParkName(); | |
| 126 | + LOGGER.info("停车场名字={}", tccname); | |
| 127 | + | |
| 128 | + | |
| 129 | + // 计算表头参数 | |
| 130 | + Workbook book = Workbook.getWorkbook(fileCal); | |
| 131 | + Sheet sheet_exp = book.getSheet(sheetname); | |
| 132 | + List<String> columnames = new ArrayList<>(); | |
| 133 | + for (int i = 0; i < sheet_exp.getColumns(); i++) { // 获取第一行,数据,作为列名 | |
| 134 | + columnames.add(sheet_exp.getCell(i, 0).getContents()); | |
| 135 | + } | |
| 136 | + LOGGER.info("表头={}", StringUtils.join(columnames.toArray(), ",")); | |
| 137 | + | |
| 138 | + // 创建ktr转换所需参数 | |
| 139 | + Map<String, Object> ktrParms = new HashMap<>(); | |
| 140 | + File ktrFile = new File(this.getClass().getResource( | |
| 141 | + dataToolsProperties.getTtinfodetailMetadatainputktr()).toURI()); | |
| 142 | + File ktrFile2 = new File(this.getClass().getResource( | |
| 143 | + dataToolsProperties.getTtinfodetailDatainputktr()).toURI()); | |
| 144 | + | |
| 145 | + // 通用参数,转换文件路径,excel输入文件路径,错误输出文件路径 | |
| 146 | + ktrParms.put("transpath", ktrFile.getAbsolutePath()); | |
| 147 | + ktrParms.put("filepath", fileCal.getAbsolutePath()); | |
| 148 | + ktrParms.put("erroroutputdir", dataToolsProperties.getTransErrordir()); | |
| 149 | + | |
| 150 | + // 附加参数 | |
| 151 | + ktrParms.put("injectktrfile", ktrFile2.getAbsolutePath()); // 注入元数据的ktr文件 | |
| 152 | + ktrParms.put("sheetname", sheetname); // sheet工作区的名字 | |
| 153 | + ktrParms.put("xlname", xlname); // 线路名称 | |
| 154 | + ktrParms.put("ttinfoname", ttname); // 时刻表名称 | |
| 155 | + ktrParms.put("ttid", ttid.intValue()); // 时刻表id | |
| 156 | + ktrParms.put("tccname", tccname); // 停车场名字 | |
| 157 | + ktrParms.put("excelfieldnames", StringUtils.join(columnames.toArray(), ",")); // 时刻表excel输入字段名,以逗号连接 | |
| 158 | + columnames.remove(0); | |
| 159 | + ktrParms.put("normalizefieldnames", StringUtils.join(columnames.toArray(), ",")); // 数据范式化字段名,以逗号连接 | |
| 160 | + | |
| 161 | + super.importData(fileCal, ktrParms); | |
| 162 | + | |
| 163 | + LOGGER.info("//---------------- 导入时刻表明细 success... ----------------//"); | |
| 164 | + } catch (Exception exp) { | |
| 165 | + LOGGER.info("//---------------- 导入时刻表明细 failed... ----------------//"); | |
| 166 | + | |
| 167 | + StringWriter sw = new StringWriter(); | |
| 168 | + exp.printStackTrace(new PrintWriter(sw)); | |
| 169 | + LOGGER.info(sw.toString()); | |
| 170 | + | |
| 171 | + throw new ScheduleException(exp.getMessage()); | |
| 172 | + } | |
| 173 | + } | |
| 174 | + | |
| 175 | + @Override | |
| 176 | + public File exportData(Map<String, Object> params) throws ScheduleException { | |
| 177 | + try { | |
| 178 | + LOGGER.info("//---------------- 导出时刻表明细 start... ----------------//"); | |
| 179 | + | |
| 180 | + // 创建ktr转换所需参数 | |
| 181 | + Map<String, Object> ktrParms = new HashMap<>(); | |
| 182 | + File ktrFile = new File(this.getClass().getResource( | |
| 183 | + dataToolsProperties.getTtinfodetailMetaoutput()).toURI()); | |
| 184 | + File ktrFile2 = new File(this.getClass().getResource( | |
| 185 | + dataToolsProperties.getTtinfodetailOutput()).toURI()); | |
| 186 | + | |
| 187 | + // 通用参数,转换文件路径,excel输出文件名 | |
| 188 | + ktrParms.put("transpath", ktrFile.getAbsolutePath()); | |
| 189 | + ktrParms.put("filename", String.format("时刻表_(id=%s)_download-", String.valueOf(params.get("ttinfoid")))); | |
| 190 | + | |
| 191 | + // 附加参数 | |
| 192 | + ktrParms.put("injectktrfile", ktrFile2.getAbsolutePath()); // 注入元数据的ktr文件 | |
| 193 | + ktrParms.put("ttinfoid", String.valueOf(params.get("ttinfoid"))); | |
| 194 | + | |
| 195 | + File file = super.exportData(ktrParms); | |
| 196 | + | |
| 197 | + LOGGER.info("//---------------- 导出时刻表明细 success... ----------------//"); | |
| 198 | + | |
| 199 | + return file; | |
| 200 | + } catch (Exception exp) { | |
| 201 | + LOGGER.info("//---------------- 导出时刻表明细 failed... ----------------//"); | |
| 202 | + | |
| 203 | + StringWriter sw = new StringWriter(); | |
| 204 | + exp.printStackTrace(new PrintWriter(sw)); | |
| 205 | + LOGGER.info(sw.toString()); | |
| 206 | + | |
| 207 | + throw new ScheduleException(exp.getMessage()); | |
| 208 | + } | |
| 209 | + } | |
| 210 | + | |
| 211 | + @Override | |
| 212 | + public EditInfo getEditInfo(Integer xlid, Long ttid) throws ScheduleException { | |
| 213 | + try { | |
| 214 | + LOGGER.info("//---------------- 时刻表编辑用数据输出 start... ----------------//"); | |
| 215 | + | |
| 216 | + // 创建ktr转换所需参数 | |
| 217 | + Map<String, Object> ktrParms = new HashMap<>(); | |
| 218 | + File ktrFile = new File(this.getClass().getResource( | |
| 219 | + dataToolsProperties.getTtinfodetailForeditktr()).toURI()); | |
| 220 | + | |
| 221 | + // 通用参数,转换文件路径,excel输出文件名,错误输出文件路径 | |
| 222 | + ktrParms.put("transpath", ktrFile.getAbsolutePath()); | |
| 223 | + ktrParms.put("filename", "todo"); | |
| 224 | + | |
| 225 | + // 附加参数 | |
| 226 | + String outputFilePath = String.format("ttinfodetail_(id=%s)_foredit-%s", | |
| 227 | + String.valueOf(ttid), new DateTime().toString("yyyyMMddHHmmss")); | |
| 228 | + | |
| 229 | + ktrParms.put("tempfilepath", dataToolsProperties.getTransTempdir() + File.separator + outputFilePath); // 数据输出文件路径 | |
| 230 | + ktrParms.put("xlid", String.valueOf(xlid)); | |
| 231 | + ktrParms.put("ttid", String.valueOf(ttid)); | |
| 232 | + | |
| 233 | + super.exportData(ktrParms); | |
| 234 | + | |
| 235 | + // 1.6、获取最大的发车数,用于输出数据的数量 | |
| 236 | + Long maxfcno = ttInfoDetailRepository.findMaxFcno(xlid, ttid); | |
| 237 | + if (maxfcno == null) | |
| 238 | + return new EditInfo(); | |
| 239 | + | |
| 240 | + // 2、读取ktr生成的excel数据,组织编辑用数据返回 | |
| 241 | + // 2-1、读取Excel文件 | |
| 242 | + Workbook book = Workbook.getWorkbook(new File(dataToolsProperties.getTransTempdir() + | |
| 243 | + File.separator + outputFilePath + ".xls")); | |
| 244 | + Sheet sheet = book.getSheet(0); | |
| 245 | + EditInfo editInfo = new EditInfo(); | |
| 246 | + // 2-2、处理数据 | |
| 247 | + int all_bc = 0; // 总班次 | |
| 248 | + double all_lc_ks = 0; // 总空驶里程 | |
| 249 | + double all_lc_yy = 0; // 总营运里程 | |
| 250 | + | |
| 251 | + String[] headarrays = new String[maxfcno.intValue() + 3]; | |
| 252 | + headarrays[0] = "路牌"; | |
| 253 | + headarrays[maxfcno.intValue() + 1] = "空驶班次/空驶里程"; | |
| 254 | + headarrays[maxfcno.intValue() + 2] = "运营班次/运营里程"; | |
| 255 | + | |
| 256 | + for (int r = 1; r < sheet.getRows(); r++) { | |
| 257 | + List<FcInfo> fcInfos = new ArrayList<>(); | |
| 258 | + // 每行第一列都是路牌 | |
| 259 | + fcInfos.add(new FcInfo(null, null, sheet.getCell(0, r).getContents(), null, null)); // 用fcsj放置路牌显示 | |
| 260 | + | |
| 261 | + int bc_ks = 0; // 空驶班次 | |
| 262 | + int bc_yy = 0; // 营运班次 | |
| 263 | + double lc_ks = 0; // 空驶里程 | |
| 264 | + double lc_yy = 0; // 营运里程 | |
| 265 | + | |
| 266 | + for (int c = 1; c <= maxfcno * 7; ) { | |
| 267 | + String ttdid_str = sheet.getCell(c, r).getContents(); // 时刻表明细id | |
| 268 | + String fcsj = sheet.getCell(c + 1, r).getContents(); // 发车时间 | |
| 269 | + String jhlc = sheet.getCell(c + 2, r).getContents(); // 计划里程 | |
| 270 | + String fzdname = sheet.getCell(c + 3, r).getContents(); // 发车站点名称 | |
| 271 | + String bctype = sheet.getCell(c + 4, r).getContents(); // 班次类型 | |
| 272 | + String xldir = sheet.getCell(c + 5, r).getContents(); // 线路上下行 | |
| 273 | + String isfb = sheet.getCell(c + 6, r).getContents(); // 是否分班 | |
| 274 | + | |
| 275 | + FcInfo fcInfo = new FcInfo(ttdid_str, bctype, fcsj, xldir, isfb); | |
| 276 | + | |
| 277 | + if (StringUtils.isNotEmpty(fzdname)) | |
| 278 | + headarrays[(int)(c / 7) + 1] = fzdname; | |
| 279 | + fcInfos.add(fcInfo); | |
| 280 | + | |
| 281 | + c += 7; | |
| 282 | + | |
| 283 | + // 计算班次里程 | |
| 284 | + if (StringUtils.isNotEmpty(jhlc)) { | |
| 285 | + if ("in".equals(bctype) || "out".equals(bctype)) { | |
| 286 | + bc_ks += 1; | |
| 287 | + lc_ks += Double.valueOf(jhlc); | |
| 288 | + | |
| 289 | + all_bc += 1; | |
| 290 | + all_lc_ks += Double.valueOf(jhlc); | |
| 291 | + | |
| 292 | + } else { | |
| 293 | + bc_yy += 1; | |
| 294 | + lc_yy += Double.valueOf(jhlc); | |
| 295 | + | |
| 296 | + all_bc += 1; | |
| 297 | + all_lc_yy += Double.valueOf(jhlc); | |
| 298 | + } | |
| 299 | + } | |
| 300 | + | |
| 301 | + } | |
| 302 | + | |
| 303 | + // 添加一列 空驶班次/空驶里程,fcsj放置数据 | |
| 304 | + fcInfos.add(new FcInfo(null, null, String.format("%d/%.2f", bc_ks, lc_ks), null, null)); | |
| 305 | + | |
| 306 | + // 添加一列 营运班次/营运里程,fcsj放置数据 | |
| 307 | + fcInfos.add(new FcInfo(null, null, String.format("%d/%.2f", bc_yy, lc_yy), null, null)); | |
| 308 | + | |
| 309 | + editInfo.getContents().add(fcInfos); | |
| 310 | + } | |
| 311 | + editInfo.getHeader().addAll(Arrays.asList(headarrays)); | |
| 312 | + | |
| 313 | + editInfo.setYy_desc(String.format("班次=%d,空驶里程=%.2f,营运里程=%.2f", all_bc, all_lc_ks, all_lc_yy)); | |
| 314 | + | |
| 315 | + LOGGER.info("//---------------- 时刻表编辑用数据输出 success... ----------------//"); | |
| 316 | + | |
| 317 | + return editInfo; | |
| 318 | + } catch (Exception exp) { | |
| 319 | + LOGGER.info("//---------------- 时刻表编辑用数据输出 failed... ----------------//"); | |
| 320 | + | |
| 321 | + StringWriter sw = new StringWriter(); | |
| 322 | + exp.printStackTrace(new PrintWriter(sw)); | |
| 323 | + LOGGER.info(sw.toString()); | |
| 324 | + | |
| 325 | + throw new ScheduleException(exp.getMessage()); | |
| 326 | + } | |
| 327 | + } | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + @Override | |
| 332 | + public void validateExcelSheet(String filename, String sheetname, Integer lineid, String linename) throws ScheduleException { | |
| 333 | + try { | |
| 334 | + Workbook book = Workbook.getWorkbook(new File(filename)); | |
| 335 | + Sheet sheet = book.getSheet(sheetname); | |
| 336 | + if (sheet.getRows() == 0 || sheet.getColumns() == 0) { // 工作区是否为空 | |
| 337 | + throw new Exception(String.format("%s 工作区没有数据!", sheetname)); | |
| 338 | + } else { | |
| 339 | + if (sheet.getRows() <= 1 || sheet.getColumns() <= 1) { | |
| 340 | + throw new Exception(String.format("工作区至少包含2行2列的数据")); | |
| 341 | + } else { | |
| 342 | + Cell[] cells = sheet.getRow(0); // 获取第一行数据列 | |
| 343 | + for (int i = 0; i < cells.length; i++) { | |
| 344 | + String cell_con = cells[i].getContents(); | |
| 345 | + | |
| 346 | + if (StringUtils.isEmpty(cell_con)) { | |
| 347 | + throw new Exception(String.format("第1行,第%d列数据不能为空", i + 1)); | |
| 348 | + } else { | |
| 349 | + // 正则表达式去除数字 | |
| 350 | + cell_con = cell_con.replaceAll("[\\d+]", ""); | |
| 351 | + | |
| 352 | + if (i == 0) { // 第一列必须是路牌2个字 | |
| 353 | + if (!"路牌".equals(cell_con.trim())) { | |
| 354 | + throw new Exception("第1行,第1列数据必须是路牌2个字"); | |
| 355 | + } | |
| 356 | + } else { // 排除出场,进场,其余内容到站点路由里查询,以各个方向的起点站为查询依据 | |
| 357 | + if ((!"出场".equals(cell_con.trim())) && | |
| 358 | + (!"进场".equals(cell_con.trim()))) { | |
| 359 | + Map<String, Object> p1 = new HashMap<>(); | |
| 360 | + p1.put("line.id_eq", lineid); | |
| 361 | + p1.put("stationName_eq", cell_con.trim()); | |
| 362 | + p1.put("stationMark_eq", "B"); | |
| 363 | + | |
| 364 | + | |
| 365 | + // TODO:这里要修改(起点站有启用撤销的标志的) | |
| 366 | + | |
| 367 | + List<StationRoute> stationRouteList = (List<StationRoute>) stationRouteService.list(p1); | |
| 368 | + if (CollectionUtils.isEmpty(stationRouteList)) { | |
| 369 | + throw new Exception(String.format("第1行,第%d列数据%s在%s站点路由中不是起点站", i + 1, cell_con.trim(), linename)); | |
| 370 | + } else if (stationRouteList.size() > 1) { | |
| 371 | + throw new Exception(String.format("第1行,第%d列数据%s在%s站点路由中上下行都是起点站", i + 1, cell_con.trim(), linename)); | |
| 372 | + } | |
| 373 | + } | |
| 374 | + | |
| 375 | + } | |
| 376 | + } | |
| 377 | + } | |
| 378 | + | |
| 379 | + // 验证路牌内容 | |
| 380 | + Map<String, Integer> gbindexmap = new HashMap<>(); // 记录每个路牌在第几行 | |
| 381 | + for (int i = 1; i < sheet.getRows(); i++) { // 从第2行开始验证数据 | |
| 382 | + Cell bcell = sheet.getRow(i)[0]; // 获取第1列 | |
| 383 | + String bcell_con = bcell.getContents(); | |
| 384 | + if (StringUtils.isEmpty(bcell_con)) { | |
| 385 | + throw new Exception(String.format("第%d行,第1列路牌无数据", i + 1)); | |
| 386 | + } else if (gbindexmap.get(bcell_con.trim()) != null) { | |
| 387 | + throw new Exception(String.format("第%d行,第1列的路牌数据与第%d行,第1列数据重复", | |
| 388 | + i + 1, | |
| 389 | + gbindexmap.get(bcell_con.trim()))); | |
| 390 | + } else { | |
| 391 | + Map<String, Object> p2 = new HashMap<>(); | |
| 392 | + p2.put("xl.id_eq", lineid); | |
| 393 | + p2.put("lpName_eq", bcell_con.trim()); | |
| 394 | + List<GuideboardInfo> guideboardInfoList = (List<GuideboardInfo>) guideboardInfoService.list(p2); | |
| 395 | + if (CollectionUtils.isEmpty(guideboardInfoList)) { | |
| 396 | + throw new Exception(String.format("第%d行,第1列的路牌在%s中不存在", i + 1, linename)); | |
| 397 | + } else if (guideboardInfoList.size() > 1) { | |
| 398 | + throw new Exception(String.format("第%d行,第1列的路牌在%s中重复", i + 1, linename)); | |
| 399 | + } else { | |
| 400 | + gbindexmap.put(bcell_con.trim(), i + 1); | |
| 401 | + } | |
| 402 | + } | |
| 403 | + } | |
| 404 | + | |
| 405 | + // 班次时间验证,正则表达式,格式hh:mm或者hhmm | |
| 406 | + String el = "^(([0-1]\\d)|(2[0-4])):[0-5]\\d$"; // hh:mm格式 | |
| 407 | + String el2 = "^(([0-1]\\d)|(2[0-4]))[0-5]\\d$"; // hhmm格式 | |
| 408 | + Pattern p = Pattern.compile(el); | |
| 409 | + Pattern p2 = Pattern.compile(el2); | |
| 410 | + | |
| 411 | + for (int i = 1; i < sheet.getRows(); i++) { // 从第2行开始验证数据 | |
| 412 | + Cell[] bcells = sheet.getRow(i); | |
| 413 | + for (int j = 1; j < bcells.length; j++) { // 从第2列开始 | |
| 414 | + String bcell_con = bcells[j].getContents(); | |
| 415 | + if (StringUtils.isNotEmpty(bcell_con)) { | |
| 416 | + Matcher m = p.matcher(bcell_con.trim()); | |
| 417 | + Matcher m2 = p2.matcher(bcell_con.trim()); | |
| 418 | + if ((!m.matches()) && (!m2.matches())) { | |
| 419 | + throw new Exception(String.format("第%d行,第%d列的发车时间格式不正确,格式应为hh:mm或hhmm", i + 1, j + 1)); | |
| 420 | + } | |
| 421 | + } | |
| 422 | + } | |
| 423 | + } | |
| 424 | + } | |
| 425 | + | |
| 426 | + } | |
| 427 | + } catch (Exception exp) { | |
| 428 | + throw new ScheduleException(exp.getMessage()); | |
| 429 | + } | |
| 430 | + | |
| 431 | + } | |
| 432 | + | |
| 433 | + @Override | |
| 434 | + public void validateAssoLineInfo(Integer lineinfoid) throws ScheduleException { | |
| 435 | + LineInformation lineInformation = lineInformationService.findById(lineinfoid); | |
| 436 | + if (lineInformation.getUpInMileage() == null) { | |
| 437 | + throw new ScheduleException("上行进场里程为空"); | |
| 438 | + } else if (lineInformation.getUpInTimer() == null) { | |
| 439 | + throw new ScheduleException("上行进场时间为空"); | |
| 440 | + } else if (lineInformation.getUpOutMileage() == null) { | |
| 441 | + throw new ScheduleException("上行出场里程为空"); | |
| 442 | + } else if (lineInformation.getUpOutTimer() == null) { | |
| 443 | + throw new ScheduleException("上行出场时间为空"); | |
| 444 | + } else if (lineInformation.getUpMileage() == null) { | |
| 445 | + throw new ScheduleException("上行班次里程为空"); | |
| 446 | + } else if (lineInformation.getUpTravelTime() == null) { | |
| 447 | + throw new ScheduleException("上行班次时间为空"); | |
| 448 | + } else if (lineInformation.getDownInMileage() == null) { | |
| 449 | + throw new ScheduleException("下行进场里程为空"); | |
| 450 | + } else if (lineInformation.getDownInTimer() == null) { | |
| 451 | + throw new ScheduleException("下行进场时间为空"); | |
| 452 | + } else if (lineInformation.getDownOutMileage() == null) { | |
| 453 | + throw new ScheduleException("下行出场里程为空"); | |
| 454 | + } else if (lineInformation.getDownOutTimer() == null) { | |
| 455 | + throw new ScheduleException("下行出场时间为空"); | |
| 456 | + } else if (lineInformation.getDownMileage() == null) { | |
| 457 | + throw new ScheduleException("下行班次里程为空"); | |
| 458 | + } else if (lineInformation.getDownTravelTime() == null) { | |
| 459 | + throw new ScheduleException("下行班次时间为空"); | |
| 460 | + } else if (StringUtils.isEmpty(lineInformation.getCarPark())) { | |
| 461 | + throw new ScheduleException("停车场必须选择"); | |
| 462 | + } | |
| 463 | + | |
| 464 | + // 单独验证停车场信息 | |
| 465 | + String tcccode = lineInformation.getCarPark(); | |
| 466 | + Map<String, Object> p1 = new HashMap<>(); | |
| 467 | + p1.put("parkCode_eq", tcccode); | |
| 468 | + List<CarPark> carParkList = (List<CarPark>) carParkService.list(p1); | |
| 469 | + if (CollectionUtils.isEmpty(carParkList)) { | |
| 470 | + throw new ScheduleException(String.format("线路标准里的停车场code=%s,在停车场信息中未找到", tcccode)); | |
| 471 | + } else if (carParkList.size() > 1) { | |
| 472 | + throw new ScheduleException(String.format("线路标准里的停车场code=%s,在停车场信息中有重复数据", tcccode)); | |
| 473 | + } else { | |
| 474 | + CarPark carPark = carParkList.get(0); | |
| 475 | + if (StringUtils.isEmpty(carPark.getParkName())) { | |
| 476 | + throw new ScheduleException(String.format("线路标准里的停车场code=%s,在停车场信息中没有停车场名字", tcccode)); | |
| 477 | + } | |
| 478 | + } | |
| 479 | + | |
| 480 | + } | |
| 481 | + | |
| 482 | + @Override | |
| 483 | + public List<TTInfoDetail> findBcdetails(Integer xlId, Long ttinfoId, Long lpId) { | |
| 484 | + return ttInfoDetailRepository.findBcdetails(xlId, ttinfoId, lpId); | |
| 485 | + } | |
| 486 | +} | ... | ... |
src/main/java/com/bsth/service/schedule/impl/TTInfoServiceImpl.java
| 1 | 1 | package com.bsth.service.schedule.impl; |
| 2 | 2 | |
| 3 | 3 | import com.bsth.entity.schedule.TTInfo; |
| 4 | -import com.bsth.service.schedule.ScheduleException; | |
| 4 | +import com.bsth.service.schedule.exception.ScheduleException; | |
| 5 | 5 | import com.bsth.service.schedule.TTInfoService; |
| 6 | 6 | import org.apache.commons.lang3.StringUtils; |
| 7 | 7 | import org.springframework.stereotype.Service; | ... | ... |
src/main/java/com/bsth/service/schedule/utils/DataToolsService.java
0 → 100644
| 1 | +package com.bsth.service.schedule.utils; | |
| 2 | + | |
| 3 | +import com.bsth.service.schedule.exception.ScheduleException; | |
| 4 | + | |
| 5 | +import java.io.File; | |
| 6 | +import java.util.Map; | |
| 7 | + | |
| 8 | +/** | |
| 9 | + * 数据服务接口。 | |
| 10 | + */ | |
| 11 | +public interface DataToolsService { | |
| 12 | + //----------------- 数据服务操作 --------------// | |
| 13 | + // 上传文件 | |
| 14 | + File uploadFile(String filename, byte[] filedata) throws ScheduleException; | |
| 15 | + // 导入数据 | |
| 16 | + void importData(File file, Map<String, Object> params) throws ScheduleException; | |
| 17 | + // 导出数据 | |
| 18 | + File exportData(Map<String, Object> params) throws ScheduleException; | |
| 19 | +} | ... | ... |
src/main/java/com/bsth/service/schedule/utils/DataToolsServiceImpl.java
0 → 100644
| 1 | +package com.bsth.service.schedule.utils; | |
| 2 | + | |
| 3 | +import com.bsth.service.schedule.exception.ScheduleException; | |
| 4 | +import com.google.common.io.Files; | |
| 5 | +import org.apache.tika.Tika; | |
| 6 | +import org.joda.time.DateTime; | |
| 7 | +import org.pentaho.di.core.KettleEnvironment; | |
| 8 | +import org.pentaho.di.core.logging.KettleLogStore; | |
| 9 | +import org.pentaho.di.core.logging.LoggingBuffer; | |
| 10 | +import org.pentaho.di.core.logging.LoggingRegistry; | |
| 11 | +import org.pentaho.di.core.util.EnvUtil; | |
| 12 | +import org.pentaho.di.trans.Trans; | |
| 13 | +import org.pentaho.di.trans.TransMeta; | |
| 14 | +import org.slf4j.Logger; | |
| 15 | +import org.slf4j.LoggerFactory; | |
| 16 | +import org.springframework.beans.factory.InitializingBean; | |
| 17 | +import org.springframework.beans.factory.annotation.Autowired; | |
| 18 | +import org.springframework.boot.context.properties.EnableConfigurationProperties; | |
| 19 | +import org.springframework.stereotype.Service; | |
| 20 | + | |
| 21 | +import java.io.File; | |
| 22 | +import java.io.PrintWriter; | |
| 23 | +import java.io.StringWriter; | |
| 24 | +import java.util.HashMap; | |
| 25 | +import java.util.Map; | |
| 26 | +import java.util.Properties; | |
| 27 | + | |
| 28 | +/** | |
| 29 | + * Created by xu on 17/1/3. | |
| 30 | + */ | |
| 31 | +@Service | |
| 32 | +@EnableConfigurationProperties(DataToolsProperties.class) | |
| 33 | +public class DataToolsServiceImpl implements DataToolsService, InitializingBean { | |
| 34 | + /** 日志记录器 */ | |
| 35 | + private static final Logger LOGGER = LoggerFactory.getLogger(DataToolsServiceImpl.class); | |
| 36 | + | |
| 37 | + @Autowired | |
| 38 | + private DataToolsProperties dataToolsProperties; | |
| 39 | + | |
| 40 | + /** | |
| 41 | + * 自定义kettle环境初始化定义。 | |
| 42 | + */ | |
| 43 | + private void ktrEnvironmentInit() throws Exception { | |
| 44 | + // 由于kettle.properties可能没有(没有安装过kettle), | |
| 45 | + // 导致 EnvUtil.environmentInit() 报找不到kettle.properties文件 | |
| 46 | + // 所以这里重写 EnvUtil.environmentInit() 方法 | |
| 47 | + | |
| 48 | + if (Thread.currentThread().getContextClassLoader() == null) { | |
| 49 | + Thread.currentThread().setContextClassLoader(ClassLoader.getSystemClassLoader()); | |
| 50 | + } | |
| 51 | + | |
| 52 | + // 获取配置文件 | |
| 53 | + File file = new File(getClass().getResource(dataToolsProperties.getKettleProperties()).toURI()); | |
| 54 | + Properties kettleProperties = EnvUtil.readProperties(file.getAbsolutePath()); | |
| 55 | + EnvUtil.applyKettleProperties(kettleProperties); | |
| 56 | + System.getProperties().put("Internal.Cluster.Size", "1"); | |
| 57 | + System.getProperties().put("Internal.Slave.Transformation.Number", "0"); | |
| 58 | + System.getProperties().put("Internal.Slave.Server.Name", "slave-trans-name"); | |
| 59 | + System.getProperties().put("Internal.Step.CopyNr", "0"); | |
| 60 | + System.getProperties().put("Internal.Step.Name", "step-name"); | |
| 61 | + System.getProperties().put("Internal.Step.Partition.ID", "partition-id"); | |
| 62 | + System.getProperties().put("Internal.Step.Partition.Number", "0"); | |
| 63 | + System.getProperties().put("Internal.Step.Unique.Count", "1"); | |
| 64 | + System.getProperties().put("Internal.Step.Unique.Number", "0"); | |
| 65 | + if (!kettleProperties.containsKey("vfs.sftp.org.apache.commons.vfs2.provider.sftp.SftpFileSystemConfigBuilder.USER_DIR_IS_ROOT")) { | |
| 66 | + System.getProperties().put("vfs.sftp.org.apache.commons.vfs2.provider.sftp.SftpFileSystemConfigBuilder.USER_DIR_IS_ROOT", "false"); | |
| 67 | + } | |
| 68 | + | |
| 69 | + } | |
| 70 | + | |
| 71 | + @Override | |
| 72 | + public void afterPropertiesSet() throws Exception { | |
| 73 | + // 初始化kettle环境(自定义) | |
| 74 | + ktrEnvironmentInit(); | |
| 75 | + | |
| 76 | + // 添加全局ktr变量,并覆盖原来的设置 | |
| 77 | + Map<String, String> kvars = new HashMap<>(); | |
| 78 | + kvars.put("v_db_ip", dataToolsProperties.getKvarsDbip()); | |
| 79 | + kvars.put("v_db_uname", dataToolsProperties.getKvarsDbuname()); | |
| 80 | + kvars.put("v_db_pwd", dataToolsProperties.getKvarsDbpwd()); | |
| 81 | + kvars.put("v_db_dname", dataToolsProperties.getKvarsDbdname()); | |
| 82 | + EnvUtil.applyKettleProperties(kvars, true); | |
| 83 | + KettleEnvironment.init(); | |
| 84 | + } | |
| 85 | + | |
| 86 | + @Override | |
| 87 | + public File uploadFile(String filename, byte[] filedata) throws ScheduleException { | |
| 88 | + // 上传文件 | |
| 89 | + try { | |
| 90 | + LOGGER.info("start uploadFile...originalFilename={}", filename); | |
| 91 | + File newFile = new File(dataToolsProperties.getFileuploadDir() + File.separator + | |
| 92 | + filename + "-upload-" + new DateTime().toString("yyyyMMddHHmmss") + ".xls"); | |
| 93 | + // TODO:判定是否excel数据 | |
| 94 | + Tika tika = new Tika(); | |
| 95 | + String type = tika.detect(filedata); | |
| 96 | + // application/x-tika-msoffice | |
| 97 | + LOGGER.info("文件格式={}", type); | |
| 98 | + if ("application/vnd.ms-excel".equals(type) || "application/x-tika-msoffice".equals(type)) { | |
| 99 | + // .xls 2007的格式 | |
| 100 | + Files.write(filedata, newFile); | |
| 101 | + } else if ("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet".equals(type)) { | |
| 102 | + // .xlsx 2007之后的格式 | |
| 103 | + throw new Exception("暂时不支持.xlsx格式文件!"); | |
| 104 | + } else { | |
| 105 | + // 非excel文件 | |
| 106 | + throw new Exception("非.xls格式文件!"); | |
| 107 | + } | |
| 108 | + | |
| 109 | + LOGGER.info("uploadFile success...newFilename={}", newFile.getAbsolutePath()); | |
| 110 | + | |
| 111 | + return newFile; | |
| 112 | + } catch (Exception exp) { | |
| 113 | + LOGGER.info("uploadFile failed...stackTrace..."); | |
| 114 | + | |
| 115 | + StringWriter sw = new StringWriter(); | |
| 116 | + exp.printStackTrace(new PrintWriter(sw)); | |
| 117 | + LOGGER.info(sw.toString()); | |
| 118 | + | |
| 119 | + throw new ScheduleException("上传文件错误!"); | |
| 120 | + } | |
| 121 | + } | |
| 122 | + | |
| 123 | + @Override | |
| 124 | + public void importData(File file, Map<String, Object> params) throws ScheduleException { | |
| 125 | + // 导入数据 | |
| 126 | + String transLogId = ""; | |
| 127 | + String transMetaLogId = ""; | |
| 128 | + try { | |
| 129 | + LOGGER.info("start importData...originalFilename={}", file.getAbsolutePath()); | |
| 130 | + // 检查参数 | |
| 131 | + String transpath = String.valueOf(params.get("transpath")); | |
| 132 | + if ("null".equals(transpath)) { | |
| 133 | + throw new Exception( | |
| 134 | + "没有指定transpath参数值,无法确定ktr转换文件!"); | |
| 135 | + } | |
| 136 | + File ktrFile = new File(transpath); | |
| 137 | + // 设置文件路径,错误输出文件路径参数 | |
| 138 | + params.put("filepath", file.getAbsolutePath()); | |
| 139 | + params.put("erroroutputdir", dataToolsProperties.getTransErrordir()); | |
| 140 | + | |
| 141 | + // 2、使用kettle运行封装数据导入逻辑的ktr转换文件 | |
| 142 | + // 2.1、初始化kettle(组件初始化已经做了) | |
| 143 | + // 2.2、创建转换元数据,转换 | |
| 144 | + TransMeta transMeta = new TransMeta(ktrFile.getAbsolutePath()); | |
| 145 | + Trans trans = new Trans(transMeta); | |
| 146 | + // 2.3、设定命名参数,用于指定数据文件,注意每个ktr必须都有以下指定的命名参数 | |
| 147 | + for (String key : params.keySet()) { | |
| 148 | + trans.setParameterValue(key, String.valueOf(params.get(key))); | |
| 149 | + } | |
| 150 | + // 2.4、执行转换 | |
| 151 | + trans.execute(null); | |
| 152 | + // 2.5、等待转换结束 | |
| 153 | + trans.waitUntilFinished(); | |
| 154 | + | |
| 155 | + // 获取日志 | |
| 156 | + transLogId = trans.getLogChannelId(); | |
| 157 | + transMetaLogId = transMeta.getLogChannelId(); | |
| 158 | + | |
| 159 | + LoggingBuffer loggingBuffer = KettleLogStore.getAppender(); | |
| 160 | + StringBuffer stringBuffer = loggingBuffer.getBuffer( | |
| 161 | + trans.getLogChannelId(), false | |
| 162 | + ); | |
| 163 | + if (trans.getErrors() > 0) { | |
| 164 | + throw new Exception(stringBuffer.toString()); | |
| 165 | + } | |
| 166 | + LOGGER.info(stringBuffer.toString()); | |
| 167 | + LOGGER.info("importData success..."); | |
| 168 | + | |
| 169 | + } catch (Exception exp) { | |
| 170 | + LOGGER.info("importData failed...statckTrace..."); | |
| 171 | + | |
| 172 | + StringWriter sw = new StringWriter(); | |
| 173 | + exp.printStackTrace(new PrintWriter(sw)); | |
| 174 | + LOGGER.info(sw.toString()); | |
| 175 | + | |
| 176 | + throw new ScheduleException("导入数据错误!"); | |
| 177 | + } finally { | |
| 178 | + // 清除日志操作 | |
| 179 | + KettleLogStore.discardLines(transLogId, true); | |
| 180 | + KettleLogStore.discardLines(transMetaLogId, true); | |
| 181 | + LoggingRegistry.getInstance().removeIncludingChildren(transLogId); | |
| 182 | + } | |
| 183 | + } | |
| 184 | + | |
| 185 | + @Override | |
| 186 | + public File exportData(Map<String, Object> params) throws ScheduleException { | |
| 187 | + // 导出数据 | |
| 188 | + String transLogId = ""; | |
| 189 | + String transMetaLogId = ""; | |
| 190 | + try { | |
| 191 | + LOGGER.info("start exportData..."); | |
| 192 | + // 检查参数 | |
| 193 | + String filename = String.valueOf(params.get("filename")); | |
| 194 | + if ("null".equals(filename)) { | |
| 195 | + filename = "temp"; | |
| 196 | + } | |
| 197 | + String transpath = String.valueOf(params.get("transpath")); | |
| 198 | + if ("null".equals(transpath)) { | |
| 199 | + throw new Exception( | |
| 200 | + "没有指定transpath参数值,无法确定ktr转换文件!"); | |
| 201 | + } | |
| 202 | + File ktrFile = new File(transpath); | |
| 203 | + // 设置文件路径参数 | |
| 204 | + String filepath = dataToolsProperties.getFileoutputDir() + | |
| 205 | + File.separator + | |
| 206 | + filename + | |
| 207 | + new DateTime().toString("yyyyMMddHHmmss") + ".xls"; | |
| 208 | + params.put("filepath", filepath); | |
| 209 | + | |
| 210 | + // 2、使用kettle运行封装数据导入逻辑的ktr转换文件 | |
| 211 | + // 2.1、初始化kettle(组件初始化已经做了) | |
| 212 | + // 2.2、创建转换元数据,转换 | |
| 213 | + TransMeta transMeta = new TransMeta(ktrFile.getAbsolutePath()); | |
| 214 | + Trans trans = new Trans(transMeta); | |
| 215 | + // 2.3、设定命名参数,用于指定数据文件,注意每个ktr必须都有以下指定的命名参数 | |
| 216 | + for (String key : params.keySet()) { | |
| 217 | + trans.setParameterValue(key, String.valueOf(params.get(key))); | |
| 218 | + } | |
| 219 | + // 2.4、执行转换 | |
| 220 | + trans.execute(null); | |
| 221 | + // 2.5、等待转换结束 | |
| 222 | + trans.waitUntilFinished(); | |
| 223 | + | |
| 224 | + // 获取日志 | |
| 225 | + transLogId = trans.getLogChannelId(); | |
| 226 | + transMetaLogId = transMeta.getLogChannelId(); | |
| 227 | + | |
| 228 | + LoggingBuffer loggingBuffer = KettleLogStore.getAppender(); | |
| 229 | + StringBuffer stringBuffer = loggingBuffer.getBuffer( | |
| 230 | + trans.getLogChannelId(), false | |
| 231 | + ); | |
| 232 | + if (trans.getErrors() > 0) { | |
| 233 | + throw new Exception(stringBuffer.toString()); | |
| 234 | + } | |
| 235 | + LOGGER.info(stringBuffer.toString()); | |
| 236 | + LOGGER.info("exportData success..."); | |
| 237 | + | |
| 238 | + return new File(filepath); | |
| 239 | + } catch (Exception exp) { | |
| 240 | + LOGGER.info("exportData failed...statckTrace..."); | |
| 241 | + | |
| 242 | + StringWriter sw = new StringWriter(); | |
| 243 | + exp.printStackTrace(new PrintWriter(sw)); | |
| 244 | + LOGGER.info(sw.toString()); | |
| 245 | + | |
| 246 | + throw new ScheduleException("导出数据错误!"); | |
| 247 | + } finally { | |
| 248 | + // 清除日志操作 | |
| 249 | + KettleLogStore.discardLines(transLogId, true); | |
| 250 | + KettleLogStore.discardLines(transMetaLogId, true); | |
| 251 | + LoggingRegistry.getInstance().removeIncludingChildren(transLogId); | |
| 252 | + } | |
| 253 | + } | |
| 254 | +} | ... | ... |
src/main/java/com/bsth/service/sys/DutyEmployeeService.java
0 → 100644
| 1 | +package com.bsth.service.sys; | |
| 2 | + | |
| 3 | +import com.bsth.entity.sys.DutyEmployee; | |
| 4 | +import com.bsth.service.BaseService; | |
| 5 | + | |
| 6 | +import java.util.List; | |
| 7 | + | |
| 8 | +/** | |
| 9 | + * Created by panzhao on 2017/1/5. | |
| 10 | + */ | |
| 11 | +public interface DutyEmployeeService extends BaseService<DutyEmployee, Long> { | |
| 12 | + | |
| 13 | + List<DutyEmployee> getDutyEmployee(String lineCode, String startTime, String endTime); | |
| 14 | +} | ... | ... |
src/main/java/com/bsth/service/sys/impl/DutyEmployeeServiceImpl.java
0 → 100644
| 1 | +package com.bsth.service.sys.impl; | |
| 2 | + | |
| 3 | +import com.bsth.entity.sys.DutyEmployee; | |
| 4 | +import com.bsth.repository.sys.DutyEmployeeRepository; | |
| 5 | +import com.bsth.service.impl.BaseServiceImpl; | |
| 6 | +import com.bsth.service.sys.DutyEmployeeService; | |
| 7 | +import org.joda.time.format.DateTimeFormat; | |
| 8 | +import org.joda.time.format.DateTimeFormatter; | |
| 9 | +import org.springframework.beans.factory.annotation.Autowired; | |
| 10 | +import org.springframework.stereotype.Service; | |
| 11 | + | |
| 12 | +import java.util.List; | |
| 13 | +import java.util.Map; | |
| 14 | + | |
| 15 | +/** | |
| 16 | + * Created by panzhao on 2017/1/5. | |
| 17 | + */ | |
| 18 | +@Service | |
| 19 | +public class DutyEmployeeServiceImpl extends BaseServiceImpl<DutyEmployee, Long> implements DutyEmployeeService { | |
| 20 | + | |
| 21 | + @Autowired | |
| 22 | + DutyEmployeeRepository dutyEmployeeRepository; | |
| 23 | + | |
| 24 | + @Override | |
| 25 | + public Map<String, Object> save(DutyEmployee dutyEmployee) { | |
| 26 | + //登入时间,当前时间 - 10分钟 | |
| 27 | + dutyEmployee.setTs(System.currentTimeMillis() - (1000 * 60 * 10)); | |
| 28 | + return super.save(dutyEmployee); | |
| 29 | + } | |
| 30 | + | |
| 31 | + | |
| 32 | + /** | |
| 33 | + * 获取当班调度 | |
| 34 | + * | |
| 35 | + * @param lineCode 线路编码 | |
| 36 | + * @param startTime 开始时间 yyyy-MM-ddHH:mm | |
| 37 | + * @param endTime 结束时间 yyyy-MM-ddHH:mm | |
| 38 | + * @return | |
| 39 | + */ | |
| 40 | + public List<DutyEmployee> getDutyEmployee(String lineCode, String startTime, String endTime) { | |
| 41 | + DateTimeFormatter fmtyyyyMMddHHmm = DateTimeFormat.forPattern("yyyy-MM-ddHH:mm"); | |
| 42 | + return dutyEmployeeRepository.findByLineAndTime(lineCode + ",", fmtyyyyMMddHHmm.parseMillis(startTime), fmtyyyyMMddHHmm.parseMillis(endTime)); | |
| 43 | + } | |
| 44 | +} | ... | ... |