From ad7df151e108ac0ed76f232baf89747747fa46d4 Mon Sep 17 00:00:00 2001 From: yuyang <2265829957@qq.com> Date: Thu, 5 Aug 2021 16:17:04 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=9C=BA=E7=AB=99=E4=BF=A1?= =?UTF-8?q?=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mapper/XhpcChargingPileMapper.java | 8 ++ .../service/XhpcChargingPileServiceImpl.java | 28 ++++++- .../service/XhpcTerminalServiceImpl.java | 21 +++--- .../mapper/XhpcChargingPileMapper.xml | 5 ++ .../mapper/XhpcChargingStationMapper.xml | 15 +++- .../com/xhpc/common/data/redis/SeqUtil.java | 2 +- .../xhpc/{order => }/OrderApplication.java | 2 +- .../controller/HxpcChargeOrderController.java | 18 +++++ .../order/mapper/HxpcChargeOrderMapper.java | 32 +++++++- .../service/IHxpcChargeOrderService.java | 13 ++++ .../impl/HxpcChargeOrderServiceImpl.java | 73 +++++++++++++++++++ .../mapper/XhpcChargeOrderMapper.xml | 47 ++++++++++++ 12 files changed, 247 insertions(+), 17 deletions(-) rename xhpc-modules/xhpc-order/src/main/java/com/xhpc/{order => }/OrderApplication.java (98%) diff --git a/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/mapper/XhpcChargingPileMapper.java b/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/mapper/XhpcChargingPileMapper.java index 5effd2ad..d649ae9d 100644 --- a/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/mapper/XhpcChargingPileMapper.java +++ b/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/mapper/XhpcChargingPileMapper.java @@ -76,4 +76,12 @@ public interface XhpcChargingPileMapper { * @return */ int getXhpcChargingPileSerialNumberCount(@Param("serialNumber")String serialNumber); + + /** + * 删除终端 + * @param chargingPileId + * @return + */ + int updateXhpcTerminal(@Param("chargingPileId")Long chargingPileId); + } diff --git a/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/service/XhpcChargingPileServiceImpl.java b/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/service/XhpcChargingPileServiceImpl.java index 78987430..640021fb 100644 --- a/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/service/XhpcChargingPileServiceImpl.java +++ b/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/service/XhpcChargingPileServiceImpl.java @@ -1,6 +1,5 @@ package com.xhpc.charging.station.service; -import com.xhpc.common.api.dto.ChargingPileDto; import com.xhpc.common.core.web.domain.AjaxResult; import com.xhpc.common.domain.XhpcChargingPile; import com.xhpc.common.domain.XhpcTerminal; @@ -68,7 +67,8 @@ public class XhpcChargingPileServiceImpl implements IXhpcChargingPileService{ xhpcTerminal.setChargingStationId(chargingStationId); xhpcTerminal.setChargingPileId(chargingPileId); xhpcTerminal.setName(serialNumber + "-" + (i)); - xhpcTerminal.setPileSerialNumber(serialNumber+ "0" + i); + xhpcTerminal.setSerialNumber(serialNumber+ "0" + i); + xhpcTerminal.setPileSerialNumber(serialNumber); xhpcTerminal.setWorkStatus(2); xhpcTerminal.setStatus(0); xhpcTerminalMapper.addXhpcTerminal(xhpcTerminal); @@ -96,6 +96,30 @@ public class XhpcChargingPileServiceImpl implements IXhpcChargingPileService{ return AjaxResult.error("桩编号不能编辑"); } + if(!xhpcChargingPile.getGunNumber().equals(xhpc.getGunNumber())){ + //删除之前的终端 + xhpcChargingPileMapper.updateXhpcTerminal(chargingPileId); + + String serialNumber = xhpcChargingPile.getSerialNumber(); + Long chargingStationId = xhpcChargingPile.getChargingStationId(); + if(xhpcChargingPile.getGunNumber()>0){ + for (int i = 0; i < xhpcChargingPile.getGunNumber(); i++) { + XhpcTerminal xhpcTerminal =new XhpcTerminal(); + xhpcTerminal.setChargingStationId(chargingStationId); + xhpcTerminal.setChargingPileId(chargingPileId); + xhpcTerminal.setName(serialNumber + "-" + (i)); + xhpcTerminal.setSerialNumber(serialNumber+ "0" + i); + xhpcTerminal.setPileSerialNumber(serialNumber); + xhpcTerminal.setWorkStatus(2); + xhpcTerminal.setStatus(0); + xhpcTerminalMapper.addXhpcTerminal(xhpcTerminal); + } + } + //插入redis 桩的编号 + HashSet noSet = new HashSet<>(); + noSet.add(serialNumber); + powerPileService.addPileWhitelist(chargingStationId, noSet); + } xhpcChargingPileMapper.updaeXhpcChargingPile(xhpcChargingPile); return AjaxResult.success(); } diff --git a/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/service/XhpcTerminalServiceImpl.java b/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/service/XhpcTerminalServiceImpl.java index ed067d2c..ac4e8814 100644 --- a/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/service/XhpcTerminalServiceImpl.java +++ b/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/service/XhpcTerminalServiceImpl.java @@ -66,16 +66,19 @@ public class XhpcTerminalServiceImpl implements IXhpcTerminalService{ public AjaxResult selectXhpcTerminalPileMessage(Long terminalId) { Map map = xhpcTerminalMapper.selectXhpcTerminalPileMessage(terminalId); - Long chargingStationId =Long.parseLong(map.get("chargingStationId").toString()); - String gunNumber = map.get("serialNumber").toString(); - //费率时段,先反设置时段,在反默认时段 - List> xhpcRateTimeTypeList = xhpcTerminalMapper.getXhpcRateTimeTypeList(chargingStationId, 1); - xhpcRateTimeTypeList.addAll(xhpcTerminalMapper.getXhpcRateTimeTypeList(chargingStationId, 2)); - map.put("rateTimeList",xhpcRateTimeTypeList); + if(map !=null && map.get("chargingStationId") !=null && map.get("serialNumber") !=null){ + Long chargingStationId =Long.parseLong(map.get("chargingStationId").toString()); + String gunNumber = map.get("serialNumber").toString(); + //费率时段,先反设置时段,在反默认时段 + List> xhpcRateTimeTypeList = xhpcTerminalMapper.getXhpcRateTimeTypeList(chargingStationId, 1); + xhpcRateTimeTypeList.addAll(xhpcTerminalMapper.getXhpcRateTimeTypeList(chargingStationId, 2)); + map.put("rateTimeList",xhpcRateTimeTypeList); - //统计终端(充redis获取终端信息) - map.putAll(xhpcTerminalMapper.getXhpcRateTimeOrderStatistics(chargingStationId,gunNumber)); - return AjaxResult.success(map); + //统计终端(充redis获取终端信息) + map.putAll(xhpcTerminalMapper.getXhpcRateTimeOrderStatistics(chargingStationId,gunNumber)); + return AjaxResult.success(map); + } + return AjaxResult.error("无效终端"); } @Override diff --git a/xhpc-modules/xhpc-charging-station/src/main/resources/mapper/XhpcChargingPileMapper.xml b/xhpc-modules/xhpc-charging-station/src/main/resources/mapper/XhpcChargingPileMapper.xml index db5ebfd9..6ae20f93 100644 --- a/xhpc-modules/xhpc-charging-station/src/main/resources/mapper/XhpcChargingPileMapper.xml +++ b/xhpc-modules/xhpc-charging-station/src/main/resources/mapper/XhpcChargingPileMapper.xml @@ -41,6 +41,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" select cp.charging_pile_id as chargingPileId, cp.charging_station_id as chargingStationId, + cp.name as chargingPileName, st.name as chargingStationName, cp.serial_number as serialNumber, cp.brand_model as brandModel, @@ -311,4 +312,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + + + update xhpc_terminal set del_flag = 2 where charging_pile_id = #{chargingPileId} + 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 a86e1b77..db5817e4 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 @@ -195,6 +195,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" ct.parking_instructions as parkingInstructions, ct.business_instructions as businessInstructions, ct.reminder_instructions as reminderInstructions, + ct.client_visible as clientVisible, ct.img_id as imgId from xhpc_charging_station as ct left join xhpc_operator as op on op.operator_id = ct.operator_id @@ -429,7 +430,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" update_by, - remark + remark, + + + station_type @@ -506,7 +510,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" #{updateBy}, - #{remark} + #{remark}, + + + #{stationType} @@ -707,7 +714,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" replace(rt.end_time,'00:00:00','24:00:00') AS endTime, rt.rate_id as rateId, rt.rate_value as id, - ra.name as rateName + ra.name as rateName, + ra.power_fee as powerFee, + ra.service_fee as serviceFee from xhpc_rate_time as rt left join xhpc_rate as ra on ra.rate_id =rt.rate_id where rt.charging_station_id=#{chargingStationId} and rt.del_flag =0 and rt.type=1 diff --git a/xhpc-modules/xhpc-common/src/main/java/com/xhpc/common/data/redis/SeqUtil.java b/xhpc-modules/xhpc-common/src/main/java/com/xhpc/common/data/redis/SeqUtil.java index 82afa9a9..99c0c3b8 100644 --- a/xhpc-modules/xhpc-common/src/main/java/com/xhpc/common/data/redis/SeqUtil.java +++ b/xhpc-modules/xhpc-common/src/main/java/com/xhpc/common/data/redis/SeqUtil.java @@ -33,7 +33,7 @@ public class SeqUtil { return upperCode; } - public synchronized static String seqDec(String key, int len) { + public synchronized static String seqDec(String key) { String upperCode = ""; RedisAtomicLong counter = new RedisAtomicLong(key, REDIS.redisTemplate.getConnectionFactory()); diff --git a/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/OrderApplication.java b/xhpc-modules/xhpc-order/src/main/java/com/xhpc/OrderApplication.java similarity index 98% rename from xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/OrderApplication.java rename to xhpc-modules/xhpc-order/src/main/java/com/xhpc/OrderApplication.java index df870d56..694a6877 100644 --- a/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/OrderApplication.java +++ b/xhpc-modules/xhpc-order/src/main/java/com/xhpc/OrderApplication.java @@ -1,4 +1,4 @@ -package com.xhpc.order; +package com.xhpc; import com.xhpc.common.security.annotation.EnableCustomConfig; import com.xhpc.common.security.annotation.EnableRyFeignClients; 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/controller/HxpcChargeOrderController.java index 35fb33e4..b84fd5db 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/controller/HxpcChargeOrderController.java @@ -31,6 +31,24 @@ public class HxpcChargeOrderController extends BaseController { return iHxpcChargeOrderService.getHistotyChargeOrderMessage(userId); } + /** + * 异常订单 + */ + @GetMapping("/getHistotyChargeOrderStatusList") + public AjaxResult getHistotyChargeOrderStatusList(@RequestParam Long userId) + { + return iHxpcChargeOrderService.getHistotyChargeOrderStatusList(userId); + } + + + /** + * 启动充电 + */ + @GetMapping("/startUp") + public AjaxResult startUp(@RequestParam Long userId,@RequestParam String serialNumber){ + return iHxpcChargeOrderService.startUp(userId, serialNumber); + } + } 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 b529b306..ba038dbe 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 @@ -1,8 +1,9 @@ package com.xhpc.order.mapper; -import com.xhpc.common.core.web.domain.AjaxResult; +import com.xhpc.common.domain.XhpcTerminal; import org.apache.ibatis.annotations.Param; +import java.util.List; import java.util.Map; /** @@ -17,4 +18,33 @@ public interface HxpcChargeOrderMapper { * @return */ Map getHistotyChargeOrderMessage(@Param("userId") Long userId); + + /** + * 异常订单 + * @param userId + * @return + */ + List> getHistotyChargeOrderStatusList(@Param("userId")Long userId); + + + /** + * 获取用户信息 + */ + Map getUserMessage(@Param("userId")Long userId); + + + /** + * 判断用户是否在充电中 + */ + int countXhpcRealTimeOrder(@Param("userId")Long userId); + + /** + * 判断用户是否有异常订单未处理 + */ + int countXhpcChargeOrder(@Param("userId")Long userId); + + /** + * 获取终端信息 + */ + XhpcTerminal getXhpcTerminalSerialNumber(@Param("serialNumber")String serialNumber); } diff --git a/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/service/IHxpcChargeOrderService.java b/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/service/IHxpcChargeOrderService.java index 39505c29..f54c703e 100644 --- a/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/service/IHxpcChargeOrderService.java +++ b/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/service/IHxpcChargeOrderService.java @@ -15,4 +15,17 @@ public interface IHxpcChargeOrderService { */ AjaxResult getHistotyChargeOrderMessage(Long userId); + /** + * 异常订单 + * @param userId + * @return + */ + AjaxResult getHistotyChargeOrderStatusList(Long userId); + + /** + * 启动充电 + * @param userId + * @return + */ + AjaxResult startUp(Long userId,String serialNumber); } 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 22918534..a9fa79b9 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,11 +1,20 @@ package com.xhpc.order.service.impl; +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.SeqUtil; +import com.xhpc.common.domain.XhpcTerminal; +import com.xhpc.order.domain.HxpcChargeOrder; import com.xhpc.order.mapper.HxpcChargeOrderMapper; import com.xhpc.order.service.IHxpcChargeOrderService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import java.math.BigDecimal; +import java.util.Map; + /** * @author yuyang * @date 2021/8/4 9:54 @@ -15,6 +24,8 @@ public class HxpcChargeOrderServiceImpl implements IHxpcChargeOrderService { @Autowired private HxpcChargeOrderMapper hxpcChargeOrderMapper; + @Autowired + private PowerPileService powerPileService; @Override public AjaxResult getHistotyChargeOrderMessage(Long userId) { @@ -22,4 +33,66 @@ public class HxpcChargeOrderServiceImpl implements IHxpcChargeOrderService { return AjaxResult.success(hxpcChargeOrderMapper.getHistotyChargeOrderMessage(userId)); } + @Override + public AjaxResult getHistotyChargeOrderStatusList(Long userId) { + + return null; + } + + @Override + public AjaxResult startUp(Long userId,String serialNumber) { + + //金额是否大于5元 + Map userMessage = hxpcChargeOrderMapper.getUserMessage(userId); + BigDecimal a = new BigDecimal(5); + if(userMessage ==null || userMessage.get("balance") ==null|| a.compareTo(new BigDecimal(userMessage.get("balance").toString())) == 1){ + return AjaxResult.error(1100,"金额小于5元,不能充电,请充值后再进行充电"); + } + //是否有申请退款的订单,还未处理 + if( Integer.parseInt(userMessage.get("isRefundApplication").toString())!=0){ + return AjaxResult.error(1101,"你有申请退款订单在审核中,需要充电请取消申请退款"); + } + //是否在充电中 + int i = hxpcChargeOrderMapper.countXhpcRealTimeOrder(userId); + if(i>0){ + return AjaxResult.error(1102,"车辆正在充电,请查询车辆充电信息"); + } + //是否存在异常的订单 + int j = hxpcChargeOrderMapper.countXhpcChargeOrder(userId); + if(j>0){ + return AjaxResult.error(1103,"你有异常订单未解决,请拨打客服电话进行解决"); + } + //终端状态是否空闲 + //是否插枪 + System.out.println("<>"+powerPileService.terminalStatus(serialNumber)); + //终端信息 + XhpcTerminal xhpcTerminal = hxpcChargeOrderMapper.getXhpcTerminalSerialNumber(serialNumber); + if(xhpcTerminal ==null || xhpcTerminal.getTerminalId()==null|| xhpcTerminal.getChargingPileId() ==null || xhpcTerminal.getPileSerialNumber()==null){ + return AjaxResult.error(1104,"无效的终端编号"); + } + //余额 + BigDecimal balance1 = new BigDecimal(userMessage.get("balance").toString()).multiply(new BigDecimal(100)); + //启动充电 + StartChargingData startChargingData =new StartChargingData(); + //订单流水号 + startChargingData.setOrderNo(SeqUtil.seqDec("gun:" + serialNumber + ".seqdec")); + startChargingData.setPileNo(xhpcTerminal.getPileSerialNumber()); + startChargingData.setGunId(xhpcTerminal.getSerialNumber()); + startChargingData.setBalance(Integer.valueOf(balance1.toString())); + startChargingData.setVersion("0A"); + //R r = powerPileService.startCharging(startChargingData); + + + + //创建充电订单 + HxpcChargeOrder hxpcChargeOrder =new HxpcChargeOrder(); + + + + + + + return null; + } + } 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 597fcb6e..39ca1e76 100644 --- a/xhpc-modules/xhpc-order/src/main/resources/mapper/XhpcChargeOrderMapper.xml +++ b/xhpc-modules/xhpc-order/src/main/resources/mapper/XhpcChargeOrderMapper.xml @@ -23,6 +23,23 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file