|
|
@@ -1,35 +1,29 @@
|
|
|
package cn.seecoder.seecoderportalserver.serviceImpl;
|
|
|
|
|
|
import cn.seecoder.seecoderportalcommon.enums.CommunicationSortStrategyEnum;
|
|
|
+import cn.seecoder.seecoderportalcommon.vo.CommunicationFileVO;
|
|
|
import cn.seecoder.seecoderportalcommon.vo.CommunicationVO;
|
|
|
import cn.seecoder.seecoderportalcommon.vo.PageVO;
|
|
|
import cn.seecoder.seecoderportalcommon.vo.UserVO;
|
|
|
-import cn.seecoder.seecoderportalcommon.vo.CommunicationVO;
|
|
|
-import cn.seecoder.seecoderportalcommon.vo.PageVO;
|
|
|
-import cn.seecoder.seecoderportalserver.domain.Communication;
|
|
|
-import cn.seecoder.seecoderportalserver.mapper.CommunicationMapper;
|
|
|
-import cn.seecoder.seecoderportalserver.repository.CommunicationRepository;
|
|
|
import cn.seecoder.seecoderportalserver.domain.Communication;
|
|
|
+import cn.seecoder.seecoderportalserver.mapper.CommunicationFileMapper;
|
|
|
import cn.seecoder.seecoderportalserver.mapper.CommunicationMapper;
|
|
|
import cn.seecoder.seecoderportalserver.repository.CommunicationRepository;
|
|
|
import cn.seecoder.seecoderportalserver.service.CommunicationService;
|
|
|
+import cn.seecoder.seecoderportalserver.utility.OssUtil;
|
|
|
+import cn.seecoder.seecoderportalserver.web.rest.errors.CustomErrorException;
|
|
|
import org.springframework.data.domain.Page;
|
|
|
import org.springframework.data.domain.PageRequest;
|
|
|
import org.springframework.data.domain.Pageable;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
+import java.io.IOException;
|
|
|
import java.util.ArrayList;
|
|
|
+import java.util.Date;
|
|
|
import java.util.List;
|
|
|
-import cn.seecoder.seecoderportalserver.utility.OkResponse;
|
|
|
-import org.springframework.data.domain.Page;
|
|
|
-import org.springframework.data.domain.PageRequest;
|
|
|
-import org.springframework.data.domain.Pageable;
|
|
|
-import org.springframework.data.domain.Sort;
|
|
|
-import org.springframework.stereotype.Service;
|
|
|
-
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.List;
|
|
|
+import java.util.Optional;
|
|
|
|
|
|
/**
|
|
|
* @author fanyanpeng
|
|
|
@@ -40,18 +34,25 @@ public class CommunicationServiceImpl implements CommunicationService {
|
|
|
|
|
|
private final CommunicationRepository communicationRepository;
|
|
|
private final CommunicationMapper communicationMapper;
|
|
|
+ private final CommunicationFileMapper communicationFileMapper;
|
|
|
|
|
|
- public CommunicationServiceImpl(CommunicationRepository communicationRepository, CommunicationMapper communicationMapper){
|
|
|
+ private final OssUtil ossUtil;
|
|
|
+
|
|
|
+
|
|
|
+ public CommunicationServiceImpl(CommunicationRepository communicationRepository, CommunicationMapper communicationMapper, CommunicationFileMapper communicationFileMapper, OssUtil ossUtil){
|
|
|
this.communicationRepository = communicationRepository;
|
|
|
this.communicationMapper = communicationMapper;
|
|
|
+ this.communicationFileMapper = communicationFileMapper;
|
|
|
+ this.ossUtil = ossUtil;
|
|
|
}
|
|
|
|
|
|
|
|
|
+ @Transactional
|
|
|
@Override
|
|
|
public PageVO<CommunicationVO> getCommunicationPageByUserId(Long userId, Integer page, Integer size) {
|
|
|
Pageable pageable = PageRequest.of(page,size);
|
|
|
Page<Communication> communicationPage = communicationRepository.findByPublisherId(userId,pageable);
|
|
|
- return toPageVO(communicationPage);
|
|
|
+ return toPageVO(communicationPage, userId);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -61,14 +62,14 @@ public class CommunicationServiceImpl implements CommunicationService {
|
|
|
* @param communicationPage
|
|
|
* @return cn.seecoder.seecoderportalcommon.vo.PageVO<cn.seecoder.seecoderportalcommon.vo.CommunicationVO>
|
|
|
*/
|
|
|
- private PageVO<CommunicationVO> toPageVO(Page<Communication> communicationPage){
|
|
|
+ private PageVO<CommunicationVO> toPageVO(Page<Communication> communicationPage,Long userId){
|
|
|
PageVO<CommunicationVO> communicationVOPageVO = new PageVO<>();
|
|
|
|
|
|
//转换分页的内容
|
|
|
List<Communication> communicationList = communicationPage.getContent();
|
|
|
List<CommunicationVO> communicationVOList = new ArrayList<>();
|
|
|
for(Communication communication:communicationList){
|
|
|
- communicationVOList.add(communicationMapper.toCommunicationVO(communication));
|
|
|
+ communicationVOList.add(communicationMapper.toCommunicationVO(communication,userId));
|
|
|
}
|
|
|
communicationVOPageVO.setContent(communicationVOList);
|
|
|
|
|
|
@@ -86,20 +87,62 @@ public class CommunicationServiceImpl implements CommunicationService {
|
|
|
|
|
|
|
|
|
@Override
|
|
|
- public String uploadCommunicationFile(MultipartFile file) {
|
|
|
- return null;
|
|
|
+ public CommunicationFileVO uploadCommunicationFile(MultipartFile file, Long userId) {
|
|
|
+ String ossUrl = null;
|
|
|
+ String fileExtension = null;
|
|
|
+ String fileName = String.format("%s/%s-%s",userId,new Date().getTime(),file.getOriginalFilename());
|
|
|
+
|
|
|
+ try{
|
|
|
+ fileExtension = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf("."));
|
|
|
+ }catch (NullPointerException nullPointerException){
|
|
|
+ throw new CustomErrorException("文件扩展名获取失败");
|
|
|
+ }
|
|
|
+
|
|
|
+ try{
|
|
|
+ ossUrl = ossUtil.upload(fileName,file.getInputStream());
|
|
|
+ }catch (IOException ioException){
|
|
|
+ throw new CustomErrorException("文件上传失败");
|
|
|
+ }
|
|
|
+
|
|
|
+ //文件上传成功,新建文件VO对象返回
|
|
|
+ CommunicationFileVO communicationFileVO = new CommunicationFileVO();
|
|
|
+ communicationFileVO.setFileOwnerId(userId);
|
|
|
+ communicationFileVO.setFileName(file.getOriginalFilename());
|
|
|
+ communicationFileVO.setFileSize(file.getSize());
|
|
|
+ communicationFileVO.setFileUrl(ossUrl);
|
|
|
+ communicationFileVO.setFileExtension(fileExtension);
|
|
|
+
|
|
|
+ return communicationFileVO;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public CommunicationVO postCommunication(CommunicationVO communicationVO) {
|
|
|
- return null;
|
|
|
+ public CommunicationVO postCommunication(CommunicationVO communicationVO, Long userId) {
|
|
|
+ Communication communication = communicationMapper.toCommunication(communicationVO);
|
|
|
+ communication.setPublisherId(userId);
|
|
|
+ communication.setPublishTime(new Date());
|
|
|
+
|
|
|
+ communicationRepository.save(communication);
|
|
|
+
|
|
|
+ return communicationMapper.toCommunicationVO(communication,userId);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ @Transactional
|
|
|
@Override
|
|
|
- public CommunicationVO getCommunicationDetail(Long communicationId) {
|
|
|
- return null;
|
|
|
+ public CommunicationVO getCommunicationDetail(Long communicationId, Long userId) {
|
|
|
+ Optional<Communication> optional = communicationRepository.findById(communicationId);
|
|
|
+ if(!optional.isPresent()){
|
|
|
+ throw new CustomErrorException("交流信息不存在");
|
|
|
+ }
|
|
|
+ Communication communication = optional.get();
|
|
|
+ return communicationMapper.toCommunicationVO(communication,userId);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
@Override
|
|
|
public PageVO<CommunicationVO> getCommunicationPage(Integer page, Integer size, CommunicationSortStrategyEnum sort) {
|
|
|
return null;
|