TLbtController.java 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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.annotation.Log;
  7. import com.ylx.common.core.domain.R;
  8. import com.ylx.common.enums.BusinessType;
  9. import com.ylx.common.exception.ServiceException;
  10. import com.ylx.massage.domain.TLbt;
  11. import com.ylx.massage.service.TLbtService;
  12. import io.swagger.annotations.Api;
  13. import io.swagger.annotations.ApiOperation;
  14. import lombok.extern.slf4j.Slf4j;
  15. import org.apache.commons.lang3.StringUtils;
  16. import org.springframework.web.bind.annotation.RequestBody;
  17. import org.springframework.web.bind.annotation.RequestMapping;
  18. import org.springframework.web.bind.annotation.RequestMethod;
  19. import org.springframework.web.bind.annotation.RestController;
  20. import javax.annotation.Resource;
  21. import java.util.List;
  22. /**
  23. * 轮播图 前端控制器
  24. */
  25. @RestController
  26. @RequestMapping("/api/lbt/v1")
  27. @Slf4j
  28. @Api(tags = {"轮播图管理"})
  29. public class TLbtController {
  30. @Resource
  31. private TLbtService lbtService;
  32. /**
  33. * 获取轮播图
  34. *
  35. * @return R<List<TLbt>>
  36. */
  37. @ApiOperation("获取轮播图")
  38. @RequestMapping(value = "/getAll", method = RequestMethod.GET)
  39. public R<List<TLbt>> getAll() {
  40. try {
  41. QueryWrapper<TLbt> wrapper = new QueryWrapper<>();
  42. wrapper.lambda().orderByAsc(TLbt::getCSort);
  43. List<TLbt> list = lbtService.list(wrapper);
  44. return R.ok(list);
  45. } catch (Exception e) {
  46. e.printStackTrace();
  47. throw new RuntimeException(e);
  48. }
  49. }
  50. /**
  51. * 添加或者更新轮播图
  52. *
  53. * @param lbt
  54. * @return R
  55. */
  56. @Log(title = "轮播图管理", businessType = BusinessType.INSERT)
  57. @RequestMapping(value = "/addOrUpdate", method = RequestMethod.POST)
  58. @ApiOperation("添加或者更新轮播图")
  59. public R addOrUpdate(@RequestBody TLbt lbt) {
  60. try {
  61. log.info("请求参数:{}", JSON.toJSONString(lbt));
  62. return R.ok(lbtService.addOrUpdate(lbt));
  63. } catch (ServiceException s) {
  64. log.error(s.toString());
  65. return R.fail(s.getMessage());
  66. } catch (Exception e) {
  67. log.error(e.toString());
  68. return R.fail("系统异常");
  69. }
  70. }
  71. /**
  72. * 分页查询轮播图数据
  73. * @param page
  74. * @param lbt
  75. * @return R<Page<TLbt>>
  76. */
  77. @ApiOperation("分页查询数据")
  78. @RequestMapping(value = "/select", method = RequestMethod.GET)
  79. public R<Page<TLbt>> selectSpfl(Page<TLbt> page, TLbt lbt) {
  80. try {
  81. LambdaQueryWrapper<TLbt> tLbtLambdaQueryWrapper = new LambdaQueryWrapper<>();
  82. tLbtLambdaQueryWrapper.like(StringUtils.isNotBlank(lbt.getCDescribe()), TLbt::getCDescribe, lbt.getCDescribe())
  83. .orderByAsc(TLbt::getCSort);
  84. // 获取查询返回结果
  85. Page<TLbt> pageSelect = lbtService.page(page, tLbtLambdaQueryWrapper);
  86. return R.ok(pageSelect);
  87. } catch (Exception e) {
  88. e.printStackTrace();
  89. throw new RuntimeException(e);
  90. }
  91. }
  92. /**
  93. * 删除轮播图
  94. *
  95. * @param tLbt
  96. * @return R
  97. */
  98. @Log(title = "轮播图管理", businessType = BusinessType.DELETE)
  99. @RequestMapping(value = "/del", method = RequestMethod.POST)
  100. @ApiOperation("删除轮播图")
  101. public R del(@RequestBody TLbt tLbt) {
  102. try {
  103. return R.ok(lbtService.del(tLbt));
  104. } catch (ServiceException s) {
  105. log.error(s.toString());
  106. return R.fail(s.getMessage());
  107. } catch (Exception e) {
  108. log.error(e.toString());
  109. return R.fail("系统异常");
  110. }
  111. }
  112. /**
  113. * 根据id查询轮播图
  114. *
  115. * @param tLbt
  116. * @return R
  117. */
  118. @ApiOperation("根据id查询轮播图")
  119. @RequestMapping(value = "/wx/getByid", method = RequestMethod.POST)
  120. public R getById(@RequestBody TLbt tLbt) {
  121. return R.ok(lbtService.getById(tLbt.getCId()));
  122. }
  123. }