zouxuan 5 年 前
コミット
9b00dfef74

+ 14 - 2
mec-biz/src/main/java/com/ym/mec/biz/dal/dao/StudentManageDao.java

@@ -173,13 +173,25 @@ public interface StudentManageDao {
      * 查询有课的学员
      * @return
      */
-    List<Integer> queryHasCourse();
+    List<Integer> queryHasCourse(Map<String, Object> params);
 
     /**
      * 查询没课的学员
      * @return
      */
-    List<Integer> queryNotCourse();
+    List<Integer> queryNotCourse(Map<String, Object> params);
+
+    /**
+     * 查询有课的学员
+     * @return
+     */
+    Integer countHasCourse(Map<String, Object> params);
+
+    /**
+     * 查询没课的学员
+     * @return
+     */
+    Integer countNotCourse(Map<String, Object> params);
 
     /**
      * 获取用户是否有课

+ 13 - 8
mec-biz/src/main/java/com/ym/mec/biz/service/impl/StudentManageServiceImpl.java

@@ -5,6 +5,7 @@ import com.ym.mec.auth.api.entity.SysUser;
 import com.ym.mec.auth.api.enums.SysUserType;
 import com.ym.mec.biz.dal.dao.*;
 import com.ym.mec.biz.dal.dto.*;
+import com.ym.mec.biz.dal.entity.CourseSchedule;
 import com.ym.mec.biz.dal.entity.MusicGroup;
 import com.ym.mec.biz.dal.entity.StudentRegistration;
 import com.ym.mec.biz.dal.entity.SysUserCashAccount;
@@ -59,23 +60,27 @@ public class StudentManageServiceImpl implements StudentManageService {
     public PageInfo findStudentsByOrganId(StudentManageQueryInfo queryInfo) {
         PageInfo<StudentManageListDto> pageInfo = new PageInfo<>(queryInfo.getPage(), queryInfo.getRows());
         Boolean hasCourse = queryInfo.getHasCourse();
+        Map<String, Object> params = new HashMap<>();
+        MapUtil.populateMap(params, queryInfo);
+        params.put("offset", pageInfo.getOffset());
+        int count = 0;
         if(hasCourse != null){
             List<Integer> userIds;
             if(hasCourse){
-                userIds = studentManageDao.queryHasCourse();
+                userIds = studentManageDao.queryHasCourse(params);
+                count = studentManageDao.countHasCourse(params);
             }else {
-                userIds = studentManageDao.queryNotCourse();
+                userIds = studentManageDao.queryNotCourse(params);
+                count = studentManageDao.countNotCourse(params);
             }
-            queryInfo.setUserIds(userIds);
+            params.remove("offset");
+            params.put("userIds",userIds);
+        }else {
+            count = studentManageDao.countStudentByOrganId(params);
         }
-        Map<String, Object> params = new HashMap<>();
-        MapUtil.populateMap(params, queryInfo);
-
         List<StudentManageListDto> dataList = null;
-        int count = studentManageDao.countStudentByOrganId(params);
         if (count > 0) {
             pageInfo.setTotal(count);
-            params.put("offset", pageInfo.getOffset());
             dataList = studentManageDao.findStudentsByOrganId(params);
             List<Integer> userIds = dataList.stream()
                     .map(StudentManageListDto::getUserId).collect(Collectors.toList());

+ 64 - 11
mec-biz/src/main/resources/config/mybatis/StudentManageDao.xml

@@ -122,7 +122,7 @@
 
     <select id="findStudentsByOrganId" resultMap="studentManageListDto">
         SELECT su.id_ user_id_,su.username_,su.gender_,su.phone_ parents_phone_,su.real_name_,su.birthdate_,su.nation_,
-        case when su.password_ is null then 0 else 1 end isActive_
+        CASE WHEN su.password_ IS NULL THEN 0 ELSE 1 END isActive_
         FROM sys_user su
         <include refid="findStudentsByOrganIdSql"/>
         ORDER BY su.create_time_ DESC
@@ -138,10 +138,10 @@
                 AND (su.phone_ LIKE CONCAT('%',#{search},'%') OR su.username_ LIKE CONCAT('%',#{search},'%') OR su.id_ LIKE CONCAT('%',#{search},'%'))
             </if>
             <if test="isActive != null and isActive == true">
-            	and su.password_ is not null
+                AND su.password_ is not null
             </if>
             <if test="isActive != null and isActive == false">
-            	and su.password_ is null
+                AND su.password_ is null
             </if>
             <if test="userIds != null">
                 AND su.id_ IN
@@ -156,7 +156,7 @@
         SELECT COUNT(DISTINCT su.id_)
         FROM sys_user su
         LEFT JOIN student_registration sr ON su.id_ = sr.user_id_
-        <include refid="findStudentsByOrganIdSql"/>
+        <include refid="queryHasCourseSql"/>
     </select>
     <select id="findStudentBaseInfoByUserID" resultMap="studentManageListDto">
         SELECT su.username_,su.gender_,su.birthdate_,su.real_name_,su.id_ user_id_,
@@ -535,18 +535,71 @@
             AND vg.status_ = #{vipGroupStatus}
         </if>
     </select>
+    <sql id="queryHasCourseSql">
+        WHERE su.user_type_ = 'STUDENT' AND cs.status_ != 'OVER'
+        <if test="organId != null">
+            AND FIND_IN_SET(su.organ_id_,#{organId})
+        </if>
+        <if test="search != null and search != ''">
+            AND (su.phone_ LIKE CONCAT('%',#{search},'%') OR su.username_ LIKE CONCAT('%',#{search},'%') OR su.id_ LIKE CONCAT('%',#{search},'%'))
+        </if>
+        <if test="isActive != null and isActive == true">
+            and su.password_ is not null
+        </if>
+        <if test="isActive != null and isActive == false">
+            and su.password_ is null
+        </if>
+    </sql>
     <select id="queryHasCourse" resultType="java.lang.Integer">
-        SELECT DISTINCT cssp.user_id_ FROM course_schedule_student_payment cssp
+        SELECT su.id_ FROM sys_user su
+        LEFT JOIN course_schedule_student_payment cssp ON cssp.user_id_ = su.id_
         LEFT JOIN course_schedule cs ON cs.id_ = cssp.course_schedule_id_
-        WHERE cs.status_ != 'OVER'
+        <include refid="queryHasCourseSql"/>
+        GROUP BY su.id_
+        ORDER BY su.create_time_ DESC
+        <include refid="global.limit"/>
+    </select>
+    <select id="countHasCourse" resultType="java.lang.Integer">
+        SELECT COUNT(DISTINCT su.id_) FROM sys_user su
+        LEFT JOIN course_schedule_student_payment cssp ON cssp.user_id_ = su.id_
+        LEFT JOIN course_schedule cs ON cs.id_ = cssp.course_schedule_id_
+        <include refid="queryHasCourseSql"/>
     </select>
     <select id="queryNotCourse" resultType="java.lang.Integer">
-        SELECT su.id_ FROM sys_user su WHERE su.id_ NOT IN
-        (SELECT DISTINCT cssp.user_id_ FROM course_schedule_student_payment cssp
-                LEFT JOIN course_schedule cs ON cs.id_ = cssp.course_schedule_id_
-        WHERE cs.status_ != 'OVER')
-        AND su.user_type_ = 'STUDENT'
+        SELECT su.id_ FROM sys_user su
+        LEFT JOIN course_schedule_student_payment cssp ON cssp.user_id_ = su.id_
+        LEFT JOIN course_schedule cs ON cs.id_ = cssp.course_schedule_id_ AND cs.status_ != 'OVER'
+        <include refid="queryNotCourseSql"/>
+        GROUP BY su.id_
+        HAVING COUNT(cs.id_) = 0
+        ORDER BY su.create_time_ DESC
+        <include refid="global.limit"/>
     </select>
+    <select id="countNotCourse" resultType="java.lang.Integer">
+        SELECT COUNT(e.id_) FROM (SELECT su.id_ FROM sys_user su
+        LEFT JOIN course_schedule_student_payment cssp ON cssp.user_id_ = su.id_
+        LEFT JOIN course_schedule cs ON cs.id_ = cssp.course_schedule_id_ AND cs.status_ != 'OVER'
+        <include refid="queryNotCourseSql"/>
+        GROUP BY su.id_
+        HAVING COUNT(cs.id_) = 0)e
+    </select>
+    <sql id="queryNotCourseSql">
+        <where>
+            su.user_type_ = 'STUDENT'
+            <if test="organId != null">
+                AND FIND_IN_SET(su.organ_id_,#{organId})
+            </if>
+            <if test="search != null and search != ''">
+                AND (su.phone_ LIKE CONCAT('%',#{search},'%') OR su.username_ LIKE CONCAT('%',#{search},'%') OR su.id_ LIKE CONCAT('%',#{search},'%'))
+            </if>
+            <if test="isActive != null and isActive == true">
+                and su.password_ is not null
+            </if>
+            <if test="isActive != null and isActive == false">
+                and su.password_ is null
+            </if>
+        </where>
+    </sql>
     <select id="queryStudentHasCourse" resultType="java.util.Map">
         SELECT cssp.user_id_ 'key',CASE WHEN COUNT(cssp.id_ AND cs.status_ != 'OVER') = 0 THEN 0 ELSE 1 END 'value'
         FROM course_schedule_student_payment cssp