| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243 |
- package com.ylx.web.controller.massage;
- import com.alibaba.fastjson.JSON;
- import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
- import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
- import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
- import com.ylx.common.core.controller.BaseController;
- import com.ylx.common.core.domain.R;
- import com.ylx.common.utils.StringUtils;
- import com.ylx.massage.domain.TFareSetting;
- import com.ylx.massage.domain.TFareFreeRule;
- import com.ylx.massage.domain.vo.DisableFareFreeRuleVo;
- import com.ylx.massage.domain.vo.FareFreeRuleVo;
- import com.ylx.massage.service.TFareSettingService;
- import com.ylx.massage.service.TFareFreeRuleService;
- import io.swagger.annotations.Api;
- import io.swagger.annotations.ApiOperation;
- import org.springframework.web.bind.annotation.*;
- import javax.annotation.Resource;
- import java.io.Serializable;
- import java.util.List;
- import java.util.Map;
- /**
- * 车费设置表(TFareSetting)控制层
- *
- * @author makejava
- * @since 2024-08-22 17:41:00
- */
- @RestController
- @Api(tags = {"车费设置"})
- @RequestMapping("tFareSetting")
- public class TFareSettingController extends BaseController {
- /**
- * 服务对象
- */
- @Resource
- private TFareSettingService tFareSettingService;
- /**
- * 免车费规则服务
- */
- @Resource
- private TFareFreeRuleService fareFreeRuleService;
- /**
- * 分页查询所有车费设置数据
- *
- * @param page 分页对象
- * @param tFareSetting 查询实体
- * @return R 所有数据
- */
- @GetMapping("selectAll")
- @ApiOperation("分页查询数据")
- public R selectAll(Page<TFareSetting> page, TFareSetting tFareSetting) {
- try {
- LambdaQueryWrapper<TFareSetting> queryWrapper = new LambdaQueryWrapper<>();
- // 城市编码查询
- if(StringUtils.isNotBlank(tFareSetting.getCityCode())){
- queryWrapper.like(TFareSetting::getCityCode, tFareSetting.getCityCode());
- }
- return R.ok(this.tFareSettingService.page(page, queryWrapper));
- } catch (Exception e) {
- e.printStackTrace();
- throw new RuntimeException(e);
- }
- }
- /**
- * 通过主键查询车费设置详情
- *
- * @param id 主键
- * @return 车费设置详情
- */
- @GetMapping("{id}")
- @ApiOperation("车费设置详情")
- public R selectOne(@PathVariable Serializable id) {
- try {
- return R.ok(this.tFareSettingService.getById(id));
- } catch (Exception e) {
- e.printStackTrace();
- throw new RuntimeException(e);
- }
- }
- /**
- * 新增车费设置数据
- *
- * @param tFareSetting 实体对象
- * @return R 新增结果
- */
- @PostMapping("add")
- @ApiOperation("新增数据")
- public R insert(@RequestBody TFareSetting tFareSetting) {
- try {
- return R.ok(this.tFareSettingService.add(tFareSetting));
- } catch (Exception e) {
- e.printStackTrace();
- throw new RuntimeException(e);
- }
- }
- /**
- * 修改车费设置数据
- *
- * @param tFareSetting 实体对象
- * @return R 修改结果
- */
- @PostMapping("update")
- @ApiOperation("修改车费设置数据")
- public R update(@RequestBody TFareSetting tFareSetting) {
- try {
- return R.ok(this.tFareSettingService.updateFareSetting(tFareSetting));
- } catch (Exception e) {
- e.printStackTrace();
- throw new RuntimeException(e);
- }
- }
- /**
- * 根据主键ID删除车费设置数据
- *
- * @param id 主键
- * @return R 删除结果
- */
- @DeleteMapping("delete/{id}")
- @ApiOperation("根据主键ID删除车费设置数据")
- public R delete(@PathVariable String id) {
- try {
- return R.ok(this.tFareSettingService.removeById(id));
- } catch (Exception e) {
- e.printStackTrace();
- throw new RuntimeException(e);
- }
- }
- /**
- * 批量删除车费设置数据
- *
- * @param idList 主键结合
- * @return R 删除结果
- */
- @PostMapping("delete")
- @ApiOperation("批量删除车费设置数据")
- public R delete(@RequestBody List<String> idList) {
- try {
- return R.ok(this.tFareSettingService.removeByIds(idList));
- } catch (Exception e) {
- e.printStackTrace();
- throw new RuntimeException(e);
- }
- }
- /**
- * 保存免车费规则(H5 技师端)
- * 支持新增和修改操作
- * - 如果传入id则修改
- * - 如果不传id则新增
- * <p>
- * 业务流程:
- * 1. 接收前端传递的免车费规则参数
- * 2. 调用服务层保存方法(自动判断新增或修改)
- * 3. 返回操作结果
- *
- * @param fareFreeRule 免车费规则(包含id则为修改,不包含则为新增)
- * @return R
- */
- @PostMapping("fareFreeRule/add")
- @ApiOperation("保存免车费规则(支持新增和修改)")
- public R saveFareFreeRule(@RequestBody TFareFreeRule fareFreeRule) {
- try {
- logger.info("保存免车费规则,前端传递的参数:{}", JSON.toJSONString(fareFreeRule));
- boolean success = fareFreeRuleService.saveFareFreeRule(fareFreeRule);
- // 根据是否包含id判断是新增还是修改
- String message = StringUtils.isNotBlank(fareFreeRule.getId()) ? "修改成功" : "新增成功";
- return success ? R.ok(message) : R.fail("操作失败");
- } catch (Exception e) {
- logger.error("保存免车费规则失败", e);
- return R.fail(e.getMessage());
- }
- }
- /**
- * 禁用(启用)免车费规则(H5 技师端)
- *
- * @param disableFareFreeRuleVo
- * @return R
- */
- @PostMapping("fareFreeRule/disable")
- @ApiOperation("禁用(启用)免车费规则")
- public R disableFareFreeRule(@RequestBody DisableFareFreeRuleVo disableFareFreeRuleVo) {
- try {
- boolean success = fareFreeRuleService.disableFareFreeRule(disableFareFreeRuleVo.getOpenId(), disableFareFreeRuleVo.getEnable());
- return success ? R.ok() : R.fail("操作失败");
- } catch (Exception e) {
- e.printStackTrace();
- return R.fail(e.getMessage());
- }
- }
- /**
- * 查询免车费规则列表
- *
- * @param openId 技师OpenID
- * @return R
- */
- @GetMapping("fareFreeRule/list")
- @ApiOperation("查询免车费规则列表")
- public R listFareFreeRules(@RequestParam String openId) {
- try {
- FareFreeRuleVo fareFreeRuleVo = fareFreeRuleService.listFareFreeRules(openId);
- return R.ok(fareFreeRuleVo);
- } catch (Exception e) {
- e.printStackTrace();
- return R.fail(e.getMessage());
- }
- }
- /**
- * 删除免车费规则
- *
- * @param idList 规则ID列表
- * @return R
- */
- @PostMapping("fareFreeRule/delete")
- @ApiOperation("删除免车费规则")
- public R deleteFareFreeRule(@RequestBody List<String> idList) {
- try {
- boolean success = fareFreeRuleService.removeByIds(idList);
- return success ? R.ok("删除成功") : R.fail("删除失败");
- } catch (Exception e) {
- return R.fail(e.getMessage());
- }
- }
- }
|