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") @RequestMapping("/uniapp/pile")
public class PileController extends BaseController { public class PileController extends BaseController {
@Autowired @Autowired
private IPileStationInfoService pileStationInfoService; private IPileStationInfoService pileStationInfoService;
@Autowired @Autowired
private IPileConnectorInfoService pileConnectorInfoService; private IPileConnectorInfoService pileConnectorInfoService;
@Autowired @Autowired
private IPileBillingTemplateService pileBillingTemplateService; private IPileBillingTemplateService pileBillingTemplateService;
@Autowired @Autowired
private IPileMerchantInfoService pileMerchantInfoService; private IPileMerchantInfoService pileMerchantInfoService;
@Autowired @Autowired
private OrderPileOccupyService orderPileOccupyService; private OrderPileOccupyService orderPileOccupyService;
/** /**
* 查询充电站信息列表(主页) * 查询充电站信息列表(主页)
* * <p>
* http://localhost:8080/uniapp/pile/queryStationInfos * http://localhost:8080/uniapp/pile/queryStationInfos
*/ */
@PostMapping("/queryStationInfos") @PostMapping("/queryStationInfos")
public RestApiResponse<?> queryStationInfos(HttpServletRequest request, @RequestBody QueryStationDTO queryStationDTO) { public RestApiResponse<?> queryStationInfos(HttpServletRequest request, @RequestBody QueryStationDTO queryStationDTO) {
logger.info("查询充电站信息列表 param:{}", JSONObject.toJSONString(queryStationDTO)); logger.info("查询充电站信息列表 param:{}", JSONObject.toJSONString(queryStationDTO));
RestApiResponse<?> response = null; RestApiResponse<?> response = null;
try { try {
// 获取appid第三方平台用 // 获取appid第三方平台用
String appId = request.getHeader("appId"); String appId = request.getHeader("appId");
if (StringUtils.isNotBlank(appId)) { if (StringUtils.isNotBlank(appId)) {
// 获取deptIds // 获取deptIds
List<String> deptIds = pileMerchantInfoService.getDeptIdsByAppId(appId); List<String> deptIds = pileMerchantInfoService.getDeptIdsByAppId(appId);
queryStationDTO.setMerchantDeptIds(deptIds); queryStationDTO.setMerchantDeptIds(deptIds);
} }
logger.info("uniApp查询充电站信息appId:{}, dto:{}", appId, JSON.toJSONString(queryStationDTO)); logger.info("uniApp查询充电站信息appId:{}, dto:{}", appId, JSON.toJSONString(queryStationDTO));
PageResponse pageResponse = pileStationInfoService.uniAppQueryStationInfoList(queryStationDTO); PageResponse pageResponse = pileStationInfoService.uniAppQueryStationInfoList(queryStationDTO);
response = new RestApiResponse<>(pageResponse); response = new RestApiResponse<>(pageResponse);
} catch (BusinessException e) { } catch (BusinessException e) {
logger.warn("查询充电站信息列表warn", e); logger.warn("查询充电站信息列表warn", e);
response = new RestApiResponse<>(e.getCode(), e.getMessage()); response = new RestApiResponse<>(e.getCode(), e.getMessage());
} catch (Exception e) { } catch (Exception e) {
logger.error("查询充电站信息列表异常 error", e); logger.error("查询充电站信息列表异常 error", e);
response = new RestApiResponse<>(ReturnCodeEnum.CODE_GET_PILE_STATION_INFO_ERROR); response = new RestApiResponse<>(ReturnCodeEnum.CODE_GET_PILE_STATION_INFO_ERROR);
} }
logger.info("查询充电站信息列表 result:{}", JSONObject.toJSONString(response)); logger.info("查询充电站信息列表 result:{}", JSONObject.toJSONString(response));
return response; return response;
} }
/** /**
* 通过站点id查询计费模板列表 * 通过站点id查询计费模板列表
* http://localhost:8080/uniapp/pile/queryBillingPrice/{stationId} * http://localhost:8080/uniapp/pile/queryBillingPrice/{stationId}
* @param stationId *
* @return * @param stationId
*/ * @return
@GetMapping("/queryBillingPrice/{stationId}") */
public RestApiResponse<?> queryBillingPrice(@PathVariable("stationId") String stationId) { @GetMapping("/queryBillingPrice/{stationId}")
logger.info("通过站点id查询计费模板列表 params:{}", stationId); public RestApiResponse<?> queryBillingPrice(@PathVariable("stationId") String stationId) {
RestApiResponse<?> response = null; logger.info("通过站点id查询计费模板列表 params:{}", stationId);
try { RestApiResponse<?> response = null;
List<BillingPriceVO> billingPriceVOList = pileBillingTemplateService.queryBillingPrice(stationId); try {
response = new RestApiResponse<>(billingPriceVOList); List<BillingPriceVO> billingPriceVOList = pileBillingTemplateService.queryBillingPrice(stationId);
} catch (Exception e) { response = new RestApiResponse<>(billingPriceVOList);
logger.error("通过站点id查询计费模板列表 error, ", e); } catch (Exception e) {
response = new RestApiResponse<>(e); logger.error("通过站点id查询计费模板列表 error, ", e);
} response = new RestApiResponse<>(e);
logger.info("通过站点id查询计费模板列表 result:{}", response); }
return response; logger.info("通过站点id查询计费模板列表 result:{}", response);
} return response;
}
/** /**
* 通过前端参数查询充电枪口列表 * 通过前端参数查询充电枪口列表
* * <p>
* http://localhost:8080/uniapp/pile/selectConnectorListByParams * http://localhost:8080/uniapp/pile/selectConnectorListByParams
* *
* @param dto * @param dto
* @return * @return
*/ */
@PostMapping("/selectConnectorListByParams") @PostMapping("/selectConnectorListByParams")
public RestApiResponse<?> selectConnectorListByParams(HttpServletRequest request, @RequestBody QueryConnectorListDTO dto) { public RestApiResponse<?> selectConnectorListByParams(HttpServletRequest request, @RequestBody QueryConnectorListDTO dto) {
logger.info("查询充电枪口列表 params:{}", JSONObject.toJSONString(dto)); logger.info("查询充电枪口列表 params:{}", JSONObject.toJSONString(dto));
RestApiResponse<?> response = null; RestApiResponse<?> response = null;
try { try {
PageResponse pageResponse = pileConnectorInfoService.getUniAppConnectorInfoListByParams(dto); PageResponse pageResponse = pileConnectorInfoService.getUniAppConnectorInfoListByParams(dto);
response = new RestApiResponse<>(pageResponse); response = new RestApiResponse<>(pageResponse);
} catch (Exception e) { } catch (Exception e) {
logger.error("查询充电枪口列表异常", e); logger.error("查询充电枪口列表异常", e);
response = new RestApiResponse<>(ReturnCodeEnum.CODE_GET_CONNECTOR_INFO_BY_STATION_ID_ERROR); response = new RestApiResponse<>(ReturnCodeEnum.CODE_GET_CONNECTOR_INFO_BY_STATION_ID_ERROR);
} }
logger.info("查询充电枪口列表 result:{}", response); logger.info("查询充电枪口列表 result:{}", response);
return response; return response;
} }
/** /**
* 根据充电站id查询枪口列表 * 根据充电站id查询枪口列表
* @param request *
* @param dto * @param request
* @return * @param dto
*/ * @return
@PostMapping("/selectStationConnectorList") */
public RestApiResponse<?> selectStationConnectorList(HttpServletRequest request, @RequestBody QueryConnectorListDTO dto) { @PostMapping("/selectStationConnectorList")
logger.info("查询充电枪口列表 params:{}", JSONObject.toJSONString(dto)); public RestApiResponse<?> selectStationConnectorList(HttpServletRequest request, @RequestBody QueryConnectorListDTO dto) {
RestApiResponse<?> response = null; logger.info("查询充电枪口列表 params:{}", JSONObject.toJSONString(dto));
try { RestApiResponse<?> response = null;
PageResponse pageResponse = pileConnectorInfoService.selectStationConnectorList(dto); try {
response = new RestApiResponse<>(pageResponse); PageResponse pageResponse = pileConnectorInfoService.selectStationConnectorList(dto);
} catch (Exception e) { response = new RestApiResponse<>(pageResponse);
logger.error("查询充电枪口列表异常", e); } catch (Exception e) {
response = new RestApiResponse<>(ReturnCodeEnum.CODE_GET_CONNECTOR_INFO_BY_STATION_ID_ERROR); logger.error("查询充电枪口列表异常", e);
} response = new RestApiResponse<>(ReturnCodeEnum.CODE_GET_CONNECTOR_INFO_BY_STATION_ID_ERROR);
logger.info("查询充电枪口列表 result:{}", response); }
return response; logger.info("查询充电枪口列表 result:{}", response);
} return response;
}
/** /**
* 远程遥控地锁指令 + 生成占桩订单 * 远程遥控地锁指令 + 生成占桩订单
*/ */
@PostMapping("/remoteGroundLock") @PostMapping("/remoteGroundLock")
public RestApiResponse<?> remoteGroundLock(HttpServletRequest request, @RequestBody RemoteGroundLockDTO dto) { public RestApiResponse<?> remoteGroundLock(HttpServletRequest request, @RequestBody RemoteGroundLockDTO dto) {
// logger.info("遥控地锁指令 params:{}", JSONObject.toJSONString(dto)); // logger.info("遥控地锁指令 params:{}", JSONObject.toJSONString(dto));
RestApiResponse<?> response = null; RestApiResponse<?> response = null;
try { try {
// 校验参数 // 校验参数
if (StringUtils.isBlank(dto.getPileSn()) || StringUtils.isBlank(dto.getConnectorCode()) if (StringUtils.isBlank(dto.getPileSn()) || StringUtils.isBlank(dto.getConnectorCode())
|| StringUtils.isBlank(dto.getOperate())) { || StringUtils.isBlank(dto.getOperate())) {
throw new BusinessException(ReturnCodeEnum.CODE_PARAM_NOT_NULL_ERROR); throw new BusinessException(ReturnCodeEnum.CODE_PARAM_NOT_NULL_ERROR);
} }
// 获取memberId // 获取memberId
dto.setMemberId(getMemberIdByAuthorization(request)); dto.setMemberId(getMemberIdByAuthorization(request));
orderPileOccupyService.remoteGroundLock(dto); orderPileOccupyService.remoteGroundLock(dto);
response = new RestApiResponse<>(); response = new RestApiResponse<>();
} catch (Exception e) { } catch (BusinessException e) {
logger.error("遥控地锁指令 error, ", e); logger.error("遥控地锁指令 warn", e);
response = new RestApiResponse<>(e); response = new RestApiResponse<>(e.getCode(), e.getMessage());
} } catch (Exception e) {
logger.info("遥控地锁指令 result:{}", response); logger.error("遥控地锁指令 error", e);
return response; 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_DATA = "ground_lock_data:";
// 地锁订单数据
public static final String GROUND_LOCK_OCCUPY_ORDER = "ground_lock_occupy_order:";
// 根据站点id查询充电桩列表 // 根据站点id查询充电桩列表
public static final String GET_PILE_LIST_BY_STATION_ID = "get_pile_list_by_station_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_GET_FIRST_LEVEL_MERCHANT_BY_APP_ID("00100058", "根据小程序appId未查询到一级运营商信息"),
// 地锁存在未完成的占桩订单
CODE_HAS_OCCUPY_PILE_ORDER_ERROR("00100059", "当前地锁存在未完成的占桩订单"),
/* 个人桩 start */ /* 个人桩 start */
CODE_PILE_HAS_BEEN_BINDING_ERROR("00400001", "此桩已被绑定,请联系管理员!"), CODE_PILE_HAS_BEEN_BINDING_ERROR("00400001", "此桩已被绑定,请联系管理员!"),

View File

@@ -174,5 +174,8 @@ public class GroundLockDataUploadHandler extends AbstractHandler{
// 关闭占桩订单 // 关闭占桩订单
orderPileOccupyService.closeOccupyPileOrder(pileSn, connectorCode); 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.github.pagehelper.PageInfo;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import com.jsowell.adapay.service.AdapayService; import com.jsowell.adapay.service.AdapayService;
import com.jsowell.common.constant.CacheConstants;
import com.jsowell.common.constant.Constants; import com.jsowell.common.constant.Constants;
import com.jsowell.common.core.page.PageResponse; 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.DelFlagEnum;
import com.jsowell.common.enums.MemberWalletEnum; import com.jsowell.common.enums.MemberWalletEnum;
import com.jsowell.common.enums.uniapp.OccupyOrderPayStatusEnum; import com.jsowell.common.enums.uniapp.OccupyOrderPayStatusEnum;
@@ -70,6 +72,9 @@ public class OrderPileOccupyServiceImpl implements OrderPileOccupyService {
@Autowired @Autowired
private OrderPileOccupyService orderPileOccupyService; private OrderPileOccupyService orderPileOccupyService;
@Autowired
private RedisCache redisCache;
@Override @Override
public int deleteByPrimaryKey(Integer id) { public int deleteByPrimaryKey(Integer id) {
return orderPileOccupyMapper.deleteByPrimaryKey(id); return orderPileOccupyMapper.deleteByPrimaryKey(id);
@@ -166,6 +171,13 @@ public class OrderPileOccupyServiceImpl implements OrderPileOccupyService {
String memberId = dto.getMemberId(); String memberId = dto.getMemberId();
String pileSn = dto.getPileSn(); String pileSn = dto.getPileSn();
String connectorCode = dto.getConnectorCode(); 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(); OrderPileOccupy orderPileOccupy = new OrderPileOccupy();
String occupyCode = "OP" + IdUtils.getOrderCode(); String occupyCode = "OP" + IdUtils.getOrderCode();
@@ -184,6 +196,9 @@ public class OrderPileOccupyServiceImpl implements OrderPileOccupyService {
orderPileOccupy.setDelFlag(DelFlagEnum.NORMAL.getValue()); orderPileOccupy.setDelFlag(DelFlagEnum.NORMAL.getValue());
orderPileOccupyMapper.insertSelective(orderPileOccupy); orderPileOccupyMapper.insertSelective(orderPileOccupy);
// 放缓存
redisCache.setCacheObject(redisKey, occupyCode, CacheConstants.cache_expire_time_10d);
return orderPileOccupy.getOccupyCode(); return orderPileOccupy.getOccupyCode();
} }
@@ -381,27 +396,29 @@ public class OrderPileOccupyServiceImpl implements OrderPileOccupyService {
* @return * @return
*/ */
public OrderPileOccupy getOccupiedOrder(String pileSn, String connectorCode) { public OrderPileOccupy getOccupiedOrder(String pileSn, String connectorCode) {
List<OrderPileOccupy> list = orderPileOccupyMapper.queryOccupiedOrder(pileSn, connectorCode); OrderPileOccupy result = null;
if (CollectionUtils.isEmpty(list)) {
return 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) { return result;
List<Integer> collect = list.stream().map(OrderPileOccupy::getId).collect(Collectors.toList());
log.info("根据pileSn:{}, connectorCode:{}, 查询出多条占桩中的占桩订单, ids:{}", pileSn, connectorCode, collect);
}
return list.get(0);
} }
@Override @Override
public void remoteGroundLock(RemoteGroundLockDTO dto) { public void remoteGroundLock(RemoteGroundLockDTO dto) {
log.info("控制地锁升降并生成占桩订单 params:{}", JSON.toJSONString(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)) { if (StringUtils.equals(dto.getOperate(), Constants.ZERO)) {
// 生成占桩订单 // 生成占桩订单
@@ -412,6 +429,13 @@ public class OrderPileOccupyServiceImpl implements OrderPileOccupyService {
// 生成占桩订单(草稿单) // 生成占桩订单(草稿单)
orderPileOccupyService.generateOccupyPileOrder(generateOccupyOrderDTO); 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); OrderPileOccupy draftOccupyOrder = getDraftOccupyOrder(pileSn, connectorCode);
// 关闭草稿订单 // 关闭草稿订单
draftOccupyOrder.setStatus(Constants.ONE); if (draftOccupyOrder != null) {
draftOccupyOrder.setPayStatus(Constants.TWO); draftOccupyOrder.setStatus(Constants.ONE);
updateByPrimaryKey(draftOccupyOrder); draftOccupyOrder.setPayStatus(Constants.TWO);
updateByPrimaryKey(draftOccupyOrder);
}
} }
/* /*