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