Commit 3f055d7a140170bc85494d3029725a66a474eefa

Authored by 娄高锋
1 parent 23b305af

重新统计update

src/main/java/com/bsth/repository/calc/CalcWaybillRepository.java
... ... @@ -49,4 +49,13 @@ public interface CalcWaybillRepository extends BaseRepository<CalcWaybill, Integ
49 49 @Query("select DISTINCT s from ScheduleRealInfo s where s.scheduleDateStr=?1 and s.xlBm=?2")
50 50 List<ScheduleRealInfo> findAllSchedule(String schDate, String lineCode);
51 51  
  52 + /**
  53 + * 根据日期获取班次信息
  54 + * @param schDate
  55 + * @return
  56 + */
  57 + @EntityGraph(value = "scheduleRealInfo_cTasks", type = EntityGraph.EntityGraphType.FETCH)
  58 + @Query("select DISTINCT s from ScheduleRealInfo s where s.scheduleDateStr=?1")
  59 + List<ScheduleRealInfo> findAllScheduleByDate(String schDate);
  60 +
52 61 }
... ...
src/main/java/com/bsth/service/calc/CalcToolService.java
... ... @@ -4,6 +4,7 @@ import java.util.List;
4 4 import java.util.Map;
5 5  
6 6 import com.bsth.entity.calc.CalcWaybill;
  7 +import com.bsth.entity.realcontrol.ScheduleRealInfo;
7 8 import com.bsth.entity.sys.Interval;
8 9  
9 10 /**
... ... @@ -11,6 +12,6 @@ import com.bsth.entity.sys.Interval;
11 12 */
12 13 public interface CalcToolService {
13 14  
14   - List<CalcWaybill> findAll(String date, String line, List<Map<String, Object>> xlList, List<Interval> djgList);
  15 + List<CalcWaybill> findAll(String date, String line, List<ScheduleRealInfo> list, List<Map<String, Object>> xlList, List<Interval> djgList);
15 16  
16 17 }
... ...
src/main/java/com/bsth/service/calc/impl/CalcToolServiceImpl.java
... ... @@ -5,12 +5,11 @@ import java.sql.SQLException;
5 5 import java.util.ArrayList;
6 6 import java.util.Date;
7 7 import java.util.HashMap;
  8 +import java.util.HashSet;
8 9 import java.util.List;
9 10 import java.util.Map;
10 11 import java.util.Set;
11 12  
12   -import javax.swing.text.Keymap;
13   -
14 13 import com.bsth.entity.calc.CalcInterval;
15 14 import com.bsth.entity.calc.CalcWaybill;
16 15 import com.bsth.entity.realcontrol.ChildTaskPlan;
... ... @@ -53,26 +52,29 @@ public class CalcToolServiceImpl implements CalcToolService {
53 52  
54 53  
55 54 @Override
56   - public List<CalcWaybill> findAll(String rq, String lineCode, List<Map<String, Object>> xlList, List<Interval> djgList) {
  55 + public List<CalcWaybill> findAll(String rq, String lineCode, List<ScheduleRealInfo> list, List<Map<String, Object>> xlList, List<Interval> djgList) {
57 56 List<CalcWaybill> listCal=new ArrayList<CalcWaybill>();
58   - List<ScheduleRealInfo> list = clacRepository.findAllSchedule(rq,lineCode);
59   - String sql ="select r.j_gh ,r.s_gh,r.cl_zbh,r.xl_bm, r.lp_name FROM"
60   - + " bsth_c_s_sp_info_real r where "
61   - + " r.schedule_date_str='"+rq+"' and r.xl_bm = '"+lineCode+"'"
62   - + " GROUP BY r.j_gh,r.s_gh,r.cl_zbh,r.xl_bm,r.lp_name ";
63   -
64   - List<Map<String, String>> listMap = jdbcTemplate.query(sql, new RowMapper<Map<String, String>>() {
65   - @Override
66   - public Map<String, String> mapRow(ResultSet arg0, int arg1) throws SQLException {
67   - Map<String, String> c = new HashMap<String,String>();
68   - c.put("jGh", arg0.getString("j_gh"));
69   - c.put("sGh", arg0.getString("s_gh")==null?"":arg0.getString("s_gh"));
70   - c.put("clZbh", arg0.getString("cl_zbh"));
71   - c.put("xlBm", arg0.getString("xl_bm"));
72   - c.put("lpName", arg0.getString("lp_name"));
73   - return c;
  57 +
  58 + List<Map<String, String>> listMap = new ArrayList<Map<String, String>>();
  59 + Set<String> tempSet = new HashSet<String>();
  60 + for(ScheduleRealInfo s : list){
  61 + String jGh = s.getjGh()!=null?s.getjGh().trim():"";
  62 + String sGh = s.getsGh()!=null?s.getsGh().trim():"";
  63 + String clZbh = s.getClZbh()!=null?s.getClZbh().trim():"";
  64 + String xlBm = s.getXlBm()!=null?s.getXlBm().trim():"";
  65 + String lpName = s.getLpName()!=null?s.getLpName().trim():"";
  66 + String key = jGh + sGh + clZbh + xlBm + lpName;
  67 + if(tempSet.add(key)){
  68 + Map<String, String> m = new HashMap<String, String>();
  69 + m.put("jGh", jGh);
  70 + m.put("sGh", sGh);
  71 + m.put("clZbh", clZbh);
  72 + m.put("xlBm", xlBm);
  73 + m.put("lpName", lpName);
  74 + listMap.add(m);
74 75 }
75   - });
  76 + }
  77 +
76 78 for (int i = 0; i < listMap.size(); i++) {
77 79 Map<String, String> m=listMap.get(i);
78 80 String jGh=m.get("jGh");
... ... @@ -196,6 +198,7 @@ public class CalcToolServiceImpl implements CalcToolService {
196 198 //list_ 全部班次 lists_执行了的班次(实到实发不为空)
197 199 private List<CalcWaybill> cul(List<ScheduleRealInfo> list_,List<ScheduleRealInfo> list_s, List<Map<String, Object>> xlList, List<Interval> djgList){
198 200 List<CalcWaybill> list=new ArrayList<CalcWaybill>();
  201 + List<CalcWaybill> list2=new ArrayList<CalcWaybill>();
199 202 if(list_.size()>0){
200 203 Date date=list_.get(0).getScheduleDate();
201 204 String dateStr=list_.get(0).getScheduleDateStr();
... ... @@ -356,8 +359,28 @@ public class CalcToolServiceImpl implements CalcToolService {
356 359 t_.setDtbczgf(0);
357 360 t_.setDtbcwgf(0);
358 361 list.add(t_);
  362 + list2.add(t_);
359 363 }
360 364 }
  365 + for(CalcWaybill c2 : list2){
  366 + boolean flag = true;
  367 + String key2 = c2.getjGh() + c2.getsGh()==null?"":c2.getsGh().trim()
  368 + + c2.getCl() + c2.getXl() + c2.getLp();
  369 + for(CalcWaybill c : list){
  370 + String key = c.getjGh() + c.getsGh()==null?"":c.getsGh().trim()
  371 + + c.getCl() + c.getXl() + c.getLp();
  372 + if(key2.equals(key)){
  373 + c.setSjyylc(Arith.add(c.getSjyylc(), c2.getSjyylc()));
  374 + c.setSjfyylc(Arith.add(c.getSjfyylc(), c2.getSjfyylc()));
  375 + c.setLjyylc(Arith.add(c.getLjyylc(), c2.getLjyylc()));
  376 + c.setLjfyylc(Arith.add(c.getLjfyylc(), c2.getLjfyylc()));
  377 + flag = false;
  378 + break;
  379 + }
  380 + }
  381 + if(flag)
  382 + list.add(c2);
  383 + }
361 384 return list;
362 385 }
363 386  
... ...
src/main/java/com/bsth/service/calc/impl/CalcWaybillServiceImpl.java
... ... @@ -33,6 +33,7 @@ import com.bsth.service.calc.CalcWaybillService;
33 33 import com.bsth.service.impl.BaseServiceImpl;
34 34 import com.bsth.service.report.CulateMileageService;
35 35 import com.bsth.util.Arith;
  36 +import com.bsth.util.BatchSaveUtils;
36 37 import com.bsth.util.ReportUtils;
37 38 import com.github.stuxuhai.jpinyin.PinyinException;
38 39 import com.github.stuxuhai.jpinyin.PinyinFormat;
... ... @@ -80,7 +81,7 @@ public class CalcWaybillServiceImpl extends BaseServiceImpl&lt;CalcWaybill, Integer
80 81 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
81 82 if(date == null || date.trim().length() == 0){
82 83 Date d = new Date();
83   - d.setTime(d.getTime() - (2 * 1000 * 60 * 60 * 24));
  84 + d.setTime(d.getTime() - (4 * 1000 * 60 * 60 * 24));
84 85 date = sdf.format(d);
85 86 }
86 87 if(line == null || line.trim().length() == 0){
... ... @@ -120,7 +121,7 @@ public class CalcWaybillServiceImpl extends BaseServiceImpl&lt;CalcWaybill, Integer
120 121 sql += " and xl_bm = '"+line+"'";
121 122 // sql += " where t.line_code = " + line;
122 123 }
123   - sql += "group by xl_bm";
  124 + sql += " group by xl_bm";
124 125 List<Map<String, Object>> listLineConfig = jdbcTemplate.query(sql,
125 126 new RowMapper<Map<String, Object>>(){
126 127 @Override
... ... @@ -148,7 +149,7 @@ public class CalcWaybillServiceImpl extends BaseServiceImpl&lt;CalcWaybill, Integer
148 149 Map<String, List<Map<String, Object>>> xlMap = new HashMap<String, List<Map<String, Object>>>();
149 150 for(Map<String, Object> m : xlList){
150 151 if(m.containsKey("line") && m.get("line").toString().trim().length() > 0){
151   - String key = m.get("line").toString();
  152 + String key = m.get("line").toString().trim();
152 153 if(!xlMap.containsKey(key))
153 154 xlMap.put(key, new ArrayList<Map<String, Object>>());
154 155 xlMap.get(key).add(m);
... ... @@ -166,7 +167,18 @@ public class CalcWaybillServiceImpl extends BaseServiceImpl&lt;CalcWaybill, Integer
166 167 return m;
167 168 }});
168 169  
  170 + Map<String, List<ScheduleRealInfo>> scheMap = new HashMap<String, List<ScheduleRealInfo>>();
  171 + List<ScheduleRealInfo> list = calcRepository.findAllScheduleByDate(date);
  172 + for(ScheduleRealInfo s : list){
  173 + String xlBm = s.getXlBm();
  174 + if(!scheMap.containsKey(xlBm)){
  175 + scheMap.put(xlBm, new ArrayList<ScheduleRealInfo>());
  176 + }
  177 + scheMap.get(xlBm).add(s);
  178 + }
  179 +
169 180 Set<String> lineSet = new HashSet<String>();
  181 + List<CalcWaybill> all = new ArrayList<CalcWaybill>();
170 182 for (int i = 0; i < listLineConfig.size(); i++) {
171 183 Map<String, Object> m =listLineConfig.get(i);
172 184 String lineCode=m.get("line_code").toString().trim();
... ... @@ -179,13 +191,14 @@ public class CalcWaybillServiceImpl extends BaseServiceImpl&lt;CalcWaybill, Integer
179 191 tempList = xlMap.get(lineCode);
180 192 }
181 193  
182   - List<CalcWaybill> findAll = calcToolService.findAll(date, lineCode, tempList, djgList);
  194 + if(!scheMap.containsKey(lineCode))
  195 + continue;
  196 + List<CalcWaybill> findAll = calcToolService.findAll(date, lineCode, scheMap.get(lineCode), tempList, djgList);
  197 + all.addAll(findAll);
183 198  
184   -// new BatchSaveUtils<CalcWaybill>().saveList2(findAll, CalcWaybill.class);
185   -
186   -// if(xlMap.get(lineCode).size() == 0)
187   - calcRepository.save(findAll);
188 199 }
  200 +// new BatchSaveUtils<CalcWaybill>().saveList2(all, CalcWaybill.class);
  201 + calcRepository.save(all);
189 202  
190 203 newMap.put("status", ResponseCode.SUCCESS);
191 204 } catch (Exception e) {
... ... @@ -405,7 +418,7 @@ public class CalcWaybillServiceImpl extends BaseServiceImpl&lt;CalcWaybill, Integer
405 418 }
406 419  
407 420 /**
408   - * @param rq 格式如:2018-03-22(留空""默认当前日期前天)
  421 + * @param rq 格式如:2018-03-22(留空""默认当前日期前天)
409 422 * @param line (留空""默认全部线路)
410 423 */
411 424 @Transactional
... ... @@ -419,7 +432,7 @@ public class CalcWaybillServiceImpl extends BaseServiceImpl&lt;CalcWaybill, Integer
419 432 Date dBefore = new Date();
420 433 Calendar calendar = Calendar.getInstance(); //得到日历
421 434 calendar.setTime(dNow);//把当前时间赋给日历
422   - calendar.add(Calendar.DAY_OF_MONTH, -1); //设置为前一天
  435 + calendar.add(Calendar.DAY_OF_MONTH, -2); //设置为前一天
423 436 dBefore = calendar.getTime(); //得到前一天的时间
424 437 rq = sdf.format(dBefore);
425 438 } else {
... ...