| | |
| | | package com.yeshi.fanli.service.impl.user;
|
| | |
|
| | | import java.io.IOException;
|
| | | import java.io.InputStream;
|
| | | import java.io.Serializable;
|
| | | import java.math.BigDecimal;
|
| | |
| | | import org.springframework.stereotype.Service;
|
| | | import org.springframework.transaction.annotation.Propagation;
|
| | | import org.springframework.transaction.annotation.Transactional;
|
| | | import org.springframework.web.multipart.MultipartFile;
|
| | | import org.yeshi.utils.HttpUtil;
|
| | | import org.yeshi.utils.NumberUtil;
|
| | | import org.yeshi.utils.tencentcloud.COSManager;
|
| | |
| | | return null;
|
| | | }
|
| | |
|
| | | @Override
|
| | | public void uploadPortrait(MultipartFile file,Long uid) throws UserInfoException, IOException {
|
| | | |
| | | UserInfo userInfo = userInfoMapper.selectByPKey(uid);
|
| | | if(userInfo == null) {
|
| | | throw new UserInfoException(1, "用户不存在");
|
| | | }
|
| | | |
| | | String portrait = userInfo.getPortrait();
|
| | | if (portrait != null && portrait.trim().length() > 0 && portrait.contains("/img/user/")) {
|
| | | COSManager.getInstance().deleteFile(portrait);
|
| | | }
|
| | | |
| | | |
| | | // 文件解析 |
| | | 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.updateByPrimaryKey(userInfo);
|
| | | }
|
| | | |
| | | |
| | | @Override
|
| | | public void saveUserInfo(String nickName, Long uid) throws UserInfoException {
|
| | | UserInfo userInfo = userInfoMapper.selectByPKey(uid);
|
| | | if(userInfo == null) {
|
| | | throw new UserInfoException(1, "用户不存在");
|
| | | }
|
| | | |
| | | UserInfo updateInfo = new UserInfo();
|
| | | updateInfo.setId(userInfo.getId());
|
| | | updateInfo.setNickName(nickName);
|
| | | userInfoMapper.updateByPrimaryKeySelective(updateInfo);
|
| | | }
|
| | | }
|