AppBannerController.java 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. package com.txz.mall.controller.appcontroller;
  2. import com.github.pagehelper.PageHelper;
  3. import com.github.pagehelper.PageInfo;
  4. import com.txz.mall.core.Result;
  5. import com.txz.mall.core.ResultCode;
  6. import com.txz.mall.model.Banner;
  7. import com.txz.mall.service.BannerService;
  8. import com.txz.mall.web.param.BannerParam;
  9. import io.swagger.annotations.Api;
  10. import io.swagger.annotations.ApiOperation;
  11. import org.slf4j.Logger;
  12. import org.slf4j.LoggerFactory;
  13. import org.springframework.web.bind.annotation.*;
  14. import tk.mybatis.mapper.entity.Condition;
  15. import tk.mybatis.mapper.entity.Example.Criteria;
  16. import javax.annotation.Resource;
  17. import java.util.Date;
  18. import java.util.List;
  19. /**
  20. * Created by CodeGenerator on 2025/08/05.
  21. */
  22. @Api(tags = "app轮播图管理")
  23. @RestController
  24. @RequestMapping("/app/banner")
  25. public class AppBannerController {
  26. private static Logger log = LoggerFactory.getLogger(AppBannerController.class);
  27. @Resource
  28. private BannerService bannerService;
  29. // @PostMapping("/add")
  30. // @ApiOperation(value = "轮播图新增")
  31. // public Result add(@RequestBody Banner banner) {
  32. // if (banner == null) {
  33. // return Result.fail(ResultCode.OBJECT_IS_NULL);
  34. // }
  35. // try {
  36. // banner.setCreateTime(new Date());
  37. //// banner.setCreateUserId(userId);
  38. // bannerService.save(banner);
  39. // } catch (Exception e) {
  40. // log.error("新增对象操作异常e:{}", e);
  41. // return Result.fail(ResultCode.INTERNAL_SERVER_ERROR);
  42. // }
  43. // return Result.success();
  44. // }
  45. //
  46. // @DeleteMapping("/delete")
  47. // @ApiOperation(value = "轮播图删除")
  48. // public Result delete(@RequestParam Long id) {
  49. // if (id == null) {
  50. // return Result.fail(ResultCode.ID_IS_NULL);
  51. // }
  52. // try {
  53. // Banner banner = new Banner();
  54. // banner.setId(id);
  55. // banner.setIsDelete(1);
  56. // bannerService.update(banner);
  57. // } catch (Exception e) {
  58. // log.error("删除对象操作异常e:{}", e);
  59. // return Result.fail(ResultCode.INTERNAL_SERVER_ERROR);
  60. // }
  61. // return Result.success();
  62. // }
  63. //
  64. // @PutMapping("/update")
  65. // @ApiOperation(value = "轮播图更新")
  66. // public Result update(@RequestBody Banner banner) {
  67. // if (banner == null) {
  68. // return Result.fail(ResultCode.OBJECT_IS_NULL);
  69. // }
  70. // if (banner.getId() == null) {
  71. // return Result.fail(ResultCode.ID_IS_NULL);
  72. // }
  73. // try {
  74. // banner.setUpdateTime(new Date());
  75. //// banner.setUpdateUserId(userId);
  76. // bannerService.update(banner);
  77. // } catch (Exception e) {
  78. // log.error("更新对象操作异常e:{}", e);
  79. // return Result.fail(ResultCode.INTERNAL_SERVER_ERROR);
  80. // }
  81. // return Result.success();
  82. // }
  83. @GetMapping("/detail")
  84. @ApiOperation(value = "轮播图获取详情")
  85. public Result<Banner> detail(@RequestParam Long id) {
  86. if (id == null) {
  87. return Result.fail(ResultCode.ID_IS_NULL);
  88. }
  89. Banner banner = null;
  90. try {
  91. banner = bannerService.findById(id);
  92. } catch (Exception e) {
  93. log.error("查询对象操作异常e:{}", e);
  94. return Result.fail(ResultCode.INTERNAL_SERVER_ERROR);
  95. }
  96. return Result.success(banner);
  97. }
  98. @PostMapping("/list")
  99. @ApiOperation(value = "轮播图获取列表")
  100. public Result<List<Banner>> list(@RequestBody BannerParam banner) {
  101. PageHelper.startPage(banner.getPage(), banner.getSize());
  102. Condition condition = new Condition(Banner.class);
  103. Criteria criteria = condition.createCriteria();
  104. criteria.andEqualTo("isDelete", 0);
  105. condition.setOrderByClause("create_time DESC");
  106. PageInfo pageInfo = null;
  107. try {
  108. List<Banner> list = bannerService.findByCondition(condition);
  109. pageInfo = new PageInfo(list);
  110. } catch (Exception e) {
  111. log.error("查询对象操作异常e:{}", e);
  112. return Result.fail(ResultCode.INTERNAL_SERVER_ERROR);
  113. }
  114. return Result.success(pageInfo);
  115. }
  116. }