Commit ca2de580be260645e8efd221bfb2f735bcbb511d

Authored by 娄高锋
1 parent 441126ca

把无路单的加油充电数据加入到“路单线路明细年、月报表”中,为了保证查询结果与查询加油充电总量一致。

src/main/java/com/bsth/repository/calc/CalcWaybillRepository.java
... ... @@ -96,12 +96,12 @@ public interface CalcWaybillRepository extends BaseRepository<CalcWaybill, Integ
96 96 //路单没有的加油
97 97 @Query(value="select DISTINCT y from Ylb y left join CalcWaybill c on y.rq = c.rq and y.xlbm = c.xl and y.jsy = c.jGh and y.nbbm = c.cl " +
98 98 "where y.xlbm in(?1) and y.rq between ?2 and ?3 and y.ssgsdm in(?4) and y.fgsdm in(?5) and c.id is null " +
99   - "and y.xlbm in (select l.lineCode from Line l where l.destroy in (?6))")
  99 + "and y.xlbm in (select l.lineCode from Line l where l.destroy in (?6)) order by y.rq desc") //按日期倒序,方便插入list
100 100 List<Ylb> ylbNotSchedule(List<String> line,Date date,Date date2,List<String> gsdm,List<String> fgsdm, List<Integer> destroy);
101 101  
102 102 //路单没有的加油
103 103 @Query(value="select DISTINCT d from Dlb d left join CalcWaybill c on d.rq = c.rq and d.xlbm = c.xl and d.jsy = c.jGh and d.nbbm = c.cl " +
104 104 "where d.xlbm in(?1) and d.rq between ?2 and ?3 and d.ssgsdm in(?4) and d.fgsdm in(?5) and c.id is null " +
105   - "and d.xlbm in (select l.lineCode from Line l where l.destroy in (?6))")
  105 + "and d.xlbm in (select l.lineCode from Line l where l.destroy in (?6)) order by d.rq desc") //按日期倒序,方便插入list
106 106 List<Dlb> DlbNotSchedule(List<String> line,Date date,Date date2,List<String> gsdm,List<String> fgsdm, List<Integer> destroy);
107 107 }
... ...
src/main/java/com/bsth/service/calc/impl/CalcWaybillServiceImpl.java
... ... @@ -2012,8 +2012,9 @@ public class CalcWaybillServiceImpl extends BaseServiceImpl&lt;CalcWaybill, Integer
2012 2012 // List类转换
2013 2013 final List<CalcWaybillDetail> listNew = JSONArray.parseArray(JSON.toJSONString(list), CalcWaybillDetail.class);
2014 2014  
2015   - if(flag == 4)
  2015 + if(flag != 2)
2016 2016 try {
  2017 + //查询出没有路单的加油充电,插入到上面查询的结果集中汇总计算。
2017 2018 List<Ylb> ylbNotSchedule = calcRepository.ylbNotSchedule(line, dateFormat.parse(startDate), dateFormat.parse(endDate), gsdm, fgsdm, destroy);
2018 2019 List<Dlb> dlbNotSchedule = calcRepository.DlbNotSchedule(line, dateFormat.parse(startDate), dateFormat.parse(endDate), gsdm, fgsdm, destroy);
2019 2020 for(Ylb y : ylbNotSchedule){
... ... @@ -2021,17 +2022,68 @@ public class CalcWaybillServiceImpl extends BaseServiceImpl&lt;CalcWaybill, Integer
2021 2022 String ylbxl = y.getXlbm();
2022 2023 String ylbgs = y.getSsgsdm();
2023 2024 String ylbfgs = y.getFgsdm();
  2025 + String ylbnbbm = y.getNbbm();
  2026 + String ylbjsy = y.getJsy();
  2027 + y.setJname(y.getJname()!=null?y.getJname():BasicData.allPerson.get(ylbgs+"-"+ylbjsy));
  2028 + String ylbjname = y.getJname();
  2029 + if(flag == 4 && (ylbxl == null || ylbxl.trim().length() == 0)){
  2030 + continue;
  2031 + }
  2032 + if(flag == 3 && (ylbnbbm == null || ylbnbbm.trim().length() == 0)){
  2033 + continue;
  2034 + }
  2035 + if(flag == 1 && (ylbjsy == null || ylbjsy.trim().length() == 0)){
  2036 + continue;
  2037 + }
2024 2038 boolean f = false;
2025 2039 int l = listNew.size();
2026 2040 for(int i = 0; i < listNew.size(); i++){
2027 2041 CalcWaybillDetail cw = listNew.get(i);
2028   - if(ylbrq.getTime() == cw.getRq().getTime()
  2042 + //线路、车辆、驾驶员三种类型,日期小的插入到前面,日期大的往后面放。
  2043 + if(flag == 4
2029 2044 && ylbgs.equals(cw.getGsdm())
2030 2045 && ylbfgs.equals(cw.getFgsdm())
2031 2046 && ylbxl.equals(cw.getXl())){
2032   - f = true;
2033   - l = i;
2034   - break;
  2047 + if(ylbrq.getTime() < cw.getRq().getTime()){
  2048 + f = false;
  2049 + l = i;
  2050 + break;
  2051 + } else if(ylbrq.getTime() == cw.getRq().getTime()){
  2052 + f = true;
  2053 + l = i;
  2054 + break;
  2055 + }
  2056 + }
  2057 + if(flag == 3
  2058 + && ylbgs.equals(cw.getGsdm())
  2059 + && ylbfgs.equals(cw.getFgsdm())
  2060 + && ylbxl.equals(cw.getXl())
  2061 + && ylbnbbm.equals(cw.getCl())){
  2062 + if(ylbrq.getTime() < cw.getRq().getTime()){
  2063 + f = false;
  2064 + l = i;
  2065 + break;
  2066 + } else if(ylbrq.getTime() == cw.getRq().getTime()){
  2067 + f = true;
  2068 + l = i;
  2069 + break;
  2070 + }
  2071 + }
  2072 + if(flag == 1
  2073 + && ylbgs.equals(cw.getGsdm())
  2074 + && ylbfgs.equals(cw.getFgsdm())
  2075 + && ylbxl.equals(cw.getXl())
  2076 + && ylbjsy.equals(cw.getjGh())
  2077 + && ylbjname.equals(cw.getjName())){
  2078 + if(ylbrq.getTime() < cw.getRq().getTime()){
  2079 + f = false;
  2080 + l = i;
  2081 + break;
  2082 + } else if(ylbrq.getTime() == cw.getRq().getTime()){
  2083 + f = true;
  2084 + l = i;
  2085 + break;
  2086 + }
2035 2087 }
2036 2088 }
2037 2089 if(f){
... ... @@ -2048,7 +2100,19 @@ public class CalcWaybillServiceImpl extends BaseServiceImpl&lt;CalcWaybill, Integer
2048 2100 cNew.setCl(y.getNbbm());
2049 2101 cNew.setjGh(y.getJsy());
2050 2102 cNew.setjName(BasicData.allPerson.get(y.getSsgsdm()+"-"+y.getJsy()));
2051   - listNew.add(l, cNew);
  2103 + cNew.setZlc(y.getZlc());
  2104 + cNew.setYh(y.getYh());
  2105 + cNew.setJzl(y.getJzl());
  2106 + if("0".equals(y.getRylx())){
  2107 + cNew.setJzl0(y.getJzl());
  2108 + }else if("1".equals(y.getRylx())){
  2109 + cNew.setJzl10(y.getJzl());
  2110 + }
  2111 + cNew.setJzyl(y.getJzyl());
  2112 + cNew.setCzyl(y.getCzyl());
  2113 + cNew.setRylx(y.getRylx());
  2114 + cNew.setBglyh((y.getZlc()==0? 0:100*y.getYh()/y.getZlc()));
  2115 + listNew.add(l, cNew); //日期更小或相同,插入到同类型的前面。
2052 2116 } else {
2053 2117 CalcWaybillDetail cNew = new CalcWaybillDetail();
2054 2118 cNew.setRq(ylbrq);
... ... @@ -2058,11 +2122,23 @@ public class CalcWaybillServiceImpl extends BaseServiceImpl&lt;CalcWaybill, Integer
2058 2122 cNew.setGsdm(y.getSsgsdm());
2059 2123 cNew.setGsname(BasicData.businessCodeNameMap.get(y.getSsgsdm()));
2060 2124 cNew.setFgsdm(y.getFgsdm());
2061   - cNew.setFgsname(BasicData.businessFgsCodeNameMap.get(y.getFgsdm()+"_"+y.getFgsdm()));
  2125 + cNew.setFgsname(BasicData.businessFgsCodeNameMap.get(y.getFgsdm()+"_"+y.getSsgsdm()));
2062 2126 cNew.setCl(y.getNbbm());
2063 2127 cNew.setjGh(y.getJsy());
2064 2128 cNew.setjName(BasicData.allPerson.get(y.getSsgsdm()+"-"+y.getJsy()));
2065   - listNew.add(listNew.size(), cNew);
  2129 + cNew.setZlc(y.getZlc());
  2130 + cNew.setYh(y.getYh());
  2131 + cNew.setJzl(y.getJzl());
  2132 + if("0".equals(y.getRylx())){
  2133 + cNew.setJzl0(y.getJzl());
  2134 + }else if("1".equals(y.getRylx())){
  2135 + cNew.setJzl10(y.getJzl());
  2136 + }
  2137 + cNew.setJzyl(y.getJzyl());
  2138 + cNew.setCzyl(y.getCzyl());
  2139 + cNew.setRylx(y.getRylx());
  2140 + cNew.setBglyh((y.getZlc()==0? 0:100*y.getYh()/y.getZlc()));
  2141 + listNew.add(l, cNew); //日期更大,插入到最后。
2066 2142 }
2067 2143 }
2068 2144 for(Dlb d : dlbNotSchedule){
... ... @@ -2070,17 +2146,68 @@ public class CalcWaybillServiceImpl extends BaseServiceImpl&lt;CalcWaybill, Integer
2070 2146 String dlbxl = d.getXlbm();
2071 2147 String dlbgs = d.getSsgsdm();
2072 2148 String dlbfgs = d.getFgsdm();
  2149 + String dlbnbbm = d.getNbbm();
  2150 + String dlbjsy = d.getJsy();
  2151 + d.setJname(d.getJname()!=null?d.getJname():BasicData.allPerson.get(dlbgs+"-"+dlbjsy));
  2152 + String dlbjname = d.getJname();
  2153 + if(flag == 4 && (dlbxl == null || dlbxl.trim().length() == 0)){
  2154 + continue;
  2155 + }
  2156 + if(flag == 3 && (dlbnbbm == null || dlbnbbm.trim().length() == 0)){
  2157 + continue;
  2158 + }
  2159 + if(flag == 1 && (dlbjsy == null || dlbjsy.trim().length() == 0)){
  2160 + continue;
  2161 + }
2073 2162 boolean f = false;
2074 2163 int l = listNew.size();
2075 2164 for(int i = 0; i < listNew.size(); i++){
2076 2165 CalcWaybillDetail cw = listNew.get(i);
2077   - if(dlbrq.getTime() == cw.getRq().getTime()
  2166 + //线路、车辆、驾驶员三种类型,日期小的插入到前面,日期大的往后面放。
  2167 + if(flag == 4
2078 2168 && dlbgs.equals(cw.getGsdm())
2079 2169 && dlbfgs.equals(cw.getFgsdm())
2080 2170 && dlbxl.equals(cw.getXl())){
2081   - f = true;
2082   - l = i;
2083   - break;
  2171 + if(dlbrq.getTime() < cw.getRq().getTime()){
  2172 + f = false;
  2173 + l = i;
  2174 + break;
  2175 + } else if(dlbrq.getTime() == cw.getRq().getTime()){
  2176 + f = true;
  2177 + l = i;
  2178 + break;
  2179 + }
  2180 + }
  2181 + if(flag == 3
  2182 + && dlbgs.equals(cw.getGsdm())
  2183 + && dlbfgs.equals(cw.getFgsdm())
  2184 + && dlbxl.equals(cw.getXl())
  2185 + && dlbnbbm.equals(cw.getCl())){
  2186 + if(dlbrq.getTime() < cw.getRq().getTime()){
  2187 + f = false;
  2188 + l = i;
  2189 + break;
  2190 + } else if(dlbrq.getTime() == cw.getRq().getTime()){
  2191 + f = true;
  2192 + l = i;
  2193 + break;
  2194 + }
  2195 + }
  2196 + if(flag == 1
  2197 + && dlbgs.equals(cw.getGsdm())
  2198 + && dlbfgs.equals(cw.getFgsdm())
  2199 + && dlbxl.equals(cw.getXl())
  2200 + && dlbjsy.equals(cw.getjGh())
  2201 + && dlbjname.equals(cw.getjName())){
  2202 + if(dlbrq.getTime() < cw.getRq().getTime()){
  2203 + f = false;
  2204 + l = i;
  2205 + break;
  2206 + } else if(dlbrq.getTime() == cw.getRq().getTime()){
  2207 + f = true;
  2208 + l = i;
  2209 + break;
  2210 + }
2084 2211 }
2085 2212 }
2086 2213 if(f){
... ... @@ -2097,7 +2224,13 @@ public class CalcWaybillServiceImpl extends BaseServiceImpl&lt;CalcWaybill, Integer
2097 2224 cNew.setCl(d.getNbbm());
2098 2225 cNew.setjGh(d.getJsy());
2099 2226 cNew.setjName(BasicData.allPerson.get(d.getSsgsdm()+"-"+d.getJsy()));
2100   - listNew.add(l, cNew);
  2227 + cNew.setZlc(d.getZlc());
  2228 + cNew.setHd(d.getHd());
  2229 + cNew.setJzcd(d.getJzcd());
  2230 + cNew.setCzcd(d.getCzcd());
  2231 + cNew.setCdl(d.getCdl());
  2232 + cNew.setBglyh((d.getZlc()==0? 0:100*d.getHd()/d.getZlc()));
  2233 + listNew.add(l, cNew); //日期更小或相同,插入到同类型的前面。
2101 2234 } else {
2102 2235 CalcWaybillDetail cNew = new CalcWaybillDetail();
2103 2236 cNew.setRq(dlbrq);
... ... @@ -2107,13 +2240,22 @@ public class CalcWaybillServiceImpl extends BaseServiceImpl&lt;CalcWaybill, Integer
2107 2240 cNew.setGsdm(d.getSsgsdm());
2108 2241 cNew.setGsname(BasicData.businessCodeNameMap.get(d.getSsgsdm()));
2109 2242 cNew.setFgsdm(d.getFgsdm());
2110   - cNew.setFgsname(BasicData.businessFgsCodeNameMap.get(d.getFgsdm()+"_"+d.getFgsdm()));
  2243 + cNew.setFgsname(BasicData.businessFgsCodeNameMap.get(d.getFgsdm()+"_"+d.getSsgsdm()));
2111 2244 cNew.setCl(d.getNbbm());
2112 2245 cNew.setjGh(d.getJsy());
2113 2246 cNew.setjName(BasicData.allPerson.get(d.getSsgsdm()+"-"+d.getJsy()));
2114   - listNew.add(listNew.size(), cNew);
  2247 + cNew.setZlc(d.getZlc());
  2248 + cNew.setHd(d.getHd());
  2249 + cNew.setJzcd(d.getJzcd());
  2250 + cNew.setCzcd(d.getCzcd());
  2251 + cNew.setCdl(d.getCdl());
  2252 + cNew.setBglyh((d.getZlc()==0? 0:100*d.getHd()/d.getZlc()));
  2253 + listNew.add(l, cNew); //日期更大,插入到最后。
2115 2254 }
2116 2255 }
  2256 +
  2257 +
  2258 +
2117 2259 } catch (Exception e) {
2118 2260 // TODO: handle exception
2119 2261 }
... ... @@ -2171,6 +2313,9 @@ public class CalcWaybillServiceImpl extends BaseServiceImpl&lt;CalcWaybill, Integer
2171 2313 ylb.setRylx(arg0.getString("rylx"));
2172 2314 ylb.setFgsdm(arg0.getString("fgsdm"));
2173 2315 ylb.setRq(rq);
  2316 + if(ylb.getSsgsdm() != null && ylb.getFgsdm() != null){
  2317 + ylb.setFgsname(BasicData.businessFgsCodeNameMap.get(ylb.getFgsdm()+"_"+ylb.getSsgsdm()));
  2318 + }
2174 2319 return ylb;
2175 2320 }
2176 2321 });
... ... @@ -2193,8 +2338,12 @@ public class CalcWaybillServiceImpl extends BaseServiceImpl&lt;CalcWaybill, Integer
2193 2338 dlb.setCzcd(Double.parseDouble(arg0.getString("czcd")));
2194 2339 dlb.setHd(Double.parseDouble(arg0.getString("hd")));
2195 2340 dlb.setSh(Double.parseDouble(arg0.getString("sh")));
  2341 + dlb.setSsgsdm(arg0.getString("ssgsdm"));
2196 2342 dlb.setFgsdm(arg0.getString("fgsdm"));
2197 2343 dlb.setRq(rq);
  2344 + if(dlb.getSsgsdm() != null && dlb.getFgsdm() != null){
  2345 + dlb.setFgsname(BasicData.businessFgsCodeNameMap.get(dlb.getFgsdm()+"_"+dlb.getSsgsdm()));
  2346 + }
2198 2347 return dlb;
2199 2348 }
2200 2349 });
... ... @@ -2311,9 +2460,17 @@ public class CalcWaybillServiceImpl extends BaseServiceImpl&lt;CalcWaybill, Integer
2311 2460  
2312 2461 CalcWaybillDetail dayc = null;
2313 2462 if("m".equals(timeType)){
2314   - while (!dayList.get(dayIndex).containsKey(cw.getRqStr())){
2315   - calcList.add(new CalcWaybillDetail());
2316   - dayIndex++;
  2463 + if(calcList.size() < dayList.size()){ //列还没加满则往后加新的列
  2464 + while (dayList.size() > dayIndex && !dayList.get(dayIndex).containsKey(cw.getRqStr())){
  2465 + calcList.add(new CalcWaybillDetail());
  2466 + dayIndex++;
  2467 + }
  2468 + } else { //列已经加满说明是前面的日期
  2469 + int temp = 0;
  2470 + while (!dayList.get(temp).containsKey(cw.getRqStr())){
  2471 + temp++;
  2472 + }
  2473 + dayIndex = temp;
2317 2474 }
2318 2475 dayc = dayList.get(dayIndex).get(cw.getRqStr());
2319 2476 } else if("y".equals(timeType)){
... ... @@ -2341,7 +2498,12 @@ public class CalcWaybillServiceImpl extends BaseServiceImpl&lt;CalcWaybill, Integer
2341 2498 CalcWaybillDetail cwd = new CalcWaybillDetail();
2342 2499 // 深度拷贝对象
2343 2500 BeanUtils.copyProperties(cw,cwd);
2344   - calcList.add(cwd);
  2501 + if(calcList.size() <= dayIndex){ //把对象往后填
  2502 + calcList.add(cwd);
  2503 + } else { //换行时会用空对象补完所有列,这里是把空的列替换掉。
  2504 + calcList.remove(dayIndex);
  2505 + calcList.add(dayIndex, cwd);
  2506 + }
2345 2507 calc.setTs(calc.getTs()+1);
2346 2508 zjCalc.setTs(zjCalc.getTs()+1);
2347 2509 }
... ... @@ -2354,10 +2516,12 @@ public class CalcWaybillServiceImpl extends BaseServiceImpl&lt;CalcWaybill, Integer
2354 2516 } else if("y".equals(timeType) && cwNext != null && key.equals(keyNext) && !cw.getRqStr().substring(0,7).equals(cwNext.getRqStr().substring(0,7))){
2355 2517 dayIndex++;
2356 2518 } else if(!key.equals(keyNext)){
2357   - // 满数据的不用补空格
  2519 + // 换行时把空位补上空的对象,满数据的不用补空格
2358 2520 while (dayList.size() > dayIndex+1){
2359   - calcList.add(new CalcWaybillDetail());
2360 2521 dayIndex++;
  2522 + if(calcList.size() < dayList.size()){
  2523 + calcList.add(new CalcWaybillDetail());
  2524 + }
2361 2525 }
2362 2526 // 换列了从头开始,上一个下标赋值为初始
2363 2527 dayIndexPrev = -1;
... ... @@ -2502,7 +2666,6 @@ public class CalcWaybillServiceImpl extends BaseServiceImpl&lt;CalcWaybill, Integer
2502 2666 double all = 0.0;
2503 2667 for (Map<String, CalcWaybillDetail> cmap:dayList) {
2504 2668 for (Map.Entry<String, CalcWaybillDetail> cw : cmap.entrySet()) {
2505   -// System.out.println("key = " + cw.getKey() + ", value = " + cw.getValue());
2506 2669 CalcWaybillDetail c1 = cw.getValue();
2507 2670 if("jzlAll".equals(itemDetails)){
2508 2671 listEnd.add(df.format(c1.getJzl()));
... ...