TFareSettingController.java 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. package com.ylx.web.controller.massage;
  2. import com.alibaba.fastjson.JSON;
  3. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  4. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  5. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  6. import com.ylx.common.core.controller.BaseController;
  7. import com.ylx.common.core.domain.R;
  8. import com.ylx.common.utils.StringUtils;
  9. import com.ylx.massage.domain.TFareSetting;
  10. import com.ylx.massage.domain.TFareFreeRule;
  11. import com.ylx.massage.domain.vo.DisableFareFreeRuleVo;
  12. import com.ylx.massage.domain.vo.FareFreeRuleVo;
  13. import com.ylx.massage.service.TFareSettingService;
  14. import com.ylx.massage.service.TFareFreeRuleService;
  15. import io.swagger.annotations.Api;
  16. import io.swagger.annotations.ApiOperation;
  17. import org.springframework.web.bind.annotation.*;
  18. import javax.annotation.Resource;
  19. import java.io.Serializable;
  20. import java.util.List;
  21. import java.util.Map;
  22. /**
  23. * 车费设置表(TFareSetting)控制层
  24. *
  25. * @author makejava
  26. * @since 2024-08-22 17:41:00
  27. */
  28. @RestController
  29. @Api(tags = {"车费设置"})
  30. @RequestMapping("tFareSetting")
  31. public class TFareSettingController extends BaseController {
  32. /**
  33. * 服务对象
  34. */
  35. @Resource
  36. private TFareSettingService tFareSettingService;
  37. /**
  38. * 免车费规则服务
  39. */
  40. @Resource
  41. private TFareFreeRuleService fareFreeRuleService;
  42. /**
  43. * 分页查询所有车费设置数据
  44. *
  45. * @param page 分页对象
  46. * @param tFareSetting 查询实体
  47. * @return R 所有数据
  48. */
  49. @GetMapping("selectAll")
  50. @ApiOperation("分页查询数据")
  51. public R selectAll(Page<TFareSetting> page, TFareSetting tFareSetting) {
  52. try {
  53. LambdaQueryWrapper<TFareSetting> queryWrapper = new LambdaQueryWrapper<>();
  54. // 城市编码查询
  55. if(StringUtils.isNotBlank(tFareSetting.getCityCode())){
  56. queryWrapper.like(TFareSetting::getCityCode, tFareSetting.getCityCode());
  57. }
  58. return R.ok(this.tFareSettingService.page(page, queryWrapper));
  59. } catch (Exception e) {
  60. e.printStackTrace();
  61. throw new RuntimeException(e);
  62. }
  63. }
  64. /**
  65. * 通过主键查询车费设置详情
  66. *
  67. * @param id 主键
  68. * @return 车费设置详情
  69. */
  70. @GetMapping("{id}")
  71. @ApiOperation("车费设置详情")
  72. public R selectOne(@PathVariable Serializable id) {
  73. try {
  74. return R.ok(this.tFareSettingService.getById(id));
  75. } catch (Exception e) {
  76. e.printStackTrace();
  77. throw new RuntimeException(e);
  78. }
  79. }
  80. /**
  81. * 新增车费设置数据
  82. *
  83. * @param tFareSetting 实体对象
  84. * @return R 新增结果
  85. */
  86. @PostMapping("add")
  87. @ApiOperation("新增数据")
  88. public R insert(@RequestBody TFareSetting tFareSetting) {
  89. try {
  90. return R.ok(this.tFareSettingService.add(tFareSetting));
  91. } catch (Exception e) {
  92. e.printStackTrace();
  93. throw new RuntimeException(e);
  94. }
  95. }
  96. /**
  97. * 修改车费设置数据
  98. *
  99. * @param tFareSetting 实体对象
  100. * @return R 修改结果
  101. */
  102. @PostMapping("update")
  103. @ApiOperation("修改车费设置数据")
  104. public R update(@RequestBody TFareSetting tFareSetting) {
  105. try {
  106. return R.ok(this.tFareSettingService.updateFareSetting(tFareSetting));
  107. } catch (Exception e) {
  108. e.printStackTrace();
  109. throw new RuntimeException(e);
  110. }
  111. }
  112. /**
  113. * 根据主键ID删除车费设置数据
  114. *
  115. * @param id 主键
  116. * @return R 删除结果
  117. */
  118. @DeleteMapping("delete/{id}")
  119. @ApiOperation("根据主键ID删除车费设置数据")
  120. public R delete(@PathVariable String id) {
  121. try {
  122. return R.ok(this.tFareSettingService.removeById(id));
  123. } catch (Exception e) {
  124. e.printStackTrace();
  125. throw new RuntimeException(e);
  126. }
  127. }
  128. /**
  129. * 批量删除车费设置数据
  130. *
  131. * @param idList 主键结合
  132. * @return R 删除结果
  133. */
  134. @PostMapping("delete")
  135. @ApiOperation("批量删除车费设置数据")
  136. public R delete(@RequestBody List<String> idList) {
  137. try {
  138. return R.ok(this.tFareSettingService.removeByIds(idList));
  139. } catch (Exception e) {
  140. e.printStackTrace();
  141. throw new RuntimeException(e);
  142. }
  143. }
  144. /**
  145. * 保存免车费规则(H5 技师端)
  146. * 支持新增和修改操作
  147. * - 如果传入id则修改
  148. * - 如果不传id则新增
  149. * <p>
  150. * 业务流程:
  151. * 1. 接收前端传递的免车费规则参数
  152. * 2. 调用服务层保存方法(自动判断新增或修改)
  153. * 3. 返回操作结果
  154. *
  155. * @param fareFreeRule 免车费规则(包含id则为修改,不包含则为新增)
  156. * @return R
  157. */
  158. @PostMapping("fareFreeRule/add")
  159. @ApiOperation("保存免车费规则(支持新增和修改)")
  160. public R saveFareFreeRule(@RequestBody TFareFreeRule fareFreeRule) {
  161. try {
  162. logger.info("保存免车费规则,前端传递的参数:{}", JSON.toJSONString(fareFreeRule));
  163. boolean success = fareFreeRuleService.saveFareFreeRule(fareFreeRule);
  164. // 根据是否包含id判断是新增还是修改
  165. String message = StringUtils.isNotBlank(fareFreeRule.getId()) ? "修改成功" : "新增成功";
  166. return success ? R.ok(message) : R.fail("操作失败");
  167. } catch (Exception e) {
  168. logger.error("保存免车费规则失败", e);
  169. return R.fail(e.getMessage());
  170. }
  171. }
  172. /**
  173. * 禁用(启用)免车费规则(H5 技师端)
  174. *
  175. * @param disableFareFreeRuleVo
  176. * @return R
  177. */
  178. @PostMapping("fareFreeRule/disable")
  179. @ApiOperation("禁用(启用)免车费规则")
  180. public R disableFareFreeRule(@RequestBody DisableFareFreeRuleVo disableFareFreeRuleVo) {
  181. try {
  182. boolean success = fareFreeRuleService.disableFareFreeRule(disableFareFreeRuleVo.getOpenId(), disableFareFreeRuleVo.getEnable());
  183. return success ? R.ok() : R.fail("操作失败");
  184. } catch (Exception e) {
  185. e.printStackTrace();
  186. return R.fail(e.getMessage());
  187. }
  188. }
  189. /**
  190. * 查询免车费规则列表
  191. *
  192. * @param openId 技师OpenID
  193. * @return R
  194. */
  195. @GetMapping("fareFreeRule/list")
  196. @ApiOperation("查询免车费规则列表")
  197. public R listFareFreeRules(@RequestParam String openId) {
  198. try {
  199. FareFreeRuleVo fareFreeRuleVo = fareFreeRuleService.listFareFreeRules(openId);
  200. return R.ok(fareFreeRuleVo);
  201. } catch (Exception e) {
  202. e.printStackTrace();
  203. return R.fail(e.getMessage());
  204. }
  205. }
  206. /**
  207. * 删除免车费规则
  208. *
  209. * @param idList 规则ID列表
  210. * @return R
  211. */
  212. @PostMapping("fareFreeRule/delete")
  213. @ApiOperation("删除免车费规则")
  214. public R deleteFareFreeRule(@RequestBody List<String> idList) {
  215. try {
  216. boolean success = fareFreeRuleService.removeByIds(idList);
  217. return success ? R.ok("删除成功") : R.fail("删除失败");
  218. } catch (Exception e) {
  219. return R.fail(e.getMessage());
  220. }
  221. }
  222. }