update 地锁逻辑修改

This commit is contained in:
2023-09-09 15:53:49 +08:00
parent 594a56e03f
commit 5b6f1c24ad
5 changed files with 184 additions and 144 deletions

View File

@@ -30,141 +30,146 @@ import java.util.List;
@RequestMapping("/uniapp/pile")
public class PileController extends BaseController {
@Autowired
private IPileStationInfoService pileStationInfoService;
@Autowired
private IPileStationInfoService pileStationInfoService;
@Autowired
private IPileConnectorInfoService pileConnectorInfoService;
@Autowired
private IPileConnectorInfoService pileConnectorInfoService;
@Autowired
private IPileBillingTemplateService pileBillingTemplateService;
@Autowired
private IPileBillingTemplateService pileBillingTemplateService;
@Autowired
private IPileMerchantInfoService pileMerchantInfoService;
@Autowired
private IPileMerchantInfoService pileMerchantInfoService;
@Autowired
private OrderPileOccupyService orderPileOccupyService;
@Autowired
private OrderPileOccupyService orderPileOccupyService;
/**
* 查询充电站信息列表(主页)
*
* http://localhost:8080/uniapp/pile/queryStationInfos
*/
@PostMapping("/queryStationInfos")
public RestApiResponse<?> queryStationInfos(HttpServletRequest request, @RequestBody QueryStationDTO queryStationDTO) {
logger.info("查询充电站信息列表 param:{}", JSONObject.toJSONString(queryStationDTO));
RestApiResponse<?> response = null;
try {
// 获取appid第三方平台用
String appId = request.getHeader("appId");
if (StringUtils.isNotBlank(appId)) {
// 获取deptIds
List<String> deptIds = pileMerchantInfoService.getDeptIdsByAppId(appId);
queryStationDTO.setMerchantDeptIds(deptIds);
}
logger.info("uniApp查询充电站信息appId:{}, dto:{}", appId, JSON.toJSONString(queryStationDTO));
PageResponse pageResponse = pileStationInfoService.uniAppQueryStationInfoList(queryStationDTO);
response = new RestApiResponse<>(pageResponse);
} catch (BusinessException e) {
logger.warn("查询充电站信息列表warn", e);
response = new RestApiResponse<>(e.getCode(), e.getMessage());
} catch (Exception e) {
logger.error("查询充电站信息列表异常 error", e);
response = new RestApiResponse<>(ReturnCodeEnum.CODE_GET_PILE_STATION_INFO_ERROR);
}
logger.info("查询充电站信息列表 result:{}", JSONObject.toJSONString(response));
return response;
}
/**
* 查询充电站信息列表(主页)
* <p>
* http://localhost:8080/uniapp/pile/queryStationInfos
*/
@PostMapping("/queryStationInfos")
public RestApiResponse<?> queryStationInfos(HttpServletRequest request, @RequestBody QueryStationDTO queryStationDTO) {
logger.info("查询充电站信息列表 param:{}", JSONObject.toJSONString(queryStationDTO));
RestApiResponse<?> response = null;
try {
// 获取appid第三方平台用
String appId = request.getHeader("appId");
if (StringUtils.isNotBlank(appId)) {
// 获取deptIds
List<String> deptIds = pileMerchantInfoService.getDeptIdsByAppId(appId);
queryStationDTO.setMerchantDeptIds(deptIds);
}
logger.info("uniApp查询充电站信息appId:{}, dto:{}", appId, JSON.toJSONString(queryStationDTO));
PageResponse pageResponse = pileStationInfoService.uniAppQueryStationInfoList(queryStationDTO);
response = new RestApiResponse<>(pageResponse);
} catch (BusinessException e) {
logger.warn("查询充电站信息列表warn", e);
response = new RestApiResponse<>(e.getCode(), e.getMessage());
} catch (Exception e) {
logger.error("查询充电站信息列表异常 error", e);
response = new RestApiResponse<>(ReturnCodeEnum.CODE_GET_PILE_STATION_INFO_ERROR);
}
logger.info("查询充电站信息列表 result:{}", JSONObject.toJSONString(response));
return response;
}
/**
* 通过站点id查询计费模板列表
* http://localhost:8080/uniapp/pile/queryBillingPrice/{stationId}
* @param stationId
* @return
*/
@GetMapping("/queryBillingPrice/{stationId}")
public RestApiResponse<?> queryBillingPrice(@PathVariable("stationId") String stationId) {
logger.info("通过站点id查询计费模板列表 params:{}", stationId);
RestApiResponse<?> response = null;
try {
List<BillingPriceVO> billingPriceVOList = pileBillingTemplateService.queryBillingPrice(stationId);
response = new RestApiResponse<>(billingPriceVOList);
} catch (Exception e) {
logger.error("通过站点id查询计费模板列表 error, ", e);
response = new RestApiResponse<>(e);
}
logger.info("通过站点id查询计费模板列表 result:{}", response);
return response;
}
/**
* 通过站点id查询计费模板列表
* http://localhost:8080/uniapp/pile/queryBillingPrice/{stationId}
*
* @param stationId
* @return
*/
@GetMapping("/queryBillingPrice/{stationId}")
public RestApiResponse<?> queryBillingPrice(@PathVariable("stationId") String stationId) {
logger.info("通过站点id查询计费模板列表 params:{}", stationId);
RestApiResponse<?> response = null;
try {
List<BillingPriceVO> billingPriceVOList = pileBillingTemplateService.queryBillingPrice(stationId);
response = new RestApiResponse<>(billingPriceVOList);
} catch (Exception e) {
logger.error("通过站点id查询计费模板列表 error, ", e);
response = new RestApiResponse<>(e);
}
logger.info("通过站点id查询计费模板列表 result:{}", response);
return response;
}
/**
* 通过前端参数查询充电枪口列表
*
* http://localhost:8080/uniapp/pile/selectConnectorListByParams
*
* @param dto
* @return
*/
@PostMapping("/selectConnectorListByParams")
public RestApiResponse<?> selectConnectorListByParams(HttpServletRequest request, @RequestBody QueryConnectorListDTO dto) {
logger.info("查询充电枪口列表 params:{}", JSONObject.toJSONString(dto));
RestApiResponse<?> response = null;
try {
PageResponse pageResponse = pileConnectorInfoService.getUniAppConnectorInfoListByParams(dto);
response = new RestApiResponse<>(pageResponse);
} catch (Exception e) {
logger.error("查询充电枪口列表异常", e);
response = new RestApiResponse<>(ReturnCodeEnum.CODE_GET_CONNECTOR_INFO_BY_STATION_ID_ERROR);
}
logger.info("查询充电枪口列表 result:{}", response);
return response;
}
/**
* 通过前端参数查询充电枪口列表
* <p>
* http://localhost:8080/uniapp/pile/selectConnectorListByParams
*
* @param dto
* @return
*/
@PostMapping("/selectConnectorListByParams")
public RestApiResponse<?> selectConnectorListByParams(HttpServletRequest request, @RequestBody QueryConnectorListDTO dto) {
logger.info("查询充电枪口列表 params:{}", JSONObject.toJSONString(dto));
RestApiResponse<?> response = null;
try {
PageResponse pageResponse = pileConnectorInfoService.getUniAppConnectorInfoListByParams(dto);
response = new RestApiResponse<>(pageResponse);
} catch (Exception e) {
logger.error("查询充电枪口列表异常", e);
response = new RestApiResponse<>(ReturnCodeEnum.CODE_GET_CONNECTOR_INFO_BY_STATION_ID_ERROR);
}
logger.info("查询充电枪口列表 result:{}", response);
return response;
}
/**
* 根据充电站id查询枪口列表
* @param request
* @param dto
* @return
*/
@PostMapping("/selectStationConnectorList")
public RestApiResponse<?> selectStationConnectorList(HttpServletRequest request, @RequestBody QueryConnectorListDTO dto) {
logger.info("查询充电枪口列表 params:{}", JSONObject.toJSONString(dto));
RestApiResponse<?> response = null;
try {
PageResponse pageResponse = pileConnectorInfoService.selectStationConnectorList(dto);
response = new RestApiResponse<>(pageResponse);
} catch (Exception e) {
logger.error("查询充电枪口列表异常", e);
response = new RestApiResponse<>(ReturnCodeEnum.CODE_GET_CONNECTOR_INFO_BY_STATION_ID_ERROR);
}
logger.info("查询充电枪口列表 result:{}", response);
return response;
}
/**
* 根据充电站id查询枪口列表
*
* @param request
* @param dto
* @return
*/
@PostMapping("/selectStationConnectorList")
public RestApiResponse<?> selectStationConnectorList(HttpServletRequest request, @RequestBody QueryConnectorListDTO dto) {
logger.info("查询充电枪口列表 params:{}", JSONObject.toJSONString(dto));
RestApiResponse<?> response = null;
try {
PageResponse pageResponse = pileConnectorInfoService.selectStationConnectorList(dto);
response = new RestApiResponse<>(pageResponse);
} catch (Exception e) {
logger.error("查询充电枪口列表异常", e);
response = new RestApiResponse<>(ReturnCodeEnum.CODE_GET_CONNECTOR_INFO_BY_STATION_ID_ERROR);
}
logger.info("查询充电枪口列表 result:{}", response);
return response;
}
/**
* 远程遥控地锁指令 + 生成占桩订单
*/
@PostMapping("/remoteGroundLock")
public RestApiResponse<?> remoteGroundLock(HttpServletRequest request, @RequestBody RemoteGroundLockDTO dto) {
// logger.info("遥控地锁指令 params:{}", JSONObject.toJSONString(dto));
RestApiResponse<?> response = null;
try {
// 校验参数
if (StringUtils.isBlank(dto.getPileSn()) || StringUtils.isBlank(dto.getConnectorCode())
|| StringUtils.isBlank(dto.getOperate())) {
throw new BusinessException(ReturnCodeEnum.CODE_PARAM_NOT_NULL_ERROR);
}
// 获取memberId
dto.setMemberId(getMemberIdByAuthorization(request));
orderPileOccupyService.remoteGroundLock(dto);
response = new RestApiResponse<>();
} catch (Exception e) {
logger.error("遥控地锁指令 error, ", e);
response = new RestApiResponse<>(e);
}
logger.info("遥控地锁指令 result:{}", response);
return response;
}
/**
* 远程遥控地锁指令 + 生成占桩订单
*/
@PostMapping("/remoteGroundLock")
public RestApiResponse<?> remoteGroundLock(HttpServletRequest request, @RequestBody RemoteGroundLockDTO dto) {
// logger.info("遥控地锁指令 params:{}", JSONObject.toJSONString(dto));
RestApiResponse<?> response = null;
try {
// 校验参数
if (StringUtils.isBlank(dto.getPileSn()) || StringUtils.isBlank(dto.getConnectorCode())
|| StringUtils.isBlank(dto.getOperate())) {
throw new BusinessException(ReturnCodeEnum.CODE_PARAM_NOT_NULL_ERROR);
}
// 获取memberId
dto.setMemberId(getMemberIdByAuthorization(request));
orderPileOccupyService.remoteGroundLock(dto);
response = new RestApiResponse<>();
} catch (BusinessException e) {
logger.error("遥控地锁指令 warn", e);
response = new RestApiResponse<>(e.getCode(), e.getMessage());
} catch (Exception e) {
logger.error("遥控地锁指令 error", e);
response = new RestApiResponse<>(e);
}
logger.info("遥控地锁指令 result:{}", response);
return response;
}
}

View File

@@ -35,6 +35,9 @@ public class CacheConstants {
// 地锁数据
public static final String GROUND_LOCK_DATA = "ground_lock_data:";
// 地锁订单数据
public static final String GROUND_LOCK_OCCUPY_ORDER = "ground_lock_occupy_order:";
// 根据站点id查询充电桩列表
public static final String GET_PILE_LIST_BY_STATION_ID = "get_pile_list_by_station_id:";

View File

@@ -122,6 +122,9 @@ public enum ReturnCodeEnum {
CODE_GET_FIRST_LEVEL_MERCHANT_BY_APP_ID("00100058", "根据小程序appId未查询到一级运营商信息"),
// 地锁存在未完成的占桩订单
CODE_HAS_OCCUPY_PILE_ORDER_ERROR("00100059", "当前地锁存在未完成的占桩订单"),
/* 个人桩 start */
CODE_PILE_HAS_BEEN_BINDING_ERROR("00400001", "此桩已被绑定,请联系管理员!"),

View File

@@ -174,5 +174,8 @@ public class GroundLockDataUploadHandler extends AbstractHandler{
// 关闭占桩订单
orderPileOccupyService.closeOccupyPileOrder(pileSn, connectorCode);
}
String occupyOrderKey = CacheConstants.GROUND_LOCK_OCCUPY_ORDER + pileSn + connectorCode;
redisCache.deleteObject(occupyOrderKey);
}
}

View File

@@ -4,8 +4,10 @@ import com.alibaba.fastjson2.JSON;
import com.github.pagehelper.PageInfo;
import com.google.common.collect.Maps;
import com.jsowell.adapay.service.AdapayService;
import com.jsowell.common.constant.CacheConstants;
import com.jsowell.common.constant.Constants;
import com.jsowell.common.core.page.PageResponse;
import com.jsowell.common.core.redis.RedisCache;
import com.jsowell.common.enums.DelFlagEnum;
import com.jsowell.common.enums.MemberWalletEnum;
import com.jsowell.common.enums.uniapp.OccupyOrderPayStatusEnum;
@@ -70,6 +72,9 @@ public class OrderPileOccupyServiceImpl implements OrderPileOccupyService {
@Autowired
private OrderPileOccupyService orderPileOccupyService;
@Autowired
private RedisCache redisCache;
@Override
public int deleteByPrimaryKey(Integer id) {
return orderPileOccupyMapper.deleteByPrimaryKey(id);
@@ -166,6 +171,13 @@ public class OrderPileOccupyServiceImpl implements OrderPileOccupyService {
String memberId = dto.getMemberId();
String pileSn = dto.getPileSn();
String connectorCode = dto.getConnectorCode();
String redisKey = CacheConstants.GROUND_LOCK_OCCUPY_ORDER + pileSn + connectorCode;
String cacheObject = redisCache.getCacheObject(redisKey);
if (StringUtils.isNotBlank(cacheObject)) {
throw new BusinessException(ReturnCodeEnum.CODE_HAS_OCCUPY_PILE_ORDER_ERROR);
}
// 创建占桩订单
OrderPileOccupy orderPileOccupy = new OrderPileOccupy();
String occupyCode = "OP" + IdUtils.getOrderCode();
@@ -184,6 +196,9 @@ public class OrderPileOccupyServiceImpl implements OrderPileOccupyService {
orderPileOccupy.setDelFlag(DelFlagEnum.NORMAL.getValue());
orderPileOccupyMapper.insertSelective(orderPileOccupy);
// 放缓存
redisCache.setCacheObject(redisKey, occupyCode, CacheConstants.cache_expire_time_10d);
return orderPileOccupy.getOccupyCode();
}
@@ -381,27 +396,29 @@ public class OrderPileOccupyServiceImpl implements OrderPileOccupyService {
* @return
*/
public OrderPileOccupy getOccupiedOrder(String pileSn, String connectorCode) {
List<OrderPileOccupy> list = orderPileOccupyMapper.queryOccupiedOrder(pileSn, connectorCode);
if (CollectionUtils.isEmpty(list)) {
return null;
OrderPileOccupy result = null;
// 查缓存中的占桩订单编号
String redisKey = CacheConstants.GROUND_LOCK_OCCUPY_ORDER + pileSn + connectorCode;
String orderCode = redisCache.getCacheObject(redisKey);
if (StringUtils.isNotBlank(orderCode)) {
result = queryByOccupyCode(orderCode);
} else {
List<OrderPileOccupy> list = orderPileOccupyMapper.queryOccupiedOrder(pileSn, connectorCode);
if (CollectionUtils.isNotEmpty(list)) {
if (list.size() > 1) {
List<Integer> collect = list.stream().map(OrderPileOccupy::getId).collect(Collectors.toList());
log.info("根据pileSn:{}, connectorCode:{}, 查询出多条占桩中的占桩订单, ids:{}", pileSn, connectorCode, collect);
}
result = list.get(0);
}
}
if (list.size() > 1) {
List<Integer> collect = list.stream().map(OrderPileOccupy::getId).collect(Collectors.toList());
log.info("根据pileSn:{}, connectorCode:{}, 查询出多条占桩中的占桩订单, ids:{}", pileSn, connectorCode, collect);
}
return list.get(0);
return result;
}
@Override
public void remoteGroundLock(RemoteGroundLockDTO dto) {
log.info("控制地锁升降并生成占桩订单 params:{}", JSON.toJSONString(dto));
// 控制地锁升降
RemoteControlGroundLockCommand command = new RemoteControlGroundLockCommand();
command.setPileSn(dto.getPileSn());
command.setConnectorCode(dto.getConnectorCode());
command.setOperate(dto.getOperate());
ykcPushCommandService.pushRemoteControlGroundLock(command);
// 如果是降锁生成占桩订单
if (StringUtils.equals(dto.getOperate(), Constants.ZERO)) {
// 生成占桩订单
@@ -412,6 +429,13 @@ public class OrderPileOccupyServiceImpl implements OrderPileOccupyService {
// 生成占桩订单(草稿单)
orderPileOccupyService.generateOccupyPileOrder(generateOccupyOrderDTO);
}
// 控制地锁升降
RemoteControlGroundLockCommand command = new RemoteControlGroundLockCommand();
command.setPileSn(dto.getPileSn());
command.setConnectorCode(dto.getConnectorCode());
command.setOperate(dto.getOperate());
ykcPushCommandService.pushRemoteControlGroundLock(command);
}
/**
@@ -465,9 +489,11 @@ public class OrderPileOccupyServiceImpl implements OrderPileOccupyService {
// 查询草稿状态的占桩订单
OrderPileOccupy draftOccupyOrder = getDraftOccupyOrder(pileSn, connectorCode);
// 关闭草稿订单
draftOccupyOrder.setStatus(Constants.ONE);
draftOccupyOrder.setPayStatus(Constants.TWO);
updateByPrimaryKey(draftOccupyOrder);
if (draftOccupyOrder != null) {
draftOccupyOrder.setStatus(Constants.ONE);
draftOccupyOrder.setPayStatus(Constants.TWO);
updateByPrimaryKey(draftOccupyOrder);
}
}
/*