Commit 45378fbbd7cfe699c2af5fa5e0d72067cde9bade

Authored by 娄高锋
1 parent b8ae17ac

LGF 报表

src/main/java/com/bsth/service/schedule/PeopleCarPlanServiceImpl.java
1 package com.bsth.service.schedule; 1 package com.bsth.service.schedule;
2 2
3 import java.math.BigDecimal; 3 import java.math.BigDecimal;
4 -import java.sql.Connection;  
5 -import java.sql.PreparedStatement;  
6 import java.sql.ResultSet; 4 import java.sql.ResultSet;
7 import java.sql.SQLException; 5 import java.sql.SQLException;
8 import java.text.DecimalFormat; 6 import java.text.DecimalFormat;
@@ -19,6 +17,8 @@ import java.util.Map; @@ -19,6 +17,8 @@ import java.util.Map;
19 import java.util.Set; 17 import java.util.Set;
20 18
21 import org.springframework.beans.factory.annotation.Autowired; 19 import org.springframework.beans.factory.annotation.Autowired;
  20 +import org.springframework.jdbc.core.JdbcTemplate;
  21 +import org.springframework.jdbc.core.RowMapper;
22 import org.springframework.stereotype.Service; 22 import org.springframework.stereotype.Service;
23 23
24 import com.bsth.entity.realcontrol.ScheduleRealInfo; 24 import com.bsth.entity.realcontrol.ScheduleRealInfo;
@@ -26,13 +26,15 @@ import com.bsth.entity.schedule.SchedulePlanInfo; @@ -26,13 +26,15 @@ import com.bsth.entity.schedule.SchedulePlanInfo;
26 import com.bsth.entity.schedule.TTInfoDetail; 26 import com.bsth.entity.schedule.TTInfoDetail;
27 import com.bsth.repository.realcontrol.ScheduleRealInfoRepository; 27 import com.bsth.repository.realcontrol.ScheduleRealInfoRepository;
28 import com.bsth.util.ReportUtils; 28 import com.bsth.util.ReportUtils;
29 -import com.bsth.util.db.DBUtils_MS;  
30 29
31 @Service 30 @Service
32 public class PeopleCarPlanServiceImpl implements PeopleCarPlanService { 31 public class PeopleCarPlanServiceImpl implements PeopleCarPlanService {
33 32
34 @Autowired 33 @Autowired
35 private ScheduleRealInfoRepository scheduleRealInfoRepository; 34 private ScheduleRealInfoRepository scheduleRealInfoRepository;
  35 +
  36 + @Autowired
  37 + private JdbcTemplate jdbcTemplate;
36 38
37 @Override 39 @Override
38 public List<Map<String, Object>> queryPeopleCar(String line, String date, String type) { 40 public List<Map<String, Object>> queryPeopleCar(String line, String date, String type) {
@@ -47,32 +49,31 @@ public class PeopleCarPlanServiceImpl implements PeopleCarPlanService { @@ -47,32 +49,31 @@ public class PeopleCarPlanServiceImpl implements PeopleCarPlanService {
47 } 49 }
48 50
49 try { 51 try {
50 - Connection conn = null;  
51 - PreparedStatement ps = null;  
52 - ResultSet rs = null;  
53 - String sql = "select * from bsth_c_s_sp_info where DATE_FORMAT(schedule_date,'%Y-%m-%d') = ?"; 52 +
  53 + String sql = "select * from bsth_c_s_sp_info where DATE_FORMAT(schedule_date,'%Y-%m-%d') = '"+date+"'";
54 if(line.length() != 0){ 54 if(line.length() != 0){
55 - sql += "and xl_bm = ?"; 55 + sql += " and xl_bm = '"+line+"'";
56 } 56 }
57 - conn = DBUtils_MS.getConnection();  
58 - ps = conn.prepareStatement(sql);  
59 - ps.setString(1, date);  
60 - if(line.length() != 0){  
61 - ps.setString(2, line);  
62 - }  
63 - rs = ps.executeQuery();  
64 - while(rs.next()){  
65 - SchedulePlanInfo schedule = new SchedulePlanInfo();  
66 - schedule.setXlName(rs.getString("xl_name"));  
67 - schedule.setLpName(rs.getString("lp_name"));  
68 - schedule.setClZbh(rs.getString("cl_zbh"));  
69 - schedule.setjName(rs.getString("j_name"));  
70 - schedule.setsName(rs.getString("s_name"));  
71 - schedule.setJhlc(rs.getDouble("jhlc"));  
72 - list.add(schedule);  
73 - }  
74 - DBUtils_MS.close(rs, ps, conn);  
75 - } catch (SQLException e) { 57 +
  58 + list =jdbcTemplate.query(sql,
  59 + new RowMapper<SchedulePlanInfo>(){
  60 + @Override
  61 + public SchedulePlanInfo mapRow(ResultSet rs, int rowNum) throws SQLException {
  62 +
  63 + SchedulePlanInfo schedule = new SchedulePlanInfo();
  64 +
  65 + schedule.setXlName(rs.getString("xl_name"));
  66 + schedule.setLpName(rs.getString("lp_name"));
  67 + schedule.setClZbh(rs.getString("cl_zbh"));
  68 + schedule.setjName(rs.getString("j_name"));
  69 + schedule.setsName(rs.getString("s_name"));
  70 + schedule.setJhlc(rs.getDouble("jhlc"));
  71 + return schedule;
  72 + }
  73 + });
  74 +
  75 +
  76 + } catch (Exception e) {
76 // TODO Auto-generated catch block 77 // TODO Auto-generated catch block
77 e.printStackTrace(); 78 e.printStackTrace();
78 } 79 }
@@ -365,52 +366,49 @@ public class PeopleCarPlanServiceImpl implements PeopleCarPlanService { @@ -365,52 +366,49 @@ public class PeopleCarPlanServiceImpl implements PeopleCarPlanService {
365 endDate = new SimpleDateFormat("yyyy-MM-dd").format(new Date()); 366 endDate = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
366 } 367 }
367 try { 368 try {
368 - Connection conn = null;  
369 - PreparedStatement ps = null;  
370 - ResultSet rs = null;  
371 - String sql = "select * from bsth_c_s_sp_info_real where DATE_FORMAT(schedule_date,'%Y-%m-%d') >= ? and DATE_FORMAT(schedule_date,'%Y-%m-%d') <= ?";  
372 - if(line.length() != 0){  
373 - sql += "and xl_bm = ?";  
374 - }  
375 - conn = DBUtils_MS.getConnection();  
376 - ps = conn.prepareStatement(sql);  
377 - ps.setString(1, startDate);  
378 - ps.setString(2, endDate); 369 +
  370 + String sql = "select * from bsth_c_s_sp_info_real where DATE_FORMAT(schedule_date,'%Y-%m-%d') >= '"+startDate+"' and DATE_FORMAT(schedule_date,'%Y-%m-%d') <= '"+endDate+"'";
379 if(line.length() != 0){ 371 if(line.length() != 0){
380 - ps.setString(3, line);  
381 - }  
382 - rs = ps.executeQuery();  
383 - while(rs.next()){  
384 - ScheduleRealInfo schedule = new ScheduleRealInfo();  
385 - schedule.setXlName(rs.getString("xl_name"));  
386 - schedule.setBcType(rs.getString("bc_type"));  
387 - schedule.setBcs(rs.getInt("bcs"));  
388 - schedule.setFcsj(rs.getString("fcsj"));  
389 - schedule.setFcsjActual(rs.getString("fcsj_actual"));  
390 - schedule.setZdsj(rs.getString("zdsj"));  
391 - schedule.setZdsjActual(rs.getString("zdsj_actual"));  
392 - schedule.setBcsj(rs.getInt("bcsj"));  
393 - schedule.setQdzName(rs.getString("qdz_name"));  
394 - if(schedule.getBcType().equals("normal"))  
395 - list.add(schedule); 372 + sql += " and xl_bm = '"+line+"'";
396 } 373 }
  374 + sql += " and bc_type = 'normal'";
  375 +
  376 + list =jdbcTemplate.query(sql,
  377 + new RowMapper<ScheduleRealInfo>(){
  378 + @Override
  379 + public ScheduleRealInfo mapRow(ResultSet rs, int rowNum) throws SQLException {
  380 + ScheduleRealInfo schedule = new ScheduleRealInfo();
  381 + schedule.setXlName(rs.getString("xl_name"));
  382 + schedule.setBcType(rs.getString("bc_type"));
  383 + schedule.setBcs(rs.getInt("bcs"));
  384 + schedule.setFcsj(rs.getString("fcsj"));
  385 + schedule.setFcsjActual(rs.getString("fcsj_actual"));
  386 + schedule.setZdsj(rs.getString("zdsj"));
  387 + schedule.setZdsjActual(rs.getString("zdsj_actual"));
  388 + schedule.setBcsj(rs.getInt("bcsj"));
  389 + schedule.setQdzName(rs.getString("qdz_name"));
  390 + return schedule;
  391 + }
  392 + });
  393 +
397 if(model.length() != 0){ 394 if(model.length() != 0){
398 - sql = "select * from bsth_c_s_ttinfo_detail where ttinfo = ?";  
399 - ps = conn.prepareStatement(sql);  
400 - ps.setString(1, model);  
401 - rs = ps.executeQuery();  
402 - while(rs.next()){ 395 + sql = "select * from bsth_c_s_ttinfo_detail where ttinfo = '"+model+"' and bc_type = 'normal'";
  396 + }
  397 +
  398 + ttList =jdbcTemplate.query(sql,
  399 + new RowMapper<TTInfoDetail>(){
  400 + @Override
  401 + public TTInfoDetail mapRow(ResultSet rs, int rowNum) throws SQLException {
403 TTInfoDetail ttInfo = new TTInfoDetail(); 402 TTInfoDetail ttInfo = new TTInfoDetail();
404 ttInfo.setBcType(rs.getString("bc_type")); 403 ttInfo.setBcType(rs.getString("bc_type"));
405 ttInfo.setBcs(rs.getInt("bcs")); 404 ttInfo.setBcs(rs.getInt("bcs"));
406 ttInfo.setFcsj(rs.getString("fcsj")); 405 ttInfo.setFcsj(rs.getString("fcsj"));
407 ttInfo.setBcsj(rs.getInt("bcsj")); 406 ttInfo.setBcsj(rs.getInt("bcsj"));
408 - if(ttInfo.getBcType().equals("normal"))  
409 - ttList.add(ttInfo); 407 + return ttInfo;
410 } 408 }
411 - }  
412 - DBUtils_MS.close(rs, ps, conn);  
413 - } catch (SQLException e) { 409 + });
  410 +
  411 + } catch (Exception e) {
414 // TODO Auto-generated catch block 412 // TODO Auto-generated catch block
415 e.printStackTrace(); 413 e.printStackTrace();
416 } 414 }
@@ -580,31 +578,28 @@ public class PeopleCarPlanServiceImpl implements PeopleCarPlanService { @@ -580,31 +578,28 @@ public class PeopleCarPlanServiceImpl implements PeopleCarPlanService {
580 endDate = sdf.format(new Date()); 578 endDate = sdf.format(new Date());
581 } 579 }
582 try { 580 try {
583 - Connection conn = null;  
584 - PreparedStatement ps = null;  
585 - ResultSet rs = null; 581 +
586 String sql = "select tt.id, tt.name, qyrq, tt.rule_days, tt.special_days from bsth_c_s_ttinfo tt left join bsth_c_line cl on cl.id = tt.xl where tt.is_cancel = 0 and tt.is_enable_dis_template = 1"; 582 String sql = "select tt.id, tt.name, qyrq, tt.rule_days, tt.special_days from bsth_c_s_ttinfo tt left join bsth_c_line cl on cl.id = tt.xl where tt.is_cancel = 0 and tt.is_enable_dis_template = 1";
587 if(line.length() != 0){ 583 if(line.length() != 0){
588 - sql += " and cl.line_code = ?"; 584 + sql += " and cl.line_code = '"+line+"'";
589 } 585 }
590 sql += " order by tt.create_date desc"; 586 sql += " order by tt.create_date desc";
591 - conn = DBUtils_MS.getConnection();  
592 - ps = conn.prepareStatement(sql);  
593 - if(line.length() != 0){  
594 - ps.setString(1, line);  
595 - }  
596 - rs = ps.executeQuery();  
597 - while(rs.next()){  
598 - Map<String, Object> map = new HashMap<String, Object>();  
599 - map.put("id", rs.getString("id"));  
600 - map.put("name", rs.getString("name"));  
601 - map.put("qyrq", rs.getString("qyrq"));  
602 - map.put("ruleDays", rs.getString("rule_days"));  
603 - map.put("specialDays", rs.getString("special_days"));  
604 - list.add(map);  
605 - }  
606 - DBUtils_MS.close(rs, ps, conn);  
607 - } catch (SQLException e) { 587 +
  588 + list = jdbcTemplate.query(sql,
  589 + new RowMapper<Map<String, Object>>(){
  590 + @Override
  591 + public Map<String, Object> mapRow(ResultSet rs, int rowNum) throws SQLException {
  592 + Map<String, Object> map = new HashMap<String, Object>();
  593 + map.put("id", rs.getString("id"));
  594 + map.put("name", rs.getString("name"));
  595 + map.put("qyrq", rs.getString("qyrq"));
  596 + map.put("ruleDays", rs.getString("rule_days"));
  597 + map.put("specialDays", rs.getString("special_days"));
  598 + return map;
  599 + }
  600 + });
  601 +
  602 + } catch (Exception e) {
608 // TODO Auto-generated catch block 603 // TODO Auto-generated catch block
609 e.printStackTrace(); 604 e.printStackTrace();
610 } 605 }
@@ -820,63 +815,48 @@ public class PeopleCarPlanServiceImpl implements PeopleCarPlanService { @@ -820,63 +815,48 @@ public class PeopleCarPlanServiceImpl implements PeopleCarPlanService {
820 date = new SimpleDateFormat("yyyy-MM-dd").format(new Date()); 815 date = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
821 816
822 try { 817 try {
823 - Connection conn = null;  
824 - PreparedStatement ps = null;  
825 - ResultSet rs = null; 818 +
826 String sql = "select r.id, r.schedule_date_str, r.xl_name, r.cl_zbh, r.j_gh, r.j_name, r.fcsj, d.timestamp, d.reply46, d.reply47, d.reply46time, d.reply47time " + 819 String sql = "select r.id, r.schedule_date_str, r.xl_name, r.cl_zbh, r.j_gh, r.j_name, r.fcsj, d.timestamp, d.reply46, d.reply47, d.reply46time, d.reply47time " +
827 - "FROM bsth_c_s_sp_info_real as r left join bsth_v_directive_60 as d on r.id = d.sch and d.is_dispatch = 1 where DATE_FORMAT(schedule_date,'%Y-%m-%d') = ?"; 820 + "FROM bsth_c_s_sp_info_real as r left join bsth_v_directive_60 as d on r.id = d.sch and d.is_dispatch = 1 where DATE_FORMAT(schedule_date,'%Y-%m-%d') = '"+date+"'";
828 if(line.length() != 0){ 821 if(line.length() != 0){
829 - sql += " and xl_bm = ?"; 822 + sql += " and xl_bm = '"+line+"'";
830 } 823 }
831 if(code.length() != 0){ 824 if(code.length() != 0){
832 - sql += " and cl_zbh = ?"; 825 + sql += " and cl_zbh = '"+code+"'";
833 } 826 }
834 sql += " union " + 827 sql += " union " +
835 "select r.id, r.schedule_date_str, r.xl_name, r.cl_zbh, r.j_gh, r.j_name, r.fcsj, d.timestamp, d.reply46, d.reply47, d.reply46time, d.reply47time " + 828 "select r.id, r.schedule_date_str, r.xl_name, r.cl_zbh, r.j_gh, r.j_name, r.fcsj, d.timestamp, d.reply46, d.reply47, d.reply46time, d.reply47time " +
836 - "FROM bsth_c_s_sp_info_real as r right join bsth_v_directive_60 as d on r.id = d.sch where d.is_dispatch = 1 and DATE_FORMAT(schedule_date,'%Y-%m-%d') = ?"; 829 + "FROM bsth_c_s_sp_info_real as r right join bsth_v_directive_60 as d on r.id = d.sch where d.is_dispatch = 1 and DATE_FORMAT(schedule_date,'%Y-%m-%d') = '"+date+"'";
837 if(line.length() != 0){ 830 if(line.length() != 0){
838 - sql += " and xl_bm = ?"; 831 + sql += " and xl_bm = '"+line+"'";
839 } 832 }
840 if(code.length() != 0){ 833 if(code.length() != 0){
841 - sql += " and cl_zbh = ?"; 834 + sql += " and cl_zbh = '"+code+"'";
842 } 835 }
843 sql += " order by fcsj"; 836 sql += " order by fcsj";
844 - conn = DBUtils_MS.getConnection();  
845 - ps = conn.prepareStatement(sql);  
846 - int i = 1;  
847 - ps.setString(i++, date);  
848 - if(line.length() != 0){  
849 - ps.setString(i++, line);  
850 - }  
851 - if(code.length() != 0){  
852 - ps.setString(i++, code);  
853 - }  
854 - ps.setString(i++, date);  
855 - if(line.length() != 0){  
856 - ps.setString(i++, line);  
857 - }  
858 - if(code.length() != 0){  
859 - ps.setString(i++, code);  
860 - }  
861 - rs = ps.executeQuery();  
862 - while(rs.next()){  
863 - Map<String, Object> map = new HashMap<String, Object>();  
864 - map.put("id", rs.getString("id"));  
865 - map.put("date", rs.getString("schedule_date_str"));  
866 - map.put("line", rs.getString("xl_name"));  
867 - map.put("clZbh", rs.getString("cl_zbh"));  
868 - map.put("jGh", rs.getString("j_gh"));  
869 - map.put("jName", rs.getString("j_name"));  
870 - map.put("fcsj", rs.getString("fcsj"));  
871 - map.put("timestamp", rs.getString("timestamp"));  
872 - map.put("reply46", rs.getString("reply46"));  
873 - map.put("reply47", rs.getString("reply47"));  
874 - map.put("reply46time", rs.getString("reply46time"));  
875 - map.put("reply47time", rs.getString("reply47time"));  
876 - list.add(map);  
877 - }  
878 - DBUtils_MS.close(rs, ps, conn);  
879 - } catch (SQLException e) { 837 +
  838 + list = jdbcTemplate.query(sql,
  839 + new RowMapper<Map<String, Object>>(){
  840 + @Override
  841 + public Map<String, Object> mapRow(ResultSet rs, int rowNum) throws SQLException {
  842 + Map<String, Object> map = new HashMap<String, Object>();
  843 + map.put("id", rs.getString("id"));
  844 + map.put("date", rs.getString("schedule_date_str"));
  845 + map.put("line", rs.getString("xl_name"));
  846 + map.put("clZbh", rs.getString("cl_zbh"));
  847 + map.put("jGh", rs.getString("j_gh"));
  848 + map.put("jName", rs.getString("j_name"));
  849 + map.put("fcsj", rs.getString("fcsj"));
  850 + map.put("timestamp", rs.getString("timestamp"));
  851 + map.put("reply46", rs.getString("reply46"));
  852 + map.put("reply47", rs.getString("reply47"));
  853 + map.put("reply46time", rs.getString("reply46time"));
  854 + map.put("reply47time", rs.getString("reply47time"));
  855 + return map;
  856 + }
  857 + });
  858 +
  859 + } catch (Exception e) {
880 // TODO Auto-generated catch block 860 // TODO Auto-generated catch block
881 e.printStackTrace(); 861 e.printStackTrace();
882 } 862 }