Commit 999fff42e5b271a50c1ba69874e40dd68278fee3

Authored by 娄高锋
1 parent 73f9bcc9

充电量接口接入到集调的表中

src/main/java/com/bsth/server_rs/electric/ElectricService.java
1 package com.bsth.server_rs.electric; 1 package com.bsth.server_rs.electric;
2 2
3 import com.alibaba.fastjson.JSONObject; 3 import com.alibaba.fastjson.JSONObject;
  4 +import com.bsth.entity.JdlReception;
  5 +import com.bsth.repository.JdlReceptionRepository;
4 import com.bsth.server_ws.electric_oil.entity.Electric; 6 import com.bsth.server_ws.electric_oil.entity.Electric;
5 import org.slf4j.Logger; 7 import org.slf4j.Logger;
6 import org.slf4j.LoggerFactory; 8 import org.slf4j.LoggerFactory;
@@ -8,9 +10,8 @@ import org.springframework.beans.factory.annotation.Autowired; @@ -8,9 +10,8 @@ import org.springframework.beans.factory.annotation.Autowired;
8 import org.springframework.jdbc.core.BeanPropertyRowMapper; 10 import org.springframework.jdbc.core.BeanPropertyRowMapper;
9 import org.springframework.jdbc.core.JdbcTemplate; 11 import org.springframework.jdbc.core.JdbcTemplate;
10 import org.springframework.stereotype.Component; 12 import org.springframework.stereotype.Component;
  13 +import org.springframework.web.bind.annotation.RequestBody;
11 14
12 -import javax.servlet.http.HttpServletRequest;  
13 -import javax.servlet.http.HttpServletResponse;  
14 import javax.ws.rs.GET; 15 import javax.ws.rs.GET;
15 import javax.ws.rs.POST; 16 import javax.ws.rs.POST;
16 import javax.ws.rs.Path; 17 import javax.ws.rs.Path;
@@ -18,8 +19,8 @@ import javax.ws.rs.PathParam; @@ -18,8 +19,8 @@ import javax.ws.rs.PathParam;
18 import javax.ws.rs.Produces; 19 import javax.ws.rs.Produces;
19 import javax.ws.rs.core.MediaType; 20 import javax.ws.rs.core.MediaType;
20 21
21 -import java.io.BufferedReader;  
22 -import java.io.InputStreamReader; 22 +import java.util.Date;
  23 +import java.util.HashMap;
23 import java.util.List; 24 import java.util.List;
24 import java.util.Map; 25 import java.util.Map;
25 26
@@ -35,6 +36,9 @@ public class ElectricService { @@ -35,6 +36,9 @@ public class ElectricService {
35 36
36 @Autowired 37 @Autowired
37 JdbcTemplate jdbcTemplate; 38 JdbcTemplate jdbcTemplate;
  39 +
  40 + @Autowired
  41 + JdlReceptionRepository jdlReceptionRepository;
38 42
39 @GET 43 @GET
40 @Path("/{company}/{rq}") 44 @Path("/{company}/{rq}")
@@ -47,33 +51,46 @@ public class ElectricService { @@ -47,33 +51,46 @@ public class ElectricService {
47 list = jdbcTemplate.query("select fgsdm as fgs_bm,c.business_name as fgs_name,ssgsdm as gs_bm,b.business_name as gs_name,cdl as jdl,'' as jdz,'' as remarks,rq,createtime as create_date,nbbm,'' as jsy from (select fgsdm,ssgsdm,sum(cdl * 1000) / 1000 as cdl,rq,max(createtime) as createtime,nbbm from bsth_c_dlb where rq = ? GROUP BY fgsdm,ssgsdm,rq,nbbm) a left join bsth_c_business b on a.ssgsdm = b.business_code LEFT JOIN bsth_c_business c on concat(a.ssgsdm, '_', a.fgsdm) = concat(c.up_code, '_', c.business_code) where ssgsdm = ?" 51 list = jdbcTemplate.query("select fgsdm as fgs_bm,c.business_name as fgs_name,ssgsdm as gs_bm,b.business_name as gs_name,cdl as jdl,'' as jdz,'' as remarks,rq,createtime as create_date,nbbm,'' as jsy from (select fgsdm,ssgsdm,sum(cdl * 1000) / 1000 as cdl,rq,max(createtime) as createtime,nbbm from bsth_c_dlb where rq = ? GROUP BY fgsdm,ssgsdm,rq,nbbm) a left join bsth_c_business b on a.ssgsdm = b.business_code LEFT JOIN bsth_c_business c on concat(a.ssgsdm, '_', a.fgsdm) = concat(c.up_code, '_', c.business_code) where ssgsdm = ?"
48 , new Object[]{ rq, company }, BeanPropertyRowMapper.newInstance(Electric.class)); 52 , new Object[]{ rq, company }, BeanPropertyRowMapper.newInstance(Electric.class));
49 }catch (Exception e){ 53 }catch (Exception e){
50 - logger.error("", e); 54 + logger.error("ElectricService", e);
51 } 55 }
52 return list; 56 return list;
53 } 57 }
54 58
55 @POST 59 @POST
56 - @Path("/charge")  
57 - public void charge(HttpServletRequest request, HttpServletResponse response){ 60 + @Path("/orderDataEnter")
  61 + public Map<String, Object> orderDataEnter(@RequestBody JSONObject body){
  62 + Map<String, Object> resMap = new HashMap<String, Object>();
58 try { 63 try {
59 - request.setCharacterEncoding("UTF-8");  
60 - response.setContentType("application/json; charset=UTF-8");  
61 - // 读取请求体  
62 - StringBuilder sb = new StringBuilder();  
63 - String line;  
64 - BufferedReader reader = new BufferedReader(new InputStreamReader(request.getInputStream()));  
65 - while ((line = reader.readLine()) != null) {  
66 - sb.append(line);  
67 - }  
68 - reader.close();  
69 - // 处理消息主体  
70 - String messageBody = sb.toString();  
71 - JSONObject body = JSONObject.parseObject(messageBody);  
72 -// JSONObject data = body.getJSONObject("Data"); 64 + JdlReception jdlReception = new JdlReception();
  65 + jdlReception.setStationName(body.getString("StationName"));
  66 + jdlReception.setConnectorId(body.getString("ConnectorID"));
  67 + jdlReception.setOrderNo(body.getString("OrderNo"));
  68 + jdlReception.setStartTime(body.getString("StartTime"));
  69 + jdlReception.setEndTime(body.getString("EndTime"));
  70 + jdlReception.setStartSoc(body.getDouble("StartSoc"));
  71 + jdlReception.setEndSoc(body.getDouble("EndSoc"));
  72 + jdlReception.setStopReason(body.getString("StopReason"));
  73 + jdlReception.setChargeCapacity(body.getDouble("ChargeCapacity"));
  74 + jdlReception.setElectricCharge(body.getDouble("ElectricCharge"));
  75 + jdlReception.setServiceCharge(body.getDouble("ServiceCharge"));
  76 + jdlReception.setTotalAmount(body.getDouble("TotalAmount"));
  77 + jdlReception.setVinCode(body.getString("VinCode"));
  78 + jdlReception.setCardNo(body.getString("CardNo"));
  79 + jdlReception.setCarCode(body.getString("CarCode"));
  80 + jdlReception.setOrigin(0);
  81 + jdlReception.setCreateBy("接口接入");
  82 + jdlReception.setCreateDate(new Date());
  83 + jdlReceptionRepository.save(jdlReception);
73 84
  85 + resMap.put("Status", 0);
  86 + resMap.put("msg", "成功");
74 }catch (Exception e){ 87 }catch (Exception e){
75 - logger.error("", e); 88 + logger.error("ElectricService.orderDataEnter", body);
  89 + logger.error("ElectricService.orderDataEnter", e);
  90 + resMap.put("Status", 1);
  91 + resMap.put("Msg", "内部错误");
76 } 92 }
  93 + return resMap;
77 } 94 }
78 95
79 } 96 }