Files
jsowell-charger-web/jsowell-admin/src/main/java/com/jsowell/service/PileService.java

608 lines
24 KiB
Java
Raw Normal View History

2023-03-04 16:29:55 +08:00
package com.jsowell.service;
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-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;
import com.jsowell.common.util.*;
2024-06-18 16:03:23 +08:00
import com.jsowell.pile.domain.*;
import com.jsowell.pile.dto.*;
2023-08-26 09:46:46 +08:00
import com.jsowell.pile.util.SnUtils;
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-07-16 14:07:06 +08:00
import com.jsowell.pile.vo.uniapp.customer.BillingPriceVO;
import com.jsowell.pile.vo.uniapp.customer.PersonPileConnectorSumInfoVO;
import com.jsowell.pile.vo.uniapp.customer.PersonPileRealTimeVO;
import com.jsowell.pile.vo.uniapp.customer.PileConnectorDetailVO;
2024-08-30 16:17:57 +08:00
import com.jsowell.pile.vo.uniapp.customer.AppletPileDetailVO;
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;
import org.apache.commons.lang3.RandomStringUtils;
2023-03-04 16:29:55 +08:00
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
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;
@Service
public class PileService {
private final Logger log = LoggerFactory.getLogger(this.getClass());
@Autowired
private TransactionService pileTransactionService;
@Resource
private SnUtils snUtils;
@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
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) {
// 批量生成sn号
List<String> snList = snUtils.generateSN(dto.getNum());
//
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号
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);
}
2023-03-04 16:29:55 +08:00
basicInfo.setSoftwareProtocol(dto.getSoftwareProtocol()); // 软件协议
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-08-30 16:17:57 +08:00
public AppletPileDetailVO getPileDetailByPileSn(String param) throws ExecutionException, InterruptedException {
2023-03-04 16:29:55 +08:00
if (StringUtils.isBlank(param)) {
throw new BusinessException(ReturnCodeEnum.CODE_PARAM_NOT_NULL_ERROR);
}
String pileSn;
if (param.length() == 16) {
pileSn = StringUtils.substring(param, 0, param.length() - 2);
} else {
pileSn = param;
}
// 查询充电桩信息
PileInfoVO pileInfoVO = pileBasicInfoService.selectPileInfoBySn(pileSn);
if (pileInfoVO == null) {
return null;
}
// 判断桩是否在线
2023-11-22 19:19:02 +08:00
boolean onLineStatus = pileConnectorInfoService.checkPileOffLine(pileInfoVO.getPileSn());
if (onLineStatus) {
// true为离线
2023-12-15 15:05:48 +08:00
throw new BusinessException(ReturnCodeEnum.CODE_PILE_CONNECTOR_STATUS_OFF_LINE);
2023-11-22 19:19:02 +08:00
}
// 查询站点信息
PileStationVO stationInfo = pileStationInfoService.getStationInfo(pileInfoVO.getStationId());
if (stationInfo == null || StringUtils.equals(stationInfo.getOpenFlag(), Constants.ZERO)) {
throw new BusinessException(ReturnCodeEnum.CODE_STATION_IS_NOT_OPEN);
}
2023-03-04 16:29:55 +08:00
// 查询充电桩下枪口信息
CompletableFuture<List<ConnectorInfoVO>> connectorInfoListFuture = CompletableFuture.supplyAsync(() -> pileConnectorInfoService.selectConnectorInfoList(pileSn));
// 查计费模板信息
CompletableFuture<List<BillingPriceVO>> billingPriceFuture = CompletableFuture.supplyAsync(() -> pileBillingTemplateService.queryBillingPrice(pileInfoVO.getStationId()));
// 查询运营商信息
2023-11-10 17:20:16 +08:00
CompletableFuture<MerchantInfoVO> merchantInfoVOFuture = CompletableFuture.supplyAsync(() -> pileMerchantInfoService.getMerchantInfoVO(pileInfoVO.getMerchantId()));
2023-03-04 16:29:55 +08:00
CompletableFuture<Void> all = CompletableFuture.allOf(connectorInfoListFuture, merchantInfoVOFuture, billingPriceFuture);
2023-03-04 16:29:55 +08:00
// .join()和.get()都会阻塞并获取线程的执行情况
// .join()会抛出未经检查的异常,不会强制开发者处理异常 .get()会抛出检查异常,需要开发者处理
all.join();
all.get();
List<ConnectorInfoVO> connectorInfoList = connectorInfoListFuture.get();
// PileStationVO pileStationVO = pileStationVOFuture.get();
2023-03-04 16:29:55 +08:00
MerchantInfoVO merchantInfoVO = merchantInfoVOFuture.get();
List<BillingPriceVO> billingPriceVOS = billingPriceFuture.get();
2024-08-30 16:17:57 +08:00
AppletPileDetailVO vo = AppletPileDetailVO.builder()
2023-03-04 16:29:55 +08:00
.pileInfo(pileInfoVO)
.connectorInfoList(connectorInfoList)
.merchantInfo(merchantInfoVO)
.stationInfo(stationInfo)
2023-03-04 16:29:55 +08:00
.billingPriceList(billingPriceVOS)
.build();
return vo;
}
/**
* 获取枪口详情信息
* 仅小程序扫码调用
* @param pileConnectorCode
* @return
* @throws ExecutionException
* @throws InterruptedException
*/
2024-08-30 16:17:57 +08:00
public AppletPileDetailVO getConnectorDetail(String pileConnectorCode) throws ExecutionException, InterruptedException {
2023-03-04 16:29:55 +08:00
PileConnectorDetailVO pileConnectorDetailVO = queryPileConnectorDetail(pileConnectorCode);
if (pileConnectorDetailVO == null) {
return null;
}
// 枪口状态不为2占用未充电
2024-08-16 10:03:16 +08:00
if (!StringUtils.equals(PileConnectorDataBaseStatusEnum.OCCUPIED_NOT_CHARGED.getValue(), pileConnectorDetailVO.getConnectorStatus())) {
2023-11-22 19:19:02 +08:00
throw new BusinessException(ReturnCodeEnum.CODE_PILE_CONNECTOR_STATUS_ERROR);
}
2023-03-04 16:29:55 +08:00
String pileSn = pileConnectorDetailVO.getPileSn();
2024-08-30 16:17:57 +08:00
AppletPileDetailVO resultVO = getPileDetailByPileSn(pileSn);
2023-03-04 16:29:55 +08:00
List<ConnectorInfoVO> connectorInfoList = resultVO.getConnectorInfoList();
if (connectorInfoList.size() > 1) {
List<ConnectorInfoVO> list = Lists.newArrayList();
// 枪口大于1个此充电桩非单枪设备根据参数展示对应枪口的信息
for (ConnectorInfoVO connectorInfoVO : connectorInfoList) {
if (StringUtils.equals(pileConnectorCode, pileSn + connectorInfoVO.getConnectorCode())) {
list.add(connectorInfoVO);
}
}
resultVO.setConnectorInfoList(list);
}
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);
// 判断桩是否为个人桩
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);
}
// 如果没被绑定,先校验桩密钥是否一致
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);
}
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());
}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);
}
2023-03-04 16:29:55 +08:00
List<PileMemberRelation> relationList = pileMemberRelationService.selectPileMemberRelationByPileSn(dto.getPileSn());
if (CollectionUtils.isEmpty(relationList)) {
// 充电桩没有绑定任何人
}
List<String> adminList = relationList.stream()
2023-07-22 15:23:31 +08:00
.filter(x -> x.getType().equals(Constants.ONE)) // 1-管理员用户
2023-03-04 16:29:55 +08:00
.map(PileMemberRelation::getMemberId)
.collect(Collectors.toList());
if (CollectionUtils.isEmpty(adminList)) {
// 没有管理员
}
// 校验身份
2023-07-22 15:23:31 +08:00
if (adminList.contains(dto.getMemberId())) {
// 如果不为空,说明被分享的用户是管理员,抛出异常
2023-03-04 16:29:55 +08:00
throw new BusinessException(ReturnCodeEnum.CODE_AUTHENTICATION_ERROR);
}
List<String> userList = relationList.stream()
2023-07-22 15:23:31 +08:00
.filter(x -> !x.getType().equals(Constants.TWO)) // 2-普通用户
2023-03-04 16:29:55 +08:00
.map(PileMemberRelation::getMemberId)
.collect(Collectors.toList());
if (userList.contains(memberBasicInfo.getMemberId())) {
// 不为空说明已绑定
throw new BusinessException(ReturnCodeEnum.CODE_USER_HAS_BEEN_THIS_PILE);
} else {
// 进行绑定,此用户为普通用户
PileMemberRelation info = new PileMemberRelation();
info.setPileSn(dto.getPileSn());
info.setMemberId(memberBasicInfo.getMemberId());
2024-07-25 14:09:32 +08:00
info.setType(Constants.TWO);
2023-03-04 16:29:55 +08:00
pileMemberRelationService.insertPileMemberRelation(info);
}
}
/**
* 获取枪口实时数据
* @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)) {
throw new BusinessException(ReturnCodeEnum.CODE_QUERY_ORDER_INFO_IS_NULL);
2023-03-04 16:29:55 +08:00
}
// 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);
// }
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)) {
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())
.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;
}
/**
* 后管调用给站点下所有桩下发二维码
* @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) {
return 0;
}
// 修改站点列表的 qrcodePrefix 字段
2023-04-07 09:18:31 +08:00
pileStationInfo.setQrcodePrefix(dto.getQrcodePrefix());
int i = pileStationInfoService.updatePileStationInfo(pileStationInfo);
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()))
.map(PileDetailVO::getPileSn)
.collect(Collectors.toList());
2023-04-06 15:30:55 +08:00
// IssueQRCodeCommand command;
for (String pileSn : pileSnList) {
// 给桩下发二维码
2023-04-07 09:18:31 +08:00
pileRemoteService.issueQRCode(pileSn, pileStationInfo.getQrcodePrefix());
}
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
}
/**
* 生成桩密钥
* @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
// System.out.println(crc);
// 将16进制转成10进制
2024-06-24 09:10:53 +08:00
int i = Integer.parseInt(crc, 16); // 1292
// 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
}