Browse Source

课表导入

tags/正式3.3.0
雍文秀 2 years ago
parent
commit
a50c47475c

+ 0
- 7
slive/src/main/java/com/xhkjedu/slive/controller/xz/XzController.java View File

@@ -184,14 +184,7 @@ public class XzController {
184 184
         Integer xzid = xz.getXzid();
185 185
         Integer createid = xz.getCreateid();
186 186
         N_Utils.validation(new Object[]{xzid, "行政直播id", 1, createid, "创建人id", 1});
187
-        /*Map<String, Object> map = PoiUtils.readKb(file, xz, xzService);
188
-        Integer code = (Integer) map.get("code");
189
-        if (code != 0) return new ResultVo(1, map.get("msg").toString());
190
-        LinkedHashMap<Integer, List<String>> errMsg = (LinkedHashMap<Integer, List<String>>) map.get("errMsg");
191
-        if (errMsg.size() != 0) return new ResultVo(1, null, errMsg);
192
-        List<XzDateVo> xzdatas = (List<XzDateVo>) map.get("xzdatas");*/
193 187
         return xzService.importKb(file, xzid, createid);
194
-        //return new ResultVo(0, "导入评价用户成功");
195 188
     }
196 189
 
197 190
 }

+ 3
- 0
slive/src/main/java/com/xhkjedu/slive/mapper/gradeclass/ClassTeacherMapper.java View File

@@ -25,4 +25,7 @@ public interface ClassTeacherMapper extends TkMapper<TClassTeacher> {
25 25
 
26 26
     //获取科目列表
27 27
     List<CTeacherVo> listSubjectBySubjectIds(@Param("subjectids") String subjectids);
28
+
29
+    //获取学校所有教师
30
+    List<CTeacherVo> listTeacherBySchoolId(@Param("schoolid") Integer schoolid);
28 31
 }

+ 10
- 2
slive/src/main/java/com/xhkjedu/slive/service/xz/XzService.java View File

@@ -725,6 +725,9 @@ public class XzService {
725 725
         try {
726 726
             //获取行政直播信息
727 727
             LXz xz = xzMapper.selectByPrimaryKey(xzid);
728
+            List<XzKjVo> kjs = xzKjMapper.listXzKjByXzId(xzid);//获取行政直播课节详情
729
+            Integer noTimeKjNum = kjs.stream().filter(k -> k.getBegintime() == null).collect(Collectors.toList()).size();
730
+            if (noTimeKjNum != 0) return new ResultVo(1, "请设置课节时间");
728 731
 
729 732
             //根据行政直播id获取该学校当前年份指定年级下的行政班和提高班
730 733
             Integer gradeid = xz.getGradeid();
@@ -740,16 +743,19 @@ public class XzService {
740 743
             Map<String, String> subjectNameMap = subjects2.stream().collect(Collectors.toMap(CTeacherVo::getSubjectid, CTeacherVo::getSubjectname));
741 744
             Map<Integer, String> subjectMap = subjects.stream().collect(Collectors.toMap(CTeacherVo::getTeacherid, CTeacherVo::getSubjectid));
742 745
             Map<Integer, String> classMap = classlst.stream().collect(Collectors.toMap(XzClassVo::getClassid, XzClassVo::getClassname));
746
+            List<CTeacherVo> users = classTeacherMapper.listTeacherBySchoolId(schoolid);//获取学校所有教师
747
+            Set<String> userNameSet = users.stream().map(CTeacherVo::getUsername).collect(Collectors.toCollection(TreeSet::new));
743 748
             Map<String, CTeacherVo> classTeacherMap = new HashMap<>();//班级教师map
744 749
             for (CTeacherVo teacher : teachers) {
750
+                CTeacherVo vo = users.stream().filter(u -> u.getTeacherid().equals(teacher.getTeacherid())).findFirst().orElse(null);
751
+                if (vo != null) teacher.setUsername(vo.getUsername());
745 752
                 teacher.setClassname(classMap.get(teacher.getClassid()));
746 753
                 teacher.setSubjectid(subjectMap.get(teacher.getTeacherid()));
747 754
                 teacher.setSubjectname(subjectNameMap.get(teacher.getSubjectid()));
748 755
                 classTeacherMap.put(teacher.getClassname() + "_" + teacher.getUsername(), teacher);
749 756
             }
750
-            List<XzKjVo> kjs = xzKjMapper.listXzKjByXzId(xzid);//获取行政直播课节详情
751 757
 
752
-            Map<String, Object> map = PoiUtils.readKb(file, xz, classTeacherMap, kjs);
758
+            Map<String, Object> map = PoiUtils.readKb(file, xz, classTeacherMap, userNameSet, kjs);
753 759
             Integer code = (Integer) map.get("code");
754 760
             if (code != 0) return new ResultVo(1, map.get("msg").toString());
755 761
             LinkedHashMap<String, List<String>> errMsg = (LinkedHashMap<String, List<String>>) map.get("errMsg");
@@ -819,6 +825,8 @@ public class XzService {
819 825
                 c.setGradeid(gradeid);
820 826
                 c.setClasstype(99);//已直播班级
821 827
                 c.setCreatetime(createtime);
828
+                c.setClassnum(0);
829
+                c.setClassstate(1);
822 830
                 classList.add(c);
823 831
 
824 832
                 TClassTeacher ct = new TClassTeacher();

+ 25
- 10
slive/src/main/java/com/xhkjedu/slive/utils/PoiUtils.java View File

@@ -24,6 +24,7 @@ import java.util.HashMap;
24 24
 import java.util.LinkedHashMap;
25 25
 import java.util.List;
26 26
 import java.util.Map;
27
+import java.util.Set;
27 28
 import java.util.stream.Collectors;
28 29
 
29 30
 /**
@@ -167,7 +168,7 @@ public class PoiUtils {
167 168
      * @Date 2022/6/21 15:13
168 169
      **/
169 170
     public static Map<String, Object> readKb(MultipartFile file, LXz xz
170
-            , Map<String, CTeacherVo> classTeacherMap, List<XzKjVo> kjs) {
171
+            , Map<String, CTeacherVo> classTeacherMap, Set<String> userNameSet, List<XzKjVo> kjs) {
171 172
         Map<String, Object> resultMap = new HashMap<>();
172 173
         Map<String, List<String>> errMsg = new LinkedHashMap<>();
173 174
         try {
@@ -192,6 +193,7 @@ public class PoiUtils {
192 193
                 sheet = work.getSheetAt(i);
193 194
                 String sheetName = sheet.getSheetName();
194 195
                 String sectiondate = weeks.get(sheetName);
196
+                if (sectiondate == null) continue;//没有当天的课不处理
195 197
                 int rows = sheet.getLastRowNum(); // 获取最后一个实际行的下标,比行数小1
196 198
                 int firstRowNum = sheet.getFirstRowNum(); // 获取第一个实际行的下标,(firstRowNum=0)
197 199
                 //遍历当前sheet中的所有行,排除第一行(标题)不纳入遍历
@@ -207,6 +209,7 @@ public class PoiUtils {
207 209
                     int lastCellNum = row.getLastCellNum();// 每一行的最后一列,获取列数,比最后一列列标大1
208 210
                     if (lastCellNum > daynum) lastCellNum = daynum;//节数大于课程的节数不处理
209 211
                     List<String> mrows = new ArrayList<>();
212
+                    String errMsgKey = sheetName + "第" + (x + 1) + "行";
210 213
                     //遍历所有的列
211 214
                     String classname = getCellValue(row.getCell(0));//第一列为班级
212 215
                     for (int y = firstCellNum + 1; y <= lastCellNum; y++) {
@@ -214,17 +217,22 @@ public class PoiUtils {
214 217
                         String username = getCellValue(cell);
215 218
                         if (N_Utils.isEmpty(username)) {
216 219
                             if (y == lastCellNum && N_Utils.isListNotEmpty(mrows)) {
217
-                                errMsg.put(sheetName + "_" + (x + 1), mrows);
220
+                                errMsg.put(errMsgKey, mrows);
218 221
                             }
219 222
                             continue;//教师为空执行下一条数据
220 223
                         }
221 224
                         CTeacherVo vo = classTeacherMap.get(classname + "_" + username);
222
-                        if (vo == null) {
223
-                            mrows.add("本班下教师【" + username + "】不存在");
225
+                        Integer kjorder = y;//课节排序
226
+                        XzKjVo kj = kjs.stream().filter(k -> k.getKjorder() == kjorder).findFirst().orElse(null);
227
+                        String kjname = kj.getKjname();
228
+                        if (!userNameSet.contains(username)) {
229
+                            mrows.add(kjname + "【" + username + "】不存在");
230
+                        } else if (vo == null) {
231
+                            mrows.add(kjname + "【" + username + "】与【" + classname + "】不匹配");
232
+                        } else if (N_Utils.isEmpty(vo.getSubjectid())) {
233
+                            mrows.add(kjname + "【" + username + "】未设置科目");
224 234
                         } else {
225
-                            Integer kjorder = y;//课节排序
226
-                            XzKjVo kj = kjs.stream().filter(k -> k.getKjorder() == kjorder).findFirst().orElse(null);
227
-                            String coursename = sheetName + kj.getKjname() + vo.getSubjectname() + "(" + username + ")";
235
+                            String coursename = sheetName + kjname + vo.getSubjectname() + "(" + username + ")";
228 236
                             LCourse t = new LCourse();
229 237
                             Integer kjid = kjMap.get(y).get(0).getKjid();
230 238
                             t.setKjid(kjid);
@@ -234,7 +242,9 @@ public class PoiUtils {
234 242
                             t.setTeacherid(vo.getTeacherid());
235 243
                             t.setBegintime(kj.getBegintime());
236 244
                             t.setEndtime(kj.getEndtime());
237
-                            Integer sectionstate = kj.getSectionstate();
245
+                            kj = kjs.stream().filter(k -> k.getKjorder() == kjorder
246
+                                    && sectiondate.equals(k.getSectiondate())).findFirst().orElse(null);
247
+                            Integer sectionstate = kj == null ? null : kj.getSectionstate();
238 248
                             if (sectionstate == null || sectionstate == 0) {//已经开始或结束的课不处理
239 249
                                 t.setBegindate(sectiondate);
240 250
                                 t.setEnddate(sectiondate);
@@ -242,16 +252,21 @@ public class PoiUtils {
242 252
                             }
243 253
                             List<String> meetDates = LiveUtil.getDaysForMeetDates(sectiondate, enddate);
244 254
                             for (int m = 1; m < meetDates.size(); m++) {
255
+                                String date = meetDates.get(m);
256
+                                String begintime = date + " " + t.getBegintime();
257
+                                Integer beginTimestamp = N_Utils.getDataToTimestamp(begintime, "yyyy-MM-dd HH:mm");
258
+                                Integer timestamp = N_Utils.getSecondTimestamp();
259
+                                if (beginTimestamp.compareTo(timestamp) != 1) continue;//如果课节开始时间不大于当前时间不处理
260
+
245 261
                                 LCourse t2 = new LCourse();
246 262
                                 BeanUtils.copyProperties(t, t2);
247
-                                String date = meetDates.get(m);
248 263
                                 t2.setBegindate(date);
249 264
                                 t2.setEnddate(date);
250 265
                                 kjTeas.add(t2);
251 266
                             }
252 267
                         }
253 268
                         if (y == lastCellNum && N_Utils.isListNotEmpty(mrows)) {
254
-                            errMsg.put(sheetName + "_" + (x + 1), mrows);
269
+                            errMsg.put(errMsgKey, mrows);
255 270
                         }
256 271
                     }
257 272
                 }

+ 7
- 3
slive/src/main/resources/mapper/gradeclass/ClassTeacherMapper.xml View File

@@ -15,9 +15,9 @@
15 15
     </select>
16 16
     <!--获取班级教师-->
17 17
     <select id="listTeacherByClassIds" resultType="com.xhkjedu.slive.vo.gradeclass.CTeacherVo">
18
-        select ct.classid,ct.teacherid,u.username
19
-        from t_class_teacher ct left join t_user u on ct.teacherid=u.userid
20
-        where ct.classid in(${classids}) and u.usertype=1 and u.userstate=1
18
+        select ct.classid,ct.teacherid
19
+        from t_class_teacher ct
20
+        where ct.classid in(${classids})
21 21
     </select>
22 22
     <!--获取教师科目-->
23 23
     <select id="listSubjectByTeacherIds" resultType="com.xhkjedu.slive.vo.gradeclass.CTeacherVo">
@@ -30,4 +30,8 @@
30 30
     <select id="listSubjectBySubjectIds" resultType="com.xhkjedu.slive.vo.gradeclass.CTeacherVo">
31 31
         select subjectid,subjectname from t_subject where subjectid in('${subjectids}')
32 32
     </select>
33
+    <!--获取学校所有教师-->
34
+    <select id="listTeacherBySchoolId" resultType="com.xhkjedu.slive.vo.gradeclass.CTeacherVo">
35
+        select userid teacherid,username from t_user where schoolid=#{schoolid} and usertype=1 and userstate=1
36
+    </select>
33 37
 </mapper>

Loading…
Cancel
Save