diff --git a/sql/20210326-zhangsai.sql b/sql/20210326-zhangsai.sql new file mode 100644 index 000000000..4a1a501af --- /dev/null +++ b/sql/20210326-zhangsai.sql @@ -0,0 +1,26 @@ +alter table exam_definition modify lesson_id bigint null comment '所属课程ID', + add map_id bigint not null comment '地图id' after id; + +-- 更新exam_definition的map_id字段 +UPDATE exam_definition SET map_id =( SELECT map_id FROM ls_lesson WHERE exam_definition.lesson_id = ls_lesson.id) +-- 更新exam_definition的type字段 +UPDATE exam_definition SET type =( SELECT prd_type FROM ls_lesson WHERE exam_definition.lesson_id = ls_lesson.id) + +alter table org_exam + modify org_id bigint not null, + add creator_id bigint not null, + add create_time datetime not null; + +ALTER TABLE `org_exam` +ADD COLUMN `id` bigint(20) NOT NULL AUTO_INCREMENT FIRST , +ADD PRIMARY KEY (`id`); + +-- org_lesson表添加主键 +ALTER TABLE `org_lesson` +ADD COLUMN `id` bigint(20) NOT NULL AUTO_INCREMENT FIRST , +ADD PRIMARY KEY (`id`); + + + + + diff --git a/src/main/java/club/joylink/rtss/controller/OrgController.java b/src/main/java/club/joylink/rtss/controller/OrgController.java index 22103d485..037873af5 100644 --- a/src/main/java/club/joylink/rtss/controller/OrgController.java +++ b/src/main/java/club/joylink/rtss/controller/OrgController.java @@ -3,10 +3,7 @@ package club.joylink.rtss.controller; import club.joylink.rtss.constants.RoleEnum; import club.joylink.rtss.controller.advice.AuthenticateInterceptor; import club.joylink.rtss.controller.advice.Role; -import club.joylink.rtss.services.org.IOrgLessonService; -import club.joylink.rtss.services.org.IOrgScoringRuleService; -import club.joylink.rtss.services.org.IOrgService; -import club.joylink.rtss.services.org.IOrgUserService; +import club.joylink.rtss.services.org.*; import club.joylink.rtss.vo.LoginUserInfoVO; import club.joylink.rtss.vo.UserVO; import club.joylink.rtss.vo.client.LessonVO; @@ -39,6 +36,9 @@ public class OrgController { @Autowired private IOrgScoringRuleService iOrgScoringRuleService; + @Autowired + private IOrgExamService iOrgExamService; + @ApiOperation(value = "创建顶级组织") @PostMapping public CompanyVO create(@RequestBody @Validated CompanyVO company, @RequestAttribute(AuthenticateInterceptor.LOGIN_USER_KEY) UserVO user) { @@ -183,15 +183,15 @@ public class OrgController { iOrgService.createCls(createVO, loginInfo); } - @ApiOperation("分页查询班级") + @ApiOperation("分页查询当前登录项目所属组织下的班级") @GetMapping("/paged/cls") public PageVO pagedQuerySelfCls(OrgQueryVO queryVO, @RequestAttribute LoginUserInfoVO loginInfo) { return iOrgService.pagedQueryCls(queryVO, loginInfo); } - @ApiOperation("查询班级") + @ApiOperation("查询当前登录项目所属组织下的班级") @GetMapping("/list/cls") - public List querySelfCls(OrgQueryVO queryVO, @RequestAttribute LoginUserInfoVO loginInfo) { + public List queryCls(OrgQueryVO queryVO, @RequestAttribute LoginUserInfoVO loginInfo) { return iOrgService.queryCls(queryVO, loginInfo); } @@ -241,8 +241,8 @@ public class OrgController { @ApiOperation("查询规则能够应用到的组织") @GetMapping("/orgScoringRule/{ruleId}/canApplyTo") - public List queryRuleCanApplyTo(@PathVariable Long ruleId) { - return iOrgScoringRuleService.queryRuleCanApplyTo(ruleId); + public List queryRuleCanApplyTo(@PathVariable Long ruleId, @RequestAttribute UserVO user) { + return iOrgScoringRuleService.queryRuleCanApplyTo(ruleId, user); } @ApiOperation("将评价规则应用到") @@ -257,4 +257,17 @@ public class OrgController { public PageVO adminPagedQueryOrg(OrgQueryVO queryVO) { return iOrgService.adminPagedQueryOrg(queryVO); } + + @ApiOperation("给班级安排考试") + @PostMapping("/orgExam/{clsId}") + public void createOrgExam(@PathVariable Long clsId, @RequestBody List examIds, @RequestAttribute UserVO user) { + iOrgExamService.create(clsId, examIds, user); + } + + @ApiOperation("查询班级安排的考试id") + @GetMapping("/orgExam/{clsId}/list") + public List queryOrgExam(@PathVariable Long clsId, @RequestAttribute UserVO user) { + return iOrgExamService.queryOrgExam(clsId, user); + } + } diff --git a/src/main/java/club/joylink/rtss/controller/publish/ExamController.java b/src/main/java/club/joylink/rtss/controller/publish/ExamController.java index 84cffe71a..038c56eae 100644 --- a/src/main/java/club/joylink/rtss/controller/publish/ExamController.java +++ b/src/main/java/club/joylink/rtss/controller/publish/ExamController.java @@ -7,7 +7,6 @@ import club.joylink.rtss.vo.client.ExamDefinitionQueryVO; import club.joylink.rtss.vo.client.ExamDefinitionVO; import club.joylink.rtss.vo.client.ExamsLessonVO; import club.joylink.rtss.vo.client.PageVO; -import club.joylink.rtss.vo.client.validGroup.ExamDefinitionCheck; import club.joylink.rtss.vo.client.validGroup.ExamDefinitionRulesCheck; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; @@ -27,30 +26,17 @@ public class ExamController { @ApiOperation(value = "创建考试") @PostMapping(path = "") - public void create(@RequestBody @Validated(value = {ExamDefinitionCheck.class, ExamDefinitionRulesCheck.class}) - ExamDefinitionVO examDefinitionVO, @RequestAttribute @ApiIgnore UserVO user) { + public void create(@RequestBody @Validated ExamDefinitionVO examDefinitionVO, @RequestAttribute @ApiIgnore UserVO user) { iExamService.create(examDefinitionVO, user); } -// @ApiOperation(value = "贵装备创建考试") -// @PostMapping(path = "/project/GZB") -// public void createGZBExam(@RequestBody @Validated(value = {ExamDefinitionCheck.class, ExamDefinitionRulesCheck.class}) -// ExamDefinitionVO examDefinitionVO, @RequestAttribute @ApiIgnore UserVO user) { -// iExamService.createGZBExam(examDefinitionVO, user); -// } - @ApiOperation(value = "检查分数是否合理") @GetMapping(path = "/checkScore") public boolean checkScore(@Validated(value = ExamDefinitionRulesCheck.class) ExamDefinitionVO examDefinitionVO) { return iExamService.checkScore(examDefinitionVO); } -// @ApiOperation(value = "查询课程下的章节信息") -// @GetMapping(path = "/{lessonId}/chapter") -// public CommonJsonResponse queryChapterInfo(@PathVariable(required = true) String lessonId) { -// return CommonJsonResponse.newSuccessResponse(iExamService.queryChapterInfo(lessonId)); -// } - + @Deprecated @ApiOperation(value = "查询课程所属产品下有实训的实训类型") @GetMapping(path = "/{lessonId}/trainingTypes") public List queryTrainingTypes(@PathVariable Long lessonId) { @@ -77,17 +63,10 @@ public class ExamController { @ApiOperation(value = "删除试题") @DeleteMapping(path = "/{id}") - public void deleteExam(@PathVariable String id, @ApiIgnore @RequestAttribute UserVO user) { + public void deleteExam(@PathVariable Long id, @ApiIgnore @RequestAttribute UserVO user) { iExamService.deleteExam(id, user); } -// @ApiOperation(value = "查询章节下允许创建的最多题目数量") -// @GetMapping(path = "/trainingNum/{lessonId}/{chapterId}") -// public CommonJsonResponse queryTrainingNum(@PathVariable(required = true) String lessonId, @PathVariable(required = true) String chapterId) { -// int trainingNum = iExamService.queryTrainingNum(lessonId, chapterId); -// return CommonJsonResponse.newSuccessResponse(trainingNum); -// } - @ApiOperation(value = "根据课程和实训类型查询实训数量") @GetMapping(path = "/trainingNum/{lessonId}/{trainingType}") public Long queryTrainingNum(@PathVariable Long lessonId, @PathVariable String trainingType, String operateType) { @@ -118,7 +97,7 @@ public class ExamController { return this.iExamService.pagedQueryByLoginProject(queryVO, loginInfo); } - @ApiOperation(value = "不分页查询当前登录项目下自己创建的试卷") + @ApiOperation(value = "不分页查询当前登录项目下的试卷") @GetMapping("/list/loginProject") public List listQueryExamByLoginProject(ExamDefinitionQueryVO queryVO, @RequestAttribute LoginUserInfoVO loginInfo) { return this.iExamService.listQueryExamByLoginProject(queryVO, loginInfo); @@ -129,4 +108,10 @@ public class ExamController { public List listQueryOrgExamOfSelf(Long clsId, @RequestAttribute LoginUserInfoVO loginInfo) { return this.iExamService.listQueryOrgExamICreated(clsId, loginInfo); } + + @ApiOperation("查询试卷") + @GetMapping("/list/{mapId}") + public List listQuery(@PathVariable Long mapId, String prdType) { + return iExamService.queryBasicInfo(mapId, prdType); + } } diff --git a/src/main/java/club/joylink/rtss/controller/publish/LessonController.java b/src/main/java/club/joylink/rtss/controller/publish/LessonController.java index 0fcebaf31..fa8e807ac 100644 --- a/src/main/java/club/joylink/rtss/controller/publish/LessonController.java +++ b/src/main/java/club/joylink/rtss/controller/publish/LessonController.java @@ -61,12 +61,6 @@ public class LessonController { return this.iOrgUserService.getLessonsByDepart(departId); } - @ApiOperation(value = "根据课程获取关联班级信息列表") - @GetMapping(path = "/{lessonId}/departs") - public List queryClassByLesson(@PathVariable Long lessonId) { - return this.iOrgUserService.getDepartsByLesson(lessonId); - } - @ApiOperation(value = "获取课程列表") @GetMapping(path = "/listOfMap") public List queryLessonsOfMap(Long mapId) { diff --git a/src/main/java/club/joylink/rtss/controller/training/TrainingV1Controller.java b/src/main/java/club/joylink/rtss/controller/training/TrainingV1Controller.java index 4f1ce72c3..f76da4e34 100644 --- a/src/main/java/club/joylink/rtss/controller/training/TrainingV1Controller.java +++ b/src/main/java/club/joylink/rtss/controller/training/TrainingV1Controller.java @@ -25,6 +25,7 @@ import org.springframework.web.bind.annotation.*; import springfox.documentation.annotations.ApiIgnore; import javax.validation.constraints.NotBlank; +import java.util.Map; import java.util.Set; @Api(tags = { "实训数据管理接口" }) @@ -195,4 +196,10 @@ public class TrainingV1Controller { public TrainingNewVO loadTraining(@PathVariable String group, @PathVariable Long id) { return iTrainingService.loadTraining(group, id); } + + @ApiOperation("查询实训、操作类型及数量") + @GetMapping("/trainingTypeAndQuantity") + public Map> queryTrainingTypeAndQuantity(Long mapId, String prdType) { + return iTrainingService.queryTrainingTypeAndQuantity(mapId, prdType); + } } diff --git a/src/main/java/club/joylink/rtss/dao/OrgDAO.java b/src/main/java/club/joylink/rtss/dao/OrgDAO.java index 39faa0c5f..b67f696ae 100644 --- a/src/main/java/club/joylink/rtss/dao/OrgDAO.java +++ b/src/main/java/club/joylink/rtss/dao/OrgDAO.java @@ -2,11 +2,15 @@ package club.joylink.rtss.dao; import club.joylink.rtss.entity.Org; import club.joylink.rtss.entity.OrgExample; +import club.joylink.rtss.vo.client.ExamDefinitionVO; import org.springframework.stereotype.Repository; +import java.util.List; + /** * OrgDAO继承基类 */ @Repository public interface OrgDAO extends MyBatisBaseDao { -} \ No newline at end of file + List queryByExamIds(List examIds, String status); +} diff --git a/src/main/java/club/joylink/rtss/dao/OrgLessonDAO.java b/src/main/java/club/joylink/rtss/dao/OrgLessonDAO.java index 155c8251e..434b6fc2c 100644 --- a/src/main/java/club/joylink/rtss/dao/OrgLessonDAO.java +++ b/src/main/java/club/joylink/rtss/dao/OrgLessonDAO.java @@ -14,20 +14,13 @@ import java.util.List; */ @Repository public interface OrgLessonDAO extends MyBatisBaseDao { - @Select("") - List getDeparts(@Param("lessonId") Long lessonId); @Select("") List getClassNames(@Param("lessonId") Long lessonId); } diff --git a/src/main/java/club/joylink/rtss/entity/ExamDefinition.java b/src/main/java/club/joylink/rtss/entity/ExamDefinition.java index f044c5acd..c5660bda3 100644 --- a/src/main/java/club/joylink/rtss/entity/ExamDefinition.java +++ b/src/main/java/club/joylink/rtss/entity/ExamDefinition.java @@ -4,12 +4,17 @@ import java.io.Serializable; import java.time.LocalDateTime; /** - * exam_definition * @author + * 考试定义表 */ public class ExamDefinition implements Serializable { private Long id; + /** + * 地图id + */ + private Long mapId; + /** * 所属课程ID */ @@ -85,6 +90,14 @@ public class ExamDefinition implements Serializable { this.id = id; } + public Long getMapId() { + return mapId; + } + + public void setMapId(Long mapId) { + this.mapId = mapId; + } + public Long getLessonId() { return lessonId; } @@ -202,6 +215,7 @@ public class ExamDefinition implements Serializable { } ExamDefinition other = (ExamDefinition) that; return (this.getId() == null ? other.getId() == null : this.getId().equals(other.getId())) + && (this.getMapId() == null ? other.getMapId() == null : this.getMapId().equals(other.getMapId())) && (this.getLessonId() == null ? other.getLessonId() == null : this.getLessonId().equals(other.getLessonId())) && (this.getName() == null ? other.getName() == null : this.getName().equals(other.getName())) && (this.getType() == null ? other.getType() == null : this.getType().equals(other.getType())) @@ -222,6 +236,7 @@ public class ExamDefinition implements Serializable { final int prime = 31; int result = 1; result = prime * result + ((getId() == null) ? 0 : getId().hashCode()); + result = prime * result + ((getMapId() == null) ? 0 : getMapId().hashCode()); result = prime * result + ((getLessonId() == null) ? 0 : getLessonId().hashCode()); result = prime * result + ((getName() == null) ? 0 : getName().hashCode()); result = prime * result + ((getType() == null) ? 0 : getType().hashCode()); @@ -245,6 +260,7 @@ public class ExamDefinition implements Serializable { sb.append(" ["); sb.append("Hash = ").append(hashCode()); sb.append(", id=").append(id); + sb.append(", mapId=").append(mapId); sb.append(", lessonId=").append(lessonId); sb.append(", name=").append(name); sb.append(", type=").append(type); diff --git a/src/main/java/club/joylink/rtss/entity/ExamDefinitionExample.java b/src/main/java/club/joylink/rtss/entity/ExamDefinitionExample.java index a92e32b56..716282de6 100644 --- a/src/main/java/club/joylink/rtss/entity/ExamDefinitionExample.java +++ b/src/main/java/club/joylink/rtss/entity/ExamDefinitionExample.java @@ -185,6 +185,66 @@ public class ExamDefinitionExample { return (Criteria) this; } + public Criteria andMapIdIsNull() { + addCriterion("map_id is null"); + return (Criteria) this; + } + + public Criteria andMapIdIsNotNull() { + addCriterion("map_id is not null"); + return (Criteria) this; + } + + public Criteria andMapIdEqualTo(Long value) { + addCriterion("map_id =", value, "mapId"); + return (Criteria) this; + } + + public Criteria andMapIdNotEqualTo(Long value) { + addCriterion("map_id <>", value, "mapId"); + return (Criteria) this; + } + + public Criteria andMapIdGreaterThan(Long value) { + addCriterion("map_id >", value, "mapId"); + return (Criteria) this; + } + + public Criteria andMapIdGreaterThanOrEqualTo(Long value) { + addCriterion("map_id >=", value, "mapId"); + return (Criteria) this; + } + + public Criteria andMapIdLessThan(Long value) { + addCriterion("map_id <", value, "mapId"); + return (Criteria) this; + } + + public Criteria andMapIdLessThanOrEqualTo(Long value) { + addCriterion("map_id <=", value, "mapId"); + return (Criteria) this; + } + + public Criteria andMapIdIn(List values) { + addCriterion("map_id in", values, "mapId"); + return (Criteria) this; + } + + public Criteria andMapIdNotIn(List values) { + addCriterion("map_id not in", values, "mapId"); + return (Criteria) this; + } + + public Criteria andMapIdBetween(Long value1, Long value2) { + addCriterion("map_id between", value1, value2, "mapId"); + return (Criteria) this; + } + + public Criteria andMapIdNotBetween(Long value1, Long value2) { + addCriterion("map_id not between", value1, value2, "mapId"); + return (Criteria) this; + } + public Criteria andLessonIdIsNull() { addCriterion("lesson_id is null"); return (Criteria) this; diff --git a/src/main/java/club/joylink/rtss/entity/OrgExam.java b/src/main/java/club/joylink/rtss/entity/OrgExam.java index d543ceb52..402dd1923 100644 --- a/src/main/java/club/joylink/rtss/entity/OrgExam.java +++ b/src/main/java/club/joylink/rtss/entity/OrgExam.java @@ -1,18 +1,33 @@ package club.joylink.rtss.entity; import java.io.Serializable; +import java.time.LocalDateTime; /** - * org_exam - * @author + * @author + * 学生的试卷和班级关系 */ public class OrgExam implements Serializable { + private Long id; + private Long examId; private Long orgId; + private Long creatorId; + + private LocalDateTime createTime; + private static final long serialVersionUID = 1L; + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + public Long getExamId() { return examId; } @@ -29,6 +44,22 @@ public class OrgExam implements Serializable { this.orgId = orgId; } + public Long getCreatorId() { + return creatorId; + } + + public void setCreatorId(Long creatorId) { + this.creatorId = creatorId; + } + + public LocalDateTime getCreateTime() { + return createTime; + } + + public void setCreateTime(LocalDateTime createTime) { + this.createTime = createTime; + } + @Override public boolean equals(Object that) { if (this == that) { @@ -41,16 +72,22 @@ public class OrgExam implements Serializable { return false; } OrgExam other = (OrgExam) that; - return (this.getExamId() == null ? other.getExamId() == null : this.getExamId().equals(other.getExamId())) - && (this.getOrgId() == null ? other.getOrgId() == null : this.getOrgId().equals(other.getOrgId())); + return (this.getId() == null ? other.getId() == null : this.getId().equals(other.getId())) + && (this.getExamId() == null ? other.getExamId() == null : this.getExamId().equals(other.getExamId())) + && (this.getOrgId() == null ? other.getOrgId() == null : this.getOrgId().equals(other.getOrgId())) + && (this.getCreatorId() == null ? other.getCreatorId() == null : this.getCreatorId().equals(other.getCreatorId())) + && (this.getCreateTime() == null ? other.getCreateTime() == null : this.getCreateTime().equals(other.getCreateTime())); } @Override public int hashCode() { final int prime = 31; int result = 1; + result = prime * result + ((getId() == null) ? 0 : getId().hashCode()); result = prime * result + ((getExamId() == null) ? 0 : getExamId().hashCode()); result = prime * result + ((getOrgId() == null) ? 0 : getOrgId().hashCode()); + result = prime * result + ((getCreatorId() == null) ? 0 : getCreatorId().hashCode()); + result = prime * result + ((getCreateTime() == null) ? 0 : getCreateTime().hashCode()); return result; } @@ -60,10 +97,13 @@ public class OrgExam implements Serializable { sb.append(getClass().getSimpleName()); sb.append(" ["); sb.append("Hash = ").append(hashCode()); + sb.append(", id=").append(id); sb.append(", examId=").append(examId); sb.append(", orgId=").append(orgId); + sb.append(", creatorId=").append(creatorId); + sb.append(", createTime=").append(createTime); sb.append(", serialVersionUID=").append(serialVersionUID); sb.append("]"); return sb.toString(); } -} +} \ No newline at end of file diff --git a/src/main/java/club/joylink/rtss/entity/OrgExamExample.java b/src/main/java/club/joylink/rtss/entity/OrgExamExample.java index d3ff9c0dc..5841b351f 100644 --- a/src/main/java/club/joylink/rtss/entity/OrgExamExample.java +++ b/src/main/java/club/joylink/rtss/entity/OrgExamExample.java @@ -1,5 +1,6 @@ package club.joylink.rtss.entity; +import java.time.LocalDateTime; import java.util.ArrayList; import java.util.List; @@ -124,6 +125,66 @@ public class OrgExamExample { criteria.add(new Criterion(condition, value1, value2)); } + public Criteria andIdIsNull() { + addCriterion("id is null"); + return (Criteria) this; + } + + public Criteria andIdIsNotNull() { + addCriterion("id is not null"); + return (Criteria) this; + } + + public Criteria andIdEqualTo(Long value) { + addCriterion("id =", value, "id"); + return (Criteria) this; + } + + public Criteria andIdNotEqualTo(Long value) { + addCriterion("id <>", value, "id"); + return (Criteria) this; + } + + public Criteria andIdGreaterThan(Long value) { + addCriterion("id >", value, "id"); + return (Criteria) this; + } + + public Criteria andIdGreaterThanOrEqualTo(Long value) { + addCriterion("id >=", value, "id"); + return (Criteria) this; + } + + public Criteria andIdLessThan(Long value) { + addCriterion("id <", value, "id"); + return (Criteria) this; + } + + public Criteria andIdLessThanOrEqualTo(Long value) { + addCriterion("id <=", value, "id"); + return (Criteria) this; + } + + public Criteria andIdIn(List values) { + addCriterion("id in", values, "id"); + return (Criteria) this; + } + + public Criteria andIdNotIn(List values) { + addCriterion("id not in", values, "id"); + return (Criteria) this; + } + + public Criteria andIdBetween(Long value1, Long value2) { + addCriterion("id between", value1, value2, "id"); + return (Criteria) this; + } + + public Criteria andIdNotBetween(Long value1, Long value2) { + addCriterion("id not between", value1, value2, "id"); + return (Criteria) this; + } + public Criteria andExamIdIsNull() { addCriterion("exam_id is null"); return (Criteria) this; @@ -194,55 +255,175 @@ public class OrgExamExample { return (Criteria) this; } - public Criteria andOrgIdEqualTo(Integer value) { + public Criteria andOrgIdEqualTo(Long value) { addCriterion("org_id =", value, "orgId"); return (Criteria) this; } - public Criteria andOrgIdNotEqualTo(Integer value) { + public Criteria andOrgIdNotEqualTo(Long value) { addCriterion("org_id <>", value, "orgId"); return (Criteria) this; } - public Criteria andOrgIdGreaterThan(Integer value) { + public Criteria andOrgIdGreaterThan(Long value) { addCriterion("org_id >", value, "orgId"); return (Criteria) this; } - public Criteria andOrgIdGreaterThanOrEqualTo(Integer value) { + public Criteria andOrgIdGreaterThanOrEqualTo(Long value) { addCriterion("org_id >=", value, "orgId"); return (Criteria) this; } - public Criteria andOrgIdLessThan(Integer value) { + public Criteria andOrgIdLessThan(Long value) { addCriterion("org_id <", value, "orgId"); return (Criteria) this; } - public Criteria andOrgIdLessThanOrEqualTo(Integer value) { + public Criteria andOrgIdLessThanOrEqualTo(Long value) { addCriterion("org_id <=", value, "orgId"); return (Criteria) this; } - public Criteria andOrgIdIn(List values) { + public Criteria andOrgIdIn(List values) { addCriterion("org_id in", values, "orgId"); return (Criteria) this; } - public Criteria andOrgIdNotIn(List values) { + public Criteria andOrgIdNotIn(List values) { addCriterion("org_id not in", values, "orgId"); return (Criteria) this; } - public Criteria andOrgIdBetween(Integer value1, Integer value2) { + public Criteria andOrgIdBetween(Long value1, Long value2) { addCriterion("org_id between", value1, value2, "orgId"); return (Criteria) this; } - public Criteria andOrgIdNotBetween(Integer value1, Integer value2) { + public Criteria andOrgIdNotBetween(Long value1, Long value2) { addCriterion("org_id not between", value1, value2, "orgId"); return (Criteria) this; } + + public Criteria andCreatorIdIsNull() { + addCriterion("creator_id is null"); + return (Criteria) this; + } + + public Criteria andCreatorIdIsNotNull() { + addCriterion("creator_id is not null"); + return (Criteria) this; + } + + public Criteria andCreatorIdEqualTo(Long value) { + addCriterion("creator_id =", value, "creatorId"); + return (Criteria) this; + } + + public Criteria andCreatorIdNotEqualTo(Long value) { + addCriterion("creator_id <>", value, "creatorId"); + return (Criteria) this; + } + + public Criteria andCreatorIdGreaterThan(Long value) { + addCriterion("creator_id >", value, "creatorId"); + return (Criteria) this; + } + + public Criteria andCreatorIdGreaterThanOrEqualTo(Long value) { + addCriterion("creator_id >=", value, "creatorId"); + return (Criteria) this; + } + + public Criteria andCreatorIdLessThan(Long value) { + addCriterion("creator_id <", value, "creatorId"); + return (Criteria) this; + } + + public Criteria andCreatorIdLessThanOrEqualTo(Long value) { + addCriterion("creator_id <=", value, "creatorId"); + return (Criteria) this; + } + + public Criteria andCreatorIdIn(List values) { + addCriterion("creator_id in", values, "creatorId"); + return (Criteria) this; + } + + public Criteria andCreatorIdNotIn(List values) { + addCriterion("creator_id not in", values, "creatorId"); + return (Criteria) this; + } + + public Criteria andCreatorIdBetween(Long value1, Long value2) { + addCriterion("creator_id between", value1, value2, "creatorId"); + return (Criteria) this; + } + + public Criteria andCreatorIdNotBetween(Long value1, Long value2) { + addCriterion("creator_id not between", value1, value2, "creatorId"); + return (Criteria) this; + } + + public Criteria andCreateTimeIsNull() { + addCriterion("create_time is null"); + return (Criteria) this; + } + + public Criteria andCreateTimeIsNotNull() { + addCriterion("create_time is not null"); + return (Criteria) this; + } + + public Criteria andCreateTimeEqualTo(LocalDateTime value) { + addCriterion("create_time =", value, "createTime"); + return (Criteria) this; + } + + public Criteria andCreateTimeNotEqualTo(LocalDateTime value) { + addCriterion("create_time <>", value, "createTime"); + return (Criteria) this; + } + + public Criteria andCreateTimeGreaterThan(LocalDateTime value) { + addCriterion("create_time >", value, "createTime"); + return (Criteria) this; + } + + public Criteria andCreateTimeGreaterThanOrEqualTo(LocalDateTime value) { + addCriterion("create_time >=", value, "createTime"); + return (Criteria) this; + } + + public Criteria andCreateTimeLessThan(LocalDateTime value) { + addCriterion("create_time <", value, "createTime"); + return (Criteria) this; + } + + public Criteria andCreateTimeLessThanOrEqualTo(LocalDateTime value) { + addCriterion("create_time <=", value, "createTime"); + return (Criteria) this; + } + + public Criteria andCreateTimeIn(List values) { + addCriterion("create_time in", values, "createTime"); + return (Criteria) this; + } + + public Criteria andCreateTimeNotIn(List values) { + addCriterion("create_time not in", values, "createTime"); + return (Criteria) this; + } + + public Criteria andCreateTimeBetween(LocalDateTime value1, LocalDateTime value2) { + addCriterion("create_time between", value1, value2, "createTime"); + return (Criteria) this; + } + + public Criteria andCreateTimeNotBetween(LocalDateTime value1, LocalDateTime value2) { + addCriterion("create_time not between", value1, value2, "createTime"); + return (Criteria) this; + } } /** diff --git a/src/main/java/club/joylink/rtss/entity/OrgLesson.java b/src/main/java/club/joylink/rtss/entity/OrgLesson.java index 06af0c00e..65da687b2 100644 --- a/src/main/java/club/joylink/rtss/entity/OrgLesson.java +++ b/src/main/java/club/joylink/rtss/entity/OrgLesson.java @@ -8,6 +8,8 @@ import java.time.LocalDateTime; * 班级课程表 */ public class OrgLesson implements Serializable { + private Long id; + /** * 课程id */ @@ -30,6 +32,14 @@ public class OrgLesson implements Serializable { private static final long serialVersionUID = 1L; + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + public Long getLessonId() { return lessonId; } @@ -74,7 +84,8 @@ public class OrgLesson implements Serializable { return false; } OrgLesson other = (OrgLesson) that; - return (this.getLessonId() == null ? other.getLessonId() == null : this.getLessonId().equals(other.getLessonId())) + return (this.getId() == null ? other.getId() == null : this.getId().equals(other.getId())) + && (this.getLessonId() == null ? other.getLessonId() == null : this.getLessonId().equals(other.getLessonId())) && (this.getOrgId() == null ? other.getOrgId() == null : this.getOrgId().equals(other.getOrgId())) && (this.getCreatorId() == null ? other.getCreatorId() == null : this.getCreatorId().equals(other.getCreatorId())) && (this.getCreateTime() == null ? other.getCreateTime() == null : this.getCreateTime().equals(other.getCreateTime())); @@ -84,6 +95,7 @@ public class OrgLesson implements Serializable { public int hashCode() { final int prime = 31; int result = 1; + result = prime * result + ((getId() == null) ? 0 : getId().hashCode()); result = prime * result + ((getLessonId() == null) ? 0 : getLessonId().hashCode()); result = prime * result + ((getOrgId() == null) ? 0 : getOrgId().hashCode()); result = prime * result + ((getCreatorId() == null) ? 0 : getCreatorId().hashCode()); @@ -97,6 +109,7 @@ public class OrgLesson implements Serializable { sb.append(getClass().getSimpleName()); sb.append(" ["); sb.append("Hash = ").append(hashCode()); + sb.append(", id=").append(id); sb.append(", lessonId=").append(lessonId); sb.append(", orgId=").append(orgId); sb.append(", creatorId=").append(creatorId); diff --git a/src/main/java/club/joylink/rtss/entity/OrgLessonExample.java b/src/main/java/club/joylink/rtss/entity/OrgLessonExample.java index c4e0dffee..10b65fdac 100644 --- a/src/main/java/club/joylink/rtss/entity/OrgLessonExample.java +++ b/src/main/java/club/joylink/rtss/entity/OrgLessonExample.java @@ -125,6 +125,66 @@ public class OrgLessonExample { criteria.add(new Criterion(condition, value1, value2)); } + public Criteria andIdIsNull() { + addCriterion("id is null"); + return (Criteria) this; + } + + public Criteria andIdIsNotNull() { + addCriterion("id is not null"); + return (Criteria) this; + } + + public Criteria andIdEqualTo(Long value) { + addCriterion("id =", value, "id"); + return (Criteria) this; + } + + public Criteria andIdNotEqualTo(Long value) { + addCriterion("id <>", value, "id"); + return (Criteria) this; + } + + public Criteria andIdGreaterThan(Long value) { + addCriterion("id >", value, "id"); + return (Criteria) this; + } + + public Criteria andIdGreaterThanOrEqualTo(Long value) { + addCriterion("id >=", value, "id"); + return (Criteria) this; + } + + public Criteria andIdLessThan(Long value) { + addCriterion("id <", value, "id"); + return (Criteria) this; + } + + public Criteria andIdLessThanOrEqualTo(Long value) { + addCriterion("id <=", value, "id"); + return (Criteria) this; + } + + public Criteria andIdIn(List values) { + addCriterion("id in", values, "id"); + return (Criteria) this; + } + + public Criteria andIdNotIn(List values) { + addCriterion("id not in", values, "id"); + return (Criteria) this; + } + + public Criteria andIdBetween(Long value1, Long value2) { + addCriterion("id between", value1, value2, "id"); + return (Criteria) this; + } + + public Criteria andIdNotBetween(Long value1, Long value2) { + addCriterion("id not between", value1, value2, "id"); + return (Criteria) this; + } + public Criteria andLessonIdIsNull() { addCriterion("lesson_id is null"); return (Criteria) this; diff --git a/src/main/java/club/joylink/rtss/services/ExamService.java b/src/main/java/club/joylink/rtss/services/ExamService.java index 02a0035ac..b1c12bd0d 100644 --- a/src/main/java/club/joylink/rtss/services/ExamService.java +++ b/src/main/java/club/joylink/rtss/services/ExamService.java @@ -4,6 +4,7 @@ import club.joylink.rtss.constants.BusinessConsts; import club.joylink.rtss.dao.*; import club.joylink.rtss.entity.*; import club.joylink.rtss.exception.BusinessExceptionAssertEnum; +import club.joylink.rtss.services.org.IOrgExamService; import club.joylink.rtss.services.org.IOrgLessonService; import club.joylink.rtss.services.org.IOrgService; import club.joylink.rtss.services.org.IOrgUserService; @@ -11,18 +12,17 @@ import club.joylink.rtss.simulation.cbtc.GroupSimulationService; import club.joylink.rtss.vo.LoginUserInfoVO; import club.joylink.rtss.vo.UserVO; import club.joylink.rtss.vo.client.*; -import club.joylink.rtss.vo.client.org.DepartmentVO; +import club.joylink.rtss.vo.client.map.MapVO; import com.github.pagehelper.Page; import com.github.pagehelper.PageHelper; +import lombok.NonNull; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; import org.springframework.util.CollectionUtils; import org.springframework.util.StringUtils; import java.time.LocalDateTime; import java.util.*; -import java.util.Map.Entry; import java.util.function.Function; import java.util.stream.Collectors; @@ -71,31 +71,28 @@ public class ExamService implements IExamService { @Autowired private IOrgLessonService iOrgLessonService; + @Autowired + private IOrgExamService iOrgExamService; + /** * 创建考试定义 */ @Override public void create(ExamDefinitionVO examDefinitionVO, UserVO userVO) { - examDefinitionVO.setCreatorId(userVO.getId()); //检查分数是否合理 BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertTrue(checkScore(examDefinitionVO)); - //检查考试名称和考试规则是否唯一 - checkName(examDefinitionVO); + //检查考试名称是否唯一 + confirmNameUnique(null, examDefinitionVO.getMapId(), examDefinitionVO.getPrdType(), examDefinitionVO.getName(), BusinessConsts.STATUS_USE); //插入考试定义表数据 ExamDefinition examDefinition = examDefinitionVO.toDB(); + examDefinition.setCreatorId(userVO.getId()); examDefinition.setCreateTime(LocalDateTime.now()); examDefinition.setStatus(BusinessConsts.STATUS_USE); - // 判断是否是管理员并设置试用 - if (this.iSysUserService.isAdmin(userVO) && examDefinitionVO.getTrial()) { - examDefinition.setTrial(true); - } else { - examDefinition.setTrial(false); - } examDefinitionDAO.insert(examDefinition); - //插入试卷班级关系 - if (!CollectionUtils.isEmpty(examDefinitionVO.getClasses())) { - examDefinitionVO.getClasses().forEach(departmentVO -> iOrgUserService.addDepartExam(examDefinition.getId(), departmentVO.getId())); - } +// //插入试卷班级关系 +// if (!CollectionUtils.isEmpty(examDefinitionVO.getClasses())) { +// examDefinitionVO.getClasses().forEach(departmentVO -> iOrgUserService.addDepartExam(examDefinition.getId(), departmentVO.getId())); +// } //插入试题规则表数据 List examDefinitionRulesVOList = examDefinitionVO.getExamDefinitionRulesVOList(); examDefinitionRulesVOList.forEach(examDefinitionRulesVO -> { @@ -105,94 +102,25 @@ public class ExamService implements IExamService { }); } - private void checkExam(ExamDefinitionVO examDefinitionVO) { - //一个课程下考试名称查重 - ExamDefinitionExample examDefinitionExample = new ExamDefinitionExample(); - examDefinitionExample.createCriteria().andLessonIdEqualTo(examDefinitionVO.getLessonId()).andNameEqualTo(examDefinitionVO.getName()); - List examDefinitionList = examDefinitionDAO.selectByExample(examDefinitionExample); - BusinessExceptionAssertEnum.DATA_UNIQUE_PROPERTY_REPEAT.assertCollectionEmpty(examDefinitionList); - //考试规则查重 - //查询已创建的考试规则数据 - int rulesNum = examDefinitionVO.getExamDefinitionRulesVOList().stream().map(ExamDefinitionRulesVO::getNum).reduce(Integer::sum).orElse(0); - List examIdList = examDefinitionDAO.selectByRulesNumAndFullPoint(rulesNum, examDefinitionVO.getFullPoint(), examDefinitionVO.getLessonId()); - if (!CollectionUtils.isEmpty(examIdList)) { - //处理待校验数据 - Map> trainingTypeMap = examDefinitionVO.getExamDefinitionRulesVOList() - .stream().collect(Collectors.groupingBy(ExamDefinitionRulesVO::getTrainingType)); - for (Long examId : examIdList) { - ExamDefinitionRulesExample examDefinitionRulesExample = new ExamDefinitionRulesExample(); - examDefinitionRulesExample.createCriteria().andExamIdEqualTo(examId); - List examDefinitionRulesList = definitionRulesDAO.selectByExample(examDefinitionRulesExample); - Map> existTrainingTypeMap = ExamDefinitionRulesVO.convert2VOList(examDefinitionRulesList) - .stream().collect(Collectors.groupingBy(ExamDefinitionRulesVO::getTrainingType)); - //检查dataMap和map数据是否一样 - trainingTypeLoop: - for (Entry> entry : trainingTypeMap.entrySet()) { - String trainingType = entry.getKey(); - // 校验实训类型 - if (null == existTrainingTypeMap.get(trainingType) || existTrainingTypeMap.get(trainingType).size() != entry.getValue().size()) { - break; - } - // 校验操作类型 - Map dataMap = entry.getValue().stream() - .collect(Collectors.toMap(ExamDefinitionRulesVO::getOperateType, Function.identity())); - Map map = existTrainingTypeMap.get(trainingType).stream() - .collect(Collectors.toMap(ExamDefinitionRulesVO::getOperateType, Function.identity())); - for (Entry en : dataMap.entrySet()) { - String operateType = en.getKey(); - if (null == map.get(operateType) || !en.getValue().equals(map.get(operateType))) { - break trainingTypeLoop; - } else { - rulesNum -= en.getValue().getNum(); - } - } - } - BusinessExceptionAssertEnum.DATA_UNIQUE_PROPERTY_REPEAT.assertNotTrue(0 == rulesNum); - } + /** + * 确认名称唯一 + * + * @param id 试卷的id。更新时检查名称重复需要去掉自己 + * @param status + */ + private void confirmNameUnique(Long id, long mapId, @NonNull String type, @NonNull String name, String status) { +// //一个课程下考试名称查重 +// ExamDefinitionExample examDefinitionExample = new ExamDefinitionExample(); +// examDefinitionExample.createCriteria().andLessonIdEqualTo(examDefinitionVO.getLessonId()).andNameEqualTo(examDefinitionVO.getName()); +// List examDefinitionList = examDefinitionDAO.selectByExample(examDefinitionExample); +// BusinessExceptionAssertEnum.DATA_UNIQUE_PROPERTY_REPEAT.assertCollectionEmpty(examDefinitionList); + ExamDefinitionExample example = new ExamDefinitionExample(); + ExamDefinitionExample.Criteria criteria = example.createCriteria().andMapIdEqualTo(mapId).andTypeEqualTo(type).andNameEqualTo(name); + if (id != null) { + criteria.andIdNotEqualTo(id); } - } - - // /** -// * GZB创建考试定义 -// */ -// @Transactional -// @Override -// public void createGZBExam(ExamDefinitionVO examDefinitionVO, UserVO userVO) { -// examDefinitionVO.setCreatorId(userVO.getId()); -// -// //检查分数是否合理 -// BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertTrue(checkScore(examDefinitionVO)); -// //检查考试名称和考试规则是否唯一 -// checkName(examDefinitionVO); -// //插入考试定义表数据 -// ExamDefinition examDefinition = examDefinitionVO.toDB(); -// examDefinition.setCreateTime(LocalDateTime.now()); -// examDefinition.setStatus(BusinessConsts.STATUS_USE); -// // 判断是否是管理员并设置试用 -// if(this.iSysUserService.isAdmin(userVO) && examDefinitionVO.getTrial()) { -// examDefinition.setTrial(true); -// }else { -// examDefinition.setTrial(false); -// } -// examDefinitionDAO.insert(examDefinition); -// //插入试卷班级关系 -// if(!CollectionUtils.isEmpty(examDefinitionVO.getClasses())) { -// examDefinitionVO.getClasses().forEach(departmentVO -> iCompanyService.addDepartExam(examDefinition.getId(),departmentVO.getId())); -// } -// //插入试题规则表数据 -// List examDefinitionRulesVOList = examDefinitionVO.getExamDefinitionRulesVOList(); -// examDefinitionRulesVOList.forEach(examDefinitionRulesVO -> { -// ExamDefinitionRules examDefinitionRules = examDefinitionRulesVO.toDB(); -// examDefinitionRules.setExamId(examDefinition.getId()); -// definitionRulesDAO.insert(examDefinitionRules); -// }); -// } - private void checkName(ExamDefinitionVO examDefinitionVO) { - //一个课程下考试名称查重 - ExamDefinitionExample examDefinitionExample = new ExamDefinitionExample(); - examDefinitionExample.createCriteria().andLessonIdEqualTo(examDefinitionVO.getLessonId()).andNameEqualTo(examDefinitionVO.getName()); - List examDefinitionList = examDefinitionDAO.selectByExample(examDefinitionExample); - BusinessExceptionAssertEnum.DATA_UNIQUE_PROPERTY_REPEAT.assertCollectionEmpty(examDefinitionList); + BusinessExceptionAssertEnum.DATA_UNIQUE_PROPERTY_REPEAT.assertTrue(examDefinitionDAO.countByExample(example) == 0, + "名称重复"); } /** @@ -217,38 +145,6 @@ public class ExamService implements IExamService { return defineFullScore == realFullScore; } -// /** -// * 查询课程下有实训的章节信息 -// * @param lessonId -// * @return -// */ -// @Override -// public List queryChapterInfo(String lessonId) { -// //返回的结果 -// List examChapterInfoVOList = new ArrayList<>(); -// -// //查询数据 -// List lessonIds = new ArrayList<>(); -// lessonIds.add(Long.valueOf(lessonId)); -// List chapterVos = this.lsLessonChapterMapper.selectChapterTrainingByLessonIds(lessonIds); -// -// //检测章节是否为空 -// if (chapterVos.size() == 0) { -// throw new DBException(ExceptionMapping.DATA_NOT_EXIST); -// } -// -// //转换为VO对象 -// chapterVos.forEach(lessonChapterVO -> { -// ExamChapterInfoVO examChapterInfoVO = new ExamChapterInfoVO(); -// examChapterInfoVO.setId(lessonChapterVO.getId()); -// examChapterInfoVO.setName(lessonChapterVO.getName()); -// -// examChapterInfoVOList.add(examChapterInfoVO); -// }); -// -// return examChapterInfoVOList; -// } - @Override public List queryTrainingTypes(Long lessonId) { // 获取课程,课程所属产品编码 @@ -265,8 +161,6 @@ public class ExamService implements IExamService { /** * 查询试题定义的详细信息 - * - * @param examId */ @Override public ExamDefinitionVO queryExamInfo(Long examId) { @@ -287,7 +181,6 @@ public class ExamService implements IExamService { examDefinitionRulesVOList.add(examDefinitionRulesVO); }); ExamDefinitionVO examDefinitionVO = new ExamDefinitionVO(examDefinition); - examDefinitionVO.setClasses(iOrgUserService.getDepartsByExamId(examId)); examDefinitionVO.setExamDefinitionRulesVOList(examDefinitionRulesVOList); return examDefinitionVO; @@ -301,47 +194,15 @@ public class ExamService implements IExamService { //查询课程信息 LessonVO lessonVO = iLessonService.getLessonInfo(lessonId); -// MapVO mapVO = iMapService.findMapBaseInfoById(lessonVO.getMapId()); -// BusinessConsts.Lesson.PrdInfo prdInfo = BusinessConsts.Lesson.PrdInfo.getBy(lessonVO.getPrdType()); -// String defaultLessonName = String.join("-", mapVO.getName(), prdInfo.getName()); -// lessonVO.setSystemFault(Objects.equals(lessonVO.getName(),defaultLessonName)); - // 如果用户关联班级 查找班级关联试卷 - List examIds = null; -// List userDepartRelVOS = this.iOrgUserService.getDepartRefByUserId(userVO.getId()); -// if (!CollectionUtils.isEmpty(userDepartRelVOS)) { -// examIds = new ArrayList<>(); -// for (UserDepartRelVO udr : userDepartRelVOS) { -// examIds.addAll(iOrgUserService.getExamIdsByDepartId(udr.getDepartmentId())); -// } -// } //查询课程下的试题信息 ExamDefinitionExample examDefinitionExample = new ExamDefinitionExample(); examDefinitionExample.createCriteria().andLessonIdEqualTo(lessonId).andStatusEqualTo(BusinessConsts.STATUS_USE); List examDefinitionList = examDefinitionDAO.selectByExample(examDefinitionExample); - // 检测试题是否有效 - LocalDateTime now = LocalDateTime.now(); - Iterator iterator = examDefinitionList.iterator(); - while (iterator.hasNext()) { - ExamDefinition exam = iterator.next(); - if (null != exam.getEndTime() && now.isAfter(exam.getEndTime())) { - this.forceOffline(exam); - iterator.remove(); - } else if (!lessonVO.isSystemFault() && Objects.nonNull(examIds) -// && !Objects.equals(exam.getName(),defaultLessonName+"试卷") - && !examIds.contains(exam.getId())) { - iterator.remove(); - } - } //转换为VO ExamsLessonVO examsLessonVO = new ExamsLessonVO(lessonVO); List examDefinitionVOList = new ArrayList<>(); examDefinitionList.forEach(examDefinition -> { ExamDefinitionVO exam = new ExamDefinitionVO(examDefinition); - // 试卷存在班级关系,获取班级列表 - List departs = iOrgUserService.getDepartsByExamId(examDefinition.getId()); - if (!CollectionUtils.isEmpty(departs)) { - exam.setClasses(departs); - } examDefinitionVOList.add(exam); }); examsLessonVO.setExamDefinitionList(examDefinitionVOList); @@ -422,49 +283,27 @@ public class ExamService implements IExamService { * 删除指定ID的考试信息 */ @Override - public void deleteExam(String id, UserVO userVO) { + public void deleteExam(Long id, UserVO userVO) { //判断是否已有用户参与考试,如果有,不能删除考试定义 UserExamExample userExamExample = new UserExamExample(); - userExamExample.createCriteria().andExamIdEqualTo(Long.parseLong(id)); + userExamExample.createCriteria().andExamIdEqualTo(id); BusinessExceptionAssertEnum.OPERATION_NOT_SUPPORTED.assertNotTrue(userExamMapper.countByExample(userExamExample) > 0, String.format("试卷[%s]已被使用", id)); //删除考试信息和规则信息 - ExamDefinition examDefinition = examDefinitionDAO.selectByPrimaryKey(Long.parseLong(id)); + ExamDefinition examDefinition = examDefinitionDAO.selectByPrimaryKey(id); if (examDefinition == null) { return; } BusinessExceptionAssertEnum.INSUFFICIENT_PERMISSIONS.assertEquals(userVO.getId(), examDefinition.getCreatorId(), String.format("你不是试卷[%s]的创建者", examDefinition.getId())); -// BusinessExceptionAssertEnum.INVALID_OPERATION.assertTrue(examDefinition != null && userVO.getId().equals(examDefinition.getCreatorId()), -// "试卷不存在或你不是试卷创建者"); + ExamDefinitionRulesExample example = new ExamDefinitionRulesExample(); - example.createCriteria().andExamIdEqualTo(Long.parseLong(id)); + example.createCriteria().andExamIdEqualTo(id); definitionRulesDAO.deleteByExample(example); - examDefinitionDAO.deleteByPrimaryKey(Long.parseLong(id)); + examDefinitionDAO.deleteByPrimaryKey(id); } - -// /** -// * 查询章节下允许创建的最多题目数量 -// * -// * @param lessonId -// * @param chapterId -// * @return -// */ -// @Override -// public int queryTrainingNum(String lessonId, String chapterId) { -// Long chapterIdLong = ConvertUtil.str2Long(chapterId); -// Long lessonIdLong = ConvertUtil.str2Long(lessonId); -// -// //查询课程章节实训映射表信息 -// LsRelChapterTrainingExample example = new LsRelChapterTrainingExample(); -// example.setDistinct(true); -// example.createCriteria().andChapterIdEqualTo(chapterIdLong).andLessonIdEqualTo(lessonIdLong); -// List lsRelChapterTrainingList = lsRelChapterTrainingMapper.selectByExample(example); -// -// return lsRelChapterTrainingList.size(); -// } @Override public Long queryTrainingNum(Long lessonId, String trainingType, String operateType) { // 获取课程数据 @@ -514,27 +353,41 @@ public class ExamService implements IExamService { return examDefinitionDAO.selectByExample(example); } - private void forceOffline(ExamDefinition exam) { - exam.setStatus(BusinessConsts.STATUS_NOT_USE); - this.examDefinitionDAO.updateByPrimaryKey(exam); + @Override + public List queryBasicInfo(Long mapId, String prdType) { + return ExamDefinitionVO.convert(findEntities(mapId, prdType)); + } + + @Override + public void copy(Long fromMapId, Long toMapId, UserVO user) { + /* 拷贝考试定义 */ + List exams = findEntities(fromMapId, null); + Map old_new_examIdMap = new HashMap<>(); + exams.forEach(examDefinition -> { + Long oldId = examDefinition.getId(); + examDefinition.setId(null); + examDefinition.setMapId(toMapId); + examDefinition.setCreatorId(user.getId()); + examDefinition.setCreateTime(LocalDateTime.now()); + examDefinitionDAO.insert(examDefinition); + old_new_examIdMap.put(oldId, examDefinition.getId()); + }); + /* 拷贝考试规则 */ + ExamDefinitionRulesExample ruleExample = new ExamDefinitionRulesExample(); + ruleExample.createCriteria().andExamIdIn(new ArrayList<>(old_new_examIdMap.keySet())); + definitionRulesDAO.selectByExample(ruleExample).forEach(rule->{ + rule.setId(null); + rule.setExamId(old_new_examIdMap.get(rule.getExamId())); + definitionRulesDAO.insert(rule); + }); } @Override public void update(Long id, ExamDefinitionVO examDefinitionVO) { ExamDefinition examDefinition = this.examDefinitionDAO.selectByPrimaryKey(id); BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertNotNull(examDefinition); - if (!CollectionUtils.isEmpty(iOrgUserService.getDepartsByExamId(id))) { - iOrgUserService.deleteDepartsExam(id); - } - if (!CollectionUtils.isEmpty(examDefinitionVO.getClasses())) { - examDefinitionVO.getClasses().forEach(departmentVO -> iOrgUserService.addDepartExam(id, departmentVO.getId())); - } //考试名称查重 - String name = examDefinitionVO.getName(); - ExamDefinitionExample examDefinitionExample = new ExamDefinitionExample(); - examDefinitionExample.createCriteria().andNameEqualTo(name).andIdNotEqualTo(id); - List examDefinitionList = examDefinitionDAO.selectByExample(examDefinitionExample); - BusinessExceptionAssertEnum.DATA_UNIQUE_PROPERTY_REPEAT.assertCollectionEmpty(examDefinitionList); + confirmNameUnique(examDefinition.getId(), examDefinition.getMapId(), examDefinition.getType(), examDefinitionVO.getName(), BusinessConsts.STATUS_USE); examDefinition.setName(examDefinitionVO.getName()); examDefinition.setTrial(examDefinitionVO.getTrial()); examDefinition.setStartTime(examDefinitionVO.getStartTime()); @@ -542,59 +395,6 @@ public class ExamService implements IExamService { this.examDefinitionDAO.updateByPrimaryKey(examDefinition); } - @Override - @Transactional - public void copy(Map lessonRelationMap, UserVO user) { - ArrayList lessonIdList = new ArrayList<>(lessonRelationMap.keySet()); - List examList = findEntityByLessonIdList(lessonIdList); - for (ExamDefinition exam : examList) { - //因为考试定义的id要变,先将考试规则查出来 - ExamDefinitionRulesExample rulesExample = new ExamDefinitionRulesExample(); - rulesExample.createCriteria() - .andExamIdEqualTo(exam.getId()); - List rulesList = examDefinitionRulesDAO.selectByExample(rulesExample); - //拷贝考试定义 - exam.setLessonId(lessonRelationMap.get(exam.getLessonId())); - exam.setCreatorId(user.getId()); - exam.setCreateTime(LocalDateTime.now()); - exam.setId(null); - examDefinitionDAO.insertSelective(exam); - for (ExamDefinitionRules rules : rulesList) { - rules.setId(null); - rules.setExamId(exam.getId()); - examDefinitionRulesDAO.insertSelective(rules); - } - } - -// ExamDefinitionExample examExample = new ExamDefinitionExample(); -// examExample.createCriteria() -// .andLessonIdEqualTo(sourceLessonId); -// List definitionList = this.examDefinitionDAO.selectByExample(examExample); -// if(!CollectionUtils.isEmpty(definitionList)) { -// definitionList.forEach(definition -> { -// // 拷贝考试定义 -// Long oldId = definition.getId(); -// definition.setId(null); -// definition.setLessonId(targetLessonId); -// definition.setCreatorId(user.getId()); -// this.examDefinitionDAO.insert(definition); -// Long newId = definition.getId(); -// // 拷贝考试规则 -// ExamDefinitionRulesExample example = new ExamDefinitionRulesExample(); -// example.createCriteria() -// .andExamIdEqualTo(oldId); -// List ruleList = this.definitionRulesDAO.selectByExample(example); -// if(!CollectionUtils.isEmpty(ruleList)) { -// ruleList.forEach(rules -> { -// rules.setId(null); -// rules.setExamId(newId); -// this.definitionRulesDAO.insert(rules); -// }); -// } -// }); -// } - } - @Override public List findEntities(Long lessonId) { ExamDefinitionExample example = new ExamDefinitionExample(); @@ -604,43 +404,38 @@ public class ExamService implements IExamService { @Override public PageVO pagedQueryByLoginProject(ExamDefinitionQueryVO queryVO, LoginUserInfoVO loginInfo) { - List lessonIds; - if (queryVO.getLessonId() != null) { - lessonIds = List.of(queryVO.getLessonId()); - } else { - List lessonVOS = iLessonService.queryNonDefaultLessons(null, loginInfo.getProject(), BusinessConsts.STATUS_USE); - lessonIds = lessonVOS.stream().map(LessonVO::getId).collect(Collectors.toList()); - } - if (CollectionUtils.isEmpty(lessonIds)) { - return new PageVO<>(queryVO.getPageNum(), queryVO.getPageSize(), 0, new ArrayList<>()); - } else { - List orgLessons = iOrgLessonService.findEntitiesByLessonIds(lessonIds); - Map> lessonOrgMap = orgLessons.stream() - .collect(Collectors.groupingBy(OrgLesson::getLessonId, Collectors.mapping(OrgLesson::getOrgId, Collectors.toList()))); - ExamDefinitionExample example = new ExamDefinitionExample(); - ExamDefinitionExample.Criteria criteria = example.createCriteria().andLessonIdIn(lessonIds); - if (StringUtils.hasText(queryVO.getName())) { - criteria.andNameLike(String.format("%%%s%%", queryVO.getName())); - } - if (StringUtils.hasText(queryVO.getCreatorName())) { - List creatorIds = iSysUserService.findUserByName(queryVO.getCreatorName()).stream().map(UserVO::getId).collect(Collectors.toList()); - if (CollectionUtils.isEmpty(creatorIds)) { - return new PageVO<>(queryVO.getPageNum(), queryVO.getPageSize(), 0, new ArrayList<>()); - } else { - criteria.andCreatorIdIn(creatorIds); - } - } - PageHelper.startPage(queryVO.getPageNum(), queryVO.getPageSize()); - Page page = (Page) examDefinitionDAO.selectByExample(example); - Map creatorMap = iSysUserService.findEntity(page.stream().map(ExamDefinition::getCreatorId).collect(Collectors.toList()), null) - .stream().collect(Collectors.toMap(SysUser::getId, Function.identity())); - List list = page.getResult().stream().map(examDefinition -> { - ExamDefinitionVO vo = new ExamDefinitionVO(examDefinition, creatorMap.get(examDefinition.getCreatorId())); - vo.setClsIds(lessonOrgMap.get(vo.getLessonId())); - return vo; - }).collect(Collectors.toList()); - return PageVO.convert(page, list); + PageVO empty = new PageVO<>(queryVO.getPageNum(), queryVO.getPageSize(), 0, new ArrayList<>()); + List creatorIds = null; + if (StringUtils.hasText(queryVO.getCreatorName())) { + List creators = iSysUserService.findUserByName(queryVO.getCreatorName()); + if (CollectionUtils.isEmpty(creators)) + return empty; + creatorIds = creators.stream().map(UserVO::getId).collect(Collectors.toList()); } + List mapIds = iMapService.findOnlineMapByProjectCode(loginInfo.getProject().name()) + .stream().map(MapVO::getId).collect(Collectors.toList()); + if (CollectionUtils.isEmpty(mapIds)) + return empty; + ExamDefinitionExample example = new ExamDefinitionExample(); + ExamDefinitionExample.Criteria criteria = example.createCriteria().andMapIdIn(mapIds); + if (!CollectionUtils.isEmpty(creatorIds)) + criteria.andCreatorIdIn(creatorIds); + if (StringUtils.hasText(queryVO.getName())) + criteria.andNameLike(String.format("%%%s%%", queryVO.getName())); + PageHelper.startPage(queryVO.getPageNum(), queryVO.getPageSize()); + Page page = (Page) examDefinitionDAO.selectByExample(example); + creatorIds = page.stream().map(ExamDefinition::getCreatorId).collect(Collectors.toList()); + Map creatorMap = iSysUserService.findEntity(creatorIds, null) + .stream().collect(Collectors.toMap(SysUser::getId, Function.identity())); + Map> examId_orgId_map = iOrgService.queryByExamIds(page.stream().map(ExamDefinition::getId).collect(Collectors.toList()), BusinessConsts.Org.Status.VALID) + .stream().collect(Collectors.toMap(ExamDefinitionVO::getId, ExamDefinitionVO::getClsIds)); + List vos = page.stream().map(exam -> { + ExamDefinitionVO vo = new ExamDefinitionVO(exam, creatorMap.get(exam.getCreatorId())); + vo.setClsIds(examId_orgId_map.get(exam.getId())); + return vo; + }) + .collect(Collectors.toList()); + return PageVO.convert(page, vos); } @Override @@ -650,7 +445,7 @@ public class ExamService implements IExamService { Org topOrg = iOrgService.getEntity(loginInfo.getProject(), BusinessConsts.Org.Status.VALID); List clsList = iOrgService.findEntitiesByParentId(topOrg.getId(), "id", BusinessConsts.Org.Status.VALID); List clsIds = clsList.stream().map(Org::getId).collect(Collectors.toList()); - lessonIds = iOrgLessonService.findEntitiesByOrgIds(clsIds).stream().map(OrgLesson::getLessonId).collect(Collectors.toList()); + lessonIds = iOrgLessonService.findEntitiesByOrgIds(clsIds).stream().map(OrgLesson::getLessonId).collect(Collectors.toList()); } else { lessonIds = iOrgLessonService.findEntitiesByOrgId(clsId, null).stream().map(OrgLesson::getLessonId).collect(Collectors.toList()); } @@ -661,30 +456,24 @@ public class ExamService implements IExamService { @Override public List listQueryExamByLoginProject(ExamDefinitionQueryVO queryVO, LoginUserInfoVO loginInfo) { - List lessonIds; - if (queryVO.getLessonId() != null) { - lessonIds = List.of(queryVO.getLessonId()); - } else { - lessonIds = iLessonService.queryByLoginProject(new LessonQueryVO(), loginInfo).stream().map(LessonVO::getId).collect(Collectors.toList()); - } - if (CollectionUtils.isEmpty(lessonIds)) { - return new ArrayList<>(); - } else { - List orgLessons = iOrgLessonService.findEntitiesByLessonIds(lessonIds); - Map> lessonOrgMap = orgLessons.stream() - .collect(Collectors.groupingBy(OrgLesson::getLessonId, Collectors.mapping(OrgLesson::getOrgId, Collectors.toList()))); - ExamDefinitionExample example = new ExamDefinitionExample(); - ExamDefinitionExample.Criteria criteria = example.createCriteria().andLessonIdIn(lessonIds).andCreatorIdEqualTo(loginInfo.getUserVO().getId()); - if (StringUtils.hasText(queryVO.getName())) { - criteria.andNameLike(String.format("%%%s%%", queryVO.getName())); - } - List exams = examDefinitionDAO.selectByExample(example); - return exams.stream().map(examDefinition -> { - ExamDefinitionVO vo = new ExamDefinitionVO(examDefinition); - vo.setClsIds(lessonOrgMap.get(vo.getLessonId())); - return vo; - }).collect(Collectors.toList()); - } + List mapIds = iMapService.findOnlineMapByProjectCode(loginInfo.getProject().name()) + .stream().map(MapVO::getId).collect(Collectors.toList()); + ExamDefinitionExample example = new ExamDefinitionExample(); + example.createCriteria().andMapIdIn(mapIds); + return ExamDefinitionVO.convert(examDefinitionDAO.selectByExample(example)); + } + + private List findEntities(long mapId, String prdType) { + ExamDefinitionExample example = new ExamDefinitionExample(); + ExamDefinitionExample.Criteria criteria = example.createCriteria().andMapIdEqualTo(mapId); + if (StringUtils.hasText(prdType)) + criteria.andTypeEqualTo(prdType); + return examDefinitionDAO.selectByExample(example); + } + + private void forceOffline(@NonNull ExamDefinition exam) { + exam.setStatus(BusinessConsts.STATUS_NOT_USE); + this.examDefinitionDAO.updateByPrimaryKey(exam); } private List findEntityByLessonIdList(List lessonIdList) { diff --git a/src/main/java/club/joylink/rtss/services/IExamService.java b/src/main/java/club/joylink/rtss/services/IExamService.java index c508a4057..7e415a626 100644 --- a/src/main/java/club/joylink/rtss/services/IExamService.java +++ b/src/main/java/club/joylink/rtss/services/IExamService.java @@ -7,6 +7,7 @@ import club.joylink.rtss.vo.client.ExamDefinitionQueryVO; import club.joylink.rtss.vo.client.ExamDefinitionVO; import club.joylink.rtss.vo.client.ExamsLessonVO; import club.joylink.rtss.vo.client.PageVO; +import org.springframework.transaction.annotation.Transactional; import java.util.List; import java.util.Map; @@ -17,8 +18,6 @@ public interface IExamService { */ void create(ExamDefinitionVO examDefinitionVO, UserVO userVO); -// void createGZBExam(ExamDefinitionVO examDefinitionVO, UserVO userVO); - /** * 检查分数定义是否合理 */ @@ -47,13 +46,8 @@ public interface IExamService { /** * 删除指定ID的考试信息 */ - void deleteExam(String id, UserVO userVO); + void deleteExam(Long id, UserVO userVO); - -// /** -// * 查询章节下允许创建的最多题目数量 -// */ -// int queryTrainingNum(String lessonId, String chapterId); /** * 根据课程和实训类型查询实训数量 */ @@ -74,8 +68,6 @@ public interface IExamService { */ void update(Long id, ExamDefinitionVO examDefinitionVO); - void copy(Map lessonRelationMap, UserVO user); - /** * 根据课程id查询考试 */ @@ -99,4 +91,9 @@ public interface IExamService { ExamDefinition getEntity(Long examId); List findEntities(List examIds); + + List queryBasicInfo(Long mapId, String prdType); + + @Transactional + void copy(Long fromMapId, Long toMapId, UserVO user); } diff --git a/src/main/java/club/joylink/rtss/services/ILessonService.java b/src/main/java/club/joylink/rtss/services/ILessonService.java index 3d68bff14..6afed4480 100644 --- a/src/main/java/club/joylink/rtss/services/ILessonService.java +++ b/src/main/java/club/joylink/rtss/services/ILessonService.java @@ -1,6 +1,7 @@ package club.joylink.rtss.services; import club.joylink.rtss.constants.Project; +import club.joylink.rtss.entity.LsLesson; import club.joylink.rtss.vo.LoginUserInfoVO; import club.joylink.rtss.vo.UserVO; import club.joylink.rtss.vo.client.*; @@ -42,7 +43,7 @@ public interface ILessonService { */ LessonVO getLessonInfo(Long id); - LessonVO findByMapAndNameAndPrdType(Long mapId, String name, String prdType); + LsLesson findEntity(long mapId, String name, String prdType, String status); LessonVO findSysFaultByMapAndPrdType(Long mapId, String prdType); diff --git a/src/main/java/club/joylink/rtss/services/LessonService.java b/src/main/java/club/joylink/rtss/services/LessonService.java index ef78d2270..82788a4de 100644 --- a/src/main/java/club/joylink/rtss/services/LessonService.java +++ b/src/main/java/club/joylink/rtss/services/LessonService.java @@ -200,7 +200,7 @@ public class LessonService implements ILessonService { @Override @Transactional public void publish(LessonVO lessonVo, LessonPublishVO publishVO) { - LessonVO publishedLesson = this.findByMapAndNameAndPrdType(publishVO.getMapId(), publishVO.getName(), publishVO.getPrdType()); + LsLesson publishedLesson = this.findEntity(publishVO.getMapId(), publishVO.getName(), publishVO.getPrdType(), BusinessConsts.STATUS_USE); lessonVo.apply(publishVO); LsLesson newLesson = lessonVo.toPublic(); newLesson.setUpdateTime(LocalDateTime.now()); @@ -210,67 +210,29 @@ public class LessonService implements ILessonService { // 新发布 newLesson.setId(null); this.lessonDAO.insert(newLesson); - //存在班级条件就创建课程班级关系 - if (!CollectionUtils.isEmpty(publishVO.getClassIdList())) { - addRelLessonClass(publishVO, newLesson.getId()); - } - -// // 自动创建商品 -// iGoodsService.autoCreateTeachAndExamGoods(newLesson); } else { - //默认课程 -// MapVO mapVO = iMapService.findMapBaseInfoById(publishVO.getMapId()); -// BusinessConsts.Lesson.PrdInfo prdInfo = BusinessConsts.Lesson.PrdInfo.getBy(publishVO.getPrdType()); -// String defaultLessonName = String.join("-", mapVO.getName(), prdInfo.getName()); BusinessExceptionAssertEnum.DATA_UNIQUE_PROPERTY_REPEAT.assertTrue(publishVO.isCoverSameNameLesson(), "与已有课程同名,请修改名称"); - LessonVO sysFaultLesson = findSysFaultByMapAndPrdType(publishVO.getMapId(), publishVO.getPrdType()); - if (sysFaultLesson != null) { - BusinessExceptionAssertEnum.INVALID_OPERATION.assertNotTrue(Objects.equals(publishVO.getName(), sysFaultLesson.getName()), "与系统默认课程重名,请修改名称"); - } // 更新 newLesson.setId(publishedLesson.getId()); this.lessonDAO.updateByPrimaryKey(newLesson); - //课程存在,预备检查与班级的关系 - OrgLessonExample departmentLessonExample = new OrgLessonExample(); - departmentLessonExample.createCriteria().andLessonIdEqualTo(publishedLesson.getId()); - List departmentLessonRefs = this.departmentLessonDAO.selectByExample(departmentLessonExample); - if (!CollectionUtils.isEmpty(publishVO.getClassIdList())) { - if (!CollectionUtils.isEmpty(departmentLessonRefs)) { - List existedClassIds = departmentLessonRefs.stream().map(OrgLesson::getOrgId).collect(Collectors.toList()); - Collections.sort(existedClassIds); - Collections.sort(publishVO.getClassIdList()); - if (!existedClassIds.equals(publishVO.getClassIdList())) { - //清除现有课程班级关系 - this.departmentLessonDAO.deleteByExample(departmentLessonExample); - addRelLessonClass(publishVO, publishedLesson.getId()); - } - } else { - addRelLessonClass(publishVO, publishedLesson.getId()); - } - } else { - if (!CollectionUtils.isEmpty(departmentLessonRefs)) { - this.departmentLessonDAO.deleteByExample(departmentLessonExample); - } - } -// if(!lessonVo.getName().equals(publishedLesson.getName())) { -// // 自动创建商品 -// iGoodsService.autoUpdateTeachAndExamGoods(newLesson); -// } } this.buildAndInsertLessonVersion(newLesson); this.saveChapterDetail(newLesson, lessonVo); } @Override - public LessonVO findByMapAndNameAndPrdType(Long mapId, String name, String prdType) { + public LsLesson findEntity(long mapId, @NonNull String name, @NonNull String prdType, String status) { LsLessonExample lessonExample = new LsLessonExample(); - lessonExample.createCriteria().andMapIdEqualTo(mapId).andNameEqualTo(name).andPrdTypeEqualTo(prdType); + Criteria criteria = lessonExample.createCriteria().andMapIdEqualTo(mapId).andNameEqualTo(name).andPrdTypeEqualTo(prdType); + if (StringUtils.hasText(status)) { + criteria.andStatusEqualTo(status); + } List lessonList = this.lessonDAO.selectByExample(lessonExample); if (CollectionUtils.isEmpty(lessonList)) { return null; } - return new LessonVO(lessonList.get(0)); + return lessonList.get(0); } @Override @@ -358,8 +320,6 @@ public class LessonService implements ILessonService { this.userTrainingStatsMapper.deleteByExample(userTrainingExample); lessonDAO.deleteByPrimaryKey(lessonId); -// // 自动删除关联商品 -// this.iGoodsService.autoDeleteTeachAndExamGoods(lsLesson.getCode()); } /** @@ -435,6 +395,9 @@ public class LessonService implements ILessonService { public void updateNameAndRemarks(Long id, String name, String remarks, UserVO user) { LsLesson lesson = this.lessonDAO.selectByPrimaryKey(id); if (Objects.nonNull(lesson)) { + LsLesson sameNameLesson = findEntity(lesson.getMapId(), name, lesson.getPrdType(), BusinessConsts.STATUS_USE); + BusinessExceptionAssertEnum.DATA_UNIQUE_PROPERTY_REPEAT.assertTrue(sameNameLesson == null || sameNameLesson.getId().equals(lesson.getId()), + "名称重复"); lesson.setName(name); lesson.setRemarks(remarks); this.lessonDAO.updateByPrimaryKey(lesson); @@ -641,17 +604,18 @@ public class LessonService implements ILessonService { } private void generateLessonBy(UserVO userVO, MapVO mapVO, BusinessConsts.Lesson.PrdInfo prdLessonInfo, String prdType) { + Long mapId = mapVO.getId(); //课程 LsLesson lesson = new LsLesson(); lesson.setUpdateTime(LocalDateTime.now()); lesson.setStatus(BusinessConsts.STATUS_USE); lesson.setCreatorId(userVO.getId()); - lesson.setMapId(mapVO.getId()); + lesson.setMapId(mapId); lesson.setName(String.join("-", mapVO.getName(), prdLessonInfo.getName())); lesson.setPrdType(prdType); lesson.setRemarks(prdLessonInfo.getRemarks()); lesson.setSysfault(true); - LessonVO existedDefaultLesson = this.findSysFaultByMapAndPrdType(mapVO.getId(), prdType); + LessonVO existedDefaultLesson = this.findSysFaultByMapAndPrdType(mapId, prdType); if (Objects.nonNull(existedDefaultLesson)) { lesson.setId(existedDefaultLesson.getId()); lessonDAO.updateByPrimaryKey(lesson); @@ -694,7 +658,7 @@ public class LessonService implements ILessonService { List examTrainings = new ArrayList<>(20); int orderNum = 1; Random random = new Random(); - Map>> trainings = iTrainingV1Service.findEntities(mapVO.getId(), prdType) + Map>> trainings = iTrainingV1Service.findEntities(mapId, prdType) .stream().collect(Collectors.groupingBy(Training::getType, Collectors.groupingBy(Training::getOperateType))); for (BusinessConsts.Training.Type type : BusinessConsts.Training.Type.values()) { Map> collect = trainings.get(type.name()); @@ -731,7 +695,9 @@ public class LessonService implements ILessonService { return; } ExamDefinition examDefinition = new ExamDefinition(); + examDefinition.setMapId(mapId); examDefinition.setLessonId(lesson.getId()); + examDefinition.setType(prdType); examDefinition.setName(lesson.getName() + "试卷"); examDefinition.setDuration(1800); examDefinition.setCreatorId(userVO.getId()); diff --git a/src/main/java/club/joylink/rtss/services/MapService.java b/src/main/java/club/joylink/rtss/services/MapService.java index ac894a784..7e8bc436e 100644 --- a/src/main/java/club/joylink/rtss/services/MapService.java +++ b/src/main/java/club/joylink/rtss/services/MapService.java @@ -173,9 +173,12 @@ public class MapService implements IMapService { Objects.requireNonNull(projectCode, "项目编号不能为空"); MapInfoExample example = new MapInfoExample(); example.setOrderByClause("order_number"); - example.createCriteria() - .andStatusEqualTo(MapStatus.Online.getCode()) - .andProjectCodeEqualTo(projectCode); + MapInfoExample.Criteria criteria = example.createCriteria().andStatusEqualTo(MapStatus.Online.getCode()); + if (Project.DEFAULT.name().equals(projectCode)) { + criteria.andProjectCodeIsNull(); + } else { + criteria.andProjectCodeEqualTo(projectCode); + } List list = mapInfoDAO.selectByExample(example); return MapVO.convert2VOList(list); } @@ -642,10 +645,8 @@ public class MapService implements IMapService { .copyAllOfMapAndPrd(id, mapNewVO.getId()); //拷贝课程 Map lessonRelationMap = iLessonService.copy(id, mapNewVO.getId(), relMap, user); - if (!CollectionUtils.isEmpty(lessonRelationMap)) { - //拷贝考试 - iExamService.copy(lessonRelationMap, user); - } + //拷贝考试 + iExamService.copy(id, mapNewVO.getId(), user); //拷贝system this.iMapSystemService.copyOfMap(id, mapNewVO.getId()); // //拷贝剧本 diff --git a/src/main/java/club/joylink/rtss/services/MapSystemService.java b/src/main/java/club/joylink/rtss/services/MapSystemService.java index ea328652c..afadbf43f 100644 --- a/src/main/java/club/joylink/rtss/services/MapSystemService.java +++ b/src/main/java/club/joylink/rtss/services/MapSystemService.java @@ -13,6 +13,7 @@ import club.joylink.rtss.services.org.IOrgService; import club.joylink.rtss.services.org.IOrgUserService; import club.joylink.rtss.vo.LoginUserInfoVO; import club.joylink.rtss.vo.UserVO; +import club.joylink.rtss.vo.client.ExamDefinitionVO; import club.joylink.rtss.vo.client.LessonVO; import club.joylink.rtss.vo.client.PageVO; import club.joylink.rtss.vo.client.TreeNode; @@ -66,6 +67,9 @@ public class MapSystemService implements IMapSystemService { @Autowired private IOrgLessonService iOrgLessonService; + @Autowired + private IExamService iExamService; + @Override @Transactional public void generateSystem(Long mapId) { @@ -223,42 +227,21 @@ public class MapSystemService implements IMapSystemService { mapSystemDetailVO.setPermissionList(permissionVOList); } else if (MapSystemType.Lesson.name().equals(mapSystem.getType()) || MapSystemType.Exam.name().equals(mapSystem.getType())) { -// Org topOrg = iOrgService.findEntity(loginInfo.getProject(), BusinessConsts.Org.Status.VALID); - List lessonVOList; -// if (!Project.CGY.equals(loginInfo.getProject()) && topOrg != null) { //由于成都工业的特殊性,先防一下 -// lessonVOList = new ArrayList<>(); -// LessonVO defaultLesson = iLessonService.findSysFaultByMapAndPrdType(mapSystem.getMapId(), mapSystem.getPrdType()); -// if (defaultLesson != null && MapStatus.Online.getCode().equals(defaultLesson.getStatus())) { -// lessonVOList.add(defaultLesson); -// } -// List lessonsICreated = iLessonService.queryNonDefaultLessons(loginInfo.getUserVO().getId(), -// loginInfo.getProject(), BusinessConsts.STATUS_USE); -// lessonVOList.addAll(lessonsICreated); -// //如果当前用户有所属班级,查询所属有效班级关联的有效课程 -// List orgUsers = iOrgUserService.findEntities(loginInfo.getUserVO().getId(), null); -// List orgIds = orgUsers.stream().map(OrgUser::getOrgId).collect(Collectors.toList()); -// List validOrgIds = iOrgService.findEntities(orgIds, BusinessConsts.Org.Status.VALID) -// .stream().map(Org::getId).collect(Collectors.toList()); -// Set lessonIdSet = lessonVOList.stream().map(LessonVO::getId).collect(Collectors.toSet()); -// List orgLessonIds = iOrgLessonService.findEntitiesByOrgIds(validOrgIds).stream().map(OrgLesson::getLessonId) -// .filter(lessonId -> !lessonIdSet.contains(lessonId)).distinct().collect(Collectors.toList()); -// lessonVOList.addAll(iLessonService.queryByIds(orgLessonIds, BusinessConsts.STATUS_USE)); -// // -// } else { - lessonVOList = iLessonService.getByMapIdAndPrdType(mapSystem.getMapId(), mapSystem.getPrdType()); -// } - + //查询课程 + List lessonVOList = iLessonService.getByMapIdAndPrdType(mapSystem.getMapId(), mapSystem.getPrdType()); if (CollectionUtils.isEmpty(lessonVOList)) { return mapSystemDetailVO; } - //查询课程关联的班级列表 - lessonVOList.forEach(lessonVO -> { + lessonVOList.forEach(lessonVO -> { //查询课程关联的班级列表 List classNames = this.iOrgUserService.getDepartNamesByLesson(lessonVO.getId()); if (!CollectionUtils.isEmpty(classNames)) { lessonVO.setClassNames(classNames); } }); mapSystemDetailVO.setLessonList(lessonVOList); + //查询考试 + List examVOS = iExamService.queryBasicInfo(mapSystem.getMapId(), mapSystem.getPrdType()); + mapSystemDetailVO.setExamList(examVOS); } else if (MapSystemType.Plan.name().equals(mapSystem.getType())) { List planVOList = iRunPlanDraftService.queryListByMapId(mapSystem.getMapId(), userVO); mapSystemDetailVO.setPlanList(planVOList); diff --git a/src/main/java/club/joylink/rtss/services/UserExamService.java b/src/main/java/club/joylink/rtss/services/UserExamService.java index 8ba04a579..aa61eeb0e 100644 --- a/src/main/java/club/joylink/rtss/services/UserExamService.java +++ b/src/main/java/club/joylink/rtss/services/UserExamService.java @@ -75,18 +75,15 @@ public class UserExamService implements IUserExamService { BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertNotNull(examDef); // 判断是否有权限 if (!examDef.getTrial()) { - Calendar calendar = Calendar.getInstance(); - calendar.setTime(new Date()); - calendar.add(Calendar.SECOND, examDef.getDuration()); - LsLesson lesson = this.lessonDAO.selectByPrimaryKey(examDef.getLessonId()); - groupSimulationService.confirmHasPermission(userVO, lesson.getMapId(), lesson.getPrdType()); -// List examPermission = iUserPermissionService.getExamUserPermission(userVO, lesson.getMapId(), lesson.getPrdType(), lesson.getId()); -// BusinessExceptionAssertEnum.SIMULATION_PERMISSION_NOT_AVAILABLE.assertCollectionNotEmpty(examPermission); + groupSimulationService.confirmHasPermission(userVO, examDef.getMapId(), examDef.getType()); } // 判断是否在考试时间之内 + LocalDateTime now = LocalDateTime.now(); if (examDef.getStartTime() != null) { - LocalDateTime now = LocalDateTime.now(); - BusinessExceptionAssertEnum.OPERATION_NOT_SUPPORTED.assertTrue(now.isAfter(examDef.getStartTime()) && now.isBefore(examDef.getEndTime())); + BusinessExceptionAssertEnum.OPERATION_NOT_SUPPORTED.assertTrue(now.isAfter(examDef.getStartTime()), "考试尚未开始"); + } + if (examDef.getEndTime() != null) { + BusinessExceptionAssertEnum.OPERATION_NOT_SUPPORTED.assertTrue(now.isBefore(examDef.getEndTime()), "考试已经结束"); } // 保存用户考试信息 UserExam userExam = new UserExam(); @@ -102,11 +99,11 @@ public class UserExamService implements IUserExamService { ruleExample.createCriteria().andExamIdEqualTo(examId); List rules = this.examDefinitionRulesDAO.selectByExample(ruleExample); BusinessExceptionAssertEnum.DATA_ERROR.assertCollectionNotEmpty(rules); - //确认课程存在 - LsLesson lesson = this.lessonDAO.selectByPrimaryKey(examDef.getLessonId()); - BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertNotNull(lesson); +// //确认课程存在 +// LsLesson lesson = this.lessonDAO.selectByPrimaryKey(examDef.getLessonId()); +// BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertNotNull(lesson); //查询实训,生成试卷 - Map>> trainings = iTrainingService.findEntities(lesson.getMapId(), lesson.getPrdType()) + Map>> trainings = iTrainingService.findEntities(examDef.getMapId(), examDef.getType()) .stream().collect(Collectors.groupingBy(Training::getType, Collectors.groupingBy(Training::getOperateType))); for (ExamDefinitionRules rule : rules) { List collect; @@ -306,7 +303,8 @@ public class UserExamService implements IUserExamService { @Override public PageVO pagedQueryOrgUserExamResult(Long orgId, Long examId, PageQueryVO queryVO) { - List userIds = iOrgUserService.findEntitiesByOrgId(orgId, BusinessConsts.OrgRole.Student).stream().map(OrgUser::getUserId).collect(Collectors.toList()); + List userIds = iOrgUserService.findEntitiesByOrgId(orgId, BusinessConsts.OrgRole.Student) + .stream().map(OrgUser::getUserId).collect(Collectors.toList()); if (CollectionUtils.isEmpty(userIds)) { return new PageVO<>(queryVO.getPageNum(), queryVO.getPageSize(), 0, new ArrayList<>()); } else { @@ -323,7 +321,8 @@ public class UserExamService implements IUserExamService { Map userExamMap = userExamMapper.selectByExample(example).stream() .collect(Collectors.toMap(UserExam::getUserId, Function.identity())); - Map userMap = iSysUserService.findEntity(userIds, "id").stream().collect(Collectors.toMap(SysUser::getId, Function.identity())); + Map userMap = iSysUserService.findEntity(userIds, "id") + .stream().collect(Collectors.toMap(SysUser::getId, Function.identity())); Org topOrg = iOrgService.getTopOrgEntity(orgId, BusinessConsts.Org.Status.VALID); List vos = userIds.stream().map(userId -> { UserExam userExam = userExamMap.get(userId); diff --git a/src/main/java/club/joylink/rtss/services/org/IOrgExamService.java b/src/main/java/club/joylink/rtss/services/org/IOrgExamService.java new file mode 100644 index 000000000..115151a36 --- /dev/null +++ b/src/main/java/club/joylink/rtss/services/org/IOrgExamService.java @@ -0,0 +1,17 @@ +package club.joylink.rtss.services.org; + +import club.joylink.rtss.entity.OrgExam; +import club.joylink.rtss.vo.UserVO; + +import java.util.List; + +public interface IOrgExamService { + + void create(Long clsId, List examIds, UserVO user); + + List findEntities(long orgId, Long creatorId); + + List findEntities(List examIds, Long creatorId); + + List queryOrgExam(Long clsId, UserVO user); +} diff --git a/src/main/java/club/joylink/rtss/services/org/IOrgLessonService.java b/src/main/java/club/joylink/rtss/services/org/IOrgLessonService.java index 905fed25c..233180d37 100644 --- a/src/main/java/club/joylink/rtss/services/org/IOrgLessonService.java +++ b/src/main/java/club/joylink/rtss/services/org/IOrgLessonService.java @@ -23,7 +23,7 @@ public interface IOrgLessonService { */ List findEntitiesByOrgIds(List orgIds); - List findEntitiesByLessonIds(List lessonIds); + List findEntitiesByLessonIds(List lessonIds, Long creatorId); List findEntitiesByLessonId(Long lessonId); diff --git a/src/main/java/club/joylink/rtss/services/org/IOrgScoringRuleService.java b/src/main/java/club/joylink/rtss/services/org/IOrgScoringRuleService.java index ec6be1520..9c356ecf9 100644 --- a/src/main/java/club/joylink/rtss/services/org/IOrgScoringRuleService.java +++ b/src/main/java/club/joylink/rtss/services/org/IOrgScoringRuleService.java @@ -57,5 +57,5 @@ public interface IOrgScoringRuleService { * 查询评价规则能应用到的组织 * @return */ - List queryRuleCanApplyTo(Long ruleId); + List queryRuleCanApplyTo(Long ruleId, UserVO user); } diff --git a/src/main/java/club/joylink/rtss/services/org/IOrgService.java b/src/main/java/club/joylink/rtss/services/org/IOrgService.java index 64636249f..850c9325e 100644 --- a/src/main/java/club/joylink/rtss/services/org/IOrgService.java +++ b/src/main/java/club/joylink/rtss/services/org/IOrgService.java @@ -4,6 +4,7 @@ import club.joylink.rtss.constants.Project; import club.joylink.rtss.entity.Org; import club.joylink.rtss.vo.LoginUserInfoVO; import club.joylink.rtss.vo.UserVO; +import club.joylink.rtss.vo.client.ExamDefinitionVO; import club.joylink.rtss.vo.client.PageVO; import club.joylink.rtss.vo.client.org.CompanyVO; import club.joylink.rtss.vo.client.org.DepartmentVO; @@ -64,4 +65,9 @@ public interface IOrgService { PageVO adminPagedQueryOrg(OrgQueryVO queryVO); CompanyVO get(Long id); + + /** + * 查询这些考试关联的班级 + */ + List queryByExamIds(List examIds, String status); } diff --git a/src/main/java/club/joylink/rtss/services/org/IOrgUserService.java b/src/main/java/club/joylink/rtss/services/org/IOrgUserService.java index b1ed5d39e..e4d1a78f7 100644 --- a/src/main/java/club/joylink/rtss/services/org/IOrgUserService.java +++ b/src/main/java/club/joylink/rtss/services/org/IOrgUserService.java @@ -17,8 +17,6 @@ public interface IOrgUserService { */ CompanyVO userScanCodeBindCompanyManager(Long userId, Long companyId); - boolean isCompanyUser(Long userId); - DepartmentVO createDepart(DepartmentVO departmentVO); void updateDepartInfo(Long id, DepartmentVO departmentVO); @@ -33,8 +31,6 @@ public interface IOrgUserService { List getDepartAndChild(Long companyId, Long deptId); - List getDepartRefByUserId(Long userId); - void addDepartUserInfo(UserVO user, UserDepartRelVO userDepartRelVO); void updateDepartUserInfo(UserVO user, UserDepartRelVO userDepartRelVO); @@ -48,14 +44,6 @@ public interface IOrgUserService { void importCompanyUserInfo(UserVO user, Long clsId, List importOrgUsers); - List getDepartsByLesson(Long lessonId); - - List getDepartsByExamId(Long examId); - - void deleteDepartsExam(Long examId); - - void addDepartExam(Long examId, Long departId); - List getDepartLessonRefs(Long departId); List getLessonsByDepart(Long departId); diff --git a/src/main/java/club/joylink/rtss/services/org/OrgExamService.java b/src/main/java/club/joylink/rtss/services/org/OrgExamService.java new file mode 100644 index 000000000..9f34ec904 --- /dev/null +++ b/src/main/java/club/joylink/rtss/services/org/OrgExamService.java @@ -0,0 +1,73 @@ +package club.joylink.rtss.services.org; + +import club.joylink.rtss.constants.BusinessConsts; +import club.joylink.rtss.dao.OrgExamDAO; +import club.joylink.rtss.entity.Org; +import club.joylink.rtss.entity.OrgExam; +import club.joylink.rtss.entity.OrgExamExample; +import club.joylink.rtss.vo.UserVO; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.time.LocalDateTime; +import java.util.List; +import java.util.stream.Collectors; + +@Service +public class OrgExamService implements IOrgExamService { + @Autowired + private IOrgService iOrgService; + + @Autowired + private IOrgUserService iOrgUserService; + + @Autowired + private OrgExamDAO orgExamDAO; + + @Override + public void create(Long clsId, List examIds, UserVO user) { + Org topOrg = iOrgService.getTopOrgEntity(clsId, BusinessConsts.Org.Status.VALID); + iOrgUserService.confirmIsTheRoleInThisOrg(user.getId(), topOrg.getId(), BusinessConsts.OrgRole.Admin); + delete(clsId, user.getId()); + LocalDateTime createTime = LocalDateTime.now(); + examIds.forEach(examId -> { + OrgExam orgExam = new OrgExam(); + orgExam.setOrgId(clsId); + orgExam.setExamId(examId); + orgExam.setCreatorId(user.getId()); + orgExam.setCreateTime(createTime); + orgExamDAO.insert(orgExam); + }); + } + + @Override + public List findEntities(long orgId, Long creatorId) { + OrgExamExample example = new OrgExamExample(); + OrgExamExample.Criteria criteria = example.createCriteria().andOrgIdEqualTo(orgId); + if (creatorId != null) { + criteria.andCreatorIdEqualTo(creatorId); + } + return orgExamDAO.selectByExample(example); + } + + @Override + public List findEntities(List examIds, Long creatorId) { + OrgExamExample example = new OrgExamExample(); + OrgExamExample.Criteria criteria = example.createCriteria().andExamIdIn(examIds); + if (creatorId != null) { + criteria.andCreatorIdEqualTo(creatorId); + } + return orgExamDAO.selectByExample(example); + } + + @Override + public List queryOrgExam(Long clsId, UserVO user) { + return findEntities(clsId, user.getId()).stream().map(orgExam -> String.valueOf(orgExam.getExamId())).collect(Collectors.toList()); + } + + private void delete(long orgId, long creatorId) { + OrgExamExample example = new OrgExamExample(); + example.createCriteria().andOrgIdEqualTo(orgId).andCreatorIdEqualTo(creatorId); + orgExamDAO.deleteByExample(example); + } +} diff --git a/src/main/java/club/joylink/rtss/services/org/OrgLessonService.java b/src/main/java/club/joylink/rtss/services/org/OrgLessonService.java index ab7fa2311..c072823e6 100644 --- a/src/main/java/club/joylink/rtss/services/org/OrgLessonService.java +++ b/src/main/java/club/joylink/rtss/services/org/OrgLessonService.java @@ -77,12 +77,15 @@ public class OrgLessonService implements IOrgLessonService { } @Override - public List findEntitiesByLessonIds(List lessonIds) { + public List findEntitiesByLessonIds(List lessonIds, Long creatorId) { if (CollectionUtils.isEmpty(lessonIds)) { return new ArrayList<>(); } else { OrgLessonExample example = new OrgLessonExample(); - example.createCriteria().andLessonIdIn(lessonIds); + OrgLessonExample.Criteria criteria = example.createCriteria().andLessonIdIn(lessonIds); + if (creatorId != null) { + criteria.andCreatorIdEqualTo(creatorId); + } return orgLessonDAO.selectByExample(example); } } diff --git a/src/main/java/club/joylink/rtss/services/org/OrgScoringRuleService.java b/src/main/java/club/joylink/rtss/services/org/OrgScoringRuleService.java index a50932119..656998b31 100644 --- a/src/main/java/club/joylink/rtss/services/org/OrgScoringRuleService.java +++ b/src/main/java/club/joylink/rtss/services/org/OrgScoringRuleService.java @@ -1,7 +1,6 @@ package club.joylink.rtss.services.org; import club.joylink.rtss.constants.BusinessConsts; -import club.joylink.rtss.dao.OrgDAO; import club.joylink.rtss.dao.OrgScoringRuleDAO; import club.joylink.rtss.dao.OrgScoringRuleRelDAO; import club.joylink.rtss.entity.*; @@ -24,6 +23,7 @@ import com.github.pagehelper.PageHelper; import lombok.NonNull; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import org.springframework.util.CollectionUtils; import org.springframework.util.StringUtils; @@ -64,7 +64,7 @@ public class OrgScoringRuleService implements IOrgScoringRuleService { private IOrgLessonService iOrgLessonService; @Autowired - private OrgDAO orgDAO; + private IOrgExamService iOrgExamService; @Override @@ -79,15 +79,23 @@ public class OrgScoringRuleService implements IOrgScoringRuleService { } // TODO: 2021/3/24 评价规则应用到班级之后不能修改,班级排课检查应用规则,算分时0处理;老师和班级的关系不要了 + @Transactional @Override public void updateScoringRule(OrgScoringRuleVO orgScoringRuleVO, UserVO user) { BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertNotNull(orgScoringRuleVO.getId(), "id不能为null"); this.check4Update(orgScoringRuleVO); - OrgScoringRuleWithBLOBs entity = getRuleEntity(orgScoringRuleVO.getId()); - OrgScoringRuleWithBLOBs rule = orgScoringRuleVO.cover4Update(entity); + OrgScoringRuleWithBLOBs rule = getRuleEntity(orgScoringRuleVO.getId()); + orgScoringRuleVO.cover4Update(rule); rule.setUpdateId(user.getId()); rule.setUpdateTime(LocalDateTime.now()); orgScoringRuleDAO.updateByPrimaryKeyWithBLOBs(rule); + /*更新rel表*/ + OrgScoringRuleRelExample relExample = new OrgScoringRuleRelExample(); + relExample.createCriteria().andRuleIdEqualTo(rule.getId()); + OrgScoringRuleRel rel = new OrgScoringRuleRel(); + rel.setRuleSchoolYear(rule.getSchoolYear()); + rel.setRuleTerm(rule.getTerm()); + orgScoringRuleRelDAO.updateByExampleSelective(rel, relExample); } @Override @@ -207,6 +215,10 @@ public class OrgScoringRuleService implements IOrgScoringRuleService { OrgScoringRuleRel rel = new OrgScoringRuleRel(); rel.setOrgId(orgId); rel.setRuleId(ruleId); + rel.setRuleOrgId(rule.getOrgId()); + rel.setRuleSchoolYear(rule.getSchoolYear()); + rel.setRuleTerm(rule.getTerm()); + rel.setRuleCreatorId(rule.getCreatorId()); return rel; }).collect(Collectors.toList()); orgScoringRuleRelDAO.batchInsert(rels); @@ -214,42 +226,25 @@ public class OrgScoringRuleService implements IOrgScoringRuleService { } @Override - public List queryRuleCanApplyTo(Long ruleId) { + public List queryRuleCanApplyTo(Long ruleId, UserVO user) { OrgScoringRuleWithBLOBs rule = getRuleEntity(ruleId); OrgScoringRuleVO vo = OrgScoringRuleVO.buildDetails(rule, null); - Set lessonIdSet = new HashSet<>(vo.getAllLessonIds()); + List lessonIds = vo.getAllLessonIds(); List examIds = vo.getAllExamIds(); - if (!CollectionUtils.isEmpty(examIds)) { - List examDefinitions = iExamService.findEntities(examIds); - examDefinitions.forEach(examDefinition -> lessonIdSet.add(examDefinition.getLessonId())); + List clsIds = new ArrayList<>(); + if (!CollectionUtils.isEmpty(lessonIds) && !CollectionUtils.isEmpty(examIds)) { //取课程和考试关联的班级的交集 + clsIds.addAll(iOrgLessonService.findEntitiesByLessonIds(lessonIds, user.getId()) + .stream().map(OrgLesson::getOrgId).collect(Collectors.toList())); + clsIds.retainAll(iOrgExamService.findEntities(examIds, user.getId()) + .stream().map(OrgExam::getOrgId).collect(Collectors.toList())); + } else if (!CollectionUtils.isEmpty(lessonIds)) { + clsIds.addAll(iOrgLessonService.findEntitiesByLessonIds(lessonIds, user.getId()) + .stream().map(OrgLesson::getOrgId).collect(Collectors.toList())); + } else { + clsIds.addAll(iOrgExamService.findEntities(examIds, user.getId()) + .stream().map(OrgExam::getOrgId).collect(Collectors.toList())); } - OrgExample orgExample = new OrgExample(); - OrgExample.Criteria criteria = orgExample.createCriteria() - .andParentIdEqualTo(rule.getOrgId()) - .andCreatorIdEqualTo(rule.getCreatorId()) - .andStatusEqualTo(BusinessConsts.Org.Status.VALID); - if (!CollectionUtils.isEmpty(lessonIdSet)) { - List orgLessonList = iOrgLessonService.findEntitiesByLessonIds(new ArrayList<>(lessonIdSet)); - if (CollectionUtils.isEmpty(orgLessonList)) { - return new ArrayList<>(); - } else { - Map> org_lessons_map = orgLessonList.stream().collect(Collectors.groupingBy(OrgLesson::getOrgId, - Collectors.mapping(OrgLesson::getLessonId, Collectors.toSet()))); - List orgIds = org_lessons_map.entrySet().stream().filter(entry -> entry.getValue().containsAll(lessonIdSet)) - .map(Map.Entry::getKey).collect(Collectors.toList()); - if (CollectionUtils.isEmpty(orgIds)) { - return new ArrayList<>(); - } else { - criteria.andIdIn(orgIds); - } - } - } - return orgDAO.selectByExample(orgExample).stream().map(org -> { - DepartmentVO departmentVO = new DepartmentVO(); - departmentVO.setId(org.getId()); - departmentVO.setName(org.getName()); - return departmentVO; - }).collect(Collectors.toList()); + return DepartmentVO.convert2VOList(iOrgService.findEntities(clsIds, BusinessConsts.Org.Status.VALID)); } private void check4Update(OrgScoringRuleVO orgScoringRuleVO) { @@ -272,7 +267,7 @@ public class OrgScoringRuleService implements IOrgScoringRuleService { .andIdIn(ruleIds); List rules = orgScoringRuleDAO.selectByExample(ruleExample); BusinessExceptionAssertEnum.OPERATION_NOT_SUPPORTED.assertCollectionEmpty(rules, - "该规则应用到的班级有些已被同学年同学期的其它规则应用到"); + "该规则要应用到的班级有些已被应用了同学年同学期的其它规则"); } } } diff --git a/src/main/java/club/joylink/rtss/services/org/OrgService.java b/src/main/java/club/joylink/rtss/services/org/OrgService.java index 6ca999ed5..5decda86c 100644 --- a/src/main/java/club/joylink/rtss/services/org/OrgService.java +++ b/src/main/java/club/joylink/rtss/services/org/OrgService.java @@ -10,6 +10,7 @@ import club.joylink.rtss.exception.BusinessExceptionAssertEnum; import club.joylink.rtss.services.ISysUserService; import club.joylink.rtss.vo.LoginUserInfoVO; import club.joylink.rtss.vo.UserVO; +import club.joylink.rtss.vo.client.ExamDefinitionVO; import club.joylink.rtss.vo.client.PageVO; import club.joylink.rtss.vo.client.org.CompanyVO; import club.joylink.rtss.vo.client.org.DepartmentVO; @@ -47,16 +48,17 @@ public class OrgService implements IOrgService { @Transactional @Override public CompanyVO createTopOrg(CompanyVO companyVO, UserVO user) { - //检查 + /* 检查 */ if (StringUtils.hasText(companyVO.getProjectCode())) { Org org = findEntity(Project.valueOf(companyVO.getProjectCode()), BusinessConsts.Org.Status.VALID); BusinessExceptionAssertEnum.DATA_ALREADY_EXIST.assertNull(org, "项目已被绑定到其他单位!"); } + //名称检查 OrgExample example = new OrgExample(); - example.createCriteria().andNameEqualTo(companyVO.getName()).andStatusEqualTo(BusinessConsts.Org.Status.VALID); + example.createCriteria().andNameEqualTo(companyVO.getName()); BusinessExceptionAssertEnum.DATA_UNIQUE_PROPERTY_REPEAT.assertTrue(orgDAO.countByExample(example) == 0, "名称重复"); - //处理 + /* 处理 */ Org entity = companyVO.toDB(); entity.setCreatorId(user.getId()); entity.setCreateTime(LocalDateTime.now()); @@ -123,7 +125,7 @@ public class OrgService implements IOrgService { } @Override - public Org findEntity(Project project, String status) { + public Org findEntity(@NonNull Project project, String status) { OrgExample example = new OrgExample(); OrgExample.Criteria criteria = example.createCriteria().andProjectCodeEqualTo(project.name()); if (StringUtils.hasText(status)) { @@ -164,7 +166,7 @@ public class OrgService implements IOrgService { } @Override - public List findEntitiesByParentId(Long parentId, String orderBy, String status) { + public List findEntitiesByParentId(@NonNull Long parentId, String orderBy, String status) { OrgExample example = new OrgExample(); if (StringUtils.hasText(orderBy)) { example.setOrderByClause(orderBy); @@ -270,10 +272,18 @@ public class OrgService implements IOrgService { return new CompanyVO(entity); } + @Override + public List queryByExamIds(List examIds, String status) { + if (CollectionUtils.isEmpty(examIds)) { + return new ArrayList<>(); + } + return orgDAO.queryByExamIds(examIds, status); + } + /** * 创建非顶级组织 */ - private Org createNonTopOrg(@NonNull String name, @NonNull Long parentId, @NonNull Long rootId, Long creatorId) { + private Org createNonTopOrg(@NonNull String name, @NonNull Long parentId, @NonNull Long rootId, @NonNull Long creatorId) { //检查顶级组织 confirmIsTopOrg(rootId); //检查同级同名组织 diff --git a/src/main/java/club/joylink/rtss/services/org/OrgUserService.java b/src/main/java/club/joylink/rtss/services/org/OrgUserService.java index bc38edb31..cb0d39657 100644 --- a/src/main/java/club/joylink/rtss/services/org/OrgUserService.java +++ b/src/main/java/club/joylink/rtss/services/org/OrgUserService.java @@ -80,13 +80,6 @@ public class OrgUserService implements IOrgUserService { // companyUserDAO.updateByExampleSelective(cu,e); // } - @Override - public boolean isCompanyUser(Long userId) { - OrgUserExample e = new OrgUserExample(); - e.createCriteria().andUserIdEqualTo(userId); - return orgUserDAO.countByExample(e) > 0; - } - //************************************部门管理********************************************** /** @@ -115,6 +108,7 @@ public class OrgUserService implements IOrgUserService { /** * 查询部门信息 + * * @param deptId */ @Override @@ -128,6 +122,7 @@ public class OrgUserService implements IOrgUserService { /** * 根据单位id查询部门及其子部门信息 + * * @param companyId */ @Override @@ -194,14 +189,6 @@ public class OrgUserService implements IOrgUserService { return ucrs.get(0); } - @Override - public List getDepartRefByUserId(Long userId) { - OrgUserExample e = new OrgUserExample(); - e.createCriteria().andUserIdEqualTo(userId).andRoleNotEqualTo(BusinessConsts.OrgRole.Admin.name()); - List departmentUserRefs = this.orgUserDAO.selectByExample(e); - return UserDepartRelVO.convert2VOList(departmentUserRefs); - } - /** * 添加部门-职位-用户关系 */ @@ -338,7 +325,8 @@ public class OrgUserService implements IOrgUserService { /** * 导入组织用户 - * @param topOrg 导入的组织所属的顶级组织 + * + * @param topOrg 导入的组织所属的顶级组织 * @param orgId * @param orgUserIdSet 导入的组织当前已有的成员 */ @@ -370,36 +358,6 @@ public class OrgUserService implements IOrgUserService { //---------------------------课程 / 考试 / 部门----------------------------------------- - @Override - public List getDepartsByLesson(Long lessonId) { - List classes = this.orgLessonDAO.getDeparts(lessonId); - return DepartmentVO.convert2VOList(classes); - } - - @Override - public List getDepartsByExamId(Long examId) { - OrgExamExample example = new OrgExamExample(); - example.createCriteria().andExamIdEqualTo(examId); - List classes = this.orgExamDAO.getDepartsByExamId(examId); - return DepartmentVO.convert2VOList(classes); - } - - @Override - public void deleteDepartsExam(Long examId) { - OrgExamExample example = new OrgExamExample(); - example.createCriteria().andExamIdEqualTo(examId); - orgExamDAO.deleteByExample(example); - } - - //TODO 判是否存在 - @Override - public void addDepartExam(Long examId, Long departId) { - OrgExam departmentExam = new OrgExam(); - departmentExam.setExamId(examId); - departmentExam.setOrgId(departId); - orgExamDAO.insert(departmentExam); - } - @Override public List getDepartLessonRefs(Long departId) { OrgLessonExample example = new OrgLessonExample(); @@ -416,8 +374,7 @@ public class OrgUserService implements IOrgUserService { @Override public List getDepartNamesByLesson(Long LessonId) { - List classes = this.orgLessonDAO.getClassNames(LessonId); - return classes; + return this.orgLessonDAO.getClassNames(LessonId); } @Transactional @@ -451,7 +408,7 @@ public class OrgUserService implements IOrgUserService { * 该用户在该组织中是否是这个角色 */ @Override - public boolean isTheRoleInThisOrg(Long userId, Long orgId, BusinessConsts.OrgRole role) { + public boolean isTheRoleInThisOrg(@NonNull Long userId, @NonNull Long orgId, @NonNull BusinessConsts.OrgRole role) { OrgUserExample example = new OrgUserExample(); example.createCriteria() .andUserIdEqualTo(userId) diff --git a/src/main/java/club/joylink/rtss/services/training/ITrainingV1Service.java b/src/main/java/club/joylink/rtss/services/training/ITrainingV1Service.java index 960a71535..049964536 100644 --- a/src/main/java/club/joylink/rtss/services/training/ITrainingV1Service.java +++ b/src/main/java/club/joylink/rtss/services/training/ITrainingV1Service.java @@ -190,4 +190,10 @@ public interface ITrainingV1Service { List findEntities(Long mapId, String prdType); List findEntities(@NonNull Long mapId); + + /** + * 查询实训类型及其数量 + * @return + */ + Map> queryTrainingTypeAndQuantity(Long mapId, String prdType); } diff --git a/src/main/java/club/joylink/rtss/services/training/TrainingV1Service.java b/src/main/java/club/joylink/rtss/services/training/TrainingV1Service.java index 5ba070933..420b18616 100644 --- a/src/main/java/club/joylink/rtss/services/training/TrainingV1Service.java +++ b/src/main/java/club/joylink/rtss/services/training/TrainingV1Service.java @@ -36,11 +36,12 @@ import org.springframework.util.StringUtils; import java.time.LocalDateTime; import java.util.*; +import java.util.stream.Collectors; /** * 实训 服务 - * @author sheng * + * @author sheng */ @Service @Slf4j @@ -207,7 +208,7 @@ public class TrainingV1Service implements ITrainingV1Service { public void nextStep(Long id, String group, TrainingStepVO step) { Assert.hasText(group, "group不能为空!"); TrainingNewVO trainingVO = this.groupTrainingDataCache.getTrainingByGroup(group); - if(Objects.nonNull(trainingVO)) { + if (Objects.nonNull(trainingVO)) { trainingVO.nextStep(step); } } @@ -218,7 +219,7 @@ public class TrainingV1Service implements ITrainingV1Service { Assert.hasText(group, "group不能为空!"); int time = Integer.parseInt(usedTime); TrainingResultVO result = this.score(group, mode, time); - if(lessonId != 0) { + if (lessonId != 0) { // 不是从演示进入,保存数据,用于统计 UserTrainingStats userTraining = new UserTrainingStats(); userTraining.setUserId(userVO.getId()); @@ -239,11 +240,11 @@ public class TrainingV1Service implements ITrainingV1Service { private TrainingResultVO score(String group, String mode, int usedTime) { TrainingNewVO training = this.groupTrainingDataCache.getTrainingByGroup(group); - if(this.isOperateCorrect(training)) { + if (this.isOperateCorrect(training)) { // 测验/考试模式 - if(mode.equals(BusinessConsts.Training.Mode.Mode04) || mode.equals(BusinessConsts.Training.Mode.Mode05)) { + if (mode.equals(BusinessConsts.Training.Mode.Mode04) || mode.equals(BusinessConsts.Training.Mode.Mode05)) { float score = 0f; - if(training.getMaxDuration() >= usedTime) { + if (training.getMaxDuration() >= usedTime) { score = calculateScore(training, usedTime, 5L, false); return new TrainingResultVO(true, score); } @@ -256,18 +257,19 @@ public class TrainingV1Service implements ITrainingV1Service { /** * 实训操作是否正确 + * * @return */ private boolean isOperateCorrect(TrainingNewVO training) { List steps = training.getSteps(); List actualSteps = training.getActualSteps(); boolean correct = true; - if(!CollectionUtils.isEmpty(steps) && !CollectionUtils.isEmpty(actualSteps) + if (!CollectionUtils.isEmpty(steps) && !CollectionUtils.isEmpty(actualSteps) && steps.size() == actualSteps.size()) { - for(int i=0; i= 5) { + } else { + score = (current.getMaxDuration() - usedTime + 1) * point / (current.getMaxDuration() - current.getMinDuration() + 1); + if (isFloat) { + long mod = (current.getMaxDuration() - usedTime + 1) * point % (current.getMaxDuration() - current.getMinDuration() + 1); + if (mod >= 5) { score += 0.5f; } } @@ -408,16 +411,16 @@ public class TrainingV1Service implements ITrainingV1Service { public TrainingResultVO judgeAndCalculate(Long id, String group, String mode, int usedTime, long point, boolean isFloat) { TrainingNewVO current = this.groupTrainingDataCache.getTrainingByGroup(group); - if(isOperateCorrect(current)) { + if (isOperateCorrect(current)) { // 测验/考试模式 - if(mode.equals(BusinessConsts.Training.Mode.Mode04) || mode.equals(BusinessConsts.Training.Mode.Mode05)) { + if (mode.equals(BusinessConsts.Training.Mode.Mode04) || mode.equals(BusinessConsts.Training.Mode.Mode05)) { float score = 0f; - if(current.getMaxDuration() >= usedTime) { + if (current.getMaxDuration() >= usedTime) { score = calculateScore(current, usedTime, point, isFloat); - }else{ + } else { return new TrainingResultVO(false, BusinessConsts.Exam.QuestionCause.OVERTIME); } - if(score == point ){ + if (score == point) { return new TrainingResultVO(true, score, BusinessConsts.Exam.QuestionCause.PERFECT); } return new TrainingResultVO(true, score, BusinessConsts.Exam.QuestionCause.CORRECT); @@ -431,7 +434,7 @@ public class TrainingV1Service implements ITrainingV1Service { @Override @Transactional public void batchSaveAutoGenerateTrainings(List trainingVOList) { - if(!CollectionUtils.isEmpty(trainingVOList)) { + if (!CollectionUtils.isEmpty(trainingVOList)) { LocalDateTime now = LocalDateTime.now(); Long userId = UserVO.system().getId(); List list = new ArrayList<>(); @@ -444,12 +447,12 @@ public class TrainingV1Service implements ITrainingV1Service { training.setScenes(JsonUtils.writeValueAsString(trainingVO.getScenes())); list.add(training); //防止数据包溢出 - if(list.size()>5){ + if (list.size() > 5) { trainingDAO.batchInsert(list); list.clear(); } }); - if(list.size()>0){ + if (list.size() > 0) { trainingDAO.batchInsert(list); } } @@ -485,19 +488,20 @@ public class TrainingV1Service implements ITrainingV1Service { @Override public void deleteAutoGenerateTrainingBy(Long mapId) { - TrainingExample example = new TrainingExample(); - example.createCriteria().andMapIdEqualTo(mapId); - List ids = this.trainingDAO.selectIdsByExample(example); - this.batchDeleteTrainingAndReferenceData(ids); + TrainingExample example = new TrainingExample(); + example.createCriteria().andMapIdEqualTo(mapId); + List ids = this.trainingDAO.selectIdsByExample(example); + this.batchDeleteTrainingAndReferenceData(ids); } /** * 批量删除实训 + * * @param ids */ @Transactional public void batchDeleteTrainingAndReferenceData(List ids) { - if(!CollectionUtils.isEmpty(ids)) { + if (!CollectionUtils.isEmpty(ids)) { // 删除实训=章节关系 this.iLessonDraftService.deleteChapterRelByTrainingIdList(ids); this.iLessonService.deleteChapterRelByTrainingIdList(ids); @@ -519,17 +523,17 @@ public class TrainingV1Service implements ITrainingV1Service { Integer maxDuration = config.getMaxDuration(); String remarks = config.getRemarks(); TrainingWithBLOBs update = new TrainingWithBLOBs(); - if((Objects.nonNull(minDuration) - || Objects.nonNull(maxDuration) - || StringUtils.hasText(remarks)) + if ((Objects.nonNull(minDuration) + || Objects.nonNull(maxDuration) + || StringUtils.hasText(remarks)) && !CollectionUtils.isEmpty(config.getOperateType())) { - if(Objects.nonNull(minDuration)) { + if (Objects.nonNull(minDuration)) { update.setMinDuration(minDuration); } - if(Objects.nonNull(maxDuration)) { + if (Objects.nonNull(maxDuration)) { update.setMaxDuration(maxDuration); } - if(StringUtils.hasText(remarks)) { + if (StringUtils.hasText(remarks)) { update.setRemarks(remarks); } config.getOperateType().forEach(operateType -> { @@ -567,7 +571,7 @@ public class TrainingV1Service implements ITrainingV1Service { .andMapIdEqualTo(sourceMapId); List trainings = this.trainingDAO.selectByExampleWithBLOBs(example); Map relMap = new HashMap<>(); - if(!CollectionUtils.isEmpty(trainings)) { + if (!CollectionUtils.isEmpty(trainings)) { trainings.forEach(training -> { Long oldId = training.getId(); training.setId(null); @@ -582,6 +586,7 @@ public class TrainingV1Service implements ITrainingV1Service { /** * 删除实训-关联删除 + * * @param training */ @Transactional @@ -603,6 +608,7 @@ public class TrainingV1Service implements ITrainingV1Service { /** * 根据实训id删除用户实训记录 + * * @param trainingId */ private void deleteUserTrainingRecordByTrainingId(Long trainingId) { @@ -613,6 +619,7 @@ public class TrainingV1Service implements ITrainingV1Service { /** * 根据实训id列表删除用户实训记录 + * * @param trainingIdList */ private void deleteUserTrainingRecordByTrainingIds(List trainingIdList) { @@ -624,39 +631,39 @@ public class TrainingV1Service implements ITrainingV1Service { @Override public PageVO pagedQueryTrainings(TrainingQueryVO trainingQueryVO) { MapInfo mapInfo = null; - if (!ObjectUtils.isEmpty(trainingQueryVO.getMapId())){ + if (!ObjectUtils.isEmpty(trainingQueryVO.getMapId())) { mapInfo = mapInfoDAO.selectByPrimaryKey(trainingQueryVO.getMapId()); } PageHelper.startPage(trainingQueryVO.getPageNum(), trainingQueryVO.getPageSize()); TrainingExample example = new TrainingExample(); example.setOrderByClause("id desc"); TrainingExample.Criteria criteria = example.createCriteria(); - if(StringUtils.hasText(trainingQueryVO.getName())) { + if (StringUtils.hasText(trainingQueryVO.getName())) { criteria.andNameLike(String.format("%%%s%%", trainingQueryVO.getName())); } - if(StringUtils.hasText(trainingQueryVO.getGenerateType())) { - if(BusinessConsts.Training.GenerateType.GenerateType01.equals(trainingQueryVO.getGenerateType())) { + if (StringUtils.hasText(trainingQueryVO.getGenerateType())) { + if (BusinessConsts.Training.GenerateType.GenerateType01.equals(trainingQueryVO.getGenerateType())) { criteria.andAuthorIdEqualTo(UserVO.system().getId()); - }else if(BusinessConsts.Training.GenerateType.GenerateType02.equals(trainingQueryVO.getGenerateType())) { + } else if (BusinessConsts.Training.GenerateType.GenerateType02.equals(trainingQueryVO.getGenerateType())) { criteria.andAuthorIdNotEqualTo(UserVO.system().getId()); } } // if(StringUtils.hasText(trainingQueryVO.getSkinCode())) { // criteria.andSkinCodeEqualTo(trainingQueryVO.getSkinCode()); // } - if (!ObjectUtils.isEmpty(mapInfo)){ + if (!ObjectUtils.isEmpty(mapInfo)) { criteria.andMapIdEqualTo(mapInfo.getId()); } - if(StringUtils.hasText(trainingQueryVO.getPrdType())) { + if (StringUtils.hasText(trainingQueryVO.getPrdType())) { criteria.andPrdTypeEqualTo(trainingQueryVO.getPrdType()); } - if(StringUtils.hasText(trainingQueryVO.getType())) { + if (StringUtils.hasText(trainingQueryVO.getType())) { criteria.andTypeEqualTo(trainingQueryVO.getType()); } - if(StringUtils.hasText(trainingQueryVO.getOperateType())) { + if (StringUtils.hasText(trainingQueryVO.getOperateType())) { criteria.andOperateTypeEqualTo(trainingQueryVO.getOperateType()); } - if(StringUtils.hasText(trainingQueryVO.getStatus())) { + if (StringUtils.hasText(trainingQueryVO.getStatus())) { criteria.andStatusEqualTo(trainingQueryVO.getStatus()); } Page trainings = (Page) this.trainingDAO.selectByExample(example); @@ -690,9 +697,12 @@ public class TrainingV1Service implements ITrainingV1Service { } @Override - public List findEntities(@NonNull Long mapId, @NonNull String prdType) { + public List findEntities(@NonNull Long mapId, String prdType) { TrainingExample example = new TrainingExample(); - example.createCriteria().andMapIdEqualTo(mapId).andPrdTypeEqualTo(prdType); + TrainingExample.Criteria criteria = example.createCriteria().andMapIdEqualTo(mapId); + if (StringUtils.hasText(prdType)) { + criteria.andPrdTypeEqualTo(prdType); + } return trainingDAO.selectByExample(example); } @@ -702,4 +712,13 @@ public class TrainingV1Service implements ITrainingV1Service { example.createCriteria().andMapIdEqualTo(mapId); return trainingDAO.selectByExample(example); } + + @Override + public Map> queryTrainingTypeAndQuantity(Long mapId, String prdType) { + List trainings = findEntities(mapId, prdType); + return trainings.stream().collect( + Collectors.groupingBy(Training::getType, + Collectors.groupingBy(Training::getOperateType, + Collectors.counting()))); + } } diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/GroupSimulationServiceImpl.java b/src/main/java/club/joylink/rtss/simulation/cbtc/GroupSimulationServiceImpl.java index d9fd3a489..4b37a2003 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/GroupSimulationServiceImpl.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/GroupSimulationServiceImpl.java @@ -327,9 +327,8 @@ public class GroupSimulationServiceImpl implements GroupSimulationService { @Override public String examSimulation(Long examId, LoginUserInfoVO loginUserInfoVO) { ExamDefinitionVO examDefinitionVO = this.iExamService.queryExamInfo(examId); - LessonVO lessonVO = this.iLessonService.getLessonInfo(examDefinitionVO.getLessonId()); - Simulation simulation = this.create(loginUserInfoVO, lessonVO.getMapId(), - MapPrdTypeEnum.getMapPrdTypeEnumByCode(lessonVO.getPrdType()), + Simulation simulation = this.create(loginUserInfoVO, examDefinitionVO.getMapId(), + MapPrdTypeEnum.getMapPrdTypeEnumByCode(examDefinitionVO.getPrdType()), Simulation.FunctionalType.EXAM); return simulation.getGroup(); } diff --git a/src/main/java/club/joylink/rtss/vo/client/ExamDefinitionRulesVO.java b/src/main/java/club/joylink/rtss/vo/client/ExamDefinitionRulesVO.java index d345787ea..2c49499a8 100644 --- a/src/main/java/club/joylink/rtss/vo/client/ExamDefinitionRulesVO.java +++ b/src/main/java/club/joylink/rtss/vo/client/ExamDefinitionRulesVO.java @@ -27,13 +27,13 @@ public class ExamDefinitionRulesVO { /** * 题目数量 */ - @NotBlank(message = "题目数量不能为空") + @NotNull(message = "题目数量不能为空") private Integer num; /** * 每题分数 */ - @NotBlank(message = "每题分数不能为空") + @NotNull(message = "每题分数不能为空") private Integer point; /** diff --git a/src/main/java/club/joylink/rtss/vo/client/ExamDefinitionVO.java b/src/main/java/club/joylink/rtss/vo/client/ExamDefinitionVO.java index 3794c4d5e..9d0911a5c 100644 --- a/src/main/java/club/joylink/rtss/vo/client/ExamDefinitionVO.java +++ b/src/main/java/club/joylink/rtss/vo/client/ExamDefinitionVO.java @@ -5,7 +5,6 @@ import club.joylink.rtss.entity.SysUser; import club.joylink.rtss.vo.client.org.DepartmentVO; import club.joylink.rtss.vo.client.validGroup.ExamDefinitionCheck; import club.joylink.rtss.vo.client.validGroup.ExamDefinitionRulesCheck; -import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.databind.annotation.JsonSerialize; import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; @@ -13,15 +12,19 @@ import io.swagger.annotations.ApiModel; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; -import org.springframework.format.annotation.DateTimeFormat; +import org.springframework.util.CollectionUtils; import springfox.documentation.annotations.ApiIgnore; import javax.validation.Valid; import javax.validation.constraints.Min; import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotNull; +import javax.validation.groups.Default; import java.time.LocalDateTime; +import java.util.ArrayList; import java.util.List; +import java.util.Objects; +import java.util.stream.Collectors; @ApiModel(value = "考试定义") @NoArgsConstructor @@ -34,41 +37,39 @@ public class ExamDefinitionVO { /** * 所属课程ID */ - @NotNull(message = "课程ID不能为空", groups = {ExamDefinitionCheck.class}) private Long lessonId; private String lessonName; + @NotNull(message = "地图id不能为空") + private Long mapId; + /** * 考试名称 */ - @NotBlank(message = "考试名称不能为空", groups = {ExamDefinitionCheck.class}) + @NotBlank(message = "考试名称不能为空") private String name; /** * 考试类型:数据字典值 */ @NotBlank(message = "考试类型不能为空") - private String type; + private String prdType; /** * 考试时长:单位s */ - @Min(value = 1, groups = {ExamDefinitionCheck.class}) + @Min(value = 1) private Integer duration; /** * 考试开始时间 */ - @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") - @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") private LocalDateTime startTime; /** * 考试结束时间 */ - @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") - @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") private LocalDateTime endTime; /** @@ -79,13 +80,13 @@ public class ExamDefinitionVO { /** * 满分 */ - @Min(value = 1, groups = {ExamDefinitionRulesCheck.class}) + @Min(value = 1) private Integer fullPoint; /** * 及格分 */ - @Min(value = 0, groups = {ExamDefinitionCheck.class}) + @Min(value = 0) private Integer passingPoint; /** @@ -129,9 +130,17 @@ public class ExamDefinitionVO { private List clsIds; @Valid - @NotNull(message = "考试规则不能为空", groups = {ExamDefinitionCheck.class, ExamDefinitionRulesCheck.class}) + @NotNull(message = "考试规则不能为空") private List examDefinitionRulesVOList; + public static List convert(List exams) { + if (CollectionUtils.isEmpty(exams)) { + return new ArrayList<>(); + } else { + return exams.stream().map(ExamDefinitionVO::new).collect(Collectors.toList()); + } + } + @ApiIgnore public String getCreatorIdStr() { return String.valueOf(this.creatorId); @@ -140,8 +149,9 @@ public class ExamDefinitionVO { public ExamDefinitionVO(ExamDefinition examDefinition) { this.id = examDefinition.getId(); this.lessonId = examDefinition.getLessonId(); + this.mapId = examDefinition.getMapId(); this.name = examDefinition.getName(); - this.type = examDefinition.getType(); + this.prdType = examDefinition.getType(); this.duration = examDefinition.getDuration(); this.startTime = examDefinition.getStartTime(); this.endTime = examDefinition.getEndTime(); @@ -156,24 +166,25 @@ public class ExamDefinitionVO { public ExamDefinitionVO(ExamDefinition examDefinition, SysUser creator) { this(examDefinition); - this.creatorName = creator.getName(); - this.creatorNickname = creator.getNickname(); + if (creator != null) { + this.creatorName = creator.getName(); + this.creatorNickname = creator.getNickname(); + } } public ExamDefinition toDB() { ExamDefinition definition = new ExamDefinition(); definition.setLessonId(this.getLessonId()); + definition.setMapId(this.mapId); definition.setName(this.getName()); - definition.setType(this.getType()); + definition.setType(this.getPrdType()); definition.setDuration(this.getDuration()); definition.setStartTime(this.getStartTime()); definition.setEndTime(this.getEndTime()); definition.setFullPoint(this.getFullPoint()); definition.setPassingPoint(this.getPassingPoint()); - definition.setCreatorId(this.getCreatorId()); - definition.setCreateTime(this.getCreateTime()); definition.setRemarks(this.getRemarks()); - definition.setStatus(this.getStatus()); + definition.setTrial(Objects.requireNonNullElse(trial, false)); return definition; } diff --git a/src/main/java/club/joylink/rtss/vo/client/map/MapVO.java b/src/main/java/club/joylink/rtss/vo/client/map/MapVO.java index 6f6e834e9..4e37acdb7 100644 --- a/src/main/java/club/joylink/rtss/vo/client/map/MapVO.java +++ b/src/main/java/club/joylink/rtss/vo/client/map/MapVO.java @@ -18,6 +18,7 @@ import org.springframework.util.CollectionUtils; import org.springframework.util.StringUtils; import java.time.LocalDate; +import java.util.ArrayList; import java.util.Comparator; import java.util.List; import java.util.Objects; @@ -131,7 +132,7 @@ public class MapVO { if (!CollectionUtils.isEmpty(list)) { return list.stream().map(MapVO::new).collect(Collectors.toList()); } - return null; + return new ArrayList<>(); } diff --git a/src/main/java/club/joylink/rtss/vo/client/org/CompanyVO.java b/src/main/java/club/joylink/rtss/vo/client/org/CompanyVO.java index 88730d5ce..a62f58a8b 100644 --- a/src/main/java/club/joylink/rtss/vo/client/org/CompanyVO.java +++ b/src/main/java/club/joylink/rtss/vo/client/org/CompanyVO.java @@ -25,6 +25,8 @@ public class CompanyVO { private String projectCode; + private String code; + public CompanyVO(Org entity) { this.id = entity.getId(); this.name = entity.getName(); diff --git a/src/main/java/club/joylink/rtss/vo/client/org/DepartmentVO.java b/src/main/java/club/joylink/rtss/vo/client/org/DepartmentVO.java index 99a729444..9c553e022 100644 --- a/src/main/java/club/joylink/rtss/vo/client/org/DepartmentVO.java +++ b/src/main/java/club/joylink/rtss/vo/client/org/DepartmentVO.java @@ -74,9 +74,11 @@ public class DepartmentVO { public DepartmentVO(Org entity, Integer numberOfPeople, SysUser creator) { this(entity, numberOfPeople); - this.creatorId = creator.getId(); - this.creatorName = creator.getName(); - this.creatorNickName = creator.getNickname(); + if (creator != null) { + this.creatorId = creator.getId(); + this.creatorName = creator.getName(); + this.creatorNickName = creator.getNickname(); + } } public static List convert2VOList(List dataList) { diff --git a/src/main/java/club/joylink/rtss/vo/client/org/OrgScoringRuleVO.java b/src/main/java/club/joylink/rtss/vo/client/org/OrgScoringRuleVO.java index f37216616..26363e4c8 100644 --- a/src/main/java/club/joylink/rtss/vo/client/org/OrgScoringRuleVO.java +++ b/src/main/java/club/joylink/rtss/vo/client/org/OrgScoringRuleVO.java @@ -122,11 +122,10 @@ public class OrgScoringRuleVO { return rule; } - public OrgScoringRuleWithBLOBs cover4Update(OrgScoringRuleWithBLOBs entity) { + public void cover4Update(OrgScoringRuleWithBLOBs entity) { entity.setSchoolYear(schoolYear); entity.setTerm(term); entity.setFinalScoringRule(JsonUtils.writeValueAsString(scoringRules)); - return entity; } /** diff --git a/src/main/resources/mybatis/mapper/ExamDefinitionDAO.xml b/src/main/resources/mybatis/mapper/ExamDefinitionDAO.xml index f47e4b600..7ff1fba62 100644 --- a/src/main/resources/mybatis/mapper/ExamDefinitionDAO.xml +++ b/src/main/resources/mybatis/mapper/ExamDefinitionDAO.xml @@ -3,6 +3,7 @@ + @@ -15,7 +16,7 @@ - + @@ -76,8 +77,8 @@ - id, lesson_id, `name`, `type`, duration, start_time, end_time, full_point, passing_point, - creator_id, create_time, remarks, `status`, trial + id, map_id, lesson_id, `name`, `type`, duration, start_time, end_time, full_point, + passing_point, creator_id, create_time, remarks, `status`, trial @@ -99,7 +99,7 @@ + SELECT + * + FROM + org + JOIN org_exam ON org.id = org_exam.org_id + where org_exam.exam_id in + + #{examId} + + + and org.status = #{status} + + + diff --git a/src/main/resources/mybatis/mapper/OrgExamDAO.xml b/src/main/resources/mybatis/mapper/OrgExamDAO.xml index 5dd537aaf..e1c8b5520 100644 --- a/src/main/resources/mybatis/mapper/OrgExamDAO.xml +++ b/src/main/resources/mybatis/mapper/OrgExamDAO.xml @@ -2,8 +2,11 @@ + - + + + @@ -64,7 +67,7 @@ - exam_id, org_id + id, exam_id, org_id, creator_id, create_time + + + delete from org_exam + where id = #{id,jdbcType=BIGINT} + delete from org_exam - - insert into org_exam (exam_id, org_id) - values (#{examId,jdbcType=BIGINT}, #{orgId,jdbcType=INTEGER}) + + insert into org_exam (exam_id, org_id, creator_id, + create_time) + values (#{examId,jdbcType=BIGINT}, #{orgId,jdbcType=BIGINT}, #{creatorId,jdbcType=BIGINT}, + #{createTime,jdbcType=TIMESTAMP}) - + insert into org_exam @@ -107,13 +122,25 @@ org_id, + + creator_id, + + + create_time, + #{examId,jdbcType=BIGINT}, - #{orgId,jdbcType=INTEGER}, + #{orgId,jdbcType=BIGINT}, + + + #{creatorId,jdbcType=BIGINT}, + + + #{createTime,jdbcType=TIMESTAMP}, @@ -126,11 +153,20 @@ update org_exam + + id = #{record.id,jdbcType=BIGINT}, + exam_id = #{record.examId,jdbcType=BIGINT}, - org_id = #{record.orgId,jdbcType=INTEGER}, + org_id = #{record.orgId,jdbcType=BIGINT}, + + + creator_id = #{record.creatorId,jdbcType=BIGINT}, + + + create_time = #{record.createTime,jdbcType=TIMESTAMP}, @@ -139,10 +175,39 @@ update org_exam - set exam_id = #{record.examId,jdbcType=BIGINT}, - org_id = #{record.orgId,jdbcType=INTEGER} + set id = #{record.id,jdbcType=BIGINT}, + exam_id = #{record.examId,jdbcType=BIGINT}, + org_id = #{record.orgId,jdbcType=BIGINT}, + creator_id = #{record.creatorId,jdbcType=BIGINT}, + create_time = #{record.createTime,jdbcType=TIMESTAMP} + + update org_exam + + + exam_id = #{examId,jdbcType=BIGINT}, + + + org_id = #{orgId,jdbcType=BIGINT}, + + + creator_id = #{creatorId,jdbcType=BIGINT}, + + + create_time = #{createTime,jdbcType=TIMESTAMP}, + + + where id = #{id,jdbcType=BIGINT} + + + update org_exam + set exam_id = #{examId,jdbcType=BIGINT}, + org_id = #{orgId,jdbcType=BIGINT}, + creator_id = #{creatorId,jdbcType=BIGINT}, + create_time = #{createTime,jdbcType=TIMESTAMP} + where id = #{id,jdbcType=BIGINT} + \ No newline at end of file diff --git a/src/main/resources/mybatis/mapper/OrgLessonDAO.xml b/src/main/resources/mybatis/mapper/OrgLessonDAO.xml index 50e14225b..50327b815 100644 --- a/src/main/resources/mybatis/mapper/OrgLessonDAO.xml +++ b/src/main/resources/mybatis/mapper/OrgLessonDAO.xml @@ -2,6 +2,7 @@ + @@ -66,7 +67,7 @@ - lesson_id, org_id, creator_id, create_time + id, lesson_id, org_id, creator_id, create_time + + + delete from org_lesson + where id = #{id,jdbcType=BIGINT} + delete from org_lesson - + insert into org_lesson (lesson_id, org_id, creator_id, create_time) values (#{lessonId,jdbcType=BIGINT}, #{orgId,jdbcType=BIGINT}, #{creatorId,jdbcType=BIGINT}, #{createTime,jdbcType=TIMESTAMP}) - + insert into org_lesson @@ -142,6 +153,9 @@ update org_lesson + + id = #{record.id,jdbcType=BIGINT}, + lesson_id = #{record.lessonId,jdbcType=BIGINT}, @@ -161,7 +175,8 @@ update org_lesson - set lesson_id = #{record.lessonId,jdbcType=BIGINT}, + set id = #{record.id,jdbcType=BIGINT}, + lesson_id = #{record.lessonId,jdbcType=BIGINT}, org_id = #{record.orgId,jdbcType=BIGINT}, creator_id = #{record.creatorId,jdbcType=BIGINT}, create_time = #{record.createTime,jdbcType=TIMESTAMP} @@ -169,4 +184,30 @@ + + update org_lesson + + + lesson_id = #{lessonId,jdbcType=BIGINT}, + + + org_id = #{orgId,jdbcType=BIGINT}, + + + creator_id = #{creatorId,jdbcType=BIGINT}, + + + create_time = #{createTime,jdbcType=TIMESTAMP}, + + + where id = #{id,jdbcType=BIGINT} + + + update org_lesson + set lesson_id = #{lessonId,jdbcType=BIGINT}, + org_id = #{orgId,jdbcType=BIGINT}, + creator_id = #{creatorId,jdbcType=BIGINT}, + create_time = #{createTime,jdbcType=TIMESTAMP} + where id = #{id,jdbcType=BIGINT} + \ No newline at end of file diff --git a/src/main/resources/mybatis/mapper/OrgScoringRuleRelDAO.xml b/src/main/resources/mybatis/mapper/OrgScoringRuleRelDAO.xml index 06c447a47..c7376e0f5 100644 --- a/src/main/resources/mybatis/mapper/OrgScoringRuleRelDAO.xml +++ b/src/main/resources/mybatis/mapper/OrgScoringRuleRelDAO.xml @@ -195,10 +195,10 @@ - insert into org_scoring_rule_rel (org_id, rule_id) + insert into org_scoring_rule_rel (org_id, rule_id, rule_org_id, rule_school_year, rule_term, rule_creator_id) values - (#{rel.orgId}, #{rel.ruleId}) + (#{rel.orgId}, #{rel.ruleId}, #{rel.ruleOrgId}, #{rel.ruleSchoolYear}, #{rel.ruleTerm}, #{rel.ruleCreatorId})