package com.ruoyi.order.controller; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.ruoyi.chargingPile.api.vo.SiteVO; import com.ruoyi.common.core.domain.R; import com.ruoyi.common.redis.service.RedisService; import com.ruoyi.common.security.service.TokenService; import com.ruoyi.common.core.web.domain.AjaxResult; import com.ruoyi.common.core.web.page.BasePage; import com.ruoyi.common.core.web.page.PageInfo; import com.ruoyi.order.api.model.TChargingOrder; import com.ruoyi.order.api.model.TOrderEvaluate; import com.ruoyi.order.api.query.TChargingCountQuery; import com.ruoyi.order.api.vo.ChargingOrderVO; import com.ruoyi.order.dto.GetMyChargingOrderList; import com.ruoyi.order.dto.GetNoInvoicedOrder; import com.ruoyi.order.dto.MyChargingOrderInfo; import com.ruoyi.order.dto.MyChargingOrderList; import com.ruoyi.order.dto.OrderEvaluateVo; import com.ruoyi.order.dto.*; import com.ruoyi.order.service.TChargingOrderService; import com.ruoyi.order.service.TOrderEvaluateService; import com.ruoyi.order.service.TOrderEvaluateTagService; import com.ruoyi.payment.api.feignClient.WxPaymentClient; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParams; import org.springframework.beans.factory.annotation.Autowired; import io.swagger.annotations.ApiOperation; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.util.List; import java.util.Map; import java.util.List; /** *

* 前端控制器 *

* * @author xiaochen * @since 2024-08-07 */ @Api(tags = "充电订单") @RestController @RequestMapping("/t-charging-order") public class TChargingOrderController { @Resource private TChargingOrderService chargingOrderService; @Autowired private TokenService tokenService; @Autowired private TOrderEvaluateService orderEvaluateService; @Autowired private TOrderEvaluateTagService orderEvaluateTagService; @Resource private WxPaymentClient wxPaymentClient; @Resource private RedisService redisService; @ResponseBody @PostMapping(value = "/chargingOrder") @ApiOperation(value = "充电桩订单列表", tags = {"管理后台-订单管理"}) public AjaxResult> chargingOrder(@RequestBody OrderEvaluateVo dto){ return AjaxResult.success(); } @ResponseBody @PostMapping(value = "/addEvaluate") @ApiOperation(value = "添加评价", tags = {"小程序-扫一扫"}) public AjaxResult getMyChargingOrderList(@RequestBody OrderEvaluateVo dto){ dto.setAppUserId(tokenService.getLoginUserApplet().getUserId()); orderEvaluateService.addOrderEvaluate(dto); return AjaxResult.success(); } /** * 查询用户最近一次充电记录使用的车辆 * @param * @return */ @GetMapping(value = "/getCar") public R getCar() { List list = chargingOrderService.list(new LambdaQueryWrapper() .eq(TChargingOrder::getAppUserId, tokenService.getLoginUserApplet().getUserId()) .isNotNull(TChargingOrder::getAppUserCarId)); if (!list.isEmpty()){ // 最近使用的车辆id Long size = list.get(0).getAppUserCarId(); return R.ok(size); }else{ return R.ok(-1L); } } /** * 查询会员在本月有多少次享受了充电折扣 * @param req * @return */ @PostMapping(value = "/getChargingCount") public R getChargingCount(@RequestBody TChargingCountQuery req) { int size = chargingOrderService.list(new LambdaQueryWrapper() .eq(TChargingOrder::getAppUserId, req.getUserId()) .eq(TChargingOrder::getRechargePaymentStatus,2) .between(TChargingOrder::getStartTime, req.getStartTime(), req.getEndTime())).size(); return R.ok(size); } //用户订单数量 @PostMapping(value = "/useOrderCount") public R useOrderCount(@RequestParam("userId") Long userId) { Long count = chargingOrderService.lambdaQuery().eq(TChargingOrder::getAppUserId, userId).count(); return R.ok(count); } //订单详情 @PostMapping(value = "/detail") public R detail(@RequestParam("orderId") Long orderId) { return R.ok(chargingOrderService.getById(orderId)); } /** * 根据充电枪id获取正在进行中的订单 * @param chargingGunId 充电枪id * @return */ @PostMapping(value = "/getOrderDetailByGunId") public R getOrderDetailByGunId(@RequestParam("chargingGunId") Integer chargingGunId){ TChargingOrder one = chargingOrderService.getOne(new LambdaQueryWrapper().eq(TChargingOrder::getChargingGunId, chargingGunId) .eq(TChargingOrder::getDelFlag, 0).eq(TChargingOrder::getStatus, 3)); return R.ok(one); } @ResponseBody @GetMapping(value = "/getMyChargingOrderList") @ApiOperation(value = "获取充电记录列表", tags = {"小程序-充电记录"}) public AjaxResult> getMyChargingOrderList(GetMyChargingOrderList query){ Map orderList = chargingOrderService.getMyChargingOrderList(query); return AjaxResult.success(orderList); } @ResponseBody @GetMapping(value = "/getMyChargingOrderInfo") @ApiOperation(value = "获取充电记订单明细", tags = {"小程序-充电记录"}) public AjaxResult getMyChargingOrderInfo(String id){ MyChargingOrderInfo myChargingOrderInfo = chargingOrderService.getMyChargingOrderInfo(id); return AjaxResult.success(myChargingOrderInfo); } @ResponseBody @GetMapping(value = "/getNoInvoicedOrder") @ApiOperation(value = "获取未开票的订单数据", tags = {"小程序-充电发票"}) public AjaxResult> getNoInvoicedOrder(GetNoInvoicedOrder query){ List list = chargingOrderService.getNoInvoicedOrder(query); return AjaxResult.success(list); } @ResponseBody @PostMapping(value = "/paymentChargingOrder") @ApiOperation(value = "支付充电充值费用", tags = {"小程序-扫一扫"}) public AjaxResult paymentChargingOrder(AddChargingOrder addChargingOrder){ return chargingOrderService.paymentChargingOrder(addChargingOrder); } /** * 充电充值支付回调 * @param request */ @ResponseBody @PostMapping(value = "/chargingOrderWXCallback") public void chargingOrderWXCallback(HttpServletRequest request){ Map data = wxPaymentClient.payNotify(request).getData(); if(null != data){ String out_trade_no = data.get("out_trade_no").toString(); String transaction_id = data.get("transaction_id").toString(); String attach = data.get("attach").toString(); AjaxResult ajaxResult = chargingOrderService.chargingOrderCallback(1, out_trade_no, transaction_id, attach); if(ajaxResult.isSuccess()){ wxPaymentClient.ack(); } } } /** * 支付宝支付成功后的回调 * @param request */ @ResponseBody @PostMapping(value = "/chargingOrderALICallback") public void chargingOrderALICallback(HttpServletRequest request){ Map data = wxPaymentClient.payNotify(request).getData(); if(null != data){ String out_trade_no = data.get("out_trade_no").toString(); String transaction_id = data.get("transaction_id").toString(); String attach = data.get("attach").toString(); AjaxResult ajaxResult = chargingOrderService.chargingOrderCallback(2, out_trade_no, transaction_id, attach); if(ajaxResult.isSuccess()){ } } } @ResponseBody @GetMapping(value = "/preChargeCheck/{id}") @ApiOperation(value = "获取安全检测数据", tags = {"小程序-扫一扫"}) @ApiImplicitParams({ @ApiImplicitParam(name = "id", value = "充电枪id", required = true) }) public AjaxResult preChargeCheck(@PathVariable Integer id){ String key = "AQJC_" + id; Object cacheObject = redisService.getCacheObject(key); return AjaxResult.success(cacheObject); } @ResponseBody @GetMapping(value = "/getChargingDetails/{id}") @ApiOperation(value = "获取充电中页面数据", tags = {"小程序-扫一扫"}) @ApiImplicitParams({ @ApiImplicitParam(name = "id", value = "充电枪id", required = true) }) public AjaxResult getChargingDetails(@PathVariable Integer id){ ChargingDetails chargingDetails = chargingOrderService.getChargingDetails(id); return AjaxResult.success(chargingDetails); } @ResponseBody @PutMapping(value = "/stopCharging/{id}") @ApiOperation(value = "手动停止充电", tags = {"小程序-扫一扫"}) @ApiImplicitParams({ @ApiImplicitParam(name = "id", value = "订单id", required = true) }) public AjaxResult stopCharging(@PathVariable String id){ return chargingOrderService.stopCharging(id); } }