GoodsController.java 8.6 KB

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