init
This commit is contained in:
@@ -8,7 +8,9 @@ import com.ruoyi.common.enums.BusinessType;
|
||||
import com.ruoyi.system.domain.vo.SysOssVo;
|
||||
import com.ruoyi.system.service.ISysOssService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
@@ -20,14 +22,22 @@ import org.springframework.web.multipart.MultipartFile;
|
||||
@RestController
|
||||
@RequestMapping("/api/file")
|
||||
@Tag(name = "文件接口")
|
||||
@Slf4j
|
||||
public class FileController {
|
||||
|
||||
@Autowired
|
||||
private ISysOssService iSysOssService;
|
||||
|
||||
@Log(title = "OSS对象存储", businessType = BusinessType.INSERT)
|
||||
@PostMapping(value = "/upload", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
||||
@Operation(summary = "上传文件")
|
||||
public R<FileResp> upload(@RequestPart("file") MultipartFile file) {
|
||||
@Operation(summary = "上传文件",
|
||||
parameters = {
|
||||
@Parameter(name = "file", description = "文件", required = true),
|
||||
@Parameter(name = "type", description = "业务类型,dynamic=动态图片,user=用户相册,头像,im=聊天,common=其他", required = false)
|
||||
})
|
||||
public R<FileResp> upload(@RequestPart("file") MultipartFile file,
|
||||
String type) {
|
||||
log.error("上传文件图片类型 type={}",type);
|
||||
if (ObjectUtil.isNull(file)) {
|
||||
return R.fail("上传文件不能为空");
|
||||
}
|
||||
@@ -38,4 +48,27 @@ public class FileController {
|
||||
resp.setOriginalName(oss.getOriginalName());
|
||||
return R.ok(resp);
|
||||
}
|
||||
|
||||
|
||||
@Log(title = "OSS对象存储", businessType = BusinessType.INSERT)
|
||||
@PostMapping(value = "/uploadImage", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
||||
@Operation(summary = "上传图片类型的文件",
|
||||
parameters = {
|
||||
@Parameter(name = "file", description = "文件", required = true),
|
||||
@Parameter(name = "type", description = "业务类型,dynamic=动态图片,user=用户相册,头像,im=聊天,common=其他", required = false)
|
||||
})
|
||||
public R<FileResp> uploadImage(@RequestPart("file") MultipartFile file,
|
||||
String type) {
|
||||
log.error("上传文件图片类型 type={}",type);
|
||||
if (ObjectUtil.isNull(file)) {
|
||||
return R.fail("上传文件不能为空");
|
||||
}
|
||||
SysOssVo oss = iSysOssService.upload(file);
|
||||
FileResp resp = new FileResp();
|
||||
resp.setUrl(oss.getUrl());
|
||||
resp.setPath(oss.getFileName());
|
||||
resp.setOriginalName(oss.getOriginalName());
|
||||
return R.ok(resp);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -26,8 +26,6 @@ public class UserDynamicAppController {
|
||||
|
||||
@Autowired
|
||||
private DynamicService dynamicService;
|
||||
@Autowired
|
||||
private UserFollowDynamicService userFollowDynamicService;
|
||||
|
||||
@GetMapping("/page")
|
||||
@Operation(summary = "动态查询动态")
|
||||
@@ -37,24 +35,6 @@ public class UserDynamicAppController {
|
||||
return R.ok(resp.getRecords());
|
||||
}
|
||||
|
||||
@PostMapping("/star")
|
||||
@Operation(summary = "关注动态")
|
||||
@Log(title = "关注动态", businessType = BusinessType.OTHER, isSaveDb = false)
|
||||
public R<Void> star(@RequestBody DynamicStarReq query){
|
||||
query.setUserId(LoginHelper.getUserId());
|
||||
userFollowDynamicService.star(query);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
@PostMapping("/unstar")
|
||||
@Operation(summary = "取消关注动态")
|
||||
@Log(title = "取消关注动态", businessType = BusinessType.OTHER, isSaveDb = false)
|
||||
public R<Void> unStar(@RequestBody DynamicStarReq query){
|
||||
query.setUserId(LoginHelper.getUserId());
|
||||
userFollowDynamicService.unStar(query);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
@PostMapping("/push")
|
||||
@Operation(summary = "发布动态")
|
||||
@Log(title = "发布动态", businessType = BusinessType.OTHER, isSaveDb = false)
|
||||
|
||||
@@ -16,6 +16,7 @@ import java.time.LocalDateTime;
|
||||
*/
|
||||
@Data
|
||||
@TableName("cai_user_follow_dynamic")
|
||||
@Deprecated
|
||||
public class UserFollowDynamic implements Serializable {
|
||||
|
||||
private static final long serialVersionUID=1L;
|
||||
|
||||
@@ -30,16 +30,19 @@ public class DynamicAddReq {
|
||||
*/
|
||||
@Schema(description = "是否有附件")
|
||||
private Integer isAttach;
|
||||
@Schema(description = "照片列表")
|
||||
private List<DynamicImageVo> imageList;
|
||||
/**
|
||||
* 状态 0 审核中 1可用 2 不可用
|
||||
*/
|
||||
@Schema(hidden = true)
|
||||
private Integer status;
|
||||
/**
|
||||
* 排序字段
|
||||
*/
|
||||
@Schema(hidden = true)
|
||||
private Long sort;
|
||||
|
||||
@Schema(hidden = true)
|
||||
private LocalDateTime createTime;
|
||||
@Schema(description = "照片列表")
|
||||
private List<DynamicImageVo> imageList;
|
||||
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import java.time.LocalDateTime;
|
||||
@Data
|
||||
public class DynamicImageVo {
|
||||
|
||||
@Schema(hidden = true)
|
||||
private Long id;
|
||||
/**
|
||||
* 用户ID
|
||||
@@ -17,6 +18,7 @@ public class DynamicImageVo {
|
||||
/**
|
||||
* 动态ID
|
||||
*/
|
||||
@Schema(hidden = true)
|
||||
private Long dynamicId;
|
||||
/**
|
||||
* 物理路径
|
||||
@@ -27,12 +29,12 @@ public class DynamicImageVo {
|
||||
* 宽度
|
||||
*/
|
||||
@Schema(description = "宽度")
|
||||
private Long width;
|
||||
private Integer width;
|
||||
/**
|
||||
* 高度
|
||||
*/
|
||||
@Schema(description = "高度")
|
||||
private Long height;
|
||||
private Integer height;
|
||||
/**
|
||||
* 图片大小
|
||||
*/
|
||||
@@ -44,5 +46,6 @@ public class DynamicImageVo {
|
||||
@Schema(description = "类型")
|
||||
private String exts;
|
||||
|
||||
@Schema(hidden = true)
|
||||
private LocalDateTime createTime;
|
||||
}
|
||||
|
||||
@@ -21,6 +21,6 @@ public class DynamicListVo extends DynamicVo{
|
||||
private String avatar;
|
||||
@Schema(description = "昵称")
|
||||
private String nickname;
|
||||
@Schema(description = "是否点赞")
|
||||
@Schema(description = "是否关注用户")
|
||||
private boolean star;
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import com.ruoyi.cai.domain.UserFollowDynamic;
|
||||
* @author 77
|
||||
* @date 2023-12-23
|
||||
*/
|
||||
@Deprecated
|
||||
public interface UserFollowDynamicMapper extends BaseMapper<UserFollowDynamic> {
|
||||
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ import com.ruoyi.cai.service.CitysService;
|
||||
import com.ruoyi.cai.service.DynamicImagesService;
|
||||
import com.ruoyi.cai.service.DynamicService;
|
||||
import com.ruoyi.cai.service.UserService;
|
||||
import com.ruoyi.cai.util.CaiFileUtils;
|
||||
import com.ruoyi.common.core.domain.PageQuery;
|
||||
import com.ruoyi.common.exception.ServiceException;
|
||||
import com.ruoyi.common.utils.BeanConvertUtil;
|
||||
@@ -108,6 +109,10 @@ public class DynamicServiceImpl extends ServiceImpl<DynamicMapper, Dynamic> impl
|
||||
List<DynamicImageVo> imageList = res.getImageList();
|
||||
if(CollectionUtil.isNotEmpty(imageList)){
|
||||
for (DynamicImageVo imageVo : imageList) {
|
||||
CaiFileUtils.FileSize fileSize = CaiFileUtils.getFileSize(imageVo.getUrl());
|
||||
imageVo.setHeight(fileSize.getHeight());
|
||||
imageVo.setWidth(fileSize.getWidth());
|
||||
imageVo.setExts(fileSize.getSuffix());
|
||||
imageVo.setDynamicId(dynamic.getId());
|
||||
imageVo.setUserId(dynamic.getUserId());
|
||||
imageVo.setId(null);
|
||||
|
||||
@@ -20,6 +20,7 @@ import org.springframework.stereotype.Service;
|
||||
*/
|
||||
@RequiredArgsConstructor
|
||||
@Service
|
||||
@Deprecated
|
||||
public class UserFollowDynamicServiceImpl extends ServiceImpl<UserFollowDynamicMapper, UserFollowDynamic> implements UserFollowDynamicService {
|
||||
|
||||
@Autowired
|
||||
|
||||
41
ruoyi-cai/src/main/java/com/ruoyi/cai/util/CaiFileUtils.java
Normal file
41
ruoyi-cai/src/main/java/com/ruoyi/cai/util/CaiFileUtils.java
Normal file
@@ -0,0 +1,41 @@
|
||||
package com.ruoyi.cai.util;
|
||||
|
||||
import com.ruoyi.common.utils.StringUtils;
|
||||
import lombok.Data;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.net.URL;
|
||||
|
||||
@Slf4j
|
||||
public class CaiFileUtils {
|
||||
|
||||
@Data
|
||||
public static class FileSize {
|
||||
private int width = 500;
|
||||
private int height = 500;
|
||||
private String suffix;
|
||||
}
|
||||
|
||||
private static String BASE_URL = "https://nono-1257812345.cos.ap-shanghai.myqcloud.com/";
|
||||
|
||||
public static FileSize getFileSize(String url){
|
||||
FileSize fileSize = new FileSize();
|
||||
String suffix = StringUtils.substring(url, url.lastIndexOf("."), url.length());
|
||||
fileSize.setSuffix(suffix);
|
||||
try {
|
||||
URL imageUrl = new URL(BASE_URL+url); // 替换为实际的图片 URL
|
||||
BufferedImage image = ImageIO.read(imageUrl);
|
||||
int width = image.getWidth();
|
||||
int height = image.getHeight();
|
||||
fileSize.setWidth(width);
|
||||
fileSize.setHeight(height);
|
||||
return fileSize;
|
||||
}catch (Exception e){
|
||||
log.error("获取文件图片大小失败",e);
|
||||
}
|
||||
return new FileSize();
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user