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 index aa10608b..eb41f30d 100644 --- 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 @@ -51,7 +51,7 @@ public class XhpcChargingStationApiController extends BaseController { * @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) { + public AjaxResult getWXXhpcChargingStationMessage(@RequestParam(value = "chargingStationId") Long chargingStationId, @RequestParam(value = "longitude") String longitude, @RequestParam(value = "latitude") String latitude) { return AjaxResult.success(xhpcChargingStationService.getWXXhpcChargingStationMessage(chargingStationId, longitude, latitude)); } 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 169d3996..04c2fcb9 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 @@ -655,6 +655,8 @@ public class XhpcChargingStationServiceImpl implements IXhpcChargingStationServi map.put("status", 3); if(cacheMap.get("status")!=null){ map.put("soc", cacheMap.get("status").toString()+"%"); + }else{ + map.put("soc", "0%"); } if(cacheMap.get("remainingTime")!=null){ int number = (int)cacheMap.get("remainingTime"); 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 af0d8796..a085c76e 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 @@ -313,7 +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(serial_number) from xhpc_terminal where status=0 and del_flag =0 and charging_station_id=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/api/PileOrderService.java b/xhpc-modules/xhpc-common/src/main/java/com/xhpc/common/api/PileOrderService.java index a7ca1a4f..60ffc99b 100644 --- a/xhpc-modules/xhpc-common/src/main/java/com/xhpc/common/api/PileOrderService.java +++ b/xhpc-modules/xhpc-common/src/main/java/com/xhpc/common/api/PileOrderService.java @@ -23,7 +23,7 @@ public interface PileOrderService { * @return */ @GetMapping("/chargeOrder/pileStartup") - R pileStartup(@RequestParam("orderNo") String orderNo, @RequestParam("status") Integer status, @RequestParam("remark") String remark); + R pileStartup(@RequestParam(value = "orderNo") String orderNo, @RequestParam(value = "status") Integer status, @RequestParam(value = "remark") String remark); /** * 桩停止回调接口 @@ -34,6 +34,6 @@ public interface PileOrderService { * @return */ @GetMapping("/chargeOrder/pileStop") - R pileStop(@RequestParam("orderNo") String orderNo, @RequestParam("status") Integer status, @RequestParam("remark") String remark); + R pileStop(@RequestParam(value = "orderNo") String orderNo, @RequestParam(value = "status") Integer status, @RequestParam(value = "remark") String remark); } 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 index 6236f970..dd3b10f9 100644 --- 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 @@ -11,7 +11,9 @@ public class PileEndOrder { private Integer status; //状态 (1 成功 2 异常) private Integer chargingTime; //累计充电时间 private Integer chargingDegree; //充电度数 - private Integer amountCharged; //已充金额 + private String amountCharged; //已充金额(分) + private String powerPrice;//电费(分) + private String servicePrice;//服务费(分) private String erroRemark; //备注 @@ -85,14 +87,34 @@ public class PileEndOrder { this.erroRemark = erroRemark; } - public Integer getAmountCharged() { + public String getAmountCharged() { return amountCharged; } - public void setAmountCharged(Integer amountCharged) { + public void setAmountCharged(String amountCharged) { this.amountCharged = amountCharged; } + public String getPowerPrice() { + + return powerPrice; + } + + public void setPowerPrice(String powerPrice) { + + this.powerPrice = powerPrice; + } + + public String getServicePrice() { + + return servicePrice; + } + + public void setServicePrice(String servicePrice) { + + this.servicePrice = servicePrice; + } + } diff --git a/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/api/HxpcPileOrderController.java b/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/api/HxpcPileOrderController.java index 509c9188..fa229310 100644 --- a/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/api/HxpcPileOrderController.java +++ b/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/api/HxpcPileOrderController.java @@ -11,15 +11,17 @@ import com.xhpc.common.dto.PileEndOrder; 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; -import org.springframework.validation.annotation.Validated; +import org.springframework.transaction.annotation.Transactional; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; +import java.math.BigDecimal; import java.util.Date; import java.util.HashMap; import java.util.Map; @@ -40,6 +42,8 @@ public class HxpcPileOrderController extends BaseController { private PileOrderService pileOrderService; + + /** * 测试 */ @@ -60,7 +64,7 @@ public class HxpcPileOrderController extends BaseController { * @return */ @GetMapping("/chargeOrder/pileStartup") - public R pileStartup(String orderNo, Integer status, String remark) { + public R pileStartup(@RequestParam(value = "orderNo")String orderNo, @RequestParam(value = "status")Integer status,@RequestParam(value = "remark") String remark) { //解析订单编号 String s = orderNo.split("\\.")[0]; String s1 = s.split(":")[1]; @@ -92,7 +96,7 @@ public class HxpcPileOrderController extends BaseController { * @return */ @GetMapping("/chargeOrder/pileStop") - public R pileStop(String orderNo, Integer status, String remark) { + public R pileStop(@RequestParam(value = "orderNo")String orderNo, @RequestParam(value = "status")Integer status,@RequestParam(value = "remark") String remark) { //解析订单编号 String s = orderNo.split("\\.")[0]; String s1 = s.split(":")[1]; @@ -132,6 +136,7 @@ public class HxpcPileOrderController extends BaseController { * 桩订单结束回调 * */ + @Transactional @GetMapping("/pileEndOrder") public R pileEndOrder(@RequestBody PileEndOrder pileEndOrder) { @@ -148,62 +153,96 @@ public class HxpcPileOrderController extends BaseController { hxpcChargeOrder.setEndTime(date); hxpcChargeOrder.setChargingTime(pileEndOrder.getChargingTime().toString()); hxpcChargeOrder.setChargingDegree(pileEndOrder.getChargingDegree().toString()); - hxpcChargeOrder.setAmountCharged(pileEndOrder.getAmountCharged().toString()); + hxpcChargeOrder.setAmountCharged(pileEndOrder.getAmountCharged()); hxpcChargeOrder.setErroRemark(pileEndOrder.getErroRemark()); - hxpcChargeOrderService.updateXhpcChargeOrder(hxpcChargeOrder); //历史订单 + Long userId =hxpcChargeOrder.getUserId(); + //生成一条历史订单 + XhpcHistoryOrder xhpcHistoryOrder =new XhpcHistoryOrder(); + + + + Map userMessage = hxpcChargeOrderService.getUserMessage(userId); + if(userMessage ==null || userMessage.get("balance") ==null){ + //订单异常 + hxpcChargeOrder.setStatus(2); + //异常原因 + hxpcChargeOrder.setErroRemark("桩异常:"+pileEndOrder.getErroRemark()+">>>>用户id:"+userId+"为空"); + } + BigDecimal balance = new BigDecimal(userMessage.get("balance").toString()); + //总金额 + BigDecimal money = new BigDecimal(pileEndOrder.getAmountCharged()); + //总电费 + BigDecimal powerPrice = new BigDecimal(pileEndOrder.getPowerPrice()); + //总服务费 + BigDecimal servicePrice = new BigDecimal(pileEndOrder.getServicePrice()); + + //电站活动抵扣--抵扣的总金额 + BigDecimal promotionDiscount = new BigDecimal(0); + //实际价格-用户支付的钱 + BigDecimal actPrice =new BigDecimal(0); -// 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、电流、电压 + + String state =""; + BigDecimal discount =new BigDecimal(0); + //判断是C端用户还是流量端用户 + if(hxpcChargeOrder.getSource() ==0){ + //用户第几次充电 + int count = hxpcChargeOrderService.getCount(userId); + if(count==0){ + //活动折扣 + Map promotion = hxpcChargeOrderService.getPromotion(); + if(promotion !=null){ + //state 1.总金额 2.电费 3.服务费 discount 折扣率 + state = promotion.get("state").toString(); + discount = (BigDecimal)promotion.get("discount"); + } + } + if(!"".equals(state)){ + //没有活动 + if("1".equals(state)){ + promotionDiscount=money.multiply(balance); + actPrice = money.subtract(promotionDiscount); + }else if("2".equals(state)){ + + } + } + } + + + + + + + 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); + // hxpcChargeOrderService.updateXhpcChargeOrder(hxpcChargeOrder); return R.ok(); } 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 8da44917..32fb50d3 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 @@ -72,4 +72,11 @@ public interface IHxpcChargeOrderService { * @return */ int updateXhpcChargeOrder(HxpcChargeOrder hxpcChargeOrder); + + /** + * appUserId 查询用户信息 + * @param userId + * @return + */ + Map getUserMessage(Long userId); } 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 8ef6ee6d..1f6190c6 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 @@ -117,7 +117,7 @@ public class HxpcChargeOrderServiceImpl implements IHxpcChargeOrderService { return AjaxResult.error(1104, "无效的终端编号"); } //余额 - String balance = userMessage.get("balance").toString(); + String balance = new BigDecimal(userMessage.get("balance").toString()).multiply(new BigDecimal(100)).toString(); //启动充电 StartChargingData startChargingData = new StartChargingData(); //订单流水号 终端号+年月日时分秒+自增4位 共32位 @@ -127,8 +127,11 @@ public class HxpcChargeOrderServiceImpl implements IHxpcChargeOrderService { String orderNo = serialNumber + format + SeqUtil.seqDec("gun:" + serialNumber + ".seqdec"); startChargingData.setOrderNo(orderNo); + if(userMessage.get("phone") !=null){ + startChargingData.setTel(userMessage.get("phone").toString()); + } startChargingData.setPileNo(xhpcTerminal.getPileSerialNumber()); - startChargingData.setGunId(xhpcTerminal.getSerialNumber()); + startChargingData.setGunId(xhpcTerminal.getSerialNumber().substring(14)); startChargingData.setBalance(Double.valueOf(balance).intValue()); startChargingData.setVersion("0A"); R r1 = powerPileService.startCharging(startChargingData); @@ -199,4 +202,9 @@ public class HxpcChargeOrderServiceImpl implements IHxpcChargeOrderService { return hxpcChargeOrderMapper.updateXhpcChargeOrder(hxpcChargeOrder); } + @Override + public Map getUserMessage(Long userId){ + return hxpcChargeOrderMapper.getUserMessage(userId); + } + } 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 edf55a42..fd6ba5b2 100644 --- a/xhpc-modules/xhpc-order/src/main/resources/mapper/XhpcChargeOrderMapper.xml +++ b/xhpc-modules/xhpc-order/src/main/resources/mapper/XhpcChargeOrderMapper.xml @@ -84,6 +84,7 @@ select app_user_id as appUserId, balance as balance, + phone as phone, is_refund_application as isRefundApplication from xhpc_app_user where del_flag=0 and app_user_id=#{userId}