merge master

This commit is contained in:
panshuling321 2022-10-08 09:37:58 +08:00
commit a5e4b8b3a0
31 changed files with 1051 additions and 190 deletions

View File

@ -1,14 +1,29 @@
package com.xhpc.evcs.api;
import com.xhpc.common.api.dto.ChargingStationDto;
import com.xhpc.evcs.dto.*;
import com.xhpc.common.domain.XhpcTerminal;
import com.xhpc.evcs.dto.CommonRequest;
import com.xhpc.evcs.dto.CommonResponse;
import com.xhpc.evcs.dto.ConnectorStatusInfo;
import com.xhpc.evcs.dto.StationStatusInfo;
import com.xhpc.evcs.dto.StationStatusInfoWrapper;
import com.xhpc.evcs.dto.StationStatusRequest;
import com.xhpc.evcs.encryption.EvcsConst;
import com.xhpc.evcs.jpa.XhpcTerminalRepository;
import com.xhpc.evcs.utils.JSONUtil;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import java.util.*;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import static cn.hutool.core.util.NumberUtil.isInteger;
import static com.xhpc.common.data.redis.StaticBeanUtil.REDIS;
@ -16,6 +31,8 @@ import static com.xhpc.common.data.redis.StaticBeanUtil.REDIS;
@RestController
public class QueryStationStatusController {
@Resource
XhpcTerminalRepository terminalRepository;
@PostMapping("/v1/query_station_status")
public CommonResponse queryStationsInfo(@RequestBody CommonRequest<StationStatusRequest> commonRequest) throws Exception {
@ -46,6 +63,10 @@ public class QueryStationStatusController {
for (int i = 0; i < keys.length; i++) {
statusMap.put(keys[i], values[i]);
}
List<XhpcTerminal> terminalList = terminalRepository.selectStatusBySql();
Map<String,Integer> terminalDBMap = terminalList.stream().collect(Collectors.toMap(XhpcTerminal::getSerialNumber,XhpcTerminal::getStatus));
for (String stationID : stationIDs) {
ChargingStationDto chargingStationDto = REDIS.getCacheObject("station:" + stationID);
Set<String> pileIds = new HashSet<>();
@ -59,11 +80,20 @@ public class QueryStationStatusController {
if (pileId.equals(value.substring(0, 14))) {
existsGun = true;
ConnectorStatusInfo connectorStatusInfo = new ConnectorStatusInfo();
Object status = REDIS.getCacheMapValue("gun:" + value, "status");
if (isInteger(status.toString())) {
connectorStatusInfo.setStatus(3);
Integer gunStatus = terminalDBMap.get(value);
if (gunStatus == null){
existsGun = false;
} else {
connectorStatusInfo.setStatus(statusMap.get(status));
if (gunStatus == 0){
Object status = REDIS.getCacheMapValue("gun:" + value, "status");
if (isInteger(status.toString())) {
connectorStatusInfo.setStatus(3);
} else {
connectorStatusInfo.setStatus(statusMap.get(status));
}
} else {
connectorStatusInfo.setStatus(0);
}
}
connectorStatusInfo.setConnectorID(value);
connectorStatusInfos.add(connectorStatusInfo);

View File

@ -7,6 +7,7 @@ import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.QueryByExampleExecutor;
import org.springframework.stereotype.Repository;
import java.util.List;
import java.util.Optional;
/**
@ -31,4 +32,7 @@ public interface XhpcTerminalRepository extends JpaRepository<XhpcTerminal, Inte
@Query("select t.pileSerialNumber from XhpcTerminal as t where t.delFlag = 0 and t.serialNumber = ?1")
String selectBySql(String serialNumber);
@Query("select t.serialNumber, t.status from XhpcTerminal as t where t.delFlag = 0")
List<XhpcTerminal> selectStatusBySql();
}

View File

@ -76,6 +76,11 @@ public class NotificationChargeOrderInfo4BonusTask extends CoreDispatcher {
if (operatorIdEvcs == null) {
Long chargingStationId = xhpcHistoryOrder.getChargingStationId();
XhpcChargingStation station = chargingStationRepo.findById(chargingStationId).orElse(null);
if(station == null){
logger.error("station[{}] is not exits", chargingStationId);
return false;
}
String stationOperatorIdEvcs = station.getOperatorIdEvcs();
if (stationOperatorIdEvcs == null) {
logger.error("station[{}] operator id evcs not set", chargingStationId);

View File

@ -45,7 +45,13 @@ public class NotificationChargeOrderInfoTask extends CoreDispatcher {
Collection<String> orderKeys = REDIS.keys("order:*");
Instant now = Instant.now();
for (String okey : orderKeys) {
Date otime = DateUtil.orderNo2Date(okey.substring(6));
String orderNo = okey.substring(6);
if(orderNo.length() < 32){
logger.error("orderNo[{}] is error", orderNo);
continue;
}
Date otime = DateUtil.orderNo2Date(orderNo);
if (Duration.between(otime.toInstant(), now).toHours() > 24 * 3) {
REDIS.deleteObject(okey);
REDIS.deleteObject(okey.replace("order", "pushOrder"));

View File

@ -1,6 +1,7 @@
package com.xhpc.evcs.notification;
import com.xhpc.common.api.dto.ChargingStationDto;
import com.xhpc.common.domain.XhpcTerminal;
import com.xhpc.evcs.domain.AuthSecretToken;
import com.xhpc.evcs.domain.XhpcInternetUser;
import com.xhpc.evcs.domain.XhpcStationInternetBlacklist;
@ -10,6 +11,7 @@ import com.xhpc.evcs.dto.ConnectorStatusInfoReq;
import com.xhpc.evcs.jpa.AuthSecretTokenRepository;
import com.xhpc.evcs.jpa.XhpcInternetUserRepository;
import com.xhpc.evcs.jpa.XhpcStationInternetBlacklistRepository;
import com.xhpc.evcs.jpa.XhpcTerminalRepository;
import com.xhpc.evcs.utils.ChangePoleStatus;
import com.xhpc.evcs.utils.JSONUtil;
import lombok.extern.slf4j.Slf4j;
@ -17,13 +19,22 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.io.IOException;
import java.time.Instant;
import java.util.*;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import static com.xhpc.common.data.redis.StaticBeanUtil.REDIS;
import static com.xhpc.evcs.domain.AuthSecretToken.SECRET_TOKEN_TYPE_OUT;
import static com.xhpc.evcs.dto.ConnectorStatusInfo.*;
import static com.xhpc.evcs.dto.ConnectorStatusInfo.CHARGING;
import static com.xhpc.evcs.dto.ConnectorStatusInfo.ERROR;
import static com.xhpc.evcs.dto.ConnectorStatusInfo.FREE;
import static com.xhpc.evcs.dto.ConnectorStatusInfo.OFF_LINE;
@Component
@Slf4j
@ -35,12 +46,17 @@ public class NotificationStationStatusTask extends CoreDispatcher {
private XhpcInternetUserRepository xhpcInternetUserRepository;
@Autowired
private XhpcStationInternetBlacklistRepository xhpcStationInternetBlacklistRepo;
@Resource
private XhpcTerminalRepository terminalRepository;
@Scheduled(fixedRate = 1000 * 45)
protected void run() throws IOException {
Collection<String> stationTerminalKeys = REDIS.keys("stationTerminalStatus:*");
List<XhpcTerminal> terminalList = terminalRepository.selectStatusBySql();
Map<String,Integer> terminalDBMap = terminalList.stream().collect(Collectors.toMap(XhpcTerminal::getSerialNumber,XhpcTerminal::getStatus));
Instant now = Instant.now();
List<XhpcInternetUser> xhpcInternetUserList =
xhpcInternetUserRepository.findByCooperationStartTimeBeforeAndCooperationEndTimeAfter(now, now);
@ -49,7 +65,7 @@ public class NotificationStationStatusTask extends CoreDispatcher {
"station"));
String operatorId = chargingStationDto.getOperatorId();
Map<String, String> terminalStatusMap = REDIS.getCacheMap(stationTerminalKey);
Set<ConnectorStatusInfo> connectorStatusInfos = translateStatus(operatorId, terminalStatusMap);
Set<ConnectorStatusInfo> connectorStatusInfos = translateStatus(operatorId, terminalStatusMap, terminalDBMap);
Set<ConnectorStatusInfo> changeStatus = ChangePoleStatus.getChangeStatus(connectorStatusInfos);
if (!changeStatus.isEmpty()) {
for (XhpcInternetUser xhpcInternetUser : xhpcInternetUserList) {
@ -70,7 +86,7 @@ public class NotificationStationStatusTask extends CoreDispatcher {
}
}
private Set<ConnectorStatusInfo> translateStatus(String operatorId, Map<String, String> terminalStatusMap) {
private Set<ConnectorStatusInfo> translateStatus(String operatorId, Map<String, String> terminalStatusMap, Map<String, Integer> terminalDBMap) {
Set<ConnectorStatusInfo> connectorStatusInfoList = new HashSet<>();
final Set<String> connectorIds = terminalStatusMap.keySet();
@ -78,7 +94,12 @@ public class NotificationStationStatusTask extends CoreDispatcher {
ConnectorStatusInfo connectorStatusInfo = new ConnectorStatusInfo();
connectorStatusInfo.setConnectorID(gunId);
connectorStatusInfo.setOperatorID(operatorId);
connectorStatusInfo.setStatus(translateStatus(terminalStatusMap.get(gunId)));
Integer dbStatus = terminalDBMap.get(gunId);
if(dbStatus == 0){
connectorStatusInfo.setStatus(translateStatus(terminalStatusMap.get(gunId)));
} else {
connectorStatusInfo.setStatus(0);
}
connectorStatusInfoList.add(connectorStatusInfo);
}
return connectorStatusInfoList;

View File

@ -90,7 +90,7 @@ public class Constants
/**
* 令牌有效期分钟
*/
public final static long TOKEN_EXPIRE = 10;
public final static long TOKEN_EXPIRE = 60*24;
/**
* 参数管理 cache key

View File

@ -566,6 +566,7 @@
and find_in_set(tenant_id, #{tenantIdsStr})
</if>
order by create_time desc
LIMIT 50
</select>
</mapper>

View File

@ -83,4 +83,12 @@ public interface PileOrderService {
@GetMapping("/api/chargeOrder/pileVin")
R pileVin(@RequestParam(value = "serialNumber") String serialNumber,@RequestParam(value = "vinNumber") String vinNumber);
/**
* 桩订单实时订单BMS回调接口
* @param orderNo 订单号
* @return
*/
@GetMapping("/chargeOrder/pileRimeOrderBms")
R pileRimeOrderBms(@RequestParam(value = "orderNo") String orderNo);
}

View File

@ -59,6 +59,17 @@ public class PileOrderFallbackFactory implements FallbackFactory<PileOrderServic
public R pileVin(String serialNumber, String vinNumber) {
return R.fail(3886,"VIN码启动失败:" + cause.getMessage());
}
/**
* 桩订单实时订单BMS回调接口
*
* @param orderNo 订单号
* @return
*/
@Override
public R pileRimeOrderBms(String orderNo) {
return R.fail("充电过程 BMS 需求与充电机输出失败:" + cause.getMessage());
}
};
}

View File

@ -0,0 +1,143 @@
package com.xhpc.common.data.redis;
import com.xhpc.common.data.up.BaseData;
//充电桩与 BMS 充电过程 BMS 需求充电机输出
public class CacheBmsReqChargerOutputData extends BaseData {
private String orderNo; //交易流水号
private String pileNo; //桩号
private String gunId; //枪号
private Double bmsVoltageRequest; //BMS 电压需求
private Double bmsCurrentRequest; //BMS 电流需求
private Integer bmsChargingMod; //BMS 充电模式
private Double bmsChargingVolt; //BMS 充电电压测量值
private Double bmsChargingCurrent; //BMS 充电电流测量值
private Double monoBatteryVolt; //BMS 最高单体动力蓄电池电压
private Integer soc; //BMS 当前荷电状态 SOC %
private Integer bmsEstRemainingTime; //BMS 估算剩余充电时间
private Double pileVoltageOutput; //电桩电压输出值
private Double pileCurrentOutput; //电桩电流输出值
private Integer chargingTimeSummary; //累计充电时间
private Integer monoBatteryVoltGroupId; // BMS 最高单体动力蓄电池电压所在组号ID
public String getOrderNo() {
return orderNo;
}
public Double getMonoBatteryVolt() {
return monoBatteryVolt;
}
public void setMonoBatteryVolt(Double monoBatteryVolt) {
this.monoBatteryVolt = monoBatteryVolt;
}
public void setOrderNo(String orderNo) {
this.orderNo = orderNo;
}
public String getPileNo() {
return pileNo;
}
public void setPileNo(String pileNo) {
this.pileNo = pileNo;
}
public String getGunId() {
return gunId;
}
public void setGunId(String gunId) {
this.gunId = gunId;
}
public Double getBmsVoltageRequest() {
return bmsVoltageRequest;
}
public void setBmsVoltageRequest(Double bmsVoltageRequest) {
this.bmsVoltageRequest = bmsVoltageRequest;
}
public Double getBmsCurrentRequest() {
return bmsCurrentRequest;
}
public void setBmsCurrentRequest(Double bmsCurrentRequest) {
this.bmsCurrentRequest = bmsCurrentRequest;
}
public Integer getBmsChargingMod() {
return bmsChargingMod;
}
public void setBmsChargingMod(Integer bmsChargingMod) {
this.bmsChargingMod = bmsChargingMod;
}
public Double getBmsChargingVolt() {
return bmsChargingVolt;
}
public void setBmsChargingVolt(Double bmsChargingVolt) {
this.bmsChargingVolt = bmsChargingVolt;
}
public Double getBmsChargingCurrent() {
return bmsChargingCurrent;
}
public void setBmsChargingCurrent(Double bmsChargingCurrent) {
this.bmsChargingCurrent = bmsChargingCurrent;
}
public Integer getMonoBatteryVoltGroupId() {
return monoBatteryVoltGroupId;
}
public void setMonoBatteryVoltGroupId(Integer monoBatteryVoltGroupId) {
this.monoBatteryVoltGroupId = monoBatteryVoltGroupId;
}
public Integer getSoc() {
return soc;
}
public void setSoc(Integer soc) {
this.soc = soc;
}
public Integer getBmsEstRemainingTime() {
return bmsEstRemainingTime;
}
public void setBmsEstRemainingTime(Integer bmsEstRemainingTime) {
this.bmsEstRemainingTime = bmsEstRemainingTime;
}
public Double getPileVoltageOutput() {
return pileVoltageOutput;
}
public void setPileVoltageOutput(Double pileVoltageOutput) {
this.pileVoltageOutput = pileVoltageOutput;
}
public Double getPileCurrentOutput() {
return pileCurrentOutput;
}
public void setPileCurrentOutput(Double pileCurrentOutput) {
this.pileCurrentOutput = pileCurrentOutput;
}
public Integer getChargingTimeSummary() {
return chargingTimeSummary;
}
public void setChargingTimeSummary(Integer chargingTimeSummary) {
this.chargingTimeSummary = chargingTimeSummary;
}
}

View File

@ -1,5 +1,9 @@
package com.xhpc.common.enums;
import java.util.Arrays;
import java.util.Map;
import java.util.stream.Collectors;
/**
* @author yuyang
* @date 2022/8/5 16:44
@ -79,6 +83,15 @@ public enum StopReasonEnum {
private final String code;
private final String name;
public String getCode(){
return code;
}
public String getName(){
return name;
}
StopReasonEnum(String code, String name){
this.code = code;
this.name = name;
@ -94,4 +107,9 @@ public enum StopReasonEnum {
return "";
}
public static Map<String, String> getMap(){
return Arrays.stream(StopReasonEnum.values()).collect(Collectors.toMap(StopReasonEnum::getCode, StopReasonEnum::getName));
}
}

View File

@ -9,6 +9,7 @@ import com.xhpc.common.api.WebSocketService;
import com.xhpc.common.api.WorkOrderYuService;
import com.xhpc.common.core.domain.R;
import com.xhpc.common.core.web.controller.BaseController;
import com.xhpc.common.data.redis.CacheBmsReqChargerOutputData;
import com.xhpc.common.data.redis.CacheOrderData;
import com.xhpc.common.data.redis.CacheRealtimeData;
import com.xhpc.common.domain.XhpcRate;
@ -802,4 +803,23 @@ public R pileStartUpBy3rd(@RequestParam(value = "internetSerialNumber") String i
workOrderYuService.addNewOrder("28","有异常订单订单且该桩进行校时效价处理","定时任务自动扫描异常订单","","","","");
}
/**
* 桩实时数据BMS回调接口
* @param orderNo 订单号
* @return
*/
@Transactional
@GetMapping("/chargeOrder/pileRimeOrderBms")
public R pileRimeOrderBms(@RequestParam(value = "orderNo")String orderNo) {
logger.info("桩实时数据BMS回调接口>>>>>orderNo" + orderNo);
//获取实时订单
xhpcRealTimeOrderService.addRealTimeOrderBms(orderNo);
return R.ok();
}
}

View File

@ -77,17 +77,57 @@ public class XhpcRealTimeOrderController extends BaseController {
return getDataTable(list);
}
@GetMapping("/timeBmsList")
public TableDataInfo timeBmsList(@RequestParam Long chargingOrderId)
{
startPage();
List<Map<String,Object>> list = xhpcRealTimeOrderService.timeBmsList(chargingOrderId);
return getDataTable(list);
}
/**
* 实时/异常订单详情数据图表PC
* @param chargingOrderId
* @return
*/
@GetMapping("/timeChartList")
public AjaxResult timeChartList(@RequestParam Long chargingOrderId)
// @GetMapping("/timeChartList")
// public AjaxResult timeChartList(@RequestParam Long chargingOrderId)
// {
// return xhpcRealTimeOrderService.timeChartList(chargingOrderId);
// }
/**
* 实时/异常订单详情数据电压图表PC
* @param chargingOrderId
* @return
*/
@GetMapping("/timeChartListVoltage")
public AjaxResult timeChartListVoltage(@RequestParam Long chargingOrderId)
{
return xhpcRealTimeOrderService.timeChartList(chargingOrderId);
return xhpcRealTimeOrderService.timeChartListVoltage(chargingOrderId);
}
/**
* 实时/异常订单详情数据电流图表PC
* @param chargingOrderId
* @return
*/
@GetMapping("/timeChartListCurrent")
public AjaxResult timeChartListCurrent(@RequestParam Long chargingOrderId)
{
return xhpcRealTimeOrderService.timeChartListCurrent(chargingOrderId);
}
/**
* 实时/异常订单详情数据soc图表PC
* @param chargingOrderId
* @return
*/
@GetMapping("/timeChartListSoc")
public AjaxResult timeChartListSoc(@RequestParam Long chargingOrderId)
{
return xhpcRealTimeOrderService.timeChartListSoc(chargingOrderId);
}
/**
*异常订单审核详情
*/

View File

@ -0,0 +1,33 @@
package com.xhpc.order.domain;
import com.xhpc.common.core.web.domain.BaseEntity;
import lombok.Data;
/**
* @author yuyang
* @date 2022/8/31 17:32
*/
@Data
public class XhpcRealTimeOrderBms extends BaseEntity {
private Long realTimeOrderBmsId;
private String orderNo; //交易流水号
private String pileNo; //桩号
private String gunId; //枪号
private Double bmsVoltageRequest; //BMS 电压需求
private Double bmsCurrentRequest; //BMS 电流需求
private Integer bmsChargingMod; //BMS 充电模式
private Double bmsChargingVolt; //BMS 充电电压测量值
private Double bmsChargingCurrent; //BMS 充电电流测量值
private Double monoBatteryVolt; //BMS 最高单体动力蓄电池电压
private Integer soc; //BMS 当前荷电状态 SOC %
private String bmsEstRemainingTime; //BMS 估算剩余充电时间
private Double pileVoltageOutput; //电桩电压输出值
private Double pileCurrentOutput; //电桩电流输出值
private String chargingTimeSummary; //累计充电时间
private Integer monoBatteryVoltGroupId; // BMS 最高单体动力蓄电池电压所在组号ID
private Long chargingOrderId;
}

View File

@ -142,7 +142,6 @@ public interface XhpcChargeOrderMapper {
*/
void addXhpcOrderRedisRecord(XhpcOrderRedisRecord xhpcOrderRedisRecord);
/**
* 添加流水
* @param userId 用户id

View File

@ -134,4 +134,7 @@ public interface XhpcHistoryOrderMapper {
* 查询启动订单表
*/
Map<String, Object> getchargingOrderById(@Param("chargingOrderId")Long chargingOrderId,@Param("userId")Long userId,@Param("source")Integer source,@Param("tenantId")String tenantId);
//获取跨天最后一帧数据
Map<String, Object> getXhpcRealTimeOrderTwentyFour(@Param("chargingOrderId")Long chargingOrderId,@Param("time")String time);
}

View File

@ -1,9 +1,6 @@
package com.xhpc.order.mapper;
import com.xhpc.order.domain.XhpcChargeOrderCurrent;
import com.xhpc.order.domain.XhpcChargeOrderSoc;
import com.xhpc.order.domain.XhpcChargeOrderVoltage;
import com.xhpc.order.domain.XhpcRealTimeOrder;
import com.xhpc.order.domain.*;
import com.xhpc.order.dto.RateTime;
import com.xhpc.order.dto.XhpcActivityDiscountDto;
import com.xhpc.order.dto.XhpcActivityFormulaDomainDto;
@ -27,7 +24,12 @@ public interface XhpcRealTimeOrderMapper {
*/
int insertXhpcRealTimeOrder(XhpcRealTimeOrder xhpcRealTimeOrder);
/**
* 添加实时充电订单
* @param xhpcRealTimeOrderBms
* @return
*/
int insertRealTimeOrderBms(XhpcRealTimeOrderBms xhpcRealTimeOrderBms);
/**
* 添加订单实时SOC
* @param xhpcChargeOrderSoc
@ -73,6 +75,10 @@ public interface XhpcRealTimeOrderMapper {
*/
Map<String,Object> getMessage(@Param("realTimeOrderId")Long realTimeOrderId);
/**
* 获取场站信息
*/
Map<String,Object> getXhpcChargingStationById(Long chargingStationId);
/**
* 异常订单详情接口(PC端)
* @param chargeOrderId
@ -88,6 +94,13 @@ public interface XhpcRealTimeOrderMapper {
*/
List<Map<String,Object>> timeList(@Param("chargingOrderId")Long chargingOrderId);
/**
* 实时订单详情数据列表BMSPC
* @param chargingOrderId
* @return
*/
List<Map<String,Object>> timeBmsList(@Param("chargingOrderId")Long chargingOrderId);
/**
* 实时订单详情数据图表SOCPC
* @param chargingOrderId

View File

@ -47,12 +47,30 @@ public interface IXhpcRealTimeOrderService {
*/
List<Map<String,Object>> timeList(Long chargingOrderId);
/**
* 实时订单详情数据列表PC
* @param chargingOrderId 充电订单id
* @return
*/
List<Map<String,Object>> timeBmsList(Long chargingOrderId);
/**
* 实时订单详情数据图表PC
* @param chargingOrderId
* @return
*/
AjaxResult timeChartList(Long chargingOrderId);
AjaxResult timeChartListVoltage(Long chargingOrderId);
/**
* 实时订单详情数据图表PC
* @param chargingOrderId
* @return
*/
AjaxResult timeChartListCurrent(Long chargingOrderId);
/**
* 实时订单详情数据图表PC
* @param chargingOrderId
* @return
*/
AjaxResult timeChartListSoc(Long chargingOrderId);
/**
* 删除之前的实时订单数据
@ -149,4 +167,11 @@ public interface IXhpcRealTimeOrderService {
* 添加一条金额为0的数据
*/
void addZeroHistoryOrder(XhpcChargeOrder xhpcChargeOrder);
/**
* 添加一条实时订单的BMS
*/
void addRealTimeOrderBms(String orderNo);
}

View File

@ -9,6 +9,7 @@ import com.xhpc.common.core.utils.StringUtils;
import com.xhpc.common.core.web.domain.AjaxResult;
import com.xhpc.common.core.web.service.BaseService;
import com.xhpc.common.data.down.StartChargingData;
import com.xhpc.common.data.redis.CacheBmsReqChargerOutputData;
import com.xhpc.common.data.redis.CacheRealtimeData;
import com.xhpc.common.data.redis.StaticBeanUtil;
import com.xhpc.common.domain.XhpcRate;
@ -440,6 +441,7 @@ public class XhpcChargeOrderServiceImpl extends BaseService implements IXhpcChar
xhpcChargeOrderMapper.addXhpcOrderRedisRecord(xhpcOrderRedisRecord);
}
@Override
public int addUserAccountStatement(Long userId, BigDecimal amount, BigDecimal remainingSum, Long chargeOrderId,
Integer type, Date date,Integer source) {
@ -507,13 +509,14 @@ public class XhpcChargeOrderServiceImpl extends BaseService implements IXhpcChar
//终端信息
XhpcTerminal xhpcTerminal = xhpcChargeOrderMapper.getXhpcTerminalSerialNumber(connectorId,null);
if (xhpcTerminal == null || xhpcTerminal.getTerminalId() == null || xhpcTerminal.getChargingPileId() == null || xhpcTerminal.getPileSerialNumber() == null) {
r.setCode(1);
String pilePrompt = redisService.getCacheObject("pilePrompt:000000");
if(!"".equals(pilePrompt) && pilePrompt !=null){
r.setMsg(pilePrompt);
}else{
r.setMsg("因限电该桩已停用,请选择其他桩进行充电");
}
r.setCode(500);
// String pilePrompt = redisService.getCacheObject("pilePrompt:000000");
// if(!"".equals(pilePrompt) && pilePrompt !=null){
// r.setMsg(pilePrompt);
// }else{
// r.setMsg("因限电该桩已停用,请选择其他桩进行充电");
// }
r.setMsg("因限电该桩已停用请选择其他桩进行充电");
return r;
}
//终端状态是否空闲

View File

@ -12,6 +12,7 @@ import com.xhpc.common.core.utils.SecurityUtils;
import com.xhpc.common.core.web.domain.AjaxResult;
import com.xhpc.common.core.web.service.BaseService;
import com.xhpc.common.data.redis.CacheRealtimeData;
import com.xhpc.common.enums.StopReasonEnum;
import com.xhpc.common.redis.service.RedisService;
import com.xhpc.common.security.service.TokenService;
import com.xhpc.common.util.UserTypeUtil;
@ -363,6 +364,9 @@ public class XhpcHistoryOrderServiceImpl extends BaseService implements IXhpcHis
list = xhpcHistoryOrderMapper.getListPage(chargingStationId,chargingPileId,terminalId,phone, transactionNumber, 0, chargingStationName, operatorId, source, beginStartTime, beginEndTime, userId, type, number,affiliationOrganization,evcsOrderNo,plateNum,internetId,internetSerialNumber,terminalName,vinCode,overStartTime,overEndTime,personnelId,confirmResult,tenantId,1);
}
Map<String, String> reasonMap = StopReasonEnum.getMap();
list.stream().forEach(map->map.put("stopReasonEvcsStr", reasonMap.get(map.get("stopReasonEvcs"))));
// 通过工具类创建writer默认创建xls格式
BigExcelWriter writer = ExcelUtil.getBigWriter("HistoryOrder_" + System.currentTimeMillis() + ".xlsx");
writer.addHeaderAlias("historyOrderId", "历史订单ID");
@ -406,7 +410,8 @@ public class XhpcHistoryOrderServiceImpl extends BaseService implements IXhpcHis
writer.addHeaderAlias("endTime", "结束充电时间");
writer.addHeaderAlias("updateTime", "结算时间");
writer.addHeaderAlias("chargingModeName", "订单来源");
writer.addHeaderAlias("stopReasonEvcs", "停止原因");
writer.addHeaderAlias("stopReasonEvcs", "停止原因代码");
writer.addHeaderAlias("stopReasonEvcsStr", "停止原因说明");
writer.addHeaderAlias("sourceName", "用户类型");
// writer.addHeaderAlias("plateNum", "电站名称");
@ -514,7 +519,12 @@ public class XhpcHistoryOrderServiceImpl extends BaseService implements IXhpcHis
if(map !=null){
BigDecimal powerPriceTotal = new BigDecimal(map.get("powerPriceTotal").toString());
BigDecimal servicePriceTotal = new BigDecimal(map.get("servicePriceTotal").toString());
xhpcRealTimeOrderService.getExamine(chargeOrderId,powerPriceTotal,servicePriceTotal,null,null,null);
BigDecimal chargingDegree = new BigDecimal(map.get("chargingDegree").toString());
if(map.get("startTime")!=null && map.get("endTime")!=null){
xhpcRealTimeOrderService.getExamine(chargeOrderId,powerPriceTotal,servicePriceTotal,chargingDegree,map.get("startTime").toString(),map.get("endTime").toString());
}else{
xhpcRealTimeOrderService.getExamine(chargeOrderId,powerPriceTotal,servicePriceTotal,chargingDegree,null,null);
}
}
}
@ -531,6 +541,7 @@ public class XhpcHistoryOrderServiceImpl extends BaseService implements IXhpcHis
BigDecimal powerPriceTotal = new BigDecimal(0);
BigDecimal servicePriceTotal = new BigDecimal(0);
BigDecimal divide = new BigDecimal(totalPower);
//累计充电时间计费模型开始时间结束时间已充金额
XhpcChargeOrder chargeOrder = xhpcChargeOrderService.getSerialNumberMessage(serialNumber);
Long rateModelId = chargeOrder.getRateModelId();
@ -540,24 +551,64 @@ public class XhpcHistoryOrderServiceImpl extends BaseService implements IXhpcHis
BigDecimal chargingDegree = new BigDecimal(totalPower);
List<Map<String, Object>> list = new ArrayList<>();
//1时间没有跨天
long betweenDay = DateUtil.between(startTime2, updateTime2, DateUnit.DAY);
DateTime parse = DateUtil.parse(DateUtil.format(startTime2, "yyyy-MM-dd"), "yyyy-MM-dd");
DateTime parse1 = DateUtil.parse(DateUtil.format(updateTime2, "yyyy-MM-dd"), "yyyy-MM-dd");
long betweenDay = DateUtil.between(parse, parse1, DateUnit.DAY);
if (betweenDay == 0) {
return getBigDecimal(totalPrice, powerPriceTotal, servicePriceTotal, chargeOrder, rateModelId, startTime2, updateTime2, chargingDegree, list);
} else {
//跨天
//当天晚上时间 23:59:59
Map<String, Object> map =new HashMap<>();
Date updateTime = DateUtil.endOfDay(startTime2);
Map<String, Object> map1 = getBigDecimal(totalPrice, powerPriceTotal, servicePriceTotal, chargeOrder, rateModelId, startTime2, updateTime, chargingDegree, list);
//获取
// BigDecimal powerPriceTotal1 = new BigDecimal(map1.get("powerPriceTotal").toString());
// BigDecimal servicePriceTotal1 = new BigDecimal(map1.get("servicePriceTotal").toString());
//明天
String format = DateUtil.format(updateTime, "yyyy-MM-dd HH:mm:ss");
DateTime tomorrow = DateUtil.offsetDay(startTime2, 1);
Date startTime3 = DateUtil.beginOfDay(tomorrow);
Map<String, Object> map2 = getBigDecimal(totalPrice, powerPriceTotal, servicePriceTotal, chargeOrder, rateModelId, startTime3, updateTime2, chargingDegree, list);
return map2;
Map<String, Object> twentyFour = xhpcHistoryOrderMapper.getXhpcRealTimeOrderTwentyFour(chargeOrder.getChargeOrderId(), format);
if(twentyFour !=null && twentyFour.get("chargingDegree")!=null){
BigDecimal chargingDegree1 = new BigDecimal(twentyFour.get("chargingDegree").toString());
BigDecimal decimal = divide.subtract(chargingDegree1);
if(chargingDegree1.compareTo(new BigDecimal(0))==0){
String start = DateUtil.formatTime(updateTime);
Map<String, Object> map1 = new HashMap<>();
map1.put("time", start+"-23:59:59");
map1.put("powerPrice", 0);
map1.put("servicePrice", 0);
map1.put("chargingDegree", 0);
map1.put("actPrice", 0);
list.add(map1);
map.put("list", list);//数据列表
map.putAll(getBigDecimal(totalPrice, powerPriceTotal, servicePriceTotal, chargeOrder, rateModelId, startTime3, updateTime2, chargingDegree, list));
return map;
}else if(decimal.compareTo(new BigDecimal(0))==1){
map =getBigDecimal(totalPrice, powerPriceTotal, servicePriceTotal, chargeOrder, rateModelId, startTime2, updateTime, chargingDegree1, list);
map.putAll(getBigDecimal(totalPrice, powerPriceTotal, servicePriceTotal, chargeOrder, rateModelId, startTime3, updateTime2, decimal, list));;
return map;
}else{
String end = DateUtil.formatTime(updateTime2);
map.putAll(getBigDecimal(totalPrice, powerPriceTotal, servicePriceTotal, chargeOrder, rateModelId, startTime2, updateTime, chargingDegree, list));
Map<String, Object> map1 = new HashMap<>();
map1.put("time", "00:00:00-"+end);
map1.put("powerPrice", 0);
map1.put("servicePrice", 0);
map1.put("chargingDegree", 0);
map1.put("actPrice", 0);
list.add(map1);
map.put("list", list);//
return map;
}
}
return null;
}
}
private Map<String, Object> getBigDecimal(String totalPrice, BigDecimal powerPriceTotal, BigDecimal servicePriceTotal, XhpcChargeOrder chargeOrder, Long rateModelId, Date startTime2, Date updateTime2, BigDecimal chargingDegree, List<Map<String, Object>> list) {
Map<String, Object> map = new HashMap<>();
@ -777,4 +828,5 @@ public class XhpcHistoryOrderServiceImpl extends BaseService implements IXhpcHis
return sr;
// }
}
}

View File

@ -11,8 +11,10 @@ import com.xhpc.common.core.domain.R;
import com.xhpc.common.core.utils.SecurityUtils;
import com.xhpc.common.core.web.domain.AjaxResult;
import com.xhpc.common.core.web.service.BaseService;
import com.xhpc.common.data.redis.CacheBmsReqChargerOutputData;
import com.xhpc.common.data.redis.CacheOrderData;
import com.xhpc.common.data.redis.CacheRealtimeData;
import com.xhpc.common.domain.XhpcRate;
import com.xhpc.common.enums.StopReasonEnum;
import com.xhpc.common.redis.service.RedisService;
import com.xhpc.common.security.service.TokenService;
@ -134,11 +136,28 @@ public class XhpcRealTimeOrderServiceImpl extends BaseService implements IXhpcRe
}
@Override
public AjaxResult timeChartList(Long chargingOrderId) {
public List<Map<String, Object>> timeBmsList(Long chargingOrderId) {
return xhpcRealTimeOrderMapper.timeBmsList(chargingOrderId);
}
@Override
public AjaxResult timeChartListVoltage(Long chargingOrderId) {
Map<String,Object> map =new HashMap();
map.put("voltage",xhpcRealTimeOrderMapper.timeChartVoltageList(chargingOrderId));
return AjaxResult.success(map);
}
@Override
public AjaxResult timeChartListCurrent(Long chargingOrderId) {
Map<String,Object> map =new HashMap();
map.put("current",xhpcRealTimeOrderMapper.timeChartCurrentList(chargingOrderId));
return AjaxResult.success(map);
}
@Override
public AjaxResult timeChartListSoc(Long chargingOrderId) {
Map<String,Object> map =new HashMap();
map.put("soc",xhpcRealTimeOrderMapper.timeChartSOCList(chargingOrderId));
map.put("voltage",xhpcRealTimeOrderMapper.timeChartVoltageList(chargingOrderId));
map.put("current",xhpcRealTimeOrderMapper.timeChartCurrentList(chargingOrderId));
return AjaxResult.success(map);
}
@ -147,6 +166,40 @@ public class XhpcRealTimeOrderServiceImpl extends BaseService implements IXhpcRe
return xhpcRealTimeOrderMapper.insertXhpcRealTimeOrder(xhpcRealTimeOrder);
}
/**
* 添加一条实时订单的BMS
*
* @param orderNo
*/
@Override
public void addRealTimeOrderBms(String orderNo) {
CacheBmsReqChargerOutputData cacheBmsReqChargerOutputData = redisService.getCacheObject("order:" + orderNo + ".bms");
if(cacheBmsReqChargerOutputData !=null){
XhpcRealTimeOrderBms xhpcRealTimeOrderBms = new XhpcRealTimeOrderBms();
BeanUtils.copyProperties(cacheBmsReqChargerOutputData, xhpcRealTimeOrderBms);
Integer bmsEstRemainingTime = cacheBmsReqChargerOutputData.getBmsEstRemainingTime();
Integer chargingTimeSummary = cacheBmsReqChargerOutputData.getChargingTimeSummary();
if (bmsEstRemainingTime > 60) {
Integer hours = bmsEstRemainingTime / 60;
Integer mins = bmsEstRemainingTime - (hours * 60);
xhpcRealTimeOrderBms.setBmsEstRemainingTime(hours + "" + mins + "");
} else {
xhpcRealTimeOrderBms.setBmsEstRemainingTime(bmsEstRemainingTime + "");
}
if (chargingTimeSummary > 60) {
Integer hours = chargingTimeSummary / 60;
Integer mins = chargingTimeSummary - (hours * 60);
xhpcRealTimeOrderBms.setChargingTimeSummary(hours + "" + mins + "");
} else {
xhpcRealTimeOrderBms.setChargingTimeSummary(chargingTimeSummary + "");
}
XhpcChargeOrder xhpcChargeOrder = xhpcChargeOrderService.getSerialNumberMessage(orderNo);
xhpcRealTimeOrderBms.setChargingOrderId(xhpcChargeOrder.getChargeOrderId());
xhpcRealTimeOrderMapper.insertRealTimeOrderBms(xhpcRealTimeOrderBms);
}
}
@Override
public int addSOC(XhpcChargeOrderSoc xhpcChargeOrderSoc) {
return xhpcRealTimeOrderMapper.insertSOC(xhpcChargeOrderSoc);
@ -165,7 +218,6 @@ public class XhpcRealTimeOrderServiceImpl extends BaseService implements IXhpcRe
@Transactional
@Override
public Map<String, Object> getExamineMessage(Long realTimeOrderId,Long chargeOrderId) {
if(realTimeOrderId==null){
Map<String, Object> message = xhpcRealTimeOrderMapper.getMessageChargeOrderId(chargeOrderId);
message.put("powerPriceTotal",0);
@ -175,145 +227,254 @@ public class XhpcRealTimeOrderServiceImpl extends BaseService implements IXhpcRe
//基本信息
Map<String, Object> message = xhpcRealTimeOrderMapper.getMessage(realTimeOrderId);
try{
if(message ==null || message.get("chargeOrderId") ==null){
XhpcChargeOrder chargeOrder = xhpcChargeOrderService.getChargingOrderId(Long.parseLong(message.get("chargeOrderId").toString()));
Map<String, Object> cacheMap = redisService.getCacheMap("order:" + chargeOrder.getSerialNumber());
if (cacheMap !=null && cacheMap.get("startTime")!=null && cacheMap.get("lastOrderTime")!=null) {
String startTime = cacheMap.get("startTime").toString();
String lastOrderTime = cacheMap.get("lastOrderTime").toString();
chargeOrder.setStartTime(DateUtil.parse(startTime));
chargeOrder.setEndTime(DateUtil.parse(lastOrderTime));
message.put("startTime",startTime);
message.put("endTime",lastOrderTime);
if (cacheMap.get("totalPower")!=null && cacheMap.get("totalMoney")!=null) {
String totalPower = cacheMap.get("totalPower").toString();
//String totalPowerSub = totalPower.substring(0, totalPower.length() - 1);
String totalMoney = cacheMap.get("totalMoney").toString();
//String totalMoneySub = totalMoney.substring(0, totalMoney.length() - 1);
chargeOrder.setChargingDegree(new BigDecimal(totalPower));
chargeOrder.setAmountCharged(new BigDecimal(totalMoney));
message.put("chargingDegree",new BigDecimal(totalPower));
}
}
if(message.get("chargeOrderId") == null){
message.put("powerPriceTotal",0);
message.put("servicePriceTotal",0);
return message;
}
//获取开始充电时间结束时间计费模型充电度数已充金额
XhpcChargeOrder chargeOrder = xhpcChargeOrderService.getChargingOrderId(Long.parseLong(message.get("chargeOrderId").toString()));
//获取该订单最后一条实时数据
Map<String, Object> cacheMap = redisService.getCacheMap("order:" + chargeOrder.getSerialNumber());
List<CacheRealtimeData> list = (List<CacheRealtimeData>) cacheMap.get("realtimeDataList");
CacheRealtimeData startData =new CacheRealtimeData();
CacheRealtimeData endData =new CacheRealtimeData();
if (list != null && list.size() > 0) {
endData =list.get(list.size()-1);
for (int i = 0; i <list.size() ; i++) {
startData =list.get(i);
if(startData.getAmountCharged()>0 && startData.getChargingTime()>0){
break;
}
}
if(chargeOrder.getRateModelId()==null || "".equals(chargeOrder.getRateModelId().toString())){
Map<String, Object> xhpcChargingStationMap = xhpcRealTimeOrderMapper.getXhpcChargingStationById(chargeOrder.getChargingStationId());
chargeOrder.setRateModelId(Long.valueOf(xhpcChargingStationMap.get("rateModelId").toString()));
}
//获取该订单最后一条实时数据
Long rateModelId = chargeOrder.getRateModelId();
if(endData !=null && endData.getAmountCharged() !=null && startData.getChargingTime()>0){
message.put("soc",endData.getSoc());
//最后一祯时间
Date endTime = DateUtil.parse(endData.getCreateTime());
Date startTime =DateUtil.parse(startData.getCreateTime());
//充电时长
Long tiem = (endTime.getTime() - startTime.getTime()) / 1000;
if (tiem > 3600) {
long hours = tiem / 3600;
double mins = (double) ((tiem - (hours * 3600)) / 60);
message.put("chargingTime",hours + "" + new BigDecimal(mins).setScale(0) + "");
chargeOrder.setChargingTime(hours + "" + new BigDecimal(mins).setScale(0) + "");
} else {
double mins = (double) (tiem / 60);
message.put("chargingTime",new BigDecimal(mins).setScale(0) + "");
chargeOrder.setChargingTime(new BigDecimal(mins).setScale(0) + "");
if(cacheMap !=null && cacheMap.get("orderData") !=null){
CacheOrderData cacheOrderData = (CacheOrderData)cacheMap.get("orderData");
BigDecimal bigDecimal = new BigDecimal(10000);
BigDecimal money = new BigDecimal(cacheOrderData.getCost()).divide(bigDecimal,2,BigDecimal.ROUND_HALF_UP);
//00: 尖费率 01: 峰费率 02: 平费率 03: 谷费率
BigDecimal t1powerFee =new BigDecimal(0);
BigDecimal t2powerFee =new BigDecimal(0);
BigDecimal t3powerFee =new BigDecimal(0);
BigDecimal t4powerFee =new BigDecimal(0);
BigDecimal t1serviceFee =new BigDecimal(0);
BigDecimal t2serviceFee =new BigDecimal(0);
BigDecimal t3serviceFee =new BigDecimal(0);
BigDecimal t4serviceFee =new BigDecimal(0);
//费率计费模型
List<XhpcRate> rateModelList = xhpcChargeOrderService.getRateModelId(rateModelId);
for (XhpcRate xhpcRate:rateModelList) {
if("00".equals(xhpcRate.getRateValue())){
t1powerFee = xhpcRate.getPowerFee();
t1serviceFee =xhpcRate.getServiceFee();
}
if("01".equals(xhpcRate.getRateValue())){
t2powerFee = xhpcRate.getPowerFee();
t2serviceFee =xhpcRate.getServiceFee();
}
if("02".equals(xhpcRate.getRateValue())){
t3powerFee = xhpcRate.getPowerFee();
t3serviceFee = xhpcRate.getServiceFee();
}
if("03".equals(xhpcRate.getRateValue())){
t4powerFee = xhpcRate.getPowerFee();
t4serviceFee =xhpcRate.getServiceFee();
}
}
BigDecimal chargingDegree = new BigDecimal(endData.getChargingDegree()).divide(new BigDecimal(10000), 2, BigDecimal.ROUND_HALF_UP);
message.put("chargingDegree",chargingDegree);
chargeOrder.setStartTime(startTime);
chargeOrder.setEndTime(endTime);
chargeOrder.setStartSoc(startData.getSoc().toString());
chargeOrder.setEndSoc(endData.getSoc().toString());
chargeOrder.setChargingTimeNumber(tiem);
chargeOrder.setChargingDegree(chargingDegree);
chargeOrder.setType("平台停止");
chargeOrder.setAmountCharged(new BigDecimal(endData.getAmountCharged()).divide(new BigDecimal(10000),2,BigDecimal.ROUND_HALF_UP));
BigDecimal powerPrice =new BigDecimal(0);
BigDecimal servicePrice =new BigDecimal(0);
//因桩有误差电费和服务费重新计算
if(!"0".equals(cacheOrderData.getT1PowerQuantity().toString())){
BigDecimal multiply1 = new BigDecimal(cacheOrderData.getT1PowerQuantity()).divide(bigDecimal).multiply(t1powerFee).setScale(2, BigDecimal.ROUND_HALF_UP);
BigDecimal multiply2 = new BigDecimal(cacheOrderData.getT1PowerQuantity()).divide(bigDecimal).multiply(t1serviceFee).setScale(2, BigDecimal.ROUND_HALF_UP);
powerPrice=powerPrice.add(multiply1);
servicePrice=servicePrice.add(multiply2);
}
if(!"0".equals(cacheOrderData.getT2PowerQuantity().toString())){
BigDecimal multiply1 = new BigDecimal(cacheOrderData.getT2PowerQuantity()).divide(bigDecimal).multiply(t2powerFee).setScale(2, BigDecimal.ROUND_HALF_UP);
BigDecimal multiply2 = new BigDecimal(cacheOrderData.getT2PowerQuantity()).divide(bigDecimal).multiply(t2serviceFee).setScale(2, BigDecimal.ROUND_HALF_UP);
powerPrice=powerPrice.add(multiply1);
servicePrice=servicePrice.add(multiply2);
}
if(!"0".equals(cacheOrderData.getT3PowerQuantity().toString())){
BigDecimal multiply1 = new BigDecimal(cacheOrderData.getT3PowerQuantity()).divide(bigDecimal).multiply(t3powerFee).setScale(2, BigDecimal.ROUND_HALF_UP);
BigDecimal multiply2 = new BigDecimal(cacheOrderData.getT3PowerQuantity()).divide(bigDecimal).multiply(t3serviceFee).setScale(2, BigDecimal.ROUND_HALF_UP);
powerPrice=powerPrice.add(multiply1);
servicePrice=servicePrice.add(multiply2);
}
if(!"0".equals(cacheOrderData.getT4PowerQuantity().toString())){
BigDecimal multiply1 = new BigDecimal(cacheOrderData.getT4PowerQuantity()).divide(bigDecimal).multiply(t4powerFee).setScale(2, BigDecimal.ROUND_HALF_UP);
BigDecimal multiply2 = new BigDecimal(cacheOrderData.getT4PowerQuantity()).divide(bigDecimal).multiply(t4serviceFee).setScale(2, BigDecimal.ROUND_HALF_UP);
powerPrice=powerPrice.add(multiply1);
servicePrice=servicePrice.add(multiply2);
}
powerPrice =powerPrice.setScale(2,BigDecimal.ROUND_HALF_UP);
//总服务费
servicePrice =servicePrice.setScale(2,BigDecimal.ROUND_HALF_UP);
message.put("powerPriceTotal",powerPrice);
message.put("servicePriceTotal",servicePrice);
chargeOrder.setStartTime(DateUtil.parse(cacheOrderData.getStartTime()));
chargeOrder.setEndTime(DateUtil.parse(cacheOrderData.getEndTime()));
if(cacheOrderData.getStartSoc() !=null){
chargeOrder.setStartSoc(cacheOrderData.getStartSoc()+"");
}
if(cacheOrderData.getEndTime() !=null){
chargeOrder.setEndSoc(cacheOrderData.getEndSoc()+"");
}
if(cacheOrderData.getTotalPowerQuantity() !=null){
BigDecimal chargingDegree1 = new BigDecimal(cacheOrderData.getTotalPowerQuantity()).divide(bigDecimal,2,BigDecimal.ROUND_HALF_UP);
chargeOrder.setChargingDegree(chargingDegree1);
}
chargeOrder.setAmountCharged(money);
}else{
//当没有缓存数据时查询数据库
XhpcRealTimeOrder startRealTimeOrder = xhpcRealTimeOrderMapper.getChargingOrderId(chargeOrder.getChargeOrderId(), 1);
if(startRealTimeOrder ==null){
message.put("powerPriceTotal",0);
message.put("servicePriceTotal",0);
return message;
}
XhpcRealTimeOrder endRealTimeOrder = xhpcRealTimeOrderMapper.getChargingOrderId(chargeOrder.getChargeOrderId(), 2);
message.put("soc",endRealTimeOrder.getSoc());
//最后一祯时间
Date endTime = endRealTimeOrder.getCreateTime();
Date startTime = startRealTimeOrder.getCreateTime();
BigDecimal chargingDegree = endRealTimeOrder.getChargingDegree();
message.put("chargingDegree",chargingDegree);
chargeOrder.setChargingTime(endRealTimeOrder.getChargingTime());
message.put("chargingTime",endRealTimeOrder.getChargingTime());
if(startRealTimeOrder.getRealTimeOrderId().equals(startRealTimeOrder.getRealTimeOrderId())){
message.put("powerPriceTotal",0);
message.put("servicePriceTotal",0);
return message;
}
chargeOrder.setStartTime(startTime);
chargeOrder.setEndTime(endTime);
chargeOrder.setStartSoc(startRealTimeOrder.getSoc());
chargeOrder.setEndSoc(endRealTimeOrder.getSoc());
Integer chargingTimeNumber = endRealTimeOrder.getChargingTimeNumber();
if(chargingTimeNumber>0){
chargeOrder.setChargingTimeNumber(Long.valueOf(chargingTimeNumber*60));
if (cacheMap.get("startTime")!=null && cacheMap.get("lastOrderTime")!=null) {
chargeOrder.setStartTime(DateUtil.parse(cacheMap.get("startTime").toString()));
chargeOrder.setEndTime(DateUtil.parse(cacheMap.get("lastOrderTime").toString()));
if (cacheMap.get("totalPower")!=null && cacheMap.get("totalMoney")!=null) {
String totalPower = cacheMap.get("totalPower").toString();
//String totalPowerSub = totalPower.substring(0, totalPower.length() - 1);
String totalMoney = cacheMap.get("totalMoney").toString();
chargeOrder.setChargingDegree(new BigDecimal(totalPower));
chargeOrder.setAmountCharged(new BigDecimal(totalMoney));
}
}else{
chargeOrder.setChargingTimeNumber(0L);
//没有获取到时间 1.获取缓存数据 2.缓存没有获取数据库数据
List<CacheRealtimeData> list = (List<CacheRealtimeData>) cacheMap.get("realtimeDataList");
CacheRealtimeData startData =new CacheRealtimeData();
CacheRealtimeData endData =new CacheRealtimeData();
if (list != null && list.size() > 0) {
endData =list.get(list.size()-1);
for (int i = 0; i <list.size() ; i++) {
startData =list.get(i);
if(startData.getAmountCharged()>0){
break;
}
}
}
if(endData !=null && endData.getAmountCharged() !=null && startData.getChargingTime()>0){
//最后一祯时间
Date endTime = DateUtil.parse(endData.getCreateTime());
Date startTime =DateUtil.parse(startData.getCreateTime());
//充电时长
BigDecimal chargingDegree = new BigDecimal(endData.getChargingDegree()).divide(new BigDecimal(10000), 2, BigDecimal.ROUND_HALF_UP);
chargeOrder.setStartTime(startTime);
chargeOrder.setEndTime(endTime);
chargeOrder.setStartSoc(startData.getSoc().toString());
chargeOrder.setEndSoc(endData.getSoc().toString());
chargeOrder.setChargingDegree(chargingDegree);
chargeOrder.setAmountCharged(new BigDecimal(endData.getAmountCharged()).divide(new BigDecimal(10000),2,BigDecimal.ROUND_HALF_UP));
}else{
//当没有缓存数据时查询数据库
XhpcRealTimeOrder startRealTimeOrder = xhpcRealTimeOrderMapper.getChargingOrderId(chargeOrder.getChargeOrderId(), 1);
if(startRealTimeOrder ==null){
message.put("powerPriceTotal",0);
message.put("servicePriceTotal",0);
return message;
}
XhpcRealTimeOrder endRealTimeOrder = xhpcRealTimeOrderMapper.getChargingOrderId(chargeOrder.getChargeOrderId(), 2);
//最后一祯时间
Date endTime = endRealTimeOrder.getCreateTime();
Date startTime = startRealTimeOrder.getCreateTime();
BigDecimal chargingDegree = endRealTimeOrder.getChargingDegree();
chargeOrder.setChargingTime(endRealTimeOrder.getChargingTime());
if(startRealTimeOrder.getRealTimeOrderId().equals(startRealTimeOrder.getRealTimeOrderId())){
message.put("powerPriceTotal",0);
message.put("servicePriceTotal",0);
return message;
}
chargeOrder.setStartTime(startTime);
chargeOrder.setEndTime(endTime);
chargeOrder.setStartSoc(startRealTimeOrder.getSoc());
chargeOrder.setEndSoc(endRealTimeOrder.getSoc());
Integer chargingTimeNumber = endRealTimeOrder.getChargingTimeNumber();
if(chargingTimeNumber>0){
chargeOrder.setChargingTimeNumber(Long.valueOf(chargingTimeNumber*60));
}else{
chargeOrder.setChargingTimeNumber(0L);
}
chargeOrder.setChargingDegree(chargingDegree);
chargeOrder.setAmountCharged(endRealTimeOrder.getAmountCharged());
}
}
Date startTime2 = chargeOrder.getStartTime();
Date updateTime2 = chargeOrder.getEndTime();
BigDecimal amountCharged = chargeOrder.getAmountCharged();
//充电度数
BigDecimal chargingDegree = chargeOrder.getChargingDegree();
BigDecimal powerPriceTotal =new BigDecimal(0);
//1时间没有跨天
DateTime parse = DateUtil.parse(DateUtil.format(startTime2, "yyyy-MM-dd"), "yyyy-MM-dd");
DateTime parse1 = DateUtil.parse(DateUtil.format(updateTime2, "yyyy-MM-dd"), "yyyy-MM-dd");
//每分钟多少度电
BigDecimal decimal = new BigDecimal((updateTime2.getTime() - startTime2.getTime())).divide(new BigDecimal(60000),4,BigDecimal.ROUND_HALF_UP);
BigDecimal divide = chargingDegree.divide(decimal,4,BigDecimal.ROUND_HALF_UP);
long betweenDay = DateUtil.between(parse,parse1, DateUnit.DAY);
if(betweenDay==0){
powerPriceTotal = getBigDecimal(rateModelId,DateUtil.formatTime(startTime2), DateUtil.formatTime(updateTime2), powerPriceTotal, divide);
}else{
//跨天
powerPriceTotal = getBigDecimal(rateModelId, DateUtil.formatTime(startTime2), "23:59:59", powerPriceTotal, divide);
System.out.println(">>>>>>跨天前>>>>>>>"+powerPriceTotal);
//明天
DateTime tomorrow = DateUtil.offsetDay(startTime2,1);
Date startTime3 = DateUtil.beginOfDay(tomorrow);
powerPriceTotal = getBigDecimal(rateModelId, DateUtil.formatTime(startTime3), DateUtil.formatTime(updateTime2), powerPriceTotal, divide);
System.out.println(">>>>>>跨天后>>>>>>>"+powerPriceTotal);
}
//算服务费和电费
if(amountCharged.compareTo(powerPriceTotal)>-1){
BigDecimal servicePriceTotal =amountCharged.subtract(powerPriceTotal);
message.put("powerPriceTotal",powerPriceTotal);
message.put("servicePriceTotal",servicePriceTotal);
}else{
message.put("powerPriceTotal",amountCharged);
message.put("servicePriceTotal",0);
}
chargeOrder.setChargingDegree(chargingDegree);
chargeOrder.setType("平台停止充电");
chargeOrder.setAmountCharged(endRealTimeOrder.getAmountCharged());
}
Date startTime2 = chargeOrder.getStartTime();
Date updateTime2 = chargeOrder.getEndTime();
BigDecimal amountCharged = chargeOrder.getAmountCharged();
//充电度数
BigDecimal chargingDegree = chargeOrder.getChargingDegree();
BigDecimal powerPriceTotal =new BigDecimal(0);
//1时间没有跨天
DateTime parse = DateUtil.parse(DateUtil.format(startTime2, "yyyy-MM-dd"), "yyyy-MM-dd");
DateTime parse1 = DateUtil.parse(DateUtil.format(updateTime2, "yyyy-MM-dd"), "yyyy-MM-dd");
//每分钟多少度电
BigDecimal decimal = new BigDecimal((updateTime2.getTime() - startTime2.getTime())).divide(new BigDecimal(60000),4,BigDecimal.ROUND_HALF_UP);
BigDecimal divide = chargingDegree.divide(decimal,4,BigDecimal.ROUND_HALF_UP);
long betweenDay = DateUtil.between(parse,parse1, DateUnit.DAY);
if(betweenDay==0){
powerPriceTotal = getBigDecimal(rateModelId,DateUtil.formatTime(startTime2), DateUtil.formatTime(updateTime2), powerPriceTotal, divide);
message.put("chargingDegree",chargeOrder.getChargingDegree());
Long tiem = (chargeOrder.getEndTime().getTime() - chargeOrder.getStartTime().getTime()) / 1000;
if (tiem > 3600) {
long hours = tiem / 3600;
double mins = (double) ((tiem - (hours * 3600)) / 60);
message.put("chargingTime",hours + "" + new BigDecimal(mins).setScale(0) + "");
chargeOrder.setChargingTime(hours + "" + new BigDecimal(mins).setScale(0) + "");
} else {
double mins = (double) (tiem / 60);
message.put("chargingTime",new BigDecimal(mins).setScale(0) + "");
chargeOrder.setChargingTime(new BigDecimal(mins).setScale(0) + "");
}
message.put("startSoc",chargeOrder.getStartSoc());
message.put("endSoc",chargeOrder.getEndSoc());
if(cacheMap.get("stopReasonHex") !=null && "".equals(cacheMap.get("stopReasonHex").toString())){
chargeOrder.setType(cacheMap.get("stopReasonHex").toString());
}else{
//跨天
powerPriceTotal = getBigDecimal(rateModelId, DateUtil.formatTime(startTime2), "23:59:59", powerPriceTotal, divide);
System.out.println(">>>>>>跨天前>>>>>>>"+powerPriceTotal);
//明天
DateTime tomorrow = DateUtil.offsetDay(startTime2,1);
Date startTime3 = DateUtil.beginOfDay(tomorrow);
powerPriceTotal = getBigDecimal(rateModelId, DateUtil.formatTime(startTime3), DateUtil.formatTime(updateTime2), powerPriceTotal, divide);
System.out.println(">>>>>>跨天后>>>>>>>"+powerPriceTotal);
chargeOrder.setType("90");
}
//算服务费和电费
if(amountCharged.compareTo(powerPriceTotal)>-1){
BigDecimal servicePriceTotal =amountCharged.subtract(powerPriceTotal);
message.put("powerPriceTotal",powerPriceTotal);
message.put("servicePriceTotal",servicePriceTotal);
}else{
message.put("powerPriceTotal",amountCharged);
message.put("servicePriceTotal",0);
}
message.put("startTime",chargeOrder.getStartTime());
message.put("endTime",chargeOrder.getEndTime());
//修改充电订单
xhpcChargeOrderService.updateXhpcChargeOrder(chargeOrder);
}catch (Exception e){
e.printStackTrace();
logger.info("======================异常订单审核异常=======================");
message.put("powerPriceTotal",0);
message.put("servicePriceTotal",0);
}
@ -334,6 +495,10 @@ public class XhpcRealTimeOrderServiceImpl extends BaseService implements IXhpcRe
xhpcChargeOrderService.updateXhpcChargeOrder(xhpcChargeOrder);
return AjaxResult.success();
}
if(xhpcChargeOrder.getRateModelId()==null || "".equals(xhpcChargeOrder.getRateModelId())){
Map<String, Object> xhpcChargingStationMap = xhpcRealTimeOrderMapper.getXhpcChargingStationById(xhpcChargeOrder.getChargingStationId());
xhpcChargeOrder.setRateModelId(Long.valueOf(xhpcChargingStationMap.get("rateModelId").toString()));
}
//总金额
BigDecimal money = powerPrice.add(servicePrice);
//总服务费 servicePrice
@ -1535,6 +1700,8 @@ public class XhpcRealTimeOrderServiceImpl extends BaseService implements IXhpcRe
xhpcHistoryOrderService.insert(xhpcHistoryOrder);
}
private BigDecimal getBigDecimal(Long rateModelId, String startTime, String updateTime, BigDecimal powerPriceTotal, BigDecimal divide) {
if("00:00:00".equals(updateTime)){
updateTime="23:59:59";

View File

@ -1530,6 +1530,7 @@ public class XhpcStatisticsServiceImpl extends BaseService implements IXhpcStati
int freeTime =0;//空闲
int charge =0;//充电
int unknown =0;//未知
int insertGun =0;//已插枪
if(terminal !=null && terminal.size()>0){
for (String st:terminal) {
Map<String, Object> cacheMap = redisService.getCacheMap("gun:" + st);
@ -1542,7 +1543,11 @@ public class XhpcStatisticsServiceImpl extends BaseService implements IXhpcStati
fault++;
}else if(cacheMap.containsKey("status") &&
"空闲".equals(cacheMap.get("status").toString())){
freeTime++;
if("".equals(cacheMap.get("vehicleGunStatus").toString())){
insertGun++;
}else{
freeTime++;
}
}else{
charge++;
}
@ -1586,6 +1591,12 @@ public class XhpcStatisticsServiceImpl extends BaseService implements IXhpcStati
mapList4.add(objectMap4);
mapList.addAll(mapList4);
List<Map<String,Object>> mapList5 =new ArrayList<>();
Map<String,Object> objectMap5 =new HashMap<>();
objectMap5.put("name","已插枪");
objectMap5.put("value",insertGun);
mapList5.add(objectMap5);
mapList.addAll(mapList5);
return mapList;
}

View File

@ -14,10 +14,10 @@ spring:
nacos:
discovery:
# 服务注册地址
server-addr: 172.31.183.135:8848
server-addr: mse-e2a05960-nacos-ans.mse.aliyuncs.com:8848
config:
# 配置中心地址
server-addr: 172.31.183.135:8848
server-addr: mse-e2a05960-nacos-ans.mse.aliyuncs.com:8848
# 配置文件格式
file-extension: yml
# 共享配置

View File

@ -1162,7 +1162,7 @@
<if test="isNotNull==1">
and ho.total_price &gt;=0
</if>
order by ho.create_time desc
order by ho.end_time desc
</select>
<select id="getReatTimeList" resultType="map">
@ -1616,4 +1616,12 @@
and serial_number=#{serialNumber}
</if>
</select>
<select id="getXhpcRealTimeOrderTwentyFour" resultType="map">
select max(real_time_order_id),
amount_charged as amountCharged,
charging_degree as chargingDegree
from xhpc_real_time_order where create_time &lt;= #{time} and charging_order_id=#{chargingOrderId}
</select>
</mapper>

View File

@ -212,6 +212,105 @@
</trim>
</insert>
<insert id="insertRealTimeOrderBms" >
insert into xhpc_real_time_order_bms
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="null != orderNo and orderNo !=''">
order_no,
</if>
<if test="null != pileNo and pileNo!=''">
pile_no,
</if>
<if test="null != gunId and gunId!='' ">
gun_id,
</if>
<if test="null != bmsVoltageRequest ">
bms_voltage_request,
</if>
<if test="null != bmsCurrentRequest ">
bms_current_request,
</if>
<if test="null != bmsChargingMod ">
bms_charging_mod,
</if>
<if test="null != bmsChargingVolt ">
bms_charging_volt,
</if>
<if test="null != bmsChargingCurrent ">
bms_charging_current,
</if>
<if test="null != soc ">
soc,
</if>
<if test="null != bmsEstRemainingTime and bmsEstRemainingTime !=''">
bms_est_remaining_time,
</if>
<if test="null != pileVoltageOutput ">
pile_voltage_output,
</if>
<if test="null != pileCurrentOutput ">
pile_current_output,
</if>
<if test="null != chargingTimeSummary and chargingTimeSummary !=''">
charging_time_summary,
</if>
<if test="null != monoBatteryVoltGroupId ">
mono_battery_volt_groupId,
</if>
<if test="null != chargingOrderId ">
charging_order_id,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="null != orderNo and orderNo !=''">
#{orderNo},
</if>
<if test="null != pileNo and pileNo!=''">
#{pileNo},
</if>
<if test="null != gunId and gunId!='' ">
#{gunId},
</if>
<if test="null != bmsVoltageRequest ">
#{bmsVoltageRequest},
</if>
<if test="null != bmsCurrentRequest ">
#{bmsCurrentRequest},
</if>
<if test="null != bmsChargingMod ">
#{bmsChargingMod},
</if>
<if test="null != monoBatteryVolt ">
#{monoBatteryVolt},
</if>
<if test="null != bmsChargingCurrent ">
#{bmsChargingCurrent},
</if>
<if test="null != soc ">
#{soc},
</if>
<if test="null != bmsEstRemainingTime and bmsEstRemainingTime!=''">
#{bmsEstRemainingTime},
</if>
<if test="null != pileVoltageOutput ">
#{pileVoltageOutput},
</if>
<if test="null != pileCurrentOutput ">
#{pileCurrentOutput},
</if>
<if test="null != chargingTimeSummary and chargingTimeSummary!=''">
#{chargingTimeSummary},
</if>
<if test="null != monoBatteryVoltGroupId ">
#{monoBatteryVoltGroupId},
</if>
<if test="null != chargingOrderId ">
#{chargingOrderId},
</if>
</trim>
</insert>
<insert id="insertSOC" parameterType="com.xhpc.order.domain.XhpcChargeOrderSoc" useGeneratedKeys="true"
keyProperty="chargeOrderSocId">
insert into xhpc_charge_order_soc
@ -547,6 +646,13 @@
where ro.real_time_order_id=#{realTimeOrderId}
</select>
<select id="getXhpcChargingStationById" resultType="map">
select
charging_station_id chargingStationId,
rate_model_id as rateModelId
from xhpc_charging_station where charging_station_id=#{chargingStationId}
</select>
<select id="getMessageChargeOrderId" resultType="map">
select
co.charge_order_id as chargeOrderId,
@ -607,6 +713,30 @@
order by create_time desc
</select>
<select id="timeBmsList" resultType="map">
select
order_no as orderNo,
pile_no as pileNo,
gun_id as gunId,
bms_voltage_request as bmsVoltageRequest,
bms_current_request as bmsCurrentRequest,
bms_charging_mod as bmsChargingMod,
bms_charging_volt as bmsChargingVolt,
bms_charging_current as gunLineTemperature,
mono_battery_volt as monoBatteryVolt,
soc as soc,
bms_est_remaining_time as bmsEstRemainingTime,
pileVoltageOutput as pileVoltageOutput,
pile_current_output as pileCurrentOutput,
charging_time_summary as chargingTimeSummary,
mono_battery_volt_groupId as monoBatteryVoltGroupId,
create_time as createTime
from xhpc_real_time_order_bms
where charging_order_id=#{chargingOrderId}
order by create_time desc
</select>
<select id="timeChartSOCList" resultType="map">
select
group_concat(soc) as soc,

View File

@ -1,19 +1,29 @@
package com.xhpc.pp.logic;
import cn.hutool.core.date.DateUtil;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.xhpc.common.api.PileOrderService;
import com.xhpc.common.data.redis.CacheBmsReqChargerOutputData;
import com.xhpc.common.data.up.BmsReqChargerOutputData;
import com.xhpc.common.enums.StationDeviceEnum;
import com.xhpc.pp.domain.XhpcDeviceMessage;
import com.xhpc.pp.mapper.XhpcDeviceMessageMapper;
import com.xhpc.pp.tx.ServiceParameter;
import com.xhpc.pp.tx.ServiceResult;
import com.xhpc.pp.tx.logic.ServiceLogic;
import com.xhpc.pp.utils.HexUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.math.RoundingMode;
import java.text.NumberFormat;
import java.util.Map;
import static com.xhpc.common.data.redis.StaticBeanUtil.REDIS;
@Lazy
@Component("BmsReqChargerOutputDataLogic")
public class BmsReqChargerOutputDataLogic implements ServiceLogic {
@ -22,10 +32,22 @@ public class BmsReqChargerOutputDataLogic implements ServiceLogic {
@Resource
XhpcDeviceMessageMapper deviceMessageMapper;
@Resource
PileOrderService pileOrderService;
@Override
public ServiceResult service(ServiceParameter sp) throws Exception {
Map<String, Object> req = sp.getParameters();
ObjectMapper objectMapper = new ObjectMapper();
BmsReqChargerOutputData orderData = objectMapper.convertValue(req, BmsReqChargerOutputData.class);
String orderNo = (String) req.get("orderNo");
String orderKey = "order:".concat(orderNo).concat(".bms");
CacheBmsReqChargerOutputData cacheBmsReqChargerOutputData = translate(orderData);
REDIS.setCacheObject(orderKey, cacheBmsReqChargerOutputData);
pileOrderService.pileRimeOrderBms(orderNo);
XhpcDeviceMessage deviceMessage = new XhpcDeviceMessage();
deviceMessage.setType(StationDeviceEnum.PILE.getCode());
@ -39,4 +61,37 @@ public class BmsReqChargerOutputDataLogic implements ServiceLogic {
return new ServiceResult(false);
}
private CacheBmsReqChargerOutputData translate(BmsReqChargerOutputData orderData) {
CacheBmsReqChargerOutputData cacheBmsReqChargerOutputData = new CacheBmsReqChargerOutputData();
cacheBmsReqChargerOutputData.setOrderNo(orderData.getOrderNo());
cacheBmsReqChargerOutputData.setPileNo(orderData.getPileNo());
cacheBmsReqChargerOutputData.setGunId(orderData.getGunId());
cacheBmsReqChargerOutputData.setBmsVoltageRequest(convertDouble(HexUtils.reverseHexInt(orderData.getBmsVoltageRequest()) * 0.1));
cacheBmsReqChargerOutputData.setBmsCurrentRequest(convertDouble(HexUtils.reverseHexInt(orderData.getBmsCurrentRequest()) * 0.1));
cacheBmsReqChargerOutputData.setBmsChargingMod(HexUtils.reverseHexInt(orderData.getBmsChargingMod()));
cacheBmsReqChargerOutputData.setBmsChargingVolt(convertDouble(HexUtils.reverseHexInt(orderData.getBmsChargingVolt()) * 0.1));
cacheBmsReqChargerOutputData.setBmsChargingCurrent(convertDouble(HexUtils.reverseHexInt(orderData.getBmsChargingCurrent()) * 0.1));
cacheBmsReqChargerOutputData.setMonoBatteryVolt(convertDouble(Integer.parseInt(orderData.getMonoBatteryVoltGroupId().substring(0, 3), 16) * 0.01));
cacheBmsReqChargerOutputData.setSoc(HexUtils.reverseHexInt(orderData.getSoc()));
cacheBmsReqChargerOutputData.setBmsEstRemainingTime(HexUtils.reverseHexInt(orderData.getBmsEstRemainingTime()));
cacheBmsReqChargerOutputData.setPileVoltageOutput(convertDouble(HexUtils.reverseHexInt(orderData.getPileVoltageOutput()) * 0.1));
cacheBmsReqChargerOutputData.setPileCurrentOutput(convertDouble(HexUtils.reverseHexInt(orderData.getPileVoltageOutput()) * 0.1));
cacheBmsReqChargerOutputData.setChargingTimeSummary(HexUtils.reverseHexInt(orderData.getChargingTimeSummary()));
cacheBmsReqChargerOutputData.setMonoBatteryVoltGroupId(Integer.parseInt(orderData.getMonoBatteryVoltGroupId().substring(3), 16));
cacheBmsReqChargerOutputData.setHex(orderData.getHex());
cacheBmsReqChargerOutputData.setCreateTime(DateUtil.now());
return cacheBmsReqChargerOutputData;
}
private Double convertDouble(Double oldVar) {
NumberFormat nf = NumberFormat.getInstance();
nf.setMaximumFractionDigits(2);
nf.setMinimumFractionDigits(2);
nf.setRoundingMode(RoundingMode.HALF_UP);
nf.setGroupingUsed(false);
return Double.parseDouble(nf.format(oldVar));
}
}

View File

@ -6,7 +6,9 @@ import com.xhpc.common.api.PileOrderService;
import com.xhpc.common.core.domain.R;
import com.xhpc.common.data.redis.CacheOrderData;
import com.xhpc.common.data.up.OrderData;
import com.xhpc.pp.controller.ChargingController;
import com.xhpc.common.enums.StationDeviceEnum;
import com.xhpc.pp.domain.XhpcDeviceMessage;
import com.xhpc.pp.mapper.XhpcDeviceMessageMapper;
import com.xhpc.pp.tx.ServiceParameter;
import com.xhpc.pp.tx.ServiceResult;
import com.xhpc.pp.tx.logic.ServiceLogic;
@ -18,6 +20,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.util.HashMap;
@ -35,6 +38,8 @@ public class OrderDataLogic implements ServiceLogic {
@Autowired
private PileOrderService pileOrderService;
@Resource
XhpcDeviceMessageMapper deviceMessageMapper;
private static Map<String, String> SM = new HashMap<>();
static {
@ -67,6 +72,7 @@ public class OrderDataLogic implements ServiceLogic {
cacheOrder.put("status", "已结束");
cacheOrder.put("stopReason", translate(cacheOrderData.getStopReason()));
cacheOrder.put("stopReasonHex", cacheOrderData.getStopReason());
cacheOrder.put("stopTime", cacheOrderData.getEndTime());
REDIS.setCacheMap(orderkey, cacheOrder);
String gunkey = "gun:".concat(orderData.getPileNo()).concat(orderData.getGunId());
Map<String, Object> cacheGun = REDIS.getCacheMap(gunkey);
@ -89,6 +95,16 @@ public class OrderDataLogic implements ServiceLogic {
"无效订单"))) {
log.error(">>INVALID order [{}] detected. MUST check the system or [{}].<<", orderNo, gunkey);
}
XhpcDeviceMessage deviceMessage = new XhpcDeviceMessage();
deviceMessage.setType(StationDeviceEnum.PILE.getCode());
deviceMessage.setSerialNumber(sp.getPileNo());
deviceMessage.setRemark("充电交易结算记录");
deviceMessage.setStatus(0);
deviceMessage.setContent((String) req.get("hex"));
deviceMessage.setChargeOrderNo((String) req.get("orderNo"));
deviceMessageMapper.insertByDomain(deviceMessage);
String resultStr = "6815".concat(req.get("seqhex").toString()).concat("0040").concat(orderNo);
if ((r != null && r.getCode() == 200) || (r != null && r.getMsg() != null && r.getMsg().contains("重复结算"))) {
resultStr = resultStr.concat(ServiceResult.HEX_00);

View File

@ -116,6 +116,13 @@ public class PileStartChargingDataLogic implements ServiceLogic {
String orderkey = "order:".concat(orderNo);
REDIS.setCacheMap(orderkey, cacheOrder);
REDIS.setCacheMapValue("gun:".concat(connectorId), "ac.on", false);
REDIS.setCacheMapValue("gun:".concat(connectorId), "orderkey", orderNo);
String pushOrderKey = orderkey.replace("order:", "pushOrder:");
Map<String, Object> map = new HashMap<>();
map.put("startChargeSeqStat", 2);
REDIS.setCacheMap(pushOrderKey, map);
resultStr = "00";
} else {
resultStr = "1C";

View File

@ -9,8 +9,11 @@ import com.xhpc.common.core.domain.R;
import com.xhpc.common.data.redis.CacheOrderData;
import com.xhpc.common.data.redis.CacheRealtimeData;
import com.xhpc.common.data.up.RealtimeData;
import com.xhpc.common.enums.StationDeviceEnum;
import com.xhpc.evcs.dto.ChargeDetails;
import com.xhpc.pp.controller.ChargingController;
import com.xhpc.pp.domain.XhpcDeviceMessage;
import com.xhpc.pp.mapper.XhpcDeviceMessageMapper;
import com.xhpc.pp.tx.ServiceParameter;
import com.xhpc.pp.tx.ServiceResult;
import com.xhpc.pp.tx.logic.ServiceLogic;
@ -21,6 +24,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
@ -45,6 +49,8 @@ public class RealtimeDataLogic implements ServiceLogic {
private PileOrderService pileOrderService;
@Autowired
private ChargingController chargingController;
@Resource
XhpcDeviceMessageMapper deviceMessageMapper;
private static final Logger log = LoggerFactory.getLogger(RealtimeDataLogic.class);
@ -126,7 +132,7 @@ public class RealtimeDataLogic implements ServiceLogic {
}
Integer balance = (Integer) cacheOrder.get("initBalance");
CacheRealtimeData cacheRealtimeData = translate(realtimeData);
balance -= cacheRealtimeData.getAmountCharged();
cacheRealtimeData.setCreateTime(DateUtil.now());
String lord = orderkey.concat(".lord");
REDIS.setCacheObject(lord, cacheRealtimeData);
@ -141,12 +147,14 @@ public class RealtimeDataLogic implements ServiceLogic {
cacheOrder.put("em1", calcem1(cdhex));
}
}
balance -= cacheRealtimeData.getAmountCharged();
cacheOrder.put("rbalance", balance);
cacheOrder.put("remainingTime", tr);
cacheOrder.put("status", statusplain);
cacheOrder.put("totalPower", cacheRealtimeData.getChargingDegree() / 10000.0);
cacheOrder.put("totalMoney", cacheRealtimeData.getAmountCharged() / 10000.0);
cacheOrder.put("realtimeDataList", realtimeDataList);
cacheOrder.put("lastOrderTime", DateUtil.now());
R r1 = pileOrderService.pileRimeOrder(orderNo);
if (r1 == null || (r1.getMsg()!=null && r1.getMsg().contains("无效订单")) || (r1.getCode() >=500 && r1.getCode() != 3886)) {
chargingController.stopInvalidOrder(orderNo);
@ -200,6 +208,16 @@ public class RealtimeDataLogic implements ServiceLogic {
cacheOrder.put("lordiss", "false");
pileOrderService.pileStop(orderNo, 4, "订单实时数据恢复");
}
// 判断金额和电量为0 防止白嫖
if(realtimeDataList.size() > 3){
if(cacheRealtimeData.getAmountCharged() < 0.1 && cacheRealtimeData.getChargingDegree() < 0.1){
log.error("实时数据充电度数:{}, 实时充电金额为: {},订单[{}] 自动结束",
cacheRealtimeData.getChargingDegree(),
cacheRealtimeData.getAmountCharged(),
cacheRealtimeData.getOrderNo());
chargingController.stopCharging(pileNo, gunId, default_version);
}
}
}
}
} else {
@ -248,6 +266,15 @@ public class RealtimeDataLogic implements ServiceLogic {
}
}
REDIS.setCacheMap(gunkey, cacheGun);
XhpcDeviceMessage deviceMessage = new XhpcDeviceMessage();
deviceMessage.setType(StationDeviceEnum.PILE.getCode());
deviceMessage.setSerialNumber(sp.getPileNo());
deviceMessage.setRemark("实时数据");
deviceMessage.setStatus(0);
deviceMessage.setContent((String) req.get("hex"));
deviceMessage.setChargeOrderNo((String) req.get("orderNo"));
deviceMessageMapper.insertByDomain(deviceMessage);
return new ServiceResult(false);
}

View File

@ -430,24 +430,28 @@ public class XhpcAppUserServiceImpl extends BaseService implements IXhpcAppUserU
*/
@Override
public R<?> voluntaryLogin(Map<String, Object> map) {
String type = StringUtils.valueOf(map.get("type"));
String openid = StringUtils.valueOf(map.get("openid"));
String tenantId = StringUtils.valueOf(map.get("tenantId"));
logger.info("<<<<<<<<<<openid>>>>>>>>>>>>");
logger.info("<<<<<<<<<<自动登录openid>>>>>>>>>>>>"+openid);
logger.info("<<<<<<<<<<openid>>>>>>>>>>>>");
Map<String, Object> userLoginTime = xhpcAppUserMapper.getUserLoginTime(Integer.valueOf(type), openid,tenantId);
if(userLoginTime ==null){
return R.fail(HttpStatus.USER_LOGIN, "请重新登录");
}
logger.info("-------userLoginTime---" + userLoginTime);
if(userLoginTime.get("status") == null){
return R.fail(HttpStatus.USER_LOGIN, "请重新登录");
} else if(UserTypeUtil.NO_LOGIN.equals(userLoginTime.get("status").toString())){
return R.fail(HttpStatus.USER_LOGIN, "请重新登录");
}
logger.info("-------status---"+userLoginTime.get("status").toString());
return appLogin(userLoginTime.get("account").toString(), type, openid, tenantId);
try{
String type = StringUtils.valueOf(map.get("type"));
String openid = StringUtils.valueOf(map.get("openid"));
String tenantId = StringUtils.valueOf(map.get("tenantId"));
logger.info("<<<<<<<<<<openid>>>>>>>>>>>>");
logger.info("<<<<<<<<<<自动登录openid>>>>>>>>>>>>"+openid);
logger.info("<<<<<<<<<<openid>>>>>>>>>>>>");
Map<String, Object> userLoginTime = xhpcAppUserMapper.getUserLoginTime(Integer.valueOf(type), openid,tenantId);
if(userLoginTime ==null){
return R.fail(HttpStatus.USER_LOGIN, "请重新登录");
}
logger.info("-------userLoginTime---" + userLoginTime);
if(userLoginTime.get("status") == null){
return R.fail(HttpStatus.USER_LOGIN, "请重新登录");
} else if(UserTypeUtil.NO_LOGIN.equals(userLoginTime.get("status").toString())){
return R.fail(HttpStatus.USER_LOGIN, "请重新登录");
}
logger.info("-------status---"+userLoginTime.get("status").toString());
return appLogin(userLoginTime.get("account").toString(), type, openid, tenantId);
}catch (Exception e){
return R.fail(HttpStatus.USER_LOGIN, "请重新登录");
}
}
/**
@ -525,6 +529,7 @@ public class XhpcAppUserServiceImpl extends BaseService implements IXhpcAppUserU
}
}catch (Exception e){
e.printStackTrace();
logger.info("-------appInfo----请重新登录---");
return AjaxResult.error("请重新登录",HttpStatus.USER_LOGIN);
}
}

View File

@ -14,10 +14,10 @@ spring:
nacos:
discovery:
# 服务注册地址
server-addr: 172.31.183.135:8848
server-addr: mse-e2a05960-nacos-ans.mse.aliyuncs.com:8848
config:
# 配置中心地址
server-addr: 172.31.183.135:8848
server-addr: mse-e2a05960-nacos-ans.mse.aliyuncs.com:8848
# 配置文件格式
file-extension: yml
# 共享配置
@ -55,4 +55,4 @@ oss:
#文件路径
file:
aliyunPath: invoicePdf/
serverStoreDisposableFileLocation: /www/wwwroot/xhpc.scxhua.com/disposableFiles/
serverStoreDisposableFileLocation: /www/wwwroot/scxhua.cn/disposableFiles/