Browse Source

feature 代码提交

xiahan 1 year ago
parent
commit
134ff0d126

+ 68 - 64
rw-training/training-server/src/main/java/com/rongwei/training/controller/PlanController.java

@@ -90,18 +90,16 @@ public class PlanController {
                 if (userIds.size() > 0) {
                     // 获取培训计划
                     List<PlanCourseDo> planCourseList = planService.getPlanCourseByPlanId(row.getId());
-                    if (planCourseList.size() == 0) {
-                        return R.errorWithMsg("查询不到该培训计划对应的课程信息");
+                    List<PlanPaperDo> planPaperList = planService.getPlanPaperByPlanId(row.getId());
+                    if (planCourseList.size() == 0 && planPaperList.size() == 0) {
+                        return R.errorWithMsg("培训计划至少包含一个课程信息或一套试卷信息");
                     }
                     log.info("当前培训计划对应的课程信息:{}", planCourseList);
+                    log.info("当前培训计划对应的试卷信息:{}", planPaperList);
                     // 获取考试计划
-                    List<PlanPaperDo> planPaperList = planService.getPlanPaperByPlanId(row.getId());
-                    if (planPaperList.size() == 0) {
-                        return R.errorWithMsg("查询不到该培训计划对应的试卷信息");
-                    } else if (planPaperList.size() > 1) {
+                    if (planPaperList.size() > 1) {
                         return R.errorWithMsg("单一培训计划只可对应一张试卷");
                     }
-                    log.info("当前培训计划对应的试卷信息:{}", planCourseList);
                     // 获取参与过本次培训计划的员工
                     QueryWrapper<EmpExamDo> queryWrapper = new QueryWrapper<>();
                     queryWrapper.eq("PLANID", row.getId());
@@ -113,66 +111,72 @@ public class PlanController {
                     // userIds.removeAll(examDoList.stream().map(EmpExamDo::getEmpid).collect(Collectors.toList()));
                     log.info("需要参与本次培训计划的用户id :{}", userIds);
                     for (String userId : userIds) {
-                        // 生成对应用户的培训计划
-                        for (PlanCourseDo v1 : planCourseList) {
-                            // 根据 计划iD,课程ID,员工id 获取员工课程关系信息
-                            List<EmpCourseDo> empCourseDoList = empCourseService.list(new QueryWrapper<EmpCourseDo>()
-                                    .lambda()
-                                    .eq(BaseDo::getDeleted, "0")
-                                    .eq(EmpCourseDo::getPlanid, row.getId())
-                                    .eq(EmpCourseDo::getCourseid, v1.getCourseid())
-                                    .eq(EmpCourseDo::getEmpid, userId));
-                            log.info("根据 计划id:{},课程id:{},员工id:{}. 获取员工课程关系信息:{}", row.getId(), v1.getCourseid(), userId, empCourseDoList);
-                            if (empCourseDoList.isEmpty()) {
-                                String uid = SecurityUtil.getUUID();
-                                EmpCourseDo empCourseDo = new EmpCourseDo();
-                                empCourseDo.setId(uid);
-                                empCourseDo.setPlanid(row.getId());
-                                empCourseDo.setPlancourseid(v1.getId());
-                                empCourseDo.setEmpid(userId); // 设置用户
-                                empCourseDo.setCourseid(v1.getCourseid()); // 设置课程id
-                                empCourseDo.setCoursename(v1.getCoursename()); // 设置课程name
-                                empCourseDo.setCoursetime(v1.getCoursetime()); // 设置课程时间
-                                empCourseDo.setDeleted("0");
-                                empCourseDo.setCreatedate(new Date());
-                                empCourseDo.setModifydate(new Date());
-                                empCourseDo.setPlanname(row.getCoursename());
-                                empCourseDo.setSerialnumber(v1.getSerialnumber());
-                                empCourseService.save(empCourseDo);
-                                log.info("新增员工和课程的对应关系:{}", empCourseDo);
+                        if (!planCourseList.isEmpty()) {
+                            // 生成对应用户的培训计划
+                            for (PlanCourseDo v1 : planCourseList) {
+                                // 根据 计划iD,课程ID,员工id 获取员工课程关系信息
+                                List<EmpCourseDo> empCourseDoList = empCourseService.list(new QueryWrapper<EmpCourseDo>()
+                                        .lambda()
+                                        .eq(BaseDo::getDeleted, "0")
+                                        .eq(EmpCourseDo::getPlanid, row.getId())
+                                        .eq(EmpCourseDo::getCourseid, v1.getCourseid())
+                                        .eq(EmpCourseDo::getEmpid, userId));
+                                log.info("根据 计划id:{},课程id:{},员工id:{}. 获取员工课程关系信息:{}", row.getId(), v1.getCourseid(), userId, empCourseDoList);
+                                if (empCourseDoList.isEmpty()) {
+                                    String uid = SecurityUtil.getUUID();
+                                    EmpCourseDo empCourseDo = new EmpCourseDo();
+                                    empCourseDo.setId(uid);
+                                    empCourseDo.setPlanid(row.getId());
+                                    empCourseDo.setPlancourseid(v1.getId());
+                                    empCourseDo.setEmpid(userId); // 设置用户
+                                    empCourseDo.setCourseid(v1.getCourseid()); // 设置课程id
+                                    empCourseDo.setCoursename(v1.getCoursename()); // 设置课程name
+                                    empCourseDo.setCoursetime(v1.getCoursetime()); // 设置课程时间
+                                    empCourseDo.setDeleted("0");
+                                    empCourseDo.setCreatedate(new Date());
+                                    empCourseDo.setModifydate(new Date());
+                                    empCourseDo.setPlanname(row.getCoursename());
+                                    empCourseDo.setSerialnumber(v1.getSerialnumber());
+                                    empCourseService.save(empCourseDo);
+                                    log.info("新增员工和课程的对应关系:{}", empCourseDo);
+                                }
                             }
+
                         }
-                        // 生成对应用户的考试计划
-                        for (PlanPaperDo v1 : planPaperList) {
-                            // 根据 计划iD,课程ID,员工id 获取员工课程关系信息
-                            List<EmpExamDo> empExamDoList = empExamService.list(new QueryWrapper<EmpExamDo>()
-                                    .lambda()
-                                    .eq(BaseDo::getDeleted, "0")
-                                    .eq(EmpExamDo::getPlanid, row.getId())
-                                    .eq(EmpExamDo::getPaperid, v1.getPaperid())
-                                    .eq(EmpExamDo::getEmpid, userId));
-                            log.info("根据 计划id:{},试卷:{},员工id:{}. 获取员工课程关系信息:{}", row.getId(), v1.getPaperid(), userId, empExamDoList);
-                            if (empExamDoList.isEmpty()) {
-                                String uid = SecurityUtil.getUUID();
-                                EmpExamDo empExamDo = new EmpExamDo();
-                                empExamDo.setId(uid);
-                                empExamDo.setPlanid(row.getId());
-                                empExamDo.setPlanpaperid(v1.getId());
-                                empExamDo.setEmpid(userId); // 设置用户
-                                empExamDo.setPaperid(v1.getPaperid()); // 设置试卷ID
-                                empExamDo.setPapername(v1.getPapername());// 设置试卷NAME
-                                empExamDo.setExamdeadtime(v1.getDeadline()); // 设置截至时间
-                                empExamDo.setDeleted("0");
-                                empExamDo.setCreatedate(new Date());
-                                empExamDo.setModifydate(new Date());
-                                empExamDo.setExamstatus("待考试");
-                                empExamDo.setPlanname(row.getCoursename());
-                                empExamService.save(empExamDo);
-                                log.info("生成员工和试卷的对应关系:{}", empExamDo);
-                                ExamPaperDo paper = examPaperService.getById(v1.getPaperid());
-                                paper.setHasused("y");
-                                examPaperService.updateById(paper);
+                        if (!planPaperList.isEmpty()) {
+                            // 生成对应用户的考试计划
+                            for (PlanPaperDo v1 : planPaperList) {
+                                // 根据 计划iD,课程ID,员工id 获取员工课程关系信息
+                                List<EmpExamDo> empExamDoList = empExamService.list(new QueryWrapper<EmpExamDo>()
+                                        .lambda()
+                                        .eq(BaseDo::getDeleted, "0")
+                                        .eq(EmpExamDo::getPlanid, row.getId())
+                                        .eq(EmpExamDo::getPaperid, v1.getPaperid())
+                                        .eq(EmpExamDo::getEmpid, userId));
+                                log.info("根据 计划id:{},试卷:{},员工id:{}. 获取员工课程关系信息:{}", row.getId(), v1.getPaperid(), userId, empExamDoList);
+                                if (empExamDoList.isEmpty()) {
+                                    String uid = SecurityUtil.getUUID();
+                                    EmpExamDo empExamDo = new EmpExamDo();
+                                    empExamDo.setId(uid);
+                                    empExamDo.setPlanid(row.getId());
+                                    empExamDo.setPlanpaperid(v1.getId());
+                                    empExamDo.setEmpid(userId); // 设置用户
+                                    empExamDo.setPaperid(v1.getPaperid()); // 设置试卷ID
+                                    empExamDo.setPapername(v1.getPapername());// 设置试卷NAME
+                                    empExamDo.setExamdeadtime(v1.getDeadline()); // 设置截至时间
+                                    empExamDo.setDeleted("0");
+                                    empExamDo.setCreatedate(new Date());
+                                    empExamDo.setModifydate(new Date());
+                                    empExamDo.setExamstatus("待考试");
+                                    empExamDo.setPlanname(row.getCoursename());
+                                    empExamService.save(empExamDo);
+                                    log.info("生成员工和试卷的对应关系:{}", empExamDo);
+                                    ExamPaperDo paper = examPaperService.getById(v1.getPaperid());
+                                    paper.setHasused("y");
+                                    examPaperService.updateById(paper);
+                                }
                             }
+
                         }
                     }
                     row.setPublish("y");