From a1feaf56fa446ed1572497d0d9e324655bae5d08 Mon Sep 17 00:00:00 2001 From: guoshengxiong <1923636941@qq.com> Date: Wed, 16 Apr 2025 19:54:57 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8C=85=E5=A4=B4bug=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../impl/QualityProblemServiceImpl.java | 14 +- .../controller/BaseMenuController.java | 167 +++++++++++++++++- .../exam/controller/ExamPaperController.java | 8 +- .../controller/ExamTrainRecordController.java | 22 +-- .../exam/controller/ExamWorkerController.java | 113 +++++++++++- .../exam/entity/ExamAnswerQuestion.java | 2 + .../exam/service/IExamPaperService.java | 10 +- .../exam/service/IExamTrainRecordService.java | 2 +- .../service/impl/ExamPaperServiceImpl.java | 18 +- .../impl/ExamTrainRecordServiceImpl.java | 77 ++++---- 10 files changed, 345 insertions(+), 88 deletions(-) diff --git a/src/main/java/com/zhgd/xmgl/modules/baotou/service/impl/QualityProblemServiceImpl.java b/src/main/java/com/zhgd/xmgl/modules/baotou/service/impl/QualityProblemServiceImpl.java index 4a93d8952..160d6840b 100644 --- a/src/main/java/com/zhgd/xmgl/modules/baotou/service/impl/QualityProblemServiceImpl.java +++ b/src/main/java/com/zhgd/xmgl/modules/baotou/service/impl/QualityProblemServiceImpl.java @@ -34,10 +34,7 @@ import com.zhgd.xmgl.modules.worker.service.impl.WorkerInfoServiceImpl; import com.zhgd.xmgl.modules.xz.mapper.XzDeductScoreRecordMapper; import com.zhgd.xmgl.modules.xz.mapper.XzTaskProgressContentMapper; import com.zhgd.xmgl.modules.xz.special.service.CountApiService; -import com.zhgd.xmgl.util.FlowSeviceUtil; -import com.zhgd.xmgl.util.FlowUtil; -import com.zhgd.xmgl.util.PageUtil; -import com.zhgd.xmgl.util.RefUtil; +import com.zhgd.xmgl.util.*; import org.apache.commons.collections.MapUtils; import org.flowable.engine.RuntimeService; import org.flowable.engine.runtime.ProcessInstance; @@ -227,7 +224,6 @@ public class QualityProblemServiceImpl extends ServiceImpl tes = Arrays.asList("土建", + "管道", + "动设备", + "静设备", + "电气", + "仪表"); + record.setTechnology(tes.indexOf(MapUtils.getString(formData, "field7713001899028")) + 1); record.setConstructionId(constructionId); record.setQualityStatement(qualityStatement); record.setQualityRequire(qualityRequire); diff --git a/src/main/java/com/zhgd/xmgl/modules/basicdata/controller/BaseMenuController.java b/src/main/java/com/zhgd/xmgl/modules/basicdata/controller/BaseMenuController.java index 118839f51..cb16f1eb2 100644 --- a/src/main/java/com/zhgd/xmgl/modules/basicdata/controller/BaseMenuController.java +++ b/src/main/java/com/zhgd/xmgl/modules/basicdata/controller/BaseMenuController.java @@ -1,17 +1,20 @@ package com.zhgd.xmgl.modules.basicdata.controller; +import cn.hutool.core.collection.CollUtil; import cn.hutool.core.convert.Convert; import cn.hutool.core.util.StrUtil; import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import com.wflow.bean.entity.WflowModelHistorys; +import com.wflow.mapper.WflowModelHistorysMapper; +import com.wflow.mapper.WflowModelsMapper; import com.zhgd.jeecg.common.api.vo.Result; import com.zhgd.jeecg.common.mybatis.EntityMap; -import com.zhgd.xmgl.modules.basicdata.entity.BaseAuthority; -import com.zhgd.xmgl.modules.basicdata.entity.BaseMenu; -import com.zhgd.xmgl.modules.basicdata.entity.BaseModule; -import com.zhgd.xmgl.modules.basicdata.entity.BaseRole; -import com.zhgd.xmgl.modules.basicdata.service.IBaseAuthorityService; -import com.zhgd.xmgl.modules.basicdata.service.IBaseMenuService; -import com.zhgd.xmgl.modules.basicdata.service.IBaseRoleService; +import com.zhgd.xmgl.modules.basicdata.entity.*; +import com.zhgd.xmgl.modules.basicdata.service.*; +import com.zhgd.xmgl.modules.basicdata.service.impl.DictionaryItemServiceImpl; import com.zhgd.xmgl.util.MapBuilder; import com.zhgd.xmgl.util.MessageUtil; import io.swagger.annotations.Api; @@ -48,6 +51,21 @@ public class BaseMenuController { @Lazy @Autowired private IBaseRoleService baseRoleService; + @Lazy + @Autowired + private WflowModelsMapper wflowModelsMapper; + @Lazy + @Autowired + private WflowModelHistorysMapper wflowModelHistorysMapper; + @Lazy + @Autowired + private ISystemUserService systemUserService; + @Lazy + @Autowired + private IBaseRoleUserService baseRoleUserService; + @Lazy + @Autowired + private DictionaryItemServiceImpl dictionaryItemService; /** * 分页列表查询 @@ -192,4 +210,139 @@ public class BaseMenuController { return Result.ok(); } + @ApiOperation(value = "查询角色参与哪些发起工作流和审批工作流", notes = "查询角色参与哪些发起工作流和审批工作流", httpMethod = "POST") + @PostMapping(value = "/getRoleFlow") + public Result getRoleFlow(@RequestBody Map param) { + /* + (idList)=>{ + { + "userType:roleName":{"发起":[formName],"审批":[formName]} + } + } + */ + //"userType:roleName":{"发起":[formName],"审批":[formName]} + List userTypes = dictionaryItemService.getDictList("user_type", null); + Map roleMap = new TreeMap<>(); + List wflowModelHistorys = wflowModelHistorysMapper.selectList(Wrappers.lambdaQuery() + .in(WflowModelHistorys::getFormId, (List) param.get("idList"))); + for (WflowModelHistorys model : wflowModelHistorys) { + //发起人:流程名称 + Map launchUserIdMap = new HashMap<>(); + Map approveUserIdMap = new HashMap<>(); + JSONObject process = JSONObject.parseObject(model.getProcess()); + //发起人 + JSONArray assignedUser1 = process.getJSONObject("props").getJSONArray("assignedUser"); + String formName = model.getFormName(); + if (assignedUser1 != null) { + for (int i = 0; i < assignedUser1.size(); i++) { + JSONObject jsonObject = assignedUser1.getJSONObject(i); + if (jsonObject.getString("type").equals("user")) { + //账号 + launchUserIdMap.put(jsonObject.getString("id"), formName); + } else { + //部门 + List userIds = systemUserService.list(new LambdaQueryWrapper() + .eq(SystemUser::getXzProjectOrgId, jsonObject.getString("id"))).stream().map(SystemUser::getUserId).collect(Collectors.toList()); + userIds.forEach(aLong -> { + launchUserIdMap.put(aLong + "", formName); + }); + } + } + } + //审批人 + addApproveUser(launchUserIdMap, approveUserIdMap, process.getJSONObject("children"), formName); + //构造"userType:roleName":{"发起":[formName],"审批":[formName]} + addRoleMap(launchUserIdMap, userTypes, roleMap, "发起", formName); + addRoleMap(approveUserIdMap, userTypes, roleMap, "审批", formName); + } + + return Result.success(roleMap); + } + + /** + * 添加 "userType:roleName":{"发起":[formName],"审批":[formName]} + * + * @param approveUserIdMap + * @param userTypes + * @param roleMap + * @param approve + * @param formName + */ + private void addRoleMap(Map approveUserIdMap, List userTypes, Map roleMap, String approve, String formName) { + if (CollUtil.isNotEmpty(approveUserIdMap)) { + List roleIds = baseRoleUserService.list(new LambdaQueryWrapper() + .in(BaseRoleUser::getUserId, new ArrayList<>(approveUserIdMap.keySet()))).stream().map(BaseRoleUser::getRoleId).collect(Collectors.toList()); + if (CollUtil.isNotEmpty(roleIds)) { + List roles = baseRoleService.list(new LambdaQueryWrapper() + .in(BaseRole::getRoleId, roleIds)); + for (BaseRole role : roles) { + String userTypeName = userTypes.stream().filter(o -> o.getData().equals(role.getUserType())).findFirst().map(o -> o).orElse(null).getName(); + roleMap.compute(userTypeName + ":" + role.getRoleName(), (k, v) -> { + if (v == null) { + v = new JSONObject(); + } + v.compute(approve, (k1, v1) -> { + if (v1 == null) { + v1 = new HashSet<>(); + } + ((Set) v1).add(formName); + return v1; + }); + return v; + }); + } + } + } + } + + /** + * 添加审批人 + * + * @param launchUserIdMap + * @param approveUserIdMap 添加审批人 + * @param children + * @param formName + */ + private void addApproveUser(Map launchUserIdMap, Map approveUserIdMap, JSONObject children, String formName) { + if (children == null) { + return; + } + String type = children.getString("type"); + if (Objects.equals("CONDITIONS", type)) { + JSONArray array = children.getJSONArray("branchs"); + Iterator iterator = array.iterator(); + while (iterator.hasNext()) { + addApproveUser(launchUserIdMap, approveUserIdMap, (JSONObject) iterator.next(), formName); + } + } + addApproveUser(launchUserIdMap, approveUserIdMap, children.getJSONObject("children"), formName); + //添加审批人 + JSONObject props = children.getJSONObject("props"); + if (props == null) { + return; + } + JSONArray assignedUser = props.getJSONArray("assignedUser"); + if (assignedUser != null) { + for (int i = 0; i < assignedUser.size(); i++) { + JSONObject jsonObject = assignedUser.getJSONObject(i); + String id = jsonObject.getString("id"); + if (jsonObject.getString("type").equals("user")) { + //账号 + if (!launchUserIdMap.containsKey(id)) { + approveUserIdMap.put(id, formName); + } + } else { + //部门 + List userIds = systemUserService.list(new LambdaQueryWrapper() + .eq(SystemUser::getXzProjectOrgId, id)).stream().map(SystemUser::getUserId).collect(Collectors.toList()); + userIds.forEach(aLong -> { + if (!launchUserIdMap.containsKey(id)) { + approveUserIdMap.put(aLong + "", formName); + } + }); + } + } + } + } + } diff --git a/src/main/java/com/zhgd/xmgl/modules/exam/controller/ExamPaperController.java b/src/main/java/com/zhgd/xmgl/modules/exam/controller/ExamPaperController.java index 1dfead668..91b90f357 100644 --- a/src/main/java/com/zhgd/xmgl/modules/exam/controller/ExamPaperController.java +++ b/src/main/java/com/zhgd/xmgl/modules/exam/controller/ExamPaperController.java @@ -226,13 +226,15 @@ public class ExamPaperController { @ApiImplicitParams({ @ApiImplicitParam(name = "id", value = "试卷ID", paramType = "body", required = true, dataType = "Integer"), @ApiImplicitParam(name = "workerCard", value = "人员证件号", paramType = "body", required = false, dataType = "String"), + @ApiImplicitParam(name = "examRecordId", value = "考试记录id", paramType = "body", required = true, dataType = "String"), }) @PostMapping(value = "/queryQuestionById") public Result> queryQuestionById(@RequestBody Map param) { String workerCard = MapUtils.getString(param, "workerCard"); Long id = MapUtils.getLong(param, "id"); + Long examRecordId = MapUtils.getLong(param, "examRecordId"); Result> result = new Result>(); - result.setResult(examPaperService.queryQuestionByPaperIdAndIdCard(id, workerCard)); + result.setResult(examPaperService.queryQuestionByPaperIdAndExamRecordId(id, workerCard, examRecordId)); result.setSuccess(true); return result; } @@ -248,12 +250,14 @@ public class ExamPaperController { @ApiImplicitParams({ @ApiImplicitParam(name = "id", value = "试题ID", paramType = "body", required = true, dataType = "Integer"), @ApiImplicitParam(name = "workerCard", value = "人员证件号", paramType = "body", required = false, dataType = "String"), + @ApiImplicitParam(name = "examRecordId", value = "考试记录id", paramType = "body", required = true, dataType = "String"), }) @PostMapping(value = "/queryStatInfo") public Result queryStatInfo(@RequestBody Map param) { String workerCard = MapUtils.getString(param, "workerCard"); Long id = MapUtils.getLong(param, "id"); - return Result.success(examPaperService.queryStatInfo(id, workerCard)); + Long examRecordId = MapUtils.getLong(param, "examRecordId"); + return Result.success(examPaperService.queryStatInfo(id, workerCard, examRecordId)); } /** diff --git a/src/main/java/com/zhgd/xmgl/modules/exam/controller/ExamTrainRecordController.java b/src/main/java/com/zhgd/xmgl/modules/exam/controller/ExamTrainRecordController.java index b0cceaedc..85eb32908 100644 --- a/src/main/java/com/zhgd/xmgl/modules/exam/controller/ExamTrainRecordController.java +++ b/src/main/java/com/zhgd/xmgl/modules/exam/controller/ExamTrainRecordController.java @@ -283,17 +283,17 @@ public class ExamTrainRecordController { return result; } - /** - * 提交考试结果 - * - * @return - */ - @OperLog(operModul = "考试记录管理", operType = "查询", operDesc = "提交考试结果") - @ApiOperation(value = "提交考试结果", notes = "提交考试结果", httpMethod = "POST") - @PostMapping(value = "/submit") - public Result submit(@RequestBody List examAnswerQuestionList) { - return Result.success(examTrainRecordService.submit(examAnswerQuestionList)); - } +// /** +// * 提交考试结果 +// * +// * @return +// */ +// @OperLog(operModul = "考试记录管理", operType = "查询", operDesc = "提交考试结果") +// @ApiOperation(value = "提交考试结果", notes = "提交考试结果", httpMethod = "POST") +// @PostMapping(value = "/submit") +// public Result submit(@RequestBody List examAnswerQuestionList) { +// return Result.success(examTrainRecordService.submit(examAnswerQuestionList)); +// } /** * 导出excel diff --git a/src/main/java/com/zhgd/xmgl/modules/exam/controller/ExamWorkerController.java b/src/main/java/com/zhgd/xmgl/modules/exam/controller/ExamWorkerController.java index 18464d5f3..5dd169e17 100644 --- a/src/main/java/com/zhgd/xmgl/modules/exam/controller/ExamWorkerController.java +++ b/src/main/java/com/zhgd/xmgl/modules/exam/controller/ExamWorkerController.java @@ -1,6 +1,7 @@ package com.zhgd.xmgl.modules.exam.controller; import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.convert.Convert; import cn.hutool.core.date.DateUtil; import cn.hutool.core.io.FileUtil; import cn.hutool.core.util.IdUtil; @@ -136,13 +137,16 @@ public class ExamWorkerController { @ApiImplicitParams({ @ApiImplicitParam(name = "paperId", value = "试卷ID", paramType = "body", required = true, dataType = "String"), @ApiImplicitParam(name = "workerCard", value = "人员证件号", paramType = "body", required = false, dataType = "String"), + @ApiImplicitParam(name = "examRecordId", value = "考试记录id", paramType = "body", required = true, dataType = "String"), + }) @PostMapping(value = "/queryQuestionById") public Result> queryQuestionById(@RequestBody @ApiIgnore Map map) { Result> result = new Result>(); Long paperId = MapUtils.getLong(map, "paperId"); String idCard = MapUtils.getString(map, "workerCard"); - result.setResult(examPaperService.queryQuestionByPaperIdAndIdCard(paperId, idCard)); + Long examRecordId = MapUtils.getLong(map, "examRecordId"); + result.setResult(examPaperService.queryQuestionByPaperIdAndExamRecordId(paperId, idCard, examRecordId)); result.setSuccess(true); return result; } @@ -156,8 +160,7 @@ public class ExamWorkerController { @ApiOperation(value = "开始考试", notes = "开始考试", httpMethod = "POST") @PostMapping(value = "/startExam") public Result startExam(@RequestBody Map param) { - examTrainRecordService.doStartExam(param); - return Result.ok(); + return Result.success(examTrainRecordService.doStartExam(param)); } /** @@ -503,4 +506,108 @@ public class ExamWorkerController { }).collect(Collectors.toList())); } } + + @ApiOperation(value = "根据分数分配正确的题目", notes = "根据分数分配正确的题目", httpMethod = "GET") + @ApiImplicitParams({ + }) + @GetMapping(value = "/updateBankByScore") + public Result updateBankByScore(@RequestParam HashMap param) { + String projectSn = "5B8B3DB047214AE188F2C7916DD08203"; + Map bankMap = examQuestionBankService.list(new LambdaQueryWrapper() + .eq(ExamQuestionBank::getProjectSn, projectSn)).stream().collect(Collectors.toMap(ExamQuestionBank::getId, Function.identity(), (o1, o2) -> o1)); + List records = examTrainRecordService.list(new LambdaQueryWrapper() + .eq(ExamTrainRecord::getProjectSn, projectSn)); + for (ExamTrainRecord record : records) { + int errSingle = 0; + int errJudge = 0; + if (record.getScore() != null) { + if (NumberUtil.isGreaterOrEqual(record.getScore(), new BigDecimal("80"))) { + if (NumberUtil.equals(record.getScore(), new BigDecimal("80"))) { + errSingle = 4; + errJudge = 0; + } else if (NumberUtil.equals(record.getScore(), new BigDecimal("81"))) { + errSingle = 1; + errJudge = 7; + } else if (NumberUtil.equals(record.getScore(), new BigDecimal("82"))) { + errSingle = 0; + errJudge = 9; + } else if (NumberUtil.equals(record.getScore(), new BigDecimal("83"))) { + errSingle = 1; + errJudge = 6; + } else if (NumberUtil.equals(record.getScore(), new BigDecimal("84"))) { + errSingle = 0; + errJudge = 8; + } else if (NumberUtil.equals(record.getScore(), new BigDecimal("85"))) { + errSingle = 1; + errJudge = 5; + } else if (NumberUtil.equals(record.getScore(), new BigDecimal("86"))) { + errSingle = 0; + errJudge = 7; + } else if (NumberUtil.equals(record.getScore(), new BigDecimal("87"))) { + errSingle = 1; + errJudge = 4; + } else if (NumberUtil.equals(record.getScore(), new BigDecimal("88"))) { + errSingle = 0; + errJudge = 6; + } else if (NumberUtil.equals(record.getScore(), new BigDecimal("89"))) { + errSingle = 1; + errJudge = 3; + } else if (NumberUtil.equals(record.getScore(), new BigDecimal("90"))) { + errSingle = 0; + errJudge = 5; + } else if (NumberUtil.equals(record.getScore(), new BigDecimal("91"))) { + errSingle = 1; + errJudge = 2; + } else if (NumberUtil.equals(record.getScore(), new BigDecimal("92"))) { + errSingle = 0; + errJudge = 4; + } else if (NumberUtil.equals(record.getScore(), new BigDecimal("93"))) { + errSingle = 1; + errJudge = 1; + } else if (NumberUtil.equals(record.getScore(), new BigDecimal("94"))) { + errSingle = 0; + errJudge = 3; + } else if (NumberUtil.equals(record.getScore(), new BigDecimal("95"))) { + errSingle = 1; + errJudge = 0; + } else if (NumberUtil.equals(record.getScore(), new BigDecimal("96"))) { + errSingle = 0; + errJudge = 2; + } else if (NumberUtil.equals(record.getScore(), new BigDecimal("98"))) { + errSingle = 0; + errJudge = 1; + } else if (NumberUtil.equals(record.getScore(), new BigDecimal("100"))) { + errSingle = 0; + errJudge = 0; + } + int[] ints = {0, 0}; + int finalErrSingle = errSingle; + int finalErrJudge = errJudge; + record.setSelectOptions(StrUtil.join(",", StrUtil.split(record.getQuestions(), ",").stream().map(s -> { + //10、6、13 + ExamQuestionBank examQuestionBank = bankMap.get(Convert.toLong(s)); + String options = examQuestionBank.getOptions(); + if (examQuestionBank.getType() == 1) { + if (finalErrSingle > ints[0]) { + if (options.equals("A")) { + options = "B"; + } + ints[0] = ints[0] + 1; + } + } else if (examQuestionBank.getType() == 3) { + if (finalErrJudge > ints[1]) { + if (options.equals("对")) { + options = "错"; + } + ints[1] = ints[1] + 1; + } + } + return options; + }).collect(Collectors.toList()))); + } + } + } + examTrainRecordService.updateBatchById(records); + return Result.ok(); + } } diff --git a/src/main/java/com/zhgd/xmgl/modules/exam/entity/ExamAnswerQuestion.java b/src/main/java/com/zhgd/xmgl/modules/exam/entity/ExamAnswerQuestion.java index c95a41ca4..63a824de3 100644 --- a/src/main/java/com/zhgd/xmgl/modules/exam/entity/ExamAnswerQuestion.java +++ b/src/main/java/com/zhgd/xmgl/modules/exam/entity/ExamAnswerQuestion.java @@ -102,5 +102,7 @@ public class ExamAnswerQuestion implements Serializable { @TableField(exist = false) @ApiModelProperty(value = "申请id") private Long applicationId; + @TableField(exist = false) + private Long workerId; } diff --git a/src/main/java/com/zhgd/xmgl/modules/exam/service/IExamPaperService.java b/src/main/java/com/zhgd/xmgl/modules/exam/service/IExamPaperService.java index f42856df0..f61f5e5af 100644 --- a/src/main/java/com/zhgd/xmgl/modules/exam/service/IExamPaperService.java +++ b/src/main/java/com/zhgd/xmgl/modules/exam/service/IExamPaperService.java @@ -51,20 +51,24 @@ public interface IExamPaperService extends IService { ExamPaperVo queryDetailById(Long examId); /** - *通过id查询详细信息 + * 通过id查询详细信息 + * * @param examId * @param idCard + * @param examRecordId * @return */ - List queryQuestionByPaperIdAndIdCard(Long examId, String idCard); + List queryQuestionByPaperIdAndExamRecordId(Long examId, String idCard, Long examRecordId); /** * 查询试题总分、参考人数和缺考人数 + * * @param examId * @param workerCard + * @param examRecordId * @return */ - Map queryStatInfo(Long examId, String workerCard); + Map queryStatInfo(Long examId, String workerCard, Long examRecordId); ExamPaper queryById(Long id); diff --git a/src/main/java/com/zhgd/xmgl/modules/exam/service/IExamTrainRecordService.java b/src/main/java/com/zhgd/xmgl/modules/exam/service/IExamTrainRecordService.java index d0eb8c757..adf93793e 100644 --- a/src/main/java/com/zhgd/xmgl/modules/exam/service/IExamTrainRecordService.java +++ b/src/main/java/com/zhgd/xmgl/modules/exam/service/IExamTrainRecordService.java @@ -68,7 +68,7 @@ public interface IExamTrainRecordService extends IService { */ List getTrainRecordsByWorkerId(String projectSn, String workerId); - void doStartExam(Map param); + ExamTrainRecord doStartExam(Map param); IPage countSpecialPageList(Page page, QueryWrapper queryWrapper, Map param); diff --git a/src/main/java/com/zhgd/xmgl/modules/exam/service/impl/ExamPaperServiceImpl.java b/src/main/java/com/zhgd/xmgl/modules/exam/service/impl/ExamPaperServiceImpl.java index af98bd11f..1c7e69f8b 100644 --- a/src/main/java/com/zhgd/xmgl/modules/exam/service/impl/ExamPaperServiceImpl.java +++ b/src/main/java/com/zhgd/xmgl/modules/exam/service/impl/ExamPaperServiceImpl.java @@ -136,17 +136,17 @@ public class ExamPaperServiceImpl extends ServiceImpl randomQueries, Integer subjectType) { - //入场培训和复工培训:单选题10道 3分、多选题 5道 4分、判断题 10道 5分 + //入场培训和复工培训:单选题10道 5分、多选题 6道 4分、判断题 13道 2分 //专项培训:单选 10道 5分、多选10道 5分 BigDecimal sum = randomQueries.stream().map(e -> { int s = 0; if (subjectType != 3) { if (e.getType() == 1) { - s = 3; + s = 5; } else if (e.getType() == 2) { s = 4; } else { - s = 5; + s = 2; } } else { if (e.getType() == 1) { @@ -198,16 +198,12 @@ public class ExamPaperServiceImpl extends ServiceImpl queryQuestionByPaperIdAndIdCard(Long examId, String idCard) { + public List queryQuestionByPaperIdAndExamRecordId(Long examId, String idCard, Long examRecordId) { ExamPaper examPaper = this.getById(examId); if (examPaper != null) { String questions; if (Objects.equals(examPaper.getCheckQuestionType(), 2)) { - ExamTrainRecord trainRecord = examTrainRecordService.getOne(new LambdaQueryWrapper() - .eq(ExamTrainRecord::getWorkerCard, idCard) - .eq(ExamTrainRecord::getExamPaperId, examId) - .last("limit 1") - ); + ExamTrainRecord trainRecord = examTrainRecordService.getById(examRecordId); questions = trainRecord.getQuestions(); } else { questions = examPaper.getQuestions(); @@ -223,9 +219,9 @@ public class ExamPaperServiceImpl extends ServiceImpl queryStatInfo(Long examId, String workerCard) { + public Map queryStatInfo(Long examId, String workerCard, Long examRecordId) { Map result = new HashMap<>(16); - List examQuestionBankVos = queryQuestionByPaperIdAndIdCard(examId, workerCard); + List examQuestionBankVos = queryQuestionByPaperIdAndExamRecordId(examId, workerCard, examRecordId); BigDecimal totalScore = examQuestionBankVos.stream().map(ExamQuestionBank::getScore).reduce(BigDecimal.ZERO, BigDecimal::add); List examRecords = examRecordService.list(Wrappers.lambdaQuery().eq(ExamRecord::getExamId, examId)); int examNum = examRecords.stream().filter(e -> e.getScore() != null).collect(Collectors.toList()).size(); diff --git a/src/main/java/com/zhgd/xmgl/modules/exam/service/impl/ExamTrainRecordServiceImpl.java b/src/main/java/com/zhgd/xmgl/modules/exam/service/impl/ExamTrainRecordServiceImpl.java index b4bf3257c..a8ac5285d 100644 --- a/src/main/java/com/zhgd/xmgl/modules/exam/service/impl/ExamTrainRecordServiceImpl.java +++ b/src/main/java/com/zhgd/xmgl/modules/exam/service/impl/ExamTrainRecordServiceImpl.java @@ -18,6 +18,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.gexin.fastjson.JSON; import com.zhgd.jeecg.common.execption.OpenAlertException; import com.zhgd.jeecg.common.system.query.QueryGenerator; import com.zhgd.redis.lock.redisson.DistributedLock; @@ -38,11 +39,13 @@ import com.zhgd.xmgl.modules.xz.service.IXzDeductScoreRecordService; import com.zhgd.xmgl.util.IdCardUtils; import com.zhgd.xmgl.util.MapBuilder; import com.zhgd.xmgl.util.NumberUtils; +import lombok.extern.slf4j.Slf4j; import org.apache.commons.collections.MapUtils; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Lazy; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import java.math.BigDecimal; import java.util.*; @@ -57,6 +60,8 @@ import java.util.stream.Collectors; * @version: V1.0 */ @Service +@Slf4j +@Transactional(rollbackFor = Exception.class) public class ExamTrainRecordServiceImpl extends ServiceImpl implements IExamTrainRecordService { public static final String ADD_SIGN = "+"; @@ -130,37 +135,27 @@ public class ExamTrainRecordServiceImpl extends ServiceImpl examAnswerQuestionList) { - String card = examAnswerQuestionList.get(0).getWorkerCard(); - if (StrUtil.isBlank(card)) { - throw new OpenAlertException("workerCard不能为空"); + log.info("提交考试:{}", JSON.toJSONString(examAnswerQuestionList)); + Long examRecordId = examAnswerQuestionList.get(0).getExamRecordId(); + if (examRecordId == null) { + throw new OpenAlertException("examRecordId不能为空"); } - Long paperId = examAnswerQuestionList.get(0).getTrainRecordId(); - Long applicationId = examAnswerQuestionList.get(0).getApplicationId(); - List rs = baseMapper.selectList(new LambdaQueryWrapper() - .eq(ExamTrainRecord::getWorkerCard, card) - .eq(ExamTrainRecord::getApplicationId, applicationId)); - ExamTrainRecord notSubmit = rs.stream().filter(o -> Objects.equals(o.getSubmit(), 0)).sorted((o1, o2) -> o2.getCreateTime().compareTo(o1.getCreateTime())).findFirst().map(o -> o).orElse(null); - if (notSubmit == null) { + ExamTrainRecord submit = baseMapper.selectById(examRecordId); + Long applicationId = submit.getApplicationId(); + Long paperId = submit.getExamPaperId(); + if (submit.getSubmit() == 1) { //您已提交试卷 - return rs.stream().filter(o -> Objects.equals(o.getSubmit(), 1)).sorted((o1, o2) -> o2.getCreateTime().compareTo(o1.getCreateTime())).findFirst().map(o -> o).orElse(null); + return submit; } - ExamTrainRecord submit = rs.stream().filter(o -> Objects.equals(o.getSubmit(), 1) && Objects.equals(o.getIsNewBatch(), 1)).sorted((o1, o2) -> o2.getCreateTime().compareTo(o1.getCreateTime())).findFirst().map(o -> o).orElse(null); - if (submit == null) { - submit = new ExamTrainRecord(); - BeanUtil.copyProperties(notSubmit, submit); - submit.setSubmit(1); - submit.setIsNewBatch(1); - } else { - //删除未提交的试卷 - examTrainRecordService.remove(new LambdaQueryWrapper() - .eq(ExamTrainRecord::getWorkerCard, card) - .eq(ExamTrainRecord::getApplicationId, applicationId) - .eq(ExamTrainRecord::getSubmit, 0) - ); - } - submit.setStartExamTime(notSubmit.getStartExamTime()); + submit.setSubmit(1); + submit.setIsNewBatch(1); + //同批次删除以前提交的试卷 + examTrainRecordService.remove(new LambdaQueryWrapper() + .ne(ExamTrainRecord::getId, examRecordId) + .eq(ExamTrainRecord::getWorkerId, submit.getWorkerId()) + .eq(ExamTrainRecord::getApplicationId, applicationId) + ); submit.setExamCount(submit.getExamCount() + 1); - submit.setQuestions(notSubmit.getQuestions()); ExamPaper examPaper = examPaperService.getById(paperId); BigDecimal score = BigDecimal.ZERO; BigDecimal totalScore = BigDecimal.ZERO; @@ -314,7 +309,7 @@ public class ExamTrainRecordServiceImpl extends ServiceImpl param) { + public ExamTrainRecord doStartExam(Map param) { //《入场培训》:人员入场和违章再教育 //《复工培训》:实名制人员 //《专项培训》:高处作业,动火作业,吊装作业,受限作业,临时用电,脚手架搭设/拆除:实名制人员 @@ -427,18 +422,6 @@ public class ExamTrainRecordServiceImpl extends ServiceImpl paper.getRetakeNum()) { -// throw new OpenAlertException("您已没有考试的次数!"); -// } -// this.setQuestionsIf(paper, trainRecord); -// trainRecord.setStartExamTime(new Date()); -// trainRecord.setExamCount(trainRecord.getExamCount() + 1); -// trainRecord.setFromType(fromType); -// baseMapper.updateById(trainRecord); -// baseMapper.update(trainRecord, new LambdaUpdateWrapper().set(ExamTrainRecord::getIsPass, null).eq(ExamTrainRecord::getId, trainRecord.getId())); -// typeName = trainRecord.getWorkerType(); -// } else { Long id; String wn; String teamName; @@ -470,7 +453,6 @@ public class ExamTrainRecordServiceImpl extends ServiceImpl() + .eq(ExamTrainRecord::getWorkerId, trainRecord.getWorkerId()) + .eq(ExamTrainRecord::getApplicationId, trainRecord.getApplicationId()) + .eq(ExamTrainRecord::getSubmit, 1) + .last("order by update_time limit 1") + ); + trainRecord.setExamCount(record == null ? 0 : record.getExamCount()); baseMapper.insert(trainRecord); -// } - ExamScanCode scanCode = new ExamScanCode(); scanCode.setExamPaperId(paper.getId()); scanCode.setEnterpriseName(info != null ? info.getEnterpriseName() : workerAdmissionDetailService.queryById(admissionDetail.getId() + "").getEnterpriseName()); @@ -497,6 +484,7 @@ public class ExamTrainRecordServiceImpl extends ServiceImpl random = examQuestionBankServie.random(randomQueryList); + random = random.stream().sorted(Comparator.comparing(ExamQuestionBank::getType)).collect(Collectors.toList()); if (CollUtil.isNotEmpty(random)) { String bankIds = StrUtil.join(",", random.stream().map(ExamQuestionBank::getId).collect(Collectors.toList())); trainRecord.setQuestions(bankIds);