mirror of
https://codeup.aliyun.com/67c68d4e484ca2f0a13ac3c1/ydc/jsowell-charger-web.git
synced 2026-04-20 11:05:18 +08:00
充电桩预约功能
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package com.jsowell.api.uniapp;
|
||||
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.jsowell.common.annotation.Anonymous;
|
||||
import com.jsowell.common.core.controller.BaseController;
|
||||
import com.jsowell.common.core.page.PageResponse;
|
||||
@@ -8,6 +9,8 @@ import com.jsowell.common.enums.ykc.ReturnCodeEnum;
|
||||
import com.jsowell.common.exception.BusinessException;
|
||||
import com.jsowell.common.response.RestApiResponse;
|
||||
import com.jsowell.common.util.StringUtils;
|
||||
import com.jsowell.pile.dto.CreateReservedDTO;
|
||||
import com.jsowell.pile.dto.PileReservedDTO;
|
||||
import com.jsowell.pile.dto.PileMemberBindingDTO;
|
||||
import com.jsowell.pile.dto.QueryPersonPileDTO;
|
||||
import com.jsowell.pile.service.PileBasicInfoService;
|
||||
@@ -251,24 +254,50 @@ public class PersonPileController extends BaseController {
|
||||
*/
|
||||
|
||||
/**
|
||||
* 取消预约
|
||||
* 修改预约充电状态
|
||||
* http://localhost:8080/uniapp/personalPile/updateReservedStatus
|
||||
*/
|
||||
public RestApiResponse<?> canal(HttpServletRequest request, @RequestBody QueryPersonPileDTO dto) {
|
||||
logger.info("取消预约params:{}", JSON.toJSONString(dto));
|
||||
@PostMapping("/updateReservedStatus")
|
||||
public RestApiResponse<?> updateReservedStatus(HttpServletRequest request, @RequestBody PileReservedDTO dto) {
|
||||
// logger.info("修改预约充电状态params:{}", dto);
|
||||
RestApiResponse<?> response = null;
|
||||
try {
|
||||
String memberId = getMemberIdByAuthorization(request);
|
||||
dto.setMemberId(memberId);
|
||||
pileService.canalReserved(dto);
|
||||
pileService.updateReservedStatus(dto);
|
||||
response = new RestApiResponse<>();
|
||||
} catch (BusinessException e) {
|
||||
logger.error("取消预约error", e);
|
||||
logger.error("修改预约充电状态error, params:{}", dto, e);
|
||||
response = new RestApiResponse<>(e.getCode(), e.getMessage());
|
||||
} catch (Exception e) {
|
||||
logger.error("取消预约error", e);
|
||||
logger.error("修改预约充电状态error, params:{}", dto, e);
|
||||
response = new RestApiResponse<>(e);
|
||||
}
|
||||
logger.info("取消预约result:{}", response);
|
||||
logger.info("修改预约充电状态params:{}, result:{}", dto, response);
|
||||
return response;
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加预约充电
|
||||
* http://localhost:8080/uniapp/personalPile/createReserved
|
||||
*/
|
||||
@PostMapping("/createReserved")
|
||||
public RestApiResponse<?> createReserved(HttpServletRequest request, @RequestBody CreateReservedDTO dto) {
|
||||
// logger.info("修改预约充电状态params:{}", dto);
|
||||
RestApiResponse<?> response = null;
|
||||
try {
|
||||
String memberId = getMemberIdByAuthorization(request);
|
||||
dto.setMemberId(memberId);
|
||||
int reservedId = pileService.createReserved(dto);
|
||||
response = new RestApiResponse<>(ImmutableMap.of("reservedId", reservedId));
|
||||
} catch (BusinessException e) {
|
||||
logger.error("添加预约充电error, params:{}", dto, e);
|
||||
response = new RestApiResponse<>(e.getCode(), e.getMessage());
|
||||
} catch (Exception e) {
|
||||
logger.error("添加预约充电error, params:{}", dto, e);
|
||||
response = new RestApiResponse<>(e);
|
||||
}
|
||||
logger.info("添加预约充电params:{}, result:{}", dto, response);
|
||||
return response;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,19 +16,10 @@ import com.jsowell.common.exception.BusinessException;
|
||||
import com.jsowell.common.util.DateUtils;
|
||||
import com.jsowell.common.util.SecurityUtils;
|
||||
import com.jsowell.common.util.StringUtils;
|
||||
import com.jsowell.pile.domain.*;
|
||||
import com.jsowell.pile.dto.*;
|
||||
import com.jsowell.pile.util.SnUtils;
|
||||
import com.jsowell.pile.service.*;
|
||||
import com.jsowell.pile.domain.MemberBasicInfo;
|
||||
import com.jsowell.pile.domain.OrderBasicInfo;
|
||||
import com.jsowell.pile.domain.PileBasicInfo;
|
||||
import com.jsowell.pile.domain.PileConnectorInfo;
|
||||
import com.jsowell.pile.domain.PileMemberRelation;
|
||||
import com.jsowell.pile.domain.PileStationInfo;
|
||||
import com.jsowell.pile.dto.BatchCreatePileDTO;
|
||||
import com.jsowell.pile.dto.MemberRegisterAndLoginDTO;
|
||||
import com.jsowell.pile.dto.PileMemberBindingDTO;
|
||||
import com.jsowell.pile.dto.QueryPersonPileDTO;
|
||||
import com.jsowell.pile.dto.QueryStationDTO;
|
||||
import com.jsowell.pile.transaction.dto.PileTransactionDTO;
|
||||
import com.jsowell.pile.transaction.service.TransactionService;
|
||||
import com.jsowell.pile.vo.base.ConnectorInfoVO;
|
||||
@@ -95,6 +86,9 @@ public class PileService {
|
||||
@Autowired
|
||||
private PileRemoteService pileRemoteService;
|
||||
|
||||
@Autowired
|
||||
private PileReservedInfoService pileReservedInfoService;
|
||||
|
||||
/**
|
||||
* 查询设备信息
|
||||
*
|
||||
@@ -562,10 +556,33 @@ public class PileService {
|
||||
|
||||
|
||||
/**
|
||||
* 取消预约充电
|
||||
* 修改预约充电状态
|
||||
* @param dto
|
||||
*/
|
||||
public void canalReserved(QueryPersonPileDTO dto) {
|
||||
public void updateReservedStatus(PileReservedDTO dto) {
|
||||
if (StringUtils.equals(dto.getStatus(), Constants.ZERO)) {
|
||||
pileReservedInfoService.deactivateReserved(dto);
|
||||
} else if (StringUtils.equals(dto.getStatus(), Constants.ONE)) {
|
||||
pileReservedInfoService.activateReserved(dto);
|
||||
}
|
||||
}
|
||||
|
||||
public int createReserved(CreateReservedDTO dto) {
|
||||
PileReservedInfo reservedInfo = new PileReservedInfo();
|
||||
reservedInfo.setMemberId(dto.getMemberId());
|
||||
reservedInfo.setPileSn(dto.getPileSn());
|
||||
reservedInfo.setStatus(Constants.ZERO); // 默认未生效
|
||||
reservedInfo.setStartTime(DateUtils.parseDate(dto.getStartTime()));
|
||||
reservedInfo.setEndTime(DateUtils.parseDate(dto.getEndTime()));
|
||||
if (StringUtils.isNotBlank(dto.getFreq())) {
|
||||
reservedInfo.setReservedType("recurring");
|
||||
reservedInfo.setFreq(dto.getFreq());
|
||||
} else {
|
||||
reservedInfo.setReservedType("single");
|
||||
reservedInfo.setFreq(null);
|
||||
}
|
||||
reservedInfo.setCreateBy(dto.getMemberId());
|
||||
pileReservedInfoService.insertSelective(reservedInfo);
|
||||
return reservedInfo.getId();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -262,6 +262,16 @@ public class SpringBootTestController {
|
||||
@Autowired
|
||||
private NotificationService notificationService;
|
||||
|
||||
@Test
|
||||
public void queryPaymentReverseTest2() {
|
||||
String paymentId = "002212024061717243610648707836701741056";
|
||||
try {
|
||||
adapayService.queryPaymentReverse(paymentId, wechatAppId1);
|
||||
} catch (BaseAdaPayException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createBalancePaymentRequestTest() {
|
||||
String outMemberId = "ACM40782726";
|
||||
|
||||
@@ -2,6 +2,8 @@ package com.jsowell.common.response;
|
||||
|
||||
import com.jsowell.common.enums.ykc.ReturnCodeEnum;
|
||||
import lombok.Data;
|
||||
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||
import org.apache.commons.lang3.builder.ToStringStyle;
|
||||
|
||||
@Data
|
||||
public class RestApiResponse<T> {
|
||||
@@ -40,4 +42,13 @@ public class RestApiResponse<T> {
|
||||
this.resCode = returnCodeEnum.getValue();
|
||||
this.msg = returnCodeEnum.getLabel();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new ToStringBuilder(this, ToStringStyle.JSON_STYLE)
|
||||
.append("resCode", resCode)
|
||||
.append("msg", msg)
|
||||
.append("obj", obj)
|
||||
.toString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
package com.jsowell.pile.dto;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||
import org.apache.commons.lang3.builder.ToStringStyle;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class CreateReservedDTO {
|
||||
/**
|
||||
* 会员id
|
||||
*/
|
||||
private String memberId;
|
||||
|
||||
/**
|
||||
* 充电桩编号
|
||||
*/
|
||||
private String pileSn;
|
||||
|
||||
/**
|
||||
* 预约开始时间
|
||||
*/
|
||||
private String startTime;
|
||||
|
||||
/**
|
||||
* 预约结束时间
|
||||
*/
|
||||
private String endTime;
|
||||
|
||||
/**
|
||||
* 周期性预约的频率,对于单次预约,该字段可以为 NULL。可能的值包括 daily, weekly, monthly
|
||||
*/
|
||||
private String freq;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new ToStringBuilder(this, ToStringStyle.JSON_STYLE)
|
||||
.append("memberId", memberId)
|
||||
.append("pileSn", pileSn)
|
||||
.append("startTime", startTime)
|
||||
.append("endTime", endTime)
|
||||
.append("freq", freq)
|
||||
.toString();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package com.jsowell.pile.dto;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||
import org.apache.commons.lang3.builder.ToStringStyle;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class PileReservedDTO {
|
||||
/**
|
||||
* 会员id
|
||||
*/
|
||||
private String memberId;
|
||||
|
||||
/**
|
||||
* 预约id
|
||||
*/
|
||||
private String reservedId;
|
||||
|
||||
/**
|
||||
* 状态 (0-停用;1-启用)
|
||||
*/
|
||||
private String status;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new ToStringBuilder(this, ToStringStyle.JSON_STYLE)
|
||||
.append("memberId", memberId)
|
||||
.append("reservedId", reservedId)
|
||||
.append("status", status)
|
||||
.toString();
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package com.jsowell.pile.service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.jsowell.pile.dto.PileReservedDTO;
|
||||
import com.jsowell.pile.domain.PileReservedInfo;
|
||||
|
||||
public interface PileReservedInfoService {
|
||||
@@ -31,9 +32,9 @@ public interface PileReservedInfoService {
|
||||
|
||||
List<PileReservedInfo> getReservationsByMemberIdAndPileSn(String memberId, String pileSn);
|
||||
|
||||
void activateReservation(int reservationId);
|
||||
void activateReserved(PileReservedDTO dto);
|
||||
|
||||
void deactivateReservation(int reservationId);
|
||||
void deactivateReserved(PileReservedDTO dto);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,8 @@ package com.jsowell.pile.service.impl;
|
||||
|
||||
import com.jsowell.common.constant.Constants;
|
||||
import com.jsowell.common.util.DateUtils;
|
||||
import com.jsowell.common.util.StringUtils;
|
||||
import com.jsowell.pile.dto.PileReservedDTO;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
@@ -81,29 +83,36 @@ public class PileReservedInfoServiceImpl implements PileReservedInfoService {
|
||||
|
||||
/**
|
||||
* 启用预约
|
||||
* @param reservationId
|
||||
*/
|
||||
@Override
|
||||
public void activateReservation(int reservationId) {
|
||||
PileReservedInfo pileReservedInfo = pileReservedInfoMapper.selectByPrimaryKey(reservationId);
|
||||
if (pileReservedInfo != null) {
|
||||
pileReservedInfo.setStatus(Constants.ONE);
|
||||
// pileReservedInfoMapper.updateByPrimaryKeySelective(pileReservedInfo);
|
||||
saveReservation(pileReservedInfo);
|
||||
public void activateReserved(PileReservedDTO dto) {
|
||||
PileReservedInfo pileReservedInfo = pileReservedInfoMapper.selectByPrimaryKey(Integer.parseInt(dto.getReservedId()));
|
||||
if (pileReservedInfo == null) {
|
||||
return;
|
||||
}
|
||||
if (!StringUtils.equals(dto.getMemberId(), pileReservedInfo.getMemberId())) {
|
||||
return;
|
||||
}
|
||||
pileReservedInfo.setStatus(Constants.ONE);
|
||||
// 保存之前,校验时间是否重叠
|
||||
saveReservation(pileReservedInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 禁用预约
|
||||
* @param reservationId
|
||||
*/
|
||||
@Override
|
||||
public void deactivateReservation(int reservationId) {
|
||||
PileReservedInfo pileReservedInfo = pileReservedInfoMapper.selectByPrimaryKey(reservationId);
|
||||
if (pileReservedInfo != null) {
|
||||
pileReservedInfo.setStatus(Constants.ZERO);
|
||||
pileReservedInfoMapper.updateByPrimaryKeySelective(pileReservedInfo);
|
||||
public void deactivateReserved(PileReservedDTO dto) {
|
||||
PileReservedInfo pileReservedInfo = pileReservedInfoMapper.selectByPrimaryKey(Integer.parseInt(dto.getReservedId()));
|
||||
if (pileReservedInfo == null) {
|
||||
return;
|
||||
}
|
||||
if (!StringUtils.equals(dto.getMemberId(), pileReservedInfo.getMemberId())) {
|
||||
return;
|
||||
}
|
||||
// 校验通过可以修改预约
|
||||
pileReservedInfo.setStatus(Constants.ZERO);
|
||||
pileReservedInfoMapper.updateByPrimaryKeySelective(pileReservedInfo);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user