Переглянути джерело

学生检索业务功能改造传参方式,加入对外api

zhaosongshan 7 місяців тому
батько
коміт
e501837cab

+ 4 - 0
snowy-plugin/snowy-plugin-disk/snowy-plugin-disk-api/src/main/java/vip/xiaonuo/disk/api/NetDiskApi.java

@@ -1,5 +1,8 @@
 package vip.xiaonuo.disk.api;
 
+import com.alibaba.fastjson.JSONObject;
+import java.util.Map;
+
 /**
  * 网盘 api
  */
@@ -12,4 +15,5 @@ public interface NetDiskApi {
      */
     void insertUserRole(String userId);
 
+    JSONObject downList(Map<String, Object> param);
 }

+ 26 - 21
snowy-plugin/snowy-plugin-disk/snowy-plugin-disk-func/src/main/java/vip/xiaonuo/disk/controller/CourseStudentRelateController.java

@@ -327,29 +327,34 @@ public class CourseStudentRelateController {
     @SaCheckPermission("/disk/coursestudentrelate/downList")
     @GetMapping("/disk/coursestudentrelate/downList")
     public CommonResult<Page<Map<String,Object>>> downList(CourseStudentRelatePageParam courseStudentRelatePageParam, HttpServletRequest req) {
-        Map param =new HashMap();
-        param.put("collegeId", req.getParameter("collegeId"));
-        String courseId="";
-        if(StringUtils.isNotEmpty(req.getParameter("courseId"))){
-            courseId=req.getParameter("courseId");
-        }else if(StringUtils.isNotEmpty(req.getParameter("gradesId")))
-        {
-            param.put("gradesId", req.getParameter("gradesId"));
-        }else if(StringUtils.isNotEmpty(req.getParameter("chapterId")))
-        {
-            Chapter chapter = chapterService.queryEntity(req.getParameter("chapterId"));
-            courseId=chapter.getCourseId();
-        }
-        else if(StringUtils.isNotEmpty(req.getParameter("hourId")))
-        {
-            ClassHour classHour = classHourService.queryEntity(req.getParameter("hourId"));
-            Chapter chapter = chapterService.queryEntity(classHour.getChapterId());
-            courseId=chapter.getCourseId();
+        Map<String,Object> param = convertRequestParamsToMapWithMultiValues(req);
+        return CommonResult.data(courseStudentRelateService.downList(param));
+    }
+
+
+    /**
+     * 将HttpServletRequest中的查询参数转换为Map(支持多值参数)
+     * @param request HTTP请求对象
+     * @return 包含所有参数的Map
+     */
+    public static Map<String, Object> convertRequestParamsToMapWithMultiValues(HttpServletRequest request) {
+        Map<String, Object> paramsMap = new HashMap<>();
+        Map<String, String[]> parameterMap = request.getParameterMap();
+
+        for (Map.Entry<String, String[]> entry : parameterMap.entrySet()) {
+            String paramName = entry.getKey();
+            String[] paramValues = entry.getValue();
+
+            if (paramValues.length == 1) {
+                paramsMap.put(paramName, paramValues[0]);
+            } else if (paramValues.length > 1) {
+                paramsMap.put(paramName, Arrays.asList(paramValues));
+            } else {
+                paramsMap.put(paramName, "");
+            }
         }
-        param.put("courseId", courseId);
-        Page<Map<String,Object>> page=courseStudentRelateService.downList(param);
 
-        return CommonResult.data(page);
+        return paramsMap;
     }
 
 

+ 42 - 0
snowy-plugin/snowy-plugin-disk/snowy-plugin-disk-func/src/main/java/vip/xiaonuo/disk/provider/NetDiskApiProvider.java

@@ -1,10 +1,18 @@
 package vip.xiaonuo.disk.provider;
 
+import com.alibaba.fastjson.JSONObject;
+import com.alibaba.fastjson2.JSON;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import org.springframework.stereotype.Service;
 import vip.xiaonuo.disk.api.NetDiskApi;
+import vip.xiaonuo.disk.service.CourseStudentRelateService;
 import vip.xiaonuo.disk.service.impl.UserService;
 
 import javax.annotation.Resource;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
 
 /**
  * 网盘服务api的实现类
@@ -15,9 +23,43 @@ public class NetDiskApiProvider implements NetDiskApi {
     @Resource
     private UserService userService;
 
+    @Resource
+    private CourseStudentRelateService courseStudentRelateService;
 
     @Override
     public void insertUserRole(String userId) {
         userService.insertUserRole(userId);
     }
+
+    @Override
+    public JSONObject downList(Map<String, Object> param) {
+        JSONObject jsonObject = new JSONObject();
+        try {
+            Page<Map<String,Object>>  page = courseStudentRelateService.downList(param);
+            List<Map<String, Object>> records = page.getRecords();
+            List<JSONObject> jsonObjectList = new ArrayList<JSONObject>();
+            if(records != null && !records.isEmpty()){
+                jsonObjectList = records.stream()
+                        .map(map -> JSON.parseObject(JSON.toJSONString(map), JSONObject.class))
+                        .collect(Collectors.toList());
+            }
+            JSONObject data = new JSONObject();
+            data.put("total", page.getTotal());
+            data.put("size", page.getSize());
+            data.put("current", page.getCurrent());
+            data.put("pages", page.getPages());
+            data.put("records", jsonObjectList);
+
+            jsonObject.put("code", 200);
+            jsonObject.put("msg", "获取成功");
+            jsonObject.put("data", data);
+        } catch (Exception e) {
+            jsonObject.put("code", 500);
+            jsonObject.put("msg", "获取失败");
+            jsonObject.put("data", null);
+            jsonObject.put("error", e.getMessage());
+            e.printStackTrace();
+        }
+        return jsonObject;
+    }
 }

+ 1 - 1
snowy-plugin/snowy-plugin-disk/snowy-plugin-disk-func/src/main/java/vip/xiaonuo/disk/service/CourseStudentRelateService.java

@@ -148,5 +148,5 @@ public interface CourseStudentRelateService extends IService<CourseStudentRelate
     /**
      *  获取关联学生-下拉列表
      */
-    Page<Map<String,Object>> downList(Map param);
+    Page<Map<String,Object>> downList(Map<String,Object> param);
 }

+ 36 - 7
snowy-plugin/snowy-plugin-disk/snowy-plugin-disk-func/src/main/java/vip/xiaonuo/disk/service/impl/CourseStudentRelateServiceImpl.java

@@ -36,10 +36,14 @@ import vip.xiaonuo.common.exception.CommonException;
 import vip.xiaonuo.common.page.CommonPageRequest;
 import vip.xiaonuo.common.util.CommonDownloadUtil;
 import vip.xiaonuo.common.util.CommonResponseUtil;
+import vip.xiaonuo.disk.domain.Chapter;
+import vip.xiaonuo.disk.domain.ClassHour;
 import vip.xiaonuo.disk.domain.CourseStudentRelate;
 import vip.xiaonuo.disk.domain.ResourceRecordUserRelate;
 import vip.xiaonuo.disk.mapper.CourseStudentRelateMapper;
 import vip.xiaonuo.disk.param.coursestudentrelate.*;
+import vip.xiaonuo.disk.service.ChapterService;
+import vip.xiaonuo.disk.service.ClassHourService;
 import vip.xiaonuo.disk.service.CourseStudentRelateService;
 import vip.xiaonuo.sys.modular.user.entity.SysUser;
 import vip.xiaonuo.sys.modular.user.param.SysUserImportParam;
@@ -70,6 +74,10 @@ public class CourseStudentRelateServiceImpl extends ServiceImpl<CourseStudentRel
     private CourseStudentRelateMapper courseStudentRelateMapper;
     @Resource
     private SysUserService sysUserService;
+    @Resource
+    private ChapterService chapterService;
+    @Resource
+    private ClassHourService classHourService;
 
     @Override
     public Page<CourseStudentRelate> page(CourseStudentRelatePageParam courseStudentRelatePageParam) {
@@ -262,17 +270,38 @@ public class CourseStudentRelateServiceImpl extends ServiceImpl<CourseStudentRel
     }
 
     @Override
-    public Page<Map<String,Object>> downList(Map param)
+    public Page<Map<String,Object>> downList(Map<String,Object> param)
     {
+        String courseId="";
+        if(param.get("courseId") != null && StringUtils.isNotEmpty(param.get("courseId").toString())){
+            courseId=param.get("courseId").toString();
+        }else if(param.get("gradesId") != null && StringUtils.isNotEmpty(param.get("gradesId").toString()))
+        {
+            param.put("gradesId", param.get("gradesId").toString());
+        }else if(param.get("chapterId") != null && StringUtils.isNotEmpty(param.get("chapterId").toString()))
+        {
+            Chapter chapter = chapterService.queryEntity(param.get("chapterId").toString());
+            courseId=chapter.getCourseId();
+        }
+        else if(param.get("hourId") != null && StringUtils.isNotEmpty(param.get("hourId").toString()))
+        {
+            ClassHour classHour = classHourService.queryEntity(param.get("hourId").toString());
+            Chapter chapter = chapterService.queryEntity(classHour.getChapterId());
+            courseId=chapter.getCourseId();
+        }
+        param.put("courseId", courseId);
 
-        HttpServletRequest request = getRequest();
-        Page<Object> objectPage =null;
-        if(StringUtils.isEmpty(request.getParameter("size"))&&StringUtils.isEmpty(request.getParameter("current"))) {
+        int current = 1;
+        int size = Integer.MAX_VALUE;
 
-            objectPage = new Page<>(1, 1000);
-        }else{
-            objectPage =CommonPageRequest.defaultPage();
+        if(param.get("current") != null && param.get("current") instanceof Integer){
+            current = (Integer) param.get("current");
         }
+        if(param.get("size") != null && param.get("size") instanceof Integer){
+            size = (Integer) param.get("size");
+        }
+
+        Page<Object> objectPage = new Page<>(current, size);
         return courseStudentRelateMapper.downList(param,objectPage);
     }
 

+ 5 - 0
snowy-plugin/snowy-plugin-exam/snowy-plugin-exam-func/pom.xml

@@ -119,5 +119,10 @@
             <groupId>vip.xiaonuo</groupId>
             <artifactId>snowy-plugin-dev-api</artifactId>
         </dependency>
+
+        <dependency>
+            <groupId>vip.xiaonuo</groupId>
+            <artifactId>snowy-plugin-disk-api</artifactId>
+        </dependency>
     </dependencies>
 </project>