StoreController.java 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. package com.yunzhi.inte.controller;
  2. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  3. import com.baomidou.mybatisplus.core.metadata.IPage;
  4. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  5. import com.yunzhi.inte.common.BaseController;
  6. import com.yunzhi.inte.common.ResponseBean;
  7. import java.util.List;
  8. import io.swagger.annotations.Api;
  9. import io.swagger.annotations.ApiOperation;
  10. import io.swagger.annotations.ApiParam;
  11. import org.springframework.beans.factory.annotation.Autowired;
  12. import org.springframework.web.bind.annotation.*;
  13. import com.yunzhi.inte.entity.Store;
  14. import com.yunzhi.inte.service.StoreService;
  15. /**
  16. * 库存表;(store)表控制层
  17. * @author : http://njyunzhi.com
  18. * @date : 2022-9-17
  19. */
  20. @Api(tags = "库存表对象功能接口")
  21. @RestController
  22. @RequestMapping("/")
  23. public class StoreController extends BaseController {
  24. @Autowired
  25. private StoreService storeService;
  26. /**
  27. * 通过ID查询单条数据
  28. *
  29. * @param id 主键
  30. * @return 实例对象
  31. */
  32. @ApiOperation("通过ID查询单条数据")
  33. @GetMapping("/store/{id}")
  34. public ResponseBean queryById(@ApiParam("对象ID") @PathVariable Integer id) throws Exception {
  35. return ResponseBean.success(storeService.getById(id));
  36. }
  37. /**
  38. * 分页查询
  39. *
  40. * @param pageNum 当前页码
  41. * @param pageSize 每页条数
  42. * @return 查询结果
  43. */
  44. @ApiOperation("分页查询")
  45. @GetMapping("/store")
  46. public ResponseBean list(@ApiParam("页码") @RequestParam(value ="pageNum",defaultValue = "1") Integer pageNum,
  47. @ApiParam("单页数据量") @RequestParam(value ="pageSize",defaultValue = "10") Integer pageSize) throws Exception {
  48. IPage<Store> pg = new Page<>(pageNum, pageSize);
  49. // QueryWrapper<Store> queryWrapper = new QueryWrapper<>();
  50. // queryWrapper.orderByDesc("create_date");
  51. IPage<Store> result = storeService.page(pg);
  52. return ResponseBean.success(result);
  53. }
  54. /**
  55. * 新增数据
  56. *
  57. * @param store 实例对象
  58. * @return 实例对象
  59. */
  60. @ApiOperation("新增数据")
  61. @PostMapping("/store")
  62. public ResponseBean add(Store store) throws Exception {
  63. storeService.save(store);
  64. return ResponseBean.success(store);
  65. }
  66. /**
  67. * 更新数据
  68. *
  69. * @param store 实例对象
  70. * @return 实例对象
  71. */
  72. @ApiOperation("更新数据")
  73. @PutMapping("/store/{id}")
  74. public ResponseBean edit(Store store) throws Exception {
  75. storeService.updateById(store);
  76. return ResponseBean.success(store);
  77. }
  78. /**
  79. * 通过主键删除数据
  80. *
  81. * @param id 主键
  82. * @return 是否成功
  83. */
  84. @ApiOperation("通过主键删除数据")
  85. @DeleteMapping("/store/{id}")
  86. public ResponseBean deleteById(@ApiParam("对象ID") @PathVariable Integer id){
  87. storeService.removeLogicById(id);
  88. return ResponseBean.success("success");
  89. }
  90. }