package com.jsowell.api.uniapp; import com.alibaba.fastjson2.JSONObject; import com.google.common.collect.ImmutableMap; import com.jsowell.common.annotation.Anonymous; import com.jsowell.common.constant.Constants; import com.jsowell.common.core.controller.BaseController; import com.jsowell.common.core.page.PageResponse; 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.domain.ykcCommond.RemoteControlGroundLockCommand; import com.jsowell.pile.dto.GenerateOccupyOrderDTO; import com.jsowell.pile.dto.QueryConnectorListDTO; import com.jsowell.pile.dto.QueryStationDTO; import com.jsowell.pile.service.*; import com.jsowell.pile.vo.uniapp.BillingPriceVO; import com.jsowell.pile.vo.uniapp.GroundLockInfoVO; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import javax.servlet.http.HttpServletRequest; import java.util.List; /** * 充电桩相关接口 * 提供给小程序调用 */ // 不登录直接访问 @Anonymous @RestController @RequestMapping("/uniapp/pile") public class PileController extends BaseController { @Autowired private YKCPushCommandService ykcPushCommandService; @Autowired private IPileStationInfoService pileStationInfoService; @Autowired private IPileConnectorInfoService pileConnectorInfoService; @Autowired private IPileBillingTemplateService pileBillingTemplateService; @Autowired private IPileMerchantInfoService pileMerchantInfoService; @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 deptIds = pileMerchantInfoService.getDeptIdsByAppId(appId); queryStationDTO.setMerchantDeptIds(deptIds); } 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 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; } /** * 根据充电站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; } /** * 远程遥控地锁指令 + 生成占桩订单 * @param command * @return */ @PostMapping("/remoteGroundLock") public RestApiResponse remoteGroundLock(HttpServletRequest request, @RequestBody RemoteControlGroundLockCommand command) { logger.info("遥控地锁指令 params:{}", JSONObject.toJSONString(command)); RestApiResponse response = null; try { ykcPushCommandService.pushRemoteControlGroundLock(command); if (StringUtils.equals(command.getOperate(), Constants.ONE)) { // 升锁不生成占桩订单 return new RestApiResponse<>(); } // 获取memberId String memberId = getMemberIdByAuthorization(request); if (StringUtils.isEmpty(memberId)) { throw new BusinessException(ReturnCodeEnum.CODE_TOKEN_ERROR); } GenerateOccupyOrderDTO dto = new GenerateOccupyOrderDTO(); dto.setMemberId(memberId); dto.setPileSn(command.getPileSn()); dto.setConnectorCode(command.getConnectorCode()); // 生成占桩订单(草稿单) String occupyOrderCode = orderPileOccupyService.generateOccupyPileOrder(dto); if (StringUtils.isNotBlank(occupyOrderCode)) { response = new RestApiResponse<>(ImmutableMap.of("occupyOrderCode", occupyOrderCode)); } } catch (Exception e) { logger.error("遥控地锁指令 error, ", e); response = new RestApiResponse<>(e); } logger.info("遥控地锁指令 result:{}", response); return response; } }