|
|
@@ -1,10 +1,71 @@
|
|
|
package cn.seecoder.seecoderportalserver.serviceImpl;
|
|
|
|
|
|
+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.service.CommunicationService;
|
|
|
+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;
|
|
|
|
|
|
/**
|
|
|
* @author fanyanpeng
|
|
|
* @date 2023/7/11 12:21
|
|
|
*/
|
|
|
+@Service
|
|
|
public class CommunicationServiceImpl implements CommunicationService {
|
|
|
+
|
|
|
+
|
|
|
+ private final CommunicationRepository communicationRepository;
|
|
|
+ private final CommunicationMapper communicationMapper;
|
|
|
+
|
|
|
+ public CommunicationServiceImpl(CommunicationRepository communicationRepository, CommunicationMapper communicationMapper){
|
|
|
+ this.communicationRepository = communicationRepository;
|
|
|
+ this.communicationMapper = communicationMapper;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public PageVO<CommunicationVO> getCommunicationPageByUserId(String userId, Integer page, Integer size) {
|
|
|
+ Pageable pageable = PageRequest.of(page,size);
|
|
|
+ Page<Communication> communicationPage = communicationRepository.findByPublisherId(pageable);
|
|
|
+ return toPageVO(communicationPage);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ * @author fanyanpeng
|
|
|
+ * @date 2023/7/12 12:00
|
|
|
+ * @param communicationPage
|
|
|
+ * @return cn.seecoder.seecoderportalcommon.vo.PageVO<cn.seecoder.seecoderportalcommon.vo.CommunicationVO>
|
|
|
+ */
|
|
|
+ private PageVO<CommunicationVO> toPageVO(Page<Communication> communicationPage){
|
|
|
+ PageVO<CommunicationVO> communicationVOPageVO = new PageVO<>();
|
|
|
+
|
|
|
+ //转换分页的内容
|
|
|
+ List<Communication> communicationList = communicationPage.getContent();
|
|
|
+ List<CommunicationVO> communicationVOList = new ArrayList<>();
|
|
|
+ for(Communication communication:communicationList){
|
|
|
+ communicationVOList.add(communicationMapper.toCommunicationVO(communication));
|
|
|
+ }
|
|
|
+ communicationVOPageVO.setContent(communicationVOList);
|
|
|
+
|
|
|
+ //设置分页的参数
|
|
|
+ communicationVOPageVO.setTotalElements(communicationPage.getTotalElements());
|
|
|
+ communicationVOPageVO.setPageNumber(communicationPage.getNumber());
|
|
|
+ communicationVOPageVO.setNumberOfElements(communicationPage.getSize());
|
|
|
+ communicationVOPageVO.setTotalPages(communicationPage.getTotalPages());
|
|
|
+
|
|
|
+ return communicationVOPageVO;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
}
|