From 98b1a0affd69bbe63223c21fdd2c404e8bedfccb Mon Sep 17 00:00:00 2001 From: admin <weikou2014> Date: 星期三, 20 五月 2020 17:25:08 +0800 Subject: [PATCH] Merge remote-tracking branch 'origin/div' into 2.1.2 --- fanli/src/main/java/com/yeshi/fanli/controller/admin/shop/BanLiShopGoodsAdminController.java | 77 ++++++++++++++++++-------------------- 1 files changed, 37 insertions(+), 40 deletions(-) diff --git a/fanli/src/main/java/com/yeshi/fanli/controller/admin/shop/BanLiShopGoodsAdminController.java b/fanli/src/main/java/com/yeshi/fanli/controller/admin/shop/BanLiShopGoodsAdminController.java index ae3dbe4..3b3fcde 100644 --- a/fanli/src/main/java/com/yeshi/fanli/controller/admin/shop/BanLiShopGoodsAdminController.java +++ b/fanli/src/main/java/com/yeshi/fanli/controller/admin/shop/BanLiShopGoodsAdminController.java @@ -1,29 +1,24 @@ package com.yeshi.fanli.controller.admin.shop; -import java.io.IOException; -import java.io.InputStream; import java.io.PrintWriter; import java.util.ArrayList; import java.util.List; -import java.util.UUID; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartHttpServletRequest; import org.yeshi.utils.JsonUtil; -import org.yeshi.utils.tencentcloud.COSManager; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.reflect.TypeToken; import com.yeshi.fanli.entity.shop.BanLiShopGoods; +import com.yeshi.fanli.entity.shop.BanLiShopGoodsClass; import com.yeshi.fanli.exception.shop.BanLiShopGoodsException; -import com.yeshi.fanli.exception.shop.BanLiShopGoodsSetException; -import com.yeshi.fanli.exception.shop.BanLiShopGoodsSetPayException; +import com.yeshi.fanli.service.inter.shop.BanLiShopGoodsClassService; import com.yeshi.fanli.service.inter.shop.BanLiShopGoodsService; import com.yeshi.fanli.tag.PageEntity; import com.yeshi.fanli.util.Constant; @@ -37,6 +32,9 @@ @Resource private BanLiShopGoodsService banLiShopGoodsService; + + @Resource + private BanLiShopGoodsClassService banLiShopGoodsClassService; /** * 淇濆瓨淇℃伅 @@ -48,50 +46,21 @@ @RequestMapping(value = "save") public void save(String callback, BanLiShopGoods record, HttpServletRequest request, PrintWriter out) { try { - String picture = null; if (request instanceof MultipartHttpServletRequest) { MultipartHttpServletRequest fileRequest = (MultipartHttpServletRequest) request; - MultipartFile file = fileRequest.getFile("file"); - if (file != null) - picture = uploadPicture(file); + banLiShopGoodsService.saveObject(fileRequest.getFile("file"),fileRequest.getFile("file2"), record); + } else { + banLiShopGoodsService.saveObject(null, null,record); } - record.setPicture(picture); - banLiShopGoodsService.addGoods(record); JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult("淇濆瓨鎴愬姛")); } catch (BanLiShopGoodsException e) { JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult(e.getMsg())); - } catch (BanLiShopGoodsSetException e) { - JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult(e.getMsg())); - } catch (BanLiShopGoodsSetPayException e) { - JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult(e.getMsg())); } catch (Exception e) { + e.printStackTrace(); JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("鎿嶄綔寮傚父")); } } - /** - * 涓婁紶鍥剧墖 - * - * @param file - * @return - * @throws Exception - */ - public String uploadPicture(MultipartFile file) throws BanLiShopGoodsException { - // 鏂囦欢瑙f瀽 - InputStream inputStream; - try { - inputStream = file.getInputStream(); - } catch (IOException e) { - e.printStackTrace(); - throw new BanLiShopGoodsException(1, "鍥剧墖鑾峰彇澶辫触"); - } - String contentType = file.getContentType(); - String type = contentType.substring(contentType.indexOf("/") + 1); - // 鏂囦欢璺緞 - String filePath = "/img/HomeNavbar/" + UUID.randomUUID().toString().replace("-", "") + "." + type; - // 鎵ц涓婁紶 - return COSManager.getInstance().uploadFile(inputStream, filePath).getUrl(); - } /** * 鏌ヨ @@ -116,6 +85,13 @@ if (list == null || list.size() == 0) { JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("鏆傛棤鏁版嵁")); return; + } + + for (BanLiShopGoods shopGoods: list) { + BanLiShopGoodsClass goodsClass = shopGoods.getGoodsClass(); + if (goodsClass != null) { + shopGoods.setGoodsClass(banLiShopGoodsClassService.selectByPrimaryKey(goodsClass.getId())); + } } long count = banLiShopGoodsService.countGoods(key, state); @@ -167,4 +143,25 @@ JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("鍒犻櫎澶辫触")); } } + + + /** + * 淇敼鐘舵�� + * @param callback + * @param id + * @param out + */ + @RequestMapping(value = "switchState") + public void switchState(String callback, Long id, PrintWriter out) { + try { + banLiShopGoodsService.switchState(id); + JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult("鎿嶄綔鎴愬姛")); + } catch (BanLiShopGoodsException e) { + JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult(e.getMsg())); + } catch (Exception e) { + JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("鎿嶄綔澶辫触")); + e.printStackTrace(); + } + } + } -- Gitblit v1.8.0