123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284 |
- package com.kmall.admin.controller;
- import com.kmall.admin.dto.GoodsDto;
- import com.kmall.admin.entity.GoodsEntity;
- import com.kmall.admin.entity.GoodsGalleryEntity;
- import com.kmall.admin.entity.StoreEntity;
- import com.kmall.admin.service.GoodsGalleryService;
- import com.kmall.admin.service.GoodsService;
- import com.kmall.admin.service.OfflineCartService;
- import com.kmall.admin.service.StoreService;
- import com.kmall.admin.utils.ParamUtils;
- import com.kmall.admin.utils.ShiroUtils;
- import com.kmall.common.constant.Dict;
- import com.kmall.common.constant.JxlsXmlTemplateName;
- import com.kmall.admin.fromcomm.entity.SysUserEntity;
- import com.kmall.common.utils.*;
- import com.kmall.common.utils.excel.ExcelUtil;
- import org.apache.commons.lang3.StringUtils;
- import org.apache.shiro.authz.annotation.RequiresPermissions;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.web.bind.annotation.*;
- import org.springframework.web.multipart.MultipartFile;
- import java.util.*;
- /**
- * Controller
- *
- * @author Scott
- * @email
- * @date 2017-08-21 21:19:49
- */
- @RestController
- @RequestMapping("goods")
- public class GoodsController {
- @Autowired
- private GoodsService goodsService;
- @Autowired
- private GoodsGalleryService goodsGalleryService;
- @Autowired
- private OfflineCartService offlineCartService;
- @Autowired
- private ExcelUtil excelUtil;
- @Autowired
- private StoreService storeService;
- /**
- * 查看列表
- */
- @RequestMapping("/list")
- @RequiresPermissions("goods:list")
- public R list(@RequestParam Map<String, Object> params) {
- ParamUtils.setQueryPowerByRoleType(params, "storeKey", "merchSn", "thirdPartyMerchCode");
- ParamUtils.setName(params, "name");
- //查询列表数据
- Query query = new Query(params);
- query.put("isDelete", 0);
- List<GoodsEntity> goodsList = goodsService.queryList(query);
- int total = goodsService.queryTotal(query);
- PageUtils pageUtil = new PageUtils(goodsList, total, query.getLimit(), query.getPage());
- return R.ok().put("page", pageUtil);
- }
- /**
- * 查看信息
- */
- @RequestMapping("/info/{id}")
- @RequiresPermissions("goods:info")
- public R info(@PathVariable("id") Integer id) {
- GoodsEntity goods = goodsService.queryObject(id);
- if(goods != null) {
- GoodsGalleryEntity goodsGalleryEntity =goodsGalleryService.queryVideoObjectByGoodId(goods.getId());
- if(goodsGalleryEntity != null){
- goods.setVideoUrl(goodsGalleryEntity.getImgUrl());
- }
- }
- return R.ok().put("goods", goods);
- }
- /**
- * 保存
- */
- @RequestMapping("/save")
- @RequiresPermissions("goods:save")
- public R save(@RequestBody GoodsEntity goods) {
- goodsService.save(goods);
- return R.ok();
- }
- /**
- * 修改
- */
- @RequestMapping("/update")
- @RequiresPermissions("goods:update")
- public R update(@RequestBody GoodsEntity goods) {
- goodsService.update(goods);
- return R.ok();
- }
- /**
- * 删除
- */
- @RequestMapping("/delete")
- @RequiresPermissions("goods:delete")
- public R delete(@RequestBody Integer[] ids) {
- goodsService.deleteBatch(ids);
- return R.ok();
- }
- /**
- * 查看所有列表
- */
- @RequestMapping("/queryAll")
- public R queryAll(@RequestParam Map<String, Object> params) {
- ParamUtils.setQueryPowerByRoleType(params, "storeKey", "merchSn", "thirdPartyMerchCode");
- params.put("isDelete", Integer.parseInt(Dict.isDelete.item_0.getItem()));
- params.put("isOnSale", Integer.parseInt(Dict.isOnSale.item_1.getItem()));
- List<GoodsEntity> list = goodsService.queryList(params);
- return R.ok().put("list", list);
- }
- /**
- * 商品回收站
- *
- * @param params
- * @return
- */
- @RequestMapping("/historyList")
- public R historyList(@RequestParam Map<String, Object> params) {
- ParamUtils.setQueryPowerByRoleType(params, "storeKey", "merchSn", "thirdPartyMerchCode");
- //查询列表数据
- Query query = new Query(params);
- query.put("isDelete", 1);
- List<GoodsEntity> goodsList = goodsService.queryList(query);
- int total = goodsService.queryTotal(query);
- PageUtils pageUtil = new PageUtils(goodsList, total, query.getLimit(), query.getPage());
- return R.ok().put("page", pageUtil);
- }
- /**
- * 商品从回收站恢复
- */
- @RequestMapping("/back")
- @RequiresPermissions("goods:back")
- public R back(@RequestBody Integer[] ids) {
- goodsService.back(ids);
- return R.ok();
- }
- /**
- * 总计
- */
- @RequestMapping("/queryTotal")
- public R queryTotal(@RequestParam Map<String, Object> params) {
- ParamUtils.setQueryPowerByRoleType(params, "storeKey", "merchSn", "thirdPartyMerchCode");
- params.put("isDelete", 0);
- int sum = goodsService.queryTotal(params);
- return R.ok().put("goodsSum", sum);
- }
- /**
- * 上架
- */
- @RequestMapping("/enSale")
- public R enSale(@RequestBody Integer id) {
- goodsService.enSale(id);
- return R.ok();
- }
- /**
- * 上架
- */
- @RequestMapping("/enSaleBatch")
- public R enSaleBatch(@RequestBody Integer[] ids) {
- goodsService.enSaleBatch(ids);
- return R.ok();
- }
- /**
- * 下架
- */
- @RequestMapping("/unSale")
- public R unSale(@RequestBody Integer id) {
- goodsService.unSale(id);
- return R.ok();
- }
- /**
- * 下架
- */
- @RequestMapping("/unSaleBatch")
- public R unSaleBatch(@RequestBody Integer[] ids) {
- goodsService.unSaleBatch(ids);
- return R.ok();
- }
- /**
- * 上传文件
- */
- @RequestMapping("/upload")
- public R upload(@RequestParam("file") MultipartFile file) {
- List<GoodsDto> goodsDtoList = new ArrayList<>();//商品信息
- try {
- Map<String, Object> beans = new HashMap<String, Object>();
- beans.put("GoodsDtoList", goodsDtoList);
- if (file.isEmpty()) {
- return R.error("文件不能为空!");
- }
- excelUtil.readExcel(JxlsXmlTemplateName.GOODS_DTO_LIST, beans, file.getInputStream());
- } catch (Exception e) {
- e.printStackTrace();
- return R.error("导入失败!");
- }
- goodsService.uploadExcel(goodsDtoList,Integer.parseInt(Dict.exportDataType.item_1.getItem()));
- //上传文件
- return R.ok();
- }
- /**
- * 上传文件
- */
- @RequestMapping("/generalGoodsUpload")
- public R generalGoodsUpload(@RequestParam("file") MultipartFile file) {
- List<GoodsDto> generalGoodsDtoList = new ArrayList<>();//商品信息
- try {
- Map<String, Object> beans = new HashMap<String, Object>();
- beans.put("GeneralGoodsDtoList", generalGoodsDtoList);
- if (file.isEmpty()) {
- return R.error("文件不能为空!");
- }
- excelUtil.readExcel(JxlsXmlTemplateName.GENERAL_GOODS_DTO_LIST, beans, file.getInputStream());
- } catch (Exception e) {
- e.printStackTrace();
- return R.error("导入失败!");
- }
- goodsService.uploadExcel(generalGoodsDtoList,Integer.parseInt(Dict.exportDataType.item_2.getItem()));
- //上传文件
- return R.ok();
- }
- /*@RequestMapping("/scannInfo")
- @RequiresPermissions("goods:scannInfo")
- public R scannInfo(@RequestParam Map<String, Object> params) {
- String goodsSn = (String)params.get("goodsSn");
- GoodsEntity goods = goodsService.queryObjectByGoodsSnAndBizType(goodsSn);
- if(goods == null) {
- return R.error("商品信息不存在");
- }
- List<OfflineCartEntity> cartEntityList = offlineCartService.offlineGoodsCart(goods);
- return R.ok().put("cartEntityList", cartEntityList);
- }*/
- @RequestMapping("/scannInfo/{prodBarcode}")
- @RequiresPermissions("goods:scannInfo")
- public R scannInfo(@PathVariable("prodBarcode")String prodBarcode) {
- SysUserEntity user = ShiroUtils.getUserEntity();
- if(user == null) {
- return R.error("用户登录超时,请重新登录");
- }
- if (!user.getRoleType().equalsIgnoreCase("2")) {
- return R.error("该操作只允许店员账户操作");
- }
- GoodsEntity goods = goodsService.queryObjectByProdBarcodeAndBizType(prodBarcode, user.getStoreId());
- if(goods == null) {
- return R.error("商品信息不存在");
- }
- return R.ok().put("goods", goods);
- }
- }
|