xiexiang 1 gadu atpakaļ
vecāks
revīzija
6f5a672ae2

+ 32 - 18
src/main/java/cn/cslg/pas/service/business/ReferencesService.java

@@ -21,6 +21,7 @@ import cn.cslg.pas.service.common.FileManagerService;
 import cn.cslg.pas.service.permissions.PermissionService;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@@ -30,7 +31,9 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 /**
  * @Author xiexiang
@@ -111,32 +114,31 @@ public class ReferencesService extends ServiceImpl<ReferencesMapper, References>
      * @return
      */
     public Records query(GetReferencesDTO getReferencesDTO) {
+        //初始化
         Integer projectId = getReferencesDTO.getProjectId();
         String fileName = getReferencesDTO.getFileName();
         Integer pageNum = getReferencesDTO.getCurrent();
         Integer pageSize = getReferencesDTO.getSize();
         List<OrderDTO> orderDTOList = getReferencesDTO.getOrderDTOList();
+        //分页配置
         Page<References> page = new Page<>(pageNum, pageSize);
-        LambdaQueryWrapper<References> queryWrapper = new LambdaQueryWrapper<>();
-        queryWrapper.eq(References::getProjectId, projectId);
-        queryWrapper.orderByDesc(References::getCreateTime);
+        QueryWrapper<References> queryWrapper = new QueryWrapper<>();
+        queryWrapper.lambda().eq(References::getProjectId, projectId);
         if (fileName != null && !fileName.equals("")) {
-            queryWrapper.like(References::getReferencesName, fileName);
+            queryWrapper.lambda().like(References::getReferencesName, fileName);
+        }
+        //添加排序逻辑
+        if (!orderDTOList.isEmpty() && orderDTOList.size() == 1) {
+            OrderDTO orderDTO = orderDTOList.get(0);
+            String orderByField = orderDTO.getOrderBy();
+            String column = this.getColumns(orderByField);
+            boolean isTrue = orderDTO.getOrderType() == 0 ? true : false;
+            if (orderByField != null && !orderByField.equals("")) {
+                queryWrapper.orderBy(true, isTrue, column);
+            }
+        } else {
+            queryWrapper.orderBy(true, true, "create_time");
         }
-        // 添加排序逻辑
-//        if (!orderDTOList.isEmpty() && orderDTOList.size() == 1) {
-//            OrderDTO orderDTO = orderDTOList.get(0);
-//            String orderByField = orderDTO.getOrderBy();
-//            Integer type = orderDTO.getOrderType();
-//            if (orderByField != null && !orderByField.equals("")) {
-//                if (type.equals(0)) {
-//                    queryWrapper.orderByAsc();
-//                } else {
-//                    queryWrapper.orderByDesc(orderByField);
-//                }
-//            }
-//        }
-
         IPage<References> referencesPage = this.page(page, queryWrapper);
         List<References> references = referencesPage.getRecords();
         List<ReferencesVO> referencesVOS = this.loadReferencesVO(references);
@@ -228,4 +230,16 @@ public class ReferencesService extends ServiceImpl<ReferencesMapper, References>
         return referencesVOS;
     }
 
+    public String getColumns(String column){
+        Map<String, String> map = new HashMap<>();
+        map.put("remark","remark");
+        map.put("projectName","project_id");
+        map.put("fileGuid","file_guid");
+        map.put("referencesName","references_name");
+        map.put("createName","create_id");
+        map.put("createTime","create_time");
+        String reStr = map.get(column);
+        return reStr;
+    }
+
 }