Commit d3bc2775d92c02d200ef666ece7dd72e57c77a23

Authored by 娄高锋
1 parent 4694ac94

青浦充电量订单接入接口。

src/main/java/com/bsth/entity/JdlReception.java 0 → 100644
  1 +package com.bsth.entity;
  2 +
  3 +import java.util.Date;
  4 +
  5 +import javax.persistence.Entity;
  6 +import javax.persistence.GeneratedValue;
  7 +import javax.persistence.GenerationType;
  8 +import javax.persistence.Id;
  9 +import javax.persistence.Table;
  10 +
  11 +import org.springframework.format.annotation.DateTimeFormat;
  12 +
  13 +/**
  14 +--------------------------------------------------------
  15 + `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'ID',
  16 + `station_name` varchar(255) DEFAULT NULL COMMENT '站点名称',
  17 + `connector_id` varchar(255) DEFAULT NULL COMMENT '枪编号',
  18 + `order_no` varchar(255) DEFAULT NULL COMMENT '订单编号',
  19 + `start_time` varchar(255) DEFAULT NULL COMMENT '充电开始时间',
  20 + `end_time` varchar(255) DEFAULT NULL COMMENT '充电结束时间',
  21 + `start_soc` double(11,2) DEFAULT NULL COMMENT '开始 SOC(%)',
  22 + `end_soc` double(11,2) DEFAULT NULL COMMENT '结束 SOC(%)',
  23 + `stop_reason` varchar(255) DEFAULT NULL COMMENT '终止原因',
  24 + `charge_capacity` double(11,3) DEFAULT NULL COMMENT '充电量,单位:度',
  25 + `electric_charge` double(11,2) DEFAULT NULL COMMENT '电费,单位:元',
  26 + `service_charge` double(11,2) DEFAULT NULL COMMENT '服务费,单位:元',
  27 + `total_amount` double(11,2) DEFAULT NULL COMMENT '总费用,单位:元',
  28 + `vin_code` varchar(255) DEFAULT NULL COMMENT '卡号',
  29 + `card_no` varchar(255) DEFAULT NULL COMMENT 'VIN,车架号',
  30 + `car_code` varchar(255) DEFAULT NULL COMMENT '车牌号',
  31 + `date_str` varchar(255) DEFAULT NULL COMMENT '营运日期',
  32 + `origin` int(2) NOT NULL DEFAULT '0' COMMENT '数据源(0:接口获取;1:导入)',
  33 + `sum_time` bigint(11) DEFAULT NULL COMMENT '总计充电时间(分钟)',
  34 + `create_by` varchar(255) DEFAULT NULL COMMENT '创建人',
  35 + `create_date` datetime DEFAULT NULL COMMENT '创建时间',
  36 + `update_by` varchar(255) DEFAULT NULL COMMENT '修改人',
  37 + `update_date` datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间',
  38 +*/
  39 +@Entity
  40 +@Table(name = "bsth_c_jdl_reception")
  41 +public class JdlReception {
  42 + @Id
  43 + @GeneratedValue(strategy = GenerationType.IDENTITY)
  44 + private Long id;
  45 + private String stationName;
  46 + private String connectorId;
  47 + private String orderNo;
  48 + private String startTime;
  49 + private String endTime;
  50 + private Double startSoc;
  51 + private Double endSoc;
  52 + private String stopReason;
  53 + private Double chargeCapacity;
  54 + private Double electricCharge;
  55 + private Double serviceCharge;
  56 + private Double totalAmount;
  57 + private String vinCode;
  58 + private String cardNo;
  59 + private String carCode;
  60 + private String dateStr;
  61 + private Integer origin;
  62 + private Integer sumTime;
  63 + private String createBy;
  64 + @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
  65 + private Date createDate;
  66 + private String updateBy;
  67 + @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
  68 + private Date updateDate;
  69 +
  70 +
  71 + public Long getId() {
  72 + return id;
  73 + }
  74 + public void setId(Long id) {
  75 + this.id = id;
  76 + }
  77 + public String getStationName() {
  78 + return stationName;
  79 + }
  80 + public void setStationName(String stationName) {
  81 + this.stationName = stationName;
  82 + }
  83 + public String getConnectorId() {
  84 + return connectorId;
  85 + }
  86 + public void setConnectorId(String connectorId) {
  87 + this.connectorId = connectorId;
  88 + }
  89 + public String getOrderNo() {
  90 + return orderNo;
  91 + }
  92 + public void setOrderNo(String orderNo) {
  93 + this.orderNo = orderNo;
  94 + }
  95 + public String getStartTime() {
  96 + return startTime;
  97 + }
  98 + public void setStartTime(String startTime) {
  99 + this.startTime = startTime;
  100 + }
  101 + public String getEndTime() {
  102 + return endTime;
  103 + }
  104 + public void setEndTime(String endTime) {
  105 + this.endTime = endTime;
  106 + }
  107 + public Double getStartSoc() {
  108 + return startSoc;
  109 + }
  110 + public void setStartSoc(Double startSoc) {
  111 + this.startSoc = startSoc;
  112 + }
  113 + public Double getEndSoc() {
  114 + return endSoc;
  115 + }
  116 + public void setEndSoc(Double endSoc) {
  117 + this.endSoc = endSoc;
  118 + }
  119 + public String getStopReason() {
  120 + return stopReason;
  121 + }
  122 + public void setStopReason(String stopReason) {
  123 + this.stopReason = stopReason;
  124 + }
  125 + public Double getChargeCapacity() {
  126 + return chargeCapacity;
  127 + }
  128 + public void setChargeCapacity(Double chargeCapacity) {
  129 + this.chargeCapacity = chargeCapacity;
  130 + }
  131 + public Double getElectricCharge() {
  132 + return electricCharge;
  133 + }
  134 + public void setElectricCharge(Double electricCharge) {
  135 + this.electricCharge = electricCharge;
  136 + }
  137 + public Double getServiceCharge() {
  138 + return serviceCharge;
  139 + }
  140 + public void setServiceCharge(Double serviceCharge) {
  141 + this.serviceCharge = serviceCharge;
  142 + }
  143 + public Double getTotalAmount() {
  144 + return totalAmount;
  145 + }
  146 + public void setTotalAmount(Double totalAmount) {
  147 + this.totalAmount = totalAmount;
  148 + }
  149 + public String getVinCode() {
  150 + return vinCode;
  151 + }
  152 + public void setVinCode(String vinCode) {
  153 + this.vinCode = vinCode;
  154 + }
  155 + public String getCardNo() {
  156 + return cardNo;
  157 + }
  158 + public void setCardNo(String cardNo) {
  159 + this.cardNo = cardNo;
  160 + }
  161 + public String getCarCode() {
  162 + return carCode;
  163 + }
  164 + public void setCarCode(String carCode) {
  165 + this.carCode = carCode;
  166 + }
  167 + public String getDateStr() {
  168 + return dateStr;
  169 + }
  170 + public void setDateStr(String dateStr) {
  171 + this.dateStr = dateStr;
  172 + }
  173 + public Integer getOrigin() {
  174 + return origin;
  175 + }
  176 + public void setOrigin(Integer origin) {
  177 + this.origin = origin;
  178 + }
  179 + public Integer getSumTime() {
  180 + return sumTime;
  181 + }
  182 + public void setSumTime(Integer sumTime) {
  183 + this.sumTime = sumTime;
  184 + }
  185 + public String getCreateBy() {
  186 + return createBy;
  187 + }
  188 + public void setCreateBy(String createBy) {
  189 + this.createBy = createBy;
  190 + }
  191 + public Date getCreateDate() {
  192 + return createDate;
  193 + }
  194 + public void setCreateDate(Date createDate) {
  195 + this.createDate = createDate;
  196 + }
  197 + public String getUpdateBy() {
  198 + return updateBy;
  199 + }
  200 + public void setUpdateBy(String updateBy) {
  201 + this.updateBy = updateBy;
  202 + }
  203 + public Date getUpdateDate() {
  204 + return updateDate;
  205 + }
  206 + public void setUpdateDate(Date updateDate) {
  207 + this.updateDate = updateDate;
  208 + }
  209 +
  210 +}
0 211 \ No newline at end of file
... ...
src/main/java/com/bsth/repository/JdlReceptionRepository.java 0 → 100644
  1 +package com.bsth.repository;
  2 +
  3 +import org.springframework.data.repository.PagingAndSortingRepository;
  4 +import org.springframework.stereotype.Repository;
  5 +
  6 +import com.bsth.entity.JdlReception;
  7 +
  8 +@Repository
  9 +public interface JdlReceptionRepository extends PagingAndSortingRepository<JdlReception, Integer>{
  10 +
  11 +}
0 12 \ No newline at end of file
... ...
src/main/java/com/bsth/repository/ScheduleRealInfoRepository.java
... ... @@ -59,4 +59,10 @@ public interface ScheduleRealInfoRepository extends PagingAndSortingRepository&lt;S
59 59 @EntityGraph(value = "scheduleRealInfo_cTasks", type = EntityGraph.EntityGraphType.FETCH)
60 60 @Query("select DISTINCT s from ScheduleRealInfo s where s.scheduleDateStr=?1 and s.gsBm=?2 and s.updateDate>=?3")
61 61 List<ScheduleRealInfo> findByDateAndCompany(String schDate, String companyCode, Date timestamp);
  62 +
  63 + @Query("select s from ScheduleRealInfo s where s.clZbh = ?1 and s.scheduleDateStr = ?2 and s.realExecDate = ?3 order by fcsj asc")
  64 + List<ScheduleRealInfo> getFirstByClZbhAndScheduleDateStrAndRealExecDateOrderByFcsjAsc(String clZbh, String scheduleDateStr, String realExecDate);
  65 +
  66 + @Query("select s from ScheduleRealInfo s where s.clZbh = ?1 and s.scheduleDateStr >= ?2 and s.scheduleDateStr <= ?3 order by scheduleDateStr desc")
  67 + List<ScheduleRealInfo> getFirstByClZbhAndScheduleDateStrBetweenOrderByScheduleDateStrDesc(String clZbh, String scheduleDateStr1, String scheduleDateStr2);
62 68 }
... ...
src/main/java/com/bsth/server_rs/electric/ElectricService.java
1 1 package com.bsth.server_rs.electric;
2 2  
  3 +import com.alibaba.fastjson.JSONObject;
  4 +import com.bsth.entity.JdlReception;
  5 +import com.bsth.entity.ScheduleRealInfo;
  6 +import com.bsth.repository.JdlReceptionRepository;
  7 +import com.bsth.repository.ScheduleRealInfoRepository;
3 8 import com.bsth.server_ws.electric_oil.entity.Electric;
4 9 import org.slf4j.Logger;
5 10 import org.slf4j.LoggerFactory;
... ... @@ -7,13 +12,20 @@ import org.springframework.beans.factory.annotation.Autowired;
7 12 import org.springframework.jdbc.core.BeanPropertyRowMapper;
8 13 import org.springframework.jdbc.core.JdbcTemplate;
9 14 import org.springframework.stereotype.Component;
  15 +import org.springframework.web.bind.annotation.RequestBody;
10 16  
11 17 import javax.ws.rs.GET;
  18 +import javax.ws.rs.POST;
12 19 import javax.ws.rs.Path;
13 20 import javax.ws.rs.PathParam;
14 21 import javax.ws.rs.Produces;
15 22 import javax.ws.rs.core.MediaType;
  23 +
  24 +import java.text.SimpleDateFormat;
  25 +import java.util.Date;
  26 +import java.util.HashMap;
16 27 import java.util.List;
  28 +import java.util.Map;
17 29  
18 30 /**
19 31 * Created by panzhao on 2018/3/27.
... ... @@ -27,6 +39,12 @@ public class ElectricService {
27 39  
28 40 @Autowired
29 41 JdbcTemplate jdbcTemplate;
  42 +
  43 + @Autowired
  44 + JdlReceptionRepository jdlReceptionRepository;
  45 +
  46 + @Autowired
  47 + ScheduleRealInfoRepository scheduleRealInfoRepository;
30 48  
31 49 @GET
32 50 @Path("/{company}/{rq}")
... ... @@ -43,4 +61,56 @@ public class ElectricService {
43 61 }
44 62 return list;
45 63 }
  64 +
  65 + @POST
  66 + @Path("/orderDataEnter")
  67 + public Map<String, Object> orderDataEnter(@RequestBody JSONObject body){
  68 + Map<String, Object> resMap = new HashMap<String, Object>();
  69 + try {
  70 + System.out.println(body);
  71 + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
  72 + SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  73 +
  74 + String startTime = body.getString("startTime");
  75 + String endTime = body.getString("endTime");
  76 +
  77 + JdlReception jdlReception = new JdlReception();
  78 + jdlReception.setStationName(body.getString("stationName"));
  79 + jdlReception.setConnectorId(body.getString("connectorId"));
  80 + jdlReception.setOrderNo(body.getString("orderNo"));
  81 + jdlReception.setStartTime(startTime);
  82 + jdlReception.setEndTime(endTime);
  83 + jdlReception.setStartSoc(body.getDouble("startSoc"));
  84 + jdlReception.setEndSoc(body.getDouble("endSoc"));
  85 + jdlReception.setStopReason(body.getString("stopReason"));
  86 + jdlReception.setChargeCapacity(body.getDouble("chargeCapacity"));
  87 + jdlReception.setElectricCharge(body.getDouble("electricCharge"));
  88 + jdlReception.setServiceCharge(body.getDouble("serviceCharge"));
  89 + jdlReception.setTotalAmount(body.getDouble("totalAmount"));
  90 + jdlReception.setVinCode(body.getString("vinCode"));
  91 + jdlReception.setCardNo(body.getString("cardNo"));
  92 + jdlReception.setCarCode(body.getString("carCode"));
  93 + jdlReception.setOrigin(0);
  94 + jdlReception.setCreateBy("接口接入");
  95 + jdlReception.setCreateDate(new Date());
  96 +
  97 + String startDate = startTime.split(" ")[0];
  98 +
  99 + Date startTime_Date = df.parse(startTime);
  100 + Date endTime_Date = df.parse(endTime);
  101 + jdlReception.setDateStr(startDate);
  102 + jdlReception.setSumTime(Integer.valueOf(((endTime_Date.getTime() - startTime_Date.getTime()) / 60000)+""));
  103 +
  104 + jdlReceptionRepository.save(jdlReception);
  105 +
  106 + resMap.put("Status", 0);
  107 + resMap.put("msg", "成功");
  108 + }catch (Exception e){
  109 + logger.error("ElectricService.orderDataEnter", body);
  110 + logger.error("ElectricService.orderDataEnter", e);
  111 + resMap.put("Status", 1);
  112 + resMap.put("Msg", "内部错误");
  113 + }
  114 + return resMap;
  115 + }
46 116 }
... ...