1
0

GoodsController.java 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  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. SysUserEntity user = ShiroUtils.getUserEntity();
  45. //判断是否是店员和商户
  46. if ("2".equals(user.getRoleType()) || "3".equals(user.getRoleType())) {
  47. params.put("merchSn", user.getMerchSn());
  48. }
  49. //查询列表数据
  50. Query query = new Query(params);
  51. query.put("isDelete", 0);
  52. List<GoodsEntity> goodsList = goodsService.queryList(query);
  53. int total = goodsService.queryTotal(query);
  54. PageUtils pageUtil = new PageUtils(goodsList, total, query.getLimit(), query.getPage());
  55. return R.ok().put("page", pageUtil);
  56. }
  57. /**
  58. * 查看信息
  59. */
  60. @RequestMapping("/info/{id}")
  61. @RequiresPermissions("goods:info")
  62. public R info(@PathVariable("id") Integer id) {
  63. GoodsEntity goods = goodsService.queryObject(id);
  64. if(goods != null) {
  65. GoodsGalleryEntity goodsGalleryEntity =goodsGalleryService.queryVideoObjectByGoodId(goods.getId());
  66. if(goodsGalleryEntity != null){
  67. goods.setVideoUrl(goodsGalleryEntity.getImgUrl());
  68. }
  69. }
  70. return R.ok().put("goods", goods);
  71. }
  72. /**
  73. * 保存
  74. */
  75. @RequestMapping("/save")
  76. @RequiresPermissions("goods:save")
  77. public R save(@RequestBody GoodsEntity goods) {
  78. goodsService.save(goods);
  79. return R.ok();
  80. }
  81. /**
  82. * 修改
  83. */
  84. @RequestMapping("/update")
  85. @RequiresPermissions("goods:update")
  86. public R update(@RequestBody GoodsEntity goods) {
  87. goodsService.update(goods);
  88. return R.ok();
  89. }
  90. /**
  91. * 删除
  92. */
  93. @RequestMapping("/delete")
  94. @RequiresPermissions("goods:delete")
  95. public R delete(@RequestBody Integer[] ids) {
  96. goodsService.deleteBatch(ids);
  97. return R.ok();
  98. }
  99. /**
  100. * 查看所有列表
  101. */
  102. @RequestMapping("/queryAll")
  103. public R queryAll(@RequestParam Map<String, Object> params) {
  104. params.put("isDelete", 0);
  105. List<GoodsEntity> list = goodsService.queryList(params);
  106. return R.ok().put("list", list);
  107. }
  108. /**
  109. * 商品回收站
  110. *
  111. * @param params
  112. * @return
  113. */
  114. @RequestMapping("/historyList")
  115. public R historyList(@RequestParam Map<String, Object> params) {
  116. //查询列表数据
  117. Query query = new Query(params);
  118. query.put("isDelete", 1);
  119. List<GoodsEntity> goodsList = goodsService.queryList(query);
  120. int total = goodsService.queryTotal(query);
  121. PageUtils pageUtil = new PageUtils(goodsList, total, query.getLimit(), query.getPage());
  122. return R.ok().put("page", pageUtil);
  123. }
  124. /**
  125. * 商品从回收站恢复
  126. */
  127. @RequestMapping("/back")
  128. @RequiresPermissions("goods:back")
  129. public R back(@RequestBody Integer[] ids) {
  130. goodsService.back(ids);
  131. return R.ok();
  132. }
  133. /**
  134. * 总计
  135. */
  136. @RequestMapping("/queryTotal")
  137. public R queryTotal(@RequestParam Map<String, Object> params) {
  138. params.put("isDelete", 0);
  139. int sum = goodsService.queryTotal(params);
  140. return R.ok().put("goodsSum", sum);
  141. }
  142. /**
  143. * 上架
  144. */
  145. @RequestMapping("/enSale")
  146. public R enSale(@RequestBody Integer id) {
  147. goodsService.enSale(id);
  148. return R.ok();
  149. }
  150. /**
  151. * 上架
  152. */
  153. @RequestMapping("/enSaleBatch")
  154. public R enSaleBatch(@RequestBody Integer[] ids) {
  155. goodsService.enSaleBatch(ids);
  156. return R.ok();
  157. }
  158. /**
  159. * 下架
  160. */
  161. @RequestMapping("/unSale")
  162. public R unSale(@RequestBody Integer id) {
  163. goodsService.unSale(id);
  164. return R.ok();
  165. }
  166. /**
  167. * 下架
  168. */
  169. @RequestMapping("/unSaleBatch")
  170. public R unSaleBatch(@RequestBody Integer[] ids) {
  171. goodsService.unSaleBatch(ids);
  172. return R.ok();
  173. }
  174. /**
  175. * 上传文件
  176. */
  177. @RequestMapping("/upload")
  178. public R upload(@RequestParam("file") MultipartFile file) {
  179. List<GoodsDto> goodsDtoList = new ArrayList<>();//商品信息
  180. try {
  181. Map<String, Object> beans = new HashMap<String, Object>();
  182. beans.put("GoodsDtoList", goodsDtoList);
  183. if (file.isEmpty()) {
  184. return R.error("文件不能为空!");
  185. }
  186. excelUtil.readExcel(JxlsXmlTemplateName.GOODS_DTO_LIST, beans, file.getInputStream());
  187. } catch (Exception e) {
  188. e.printStackTrace();
  189. return R.error("导入失败!");
  190. }
  191. goodsService.uploadExcel(goodsDtoList,1);
  192. //上传文件
  193. return R.ok();
  194. }
  195. /**
  196. * 上传文件
  197. */
  198. @RequestMapping("/generalGoodsUpload")
  199. public R generalGoodsUpload(@RequestParam("file") MultipartFile file) {
  200. List<GoodsDto> generalGoodsDtoList = new ArrayList<>();//商品信息
  201. try {
  202. Map<String, Object> beans = new HashMap<String, Object>();
  203. beans.put("GeneralGoodsDtoList", generalGoodsDtoList);
  204. if (file.isEmpty()) {
  205. return R.error("文件不能为空!");
  206. }
  207. excelUtil.readExcel(JxlsXmlTemplateName.GENERAL_GOODS_DTO_LIST, beans, file.getInputStream());
  208. } catch (Exception e) {
  209. e.printStackTrace();
  210. return R.error("导入失败!");
  211. }
  212. goodsService.uploadExcel(generalGoodsDtoList,2);
  213. //上传文件
  214. return R.ok();
  215. }
  216. /*@RequestMapping("/scannInfo")
  217. @RequiresPermissions("goods:scannInfo")
  218. public R scannInfo(@RequestParam Map<String, Object> params) {
  219. String goodsSn = (String)params.get("goodsSn");
  220. GoodsEntity goods = goodsService.queryObjectByGoodsSnAndBizType(goodsSn);
  221. if(goods == null) {
  222. return R.error("商品信息不存在");
  223. }
  224. List<OfflineCartEntity> cartEntityList = offlineCartService.offlineGoodsCart(goods);
  225. return R.ok().put("cartEntityList", cartEntityList);
  226. }*/
  227. @RequestMapping("/scannInfo/{prodBarcode}")
  228. @RequiresPermissions("goods:scannInfo")
  229. public R scannInfo(@PathVariable("prodBarcode")String prodBarcode) {
  230. SysUserEntity user = ShiroUtils.getUserEntity();
  231. if(user == null) {
  232. return R.error("用户登录超时,请重新登录");
  233. }
  234. if (!user.getRoleType().equalsIgnoreCase("2")) {
  235. return R.error("该操作只允许店员账户操作");
  236. }
  237. GoodsEntity goods = goodsService.queryObjectByProdBarcodeAndBizType(prodBarcode);
  238. if(goods == null) {
  239. return R.error("商品信息不存在");
  240. }
  241. return R.ok().put("goods", goods);
  242. }
  243. }