2023-03-04 16:29:55 +08:00
|
|
|
|
package com.jsowell.service;
|
|
|
|
|
|
|
2024-09-09 19:25:26 +08:00
|
|
|
|
import com.alibaba.fastjson2.JSON;
|
2023-03-04 16:29:55 +08:00
|
|
|
|
import com.github.pagehelper.PageHelper;
|
|
|
|
|
|
import com.github.pagehelper.PageInfo;
|
|
|
|
|
|
import com.google.common.collect.Lists;
|
|
|
|
|
|
import com.jsowell.common.constant.Constants;
|
|
|
|
|
|
import com.jsowell.common.core.domain.ykc.RealTimeMonitorData;
|
|
|
|
|
|
import com.jsowell.common.core.page.PageResponse;
|
2023-07-29 15:37:11 +08:00
|
|
|
|
import com.jsowell.common.enums.DelFlagEnum;
|
2024-09-21 14:54:58 +08:00
|
|
|
|
import com.jsowell.common.enums.SoftwareProtocolEnum;
|
2024-08-16 10:03:16 +08:00
|
|
|
|
import com.jsowell.common.enums.ykc.*;
|
2023-03-04 16:29:55 +08:00
|
|
|
|
import com.jsowell.common.exception.BusinessException;
|
2024-06-21 13:50:19 +08:00
|
|
|
|
import com.jsowell.common.util.*;
|
2024-09-10 12:03:53 +08:00
|
|
|
|
import com.jsowell.common.util.spring.SpringUtils;
|
2024-06-18 16:03:23 +08:00
|
|
|
|
import com.jsowell.pile.domain.*;
|
|
|
|
|
|
import com.jsowell.pile.dto.*;
|
2023-07-08 09:44:05 +08:00
|
|
|
|
import com.jsowell.pile.service.*;
|
2023-03-04 16:29:55 +08:00
|
|
|
|
import com.jsowell.pile.transaction.dto.PileTransactionDTO;
|
|
|
|
|
|
import com.jsowell.pile.transaction.service.TransactionService;
|
|
|
|
|
|
import com.jsowell.pile.vo.base.ConnectorInfoVO;
|
|
|
|
|
|
import com.jsowell.pile.vo.base.MerchantInfoVO;
|
|
|
|
|
|
import com.jsowell.pile.vo.base.PileInfoVO;
|
2024-09-03 09:39:28 +08:00
|
|
|
|
import com.jsowell.pile.vo.uniapp.customer.*;
|
2023-03-31 16:19:26 +08:00
|
|
|
|
import com.jsowell.pile.vo.web.PileDetailVO;
|
2023-03-04 16:29:55 +08:00
|
|
|
|
import com.jsowell.pile.vo.web.PileStationVO;
|
|
|
|
|
|
import org.apache.commons.collections4.CollectionUtils;
|
2023-03-13 17:01:07 +08:00
|
|
|
|
import org.apache.commons.lang3.RandomStringUtils;
|
2024-09-09 19:25:26 +08:00
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
|
|
import org.slf4j.LoggerFactory;
|
2023-03-04 16:29:55 +08:00
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
2024-09-10 12:03:53 +08:00
|
|
|
|
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
2023-03-04 16:29:55 +08:00
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
|
import java.math.BigDecimal;
|
2023-07-12 16:31:09 +08:00
|
|
|
|
import java.util.*;
|
2023-03-04 16:29:55 +08:00
|
|
|
|
import java.util.concurrent.CompletableFuture;
|
|
|
|
|
|
import java.util.concurrent.ExecutionException;
|
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
2024-09-09 19:25:26 +08:00
|
|
|
|
|
2023-03-04 16:29:55 +08:00
|
|
|
|
@Service
|
|
|
|
|
|
public class PileService {
|
2024-09-09 19:25:26 +08:00
|
|
|
|
private final Logger log = LoggerFactory.getLogger(PileService.class);
|
2023-03-04 16:29:55 +08:00
|
|
|
|
|
2024-09-10 12:03:53 +08:00
|
|
|
|
// 引入线程池
|
|
|
|
|
|
private ThreadPoolTaskExecutor executor = SpringUtils.getBean("threadPoolTaskExecutor");
|
|
|
|
|
|
|
2023-03-04 16:29:55 +08:00
|
|
|
|
@Autowired
|
|
|
|
|
|
private TransactionService pileTransactionService;
|
|
|
|
|
|
|
|
|
|
|
|
@Resource
|
2024-09-03 09:36:27 +08:00
|
|
|
|
private PileSnGenerateService snUtils;
|
2023-03-04 16:29:55 +08:00
|
|
|
|
|
|
|
|
|
|
@Autowired
|
2024-01-06 15:20:28 +08:00
|
|
|
|
private PileBasicInfoService pileBasicInfoService;
|
2023-03-04 16:29:55 +08:00
|
|
|
|
|
|
|
|
|
|
@Autowired
|
2024-01-06 15:20:28 +08:00
|
|
|
|
private PileConnectorInfoService pileConnectorInfoService;
|
2023-03-04 16:29:55 +08:00
|
|
|
|
|
|
|
|
|
|
@Autowired
|
2024-01-06 15:20:28 +08:00
|
|
|
|
private PileStationInfoService pileStationInfoService;
|
2023-03-04 16:29:55 +08:00
|
|
|
|
|
|
|
|
|
|
@Autowired
|
2024-01-06 15:20:28 +08:00
|
|
|
|
private PileMerchantInfoService pileMerchantInfoService;
|
2023-03-04 16:29:55 +08:00
|
|
|
|
|
|
|
|
|
|
@Autowired
|
2024-01-06 15:20:28 +08:00
|
|
|
|
private PileBillingTemplateService pileBillingTemplateService;
|
2023-03-04 16:29:55 +08:00
|
|
|
|
|
|
|
|
|
|
@Autowired
|
2024-01-06 15:20:28 +08:00
|
|
|
|
private PileMemberRelationService pileMemberRelationService;
|
2023-03-04 16:29:55 +08:00
|
|
|
|
|
|
|
|
|
|
@Autowired
|
2024-01-06 15:20:28 +08:00
|
|
|
|
private MemberBasicInfoService memberBasicInfoService;
|
2023-03-04 16:29:55 +08:00
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
private MemberService memberService;
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
2024-01-06 15:13:50 +08:00
|
|
|
|
private OrderBasicInfoService orderBasicInfoService;
|
2023-03-04 16:29:55 +08:00
|
|
|
|
|
2023-04-06 15:30:55 +08:00
|
|
|
|
@Autowired
|
|
|
|
|
|
private PileRemoteService pileRemoteService;
|
|
|
|
|
|
|
2024-06-18 16:03:23 +08:00
|
|
|
|
@Autowired
|
2024-06-20 14:34:35 +08:00
|
|
|
|
private PileReservationInfoService pileReservationInfoService;
|
2024-06-18 16:03:23 +08:00
|
|
|
|
|
2024-11-19 17:11:07 +08:00
|
|
|
|
@Autowired
|
|
|
|
|
|
private PersonalChargingRecordService personalChargingRecordService;
|
|
|
|
|
|
|
2023-03-04 16:29:55 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 查询设备信息
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param pileConnectorCode 充电枪编号 880000000000000101
|
|
|
|
|
|
* @return 设备信息集合
|
|
|
|
|
|
*/
|
|
|
|
|
|
public PileConnectorDetailVO queryPileConnectorDetail(String pileConnectorCode) {
|
|
|
|
|
|
return pileBasicInfoService.queryPileConnectorDetail(pileConnectorCode);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 查询设备信息
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param pileSn 充电枪编号 8800000000000001
|
|
|
|
|
|
* @param connectorCode 充电枪口号 01
|
|
|
|
|
|
* @return 设备信息集合
|
|
|
|
|
|
*/
|
|
|
|
|
|
public PileConnectorDetailVO queryPileConnectorDetail(String pileSn, String connectorCode) {
|
|
|
|
|
|
return queryPileConnectorDetail(pileSn + connectorCode);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public int batchCreatePile(BatchCreatePileDTO dto) {
|
2024-09-21 14:54:58 +08:00
|
|
|
|
String softwareProtocol = dto.getSoftwareProtocol();
|
2024-12-13 17:12:44 +08:00
|
|
|
|
// if (StringUtils.isBlank(softwareProtocol)) {
|
|
|
|
|
|
// throw new BusinessException(ReturnCodeEnum.valueOf("软件协议不能为空"));
|
|
|
|
|
|
// }
|
2023-03-04 16:29:55 +08:00
|
|
|
|
// 批量生成sn号
|
2024-09-21 14:54:58 +08:00
|
|
|
|
List<String> snList = null;
|
|
|
|
|
|
if (StringUtils.equals(SoftwareProtocolEnum.YOU_DIAN.getValue(), softwareProtocol)) {
|
2024-09-21 16:26:05 +08:00
|
|
|
|
snList = snUtils.generateEBikeSN(dto.getNum());
|
2024-12-13 17:12:44 +08:00
|
|
|
|
} else if (StringUtils.equals(SoftwareProtocolEnum.YUN_KUAI_CHONG.getValue(), softwareProtocol)){
|
2024-09-21 16:26:05 +08:00
|
|
|
|
snList = snUtils.generateEVPileSN(dto.getNum());
|
2024-12-13 17:12:44 +08:00
|
|
|
|
} else {
|
|
|
|
|
|
throw new BusinessException(ReturnCodeEnum.valueOf("软件协议不正确"));
|
2024-09-21 14:54:58 +08:00
|
|
|
|
}
|
2023-03-04 16:29:55 +08:00
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
List<PileBasicInfo> basicInfoList = Lists.newArrayList();
|
|
|
|
|
|
List<PileConnectorInfo> connectorInfoList = Lists.newArrayList();
|
|
|
|
|
|
PileBasicInfo basicInfo = null;
|
|
|
|
|
|
PileConnectorInfo connectorInfo = null;
|
|
|
|
|
|
for (String sn : snList) {
|
|
|
|
|
|
// 组装pile_basic_info表数据
|
|
|
|
|
|
basicInfo = new PileBasicInfo();
|
|
|
|
|
|
basicInfo.setSn(sn); // sn号
|
2023-03-13 17:01:07 +08:00
|
|
|
|
basicInfo.setBusinessType(dto.getChargerPileType()); // 经营类型 1-运营桩;2-个人桩
|
|
|
|
|
|
if (StringUtils.equals(BusinessTypeEnum.INDIVIDUAL_PILE.getValue(), dto.getChargerPileType())) {
|
|
|
|
|
|
// 个人桩生成一个八位的密钥(字母加数字)
|
|
|
|
|
|
String secretKey = RandomStringUtils.randomAlphanumeric(8).toUpperCase(Locale.ROOT);
|
|
|
|
|
|
basicInfo.setSecretKey(secretKey);
|
|
|
|
|
|
}
|
2024-09-21 14:54:58 +08:00
|
|
|
|
basicInfo.setSoftwareProtocol(softwareProtocol); // 软件协议
|
2023-03-04 16:29:55 +08:00
|
|
|
|
basicInfo.setMerchantId(Long.valueOf(dto.getMerchantId())); // 运营商id
|
|
|
|
|
|
basicInfo.setStationId(Long.valueOf(dto.getStationId())); // 站点id
|
|
|
|
|
|
basicInfo.setModelId(Long.valueOf(dto.getModelId())); // 型号id
|
|
|
|
|
|
basicInfo.setProductionDate(dto.getProductionDate()); // 生产日期
|
|
|
|
|
|
basicInfo.setLicenceId(null); // TODO 证书编号
|
|
|
|
|
|
basicInfo.setSimId(null); // TODO sim卡
|
|
|
|
|
|
basicInfo.setRemark(dto.getRemark()); // 备注
|
|
|
|
|
|
basicInfo.setCreateBy(SecurityUtils.getUsername()); // 创建人
|
2023-07-29 15:37:11 +08:00
|
|
|
|
basicInfo.setDelFlag(DelFlagEnum.NORMAL.getValue()); // 删除标识
|
2023-03-04 16:29:55 +08:00
|
|
|
|
basicInfoList.add(basicInfo);
|
|
|
|
|
|
|
|
|
|
|
|
for (int i = 1; i < dto.getConnectorNum() + 1; i++) {
|
|
|
|
|
|
// 组装pile_connector_info表数据
|
|
|
|
|
|
connectorInfo = new PileConnectorInfo();
|
|
|
|
|
|
connectorInfo.setPileSn(sn); // sn号
|
|
|
|
|
|
String connectorCode = String.format("%1$02d", i);
|
|
|
|
|
|
connectorInfo.setPileConnectorCode(sn + connectorCode); // 枪口号
|
|
|
|
|
|
connectorInfo.setStatus(Constants.ZERO); //状态,默认 0-离网
|
|
|
|
|
|
connectorInfo.setCreateBy(SecurityUtils.getUsername()); // 创建人
|
2023-07-29 15:37:11 +08:00
|
|
|
|
connectorInfo.setDelFlag(DelFlagEnum.NORMAL.getValue()); // 删除标识
|
2023-03-04 16:29:55 +08:00
|
|
|
|
connectorInfoList.add(connectorInfo);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 批量入库
|
|
|
|
|
|
PileTransactionDTO transactionDTO = PileTransactionDTO.builder()
|
|
|
|
|
|
.pileBasicInfoList(basicInfoList)
|
|
|
|
|
|
.pileConnectorInfoList(connectorInfoList)
|
|
|
|
|
|
.build();
|
|
|
|
|
|
return pileTransactionService.doCreatePileTransaction(transactionDTO);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 前端扫码跳转接口
|
|
|
|
|
|
*/
|
2024-09-10 12:03:53 +08:00
|
|
|
|
public AppletPileDetailVO getPileDetailByPileSnV2(String param) throws Exception {
|
2024-09-09 20:19:26 +08:00
|
|
|
|
AppletPileDetailVO vo = null;
|
2024-09-09 20:47:34 +08:00
|
|
|
|
log.info("查询充电枪口详情-getPileDetailByPileSn, param:{}", param);
|
|
|
|
|
|
if (StringUtils.isBlank(param)) {
|
|
|
|
|
|
throw new BusinessException(ReturnCodeEnum.CODE_PARAM_NOT_NULL_ERROR);
|
|
|
|
|
|
}
|
|
|
|
|
|
String pileSn = YKCUtils.getPileSn(param);
|
|
|
|
|
|
log.info("查询充电枪口详情-getPileDetailByPileSn, pileSn:{}", pileSn);
|
|
|
|
|
|
// 查询充电桩信息
|
|
|
|
|
|
PileInfoVO pileInfoVO = pileBasicInfoService.selectPileInfoBySn(pileSn);
|
|
|
|
|
|
log.info("查询充电枪口详情-pileInfoVO:{}", JSON.toJSONString(pileInfoVO));
|
2024-09-09 21:45:49 +08:00
|
|
|
|
if (pileInfoVO == null) {
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 判断桩是否在线
|
|
|
|
|
|
boolean onLineStatus = pileConnectorInfoService.checkPileOffLine(pileInfoVO.getPileSn());
|
|
|
|
|
|
log.info("查询充电枪口详情-判断桩是否在线:{}, onLineStatus:{}", pileInfoVO.getPileSn(), onLineStatus);
|
|
|
|
|
|
if (onLineStatus) {
|
|
|
|
|
|
// true为离线
|
|
|
|
|
|
throw new BusinessException(ReturnCodeEnum.CODE_PILE_CONNECTOR_STATUS_OFF_LINE);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 查询站点信息
|
|
|
|
|
|
PileStationVO stationInfo = pileStationInfoService.getStationInfo(pileInfoVO.getStationId());
|
|
|
|
|
|
log.info("查询充电枪口详情-getStationInfo:{}, onLineStatus:{}", pileInfoVO.getStationId(), JSON.toJSONString(stationInfo));
|
|
|
|
|
|
if (stationInfo == null || StringUtils.equals(stationInfo.getOpenFlag(), Constants.ZERO)) {
|
|
|
|
|
|
throw new BusinessException(ReturnCodeEnum.CODE_STATION_IS_NOT_OPEN);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
List<ConnectorInfoVO> connectorInfoList = pileConnectorInfoService.selectConnectorInfoList(pileSn);
|
|
|
|
|
|
List<BillingPriceVO> billingPriceVOS = pileBillingTemplateService.queryBillingPrice(pileInfoVO.getStationId());
|
|
|
|
|
|
MerchantInfoVO merchantInfoVO = pileMerchantInfoService.getMerchantInfoVO(pileInfoVO.getMerchantId());
|
|
|
|
|
|
|
|
|
|
|
|
vo = AppletPileDetailVO.builder()
|
|
|
|
|
|
.pileInfo(pileInfoVO)
|
|
|
|
|
|
.connectorInfoList(connectorInfoList)
|
|
|
|
|
|
.merchantInfo(merchantInfoVO)
|
|
|
|
|
|
.stationInfo(stationInfo)
|
|
|
|
|
|
.billingPriceList(billingPriceVOS)
|
|
|
|
|
|
.build();
|
|
|
|
|
|
return vo;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-09-10 12:03:53 +08:00
|
|
|
|
public AppletPileDetailVO getPileDetailByPileSn(String param) throws Exception {
|
2024-09-09 21:45:49 +08:00
|
|
|
|
AppletPileDetailVO vo = null;
|
|
|
|
|
|
log.info("查询充电枪口详情-getPileDetailByPileSn, param:{}", param);
|
|
|
|
|
|
if (StringUtils.isBlank(param)) {
|
|
|
|
|
|
throw new BusinessException(ReturnCodeEnum.CODE_PARAM_NOT_NULL_ERROR);
|
|
|
|
|
|
}
|
|
|
|
|
|
String pileSn = YKCUtils.getPileSn(param);
|
|
|
|
|
|
log.info("查询充电枪口详情-getPileDetailByPileSn, pileSn:{}", pileSn);
|
|
|
|
|
|
// 查询充电桩信息
|
|
|
|
|
|
PileInfoVO pileInfoVO = pileBasicInfoService.selectPileInfoBySn(pileSn);
|
|
|
|
|
|
log.info("查询充电枪口详情-pileInfoVO:{}", JSON.toJSONString(pileInfoVO));
|
2024-09-09 20:47:34 +08:00
|
|
|
|
if (pileInfoVO == null) {
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
2024-09-09 20:19:26 +08:00
|
|
|
|
|
2024-09-09 20:47:34 +08:00
|
|
|
|
// 判断桩是否在线
|
|
|
|
|
|
boolean onLineStatus = pileConnectorInfoService.checkPileOffLine(pileInfoVO.getPileSn());
|
2024-09-30 15:49:55 +08:00
|
|
|
|
String activeProfile = SpringUtils.getActiveProfile();
|
|
|
|
|
|
log.info("查询充电枪口详情-判断桩是否在线:{}, onLineStatus:{}, activeProfile:{}", pileInfoVO.getPileSn(), onLineStatus, activeProfile);
|
|
|
|
|
|
if ("prd".equals(activeProfile)) {
|
|
|
|
|
|
if (onLineStatus) {
|
|
|
|
|
|
// true为离线
|
|
|
|
|
|
throw new BusinessException(ReturnCodeEnum.CODE_PILE_CONNECTOR_STATUS_OFF_LINE);
|
|
|
|
|
|
}
|
2024-09-09 20:47:34 +08:00
|
|
|
|
}
|
2023-09-13 14:15:19 +08:00
|
|
|
|
|
2024-09-09 20:47:34 +08:00
|
|
|
|
// 查询站点信息
|
|
|
|
|
|
PileStationVO stationInfo = pileStationInfoService.getStationInfo(pileInfoVO.getStationId());
|
|
|
|
|
|
log.info("查询充电枪口详情-getStationInfo:{}, onLineStatus:{}", pileInfoVO.getStationId(), JSON.toJSONString(stationInfo));
|
|
|
|
|
|
if (stationInfo == null || StringUtils.equals(stationInfo.getOpenFlag(), Constants.ZERO)) {
|
|
|
|
|
|
throw new BusinessException(ReturnCodeEnum.CODE_STATION_IS_NOT_OPEN);
|
2023-04-03 10:47:45 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-09-09 20:47:34 +08:00
|
|
|
|
// 查询充电桩下枪口信息
|
2024-09-10 12:03:53 +08:00
|
|
|
|
CompletableFuture<List<ConnectorInfoVO>> connectorInfoListFuture = CompletableFuture.supplyAsync(() -> pileConnectorInfoService.selectConnectorInfoList(pileSn), executor);
|
|
|
|
|
|
// log.info("查询充电枪口详情-supplyAsync-selectConnectorInfoList:{}", connectorInfoListFuture);
|
2024-09-09 20:47:34 +08:00
|
|
|
|
|
|
|
|
|
|
// 查计费模板信息
|
2024-09-10 12:03:53 +08:00
|
|
|
|
CompletableFuture<List<BillingPriceVO>> billingPriceFuture = CompletableFuture.supplyAsync(() -> pileBillingTemplateService.queryBillingPrice(pileInfoVO.getStationId()), executor);
|
|
|
|
|
|
// log.info("查询充电枪口详情-supplyAsync-queryBillingPrice:{}", billingPriceFuture);
|
2024-09-09 20:47:34 +08:00
|
|
|
|
|
|
|
|
|
|
// 查询运营商信息
|
2024-09-10 12:03:53 +08:00
|
|
|
|
CompletableFuture<MerchantInfoVO> merchantInfoVOFuture = CompletableFuture.supplyAsync(() -> pileMerchantInfoService.getMerchantInfoVO(pileInfoVO.getMerchantId()), executor);
|
|
|
|
|
|
// log.info("查询充电枪口详情-supplyAsync-getMerchantInfoVO:{}", merchantInfoVOFuture);
|
2024-09-09 20:47:34 +08:00
|
|
|
|
|
2024-09-09 21:32:31 +08:00
|
|
|
|
CompletableFuture all = FutureUtil.allOf(connectorInfoListFuture, merchantInfoVOFuture, billingPriceFuture);
|
2024-09-09 20:47:34 +08:00
|
|
|
|
// .join()和.get()都会阻塞并获取线程的执行情况
|
|
|
|
|
|
// .join()会抛出未经检查的异常,不会强制开发者处理异常 .get()会抛出检查异常,需要开发者处理
|
|
|
|
|
|
all.join();
|
|
|
|
|
|
all.get();
|
|
|
|
|
|
List<ConnectorInfoVO> connectorInfoList = connectorInfoListFuture.get();
|
|
|
|
|
|
// List<ConnectorInfoVO> connectorInfoList = pileConnectorInfoService.selectConnectorInfoList(pileSn);
|
|
|
|
|
|
log.info("查询充电枪口详情-connectorInfoList:{}", JSON.toJSONString(connectorInfoList));
|
|
|
|
|
|
// PileStationVO pileStationVO = pileStationVOFuture.get();
|
|
|
|
|
|
MerchantInfoVO merchantInfoVO = merchantInfoVOFuture.get();
|
|
|
|
|
|
// List<BillingPriceVO> billingPriceVOS= pileBillingTemplateService.queryBillingPrice(pileInfoVO.getStationId());
|
|
|
|
|
|
log.info("查询充电枪口详情-merchantInfoVO:{}", JSON.toJSONString(merchantInfoVO));
|
|
|
|
|
|
List<BillingPriceVO> billingPriceVOS = billingPriceFuture.get();
|
|
|
|
|
|
// MerchantInfoVO merchantInfoVO = pileMerchantInfoService.getMerchantInfoVO(pileInfoVO.getMerchantId());
|
|
|
|
|
|
log.info("查询充电枪口详情-billingPriceVOS:{}", JSON.toJSONString(billingPriceVOS));
|
|
|
|
|
|
|
|
|
|
|
|
vo = AppletPileDetailVO.builder()
|
|
|
|
|
|
.pileInfo(pileInfoVO)
|
|
|
|
|
|
.connectorInfoList(connectorInfoList)
|
|
|
|
|
|
.merchantInfo(merchantInfoVO)
|
|
|
|
|
|
.stationInfo(stationInfo)
|
|
|
|
|
|
.billingPriceList(billingPriceVOS)
|
|
|
|
|
|
.build();
|
2023-03-04 16:29:55 +08:00
|
|
|
|
return vo;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-09-14 08:40:51 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 获取枪口详情信息
|
|
|
|
|
|
* 仅小程序扫码调用
|
|
|
|
|
|
* @param pileConnectorCode
|
|
|
|
|
|
* @return
|
|
|
|
|
|
* @throws ExecutionException
|
|
|
|
|
|
* @throws InterruptedException
|
|
|
|
|
|
*/
|
2024-09-09 19:25:26 +08:00
|
|
|
|
public AppletPileDetailVO getConnectorDetail(String pileConnectorCode) throws Exception {
|
2024-09-09 19:39:06 +08:00
|
|
|
|
log.info("查询充电枪口详情, pileConnectorCode:{}", pileConnectorCode);
|
2023-03-04 16:29:55 +08:00
|
|
|
|
PileConnectorDetailVO pileConnectorDetailVO = queryPileConnectorDetail(pileConnectorCode);
|
2024-09-09 19:39:06 +08:00
|
|
|
|
log.info("查询充电枪口详情, pileConnectorDetailVO:{}", JSON.toJSONString(pileConnectorDetailVO));
|
2023-03-04 16:29:55 +08:00
|
|
|
|
if (pileConnectorDetailVO == null) {
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
2024-08-30 17:23:04 +08:00
|
|
|
|
// 不是电单车的桩, 需要判断插枪状态
|
|
|
|
|
|
if (!StringUtils.equals(Constants.THREE, pileConnectorDetailVO.getChargePortType())) {
|
|
|
|
|
|
// 枪口状态不为2:占用(未充电)
|
|
|
|
|
|
if (!StringUtils.equals(PileConnectorDataBaseStatusEnum.OCCUPIED_NOT_CHARGED.getValue(), pileConnectorDetailVO.getConnectorStatus())) {
|
|
|
|
|
|
throw new BusinessException(ReturnCodeEnum.CODE_PILE_CONNECTOR_STATUS_ERROR);
|
|
|
|
|
|
}
|
2023-11-22 19:19:02 +08:00
|
|
|
|
}
|
2023-03-04 16:29:55 +08:00
|
|
|
|
String pileSn = pileConnectorDetailVO.getPileSn();
|
2024-08-30 16:17:57 +08:00
|
|
|
|
AppletPileDetailVO resultVO = getPileDetailByPileSn(pileSn);
|
2024-09-09 21:00:01 +08:00
|
|
|
|
log.info("查询充电枪口详情getConnectorDetail, pileSn:{}, pileConnectorDetailVO:{}, resultVO:{}", pileSn, JSON.toJSONString(pileConnectorDetailVO), JSON.toJSONString(resultVO));
|
|
|
|
|
|
List<ConnectorInfoVO> connectorInfoList = resultVO.getConnectorInfoList();
|
|
|
|
|
|
if (connectorInfoList.size() > 1 && !StringUtils.equals(pileConnectorDetailVO.getChargePortType(), "3")) {
|
|
|
|
|
|
List<ConnectorInfoVO> list = Lists.newArrayList();
|
|
|
|
|
|
// 枪口大于1个,此充电桩非单枪设备,根据参数展示对应枪口的信息
|
|
|
|
|
|
for (ConnectorInfoVO connectorInfoVO : connectorInfoList) {
|
|
|
|
|
|
if (StringUtils.equals(pileConnectorCode, pileSn + connectorInfoVO.getConnectorCode())) {
|
|
|
|
|
|
list.add(connectorInfoVO);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
resultVO.setConnectorInfoList(list);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
resultVO.setConnectorInfoList(connectorInfoList);
|
|
|
|
|
|
}
|
|
|
|
|
|
return resultVO;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public AppletPileDetailVO getConnectorDetailV2(String pileConnectorCode) throws Exception {
|
|
|
|
|
|
log.info("查询充电枪口详情, pileConnectorCode:{}", pileConnectorCode);
|
|
|
|
|
|
PileConnectorDetailVO pileConnectorDetailVO = queryPileConnectorDetail(pileConnectorCode);
|
|
|
|
|
|
log.info("查询充电枪口详情, pileConnectorDetailVO:{}", JSON.toJSONString(pileConnectorDetailVO));
|
|
|
|
|
|
if (pileConnectorDetailVO == null) {
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
// 不是电单车的桩, 需要判断插枪状态
|
|
|
|
|
|
if (!StringUtils.equals(Constants.THREE, pileConnectorDetailVO.getChargePortType())) {
|
|
|
|
|
|
// 枪口状态不为2:占用(未充电)
|
|
|
|
|
|
if (!StringUtils.equals(PileConnectorDataBaseStatusEnum.OCCUPIED_NOT_CHARGED.getValue(), pileConnectorDetailVO.getConnectorStatus())) {
|
|
|
|
|
|
throw new BusinessException(ReturnCodeEnum.CODE_PILE_CONNECTOR_STATUS_ERROR);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
String pileSn = pileConnectorDetailVO.getPileSn();
|
|
|
|
|
|
AppletPileDetailVO resultVO = getPileDetailByPileSn(pileSn);
|
2024-09-09 19:39:06 +08:00
|
|
|
|
log.info("查询充电枪口详情getConnectorDetail, pileSn:{}, pileConnectorDetailVO:{}, resultVO:{}", pileSn, JSON.toJSONString(pileConnectorDetailVO), JSON.toJSONString(resultVO));
|
2023-03-04 16:29:55 +08:00
|
|
|
|
List<ConnectorInfoVO> connectorInfoList = resultVO.getConnectorInfoList();
|
2024-09-06 14:51:39 +08:00
|
|
|
|
if (connectorInfoList.size() > 1 && !StringUtils.equals(pileConnectorDetailVO.getChargePortType(), "3")) {
|
2023-03-04 16:29:55 +08:00
|
|
|
|
List<ConnectorInfoVO> list = Lists.newArrayList();
|
|
|
|
|
|
// 枪口大于1个,此充电桩非单枪设备,根据参数展示对应枪口的信息
|
|
|
|
|
|
for (ConnectorInfoVO connectorInfoVO : connectorInfoList) {
|
|
|
|
|
|
if (StringUtils.equals(pileConnectorCode, pileSn + connectorInfoVO.getConnectorCode())) {
|
|
|
|
|
|
list.add(connectorInfoVO);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
resultVO.setConnectorInfoList(list);
|
2024-09-06 14:51:39 +08:00
|
|
|
|
} else {
|
|
|
|
|
|
resultVO.setConnectorInfoList(connectorInfoList);
|
2023-03-04 16:29:55 +08:00
|
|
|
|
}
|
|
|
|
|
|
return resultVO;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public PileInfoVO selectPileInfoBySn(String pileSn) {
|
|
|
|
|
|
return pileBasicInfoService.selectPileInfoBySn(pileSn);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 用户绑定个人桩
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param dto
|
|
|
|
|
|
* @return
|
|
|
|
|
|
*/
|
|
|
|
|
|
public int pileMemberBinding(PileMemberBindingDTO dto){
|
|
|
|
|
|
// 校验短信验证码
|
|
|
|
|
|
MemberRegisterAndLoginDTO registerAndLoginDTO = MemberRegisterAndLoginDTO.builder()
|
|
|
|
|
|
.mobileNumber(dto.getPhoneNumber())
|
|
|
|
|
|
.verificationCode(dto.getVerificationCode())
|
|
|
|
|
|
.build();
|
|
|
|
|
|
memberService.checkVerificationCode(registerAndLoginDTO);
|
|
|
|
|
|
|
2023-03-16 11:18:10 +08:00
|
|
|
|
// 判断桩是否为个人桩
|
|
|
|
|
|
PileBasicInfo pileBasicInfo = pileBasicInfoService.selectPileBasicInfoBySN(dto.getPileSn());
|
|
|
|
|
|
if (pileBasicInfo == null) {
|
|
|
|
|
|
// 未查到则说明没有此桩
|
|
|
|
|
|
throw new BusinessException(ReturnCodeEnum.CODE_PILE_NOT_INFO);
|
|
|
|
|
|
}
|
|
|
|
|
|
String businessType = pileBasicInfo.getBusinessType();
|
|
|
|
|
|
if (!StringUtils.equals(BusinessTypeEnum.INDIVIDUAL_PILE.getValue(), businessType)){
|
|
|
|
|
|
// 不一致则此桩不是个人桩
|
|
|
|
|
|
throw new BusinessException(ReturnCodeEnum.CODE_THIS_PILE_NOT_PERSONAL_PILE);
|
|
|
|
|
|
}
|
2024-08-12 13:28:32 +08:00
|
|
|
|
|
|
|
|
|
|
// 初始化个人桩预约信息
|
|
|
|
|
|
pileReservationInfoService.initPersonalPileReservation(dto.getPileSn(), null);
|
|
|
|
|
|
|
2023-03-04 16:29:55 +08:00
|
|
|
|
// 检查桩是否已经被绑定
|
|
|
|
|
|
PileMemberRelation pileMemberRelation = new PileMemberRelation();
|
|
|
|
|
|
pileMemberRelation.setPileSn(dto.getPileSn());
|
|
|
|
|
|
List<PileMemberRelation> list = pileMemberRelationService.selectPileMemberRelationList(pileMemberRelation);
|
|
|
|
|
|
if (CollectionUtils.isNotEmpty(list)){
|
|
|
|
|
|
// 说明已经被绑定过,抛出异常
|
|
|
|
|
|
throw new BusinessException(ReturnCodeEnum.CODE_PILE_HAS_BEEN_BINDING_ERROR);
|
|
|
|
|
|
}
|
2023-03-13 17:01:07 +08:00
|
|
|
|
// 如果没被绑定,先校验桩密钥是否一致
|
|
|
|
|
|
if (!StringUtils.equals(pileBasicInfo.getSecretKey(), dto.getSecretKey())) {
|
|
|
|
|
|
// 错误的密钥信息
|
|
|
|
|
|
throw new BusinessException(ReturnCodeEnum.CODE_SECRET_KEY_ERROR);
|
|
|
|
|
|
}
|
|
|
|
|
|
// 密钥正确,且桩未被绑定,则此用户为管理员
|
2023-03-04 16:29:55 +08:00
|
|
|
|
pileMemberRelation.setMemberId(dto.getMemberId());
|
2024-08-12 13:28:32 +08:00
|
|
|
|
pileMemberRelation.setType(Constants.ONE); // 1-管理员
|
2023-03-04 16:29:55 +08:00
|
|
|
|
return pileMemberRelationService.insertPileMemberRelation(pileMemberRelation);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-11-05 14:29:30 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 用户绑定个人桩(蓝牙)
|
|
|
|
|
|
*/
|
|
|
|
|
|
public int pileMemberBindingForBT(PileMemberBindingDTO dto) {
|
|
|
|
|
|
// 判断桩是否为个人桩
|
|
|
|
|
|
PileBasicInfo pileBasicInfo = pileBasicInfoService.selectPileBasicInfoBySN(dto.getPileSn());
|
|
|
|
|
|
if (pileBasicInfo == null) {
|
|
|
|
|
|
// 未查到则说明没有此桩
|
|
|
|
|
|
throw new BusinessException(ReturnCodeEnum.CODE_PILE_NOT_INFO);
|
|
|
|
|
|
}
|
|
|
|
|
|
String businessType = pileBasicInfo.getBusinessType();
|
|
|
|
|
|
if (!StringUtils.equals(BusinessTypeEnum.INDIVIDUAL_PILE.getValue(), businessType)){
|
|
|
|
|
|
// 不一致则此桩不是个人桩
|
|
|
|
|
|
throw new BusinessException(ReturnCodeEnum.CODE_THIS_PILE_NOT_PERSONAL_PILE);
|
|
|
|
|
|
}
|
|
|
|
|
|
// 初始化个人桩预约信息
|
|
|
|
|
|
pileReservationInfoService.initPersonalPileReservation(dto.getPileSn(), null);
|
|
|
|
|
|
// 检查桩是否已经被绑定
|
|
|
|
|
|
PileMemberRelation pileMemberRelation = new PileMemberRelation();
|
|
|
|
|
|
pileMemberRelation.setPileSn(dto.getPileSn());
|
|
|
|
|
|
List<PileMemberRelation> list = pileMemberRelationService.selectPileMemberRelationList(pileMemberRelation);
|
|
|
|
|
|
if (CollectionUtils.isNotEmpty(list)){
|
|
|
|
|
|
// 说明已经被绑定过,抛出异常
|
|
|
|
|
|
throw new BusinessException(ReturnCodeEnum.CODE_PILE_HAS_BEEN_BINDING_ERROR);
|
|
|
|
|
|
}
|
|
|
|
|
|
// 保存绑定关系
|
|
|
|
|
|
pileMemberRelation.setMemberId(dto.getMemberId());
|
|
|
|
|
|
pileMemberRelation.setType(Constants.ONE); // 1-管理员
|
|
|
|
|
|
pileMemberRelation.setDeviceName(dto.getDeviceName());
|
|
|
|
|
|
pileMemberRelation.setDeviceId(dto.getDeviceId());
|
|
|
|
|
|
return pileMemberRelationService.insertPileMemberRelation(pileMemberRelation);
|
|
|
|
|
|
}
|
2023-07-12 16:31:09 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 用户解绑个人桩
|
|
|
|
|
|
* @param dto
|
|
|
|
|
|
*
|
|
|
|
|
|
*/
|
|
|
|
|
|
public int userUnbindPile(PileMemberBindingDTO dto) {
|
|
|
|
|
|
// 查询该用户的身份,是管理员还是普通用户
|
|
|
|
|
|
PileMemberRelation relation = new PileMemberRelation();
|
|
|
|
|
|
relation.setPileSn(dto.getPileSn());
|
|
|
|
|
|
relation.setMemberId(dto.getMemberId());
|
|
|
|
|
|
PileMemberRelation pileMemberRelation = pileMemberRelationService.selectPileMemberRelation(relation);
|
|
|
|
|
|
if (pileMemberRelation == null) {
|
|
|
|
|
|
throw new BusinessException(ReturnCodeEnum.CODE_THIS_PILE_INFO_IS_NULL);
|
|
|
|
|
|
}
|
|
|
|
|
|
String type = pileMemberRelation.getType();
|
|
|
|
|
|
List<Integer> idList = new ArrayList<>();
|
|
|
|
|
|
// 管理员解绑则会将此桩下面所有用户解绑
|
|
|
|
|
|
if (StringUtils.equals(Constants.ONE, type)) {
|
|
|
|
|
|
List<PileMemberRelation> pileMemberRelations = pileMemberRelationService.selectPileMemberRelationByPileSn(dto.getPileSn());
|
|
|
|
|
|
idList = pileMemberRelations.stream().map(PileMemberRelation::getId).collect(Collectors.toList());
|
2024-11-06 10:44:16 +08:00
|
|
|
|
|
|
|
|
|
|
// 管理员解绑,需要删除该桩的预约信息
|
|
|
|
|
|
pileReservationInfoService.deleteReservationByPileSn(dto.getPileSn());
|
2023-07-12 16:31:09 +08:00
|
|
|
|
}else {
|
|
|
|
|
|
idList.add(pileMemberRelation.getId());
|
|
|
|
|
|
}
|
|
|
|
|
|
return pileMemberRelationService.deleteRelationByIds(idList);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-03-04 16:29:55 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 个人桩管理员下发给其他用户使用
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param dto
|
|
|
|
|
|
*/
|
|
|
|
|
|
public void adminIssuePile(PileMemberBindingDTO dto) {
|
2023-09-11 10:54:41 +08:00
|
|
|
|
// 通过前端传的手机号查询是否有此用户
|
2024-07-25 14:09:32 +08:00
|
|
|
|
MemberBasicInfo memberBasicInfo = memberBasicInfoService.selectInfoByMobileNumber(dto.getPhoneNumber(), dto.getFirstLevelMerchantId());
|
2023-09-11 10:54:41 +08:00
|
|
|
|
if (memberBasicInfo == null) {
|
|
|
|
|
|
// 为空说明此用户未注册平台账号
|
|
|
|
|
|
throw new BusinessException(ReturnCodeEnum.CODE_USER_IS_NOT_REGISTER);
|
|
|
|
|
|
}
|
2024-12-12 14:31:35 +08:00
|
|
|
|
// 被分享的用户memberId
|
|
|
|
|
|
String memberId = memberBasicInfo.getMemberId();
|
2023-09-11 10:54:41 +08:00
|
|
|
|
|
2023-03-04 16:29:55 +08:00
|
|
|
|
List<PileMemberRelation> relationList = pileMemberRelationService.selectPileMemberRelationByPileSn(dto.getPileSn());
|
|
|
|
|
|
if (CollectionUtils.isEmpty(relationList)) {
|
|
|
|
|
|
// 充电桩没有绑定任何人
|
2024-12-12 14:31:35 +08:00
|
|
|
|
throw new BusinessException(ReturnCodeEnum.CODE_NO_ADMIN_FOR_PILE);
|
2023-03-04 16:29:55 +08:00
|
|
|
|
}
|
2024-12-12 14:31:35 +08:00
|
|
|
|
// 使用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); // 管理员列表
|
2024-12-12 14:54:18 +08:00
|
|
|
|
|
2024-12-12 14:31:35 +08:00
|
|
|
|
if (CollectionUtils.isEmpty(adminMemberRelationList)) {
|
|
|
|
|
|
// 充电桩没有管理员
|
|
|
|
|
|
throw new BusinessException(ReturnCodeEnum.CODE_NO_ADMIN_FOR_PILE);
|
|
|
|
|
|
}
|
|
|
|
|
|
List<String> adminList = adminMemberRelationList.stream()
|
2023-03-04 16:29:55 +08:00
|
|
|
|
.map(PileMemberRelation::getMemberId)
|
|
|
|
|
|
.collect(Collectors.toList());
|
2024-12-12 14:31:35 +08:00
|
|
|
|
// 校验身份 入参是否是管理员
|
|
|
|
|
|
if (adminList.contains(memberId)) {
|
2023-07-22 15:23:31 +08:00
|
|
|
|
// 如果不为空,说明被分享的用户是管理员,抛出异常
|
2024-12-12 14:31:35 +08:00
|
|
|
|
throw new BusinessException(ReturnCodeEnum.CODE_ALREADY_AN_ADMIN);
|
2023-03-04 16:29:55 +08:00
|
|
|
|
}
|
2024-12-12 14:54:18 +08:00
|
|
|
|
|
2024-12-12 14:52:30 +08:00
|
|
|
|
List<String> userList = Lists.newArrayList();
|
2024-12-12 14:54:18 +08:00
|
|
|
|
List<PileMemberRelation> userMemberRelations = map.get(Constants.TWO); // 普通用户列表
|
2024-12-12 14:52:30 +08:00
|
|
|
|
if (CollectionUtils.isNotEmpty(userMemberRelations)) {
|
|
|
|
|
|
userList = userMemberRelations.stream()
|
|
|
|
|
|
.map(PileMemberRelation::getMemberId)
|
|
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
|
}
|
2024-12-12 14:31:35 +08:00
|
|
|
|
// 校验身份 入参是否是普通用户
|
|
|
|
|
|
if (userList.contains(memberId)) {
|
2023-03-04 16:29:55 +08:00
|
|
|
|
// 不为空说明已绑定
|
2024-12-12 14:31:35 +08:00
|
|
|
|
throw new BusinessException(ReturnCodeEnum.CODE_ALREADY_AN_USER);
|
2023-03-04 16:29:55 +08:00
|
|
|
|
}
|
2024-12-12 14:52:30 +08:00
|
|
|
|
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);
|
2023-03-04 16:29:55 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 获取枪口实时数据
|
|
|
|
|
|
* @param dto
|
|
|
|
|
|
* @return
|
|
|
|
|
|
*/
|
|
|
|
|
|
public PersonPileRealTimeVO getConnectorRealTimeInfo(QueryPersonPileDTO dto) {
|
|
|
|
|
|
// 根据memberId查出该用户 正在充电、个人桩启动(白名单支付方式)的订单号
|
|
|
|
|
|
OrderBasicInfo orderBasicInfo = OrderBasicInfo.builder()
|
2024-07-25 16:18:23 +08:00
|
|
|
|
// .memberId(dto.getMemberId())
|
2023-03-04 16:29:55 +08:00
|
|
|
|
.orderStatus(OrderStatusEnum.IN_THE_CHARGING.getValue())
|
|
|
|
|
|
.pileConnectorCode(dto.getPileConnectorCode())
|
2023-03-11 10:32:18 +08:00
|
|
|
|
.payMode(OrderPayModeEnum.PAYMENT_OF_WHITELIST.getValue()) // 3- 白名单支付
|
2023-03-04 16:29:55 +08:00
|
|
|
|
.build();
|
|
|
|
|
|
OrderBasicInfo basicInfo = orderBasicInfoService.getOrderBasicInfo(orderBasicInfo);
|
|
|
|
|
|
if (basicInfo == null){
|
|
|
|
|
|
throw new BusinessException(ReturnCodeEnum.CODE_NO_CHARGING_ORDER_ERROR);
|
|
|
|
|
|
}
|
|
|
|
|
|
// 根据订单号从redis中获取实时数据信息(默认时间倒叙排列,所以取第一条)
|
2023-03-14 09:19:47 +08:00
|
|
|
|
List<RealTimeMonitorData> chargingRealTimeData = orderBasicInfoService.getChargingRealTimeData(basicInfo.getTransactionCode());
|
2023-03-04 16:29:55 +08:00
|
|
|
|
if (CollectionUtils.isEmpty(chargingRealTimeData)) {
|
|
|
|
|
|
throw new BusinessException(ReturnCodeEnum.CODE_NO_REAL_TIME_INFO);
|
|
|
|
|
|
}
|
|
|
|
|
|
RealTimeMonitorData realTimeMonitorData = chargingRealTimeData.get(0);
|
|
|
|
|
|
// 将需要的数据set
|
|
|
|
|
|
PersonPileRealTimeVO vo = PersonPileRealTimeVO.builder()
|
|
|
|
|
|
.chargingDegree(realTimeMonitorData.getChargingDegree())
|
|
|
|
|
|
.chargingTime(realTimeMonitorData.getSumChargingTime())
|
|
|
|
|
|
.startTime(DateUtils.formatDateTime(orderBasicInfo.getChargeStartTime()))
|
|
|
|
|
|
.instantCurrent(realTimeMonitorData.getOutputCurrent())
|
|
|
|
|
|
.instantVoltage(realTimeMonitorData.getOutputVoltage())
|
|
|
|
|
|
.instantPower(realTimeMonitorData.getOutputPower())
|
2024-07-26 09:52:03 +08:00
|
|
|
|
.status(orderBasicInfo.getOrderStatus())
|
|
|
|
|
|
.soc(realTimeMonitorData.getSOC())
|
2023-03-04 16:29:55 +08:00
|
|
|
|
.build();
|
|
|
|
|
|
return vo;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 获取某枪口某段时间内累计信息
|
|
|
|
|
|
* @param dto
|
|
|
|
|
|
* @return
|
|
|
|
|
|
*/
|
|
|
|
|
|
public PersonPileConnectorSumInfoVO getAccumulativeInfo(QueryPersonPileDTO dto) {
|
|
|
|
|
|
List<PersonPileConnectorSumInfoVO> accumulativeInfo = orderBasicInfoService.getAccumulativeInfo(dto);
|
|
|
|
|
|
if (CollectionUtils.isEmpty(accumulativeInfo)) {
|
2023-03-13 17:01:07 +08:00
|
|
|
|
throw new BusinessException(ReturnCodeEnum.CODE_QUERY_ORDER_INFO_IS_NULL);
|
2023-03-04 16:29:55 +08:00
|
|
|
|
}
|
|
|
|
|
|
Map<String, String> sumInfo = getSumInfo(accumulativeInfo);
|
|
|
|
|
|
// set 对象
|
|
|
|
|
|
PersonPileConnectorSumInfoVO vo = new PersonPileConnectorSumInfoVO();
|
|
|
|
|
|
vo.setStartTime(dto.getStartTime());
|
|
|
|
|
|
vo.setEndTime(dto.getEndTime());
|
|
|
|
|
|
vo.setMemberId(dto.getMemberId());
|
|
|
|
|
|
vo.setSumChargingDegree(sumInfo.get("sumUsedElectricity"));
|
|
|
|
|
|
vo.setSumChargingTime(sumInfo.get("sumChargingTime"));
|
|
|
|
|
|
return vo;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 获取充电记录(默认30天)
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param dto
|
|
|
|
|
|
*/
|
|
|
|
|
|
public PageResponse getChargingRecord(QueryPersonPileDTO dto) {
|
|
|
|
|
|
int pageNum = dto.getPageNum() == 0 ? 1 : dto.getPageNum();
|
|
|
|
|
|
int pageSize = dto.getPageSize() == 0 ? 10 : dto.getPageSize();
|
|
|
|
|
|
// 获取三十天前的数据
|
|
|
|
|
|
Date date = DateUtils.addMonths(new Date(), -1);
|
|
|
|
|
|
String dateStr = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, date);
|
|
|
|
|
|
dto.setStartTime(dateStr);
|
|
|
|
|
|
dto.setEndTime(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, new Date()));
|
|
|
|
|
|
|
|
|
|
|
|
// 分页查询
|
|
|
|
|
|
PageHelper.startPage(pageNum, pageSize);
|
|
|
|
|
|
List<PersonPileConnectorSumInfoVO> accumulativeInfo = orderBasicInfoService.getAccumulativeInfo(dto);
|
|
|
|
|
|
if (CollectionUtils.isEmpty(accumulativeInfo)) {
|
2023-03-13 17:01:07 +08:00
|
|
|
|
throw new BusinessException(ReturnCodeEnum.CODE_QUERY_ORDER_INFO_IS_NULL);
|
2023-03-04 16:29:55 +08:00
|
|
|
|
}
|
|
|
|
|
|
PageInfo<PersonPileConnectorSumInfoVO> pageInfo = new PageInfo<>(accumulativeInfo);
|
|
|
|
|
|
for (PersonPileConnectorSumInfoVO personPileConnectorSumInfoVO : pageInfo.getList()) {
|
|
|
|
|
|
if (StringUtils.isNotBlank(personPileConnectorSumInfoVO.getChargeStartTime()) && StringUtils.isNotBlank(personPileConnectorSumInfoVO.getChargeEndTime())){
|
|
|
|
|
|
String datePoor = DateUtils.getDatePoor(DateUtils.parseDate(personPileConnectorSumInfoVO.getChargeEndTime()),
|
|
|
|
|
|
DateUtils.parseDate(personPileConnectorSumInfoVO.getChargeStartTime()));
|
|
|
|
|
|
personPileConnectorSumInfoVO.setSumChargingTime(datePoor);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return PageResponse.builder()
|
|
|
|
|
|
.pageNum(pageInfo.getPageNum())
|
|
|
|
|
|
.pageSize(pageInfo.getPageSize())
|
|
|
|
|
|
.list(pageInfo.getList())
|
|
|
|
|
|
.pages(pageInfo.getPages())
|
|
|
|
|
|
.total(pageInfo.getTotal())
|
2024-11-19 17:11:07 +08:00
|
|
|
|
.build();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public PageResponse getChargingRecordV2(QueryPersonPileDTO dto) {
|
|
|
|
|
|
int pageNum = dto.getPageNum() == 0 ? 1 : dto.getPageNum();
|
|
|
|
|
|
int pageSize = dto.getPageSize() == 0 ? 10 : dto.getPageSize();
|
|
|
|
|
|
// 获取三十天前的数据
|
|
|
|
|
|
Date date = DateUtils.addMonths(new Date(), -1);
|
|
|
|
|
|
String dateStr = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, date);
|
|
|
|
|
|
dto.setStartTime(dateStr);
|
|
|
|
|
|
dto.setEndTime(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, new Date()));
|
|
|
|
|
|
|
|
|
|
|
|
// 分页查询
|
|
|
|
|
|
PageHelper.startPage(pageNum, pageSize);
|
|
|
|
|
|
List<PersonalChargingRecord> personalChargingRecordList = personalChargingRecordService.getPersonalChargingRecord(dto);
|
|
|
|
|
|
if (CollectionUtils.isEmpty(personalChargingRecordList)) {
|
|
|
|
|
|
throw new BusinessException(ReturnCodeEnum.CODE_QUERY_ORDER_INFO_IS_NULL);
|
|
|
|
|
|
}
|
|
|
|
|
|
PageInfo<PersonalChargingRecord> pageInfo = new PageInfo<>(personalChargingRecordList);
|
|
|
|
|
|
List<PersonPileConnectorSumInfoVO> list = Lists.newArrayList();
|
|
|
|
|
|
PersonPileConnectorSumInfoVO vo;
|
|
|
|
|
|
for (PersonalChargingRecord personalChargingRecord : pageInfo.getList()) {
|
|
|
|
|
|
vo = new PersonPileConnectorSumInfoVO();
|
2024-11-22 11:19:45 +08:00
|
|
|
|
vo.setSourceType(personalChargingRecord.getSourceType());
|
2024-11-19 17:11:07 +08:00
|
|
|
|
if (personalChargingRecord.getChargeStartTime() != null && personalChargingRecord.getChargeEndTime() != null){
|
2024-11-25 09:56:59 +08:00
|
|
|
|
vo.setChargeStartTime(DateUtils.formatDateTime(personalChargingRecord.getChargeStartTime()));
|
|
|
|
|
|
vo.setChargeEndTime(DateUtils.formatDateTime(personalChargingRecord.getChargeEndTime()));
|
2024-11-19 17:11:07 +08:00
|
|
|
|
String datePoor = DateUtils.getDatePoor(personalChargingRecord.getChargeEndTime(), personalChargingRecord.getChargeStartTime());
|
|
|
|
|
|
vo.setSumChargingTime(datePoor);
|
|
|
|
|
|
}
|
|
|
|
|
|
vo.setMemberId(personalChargingRecord.getMemberId());
|
|
|
|
|
|
vo.setSumChargingDegree(personalChargingRecord.getTotalUsedElectricity().toString());
|
2024-12-17 10:08:15 +08:00
|
|
|
|
vo.setStopReasonCode(personalChargingRecord.getStopReasonCode());
|
2024-11-25 09:56:59 +08:00
|
|
|
|
vo.setStopReasonMsg(personalChargingRecord.getReason());
|
2024-11-19 17:11:07 +08:00
|
|
|
|
list.add(vo);
|
|
|
|
|
|
}
|
|
|
|
|
|
return PageResponse.builder()
|
|
|
|
|
|
.pageNum(pageInfo.getPageNum())
|
|
|
|
|
|
.pageSize(pageInfo.getPageSize())
|
|
|
|
|
|
.list(list)
|
|
|
|
|
|
.pages(pageInfo.getPages())
|
|
|
|
|
|
.total(pageInfo.getTotal())
|
2023-03-04 16:29:55 +08:00
|
|
|
|
.build();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 获取总充电时长、总充电量
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param accumulativeInfo
|
|
|
|
|
|
* @return
|
|
|
|
|
|
*/
|
|
|
|
|
|
private Map<String, String> getSumInfo(List<PersonPileConnectorSumInfoVO> accumulativeInfo){
|
|
|
|
|
|
Map<String, String> resultMap = new HashMap<>();
|
|
|
|
|
|
BigDecimal sumChargingTime = BigDecimal.ZERO;
|
|
|
|
|
|
BigDecimal sumUsedElectricity = BigDecimal.ZERO;
|
|
|
|
|
|
// 将返回的结果进行for循环,将总充电量、总充电时长进行累加(充电时长需要通过 充电开始时间 和 充电结束时间 进行计算)
|
|
|
|
|
|
for (PersonPileConnectorSumInfoVO personPileConnectorSumInfoVO : accumulativeInfo) {
|
|
|
|
|
|
if (StringUtils.isNotBlank(personPileConnectorSumInfoVO.getChargeStartTime()) && StringUtils.isNotBlank(personPileConnectorSumInfoVO.getChargeEndTime())){
|
|
|
|
|
|
long longChargingTime = DateUtils.intervalTime(personPileConnectorSumInfoVO.getChargeStartTime(), personPileConnectorSumInfoVO.getChargeEndTime());
|
|
|
|
|
|
BigDecimal chargingTime = new BigDecimal(String.valueOf(longChargingTime));
|
|
|
|
|
|
sumChargingTime = sumChargingTime.add(chargingTime);
|
|
|
|
|
|
}
|
|
|
|
|
|
BigDecimal chargingDegree = StringUtils.isBlank(personPileConnectorSumInfoVO.getSumChargingDegree())
|
|
|
|
|
|
? BigDecimal.ZERO
|
|
|
|
|
|
: new BigDecimal(personPileConnectorSumInfoVO.getSumChargingDegree());
|
|
|
|
|
|
sumUsedElectricity = sumUsedElectricity.add(chargingDegree);
|
|
|
|
|
|
}
|
|
|
|
|
|
resultMap.put("sumChargingTime", String.valueOf(sumChargingTime));
|
|
|
|
|
|
resultMap.put("sumUsedElectricity", String.valueOf(sumUsedElectricity));
|
|
|
|
|
|
return resultMap;
|
|
|
|
|
|
}
|
2023-03-31 16:19:26 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 后管调用,给站点下所有桩下发二维码
|
|
|
|
|
|
* @param dto
|
|
|
|
|
|
* @return
|
|
|
|
|
|
*/
|
|
|
|
|
|
public int updateStationQRCodePrefix(QueryStationDTO dto) {
|
|
|
|
|
|
String stationId = dto.getStationId();
|
|
|
|
|
|
// 通过站点id查询数据
|
2023-04-07 09:18:31 +08:00
|
|
|
|
PileStationInfo pileStationInfo = pileStationInfoService.selectPileStationInfoById(Long.parseLong(stationId));
|
|
|
|
|
|
if (pileStationInfo == null) {
|
2023-03-31 16:19:26 +08:00
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
// 修改站点列表的 qrcodePrefix 字段
|
2023-04-07 09:18:31 +08:00
|
|
|
|
pileStationInfo.setQrcodePrefix(dto.getQrcodePrefix());
|
|
|
|
|
|
int i = pileStationInfoService.updatePileStationInfo(pileStationInfo);
|
2023-03-31 16:19:26 +08:00
|
|
|
|
if (i == 0) {
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
// 查出这个站点下的所有桩
|
|
|
|
|
|
List<PileDetailVO> pileDetailVOS = pileBasicInfoService.selectPileListByStationIds(Lists.newArrayList(Long.parseLong(stationId)));
|
|
|
|
|
|
List<String> pileSnList = pileDetailVOS.stream()
|
2023-04-07 09:18:31 +08:00
|
|
|
|
.filter(x -> StringUtils.equals(x.getStatus(), PileStatusEnum.ON_LINE.getValue()))
|
2023-03-31 16:19:26 +08:00
|
|
|
|
.map(PileDetailVO::getPileSn)
|
|
|
|
|
|
.collect(Collectors.toList());
|
2023-04-06 15:30:55 +08:00
|
|
|
|
// IssueQRCodeCommand command;
|
2023-03-31 16:19:26 +08:00
|
|
|
|
for (String pileSn : pileSnList) {
|
|
|
|
|
|
// 给桩下发二维码
|
2023-04-07 09:18:31 +08:00
|
|
|
|
pileRemoteService.issueQRCode(pileSn, pileStationInfo.getQrcodePrefix());
|
2023-03-31 16:19:26 +08:00
|
|
|
|
}
|
|
|
|
|
|
return 1;
|
|
|
|
|
|
}
|
2024-06-18 09:36:02 +08:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 查询充电桩预约记录
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2024-06-18 16:03:23 +08:00
|
|
|
|
* 修改预约充电状态
|
2024-06-18 09:36:02 +08:00
|
|
|
|
* @param dto
|
|
|
|
|
|
*/
|
2024-06-20 16:36:25 +08:00
|
|
|
|
public void updateReservedStatus(PileReservationDTO dto) {
|
2024-06-18 16:03:23 +08:00
|
|
|
|
if (StringUtils.equals(dto.getStatus(), Constants.ZERO)) {
|
2024-06-18 17:13:29 +08:00
|
|
|
|
// 停用
|
2024-06-20 14:34:35 +08:00
|
|
|
|
pileReservationInfoService.deactivateReserved(dto);
|
2024-06-18 16:03:23 +08:00
|
|
|
|
} else if (StringUtils.equals(dto.getStatus(), Constants.ONE)) {
|
2024-06-18 17:13:29 +08:00
|
|
|
|
// 启用
|
2024-06-20 14:34:35 +08:00
|
|
|
|
pileReservationInfoService.activateReserved(dto);
|
2024-06-18 16:03:23 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2024-06-18 09:36:02 +08:00
|
|
|
|
|
2024-06-20 16:36:25 +08:00
|
|
|
|
public void deleteReservation(PileReservationDTO dto) {
|
|
|
|
|
|
pileReservationInfoService.deleteReservation(dto);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 个人桩启动充电
|
|
|
|
|
|
* @param dto
|
|
|
|
|
|
* @return
|
|
|
|
|
|
*/
|
|
|
|
|
|
public String startPersonalPileCharging(StartPersonPileDTO dto) {
|
2024-06-27 11:14:41 +08:00
|
|
|
|
return pileBasicInfoService.startPersonalPileCharging(dto);
|
2024-06-20 16:36:25 +08:00
|
|
|
|
}
|
2024-06-21 13:50:19 +08:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 生成桩密钥
|
|
|
|
|
|
* @return
|
|
|
|
|
|
*/
|
|
|
|
|
|
public String generatePileSecret() {
|
|
|
|
|
|
// 获取 年月日 日期
|
|
|
|
|
|
String dateStr = DateUtils.dateTimeNow(DateUtils.YYYYMMDD);
|
|
|
|
|
|
// System.out.println("dateStr:" + dateStr);
|
|
|
|
|
|
int dateInt = Integer.parseInt(dateStr);
|
|
|
|
|
|
// 将年月日加上 160829
|
|
|
|
|
|
String data = String.valueOf(dateInt + 160829);
|
|
|
|
|
|
byte[] bytes = BytesUtil.str2Bcd(data);
|
|
|
|
|
|
// crc16加密
|
2024-06-24 09:10:53 +08:00
|
|
|
|
String crc = String.format("%04x", CRC16Util.calcCrc16(bytes)); // 050C
|
2024-06-21 13:50:19 +08:00
|
|
|
|
// System.out.println(crc);
|
|
|
|
|
|
// 将16进制转成10进制
|
2024-06-24 09:10:53 +08:00
|
|
|
|
int i = Integer.parseInt(crc, 16); // 1292
|
2024-06-21 13:50:19 +08:00
|
|
|
|
// System.out.println(i);
|
|
|
|
|
|
return String.valueOf(i);
|
|
|
|
|
|
}
|
2024-07-25 14:09:32 +08:00
|
|
|
|
|
2024-08-12 13:28:32 +08:00
|
|
|
|
|
|
|
|
|
|
|
2023-03-04 16:29:55 +08:00
|
|
|
|
}
|