diff --git a/evcs-modules/evcs-core/src/main/java/com/xhpc/evcs/api/QueryEquipChargeStatusController.java b/evcs-modules/evcs-core/src/main/java/com/xhpc/evcs/api/QueryEquipChargeStatusController.java index 18550cb6..bfeac2ce 100644 --- a/evcs-modules/evcs-core/src/main/java/com/xhpc/evcs/api/QueryEquipChargeStatusController.java +++ b/evcs-modules/evcs-core/src/main/java/com/xhpc/evcs/api/QueryEquipChargeStatusController.java @@ -8,11 +8,10 @@ import com.xhpc.evcs.dto.CommonRequest; import com.xhpc.evcs.dto.CommonResponse; import com.xhpc.evcs.dto.EquipChargeStatus; import com.xhpc.evcs.encryption.EvcsConst; -import com.xhpc.evcs.http.ServerInternalException; import com.xhpc.evcs.jpa.OrderMappingRepository; import com.xhpc.evcs.jpa.XhpcHistoryOrderRepository; import com.xhpc.evcs.utils.JSONUtil; -import com.xhpc.pp.utils.HexUtils; +import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; @@ -25,6 +24,7 @@ import static com.xhpc.common.data.redis.StaticBeanUtil.REDIS; import static com.xhpc.evcs.notification.NotificationEquipChargeStatusTask.calculateEm; import static com.xhpc.evcs.utils.DateUtil.orderNo2DateStr; +@Slf4j @RestController() public class QueryEquipChargeStatusController { @@ -42,10 +42,14 @@ public class QueryEquipChargeStatusController { ChargeInfoRequest chargeInfoRequest = JSONUtil.readParams(data, ChargeInfoRequest.class); String startChargeSeq = chargeInfoRequest.getStartChargeSeq(); equipChargeStatus.setStartChargeSeq(startChargeSeq); + CommonResponse response = new CommonResponse(); //充电订单状态 EtOrderMapping etOrderMapping = orderMappingRepository.findByEvcsOrderNo(startChargeSeq).orElse(null); if (etOrderMapping == null) { - throw new ServerInternalException("未查询到该订单编号数据"); + response.setRet(EvcsConst.RET_FAIL); + response.setMsg("Order not found/started"); + log.error("3rdpty order[{}] not found", startChargeSeq); + return response; } String internalOrderNum = etOrderMapping.getXhOrderNo(); Map cacheOrder = REDIS.getCacheMap("order:" + internalOrderNum); @@ -94,13 +98,11 @@ public class QueryEquipChargeStatusController { } equipChargeStatus.setConnectorStatus(connectorStatus); //A相电流 - String current = (String) cacheGunData.get("current"); - Double currentA = HexUtils.reverseHexInt(current) / 10.0; - equipChargeStatus.setCurrentA(currentA); + Double current = (Double) cacheGunData.get("current"); + equipChargeStatus.setCurrentA(current); //A相电压 - String voltage = (String) cacheGunData.get("voltage"); - Double voltageA = HexUtils.reverseHexInt(voltage) / 10.0; - equipChargeStatus.setVoltageA(voltageA); + Double voltage = (Double) cacheGunData.get("voltage"); + equipChargeStatus.setVoltageA(voltage); //电池剩余电量 Integer endSoc = (Integer) cacheOrder.get("endSoc"); Double soc = Double.valueOf(endSoc == null ? 0 : endSoc); @@ -125,7 +127,6 @@ public class QueryEquipChargeStatusController { final Long rateModelId = REDIS.getCacheMapValue("pile:".concat(connectorId.substring(0, 14)), "rateModelId"); final CacheRateModel cacheRateModel = REDIS.getCacheObject("rateModel:" + rateModelId); calculateEm(equipChargeStatus, cacheRateModel); - CommonResponse response = new CommonResponse(); response.setRet(EvcsConst.RET_SUCC); response.setData(JSONUtil.toJSONString(equipChargeStatus)); response.setMsg("success"); diff --git a/evcs-modules/evcs-core/src/main/java/com/xhpc/evcs/api/QueryStartChargeController.java b/evcs-modules/evcs-core/src/main/java/com/xhpc/evcs/api/QueryStartChargeController.java index 047c60aa..97692174 100644 --- a/evcs-modules/evcs-core/src/main/java/com/xhpc/evcs/api/QueryStartChargeController.java +++ b/evcs-modules/evcs-core/src/main/java/com/xhpc/evcs/api/QueryStartChargeController.java @@ -2,7 +2,7 @@ package com.xhpc.evcs.api; import com.xhpc.common.api.PileOrderService; import com.xhpc.common.core.domain.R; -import com.xhpc.evcs.domain.AuthSecretToken; +import com.xhpc.common.core.utils.DateUtils; import com.xhpc.evcs.domain.EtOrderMapping; import com.xhpc.evcs.dto.CommonRequest; import com.xhpc.evcs.dto.CommonResponse; @@ -11,17 +11,21 @@ import com.xhpc.evcs.dto.StartChargeResponse; import com.xhpc.evcs.encryption.EvcsConst; import com.xhpc.evcs.jpa.AuthSecretTokenRepository; import com.xhpc.evcs.jpa.OrderMappingRepository; +import com.xhpc.evcs.jpa.XhpcHistoryOrderRepository; +import com.xhpc.evcs.jpa.XhpcTerminalRepository; import com.xhpc.evcs.utils.JSONUtil; +import com.xhpc.order.domain.XhpcHistoryOrder; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RestController; +import java.util.Date; import java.util.HashMap; import java.util.Map; -import java.util.Optional; import static com.xhpc.common.data.redis.StaticBeanUtil.REDIS; +import static com.xhpc.common.data.redis.StaticBeanUtil.genOrder; @RestController public class QueryStartChargeController { @@ -31,6 +35,10 @@ public class QueryStartChargeController { @Autowired private OrderMappingRepository etOrderMappingRepo; @Autowired + private XhpcHistoryOrderRepository xhpcHistoryOrderRepository; + @Autowired + private XhpcTerminalRepository xhpcTerminalRepository; + @Autowired private PileOrderService pileOrderService; @PostMapping(value = "/v1/query_start_charge") @@ -40,73 +48,82 @@ public class QueryStartChargeController { StartChargeResponse startChargeResponse = new StartChargeResponse(); StartChargeRequest startChargeRequest = JSONUtil.readParams(commonRequest.getData(), StartChargeRequest.class); String startChargeSeq = startChargeRequest.getStartChargeSeq(); - String connectorID = startChargeRequest.getConnectorId(); - String operatorId = startChargeSeq.substring(0, 9); - Optional authSecretTokenIn = - authSecretTokenRepository.findByOperatorId3irdptyAndSecretTokenType(operatorId, "IN"); - if (!authSecretTokenIn.isPresent()) { - startChargeResponse.setSuccStat(1); - startChargeResponse.setFailReason(3); - startChargeResponse.setStartChargeSeqStat(5); - resp.setMsg("This 3rd has no token"); + String connectorId = startChargeRequest.getConnectorId(); + Map cacheGun = REDIS.getCacheMap("gun:".concat(connectorId)); + String terminalStatus = (String) cacheGun.get("vehicleGunStatus"); + String status = (String) cacheGun.get("status"); + EtOrderMapping etOrderMapping = new EtOrderMapping(); + etOrderMapping.setEvcsOrderNo(startChargeSeq); + if (!"空闲".equals(status)) { + resp.setMsg("终端状态异常:[".concat(status == null ? "未注册" : status).concat("]")); + resp.setRet("500"); + emptyHorder(startChargeSeq, connectorId, etOrderMapping); + } else if ("否".equals(terminalStatus)) { + resp.setMsg("未插枪"); + resp.setRet("500"); + emptyHorder(startChargeSeq, connectorId, etOrderMapping); } else { - Map cacheGun = REDIS.getCacheMap("gun:".concat(connectorID)); - String terminalStatus = (String) cacheGun.get("vehicleGunStatus"); - String status = (String) cacheGun.get("status"); - if (!"空闲".equals(status)) { - resp.setMsg("终端状态异常:[".concat(status == null ? "未注册" : status).concat("]")); - resp.setRet("500"); - } else if ("否".equals(terminalStatus)) { - resp.setMsg("未插枪"); - resp.setRet("500"); + String plateNum = startChargeRequest.getPlateNum(); + plateNum = plateNum == null ? startChargeRequest.getPlateNum2() : plateNum; + R res = pileOrderService.pileStartUpBy3rd(startChargeSeq, startChargeRequest.getDriverId(), + startChargeRequest.getChargingAmt(), plateNum, -1, connectorId); + startChargeResponse.setStartChargeSeq(startChargeSeq); + startChargeResponse.setConnectorID(connectorId); + if (res.getCode() != 200) { + if (res.getCode() != 500) { + startChargeResponse.setFailReason(res.getCode()); + } else { + startChargeResponse.setFailReason(3); + } + startChargeResponse.setSuccStat(1); + startChargeResponse.setStartChargeSeqStat(4); } else { - String plateNum = startChargeRequest.getPlateNum(); - plateNum = plateNum == null ? startChargeRequest.getPlateNum2() : plateNum; - R res = pileOrderService.pileStartUpBy3rd(startChargeSeq, startChargeRequest.getDriverId(), - startChargeRequest.getChargingAmt(), plateNum, -1, connectorID); - startChargeResponse.setStartChargeSeq(startChargeSeq); - startChargeResponse.setConnectorID(connectorID); - if (res.getCode() != 200) { - if (res.getCode() != 500) { - startChargeResponse.setFailReason(res.getCode()); - } else { - startChargeResponse.setFailReason(3); - } - startChargeResponse.setSuccStat(1); - startChargeResponse.setStartChargeSeqStat(4); - } else { - Map etOrderData = (Map) res.getData(); - EtOrderMapping etOrderMapping = new EtOrderMapping(); - etOrderMapping.setEvcsOrderNo(startChargeSeq); - etOrderMapping.setXhOrderNo(String.valueOf(etOrderData.get("orderNo"))); - etOrderMappingRepo.save(etOrderMapping); - startChargeResponse.setStartChargeSeqStat(1); - startChargeResponse.setSuccStat(0); - startChargeResponse.setFailReason(0); - //insert a gunStatusData to redis - Map pushOrder = new HashMap<>(); - //1 means starting. - pushOrder.put("startChargeSeqStat", 1); - String orderNo = String.valueOf(etOrderData.get("orderNo")); - pushOrder.put("internetSerialNumber", startChargeRequest.getStartChargeSeq()); - pushOrder.put("connectorID", connectorID); - pushOrder.put("startTime", etOrderData.get("startTime")); - //0 means needs to be notified. - pushOrder.put("startChargeNotificationStat", 0); - //0 means needs to be notified. - pushOrder.put("chargeOrderInfoNotificationStat", 0); - pushOrder.put("operatorId3rdpty", startChargeSeq.substring(0, 9)); - REDIS.setCacheMap("pushOrder:".concat(orderNo), pushOrder); - } - if (res.getCode() != 200) { - resp.setRet(EvcsConst.RET_FAIL); - } else { - resp.setRet(EvcsConst.RET_SUCC); - } - resp.setMsg(res.getMsg()); + startChargeResponse.setStartChargeSeqStat(1); + startChargeResponse.setSuccStat(0); + startChargeResponse.setFailReason(0); } + Map etOrderData = (Map) res.getData(); + etOrderMapping.setXhOrderNo(String.valueOf(etOrderData.get("orderNo"))); + Map pushOrder = new HashMap<>(); + pushOrder.put("startChargeSeqStat", 1); + String orderNo = String.valueOf(etOrderData.get("orderNo")); + pushOrder.put("internetSerialNumber", startChargeRequest.getStartChargeSeq()); + pushOrder.put("connectorID", connectorId); + pushOrder.put("startTime", etOrderData.get("startTime")); + pushOrder.put("startChargeNotificationStat", 0); + pushOrder.put("chargeOrderInfoNotificationStat", 0); + pushOrder.put("operatorId3rdpty", startChargeSeq.substring(0, 9)); + REDIS.setCacheMap("pushOrder:".concat(orderNo), pushOrder); + if (res.getCode() != 200) { + resp.setRet(EvcsConst.RET_FAIL); + } else { + resp.setRet(EvcsConst.RET_SUCC); + } + resp.setMsg(res.getMsg()); } + etOrderMappingRepo.save(etOrderMapping); resp.setData(JSONUtil.toJSONString(startChargeResponse)); return resp; } + + private void emptyHorder(String startChargeSeq, String connectorId, EtOrderMapping etOrderMapping) { + + XhpcHistoryOrder emptyHorder = new XhpcHistoryOrder(); + Date now = DateUtils.getNowDate(); + emptyHorder.setStartTime(now); + emptyHorder.setEndTime(now); + emptyHorder.setCreateTime(now); + emptyHorder.setUpdateTime(now); + String sn = genOrder(connectorId); + etOrderMapping.setXhOrderNo(sn); + emptyHorder.setSerialNumber(sn); + emptyHorder.setOperatorId3rdptyEvcs(startChargeSeq.substring(0, 9)); + emptyHorder.setType(1); + emptyHorder.setState(2); + emptyHorder.setChargingStationId(REDIS.getCacheMapValue("pile:".concat(connectorId.substring(0, 14)), "stationId")); + emptyHorder.setTerminalId(xhpcTerminalRepository.findOneBySerialNumber(connectorId).get().getTerminalId()); + xhpcHistoryOrderRepository.save(emptyHorder); + } + + } diff --git a/evcs-modules/evcs-core/src/main/java/com/xhpc/evcs/notification/CoreDispatcher.java b/evcs-modules/evcs-core/src/main/java/com/xhpc/evcs/notification/CoreDispatcher.java index 265320f4..98b95665 100644 --- a/evcs-modules/evcs-core/src/main/java/com/xhpc/evcs/notification/CoreDispatcher.java +++ b/evcs-modules/evcs-core/src/main/java/com/xhpc/evcs/notification/CoreDispatcher.java @@ -37,8 +37,8 @@ import static com.xhpc.evcs.config.EvcsFilter.encryptReqOut; @Slf4j public class CoreDispatcher { - @Value("${xhpc.evcs.oklog:false}") - private boolean oklog; + @Value("${xhpc.evcs.oklog2:false}") + private boolean oklog2; @Autowired private AuthSecretTokenRepository authSecretTokenRepository; public static final okhttp3.MediaType JSON = okhttp3.MediaType.parse("application/json; charset=utf-8"); @@ -52,7 +52,7 @@ public class CoreDispatcher { } okhttp3.RequestBody body = null; OkHttpClient.Builder builder = new OkHttpClient.Builder(); - if (oklog) { + if (oklog2) { HttpLoggingInterceptor logging = new HttpLoggingInterceptor(); logging.setLevel(HttpLoggingInterceptor.Level.BODY); builder.addInterceptor(logging); diff --git a/evcs-modules/evcs-core/src/main/java/com/xhpc/evcs/notification/NotificationEquipChargeStatusTask.java b/evcs-modules/evcs-core/src/main/java/com/xhpc/evcs/notification/NotificationEquipChargeStatusTask.java index 39d6b729..212d605e 100644 --- a/evcs-modules/evcs-core/src/main/java/com/xhpc/evcs/notification/NotificationEquipChargeStatusTask.java +++ b/evcs-modules/evcs-core/src/main/java/com/xhpc/evcs/notification/NotificationEquipChargeStatusTask.java @@ -11,7 +11,6 @@ import com.xhpc.evcs.jpa.OrderMappingRepository; import com.xhpc.evcs.jpa.StatisticTimeIntervalRepository; import com.xhpc.evcs.utils.DateUtil; import com.xhpc.evcs.utils.JSONUtil; -import com.xhpc.pp.utils.HexUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -69,10 +68,8 @@ public class NotificationEquipChargeStatusTask extends CoreDispatcher { equipChargeStatus.setStartChargeSeqStat(2); equipChargeStatus.setConnectorID(orderkey.substring(6, 22)); equipChargeStatus.setConnectorStatus(3); - String current = REDIS.getCacheMapValue(gunkey, "current"); - equipChargeStatus.setCurrentA(HexUtils.reverseHexInt(current == null ? "9600" : current) / 10.0); - String voltage = REDIS.getCacheMapValue(gunkey, "voltage"); - equipChargeStatus.setVoltageA(HexUtils.reverseHexInt(voltage == null ? "D80E" : voltage) / 10.0); + equipChargeStatus.setCurrentA(REDIS.getCacheMapValue(gunkey, "current")); + equipChargeStatus.setVoltageA(REDIS.getCacheMapValue(gunkey, "voltage")); Integer soc = REDIS.getCacheMapValue(orderkey, "endSoc"); equipChargeStatus.setSoc(soc == null ? 0.0 : Double.valueOf(soc.toString())); CacheRealtimeData lord = REDIS.getCacheObject(orderkey.concat(".lord")); diff --git a/evcs-modules/evcs-core/src/main/resources/logback.xml b/evcs-modules/evcs-core/src/main/resources/logback.xml index 6bce5447..70536994 100644 --- a/evcs-modules/evcs-core/src/main/resources/logback.xml +++ b/evcs-modules/evcs-core/src/main/resources/logback.xml @@ -59,7 +59,7 @@ - + diff --git a/xhpc-modules/xhpc-common/src/main/java/com/xhpc/common/data/redis/StaticBeanUtil.java b/xhpc-modules/xhpc-common/src/main/java/com/xhpc/common/data/redis/StaticBeanUtil.java index 4b92a781..734b19dc 100644 --- a/xhpc-modules/xhpc-common/src/main/java/com/xhpc/common/data/redis/StaticBeanUtil.java +++ b/xhpc-modules/xhpc-common/src/main/java/com/xhpc/common/data/redis/StaticBeanUtil.java @@ -1,5 +1,6 @@ package com.xhpc.common.data.redis; +import cn.hutool.core.date.DateUtil; import com.xhpc.common.api.PileOrderService; import com.xhpc.common.redis.service.RedisService; import org.springframework.beans.factory.annotation.Autowired; @@ -7,6 +8,8 @@ import org.springframework.data.redis.support.atomic.RedisAtomicLong; import org.springframework.stereotype.Component; import javax.annotation.PostConstruct; +import java.util.Calendar; +import java.util.Date; @Component public class StaticBeanUtil { @@ -60,4 +63,13 @@ public class StaticBeanUtil { return upperCode; } + public static String genOrder(String terminalSerialNumber) { + + Date date = Calendar.getInstance().getTime(); + String format = DateUtil.format(date, "yyMMddHHmmss"); + //自增 + String orderNo = terminalSerialNumber + format + seqDec("gun:" + terminalSerialNumber + ".seqdec"); + return orderNo; + } + } diff --git a/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/service/impl/XhpcChargeOrderServiceImpl.java b/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/service/impl/XhpcChargeOrderServiceImpl.java index a3790561..e03016a6 100644 --- a/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/service/impl/XhpcChargeOrderServiceImpl.java +++ b/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/service/impl/XhpcChargeOrderServiceImpl.java @@ -27,6 +27,8 @@ import java.util.*; import java.util.regex.Matcher; import java.util.regex.Pattern; +import static com.xhpc.common.data.redis.StaticBeanUtil.genOrder; + /** * @author yuyang * @date 2021/8/4 9:54 @@ -78,11 +80,12 @@ public class XhpcChargeOrderServiceImpl implements IXhpcChargeOrderService { @Override @Transactional - public AjaxResult startUp(Long userId, String serialNumber,Integer type) { + public AjaxResult startUp(Long userId, String terminalSerialNumber, Integer type) { + String pattern = "^([0-9]{16})"; Pattern compile = Pattern.compile(pattern); - Matcher m = compile.matcher(serialNumber); - if (serialNumber.length()!=16 || !m.matches()) { + Matcher m = compile.matcher(terminalSerialNumber); + if (terminalSerialNumber.length() != 16 || !m.matches()) { return AjaxResult.error(1104, "无效的终端编号"); } //查看充电用户金额是否大于5元 @@ -108,10 +111,10 @@ public class XhpcChargeOrderServiceImpl implements IXhpcChargeOrderService { } //终端状态是否空闲 //是否插枪 - Map cacheMap = REDIS.getCacheMap("gun:" + serialNumber); + Map cacheMap = REDIS.getCacheMap("gun:" + terminalSerialNumber); logger.info("<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>"); - logger.info("<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>"+serialNumber); - logger.info("<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>"+cacheMap.toString()); + logger.info("<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>" + terminalSerialNumber); + logger.info("<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>" + cacheMap.toString()); logger.info("<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>"); if(cacheMap==null){ @@ -137,7 +140,7 @@ public class XhpcChargeOrderServiceImpl implements IXhpcChargeOrderService { } //终端信息 - XhpcTerminal xhpcTerminal = xhpcChargeOrderMapper.getXhpcTerminalSerialNumber(serialNumber); + XhpcTerminal xhpcTerminal = xhpcChargeOrderMapper.getXhpcTerminalSerialNumber(terminalSerialNumber); if (xhpcTerminal == null || xhpcTerminal.getTerminalId() == null || xhpcTerminal.getChargingPileId() == null || xhpcTerminal.getPileSerialNumber() == null) { return AjaxResult.error(1104, "无效的终端编号"); } @@ -152,10 +155,7 @@ public class XhpcChargeOrderServiceImpl implements IXhpcChargeOrderService { //启动充电 StartChargingData startChargingData = new StartChargingData(); //订单流水号 终端号+年月日时分秒+自增4位 共32位 - Date date = Calendar.getInstance().getTime(); - String format = DateUtil.format(date, "yyMMddHHmmss"); - //自增 - String orderNo = serialNumber + format + StaticBeanUtil.seqDec("gun:" + serialNumber + ".seqdec"); + String orderNo = genOrder(terminalSerialNumber); startChargingData.setOrderNo(orderNo); if(userMessage.get("phone") !=null){ diff --git a/xhpc-modules/xhpc-power-pile/src/main/java/com/xhpc/pp/logic/RealtimeDataLogic.java b/xhpc-modules/xhpc-power-pile/src/main/java/com/xhpc/pp/logic/RealtimeDataLogic.java index 5b4515b6..7d398dc5 100644 --- a/xhpc-modules/xhpc-power-pile/src/main/java/com/xhpc/pp/logic/RealtimeDataLogic.java +++ b/xhpc-modules/xhpc-power-pile/src/main/java/com/xhpc/pp/logic/RealtimeDataLogic.java @@ -6,7 +6,6 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.xhpc.common.api.PileOrderService; import com.xhpc.common.api.SmsService; import com.xhpc.common.core.domain.R; -import com.xhpc.common.data.down.StartChargingData; import com.xhpc.common.data.redis.CacheOrderData; import com.xhpc.common.data.redis.CacheRealtimeData; import com.xhpc.common.data.up.RealtimeData; @@ -71,8 +70,10 @@ public class RealtimeDataLogic implements ServiceLogic { String statusplain = stable[statusInt]; cacheGun.put("pileGunStatus", pvgstable[Integer.parseInt(realtimeData.getPileGunStatus())]); cacheGun.put("vehicleGunStatus", pvgstable[Integer.parseInt(realtimeData.getVehicleGunStatus())]); - cacheGun.put("voltage", realtimeData.getWorkingVoltage()); - cacheGun.put("current", realtimeData.getWorkingCurrent()); + double wv = reverseHexInt(realtimeData.getWorkingVoltage()) / 10.0; + cacheGun.put("voltage", wv); + double wc = reverseHexInt(realtimeData.getWorkingCurrent()) / 10.0; + cacheGun.put("current", wc); String hardwareFault = realtimeData.getHardwareFault(); String hfs = toBits(hardwareFault); char[] hfcs = hfs.toCharArray(); @@ -116,17 +117,9 @@ public class RealtimeDataLogic implements ServiceLogic { if (realtimeDataList == null) { realtimeDataList = new ArrayList<>(); } - StartChargingData startChargingData = new StartChargingData(); Integer balance = (Integer) cacheOrder.get("initBalance"); CacheRealtimeData cacheRealtimeData = translate(realtimeData); balance -= cacheRealtimeData.getAmountCharged(); -// startChargingData.setBalance(balance); //todo make pile work then uncomment -// startChargingData.setLogicCardNo(cacheOrder.get("logicCardNo").toString()); -// startChargingData.setPhysicCardNo(cacheOrder.get("physicCardNo").toString()); -// startChargingData.setPileNo(cacheOrder.get("pileNo").toString()); -// startChargingData.setGunId(cacheOrder.get("gunId").toString()); -// Thread.sleep(300); -// chargingController.nativeRefreshBalance(startChargingData); cacheRealtimeData.setCreateTime(DateUtil.now()); String lord = orderkey.concat(".lord"); REDIS.setCacheObject(lord, cacheRealtimeData); @@ -149,38 +142,49 @@ public class RealtimeDataLogic implements ServiceLogic { cacheOrder.put("totalMoney", cacheRealtimeData.getAmountCharged() / 10000.0); cacheOrder.put("realtimeDataList", realtimeDataList); pileOrderService.pileRimeOrder(orderNo); - Integer stopSoc = (Integer) cacheOrder.get("stopSoc"); - if (stopSoc != null && socInt >= stopSoc) { - String alerted = (String) cacheOrder.get("socalerted"); - String tel = (String) cacheOrder.get("tel"); - if (alerted == null && tel != null) { - R r = chargingController.nativeStopCharging(pileNo, gunId, default_version); - if (r.getCode() == 200) { - HashMap paramMap = new HashMap<>(); - paramMap.put("battery", stopSoc.toString()); - paramMap.put("phone", tel); - paramMap.put("content", "【小华充电】尊敬的用户,你的车辆已充电达至设定的SOC(" + stopSoc + "%)" + - "已自动停止充电,请您尽快将车辆挪走以方便他人使用充电桩,谢谢合作。"); - smsService.sendNotice(paramMap); - cacheOrder.put("socalerted", "true"); + Integer vul = (Integer) cachePile.get("voltageUpperLimits"); + Integer cul = (Integer) cachePile.get("current"); + if (wc > cul || wv > vul) { + R r = chargingController.nativeStopCharging(pileNo, gunId, default_version); + if (r.getCode() == 200) { + Integer vcpcnt = (Integer) cacheOrder.get("vcpcnt"); + cacheOrder.put("vcpcnt", vcpcnt == null ? 1 : vcpcnt++); + log.error("{} alert: v[{}], c[{}]", orderNo, wv, wc); + } + } else { + Integer stopSoc = (Integer) cacheOrder.get("stopSoc"); + if (stopSoc != null && socInt >= stopSoc) { + String alerted = (String) cacheOrder.get("socalerted"); + String tel = (String) cacheOrder.get("tel"); + if (alerted == null && tel != null) { + R r = chargingController.nativeStopCharging(pileNo, gunId, default_version); + if (r.getCode() == 200) { + HashMap paramMap = new HashMap<>(); + paramMap.put("battery", stopSoc.toString()); + paramMap.put("phone", tel); + paramMap.put("content", "【小华充电】尊敬的用户,你的车辆已充电达至设定的SOC(" + stopSoc + "%)" + + "已自动停止充电,请您尽快将车辆挪走以方便他人使用充电桩,谢谢合作。"); + smsService.sendNotice(paramMap); + cacheOrder.put("socalerted", "true"); + } } } - } - if (balance < 50000) { - String alerted = (String) cacheOrder.get("lt5alerted"); - String tel = (String) cacheOrder.get("tel"); - if (alerted == null && tel != null) { - HashMap paramMap = new HashMap<>(); - paramMap.put("money", "5"); - paramMap.put("phone", tel); - paramMap.put("content", "【小华充电】尊敬的用户,你的账户余额小于5元,为不影响您的正常充电,请您尽快充值交费,谢谢。"); - smsService.sendNotice(paramMap); - cacheOrder.put("lt5alerted", "true"); + if (balance < 50000) { + String alerted = (String) cacheOrder.get("lt5alerted"); + String tel = (String) cacheOrder.get("tel"); + if (alerted == null && tel != null) { + HashMap paramMap = new HashMap<>(); + paramMap.put("money", "5"); + paramMap.put("phone", tel); + paramMap.put("content", "【小华充电】尊敬的用户,你的账户余额小于5元,为不影响您的正常充电,请您尽快充值交费,谢谢。"); + smsService.sendNotice(paramMap); + cacheOrder.put("lt5alerted", "true"); + } + } + if ("true".equals(cacheOrder.get("lordiss"))) { + cacheOrder.put("lordiss", "false"); + pileOrderService.pileStop(orderNo, 4, "订单实时数据恢复"); } - } - if ("true".equals(cacheOrder.get("lordiss"))) { - cacheOrder.put("lordiss", "false"); - pileOrderService.pileStop(orderNo, 4, "订单实时数据恢复"); } } else { Integer errorfreecnt = (Integer) cacheOrder.get("errorfreecnt"); diff --git a/xhpc-modules/xhpc-power-pile/src/main/java/com/xhpc/pp/server/RateModelTask.java b/xhpc-modules/xhpc-power-pile/src/main/java/com/xhpc/pp/server/RateModelTask.java index 7a7f9349..47e82c32 100644 --- a/xhpc-modules/xhpc-power-pile/src/main/java/com/xhpc/pp/server/RateModelTask.java +++ b/xhpc-modules/xhpc-power-pile/src/main/java/com/xhpc/pp/server/RateModelTask.java @@ -36,7 +36,7 @@ public class RateModelTask { Collection gks = REDIS.keys(gkPattern); boolean charging = false; for (String gk : gks) { - if (isInteger(REDIS.getCacheMapValue(gk, "status"))) { + if (gk.length() == 20 && isInteger(REDIS.getCacheMapValue(gk, "status"))) { charging = true; break; }