query_equip_business_policy接口开发中
query_stop_charge接口部分完成
This commit is contained in:
parent
7bcca156ac
commit
794070a57a
@ -0,0 +1,19 @@
|
||||
package com.xhpc.evcs.dto;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonAutoDetect;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.ANY, getterVisibility = JsonAutoDetect.Visibility.NONE,
|
||||
setterVisibility = JsonAutoDetect.Visibility.NONE, creatorVisibility = JsonAutoDetect.Visibility.NONE)
|
||||
public class QueryStopChargeRequest {
|
||||
|
||||
@JsonProperty("startChargeSeq")
|
||||
String startChargeSeq;
|
||||
@JsonProperty("connectorId")
|
||||
String connectorId;
|
||||
|
||||
}
|
||||
@ -0,0 +1,31 @@
|
||||
package com.xhpc.evcs.dto;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonAutoDetect;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.ANY, getterVisibility = JsonAutoDetect.Visibility.NONE,
|
||||
setterVisibility = JsonAutoDetect.Visibility.NONE, creatorVisibility = JsonAutoDetect.Visibility.NONE)
|
||||
//定义该对象转换后的json对象的键值对顺序
|
||||
@JsonPropertyOrder({
|
||||
"StartChargeSeq",
|
||||
"StartChargeSeqStat",
|
||||
"SuccStat",
|
||||
"FailReason",
|
||||
})
|
||||
public class QueryStopChargeResponse {
|
||||
|
||||
@JsonProperty("StartChargeSeq")
|
||||
String startChargeSeq;
|
||||
@JsonProperty("StartChargeSeqStat")
|
||||
int startChargeSeqStat;
|
||||
@JsonProperty("SuccStat")
|
||||
int succStat;
|
||||
@JsonProperty("FailReason")
|
||||
int failReason;
|
||||
|
||||
}
|
||||
@ -31,8 +31,6 @@ public class QueryEquipBusinessPolicyController {
|
||||
String connectorId = equipBizRequest.getConnectorId();
|
||||
//获取枪所对应的桩编码
|
||||
String bySerialNumber = xhpcTerminalRepository.selectBySql(connectorId);
|
||||
System.out.println(bySerialNumber);
|
||||
|
||||
String pileSerialNumber = bySerialNumber;
|
||||
//通过桩编码,进入redis,找到其所用的费率模型id
|
||||
Map<String, Object> cacheMap = REDIS.getCacheMap("pile:" + pileSerialNumber);
|
||||
@ -41,10 +39,6 @@ public class QueryEquipBusinessPolicyController {
|
||||
CacheRateModel rateModel = REDIS.getCacheObject("rateModel:" + rateModelId);
|
||||
String[] tfPricesSeq = rateModel.getTfPricesSeq();
|
||||
|
||||
//查询所需要的数据
|
||||
// EquipBizResponse equipBizResponse = load(tfPricesSeq,equipBizRequest);
|
||||
|
||||
|
||||
//遍历获取每一个时段
|
||||
//存储时段
|
||||
ArrayList<String> modelTypes = new ArrayList<>();
|
||||
@ -76,24 +70,41 @@ public class QueryEquipBusinessPolicyController {
|
||||
//放入到个数List中
|
||||
modelCount.add(lastCount);
|
||||
|
||||
//"030000" "240000"
|
||||
//获取各个类型的时段的时间区间,并将其存放至timeList集合中。
|
||||
//定义一个初始时间段
|
||||
String initTime = "000000";
|
||||
String initTime1 = "240000";
|
||||
ArrayList<String> list = new ArrayList<>();
|
||||
//添加临时存储变量
|
||||
int temp = -1;
|
||||
ArrayList<String> timeList = new ArrayList<>();
|
||||
//放入必有初始时间
|
||||
timeList.add(initTime);
|
||||
//根据出现的时段个数确定他们的时间区间,然后存放至List集合中
|
||||
for (int i = 0; i < modelCount.size() - 1; i++) {
|
||||
Integer integer = modelCount.get(i);
|
||||
int hours = integer / 2;
|
||||
if (integer >= 10) {
|
||||
String str = String.valueOf(hours);
|
||||
initTime1.replace("24", "" + hours);
|
||||
if (temp != -1) {
|
||||
Integer integer = modelCount.get(i);
|
||||
int hours = integer / 2;
|
||||
temp = temp + hours;
|
||||
String hoursStr = String.format("%02d", temp);
|
||||
String finalTime = hoursStr + "0000";
|
||||
timeList.add(finalTime);
|
||||
} else {
|
||||
String str = String.valueOf(hours);
|
||||
initTime1.substring(2);
|
||||
Integer integer = modelCount.get(i);
|
||||
int hours = integer / 2;
|
||||
//记录中间时间
|
||||
temp = hours;
|
||||
String hoursStr = String.format("%02d", temp);
|
||||
String finalTime = hoursStr + "0000";
|
||||
timeList.add(finalTime);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
PolicyInfos[] policyInfosArr = new PolicyInfos[timeList.size()];
|
||||
for (int i = 0; i < timeList.size() - 1; i++) {
|
||||
PolicyInfos policyInfos = new PolicyInfos();
|
||||
policyInfos.setStartTime(timeList.get(i));
|
||||
//todo 明天继续
|
||||
policyInfos.setServicePrice(0);
|
||||
policyInfos.setElecPrice(0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -0,0 +1,84 @@
|
||||
package com.xhpc.evcs.api;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.xhpc.common.api.PowerPileService;
|
||||
import com.xhpc.evcs.dto.CommonResponse;
|
||||
import com.xhpc.evcs.dto.QueryStopChargeRequest;
|
||||
import com.xhpc.evcs.dto.QueryStopChargeResponse;
|
||||
import com.xhpc.evcs.utils.JSONUtil;
|
||||
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;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import static com.xhpc.common.data.redis.StaticBeanUtil.REDIS;
|
||||
|
||||
@Slf4j
|
||||
@RestController
|
||||
public class QueryStopChargeController {
|
||||
|
||||
|
||||
@Autowired
|
||||
PowerPileService powerPileService;
|
||||
|
||||
@PostMapping("/v1/query_stop_charge")
|
||||
public CommonResponse queryStopCharge(@RequestBody QueryStopChargeRequest queryStopChargeRequest) {
|
||||
//充电订单号
|
||||
String chargingOrderSeq = queryStopChargeRequest.getStartChargeSeq();
|
||||
//充电设备接口编码(枪编码)
|
||||
String connectorId = queryStopChargeRequest.getConnectorId();
|
||||
//获取桩编码
|
||||
String pileNum = connectorId.substring(0, connectorId.length() - 2);
|
||||
//从桩上面获取版本号
|
||||
//获取Redis中的桩信息
|
||||
Map<String, Object> pile = REDIS.getCacheMap("pile:" + pileNum);
|
||||
String vesrionNum = (String) pile.get("vesrion");
|
||||
|
||||
//给对应的枪发送停止充电指令
|
||||
powerPileService.stopCharging(chargingOrderSeq, pileNum, connectorId, "0A"); //ToDo 暂时写死
|
||||
|
||||
//Todo 获取Redis中的充电状态来判断是否启动成功
|
||||
if (true) {
|
||||
//设置Redis中的充电订单为已结束
|
||||
Map<String, Object> order = REDIS.getCacheMap("order:" + chargingOrderSeq);
|
||||
order.replace("status", "已结束");
|
||||
REDIS.setCacheMap("order:" + chargingOrderSeq, order);
|
||||
|
||||
//封装实体类数据
|
||||
QueryStopChargeResponse queryStopChargeResponse = new QueryStopChargeResponse();
|
||||
//充电订单号
|
||||
queryStopChargeResponse.setStartChargeSeq(chargingOrderSeq);
|
||||
//充电订单状态
|
||||
queryStopChargeResponse.setStartChargeSeqStat(4);
|
||||
//操作结果
|
||||
queryStopChargeResponse.setSuccStat(0);
|
||||
//失败原因
|
||||
queryStopChargeResponse.setFailReason(0);
|
||||
|
||||
//转换为json对象
|
||||
String data = null;
|
||||
try {
|
||||
data = JSONUtil.toJSONString(queryStopChargeResponse);
|
||||
} catch (JsonProcessingException e) {
|
||||
e.printStackTrace();
|
||||
System.out.println("json转换出问题了");
|
||||
}
|
||||
|
||||
CommonResponse commonResponse = new CommonResponse();
|
||||
commonResponse.setRet("0");
|
||||
commonResponse.setMsg("请求停止充电成功");
|
||||
commonResponse.setData(data);
|
||||
|
||||
return commonResponse;
|
||||
} else {
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@ -141,7 +141,11 @@ public class EvcsFilter extends OncePerRequestFilter {
|
||||
&& now.before(authSecretTokenIn.getTokenExpiry())
|
||||
&& authorization != null && authorization.substring(7).equals(authSecretTokenIn.getToken())) {
|
||||
try {
|
||||
decryptedData = decrypt(request, authSecretTokenIn, commonRequest, bodyString);
|
||||
if (authSecretTokenIn.isEncrypt()) {
|
||||
decryptedData = decrypt(request, authSecretTokenIn, commonRequest, bodyString);
|
||||
} else {
|
||||
decryptedData = ((String) commonRequest.getData()).getBytes(StandardCharsets.UTF_8);
|
||||
}
|
||||
log.debug("in.dec: {}", new String(decryptedData));
|
||||
} catch (BadPaddingException | InvalidAlgorithmParameterException | NoSuchAlgorithmException | IllegalBlockSizeException | NoSuchPaddingException | InvalidKeyException e) {
|
||||
erroMsg = e.getMessage();
|
||||
|
||||
@ -0,0 +1,110 @@
|
||||
package com.xhpc.evcs.notification;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.xhpc.common.data.redis.CacheOrderData;
|
||||
import com.xhpc.evcs.api.CoreDispatcher;
|
||||
import com.xhpc.evcs.dto.ChargeResultRequest;
|
||||
import com.xhpc.evcs.dto.CommonRequest;
|
||||
import com.xhpc.evcs.utils.JSONUtil;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static com.xhpc.common.data.redis.StaticBeanUtil.REDIS;
|
||||
|
||||
public class NotificationStopChargeResultTask extends CoreDispatcher {
|
||||
|
||||
@Scheduled(fixedRate = 1000 * 20)
|
||||
public void run() throws IOException {
|
||||
|
||||
notifyService();
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取充电订单号
|
||||
* 获取充电订单状态
|
||||
* 获取充电设备接口编码
|
||||
* 获取成功标识
|
||||
* 获取停止失败原因
|
||||
* 推送过去
|
||||
* <p>
|
||||
* 出现异常逻辑
|
||||
* 如果当充电桩因为异常停止充电时,那么谁告诉我订单是个异常订单?
|
||||
*/
|
||||
public void notifyService() {
|
||||
|
||||
//20秒检测一次Redis中的数据状态,并推送
|
||||
|
||||
//获取Redis中的所有订单状态数据
|
||||
List<Object> orderStatusList = REDIS.getCacheList("orderStatus:*");
|
||||
|
||||
//使用for循环遍历所有订单状态数据找到已结束的充电订单
|
||||
for (int i = 0; i < orderStatusList.size() - 1; i++) {
|
||||
|
||||
//获取订单数据
|
||||
Map<String, Object> orderStatus = (Map<String, Object>) orderStatusList.get(i);
|
||||
//判断该订单数据是否已经被推送过了,如果已经推送过了,则不在推送
|
||||
Boolean isPush = (Boolean) orderStatus.get("isPush");
|
||||
if (!isPush) {
|
||||
//获取内部的充电订单号
|
||||
String orderNo = (String) orderStatus.get("orderNo");
|
||||
//通过充电订单号,获取指定的订单
|
||||
Map<String, Object> order = REDIS.getCacheMap("order:" + orderNo);
|
||||
//判断订单充电状态
|
||||
String status = (String) order.get("status");
|
||||
if (status.equals("已结束")) {
|
||||
//获取指定的订单的数据
|
||||
CacheOrderData orderData = (CacheOrderData) order.get("orderData");
|
||||
//获取充电设备接口编码
|
||||
String pileNo = orderData.getPileNo();
|
||||
String gunId = orderData.getGunId();
|
||||
String gunSerial = pileNo + gunId;
|
||||
//设置成功标识
|
||||
int succStat = 0;
|
||||
//设置停止失败原因
|
||||
int failReason = 0;
|
||||
|
||||
//使用指定包装类封装数据
|
||||
ChargeResultRequest chargeResultRequest = new ChargeResultRequest();
|
||||
chargeResultRequest.setStartChargeSeq(null);
|
||||
chargeResultRequest.setStartChargeSeqStat(status);
|
||||
chargeResultRequest.setConnectorID(gunSerial);
|
||||
chargeResultRequest.setSuccStat(succStat);
|
||||
chargeResultRequest.setFailReason(failReason);
|
||||
//将其转换为json
|
||||
String jsonData = null;
|
||||
try {
|
||||
jsonData = JSONUtil.toJSONString(chargeResultRequest);
|
||||
} catch (JsonProcessingException e) {
|
||||
e.printStackTrace();
|
||||
System.out.println("转换成Json失败");
|
||||
}
|
||||
|
||||
//将包装类塞入要发送的请求的包装类中
|
||||
//泛型为放入json数据的实体类类型
|
||||
CommonRequest<ChargeResultRequest> chargeResultRequestCommonRequest = new CommonRequest<>();
|
||||
chargeResultRequestCommonRequest.setData(jsonData);
|
||||
|
||||
//推送数据
|
||||
//operatorId第三方的 我们场站运营商的
|
||||
ok(chargeResultRequestCommonRequest, "/notification_stop_charge_result", "765367656", null);
|
||||
|
||||
// TODO: 2021/10/21 设置该订单数据已经被推送的标识符
|
||||
orderStatus.put("isPush", true);
|
||||
// 获取对应的orderStatus的Key
|
||||
//REDIS.setCacheMap("",orderStatus);
|
||||
}
|
||||
|
||||
// TODO:如果充电状态为停止中:
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user