package com.xiaopeng.operation.controller;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.xiaopeng.api.dto.account.UcUserInfo;
import com.xiaopeng.api.dto.map.RouteAndFareDto;
import com.xiaopeng.api.dto.operation.LonLatDto;
import com.xiaopeng.api.feignClient.account.UserResourcesClient;
import com.xiaopeng.api.model.operation.XpPricing;
import com.xiaopeng.api.model.operation.XpWhitelist;
import com.xiaopeng.api.vo.operation.RouteAndFareVo;
import com.xiaopeng.common.core.domain.R;
import com.xiaopeng.common.core.exception.ServiceException;
import com.xiaopeng.common.core.web.controller.BaseController;
import com.xiaopeng.common.core.web.page.PageInfo;
import com.xiaopeng.operation.constant.I18nKeyConstant;
import com.xiaopeng.operation.dto.*;
import com.xiaopeng.operation.query.PricingPageListQuery;
import com.xiaopeng.operation.service.*;
import com.xiaopeng.operation.utils.ImageTagProcessor;
import com.xiaopeng.operation.vo.PricingPageListVO;
import com.xiaopeng.operation.vo.SaveOrderVo;
import com.xiaopeng.unifiedverification.interceptor.XpClientCheck;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
/**
*
* 费项管理 前端控制器
*
*
* @author mitao
* @since 2026-02-03
*/
@Slf4j
@RestController
@RequestMapping("")
@Api(tags = "费用管理")
public class XpPricingController extends BaseController {
private final XpPricingService xpPricingService;
private final IXpGeoQueryEntityService xpGeoQueryEntityService;
private final UserResourcesClient userResourcesClient;
private final IXpWhitelistService xpWhitelistService;
private final XpOpenCityService xpOpenCityService;
private final ImageTagProcessor imageTagProcessor;
public XpPricingController(XpPricingService xpPricingService, IXpGeoQueryEntityService xpGeoQueryEntityService, UserResourcesClient userResourcesClient, IXpWhitelistService xpWhitelistService, XpRegionService xpRegionService, XpOpenCityService xpOpenCityService, ImageTagProcessor imageTagProcessor) {
this.xpPricingService = xpPricingService;
this.xpGeoQueryEntityService = xpGeoQueryEntityService;
this.userResourcesClient = userResourcesClient;
this.xpWhitelistService = xpWhitelistService;
this.xpOpenCityService = xpOpenCityService;
this.imageTagProcessor = imageTagProcessor;
}
@PostMapping("/base/v1/mini-program/navigation/route-and-fare")
@ApiOperation(value = "导航-获取路线和费用(弃用)", tags = {"小程序-获取路线和费用(弃用)"}, response = RouteAndFareVo.class)
@XpClientCheck(checkToken = false, checkOtpToken = true)
public R getRouteAndFare(@RequestBody @Valid RouteAndFareDto routeAndFareDto, HttpServletRequest request) {
// uid已通过拦截器otp校验,可以直接使用
String uid = request.getHeader("XP-Uid");
return R.ok(xpPricingService.getRouteAndFare(routeAndFareDto, uid));
}
// 根据开通城市 获取定价
@GetMapping("/base/v1/mini-program/getPricingByCityId/{cityId}")
@XpClientCheck(checkToken = false, checkOtpToken = true)
public R getPricingByCityId(@PathVariable("cityId") Long cityId) {
XpPricing pricing = xpPricingService.lambdaQuery().eq(XpPricing::getCityId, cityId).last("limit 1").one();
return R.ok(pricing);
}
// 根据开通城市 获取定价
@GetMapping("/logan/inner/v1/getPricingByCid")
public R getPricingByCid(@RequestParam Long cityId,@RequestParam(required = false) String vehicleModelId) {
LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(XpPricing::getCityId, cityId);
if(null != vehicleModelId){
queryWrapper.eq(XpPricing::getVehicleModel, vehicleModelId);
}
XpPricing pricing = xpPricingService.getOne(queryWrapper);
return R.ok(pricing);
}
@GetMapping("/base/v1/mini-program/pricing/rules/{openCityId}")
@XpClientCheck(checkToken = false, checkOtpToken = true)
@ApiOperation(value = "获取费用规则(弃用)", tags = {"小程序-根据开通城市获取费用规则(弃用)"}, response = String.class)
public R> getPricingRules(@PathVariable Long openCityId) {
XpPricing xpPricing = xpPricingService.getOne(new LambdaQueryWrapper().eq(XpPricing::getCityId, openCityId).last("limit 1"));
if (xpPricing != null) {
return R.ok(xpPricing.getPriceRule());
}
return R.ok("");
}
/**
* 获取等待时间
* @param dto
* @return
*/
@PostMapping("/base/v1/mini-program/pricing/getWaitTime")
@XpClientCheck(checkToken = false, checkOtpToken = true)
@ApiOperation(value = "获取等待时间(弃用)", tags = {"小程序-获取等待时间(弃用)"}, response = Integer.class)
public R getWaitTime(@RequestBody LonLatDto dto) {
return R.ok(xpPricingService.getWaitTime(dto.getLongitude(), dto.getLatitude()));
}
/**
* 获取用户是否在白名单中
*/
@PostMapping("/base/v1/mini-program/pricing/isInWhiteList")
@ApiOperation(value = "获取用户是否在白名单中", tags = {"小程序-获取用户是否在白名单中"}, response = Boolean.class)
@XpClientCheck(checkToken = false, checkOtpToken = true)
public R isInWhiteList(HttpServletRequest request) {
String uid = request.getHeader("XP-Uid");
UcUserInfo baseUserByUid = userResourcesClient.getBaseUserByUid(uid);
if (baseUserByUid != null) {
try {
String phone = baseUserByUid.getMobile();
long count = xpWhitelistService.count(new LambdaQueryWrapper().eq(XpWhitelist::getAccount, phone).eq(XpWhitelist::getStatus, 1));
return R.ok(count > 0);
} catch (Exception e) {
log.error("获取用户信息失败: {}", e.getMessage());
return R.ok(false);
}
}
return R.ok(false);
}
/**
* 保存信息
* @param
* @return
*/
@PostMapping("/logan/inner/updateXpGeoQueryEntity")
public R> updateXpGeoQueryEntity(@RequestParam String orderId) {
xpGeoQueryEntityService.updateByOrderId(orderId);
return R.ok();
}
@PostMapping("/logan/inner/deleteXpGeoQueryEntity")
public R> deleteXpGeoQueryEntity(@RequestParam String orderId){
xpGeoQueryEntityService.deleteXpGeoQueryEntity(orderId);
return R.ok();
}
/**
* 播单
*/
@PostMapping("/base/v1/mini-program/order/save")
@ApiOperation(value = "保存订单(弃用)", tags = {"小程序-保存订单(弃用)"})
@XpClientCheck(checkToken = false, checkOtpToken = true)
public R saveOrder(@RequestBody @Validated XpOrderDto dto, HttpServletRequest request) {
String uid = request.getHeader("XP-Uid");
Long l = xpPricingService.saveOrder(dto, uid);
SaveOrderVo saveOrderVo = new SaveOrderVo();
saveOrderVo.setOrderId(l);
return R.ok(saveOrderVo);
}
@PostMapping("/api/v1/pricing/pageList")
@ApiOperation(value = "管理后台-定价管理分页列表", tags = {"管理后台-定价管理"})
public R> pageList(@RequestBody PricingPageListQuery query) {
return R.ok(xpPricingService.pageList(query));
}
@GetMapping("/api/v1/pricing/queryById")
@ApiOperation(value = "管理后台-定价管理-详情", tags = {"管理后台-定价管理"}, response = XpPricing.class)
public R queryById(@RequestParam Long id) {
XpPricing pricing = xpPricingService.getById(id);
if (pricing == null) {
throw new ServiceException("定价不存在", I18nKeyConstant.PRICING_NOT_EXIST);
}
//获取城市信息
String cityName = xpOpenCityService.getNameWithCityName(pricing.getCityId());
pricing.setCityName(cityName);
String priceRule = pricing.getPriceRule();
if (priceRule != null && priceRule.contains("
add(@Valid @RequestBody PricingAddDTO dto) {
return R.ok(xpPricingService.add(dto));
}
@PostMapping("/api/v1/pricing/edit")
@ApiOperation(value = "管理后台-编辑定价", tags = {"管理后台-定价管理"})
public R> edit(@Valid @RequestBody PricingEditDTO dto) {
return R.ok(xpPricingService.edit(dto));
}
@PostMapping("/api/v1/pricing/setPrice")
@ApiOperation(value = "管理后台-定价管理-设置价格", tags = {"管理后台-定价管理"})
public R> setPrice(@Valid @RequestBody PricingSetPriceDTO dto) {
xpPricingService.setPrice(dto);
return R.ok();
}
@PostMapping("/api/v1/pricing/setRule")
@ApiOperation(value = "管理后台-计费规则富文本配置", tags = {"管理后台-定价管理"})
public R> setRule(@Valid @RequestBody PricingSetRuleDTO dto) {
xpPricingService.setRule(dto);
return R.ok();
}
@DeleteMapping("/api/v1/pricing/deleteById")
@ApiOperation(value = "管理后台-定价管理-删除", tags = {"管理后台-定价管理"})
public R> deleteById(@RequestParam Long id) {
XpPricing pricing = xpPricingService.getById(id);
if (pricing == null) {
throw new ServiceException("定价不存在", I18nKeyConstant.PRICING_NOT_EXIST);
}
xpPricingService.removeById(id);
return R.ok();
}
}