Commit 29ece7a2f4f747837ce11f2432ae0bf19eb7a5fc

Authored by 廖磊
1 parent 91d5efdc

定时器计算班次准点率 班次日报表,行车路单日报表 加入电量

src/main/java/com/bsth/controller/report/SheetController.java 0 → 100644
  1 +package com.bsth.controller.report;
  2 +
  3 +import java.util.List;
  4 +import java.util.Map;
  5 +
  6 +import org.springframework.beans.factory.annotation.Autowired;
  7 +import org.springframework.web.bind.annotation.RequestMapping;
  8 +import org.springframework.web.bind.annotation.RequestMethod;
  9 +import org.springframework.web.bind.annotation.RequestParam;
  10 +import org.springframework.web.bind.annotation.RestController;
  11 +
  12 +import com.bsth.controller.BaseController;
  13 +import com.bsth.entity.sheet.Sheet;
  14 +import com.bsth.service.report.SheetService;
  15 +
  16 +@RestController
  17 +@RequestMapping("sheet")
  18 +public class SheetController extends BaseController<Sheet, Integer>{
  19 + @Autowired
  20 + SheetService sheetService;
  21 + @RequestMapping(value = "/saveListSheet",method = RequestMethod.POST)
  22 + public String saveListSheet(){
  23 + String result="";
  24 + try {
  25 + result = sheetService.saveSheetList();
  26 + } catch (Exception e) {
  27 + // TODO Auto-generated catch block
  28 + e.printStackTrace();
  29 + }
  30 + return result;
  31 + }
  32 +
  33 +
  34 + @RequestMapping(value = "/sheetList",method = RequestMethod.GET)
  35 + public List<Sheet> sheetList(@RequestParam Integer id){
  36 + List<Sheet> list=sheetService.sheetList(id);
  37 + return list;
  38 + }
  39 + @RequestMapping(value = "/countList",method = RequestMethod.GET)
  40 + public List<Map<String, Object>> countList(@RequestParam Map<String, Object> map){
  41 + List<Map<String, Object>> list=sheetService.countList(map);
  42 + return list;
  43 + }
  44 +}
src/main/java/com/bsth/data/schedule/thread/CalcOilThread.java
@@ -3,6 +3,8 @@ package com.bsth.data.schedule.thread; @@ -3,6 +3,8 @@ package com.bsth.data.schedule.thread;
3 import com.bsth.service.oil.DlbService; 3 import com.bsth.service.oil.DlbService;
4 import com.bsth.data.safe_driv.SafeDrivCenter; 4 import com.bsth.data.safe_driv.SafeDrivCenter;
5 import com.bsth.service.oil.YlbService; 5 import com.bsth.service.oil.YlbService;
  6 +import com.bsth.service.report.SheetService;
  7 +
6 import org.slf4j.Logger; 8 import org.slf4j.Logger;
7 import org.slf4j.LoggerFactory; 9 import org.slf4j.LoggerFactory;
8 import org.springframework.beans.factory.annotation.Autowired; 10 import org.springframework.beans.factory.annotation.Autowired;
@@ -19,6 +21,9 @@ public class CalcOilThread extends Thread{ @@ -19,6 +21,9 @@ public class CalcOilThread extends Thread{
19 YlbService ylbService; 21 YlbService ylbService;
20 @Autowired 22 @Autowired
21 DlbService dlbService; 23 DlbService dlbService;
  24 +
  25 + @Autowired
  26 + SheetService sheetService;
22 Logger logger = LoggerFactory.getLogger(this.getClass()); 27 Logger logger = LoggerFactory.getLogger(this.getClass());
23 28
24 @Override 29 @Override
@@ -28,7 +33,9 @@ public class CalcOilThread extends Thread{ @@ -28,7 +33,9 @@ public class CalcOilThread extends Thread{
28 ylbService.obtainDsq(); 33 ylbService.obtainDsq();
29 dlbService.obtainDsq(); 34 dlbService.obtainDsq();
30 logger.info("计算路单里程加注量结束!"); 35 logger.info("计算路单里程加注量结束!");
31 - 36 + logger.info("开始计算班次准点率....");
  37 + sheetService.saveSheetList();
  38 + logger.info("计算班次准点率结束!");
32 //清除安全驾驶数据 先临时蹭这个线程 39 //清除安全驾驶数据 先临时蹭这个线程
33 SafeDrivCenter.clear(); 40 SafeDrivCenter.clear();
34 } catch(Exception e){ 41 } catch(Exception e){
src/main/java/com/bsth/entity/sheet/Sheet.java 0 → 100644
  1 +package com.bsth.entity.sheet;
  2 +
  3 +import java.util.Date;
  4 +
  5 +import javax.persistence.Entity;
  6 +import javax.persistence.GeneratedValue;
  7 +import javax.persistence.Id;
  8 +import javax.persistence.Table;
  9 +import javax.persistence.Transient;
  10 +@Entity
  11 +@Table(name = "bsth_c_sheet")
  12 +public class Sheet {
  13 + @Id
  14 + @GeneratedValue
  15 + private Integer id;
  16 + private String gs;
  17 + private String fgs;
  18 + private String line;
  19 + private String date;
  20 + private String realDate;
  21 + private String jhsj;
  22 + private Long jhsjt;
  23 + private String sjsj;
  24 + private Long sjsjt;
  25 + private String xlDir;
  26 + private Date createDate;
  27 + private String zdname;
  28 +
  29 + @Transient
  30 + private String sfzd;
  31 +
  32 + public Integer getId() {
  33 + return id;
  34 + }
  35 + public void setId(Integer id) {
  36 + this.id = id;
  37 + }
  38 + public String getGs() {
  39 + return gs;
  40 + }
  41 + public void setGs(String gs) {
  42 + this.gs = gs;
  43 + }
  44 + public String getFgs() {
  45 + return fgs;
  46 + }
  47 + public void setFgs(String fgs) {
  48 + this.fgs = fgs;
  49 + }
  50 + public String getLine() {
  51 + return line;
  52 + }
  53 + public void setLine(String line) {
  54 + this.line = line;
  55 + }
  56 + public String getDate() {
  57 + return date;
  58 + }
  59 + public void setDate(String date) {
  60 + this.date = date;
  61 + }
  62 + public String getRealDate() {
  63 + return realDate;
  64 + }
  65 + public void setRealDate(String realDate) {
  66 + this.realDate = realDate;
  67 + }
  68 + public String getJhsj() {
  69 + return jhsj;
  70 + }
  71 + public void setJhsj(String jhsj) {
  72 + this.jhsj = jhsj;
  73 + }
  74 + public String getSjsj() {
  75 + return sjsj;
  76 + }
  77 + public void setSjsj(String sjsj) {
  78 + this.sjsj = sjsj;
  79 + }
  80 +
  81 + public Long getJhsjt() {
  82 + return jhsjt;
  83 + }
  84 + public void setJhsjt(Long jhsjt) {
  85 + this.jhsjt = jhsjt;
  86 + }
  87 + public Long getSjsjt() {
  88 + return sjsjt;
  89 + }
  90 + public void setSjsjt(Long sjsjt) {
  91 + this.sjsjt = sjsjt;
  92 + }
  93 + public String getXlDir() {
  94 + return xlDir;
  95 + }
  96 + public void setXlDir(String xlDir) {
  97 + this.xlDir = xlDir;
  98 + }
  99 + public Date getCreateDate() {
  100 + return createDate;
  101 + }
  102 + public void setCreateDate(Date createDate) {
  103 + this.createDate = createDate;
  104 + }
  105 +
  106 + public String getZdname() {
  107 + return zdname;
  108 + }
  109 + public void setZdname(String zdname) {
  110 + this.zdname = zdname;
  111 + }
  112 + public String getSfzd() {
  113 + return sfzd;
  114 + }
  115 + public void setSfzd(String sfzd) {
  116 + this.sfzd = sfzd;
  117 + }
  118 +
  119 +
  120 +
  121 +}
src/main/java/com/bsth/repository/sheet/SheetRepository.java 0 → 100644
  1 +package com.bsth.repository.sheet;
  2 +
  3 +import com.bsth.entity.sheet.Sheet;
  4 +import com.bsth.repository.BaseRepository;
  5 +import org.springframework.stereotype.Repository;
  6 +
  7 +/**
  8 + *
  9 + */
  10 +@Repository
  11 +public interface SheetRepository extends BaseRepository<Sheet, Integer>{
  12 +}
src/main/java/com/bsth/service/forms/impl/FormsServiceImpl.java
@@ -28,10 +28,12 @@ import com.bsth.entity.mcy_forms.Singledata; @@ -28,10 +28,12 @@ import com.bsth.entity.mcy_forms.Singledata;
28 import com.bsth.entity.mcy_forms.Turnoutrate; 28 import com.bsth.entity.mcy_forms.Turnoutrate;
29 import com.bsth.entity.mcy_forms.Vehicleloading; 29 import com.bsth.entity.mcy_forms.Vehicleloading;
30 import com.bsth.entity.mcy_forms.Waybillday; 30 import com.bsth.entity.mcy_forms.Waybillday;
  31 +import com.bsth.entity.oil.Dlb;
31 import com.bsth.entity.oil.Ylb; 32 import com.bsth.entity.oil.Ylb;
32 import com.bsth.entity.realcontrol.ScheduleRealInfo; 33 import com.bsth.entity.realcontrol.ScheduleRealInfo;
33 import com.bsth.entity.schedule.SchedulePlanInfo; 34 import com.bsth.entity.schedule.SchedulePlanInfo;
34 import com.bsth.repository.LineRepository; 35 import com.bsth.repository.LineRepository;
  36 +import com.bsth.repository.oil.DlbRepository;
35 import com.bsth.repository.oil.YlbRepository; 37 import com.bsth.repository.oil.YlbRepository;
36 import com.bsth.repository.realcontrol.ScheduleRealInfoRepository; 38 import com.bsth.repository.realcontrol.ScheduleRealInfoRepository;
37 import com.bsth.data.BasicData; 39 import com.bsth.data.BasicData;
@@ -67,6 +69,9 @@ public class FormsServiceImpl implements FormsService { @@ -67,6 +69,9 @@ public class FormsServiceImpl implements FormsService {
67 YlbRepository ylbRepository; 69 YlbRepository ylbRepository;
68 70
69 @Autowired 71 @Autowired
  72 + DlbRepository dlbRepository;
  73 +
  74 + @Autowired
70 LineRepository lineRepository; 75 LineRepository lineRepository;
71 76
72 77
@@ -98,6 +103,7 @@ public class FormsServiceImpl implements FormsService { @@ -98,6 +103,7 @@ public class FormsServiceImpl implements FormsService {
98 }); 103 });
99 List<ScheduleRealInfo> realList= scheduleRealInfoRepository.scheduleByDateAndLineTjrb(line, date); 104 List<ScheduleRealInfo> realList= scheduleRealInfoRepository.scheduleByDateAndLineTjrb(line, date);
100 List<Ylb> listYlb= ylbRepository.obtainYl(date, "", "", line, "", "xlbm"); 105 List<Ylb> listYlb= ylbRepository.obtainYl(date, "", "", line, "", "xlbm");
  106 + List<Dlb> listDlb= dlbRepository.obtainDl(date, "", "", line, "", "xlbm");
101 double jzl=0.0,sh=0.0,yh=0.0; 107 double jzl=0.0,sh=0.0,yh=0.0;
102 for (int i = 0; i < list.size(); i++) { 108 for (int i = 0; i < list.size(); i++) {
103 Waybillday w=list.get(i); 109 Waybillday w=list.get(i);
@@ -132,6 +138,14 @@ public class FormsServiceImpl implements FormsService { @@ -132,6 +138,14 @@ public class FormsServiceImpl implements FormsService {
132 } 138 }
133 } 139 }
134 140
  141 + for (int j = 0; j < listDlb.size(); j++) {
  142 + Dlb d=listDlb.get(j);
  143 + if(w.getNbbm().equals(d.getNbbm()) && w.getJgh().equals(d.getJsy())){
  144 + jzl=Arith.add(jzl, d.getCdl());
  145 + sh=Arith.add(sh, d.getSh());
  146 + yh=Arith.add(yh, d.getHd());
  147 + }
  148 + }
135 w.setJzl(String.valueOf(jzl)); 149 w.setJzl(String.valueOf(jzl));
136 w.setYh(String.valueOf(yh)); 150 w.setYh(String.valueOf(yh));
137 w.setSh(String.valueOf(sh)); 151 w.setSh(String.valueOf(sh));
@@ -1087,7 +1101,10 @@ public class FormsServiceImpl implements FormsService { @@ -1087,7 +1101,10 @@ public class FormsServiceImpl implements FormsService {
1087 1101
1088 @Override 1102 @Override
1089 public List<Daily> daily(Map<String, Object> map) { 1103 public List<Daily> daily(Map<String, Object> map) {
1090 - 1104 + String xlbm="";;
  1105 + if(map.get("line")!=null){
  1106 + xlbm=map.get("line").toString().trim();
  1107 + }
1091 String gsbm=""; 1108 String gsbm="";
1092 if(map.get("gsdmDaily")!=null){ 1109 if(map.get("gsdmDaily")!=null){
1093 gsbm=map.get("gsdmDaily").toString(); 1110 gsbm=map.get("gsdmDaily").toString();
@@ -1098,7 +1115,7 @@ public class FormsServiceImpl implements FormsService { @@ -1098,7 +1115,7 @@ public class FormsServiceImpl implements FormsService {
1098 fgsbm=map.get("fgsdmDaily").toString(); 1115 fgsbm=map.get("fgsdmDaily").toString();
1099 } 1116 }
1100 1117
1101 - String sql="select t.schedule_date_str," 1118 + /*String sql="select t.schedule_date_str,"
1102 + " t.cl_zbh,t.j_gh,t.j_name,x.yh from (select r.schedule_date_str,r.xl_bm," 1119 + " t.cl_zbh,t.j_gh,t.j_name,x.yh from (select r.schedule_date_str,r.xl_bm,"
1103 + " r.cl_zbh,r.j_gh,r.j_name from bsth_c_s_sp_info_real r WHERE " 1120 + " r.cl_zbh,r.j_gh,r.j_name from bsth_c_s_sp_info_real r WHERE "
1104 + " r.xl_bm='" + map.get("line").toString() + "' " 1121 + " r.xl_bm='" + map.get("line").toString() + "' "
@@ -1112,7 +1129,20 @@ public class FormsServiceImpl implements FormsService { @@ -1112,7 +1129,20 @@ public class FormsServiceImpl implements FormsService {
1112 + " and y.ssgsdm like '%"+gsbm+"%' " 1129 + " and y.ssgsdm like '%"+gsbm+"%' "
1113 + " and y.fgsdm like '%"+fgsbm+"%'" 1130 + " and y.fgsdm like '%"+fgsbm+"%'"
1114 + " ) x" 1131 + " ) x"
1115 - + " on t.cl_zbh = x.nbbm and t.j_gh=x.jsy"; 1132 + + " on t.cl_zbh = x.nbbm and t.j_gh=x.jsy";*/
  1133 +
  1134 + String sql="select r.schedule_date_str, "
  1135 + + " r.xl_bm,r.cl_zbh,r.j_gh,r.j_name,r.gs_bm,r.fgs_bm"
  1136 + + " from bsth_c_s_sp_info_real r where "
  1137 + + "r.schedule_date_str = '"+map.get("date").toString()+"'";
  1138 + if(xlbm.equals("")){
  1139 + sql +="and r.gs_bm='"+gsbm+"' "
  1140 + + " and r.fgs_bm='"+fgsbm+"'";
  1141 + }else{
  1142 + sql += " and r.xl_bm = '"+xlbm+"'";
  1143 + }
  1144 + sql += " group by r.schedule_date_str,"
  1145 + + " r.xl_bm,r.cl_zbh,r.j_gh,r.j_name,r.gs_bm,r.fgs_bm order by r.xl_bm,r.cl_zbh";
1116 1146
1117 List<Daily> list = jdbcTemplate.query(sql, new RowMapper<Daily>() { 1147 List<Daily> list = jdbcTemplate.query(sql, new RowMapper<Daily>() {
1118 @Override 1148 @Override
@@ -1122,21 +1152,31 @@ public class FormsServiceImpl implements FormsService { @@ -1122,21 +1152,31 @@ public class FormsServiceImpl implements FormsService {
1122 daily.setZbh(arg0.getString("cl_zbh")); 1152 daily.setZbh(arg0.getString("cl_zbh"));
1123 daily.setJgh(arg0.getString("j_gh")); 1153 daily.setJgh(arg0.getString("j_gh"));
1124 daily.setjName(arg0.getString("j_name")); 1154 daily.setjName(arg0.getString("j_name"));
1125 - daily.setYh(arg0.getString("yh"));  
1126 return daily; 1155 return daily;
1127 } 1156 }
1128 }); 1157 });
  1158 + List<Ylb> listYlb= ylbRepository.obtainYl(map.get("date").toString(), "", "", xlbm, "", "xlbm");
  1159 + List<Dlb> listDlb= dlbRepository.obtainDl(map.get("date").toString(), "", "", xlbm, "", "xlbm");
1129 List<ScheduleRealInfo> sList; 1160 List<ScheduleRealInfo> sList;
1130 List<ScheduleRealInfo> lists=scheduleRealInfoRepository.scheduleByDateAndLineTjrb(map.get("line").toString(), map.get("date").toString()); 1161 List<ScheduleRealInfo> lists=scheduleRealInfoRepository.scheduleByDateAndLineTjrb(map.get("line").toString(), map.get("date").toString());
1131 for(int i=0;i<list.size();i++){ 1162 for(int i=0;i<list.size();i++){
1132 sList =new ArrayList<ScheduleRealInfo>(); 1163 sList =new ArrayList<ScheduleRealInfo>();
1133 Daily d=list.get(i); 1164 Daily d=list.get(i);
1134 - if(d.getYh()==null){  
1135 - d.setYh("0");  
1136 - }else{  
1137 - if(d.getYh().equals(""))  
1138 - d.setYh("0"); 1165 + Double yh=0.0;
  1166 + for (int j = 0; j < listYlb.size(); j++) {
  1167 + Ylb y=listYlb.get(j);
  1168 + if(y.getNbbm().equals(d.getZbh())&& y.getJsy().equals(d.getJgh())){
  1169 + yh=Arith.add(yh, y.getYh());
  1170 + }
  1171 + }
  1172 +
  1173 + for (int j = 0; j < listDlb.size(); j++) {
  1174 + Dlb b=listDlb.get(j);
  1175 + if(b.getNbbm().equals(d.getZbh())&& b.getJsy().equals(d.getJgh())){
  1176 + yh=Arith.add(yh, b.getHd());
  1177 + }
1139 } 1178 }
  1179 + d.setYh(String.valueOf(yh));
1140 for (int j = 0; j < lists.size(); j++) { 1180 for (int j = 0; j < lists.size(); j++) {
1141 ScheduleRealInfo s=lists.get(j); 1181 ScheduleRealInfo s=lists.get(j);
1142 if(d.getJgh().equals(s.getjGh()) && d.getZbh().equals(s.getClZbh())){ 1182 if(d.getJgh().equals(s.getjGh()) && d.getZbh().equals(s.getClZbh())){
src/main/java/com/bsth/service/report/SheetService.java 0 → 100644
  1 +package com.bsth.service.report;
  2 +
  3 +import java.util.List;
  4 +import java.util.Map;
  5 +
  6 +import com.bsth.entity.sheet.Sheet;
  7 +import com.bsth.service.BaseService;
  8 +
  9 +public interface SheetService extends BaseService<Sheet, Integer>{
  10 + public List<Map<String, Object>> bcPunctual(Map<String, Object> map);
  11 + public String saveSheetList() throws Exception;
  12 + public List<Map<String, Object>> countList(Map<String, Object> map);
  13 +
  14 + public List<Sheet> sheetList(Integer id);
  15 +}
src/main/java/com/bsth/service/report/impl/SheetServiceImpl.java 0 → 100644
  1 +package com.bsth.service.report.impl;
  2 +
  3 +import java.sql.ResultSet;
  4 +import java.sql.SQLException;
  5 +import java.text.DecimalFormat;
  6 +import java.text.ParseException;
  7 +import java.text.SimpleDateFormat;
  8 +import java.util.ArrayList;
  9 +import java.util.Calendar;
  10 +import java.util.Collections;
  11 +import java.util.Comparator;
  12 +import java.util.Date;
  13 +import java.util.GregorianCalendar;
  14 +import java.util.HashMap;
  15 +import java.util.Iterator;
  16 +import java.util.List;
  17 +import java.util.Map;
  18 +import java.util.Set;
  19 +
  20 +import javax.transaction.Transactional;
  21 +
  22 +import org.apache.poi.hssf.eventusermodel.EventWorkbookBuilder.SheetRecordCollectingListener;
  23 +import org.slf4j.Logger;
  24 +import org.slf4j.LoggerFactory;
  25 +import org.springframework.beans.factory.annotation.Autowired;
  26 +import org.springframework.jdbc.core.JdbcTemplate;
  27 +import org.springframework.jdbc.core.RowMapper;
  28 +import org.springframework.scheduling.commonj.ScheduledTimerListener;
  29 +import org.springframework.stereotype.Service;
  30 +
  31 +import com.bsth.data.BasicData;
  32 +import com.bsth.entity.Line;
  33 +import com.bsth.entity.oil.Ylb;
  34 +import com.bsth.entity.realcontrol.ChildTaskPlan;
  35 +import com.bsth.entity.realcontrol.ScheduleRealInfo;
  36 +import com.bsth.entity.sheet.Sheet;
  37 +import com.bsth.repository.LineRepository;
  38 +import com.bsth.repository.realcontrol.ScheduleRealInfoRepository;
  39 +import com.bsth.repository.sheet.SheetRepository;
  40 +import com.bsth.service.impl.BaseServiceImpl;
  41 +import com.bsth.service.report.SheetService;
  42 +import com.bsth.util.BatchSaveUtils;
  43 +import com.bsth.util.ComparableChild;
  44 +import com.bsth.util.ComparableReal;
  45 +import com.google.common.util.concurrent.AbstractScheduledService.Scheduler;
  46 +
  47 +@Service
  48 +public class SheetServiceImpl extends BaseServiceImpl<Sheet, Integer> implements SheetService {
  49 + Logger logger = LoggerFactory.getLogger(this.getClass());
  50 + @Autowired
  51 + ScheduleRealInfoRepository scheduleRealInfoRepository;
  52 + @Autowired
  53 + LineRepository lineRepository;
  54 + @Autowired
  55 + JdbcTemplate jdbcTemplate;
  56 + @Autowired
  57 + SheetRepository sheetRepository;
  58 + /**
  59 + * 班次准点率
  60 + */
  61 + @Override
  62 + public List<Map<String, Object>> bcPunctual(Map<String, Object> map) {
  63 + // TODO Auto-generated method stub
  64 + String line =map.get("line").toString();
  65 + String date =map.get("date").toString();
  66 + List<ScheduleRealInfo> realList=scheduleRealInfoRepository.scheduleByDateAndLineTjrb(line, date);
  67 +
  68 + return null;
  69 + }
  70 + public static boolean isInOut(ScheduleRealInfo s){
  71 + boolean fage=false;
  72 + if(s.getBcType().equals("in")){
  73 + fage=true;
  74 + }
  75 + if(s.getBcType().equals("out")){
  76 + fage=true;
  77 + }
  78 + if(s.getBcType().equals("ldks")){
  79 + fage=true;
  80 + }
  81 +
  82 + return fage;
  83 + }
  84 + @Override
  85 + public String saveSheetList() throws Exception{
  86 + Map<String, Object> map=new HashMap<String,Object>();
  87 + String result = "failure";
  88 + try {
  89 + SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
  90 + Date dNow = new Date(); //当前时间
  91 + Calendar calendar = Calendar.getInstance(); //得到日历
  92 + calendar.setTime(dNow);//把当前时间赋给日历
  93 + calendar.add(Calendar.DAY_OF_MONTH, -3); //设置为前三天
  94 +
  95 + String rq=sdf.format(calendar.getTime());
  96 +// String rq="2017-05-16";
  97 +
  98 + List<Line> lineList = (List<Line>) lineRepository.findAll();
  99 +
  100 + List<ScheduleRealInfo> lists= scheduleRealInfoRepository.findByDate(rq);
  101 + List<Sheet> listAdds=new ArrayList<Sheet>();
  102 + for (int i = 0; i < lineList.size(); i++) {
  103 + List<ScheduleRealInfo> list=new ArrayList<ScheduleRealInfo>();
  104 + String line=lineList.get(i).getLineCode();
  105 + for (int j = 0; j < lists.size(); j++) {
  106 + ScheduleRealInfo s=lists.get(j);
  107 + if(!isInOut(s)){
  108 + if(s.getXlBm().equals(line)){
  109 + list.add(s);
  110 + }
  111 + }
  112 +
  113 + }
  114 + if(list.size()>0){
  115 + List<Sheet> listAdd=punctualByLine(line,list);
  116 + if(listAdd.size()>0){
  117 + listAdds.addAll(listAdd);
  118 + }
  119 + }
  120 +
  121 + }
  122 +
  123 + if(listAdds.size()>0){
  124 + new BatchSaveUtils<Sheet>().saveList(listAdds, Sheet.class);
  125 + }
  126 + result = "success";
  127 + }catch (Exception e) {
  128 + // TODO Auto-generated catch block
  129 + throw e;
  130 + }finally{
  131 + logger.info("setDDRB:"+result);
  132 + }
  133 +
  134 + return result;
  135 + }
  136 +
  137 + public List<Sheet> punctualByLine(String line,List<ScheduleRealInfo> list){
  138 + List<Sheet> listAdd=new ArrayList<Sheet>();
  139 +// String line =map.get("line").toString();
  140 +// String date =map.get("date").toString();
  141 + SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm");
  142 + String sqlMinYysj="select start_opt from bsth_c_line_config where "
  143 + + " id = ("
  144 + + "select max(id) from bsth_c_line_config where line ='"+BasicData.lineId2CodeMap.inverse().get(line) +"'"
  145 + + ")";
  146 + List<String> listMin=jdbcTemplate.query(sqlMinYysj,
  147 + new RowMapper<String>(){
  148 + @Override
  149 + public String mapRow(ResultSet rs, int rowNum) throws SQLException {
  150 + String s=rs.getString("start_opt");
  151 + return s;
  152 + }
  153 + });
  154 + if(listMin.size()>0){
  155 + String minfcsj=listMin.get(0);
  156 + String[] minSjs = minfcsj.split(":");
  157 + //车辆最早发车时间 用了过滤超第二天0点的数据
  158 + Long minSj=Long.parseLong(minSjs[0])*60+Long.parseLong(minSjs[1]);
  159 + //0 上行 1下行
  160 + List<ScheduleRealInfo> listJhsj0=new ArrayList<ScheduleRealInfo>();
  161 +
  162 + List<ScheduleRealInfo> listJhsj1=new ArrayList<ScheduleRealInfo>();
  163 +
  164 + List<ScheduleRealInfo> listReal0=new ArrayList<ScheduleRealInfo>();
  165 +
  166 + List<ScheduleRealInfo> listReal1=new ArrayList<ScheduleRealInfo>();
  167 + //排除所有进出场班次
  168 +// List<ScheduleRealInfo> list=scheduleRealInfoRepository.scheduleByDateAndLine2(line, date);
  169 + /* for (int i = 0; i < list.size(); i++) {
  170 + //排除所有烂班的班次
  171 + ScheduleRealInfo s=list.get(i);
  172 + Set<ChildTaskPlan> cts=s.getcTasks();
  173 + if(cts!=null && cts.size() > 0){
  174 +
  175 + }
  176 + ScheduleRealInfo r=checkBc(s);
  177 + String[] fcsj= r.getFcsj().split(":");
  178 + Long fcsjL=Long.parseLong(fcsj[0])*60+Long.parseLong(fcsj[1]);
  179 + Long fscjT=0L;
  180 + if(fcsjL<minSj){
  181 + Calendar calendar = new GregorianCalendar();
  182 + calendar.setTime(r.getScheduleDate());
  183 + calendar.add(calendar.DATE,1);
  184 + r.setScheduleDate(calendar.getTime());
  185 + try {
  186 + fscjT = sdf.parse(sdf.format(r.getScheduleDate())+" "+r.getFcsj()).getTime();
  187 + } catch (ParseException e) {
  188 + // TODO Auto-generated catch block
  189 + e.printStackTrace();
  190 + }
  191 +
  192 + }else{
  193 + try {
  194 + fscjT =sdf.parse(r.getScheduleDateStr()+" "+r.getFcsj()).getTime();
  195 + } catch (ParseException e) {
  196 + // TODO Auto-generated catch block
  197 + e.printStackTrace();
  198 + };
  199 + }
  200 +
  201 + Sheet sheet=new Sheet();
  202 + Long fcsjAcual=0L;
  203 + if (r.getFcsjActual()!=null) {
  204 + if(!r.getFcsjActual().equals("")){
  205 + try {
  206 + fcsjAcual =sdf.parse(r.getRealExecDate()+" "+r.getFcsjActual()).getTime();
  207 + } catch (ParseException e) {
  208 + // TODO Auto-generated catch block
  209 + e.printStackTrace();
  210 + }
  211 +
  212 +
  213 + Long sjc=fscjT-fcsjAcual;
  214 + //在快慢五分钟内直接添加
  215 + if(sjc>= 3*60*1000*-1 && sjc <=3*60*1000){
  216 +
  217 + sheet.setDate(r.getScheduleDateStr());
  218 + sheet.setRealDate(r.getRealExecDate());
  219 + sheet.setJhsjt(fscjT);
  220 + sheet.setJhsj(r.getFcsj());
  221 + sheet.setSjsjt(fcsjAcual);
  222 + sheet.setSjsj(r.getFcsjActual());
  223 + sheet.setGs(r.getGsBm());
  224 + sheet.setFgs(r.getFgsBm());
  225 + sheet.setLine(r.getXlBm());
  226 + sheet.setXlDir(r.getXlDir());
  227 + sheet.setZdname(r.getQdzName());
  228 + sheet.setCreateDate(new Date());
  229 + listAdd.add(sheet);
  230 + }else{
  231 + r.setFcsjActualTime(fcsjAcual);
  232 + r.setFcsjT(fscjT);
  233 + if(r.getXlDir().equals("0")){
  234 + listJhsj0.add(r);
  235 + listReal0.add(r);
  236 + }else{
  237 + listJhsj1.add(r);
  238 + listReal1.add(r);
  239 + }
  240 + }
  241 + }else{
  242 + sheet.setDate(r.getScheduleDateStr());
  243 + sheet.setRealDate(r.getRealExecDate());
  244 + sheet.setJhsjt(fscjT);
  245 + sheet.setJhsj(r.getFcsj());
  246 + sheet.setSjsjt(0L);
  247 + sheet.setSjsj("烂班");
  248 + sheet.setGs(r.getGsBm());
  249 + sheet.setFgs(r.getFgsBm());
  250 + sheet.setLine(r.getXlBm());
  251 + sheet.setXlDir(r.getXlDir());
  252 + sheet.setZdname(r.getQdzName());
  253 + sheet.setCreateDate(new Date());
  254 + listAdd.add(sheet);
  255 + }
  256 + }else{
  257 + sheet.setDate(r.getScheduleDateStr());
  258 + sheet.setRealDate(r.getRealExecDate());
  259 + sheet.setJhsjt(fscjT);
  260 + sheet.setJhsj(r.getFcsj());
  261 + sheet.setSjsjt(0L);
  262 + sheet.setSjsj("烂班");
  263 + sheet.setGs(r.getGsBm());
  264 + sheet.setFgs(r.getFgsBm());
  265 + sheet.setLine(r.getXlBm());
  266 + sheet.setXlDir(r.getXlDir());
  267 + sheet.setZdname(r.getQdzName());
  268 + sheet.setCreateDate(new Date());
  269 + listAdd.add(sheet);
  270 + }
  271 + }*/
  272 + for (int i = 0; i < list.size(); i++) {
  273 + ScheduleRealInfo s=list.get(i);
  274 + ScheduleRealInfo r=checkBc(s);
  275 + String[] fcsj= r.getFcsj().split(":");
  276 + Long fcsjL=Long.parseLong(fcsj[0])*60+Long.parseLong(fcsj[1]);
  277 + Long fscjT=0L;
  278 + if(fcsjL<minSj){
  279 + Calendar calendar = new GregorianCalendar();
  280 + calendar.setTime(r.getScheduleDate());
  281 + calendar.add(calendar.DATE,1);
  282 + r.setScheduleDate(calendar.getTime());
  283 + try {
  284 + fscjT = sdf.parse(sdf.format(r.getScheduleDate())+" "+r.getFcsj()).getTime();
  285 + } catch (ParseException e) {
  286 + // TODO Auto-generated catch block
  287 + e.printStackTrace();
  288 + }
  289 +
  290 + }else{
  291 + try {
  292 + fscjT =sdf.parse(r.getScheduleDateStr()+" "+r.getFcsj()).getTime();
  293 + } catch (ParseException e) {
  294 + // TODO Auto-generated catch block
  295 + e.printStackTrace();
  296 + };
  297 + }
  298 + r.setFcsjT(fscjT);
  299 + Sheet sheet=new Sheet();
  300 + if (s.getFcsjActual() != null) {
  301 + Long fcsjAcual = 0L;
  302 + try {
  303 + fcsjAcual = sdf.parse(r.getRealExecDate() + " " + r.getFcsjActual()).getTime();
  304 + r.setFcsjActualTime(fcsjAcual);
  305 + r.setFcsjT(fscjT);
  306 + } catch (ParseException e) {
  307 + // TODO Auto-generated catch block
  308 + e.printStackTrace();
  309 + }
  310 + if (r.isSflj()) {
  311 + if (s.getXlDir().equals("0")) {
  312 + listReal0.add(r);
  313 + } else {
  314 + listReal1.add(r);
  315 + }
  316 +
  317 + } else {
  318 + if (s.getFcsjActual() != null) {
  319 + Long sjc = fcsjAcual - fscjT;
  320 + // 在快慢五分钟内直接添加
  321 + if (sjc >= 1 * 60 * 1000 * -1 && sjc <= 3 * 60 * 1000) {
  322 + sheet.setDate(r.getScheduleDateStr());
  323 + sheet.setRealDate(r.getRealExecDate());
  324 + sheet.setJhsjt(fscjT);
  325 + sheet.setJhsj(r.getFcsj());
  326 + sheet.setSjsjt(fcsjAcual);
  327 + sheet.setSjsj(r.getFcsjActual());
  328 + sheet.setGs(r.getGsBm());
  329 + sheet.setFgs(r.getFgsBm());
  330 + sheet.setLine(r.getXlBm());
  331 + sheet.setXlDir(r.getXlDir());
  332 + sheet.setZdname(r.getQdzName());
  333 + sheet.setCreateDate(new Date());
  334 + listAdd.add(sheet);
  335 + } else {
  336 + if (r.getXlDir().equals("0")) {
  337 + listJhsj0.add(r);
  338 + listReal0.add(r);
  339 + } else {
  340 + listJhsj1.add(r);
  341 + listReal1.add(r);
  342 + }
  343 + }
  344 + }
  345 + }
  346 + } else {
  347 + /*sheet.setDate(r.getScheduleDateStr());
  348 + sheet.setRealDate(r.getRealExecDate());
  349 + sheet.setJhsjt(fscjT);
  350 + sheet.setJhsj(r.getFcsj());
  351 + sheet.setSjsjt(0L);
  352 + sheet.setSjsj("烂班");
  353 + sheet.setGs(r.getGsBm());
  354 + sheet.setFgs(r.getFgsBm());
  355 + sheet.setLine(r.getXlBm());
  356 + sheet.setXlDir(r.getXlDir());
  357 + sheet.setZdname(r.getQdzName());
  358 + sheet.setCreateDate(new Date());
  359 + listAdd.add(sheet);*/
  360 + r.setFcsjActualTime(0L);
  361 + r.setFcsjT(fscjT);
  362 + r.setFcsjActual("烂班");
  363 + if (r.getXlDir().equals("0")) {
  364 + listJhsj0.add(r);
  365 + listReal0.add(r);
  366 + } else {
  367 + listJhsj1.add(r);
  368 + listReal1.add(r);
  369 + }
  370 +
  371 + }
  372 +
  373 + }
  374 + //计发排序
  375 + Collections.sort(listJhsj0, new ComparableReal());
  376 + Collections.sort(listJhsj1, new ComparableReal());
  377 + //实发排序
  378 + Collections.sort(listReal0,new ComparableAcual());
  379 + Collections.sort(listReal1,new ComparableAcual());
  380 +
  381 + //计划发车时间和实际发车时间比较计算准点率
  382 +
  383 +
  384 +
  385 + int no=listJhsj0.size()*2;
  386 + boolean fage=true;
  387 +// for (int p = no; p > 0; p--) {
  388 + while(fage){
  389 + //查询所有的实发 对应最接近的 计发
  390 + List<Map<String, Object>> list_map=new ArrayList<Map<String,Object>>();
  391 + for (int i = 0; i < listReal0.size(); i++) {
  392 + Map<String, Object> m_=new HashMap<String,Object>();
  393 + ScheduleRealInfo s1=listReal0.get(i);
  394 + Long sjsj=s1.getFcsjActualTime();
  395 + ScheduleRealInfo absInfo=new ScheduleRealInfo();
  396 + int next_j=listJhsj0.size();
  397 + for (int j = 0; j < listJhsj0.size(); j++) {
  398 + ScheduleRealInfo s2=listJhsj0.get(j);
  399 + if(j==0){
  400 + absInfo=s2;
  401 + }else{
  402 + //计发实发时间绝对值比较 取到最接近的值
  403 + Long abs1 = Math.abs(sjsj - s2.getFcsjT());
  404 + Long abs2 = Math.abs(sjsj -absInfo.getFcsjT());
  405 + if(abs2-abs1>0){
  406 + absInfo=s2;
  407 + next_j=j;
  408 + }
  409 + }
  410 + }
  411 + if(next_j<=0){
  412 + break;
  413 + }else{
  414 + m_.put("s", s1.getId());
  415 + m_.put("j", absInfo.getId());
  416 + m_.put("s_list", s1);
  417 + m_.put("j_list", absInfo);
  418 + m_.put("abs", Math.abs(sjsj-absInfo.getFcsjT()));
  419 + list_map.add(m_);
  420 + }
  421 + }
  422 + Collections.sort(list_map,new ComparableMap());
  423 + Map<String, Object> m_s=new HashMap<String,Object>();
  424 + List<Map<String, Object>> list_m_s=new ArrayList<Map<String,Object>>();
  425 +
  426 + for (int i = 0; i < list_map.size(); i++) {
  427 + Map<String, Object> m_=list_map.get(i);
  428 + Map<String, Object> m_l=new HashMap<String,Object>();
  429 + if(m_s.get(m_.get("j").toString())==null){
  430 + m_s.put(m_.get("s").toString(), m_.get("s"));
  431 + m_s.put(m_.get("j").toString(), m_.get("j"));
  432 + m_l.put("s", m_.get("s"));
  433 + m_l.put("j", m_.get("j"));
  434 + m_l.put("s_l",m_.get("s_list"));
  435 + m_l.put("j_l",m_.get("j_list"));
  436 + list_m_s.add(m_l);
  437 + }
  438 + }
  439 + for (int i = 0; i < list_m_s.size(); i++) {
  440 + Map<String, Object> m_l=list_m_s.get(i);
  441 + Long s=Long.parseLong(m_l.get("s").toString());
  442 + boolean s_bool=false;
  443 + for (int k = 0; k < listReal0.size(); k++) {
  444 + ScheduleRealInfo s0=listReal0.get(k);
  445 + if(s0.getId()-s==0){
  446 + listReal0.remove(s0);
  447 + s_bool=true;
  448 + }
  449 + }
  450 +
  451 + Long j=Long.parseLong(m_l.get("j").toString());
  452 + boolean j_bool=false;
  453 + for (int j2 = 0; j2 < listJhsj0.size(); j2++) {
  454 + ScheduleRealInfo j0=listJhsj0.get(j2);
  455 + if(j0.getId()-j==0){
  456 + listJhsj0.remove(j0);
  457 + j_bool=true;
  458 + }
  459 + }
  460 +
  461 + if(s_bool&&j_bool){
  462 + ScheduleRealInfo sf=(ScheduleRealInfo)m_l.get("s_l");
  463 + ScheduleRealInfo jf=(ScheduleRealInfo)m_l.get("j_l");
  464 + Sheet sheet=new Sheet();
  465 + sheet.setDate(sf.getScheduleDateStr());
  466 + sheet.setRealDate(sf.getRealExecDate());
  467 + sheet.setJhsjt(jf.getFcsjT());
  468 + sheet.setJhsj(jf.getFcsj());
  469 + sheet.setSjsjt(sf.getFcsjActualTime());
  470 + sheet.setSjsj(sf.getFcsjActual());
  471 + sheet.setGs(sf.getGsBm());
  472 + sheet.setFgs(sf.getFgsBm());
  473 + sheet.setLine(sf.getXlBm());
  474 + sheet.setXlDir(sf.getXlDir());
  475 + sheet.setZdname(sf.getQdzName());
  476 + sheet.setCreateDate(new Date());
  477 + listAdd.add(sheet);
  478 + }
  479 + }
  480 +
  481 + if(listJhsj0.size()<=0){
  482 + fage=false;
  483 + }
  484 + no--;
  485 + if(no<0){
  486 + fage=false;
  487 + }
  488 + }
  489 +
  490 +
  491 + int nos=listJhsj1.size()*2;
  492 + fage=true;
  493 + while(fage){
  494 + //查询所有的实发 对应最接近的 计发
  495 + List<Map<String, Object>> list_map=new ArrayList<Map<String,Object>>();
  496 + for (int i = 0; i < listReal1.size(); i++) {
  497 + Map<String, Object> m_=new HashMap<String,Object>();
  498 + ScheduleRealInfo s1=listReal1.get(i);
  499 + Long sjsj=s1.getFcsjActualTime();
  500 + ScheduleRealInfo absInfo=new ScheduleRealInfo();
  501 + int next_j=listJhsj1.size();
  502 + for (int j = 0; j < listJhsj1.size(); j++) {
  503 + ScheduleRealInfo s2=listJhsj1.get(j);
  504 + if(j==0){
  505 + absInfo=s2;
  506 + }else{
  507 + //计发实发时间绝对值比较 取到最接近的值
  508 + Long abs1 = Math.abs(sjsj - s2.getFcsjT());
  509 + Long abs2 = Math.abs(sjsj -absInfo.getFcsjT());
  510 + if(abs2-abs1>0){
  511 + absInfo=s2;
  512 + next_j=j;
  513 + }
  514 + }
  515 + }
  516 + if(next_j<=0){
  517 + break;
  518 + }else{
  519 + m_.put("s", s1.getId());
  520 + m_.put("j", absInfo.getId());
  521 + m_.put("s_list", s1);
  522 + m_.put("j_list", absInfo);
  523 + m_.put("abs", Math.abs(sjsj-absInfo.getFcsjT()));
  524 + list_map.add(m_);
  525 + }
  526 +
  527 + }
  528 + Collections.sort(list_map,new ComparableMap());
  529 + Map<String, Object> m_s=new HashMap<String,Object>();
  530 + List<Map<String, Object>> list_m_s=new ArrayList<Map<String,Object>>();
  531 +
  532 + for (int i = 0; i < list_map.size(); i++) {
  533 + Map<String, Object> m_=list_map.get(i);
  534 + Map<String, Object> m_l=new HashMap<String,Object>();
  535 + if(m_s.get(m_.get("j").toString())==null){
  536 + m_s.put(m_.get("s").toString(), m_.get("s"));
  537 + m_s.put(m_.get("j").toString(), m_.get("j"));
  538 + m_l.put("s", m_.get("s"));
  539 + m_l.put("j", m_.get("j"));
  540 + m_l.put("s_l",m_.get("s_list"));
  541 + m_l.put("j_l",m_.get("j_list"));
  542 + list_m_s.add(m_l);
  543 + }
  544 + }
  545 + for (int i = 0; i < list_m_s.size(); i++) {
  546 + Map<String, Object> m_l=list_m_s.get(i);
  547 + Long s=Long.parseLong(m_l.get("s").toString());
  548 + boolean s_bool=false;
  549 + for (int k = 0; k < listReal1.size(); k++) {
  550 + ScheduleRealInfo s0=listReal1.get(k);
  551 + if(s0.getId()-s==0){
  552 + listReal1.remove(s0);
  553 + s_bool=true;
  554 + }
  555 + }
  556 +
  557 + Long j=Long.parseLong(m_l.get("j").toString());
  558 + boolean j_bool=false;
  559 + for (int j2 = 0; j2 < listJhsj1.size(); j2++) {
  560 + ScheduleRealInfo j0=listJhsj1.get(j2);
  561 + if(j0.getId()-j==0){
  562 + listJhsj1.remove(j0);
  563 + j_bool=true;
  564 + }
  565 + }
  566 +
  567 + if(s_bool&&j_bool){
  568 + ScheduleRealInfo sf=(ScheduleRealInfo)m_l.get("s_l");
  569 + ScheduleRealInfo jf=(ScheduleRealInfo)m_l.get("j_l");
  570 + Sheet sheet=new Sheet();
  571 + sheet.setDate(sf.getScheduleDateStr());
  572 + sheet.setRealDate(sf.getRealExecDate());
  573 + sheet.setJhsjt(jf.getFcsjT());
  574 + sheet.setJhsj(jf.getFcsj());
  575 + sheet.setSjsjt(sf.getFcsjActualTime());
  576 + sheet.setSjsj(sf.getFcsjActual());
  577 + sheet.setGs(sf.getGsBm());
  578 + sheet.setFgs(sf.getFgsBm());
  579 + sheet.setLine(sf.getXlBm());
  580 + sheet.setXlDir(sf.getXlDir());
  581 + sheet.setZdname(sf.getQdzName());
  582 + sheet.setCreateDate(new Date());
  583 + listAdd.add(sheet);
  584 + }
  585 + }
  586 +
  587 + if(listJhsj1.size()<=0){
  588 + fage=false;
  589 + }
  590 + nos--;
  591 + if(nos<0){
  592 + fage=false;
  593 + }
  594 + }
  595 + }
  596 + return listAdd;
  597 + }
  598 +
  599 + public ScheduleRealInfo checkBc(ScheduleRealInfo s){
  600 + //如果班次有子任务 且 子任务中有属于营运的。把该子任务的发车时间设置成班次的发车时间
  601 + Set<ChildTaskPlan> childTaskPlans = s.getcTasks();
  602 + if(!childTaskPlans.isEmpty()){
  603 + List<ChildTaskPlan> listit=new ArrayList<ChildTaskPlan>(childTaskPlans);
  604 + Collections.sort(listit, new ComparableChild());
  605 + for (int i = 0; i < listit.size(); i++) {
  606 + ChildTaskPlan c=listit.get(i);
  607 + if(!c.isDestroy()){
  608 + if(c.getMileageType().equals("service")){
  609 + s.setFcsjActual(c.getStartDate());
  610 + break;
  611 + }
  612 +
  613 + }
  614 + }
  615 + }
  616 + return s;
  617 + }
  618 +
  619 + public Long abs_js(List<ScheduleRealInfo> list,ScheduleRealInfo t){
  620 + Long jhsj=t.getFcsjT();
  621 + ScheduleRealInfo absInfo=new ScheduleRealInfo();
  622 + for (int j = 0; j < list.size(); j++) {
  623 + ScheduleRealInfo s =list.get(j);
  624 + if(j==0){
  625 + absInfo=s;
  626 + }else{
  627 + //计发实发时间绝对值比较 取到最接近的值
  628 + Long abs1 = Math.abs(jhsj - s.getFcsjActualTime());
  629 + Long abs2 = Math.abs(absInfo.getFcsjActualTime());
  630 + if(abs2-abs1>0){
  631 + absInfo=s;
  632 + }
  633 + }
  634 + }
  635 + return absInfo.getId();
  636 +
  637 + }
  638 +
  639 + @Override
  640 + public List<Map<String, Object>> countList(Map<String, Object> map) {
  641 + // TODO Auto-generated method stub
  642 + List<Map<String, Object>> listmap=new ArrayList<Map<String,Object>>();
  643 + String line="";
  644 + if(map.get("line")!=null){
  645 + line =map.get("line").toString();
  646 + }
  647 + String gs="";
  648 + if(map.get("gs")!=null){
  649 + gs=map.get("gs").toString();
  650 + }
  651 + String fgs="";
  652 + if(map.get("fgs")!=null){
  653 + fgs=map.get("fgs").toString();
  654 + }
  655 + String date=map.get("date").toString();
  656 + String sql="select * from bsth_c_sheet where date='"+date+"'";
  657 + if(line.trim().equals("")){
  658 + sql +=" and gs like '%"+gs+"%' and fgs like '%"+fgs+"%'";
  659 + }else{
  660 + sql +=" and line ='"+line+"'";
  661 + }
  662 + sql +=" order by line ";
  663 + List<Sheet> list=jdbcTemplate.query(sql,
  664 + new RowMapper<Sheet>(){
  665 + @Override
  666 + public Sheet mapRow(ResultSet rs, int rowNum) throws SQLException {
  667 + Sheet s=new Sheet();
  668 + s.setGs(rs.getString("gs"));
  669 + s.setFgs(rs.getString("fgs"));
  670 + s.setLine(rs.getString("line"));
  671 + s.setDate(rs.getString("date"));
  672 + s.setJhsj(rs.getString("jhsj"));
  673 + s.setJhsjt(rs.getLong("jhsjt"));
  674 + s.setSjsj(rs.getString("sjsj"));
  675 + s.setSjsjt(rs.getLong("sjsjt"));
  676 + s.setId(rs.getInt("id"));
  677 + return s;
  678 + }
  679 + });
  680 +
  681 + String sqlByLine="select line from bsth_c_sheet where date='"+date+"'";
  682 + if(line.trim().equals("")){
  683 + sqlByLine +=" and gs like '%"+gs+"%' and fgs like '%"+fgs+"%'";
  684 + }else{
  685 + sqlByLine +=" and line ='"+line+"'";
  686 + }
  687 + sqlByLine +=" group by line ";
  688 + List<String> listLine=jdbcTemplate.query(sqlByLine,
  689 + new RowMapper<String>(){
  690 + @Override
  691 + public String mapRow(ResultSet rs, int rowNum) throws SQLException {
  692 + String line=rs.getString("line");
  693 + return line;
  694 + }
  695 + });
  696 + for (int i = 0; i < listLine.size(); i++) {
  697 + String xlbm=listLine.get(i);
  698 + List<Sheet> newList=new ArrayList<Sheet>();
  699 + for (int j = 0; j < list.size(); j++) {
  700 + if(xlbm.equals(list.get(j).getLine())){
  701 + newList.add(list.get(j));
  702 + }
  703 + }
  704 +
  705 + if(newList.size()>0){
  706 + Map<String, Object> newmap=culateByLine(newList);
  707 + listmap.add(newmap);
  708 + }
  709 +
  710 + }
  711 + return listmap;
  712 + }
  713 +
  714 + public Map<String, Object> culateByLine(List<Sheet> list){
  715 + Map<String, Object> map=new HashMap<String,Object>();
  716 + String gs=BasicData.businessCodeNameMap.get(list.get(0).getGs());
  717 + String fgs=BasicData.businessFgsCodeNameMap.get(list.get(0).getFgs()+"_"+list.get(0).getGs());
  718 + String line=BasicData.lineCode2NameMap.get(list.get(0).getLine());
  719 + Integer id=list.get(0).getId();
  720 + int bcs=list.size();
  721 + int zdbcs=0;
  722 + for (int i = 0; i < list.size(); i++) {
  723 + Sheet s=list.get(i);
  724 + Long sjc=s.getJhsjt()-s.getSjsjt();
  725 + if(sjc>= 3*60*1000*-1 && sjc <=1*60*1000){
  726 + zdbcs++;
  727 + }
  728 + }
  729 + double zdlv =(zdbcs*1.0/bcs)*100;
  730 + DecimalFormat df = new DecimalFormat("0.00");
  731 + map.put("gs", gs);
  732 + map.put("fgs", fgs);
  733 + map.put("line", line);
  734 + map.put("bcs", bcs);
  735 + map.put("zdbcs", zdbcs);
  736 + map.put("zdlv", df.format(zdlv)+"%");
  737 + map.put("id", id);
  738 + return map;
  739 + }
  740 + @Override
  741 + public List<Sheet> sheetList(Integer id) {
  742 + // TODO Auto-generated method stub
  743 + Sheet sheet=sheetRepository.findOne(id);
  744 + String sql="select * from bsth_c_sheet where date='"+sheet.getDate()+"' and line = '"+sheet.getLine()+"'"
  745 + + " order by xl_dir,jhsj";
  746 +
  747 + List<Sheet> list=jdbcTemplate.query(sql,
  748 + new RowMapper<Sheet>(){
  749 + @Override
  750 + public Sheet mapRow(ResultSet rs, int rowNum) throws SQLException {
  751 + Sheet s=new Sheet();
  752 + s.setId(rs.getInt("id"));
  753 + s.setGs(rs.getString("gs"));
  754 + s.setFgs(rs.getString("fgs"));
  755 + s.setLine(rs.getString("line"));
  756 + s.setDate(rs.getString("date"));
  757 + s.setJhsj(rs.getString("jhsj"));
  758 + s.setJhsjt(rs.getLong("jhsjt"));
  759 + s.setSjsj(rs.getString("sjsj"));
  760 + s.setSjsjt(rs.getLong("sjsjt"));
  761 + s.setZdname(rs.getString("zdname"));
  762 + return s;
  763 + }
  764 + });
  765 + for (int i = 0; i < list.size(); i++) {
  766 + Sheet t=list.get(i);
  767 + t.setLine(BasicData.lineCode2NameMap.get(t.getLine()));
  768 + Long sjc=t.getJhsjt()-t.getSjsjt();
  769 + if(sjc>= 3*60*1000*-1 && sjc <=1*60*1000){
  770 + t.setSfzd("Y");
  771 + }else{
  772 + t.setSfzd("N");
  773 + }
  774 + }
  775 +
  776 + return list;
  777 + }
  778 +
  779 +
  780 +}
  781 + class ComparableAcual implements Comparator<ScheduleRealInfo>{
  782 +
  783 + @Override
  784 + public int compare(ScheduleRealInfo o1, ScheduleRealInfo o2) {
  785 + // TODO Auto-generated method stub
  786 + return o1.getFcsjActualTime().compareTo(o2.getFcsjActualTime());
  787 + }
  788 +
  789 +}
  790 +
  791 + class ComparableMap implements Comparator<Map<String, Object>>{
  792 + @Override
  793 + public int compare(Map<String, Object> o1, Map<String, Object> o2) {
  794 + // TODO Auto-generated method stub
  795 + return (int) (Long.parseLong(o1.get("abs").toString())-Long.parseLong((o2.get("abs").toString())));
  796 + }
  797 + }
src/main/resources/static/pages/report/sheet/list.html 0 → 100644
  1 +<style type="text/css">
  2 + .table-bordered {
  3 + border: 1px solid; }
  4 + .table-bordered > thead > tr > th,
  5 + .table-bordered > thead > tr > td,
  6 + .table-bordered > tbody > tr > th,
  7 + .table-bordered > tbody > tr > td,
  8 + .table-bordered > tfoot > tr > th,
  9 + .table-bordered > tfoot > tr > td {
  10 + border: 1px solid; }
  11 + .table-bordered > thead > tr > th,
  12 + .table-bordered > thead > tr > td {
  13 + border-bottom-width: 2px; }
  14 +
  15 + .table > tbody + tbody {
  16 + border-top: 1px solid; }
  17 +</style>
  18 +
  19 +<div class="page-head">
  20 + <div class="page-title" style="margin-left: 20px">
  21 + <button>数据导出</button>
  22 + </div>
  23 +</div>
  24 +
  25 +<div class="row" id="sheetList">
  26 + <div class="col-md-12">
  27 + <div class="portlet light porttlet-fit bordered">
  28 + <div class="portlet-body">
  29 + <div class="table-container" style="margin-top: 10px;overflow:auto;min-width: 600px">
  30 + <table class="table table-bordered table-hover table-checkable" id="forms_1">
  31 + <thead>
  32 + <tr>
  33 + <td></td>
  34 + <td>日期</td>
  35 + <td>线路</td>
  36 + <td>站点</td>
  37 + <td>计划时间</td>
  38 + <td>实际时间</td>
  39 + <td>是否准点</td>
  40 + </tr>
  41 + </thead>
  42 +
  43 + <tbody >
  44 +
  45 + </tbody>
  46 + </table>
  47 + </div>
  48 + </div>
  49 + </div>
  50 + </div>
  51 +</div>
  52 +
  53 +<script>
  54 + $(function(){
  55 + // 关闭左侧栏
  56 + if (!$('body').hasClass('page-sidebar-closed'))
  57 + $('.menu-toggler.sidebar-toggler').click();
  58 +
  59 + $("#sheetList").on('init', function (e, id) {
  60 + $get('/sheet/sheetList',{id:id},function(result){
  61 + var sheetList_1 = template('sheetList_1',{list:result});
  62 + $('#forms_1 tbody').html(sheetList_1);
  63 + });
  64 + })
  65 + /* $("#query").on('click',function(){
  66 + var line = $("#line").val();
  67 + var date = $("#date").val();
  68 + var fgs=$('#fgsdm').val();
  69 + var gs=$('#gsdm').val();
  70 + $get('/sheet/countList',{line:line,date:date,gs:gs,fgs:fgs},function(result){
  71 + var sheetList = template('sheetList',{list:result});
  72 + $('#forms tbody').html(sheetList);
  73 + $('.btn-sheetList').on('click', openSheetList);
  74 + });
  75 + }); */
  76 +
  77 +
  78 + });
  79 +</script>
  80 +<script type="text/html" id="sheetList_1">
  81 + {{each list as obj i}}
  82 + <tr {{if obj.sfzd!="Y"}}style="color: red" {{/if}}>
  83 + <td>{{i}}</td>
  84 + <td>{{obj.date}}</td>
  85 + <td>{{obj.line}}</td>
  86 + <td>{{obj.zdname}}</td>
  87 + <td>{{obj.jhsj}}</td>
  88 + <td>{{obj.sjsj}}</td>
  89 + <td>
  90 + {{if obj.sfzd=="Y"}}准点{{else}}不准点{{/if}}
  91 + </td>
  92 + </tr>
  93 + {{/each}}
  94 + {{if list.length == 0}}
  95 + <tr>
  96 + <td colspan="7"><h6 class="muted">没有找到相关数据</h6></td>
  97 + </tr>
  98 + {{/if}}
  99 +</script>
0 \ No newline at end of file 100 \ No newline at end of file
src/main/resources/static/pages/report/sheet/sheetList.html 0 → 100644
  1 +<style type="text/css">
  2 + .table-bordered {
  3 + border: 1px solid; }
  4 + .table-bordered > thead > tr > th,
  5 + .table-bordered > thead > tr > td,
  6 + .table-bordered > tbody > tr > th,
  7 + .table-bordered > tbody > tr > td,
  8 + .table-bordered > tfoot > tr > th,
  9 + .table-bordered > tfoot > tr > td {
  10 + border: 1px solid; }
  11 + .table-bordered > thead > tr > th,
  12 + .table-bordered > thead > tr > td {
  13 + border-bottom-width: 2px; }
  14 +
  15 + .table > tbody + tbody {
  16 + border-top: 1px solid; }
  17 +</style>
  18 +
  19 +<div class="page-head">
  20 + <div class="page-title">
  21 + <h1>发车准点率</h1>
  22 + </div>
  23 +</div>
  24 +
  25 +<div class="row">
  26 + <div class="col-md-12">
  27 + <div class="portlet light porttlet-fit bordered">
  28 + <div class="portlet-title">
  29 + <form class="form-inline" action="">
  30 + <div style="display: inline-block; margin-left: 33px;" id="gsdmDiv">
  31 + <span class="item-label" style="width: 80px;">公司: </span>
  32 + <select class="form-control" name="company" id="gsdm" style="width: 180px;"></select>
  33 + </div>
  34 + <div style="display: inline-block; margin-left: 24px;" id="fgsdmDiv">
  35 + <span class="item-label" style="width: 80px;">分公司: </span>
  36 + <select class="form-control" name="subCompany" id="fgsdm" style="width: 180px;"></select>
  37 + </div>
  38 + <div style="display: inline-block;margin-left: 15px;">
  39 + <span class="item-label" style="width: 80px;">线路: </span>
  40 + <select class="form-control" name="line" id="line" style="width: 180px;"></select>
  41 + </div>
  42 + <div style="display: inline-block;">
  43 + <span class="item-label" style="width: 80px;">时间: </span>
  44 + <input class="form-control" type="text" id="date" style="width: 180px;"/>
  45 + </div>
  46 +
  47 + <div class="form-group">
  48 + <input class="btn btn-default" type="button" id="query" value="查询"/>
  49 +<!-- <input class="btn btn-default" type="button" id="export" value="导出"/> -->
  50 + </div>
  51 + </form>
  52 + </div>
  53 + <div class="portlet-body">
  54 + <div class="table-container" style="margin-top: 10px;overflow:auto;min-width: 906px">
  55 + <table class="table table-bordered table-hover table-checkable" id="forms">
  56 + <thead>
  57 + <tr>
  58 + <td>公司</td>
  59 + <td>分公司</td>
  60 + <td>线路</td>
  61 + <td>班次数</td>
  62 + <td>准点班次数</td>
  63 + <td>准点率</td>
  64 + <td>查看</td>
  65 + </tr>
  66 + </thead>
  67 +
  68 + <tbody >
  69 +
  70 + </tbody>
  71 + </table>
  72 + </div>
  73 + </div>
  74 + </div>
  75 + </div>
  76 +</div>
  77 +
  78 +<script>
  79 + $(function(){
  80 + // 关闭左侧栏
  81 + if (!$('body').hasClass('page-sidebar-closed'))
  82 + $('.menu-toggler.sidebar-toggler').click();
  83 +
  84 + $("#date").datetimepicker({
  85 + format : 'YYYY-MM-DD',
  86 + locale : 'zh-cn'
  87 + });
  88 + var d = new Date();
  89 + var year = d.getFullYear();
  90 + var month = d.getMonth() + 1;
  91 + var day = d.getDate();
  92 + if(day < 10)
  93 + day = "0"+day;
  94 + if(month > 9){
  95 + $("#date").val(year + "-" + month + "-" + day);
  96 + } else {
  97 + $("#date").val(year + "-0" + month + "-" + day);
  98 + }
  99 +
  100 + var fage=false;
  101 + var obj = [];
  102 + var xlList;
  103 + $.get('/report/lineList',function(result){
  104 + xlList=result;
  105 +
  106 + $.get('/user/companyData', function(result){
  107 + obj = result;
  108 + console.log(obj);
  109 + var options = '';
  110 + for(var i = 0; i < obj.length; i++){
  111 + options += '<option value="'+obj[i].companyCode+'">'+obj[i].companyName+'</option>';
  112 + }
  113 +
  114 + if(obj.length ==0){
  115 + $("#gsdmDiv").css('display','none');
  116 + }else if(obj.length ==1){
  117 + $("#gsdmDiv").css('display','none');
  118 + if(obj[0].children.length == 1 || obj[0].children.length ==0)
  119 + $('#fgsdmDiv').css('display','none');
  120 + }
  121 + $('#gsdm').html(options);
  122 +
  123 + updateCompany();
  124 + });
  125 + });
  126 +
  127 + $("#gsdm").on("change",updateCompany);
  128 + function updateCompany(){
  129 + var company = $('#gsdm').val();
  130 + var options = '';
  131 + for(var i = 0; i < obj.length; i++){
  132 + if(obj[i].companyCode == company){
  133 + var children = obj[i].children;
  134 + for(var j = 0; j < children.length; j++){
  135 + options += '<option value="'+children[j].code+'">'+children[j].name+'</option>';
  136 + }
  137 + }
  138 + }
  139 + $('#fgsdm').html(options);
  140 + initXl();
  141 + }
  142 +
  143 +
  144 +
  145 +
  146 + $("#fgsdm").on("change",initXl);
  147 + function initXl(){
  148 + var data=[];
  149 + if(fage){
  150 + $("#line").select2("destroy").html('');
  151 + }
  152 + data.push({id: " ", text: "请选择"});
  153 + var fgs=$('#fgsdm').val();
  154 + var gs=$('#gsdm').val();
  155 + for(var i=0;i<xlList.length;i++){
  156 + if(gs!=""){
  157 + if(fgs!=""){
  158 + if(xlList[i]["fgsbm"]==fgs && xlList[i]["gsbm"]==gs){
  159 + data.push({id: xlList[i]["xlbm"], text: xlList[i]["xlname"]});
  160 + }
  161 + }else{
  162 + if(xlList[i]["gsbm"]==gs){
  163 + data.push({id: xlList[i]["xlbm"], text: xlList[i]["xlname"]});
  164 + }
  165 + }
  166 + }
  167 + }
  168 + initPinYinSelect2('#line',data,'');
  169 + fage=true;
  170 + }
  171 + //查询
  172 + $("#query").on('click',function(){
  173 + var line = $("#line").val();
  174 + var date = $("#date").val();
  175 + var fgs=$('#fgsdm').val();
  176 + var gs=$('#gsdm').val();
  177 + $get('/sheet/countList',{line:line,date:date,gs:gs,fgs:fgs},function(result){
  178 + var sheetList = template('sheetList',{list:result});
  179 + $('#forms tbody').html(sheetList);
  180 + $('.btn-sheetList').on('click', openSheetList);
  181 + });
  182 +// $post('/sheet/saveListSheet',function(result){
  183 +// });
  184 + });
  185 +
  186 + function openSheetList(){
  187 + var id = $(this).data('id');
  188 + $.get('/pages/report/sheet/list.html', function (content) {
  189 + layer.open({
  190 + type: 1,
  191 + area: ['800px', '600px'],
  192 + content: content,
  193 + title: '线路准点率详细',
  194 + shift: 5,
  195 + scrollbar: false,
  196 + success: function () {
  197 + $('#sheetList').trigger('init', id);
  198 + }
  199 + });
  200 + });
  201 + }
  202 + });
  203 +</script>
  204 +<script type="text/html" id="sheetList">
  205 + {{each list as obj i}}
  206 + <tr>
  207 + <td>{{obj.gs}}</td>
  208 + <td>{{obj.fgs}}</td>
  209 + <td>{{obj.line}}</td>
  210 + <td>{{obj.bcs}}</td>
  211 + <td>{{obj.zdbcs}}</td>
  212 + <td>{{obj.zdlv}}</td>
  213 + <td>
  214 + <button type="button" class="btn btn-sm blue btn-sheetList"
  215 + data-id="{{obj.id}}">查看</button>
  216 + </td>
  217 + </tr>
  218 + {{/each}}
  219 + {{if list.length == 0}}
  220 + <tr>
  221 + <td colspan="7"><h6 class="muted">没有找到相关数据</h6></td>
  222 + </tr>
  223 + {{/if}}
  224 +</script>
0 \ No newline at end of file 225 \ No newline at end of file