Merge remote-tracking branch 'origin/main'

main
wangqing 10 months ago
commit 3dbb0ea338

@ -68,20 +68,21 @@ public class JournalController {
@Autowired @Autowired
private JwtUtil jwtUtil; private JwtUtil jwtUtil;
//mock data // mock data
private static final String JOURNAL_TAG_FILE_PATH="journalTags.txt"; private static final String JOURNAL_TAG_FILE_PATH = "journalTags.txt";
private Map<String,List<String>> journalTagMap=new HashMap<>(); private Map<String, List<String>> journalTagMap = new HashMap<>();
private static final String[] EDITOR = new String[] { "左岸以西", "落在低处" }; private static final String[] EDITOR = new String[] { "左岸以西", "落在低处" };
@PostConstruct @PostConstruct
@SneakyThrows @SneakyThrows
private void init() { private void init() {
getLines(JOURNAL_TAG_FILE_PATH).forEach(s->{ getLines(JOURNAL_TAG_FILE_PATH).forEach(s -> {
String[] segs=s.split("\\|"); String[] segs = s.split("\\|");
List<String> tags=Arrays.stream(segs[1].split(",")).collect(Collectors.toList()); List<String> tags = Arrays.stream(segs[1].split(",")).collect(Collectors.toList());
journalTagMap.put(segs[0], tags); journalTagMap.put(segs[0], tags);
}); });
} }
private static List<String> getLines(String filePath) { private static List<String> getLines(String filePath) {
try (InputStream is = new ClassPathResource(filePath).getInputStream(); try (InputStream is = new ClassPathResource(filePath).getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(is));) { BufferedReader reader = new BufferedReader(new InputStreamReader(is));) {
@ -91,6 +92,7 @@ public class JournalController {
} }
return Collections.emptyList(); return Collections.emptyList();
} }
@ApiOperation(value = "1.查询期刊信息", notes = "若authorization为空或authorization校验失败默认返回最新的10期期刊筛选条件对游客不可用") @ApiOperation(value = "1.查询期刊信息", notes = "若authorization为空或authorization校验失败默认返回最新的10期期刊筛选条件对游客不可用")
@GetMapping("/list") @GetMapping("/list")
@GlobalInterceptor @GlobalInterceptor
@ -105,31 +107,30 @@ public class JournalController {
queryReq.setPageSize(10); queryReq.setPageSize(10);
} }
Page<Article> pageList = articleService.queryPage(queryReq); Page<Article> pageList = articleService.queryPage(queryReq);
Set<String> journalCollectSet = null==user?Collections.emptySet():userCollectService.getCollectSet(user.getUserId(),CollectTypeEnum.JOURNAL); Set<String> journalCollectSet = null == user ? Collections.emptySet()
: userCollectService.getCollectSet(user.getUserId(), 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));
} }
@ApiOperation(value = "2.查询收藏期刊信息") @ApiOperation(value = "2.查询收藏期刊信息")
@ApiImplicitParams({ @ApiImplicitParams({ @ApiImplicitParam(name = "userId", value = "用户id", required = true),
@ApiImplicitParam(name = "userId", value = "用户id", required = true),
@ApiImplicitParam(name = "pageNum", value = "分页: 页码以1开始", required = true), @ApiImplicitParam(name = "pageNum", value = "分页: 页码以1开始", required = true),
@ApiImplicitParam(name = "pageSize", value = "分页: 每页数量", required = true) @ApiImplicitParam(name = "pageSize", value = "分页: 每页数量", required = true) })
})
@GetMapping("/collect/{userId}/{pageNum}/{pageSize}") @GetMapping("/collect/{userId}/{pageNum}/{pageSize}")
@GlobalInterceptor(checkAppUserLogin = true) @GlobalInterceptor(checkAppUserLogin = true)
public Result<PageResult<JournalRespDTO>> collectPage( public Result<PageResult<JournalRespDTO>> collectPage(
@RequestHeader(value = "Authorization", required = false) String authorization, @RequestHeader(value = "Authorization", required = true) String authorization,
@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); List<String> objectIds = userCollectService.getCollectList(userId, pageNum, pageSize, CollectTypeEnum.JOURNAL);
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<Article> pageList = articleService.orderByField(objectIds); List<Article> pageList = articleService.orderByField(objectIds);
Set<String> journalCollectSet = objectIds.isEmpty()?Collections.emptySet(): new HashSet<>(objectIds); Set<String> journalCollectSet = objectIds.isEmpty() ? Collections.emptySet() : 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));
@ -138,11 +139,13 @@ public class JournalController {
@ApiOperation(value = "3.根据期刊id查询期刊信息") @ApiOperation(value = "3.根据期刊id查询期刊信息")
@GetMapping("/{id}") @GetMapping("/{id}")
@GlobalInterceptor @GlobalInterceptor
public Result<JournalRespDTO> findById(@RequestHeader(value = "Authorization", required = false) String authorization, public Result<JournalRespDTO> findById(
@RequestHeader(value = "Authorization", required = false) String authorization,
@PathVariable @VerifyParam(required = true) String id) { @PathVariable @VerifyParam(required = true) String id) {
UserLoginDto user = jwtUtil.getUserLoginDto(authorization); UserLoginDto user = jwtUtil.getUserLoginDto(authorization);
Article journal=articleService.findById(id); Article journal = articleService.findById(id);
Set<String> journalCollectSet = null==user?Collections.emptySet():userCollectService.getCollectSet(user.getUserId(),CollectTypeEnum.JOURNAL); Set<String> journalCollectSet = null == user ? Collections.emptySet()
: userCollectService.getCollectSet(user.getUserId(), CollectTypeEnum.JOURNAL);
return Result.success(getJournalRespDTO(journal, journalCollectSet)); return Result.success(getJournalRespDTO(journal, journalCollectSet));
} }
@ -157,12 +160,12 @@ public class JournalController {
journalRespDTO.setIpLocation("广东"); journalRespDTO.setIpLocation("广东");
journalRespDTO.setTags(getTags(journalRespDTO.getJournalNo())); journalRespDTO.setTags(getTags(journalRespDTO.getJournalNo()));
String content=article.getContent(); String content = article.getContent();
if(StringTools.isEmpty(content)) { if (StringTools.isEmpty(content)) {
Poem poem=RandomSource.languageSource().randomTangPoem(); Poem poem = RandomSource.languageSource().randomTangPoem();
journalRespDTO.setEditor(poem.getAuthor()); journalRespDTO.setEditor(poem.getAuthor());
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); int index = RandomSource.numberSource().randomInt(0, EDITOR.length);
String editor = EDITOR[index]; String editor = EDITOR[index];
@ -173,12 +176,14 @@ public class JournalController {
} }
private List<String> getTags(String journalNo) { private List<String> getTags(String journalNo) {
return journalTagMap.computeIfAbsent(journalNo, a->getTags()); return journalTagMap.computeIfAbsent(journalNo, a -> getTags());
} }
private List<String> getTags() { private List<String> getTags() {
int limit = RandomSource.numberSource().randomInt(1, 3); int limit = RandomSource.numberSource().randomInt(1, 3);
return tagDao.random(limit).stream().map(Tag::getNameCh).sorted().collect(Collectors.toList()); return tagDao.random(limit).stream().map(Tag::getNameCh).sorted().collect(Collectors.toList());
} }
private String getEditDate(Article article) { private String getEditDate(Article article) {
Date date = null == article.getUpdatetime() ? article.getCreatetime() : article.getUpdatetime(); Date date = null == article.getUpdatetime() ? article.getCreatetime() : article.getUpdatetime();
return DateUtil.format(date, DateTimePatternEnum.YYYY_DOT_MM_DOT_DD.getPattern()); return DateUtil.format(date, DateTimePatternEnum.YYYY_DOT_MM_DOT_DD.getPattern());

@ -80,7 +80,7 @@ public class SongController {
@GetMapping("/collect/{userId}/{pageNum}/{pageSize}") @GetMapping("/collect/{userId}/{pageNum}/{pageSize}")
@GlobalInterceptor(checkAppUserLogin = true) @GlobalInterceptor(checkAppUserLogin = true)
public Result<PageResult<SongRespDTO>> collectPage( public Result<PageResult<SongRespDTO>> collectPage(
@RequestHeader(value = "Authorization", required = false) String authorization, @RequestHeader(value = "Authorization", required = true) String authorization,
@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) {

@ -206,7 +206,7 @@ public class LoginController extends BaseController {
@ApiOperation(value = "6.退出登录") @ApiOperation(value = "6.退出登录")
@PostMapping("/logout") @PostMapping("/logout")
@GlobalInterceptor(checkAppUserLogin = true) @GlobalInterceptor(checkAppUserLogin = true)
public Result<Void> logout(@RequestHeader(value = "Authorization", required = false) String authorization){ public Result<Void> logout(@RequestHeader(value = "Authorization", required = true) String authorization){
return Result.success(); return Result.success();
} }
} }

@ -31,7 +31,7 @@ public class UserCollectController {
@ApiImplicitParam(name = "collectType", value = "0:歌曲1:期刊2:关注3:黑名单", required = true) }) @ApiImplicitParam(name = "collectType", value = "0:歌曲1:期刊2:关注3:黑名单", required = true) })
@PostMapping @PostMapping
@GlobalInterceptor(checkAppUserLogin = true) @GlobalInterceptor(checkAppUserLogin = true)
public Result<Void> addCollect(@RequestHeader(value = "Authorization", required = false) String authorization, public Result<Void> addCollect(@RequestHeader(value = "Authorization", required = true) String authorization,
@VerifyParam(required = true) @RequestParam("objectId") String objectId, @VerifyParam(required = true) @RequestParam("objectId") String objectId,
@VerifyParam(required = true) @RequestParam("collectType") Integer collectType) { @VerifyParam(required = true) @RequestParam("collectType") Integer collectType) {
UserLoginDto loginDto = jwtUtil.getUserLoginDto(authorization); UserLoginDto loginDto = jwtUtil.getUserLoginDto(authorization);
@ -48,7 +48,7 @@ public class UserCollectController {
@ApiImplicitParam(name = "collectType", value = "0:歌曲1:期刊2:关注3:黑名单4:粉丝", required = true) }) @ApiImplicitParam(name = "collectType", value = "0:歌曲1:期刊2:关注3:黑名单4:粉丝", required = true) })
@DeleteMapping @DeleteMapping
@GlobalInterceptor(checkAppUserLogin = true) @GlobalInterceptor(checkAppUserLogin = true)
public Result<Void> cancelCollect(@RequestHeader(value = "Authorization", required = false) String authorization, public Result<Void> cancelCollect(@RequestHeader(value = "Authorization", required = true) String authorization,
@VerifyParam(required = true) @RequestParam("objectId") String objectId, @VerifyParam(required = true) @RequestParam("objectId") String objectId,
@VerifyParam(required = true) @RequestParam("collectType") Integer collectType) { @VerifyParam(required = true) @RequestParam("collectType") Integer collectType) {
UserLoginDto loginDto = jwtUtil.getUserLoginDto(authorization); UserLoginDto loginDto = jwtUtil.getUserLoginDto(authorization);

Loading…
Cancel
Save