Sfoglia il codice sorgente

Merge remote-tracking branch 'origin/master'

周箭河 4 anni fa
parent
commit
d76f31e4cf

+ 2 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/dao/ClassGroupStudentMapperDao.java

@@ -14,6 +14,8 @@ import java.util.List;
 import java.util.Map;
 
 public interface ClassGroupStudentMapperDao extends BaseDAO<Long, ClassGroupStudentMapper> {
+
+    int batchUpdate(@Param("classGroupStudentMappers") List<ClassGroupStudentMapper> classGroupStudentMappers);
     /**
      * 批量插入学生
      *

+ 12 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/dao/CourseScheduleDao.java

@@ -141,6 +141,18 @@ public interface CourseScheduleDao extends BaseDAO<Long, CourseSchedule> {
     int deleteMusicGroupCourseSchedulesWithStudent(@Param("courseScheduleIds") List<Long> courseScheduleIds,
                                                    @Param("userId") Integer userId);
 
+    int deleteMusicGroupCourseSchedulesWithStudents(@Param("courseScheduleIds") List<Long> courseScheduleIds,
+                                                   @Param("userIds") List<Integer> userIds);
+
+    /**
+     * @describe 获取班级上未开始的课程
+     * @author Joburgess
+     * @date 2020.11.05
+     * @param classGroupId:
+     * @return java.util.List<com.ym.mec.biz.dal.entity.CourseSchedule>
+     */
+    List<CourseSchedule> getClassGroupNotStartCourse(@Param("classGroupId") Long classGroupId);
+
     /**
      * @param teacherId: 教师编号
      * @param classDate: 上课日期

+ 10 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/dto/MusicGroupPaymentCalenderAuditDto.java

@@ -37,6 +37,8 @@ public class MusicGroupPaymentCalenderAuditDto {
     @ApiModelProperty(value = "原价",required = false)
     private BigDecimal courseOriginalPrice;
 
+    private BigDecimal paymentAmount;
+
     @ApiModelProperty(value = "申请价格",required = false)
     private BigDecimal courseCurrentPrice;
 
@@ -73,6 +75,14 @@ public class MusicGroupPaymentCalenderAuditDto {
     @ApiModelProperty(value = "缴费截止日期",required = false)
     private String deadlinePaymentDate;
 
+    public BigDecimal getPaymentAmount() {
+        return paymentAmount;
+    }
+
+    public void setPaymentAmount(BigDecimal paymentAmount) {
+        this.paymentAmount = paymentAmount;
+    }
+
     public String getAuditMemo() {
         return auditMemo;
     }

+ 2 - 1
mec-biz/src/main/java/com/ym/mec/biz/service/ClassGroupStudentMapperService.java

@@ -10,6 +10,7 @@ import com.ym.mec.common.service.BaseService;
 
 import java.io.IOException;
 import java.util.List;
+import java.util.Set;
 
 public interface ClassGroupStudentMapperService extends BaseService<Long, ClassGroupStudentMapper> {
 
@@ -86,6 +87,6 @@ public interface ClassGroupStudentMapperService extends BaseService<Long, ClassG
      * @param studentIds:
      * @return void
      */
-    void updateClassGroupStudents(Long classGroupId, String studentIds);
+    void updateClassGroupStudents(Long classGroupId, Set<Integer> studentIds);
 
 }

+ 76 - 11
mec-biz/src/main/java/com/ym/mec/biz/service/impl/ClassGroupStudentMapperServiceImpl.java

@@ -2,15 +2,11 @@ package com.ym.mec.biz.service.impl;
 
 import java.io.IOException;
 import java.math.BigDecimal;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Date;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 import java.util.stream.Collectors;
 
+import com.ym.mec.biz.dal.dao.CourseScheduleDao;
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
@@ -49,6 +45,7 @@ import com.ym.mec.common.exception.BizException;
 import com.ym.mec.common.service.impl.BaseServiceImpl;
 import com.ym.mec.im.ImFeignService;
 import com.ym.mec.util.http.HttpUtil;
+import org.springframework.util.CollectionUtils;
 
 @Service
 public class ClassGroupStudentMapperServiceImpl extends BaseServiceImpl<Long, ClassGroupStudentMapper> implements ClassGroupStudentMapperService {
@@ -78,6 +75,8 @@ public class ClassGroupStudentMapperServiceImpl extends BaseServiceImpl<Long, Cl
     private TeacherDefaultMusicGroupSalaryService teacherDefaultMusicGroupSalaryService;
     @Autowired
     private StudentDao studentDao;
+    @Autowired
+    private CourseScheduleDao courseScheduleDao;
 
     private static String holidayUrl = "http://tool.bitefu.net/jiari/?d=";
 
@@ -357,11 +356,77 @@ public class ClassGroupStudentMapperServiceImpl extends BaseServiceImpl<Long, Cl
     }
 
     @Override
-    public void updateClassGroupStudents(Long classGroupId, String studentIds) {
+    public void updateClassGroupStudents(Long classGroupId, Set<Integer> studentIds) {
+        ClassGroup classGroup = classGroupService.get(classGroupId.intValue());
+        if(Objects.isNull(classGroup)){
+            throw new BizException("班级信息错误");
+        }
         List<ClassGroupStudentMapper> classGroupStudents = classGroupStudentMapperDao.findAllByClassGroup(classGroupId);
 
-        List<Integer> allStudentIds = new ArrayList<>();
-        List<Integer> addStudentIds = new ArrayList<>();
-        List<Integer> removeStudentIds = new ArrayList<>();
+        Set<Integer> allStudentIds = new HashSet<>();
+        Set<Integer> oldStudentIds = new HashSet<>();
+        Set<Integer> oldNormalStudentIds = new HashSet<>();
+        Set<Integer> addStudentIds;
+        Set<Integer> removeStudentIds;
+
+        if(!CollectionUtils.isEmpty(studentIds)){
+            allStudentIds = studentIds;
+        }
+
+        if(!CollectionUtils.isEmpty(classGroupStudents)){
+            oldStudentIds = classGroupStudents.stream().map(ClassGroupStudentMapper::getUserId).collect(Collectors.toSet());
+            oldNormalStudentIds = classGroupStudents.stream().filter(s -> ClassGroupStudentStatusEnum.NORMAL.equals(s.getStatus())).map(ClassGroupStudentMapper::getUserId).collect(Collectors.toSet());
+        }
+
+        Set<Integer> repeatStudentIds = allStudentIds.stream().filter(oldNormalStudentIds::contains).collect(Collectors.toSet());
+        addStudentIds = allStudentIds.stream().filter(id -> !repeatStudentIds.contains(id)).collect(Collectors.toSet());
+        removeStudentIds = oldNormalStudentIds.stream().filter(id -> !repeatStudentIds.contains(id)).collect(Collectors.toSet());
+
+        for (ClassGroupStudentMapper classGroupStudent : classGroupStudents) {
+            if(addStudentIds.contains(classGroupStudent.getUserId())){
+                classGroupStudent.setStatus(ClassGroupStudentStatusEnum.NORMAL);
+            }else if(removeStudentIds.contains(classGroupStudent.getUserId())){
+                classGroupStudent.setStatus(ClassGroupStudentStatusEnum.QUIT);
+            }
+        }
+
+        classGroupStudentMapperDao.batchUpdate(classGroupStudents);
+
+        Date now = new Date();
+        List<ClassGroupStudentMapper> classGroupStudentMappers = new ArrayList<>();
+        for (Integer addStudentId : addStudentIds) {
+            if(oldStudentIds.contains(addStudentId)){
+                continue;
+            }
+            ClassGroupStudentMapper classGroupStudentMapper = new ClassGroupStudentMapper();
+            classGroupStudentMapper.setMusicGroupId(classGroup.getMusicGroupId());
+            classGroupStudentMapper.setClassGroupId(classGroupId.intValue());
+            classGroupStudentMapper.setUserId(addStudentId);
+            classGroupStudentMapper.setCreateTime(now);
+            classGroupStudentMapper.setStatus(ClassGroupStudentStatusEnum.NORMAL);
+            classGroupStudentMapper.setGroupType(GroupType.MUSIC);
+            classGroupStudentMappers.add(classGroupStudentMapper);
+        }
+
+        if (classGroupStudentMappers.size() > 0) {
+            classGroupStudentMapperDao.classGroupStudentsInsert(classGroupStudentMappers);
+        }
+
+        classGroupService.updateClassStudentNum(classGroupId.intValue(), allStudentIds.size());
+
+        List<CourseSchedule> classGroupNotStartCourse = courseScheduleDao.getClassGroupNotStartCourse(classGroupId);
+        if(CollectionUtils.isEmpty(classGroupNotStartCourse)){
+            return;
+        }
+
+        List<Long> courseIds = classGroupNotStartCourse.stream().map(CourseSchedule::getId).collect(Collectors.toList());
+
+        if(!CollectionUtils.isEmpty(removeStudentIds)){
+            courseScheduleDao.deleteMusicGroupCourseSchedulesWithStudents(courseIds, new ArrayList<>(removeStudentIds));
+        }
+
+        if(!CollectionUtils.isEmpty(addStudentIds)){
+            courseScheduleStudentPaymentService.createForMusicGroup(classGroup.getMusicGroupId(), classGroupNotStartCourse, new ArrayList<>(addStudentIds));
+        }
     }
 }

+ 16 - 0
mec-biz/src/main/resources/config/mybatis/ClassGroupStudentMapperMapper.xml

@@ -61,6 +61,22 @@
         WHERE id_ = #{id}
     </update>
 
+    <update id="batchUpdate" parameterType="com.ym.mec.biz.dal.entity.ClassGroupStudentMapper">
+        <foreach collection="classGroupStudentMappers" item="classGroupStudentMapper" separator=";">
+            UPDATE class_group_student_mapper
+            <set>
+                <if test="classGroupStudentMapper.status != null">
+                    status_ = #{classGroupStudentMapper.status,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
+                </if>
+                <if test="classGroupStudentMapper.groupType != null">
+                    group_type_ = #{classGroupStudentMapper.groupType,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
+                </if>
+                update_time_ = now(),
+            </set>
+            WHERE id_ = #{classGroupStudentMapper.id}
+        </foreach>
+    </update>
+
     <!-- 根据主键删除一条记录 -->
     <delete id="delete">
 		DELETE FROM class_group_student_mapper WHERE id_ = #{id} 

+ 18 - 0
mec-biz/src/main/resources/config/mybatis/CourseScheduleMapper.xml

@@ -2006,6 +2006,24 @@
         </foreach>
     </delete>
 
+    <delete id="deleteMusicGroupCourseSchedulesWithStudents">
+        DELETE
+        FROM
+        course_schedule_student_payment
+        WHERE user_id_ IN
+        <foreach collection="userIds" item="userId" open="(" close=")" separator=",">
+            #{userId}
+        </foreach>
+        AND course_schedule_id_ IN
+        <foreach collection="courseScheduleIds" item="courseScheduleId" open="(" close=")" separator=",">
+            #{courseScheduleId}
+        </foreach>
+    </delete>
+
+    <select id="getClassGroupNotStartCourse" resultMap="CourseSchedule">
+        SELECT * FROM course_schedule WHERE class_group_id_=#{classGroupId} AND CONCAT(class_date_,' ', start_class_time_) &gt; NOW()
+    </select>
+
     <delete id="deleteCourseSchedulesByClassGroupIds">
         DELETE FROM course_schedule WHERE id_ IN
         <foreach collection="courseScheduleIds" item="courseScheduleId" open="(" close=")" separator=",">

+ 3 - 2
mec-biz/src/main/resources/config/mybatis/MusicGroupPaymentCalenderMapper.xml

@@ -317,7 +317,7 @@
     </select>
     <select id="queryEndIds" resultType="java.lang.Long">
         SELECT DISTINCT mgpc.id_ FROM music_group_payment_calender mgpc
-        WHERE mgpc.payment_valid_end_date_ IS NOT NULL AND DATEDIFF(mgpc.payment_valid_end_date_,#{format}) = #{configValue};
+        WHERE mgpc.payment_valid_end_date_ IS NOT NULL AND DATEDIFF(mgpc.payment_valid_end_date_,#{format}) = #{configValue} AND mgpc.payment_type_ IN ('MUSIC_APPLY','MUSIC_RENEW')
     </select>
     <resultMap id="CalenderPushDto" type="com.ym.mec.biz.dal.dto.CalenderPushDto">
         <result property="paymentValidEndDate" column="payment_valid_end_date_"/>
@@ -398,6 +398,7 @@
         <result property="startPaymentDate" column="start_payment_date_"/>
         <result property="deadlinePaymentDate" column="deadline_payment_date_"/>
         <result property="auditMemo" column="audit_memo_"/>
+        <result property="paymentAmount" column="payment_amount_"/>
     </resultMap>
     <sql id="MusicGroupPaymentCalenderAuditDtoSql">
         <where>
@@ -450,7 +451,7 @@
         mgpc.pay_user_type_,mgpc.memo_,mgpc.status_,SUM(mgpccs.course_total_minuties_) course_total_minuties_,
         SUM(mgpccs.course_original_price_) course_original_price_,SUM(mgpccs.course_current_price_) course_current_price_,
         MAX(mg.name_) music_group_name_,MAX(mg.organ_id_) organ_id_,MAX(mgpccs.name_) calender_settings_name_,mgpc.payment_pattern_,mgpc.payment_valid_start_date_,
-        mgpc.payment_valid_end_date_,mgpc.start_payment_date_,mgpc.deadline_payment_date_,mgpc.audit_memo_
+        mgpc.payment_valid_end_date_,mgpc.start_payment_date_,mgpc.deadline_payment_date_,mgpc.audit_memo_,mgpc.payment_amount_
         FROM music_group_payment_calender mgpc
         LEFT JOIN music_group mg ON mg.id_ = mgpc.music_group_id_
         LEFT JOIN music_group_payment_calender_course_settings mgpccs ON mgpc.id_ = mgpccs.music_group_payment_calender_id_

+ 10 - 0
mec-web/src/main/java/com/ym/mec/web/controller/ClassGroupStudentController.java

@@ -9,6 +9,7 @@ import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiImplicitParam;
 import io.swagger.annotations.ApiImplicitParams;
 import io.swagger.annotations.ApiOperation;
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.web.bind.annotation.GetMapping;
@@ -17,7 +18,11 @@ import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
 import java.io.IOException;
+import java.util.Arrays;
+import java.util.HashSet;
 import java.util.Objects;
+import java.util.Set;
+import java.util.stream.Collectors;
 
 @RequestMapping("classGroupStudent")
 @Api(tags = "班级学生服务")
@@ -88,6 +93,11 @@ public class ClassGroupStudentController extends BaseController {
         if(Objects.isNull(classGroupId)){
             return failed("请指定班级");
         }
+        Set<Integer> studentIdSet = new HashSet<>();
+        if(StringUtils.isNotBlank(studentIds)){
+            studentIdSet = Arrays.stream(studentIds.split(",")).map(Integer::valueOf).collect(Collectors.toSet());
+        }
+        classGroupStudentMapperService.updateClassGroupStudents(classGroupId, studentIdSet);
         return succeed();
     }
 }