2026-01-16 15:37:45 +08:00
|
|
|
package com.cdzy.operations.controller;
|
|
|
|
|
|
|
|
|
|
import cn.dev33.satoken.stp.StpUtil;
|
|
|
|
|
import com.cdzy.common.enums.Code;
|
|
|
|
|
import com.cdzy.common.ex.EbikeException;
|
2026-02-26 16:17:12 +08:00
|
|
|
import com.cdzy.common.model.dto.ResGPSDto;
|
2026-02-26 17:28:54 +08:00
|
|
|
import com.cdzy.common.model.request.PageParam;
|
2026-01-16 15:37:45 +08:00
|
|
|
import com.cdzy.common.model.response.CommonStaffInfo;
|
|
|
|
|
import com.cdzy.common.model.response.JsonResult;
|
2026-02-26 16:17:12 +08:00
|
|
|
import com.cdzy.operations.model.dto.EbikeCloseOrderDto;
|
|
|
|
|
import com.cdzy.operations.model.entity.EbikeEcuInfo;
|
|
|
|
|
import com.cdzy.operations.service.EbikeEcuInfoService;
|
|
|
|
|
import com.cdzy.operations.utils.RedisUtil;
|
2026-01-16 15:37:45 +08:00
|
|
|
import com.ebike.feign.clients.UserFeignClient;
|
2026-02-26 16:17:12 +08:00
|
|
|
import com.ebike.feign.model.dto.FeignDiffOperatorOrderList;
|
|
|
|
|
import com.ebike.feign.model.dto.FeignEbikeCloseOrderDto;
|
2026-01-16 15:37:45 +08:00
|
|
|
import com.ebike.feign.model.dto.FeignEbikeOrderStatisticsDto;
|
2026-02-09 16:08:40 +08:00
|
|
|
import com.ebike.feign.model.dto.FeignEbikePaymentAmountDto;
|
2026-01-16 15:37:45 +08:00
|
|
|
import jakarta.annotation.Resource;
|
|
|
|
|
import org.springframework.validation.annotation.Validated;
|
2026-02-26 16:17:12 +08:00
|
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
2026-01-16 15:37:45 +08:00
|
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
|
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
2026-01-16 17:13:24 +08:00
|
|
|
import java.util.Collections;
|
|
|
|
|
import java.util.Optional;
|
|
|
|
|
|
2026-01-16 15:37:45 +08:00
|
|
|
/**
|
2026-01-16 16:03:43 +08:00
|
|
|
* 用户订单统计 控制层
|
|
|
|
|
*
|
2026-01-16 15:37:45 +08:00
|
|
|
* @author yanglei
|
|
|
|
|
* @since 2026-01-16 15:15
|
|
|
|
|
*/
|
|
|
|
|
@RestController
|
|
|
|
|
@RequestMapping("/statistics")
|
|
|
|
|
public class EbikeStatisticsController {
|
|
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
|
private UserFeignClient userFeignClient;
|
|
|
|
|
|
2026-02-26 16:17:12 +08:00
|
|
|
@Resource
|
|
|
|
|
private RedisUtil redisUtil;
|
|
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
|
private EbikeEcuInfoService ecuInfoService;
|
|
|
|
|
|
|
|
|
|
|
2026-01-16 15:37:45 +08:00
|
|
|
/**
|
|
|
|
|
* 查询用户订单统计
|
|
|
|
|
*
|
|
|
|
|
* @param dto 参数参数
|
|
|
|
|
* @return 用户订单数据统计
|
|
|
|
|
*/
|
|
|
|
|
@PostMapping("/getOrderStatistics")
|
|
|
|
|
public JsonResult<?> getOrderStatistics(@RequestBody @Validated FeignEbikeOrderStatisticsDto dto) {
|
2026-01-16 16:03:09 +08:00
|
|
|
long staffId = StpUtil.getLoginIdAsLong();
|
|
|
|
|
CommonStaffInfo staffInfo = StpUtil.getSession().getModel(String.valueOf(staffId), CommonStaffInfo.class);
|
2026-01-16 17:13:24 +08:00
|
|
|
if (staffInfo == null) {
|
|
|
|
|
throw new EbikeException("当前用户信息不存在");
|
|
|
|
|
}
|
|
|
|
|
boolean isSuperAdmin = Optional.ofNullable(staffInfo.getRoles())
|
|
|
|
|
.orElse(Collections.emptyList())
|
|
|
|
|
.stream()
|
|
|
|
|
.anyMatch(role -> "super_admin".equals(role.getRoleCode()));
|
|
|
|
|
// 判断是否超级管理员
|
|
|
|
|
if (!isSuperAdmin) {
|
|
|
|
|
dto.setOperatorId(staffInfo.getOperatorId());
|
|
|
|
|
}
|
2026-01-16 15:37:45 +08:00
|
|
|
JsonResult<?> jsonResult = userFeignClient.getOrderStatistics(dto);
|
|
|
|
|
if (jsonResult.getCode() != Code.SUCCESS) {
|
|
|
|
|
throw new EbikeException(jsonResult.getMessage());
|
|
|
|
|
}
|
|
|
|
|
return JsonResult.success(jsonResult.getData());
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-09 16:08:40 +08:00
|
|
|
/**
|
|
|
|
|
* 根据车辆编号修改当前订单金额
|
|
|
|
|
*
|
|
|
|
|
* @param dto 车辆请求参数
|
|
|
|
|
*/
|
|
|
|
|
@PostMapping("updateOrderAmount")
|
|
|
|
|
public JsonResult<?> updateOrderAmount(@RequestBody @Validated FeignEbikePaymentAmountDto dto) {
|
|
|
|
|
JsonResult<?> jsonResult = userFeignClient.updateOrderAmount(dto);
|
|
|
|
|
if (jsonResult.getCode() != Code.SUCCESS) {
|
|
|
|
|
throw new EbikeException(jsonResult.getMessage());
|
|
|
|
|
}
|
|
|
|
|
return JsonResult.success();
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-26 16:17:12 +08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 结束用户骑行订单
|
|
|
|
|
*
|
|
|
|
|
* @param dto 结束骑行参数
|
|
|
|
|
* @return 订单id
|
|
|
|
|
*/
|
|
|
|
|
@PostMapping("/closeOrder")
|
|
|
|
|
public JsonResult<?> closeBikeOrder(@RequestBody @Validated EbikeCloseOrderDto dto) {
|
|
|
|
|
// 根据车辆编号获取车辆ecu
|
|
|
|
|
EbikeEcuInfo ebikeEcuInfo = ecuInfoService.getEcu(dto.getBikeCode());
|
|
|
|
|
// 从redis获取车辆当前位置
|
|
|
|
|
ResGPSDto resGPSDto = (ResGPSDto) redisUtil.getEcu(ebikeEcuInfo.getEcuSn());
|
|
|
|
|
|
|
|
|
|
FeignEbikeCloseOrderDto ebikeCloseOrderDto = FeignEbikeCloseOrderDto.builder()
|
|
|
|
|
.bikeCode(dto.getBikeCode())
|
|
|
|
|
.lng(resGPSDto.getLongitude())
|
|
|
|
|
.lat(resGPSDto.getLatitude())
|
|
|
|
|
.build();
|
|
|
|
|
//远程调用用户端关锁结束骑行
|
|
|
|
|
JsonResult<?> jsonResult = userFeignClient.closeOrder(ebikeCloseOrderDto);
|
|
|
|
|
if (jsonResult.getCode() != Code.SUCCESS) {
|
|
|
|
|
throw new EbikeException(jsonResult.getMessage());
|
|
|
|
|
}
|
|
|
|
|
return JsonResult.success(jsonResult.getData());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 不同运营商获取骑行中与待支付的订单列表
|
|
|
|
|
*
|
|
|
|
|
* @return 订单列表
|
|
|
|
|
*/
|
|
|
|
|
@GetMapping("getDiffOperatorOrderList")
|
2026-02-26 17:28:54 +08:00
|
|
|
public JsonResult<?> getDiffOperatorOrderList(String bikeCode, PageParam pageParam) {
|
2026-02-26 16:17:12 +08:00
|
|
|
FeignDiffOperatorOrderList dto = new FeignDiffOperatorOrderList();
|
|
|
|
|
long staffId = StpUtil.getLoginIdAsLong();
|
|
|
|
|
CommonStaffInfo staffInfo = StpUtil.getSession().getModel(String.valueOf(staffId), CommonStaffInfo.class);
|
|
|
|
|
if (staffInfo == null) {
|
|
|
|
|
throw new EbikeException("当前用户信息不存在");
|
|
|
|
|
}
|
|
|
|
|
boolean isSuperAdmin = Optional.ofNullable(staffInfo.getRoles())
|
|
|
|
|
.orElse(Collections.emptyList())
|
|
|
|
|
.stream()
|
|
|
|
|
.anyMatch(role -> "super_admin".equals(role.getRoleCode()));
|
|
|
|
|
// 判断是否超级管理员
|
|
|
|
|
if (!isSuperAdmin) {
|
|
|
|
|
dto.setOperatorId(staffInfo.getOperatorId());
|
|
|
|
|
}
|
2026-02-26 17:28:54 +08:00
|
|
|
dto.setBikeCode(bikeCode);
|
|
|
|
|
dto.setPageParam(pageParam);
|
2026-02-26 16:17:12 +08:00
|
|
|
JsonResult<?> jsonResult = userFeignClient.getDiffOperatorOrderList(dto);
|
|
|
|
|
if (jsonResult.getCode() != Code.SUCCESS) {
|
|
|
|
|
throw new EbikeException(jsonResult.getMessage());
|
|
|
|
|
}
|
|
|
|
|
return JsonResult.success(jsonResult.getData());
|
|
|
|
|
}
|
2026-01-16 15:37:45 +08:00
|
|
|
}
|