Commit 403100481006828dfa372af41204cfbba7dff560

Authored by 廖磊
2 parents 439fe480 324c6bd8

Merge branch 'minhang' of

http://222.66.0.204:8090/panzhaov5/bsth_control into minhang
src/main/java/com/bsth/controller/realcontrol/summary/FastAndSlowController.java
... ... @@ -2,9 +2,16 @@ package com.bsth.controller.realcontrol.summary;
2 2  
3 3 import com.bsth.controller.BaseController;
4 4 import com.bsth.data.summary.entity.FastAndSlow;
  5 +import com.bsth.data.summary.service.FastAndSlowService;
  6 +import org.springframework.beans.factory.annotation.Autowired;
  7 +import org.springframework.web.bind.annotation.PathVariable;
5 8 import org.springframework.web.bind.annotation.RequestMapping;
  9 +import org.springframework.web.bind.annotation.RequestParam;
6 10 import org.springframework.web.bind.annotation.RestController;
7 11  
  12 +import javax.servlet.http.HttpServletRequest;
  13 +import javax.servlet.http.HttpServletResponse;
  14 +
8 15 /**
9 16 * 快慢误点统计
10 17 * Created by panzhao on 2017/10/24.
... ... @@ -12,4 +19,13 @@ import org.springframework.web.bind.annotation.RestController;
12 19 @RestController
13 20 @RequestMapping("/summary/fastAndSlow")
14 21 public class FastAndSlowController extends BaseController<FastAndSlow, Long> {
15   -}
  22 +
  23 + @Autowired
  24 + FastAndSlowService fastAndSlowService;
  25 +
  26 + @RequestMapping("/excel/{lineCode}")
  27 + public void excel(@PathVariable("lineCode") String lineCode, @RequestParam String st
  28 + , @RequestParam String et, @RequestParam int type, HttpServletRequest request, HttpServletResponse response) {
  29 + fastAndSlowService.excel(lineCode, st, et, type, request, response);
  30 + }
  31 +}
16 32 \ No newline at end of file
... ...
src/main/java/com/bsth/data/schedule/late_adjust/LateAdjustHandle.java
... ... @@ -135,6 +135,12 @@ public class LateAdjustHandle implements ApplicationContextAware{
135 135 if(sch == null)
136 136 return;
137 137  
  138 + //可能是延迟信号,gps时间没有误点
  139 + if(gps.getTimestamp() <= sch.getDfsjT()){
  140 + sch.setLate2(false);
  141 + lateSchMap.remove(sch.getClZbh());
  142 + return;
  143 + }
138 144 //进的是班次起点(名称一样即可)
139 145 gps.setStationName(BasicData.stationCode2NameMap.get(gps.getLineId() + "_" + gps.getUpDown() + "_" + gps.getStopNo()));
140 146 if(gps.getStationName().equals(sch.getQdzName())
... ...
src/main/java/com/bsth/data/summary/entity/FastAndSlow.java
... ... @@ -273,4 +273,12 @@ public class FastAndSlow {
273 273 public void setT(Long t) {
274 274 this.t = t;
275 275 }
276   -}
  276 +
  277 + public boolean isSlow() {
  278 + return this.fcsjSlow>0 || this.dfsjSlow>0 || this.zdsjSlow>0 || this.zdsjDfSlow>0;
  279 + }
  280 +
  281 + public boolean isFast() {
  282 + return this.fcsjFast>0 || this.dfsjFast>0 || this.zdsjFast>0 || this.zdsjDfFast>0;
  283 + }
  284 +}
277 285 \ No newline at end of file
... ...
src/main/java/com/bsth/data/summary/service/FastAndSlowService.java
... ... @@ -3,8 +3,12 @@ package com.bsth.data.summary.service;
3 3 import com.bsth.data.summary.entity.FastAndSlow;
4 4 import com.bsth.service.BaseService;
5 5  
  6 +import javax.servlet.http.HttpServletRequest;
  7 +import javax.servlet.http.HttpServletResponse;
  8 +
6 9 /**
7 10 * Created by panzhao on 2017/10/24.
8 11 */
9 12 public interface FastAndSlowService extends BaseService<FastAndSlow, Long>{
10   -}
  13 + void excel(String lineCode, String st, String et, int type, HttpServletRequest request, HttpServletResponse response);
  14 +}
11 15 \ No newline at end of file
... ...
src/main/java/com/bsth/data/summary/service/impl/FastAndSlowServiceImpl.java
1 1 package com.bsth.data.summary.service.impl;
2 2  
  3 +import com.bsth.data.BasicData;
3 4 import com.bsth.data.summary.entity.FastAndSlow;
4 5 import com.bsth.data.summary.service.FastAndSlowService;
  6 +import com.bsth.data.utils.ConvertUtil;
5 7 import com.bsth.service.impl.BaseServiceImpl;
  8 +import com.google.common.collect.ArrayListMultimap;
  9 +import org.apache.poi.hssf.usermodel.HSSFWorkbook;
  10 +import org.apache.poi.poifs.filesystem.POIFSFileSystem;
  11 +import org.apache.poi.ss.usermodel.Row;
  12 +import org.apache.poi.ss.usermodel.Sheet;
  13 +import org.apache.poi.ss.util.CellRangeAddress;
  14 +import org.joda.time.format.DateTimeFormat;
  15 +import org.joda.time.format.DateTimeFormatter;
  16 +import org.slf4j.Logger;
  17 +import org.slf4j.LoggerFactory;
6 18 import org.springframework.stereotype.Service;
7 19  
  20 +import javax.servlet.http.HttpServletRequest;
  21 +import javax.servlet.http.HttpServletResponse;
  22 +import java.io.FileInputStream;
  23 +import java.io.OutputStream;
  24 +import java.net.URLEncoder;
  25 +import java.text.ParseException;
  26 +import java.text.SimpleDateFormat;
  27 +import java.util.*;
  28 +
8 29 /**
9 30 * Created by panzhao on 2017/10/24.
10 31 */
11 32 @Service
12 33 public class FastAndSlowServiceImpl extends BaseServiceImpl<FastAndSlow, Long> implements FastAndSlowService {
13   -}
  34 +
  35 + Logger logger = LoggerFactory.getLogger(this.getClass());
  36 +
  37 + private static DateTimeFormatter fmtyyyyMMdd = DateTimeFormat.forPattern("yyyy-MM-dd");
  38 +
  39 + @Override
  40 + public Iterable<FastAndSlow> list(Map<String, Object> map) {
  41 + try {
  42 + //最多5天
  43 + map.put("rq_le", maxEndTime(map.get("rq_ge").toString()
  44 + , map.get("rq_le").toString(), 5));
  45 +
  46 + List<FastAndSlow> list = (List) super.list(map);
  47 + String type = String.valueOf(map.get("type"));
  48 +
  49 + return filterByType(list, type);
  50 + } catch (Exception e) {
  51 + logger.error("", e);
  52 + }
  53 + return null;
  54 + }
  55 +
  56 + @Override
  57 + public void excel(String lineCode, String st, String et, int type, HttpServletRequest request, HttpServletResponse response) {
  58 + try {
  59 + Map<String, Object> params = new HashMap();
  60 + //最多31天
  61 + et = maxEndTime(st, et, 31);
  62 + params.put("rq_ge", st);
  63 + params.put("rq_le", et);
  64 + params.put("lineCode_eq", lineCode);
  65 + List<FastAndSlow> list = filterByType((List) super.list(params), type + "");
  66 +
  67 + if(list.size() == 0){
  68 + response.setHeader("Content-type", "text/html;charset=UTF-8");
  69 + response.getWriter().print("<span style='color:red;font-size:24px;'>根据查询条件没有搜索到数据,别导了!</span>");
  70 + return ;
  71 + }
  72 + //排序
  73 + Collections.sort(list, new Comparator<FastAndSlow>() {
  74 + @Override
  75 + public int compare(FastAndSlow fas1, FastAndSlow fas2) {
  76 + return (int) (fas1.getT() - fas2.getT());
  77 + }
  78 + });
  79 + //按日期分组
  80 + ArrayListMultimap<String, FastAndSlow> multimap =
  81 + new ConvertUtil<FastAndSlow>().groupMultiList(list, "_", FastAndSlow.class.getDeclaredField("rq"));
  82 + //输出excel
  83 + String basePath = Thread.currentThread().getContextClassLoader().getResource("").getPath();
  84 + String filePath = basePath + "/static/pages/summary/excel/快慢误点报表.xls";
  85 + POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream(filePath));
  86 + HSSFWorkbook wb = new HSSFWorkbook(fs);
  87 +
  88 + //写入数据
  89 + List<String> ks = new ArrayList<>(multimap.keySet());
  90 + Collections.sort(ks);
  91 + for(int i = 0; i < ks.size(); i++){
  92 + Sheet sheet = wb.getSheetAt(i);
  93 + writeData(sheet, multimap.get(ks.get(i)));
  94 + //sheet name
  95 + wb.setSheetName(i, ks.get(i));
  96 + }
  97 + //删除多余的sheet
  98 + for(int i = ks.size(); i <31; i++){
  99 + wb.removeSheetAt(ks.size());
  100 + }
  101 +
  102 + //response 输出
  103 + String filename = BasicData.lineCode2NameMap.get(lineCode) + st + "至" + et + "快慢误点明细.xls";
  104 + response.setContentType("application/x-msdownload");
  105 + response.setHeader("content-disposition", "attachment;filename=" + URLEncoder.encode(filename, "UTF-8"));
  106 +
  107 + OutputStream os = response.getOutputStream();
  108 + wb.write(os);
  109 + os.flush();
  110 + os.close();
  111 + } catch (Exception e) {
  112 + logger.error("", e);
  113 + }
  114 + }
  115 +
  116 + private void writeData(Sheet sheet, List<FastAndSlow> list) {
  117 + List<FastAndSlow> ups = new ArrayList<>()
  118 + ,downs = new ArrayList<>();
  119 + //前4行是表头
  120 + Row row;
  121 + row = sheet.getRow(0);
  122 + row.getCell(4).setCellValue(list.get(0).getRq());
  123 + row.getCell(13).setCellValue(BasicData.lineCode2NameMap.get(list.get(0).getLineCode()));
  124 + FastAndSlow fas;
  125 + for(int i = 0; i < list.size(); i++){
  126 + fas = list.get(i);
  127 + row = sheet.createRow(i + 4);
  128 + row.createCell(0).setCellValue(i + 1);
  129 + row.createCell(1).setCellValue(fas.getStationName());
  130 + row.createCell(2).setCellValue(fas.getUpDown());
  131 + row.createCell(3).setCellValue(fas.getFcsj());
  132 + row.createCell(4).setCellValue(fas.getDfsj());
  133 + row.createCell(5).setCellValue(fas.getFcsjActual());
  134 + row.createCell(6).setCellValue(fas.getFcsjFast());
  135 + row.createCell(7).setCellValue(fas.getFcsjSlow());
  136 + row.createCell(8).setCellValue(fas.getDfsjFast());
  137 + row.createCell(9).setCellValue(fas.getDfsjSlow());
  138 + row.createCell(10).setCellValue(fas.getZdsj());
  139 + row.createCell(11).setCellValue(fas.getZdsjDf());
  140 + row.createCell(12).setCellValue(fas.getZdsjActual());
  141 + row.createCell(13).setCellValue(fas.getZdsjFast());
  142 + row.createCell(14).setCellValue(fas.getZdsjSlow());
  143 + row.createCell(15).setCellValue(fas.getZdsjDfFast());
  144 + row.createCell(16).setCellValue(fas.getZdsjDfSlow());
  145 +
  146 + if(fas.getUpDown()==0)
  147 + ups.add(fas);
  148 + else
  149 + downs.add(fas);
  150 + }
  151 + //合计
  152 + int size = list.size();
  153 + row = sheet.createRow(size + 4);
  154 + row.createCell(1).setCellValue("发车:上行(计划快误点:"+jhfcFast(ups)+" 累计时间:"+jhfcFastTime(ups)+" 待发快误点:"+dffcFast(ups)+" 累计时间:"+dffcFastTime(ups)+") ");
  155 + row.createCell(9).setCellValue("下行(计划快误点:"+jhfcFast(downs)+" 累计时间:"+jhfcFastTime(downs)+" 待发快误点:"+dffcFast(downs)+" 累计时间:"+dffcFastTime(downs)+")");
  156 + row = sheet.createRow(size + 5);
  157 + row.createCell(1).setCellValue("发车:上行(计划慢误点:"+jhfcSlow(ups)+" 累计时间:"+jhfcSlowTime(ups)+" 待发慢误点:"+dffcSlow(ups)+" 累计时间:"+dffcSlowTime(ups)+") ");
  158 + row.createCell(9).setCellValue("下行(计划慢误点:"+jhfcSlow(downs)+" 累计时间:"+jhfcSlowTime(downs)+" 待发慢误点:"+dffcSlow(downs)+" 累计时间:"+dffcSlowTime(downs)+")");
  159 + row = sheet.createRow(size + 6);
  160 + row.createCell(1).setCellValue("到达:上行(计划快误点:"+jhzdFast(ups)+" 累计时间:"+jhzdFastTime(ups)+" 待发快误点:"+dfzdFast(ups)+" 累计时间:"+dfzdFastTime(ups)+") ");
  161 + row.createCell(9).setCellValue("下行(计划快误点:"+jhzdFast(downs)+" 累计时间:"+jhzdFastTime(downs)+" 待发快误点:"+dfzdFast(downs)+" 累计时间:"+dfzdFastTime(downs)+")");
  162 + row = sheet.createRow(size + 7);
  163 + row.createCell(1).setCellValue("到达:上行(计划慢误点:"+jhzdSlow(ups)+" 累计时间:"+jhzdSlowTime(ups)+" 待发慢误点:"+dfzdSlow(ups)+" 累计时间:"+dfzdSlowTime(ups)+") ");
  164 + row.createCell(9).setCellValue("下行(计划慢误点:"+jhzdSlow(downs)+" 累计时间:"+jhzdSlowTime(downs)+" 待发慢误点:"+dfzdSlow(downs)+" 累计时间:"+dfzdSlowTime(downs)+")");
  165 + //合并单元格
  166 + sheet.addMergedRegion(new CellRangeAddress(size + 4, size + 4, 1, 8));
  167 + sheet.addMergedRegion(new CellRangeAddress(size + 4, size + 4, 9, 16));
  168 + sheet.addMergedRegion(new CellRangeAddress(size + 5, size + 5, 1, 8));
  169 + sheet.addMergedRegion(new CellRangeAddress(size + 5, size + 5, 9, 16));
  170 + sheet.addMergedRegion(new CellRangeAddress(size + 6, size + 6, 1, 8));
  171 + sheet.addMergedRegion(new CellRangeAddress(size + 6, size + 6, 9, 16));
  172 + sheet.addMergedRegion(new CellRangeAddress(size + 7, size + 7, 1, 8));
  173 + sheet.addMergedRegion(new CellRangeAddress(size + 7, size + 7, 9, 16));
  174 +
  175 + sheet.addMergedRegion(new CellRangeAddress(size + 4, size + 7, 0, 0));
  176 + }
  177 +
  178 + private List<FastAndSlow> filterByType(List<FastAndSlow> all, String type) {
  179 + List rsList = new ArrayList();
  180 + if ("-1".equals(type)) {//慢误
  181 + for (FastAndSlow fas : all) {
  182 + if (fas.isSlow())
  183 + rsList.add(fas);
  184 + }
  185 + return rsList;
  186 + } else if ("1".equals(type)) {//快误
  187 + for (FastAndSlow fas : all) {
  188 + if (fas.isFast())
  189 + rsList.add(fas);
  190 + }
  191 + return rsList;
  192 + }
  193 + return all;
  194 + }
  195 +
  196 +
  197 + private String maxEndTime(String sStr, String eStr, int space) throws ParseException {
  198 + try {
  199 + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
  200 + long st = sdf.parse(sStr).getTime();
  201 + long et = sdf.parse(eStr).getTime();
  202 + long dayTime = 24 * 60 * 60 * 1000;
  203 + long spaceTime = dayTime * space;
  204 +
  205 + if (et - st > spaceTime) {
  206 + eStr = sdf.format(new Date(st + spaceTime));
  207 + }
  208 + } catch (Exception e) {
  209 + throw e;
  210 + }
  211 + return eStr;
  212 + }
  213 +
  214 + /**
  215 + * 计划发出快误点
  216 + * @param list
  217 + * @return
  218 + */
  219 + private int jhfcFast(List<FastAndSlow> list){
  220 + int count=0;
  221 + for(FastAndSlow fas : list){
  222 + if(fas.getFcsjFast() > 0)
  223 + count++;
  224 + }
  225 + return count;
  226 + }
  227 +
  228 + /**
  229 + * 计划终点快误点
  230 + * @param list
  231 + * @return
  232 + */
  233 + private int jhzdFast(List<FastAndSlow> list){
  234 + int count=0;
  235 + for(FastAndSlow fas : list){
  236 + if(fas.getZdsjFast() > 0)
  237 + count++;
  238 + }
  239 + return count;
  240 + }
  241 +
  242 + /**
  243 + * 待发发出快误点
  244 + * @param list
  245 + * @return
  246 + */
  247 + private int dffcFast(List<FastAndSlow> list){
  248 + int count=0;
  249 + for(FastAndSlow fas : list){
  250 + if(fas.getDfsjFast() > 0)
  251 + count++;
  252 + }
  253 + return count;
  254 + }
  255 +
  256 + /**
  257 + * 待发终点快误点
  258 + * @param list
  259 + * @return
  260 + */
  261 + private int dfzdFast(List<FastAndSlow> list){
  262 + int count=0;
  263 + for(FastAndSlow fas : list){
  264 + if(fas.getZdsjDfFast() > 0)
  265 + count++;
  266 + }
  267 + return count;
  268 + }
  269 +
  270 + //----------
  271 +
  272 + /**
  273 + * 计划发出慢误点
  274 + * @param list
  275 + * @return
  276 + */
  277 + private int jhfcSlow(List<FastAndSlow> list){
  278 + int count=0;
  279 + for(FastAndSlow fas : list){
  280 + if(fas.getFcsjSlow() > 0)
  281 + count++;
  282 + }
  283 + return count;
  284 + }
  285 +
  286 + /**
  287 + * 计划终点慢误点
  288 + * @param list
  289 + * @return
  290 + */
  291 + private int jhzdSlow(List<FastAndSlow> list){
  292 + int count=0;
  293 + for(FastAndSlow fas : list){
  294 + if(fas.getZdsjSlow() > 0)
  295 + count++;
  296 + }
  297 + return count;
  298 + }
  299 +
  300 + /**
  301 + * 待发发出慢误点
  302 + * @param list
  303 + * @return
  304 + */
  305 + private int dffcSlow(List<FastAndSlow> list){
  306 + int count=0;
  307 + for(FastAndSlow fas : list){
  308 + if(fas.getDfsjSlow() > 0)
  309 + count++;
  310 + }
  311 + return count;
  312 + }
  313 +
  314 + /**
  315 + * 待发终点慢误点
  316 + * @param list
  317 + * @return
  318 + */
  319 + private int dfzdSlow(List<FastAndSlow> list){
  320 + int count=0;
  321 + for(FastAndSlow fas : list){
  322 + if(fas.getZdsjDfSlow() > 0)
  323 + count++;
  324 + }
  325 + return count;
  326 + }
  327 + /**
  328 + * ################
  329 + */
  330 + /**
  331 + * 计划发出快误点
  332 + * @param list
  333 + * @return
  334 + */
  335 + private int jhfcFastTime(List<FastAndSlow> list){
  336 + int sum=0;
  337 + for(FastAndSlow fas : list){
  338 + sum+=fas.getFcsjFast();
  339 + }
  340 + return sum;
  341 + }
  342 +
  343 + /**
  344 + * 计划终点快误点
  345 + * @param list
  346 + * @return
  347 + */
  348 + private int jhzdFastTime(List<FastAndSlow> list){
  349 + int sum=0;
  350 + for(FastAndSlow fas : list){
  351 + sum+=fas.getZdsjFast();
  352 + }
  353 + return sum;
  354 + }
  355 +
  356 + /**
  357 + * 待发发出快误点
  358 + * @param list
  359 + * @return
  360 + */
  361 + private int dffcFastTime(List<FastAndSlow> list){
  362 + int sum=0;
  363 + for(FastAndSlow fas : list){
  364 + sum+=fas.getDfsjFast();
  365 + }
  366 + return sum;
  367 + }
  368 +
  369 + /**
  370 + * 待发终点快误点
  371 + * @param list
  372 + * @return
  373 + */
  374 + private int dfzdFastTime(List<FastAndSlow> list){
  375 + int sum=0;
  376 + for(FastAndSlow fas : list){
  377 + sum+=fas.getZdsjDfFast();
  378 + }
  379 + return sum;
  380 + }
  381 +
  382 + //----------
  383 +
  384 + /**
  385 + * 计划发出慢误点
  386 + * @param list
  387 + * @return
  388 + */
  389 + private int jhfcSlowTime(List<FastAndSlow> list){
  390 + int sum=0;
  391 + for(FastAndSlow fas : list){
  392 + sum+=fas.getFcsjSlow();
  393 + }
  394 + return sum;
  395 + }
  396 +
  397 + /**
  398 + * 计划终点慢误点
  399 + * @param list
  400 + * @return
  401 + */
  402 + private int jhzdSlowTime(List<FastAndSlow> list){
  403 + int sum=0;
  404 + for(FastAndSlow fas : list){
  405 + sum+=fas.getZdsjSlow();
  406 + }
  407 + return sum;
  408 + }
  409 +
  410 + /**
  411 + * 待发发出慢误点
  412 + * @param list
  413 + * @return
  414 + */
  415 + private int dffcSlowTime(List<FastAndSlow> list){
  416 + int sum=0;
  417 + for(FastAndSlow fas : list){
  418 + sum+=fas.getDfsjSlow();
  419 + }
  420 + return sum;
  421 + }
  422 +
  423 + /**
  424 + * 待发终点慢误点
  425 + * @param list
  426 + * @return
  427 + */
  428 + private int dfzdSlowTime(List<FastAndSlow> list){
  429 + int sum=0;
  430 + for(FastAndSlow fas : list){
  431 + sum+=fas.getZdsjDfSlow();
  432 + }
  433 + return sum;
  434 + }
  435 +}
14 436 \ No newline at end of file
... ...
src/main/java/com/bsth/data/utils/ConvertUtil.java 0 → 100644
  1 +package com.bsth.data.utils;
  2 +
  3 +import com.google.common.collect.ArrayListMultimap;
  4 +import org.joda.time.format.DateTimeFormat;
  5 +import org.joda.time.format.DateTimeFormatter;
  6 +import org.slf4j.Logger;
  7 +import org.slf4j.LoggerFactory;
  8 +
  9 +import java.lang.reflect.Field;
  10 +import java.util.*;
  11 +
  12 +/**
  13 + * 数据转换
  14 + * Created by panzhao on 2017/3/13.
  15 + */
  16 +public class ConvertUtil<T> {
  17 +
  18 + Logger logger = LoggerFactory.getLogger(this.getClass());
  19 + private static DateTimeFormatter fmtyyyyMMdd = DateTimeFormat.forPattern("yyyyMMdd");
  20 +
  21 + /**
  22 + * 根据指定字段 将 list 分组
  23 + *
  24 + * @param list
  25 + * @param separator 字段使用分隔符连接 组成key
  26 + * @param fields
  27 + * @return
  28 + */
  29 + public ArrayListMultimap<String, T> groupMultiList(List<T> list, String separator, Field... fields) {
  30 + ArrayListMultimap<String, T> multimap = ArrayListMultimap.create();
  31 +
  32 + String key;
  33 + //Object field;
  34 + try {
  35 + for (T t : list) {
  36 +
  37 + key = "";
  38 + for (Field f : fields) {
  39 + f.setAccessible(true);
  40 + if(null == f.get(t))
  41 + continue;
  42 + //日期类型格式化为 YYYY-MM-DD
  43 + if (f.getType().equals(Date.class))
  44 + key += (separator + fmtyyyyMMdd.print(((Date) f.get(t)).getTime()));
  45 + else
  46 + key += (separator + f.get(t).toString());
  47 + }
  48 + if(key.length() > 1)
  49 + key = key.substring(1);
  50 +
  51 + multimap.put(key, t);
  52 + }
  53 + } catch (Exception e) {
  54 + logger.error("", e);
  55 + }
  56 +
  57 + return multimap;
  58 + }
  59 +
  60 + /**
  61 + * 根据指定字段 将 list 分组
  62 + *
  63 + * @param list
  64 + * @param separator 字段使用分隔符连接 组成key
  65 + * @param fields
  66 + * @return
  67 + */
  68 + public Map<String, T> groupList(List<T> list, String separator, Field... fields) {
  69 + Map<String, T> map = new HashMap<>();
  70 +
  71 + String key;
  72 + //Object field;
  73 + try {
  74 + for (T t : list) {
  75 +
  76 + key = "";
  77 + for (Field f : fields) {
  78 + f.setAccessible(true);
  79 + //日期类型格式化为 YYYY-MM-DD
  80 + if (f.getType().equals(Date.class))
  81 + key += (separator + fmtyyyyMMdd.print(((Date) f.get(t)).getTime()));
  82 + else
  83 + key += (separator + f.get(t).toString());
  84 + }
  85 + key = key.substring(1);
  86 +
  87 + map.put(key, t);
  88 + }
  89 + } catch (Exception e) {
  90 + logger.error("", e);
  91 + }
  92 +
  93 + return map;
  94 + }
  95 +
  96 + /**
  97 + * 计算并集
  98 + *
  99 + * @param all
  100 + * @param sub
  101 + * @return
  102 + */
  103 + public List<String> calcUnion(Collection<String> all, Collection<String> sub) {
  104 + List<String> rs = new ArrayList<>();
  105 +
  106 + for (String str : all) {
  107 + if (sub.contains(str))
  108 + rs.add(str);
  109 + }
  110 + return rs;
  111 + }
  112 +
  113 + /**
  114 + * 计算补集
  115 + *
  116 + * @param all
  117 + * @param sub
  118 + * @return
  119 + */
  120 + public List<String> calcComplement(Collection<String> all, Collection<String> sub) {
  121 + List<String> rs = new ArrayList<>();
  122 +
  123 + for (String str : all) {
  124 + if (!sub.contains(str))
  125 + rs.add(str);
  126 + }
  127 + return rs;
  128 + }
  129 +}
... ...
src/main/resources/static/pages/summary/excel/快慢误点报表.xls 0 → 100644
No preview for this file type
src/main/resources/static/pages/summary/fast_and_slow/data.html
1 1 <div class="ct_data_body_wrap">
2 2 <div class="uk-card uk-card-default uk-card-body ct_rq_left">
3   - <ul uk-scrollspy-nav="closest: li; scroll: true; " class="uk-nav uk-nav-default tm-nav uk-nav-parent-icon"></ul>
  3 + <ul uk-scrollspy-nav="closest: li; scroll: true; offset: 285" class="uk-nav uk-nav-default tm-nav uk-nav-parent-icon"></ul>
4 4 </div>
5 5  
6 6 <div class="uk-card uk-card-default uk-card-body ct_right_tables" >
... ... @@ -15,9 +15,7 @@
15 15  
16 16 <script id="fast_and_slow_right_body_temp" type="text/html">
17 17 <div>
18   - {{each listMap as obj k}}
19   - <h2 id="table_{{k}}">{{k}}</h2>
20   - <div class="data_table_wrap">
  18 + <div class="data_table_wrap head">
21 19 <table cellspacing="1" class="data_table">
22 20 <col />
23 21 <col width="14%"/>
... ... @@ -65,11 +63,34 @@
65 63 <td>快</td>
66 64 <td>慢</td>
67 65 </tr>
  66 + </table>
  67 + </div>
  68 + {{each listMap as obj k}}
  69 + <h4><a>{{k}}</a></h4>
  70 + <div class="data_table_wrap data" id="table_{{k}}">
  71 + <table cellspacing="1" class="data_table">
  72 + <col />
  73 + <col width="14%"/>
  74 + <col width="4%"/>
  75 + <col width="6%"/>
  76 + <col width="6%"/>
  77 + <col width="6%"/>
  78 + <col width="5%"/>
  79 + <col width="5%"/>
  80 + <col width="5%"/>
  81 + <col width="5%"/>
  82 + <col width="6%"/>
  83 + <col width="6%"/>
  84 + <col width="6%"/>
  85 + <col width="5%"/>
  86 + <col width="5%"/>
  87 + <col width="5%"/>
  88 + <col width="5%"/>
68 89 {{each listMap[k] as obj i}}
69 90 <tr>
70 91 <td>{{i+1}}</td>
71 92 <td>{{obj.stationName}}</td>
72   - <td>{{obj.upDown==0?"上行":"下行"}}</td>
  93 + <td class="cell_dir_{{obj.upDown}}">{{obj.upDown==0?"上行":"下行"}}</td>
73 94 <td>{{obj.fcsj}}</td>
74 95 <td>{{obj.dfsj}}</td>
75 96 <td>{{obj.fcsjActual}}</td>
... ... @@ -87,13 +108,21 @@
87 108 </tr>
88 109 {{/each}}
89 110 <tr>
90   - <td rowspan="2">合计:</td>
91   - <td colspan="8" class="count_col">上行(计划快误点:12 累计时间:50 待发快误点:15 累计时间:70)</td>
92   - <td colspan="8" class="count_col">下行(计划快误点:12 累计时间:50 待发快误点:15 累计时间:70)</td>
  111 + <td rowspan="4">合计:</td>
  112 + <td colspan="8" class="count_col">发车:上行(计划快误点:<a class="c_c_0">{{countMap[k][0]['fast'][0]}}</a> &nbsp;累计时间:<a class="c_c_0">{{timeCountMap[k][0]['fast'][0]}}</a> &nbsp;待发快误点:<a class="c_c_0">{{countMap[k][0]['fast'][1]}}</a> &nbsp;累计时间:<a class="c_c_0">{{timeCountMap[k][0]['fast'][1]}}</a>)</td>
  113 + <td colspan="8" class="count_col">发车:下行(计划快误点:<a class="c_c_1">{{countMap[k][1]['fast'][0]}}</a> &nbsp;累计时间:<a class="c_c_1">{{timeCountMap[k][1]['fast'][0]}}</a> 待发快误点:<a class="c_c_1">{{countMap[k][1]['fast'][1]}}</a> &nbsp;累计时间:<a class="c_c_1">{{timeCountMap[k][1]['fast'][1]}}</a>)</td>
  114 + </tr>
  115 + <tr>
  116 + <td colspan="8" class="count_col">发车:上行(计划慢误点:<a class="c_c_0">{{countMap[k][0]['slow'][0]}}</a> &nbsp;累计时间:<a class="c_c_0">{{timeCountMap[k][0]['slow'][0]}}</a> &nbsp;待发慢误点:<a class="c_c_0">{{countMap[k][0]['slow'][1]}}</a> &nbsp;累计时间:<a class="c_c_0">{{timeCountMap[k][0]['slow'][1]}}</a>)</td>
  117 + <td colspan="8" class="count_col">发车:下行(计划慢误点:<a class="c_c_1">{{countMap[k][1]['slow'][0]}}</a> &nbsp;累计时间:<a class="c_c_1">{{timeCountMap[k][1]['slow'][0]}}</a> &nbsp;待发慢误点:<a class="c_c_1">{{countMap[k][1]['slow'][1]}}</a> &nbsp;累计时间:<a class="c_c_1">{{timeCountMap[k][1]['slow'][1]}}</a>)</td>
93 118 </tr>
94 119 <tr>
95   - <td colspan="8" class="count_col">上行(计划快误点:12 累计时间:50 待发快误点:15 累计时间:70)</td>
96   - <td colspan="8" class="count_col">下行(计划快误点:12 累计时间:50 待发快误点:15 累计时间:70)</td>
  120 + <td colspan="8" class="count_col">到达:上行(计划快误点:<a class="c_c_0">{{countMap[k][0]['fast'][2]}}</a> &nbsp;累计时间:<a class="c_c_0">{{timeCountMap[k][0]['fast'][2]}}</a> &nbsp;待发快误点:<a class="c_c_0">{{countMap[k][0]['fast'][3]}}</a> &nbsp;累计时间:<a class="c_c_0">{{timeCountMap[k][0]['fast'][3]}}</a>)</td>
  121 + <td colspan="8" class="count_col">到达:下行(计划快误点:<a class="c_c_1">{{countMap[k][1]['fast'][2]}}</a> &nbsp;累计时间:<a class="c_c_1">{{timeCountMap[k][1]['fast'][2]}}</a> &nbsp;待发快误点:<a class="c_c_1">{{countMap[k][1]['fast'][3]}}</a> &nbsp;累计时间:<a class="c_c_1">{{timeCountMap[k][1]['fast'][3]}}</a>)</td>
  122 + </tr>
  123 + <tr>
  124 + <td colspan="8" class="count_col">到达:上行(计划慢误点:<a class="c_c_0">{{countMap[k][0]['slow'][2]}}</a> &nbsp;累计时间:<a class="c_c_0">{{timeCountMap[k][0]['slow'][2]}}</a> &nbsp;待发慢误点:<a class="c_c_0">{{countMap[k][0]['slow'][3]}}</a> &nbsp;累计时间:<a class="c_c_0">{{timeCountMap[k][0]['slow'][3]}}</a>)</td>
  125 + <td colspan="8" class="count_col">到达:下行(计划慢误点:<a class="c_c_1">{{countMap[k][1]['slow'][2]}}</a> &nbsp;累计时间:<a class="c_c_1">{{timeCountMap[k][1]['slow'][2]}}</a> &nbsp;待发慢误点:<a class="c_c_1">{{countMap[k][1]['slow'][3]}}</a> &nbsp;累计时间:<a class="c_c_1">{{timeCountMap[k][1]['slow'][3]}}</a>)</td>
97 126 </tr>
98 127 </table>
99 128 </div>
... ... @@ -104,17 +133,64 @@
104 133 <script>
105 134 (function () {
106 135 var wrap = '.ct_data_body_wrap',
107   - listMap;
  136 + listMap, countMap={}, timeCountMap={};
108 137  
109 138 $(wrap).on('init', function (e, data) {
110 139 e.stopPropagation();
111 140 listMap = data.listMap;
112 141  
  142 + //统计
  143 + for(var rq in listMap){
  144 + /**
  145 + * 2017-10-20:[{fast: [发车, 待发, 计划终点,待发终点], slow: [发车, 待发, 计划终点,待发终点]},{}]
  146 + */
  147 + countMap[rq]=[{fast:[0,0,0,0], slow:[0,0,0,0]}, {fast:[0,0,0,0], slow:[0,0,0,0]}];
  148 + timeCountMap[rq]=[{fast:[0,0,0,0], slow:[0,0,0,0]}, {fast:[0,0,0,0], slow:[0,0,0,0]}];
  149 + for(var i=0,obj;obj=listMap[rq][i++];){
  150 + countDetail(countMap[rq], obj);
  151 + sumTime(timeCountMap[rq], obj);
  152 + }
  153 + }
  154 +
113 155 //左侧日期list
114 156 $('.ct_rq_left>ul',wrap).html(template('fast_and_slow_left_rq_temp', {listMap: listMap}));
115 157 //右侧
116   - $('.ct_right_tables',wrap).html(template('fast_and_slow_right_body_temp', {listMap: listMap}));
  158 + $('.ct_right_tables',wrap).html(template('fast_and_slow_right_body_temp', {listMap: listMap, countMap: countMap, timeCountMap: timeCountMap}));
117 159 });
  160 +
  161 +
  162 + function countDetail(json, obj) {
  163 + var i = obj.upDown;
  164 + if(obj.fcsjFast)
  165 + json[i]['fast'][0]++;
  166 + if(obj.dfsjFast)
  167 + json[i]['fast'][1]++;
  168 + if(obj.zdsjFast)
  169 + json[i]['fast'][2]++;
  170 + if(obj.zdsjDfFast)
  171 + json[i]['fast'][3]++;
  172 +
  173 + if(obj.fcsjSlow)
  174 + json[i]['slow'][0]++;
  175 + if(obj.dfsjSlow)
  176 + json[i]['slow'][1]++;
  177 + if(obj.zdsjSlow)
  178 + json[i]['slow'][2]++;
  179 + if(obj.zdsjDfSlow)
  180 + json[i]['slow'][3]++;
  181 + }
  182 +
  183 + function sumTime(json, obj) {
  184 + var i = obj.upDown;
  185 + json[i]['fast'][0]+=obj.fcsjFast;
  186 + json[i]['fast'][1]+=obj.dfsjFast;
  187 + json[i]['fast'][2]+=obj.zdsjFast;
  188 + json[i]['fast'][3]+=obj.zdsjDfFast;
  189 + json[i]['slow'][0]+=obj.fcsjSlow;
  190 + json[i]['slow'][1]+=obj.dfsjSlow;
  191 + json[i]['slow'][2]+=obj.zdsjSlow;
  192 + json[i]['slow'][3]+=obj.zdsjDfSlow;
  193 + }
118 194 })();
119 195 </script>
120 196 </div>
121 197 \ No newline at end of file
... ...
src/main/resources/static/pages/summary/fast_and_slow/main.html
... ... @@ -121,7 +121,8 @@
121 121 top: 15px;
122 122 }
123 123 .uk-nav-default>li.uk-active>a {
124   - color: #222;
  124 + color: blue;
  125 + font-weight: 600;
125 126 }
126 127  
127 128 .data_table_wrap{
... ... @@ -134,6 +135,7 @@
134 135 text-align: center;
135 136 font-size: 14px;
136 137 table-layout: fixed;
  138 + color: #000;
137 139 }
138 140  
139 141 .ct_right_tables table td{
... ... @@ -148,14 +150,26 @@
148 150 text-align: left;
149 151 height: 40px;
150 152 text-indent:15px;
  153 + font-size: 14px !important;
  154 + font-weight: 400;
151 155 }
152 156  
153   - .ct_right_tables table tr:nth-child(-n+3) td{
  157 + .data_table_wrap.head{
  158 + position: fixed;
  159 + width: calc(100% - 300px);
  160 + top: 155px;
  161 + padding-top: 25px;
  162 + background: #fff;
  163 + }
  164 +
  165 + .ct_right_tables .data_table_wrap.head table tr:nth-child(-n+3) td{
154 166 background: #ededed;
155 167 }
156 168  
157 169 .ct_right_tables table tr:nth-last-child(1) td,
158   - .ct_right_tables table tr:nth-last-child(2) td{
  170 + .ct_right_tables table tr:nth-last-child(2) td,
  171 + .ct_right_tables table tr:nth-last-child(3) td,
  172 + .ct_right_tables table tr:nth-last-child(4) td{
159 173 background: #ededed;
160 174 }
161 175  
... ... @@ -167,6 +181,36 @@
167 181 z-index: 2;
168 182 padding-top: 25px;
169 183 }
  184 +
  185 + .ct_right_tables h2{
  186 + margin-bottom: 10px;
  187 + }
  188 +
  189 + .data_table_wrap:nth-child(2) {
  190 + margin-top: 91px;
  191 + }
  192 +
  193 + .cell_dir_0{
  194 + color: #0000ff96;
  195 + font-weight: 600;
  196 + font-size: 12px;
  197 + }
  198 + .cell_dir_1{
  199 + color: #ff00009e;
  200 + font-weight: 600;
  201 + font-size: 12px;
  202 + }
  203 +
  204 + .count_col .c_c_0{
  205 + color: #0000ffe0;
  206 + }
  207 +
  208 + .count_col .c_c_1{
  209 + color: #ff0000d1;
  210 + }
  211 + .ct_cont{
  212 + display: none;
  213 + }
170 214 </style>
171 215 </head>
172 216  
... ... @@ -199,22 +243,22 @@
199 243 </div>
200 244 <div class="ct_field">
201 245 <label>日期范围:
202   - <input class="uk-input" name="rq" style="width: 200px;">
  246 + <input class="uk-input" name="rq" style="width: 200px;" >
203 247 </label>
204 248 </div>
205 249 <div class="ct_field">
206   - <label><input class="uk-radio" type="radio" name="type" checked> 全部</label>&nbsp;
207   - <label><input class="uk-radio" type="radio" name="type"> 快误</label>&nbsp;
208   - <label><input class="uk-radio" type="radio" name="type"> 慢误</label>
  250 + <label><input class="uk-radio" type="radio" name="type" value="0" checked> 全部</label>&nbsp;
  251 + <label><input class="uk-radio" type="radio" name="type" value="1"> 快误</label>&nbsp;
  252 + <label><input class="uk-radio" type="radio" name="type" value="-1"> 慢误</label>
209 253 </div>
210 254 <div class="ct_field">
211   - <button class="uk-button uk-button-primary search"><i uk-icon="icon: search"></i>搜索</button>
  255 + <button class="uk-button uk-button-primary search"><i uk-icon="icon: search" ></i>搜索</button>
212 256 </div>
213 257 <div class="ct_field ct_field_bottom">
214   - <button class="uk-button uk-button-text" style="padding: 0 5px;">导出数据</button>
  258 + <button class="uk-button uk-button-text export_excel" style="padding: 0 5px;">导出数据</button>
215 259 </div>
216 260 <div class="ct_field ct_field_bottom">
217   - <span uk-icon="icon: question" title="快1慢3不算误点,排除进出场班次" uk-tooltip="pos: bottom"></span>
  261 + <span uk-icon="icon: question" title="快1慢3; 排除进出场班次<br>一次至多查询5天的数据,如需更大查询范围,请导出" uk-tooltip="pos: bottom"></span>
218 262 </div>
219 263 </form>
220 264 </div>
... ... @@ -259,8 +303,8 @@
259 303  
260 304 //日期选择框
261 305 var fs='YYYY-MM-DD'
262   - , ets=moment().format(fs)
263   - , sts=moment().subtract(7, 'days').format(fs);
  306 + , ets=moment().subtract(1, 'days').format(fs)
  307 + , sts=moment().subtract(6, 'days').format(fs);
264 308 flatpickr('.ct_search_form_wrap [name=rq]', {
265 309 mode: "range", dateFormat: "Y-m-d","locale": "zh", defaultDate: [sts, ets]
266 310 });
... ... @@ -323,6 +367,22 @@
323 367 * 点击搜索
324 368 */
325 369 $('.search', f).on('click', function () {
  370 + var that = this;
  371 + $(that).attr('disabled', 'disabled');
  372 + var params = serializeFormJSON();
  373 + $('.ct_cont').hide();
  374 + $.get('/summary/fastAndSlow/all', params, function (rs) {
  375 + $(that).removeAttr('disabled');
  376 + //按日期分组
  377 + var listMap = groupBy(rs, 'rq');
  378 + $('.ct_data_body_wrap').trigger('init', {listMap: listMap});
  379 + if(!rs || rs.length==0)
  380 + return UIkit.notification('没有搜索到相关数据!!', 'danger');
  381 + $('.ct_cont').show();
  382 + });
  383 + });
  384 +
  385 + function serializeFormJSON() {
326 386 var data = f.serializeJSON();
327 387 if(!data.rq)
328 388 return UIkit.notification('你必须选择时间范围!', 'danger');
... ... @@ -330,13 +390,8 @@
330 390 var sDate = data.rq.substr(0, 10),
331 391 eDate = data.rq.substr(13);
332 392  
333   - var params = {lineCode_eq: data.lineCode_eq, rq_ge: sDate, rq_le: eDate, order: 't'};
334   - $.get('/summary/fastAndSlow/all', params, function (rs) {
335   - //按日期分组
336   - var listMap = groupBy(rs, 'rq');
337   - $('.ct_data_body_wrap').trigger('init', {listMap: listMap});
338   - });
339   - });
  393 + return {lineCode_eq: data.lineCode_eq, rq_ge: sDate, rq_le: eDate, order: 't',type: data.type};
  394 + }
340 395  
341 396 f.on('submit', function (e) {
342 397 return false;
... ... @@ -355,6 +410,15 @@
355 410  
356 411 return rs;
357 412 };
  413 +
  414 + /**
  415 + * 导出
  416 + */
  417 + $('.export_excel').on('click', function () {
  418 + var params = serializeFormJSON();
  419 +
  420 + window.open('/summary/fastAndSlow/excel/' + params.lineCode_eq + "?st="+params.rq_ge+"&et="+params.rq_le+"&type="+params.type);
  421 + });
358 422 })();
359 423 </script>
360 424 </body>
... ...