Commit bb5842a2344d845b22e4c38435ba156da46a9073

Authored by 娄高锋
1 parent 6b52b7ba

改掉sql拼接(sql注入漏洞)。

src/main/java/com/bsth/service/impl/BusIntervalServiceImpl.java
... ... @@ -828,31 +828,38 @@ public class BusIntervalServiceImpl implements BusIntervalService {
828 828  
829 829 try {
830 830  
831   - String where = "";
  831 + List<String> objList = new ArrayList<String>();
  832 + String sql = "select id, schedule_date_str, real_exec_date, xl_name, lp_name, bcs, bcsj, jhlc, bc_type, xl_bm, fgs_bm,"
  833 + + " fcsj, fcsj_actual, zdsj, zdsj_actual, qdz_name, zdz_name, xl_dir, status, remarks, gs_name, fgs_name, sp_id"
  834 + + " ,cc_service from bsth_c_s_sp_info_real where schedule_date_str >= ? and schedule_date_str <= ?";
  835 + objList.add(startDate);
  836 + objList.add(endDate);
  837 +
832 838 if(line.length() != 0 && statu.equals("1")){
833   - where += " and xl_bm = '"+line+"'";
  839 + sql += " and xl_bm = ?";
  840 + objList.add(line);
834 841 }
835 842 if(lp.length() != 0 && statu.equals("1")){
836   - where += " and lp_name = '"+lp+"'";
  843 + sql += " and lp_name = ?";
  844 + objList.add(lp);
837 845 }
838 846 if(company.length() != 0){
839   - where += " and gs_bm = '"+company+"'";
  847 + sql += " and gs_bm = ?";
  848 + objList.add(company);
840 849 }
841 850 if(subCompany.length() != 0){
842   - where += " and fgs_bm = '"+subCompany+"'";
  851 + sql += " and fgs_bm = ?";
  852 + objList.add(subCompany);
843 853 }
844 854 if(sfqr == 1){
845   - where += " and zdsj >= '"+times1+"' and fcsj <= '"+times2+"'";
  855 + sql += " and zdsj >= ? and fcsj <= ?";
  856 + objList.add(times1);
  857 + objList.add(times2);
846 858 }
847   -// where += " and bc_type != 'in' and bc_type != 'out' and bc_type != 'ldks'";
848   - where += " and bc_type != 'ldks'";
849   -
850   - String sql = "select id, schedule_date_str, real_exec_date, xl_name, lp_name, bcs, bcsj, jhlc, bc_type, xl_bm, fgs_bm,"
851   - + " fcsj, fcsj_actual, zdsj, zdsj_actual, qdz_name, zdz_name, xl_dir, status, remarks, gs_name, fgs_name, sp_id"
852   - + " ,cc_service from bsth_c_s_sp_info_real where schedule_date_str >= '"+startDate+"'"
853   - + " and schedule_date_str <= '"+endDate+"'"+where+"";
  859 + sql += " and bc_type != 'ldks'";
854 860  
855 861 list = jdbcTemplate.query(sql,
  862 + objList.toArray(),
856 863 new RowMapper<ScheduleRealInfo>(){
857 864 @Override
858 865 public ScheduleRealInfo mapRow(ResultSet rs, int rowNum) throws SQLException {
... ... @@ -932,23 +939,32 @@ public class BusIntervalServiceImpl implements BusIntervalService {
932 939 {
933 940 List<Map<String, String>> temp1 = new ArrayList<Map<String, String>>();
934 941 List<Map<String, String>> temp2 = new ArrayList<Map<String, String>>();
  942 +
  943 + List<String> objList2 = new ArrayList<String>();
935 944 sql = "select id, lp, fcsj, xl_bm, tt_info from bsth_c_s_sp_info where bc_type != 'in' and bc_type != 'out' and bc_type != 'ldks'";
936 945  
937 946 if(startDate.equals(endDate)){
938   - sql += " and schedule_date = '"+startDate+"'";
  947 + sql += " and schedule_date = ?";
  948 + objList2.add(startDate);
939 949 } else {
940   - sql += " and schedule_date >= '"+startDate+"' and schedule_date <= '"+endDate+"'";
  950 + sql += " and schedule_date >= ? and schedule_date <= ?";
  951 + objList2.add(startDate);
  952 + objList2.add(endDate);
941 953 }
942 954 if(line.length() != 0 && statu.equals("1")){
943   - sql += " and xl_bm = '"+line+"'";
  955 + sql += " and xl_bm = ?";
  956 + objList2.add(line);
944 957 }
945 958 if(company.length() != 0){
946   - sql += " and gs_bm = '"+company+"'";
  959 + sql += " and gs_bm = ?";
  960 + objList2.add(company);
947 961 }
948 962 if(subCompany.length() != 0){
949   - sql += " and fgs_bm = '"+subCompany+"'";
  963 + sql += " and fgs_bm = ?";
  964 + objList2.add(subCompany);
950 965 }
951 966 temp1 = jdbcTemplate.query(sql,
  967 + objList2.toArray(),
952 968 new RowMapper<Map<String, String>>(){
953 969 @Override
954 970 public Map<String, String> mapRow(ResultSet rs, int rowNum) throws SQLException {
... ... @@ -961,13 +977,17 @@ public class BusIntervalServiceImpl implements BusIntervalService {
961 977 return m;
962 978 }
963 979 });
  980 +
  981 + List<String> objList3 = new ArrayList<String>();
964 982 sql = "select * from bsth_c_s_ttinfo_detail where ists = 1"
965 983 + " and bc_type != 'in' and bc_type != 'out' and bc_type != 'ldks'";
966 984  
967 985 if(line.length() != 0 && statu.equals("1")){
968   - sql += " and xl = '"+line+"'";
  986 + sql += " and xl = ?";
  987 + objList3.add(line);
969 988 }
970 989 temp2 = jdbcTemplate.query(sql,
  990 + objList.toArray(),
971 991 new RowMapper<Map<String, String>>(){
972 992 @Override
973 993 public Map<String, String> mapRow(ResultSet rs, int rowNum) throws SQLException {
... ... @@ -998,6 +1018,7 @@ public class BusIntervalServiceImpl implements BusIntervalService {
998 1018 if(id1 == 0 || id1 > s.getId())
999 1019 id1 = s.getId();
1000 1020 }
  1021 +
1001 1022 sql = "select destroy, start_date, end_date, mileage, mileage_type, schedule from bsth_c_s_child_task";
1002 1023 sql += " where id >= "+id1+" and id <= "+id2+" order by start_date";
1003 1024  
... ... @@ -1017,12 +1038,17 @@ public class BusIntervalServiceImpl implements BusIntervalService {
1017 1038 });
1018 1039  
1019 1040 if(model.length() != 0){
  1041 + List<String> objList4 = new ArrayList<String>();
1020 1042 sql = "select sp.id from "
1021   - + "(select id, tt_info, xl_bm, lp, fcsj from bsth_c_s_sp_info where schedule_date >= '"+startDate+"' and schedule_date <= '"+endDate+"'"
1022   - + " and tt_info = '" + model + "' and bc_type != 'ldks') sp"
  1043 + + "(select id, tt_info, xl_bm, lp, fcsj from bsth_c_s_sp_info where schedule_date >= ? and schedule_date <= ?"
  1044 + + " and tt_info = ? and bc_type != 'ldks') sp"
1023 1045 + " left join bsth_c_s_ttinfo_detail tt on sp.tt_info = tt.ttinfo and sp.xl_bm = tt.xl and sp.lp = tt.lp and sp.fcsj = tt.fcsj";
  1046 + objList4.add(startDate);
  1047 + objList4.add(endDate);
  1048 + objList4.add(model);
1024 1049  
1025 1050 ttList = jdbcTemplate.query(sql,
  1051 + objList4.toArray(),
1026 1052 new RowMapper<Map<String, Object>>(){
1027 1053 @Override
1028 1054 public Map<String, Object> mapRow(ResultSet rs, int rowNum) throws SQLException {
... ...