| | |
| | | package com.yeshi.fanli.service.impl.user;
|
| | |
|
| | | import java.io.File;
|
| | | import java.io.IOException;
|
| | | import java.io.InputStream;
|
| | | import java.io.Serializable;
|
| | |
| | | import org.springframework.transaction.annotation.Propagation;
|
| | | import org.springframework.transaction.annotation.Transactional;
|
| | | import org.springframework.web.multipart.MultipartFile;
|
| | | import org.yeshi.utils.FileUtil;
|
| | | import org.yeshi.utils.HttpUtil;
|
| | | import org.yeshi.utils.NumberUtil;
|
| | | import org.yeshi.utils.tencentcloud.COSManager;
|
| | |
| | | import com.yeshi.fanli.util.account.UserUtil;
|
| | | import com.yeshi.fanli.util.wx.WXLoginUtil;
|
| | | import com.yeshi.fanli.vo.user.UserInfoVO;
|
| | |
|
| | | import net.coobird.thumbnailator.Thumbnails;
|
| | |
|
| | | @Service
|
| | | public class UserInfoServiceImpl implements UserInfoService {
|
| | |
| | | throw new UserInfoException(1, "用户不存在");
|
| | | }
|
| | |
|
| | | String portrait = userInfo.getPortrait();
|
| | | if (portrait != null && portrait.trim().length() > 0 && portrait.contains("/img/user/")) {
|
| | | COSManager.getInstance().deleteFile(portrait);
|
| | | // 谷歌压缩图片
|
| | | String targetPath = FileUtil.getCacheDir() + "/uploadPortrait_" + uid + "_" + System.currentTimeMillis() + ".jpg";
|
| | | Thumbnails.of(file.getInputStream()).size(200, 200).toFile(targetPath);
|
| | | |
| | | // 执行上传
|
| | | String filePath="/img/user/" + UUID.randomUUID().toString().replace("-", "") + ".jpg";
|
| | | String fileLink= COSManager.getInstance().uploadFile(new File(targetPath), filePath).getUrl();
|
| | | |
| | | // 删除本地图片
|
| | | if (new File(targetPath).exists()) {
|
| | | new File(targetPath).delete();
|
| | | }
|
| | |
|
| | | // 原头像
|
| | | String portrait = userInfo.getPortrait();
|
| | |
|
| | | // 文件解析 |
| | | InputStream inputStream = file.getInputStream();
|
| | | String contentType = file.getContentType();
|
| | | String type = contentType.substring(contentType.indexOf("/") + 1);
|
| | | |
| | | // 文件路径
|
| | | String filePath="/img/user/"+UUID.randomUUID().toString().replace("-", "") + "." + type;
|
| | | // 执行上传
|
| | | String fileLink= COSManager.getInstance().uploadFile(inputStream, filePath).getUrl();
|
| | | |
| | | // 更新信息
|
| | | userInfo.setPortrait(fileLink);
|
| | | userInfoMapper.updateByPrimaryKeySelective(userInfo);
|
| | |
|
| | | // 删除原头像
|
| | | if (!StringUtil.isNullOrEmpty(portrait) && portrait.contains("/img/user/")) {
|
| | | COSManager.getInstance().deleteFile(portrait);
|
| | | }
|
| | |
|
| | | executor.execute(new Runnable() {
|
| | | @Override
|
| | |
| | | }
|
| | | }
|
| | | });
|
| | | |
| | | }
|
| | |
|
| | |
|