update 运营端小程序查询枪口列表页

This commit is contained in:
Lemon
2026-01-05 16:38:22 +08:00
parent c2e5e900b0
commit 96725e53e5
9 changed files with 281 additions and 39 deletions

View File

@@ -10,6 +10,7 @@ import org.springframework.stereotype.Component;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
/**
* spring redis 工具类
@@ -603,4 +604,44 @@ public class RedisCache {
redisTemplate.opsForList().trim(redisKey, 0, 9);
}
/**
* 批量获取 Redis List 中每个 key 对应的最后一条数据
*
* @param keys Redis 键集合
* @param <T> 返回值类型
* @return Mapkey 为 Redis 键value 为对应 List 的最后一条数据
*/
public <T> Map<String, T> multiGetLastListValue(final List<String> keys) {
if (keys == null || keys.isEmpty()) {
return new HashMap<>();
}
Map<String, T> result = new HashMap<>();
for (String key : keys) {
if (StringUtils.isNotBlank(key)) {
// 使用 index -1 获取 List 的最后一个元素
T lastValue = (T) redisTemplate.opsForList().index(key, -1);
if (lastValue != null) {
result.put(key, lastValue);
}
}
}
return result;
}
/**
* 获取 Redis List 中指定 key 的最后一条数据
*
* @param key Redis 键
* @param <T> 返回值类型
* @return List 的最后一条数据,如果 key 不存在或 List 为空则返回 null
*/
public <T> T getLastListValue(final String key) {
if (StringUtils.isBlank(key)) {
return null;
}
// 使用 index -1 获取 List 的最后一个元素
return (T) redisTemplate.opsForList().index(key, -1);
}
}

View File

@@ -450,4 +450,11 @@ public interface OrderBasicInfoMapper {
* @return
*/
List<IndexPlatformProfitVO> getInsuranceAmount(@Param("dto") IndexQueryDTO dto);
/**
* 批量查询充电枪信息
* @param chargingConnectorCodeList
* @return
*/
List<BusinessOrderDetailInfoVO> batchQueryChargingConnectorInfo(@Param("pileConnectorCodes") List<String> chargingConnectorCodeList);
}

View File

@@ -136,6 +136,14 @@ public interface PileConnectorInfoMapper {
*/
List<ConnectorInfoVO> batchSelectConnectorList(@Param("stationIds") List<String> stationIds);
/**
* 此方法与上面方法一样只是多加了status字段
* @param stationIds
* @param status
* @return
*/
List<ConnectorInfoVO> batchSelectConnectorListByStatus(@Param("stationIds") List<String> stationIds, @Param("status") String status);
/**
* 查询异常设备数量
* @param stationId

View File

@@ -652,4 +652,18 @@ public interface OrderBasicInfoService{
* @return
*/
List<IndexPlatformProfitVO> getInsuranceAmount(IndexQueryDTO dto);
/**
* 批量查询充电枪信息
* @param chargingConnectorCodeList
* @return
*/
List<BusinessOrderDetailInfoVO> batchQueryChargingConnectorInfo(List<String> chargingConnectorCodeList);
/**
* 批量查询充电枪实时数据
* @param transactionCodeList
* @return
*/
List<RealTimeMonitorData> getRealTimeMonitorDataList(List<String> transactionCodeList);
}

View File

@@ -6245,5 +6245,64 @@ public class OrderBasicInfoServiceImpl implements OrderBasicInfoService {
public List<IndexPlatformProfitVO> getInsuranceAmount(IndexQueryDTO dto) {
return orderBasicInfoMapper.getInsuranceAmount(dto);
}
/**
* 批量查询充电枪口信息
* @param chargingConnectorCodeList
* @return
*/
@Override
public List<BusinessOrderDetailInfoVO> batchQueryChargingConnectorInfo(List<String> chargingConnectorCodeList) {
// 这个infoVOs只有简单数据没有充电中数据
List<BusinessOrderDetailInfoVO> infoVOS = orderBasicInfoMapper.batchQueryChargingConnectorInfo(chargingConnectorCodeList);
List<String> transactionCodes = infoVOS.stream()
.map(BusinessOrderDetailInfoVO::getTransactionCode)
.collect(Collectors.toList());
List<RealTimeMonitorData> list = getRealTimeMonitorDataList(transactionCodes);
Map<String, RealTimeMonitorData> bMap = list.stream()
.collect(Collectors.toMap(
RealTimeMonitorData::getPileConnectorCode,
x -> x,
(existing, replacement) -> existing // 如果有重复key保留第一个
));
for (BusinessOrderDetailInfoVO infoVO : infoVOS) {
String pileConnectorCode = infoVO.getPileConnectorCode();
if (pileConnectorCode != null && bMap.containsKey(pileConnectorCode)) {
RealTimeMonitorData realTimeMonitorData = bMap.get(pileConnectorCode);
infoVO.setChargeDegree(realTimeMonitorData.getChargingDegree());
infoVO.setChargeTime(realTimeMonitorData.getSumChargingTime());
infoVO.setEndSOC(realTimeMonitorData.getSOC());
infoVO.setTimeRemaining(realTimeMonitorData.getTimeRemaining());
}
}
return infoVOS;
}
/**
* 批量查询实时监控数据
* @param transactionCodeList
* @return
*/
@Override
public List<RealTimeMonitorData> getRealTimeMonitorDataList(List<String> transactionCodeList) {
List<RealTimeMonitorData> resultList = new ArrayList<>();
List<String> redisKeys = new ArrayList<>();
for (String transactionCode : transactionCodeList) {
// 截取枪口编号
String pileConnectorCode = transactionCode.substring(0, 16);
redisKeys.add(CacheConstants.PILE_REAL_TIME_MONITOR_DATA + pileConnectorCode + "_" + transactionCode);
}
// 批量查询多个key值的数据 key: redisKey, value: 最后一条实时数据
Map<String, RealTimeMonitorData> map = redisCache.multiGetLastListValue(redisKeys);
// 循环该map
for (Map.Entry<String, RealTimeMonitorData> entry : map.entrySet()) {
resultList.add(entry.getValue());
}
return resultList;
}
}

View File

@@ -20,6 +20,7 @@ import com.jsowell.common.enums.ykc.PileStatusEnum;
import com.jsowell.common.enums.ykc.ReturnCodeEnum;
import com.jsowell.common.exception.BusinessException;
import com.jsowell.common.util.DateUtils;
import com.jsowell.common.util.PageUtils;
import com.jsowell.common.util.SecurityUtils;
import com.jsowell.common.util.StringUtils;
import com.jsowell.common.util.spring.SpringUtils;
@@ -34,9 +35,12 @@ import com.jsowell.pile.dto.business.QueryConnectorInfoDTO;
import com.jsowell.pile.mapper.PileBasicInfoMapper;
import com.jsowell.pile.mapper.PileConnectorInfoMapper;
import com.jsowell.pile.service.*;
import com.jsowell.pile.util.UserUtils;
import com.jsowell.pile.vo.base.ConnectorInfoVO;
import com.jsowell.pile.vo.base.LoginUserDetailVO;
import com.jsowell.pile.vo.uniapp.business.BusinessConnectorDetailVO;
import com.jsowell.pile.vo.uniapp.business.BusinessConnectorInfoVO;
import com.jsowell.pile.vo.uniapp.business.BusinessOrderDetailInfoVO;
import com.jsowell.pile.vo.web.PileConnectorInfoVO;
import com.jsowell.pile.vo.web.PileDetailVO;
import com.jsowell.pile.vo.web.PileModelInfoVO;
@@ -1053,57 +1057,120 @@ public class PileConnectorInfoServiceImpl implements PileConnectorInfoService {
/**
* 查询站点枪口列表
*
* @param dto
* @return
*/
@Override
public BusinessConnectorInfoVO getConnectorListByStationAndStatus(QueryConnectorInfoDTO dto) {
List<PileConnectorInfoVO> list = new ArrayList<>();
PileConnectorInfoVO info = null;
int pageNum = dto.getPageNum() == 0 ? 1 : dto.getPageNum();
int pageSize = dto.getPageSize() == 0 ? 10 : dto.getPageSize();
// 获取登录账号信息
Long deptId = SecurityUtils.getDeptId();
List<String> stationIds = pileMerchantInfoService.queryByMerchantDeptIds(Lists.newArrayList(String.valueOf(deptId)));
LoginUserDetailVO loginUserDetail = UserUtils.getLoginUserDetail();
List<String> merchantIdList = loginUserDetail.getFirstMerchantIdList();
List<PileStationInfo> stationInfos = pileStationInfoService.getStationInfosByMerchantIds(merchantIdList);
// 获取站点ids
List<Long> longStationIds = stationInfos.stream()
.map(PileStationInfo::getId)
.collect(Collectors.toList());
List<String> stationIds = longStationIds.stream()
.map(String::valueOf) // 或 s -> Long.parseLong(s)
.collect(Collectors.toList());
String connectorStatus = dto.getConnectorStatus();
int pageNum = dto.getPageNum();
int pageSize = dto.getPageSize();
BusinessConnectorInfoVO vo = new BusinessConnectorInfoVO();
// 根据站点ids查询枪口列表(有缓存)
List<ConnectorInfoVO> connectorInfoVOS = batchSelectConnectorList(stationIds);
// 筛选出枪口编号
List<String> pileConnectorCodeList = connectorInfoVOS.stream()
.map(ConnectorInfoVO::getPileConnectorCode)
.collect(Collectors.toList());
// 批量获取某状态的枪口数量
Map<String, Integer> connectorStatusNumMap = getConnectorStatus(pileConnectorCodeList);
Integer offlineNum = connectorStatusNumMap.get("offlineNum");
Integer freeNum = connectorStatusNumMap.get("freeNum");
Integer occupiedNum = connectorStatusNumMap.get("occupiedNum");
Integer chargingNum = connectorStatusNumMap.get("chargingNum");
Integer faultNum = connectorStatusNumMap.get("faultNum");
// 根据站点ids、枪口状态查询枪口列表(有缓存)
PageUtils.startPage(pageNum, pageSize);
// List<ConnectorInfoVO> connectorInfoVOS = batchSelectConnectorList(stationIds);
List<ConnectorInfoVO> connectorInfoVOS = pileConnectorInfoMapper.batchSelectConnectorListByStatus(stationIds, connectorStatus);
vo.setConnectorNum(pileConnectorCodeList.size());
vo.setOfflineConnectorNum(offlineNum);
vo.setFreeConnectorNum(freeNum);
vo.setOccupiedConnectorNum(occupiedNum);
vo.setChargingConnectorNum(chargingNum);
vo.setFaultConnectorNum(faultNum);
// 初始化对象
List<String> chargingConnectorCodeList = new ArrayList<>(); // 充电中枪口 pileConnectorCodeList
int offlineNum = 0;
int freeNum = 0;
int occupiedNum = 0;
int chargingNum = 0;
int faultNum = 0;
List<Long> longStationIds = stationIds.stream()
.map(Long::parseLong) // 或 s -> Long.parseLong(s)
.collect(Collectors.toList());
for (ConnectorInfoVO connectorInfoVO : connectorInfoVOS) {
String pileConnectorCode = connectorInfoVO.getPileConnectorCode();
String status = connectorInfoVO.getConnectorStatus();
info = new PileConnectorInfoVO();
if (StringUtils.equals(status, PileConnectorDataBaseStatusEnum.OFF_NETWORK.getValue())) {
// 离网
offlineNum += 1;
info.setPileConnectorCode(pileConnectorCode);
info.setStatus(Integer.parseInt(PileConnectorDataBaseStatusEnum.OFF_NETWORK.getValue()));
list.add(info);
}
if (StringUtils.equals(status, PileConnectorDataBaseStatusEnum.FREE.getValue())) {
// 空闲
freeNum += 1;
info.setPileConnectorCode(pileConnectorCode);
info.setStatus(Integer.parseInt(PileConnectorDataBaseStatusEnum.FREE.getValue()));
list.add(info);
}
if (StringUtils.equals(status, PileConnectorDataBaseStatusEnum.OCCUPIED_NOT_CHARGED.getValue())) {
// 占用未充电
occupiedNum += 1;
info.setPileConnectorCode(pileConnectorCode);
info.setStatus(Integer.parseInt(PileConnectorDataBaseStatusEnum.OCCUPIED_NOT_CHARGED.getValue()));
list.add(info);
}
if (StringUtils.equals(status, PileConnectorDataBaseStatusEnum.OCCUPIED_CHARGING.getValue())) {
// 充电中
chargingNum += 1;
chargingConnectorCodeList.add(pileConnectorCode);
}
if (StringUtils.equals(status, PileConnectorDataBaseStatusEnum.FAULT.getValue())) {
// 故障
faultNum += 1;
info.setPileConnectorCode(pileConnectorCode);
info.setStatus(Integer.parseInt(PileConnectorDataBaseStatusEnum.FAULT.getValue()));
list.add(info);
}
vo.setConnectorNum(connectorInfoVOS.size());
vo.setOfflineConnectorNum(offlineNum);
vo.setFreeConnectorNum(freeNum);
vo.setOccupiedConnectorNum(occupiedNum);
vo.setChargingConnectorNum(chargingNum);
vo.setFaultConnectorNum(faultNum);
// 根据站点id和枪口状态查询枪口列表
QueryConnectorListDTO queryConnectorListDTO = QueryConnectorListDTO.builder()
.pageNum(pageNum)
.pageSize(pageSize)
.stationIdList(longStationIds)
.build();
List<PileConnectorInfoVO> pileConnectorInfoVOList = getConnectorInfoListByParams(queryConnectorListDTO);
if (connectorStatus != null) {
// 筛选出符合状态的数据
pileConnectorInfoVOList = pileConnectorInfoVOList.stream()
.filter(x -> x.getStatus() == Integer.parseInt(connectorStatus))
.collect(Collectors.toList());
}
vo.setPileConnectorInfoVOList(pileConnectorInfoVOList);
// 如果充电中的枪列表不为空
if (CollectionUtils.isNotEmpty(chargingConnectorCodeList)) {
// 根据充电中的枪口List批量获取充电中的枪口信息
List<BusinessOrderDetailInfoVO> infoVOS = orderBasicInfoService.batchQueryChargingConnectorInfo(chargingConnectorCodeList);
Map<String, BusinessOrderDetailInfoVO> bMap = infoVOS.stream()
.collect(Collectors.toMap(
BusinessOrderDetailInfoVO::getPileConnectorCode,
x -> x,
(existing, replacement) -> existing // 如果有重复key保留第一个
));
for (PileConnectorInfoVO pileConnectorInfoVO : list) {
String pileConnectorCode = pileConnectorInfoVO.getPileConnectorCode();
if (pileConnectorCode != null && bMap.containsKey(pileConnectorCode)) {
BusinessOrderDetailInfoVO businessOrderDetailInfoVO = bMap.get(pileConnectorCode);
pileConnectorInfoVO.setStatus(Integer.parseInt(PileConnectorDataBaseStatusEnum.OCCUPIED_CHARGING.getValue()));
pileConnectorInfoVO.setChargingDegree(new BigDecimal(businessOrderDetailInfoVO.getChargeDegree()));
pileConnectorInfoVO.setChargingTime(businessOrderDetailInfoVO.getChargeTime());
pileConnectorInfoVO.setSOC(businessOrderDetailInfoVO.getEndSOC());
pileConnectorInfoVO.setTimeRemaining(businessOrderDetailInfoVO.getTimeRemaining());
}
}
}
vo.setPileConnectorInfoVOList(list);
return vo;
}

View File

@@ -25,6 +25,11 @@ public class BusinessOrderDetailInfoVO {
private String pileConnectorCode;
/**
* 交易流水号
*/
private String transactionCode;
/**
* 充电次数
*/
@@ -185,4 +190,9 @@ public class BusinessOrderDetailInfoVO {
*/
private String memberId;
/**
* 剩余时间
*/
private String timeRemaining;
}

View File

@@ -3521,4 +3521,17 @@
and `settlement_time` BETWEEN #{dto.startTime,jdbcType=VARCHAR} and #{dto.endTime,jdbcType=VARCHAR}
group by DATE_FORMAT(settlement_time, '%Y-%m-%d');
</select>
<select id="batchQueryChargingConnectorInfo"
resultType="com.jsowell.pile.vo.uniapp.business.BusinessOrderDetailInfoVO">
select
order_code as orderCode,
transaction_code as transactionCode,
pile_connector_code as pileConnectorCode
from order_basic_info where pile_connector_code in
<foreach item="pileConnectorCode" collection="pileConnectorCodes" separator="," open="(" close=")">
#{pileConnectorCode}
</foreach>
and order_status = '1'
</select>
</mapper>

View File

@@ -319,4 +319,27 @@
AND
t1.del_flag = '0'
</select>
<select id="batchSelectConnectorListByStatus" resultType="com.jsowell.pile.vo.base.ConnectorInfoVO">
SELECT
t1.pile_connector_code as pileConnectorCode,
t2.station_id as stationId,
t1.STATUS as connectorStatus,
t1.pile_sn as pileSn,
t2.model_id as modelId,
t3.speed_type as chargingType,
t3.rated_power as ratedPower
FROM
pile_connector_info t1
JOIN pile_basic_info t2 ON (t1.pile_sn = t2.sn AND t2.del_flag = '0')
JOIN pile_model_info t3 ON (t2.model_id = t3.id AND t3.del_flag = '0')
WHERE t1.del_flag = '0'
AND t2.station_id in
<foreach collection="stationIds" item="stationId" open="(" separator="," close=")">
#{stationId, jdbcType=VARCHAR}
</foreach>
<if test="status != null and status != ''">
AND t1.status = #{status,jdbcType=VARCHAR}
</if>
</select>
</mapper>