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