From 77602de9c796b5fd42b74003727d934df14152fa Mon Sep 17 00:00:00 2001 From: yujian <yujian> Date: 星期五, 26 四月 2019 12:24:28 +0800 Subject: [PATCH] 品牌店铺信息管理 +前端接口 --- fanli/src/main/java/com/yeshi/fanli/service/impl/taobao/TaoBaoShopServiceImpl.java | 80 ++++++++++++++++++++++++++++++++++++++++ 1 files changed, 80 insertions(+), 0 deletions(-) diff --git a/fanli/src/main/java/com/yeshi/fanli/service/impl/taobao/TaoBaoShopServiceImpl.java b/fanli/src/main/java/com/yeshi/fanli/service/impl/taobao/TaoBaoShopServiceImpl.java index 483a5a3..73957b9 100644 --- a/fanli/src/main/java/com/yeshi/fanli/service/impl/taobao/TaoBaoShopServiceImpl.java +++ b/fanli/src/main/java/com/yeshi/fanli/service/impl/taobao/TaoBaoShopServiceImpl.java @@ -1,13 +1,21 @@ package com.yeshi.fanli.service.impl.taobao; +import java.io.InputStream; +import java.util.UUID; + import javax.annotation.Resource; import org.springframework.stereotype.Service; +import org.springframework.web.multipart.MultipartFile; +import org.yeshi.utils.tencentcloud.COSManager; +import com.yeshi.fanli.dao.mybatis.taobao.TaoBaoShopMapper; import com.yeshi.fanli.entity.taobao.TaoBaoGoodsBrief; +import com.yeshi.fanli.entity.taobao.TaoBaoShop; import com.yeshi.fanli.entity.taobao.TaoBaoShopInfo; import com.yeshi.fanli.log.LogHelper; import com.yeshi.fanli.service.inter.taobao.TaoBaoShopService; +import com.yeshi.fanli.util.StringUtil; import com.yeshi.fanli.util.db.MongoDBManager; import com.yeshi.fanli.util.taobao.TaoBaoShopUtil; @@ -16,6 +24,9 @@ @Resource private MongoDBManager mongoDBManager; + + @Resource + private TaoBaoShopMapper taoBaoShopMapper; @Override public TaoBaoShopInfo getTaoBaoShopInfo(TaoBaoGoodsBrief goodsInfo) { @@ -44,7 +55,76 @@ } + @Override + public TaoBaoShop selectByPrimaryKey(Long id) { + return taoBaoShopMapper.selectByPrimaryKey(id); + } + + + @Override + public int insertSelective(TaoBaoShop record) { + return taoBaoShopMapper.insertSelective(record); + } + + + @Override + public int updateByPrimaryKeySelective(TaoBaoShop record) { + return taoBaoShopMapper.updateByPrimaryKeySelective(record); + } + @Override + public void changeInfo(MultipartFile file, Long id, String shopName) { + TaoBaoShop taoBaoShop = taoBaoShopMapper.selectByPrimaryKey(id); + if (taoBaoShop == null) { + return; + } + + String fileLink = null; + if (file != null) { + try { + fileLink = uploadPicture(file); + } catch (Exception e) { + e.printStackTrace(); + } + } + + TaoBaoShop updateShop = new TaoBaoShop(); + if (!StringUtil.isNullOrEmpty(fileLink)) { + updateShop.setShopIconCustom(fileLink); + + // 鍒犻櫎鍥剧墖 + String shopIconCustom = taoBaoShop.getShopIconCustom(); + if (!StringUtil.isNullOrEmpty(shopIconCustom)) { + COSManager.getInstance().deleteFile(shopIconCustom); + } + } + + updateShop.setId(id); + updateShop.setShopName(shopName); + taoBaoShopMapper.updateByPrimaryKeySelective(updateShop); + } + + + /** + * 涓婁紶鍥剧墖 + * @param file + * @return + * @throws Exception + */ + public String uploadPicture(MultipartFile file) throws Exception { + // 鏂囦欢瑙f瀽 + InputStream inputStream = file.getInputStream(); + String contentType = file.getContentType(); + String type = contentType.substring(contentType.indexOf("/") + 1); + + // 鏂囦欢璺緞 + String filePath="/img/TaoBaoShop/"+UUID.randomUUID().toString().replace("-", "") + "." + type; + // 鎵ц涓婁紶 + String fileLink= COSManager.getInstance().uploadFile(inputStream, filePath).getUrl(); + + return fileLink; + } + } -- Gitblit v1.8.0