GoodsController.java 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  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.dto.GoodsPanoramaDto;
  5. import com.kmall.admin.entity.GoodsEntity;
  6. import com.kmall.admin.entity.GoodsGalleryEntity;
  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.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("/infoByQuery")
  78. public R infoByQuery(@RequestParam Map<String, Object> params) {
  79. ParamUtils.setQueryPowerByRoleType(params, "storeKey", "merchSn", "thirdPartyMerchCode");
  80. ParamUtils.setName(params, "name");
  81. //查询列表数据
  82. Query query = new Query(params);
  83. query.put("isDelete", 0);
  84. List<GoodsEntity> goodsList = goodsService.queryList(query);
  85. if(goodsList != null && goodsList.size() != 0) {
  86. return R.ok().put("goods", goodsList.get(0));
  87. }
  88. return R.ok().put("goods", new GoodsEntity());
  89. }
  90. /**
  91. * 保存
  92. */
  93. @RequestMapping("/save")
  94. @RequiresPermissions("goods:save")
  95. public R save(@RequestBody GoodsEntity goods) {
  96. goodsService.save(goods);
  97. return R.ok();
  98. }
  99. /**
  100. * 修改
  101. */
  102. @RequestMapping("/update")
  103. @RequiresPermissions("goods:update")
  104. public R update(@RequestBody GoodsEntity goods) {
  105. goodsService.update(goods);
  106. return R.ok();
  107. }
  108. /**
  109. * 删除
  110. */
  111. @RequestMapping("/delete")
  112. @RequiresPermissions("goods:delete")
  113. public R delete(@RequestBody Integer[] ids) {
  114. goodsService.deleteBatch(ids);
  115. return R.ok();
  116. }
  117. /**
  118. * 查看所有列表
  119. */
  120. @RequestMapping("/queryAll")
  121. public R queryAll(@RequestParam Map<String, Object> params) {
  122. ParamUtils.setQueryPowerByRoleType(params, "storeKey", "merchSn", "thirdPartyMerchCode");
  123. params.put("isDelete", Integer.parseInt(Dict.isDelete.item_0.getItem()));
  124. params.put("isOnSale", Integer.parseInt(Dict.isOnSale.item_1.getItem()));
  125. List<GoodsEntity> list = goodsService.queryList(params);
  126. return R.ok().put("list", list);
  127. }
  128. /**
  129. * 商品回收站
  130. *
  131. * @param params
  132. * @return
  133. */
  134. @RequestMapping("/historyList")
  135. public R historyList(@RequestParam Map<String, Object> params) {
  136. ParamUtils.setQueryPowerByRoleType(params, "storeKey", "merchSn", "thirdPartyMerchCode");
  137. //查询列表数据
  138. Query query = new Query(params);
  139. query.put("isDelete", 1);
  140. List<GoodsEntity> goodsList = goodsService.queryList(query);
  141. int total = goodsService.queryTotal(query);
  142. PageUtils pageUtil = new PageUtils(goodsList, total, query.getLimit(), query.getPage());
  143. return R.ok().put("page", pageUtil);
  144. }
  145. /**
  146. * 商品从回收站恢复
  147. */
  148. @RequestMapping("/back")
  149. @RequiresPermissions("goods:back")
  150. public R back(@RequestBody Integer[] ids) {
  151. goodsService.back(ids);
  152. return R.ok();
  153. }
  154. /**
  155. * 总计
  156. */
  157. @RequestMapping("/queryTotal")
  158. public R queryTotal(@RequestParam Map<String, Object> params) {
  159. ParamUtils.setQueryPowerByRoleType(params, "storeKey", "merchSn", "thirdPartyMerchCode");
  160. params.put("isDelete", 0);
  161. int sum = goodsService.queryTotal(params);
  162. return R.ok().put("goodsSum", sum);
  163. }
  164. /**
  165. * 上架
  166. */
  167. @RequestMapping("/enSale")
  168. public R enSale(@RequestBody Integer id) {
  169. goodsService.enSale(id);
  170. return R.ok();
  171. }
  172. /**
  173. * 上架
  174. */
  175. @RequestMapping("/enSaleBatch")
  176. public R enSaleBatch(@RequestBody Integer[] ids) {
  177. goodsService.enSaleBatch(ids);
  178. return R.ok();
  179. }
  180. /**
  181. * 下架
  182. */
  183. @RequestMapping("/unSale")
  184. public R unSale(@RequestBody Integer id) {
  185. goodsService.unSale(id);
  186. return R.ok();
  187. }
  188. /**
  189. * 下架
  190. */
  191. @RequestMapping("/unSaleBatch")
  192. public R unSaleBatch(@RequestBody Integer[] ids) {
  193. goodsService.unSaleBatch(ids);
  194. return R.ok();
  195. }
  196. /**
  197. * 上传文件
  198. */
  199. @RequestMapping("/upload")
  200. public R upload(@RequestParam("file") MultipartFile file) {
  201. List<GoodsDto> goodsDtoList = new ArrayList<>();//商品信息
  202. try {
  203. Map<String, Object> beans = new HashMap<String, Object>();
  204. beans.put("GoodsDtoList", goodsDtoList);
  205. if (file.isEmpty()) {
  206. return R.error("文件不能为空!");
  207. }
  208. excelUtil.readExcel(JxlsXmlTemplateName.GOODS_DTO_LIST, beans, file.getInputStream());
  209. } catch (Exception e) {
  210. e.printStackTrace();
  211. return R.error("导入失败!");
  212. }
  213. goodsService.uploadExcel(goodsDtoList,Integer.parseInt(Dict.exportDataType.item_1.getItem()));
  214. //上传文件
  215. return R.ok();
  216. }
  217. /**
  218. * 上传文件
  219. */
  220. @RequestMapping("/generalGoodsUpload")
  221. public R generalGoodsUpload(@RequestParam("file") MultipartFile file) {
  222. List<GoodsDto> generalGoodsDtoList = new ArrayList<>();//商品信息
  223. try {
  224. Map<String, Object> beans = new HashMap<String, Object>();
  225. beans.put("GeneralGoodsDtoList", generalGoodsDtoList);
  226. if (file.isEmpty()) {
  227. return R.error("文件不能为空!");
  228. }
  229. excelUtil.readExcel(JxlsXmlTemplateName.GENERAL_GOODS_DTO_LIST, beans, file.getInputStream());
  230. } catch (Exception e) {
  231. e.printStackTrace();
  232. return R.error("导入失败!");
  233. }
  234. goodsService.uploadExcel(generalGoodsDtoList,Integer.parseInt(Dict.exportDataType.item_2.getItem()));
  235. //上传文件
  236. return R.ok();
  237. }
  238. /*@RequestMapping("/scannInfo")
  239. @RequiresPermissions("goods:scannInfo")
  240. public R scannInfo(@RequestParam Map<String, Object> params) {
  241. String goodsSn = (String)params.get("goodsSn");
  242. GoodsEntity goods = goodsService.queryObjectByGoodsSnAndBizType(goodsSn);
  243. if(goods == null) {
  244. return R.error("商品信息不存在");
  245. }
  246. List<OfflineCartEntity> cartEntityList = offlineCartService.offlineGoodsCart(goods);
  247. return R.ok().put("cartEntityList", cartEntityList);
  248. }*/
  249. @RequestMapping("/scannInfo/{prodBarcode}")
  250. @RequiresPermissions("goods:scannInfo")
  251. public R scannInfo(@PathVariable("prodBarcode")String prodBarcode) {
  252. SysUserEntity user = ShiroUtils.getUserEntity();
  253. if(user == null) {
  254. return R.error("用户登录超时,请重新登录");
  255. }
  256. if (!user.getRoleType().equalsIgnoreCase("2")) {
  257. return R.error("该操作只允许店员账户操作");
  258. }
  259. GoodsEntity goods = goodsService.queryObjectByProdBarcodeAndBizType(prodBarcode, user.getStoreId());
  260. if(goods == null) {
  261. return R.error("商品信息不存在");
  262. }
  263. return R.ok().put("goods", goods);
  264. }
  265. @RequestMapping("/details/{prodBarcode}/{storeId}")
  266. // @RequiresPermissions("goods:details") http://127.0.0.1:8080/goods/details/11111
  267. public R details(@PathVariable("prodBarcode")String prodBarcode,@PathVariable("storeId")String storeId) {
  268. SysUserEntity user = ShiroUtils.getUserEntity();
  269. if(user == null) {
  270. return R.error("用户登录超时,请重新登录");
  271. }
  272. if (!user.getRoleType().equalsIgnoreCase("2")) {
  273. return R.error("该操作只允许店员账户操作");
  274. }
  275. GoodsDetailsDto goods = goodsService.queryGoodsDetailsByProdBarcode(prodBarcode,storeId);
  276. if(goods == null) {
  277. return R.error("商品信息不存在");
  278. }
  279. return R.ok().put("goodsDetails", goods);
  280. }
  281. /**
  282. * 根据商品编码或者条码查询商品信息(17.商品全景图)
  283. * @param keyword
  284. * @return
  285. */
  286. @GetMapping("/search/{keyword}")
  287. public R searchByKeyword(@PathVariable("keyword") String keyword){
  288. if (keyword == null || "".equals(keyword)){
  289. return R.error("请输入商品编码或者条码!");
  290. }
  291. GoodsPanoramaDto goodsPanoramaDto = goodsService.searchGoodsPanoramaDtoByKeyword(keyword);
  292. //GoodsEntity goods = goodsService.searchGoodsByKeyword(keyword);
  293. if (goodsPanoramaDto == null || "".equals(goodsPanoramaDto)) {
  294. return R.error("没有该商品!");
  295. }
  296. return R.ok().put("goodsPanoramaDto",goodsPanoramaDto);
  297. }
  298. }