|
@@ -7,6 +7,7 @@ import cn.hutool.core.collection.CollectionUtil;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import com.aliyun.oss.OSSClient;
|
|
|
+import com.aliyun.oss.model.PutObjectResult;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
@@ -55,6 +56,7 @@ import javax.validation.Validator;
|
|
|
import javax.validation.constraints.NotNull;
|
|
|
import java.io.File;
|
|
|
import java.io.IOException;
|
|
|
+import java.io.InputStream;
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
@@ -99,6 +101,10 @@ public class UserController {
|
|
|
@ApiOperation(value = "查询用户")
|
|
|
public ResponseEntity queryById(@RequestParam("id") String id) {
|
|
|
UserDTO userDTO = userService.get ( id );
|
|
|
+ if (ObjectUtil.isNotEmpty(userDTO) && StringUtils.isNotBlank(userDTO.getPhoto())) {
|
|
|
+ String lsUrl = UserUtils.getLsUrl(userDTO.getPhoto());
|
|
|
+ userDTO.setPhoto(lsUrl);
|
|
|
+ }
|
|
|
if(StringUtils.isNotBlank(userDTO.getManageOfficeIds())){
|
|
|
//获取当前人管理的部门id
|
|
|
List<String> manageOfficeIdList=Arrays.asList(userDTO.getManageOfficeIds().split(","));
|
|
@@ -493,15 +499,16 @@ public class UserController {
|
|
|
if ( !file.isEmpty ( ) ) {
|
|
|
if ( fileProperties.isImage ( file.getOriginalFilename ( ) ) ) {
|
|
|
// 文件保存路径
|
|
|
- String realPath = FileKit.getAttachmentDir ( ) + "sys/user/images/";
|
|
|
- // 转存文件
|
|
|
- FileUtils.createDirectory ( realPath );
|
|
|
- file.transferTo ( new File ( realPath + file.getOriginalFilename ( ) ) );
|
|
|
- User user = new User ( userId );
|
|
|
- user.setPhoto ( FileKit.getAttachmentUrl ( ) + "sys/user/images/" + file.getOriginalFilename ( ) );
|
|
|
- userService.updateById ( user );
|
|
|
- UserUtils.deleteCache ( UserUtils.getCurrentUserDTO ( ) );
|
|
|
- return ResponseUtil.newInstance ( ).add ( "path", FileKit.getAttachmentUrl ( ) + "sys/user/images/" + file.getOriginalFilename ( ) ).ok ( "上传成功!" );
|
|
|
+ String realPath = "attachment-file"+"/"+"user_avatar"+this.datePath()+"/"+ System.currentTimeMillis();
|
|
|
+ //文件原名称
|
|
|
+ String newName = file.getOriginalFilename();
|
|
|
+ this.uploadFile(file.getInputStream(),realPath,newName); // 文件上传到oss
|
|
|
+ String filePath = realPath + newName;
|
|
|
+ userService.updateAvatarById ( userId,filePath ); // 修改头像
|
|
|
+ String url = aliyunUrl + "/" + realPath + newName;
|
|
|
+ String lsUrl = UserUtils.getLsUrl(url); // 获取头像临时地址
|
|
|
+ // 获取临时头像地址
|
|
|
+ return ResponseUtil.newInstance ( ).add ( "path", lsUrl ).ok ( "上传成功!" );
|
|
|
} else {
|
|
|
return ResponseEntity.badRequest ( ).body ( "请上传图片!" );
|
|
|
}
|
|
@@ -779,4 +786,32 @@ public class UserController {
|
|
|
Boolean updatePassword = userService.isUpdatePassword(userDTO.getId());
|
|
|
return ResponseEntity.ok(updatePassword);
|
|
|
}
|
|
|
+
|
|
|
+ public String uploadFile(InputStream inStream, String fileDir, String fileName) {
|
|
|
+ //初始化OSSClient
|
|
|
+ OSSClient ossClient = new OSSClient(endpoint,accessKeyId,accessKeySecret);
|
|
|
+// long start = System.currentTimeMillis();
|
|
|
+ //上传文件
|
|
|
+ PutObjectResult putResult = ossClient.putObject(bucketName, fileDir + fileName, inStream);
|
|
|
+ String ret = putResult.getETag();
|
|
|
+
|
|
|
+ try {
|
|
|
+ if (inStream != null) {
|
|
|
+ inStream.close();
|
|
|
+ }
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+// long end = System.currentTimeMillis();
|
|
|
+// log.info("上传文件到云服务器成功,文件名:{},耗时:{}ms",fileName,end-start);
|
|
|
+ return ret;
|
|
|
+ }
|
|
|
+ public String datePath(){
|
|
|
+ Calendar date = Calendar.getInstance();
|
|
|
+ String year = String.valueOf(date.get(Calendar.YEAR));
|
|
|
+ String month = String.valueOf(date.get(Calendar.MONTH)+1);
|
|
|
+ String day = String.valueOf(date.get(Calendar.DAY_OF_MONTH));
|
|
|
+ String path = "/"+year+"/"+month+"/"+day;
|
|
|
+ return path;
|
|
|
+ }
|
|
|
}
|