GoodsController.java 9.7 KB

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