From d48ba4bb9fe010d04b6381cd0876248ffd6bb139 Mon Sep 17 00:00:00 2001 From: yuyang <2265829957@qq.com> Date: Mon, 16 Aug 2021 19:24:26 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=B0=8F=E7=A8=8B=E5=BA=8F?= =?UTF-8?q?=E8=AF=B7=E6=B1=82=E8=B7=AF=E5=BE=84=EF=BC=8C=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E6=A1=A9=E8=AE=A2=E5=8D=95=E7=BB=93=E6=9D=9F=E5=9B=9E=E8=B0=83?= =?UTF-8?q?=E5=AE=9E=E4=BD=93=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/XhpcChargingStationApiController.java | 90 +++++++++ .../XhpcChargingStationController.java | 51 +---- .../controller/XhpcTerminalController.java | 7 - .../XhpcChargingStationServiceImpl.java | 75 ++++++- .../mapper/XhpcChargingStationMapper.xml | 3 + .../com/xhpc/common/dto/PileEndOrder.java | 98 +++++++++ .../HxpcChargeOrderController.java | 33 ++- .../HxpcPileOrderController.java | 191 ++++++++++-------- .../XhpcHistoryOrderController.java | 27 --- .../xhpc/order/domain/HxpcChargeOrder.java | 14 ++ .../order/mapper/HxpcChargeOrderMapper.java | 9 +- .../impl/HxpcChargeOrderServiceImpl.java | 20 +- .../mapper/XhpcChargeOrderMapper.xml | 8 +- .../config/ApplicationContextRegister.java | 26 +++ 14 files changed, 458 insertions(+), 194 deletions(-) create mode 100644 xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/api/XhpcChargingStationApiController.java create mode 100644 xhpc-modules/xhpc-common/src/main/java/com/xhpc/common/dto/PileEndOrder.java rename xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/{controller => api}/HxpcChargeOrderController.java (67%) rename xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/{controller => api}/HxpcPileOrderController.java (50%) create mode 100644 xhpc-modules/xhpc-wxma/src/main/java/com/xhpc/wxma/config/ApplicationContextRegister.java diff --git a/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/api/XhpcChargingStationApiController.java b/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/api/XhpcChargingStationApiController.java new file mode 100644 index 00000000..aa10608b --- /dev/null +++ b/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/api/XhpcChargingStationApiController.java @@ -0,0 +1,90 @@ +package com.xhpc.charging.station.api; + +import com.xhpc.charging.station.service.IXhpcChargingStationService; +import com.xhpc.charging.station.service.IXhpcTerminalService; +import com.xhpc.common.core.web.controller.BaseController; +import com.xhpc.common.core.web.domain.AjaxResult; +import com.xhpc.common.core.web.page.TableDataInfo; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +import java.util.List; +import java.util.Map; + +@RestController +@RequestMapping("/api/station") +public class XhpcChargingStationApiController extends BaseController { + + @Autowired + private IXhpcChargingStationService xhpcChargingStationService; + @Autowired + private IXhpcTerminalService xhpcTerminalService; + + /** + * 微信小程序电站列表 + * + * @param name 电站名称 + * @param serviceFacilities 标签(服务设施) + * @param code 城市id + * @param longitude 经度 + * @param latitude 维度 + * @return + */ + //@PreAuthorize(hasPermi = "system:station:list") + @GetMapping("/getWXList") + public TableDataInfo getWXList(String name, String serviceFacilities, Integer code, String longitude, String latitude) { + + startPage(); + List> list = xhpcChargingStationService.getWXList(name, serviceFacilities, code, longitude, latitude); + return getDataTable(list); + } + + /** + * 电站详情+站点详情(微信) + * + * @param chargingStationId 站点id + * @param longitude 经度 + * @param latitude 维度 + * @return + */ + @GetMapping(value = "/getWXXhpcChargingStationMessage") + public AjaxResult getWXXhpcChargingStationMessage(@RequestParam(value = "chargingStationId", required = true) Long chargingStationId, @RequestParam(value = "longitude", required = true) String longitude, @RequestParam(value = "latitude", required = true) String latitude) { + + return AjaxResult.success(xhpcChargingStationService.getWXXhpcChargingStationMessage(chargingStationId, longitude, latitude)); + } + + /** + * 电站详情---价格详情 + * + * @param chargingStationId 站点id + * @return + */ + @GetMapping(value = "/getWXXhpcRateTimeMassage") + public AjaxResult getXhpcRateTimeMassage(@RequestParam Long chargingStationId) { + + return AjaxResult.success(xhpcChargingStationService.getWXXhpcRateTimeMassage(chargingStationId)); + } + + /** + * 电站详情---终端列表(微信) + * + * @param chargingStationId 站点id + * @return + */ + @GetMapping(value = "/getWXXhpcTerminalMassage") + public AjaxResult getWXXhpcTerminalMassage(@RequestParam Long chargingStationId) { + + return AjaxResult.success(xhpcChargingStationService.getWXXhpcTerminalMassage(chargingStationId)); + } + + /** + * 通过终端编号进入小程序开始充电页面 + */ + @GetMapping(value = "/getWXpNumMessage") + public AjaxResult getWXpNumMessage(@RequestParam(value = "pNum") String pNum) { + return xhpcTerminalService.getWXpNumMessage(pNum); + } +} diff --git a/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/controller/XhpcChargingStationController.java b/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/controller/XhpcChargingStationController.java index ec052ace..c5e210af 100644 --- a/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/controller/XhpcChargingStationController.java +++ b/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/controller/XhpcChargingStationController.java @@ -160,63 +160,14 @@ public class XhpcChargingStationController extends BaseController { return AjaxResult.success(xhpcChargingStationService.getXhpcChargingStationMessage(chargingStationId, type)); } - /** - * 微信小程序电站列表 - * - * @param name 电站名称 - * @param serviceFacilities 标签(服务设施) - * @param code 城市id - * @param longitude 经度 - * @param latitude 维度 - * @return - */ - //@PreAuthorize(hasPermi = "system:station:list") - @GetMapping("/getWXList") - public TableDataInfo getWXList(String name, String serviceFacilities, Integer code, String longitude, String latitude) { - - startPage(); - List> list = xhpcChargingStationService.getWXList(name, serviceFacilities, code, longitude, latitude); - return getDataTable(list); - } - /** - * 电站详情+站点详情 - * - * @param chargingStationId 站点id - * @param longitude 经度 - * @param latitude 维度 - * @return - */ - @GetMapping(value = "/getWXXhpcChargingStationMessage") - public AjaxResult getWXXhpcChargingStationMessage(@RequestParam(value = "chargingStationId", required = true) Long chargingStationId, @RequestParam(value = "longitude", required = true) String longitude, @RequestParam(value = "latitude", required = true) String latitude) { - return AjaxResult.success(xhpcChargingStationService.getWXXhpcChargingStationMessage(chargingStationId, longitude, latitude)); - } - /** - * 电站详情---价格详情 - * - * @param chargingStationId 站点id - * @return - */ - @GetMapping(value = "/getWXXhpcRateTimeMassage") - public AjaxResult getXhpcRateTimeMassage(@RequestParam Long chargingStationId) { - return AjaxResult.success(xhpcChargingStationService.getWXXhpcRateTimeMassage(chargingStationId)); - } - /** - * 电站详情---终端列表 - * - * @param chargingStationId 站点id - * @return - */ - @GetMapping(value = "/getWXXhpcTerminalMassage") - public AjaxResult getWXXhpcTerminalMassage(@RequestParam Long chargingStationId) { - return AjaxResult.success(xhpcChargingStationService.getWXXhpcTerminalMassage(chargingStationId)); - } + /** diff --git a/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/controller/XhpcTerminalController.java b/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/controller/XhpcTerminalController.java index f5274d99..7e122352 100644 --- a/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/controller/XhpcTerminalController.java +++ b/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/controller/XhpcTerminalController.java @@ -84,14 +84,7 @@ public class XhpcTerminalController extends BaseController { } - /** - * 通过终端编号进入小程序开始充电页面 - */ - @GetMapping(value = "/getWXpNumMessage") - public AjaxResult getWXpNumMessage(@RequestParam(value = "pNum") String pNum) { - return xhpcTerminalService.getWXpNumMessage(pNum); - } } diff --git a/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/service/XhpcChargingStationServiceImpl.java b/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/service/XhpcChargingStationServiceImpl.java index 5ed2cedc..169d3996 100644 --- a/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/service/XhpcChargingStationServiceImpl.java +++ b/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/service/XhpcChargingStationServiceImpl.java @@ -16,6 +16,7 @@ import com.xhpc.common.domain.XhpcChargingStation; import com.xhpc.common.domain.XhpcRate; import com.xhpc.common.domain.XhpcRateModel; import com.xhpc.common.domain.XhpcRateTime; +import com.xhpc.common.redis.service.RedisService; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -43,6 +44,8 @@ public class XhpcChargingStationServiceImpl implements IXhpcChargingStationServi private IXhpcTerminalService xhpcTerminalService; @Autowired private PowerPileService powerPileService; + @Autowired + private RedisService redisService; /** * 查询电站 @@ -579,7 +582,11 @@ public class XhpcChargingStationServiceImpl implements IXhpcChargingStationServi for (int i = 0; i < list.size(); i++) { Map map = list.get(i); //桩(空闲和使用从redis获取) - map.put("free", 10); + if(map.get("serialNumbers") !=null){ + map.put("free", countTerminal(map.get("serialNumbers").toString())); + }else{ + map.put("free", 0); + } } } return list; @@ -592,7 +599,11 @@ public class XhpcChargingStationServiceImpl implements IXhpcChargingStationServi Map map = xhpcChargingStationMapper.getWXXhpcChargingStationMessage(chargingStationId, longitude, latitude); //桩(空闲和使用从redis获取) - map.put("free", 10); + if(map.get("serialNumbers") !=null){ + map.put("free", countTerminal(map.get("serialNumbers").toString())); + }else{ + map.put("free", 0); + } //图片信息 List imgList = new ArrayList<>(); @@ -630,12 +641,44 @@ public class XhpcChargingStationServiceImpl implements IXhpcChargingStationServi for (int i = 0; i < list.size(); i++) { Map map = list.get(i); //终端状态用 redis数据 - //终端状态 - map.put("status", "1"); - //soc - map.put("soc", "18%"); - //剩余时间 - map.put("remainingTime", "16分钟"); + if(map.get("serialNumber") !=null){ + Map cacheMap =redisService.getCacheMap("gun:"+map.get("serialNumber").toString()); + if(cacheMap !=null){ + if("空闲".equals(cacheMap.get("status"))){ + map.put("status", 2); + }else if ("离线".equals(cacheMap.get("status"))){ + map.put("status", 0); + }else if("故障".equals(cacheMap.get("status"))){ + map.put("status", 1); + }else{ + //充电桩 + map.put("status", 3); + if(cacheMap.get("status")!=null){ + map.put("soc", cacheMap.get("status").toString()+"%"); + } + if(cacheMap.get("remainingTime")!=null){ + int number = (int)cacheMap.get("remainingTime"); + if(number>300){ + map.put("remainingTime", "未知"); + }else{ + int mins = number % 60; + int hours = number / 60; + if(mins>0){ + map.put("remainingTime", mins+"小时"+hours+"分钟"); + }else{ + map.put("remainingTime", hours+"分钟"); + } + } + }else{ + map.put("remainingTime", "--"); + } + } + }else{ + map.put("status", 1); + } + }else{ + map.put("status", 1); + } } } return list; @@ -846,6 +889,22 @@ public class XhpcChargingStationServiceImpl implements IXhpcChargingStationServi } + public int countTerminal(String serialNumbers){ + int number =0; + //获取空闲终端 + String[] split = serialNumbers.split(","); + + if(!"".equals(serialNumbers) && serialNumbers !=null){ + for (String serialNumber:split) { + Map cacheMap =redisService.getCacheMap("gun:"+serialNumber); + if(cacheMap !=null && "空闲".equals(cacheMap.get("status"))){ + number++; + } + } + } + return number; + } + public static void main(String[] args) { //时间差 long betweenDay = DateUtil.between(DateUtil.parse("00:00:00"), DateUtil.parse("10:00:00"), DateUnit.SECOND); diff --git a/xhpc-modules/xhpc-charging-station/src/main/resources/mapper/XhpcChargingStationMapper.xml b/xhpc-modules/xhpc-charging-station/src/main/resources/mapper/XhpcChargingStationMapper.xml index 362c8261..af0d8796 100644 --- a/xhpc-modules/xhpc-charging-station/src/main/resources/mapper/XhpcChargingStationMapper.xml +++ b/xhpc-modules/xhpc-charging-station/src/main/resources/mapper/XhpcChargingStationMapper.xml @@ -255,6 +255,8 @@ cs.service_facilities as serviceFacilities, (select count(terminal_id) from xhpc_terminal where status=0 and del_flag =0 and charging_station_id=cs.charging_station_id) as common, + (select GROUP_CONCAT(serial_number) from xhpc_terminal where status=0 and del_flag =0 and + charging_station_id=cs.charging_station_id) as serialNumbers, (select (ra.power_fee+ra.service_fee) as serviceFee from xhpc_rate as ra where ra.status = 0 @@ -311,6 +313,7 @@ and del_flag = 0 and status = 0 limit 1) as type, (select count(terminal_id) from xhpc_terminal where status=0 and del_flag =0 and charging_station_id=charging_station_id) as common, + (select GROUP_CONCAT(serial_number) from xhpc_terminal where status=0 and del_flag =0 and charging_station_id=cs.charging_station_id) as serialNumbers, (select GROUP_CONCAT(dict_value) from xhpc_dict_biz where FIND_IN_SET(dict_key,service_facilities ) and code= 'service_facilities' and parent_id > 0 and del_flag = 0) as serviceFacilitiesName, name as name, reminder_instructions as reminderInstructions, diff --git a/xhpc-modules/xhpc-common/src/main/java/com/xhpc/common/dto/PileEndOrder.java b/xhpc-modules/xhpc-common/src/main/java/com/xhpc/common/dto/PileEndOrder.java new file mode 100644 index 00000000..e1c1beda --- /dev/null +++ b/xhpc-modules/xhpc-common/src/main/java/com/xhpc/common/dto/PileEndOrder.java @@ -0,0 +1,98 @@ +package com.xhpc.common.dto; + +/** + * 订单结束回调实体类 + */ +public class PileEndOrder { + + private String orderNo; //交易流水号 + private String startSoc; //充电启始soc + private String endSoc; //充电结束soc + private Integer status; //状态 (1 成功 2 异常) + private Integer chargingTime; //累计充电时间 + private Integer chargingDegree; //充电度数 + private Integer amountCharged; //已充金额 + private Integer erroRemark; //备注 + + + public String getOrderNo() { + + return orderNo; + } + + public void setOrderNo(String orderNo) { + + this.orderNo = orderNo; + } + + public String getStartSoc() { + + return startSoc; + } + + public void setStartSoc(String startSoc) { + + this.startSoc = startSoc; + } + + public String getEndSoc() { + + return endSoc; + } + + public void setEndSoc(String endSoc) { + + this.endSoc = endSoc; + } + + public Integer getStatus() { + + return status; + } + + public void setStatus(Integer status) { + + this.status = status; + } + + public Integer getChargingTime() { + + return chargingTime; + } + + public void setChargingTime(Integer chargingTime) { + + this.chargingTime = chargingTime; + } + + public Integer getChargingDegree() { + + return chargingDegree; + } + + public void setChargingDegree(Integer chargingDegree) { + + this.chargingDegree = chargingDegree; + } + + public Integer getErroRemark() { + + return erroRemark; + } + + public void setErroRemark(Integer erroRemark) { + + this.erroRemark = erroRemark; + } + + public Integer getAmountCharged() { + + return amountCharged; + } + + public void setAmountCharged(Integer amountCharged) { + + this.amountCharged = amountCharged; + } + +} diff --git a/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/controller/HxpcChargeOrderController.java b/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/api/HxpcChargeOrderController.java similarity index 67% rename from xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/controller/HxpcChargeOrderController.java rename to xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/api/HxpcChargeOrderController.java index cfb841f1..c66772b7 100644 --- a/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/controller/HxpcChargeOrderController.java +++ b/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/api/HxpcChargeOrderController.java @@ -1,9 +1,10 @@ -package com.xhpc.order.controller; +package com.xhpc.order.api; import com.xhpc.common.core.web.controller.BaseController; import com.xhpc.common.core.web.domain.AjaxResult; import com.xhpc.common.core.web.page.TableDataInfo; import com.xhpc.order.service.IHxpcChargeOrderService; +import com.xhpc.order.service.IXhpcHistoryOrderService; import io.swagger.annotations.Api; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; @@ -19,12 +20,15 @@ import java.util.Map; * @date 2021/8/4 9:59 */ @RestController -@RequestMapping("/chargeOrder") +@RequestMapping("/api/chargeOrder") @Api(value = "充电订单接口", tags = "充电订单接口") public class HxpcChargeOrderController extends BaseController { @Autowired private IHxpcChargeOrderService iHxpcChargeOrderService; + @Autowired + private IXhpcHistoryOrderService xhpcHistoryOrderService; + /** * 实时订单(微信) @@ -74,6 +78,31 @@ public class HxpcChargeOrderController extends BaseController { } + /** + * 用户历史订单列表接口 + */ + @GetMapping("/list") + public TableDataInfo list(@RequestParam Long userId) + { + startPage(); + List> list = xhpcHistoryOrderService.list(userId); + return getDataTable(list); + } + + + /** + * 用户订单详情接口 + * @param userId 用户id + * @param historyOrderId 历史订单id + * @param type 1 历史订单id 2 充电订单id (暂时没用) + * @param chargingOrderId 充电订单id + * @return + */ + @GetMapping("/gethistotyOrderMessage") + public AjaxResult gethistotyOrderMessage(@RequestParam Long userId,@RequestParam Long historyOrderId,Integer type,Long chargingOrderId) + { + return xhpcHistoryOrderService.gethistotyOrderMessage(userId,historyOrderId,type,chargingOrderId); + } } diff --git a/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/controller/HxpcPileOrderController.java b/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/api/HxpcPileOrderController.java similarity index 50% rename from xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/controller/HxpcPileOrderController.java rename to xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/api/HxpcPileOrderController.java index 7fafc71d..6382ca10 100644 --- a/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/controller/HxpcPileOrderController.java +++ b/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/api/HxpcPileOrderController.java @@ -1,7 +1,5 @@ -package com.xhpc.order.controller; +package com.xhpc.order.api; -import com.alibaba.fastjson.JSON; -import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.rabbitmq.client.Channel; import com.rabbitmq.client.Connection; @@ -9,11 +7,9 @@ import com.xhpc.common.api.PileOrderService; import com.xhpc.common.core.domain.R; import com.xhpc.common.core.web.controller.BaseController; import com.xhpc.common.core.web.domain.AjaxResult; -import com.xhpc.common.data.redis.CacheRealtimeData; import com.xhpc.common.redis.service.RedisService; import com.xhpc.common.util.ConnectionRabbitMQUtil; import com.xhpc.order.domain.HxpcChargeOrder; -import com.xhpc.order.domain.XhpcHistoryOrder; import com.xhpc.order.service.IHxpcChargeOrderService; import com.xhpc.order.service.IXhpcHistoryOrderService; import org.springframework.beans.factory.annotation.Autowired; @@ -45,7 +41,8 @@ public class HxpcPileOrderController extends BaseController { * 测试 */ @GetMapping("/test/chargeOrder/pileStartup") - private R test(@RequestParam String orderNo, @RequestParam Integer status, @RequestParam String remark){ + private R test(@RequestParam String orderNo, @RequestParam Integer status, @RequestParam String remark) { + R r = pileOrderService.pileStop(orderNo, status, remark); return r; } @@ -53,33 +50,34 @@ public class HxpcPileOrderController extends BaseController { /** * 桩启动回调接口 - * @param orderNo 订单号 - * @param status 1 成功 2失败 - * @param remark 备注 + * + * @param orderNo 订单号 + * @param status 1 成功 2失败 + * @param remark 备注 * @return */ @GetMapping("/chargeOrder/pileStartup") - public R pileStartup(String orderNo, Integer status, String remark){ + public R pileStartup(String orderNo, Integer status, String remark) { //解析订单编号 String s = orderNo.split("\\.")[0]; String s1 = s.split(":")[1]; Long userId; - Integer code ; - if(status ==1){ - code=200; - userId=update(0, 0,remark, s1,0); - }else{ - code=500; - userId=update(-1, 1,remark, s1,0); + Integer code; + if (status == 1) { + code = 200; + userId = update(0, 0, remark, s1, 0); + } else { + code = 500; + userId = update(-1, 1, remark, s1, 0); } - Map map =new HashMap<>(); - map.put("code",code); - map.put("userId",userId); - map.put("message",remark); + Map map = new HashMap<>(); + map.put("code", code); + map.put("userId", userId); + map.put("message", remark); JSONObject json = new JSONObject(map); //消息对了内容 - rabbimt(userId+"##"+json); - return R.ok(); + rabbimt(userId + "##" + json); + return R.ok(); } /** @@ -96,94 +94,122 @@ public class HxpcPileOrderController extends BaseController { String s = orderNo.split("\\.")[0]; String s1 = s.split(":")[1]; Integer code = 300; - Long userId = update(status, 0, remark, s1, 1); + Long userId = update(0, 0, remark, s1, 1); Map map = new HashMap<>(); map.put("code", code); map.put("userId", userId); if (status == 1) { map.put("message", "停止充电成功"); - }else{ - map.put("message",remark); + } else { + map.put("message", remark); } JSONObject json = new JSONObject(map); //消息对了内容 - rabbimt(userId+"##"+json); - return R.ok(); + rabbimt(userId + "##" + json); + return R.ok(); } /** * 桩实时数据回调接口 + * * @param orderNo 订单号 - * @param status 离线、故障、充电、空闲、计费错误(重新计算费用,电量默认为正确) - * @param remark 备注 + * @param status 离线、故障、充电、空闲、计费错误(重新计算费用,电量默认为正确) + * @param remark 备注 * @param rateModel 费率模型id * @return */ @GetMapping("/pileRealtime") - public AjaxResult pileRealtime(String orderNo, Integer status, String remark, String rateModel){ + public AjaxResult pileRealtime(String orderNo, Integer status, String remark, String rateModel) { + return AjaxResult.success(); } /** - * @param status 状态 - * @param delFlag 是否删除 - * @param remark 备注 - * @param serialNumber 订单号 - * @param type 结束订单状态 + * 桩订单结束回调 + * + * @param orderNo 订单号 + * @param status 状态 1正常 2异常 + * @param remark 备注 * @return */ - private Long update(Integer status,Integer delFlag, String remark, String serialNumber,Integer type) { + @GetMapping("/pileEndOrder") + public R pileEndOrder(String orderNo, Integer status, String remark) { + + //解析订单编号 + String s = orderNo.split("\\.")[0]; + String s1 = s.split(":")[1]; + + +// Date date = new Date(); +// //获取实时订单 +// Map cacheMap = redisService.getCacheMap("order:"+serialNumber); +// JSONArray st = (JSONArray)cacheMap.get("realtimeDataList"); +// System.out.println(st.toString()); +// CacheRealtimeData cacheRealtimeData = JSON.toJavaObject(st.getJSONObject(0), CacheRealtimeData.class); +// +// //用户第几次充电 +// int count = iHxpcChargeOrderService.getCount(userId); +// String state =""; +// String discount =""; +// if(count==0){ +// //活动折扣 +// Map promotion = iHxpcChargeOrderService.getPromotion(); +// if(promotion !=null){ +// //state 1.总金额 2.金额 3.服务费 discount 折扣率 +// state = promotion.get("state").toString(); +// discount = promotion.get("discount").toString(); +// } +// } +// +// //生成一条历史订单 +// XhpcHistoryOrder xhpcHistoryOrder =new XhpcHistoryOrder(); +// xhpcHistoryOrder.setChargeOrderId(hxpcChargeOrder.getChargeOrderId()); +// xhpcHistoryOrder.setChargingStationId(hxpcChargeOrder.getChargingStationId()); +// xhpcHistoryOrder.setUserId(userId); +// xhpcHistoryOrder.setTerminalId(hxpcChargeOrder.getTerminalId()); +// xhpcHistoryOrder.setSerialNumber(hxpcChargeOrder.getSerialNumber()); +// xhpcHistoryOrder.setStartSoc(hxpcChargeOrder.getStartSoc()); +// xhpcHistoryOrder.setReconciliationStatus(0); +// xhpcHistoryOrder.setSortingStatus(0); +// xhpcHistoryOrder.setType(1); +// xhpcHistoryOrder.setStatus(0); +// xhpcHistoryOrder.setDelFlag(0); +// xhpcHistoryOrder.setCreateTime(date); +// //订单总价---运维服务费抽成 +// //结束时soc +// xhpcHistoryOrderService.insert(xhpcHistoryOrder); +// +// //充电订单 --结束soc、充电时长、充电度数 +// hxpcChargeOrder.setEndTime(date); +// +// //实时数据存入MYsql、soc、电流、电压 + + + return R.ok(); + } + + + /** + * @param status 状态 + * @param delFlag 是否删除 + * @param remark 备注 + * @param serialNumber 订单号 + * @param type 结束订单状态 + * @return + */ + private Long update(Integer status, Integer delFlag, String remark, String serialNumber, Integer type) { + HxpcChargeOrder hxpcChargeOrder = iHxpcChargeOrderService.getSerialNumberMessage(serialNumber); hxpcChargeOrder.setStatus(status); hxpcChargeOrder.setDelFlag(delFlag); - hxpcChargeOrder.setRemark(remark); + hxpcChargeOrder.setErroRemark(remark); - Long userId = hxpcChargeOrder.getUserId(); - if(type==1){ + Long userId = hxpcChargeOrder.getUserId(); + if (type == 1) { Date date = new Date(); - //获取实时订单 - Map cacheMap = redisService.getCacheMap("order:"+serialNumber); - JSONArray st = (JSONArray)cacheMap.get("realtimeDataList"); - System.out.println(st.toString()); - CacheRealtimeData cacheRealtimeData = JSON.toJavaObject(st.getJSONObject(0), CacheRealtimeData.class); - - //用户第几次充电 - int count = iHxpcChargeOrderService.getCount(userId); - String state =""; - String discount =""; - if(count==0){ - //活动折扣 - Map promotion = iHxpcChargeOrderService.getPromotion(); - if(promotion !=null){ - //state 1.总金额 2.金额 3.服务费 discount 折扣率 - state = promotion.get("state").toString(); - discount = promotion.get("discount").toString(); - } - } - - //生成一条历史订单 - XhpcHistoryOrder xhpcHistoryOrder =new XhpcHistoryOrder(); - xhpcHistoryOrder.setChargeOrderId(hxpcChargeOrder.getChargeOrderId()); - xhpcHistoryOrder.setChargingStationId(hxpcChargeOrder.getChargingStationId()); - xhpcHistoryOrder.setUserId(userId); - xhpcHistoryOrder.setTerminalId(hxpcChargeOrder.getTerminalId()); - xhpcHistoryOrder.setSerialNumber(hxpcChargeOrder.getSerialNumber()); - xhpcHistoryOrder.setStartSoc(hxpcChargeOrder.getStartSoc()); - xhpcHistoryOrder.setReconciliationStatus(0); - xhpcHistoryOrder.setSortingStatus(0); - xhpcHistoryOrder.setType(1); - xhpcHistoryOrder.setStatus(0); - xhpcHistoryOrder.setDelFlag(0); - xhpcHistoryOrder.setCreateTime(date); - //订单总价---运维服务费抽成 - //结束时soc - xhpcHistoryOrderService.insert(xhpcHistoryOrder); - //充电订单 --结束soc、充电时长、充电度数 hxpcChargeOrder.setEndTime(date); - - //实时数据存入MYsql、soc、电流、电压 } iHxpcChargeOrderService.updateXhpcChargeOrder(hxpcChargeOrder); @@ -192,7 +218,7 @@ public class HxpcPileOrderController extends BaseController { private void rabbimt(String message) { //发送消息队列 - try{ + try { // 1、获取到连接 Connection connection = ConnectionRabbitMQUtil.getConnection(); // 2、从连接中创建通道,使用通道才能完成消息相关的操作 @@ -203,8 +229,9 @@ public class HxpcPileOrderController extends BaseController { channel.basicPublish("", "webSocket", null, message.getBytes()); channel.close(); connection.close(); - }catch (Exception e){ + } catch (Exception e) { } } + } diff --git a/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/controller/XhpcHistoryOrderController.java b/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/controller/XhpcHistoryOrderController.java index 15a810ed..d5e12d72 100644 --- a/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/controller/XhpcHistoryOrderController.java +++ b/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/controller/XhpcHistoryOrderController.java @@ -25,33 +25,6 @@ import java.util.Map; public class XhpcHistoryOrderController extends BaseController { - @Autowired - private IXhpcHistoryOrderService xhpcHistoryOrderService; - /** - * 用户历史订单接口 - */ - @GetMapping("/list") - public TableDataInfo list(@RequestParam Long userId) - { - startPage(); - List> list = xhpcHistoryOrderService.list(userId); - return getDataTable(list); - } - - - /** - * 用户订单详情接口 - * @param userId 用户id - * @param historyOrderId 历史订单id - * @param type 1 历史订单id 2 充电订单id (暂时没用) - * @param chargingOrderId 充电订单id - * @return - */ - @GetMapping("/gethistotyOrderMessage") - public AjaxResult gethistotyOrderMessage(@RequestParam Long userId,@RequestParam Long historyOrderId,Integer type,Long chargingOrderId) - { - return xhpcHistoryOrderService.gethistotyOrderMessage(userId,historyOrderId,type,chargingOrderId); - } diff --git a/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/domain/HxpcChargeOrder.java b/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/domain/HxpcChargeOrder.java index a89cc410..1450d0f0 100644 --- a/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/domain/HxpcChargeOrder.java +++ b/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/domain/HxpcChargeOrder.java @@ -88,6 +88,10 @@ public class HxpcChargeOrder extends BaseEntity { /** 0桩停止充电 1 远程停止充电 */ private Integer type; + /** 异常备注 */ + private String erroRemark; + + public Long getChargeOrderId() { return chargeOrderId; @@ -268,4 +272,14 @@ public class HxpcChargeOrder extends BaseEntity { this.type = type; } + public String getErroRemark() { + + return erroRemark; + } + + public void setErroRemark(String erroRemark) { + + this.erroRemark = erroRemark; + } + } diff --git a/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/mapper/HxpcChargeOrderMapper.java b/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/mapper/HxpcChargeOrderMapper.java index 7c7405af..9ebd435e 100644 --- a/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/mapper/HxpcChargeOrderMapper.java +++ b/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/mapper/HxpcChargeOrderMapper.java @@ -41,7 +41,7 @@ public interface HxpcChargeOrderMapper { /** * 判断用户是否在充电中 */ - int countXhpcRealTimeOrder(@Param("userId")Long userId); + String countXhpcRealTimeOrder(@Param("userId")Long userId); /** * 判断用户是否有异常订单未处理 @@ -87,5 +87,10 @@ public interface HxpcChargeOrderMapper { */ Map getPromotion(); - + /** + * 获取充电订单数据 + * @param chargingOrderId 订单id + * @return + */ + HxpcChargeOrder getChargingOrderId(@Param("chargingOrderId") Long chargingOrderId); } diff --git a/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/service/impl/HxpcChargeOrderServiceImpl.java b/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/service/impl/HxpcChargeOrderServiceImpl.java index 0c86f89a..8ef6ee6d 100644 --- a/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/service/impl/HxpcChargeOrderServiceImpl.java +++ b/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/service/impl/HxpcChargeOrderServiceImpl.java @@ -1,25 +1,17 @@ package com.xhpc.order.service.impl; import cn.hutool.core.date.DateUtil; -import com.alibaba.fastjson.JSON; -import com.alibaba.fastjson.JSONArray; -import com.alibaba.fastjson.JSONObject; -import com.rabbitmq.client.Channel; -import com.rabbitmq.client.Connection; import com.xhpc.common.api.PowerPileService; import com.xhpc.common.core.domain.R; import com.xhpc.common.core.web.domain.AjaxResult; import com.xhpc.common.data.down.StartChargingData; -import com.xhpc.common.data.redis.CacheRealtimeData; import com.xhpc.common.data.redis.SeqUtil; import com.xhpc.common.domain.XhpcTerminal; import com.xhpc.common.redis.service.RedisService; import com.xhpc.order.domain.HxpcChargeOrder; -import com.xhpc.order.domain.XhpcHistoryOrder; import com.xhpc.order.mapper.HxpcChargeOrderMapper; import com.xhpc.order.service.IHxpcChargeOrderService; import com.xhpc.order.service.IXhpcHistoryOrderService; -import com.xhpc.common.util.ConnectionRabbitMQUtil; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -27,7 +19,6 @@ import org.springframework.transaction.annotation.Transactional; import javax.annotation.PostConstruct; import java.math.BigDecimal; import java.util.Date; -import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.regex.Matcher; @@ -93,8 +84,9 @@ public class HxpcChargeOrderServiceImpl implements IHxpcChargeOrderService { return AjaxResult.error(1101, "你有申请退款订单在审核中,需要充电请取消申请退款"); } //是否在充电中 - int i = hxpcChargeOrderMapper.countXhpcRealTimeOrder(userId); - if (i > 0) { + String i = hxpcChargeOrderMapper.countXhpcRealTimeOrder(userId); + + if (!"".equals(i) && i!=null) { return AjaxResult.error(1102, "车辆正在充电,请查询车辆充电信息"); } //是否存在异常的订单 @@ -177,9 +169,9 @@ public class HxpcChargeOrderServiceImpl implements IHxpcChargeOrderService { if (xhpcTerminal == null || xhpcTerminal.getTerminalId() == null || xhpcTerminal.getChargingPileId() == null || xhpcTerminal.getPileSerialNumber() == null) { return AjaxResult.error(1104, "无效的终端编号"); } - //HxpcChargeOrder serialNumberMessage = hxpcChargeOrderMapper.getSerialNumberMessage(serialNumber); - //serialNumberMessage.setType(1); - //hxpcChargeOrderMapper.updateXhpcChargeOrder(serialNumberMessage); + HxpcChargeOrder serialNumberMessage = hxpcChargeOrderMapper.getChargingOrderId(chargingOrderId); + serialNumberMessage.setType(1); + hxpcChargeOrderMapper.updateXhpcChargeOrder(serialNumberMessage); R oa = powerPileService.stopCharging(xhpcTerminal.getPileSerialNumber(), xhpcTerminal.getSerialNumber(), "OA"); if(oa.getCode() !=200){ return AjaxResult.error(oa.getMsg()); diff --git a/xhpc-modules/xhpc-order/src/main/resources/mapper/XhpcChargeOrderMapper.xml b/xhpc-modules/xhpc-order/src/main/resources/mapper/XhpcChargeOrderMapper.xml index fec4f6bf..6f31cba6 100644 --- a/xhpc-modules/xhpc-order/src/main/resources/mapper/XhpcChargeOrderMapper.xml +++ b/xhpc-modules/xhpc-order/src/main/resources/mapper/XhpcChargeOrderMapper.xml @@ -86,8 +86,8 @@ from xhpc_app_user where del_flag=0 and app_user_id=#{userId} - + select charge_order_id as chargeOrderId from xhpc_charge_order where user_id =#{userId} and status=0 and del_flag =0 limit 1 select discount,state from xhpc_promotion where del_flag=0 and status=0 and type=0 and start_time <= now() and end_time >=now() order by update_time desc + + \ No newline at end of file diff --git a/xhpc-modules/xhpc-wxma/src/main/java/com/xhpc/wxma/config/ApplicationContextRegister.java b/xhpc-modules/xhpc-wxma/src/main/java/com/xhpc/wxma/config/ApplicationContextRegister.java new file mode 100644 index 00000000..8dcc4293 --- /dev/null +++ b/xhpc-modules/xhpc-wxma/src/main/java/com/xhpc/wxma/config/ApplicationContextRegister.java @@ -0,0 +1,26 @@ +package com.xhpc.wxma.config; + +import org.springframework.beans.BeansException; +import org.springframework.context.ApplicationContext; +import org.springframework.context.ApplicationContextAware; +import org.springframework.context.annotation.Lazy; +import org.springframework.stereotype.Component; + +@Component +@Lazy(false) +public class ApplicationContextRegister implements ApplicationContextAware { + + private static ApplicationContext APPLICATION_CONTEXT; + + /** + * 设置spring上下文 * * @param applicationContext spring上下文 * @throws BeansException + */ + @Override + public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { + APPLICATION_CONTEXT = applicationContext; + } + + public static ApplicationContext getApplicationContext() { + return APPLICATION_CONTEXT; + } +}