feat: 排行榜普通方法

This commit is contained in:
2024-03-06 20:39:28 +08:00
parent 0c2026eb80
commit 2a1d171b5f
18 changed files with 254 additions and 17 deletions

View File

@@ -1,44 +0,0 @@
package com.landaiqing.subject.application.context;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
/**
* @Classname LoginContextHolder
* @BelongsProject: qing-yu-club
* @BelongsPackage: com.landaiqing.subject.application.context
* @Author: landaiqing
* @CreateTime: 2024-03-03 18:11
* @Description: 登录上下文对象
* @Version: 1.0
*/
public class LoginContextHolder {
private static final InheritableThreadLocal <Map<String,Object>> THREAD_LOCAL=new InheritableThreadLocal<>();
public static void set(String key,Object val){
Map<String,Object> map=getThreadLoacalMap();
map.put(key, val);
}
public static Object get(String key){
Map<String,Object> threadLoacalMap=getThreadLoacalMap();
return threadLoacalMap.get(key);
}
public static void remove(){
THREAD_LOCAL.remove();
}
public static String getLoginId(){
return (String) getThreadLoacalMap().get("loginId");
}
public static Map<String,Object> getThreadLoacalMap(){
Map<String,Object> map =THREAD_LOCAL.get();
if (Objects.isNull(map)){
map=new ConcurrentHashMap<>();
THREAD_LOCAL.set(map);
}
return map;
}
}

View File

@@ -14,7 +14,10 @@ import com.landaiqing.subject.infra.basic.entity.SubjectInfoEs;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.util.List;
@@ -145,4 +148,25 @@ public class SubjectController {
return Result.fail("全文检索失败!");
}
}
/**
* @description: 获取题目贡献榜
* @param: []
* @return: com.landaiqing.subject.common.entity.Result<java.util.List < com.landaiqing.subject.application.dto.SubjectInfoDTO>>
* @author landaiqing
* @date: 2024/3/6 20:16
*/
@PostMapping("/getContributeList")
public Result<List<SubjectInfoDTO>> getContributeList() {
try {
List<SubjectInfoBO> boList = subjectInfoDomainService.getContributeList();
List<SubjectInfoDTO> dtoList = SubjectInfoDTOConverter.INSTANCE.convertBOToDTOList(boList);
return Result.ok(dtoList);
} catch (Exception e) {
log.error("SubjectController.getContributeList.error:{}", e.getMessage(), e);
return Result.fail("获取贡献榜失败!");
}
}
}

View File

@@ -1,8 +1,6 @@
package com.landaiqing.subject.application.convert;
import com.landaiqing.subject.application.dto.SubjectCategoryDTO;
import com.landaiqing.subject.application.dto.SubjectInfoDTO;
import com.landaiqing.subject.domain.entity.SubjectCategoryBO;
import com.landaiqing.subject.domain.entity.SubjectInfoBO;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
@@ -21,6 +19,7 @@ public interface SubjectInfoDTOConverter {
SubjectInfoBO convertDtoToBO(SubjectInfoDTO subjectInfoDTO);
SubjectInfoDTO convertBOToDTO(SubjectInfoBO subjectInfoBO);
List<SubjectInfoDTO> convertBOToDTOList(List<SubjectInfoBO> subjectInfoBO);
}

View File

@@ -4,7 +4,6 @@ import com.landaiqing.subject.common.entity.PageInfo;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
/**
@@ -74,6 +73,18 @@ public class SubjectInfoDTO extends PageInfo implements Serializable {
private List<String> labelName;
private String keyWord;
/**
* 创建人昵称
*/
private String creatUser;
/**
* 创建人头像
*/
private String createUserAvatar;
/**
* 题目数量
*/
private Integer subjectCount;
}

View File

@@ -4,7 +4,6 @@ import feign.RequestInterceptor;
import feign.RequestTemplate;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

View File

@@ -1,13 +1,12 @@
package com.landaiqing.subject.application.interceptor;
import com.landaiqing.subject.application.context.LoginContextHolder;
import com.landaiqing.subject.common.context.LoginContextHolder;
import org.apache.commons.lang3.StringUtils;
import org.springframework.lang.Nullable;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Enumeration;
/**
* @Classname LoginInterceptor
@@ -22,7 +21,9 @@ public class LoginInterceptor implements HandlerInterceptor {
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
String loginId = request.getHeader("loginId");
LoginContextHolder.set("loginId",loginId);
if (StringUtils.isNotBlank(loginId)) {
LoginContextHolder.set("loginId", loginId);
}
return true;
}

View File

@@ -1,19 +0,0 @@
package com.landaiqing.subject.application.util;
import com.landaiqing.subject.application.context.LoginContextHolder;
/**
* @Classname LoginUtil
* @BelongsProject: qing-yu-club
* @BelongsPackage: com.landaiqing.subject.application.util
* @Author: landaiqing
* @CreateTime: 2024-03-03 18:33
* @Description: 用户登录util
* @Version: 1.0
*/
public class LoginUtil {
public static String getLoginId() {
return LoginContextHolder.getLoginId();
}
}