fix NPE
This commit is contained in:
parent
2152fcb6c7
commit
ef11c74fef
@ -23,6 +23,7 @@ import java.util.Map;
|
|||||||
|
|
||||||
import static com.xhpc.common.data.redis.StaticBeanUtil.REDIS;
|
import static com.xhpc.common.data.redis.StaticBeanUtil.REDIS;
|
||||||
import static com.xhpc.evcs.notification.NotificationEquipChargeStatusTask.calculateEm;
|
import static com.xhpc.evcs.notification.NotificationEquipChargeStatusTask.calculateEm;
|
||||||
|
import static com.xhpc.evcs.utils.DateUtil.orderNo2DateStr;
|
||||||
|
|
||||||
@RestController()
|
@RestController()
|
||||||
public class QueryEquipChargeStatusController {
|
public class QueryEquipChargeStatusController {
|
||||||
@ -47,8 +48,8 @@ public class QueryEquipChargeStatusController {
|
|||||||
throw new ServerInternalException("未查询到该订单编号数据");
|
throw new ServerInternalException("未查询到该订单编号数据");
|
||||||
}
|
}
|
||||||
String internalOrderNum = etOrderMapping.getXhOrderNo();
|
String internalOrderNum = etOrderMapping.getXhOrderNo();
|
||||||
Map<String, Object> order = REDIS.getCacheMap("order:" + internalOrderNum);
|
Map<String, Object> cacheOrder = REDIS.getCacheMap("order:" + internalOrderNum);
|
||||||
String orderStatus = (String) order.get("status");
|
String orderStatus = (String) cacheOrder.get("status");
|
||||||
int startChargeSeqStat = 0;
|
int startChargeSeqStat = 0;
|
||||||
if (orderStatus == null) {
|
if (orderStatus == null) {
|
||||||
startChargeSeqStat = 5;
|
startChargeSeqStat = 5;
|
||||||
@ -101,11 +102,12 @@ public class QueryEquipChargeStatusController {
|
|||||||
Double voltageA = HexUtils.reverseHexInt(voltage) / 10.0;
|
Double voltageA = HexUtils.reverseHexInt(voltage) / 10.0;
|
||||||
equipChargeStatus.setVoltageA(voltageA);
|
equipChargeStatus.setVoltageA(voltageA);
|
||||||
//电池剩余电量
|
//电池剩余电量
|
||||||
Integer endSoc = (Integer) order.get("endSoc");
|
Integer endSoc = (Integer) cacheOrder.get("endSoc");
|
||||||
Double soc = Double.valueOf(endSoc == null ? 0 : endSoc);
|
Double soc = Double.valueOf(endSoc == null ? 0 : endSoc);
|
||||||
equipChargeStatus.setSoc(soc);
|
equipChargeStatus.setSoc(soc);
|
||||||
//开始充电时间
|
//开始充电时间
|
||||||
String startTime = (String) order.get("startTime");
|
String startTime = (String) cacheOrder.get("startTime");
|
||||||
|
if (startTime == null) startTime = orderNo2DateStr(internalOrderNum);
|
||||||
equipChargeStatus.setStartTime(startTime);
|
equipChargeStatus.setStartTime(startTime);
|
||||||
//本次采样时间 直接new一个当前时间的Date就可以了
|
//本次采样时间 直接new一个当前时间的Date就可以了
|
||||||
CacheRealtimeData lord = REDIS.getCacheObject("order:" + internalOrderNum + ".lord");
|
CacheRealtimeData lord = REDIS.getCacheObject("order:" + internalOrderNum + ".lord");
|
||||||
@ -118,7 +120,7 @@ public class QueryEquipChargeStatusController {
|
|||||||
equipChargeStatus.setTotalMoney(0.0);
|
equipChargeStatus.setTotalMoney(0.0);
|
||||||
equipChargeStatus.setTotalPower(0.0);
|
equipChargeStatus.setTotalPower(0.0);
|
||||||
}
|
}
|
||||||
Integer chargeModel = (Integer) order.get("chargeModel");
|
Integer chargeModel = (Integer) cacheOrder.get("chargeModel");
|
||||||
equipChargeStatus.setChargeModel(chargeModel == null ? 0 : chargeModel);
|
equipChargeStatus.setChargeModel(chargeModel == null ? 0 : chargeModel);
|
||||||
final Long rateModelId = REDIS.getCacheMapValue("pile:".concat(connectorId.substring(0, 14)), "rateModelId");
|
final Long rateModelId = REDIS.getCacheMapValue("pile:".concat(connectorId.substring(0, 14)), "rateModelId");
|
||||||
final CacheRateModel cacheRateModel = REDIS.getCacheObject("rateModel:" + rateModelId);
|
final CacheRateModel cacheRateModel = REDIS.getCacheObject("rateModel:" + rateModelId);
|
||||||
|
|||||||
@ -8,6 +8,7 @@ import com.xhpc.evcs.dto.CommonRequest;
|
|||||||
import com.xhpc.evcs.dto.DTOJsonHelper;
|
import com.xhpc.evcs.dto.DTOJsonHelper;
|
||||||
import com.xhpc.evcs.jpa.AuthSecretTokenRepository;
|
import com.xhpc.evcs.jpa.AuthSecretTokenRepository;
|
||||||
import com.xhpc.evcs.jpa.XhpcHistoryOrderRepository;
|
import com.xhpc.evcs.jpa.XhpcHistoryOrderRepository;
|
||||||
|
import com.xhpc.evcs.utils.DateUtil;
|
||||||
import com.xhpc.evcs.utils.JSONUtil;
|
import com.xhpc.evcs.utils.JSONUtil;
|
||||||
import com.xhpc.order.domain.XhpcHistoryOrder;
|
import com.xhpc.order.domain.XhpcHistoryOrder;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
@ -16,6 +17,10 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||||||
import org.springframework.scheduling.annotation.Scheduled;
|
import org.springframework.scheduling.annotation.Scheduled;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.time.Duration;
|
||||||
|
import java.time.Instant;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static com.xhpc.common.data.redis.StaticBeanUtil.REDIS;
|
import static com.xhpc.common.data.redis.StaticBeanUtil.REDIS;
|
||||||
@ -37,6 +42,16 @@ public class NotificationChargeOrderInfoTask extends CoreDispatcher {
|
|||||||
@Scheduled(fixedRate = 1000 * 15)
|
@Scheduled(fixedRate = 1000 * 15)
|
||||||
public void run() throws JsonProcessingException {
|
public void run() throws JsonProcessingException {
|
||||||
|
|
||||||
|
Collection<String> orderKeys = REDIS.keys("order:*");
|
||||||
|
Instant now = Instant.now();
|
||||||
|
for (String okey : orderKeys) {
|
||||||
|
Date otime = DateUtil.orderNo2Date(okey.substring(6));
|
||||||
|
if (Duration.between(otime.toInstant(), now).toHours() > 24) {
|
||||||
|
REDIS.deleteObject(okey);
|
||||||
|
REDIS.deleteObject(okey.replace("order", "pushOrder"));
|
||||||
|
logger.info("clear cache..{}", okey);
|
||||||
|
}
|
||||||
|
}
|
||||||
List<AuthSecretToken> authSecretTokenList = authSecretTokenRepository.findBySecretTokenType(SECRET_TOKEN_TYPE_OUT);
|
List<AuthSecretToken> authSecretTokenList = authSecretTokenRepository.findBySecretTokenType(SECRET_TOKEN_TYPE_OUT);
|
||||||
List<XhpcHistoryOrder> xhpcHistoryOrderList =
|
List<XhpcHistoryOrder> xhpcHistoryOrderList =
|
||||||
xhpcHistoryOrderRepository.findByConfirmResultNotAndOperatorId3rdptyEvcsIsNotNull(0);
|
xhpcHistoryOrderRepository.findByConfirmResultNotAndOperatorId3rdptyEvcsIsNotNull(0);
|
||||||
|
|||||||
@ -103,8 +103,8 @@ public class NotificationEquipChargeStatusTask extends CoreDispatcher {
|
|||||||
equipChargeStatus.setChargeDetails(new ChargeDetails[0]);
|
equipChargeStatus.setChargeDetails(new ChargeDetails[0]);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final Date endTime = DateUtil.string2Date(equipChargeStatus.getEndTime());
|
final Date endTime = DateUtil.yyyyMMDDhhmmss2Date(equipChargeStatus.getEndTime());
|
||||||
final Date startTime = DateUtil.string2Date(equipChargeStatus.getStartTime());
|
final Date startTime = DateUtil.yyyyMMDDhhmmss2Date(equipChargeStatus.getStartTime());
|
||||||
long totalMilSec = endTime.getTime() - startTime.getTime();
|
long totalMilSec = endTime.getTime() - startTime.getTime();
|
||||||
BigDecimal hours = new BigDecimal(totalMilSec).divide(new BigDecimal(3600000), 2, RoundingMode.FLOOR);
|
BigDecimal hours = new BigDecimal(totalMilSec).divide(new BigDecimal(3600000), 2, RoundingMode.FLOOR);
|
||||||
int sumPeriod = hours.setScale(0, RoundingMode.CEILING).intValue() + 1;
|
int sumPeriod = hours.setScale(0, RoundingMode.CEILING).intValue() + 1;
|
||||||
|
|||||||
@ -26,11 +26,16 @@ public class DateUtil {
|
|||||||
* @param dateStr string format of date
|
* @param dateStr string format of date
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static final Date string2Date(String dateStr) {
|
public static final Date yyyyMMDD2Date(String dateStr) {
|
||||||
|
|
||||||
return string2Date(dateStr + " 00:00:00", DATE_FORMAT_DATE_TIME);
|
return string2Date(dateStr + " 00:00:00", DATE_FORMAT_DATE_TIME);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static final Date yyyyMMDDhhmmss2Date(String dateStr) {
|
||||||
|
|
||||||
|
return string2Date(dateStr, DATE_FORMAT_DATE_TIME);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* string to date, the format is same to SimpleDateFormat for example
|
* string to date, the format is same to SimpleDateFormat for example
|
||||||
* "yyyyMMdd" "yyyy-MM-dd HH:mm:ss" etc please see
|
* "yyyyMMdd" "yyyy-MM-dd HH:mm:ss" etc please see
|
||||||
@ -101,7 +106,7 @@ public class DateUtil {
|
|||||||
/**
|
/**
|
||||||
* date 2006-04-10 author :zhaopeng
|
* date 2006-04-10 author :zhaopeng
|
||||||
*/
|
*/
|
||||||
private static SimpleDateFormat sf = new SimpleDateFormat(
|
private static final SimpleDateFormat sf = new SimpleDateFormat(
|
||||||
"yyyy-MM-dd HH:mm:ss");
|
"yyyy-MM-dd HH:mm:ss");
|
||||||
|
|
||||||
public static Date getWeek(Date date) {
|
public static Date getWeek(Date date) {
|
||||||
@ -188,20 +193,20 @@ public class DateUtil {
|
|||||||
if (date.length() == 2) {
|
if (date.length() == 2) {
|
||||||
String ten = date.substring(0, 1); // ʮλ
|
String ten = date.substring(0, 1); // ʮλ
|
||||||
String entries = date.substring(1, 2); // <EFBFBD><EFBFBD>λ
|
String entries = date.substring(1, 2); // <EFBFBD><EFBFBD>λ
|
||||||
if (ten.substring(0).equals("1")) {
|
if (ten.equals("1")) {
|
||||||
sb.append("ʮ");
|
sb.append("ʮ");
|
||||||
}
|
}
|
||||||
if (ten.substring(0).equals("2")) {
|
if (ten.equals("2")) {
|
||||||
sb.append("<EFBFBD><EFBFBD>ʮ");
|
sb.append("<EFBFBD><EFBFBD>ʮ");
|
||||||
}
|
}
|
||||||
if (ten.substring(0).equals("3")) {
|
if (ten.equals("3")) {
|
||||||
sb.append("<EFBFBD><EFBFBD>ʮ");
|
sb.append("<EFBFBD><EFBFBD>ʮ");
|
||||||
}
|
}
|
||||||
if (!entries.equals("0")) {
|
if (!entries.equals("0")) {
|
||||||
sb.append(number2Chinese(entries));
|
sb.append(number2Chinese(entries));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
String entries = date.substring(0);
|
String entries = date;
|
||||||
sb.append(number2Chinese(entries));
|
sb.append(number2Chinese(entries));
|
||||||
}
|
}
|
||||||
return sb.toString();
|
return sb.toString();
|
||||||
@ -463,7 +468,7 @@ public class DateUtil {
|
|||||||
int year = now.get(Calendar.YEAR);
|
int year = now.get(Calendar.YEAR);
|
||||||
int month = now.get(Calendar.MONTH) + 1;
|
int month = now.get(Calendar.MONTH) + 1;
|
||||||
int day = now.get(Calendar.DAY_OF_MONTH);
|
int day = now.get(Calendar.DAY_OF_MONTH);
|
||||||
String dayNames[] = {"星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"};
|
String[] dayNames = {"星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"};
|
||||||
int dayOfWeek = now.get(Calendar.DAY_OF_WEEK) - 1;
|
int dayOfWeek = now.get(Calendar.DAY_OF_WEEK) - 1;
|
||||||
if (dayOfWeek < 0) dayOfWeek = 0;
|
if (dayOfWeek < 0) dayOfWeek = 0;
|
||||||
String week = dayNames[dayOfWeek];
|
String week = dayNames[dayOfWeek];
|
||||||
@ -483,10 +488,33 @@ public class DateUtil {
|
|||||||
return String.valueOf(DateTime.now().getField(DateField.YEAR));
|
return String.valueOf(DateTime.now().getField(DateField.YEAR));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String orderNo2DateStr(String orderNo) {
|
||||||
|
|
||||||
|
return "20".concat(orderNo.substring(16, 18))
|
||||||
|
.concat("-").concat(orderNo.substring(18, 20))
|
||||||
|
.concat("-").concat(orderNo.substring(20, 22))
|
||||||
|
.concat(" ").concat(orderNo.substring(22, 24))
|
||||||
|
.concat(":").concat(orderNo.substring(24, 26))
|
||||||
|
.concat(":").concat(orderNo.substring(26, 28));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Date orderNo2Date(String orderNo) {
|
||||||
|
|
||||||
|
return yyyyMMDDhhmmss2Date("20".concat(orderNo.substring(16, 18)) //80836000010001012111251808140167
|
||||||
|
.concat("-").concat(orderNo.substring(18, 20))
|
||||||
|
.concat("-").concat(orderNo.substring(20, 22))
|
||||||
|
.concat(" ").concat(orderNo.substring(22, 24))
|
||||||
|
.concat(":").concat(orderNo.substring(24, 26))
|
||||||
|
.concat(":").concat(orderNo.substring(26, 28)));
|
||||||
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
// "80836000010001012110191723410021";
|
// "80836000010001012110191723410021";
|
||||||
// return operatorId.concat(DateUtil.getYYYY()).concat(orderNo.substring(17));
|
// return operatorId.concat(DateUtil.getYYYY()).concat(orderNo.substring(17));
|
||||||
System.out.println("80836000010001012110191723410021".substring(18));
|
// System.out.println("80836000010001012110191723410021".substring(18));
|
||||||
|
|
||||||
|
String pushOrderKey = "pushOrder:80836000010001012111251808140167";
|
||||||
|
System.out.println(orderNo2Date(pushOrderKey.substring(10)));
|
||||||
// DateUtil.isWeekend(new Date());
|
// DateUtil.isWeekend(new Date());
|
||||||
// DateUtil.isWeekend(DateUtil.string2Date("2016-06-08", "yyyy-MM-dd"));
|
// DateUtil.isWeekend(DateUtil.string2Date("2016-06-08", "yyyy-MM-dd"));
|
||||||
// DateUtil.isWeekend(DateUtil.string2Date("2016-06-09", "yyyy-MM-dd"));
|
// DateUtil.isWeekend(DateUtil.string2Date("2016-06-09", "yyyy-MM-dd"));
|
||||||
|
|||||||
@ -18,10 +18,10 @@ spring:
|
|||||||
nacos:
|
nacos:
|
||||||
discovery:
|
discovery:
|
||||||
# 服务注册地址
|
# 服务注册地址
|
||||||
server-addr: 127.0.0.1:8848
|
server-addr: 172.31.183.135:8848
|
||||||
config:
|
config:
|
||||||
# 配置中心地址
|
# 配置中心地址
|
||||||
server-addr: 127.0.0.1:8848
|
server-addr: 172.31.183.135:8848
|
||||||
# 配置文件格式
|
# 配置文件格式
|
||||||
file-extension: yml
|
file-extension: yml
|
||||||
# 共享配置
|
# 共享配置
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user