GoodsController.java 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  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, null, "merchSn", true);
  50. if (Dict.roleType.item_2.getItem().equals(ShiroUtils.getUserEntity().getRoleType())) {
  51. StoreEntity storeEntity = storeService.queryObject(ShiroUtils.getUserEntity().getStoreId());
  52. if(StringUtils.isNotEmpty(storeEntity.getThirdPartyMerchCode())) {
  53. params.put("thirdPartyMerchCode", storeEntity.getThirdPartyMerchCode());
  54. }else{
  55. throw new RRException("请维护门店信息中的第三方商户编号信息!再进行商品查看");
  56. }
  57. }
  58. String goodsName = (String) params.get("name");
  59. if(org.apache.commons.lang3.StringUtils.isNotEmpty(goodsName)){
  60. try{
  61. goodsName = new String(goodsName.getBytes("iso-8859-1"),"utf-8");
  62. }catch (Exception e){
  63. e.printStackTrace();
  64. }
  65. params.put("name", goodsName);
  66. }
  67. //查询列表数据
  68. Query query = new Query(params);
  69. query.put("isDelete", 0);
  70. List<GoodsEntity> goodsList = goodsService.queryList(query);
  71. int total = goodsService.queryTotal(query);
  72. PageUtils pageUtil = new PageUtils(goodsList, total, query.getLimit(), query.getPage());
  73. return R.ok().put("page", pageUtil);
  74. }
  75. /**
  76. * 查看信息
  77. */
  78. @RequestMapping("/info/{id}")
  79. @RequiresPermissions("goods:info")
  80. public R info(@PathVariable("id") Integer id) {
  81. GoodsEntity goods = goodsService.queryObject(id);
  82. if(goods != null) {
  83. GoodsGalleryEntity goodsGalleryEntity =goodsGalleryService.queryVideoObjectByGoodId(goods.getId());
  84. if(goodsGalleryEntity != null){
  85. goods.setVideoUrl(goodsGalleryEntity.getImgUrl());
  86. }
  87. }
  88. return R.ok().put("goods", goods);
  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, null, "merchSn", true);
  123. if (Dict.roleType.item_2.getItem().equals(ShiroUtils.getUserEntity().getRoleType())) {
  124. StoreEntity storeEntity = storeService.queryObject(ShiroUtils.getUserEntity().getStoreId());
  125. if(StringUtils.isNotEmpty(storeEntity.getThirdPartyMerchCode())) {
  126. params.put("thirdPartyMerchCode", storeEntity.getThirdPartyMerchCode());
  127. }else{
  128. throw new RRException("请维护门店信息中的第三方商户编号信息!再进行商品查看");
  129. }
  130. }
  131. params.put("isDelete", Integer.parseInt(Dict.isDelete.item_0.getItem()));
  132. params.put("isOnSale", Integer.parseInt(Dict.isOnSale.item_1.getItem()));
  133. List<GoodsEntity> list = goodsService.queryList(params);
  134. return R.ok().put("list", list);
  135. }
  136. /**
  137. * 商品回收站
  138. *
  139. * @param params
  140. * @return
  141. */
  142. @RequestMapping("/historyList")
  143. public R historyList(@RequestParam Map<String, Object> params) {
  144. ParamUtils.setQueryPowerByRoleType(params, null, "merchSn", true);
  145. if (Dict.roleType.item_2.getItem().equals(ShiroUtils.getUserEntity().getRoleType())) {
  146. StoreEntity storeEntity = storeService.queryObject(ShiroUtils.getUserEntity().getStoreId());
  147. if(StringUtils.isNotEmpty(storeEntity.getThirdPartyMerchCode())) {
  148. params.put("thirdPartyMerchCode", storeEntity.getThirdPartyMerchCode());
  149. }else{
  150. throw new RRException("请维护门店信息中的第三方商户编号信息!再进行商品查看");
  151. }
  152. }
  153. //查询列表数据
  154. Query query = new Query(params);
  155. query.put("isDelete", 1);
  156. List<GoodsEntity> goodsList = goodsService.queryList(query);
  157. int total = goodsService.queryTotal(query);
  158. PageUtils pageUtil = new PageUtils(goodsList, total, query.getLimit(), query.getPage());
  159. return R.ok().put("page", pageUtil);
  160. }
  161. /**
  162. * 商品从回收站恢复
  163. */
  164. @RequestMapping("/back")
  165. @RequiresPermissions("goods:back")
  166. public R back(@RequestBody Integer[] ids) {
  167. goodsService.back(ids);
  168. return R.ok();
  169. }
  170. /**
  171. * 总计
  172. */
  173. @RequestMapping("/queryTotal")
  174. public R queryTotal(@RequestParam Map<String, Object> params) {
  175. ParamUtils.setQueryPowerByRoleType(params, null, "merchSn", true);
  176. if (Dict.roleType.item_2.getItem().equals(ShiroUtils.getUserEntity().getRoleType())) {
  177. StoreEntity storeEntity = storeService.queryObject(ShiroUtils.getUserEntity().getStoreId());
  178. if(StringUtils.isNotEmpty(storeEntity.getThirdPartyMerchCode())) {
  179. params.put("thirdPartyMerchCode", storeEntity.getThirdPartyMerchCode());
  180. }else{
  181. throw new RRException("请维护门店信息中的第三方商户编号信息!再进行商品查看");
  182. }
  183. }
  184. params.put("isDelete", 0);
  185. int sum = goodsService.queryTotal(params);
  186. return R.ok().put("goodsSum", sum);
  187. }
  188. /**
  189. * 上架
  190. */
  191. @RequestMapping("/enSale")
  192. public R enSale(@RequestBody Integer id) {
  193. goodsService.enSale(id);
  194. return R.ok();
  195. }
  196. /**
  197. * 上架
  198. */
  199. @RequestMapping("/enSaleBatch")
  200. public R enSaleBatch(@RequestBody Integer[] ids) {
  201. goodsService.enSaleBatch(ids);
  202. return R.ok();
  203. }
  204. /**
  205. * 下架
  206. */
  207. @RequestMapping("/unSale")
  208. public R unSale(@RequestBody Integer id) {
  209. goodsService.unSale(id);
  210. return R.ok();
  211. }
  212. /**
  213. * 下架
  214. */
  215. @RequestMapping("/unSaleBatch")
  216. public R unSaleBatch(@RequestBody Integer[] ids) {
  217. goodsService.unSaleBatch(ids);
  218. return R.ok();
  219. }
  220. /**
  221. * 上传文件
  222. */
  223. @RequestMapping("/upload")
  224. public R upload(@RequestParam("file") MultipartFile file) {
  225. List<GoodsDto> goodsDtoList = new ArrayList<>();//商品信息
  226. try {
  227. Map<String, Object> beans = new HashMap<String, Object>();
  228. beans.put("GoodsDtoList", goodsDtoList);
  229. if (file.isEmpty()) {
  230. return R.error("文件不能为空!");
  231. }
  232. excelUtil.readExcel(JxlsXmlTemplateName.GOODS_DTO_LIST, beans, file.getInputStream());
  233. } catch (Exception e) {
  234. e.printStackTrace();
  235. return R.error("导入失败!");
  236. }
  237. goodsService.uploadExcel(goodsDtoList,1);
  238. //上传文件
  239. return R.ok();
  240. }
  241. /**
  242. * 上传文件
  243. */
  244. @RequestMapping("/generalGoodsUpload")
  245. public R generalGoodsUpload(@RequestParam("file") MultipartFile file) {
  246. List<GoodsDto> generalGoodsDtoList = new ArrayList<>();//商品信息
  247. try {
  248. Map<String, Object> beans = new HashMap<String, Object>();
  249. beans.put("GeneralGoodsDtoList", generalGoodsDtoList);
  250. if (file.isEmpty()) {
  251. return R.error("文件不能为空!");
  252. }
  253. excelUtil.readExcel(JxlsXmlTemplateName.GENERAL_GOODS_DTO_LIST, beans, file.getInputStream());
  254. } catch (Exception e) {
  255. e.printStackTrace();
  256. return R.error("导入失败!");
  257. }
  258. goodsService.uploadExcel(generalGoodsDtoList,2);
  259. //上传文件
  260. return R.ok();
  261. }
  262. /*@RequestMapping("/scannInfo")
  263. @RequiresPermissions("goods:scannInfo")
  264. public R scannInfo(@RequestParam Map<String, Object> params) {
  265. String goodsSn = (String)params.get("goodsSn");
  266. GoodsEntity goods = goodsService.queryObjectByGoodsSnAndBizType(goodsSn);
  267. if(goods == null) {
  268. return R.error("商品信息不存在");
  269. }
  270. List<OfflineCartEntity> cartEntityList = offlineCartService.offlineGoodsCart(goods);
  271. return R.ok().put("cartEntityList", cartEntityList);
  272. }*/
  273. @RequestMapping("/scannInfo/{prodBarcode}")
  274. @RequiresPermissions("goods:scannInfo")
  275. public R scannInfo(@PathVariable("prodBarcode")String prodBarcode) {
  276. SysUserEntity user = ShiroUtils.getUserEntity();
  277. if(user == null) {
  278. return R.error("用户登录超时,请重新登录");
  279. }
  280. if (!user.getRoleType().equalsIgnoreCase("2")) {
  281. return R.error("该操作只允许店员账户操作");
  282. }
  283. GoodsEntity goods = goodsService.queryObjectByProdBarcodeAndBizType(prodBarcode, user.getStoreId());
  284. if(goods == null) {
  285. return R.error("商品信息不存在");
  286. }
  287. return R.ok().put("goods", goods);
  288. }
  289. }