瀏覽代碼

开发任务数量查询提交

zsy 1 月之前
父節點
當前提交
9c821bf9e6

+ 10 - 2
src/main/java/com/rf/help/task/dao/repository/TaskRepository.java

@@ -7,6 +7,8 @@ import org.springframework.data.domain.Page;
 import org.springframework.data.domain.PageRequest;
 import org.springframework.data.jpa.repository.Query;
 
+import java.util.List;
+
 /**
  * @Description: 用户注册登录等相关接口
  * @Author: zsy
@@ -14,17 +16,23 @@ import org.springframework.data.jpa.repository.Query;
  */
 public interface TaskRepository extends BaseRepository<TaskEntity, String> {
 
-    @Query(value = "select * from t_task_info where task_type = ?1 " +
+    @Query(value = "select * from t_task_info where 1=1 " +
+            "and if(?1 is not null and ?1 !='',(task_type = ?1),1=1) " +
             "and if(?2 is not null and ?2 !='',(details like CONCAT('%',?2,'%') or phone like CONCAT('%',?2,'%')),1=1) " +
             "and if(?3 is not null and ?3 !='',(publish_user_id = ?3),1=1) " +
             "and if(?4 is not null and ?4 !='',(accept_user_id = ?4),1=1) " +
             "and if(?5 is not null and ?5 !='',(task_status = ?5),1=1) " +
             "order by create_time desc ",
-            countQuery = "select * from t_task_info where task_type = ?1 " +
+            countQuery = "select * from t_task_info where where 1=1 " +
+                    "and if(?1 is not null and ?1 !='',(task_type = ?1),1=1) " +
                     "and if(?2 is not null and ?2 !='',(details like CONCAT('%',?2,'%') or phone like CONCAT('%',?2,'%')),1=1) " +
                     "and if(?3 is not null and ?3 !='',(publish_user_id = ?3),1=1) " +
                     "and if(?4 is not null and ?4 !='',(accept_user_id = ?4),1=1) " +
                     "and if(?5 is not null and ?5 !='',(task_status = ?5),1=1) ",
             nativeQuery = true)
     Page<TaskEntity> findTaskList(String taskType, String searchKey, String publishUserId, String acceptUserId, String taskStatus, PageRequest of);
+
+    List<TaskEntity> findByPublishUserId(String userId);
+
+    List<TaskEntity> findByAcceptUserId(String userId);
 }

+ 11 - 0
src/main/java/com/rf/help/task/rest/TaskController.java

@@ -32,6 +32,7 @@ import java.io.FileInputStream;
 import java.io.IOException;
 import java.util.Date;
 import java.util.HashMap;
+import java.util.List;
 
 /**
  * @Description: 任务等相关接口
@@ -120,6 +121,16 @@ public class TaskController extends BaseController {
         return success(taskEntities);
     }
 
+    @GetMapping("/taskNum")
+    @ApiOperation(value = "任务数量查询", notes = "参数包括:userId:用户id")
+    public Result findTaskNum(@RequestParam String userId) {
+        List<TaskEntity> publishNum = this.taskService.findByPublishUserId(userId);
+        List<TaskEntity> acceptNum = this.taskService.findByAcceptUserId(userId);
 
+        JSONObject returnJson = new JSONObject();
+        returnJson.put("publishNum",publishNum.size());
+        returnJson.put("acceptNum",acceptNum.size());
+        return success(returnJson);
+    }
 
 }

+ 6 - 0
src/main/java/com/rf/help/task/service/TaskService.java

@@ -4,6 +4,8 @@ package com.rf.help.task.service;
 import com.rf.help.task.dao.model.TaskEntity;
 import org.springframework.data.domain.Page;
 
+import java.util.List;
+
 /**
  * @Description: 用户注册登录等相关接口
  * @Author: zsy
@@ -18,4 +20,8 @@ public interface TaskService {
     TaskEntity findById(String taskId);
 
     Page<TaskEntity> findTaskList(String taskType, String searchKey, String publishUserId, String acceptUserId, String taskStatus, int beginNum, int pageSize);
+
+    List<TaskEntity> findByPublishUserId(String userId);
+
+    List<TaskEntity> findByAcceptUserId(String userId);
 }

+ 12 - 0
src/main/java/com/rf/help/task/service/impl/TaskServiceImpl.java

@@ -12,6 +12,8 @@ import org.springframework.data.domain.Page;
 import org.springframework.data.domain.PageRequest;
 import org.springframework.stereotype.Service;
 
+import java.util.List;
+
 
 /**
  * @Description: 用户注册登录等相关接口
@@ -43,4 +45,14 @@ public class TaskServiceImpl implements TaskService {
     public Page<TaskEntity> findTaskList(String taskType, String searchKey, String publishUserId, String acceptUserId, String taskStatus, int beginNum, int pageSize) {
         return this.taskRepository.findTaskList(taskType, searchKey, publishUserId, acceptUserId, taskStatus, PageRequest.of(beginNum - 1, pageSize));
     }
+
+    @Override
+    public List<TaskEntity> findByPublishUserId(String userId) {
+        return this.taskRepository.findByPublishUserId(userId);
+    }
+
+    @Override
+    public List<TaskEntity> findByAcceptUserId(String userId) {
+        return this.taskRepository.findByAcceptUserId(userId);
+    }
 }