|
|
|
@ -29,6 +29,8 @@ import io.swagger.annotations.*;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.core.io.ClassPathResource;
|
|
|
|
|
import org.springframework.data.domain.Page;
|
|
|
|
|
import org.springframework.data.domain.PageRequest;
|
|
|
|
|
import org.springframework.data.domain.Pageable;
|
|
|
|
|
import org.springframework.data.mongodb.core.MongoTemplate;
|
|
|
|
|
import org.springframework.data.mongodb.core.aggregation.Aggregation;
|
|
|
|
|
import org.springframework.data.mongodb.core.aggregation.AggregationResults;
|
|
|
|
@ -37,8 +39,7 @@ import org.springframework.web.bind.annotation.*;
|
|
|
|
|
import com.luoo.music.pojo.Journal;
|
|
|
|
|
import com.luoo.music.pojo.Tag;
|
|
|
|
|
import com.luoo.music.service.JournalService;
|
|
|
|
|
import com.luoo.music.service.UserCollectService;
|
|
|
|
|
|
|
|
|
|
import com.luoo.music.service.UserCollectInfoService;
|
|
|
|
|
import annotation.GlobalInterceptor;
|
|
|
|
|
import annotation.VerifyParam;
|
|
|
|
|
import api.PageResult;
|
|
|
|
@ -64,7 +65,8 @@ import util.StringTools;
|
|
|
|
|
@RequestMapping("/journal")
|
|
|
|
|
public class JournalController {
|
|
|
|
|
@Autowired
|
|
|
|
|
private UserCollectService userCollectService;
|
|
|
|
|
private UserCollectInfoService userCollectInfoService;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private JournalService journalService;
|
|
|
|
|
|
|
|
|
@ -120,8 +122,9 @@ public class JournalController {
|
|
|
|
|
queryReq.setPageSize(10);
|
|
|
|
|
}
|
|
|
|
|
Page<Journal> pageList = journalService.queryPage(queryReq);
|
|
|
|
|
List<String> ids=pageList.stream().map(Journal::getId).collect(Collectors.toList());
|
|
|
|
|
Set<String> journalCollectSet = null == user ? Collections.emptySet()
|
|
|
|
|
: userCollectService.getCollectSet(user.getUserId(), CollectTypeEnum.JOURNAL);
|
|
|
|
|
: userCollectInfoService.getCollectSet(user.getUserId(),ids, CollectTypeEnum.JOURNAL);
|
|
|
|
|
List<JournalRespDTO> list = pageList.stream().map(a -> getJournalRespDTO(a, journalCollectSet))
|
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
return Result.success(new PageResult<JournalRespDTO>(Long.valueOf(list.size()), list));
|
|
|
|
@ -138,12 +141,13 @@ public class JournalController {
|
|
|
|
|
@PathVariable @VerifyParam(required = true) String userId,
|
|
|
|
|
@PathVariable @VerifyParam(required = true) Integer pageNum,
|
|
|
|
|
@PathVariable @VerifyParam(required = true) Integer pageSize) {
|
|
|
|
|
List<String> objectIds = userCollectService.getCollectList(userId, pageNum, pageSize, CollectTypeEnum.JOURNAL);
|
|
|
|
|
Pageable pageable = PageRequest.of(pageNum-1,pageSize);
|
|
|
|
|
List<String> objectIds=userCollectInfoService.findByUserIdAndCollectType(userId, CollectTypeEnum.JOURNAL, pageable);
|
|
|
|
|
if (objectIds.isEmpty()) {
|
|
|
|
|
return Result.success(new PageResult<JournalRespDTO>(0L, Collections.emptyList()));
|
|
|
|
|
}
|
|
|
|
|
List<Journal> pageList = journalService.orderByField(objectIds);
|
|
|
|
|
Set<String> journalCollectSet = objectIds.isEmpty() ? Collections.emptySet() : new HashSet<>(objectIds);
|
|
|
|
|
Set<String> journalCollectSet = new HashSet<>(objectIds);
|
|
|
|
|
List<JournalRespDTO> list = pageList.stream().map(a -> getJournalRespDTO(a, journalCollectSet))
|
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
return Result.success(new PageResult<JournalRespDTO>(Long.valueOf(list.size()), list));
|
|
|
|
@ -157,9 +161,10 @@ public class JournalController {
|
|
|
|
|
@PathVariable @VerifyParam(required = true) String id) {
|
|
|
|
|
UserLoginDto user = jwtUtil.getUserLoginDto(authorization);
|
|
|
|
|
Journal journal = journalService.findById(id);
|
|
|
|
|
Set<String> journalCollectSet = null == user ? Collections.emptySet()
|
|
|
|
|
: userCollectService.getCollectSet(user.getUserId(), CollectTypeEnum.JOURNAL);
|
|
|
|
|
return Result.success(getJournalRespDTO(journal, journalCollectSet));
|
|
|
|
|
JournalRespDTO journalRespDTO=getJournalRespDTO(journal, Collections.emptySet());
|
|
|
|
|
boolean isCollect=null == user ? false:userCollectInfoService.isCollect(user.getUserId(),id, CollectTypeEnum.JOURNAL);
|
|
|
|
|
journalRespDTO.setHaveCollect(isCollect);
|
|
|
|
|
return Result.success(journalRespDTO);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private JournalRespDTO getJournalRespDTO(Journal journal, Set<String> journalCollectSet) {
|
|
|
|
@ -171,7 +176,7 @@ public class JournalController {
|
|
|
|
|
journalRespDTO.setDate(getEditDate(journal));
|
|
|
|
|
journalRespDTO.setHaveCollect(journalCollectSet.contains(journalRespDTO.getId()));
|
|
|
|
|
journalRespDTO.setIpLocation("广东");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
journalRespDTO.setTags(getTags(journalRespDTO.getJournalNo()));
|
|
|
|
|
String content = journal.getContent();
|
|
|
|
|
if (StringTools.isEmpty(content)) {
|
|
|
|
@ -180,9 +185,8 @@ public class JournalController {
|
|
|
|
|
journalRespDTO.setContent(Arrays.stream(poem.getContent()).collect(Collectors.joining("\r\n")));
|
|
|
|
|
} else {
|
|
|
|
|
journalRespDTO.setContent(content);
|
|
|
|
|
int index = RandomSource.numberSource().randomInt(0, EDITOR.length);
|
|
|
|
|
String editor = EDITOR[index];
|
|
|
|
|
journalRespDTO.setEditor(editor);
|
|
|
|
|
|
|
|
|
|
journalRespDTO.setEditor(getEditor(journal.getUserName()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -220,6 +224,10 @@ public class JournalController {
|
|
|
|
|
return journalRespDTO;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private String getEditor(String userName) {
|
|
|
|
|
return StringTools.isEmpty(userName)?EDITOR[RandomSource.numberSource().randomInt(0, EDITOR.length)]:userName;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private List<String> getTags(String journalNo) {
|
|
|
|
|
return journalTagMap.computeIfAbsent(journalNo, a -> getTags());
|
|
|
|
|
}
|
|
|
|
|