|
|
@@ -4,8 +4,11 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.zsElectric.boot.business.mapper.BannerInfoMapper;
|
|
|
+import com.zsElectric.boot.business.mapper.ChargeOrderInfoMapper;
|
|
|
+import com.zsElectric.boot.business.mapper.DiscountsActivityMapper;
|
|
|
import com.zsElectric.boot.business.mapper.PolicyFeeMapper;
|
|
|
import com.zsElectric.boot.business.mapper.ThirdPartyStationInfoMapper;
|
|
|
+import com.zsElectric.boot.business.mapper.UserAccountMapper;
|
|
|
import com.zsElectric.boot.business.mapper.UserFirmMapper;
|
|
|
import com.zsElectric.boot.charging.entity.ThirdPartyChargeStatus;
|
|
|
import com.zsElectric.boot.charging.entity.ThirdPartyConnectorInfo;
|
|
|
@@ -19,7 +22,10 @@ import com.zsElectric.boot.business.mapper.ThirdPartyEquipmentInfoMapper;
|
|
|
import com.zsElectric.boot.charging.mapper.ThirdPartyEquipmentPricePolicyMapper;
|
|
|
import com.zsElectric.boot.charging.mapper.ThirdPartyPolicyInfoMapper;
|
|
|
import com.zsElectric.boot.business.model.entity.BannerInfo;
|
|
|
+import com.zsElectric.boot.business.model.entity.ChargeOrderInfo;
|
|
|
+import com.zsElectric.boot.business.model.entity.DiscountsActivity;
|
|
|
import com.zsElectric.boot.business.model.entity.PolicyFee;
|
|
|
+import com.zsElectric.boot.business.model.entity.UserAccount;
|
|
|
import com.zsElectric.boot.business.model.entity.UserFirm;
|
|
|
import com.zsElectric.boot.business.model.query.StationInfoQuery;
|
|
|
import com.zsElectric.boot.business.model.vo.AppletConnectorListVO;
|
|
|
@@ -54,6 +60,7 @@ public class AppletHomeServiceImpl implements AppletHomeService {
|
|
|
|
|
|
private final ThirdPartyStationInfoMapper thirdPartyStationInfoMapper;
|
|
|
private final UserFirmMapper userFirmMapper;
|
|
|
+ private final UserAccountMapper userAccountMapper;
|
|
|
private final BannerInfoMapper bannerInfoMapper;
|
|
|
private final BannerInfoConverter bannerInfoConverter;
|
|
|
private final ThirdPartyConnectorInfoMapper thirdPartyConnectorInfoMapper;
|
|
|
@@ -62,6 +69,8 @@ public class AppletHomeServiceImpl implements AppletHomeService {
|
|
|
private final ThirdPartyPolicyInfoMapper thirdPartyPolicyInfoMapper;
|
|
|
private final PolicyFeeMapper policyFeeMapper;
|
|
|
private final ThirdPartyChargeStatusMapper thirdPartyChargeStatusMapper;
|
|
|
+ private final ChargeOrderInfoMapper chargeOrderInfoMapper;
|
|
|
+ private final DiscountsActivityMapper discountsActivityMapper;
|
|
|
|
|
|
/**
|
|
|
* 时间格式化器 HHmmss
|
|
|
@@ -678,195 +687,68 @@ public class AppletHomeServiceImpl implements AppletHomeService {
|
|
|
|
|
|
@Override
|
|
|
public AppletConnectorDetailVO getConnectorDetail(Long connectorId) {
|
|
|
- // 查询充电接口信息
|
|
|
- ThirdPartyConnectorInfo connectorInfo = thirdPartyConnectorInfoMapper.selectById(connectorId);
|
|
|
- if (connectorInfo == null) {
|
|
|
- log.warn("充电接口不存在,connectorId: {}", connectorId);
|
|
|
- return null;
|
|
|
- }
|
|
|
-
|
|
|
- // 构建返回VO
|
|
|
- AppletConnectorDetailVO result = new AppletConnectorDetailVO();
|
|
|
- result.setConnectorId(connectorId);
|
|
|
- result.setConnectorCode(connectorInfo.getConnectorId());
|
|
|
- result.setConnectorName(connectorInfo.getConnectorName());
|
|
|
- result.setConnectorType(connectorInfo.getConnectorType());
|
|
|
- result.setConnectorTypeName(getConnectorTypeName(connectorInfo.getConnectorType()));
|
|
|
- result.setVoltageUpperLimits(connectorInfo.getVoltageUpperLimits());
|
|
|
- result.setVoltageLowerLimits(connectorInfo.getVoltageLowerLimits());
|
|
|
- result.setCurrent(connectorInfo.getCurrent());
|
|
|
- result.setPower(connectorInfo.getPower());
|
|
|
- result.setParkNo(connectorInfo.getParkNo());
|
|
|
- result.setNationalStandard(connectorInfo.getNationalStandard());
|
|
|
- result.setNationalStandardName(getNationalStandardName(connectorInfo.getNationalStandard()));
|
|
|
- result.setStatus(connectorInfo.getStatus());
|
|
|
- result.setStatusName(getStatusName(connectorInfo.getStatus()));
|
|
|
-
|
|
|
- // 查询设备信息
|
|
|
- ThirdPartyEquipmentInfo equipmentInfo = thirdPartyEquipmentInfoMapper.selectOne(
|
|
|
- new LambdaQueryWrapper<ThirdPartyEquipmentInfo>()
|
|
|
- .eq(ThirdPartyEquipmentInfo::getEquipmentId, connectorInfo.getEquipmentId())
|
|
|
- .last("LIMIT 1")
|
|
|
- );
|
|
|
-
|
|
|
- if (equipmentInfo != null) {
|
|
|
- result.setEquipmentId(equipmentInfo.getId());
|
|
|
- result.setEquipmentCode(equipmentInfo.getEquipmentId());
|
|
|
- result.setEquipmentName(equipmentInfo.getEquipmentName());
|
|
|
- result.setEquipmentType(equipmentInfo.getEquipmentType());
|
|
|
- result.setEquipmentTypeName(getEquipmentTypeName(equipmentInfo.getEquipmentType()));
|
|
|
-
|
|
|
- // 查询充电站信息
|
|
|
- ThirdPartyStationInfo stationInfo = thirdPartyStationInfoMapper.selectOne(
|
|
|
- new LambdaQueryWrapper<ThirdPartyStationInfo>()
|
|
|
- .eq(ThirdPartyStationInfo::getStationId, equipmentInfo.getStationId())
|
|
|
- .last("LIMIT 1")
|
|
|
+ // 获取当前登录用户ID
|
|
|
+ Long userId = SecurityUtils.getUserId();
|
|
|
+
|
|
|
+ // 获取当前时间(HHmmss格式)
|
|
|
+ String currentTime = LocalTime.now().format(TIME_FORMATTER);
|
|
|
+
|
|
|
+ // 查询用户余额
|
|
|
+ BigDecimal userBalance = null;
|
|
|
+ if (userId != null) {
|
|
|
+ UserAccount userAccount = userAccountMapper.selectOne(
|
|
|
+ new LambdaQueryWrapper<UserAccount>()
|
|
|
+ .eq(UserAccount::getUserId, userId)
|
|
|
+ .eq(UserAccount::getIsDeleted, 0)
|
|
|
);
|
|
|
-
|
|
|
- if (stationInfo != null) {
|
|
|
- result.setStationId(stationInfo.getId());
|
|
|
- result.setStationName(stationInfo.getStationName());
|
|
|
- result.setStationAddress(stationInfo.getAddress());
|
|
|
- result.setParkingTips(stationInfo.getStationTips());
|
|
|
-
|
|
|
- // 获取当前价格信息
|
|
|
- String currentTime = LocalTime.now().format(TIME_FORMATTER);
|
|
|
-
|
|
|
- // 查询价格策略
|
|
|
- ThirdPartyEquipmentPricePolicy pricePolicy = thirdPartyEquipmentPricePolicyMapper.selectOne(
|
|
|
- new LambdaQueryWrapper<ThirdPartyEquipmentPricePolicy>()
|
|
|
- .eq(ThirdPartyEquipmentPricePolicy::getConnectorId, connectorInfo.getConnectorId())
|
|
|
- .eq(ThirdPartyEquipmentPricePolicy::getIsDeleted, 0)
|
|
|
- .last("LIMIT 1")
|
|
|
- );
|
|
|
-
|
|
|
- if (pricePolicy != null) {
|
|
|
- // 查询当前时段的价格
|
|
|
- List<ThirdPartyPolicyInfo> policyInfoList = thirdPartyPolicyInfoMapper.selectList(
|
|
|
- new LambdaQueryWrapper<ThirdPartyPolicyInfo>()
|
|
|
- .eq(ThirdPartyPolicyInfo::getPricePolicyId, pricePolicy.getId())
|
|
|
- .eq(ThirdPartyPolicyInfo::getIsDeleted, 0)
|
|
|
- .le(ThirdPartyPolicyInfo::getStartTime, currentTime)
|
|
|
- .orderByDesc(ThirdPartyPolicyInfo::getStartTime)
|
|
|
- .last("LIMIT 1")
|
|
|
- );
|
|
|
-
|
|
|
- if (!policyInfoList.isEmpty()) {
|
|
|
- ThirdPartyPolicyInfo currentPolicyInfo = policyInfoList.get(0);
|
|
|
- BigDecimal elecPrice = currentPolicyInfo.getElecPrice() != null ? currentPolicyInfo.getElecPrice() : BigDecimal.ZERO;
|
|
|
- BigDecimal servicePrice = currentPolicyInfo.getServicePrice() != null ? currentPolicyInfo.getServicePrice() : BigDecimal.ZERO;
|
|
|
- result.setCurrentPrice(elecPrice.add(servicePrice));
|
|
|
- result.setCurrentPeriodDesc(getPeriodFlagName(currentPolicyInfo.getPeriodFlag()));
|
|
|
-
|
|
|
- // 获取当前登录用户ID,查询是否为企业用户
|
|
|
- Long userId = SecurityUtils.getUserId();
|
|
|
- if (userId != null) {
|
|
|
- UserFirm userFirm = userFirmMapper.selectOne(
|
|
|
- new LambdaQueryWrapper<UserFirm>()
|
|
|
- .eq(UserFirm::getUserId, userId)
|
|
|
- .last("LIMIT 1")
|
|
|
- );
|
|
|
-
|
|
|
- if (userFirm != null) {
|
|
|
- // 查询企业价格
|
|
|
- PolicyFee policyFee = policyFeeMapper.selectOne(
|
|
|
- new LambdaQueryWrapper<PolicyFee>()
|
|
|
- .eq(PolicyFee::getStationInfoId, stationInfo.getId())
|
|
|
- .eq(PolicyFee::getSalesType, 1) // 1-企业
|
|
|
- .eq(PolicyFee::getFirmId, userFirm.getFirmId())
|
|
|
- .eq(PolicyFee::getStartTime, currentPolicyInfo.getStartTime())
|
|
|
- .eq(PolicyFee::getIsDeleted, 0)
|
|
|
- .last("LIMIT 1")
|
|
|
- );
|
|
|
-
|
|
|
- if (policyFee != null) {
|
|
|
- // 企业价格 = 电费 + 服务费 + 运营费 + 综合销售费
|
|
|
- BigDecimal opFee = policyFee.getOpFee() != null ? policyFee.getOpFee() : BigDecimal.ZERO;
|
|
|
- BigDecimal compSalesFee = policyFee.getCompSalesFee() != null ? policyFee.getCompSalesFee() : BigDecimal.ZERO;
|
|
|
- BigDecimal enterprisePrice = elecPrice.add(servicePrice).add(opFee).add(compSalesFee);
|
|
|
- result.setEnterprisePrice(enterprisePrice);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ if (userAccount != null) {
|
|
|
+ userBalance = userAccount.getBalance();
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- // 如果是充电中状态,查询实时充电数据
|
|
|
- if (connectorInfo.getStatus() != null && connectorInfo.getStatus() == 3) {
|
|
|
- // 查询正在充电的订单
|
|
|
- ThirdPartyChargeStatus chargeStatus = thirdPartyChargeStatusMapper.selectOne(
|
|
|
- new LambdaQueryWrapper<ThirdPartyChargeStatus>()
|
|
|
- .eq(ThirdPartyChargeStatus::getConnectorId, connectorInfo.getConnectorId())
|
|
|
- .eq(ThirdPartyChargeStatus::getStartChargeSeqStat, 2) // 充电中
|
|
|
- .orderByDesc(ThirdPartyChargeStatus::getUpdateTime)
|
|
|
- .last("LIMIT 1")
|
|
|
+
|
|
|
+ // 查询新用户优惠金额(仅当用户为新用户时)
|
|
|
+ BigDecimal newUserDiscount = null;
|
|
|
+ if (userId != null) {
|
|
|
+ // 检查用户是否有充电订单
|
|
|
+ Long orderCount = chargeOrderInfoMapper.selectCount(
|
|
|
+ new LambdaQueryWrapper<ChargeOrderInfo>()
|
|
|
+ .eq(ChargeOrderInfo::getUserId, userId)
|
|
|
+ .eq(ChargeOrderInfo::getIsDeleted, 0)
|
|
|
);
|
|
|
-
|
|
|
- if (chargeStatus != null) {
|
|
|
- // 电流取A相电流
|
|
|
- result.setCurrentCurrent(chargeStatus.getCurrentA());
|
|
|
- // 电压取A相电压
|
|
|
- result.setCurrentVoltage(chargeStatus.getVoltageA());
|
|
|
- // 功率 = 电压 * 电流 / 1000 (转换为kW)
|
|
|
- if (chargeStatus.getVoltageA() != null && chargeStatus.getCurrentA() != null) {
|
|
|
- BigDecimal power = chargeStatus.getVoltageA()
|
|
|
- .multiply(chargeStatus.getCurrentA())
|
|
|
- .divide(new BigDecimal("1000"), 2, BigDecimal.ROUND_HALF_UP);
|
|
|
- result.setCurrentPower(power);
|
|
|
+
|
|
|
+ // 如果是新用户(没有订单),查询新用户首单优惠金额
|
|
|
+ if (orderCount == 0) {
|
|
|
+ // 查询c_discounts_activity表,type=1(新用户首单立减)且status=1(启用)的数据
|
|
|
+ List<DiscountsActivity> discountActivities = discountsActivityMapper.selectList(
|
|
|
+ new LambdaQueryWrapper<DiscountsActivity>()
|
|
|
+ .eq(DiscountsActivity::getType, 1) // 1-新用户首单立减
|
|
|
+ .eq(DiscountsActivity::getStatus, 1) // 1-启用
|
|
|
+ .eq(DiscountsActivity::getIsDeleted, 0)
|
|
|
+ );
|
|
|
+
|
|
|
+ // 计算所有启用的新用户优惠金额总和
|
|
|
+ if (!discountActivities.isEmpty()) {
|
|
|
+ newUserDiscount = discountActivities.stream()
|
|
|
+ .map(DiscountsActivity::getDiscount)
|
|
|
+ .filter(discount -> discount != null)
|
|
|
+ .reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+
|
|
|
+ log.info("新用户首单优惠金额 - userId: {}, discount: {}", userId, newUserDiscount);
|
|
|
}
|
|
|
- result.setSoc(chargeStatus.getSoc());
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- // 设置最后更新时间
|
|
|
- if (connectorInfo.getUpdateTime() != null) {
|
|
|
- result.setLastUpdateTime(connectorInfo.getUpdateTime().toString());
|
|
|
+
|
|
|
+ // 调用Mapper方法,一次SQL查询获取所有信息
|
|
|
+ AppletConnectorDetailVO result = thirdPartyConnectorInfoMapper.selectConnectorDetailById(
|
|
|
+ connectorId, userId, currentTime, userBalance, newUserDiscount
|
|
|
+ );
|
|
|
+
|
|
|
+ if (result == null) {
|
|
|
+ log.warn("充电接口不存在,connectorId: {}", connectorId);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 获取接口类型名称
|
|
|
- */
|
|
|
- private String getConnectorTypeName(Integer connectorType) {
|
|
|
- if (connectorType == null) {
|
|
|
- return "未知";
|
|
|
- }
|
|
|
- switch (connectorType) {
|
|
|
- case 1:
|
|
|
- return "家用插座";
|
|
|
- case 2:
|
|
|
- return "交流接口插座";
|
|
|
- case 3:
|
|
|
- return "交流接口插头";
|
|
|
- case 4:
|
|
|
- return "直流接口枪头";
|
|
|
- case 5:
|
|
|
- return "无线充电座";
|
|
|
- case 6:
|
|
|
- return "其他";
|
|
|
- default:
|
|
|
- return "未知";
|
|
|
- }
|
|
|
- }
|
|
|
|
|
|
- /**
|
|
|
- * 获取国家标准名称
|
|
|
- */
|
|
|
- private String getNationalStandardName(Integer nationalStandard) {
|
|
|
- if (nationalStandard == null) {
|
|
|
- return "未知";
|
|
|
- }
|
|
|
- switch (nationalStandard) {
|
|
|
- case 1:
|
|
|
- return "2011版";
|
|
|
- case 2:
|
|
|
- return "2015版";
|
|
|
- default:
|
|
|
- return "未知";
|
|
|
- }
|
|
|
- }
|
|
|
}
|