GoodsController.java 9.4 KB

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