GoodsController.java 4.8 KB

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