From a440b1c265dab57d212e22fcdb1cb07ffb34d51e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A7=9C=E7=8E=89=E7=90=A6?= <7507756+jiang_yuqi@user.noreply.gitee.com> Date: Fri, 4 Oct 2024 14:40:48 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../yanzhu/common/core/enums/CraftType.java | 31 ++ .../common/core/enums/UseStateEnums.java | 32 ++ .../com/yanzhu/manage/domain/BusExamUser.java | 25 +- .../manage/domain/BusExamUserResult.java | 103 +++-- .../manage/mapper/BusExamInfoMapper.java | 8 + .../manage/mapper/BusExamUserMapper.java | 27 ++ .../mapper/manage/BusExamInfoMapper.xml | 5 + .../mapper/manage/BusExamQuestionMapper.xml | 1 + .../mapper/manage/BusExamUserMapper.xml | 58 ++- .../controller/BusExamUserController.java | 15 +- .../BusExamUserResultController.java | 98 ----- .../manage/service/IBusExamUserService.java | 3 +- .../service/impl/BusExamUserServiceImpl.java | 215 +++++++++- .../src/views/manage/busExamInfo/index.vue | 22 +- .../views/manage/busExamQuestion/index.vue | 157 +++++--- .../src/views/manage/busExamUser/index.vue | 369 +++++++++++++----- .../views/manage/busExamUserResult/index.vue | 295 -------------- 17 files changed, 854 insertions(+), 610 deletions(-) create mode 100644 yanzhu-common/yanzhu-common-core/src/main/java/com/yanzhu/common/core/enums/CraftType.java create mode 100644 yanzhu-common/yanzhu-common-core/src/main/java/com/yanzhu/common/core/enums/UseStateEnums.java delete mode 100644 yanzhu-modules/yanzhu-manage/src/main/java/com/yanzhu/manage/controller/BusExamUserResultController.java delete mode 100644 yanzhu-ui-vue3/src/views/manage/busExamUserResult/index.vue diff --git a/yanzhu-common/yanzhu-common-core/src/main/java/com/yanzhu/common/core/enums/CraftType.java b/yanzhu-common/yanzhu-common-core/src/main/java/com/yanzhu/common/core/enums/CraftType.java new file mode 100644 index 00000000..3d9622ef --- /dev/null +++ b/yanzhu-common/yanzhu-common-core/src/main/java/com/yanzhu/common/core/enums/CraftType.java @@ -0,0 +1,31 @@ +package com.yanzhu.common.core.enums; + +/** + * 工种类型 + */ +public enum CraftType { + + PTGZ("1", "普通工种"), + TSGZ("2", "特殊工种"), + GLRY("3", "管理人员"); + + private final String code; + private final String info; + + CraftType(String code, String info) + { + this.code = code; + this.info = info; + } + + public String getCode() + { + return code; + } + + public String getInfo() + { + return info; + } + +} diff --git a/yanzhu-common/yanzhu-common-core/src/main/java/com/yanzhu/common/core/enums/UseStateEnums.java b/yanzhu-common/yanzhu-common-core/src/main/java/com/yanzhu/common/core/enums/UseStateEnums.java new file mode 100644 index 00000000..1ce256ee --- /dev/null +++ b/yanzhu-common/yanzhu-common-core/src/main/java/com/yanzhu/common/core/enums/UseStateEnums.java @@ -0,0 +1,32 @@ +package com.yanzhu.common.core.enums; + +/** + * 进场状态 + * + * @author ruoyi + */ +public enum UseStateEnums { + + IN("1", "进场"), + OUT("2", "离场"); + + private final String code; + private final String info; + + UseStateEnums(String code, String info) + { + this.code = code; + this.info = info; + } + + public String getCode() + { + return code; + } + + public String getInfo() + { + return info; + } + +} diff --git a/yanzhu-common/yanzhu-common-mapper/src/main/java/com/yanzhu/manage/domain/BusExamUser.java b/yanzhu-common/yanzhu-common-mapper/src/main/java/com/yanzhu/manage/domain/BusExamUser.java index ae9fb79e..42b6d9c2 100644 --- a/yanzhu-common/yanzhu-common-mapper/src/main/java/com/yanzhu/manage/domain/BusExamUser.java +++ b/yanzhu-common/yanzhu-common-mapper/src/main/java/com/yanzhu/manage/domain/BusExamUser.java @@ -5,6 +5,8 @@ import com.yanzhu.common.core.web.domain.BaseEntity; import org.apache.commons.lang3.builder.ToStringBuilder; import org.apache.commons.lang3.builder.ToStringStyle; +import java.util.List; + /** * 用户试卷对象 bus_exam_user * @@ -39,11 +41,11 @@ public class BusExamUser extends BaseEntity /** 用户名称 */ @Excel(name = "用户名称") - private Long userNick; + private String userNick; /** 用户账号 */ @Excel(name = "用户账号") - private Long userName; + private String userName; /** 试卷名称 */ @Excel(name = "试卷名称") @@ -89,6 +91,9 @@ public class BusExamUser extends BaseEntity @Excel(name = "删除标识") private Long isDel; + /** 用户试卷结果信息 */ + private List busExamUserResultList; + public void setId(Long id) { this.id = id; @@ -143,19 +148,19 @@ public class BusExamUser extends BaseEntity return userId; } - public Long getUserNick() { + public String getUserNick() { return userNick; } - public void setUserNick(Long userNick) { + public void setUserNick(String userNick) { this.userNick = userNick; } - public Long getUserName() { + public String getUserName() { return userName; } - public void setUserName(Long userName) { + public void setUserName(String userName) { this.userName = userName; } @@ -259,6 +264,14 @@ public class BusExamUser extends BaseEntity return isDel; } + public List getBusExamUserResultList() { + return busExamUserResultList; + } + + public void setBusExamUserResultList(List busExamUserResultList) { + this.busExamUserResultList = busExamUserResultList; + } + @Override public String toString() { return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) diff --git a/yanzhu-common/yanzhu-common-mapper/src/main/java/com/yanzhu/manage/domain/BusExamUserResult.java b/yanzhu-common/yanzhu-common-mapper/src/main/java/com/yanzhu/manage/domain/BusExamUserResult.java index 7ee2ccf6..a2fd8c53 100644 --- a/yanzhu-common/yanzhu-common-mapper/src/main/java/com/yanzhu/manage/domain/BusExamUserResult.java +++ b/yanzhu-common/yanzhu-common-mapper/src/main/java/com/yanzhu/manage/domain/BusExamUserResult.java @@ -9,27 +9,41 @@ import org.apache.commons.lang3.builder.ToStringStyle; * 用户试卷结果对象 bus_exam_user_result * * @author JiangYuQi - * @date 2024-08-25 + * @date 2024-10-03 */ public class BusExamUserResult extends BaseEntity { private static final long serialVersionUID = 1L; + /** 主键 */ + private Long id; + /** 用户试卷主键 */ @Excel(name = "用户试卷主键") private Long examUserId; /** 问题主键 */ - @Excel(name = "问题主键") private Long questionId; + /** 问题描述 */ + @Excel(name = "问题描述") + private String questionTitle; + + /** 问题类型 */ + @Excel(name = "问题类型") + private Long questionType; + + /** 问题选项 */ + @Excel(name = "问题选项") + private String questionOption; + /** 用户答案 */ @Excel(name = "用户答案") - private String answers; + private String userAnswer; - /** 排序 */ - @Excel(name = "排序") - private Long sortBy; + /** 问题答案 */ + @Excel(name = "问题答案") + private String answer; /** 答题结果 */ @Excel(name = "答题结果") @@ -39,6 +53,15 @@ public class BusExamUserResult extends BaseEntity @Excel(name = "答题得分") private String useMark; + public void setId(Long id) + { + this.id = id; + } + + public Long getId() + { + return id; + } public void setExamUserId(Long examUserId) { this.examUserId = examUserId; @@ -48,32 +71,58 @@ public class BusExamUserResult extends BaseEntity { return examUserId; } - public void setQuestionId(Long questionId) + public void setQuestionTitle(String questionTitle) { + this.questionTitle = questionTitle; + } + + public String getQuestionTitle() + { + return questionTitle; + } + + public Long getQuestionId() { + return questionId; + } + + public void setQuestionId(Long questionId) { this.questionId = questionId; } - public Long getQuestionId() - { - return questionId; - } - public void setAnswers(String answers) - { - this.answers = answers; + public Long getQuestionType() { + return questionType; } - public String getAnswers() - { - return answers; - } - public void setSortBy(Long sortBy) - { - this.sortBy = sortBy; + public void setQuestionType(Long questionType) { + this.questionType = questionType; } - public Long getSortBy() + public void setQuestionOption(String questionOption) { - return sortBy; + this.questionOption = questionOption; + } + + public String getQuestionOption() + { + return questionOption; + } + public void setUserAnswer(String userAnswer) + { + this.userAnswer = userAnswer; + } + + public String getUserAnswer() + { + return userAnswer; + } + public void setAnswer(String answer) + { + this.answer = answer; + } + + public String getAnswer() + { + return answer; } public void setUseRes(String useRes) { @@ -97,10 +146,12 @@ public class BusExamUserResult extends BaseEntity @Override public String toString() { return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) + .append("id", getId()) .append("examUserId", getExamUserId()) - .append("questionId", getQuestionId()) - .append("answers", getAnswers()) - .append("sortBy", getSortBy()) + .append("questionTitle", getQuestionTitle()) + .append("questionOption", getQuestionOption()) + .append("userAnswer", getUserAnswer()) + .append("answer", getAnswer()) .append("useRes", getUseRes()) .append("useMark", getUseMark()) .toString(); diff --git a/yanzhu-common/yanzhu-common-mapper/src/main/java/com/yanzhu/manage/mapper/BusExamInfoMapper.java b/yanzhu-common/yanzhu-common-mapper/src/main/java/com/yanzhu/manage/mapper/BusExamInfoMapper.java index b99085dc..c697d567 100644 --- a/yanzhu-common/yanzhu-common-mapper/src/main/java/com/yanzhu/manage/mapper/BusExamInfoMapper.java +++ b/yanzhu-common/yanzhu-common-mapper/src/main/java/com/yanzhu/manage/mapper/BusExamInfoMapper.java @@ -44,6 +44,14 @@ public interface BusExamInfoMapper */ public int updateBusExamInfo(BusExamInfo busExamInfo); + /** + * 修改基础试卷使用次数 + * + * @param id 基础试卷主键 + * @return 结果 + */ + public void updateExamUseNumber(Long id); + /** * 删除基础试卷 * diff --git a/yanzhu-common/yanzhu-common-mapper/src/main/java/com/yanzhu/manage/mapper/BusExamUserMapper.java b/yanzhu-common/yanzhu-common-mapper/src/main/java/com/yanzhu/manage/mapper/BusExamUserMapper.java index 961301e7..3ef481e2 100644 --- a/yanzhu-common/yanzhu-common-mapper/src/main/java/com/yanzhu/manage/mapper/BusExamUserMapper.java +++ b/yanzhu-common/yanzhu-common-mapper/src/main/java/com/yanzhu/manage/mapper/BusExamUserMapper.java @@ -2,6 +2,7 @@ package com.yanzhu.manage.mapper; import java.util.List; import com.yanzhu.manage.domain.BusExamUser; +import com.yanzhu.manage.domain.BusExamUserResult; /** * 用户试卷Mapper接口 @@ -58,4 +59,30 @@ public interface BusExamUserMapper * @return 结果 */ public int deleteBusExamUserByIds(Long[] ids); + + + /** + * 批量删除用户试卷结果 + * + * @param ids 需要删除的数据主键集合 + * @return 结果 + */ + public int deleteBusExamUserResultByExamUserIds(Long[] ids); + + /** + * 批量新增用户试卷结果 + * + * @param busExamUserResultList 用户试卷结果列表 + * @return 结果 + */ + public int batchBusExamUserResult(List busExamUserResultList); + + + /** + * 通过用户试卷主键删除用户试卷结果信息 + * + * @param id 用户试卷ID + * @return 结果 + */ + public int deleteBusExamUserResultByExamUserId(Long id); } diff --git a/yanzhu-common/yanzhu-common-mapper/src/main/resources/mapper/manage/BusExamInfoMapper.xml b/yanzhu-common/yanzhu-common-mapper/src/main/resources/mapper/manage/BusExamInfoMapper.xml index da461750..c7636579 100644 --- a/yanzhu-common/yanzhu-common-mapper/src/main/resources/mapper/manage/BusExamInfoMapper.xml +++ b/yanzhu-common/yanzhu-common-mapper/src/main/resources/mapper/manage/BusExamInfoMapper.xml @@ -60,6 +60,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" and bei.exam_type = #{examType} and bei.craft_type = #{craftType} and bei.craft_post = #{craftPost} + and bei.is_del = #{isDel} order by bei.id desc @@ -152,6 +153,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" where id = #{id} + + update bus_exam_info set use_number = use_number+1 where id = #{id} + + delete from bus_exam_info where id = #{id} diff --git a/yanzhu-common/yanzhu-common-mapper/src/main/resources/mapper/manage/BusExamQuestionMapper.xml b/yanzhu-common/yanzhu-common-mapper/src/main/resources/mapper/manage/BusExamQuestionMapper.xml index 698c0644..fba11ba3 100644 --- a/yanzhu-common/yanzhu-common-mapper/src/main/resources/mapper/manage/BusExamQuestionMapper.xml +++ b/yanzhu-common/yanzhu-common-mapper/src/main/resources/mapper/manage/BusExamQuestionMapper.xml @@ -62,6 +62,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" and beq.question_type = #{questionType} and beq.question_scope = #{questionScope} and beq.question_desc = #{questionDesc} + and beq.is_del = #{isDel} order by beq.id desc diff --git a/yanzhu-common/yanzhu-common-mapper/src/main/resources/mapper/manage/BusExamUserMapper.xml b/yanzhu-common/yanzhu-common-mapper/src/main/resources/mapper/manage/BusExamUserMapper.xml index b5ee9814..b5f3ce50 100644 --- a/yanzhu-common/yanzhu-common-mapper/src/main/resources/mapper/manage/BusExamUserMapper.xml +++ b/yanzhu-common/yanzhu-common-mapper/src/main/resources/mapper/manage/BusExamUserMapper.xml @@ -31,8 +31,25 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + + + + + + + + + + + + + + + + + - select beu.id, beu.com_id, sd.dept_name as com_name, beu.project_id, pi.project_name, beu.user_id, su.user_nick, su.user_name, beu.exam_title, beu.exam_type, beu.craft_type, beu.craft_post, beu.single_num, beu.multiple_num, beu.estimate_num, beu.user_mark, beu.res_status, beu.use_times, beu.is_del, beu.create_by, beu.create_time, beu.update_by, beu.update_time, beu.remark from bus_exam_user beu + select beu.id, beu.com_id, sd.dept_name as com_name, beu.project_id, pi.project_name, beu.user_id, su.nick_name as user_nick, su.user_name, beu.exam_title, beu.exam_type, beu.craft_type, beu.craft_post, beu.single_num, beu.multiple_num, beu.estimate_num, beu.user_mark, beu.res_status, beu.use_times, beu.is_del, beu.create_by, beu.create_time, beu.update_by, beu.update_time, beu.remark from bus_exam_user beu left join pro_project_info pi on pi.id = beu.project_id left join sys_dept sd on sd.dept_id = pi.com_id left join sys_user su on su.user_id = beu.user_id @@ -41,7 +58,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - + select a.id, a.com_id, sd.dept_name as com_name, a.project_id, pi.project_name, a.user_id, su.nick_name as user_nick, su.user_name, a.exam_title, a.exam_type, a.craft_type, a.craft_post, a.single_num, a.multiple_num, a.estimate_num, a.user_mark, a.res_status, a.use_times, a.is_del, a.create_by, a.create_time, a.update_by, a.update_time, a.remark, + b.id as sub_id, b.exam_user_id as sub_exam_user_id, b.question_id as sub_question_id, b.question_title as sub_question_title, b.question_type as sub_question_type, b.question_option as sub_question_option, b.user_answer as sub_user_answer, b.answer as sub_answer, b.use_res as sub_use_res, b.use_mark as sub_use_mark + from bus_exam_user a + left join pro_project_info pi on pi.id = a.project_id + left join sys_dept sd on sd.dept_id = a.com_id + left join sys_user su on su.user_id = a.user_id + left join bus_exam_user_result b on b.exam_user_id = a.id + where a.id = #{id} insert into bus_exam_user - dept_id, + com_id, project_id, user_id, exam_title, @@ -87,7 +110,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" remark, - #{deptId}, + #{comId}, #{projectId}, #{userId}, #{examTitle}, @@ -112,7 +135,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" update bus_exam_user - dept_id = #{deptId}, + com_id = #{comId}, project_id = #{projectId}, user_id = #{userId}, exam_title = #{examTitle}, @@ -145,4 +168,23 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" #{id} + + + delete from bus_exam_user_result where exam_user_id in + + #{examUserId} + + + + + delete from bus_exam_user_result where exam_user_id = #{examUserId} + + + + insert into bus_exam_user_result( id, exam_user_id, question_id, question_title, question_type, question_option, user_answer, answer, use_res, use_mark) values + + ( #{item.id}, #{item.examUserId}, #{item.questionId}, #{item.questionTitle}, #{item.questionType}, #{item.questionOption}, #{item.userAnswer}, #{item.answer}, #{item.useRes}, #{item.useMark}) + + + \ No newline at end of file diff --git a/yanzhu-modules/yanzhu-manage/src/main/java/com/yanzhu/manage/controller/BusExamUserController.java b/yanzhu-modules/yanzhu-manage/src/main/java/com/yanzhu/manage/controller/BusExamUserController.java index 47082f77..d39196fd 100644 --- a/yanzhu-modules/yanzhu-manage/src/main/java/com/yanzhu/manage/controller/BusExamUserController.java +++ b/yanzhu-modules/yanzhu-manage/src/main/java/com/yanzhu/manage/controller/BusExamUserController.java @@ -63,17 +63,6 @@ public class BusExamUserController extends BaseController return success(busExamUserService.selectBusExamUserById(id)); } - /** - * 新增用户试卷 - */ - @RequiresPermissions("manage:busExamUser:add") - @Log(title = "用户试卷", businessType = BusinessType.INSERT) - @PostMapping - public AjaxResult add(@RequestBody BusExamUser busExamUser) - { - return success(busExamUserService.insertBusExamUser(busExamUser)); - } - /** * 修改用户试卷 */ @@ -102,8 +91,8 @@ public class BusExamUserController extends BaseController */ @Log(title = "新增试卷考题", businessType = BusinessType.INSERT) @PostMapping("/push") - public AjaxResult pushBusExamUser(@RequestBody BusExamUser busExamUser) + public AjaxResult pushBusExamUser() { - return success(busExamUserService.insertBusExamUser(busExamUser)); + return success(busExamUserService.insertBusExamUser()); } } diff --git a/yanzhu-modules/yanzhu-manage/src/main/java/com/yanzhu/manage/controller/BusExamUserResultController.java b/yanzhu-modules/yanzhu-manage/src/main/java/com/yanzhu/manage/controller/BusExamUserResultController.java deleted file mode 100644 index 0c9d51ae..00000000 --- a/yanzhu-modules/yanzhu-manage/src/main/java/com/yanzhu/manage/controller/BusExamUserResultController.java +++ /dev/null @@ -1,98 +0,0 @@ -package com.yanzhu.manage.controller; - -import com.yanzhu.common.core.utils.poi.ExcelUtil; -import com.yanzhu.common.core.web.controller.BaseController; -import com.yanzhu.common.core.web.domain.AjaxResult; -import com.yanzhu.common.core.web.page.TableDataInfo; -import com.yanzhu.common.log.annotation.Log; -import com.yanzhu.common.log.enums.BusinessType; -import com.yanzhu.common.security.annotation.RequiresPermissions; -import com.yanzhu.manage.domain.BusExamUserResult; -import com.yanzhu.manage.service.IBusExamUserResultService; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.*; - -import javax.servlet.http.HttpServletResponse; -import java.util.List; - -/** - * 用户试卷结果Controller - * - * @author JiangYuQi - * @date 2024-08-25 - */ -@RestController -@RequestMapping("/busExamUserResult") -public class BusExamUserResultController extends BaseController -{ - @Autowired - private IBusExamUserResultService busExamUserResultService; - - /** - * 查询用户试卷结果列表 - */ - @RequiresPermissions("manage:busExamUserResult:list") - @GetMapping("/list") - public TableDataInfo list(BusExamUserResult busExamUserResult) - { - startPage(); - List list = busExamUserResultService.selectBusExamUserResultList(busExamUserResult); - return getDataTable(list); - } - - /** - * 导出用户试卷结果列表 - */ - @RequiresPermissions("manage:busExamUserResult:export") - @Log(title = "用户试卷结果", businessType = BusinessType.EXPORT) - @PostMapping("/export") - public void export(HttpServletResponse response, BusExamUserResult busExamUserResult) - { - List list = busExamUserResultService.selectBusExamUserResultList(busExamUserResult); - ExcelUtil util = new ExcelUtil(BusExamUserResult.class); - util.exportExcel(response, list, "用户试卷结果数据"); - } - - /** - * 获取用户试卷结果详细信息 - */ - @RequiresPermissions("manage:busExamUserResult:query") - @GetMapping(value = "/{examUserId}") - public AjaxResult getInfo(@PathVariable("examUserId") Long examUserId) - { - return success(busExamUserResultService.selectBusExamUserResultByExamUserId(examUserId)); - } - - /** - * 新增用户试卷结果 - */ - @RequiresPermissions("manage:busExamUserResult:add") - @Log(title = "用户试卷结果", businessType = BusinessType.INSERT) - @PostMapping - public AjaxResult add(@RequestBody BusExamUserResult busExamUserResult) - { - return toAjax(busExamUserResultService.insertBusExamUserResult(busExamUserResult)); - } - - /** - * 修改用户试卷结果 - */ - @RequiresPermissions("manage:busExamUserResult:edit") - @Log(title = "用户试卷结果", businessType = BusinessType.UPDATE) - @PutMapping - public AjaxResult edit(@RequestBody BusExamUserResult busExamUserResult) - { - return toAjax(busExamUserResultService.updateBusExamUserResult(busExamUserResult)); - } - - /** - * 删除用户试卷结果 - */ - @RequiresPermissions("manage:busExamUserResult:remove") - @Log(title = "用户试卷结果", businessType = BusinessType.DELETE) - @DeleteMapping("/{examUserIds}") - public AjaxResult remove(@PathVariable Long[] examUserIds) - { - return toAjax(busExamUserResultService.deleteBusExamUserResultByExamUserIds(examUserIds)); - } -} diff --git a/yanzhu-modules/yanzhu-manage/src/main/java/com/yanzhu/manage/service/IBusExamUserService.java b/yanzhu-modules/yanzhu-manage/src/main/java/com/yanzhu/manage/service/IBusExamUserService.java index 9a08b6e8..33b2ef89 100644 --- a/yanzhu-modules/yanzhu-manage/src/main/java/com/yanzhu/manage/service/IBusExamUserService.java +++ b/yanzhu-modules/yanzhu-manage/src/main/java/com/yanzhu/manage/service/IBusExamUserService.java @@ -30,10 +30,9 @@ public interface IBusExamUserService /** * 新增用户试卷 * - * @param busExamUser 用户试卷 * @return 结果 */ - public BusExamUser insertBusExamUser(BusExamUser busExamUser); + public BusExamUser insertBusExamUser(); /** * 修改用户试卷 diff --git a/yanzhu-modules/yanzhu-manage/src/main/java/com/yanzhu/manage/service/impl/BusExamUserServiceImpl.java b/yanzhu-modules/yanzhu-manage/src/main/java/com/yanzhu/manage/service/impl/BusExamUserServiceImpl.java index 381bf6d2..f22edeea 100644 --- a/yanzhu-modules/yanzhu-manage/src/main/java/com/yanzhu/manage/service/impl/BusExamUserServiceImpl.java +++ b/yanzhu-modules/yanzhu-manage/src/main/java/com/yanzhu/manage/service/impl/BusExamUserServiceImpl.java @@ -1,14 +1,24 @@ package com.yanzhu.manage.service.impl; -import java.util.List; +import java.util.*; +import java.util.stream.Collectors; + +import com.alibaba.fastjson2.JSON; +import com.yanzhu.common.core.enums.CraftType; +import com.yanzhu.common.core.enums.IsDelEnums; +import com.yanzhu.common.core.enums.UseStateEnums; +import com.yanzhu.common.core.exception.ServiceException; +import com.yanzhu.common.core.text.Convert; import com.yanzhu.common.core.utils.DateUtils; +import com.yanzhu.common.core.utils.StringUtils; import com.yanzhu.common.security.utils.SecurityUtils; +import com.yanzhu.manage.domain.*; +import com.yanzhu.manage.mapper.*; import com.yanzhu.system.api.domain.SysUser; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; -import com.yanzhu.manage.mapper.BusExamUserMapper; -import com.yanzhu.manage.domain.BusExamUser; import com.yanzhu.manage.service.IBusExamUserService; +import org.springframework.transaction.annotation.Transactional; /** * 用户试卷Service业务层处理 @@ -19,9 +29,18 @@ import com.yanzhu.manage.service.IBusExamUserService; @Service public class BusExamUserServiceImpl implements IBusExamUserService { + @Autowired + private BusExamInfoMapper busExamInfoMapper; + @Autowired private BusExamUserMapper busExamUserMapper; + @Autowired + private BusExamQuestionMapper busExamQuestionMapper; + + @Autowired + private ProProjectInfoSubdeptsUsersMapper proProjectInfoSubdeptsUsersMapper; + /** * 查询用户试卷 * @@ -43,22 +62,176 @@ public class BusExamUserServiceImpl implements IBusExamUserService @Override public List selectBusExamUserList(BusExamUser busExamUser) { + busExamUser.setActiveComId(SecurityUtils.getLoginUser().getProjectDeptId()); + busExamUser.setActiveProjectId(SecurityUtils.getLoginUser().getProjectId()); return busExamUserMapper.selectBusExamUserList(busExamUser); } /** * 新增用户试卷 - * - * @param busExamUser 用户试卷 + * * @return 结果 */ @Override - public BusExamUser insertBusExamUser(BusExamUser busExamUser) + @Transactional + public BusExamUser insertBusExamUser() { + BusExamUser busExamUser = new BusExamUser(); SysUser cache = SecurityUtils.getLoginUser().getSysUser(); - - busExamUser.setCreateTime(DateUtils.getNowDate()); - return busExamUserMapper.insertBusExamUser(busExamUser); + // 查询用户详细 + ProProjectInfoSubdeptsUsers userQuery = new ProProjectInfoSubdeptsUsers(); + userQuery.setUserId(cache.getUserId()); + userQuery.setComId(cache.getActiveComId()); + userQuery.setProjectId(cache.getActiveProjectId()); + userQuery.setUseStatus(UseStateEnums.IN.getCode()); + userQuery.setIsDel(IsDelEnums.NO.getCode()); + List userList = proProjectInfoSubdeptsUsersMapper.selectProProjectInfoSubdeptsUsersList(userQuery); + + if(StringUtils.isEmpty(userList)){ + throw new ServiceException("用户信息异常...不能抽取试题..."); + } + ProProjectInfoSubdeptsUsers userEntity = userList.get(0); + + // 查询试卷列表 + BusExamInfo query = new BusExamInfo(); + query.setComId(cache.getActiveComId()); + query.setProjectId(cache.getActiveProjectId()); + query.setCraftType(userEntity.getCraftType()); + // 管理人员获取所有管理类试卷 + if(!Objects.equals(CraftType.GLRY.getCode(),query.getCraftType())){ + query.setCraftPost(userEntity.getCraftPost()); + } + query.setIsDel(IsDelEnums.NO.getCode()); + List examInfoList = busExamInfoMapper.selectBusExamInfoList(query); + if(StringUtils.isNotEmpty(examInfoList)){ + // 优先从项目试卷中获取试卷、未找到项目试卷则从所有试卷中筛选 + List _projectExamInfolist = examInfoList.stream().filter(examInfo -> examInfo.getProjectId() != null) + .collect(Collectors.toList()); + Random random = new Random(); + BusExamInfo findExamInfo; + if(StringUtils.isNotEmpty(_projectExamInfolist)){ + int randomIntBound = random.nextInt(_projectExamInfolist.size()); + findExamInfo = _projectExamInfolist.get(randomIntBound); + }else{ + int randomIntBound = random.nextInt(examInfoList.size()); + findExamInfo = examInfoList.get(randomIntBound); + } + + // 获取试卷试题 + List questions = extractExamQuestion(findExamInfo,userEntity.getCraftPost()); + // 试题重新排序 + Collections.shuffle(questions); + + busExamUser.setComId(userEntity.getComId()); + busExamUser.setProjectId(userEntity.getProjectId()); + busExamUser.setUserId(cache.getUserId()); + busExamUser.setExamTitle(findExamInfo.getExamTitle()); + busExamUser.setExamType(findExamInfo.getExamType()); + busExamUser.setCraftType(userEntity.getCraftType()); + busExamUser.setCraftPost(userEntity.getCraftPost()); + busExamUser.setSingleNum(findExamInfo.getSingleNum()); + busExamUser.setMultipleNum(findExamInfo.getMultipleNum()); + busExamUser.setEstimateNum(findExamInfo.getEstimateNum()); + busExamUser.setCreateBy(cache.getUserName()); + busExamUser.setCreateTime(DateUtils.getNowDate()); + busExamUserMapper.insertBusExamUser(busExamUser); + + List busExamUserResultList = new ArrayList<>(); + for(BusExamQuestion examQuestion:questions){ + BusExamQuestion question = busExamQuestionMapper.selectBusExamQuestionById(examQuestion.getId()); + BusExamUserResult entity = new BusExamUserResult(); + entity.setExamUserId(busExamUser.getId()); + entity.setQuestionId(examQuestion.getId()); + entity.setQuestionTitle(examQuestion.getQuestionDesc()); + entity.setQuestionType(examQuestion.getQuestionType()); + entity.setQuestionOption(JSON.toJSONString(question.getBusExamQuestionResultList())); + entity.setAnswer(question.getQuestionAnswer()); + busExamUserResultList.add(entity); + } + busExamUser.setBusExamUserResultList(busExamUserResultList); + busExamUserMapper.batchBusExamUserResult(busExamUserResultList); + + // 修改试卷使用次数 + busExamInfoMapper.updateExamUseNumber(findExamInfo.getId()); + }else{ + throw new ServiceException("当前项目未配置试卷信息,请联系管理员配置..."); + } + return busExamUser; + } + + /** + * 根据试卷抽取考题 + * @param findExamInfo 试卷 + * @param craftPost 试题范围 + * @return + */ + private List extractExamQuestion(BusExamInfo findExamInfo,String craftPost){ + BusExamQuestion questionQuery = new BusExamQuestion(); + questionQuery.setActiveComId(findExamInfo.getComId()); + questionQuery.setActiveProjectId(findExamInfo.getProjectId()); + questionQuery.setCraftPost(craftPost); + questionQuery.setIsDel(IsDelEnums.NO.getCode()); + List list = new ArrayList<>(); + List allQuestionList = busExamQuestionMapper.selectBusExamQuestionList(questionQuery); + if(StringUtils.isNotEmpty(allQuestionList)){ + /** + * 根据试卷配置进行抽题 + * oxtQuestionList 单选题列表 + * dxtQuestionList 多选题列表 + * pdtQuestionList 判断题列表 + */ + List oxtQuestionList = allQuestionList.stream().filter(question -> question.getQuestionType() == 1L).collect(Collectors.toList()); + List dxtQuestionList = allQuestionList.stream().filter(question -> question.getQuestionType() == 2L).collect(Collectors.toList()); + List pdtQuestionList = allQuestionList.stream().filter(question -> question.getQuestionType() == 3L).collect(Collectors.toList()); + int singleNum = Convert.toInt(findExamInfo.getSingleNum(),0); + if(singleNum>0){ + if(Objects.nonNull(oxtQuestionList) && oxtQuestionList.size()>singleNum){ + list.addAll(getRandomQuestions(oxtQuestionList,singleNum)); + }else{ + if(Objects.nonNull(oxtQuestionList)){ + list.addAll(oxtQuestionList); + } + } + } + int multipleNum = Convert.toInt(findExamInfo.getMultipleNum(),0); + if(multipleNum>0){ + if(Objects.nonNull(dxtQuestionList) && dxtQuestionList.size()>multipleNum){ + list.addAll(getRandomQuestions(dxtQuestionList,multipleNum)); + }else{ + if(Objects.nonNull(dxtQuestionList)){ + list.addAll(dxtQuestionList); + } + } + } + int estimateNum = Convert.toInt(findExamInfo.getEstimateNum(),0); + if(singleNum>0){ + if(Objects.nonNull(pdtQuestionList) && pdtQuestionList.size()>estimateNum){ + list.addAll(getRandomQuestions(pdtQuestionList,estimateNum)); + }else{ + if(Objects.nonNull(pdtQuestionList)){ + list.addAll(pdtQuestionList); + } + } + } + }else{ + throw new ServiceException("请联系管理员配置试题..."); + } + return list; + } + + /** + * 随机试题 + * @param questionList + * @param numberOfQuestions + * @return + */ + private static List getRandomQuestions(List questionList, int numberOfQuestions) { + // 打乱列表 + Collections.shuffle(questionList); + // 获取前 numberOfQuestions 个元素 + return questionList.stream() + .limit(numberOfQuestions) + .collect(Collectors.toList()); } /** @@ -97,4 +270,28 @@ public class BusExamUserServiceImpl implements IBusExamUserService { return busExamUserMapper.deleteBusExamUserById(id); } + + /** + * 新增用户试卷结果信息 + * + * @param busExamUser 用户试卷对象 + */ + public void insertBusExamUserResult(BusExamUser busExamUser) + { + List busExamUserResultList = busExamUser.getBusExamUserResultList(); + Long id = busExamUser.getId(); + if (StringUtils.isNotNull(busExamUserResultList)) + { + List list = new ArrayList(); + for (BusExamUserResult busExamUserResult : busExamUserResultList) + { + busExamUserResult.setExamUserId(id); + list.add(busExamUserResult); + } + if (list.size() > 0) + { + busExamUserMapper.batchBusExamUserResult(list); + } + } + } } diff --git a/yanzhu-ui-vue3/src/views/manage/busExamInfo/index.vue b/yanzhu-ui-vue3/src/views/manage/busExamInfo/index.vue index 9efc0432..b6ed8f0b 100644 --- a/yanzhu-ui-vue3/src/views/manage/busExamInfo/index.vue +++ b/yanzhu-ui-vue3/src/views/manage/busExamInfo/index.vue @@ -102,12 +102,12 @@ - - - - - - + + + + + +