From 30d8e227e8d823b6c38c3b9c90ac2df03b63befe Mon Sep 17 00:00:00 2001 From: admin <weikou2014> Date: 星期二, 25 二月 2025 16:41:22 +0800 Subject: [PATCH] 淘宝转链接口更新 --- fanli/src/main/java/com/yeshi/fanli/service/impl/config/SpreadImgServiceImpl.java | 224 +++++++++++++++++++++++++++++-------------------------- 1 files changed, 117 insertions(+), 107 deletions(-) diff --git a/fanli/src/main/java/com/yeshi/fanli/service/impl/config/SpreadImgServiceImpl.java b/fanli/src/main/java/com/yeshi/fanli/service/impl/config/SpreadImgServiceImpl.java index 5776b75..5848d5e 100644 --- a/fanli/src/main/java/com/yeshi/fanli/service/impl/config/SpreadImgServiceImpl.java +++ b/fanli/src/main/java/com/yeshi/fanli/service/impl/config/SpreadImgServiceImpl.java @@ -1,107 +1,117 @@ -package com.yeshi.fanli.service.impl.config; - -import java.io.InputStream; -import java.util.Date; -import java.util.List; -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.user.SpreadImgMapper; -import com.yeshi.fanli.entity.bus.invite.SpreadImg; -import com.yeshi.fanli.service.inter.config.SpreadImgService; - -@Service -public class SpreadImgServiceImpl implements SpreadImgService { - - @Resource - private SpreadImgMapper spreadImgMapper; - - - @Override - public void deleteInviteFriendImg(long id) { - spreadImgMapper.deleteByPrimaryKey(id); - } - - @Override - public SpreadImg getInviteSpreadImg(long id) { - return spreadImgMapper.selectByPrimaryKey(id); - } - - @Override - public void saveObject(MultipartFile file, SpreadImg record) throws Exception{ - - String picture = null; - if (file != null) { - picture = uploadPicture(file); - } - - Long id = record.getId(); - if (id == null) { - record.setUrl(picture); - record.setCreatetime(new Date()); - spreadImgMapper.insert(record); - } else { - // 淇敼 - SpreadImg resultObj = spreadImgMapper.selectByPrimaryKey(id); - if (resultObj == null) { - throw new Exception("淇敼鍐呭宸蹭笉瀛樺湪"); - } - - if (picture != null && picture.trim().length() > 0) { - // 鍒犻櫎宸插瓨鍦ㄥ浘鐗� - removePicture(resultObj.getUrl()); - record.setUrl(picture); - } else { - record.setUrl(resultObj.getUrl()); - } - - record.setCreatetime(resultObj.getCreatetime()); - spreadImgMapper.updateByPrimaryKey(record); - } - } - - /** - * 涓婁紶鍥剧墖 - * @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/invite/"+UUID.randomUUID().toString().replace("-", "") + "." + type; - // 鎵ц涓婁紶 - return COSManager.getInstance().uploadFile(inputStream, filePath).getUrl(); - } - - /** - * 鍒犻櫎鍥剧墖 - * @param record - * @throws Exception - */ - public void removePicture(String picture) throws Exception { - if (picture != null && picture.trim().length() > 0) { - COSManager.getInstance().deleteFile(picture); - } - } - - @Override - public List<SpreadImg> listQuery(int start, int pageSize, String key) { - return spreadImgMapper.listQuery(start, pageSize, key); - } - - @Override - public long countQuery(String key) { - return spreadImgMapper.countQuery(key); - } - -} +package com.yeshi.fanli.service.impl.config; + +import java.io.InputStream; +import java.util.Date; +import java.util.List; +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.user.SpreadImgMapper; +import com.yeshi.fanli.entity.bus.invite.SpreadImg; +import com.yeshi.fanli.service.inter.config.SpreadImgService; +import com.yeshi.fanli.util.FilePathEnum; + +@Service +public class SpreadImgServiceImpl implements SpreadImgService { + + @Resource + private SpreadImgMapper spreadImgMapper; + + + @Override + public void deleteInviteFriendImg(long id) { + spreadImgMapper.deleteByPrimaryKey(id); + } + + @Override + public SpreadImg getInviteSpreadImg(long id) { + return spreadImgMapper.selectByPrimaryKey(id); + } + + @Override + public void saveObject(MultipartFile file, SpreadImg record) throws Exception{ + + String picture = null; + if (file != null) { + picture = uploadPicture(file); + } + + Long id = record.getId(); + if (id == null) { + record.setUrl(picture); + record.setCreatetime(new Date()); + spreadImgMapper.insert(record); + } else { + // 淇敼 + SpreadImg resultObj = spreadImgMapper.selectByPrimaryKey(id); + if (resultObj == null) { + throw new Exception("淇敼鍐呭宸蹭笉瀛樺湪"); + } + + if (picture != null && picture.trim().length() > 0) { + // 鍒犻櫎宸插瓨鍦ㄥ浘鐗� + removePicture(resultObj.getUrl()); + record.setUrl(picture); + } else { + record.setUrl(resultObj.getUrl()); + } + + record.setCreatetime(resultObj.getCreatetime()); + spreadImgMapper.updateByPrimaryKey(record); + } + } + + /** + * 涓婁紶鍥剧墖 + * @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=FilePathEnum.invite.getPath() + UUID.randomUUID().toString().replace("-", "") + "." + type; + // 鎵ц涓婁紶 + return COSManager.getInstance().uploadFile(inputStream, filePath).getUrl(); + } + + /** + * 鍒犻櫎鍥剧墖 + * @param record + * @throws Exception + */ + public void removePicture(String picture) throws Exception { + if (picture != null && picture.trim().length() > 0) { + COSManager.getInstance().deleteFile(picture); + } + } + + @Override + public List<SpreadImg> listQuery(int start, int pageSize, String key) { + return spreadImgMapper.listQuery(start, pageSize, key); + } + + @Override + public long countQuery(String key) { + return spreadImgMapper.countQuery(key); + } + + @Override + public List<SpreadImg> listAll() { + return spreadImgMapper.listAll(); + } + + @Override + public long countAll() { + return spreadImgMapper.countAll(); + } +} -- Gitblit v1.8.0