GoodsController.java 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  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.admin.utils.ParamUtils;
  9. import com.kmall.common.constant.JxlsXmlTemplateName;
  10. import com.kmall.common.entity.SysUserEntity;
  11. import com.kmall.common.utils.PageUtils;
  12. import com.kmall.common.utils.Query;
  13. import com.kmall.common.utils.R;
  14. import com.kmall.common.utils.ShiroUtils;
  15. import com.kmall.common.utils.excel.ExcelUtil;
  16. import org.apache.shiro.authz.annotation.RequiresPermissions;
  17. import org.springframework.beans.factory.annotation.Autowired;
  18. import org.springframework.web.bind.annotation.*;
  19. import org.springframework.web.multipart.MultipartFile;
  20. import java.util.*;
  21. /**
  22. * Controller
  23. *
  24. * @author Scott
  25. * @email
  26. * @date 2017-08-21 21:19:49
  27. */
  28. @RestController
  29. @RequestMapping("goods")
  30. public class GoodsController {
  31. @Autowired
  32. private GoodsService goodsService;
  33. @Autowired
  34. private GoodsGalleryService goodsGalleryService;
  35. @Autowired
  36. private OfflineCartService offlineCartService;
  37. @Autowired
  38. private ExcelUtil excelUtil;
  39. /**
  40. * 查看列表
  41. */
  42. @RequestMapping("/list")
  43. @RequiresPermissions("goods:list")
  44. public R list(@RequestParam Map<String, Object> params) {
  45. ParamUtils.setQueryPowerByRoleType(params, null, "merchSn", true);
  46. //查询列表数据
  47. Query query = new Query(params);
  48. query.put("isDelete", 0);
  49. List<GoodsEntity> goodsList = goodsService.queryList(query);
  50. int total = goodsService.queryTotal(query);
  51. PageUtils pageUtil = new PageUtils(goodsList, total, query.getLimit(), query.getPage());
  52. return R.ok().put("page", pageUtil);
  53. }
  54. /**
  55. * 查看信息
  56. */
  57. @RequestMapping("/info/{id}")
  58. @RequiresPermissions("goods:info")
  59. public R info(@PathVariable("id") Integer id) {
  60. GoodsEntity goods = goodsService.queryObject(id);
  61. if(goods != null) {
  62. GoodsGalleryEntity goodsGalleryEntity =goodsGalleryService.queryVideoObjectByGoodId(goods.getId());
  63. if(goodsGalleryEntity != null){
  64. goods.setVideoUrl(goodsGalleryEntity.getImgUrl());
  65. }
  66. }
  67. return R.ok().put("goods", goods);
  68. }
  69. /**
  70. * 保存
  71. */
  72. @RequestMapping("/save")
  73. @RequiresPermissions("goods:save")
  74. public R save(@RequestBody GoodsEntity goods) {
  75. goodsService.save(goods);
  76. return R.ok();
  77. }
  78. /**
  79. * 修改
  80. */
  81. @RequestMapping("/update")
  82. @RequiresPermissions("goods:update")
  83. public R update(@RequestBody GoodsEntity goods) {
  84. goodsService.update(goods);
  85. return R.ok();
  86. }
  87. /**
  88. * 删除
  89. */
  90. @RequestMapping("/delete")
  91. @RequiresPermissions("goods:delete")
  92. public R delete(@RequestBody Integer[] ids) {
  93. goodsService.deleteBatch(ids);
  94. return R.ok();
  95. }
  96. /**
  97. * 查看所有列表
  98. */
  99. @RequestMapping("/queryAll")
  100. public R queryAll(@RequestParam Map<String, Object> params) {
  101. ParamUtils.setQueryPowerByRoleType(params, null, "merchSn", true);
  102. params.put("isDelete", 0);
  103. List<GoodsEntity> list = goodsService.queryList(params);
  104. return R.ok().put("list", list);
  105. }
  106. /**
  107. * 商品回收站
  108. *
  109. * @param params
  110. * @return
  111. */
  112. @RequestMapping("/historyList")
  113. public R historyList(@RequestParam Map<String, Object> params) {
  114. ParamUtils.setQueryPowerByRoleType(params, null, "merchSn", true);
  115. //查询列表数据
  116. Query query = new Query(params);
  117. query.put("isDelete", 1);
  118. List<GoodsEntity> goodsList = goodsService.queryList(query);
  119. int total = goodsService.queryTotal(query);
  120. PageUtils pageUtil = new PageUtils(goodsList, total, query.getLimit(), query.getPage());
  121. return R.ok().put("page", pageUtil);
  122. }
  123. /**
  124. * 商品从回收站恢复
  125. */
  126. @RequestMapping("/back")
  127. @RequiresPermissions("goods:back")
  128. public R back(@RequestBody Integer[] ids) {
  129. goodsService.back(ids);
  130. return R.ok();
  131. }
  132. /**
  133. * 总计
  134. */
  135. @RequestMapping("/queryTotal")
  136. public R queryTotal(@RequestParam Map<String, Object> params) {
  137. ParamUtils.setQueryPowerByRoleType(params, null, "merchSn", true);
  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. }