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.domain.vo.SysOssVo;
|
||||||
import com.ruoyi.system.service.ISysOssService;
|
import com.ruoyi.system.service.ISysOssService;
|
||||||
import io.swagger.v3.oas.annotations.Operation;
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
|
import io.swagger.v3.oas.annotations.Parameter;
|
||||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.http.MediaType;
|
import org.springframework.http.MediaType;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
@@ -20,14 +22,22 @@ import org.springframework.web.multipart.MultipartFile;
|
|||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/api/file")
|
@RequestMapping("/api/file")
|
||||||
@Tag(name = "文件接口")
|
@Tag(name = "文件接口")
|
||||||
|
@Slf4j
|
||||||
public class FileController {
|
public class FileController {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private ISysOssService iSysOssService;
|
private ISysOssService iSysOssService;
|
||||||
|
|
||||||
@Log(title = "OSS对象存储", businessType = BusinessType.INSERT)
|
@Log(title = "OSS对象存储", businessType = BusinessType.INSERT)
|
||||||
@PostMapping(value = "/upload", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
@PostMapping(value = "/upload", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
||||||
@Operation(summary = "上传文件")
|
@Operation(summary = "上传文件",
|
||||||
public R<FileResp> upload(@RequestPart("file") MultipartFile file) {
|
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)) {
|
if (ObjectUtil.isNull(file)) {
|
||||||
return R.fail("上传文件不能为空");
|
return R.fail("上传文件不能为空");
|
||||||
}
|
}
|
||||||
@@ -38,4 +48,27 @@ public class FileController {
|
|||||||
resp.setOriginalName(oss.getOriginalName());
|
resp.setOriginalName(oss.getOriginalName());
|
||||||
return R.ok(resp);
|
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
|
@Autowired
|
||||||
private DynamicService dynamicService;
|
private DynamicService dynamicService;
|
||||||
@Autowired
|
|
||||||
private UserFollowDynamicService userFollowDynamicService;
|
|
||||||
|
|
||||||
@GetMapping("/page")
|
@GetMapping("/page")
|
||||||
@Operation(summary = "动态查询动态")
|
@Operation(summary = "动态查询动态")
|
||||||
@@ -37,24 +35,6 @@ public class UserDynamicAppController {
|
|||||||
return R.ok(resp.getRecords());
|
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")
|
@PostMapping("/push")
|
||||||
@Operation(summary = "发布动态")
|
@Operation(summary = "发布动态")
|
||||||
@Log(title = "发布动态", businessType = BusinessType.OTHER, isSaveDb = false)
|
@Log(title = "发布动态", businessType = BusinessType.OTHER, isSaveDb = false)
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ import java.time.LocalDateTime;
|
|||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
@TableName("cai_user_follow_dynamic")
|
@TableName("cai_user_follow_dynamic")
|
||||||
|
@Deprecated
|
||||||
public class UserFollowDynamic implements Serializable {
|
public class UserFollowDynamic implements Serializable {
|
||||||
|
|
||||||
private static final long serialVersionUID=1L;
|
private static final long serialVersionUID=1L;
|
||||||
|
|||||||
@@ -30,16 +30,19 @@ public class DynamicAddReq {
|
|||||||
*/
|
*/
|
||||||
@Schema(description = "是否有附件")
|
@Schema(description = "是否有附件")
|
||||||
private Integer isAttach;
|
private Integer isAttach;
|
||||||
|
@Schema(description = "照片列表")
|
||||||
|
private List<DynamicImageVo> imageList;
|
||||||
/**
|
/**
|
||||||
* 状态 0 审核中 1可用 2 不可用
|
* 状态 0 审核中 1可用 2 不可用
|
||||||
*/
|
*/
|
||||||
|
@Schema(hidden = true)
|
||||||
private Integer status;
|
private Integer status;
|
||||||
/**
|
/**
|
||||||
* 排序字段
|
* 排序字段
|
||||||
*/
|
*/
|
||||||
|
@Schema(hidden = true)
|
||||||
private Long sort;
|
private Long sort;
|
||||||
|
@Schema(hidden = true)
|
||||||
private LocalDateTime createTime;
|
private LocalDateTime createTime;
|
||||||
@Schema(description = "照片列表")
|
|
||||||
private List<DynamicImageVo> imageList;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import java.time.LocalDateTime;
|
|||||||
@Data
|
@Data
|
||||||
public class DynamicImageVo {
|
public class DynamicImageVo {
|
||||||
|
|
||||||
|
@Schema(hidden = true)
|
||||||
private Long id;
|
private Long id;
|
||||||
/**
|
/**
|
||||||
* 用户ID
|
* 用户ID
|
||||||
@@ -17,6 +18,7 @@ public class DynamicImageVo {
|
|||||||
/**
|
/**
|
||||||
* 动态ID
|
* 动态ID
|
||||||
*/
|
*/
|
||||||
|
@Schema(hidden = true)
|
||||||
private Long dynamicId;
|
private Long dynamicId;
|
||||||
/**
|
/**
|
||||||
* 物理路径
|
* 物理路径
|
||||||
@@ -27,12 +29,12 @@ public class DynamicImageVo {
|
|||||||
* 宽度
|
* 宽度
|
||||||
*/
|
*/
|
||||||
@Schema(description = "宽度")
|
@Schema(description = "宽度")
|
||||||
private Long width;
|
private Integer width;
|
||||||
/**
|
/**
|
||||||
* 高度
|
* 高度
|
||||||
*/
|
*/
|
||||||
@Schema(description = "高度")
|
@Schema(description = "高度")
|
||||||
private Long height;
|
private Integer height;
|
||||||
/**
|
/**
|
||||||
* 图片大小
|
* 图片大小
|
||||||
*/
|
*/
|
||||||
@@ -44,5 +46,6 @@ public class DynamicImageVo {
|
|||||||
@Schema(description = "类型")
|
@Schema(description = "类型")
|
||||||
private String exts;
|
private String exts;
|
||||||
|
|
||||||
|
@Schema(hidden = true)
|
||||||
private LocalDateTime createTime;
|
private LocalDateTime createTime;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,6 +21,6 @@ public class DynamicListVo extends DynamicVo{
|
|||||||
private String avatar;
|
private String avatar;
|
||||||
@Schema(description = "昵称")
|
@Schema(description = "昵称")
|
||||||
private String nickname;
|
private String nickname;
|
||||||
@Schema(description = "是否点赞")
|
@Schema(description = "是否关注用户")
|
||||||
private boolean star;
|
private boolean star;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import com.ruoyi.cai.domain.UserFollowDynamic;
|
|||||||
* @author 77
|
* @author 77
|
||||||
* @date 2023-12-23
|
* @date 2023-12-23
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public interface UserFollowDynamicMapper extends BaseMapper<UserFollowDynamic> {
|
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.DynamicImagesService;
|
||||||
import com.ruoyi.cai.service.DynamicService;
|
import com.ruoyi.cai.service.DynamicService;
|
||||||
import com.ruoyi.cai.service.UserService;
|
import com.ruoyi.cai.service.UserService;
|
||||||
|
import com.ruoyi.cai.util.CaiFileUtils;
|
||||||
import com.ruoyi.common.core.domain.PageQuery;
|
import com.ruoyi.common.core.domain.PageQuery;
|
||||||
import com.ruoyi.common.exception.ServiceException;
|
import com.ruoyi.common.exception.ServiceException;
|
||||||
import com.ruoyi.common.utils.BeanConvertUtil;
|
import com.ruoyi.common.utils.BeanConvertUtil;
|
||||||
@@ -108,6 +109,10 @@ public class DynamicServiceImpl extends ServiceImpl<DynamicMapper, Dynamic> impl
|
|||||||
List<DynamicImageVo> imageList = res.getImageList();
|
List<DynamicImageVo> imageList = res.getImageList();
|
||||||
if(CollectionUtil.isNotEmpty(imageList)){
|
if(CollectionUtil.isNotEmpty(imageList)){
|
||||||
for (DynamicImageVo imageVo : 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.setDynamicId(dynamic.getId());
|
||||||
imageVo.setUserId(dynamic.getUserId());
|
imageVo.setUserId(dynamic.getUserId());
|
||||||
imageVo.setId(null);
|
imageVo.setId(null);
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import org.springframework.stereotype.Service;
|
|||||||
*/
|
*/
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
@Service
|
@Service
|
||||||
|
@Deprecated
|
||||||
public class UserFollowDynamicServiceImpl extends ServiceImpl<UserFollowDynamicMapper, UserFollowDynamic> implements UserFollowDynamicService {
|
public class UserFollowDynamicServiceImpl extends ServiceImpl<UserFollowDynamicMapper, UserFollowDynamic> implements UserFollowDynamicService {
|
||||||
|
|
||||||
@Autowired
|
@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();
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -19,7 +19,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||||||
t1.id,t1.user_id,t1.city_id,t1.city,t1.is_attach,t1.audit_status,t1.create_time,t1.content
|
t1.id,t1.user_id,t1.city_id,t1.city,t1.is_attach,t1.audit_status,t1.create_time,t1.content
|
||||||
from cai_dynamic t1
|
from cai_dynamic t1
|
||||||
left join cai_user t2 on t1.user_id = t2.id
|
left join cai_user t2 on t1.user_id = t2.id
|
||||||
left join cai_user_follow_dynamic t3 on t1.id = t3.dynamic_id and t3.user_id = #{query.currentUserId}
|
left join cai_user_follow t3 on t1.user_id = t3.follow_user and t3.user_id = #{query.currentUserId}
|
||||||
where t1.audit_status = 2 and t2.status = 0
|
where t1.audit_status = 2 and t2.status = 0
|
||||||
<if test="query.userId != null">
|
<if test="query.userId != null">
|
||||||
and t1.user_id = #{query.userId}
|
and t1.user_id = #{query.userId}
|
||||||
|
|||||||
Reference in New Issue
Block a user