This commit is contained in:
Lemon
2024-12-12 15:25:28 +08:00
10 changed files with 91 additions and 28 deletions

View File

@@ -488,42 +488,54 @@ public class PileService {
// 为空说明此用户未注册平台账号 // 为空说明此用户未注册平台账号
throw new BusinessException(ReturnCodeEnum.CODE_USER_IS_NOT_REGISTER); throw new BusinessException(ReturnCodeEnum.CODE_USER_IS_NOT_REGISTER);
} }
// 被分享的用户memberId
String memberId = memberBasicInfo.getMemberId();
List<PileMemberRelation> relationList = pileMemberRelationService.selectPileMemberRelationByPileSn(dto.getPileSn()); List<PileMemberRelation> relationList = pileMemberRelationService.selectPileMemberRelationByPileSn(dto.getPileSn());
if (CollectionUtils.isEmpty(relationList)) { if (CollectionUtils.isEmpty(relationList)) {
// 充电桩没有绑定任何人 // 充电桩没有绑定任何人
throw new BusinessException(ReturnCodeEnum.CODE_NO_ADMIN_FOR_PILE);
} }
// 使用stream把relationList转为map, key为type, value为List<PileMemberRelation>
Map<String, List<PileMemberRelation>> map = relationList.stream().collect(Collectors.groupingBy(PileMemberRelation::getType));
List<PileMemberRelation> adminMemberRelationList = map.get(Constants.ONE); // 管理员列表
List<String> adminList = relationList.stream() if (CollectionUtils.isEmpty(adminMemberRelationList)) {
.filter(x -> x.getType().equals(Constants.ONE)) // 1-管理员用户 // 充电桩没有管理员
throw new BusinessException(ReturnCodeEnum.CODE_NO_ADMIN_FOR_PILE);
}
List<String> adminList = adminMemberRelationList.stream()
.map(PileMemberRelation::getMemberId) .map(PileMemberRelation::getMemberId)
.collect(Collectors.toList()); .collect(Collectors.toList());
if (CollectionUtils.isEmpty(adminList)) { // 校验身份 入参是否是管理员
// 没有管理员 if (adminList.contains(memberId)) {
}
// 校验身份
if (adminList.contains(dto.getMemberId())) {
// 如果不为空,说明被分享的用户是管理员,抛出异常 // 如果不为空,说明被分享的用户是管理员,抛出异常
throw new BusinessException(ReturnCodeEnum.CODE_AUTHENTICATION_ERROR); throw new BusinessException(ReturnCodeEnum.CODE_ALREADY_AN_ADMIN);
} }
List<String> userList = relationList.stream() List<String> userList = Lists.newArrayList();
.filter(x -> !x.getType().equals(Constants.TWO)) // 2-普通用户 List<PileMemberRelation> userMemberRelations = map.get(Constants.TWO); // 普通用户列表
.map(PileMemberRelation::getMemberId) if (CollectionUtils.isNotEmpty(userMemberRelations)) {
.collect(Collectors.toList()); userList = userMemberRelations.stream()
.map(PileMemberRelation::getMemberId)
if (userList.contains(memberBasicInfo.getMemberId())) { .collect(Collectors.toList());
}
// 校验身份 入参是否是普通用户
if (userList.contains(memberId)) {
// 不为空说明已绑定 // 不为空说明已绑定
throw new BusinessException(ReturnCodeEnum.CODE_USER_HAS_BEEN_THIS_PILE); throw new BusinessException(ReturnCodeEnum.CODE_ALREADY_AN_USER);
} else {
// 进行绑定,此用户为普通用户
PileMemberRelation info = new PileMemberRelation();
info.setPileSn(dto.getPileSn());
info.setMemberId(memberBasicInfo.getMemberId());
info.setType(Constants.TWO);
pileMemberRelationService.insertPileMemberRelation(info);
} }
PileMemberRelation pileMemberRelation = adminMemberRelationList.get(0); // 获取管理员列表的第一个元素
// 进行绑定,此用户为普通用户
PileMemberRelation info = new PileMemberRelation();
info.setPileSn(dto.getPileSn());
info.setMemberId(memberId);
info.setType(Constants.TWO);
if (pileMemberRelation != null && StringUtils.isNotBlank(pileMemberRelation.getDeviceId())) {
info.setDeviceId(pileMemberRelation.getDeviceId());
info.setDeviceName(pileMemberRelation.getDeviceName());
}
pileMemberRelationService.insertPileMemberRelation(info);
} }
/** /**

View File

@@ -187,6 +187,14 @@ public enum ReturnCodeEnum {
CODE_START_PERSONAL_PILE_CHARGING_ERROR("00400020", "个人桩启动充电异常"), CODE_START_PERSONAL_PILE_CHARGING_ERROR("00400020", "个人桩启动充电异常"),
CODE_PILE_MEMBER_RELATION_IS_EMPTY("00400021", "个人桩绑定列表为空"),
CODE_NO_ADMIN_FOR_PILE("00400022", "充电桩未设置管理员"),
CODE_ALREADY_AN_ADMIN("00400023", "您已经是此充电桩管理员, 无需再次绑定"),
CODE_ALREADY_AN_USER("00400024", "您已经是此充电桩用户, 无需再次绑定"),
/* 个人桩 end */ /* 个人桩 end */
CODE_THIS_CARNO_HAS_BEEN_BINDING("00500001", "当前车牌号已经绑定,请检查!"), CODE_THIS_CARNO_HAS_BEEN_BINDING("00500001", "当前车牌号已经绑定,请检查!"),

View File

@@ -394,6 +394,7 @@ public class YKCUtils {
/** /**
* 保存soc * 保存soc
* 默认保存7天
* @param transactionCode * @param transactionCode
* @param soc * @param soc
*/ */
@@ -429,16 +430,27 @@ public class YKCUtils {
} }
} }
/**
* 根据交易流水号获取redis保存的soc信息
*/
public static Map<String, String> getSOCMap(String transactionCode) {
String hashKey = CacheConstants.GET_THE_SOC + transactionCode;
RedisCache staticRedisCache = StaticRedisCache.staticRedisCache;
return staticRedisCache.getCacheMap(hashKey);
}
/** /**
* 根据的交易码获取当前soc * 根据的交易码获取当前soc
* @param transactionCode * @param transactionCode
*/ */
public static String getCurrentSOC(String transactionCode) { public static String getCurrentSOC(String transactionCode) {
String hashKey = CacheConstants.GET_THE_SOC + transactionCode; // String hashKey = CacheConstants.GET_THE_SOC + transactionCode;
RedisCache staticRedisCache = StaticRedisCache.staticRedisCache; // RedisCache staticRedisCache = StaticRedisCache.staticRedisCache;
Map<String, Object> cacheMap = staticRedisCache.getCacheMap(hashKey); // Map<String, Object> cacheMap = staticRedisCache.getCacheMap(hashKey);
Map<String, String> socMap = getSOCMap(transactionCode);
// 获取最小值和最大值, 两个值中最大的为当前soc // 获取最小值和最大值, 两个值中最大的为当前soc
return (String) cacheMap.get("max"); return (String) socMap.get("max");
} }
} }

View File

@@ -229,9 +229,11 @@ public class BMSDemandAndChargerOutputHandler extends AbstractYkcHandler {
.pileVoltageOutput(pileVoltageOutput) .pileVoltageOutput(pileVoltageOutput)
.pileCurrentOutput(pileCurrentOutput) .pileCurrentOutput(pileCurrentOutput)
.chargingTime(chargingTime) .chargingTime(chargingTime)
.build(); .build();
// 保存此订单的soc
YKCUtils.saveSOC(transactionCode, soc);
// 调用方法存入缓存 // 调用方法存入缓存
pileBasicInfoService.saveBMSDemandAndChargerOutputInfo2Redis(bmsDemandAndChargerOutputData); pileBasicInfoService.saveBMSDemandAndChargerOutputInfo2Redis(bmsDemandAndChargerOutputData);

View File

@@ -115,6 +115,9 @@ public class ChargeEndHandler extends AbstractYkcHandler {
} }
updateOrder.setUpdateTime(nowDate); updateOrder.setUpdateTime(nowDate);
orderBasicInfoService.updateOrderBasicInfo(updateOrder); orderBasicInfoService.updateOrderBasicInfo(updateOrder);
// 保存此订单的soc
YKCUtils.saveSOC(transactionCode, stopSoc);
} }
return null; return null;

View File

@@ -157,6 +157,9 @@ public class ParameterConfigurationHandler extends AbstractYkcHandler {
.build(); .build();
orderBasicInfoService.updateOrderBasicInfo(orderBasicInfo); orderBasicInfoService.updateOrderBasicInfo(orderBasicInfo);
log.info("更新订单起始SOC, orderCode:{}, transactionCode:{}, startSoc:{}", orderInfo.getOrderCode(), transactionCode, soc); log.info("更新订单起始SOC, orderCode:{}, transactionCode:{}, startSoc:{}", orderInfo.getOrderCode(), transactionCode, soc);
// 保存此订单的soc
YKCUtils.saveSOC(transactionCode, data.getSoc());
} }
return null; return null;

View File

@@ -288,6 +288,9 @@ public class UploadRealTimeMonitorHandler extends AbstractYkcHandler {
// 查询数据库中该订单当前信息 // 查询数据库中该订单当前信息
OrderBasicInfo orderInfo = orderBasicInfoService.getOrderInfoByTransactionCode(transactionCode); OrderBasicInfo orderInfo = orderBasicInfoService.getOrderInfoByTransactionCode(transactionCode);
if (Objects.nonNull(orderInfo)) { if (Objects.nonNull(orderInfo)) {
// 保存此订单的soc
YKCUtils.saveSOC(transactionCode, realTimeMonitorData.getSOC());
if (StringUtils.equals(orderInfo.getOrderStatus(), OrderStatusEnum.ORDER_COMPLETE.getValue()) if (StringUtils.equals(orderInfo.getOrderStatus(), OrderStatusEnum.ORDER_COMPLETE.getValue())
|| StringUtils.equals(orderInfo.getOrderStatus(), OrderStatusEnum.STAY_SETTLEMENT.getValue())) { || StringUtils.equals(orderInfo.getOrderStatus(), OrderStatusEnum.STAY_SETTLEMENT.getValue())) {
// 在订单状态为 订单完成或待结算,不保存 // 在订单状态为 订单完成或待结算,不保存

View File

@@ -666,6 +666,7 @@ public class PileBasicInfoServiceImpl implements PileBasicInfoService {
* 0x23信息设置缓存 (缓存时间3天) * 0x23信息设置缓存 (缓存时间3天)
* @param data * @param data
*/ */
@Override
public void saveBMSDemandAndChargerOutputInfo2Redis(BMSDemandAndChargerOutputData data) { public void saveBMSDemandAndChargerOutputInfo2Redis(BMSDemandAndChargerOutputData data) {
if (StringUtils.equals(data.getTransactionCode(), Constants.ILLEGAL_TRANSACTION_CODE)) { if (StringUtils.equals(data.getTransactionCode(), Constants.ILLEGAL_TRANSACTION_CODE)) {
return; return;

View File

@@ -116,6 +116,7 @@ public class PileMemberRelationServiceImpl implements PileMemberRelationService
return selectPileMemberRelationList(pileMemberRelation); return selectPileMemberRelationList(pileMemberRelation);
} }
@Override
public List<MemberVO> selectMemberList(String pileSn) { public List<MemberVO> selectMemberList(String pileSn) {
return pileMemberRelationMapper.selectMemberList(pileSn); return pileMemberRelationMapper.selectMemberList(pileSn);
} }

View File

@@ -16,6 +16,7 @@ import com.jsowell.common.enums.ykc.OrderPayRecordEnum;
import com.jsowell.common.enums.ykc.OrderStatusEnum; import com.jsowell.common.enums.ykc.OrderStatusEnum;
import com.jsowell.common.util.DateUtils; import com.jsowell.common.util.DateUtils;
import com.jsowell.common.util.StringUtils; import com.jsowell.common.util.StringUtils;
import com.jsowell.common.util.YKCUtils;
import com.jsowell.pile.domain.*; import com.jsowell.pile.domain.*;
import com.jsowell.pile.domain.ebike.deviceupload.EBikeMessageCmd03; import com.jsowell.pile.domain.ebike.deviceupload.EBikeMessageCmd03;
import com.jsowell.pile.dto.*; import com.jsowell.pile.dto.*;
@@ -242,6 +243,23 @@ public abstract class AbstractProgramLogic implements InitializingBean {
orderBasicInfo.setSettlementTime(DateUtils.getNowDate()); // 结算时间 orderBasicInfo.setSettlementTime(DateUtils.getNowDate()); // 结算时间
} }
orderBasicInfo.setRefundAmount(residue); // 结算退款金额 orderBasicInfo.setRefundAmount(residue); // 结算退款金额
if (StringUtils.isBlank(orderBasicInfo.getStartSoc()) || StringUtils.isBlank(orderBasicInfo.getEndSoc())) {
try {
Map<String, String> socMap = YKCUtils.getSOCMap(orderBasicInfo.getTransactionCode());
if (Objects.nonNull(socMap)) {
if (StringUtils.isBlank(orderBasicInfo.getStartSoc())) {
orderBasicInfo.setStartSoc(socMap.get("startSoc"));
}
if (StringUtils.isBlank(orderBasicInfo.getEndSoc())) {
orderBasicInfo.setEndSoc(socMap.get("endSoc"));
}
}
} catch (Exception e) {
logger.error("获取订单充电开始结束SOC失败:{}", e.getMessage());
}
}
} }
/** /**