GoodsController.java 8.2 KB

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