Commit 24999b6162a475ba2d388a96ea433b85d0131fa8
1 parent
e8c1bd9d
油量。报表
Showing
1 changed file
with
108 additions
and
15 deletions
src/main/java/com/bsth/service/oil/impl/CwjyServiceImpl.java
| @@ -6,17 +6,26 @@ import java.text.ParseException; | @@ -6,17 +6,26 @@ import java.text.ParseException; | ||
| 6 | import java.text.SimpleDateFormat; | 6 | import java.text.SimpleDateFormat; |
| 7 | import java.util.ArrayList; | 7 | import java.util.ArrayList; |
| 8 | import java.util.Arrays; | 8 | import java.util.Arrays; |
| 9 | +import java.util.Date; | ||
| 9 | import java.util.HashMap; | 10 | import java.util.HashMap; |
| 10 | import java.util.List; | 11 | import java.util.List; |
| 11 | import java.util.Map; | 12 | import java.util.Map; |
| 12 | 13 | ||
| 14 | +import javax.transaction.Transactional; | ||
| 15 | + | ||
| 16 | +import org.apache.commons.lang3.StringEscapeUtils; | ||
| 17 | +import org.slf4j.Logger; | ||
| 18 | +import org.slf4j.LoggerFactory; | ||
| 13 | import org.springframework.beans.factory.annotation.Autowired; | 19 | import org.springframework.beans.factory.annotation.Autowired; |
| 14 | import org.springframework.jdbc.core.JdbcTemplate; | 20 | import org.springframework.jdbc.core.JdbcTemplate; |
| 15 | import org.springframework.jdbc.core.RowMapper; | 21 | import org.springframework.jdbc.core.RowMapper; |
| 16 | import org.springframework.stereotype.Service; | 22 | import org.springframework.stereotype.Service; |
| 17 | 23 | ||
| 24 | +import com.alibaba.fastjson.JSONArray; | ||
| 25 | +import com.alibaba.fastjson.JSONObject; | ||
| 18 | import com.bsth.common.ResponseCode; | 26 | import com.bsth.common.ResponseCode; |
| 19 | import com.bsth.entity.oil.Cwjy; | 27 | import com.bsth.entity.oil.Cwjy; |
| 28 | +import com.bsth.entity.oil.Cyl; | ||
| 20 | import com.bsth.entity.oil.Ylxxb; | 29 | import com.bsth.entity.oil.Ylxxb; |
| 21 | import com.bsth.repository.oil.CwjyRepository; | 30 | import com.bsth.repository.oil.CwjyRepository; |
| 22 | import com.bsth.repository.oil.YlxxbRepository; | 31 | import com.bsth.repository.oil.YlxxbRepository; |
| @@ -35,8 +44,8 @@ public class CwjyServiceImpl extends BaseServiceImpl<Cwjy,Integer> implements Cw | @@ -35,8 +44,8 @@ public class CwjyServiceImpl extends BaseServiceImpl<Cwjy,Integer> implements Cw | ||
| 35 | 44 | ||
| 36 | @Autowired | 45 | @Autowired |
| 37 | JdbcTemplate jdbcTemplate; | 46 | JdbcTemplate jdbcTemplate; |
| 38 | - | ||
| 39 | - @SuppressWarnings("unchecked") | 47 | + Logger logger = LoggerFactory.getLogger(this.getClass()); |
| 48 | + /*@SuppressWarnings("unchecked") | ||
| 40 | public PageObject<Ylxxb> Pagequery(Map<String, Object> map) { | 49 | public PageObject<Ylxxb> Pagequery(Map<String, Object> map) { |
| 41 | int page=Integer.parseInt(map.get("page").toString()); | 50 | int page=Integer.parseInt(map.get("page").toString()); |
| 42 | SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd"); | 51 | SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd"); |
| @@ -129,7 +138,7 @@ public class CwjyServiceImpl extends BaseServiceImpl<Cwjy,Integer> implements Cw | @@ -129,7 +138,7 @@ public class CwjyServiceImpl extends BaseServiceImpl<Cwjy,Integer> implements Cw | ||
| 129 | return t; | 138 | return t; |
| 130 | } | 139 | } |
| 131 | }); | 140 | }); |
| 132 | - /*List<Object[]> list=repository.obtainCwjycl(rq,nbbm); | 141 | + List<Object[]> list=repository.obtainCwjycl(rq,nbbm); |
| 133 | for (int i = 0; i < list.size(); i++) { | 142 | for (int i = 0; i < list.size(); i++) { |
| 134 | Ylxxb y=new Ylxxb(); | 143 | Ylxxb y=new Ylxxb(); |
| 135 | y.setGsdm(list.get(i)[0]==null?"":list.get(i)[0].toString()); | 144 | y.setGsdm(list.get(i)[0]==null?"":list.get(i)[0].toString()); |
| @@ -148,13 +157,13 @@ public class CwjyServiceImpl extends BaseServiceImpl<Cwjy,Integer> implements Cw | @@ -148,13 +157,13 @@ public class CwjyServiceImpl extends BaseServiceImpl<Cwjy,Integer> implements Cw | ||
| 148 | e.printStackTrace(); | 157 | e.printStackTrace(); |
| 149 | } | 158 | } |
| 150 | yList.add(y); | 159 | yList.add(y); |
| 151 | - }*/ | 160 | + } |
| 152 | PageHelper pageHelper = new PageHelper(listsize, map); | 161 | PageHelper pageHelper = new PageHelper(listsize, map); |
| 153 | pageHelper.getMap(); | 162 | pageHelper.getMap(); |
| 154 | PageObject<Ylxxb> pageObject=pageHelper.getPageObject(); | 163 | PageObject<Ylxxb> pageObject=pageHelper.getPageObject(); |
| 155 | pageObject.setDataList(yList); | 164 | pageObject.setDataList(yList); |
| 156 | return pageObject; | 165 | return pageObject; |
| 157 | - } | 166 | + }*/ |
| 158 | 167 | ||
| 159 | @Override | 168 | @Override |
| 160 | public Ylxxb bynbbm(Map<String, Object> map) { | 169 | public Ylxxb bynbbm(Map<String, Object> map) { |
| @@ -188,28 +197,112 @@ public class CwjyServiceImpl extends BaseServiceImpl<Cwjy,Integer> implements Cw | @@ -188,28 +197,112 @@ public class CwjyServiceImpl extends BaseServiceImpl<Cwjy,Integer> implements Cw | ||
| 188 | return y; | 197 | return y; |
| 189 | } | 198 | } |
| 190 | 199 | ||
| 200 | + @Transactional | ||
| 191 | @Override | 201 | @Override |
| 192 | - public Map<String, Object> savejzl(Ylxxb t) { | 202 | + public Map<String, Object> savejzl(Map<String, Object> maps) throws Exception { |
| 193 | // TODO Auto-generated method stub | 203 | // TODO Auto-generated method stub |
| 194 | Map<String, Object> map=new HashMap<String,Object>(); | 204 | Map<String, Object> map=new HashMap<String,Object>(); |
| 195 | try { | 205 | try { |
| 196 | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); | 206 | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); |
| 197 | - String rq = sdf.format(t.getYyrq()); | ||
| 198 | - String nbbm=t.getNbbm(); | ||
| 199 | - List<Ylxxb> yList=ylxxbRepository.obtainYlxx2(rq,nbbm); | ||
| 200 | - if(yList.size()>0){ | ||
| 201 | - t.setId(yList.get(0).getId()); | ||
| 202 | - ylxxbRepository.save(t); | ||
| 203 | - }else{ | ||
| 204 | - ylxxbRepository.save(t); | 207 | +// String rq = sdf.format(t.getYyrq()); |
| 208 | +// String nbbm=t.getNbbm(); | ||
| 209 | +// List<Ylxxb> yList=ylxxbRepository.obtainYlxx2(rq,nbbm); | ||
| 210 | +// if(yList.size()>0){ | ||
| 211 | +// t.setId(yList.get(0).getId()); | ||
| 212 | +// ylxxbRepository.save(t); | ||
| 213 | +// }else{ | ||
| 214 | +// ylxxbRepository.save(t); | ||
| 215 | +// } | ||
| 216 | + String gsbm=maps.get("gsbm").toString(); | ||
| 217 | + String fgsbm=maps.get("fgsbm").toString(); | ||
| 218 | + String rq=maps.get("rq").toString(); | ||
| 219 | + Date date=sdf.parse(rq); | ||
| 220 | + String json =StringEscapeUtils.unescapeHtml4(maps.get("ylbList").toString()); | ||
| 221 | + JSONArray jsonArray=JSONArray.parseArray(json); | ||
| 222 | + JSONObject jsonObject; | ||
| 223 | + // 获取车辆存油信息 | ||
| 224 | + for (int i = 0; i < jsonArray.size(); i++) { | ||
| 225 | + jsonObject=jsonArray.getJSONObject(i); | ||
| 226 | + Integer id =jsonObject.getInteger("id"); | ||
| 227 | + String jsy=jsonObject.getString("jsy"); | ||
| 228 | + double jzl=jsonObject.getDoubleValue("jzl"); | ||
| 229 | + String stationid=jsonObject.getString("stationid"); | ||
| 230 | + int nylx=jsonObject.getIntValue("nylx"); | ||
| 231 | + String jyggh=jsonObject.getString("jyggh"); | ||
| 232 | + String bz=jsonObject.getString("bz"); | ||
| 233 | + Ylxxb y; | ||
| 234 | + if(id>0){ | ||
| 235 | + y=ylxxbRepository.findOne(id); | ||
| 236 | + y.setJsy(jsy); | ||
| 237 | + y.setJzl(jzl); | ||
| 238 | + y.setStationid(stationid); | ||
| 239 | + y.setJyggh(jyggh); | ||
| 240 | + y.setBz(bz); | ||
| 241 | + y.setCreatetime(date); | ||
| 242 | + ylxxbRepository.save(y); | ||
| 243 | + }else{ | ||
| 244 | + y=new Ylxxb(); | ||
| 245 | + y.setGsdm(gsbm); | ||
| 246 | + y.setJsy(jsy); | ||
| 247 | + y.setJzl(jzl); | ||
| 248 | + y.setStationid(stationid); | ||
| 249 | + y.setJyggh(jyggh); | ||
| 250 | + y.setBz(bz); | ||
| 251 | + y.setCreatetime(date); | ||
| 252 | + y.setJylx(1); | ||
| 253 | + ylxxbRepository.save(y); | ||
| 254 | + } | ||
| 205 | } | 255 | } |
| 206 | map.put("status", ResponseCode.SUCCESS); | 256 | map.put("status", ResponseCode.SUCCESS); |
| 257 | + | ||
| 207 | } catch (Exception e) { | 258 | } catch (Exception e) { |
| 208 | map.put("status", ResponseCode.ERROR); | 259 | map.put("status", ResponseCode.ERROR); |
| 209 | - e.printStackTrace(); | 260 | + logger.error("save erro.", e); |
| 261 | + throw e; | ||
| 210 | // TODO: handle exception | 262 | // TODO: handle exception |
| 211 | } | 263 | } |
| 212 | return map; | 264 | return map; |
| 213 | } | 265 | } |
| 214 | 266 | ||
| 267 | + @Override | ||
| 268 | + public List<Ylxxb> Pagequery(Map<String, Object> map) { | ||
| 269 | + // TODO Auto-generated method stub | ||
| 270 | + String rq=map.get("rq").toString(); | ||
| 271 | + String nbbm=map.get("nbbh").toString(); | ||
| 272 | + String sql="SELECT a.gsdm as gsdm,a.fgsdm as fgsdm,a.nbbm as nbbm," | ||
| 273 | + + "b.jyggh as jyggh,b.jzl as jzl ,b.stationid as stationid,b.jsy as jsy," | ||
| 274 | + + "b.nylx as nylx,b.yj as yj,b.bz as bz,b.id as id ,c.jsy as ldgh FROM bsth_c_cwjy a "+ | ||
| 275 | + " left join (" | ||
| 276 | + + " select * from bsth_c_ylxxb b " | ||
| 277 | + + "where to_days(b.yyrq)=to_days('"+rq+"') and jylx=1) b " + | ||
| 278 | + " on a.nbbm=b.nbbm " | ||
| 279 | + + "left join (select nbbm,group_concat(jsy) as jsy " | ||
| 280 | + + "from bsth_c_ylb where to_days(rq)= to_days('"+rq+"' ) group by nbbm "+ | ||
| 281 | + " ) c on a.nbbm=c.nbbm " | ||
| 282 | + + "where a.nbbm like '%"+nbbm+"%'"; | ||
| 283 | + | ||
| 284 | + List<Ylxxb> yList= jdbcTemplate.query(sql, | ||
| 285 | + new RowMapper<Ylxxb>(){ | ||
| 286 | + @Override | ||
| 287 | + public Ylxxb mapRow(ResultSet rs, int rowNum) throws SQLException { | ||
| 288 | + Ylxxb t=new Ylxxb(); | ||
| 289 | + t.setId(rs.getInt("id")); | ||
| 290 | + t.setGsdm(rs.getString("gsdm")); | ||
| 291 | + t.setFgsdm(rs.getString("fgsdm")); | ||
| 292 | + t.setNbbm(rs.getString("nbbm")); | ||
| 293 | + t.setJyggh(rs.getString("jyggh")); | ||
| 294 | + t.setJsy(rs.getString("jsy")); | ||
| 295 | + t.setJzl(rs.getDouble("jzl")); | ||
| 296 | + t.setStationid(rs.getString("stationid")); | ||
| 297 | + t.setNylx(rs.getInt("nylx")); | ||
| 298 | + t.setYj(rs.getDouble("yj")); | ||
| 299 | + t.setBz(rs.getString("bz")); | ||
| 300 | + t.setJsy(rs.getString("ldgh")); | ||
| 301 | + return t; | ||
| 302 | + } | ||
| 303 | + }); | ||
| 304 | + | ||
| 305 | + return yList; | ||
| 306 | + } | ||
| 307 | + | ||
| 215 | } | 308 | } |