241 lines
8.3 KiB
Java
241 lines
8.3 KiB
Java
package com.cdzy.operations.controller;
|
|
|
|
import cn.dev33.satoken.stp.StpUtil;
|
|
import com.cdzy.common.ex.EbikeException;
|
|
import com.cdzy.common.model.request.PageParam;
|
|
import com.cdzy.common.model.response.JsonResult;
|
|
import com.cdzy.operations.enums.RegionStatus;
|
|
import com.cdzy.operations.model.dto.EbikeSpecialBillingConfigurationDto;
|
|
import com.cdzy.operations.model.entity.EbikeDefaultBillingConfiguration;
|
|
import com.cdzy.operations.model.entity.EbikeRegion;
|
|
import com.cdzy.operations.model.vo.EbikeDefaultBillingConfigurationVo;
|
|
import com.cdzy.operations.model.vo.EbikeOperationConfigVo;
|
|
import com.cdzy.operations.model.vo.EbikeRegionVo;
|
|
import com.cdzy.operations.model.vo.EbikeSpecialBillingConfigurationVo;
|
|
import com.cdzy.operations.service.EbikeDefaultBillingConfigurationService;
|
|
import com.cdzy.operations.service.EbikeRegionService;
|
|
import com.cdzy.operations.service.EbikeSpecialBillingConfigurationService;
|
|
import com.mybatisflex.core.paginate.Page;
|
|
import com.mybatisflex.core.query.QueryWrapper;
|
|
import com.mybatisflex.core.update.UpdateChain;
|
|
import com.mybatisflex.core.util.StringUtil;
|
|
import jakarta.annotation.Resource;
|
|
import org.springframework.validation.annotation.Validated;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
import java.util.List;
|
|
|
|
import static com.cdzy.operations.model.entity.table.EbikeDefaultBillingConfigurationTableDef.EBIKE_DEFAULT_BILLING_CONFIGURATION;
|
|
import static com.cdzy.operations.model.entity.table.EbikeRegionTableDef.EBIKE_REGION;
|
|
|
|
/**
|
|
* 运营区域表 控制层。
|
|
*
|
|
* @author attiya
|
|
* @since 2025-10-22
|
|
*/
|
|
@RestController
|
|
@RequestMapping("/ebikeRegion")
|
|
@Validated
|
|
public class EbikeRegionController {
|
|
|
|
@Resource
|
|
private EbikeRegionService ebikeRegionService;
|
|
|
|
@Resource
|
|
private EbikeDefaultBillingConfigurationService defaultConfigurationService;
|
|
|
|
@Resource
|
|
private EbikeSpecialBillingConfigurationService specialBillingConfigurationService;
|
|
|
|
/**
|
|
* 添加运营区域。
|
|
*
|
|
* @param ebikeRegion 运营区域
|
|
* @return {@code true} 添加成功,{@code false} 添加失败
|
|
*/
|
|
@PostMapping("save")
|
|
public JsonResult<?> save(@Validated @RequestBody EbikeRegionVo ebikeRegion) {
|
|
ebikeRegionService.save(ebikeRegion);
|
|
return JsonResult.success();
|
|
}
|
|
|
|
/**
|
|
* 根据主键删除运营区域表。
|
|
*
|
|
* @param regionId 主键
|
|
* @return {@code true} 删除成功,{@code false} 删除失败
|
|
*/
|
|
@GetMapping("remove")
|
|
public JsonResult<?> remove(@Validated @RequestParam Long regionId) {
|
|
ebikeRegionService.removeById(regionId);
|
|
return JsonResult.success();
|
|
}
|
|
|
|
/**
|
|
* 根据主键更新运营区域表。
|
|
*
|
|
* @param ebikeRegion 运营区域表
|
|
* @return {@code true} 更新成功,{@code false} 更新失败
|
|
*/
|
|
@PostMapping("update")
|
|
public JsonResult<?> update(@RequestBody EbikeRegionVo ebikeRegion) {
|
|
ebikeRegionService.update(ebikeRegion);
|
|
return JsonResult.success();
|
|
}
|
|
|
|
/**
|
|
* 查询所有运营区域表。
|
|
*
|
|
* @return 所有数据
|
|
*/
|
|
@GetMapping("list")
|
|
public JsonResult<?> list() {
|
|
List<EbikeRegion> list = ebikeRegionService.list();
|
|
return JsonResult.success(list);
|
|
}
|
|
|
|
/**
|
|
* 根据运营区域表主键获取详细信息。
|
|
*
|
|
* @param regionId 运营区域表主键
|
|
* @return 运营区域表详情
|
|
*/
|
|
@GetMapping("getInfo")
|
|
public JsonResult<?> getInfo(@RequestParam Long regionId) {
|
|
EbikeRegion ebikeRegion = ebikeRegionService.getById(regionId);
|
|
return JsonResult.success(ebikeRegion);
|
|
}
|
|
|
|
/**
|
|
* 分页查询运营区域表。
|
|
*
|
|
* @param pageParam 分页对象
|
|
* @param regionName 运营区名称
|
|
* @param regionSimpleName 运营区简称
|
|
* @return 分页对象
|
|
*/
|
|
@GetMapping("page")
|
|
public JsonResult<?> page(PageParam pageParam, String regionName, String regionSimpleName) {
|
|
QueryWrapper queryWrapper = QueryWrapper.create()
|
|
.where(EBIKE_REGION.REGION_NAME.like(regionName, StringUtil.hasText(regionName)))
|
|
.where(EBIKE_REGION.REGION_SIMPLE_NAME.like(regionSimpleName, StringUtil.hasText(regionSimpleName)));
|
|
Page<EbikeRegion> page = ebikeRegionService.page(pageParam.getPage(), queryWrapper);
|
|
return JsonResult.success(page);
|
|
}
|
|
|
|
|
|
/**
|
|
* 开始运营。
|
|
*
|
|
* @param regionId 运营区主键
|
|
* @return 分页对象
|
|
*/
|
|
@GetMapping("commenceOperation")
|
|
public JsonResult<?> commenceOperation(@RequestParam Long regionId) {
|
|
QueryWrapper queryWrapper = QueryWrapper.create()
|
|
.where(EBIKE_DEFAULT_BILLING_CONFIGURATION.REGION_ID.eq(regionId));
|
|
EbikeDefaultBillingConfiguration configuration = defaultConfigurationService.getOne(queryWrapper);
|
|
if (configuration == null) {
|
|
throw new EbikeException("请配置计费规则后再开始运营");
|
|
}
|
|
UpdateChain.of(EbikeRegion.class)
|
|
.where(EbikeRegion::getRegionId).eq(regionId)
|
|
.set(EBIKE_REGION.STATUS, RegionStatus.OPERATION)
|
|
.set(EBIKE_REGION.UPDATED_BY, StpUtil.getLoginIdAsLong())
|
|
.update();
|
|
return JsonResult.success();
|
|
}
|
|
|
|
/**
|
|
* 结束运营。
|
|
*
|
|
* @param regionId 运营区主键
|
|
* @return 分页对象
|
|
*/
|
|
@GetMapping("stopOperation")
|
|
public JsonResult<?> stopOperation(@RequestParam Long regionId) {
|
|
UpdateChain.of(EbikeRegion.class)
|
|
.where(EbikeRegion::getRegionId).eq(regionId)
|
|
.set(EBIKE_REGION.STATUS, RegionStatus.STOP_OPERATION)
|
|
.set(EBIKE_REGION.UPDATED_BY, StpUtil.getLoginIdAsLong())
|
|
.update();
|
|
return JsonResult.success();
|
|
}
|
|
|
|
/**
|
|
* 保存运营区默认计费规则。
|
|
*
|
|
* @param configurationVo 配置信息
|
|
* @return 分页对象
|
|
*/
|
|
@PostMapping("defaultConfiguration")
|
|
public JsonResult<?> defaultConfiguration(@Validated @RequestBody EbikeDefaultBillingConfigurationVo configurationVo) {
|
|
defaultConfigurationService.defaultConfiguration(configurationVo);
|
|
return JsonResult.success();
|
|
}
|
|
|
|
/**
|
|
* 获取运营区默认计费规则。
|
|
*
|
|
* @param regionId 区域ID
|
|
* @return 分页对象
|
|
*/
|
|
@GetMapping("getDefaultConfiguration")
|
|
public JsonResult<?> getDefaultConfiguration(@RequestParam Long regionId) {
|
|
QueryWrapper queryWrapper = QueryWrapper.create()
|
|
.where(EBIKE_DEFAULT_BILLING_CONFIGURATION.REGION_ID.eq(regionId));
|
|
EbikeDefaultBillingConfiguration configuration = defaultConfigurationService.getOne(queryWrapper);
|
|
return JsonResult.success(configuration);
|
|
}
|
|
|
|
|
|
/**
|
|
* 保存运营区高峰计费规则。
|
|
*
|
|
* @param configurationVo 配置信息
|
|
* @return 分页对象
|
|
*/
|
|
@PostMapping("specialConfiguration")
|
|
public JsonResult<?> specialConfiguration(@Validated @RequestBody EbikeSpecialBillingConfigurationVo configurationVo) {
|
|
specialBillingConfigurationService.specialConfiguration(configurationVo);
|
|
return JsonResult.success();
|
|
}
|
|
|
|
/**
|
|
* 获取运营区高峰计费规则。
|
|
*
|
|
* @param regionId 区域ID
|
|
* @return 分页对象
|
|
*/
|
|
@GetMapping("getSpecialConfiguration")
|
|
public JsonResult<?> getSpecialConfiguration(@RequestParam Long regionId) {
|
|
EbikeSpecialBillingConfigurationDto configuration = specialBillingConfigurationService.info(regionId);
|
|
return JsonResult.success(configuration);
|
|
}
|
|
|
|
/**
|
|
* 保存运营配置。
|
|
*
|
|
* @param configurationVo 配置信息
|
|
* @return 分页对象
|
|
*/
|
|
@PostMapping("operationConfiguration")
|
|
public JsonResult<?> operationConfiguration(@Validated @RequestBody EbikeOperationConfigVo configurationVo) {
|
|
ebikeRegionService.operationConfiguration(configurationVo);
|
|
return JsonResult.success();
|
|
}
|
|
|
|
/**
|
|
* 获取运营配置。
|
|
*
|
|
* @param regionId 区域ID
|
|
* @return 分页对象
|
|
*/
|
|
@GetMapping("getOperationConfiguration")
|
|
public JsonResult<?> getOperationConfiguration(@RequestParam Long regionId) {
|
|
EbikeOperationConfigVo configuration = ebikeRegionService.getOperationConfiguration(regionId);
|
|
return JsonResult.success(configuration);
|
|
}
|
|
}
|