GoodsController.java 8.8 KB

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