zouxuan 5 years ago
parent
commit
7eb5cac5bf

+ 26 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/dao/StudentManageDao.java

@@ -168,4 +168,30 @@ public interface StudentManageDao {
      * @return
      */
     int countStudentVipGroupClass(Map<String, Object> params);
+
+    /**
+     * 查询有课的学员
+     * @return
+     */
+    List<Integer> queryHasCourse();
+
+    /**
+     * 查询没课的学员
+     * @return
+     */
+    List<Integer> queryNotCourse();
+
+    /**
+     * 获取用户是否有课
+     * @param userIds
+     * @return
+     */
+    List<Map<Integer, Boolean>> queryStudentHasCourse(@Param("userIds") List<Integer> userIds);
+
+    /**
+     * 获取未激活,有课的列表
+     * @return
+     */
+    List<StudentHasCourseDto> queryHasCourseStudent(@Param("organId") String organId);
+
 }

+ 53 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/dto/StudentHasCourseDto.java

@@ -0,0 +1,53 @@
+package com.ym.mec.biz.dal.dto;
+
+public class StudentHasCourseDto{
+    private String organName;
+
+    private String userName;
+
+    private String musicGroupName;
+
+    private String vipGroupName;
+
+    private Integer userId;
+
+    public Integer getUserId() {
+        return userId;
+    }
+
+    public void setUserId(Integer userId) {
+        this.userId = userId;
+    }
+
+    public String getOrganName() {
+        return organName;
+    }
+
+    public void setOrganName(String organName) {
+        this.organName = organName;
+    }
+
+    public String getUserName() {
+        return userName;
+    }
+
+    public void setUserName(String userName) {
+        this.userName = userName;
+    }
+
+    public String getMusicGroupName() {
+        return musicGroupName;
+    }
+
+    public void setMusicGroupName(String musicGroupName) {
+        this.musicGroupName = musicGroupName;
+    }
+
+    public String getVipGroupName() {
+        return vipGroupName;
+    }
+
+    public void setVipGroupName(String vipGroupName) {
+        this.vipGroupName = vipGroupName;
+    }
+}

+ 11 - 1
mec-biz/src/main/java/com/ym/mec/biz/dal/dto/StudentManageListDto.java

@@ -44,7 +44,17 @@ public class StudentManageListDto {
     @ApiModelProperty(value = "课程余额")
     private BigDecimal courseBalance;
     
-    private Boolean isActive = false;
+    private Boolean isActive;
+
+    private Long hasCourse;
+
+    public Long getHasCourse() {
+        return hasCourse;
+    }
+
+    public void setHasCourse(Long hasCourse) {
+        this.hasCourse = hasCourse;
+    }
 
     public String getNation() {
         return nation;

+ 23 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/page/StudentManageQueryInfo.java

@@ -5,6 +5,8 @@ import io.swagger.annotations.ApiModelProperty;
 import com.ym.mec.biz.dal.enums.ClassGroupStudentStatusEnum;
 import com.ym.mec.common.page.QueryInfo;
 
+import java.util.List;
+
 /**
  * @Author Joburgess
  * @Date 2019/9/19
@@ -14,6 +16,9 @@ public class StudentManageQueryInfo extends QueryInfo {
     @ApiModelProperty(value = "部门ID")
     private String organId;
 
+    @ApiModelProperty(value = "学员编号")
+    private List<Integer> userIds;
+
     @ApiModelProperty(value = "乐团ID")
     private String musicGroupId;
 
@@ -25,6 +30,24 @@ public class StudentManageQueryInfo extends QueryInfo {
     
     private Boolean isActive;
 
+    private Boolean hasCourse;
+
+    public List<Integer> getUserIds() {
+        return userIds;
+    }
+
+    public void setUserIds(List<Integer> userIds) {
+        this.userIds = userIds;
+    }
+
+    public Boolean getHasCourse() {
+        return hasCourse;
+    }
+
+    public void setHasCourse(Boolean hasCourse) {
+        this.hasCourse = hasCourse;
+    }
+
     public String getStudentName() {
         return studentName;
     }

+ 7 - 0
mec-biz/src/main/java/com/ym/mec/biz/service/StudentManageService.java

@@ -130,4 +130,11 @@ public interface StudentManageService {
      * @return
      */
     List<StudentRegisterPerDto> queryStudentPer();
+
+    /**
+     * 获取有课没有激活的列表
+     * @return
+     */
+    List<StudentHasCourseDto> queryHasCourseStudent(String organId);
+
 }

+ 20 - 3
mec-biz/src/main/java/com/ym/mec/biz/service/impl/StudentManageServiceImpl.java

@@ -58,6 +58,16 @@ public class StudentManageServiceImpl implements StudentManageService {
     @Override
     public PageInfo findStudentsByOrganId(StudentManageQueryInfo queryInfo) {
         PageInfo<StudentManageListDto> pageInfo = new PageInfo<>(queryInfo.getPage(), queryInfo.getRows());
+        Boolean hasCourse = queryInfo.getHasCourse();
+        if(hasCourse != null){
+            List<Integer> userIds;
+            if(hasCourse){
+                userIds = studentManageDao.queryHasCourse();
+            }else {
+                userIds = studentManageDao.queryNotCourse();
+            }
+            queryInfo.setUserIds(userIds);
+        }
         Map<String, Object> params = new HashMap<>();
         MapUtil.populateMap(params, queryInfo);
 
@@ -70,11 +80,13 @@ public class StudentManageServiceImpl implements StudentManageService {
             List<Integer> userIds = dataList.stream()
                     .map(StudentManageListDto::getUserId).collect(Collectors.toList());
             List<SysUserCashAccount> byUserIds = sysUserCashAccountDao.findByUserIds(userIds);
+            Map<Integer,Long> hasCourseMap = MapUtil.convertIntegerMap(studentManageDao.queryStudentHasCourse(userIds));
             Map<Integer, SysUserCashAccount> collect = byUserIds.stream()
                     .collect(Collectors.toMap(SysUserCashAccount::getUserId, sysUserCashAccount -> sysUserCashAccount));
-            dataList.forEach(studentManageListDto -> {
-                if(collect.get(studentManageListDto.getUserId()) != null){
-                    studentManageListDto.setCourseBalance(collect.get(studentManageListDto.getUserId()).getCourseBalance());
+            dataList.forEach(e -> {
+                e.setHasCourse(hasCourseMap.get(e.getUserId()));
+                if(collect.get(e.getUserId()) != null){
+                    e.setCourseBalance(collect.get(e.getUserId()).getCourseBalance());
                 }
             });
         }
@@ -324,4 +336,9 @@ public class StudentManageServiceImpl implements StudentManageService {
     public List<StudentRegisterPerDto> queryStudentPer() {
         return studentRegistrationDao.queryStudentPer();
     }
+
+    @Override
+    public List<StudentHasCourseDto> queryHasCourseStudent(String organId) {
+        return studentManageDao.queryHasCourseStudent(organId);
+    }
 }

+ 53 - 0
mec-biz/src/main/resources/config/mybatis/StudentManageDao.xml

@@ -143,6 +143,12 @@
             <if test="isActive != null and isActive == false">
             	and su.password_ is null
             </if>
+            <if test="userIds != null">
+                AND su.id_ IN
+                <foreach collection="userIds" open="(" close=")" separator="," item="item">
+                    #{item}
+                </foreach>
+            </if>
         </where>
     </sql>
 
@@ -529,5 +535,52 @@
             AND vg.status_ = #{vipGroupStatus}
         </if>
     </select>
+    <select id="queryHasCourse" resultType="java.lang.Integer">
+        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'
+    </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>
+    <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
+        LEFT JOIN course_schedule cs ON cs.id_ = cssp.course_schedule_id_
+        <where>
+            <if test="userIds != null">
+                cssp.user_id_ IN
+                <foreach collection="userIds" open="(" close=")" separator="," item="item">
+                    #{item}
+                </foreach>
+            </if>
+        </where>
+        GROUP BY cssp.user_id_
+    </select>
+    <resultMap id="StudentHasCourseDtoMap" type="com.ym.mec.biz.dal.dto.StudentHasCourseDto">
+        <result property="userName" column="username_"/>
+        <result property="musicGroupName" column="music_group_name_"/>
+        <result property="vipGroupName" column="vip_group_name_"/>
+        <result property="organName" column="organ_name_"/>
+        <result property="userId" column="id_"/>
+    </resultMap>
+    <select id="queryHasCourseStudent" resultMap="StudentHasCourseDtoMap">
+        SELECT su.id_,GROUP_CONCAT(DISTINCT su.username_) username_,GROUP_CONCAT(DISTINCT mg.name_) music_group_name_,
+        GROUP_CONCAT(DISTINCT vg.name_) vip_group_name_,GROUP_CONCAT(DISTINCT o.name_) organ_name_ FROM sys_user su
+        LEFT JOIN course_schedule_student_payment cssp ON su.id_ = cssp.user_id_
+        LEFT JOIN course_schedule cs ON cs.id_ = cssp.course_schedule_id_
+        LEFT JOIN music_group mg ON cssp.music_group_id_ = mg.id_ AND cssp.group_type_ = 'MUSIC'
+        LEFT JOIN vip_group vg ON cssp.music_group_id_ = vg.id_ AND cssp.group_type_ = 'VIP'
+        LEFT JOIN organization o ON su.organ_id_ = o.id_
+        WHERE cs.status_ != 'OVER' AND su.password_ IS NULL AND su.user_type_ = 'STUDENT'
+        <if test="organId != null">
+            AND FIND_IN_SET(su.organ_id_,#{organId})
+        </if>
+        GROUP BY su.id_
+    </select>
 
 </mapper>

+ 16 - 8
mec-biz/src/main/resources/config/mybatis/StudentRegistrationMapper.xml

@@ -268,7 +268,7 @@
     <select id="queryStudentDetailPage" resultMap="studentApplyDetail">
         SELECT sr.id_, sr.user_id_,su.username_ username_,sr.parents_name_,sr.current_class_,sr.current_grade_,
         su.gender_,sr.is_allow_adjust_, s.name_ subject_name_,ss.name_
-        actual_subject_name_,sr.parents_phone_,sr.payment_status_,sr.remark_,sr.actual_subject_id_
+        actual_subject_name_,su.phone_ parents_phone_,sr.payment_status_,sr.remark_,sr.actual_subject_id_
         FROM student_registration sr
         LEFT JOIN sys_user su ON sr.user_id_ = su.id_
         LEFT JOIN `subject` s ON sr.subject_id_ = s.id_
@@ -556,13 +556,21 @@
         <result property="perNum" column="per_num_"/>
     </resultMap>
     <select id="queryStudentPer" resultMap="StudentRegisterPerDtoMap">
-        SELECT o.`name_` organ_name_ ,a.n student_num_,ifnull(b.num,0) per_num_,ifnull(b.num,0)*100/a.n per_ FROM
-        (SELECT u.`organ_id_` ,count(u.id_) n from `sys_user` u WHERE u.`user_type_` = 'STUDENT' GROUP BY u.`organ_id_` ) a
-        left join
-        (select u.`organ_id_`,count(ifnull(u.id_,0)) num  from `sys_user` u WHERE u.`password_` IS NOT NULL and u.`user_type_` = 'STUDENT' GROUP BY u.`organ_id_` ) b
-        on a.organ_id_ = b.organ_id_ LEFT JOIN `organization` o on o.`id_` = a.organ_id_
-        WHERE o.del_flag_ != 1 AND o.id_ IS NOT NULL
-        ORDER BY per_num_ DESC
+        SELECT a.name_ organ_name_,a.num student_num_,b.num per_num_,ifnull(b.num,0)*100/a.num per_ FROM (
+        SELECT b.name_,COUNT(a.id_) num,b.id_ FROM sys_user a LEFT JOIN organization b on a.organ_id_=b.id_
+        WHERE a.id_ IN(
+        SELECT b.id_ FROM course_schedule_student_payment a LEFT JOIN sys_user b ON a.user_id_=b.id_ WHERE b.user_type_='STUDENT' GROUP BY a.user_id_,b.organ_id_ )
+        AND b.del_flag_ = 0
+        GROUP BY organ_id_) a
+        LEFT JOIN
+        (SELECT b.name_,COUNT(a.id_) num,b.id_ FROM sys_user a LEFT JOIN organization b on a.organ_id_=b.id_
+        WHERE a.id_ IN(
+        SELECT b.id_ FROM course_schedule_student_payment a LEFT JOIN sys_user b ON a.user_id_=b.id_ WHERE b.user_type_='STUDENT' AND password_ IS NOT NULL GROUP BY a.user_id_,b.organ_id_ )
+        AND b.del_flag_ = 0
+        GROUP BY organ_id_) b
+        ON a.id_=b.id_
+        WHERE a.name_ IS NOT NULL
+        ORDER BY per_ DESC
     </select>
 
     <update id="updateUser">

+ 32 - 0
mec-web/src/main/java/com/ym/mec/web/controller/ExportController.java

@@ -1,12 +1,16 @@
 package com.ym.mec.web.controller;
 
+import com.ym.mec.auth.api.client.SysUserFeignService;
+import com.ym.mec.auth.api.entity.SysUser;
 import com.ym.mec.biz.dal.dto.StudentApplyDetailDto;
+import com.ym.mec.biz.dal.dto.StudentHasCourseDto;
 import com.ym.mec.biz.dal.dto.TeacherSalaryDto;
 import com.ym.mec.biz.dal.dto.musicalListDetailDto;
 import com.ym.mec.biz.dal.entity.Goods;
 import com.ym.mec.biz.dal.page.CourseScheduleTeacherSalaryQueryInfo;
 import com.ym.mec.biz.dal.page.StudentRegistrationQueryInfo;
 import com.ym.mec.biz.service.CourseScheduleTeacherSalaryService;
+import com.ym.mec.biz.service.StudentManageService;
 import com.ym.mec.biz.service.StudentPaymentOrderDetailService;
 import com.ym.mec.biz.service.StudentRegistrationService;
 import com.ym.mec.common.controller.BaseController;
@@ -21,6 +25,7 @@ import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.stereotype.Controller;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
+
 import javax.servlet.http.HttpServletResponse;
 import java.util.Date;
 import java.util.List;
@@ -33,9 +38,36 @@ public class ExportController extends BaseController {
     @Autowired
     private StudentRegistrationService studentRegistrationService;
     @Autowired
+    private StudentManageService studentManageService;
+    @Autowired
     private StudentPaymentOrderDetailService studentPaymentOrderDetailService;
     @Autowired
     private CourseScheduleTeacherSalaryService courseScheduleTeacherSalaryService;
+    @Autowired
+    private SysUserFeignService sysUserFeignService;
+
+    @ApiOperation(value = "导出学员是否有课")
+    @PostMapping("export/studentHasCourse")
+    @PreAuthorize("@pcs.hasPermissions('export/studentHasCourse')")
+    public void studentHasCourse(HttpServletResponse response){
+        SysUser sysUser = sysUserFeignService.queryUserInfo();
+        if(sysUser == null){
+            throw new BizException("获取用户信息失败");
+        }
+        List<StudentHasCourseDto> hasCourseDtos =  studentManageService.queryHasCourseStudent(sysUser.getOrganId());
+        try {
+            HSSFWorkbook workbook = POIUtil.exportExcel(new String[] {"学员编号", "姓名","分部","所在乐团","所在vip课"}, new String[] {
+                    "userId","userName","organName","musicGroupName","vipGroupName"}, hasCourseDtos);
+            response.setContentType("application/octet-stream");
+            response.setHeader("Content-Disposition", "attachment;filename=lender-" + DateUtil.getDate(new Date()) + ".xls");
+            response.flushBuffer();
+            workbook.write(response.getOutputStream());
+            workbook.close();
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+
 
     @ApiOperation(value = "导出乐器采购清单")
     @PostMapping("order/musicalListExport")