Browse Source

bug修复

dzx 1 year ago
parent
commit
a22704b5fb

+ 39 - 8
src/main/java/com/xjrsoft/module/banding/service/impl/BandingTaskServiceImpl.java

@@ -42,6 +42,7 @@ import com.xjrsoft.module.organization.entity.UserRoleRelation;
 import com.xjrsoft.module.organization.service.IUserRoleRelationService;
 import com.xjrsoft.module.organization.service.IUserService;
 import com.xjrsoft.module.outint.vo.IdCountVo;
+import com.xjrsoft.module.banding.vo.IdManyCountVo;
 import com.xjrsoft.module.student.entity.BaseClassMajorSet;
 import com.xjrsoft.module.student.entity.BaseNewStudent;
 import com.xjrsoft.module.student.entity.BaseStudent;
@@ -174,18 +175,38 @@ public class BandingTaskServiceImpl extends MPJBaseServiceImpl<BandingTaskMapper
         );
         List<String> ruleCodes = ruleList.stream().map(BandingRule::getCode).collect(Collectors.toList());
 
+        //查询每个专业符合限制条件的人数
+        List<IdManyCountVo> majorStudentCountList = newStudentService.getMajorStudentCount(bandingTask.getId());
+        Map<Long, IdManyCountVo> majorStudentCountMap = majorStudentCountList.stream().collect(Collectors.toMap(IdManyCountVo::getId, x -> x));
+        //查询每个专业下面有多少个班级
+        List<IdCountVo> majorClassCountList = taskClassMapper.getMajorClassCount(bandingTask.getId());
+        Map<Long, Integer> majorClassCount = majorClassCountList.stream().collect(Collectors.toMap(IdCountVo::getId, IdCountVo::getCount));
+        //计算每个专业平均的男女人数
+        Map<Long, Integer> majorMaleCountMap = new HashMap<>();
+        Map<Long, Integer> majorFemaleCountMap = new HashMap<>();
+        if(ruleCodes.contains("BR0001")){
+            for (Long majorSetId : majorClassCount.keySet()) {
+                int classCount = majorClassCount.get(majorSetId);
+                Integer maleCount = majorStudentCountMap.get(majorSetId).getMaleCount();
+                Integer femaleCount = majorStudentCountMap.get(majorSetId).getFemaleCount();
+                if(classCount == 1 || classCount == 0){
+                    majorMaleCountMap.put(majorSetId, maleCount);
+                    majorFemaleCountMap.put(majorSetId, femaleCount);
+                    continue;
+                }
+                majorMaleCountMap.put(majorSetId, maleCount / classCount);
+                majorFemaleCountMap.put(majorSetId, femaleCount / classCount);
+            }
+        }
+
         //包含下面个条件,则需要计算每个班级应该分配的人数
         Map<Long, Integer> classLimitMap = new HashMap<>();
         if(ruleCodes.contains("BR0004")){
-            //查询每个专业下面有多少个班级
-            List<IdCountVo> majorClassCountList = taskClassMapper.getMajorClassCount(bandingTask.getId());
-            Map<Long, Integer> majorClassCount = majorClassCountList.stream().collect(Collectors.toMap(IdCountVo::getId, IdCountVo::getCount));
             //查询每个专业下面的班级人数
             Map<Long, Integer> majorClassStudentCount = taskClassMapper.getMajorClassStudentCount(bandingTask.getId())
                     .stream().collect(Collectors.toMap(IdCountVo::getId, IdCountVo::getCount));
-            //查询每个专业符合限制条件的人数
-            Map<Long, Integer> majorStudentCount = newStudentService.getMajorStudentCount(bandingTask.getId())
-                    .stream().collect(Collectors.toMap(IdCountVo::getId, IdCountVo::getCount));
+
+            Map<Long, Integer> majorStudentCount = majorStudentCountList.stream().collect(Collectors.toMap(IdManyCountVo::getId, IdManyCountVo::getCount));
 
             Map<Long, Integer> majorLimitMap = new HashMap<>();
             for (Long majorSetId : majorClassStudentCount.keySet()) {
@@ -193,7 +214,7 @@ public class BandingTaskServiceImpl extends MPJBaseServiceImpl<BandingTaskMapper
                 if(majorClassStudentCount.get(majorSetId) != null){
                     majorClassNumber = majorClassStudentCount.get(majorSetId);
                 }
-                if(majorClassNumber == 1 || majorClassNumber == 0){
+                if(majorClassCount.get(majorSetId) == 1 || majorClassCount.get(majorSetId) == 0){
                     continue;
                 }
                 int majorStudentNumber = 0;
@@ -214,6 +235,7 @@ public class BandingTaskServiceImpl extends MPJBaseServiceImpl<BandingTaskMapper
                 classLimitMap.put(bandingTaskClass.getId(), majorLimitMap.get(bandingTaskClass.getMajorSetId()));
             }
         }
+
         //查询每个专业的限制条件
         List<BandingTaskMajorCondition> list = conditionService.list(
                 new QueryWrapper<BandingTaskMajorCondition>().lambda()
@@ -228,6 +250,7 @@ public class BandingTaskServiceImpl extends MPJBaseServiceImpl<BandingTaskMapper
         if(ruleCodes.contains("BR0002")){
             classStudentMap.putAll(divideStudentByScore(classConditionMap, baseNewStudents, classList));
         }
+
         //存班级和学生的关系
         Map<Long, Long> studentClassMap = new HashMap<>();
         Map<Long, List<String>> classNameMap = new HashMap<>();
@@ -241,6 +264,7 @@ public class BandingTaskServiceImpl extends MPJBaseServiceImpl<BandingTaskMapper
             }
             Integer maleCount = 0, femaleCount = 0;
             if(ruleCodes.contains("BR0001")){
+                IdManyCountVo countVo = majorStudentCountMap.get(taskClass.getMajorSetId());
                 maleCount = number / 2;
                 femaleCount = number / 2;
                 //如果班级人数是奇数,随机分配一个名额
@@ -255,6 +279,13 @@ public class BandingTaskServiceImpl extends MPJBaseServiceImpl<BandingTaskMapper
                         femaleCount ++ ;
                     }
                 }
+                if(majorMaleCountMap.get(taskClass.getMajorSetId()) < maleCount){
+                    maleCount = countVo.getMaleCount();
+                    femaleCount = number - maleCount;
+                }else if(majorFemaleCountMap.get(taskClass.getMajorSetId()) < femaleCount){
+                    femaleCount = countVo.getFemaleCount();
+                    maleCount = number - femaleCount;
+                }
             }
             List<String> nameList = new ArrayList<>();
             List<BaseNewStudent> maleList = new ArrayList();//男生
@@ -284,7 +315,7 @@ public class BandingTaskServiceImpl extends MPJBaseServiceImpl<BandingTaskMapper
                     continue;
                 }
                 //判断该班性别是否已满,如果设置了排序,即使性别满了班级人数没满继续分班
-                if(ruleCodes.contains("BR0001") && taskClass.getSortCode() == null){
+                if(ruleCodes.contains("BR0001")){
                     if(GenderDictionaryEnum.MALE.getCode().equals(newStudent.getGender()) && maleList.size() == maleCount){
                         continue;
                     }else if(GenderDictionaryEnum.FEMALE.getCode().equals(newStudent.getGender()) && femaleList.size() == femaleCount){

+ 24 - 0
src/main/java/com/xjrsoft/module/banding/vo/IdManyCountVo.java

@@ -0,0 +1,24 @@
+package com.xjrsoft.module.banding.vo;
+
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+/**
+ * @author dzx
+ * @date 2024/7/13
+ */
+@Data
+public class IdManyCountVo {
+
+    @ApiModelProperty("主键")
+    private Long id;
+
+    @ApiModelProperty("数量")
+    private Integer count;
+
+    @ApiModelProperty("男生数量")
+    private Integer maleCount;
+
+    @ApiModelProperty("女生数量")
+    private Integer femaleCount;
+}

+ 2 - 1
src/main/java/com/xjrsoft/module/student/mapper/BaseNewStudentMapper.java

@@ -2,6 +2,7 @@ package com.xjrsoft.module.student.mapper;
 
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.github.yulichang.base.MPJBaseMapper;
+import com.xjrsoft.module.banding.vo.IdManyCountVo;
 import com.xjrsoft.module.outint.vo.IdCountVo;
 import com.xjrsoft.module.student.dto.BaseNewStudentPageDto;
 import com.xjrsoft.module.student.entity.BaseNewStudent;
@@ -32,5 +33,5 @@ public interface BaseNewStudentMapper extends MPJBaseMapper<BaseNewStudent> {
 
     List<IdCountVo> getSecondAmbitionStudentCount(@Param("gradeId") Long gradeId, @Param("enrollType") String enrollType);
 
-    List<IdCountVo> getMajorStudentCount(@Param("id") Long bandingTaskId);
+    List<IdManyCountVo> getMajorStudentCount(@Param("id") Long bandingTaskId);
 }

+ 2 - 1
src/main/java/com/xjrsoft/module/student/service/IBaseNewStudentService.java

@@ -2,6 +2,7 @@ package com.xjrsoft.module.student.service;
 
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.github.yulichang.base.MPJBaseService;
+import com.xjrsoft.module.banding.vo.IdManyCountVo;
 import com.xjrsoft.module.outint.vo.IdCountVo;
 import com.xjrsoft.module.student.dto.BaseNewStudentPageDto;
 import com.xjrsoft.module.student.entity.BaseNewStudent;
@@ -37,5 +38,5 @@ public interface IBaseNewStudentService extends MPJBaseService<BaseNewStudent> {
 
     List<IdCountVo> getMajorStudent(Long gradeId, String enrollType, Integer index);
 
-    List<IdCountVo> getMajorStudentCount(Long bandingTaskId);
+    List<IdManyCountVo> getMajorStudentCount(Long bandingTaskId);
 }

+ 2 - 1
src/main/java/com/xjrsoft/module/student/service/impl/BaseNewStudentServiceImpl.java

@@ -9,6 +9,7 @@ import com.github.yulichang.base.MPJBaseServiceImpl;
 import com.github.yulichang.wrapper.MPJLambdaWrapper;
 import com.xjrsoft.common.enums.YesOrNoEnum;
 import com.xjrsoft.common.utils.VoToColumnUtil;
+import com.xjrsoft.module.banding.vo.IdManyCountVo;
 import com.xjrsoft.module.base.entity.BaseMajorSet;
 import com.xjrsoft.module.base.service.IBaseMajorSetService;
 import com.xjrsoft.module.outint.vo.IdCountVo;
@@ -247,7 +248,7 @@ public class BaseNewStudentServiceImpl extends MPJBaseServiceImpl<BaseNewStudent
     }
 
     @Override
-    public List<IdCountVo> getMajorStudentCount(Long bandingTaskId) {
+    public List<IdManyCountVo> getMajorStudentCount(Long bandingTaskId) {
         return this.baseMapper.getMajorStudentCount(bandingTaskId);
     }
 

+ 12 - 2
src/main/resources/mapper/student/BaseNewStudentMapper.xml

@@ -97,12 +97,22 @@
         WHERE t1.delete_mark = 0 AND t2.grade_id = #{gradeId} AND t2.enroll_type = #{enrollType}
         GROUP BY t1.second_ambition_id
     </select>
-    <select id="getMajorStudentCount" resultType="com.xjrsoft.module.outint.vo.IdCountVo">
+    <select id="getMajorStudentCount" resultType="com.xjrsoft.module.banding.vo.IdManyCountVo">
         SELECT t1.id,(
         SELECT COUNT(id) FROM base_new_student WHERE delete_mark = 0
         AND (first_ambition_id = t1.id OR second_ambition_id = t1.id)
         AND score >= IFNULL(t2.score,0) AND height >= IFNULL(t2.height,0)
-        ) AS COUNT FROM base_major_set t1
+        ) AS count,(
+        SELECT COUNT(id) FROM base_new_student WHERE delete_mark = 0
+        AND (first_ambition_id = t1.id OR second_ambition_id = t1.id)
+        AND score >= IFNULL(t2.score,0) AND height >= IFNULL(t2.height,0)
+        AND gender = 'SB10001'
+        ) AS male_count,(
+        SELECT COUNT(id) FROM base_new_student WHERE delete_mark = 0
+        AND (first_ambition_id = t1.id OR second_ambition_id = t1.id)
+        AND score >= IFNULL(t2.score,0) AND height >= IFNULL(t2.height,0)
+        AND gender = 'SB10002'
+        ) AS female_count FROM base_major_set t1
         LEFT JOIN banding_task_major_condition t2 ON t1.id = t2.major_set_id AND t2.banding_task_id = #{id}
         AND t2.delete_mark = 0
         WHERE t1.delete_mark = 0