GoodsController.java 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. package com.kmall.admin.controller;
  2. import com.kmall.admin.entity.GoodsEntity;
  3. import com.kmall.admin.service.GoodsService;
  4. import com.kmall.common.utils.PageUtils;
  5. import com.kmall.common.utils.Query;
  6. import com.kmall.common.utils.R;
  7. import org.apache.shiro.authz.annotation.RequiresPermissions;
  8. import org.springframework.beans.factory.annotation.Autowired;
  9. import org.springframework.web.bind.annotation.*;
  10. import org.springframework.web.multipart.MultipartFile;
  11. import java.util.List;
  12. import java.util.Map;
  13. /**
  14. * Controller
  15. *
  16. * @author Scott
  17. * @email
  18. * @date 2017-08-21 21:19:49
  19. */
  20. @RestController
  21. @RequestMapping("goods")
  22. public class GoodsController {
  23. @Autowired
  24. private GoodsService goodsService;
  25. /**
  26. * 查看列表
  27. */
  28. @RequestMapping("/list")
  29. @RequiresPermissions("goods:list")
  30. public R list(@RequestParam Map<String, Object> params) {
  31. //查询列表数据
  32. Query query = new Query(params);
  33. query.put("isDelete", 0);
  34. List<GoodsEntity> goodsList = goodsService.queryList(query);
  35. int total = goodsService.queryTotal(query);
  36. PageUtils pageUtil = new PageUtils(goodsList, total, query.getLimit(), query.getPage());
  37. return R.ok().put("page", pageUtil);
  38. }
  39. /**
  40. * 查看信息
  41. */
  42. @RequestMapping("/info/{id}")
  43. @RequiresPermissions("goods:info")
  44. public R info(@PathVariable("id") Integer id) {
  45. GoodsEntity goods = goodsService.queryObject(id);
  46. return R.ok().put("goods", goods);
  47. }
  48. /**
  49. * 保存
  50. */
  51. @RequestMapping("/save")
  52. @RequiresPermissions("goods:save")
  53. public R save(@RequestBody GoodsEntity goods) {
  54. goodsService.save(goods);
  55. return R.ok();
  56. }
  57. /**
  58. * 修改
  59. */
  60. @RequestMapping("/update")
  61. @RequiresPermissions("goods:update")
  62. public R update(@RequestBody GoodsEntity goods) {
  63. goodsService.update(goods);
  64. return R.ok();
  65. }
  66. /**
  67. * 删除
  68. */
  69. @RequestMapping("/delete")
  70. @RequiresPermissions("goods:delete")
  71. public R delete(@RequestBody Integer[] ids) {
  72. goodsService.deleteBatch(ids);
  73. return R.ok();
  74. }
  75. /**
  76. * 查看所有列表
  77. */
  78. @RequestMapping("/queryAll")
  79. public R queryAll(@RequestParam Map<String, Object> params) {
  80. params.put("isDelete", 0);
  81. List<GoodsEntity> list = goodsService.queryList(params);
  82. return R.ok().put("list", list);
  83. }
  84. /**
  85. * 商品回收站
  86. *
  87. * @param params
  88. * @return
  89. */
  90. @RequestMapping("/historyList")
  91. public R historyList(@RequestParam Map<String, Object> params) {
  92. //查询列表数据
  93. Query query = new Query(params);
  94. query.put("isDelete", 1);
  95. List<GoodsEntity> goodsList = goodsService.queryList(query);
  96. int total = goodsService.queryTotal(query);
  97. PageUtils pageUtil = new PageUtils(goodsList, total, query.getLimit(), query.getPage());
  98. return R.ok().put("page", pageUtil);
  99. }
  100. /**
  101. * 商品从回收站恢复
  102. */
  103. @RequestMapping("/back")
  104. @RequiresPermissions("goods:back")
  105. public R back(@RequestBody Integer[] ids) {
  106. goodsService.back(ids);
  107. return R.ok();
  108. }
  109. /**
  110. * 总计
  111. */
  112. @RequestMapping("/queryTotal")
  113. public R queryTotal(@RequestParam Map<String, Object> params) {
  114. params.put("isDelete", 0);
  115. int sum = goodsService.queryTotal(params);
  116. return R.ok().put("goodsSum", sum);
  117. }
  118. /**
  119. * 上架
  120. */
  121. @RequestMapping("/enSale")
  122. public R enSale(@RequestBody Integer id) {
  123. goodsService.enSale(id);
  124. return R.ok();
  125. }
  126. /**
  127. * 上架
  128. */
  129. @RequestMapping("/enSaleBatch")
  130. public R enSaleBatch(@RequestBody Integer[] ids) {
  131. goodsService.enSaleBatch(ids);
  132. return R.ok();
  133. }
  134. /**
  135. * 下架
  136. */
  137. @RequestMapping("/unSale")
  138. public R unSale(@RequestBody Integer id) {
  139. goodsService.unSale(id);
  140. return R.ok();
  141. }
  142. /**
  143. * 下架
  144. */
  145. @RequestMapping("/unSaleBatch")
  146. public R unSaleBatch(@RequestBody Integer[] ids) {
  147. goodsService.unSaleBatch(ids);
  148. return R.ok();
  149. }
  150. /**
  151. * 上传文件
  152. */
  153. @RequestMapping("/upload")
  154. public R upload(@RequestParam("file") MultipartFile file) throws Exception {
  155. goodsService.uploadExcel(file);
  156. //上传文件
  157. return R.ok();
  158. }
  159. }