GoodsController.java 10 KB

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