Commit 1d86fd9f authored by 刘基明's avatar 刘基明

编辑接口

parent a74a2161
package com.tanpu.community.api.beans.qo;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@Data
public class MyCommentThemeQo extends ThemeQo{
@ApiModelProperty(value = "评论内容")
private String comment;
}
...@@ -7,7 +7,7 @@ import lombok.Builder; ...@@ -7,7 +7,7 @@ import lombok.Builder;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
@ApiModel(value = "创建主题") @ApiModel(value = "创建主题返回值")
@Data @Data
@Builder @Builder
@NoArgsConstructor @NoArgsConstructor
......
package com.tanpu.community.api.beans.resp;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
@ApiModel(value = "文件上传返回")
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class FileUploadResp {
@ApiModelProperty(value = "文件id")
private String fileId;
@ApiModelProperty(value = "文件url")
private String url;
@ApiModelProperty(value = "图片高度")
private Integer imgHeight;
@ApiModelProperty(value = "图片宽度")
private Integer imgWidth;
@ApiModelProperty(value = "类型:1:图片")
private Integer fileType;
@ApiModelProperty(value = "文件名称")
private String fileName;
@ApiModelProperty(value = "阿里云key")
private String fileOssKey;
@ApiModelProperty(value = "预览url")
private String previewUrl;
}
...@@ -19,8 +19,7 @@ public class ImagesDTO { ...@@ -19,8 +19,7 @@ public class ImagesDTO {
@ApiModelProperty("关联id") @ApiModelProperty("关联id")
private String relId; private String relId;
@ApiModelProperty("图片url")
private String remark; private String remark;
@ApiModelProperty("图片宽度") @ApiModelProperty("图片宽度")
......
package com.tanpu.community.controller; package com.tanpu.community.controller;
import com.tanpu.common.api.CommonResp; import com.tanpu.common.api.CommonResp;
import com.tanpu.common.constant.ErrorCodeConstant; import com.tanpu.community.api.beans.resp.FileUploadResp;
import com.tanpu.common.exception.BizException;
import com.tanpu.community.dao.entity.community.FileRecordEntity;
import com.tanpu.community.manager.FileManager; import com.tanpu.community.manager.FileManager;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import java.util.Date;
@RestController @RestController
@Slf4j @Slf4j
@RequestMapping(value = "/api/file") @RequestMapping(value = "/api/file")
...@@ -22,7 +18,7 @@ public class FileController { ...@@ -22,7 +18,7 @@ public class FileController {
@PostMapping("/uploadFile") @PostMapping("/uploadFile")
@ResponseBody @ResponseBody
public CommonResp<FileRecordEntity> uploadToRemote(@RequestParam(value = "file") MultipartFile file) { public CommonResp<FileUploadResp> uploadToRemote(@RequestParam(value = "file") MultipartFile file) {
return CommonResp.success(fileManager.uploadFile(file)); return CommonResp.success(fileManager.uploadFile(file));
} }
} }
...@@ -2,8 +2,10 @@ package com.tanpu.community.manager; ...@@ -2,8 +2,10 @@ package com.tanpu.community.manager;
import com.tanpu.common.constant.ErrorCodeConstant; import com.tanpu.common.constant.ErrorCodeConstant;
import com.tanpu.common.exception.BizException; import com.tanpu.common.exception.BizException;
import com.tanpu.community.api.beans.resp.FileUploadResp;
import com.tanpu.community.dao.entity.community.FileRecordEntity; import com.tanpu.community.dao.entity.community.FileRecordEntity;
import com.tanpu.community.service.OSSFileService; import com.tanpu.community.service.OSSFileService;
import com.tanpu.community.util.ConvertUtil;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
...@@ -22,7 +24,7 @@ public class FileManager { ...@@ -22,7 +24,7 @@ public class FileManager {
@Autowired @Autowired
private OSSFileService ossFileService; private OSSFileService ossFileService;
public FileRecordEntity uploadFile(MultipartFile file) { public FileUploadResp uploadFile(MultipartFile file) {
if (file == null) { if (file == null) {
throw new BizException(ErrorCodeConstant.FILE_UPLOAD_FAIL); throw new BizException(ErrorCodeConstant.FILE_UPLOAD_FAIL);
} }
...@@ -39,7 +41,8 @@ public class FileManager { ...@@ -39,7 +41,8 @@ public class FileManager {
if (data.length==0 || StringUtils.isEmpty(originalName)){ if (data.length==0 || StringUtils.isEmpty(originalName)){
throw new BizException("上传文件为空"); throw new BizException("上传文件为空");
} }
return ossFileService.uploadFile(data, originalName); FileRecordEntity fileRecordEntity = ossFileService.uploadFile(data, originalName);
return ConvertUtil.fileRecordEntity2Resp(fileRecordEntity);
} }
public Map<String,String> getFileUrlByIds(List<String> fileIds){ public Map<String,String> getFileUrlByIds(List<String> fileIds){
......
...@@ -5,15 +5,15 @@ import com.google.common.collect.Sets; ...@@ -5,15 +5,15 @@ import com.google.common.collect.Sets;
import com.tanpu.common.api.CommonResp; import com.tanpu.common.api.CommonResp;
import com.tanpu.common.enums.fund.ProductTypeEnum; import com.tanpu.common.enums.fund.ProductTypeEnum;
import com.tanpu.common.util.JsonUtil; import com.tanpu.common.util.JsonUtil;
import com.tanpu.community.api.beans.vo.ImagesDTO;
import com.tanpu.community.api.beans.qo.AttachmentDetailVo; import com.tanpu.community.api.beans.qo.AttachmentDetailVo;
import com.tanpu.community.api.beans.qo.ThemeContentQo; import com.tanpu.community.api.beans.qo.ThemeContentQo;
import com.tanpu.community.api.beans.qo.ThemeQo; import com.tanpu.community.api.beans.qo.ThemeQo;
import com.tanpu.community.api.beans.vo.ImagesDTO;
import com.tanpu.community.api.beans.vo.feign.course.CourseSimpleResp;
import com.tanpu.community.api.beans.vo.feign.course.ShortVideoBaseInfoResp;
import com.tanpu.community.api.beans.vo.feign.product.FundInfoBaseResp; import com.tanpu.community.api.beans.vo.feign.product.FundInfoBaseResp;
import com.tanpu.community.api.beans.vo.feign.product.ProductInfoVO; import com.tanpu.community.api.beans.vo.feign.product.ProductInfoVO;
import com.tanpu.community.api.beans.vo.feign.course.ShortVideoBaseInfoResp;
import com.tanpu.community.api.beans.vo.feign.zhibo.ZhiboListResp; import com.tanpu.community.api.beans.vo.feign.zhibo.ZhiboListResp;
import com.tanpu.community.api.beans.vo.feign.course.CourseSimpleResp;
import com.tanpu.community.api.enums.RelTypeEnum; import com.tanpu.community.api.enums.RelTypeEnum;
import com.tanpu.community.dao.entity.community.FileRecordEntity; import com.tanpu.community.dao.entity.community.FileRecordEntity;
import com.tanpu.community.dao.entity.community.TopicEntity; import com.tanpu.community.dao.entity.community.TopicEntity;
...@@ -225,6 +225,7 @@ public class ProductService { ...@@ -225,6 +225,7 @@ public class ProductService {
imgMap.putAll(fileRecordEntities.stream().collect(Collectors imgMap.putAll(fileRecordEntities.stream().collect(Collectors
.toMap(FileRecordEntity::getFileId, o -> o))); .toMap(FileRecordEntity::getFileId, o -> o)));
} }
} }
if (!CollectionUtils.isEmpty(topicIds)) { if (!CollectionUtils.isEmpty(topicIds)) {
// 查询话题标题 // 查询话题标题
...@@ -430,7 +431,7 @@ public class ProductService { ...@@ -430,7 +431,7 @@ public class ProductService {
themeContent.setImgList(Collections.singletonList(imagesDTO)); themeContent.setImgList(Collections.singletonList(imagesDTO));
} }
} }
}else if (themeContent.getType().equals(RelTypeEnum.MULTIPLE_IMAGE.type)) { } else if (themeContent.getType().equals(RelTypeEnum.MULTIPLE_IMAGE.type)) {
//多图写入图片宽高 //多图写入图片宽高
List<ImagesDTO> imgList = themeContent.getImgList(); List<ImagesDTO> imgList = themeContent.getImgList();
for (ImagesDTO imagesDTO : imgList) { for (ImagesDTO imagesDTO : imgList) {
......
...@@ -2,6 +2,7 @@ package com.tanpu.community.util; ...@@ -2,6 +2,7 @@ package com.tanpu.community.util;
import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.core.type.TypeReference;
import com.tanpu.common.util.JsonUtil; import com.tanpu.common.util.JsonUtil;
import com.tanpu.community.api.beans.resp.FileUploadResp;
import com.tanpu.community.api.beans.vo.ImagesDTO; import com.tanpu.community.api.beans.vo.ImagesDTO;
import com.tanpu.community.api.beans.vo.TopicDO; import com.tanpu.community.api.beans.vo.TopicDO;
import com.tanpu.community.api.beans.qo.*; import com.tanpu.community.api.beans.qo.*;
...@@ -12,9 +13,11 @@ import com.tanpu.community.api.enums.RelTypeEnum; ...@@ -12,9 +13,11 @@ import com.tanpu.community.api.enums.RelTypeEnum;
import com.tanpu.community.dao.entity.community.*; import com.tanpu.community.dao.entity.community.*;
import com.tanpu.community.dao.entity.user.UserInfoEntity; import com.tanpu.community.dao.entity.user.UserInfoEntity;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.util.StringUtils;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.stream.Collectors; import java.util.stream.Collectors;
public class ConvertUtil { public class ConvertUtil {
...@@ -202,6 +205,18 @@ public class ConvertUtil { ...@@ -202,6 +205,18 @@ public class ConvertUtil {
.build(); .build();
} }
public static FileUploadResp fileRecordEntity2Resp(FileRecordEntity entity){
FileUploadResp resp = new FileUploadResp();
BeanUtils.copyProperties(entity,resp);
String extInfo = entity.getExtInfo();
if (!StringUtils.isEmpty(extInfo)) {
Map<String, Object> extMap = JsonUtil.toMap(extInfo);
resp.setImgHeight((Integer) extMap.get("height"));
resp.setImgWidth((Integer) extMap.get("width"));
}
return resp;
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment