GoodsController.java 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. package com.kmall.admin.controller;
  2. import com.kmall.admin.dto.GoodsDto;
  3. import com.kmall.admin.entity.GoodsEntity;
  4. import com.kmall.admin.entity.GoodsGalleryEntity;
  5. import com.kmall.admin.service.GoodsGalleryService;
  6. import com.kmall.admin.service.GoodsService;
  7. import com.kmall.admin.service.OfflineCartService;
  8. import com.kmall.common.constant.JxlsXmlTemplateName;
  9. import com.kmall.common.entity.SysUserEntity;
  10. import com.kmall.common.utils.PageUtils;
  11. import com.kmall.common.utils.Query;
  12. import com.kmall.common.utils.R;
  13. import com.kmall.common.utils.ShiroUtils;
  14. import com.kmall.common.utils.excel.ExcelUtil;
  15. import org.apache.shiro.authz.annotation.RequiresPermissions;
  16. import org.springframework.beans.factory.annotation.Autowired;
  17. import org.springframework.web.bind.annotation.*;
  18. import org.springframework.web.multipart.MultipartFile;
  19. import java.util.*;
  20. /**
  21. * Controller
  22. *
  23. * @author Scott
  24. * @email
  25. * @date 2017-08-21 21:19:49
  26. */
  27. @RestController
  28. @RequestMapping("goods")
  29. public class GoodsController {
  30. @Autowired
  31. private GoodsService goodsService;
  32. @Autowired
  33. private GoodsGalleryService goodsGalleryService;
  34. @Autowired
  35. private OfflineCartService offlineCartService;
  36. @Autowired
  37. private ExcelUtil excelUtil;
  38. /**
  39. * 查看列表
  40. */
  41. @RequestMapping("/list")
  42. @RequiresPermissions("goods:list")
  43. public R list(@RequestParam Map<String, Object> params) {
  44. //查询列表数据
  45. Query query = new Query(params);
  46. query.put("isDelete", 0);
  47. List<GoodsEntity> goodsList = goodsService.queryList(query);
  48. int total = goodsService.queryTotal(query);
  49. PageUtils pageUtil = new PageUtils(goodsList, total, query.getLimit(), query.getPage());
  50. return R.ok().put("page", pageUtil);
  51. }
  52. /**
  53. * 查看信息
  54. */
  55. @RequestMapping("/info/{id}")
  56. @RequiresPermissions("goods:info")
  57. public R info(@PathVariable("id") Integer id) {
  58. GoodsEntity goods = goodsService.queryObject(id);
  59. if(goods != null) {
  60. GoodsGalleryEntity goodsGalleryEntity =goodsGalleryService.queryVideoObjectByGoodId(goods.getId());
  61. if(goodsGalleryEntity != null){
  62. goods.setVideoUrl(goodsGalleryEntity.getImgUrl());
  63. }
  64. }
  65. return R.ok().put("goods", goods);
  66. }
  67. /**
  68. * 保存
  69. */
  70. @RequestMapping("/save")
  71. @RequiresPermissions("goods:save")
  72. public R save(@RequestBody GoodsEntity goods) {
  73. goodsService.save(goods);
  74. return R.ok();
  75. }
  76. /**
  77. * 修改
  78. */
  79. @RequestMapping("/update")
  80. @RequiresPermissions("goods:update")
  81. public R update(@RequestBody GoodsEntity goods) {
  82. goodsService.update(goods);
  83. return R.ok();
  84. }
  85. /**
  86. * 删除
  87. */
  88. @RequestMapping("/delete")
  89. @RequiresPermissions("goods:delete")
  90. public R delete(@RequestBody Integer[] ids) {
  91. goodsService.deleteBatch(ids);
  92. return R.ok();
  93. }
  94. /**
  95. * 查看所有列表
  96. */
  97. @RequestMapping("/queryAll")
  98. public R queryAll(@RequestParam Map<String, Object> params) {
  99. params.put("isDelete", 0);
  100. List<GoodsEntity> list = goodsService.queryList(params);
  101. return R.ok().put("list", list);
  102. }
  103. /**
  104. * 商品回收站
  105. *
  106. * @param params
  107. * @return
  108. */
  109. @RequestMapping("/historyList")
  110. public R historyList(@RequestParam Map<String, Object> params) {
  111. //查询列表数据
  112. Query query = new Query(params);
  113. query.put("isDelete", 1);
  114. List<GoodsEntity> goodsList = goodsService.queryList(query);
  115. int total = goodsService.queryTotal(query);
  116. PageUtils pageUtil = new PageUtils(goodsList, total, query.getLimit(), query.getPage());
  117. return R.ok().put("page", pageUtil);
  118. }
  119. /**
  120. * 商品从回收站恢复
  121. */
  122. @RequestMapping("/back")
  123. @RequiresPermissions("goods:back")
  124. public R back(@RequestBody Integer[] ids) {
  125. goodsService.back(ids);
  126. return R.ok();
  127. }
  128. /**
  129. * 总计
  130. */
  131. @RequestMapping("/queryTotal")
  132. public R queryTotal(@RequestParam Map<String, Object> params) {
  133. params.put("isDelete", 0);
  134. int sum = goodsService.queryTotal(params);
  135. return R.ok().put("goodsSum", sum);
  136. }
  137. /**
  138. * 上架
  139. */
  140. @RequestMapping("/enSale")
  141. public R enSale(@RequestBody Integer id) {
  142. goodsService.enSale(id);
  143. return R.ok();
  144. }
  145. /**
  146. * 上架
  147. */
  148. @RequestMapping("/enSaleBatch")
  149. public R enSaleBatch(@RequestBody Integer[] ids) {
  150. goodsService.enSaleBatch(ids);
  151. return R.ok();
  152. }
  153. /**
  154. * 下架
  155. */
  156. @RequestMapping("/unSale")
  157. public R unSale(@RequestBody Integer id) {
  158. goodsService.unSale(id);
  159. return R.ok();
  160. }
  161. /**
  162. * 下架
  163. */
  164. @RequestMapping("/unSaleBatch")
  165. public R unSaleBatch(@RequestBody Integer[] ids) {
  166. goodsService.unSaleBatch(ids);
  167. return R.ok();
  168. }
  169. /**
  170. * 上传文件
  171. */
  172. @RequestMapping("/upload")
  173. public R upload(@RequestParam("file") MultipartFile file) {
  174. List<GoodsDto> goodsDtoList = new ArrayList<>();//商品信息
  175. try {
  176. Map<String, Object> beans = new HashMap<String, Object>();
  177. beans.put("GoodsDtoList", goodsDtoList);
  178. if (file.isEmpty()) {
  179. return R.error("文件不能为空!");
  180. }
  181. excelUtil.readExcel(JxlsXmlTemplateName.GOODS_DTO_LIST, beans, file.getInputStream());
  182. } catch (Exception e) {
  183. e.printStackTrace();
  184. return R.error("导入失败!");
  185. }
  186. goodsService.uploadExcel(goodsDtoList);
  187. //上传文件
  188. return R.ok();
  189. }
  190. /**
  191. * 上传文件
  192. */
  193. @RequestMapping("/generalGoodsUpload")
  194. public R generalGoodsUpload(@RequestParam("file") MultipartFile file) {
  195. List<GoodsDto> generalGoodsDtoList = new ArrayList<>();//商品信息
  196. try {
  197. Map<String, Object> beans = new HashMap<String, Object>();
  198. beans.put("GeneralGoodsDtoList", generalGoodsDtoList);
  199. if (file.isEmpty()) {
  200. return R.error("文件不能为空!");
  201. }
  202. excelUtil.readExcel(JxlsXmlTemplateName.GENERAL_GOODS_DTO_LIST, beans, file.getInputStream());
  203. } catch (Exception e) {
  204. e.printStackTrace();
  205. return R.error("导入失败!");
  206. }
  207. goodsService.uploadExcel(generalGoodsDtoList);
  208. //上传文件
  209. return R.ok();
  210. }
  211. /*@RequestMapping("/scannInfo")
  212. @RequiresPermissions("goods:scannInfo")
  213. public R scannInfo(@RequestParam Map<String, Object> params) {
  214. String goodsSn = (String)params.get("goodsSn");
  215. GoodsEntity goods = goodsService.queryObjectByGoodsSnAndBizType(goodsSn);
  216. if(goods == null) {
  217. return R.error("商品信息不存在");
  218. }
  219. List<OfflineCartEntity> cartEntityList = offlineCartService.offlineGoodsCart(goods);
  220. return R.ok().put("cartEntityList", cartEntityList);
  221. }*/
  222. @RequestMapping("/scannInfo/{prodBarcode}")
  223. @RequiresPermissions("goods:scannInfo")
  224. public R scannInfo(@PathVariable("prodBarcode")String prodBarcode) {
  225. SysUserEntity user = ShiroUtils.getUserEntity();
  226. if(user == null) {
  227. return R.error("用户登录超时,请重新登录");
  228. }
  229. if (!user.getRoleType().equalsIgnoreCase("2")) {
  230. return R.error("该操作只允许店员账户操作");
  231. }
  232. GoodsEntity goods = goodsService.queryObjectByProdBarcodeAndBizType(prodBarcode);
  233. if(goods == null) {
  234. return R.error("商品信息不存在");
  235. }
  236. return R.ok().put("goods", goods);
  237. }
  238. }