From 146f751f1af1a9587a0200231326a4b46e731013 Mon Sep 17 00:00:00 2001 From: ty <1577900710@qq.com> Date: Thu, 21 Mar 2024 08:59:48 +0800 Subject: [PATCH] =?UTF-8?q?=E8=80=83=E8=AF=95=E8=AE=B0=E5=BD=95=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E6=9F=A5=E8=AF=A2=E9=A1=B5=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/hnac/hzims/safeproduct/dto/TestDTO.java | 8 ++- .../hnac/hzims/safeproduct/entity/TestEntity.java | 1 + .../hzims/safeproduct/entity/TestScoreEntity.java | 12 +++++ .../com/hnac/hzims/safeproduct/vo/TestScoreVO.java | 3 ++ .../safeproduct/controller/TrainController.java | 9 ++-- .../safeproduct/service/ITestScoreService.java | 2 +- .../hzims/safeproduct/service/ITestService.java | 4 +- .../service/impl/TestScoreServiceImpl.java | 59 +++++++++++++++------- .../safeproduct/service/impl/TestServiceImpl.java | 42 +++++++++++---- 9 files changed, 105 insertions(+), 35 deletions(-) diff --git a/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/dto/TestDTO.java b/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/dto/TestDTO.java index 6b55684..2c0e72f 100644 --- a/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/dto/TestDTO.java +++ b/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/dto/TestDTO.java @@ -1,20 +1,26 @@ package com.hnac.hzims.safeproduct.dto; +import com.hnac.hzims.safeproduct.entity.TestEntity; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; +import javax.validation.constraints.Size; + /** * @author liwen * @date 2023-12-25 */ @Data @ApiModel(value = "考试记录DTO类") -public class TestDTO { +public class TestDTO extends TestEntity { @ApiModelProperty("考试记录id") private Long id; @ApiModelProperty("考试记录名称") private String testName; + + @ApiModelProperty("参考人员Id,以,分隔") + private String peopleId; } diff --git a/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/entity/TestEntity.java b/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/entity/TestEntity.java index 354920b..8292f97 100644 --- a/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/entity/TestEntity.java +++ b/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/entity/TestEntity.java @@ -67,6 +67,7 @@ public class TestEntity extends BaseEntity { @ApiModelProperty("参考人员") private String peopleName; + @Size(max = 1000, message = "考试图片字段长度不能超过1000") @ApiModelProperty("考试图片") private String imgPath; diff --git a/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/entity/TestScoreEntity.java b/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/entity/TestScoreEntity.java index a95020e..9a2b8f3 100644 --- a/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/entity/TestScoreEntity.java +++ b/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/entity/TestScoreEntity.java @@ -29,6 +29,18 @@ public class TestScoreEntity extends BaseEntity { @ApiModelProperty("姓名") private String name; + @Size(max = 50, message = "姓名字段长度不能超过50") + @ApiModelProperty("姓名") + private String userId; + + @Size(max = 50, message = "姓名字段长度不能超过50") + @ApiModelProperty("机构名称") + private String deptName; + + @Size(max = 50, message = "姓名字段长度不能超过50") + @ApiModelProperty("机构Id") + private String deptId; + @NotNull @Min(value = 0, message = "成绩必须大于等于0") @Max(value = 100, message = "成绩必须小于等于100") diff --git a/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/vo/TestScoreVO.java b/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/vo/TestScoreVO.java index 7de3c9a..f04fea1 100644 --- a/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/vo/TestScoreVO.java +++ b/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/vo/TestScoreVO.java @@ -24,6 +24,9 @@ public class TestScoreVO { @ApiModelProperty("姓名") private String name; + @ApiModelProperty("姓名") + private String userId; + @ApiModelProperty("成绩") private Integer score; } diff --git a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/controller/TrainController.java b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/controller/TrainController.java index e5cef0f..9dd6c2c 100644 --- a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/controller/TrainController.java +++ b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/controller/TrainController.java @@ -6,6 +6,7 @@ import com.hnac.hzims.safeproduct.dto.TestDTO; import com.hnac.hzims.safeproduct.dto.TestScoreDTO; import com.hnac.hzims.safeproduct.dto.TrainRecordDTO; import com.hnac.hzims.safeproduct.entity.TestEntity; +import com.hnac.hzims.safeproduct.entity.TestScoreEntity; import com.hnac.hzims.safeproduct.entity.TrainPlanEntity; import com.hnac.hzims.safeproduct.entity.TrainRecordEntity; import com.hnac.hzims.safeproduct.service.ITestScoreService; @@ -142,14 +143,14 @@ public class TrainController extends BladeController { @PostMapping("/saveTest") @ApiOperation(value = "新增考试") @ApiOperationSupport(order = 12) - public R saveTest(@Valid @RequestBody TestEntity testEntity) { + public R saveTest(@Valid @RequestBody TestDTO testEntity) { return testService.saveTest(testEntity); } @PostMapping("/updateTest") @ApiOperation(value = "修改考试") @ApiOperationSupport(order = 13) - public R updateTest(@Valid @RequestBody TestEntity testEntity) { + public R updateTest(@Valid @RequestBody TestDTO testEntity) { return R.status(testService.updateTest(testEntity)); } @@ -192,8 +193,8 @@ public class TrainController extends BladeController { @GetMapping("/testScoreList") @ApiOperation(value = "考试成绩列表") @ApiOperationSupport(order = 18) - public R> testScoreList(@RequestParam Long testId, String name) { - List list = testScoreService.testScoreList(testId, name); + public R> testScoreList(@RequestParam Long testId, String name) { + List list = testScoreService.testScoreList(testId, name); return R.data(list); } @GetMapping("/testScoreSum") diff --git a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/ITestScoreService.java b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/ITestScoreService.java index ce7e884..54ca22f 100644 --- a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/ITestScoreService.java +++ b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/ITestScoreService.java @@ -22,7 +22,7 @@ public interface ITestScoreService extends IService { * @param name 姓名 * @return 考试成绩列表 */ - List testScoreList(Long testId, String name); + List testScoreList(Long testId, String name); /** * 批量填写分数 diff --git a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/ITestService.java b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/ITestService.java index 4a59b6e..c1bfaf6 100644 --- a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/ITestService.java +++ b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/ITestService.java @@ -23,7 +23,7 @@ public interface ITestService extends IService { * @param testEntity 考试记录实体类 * @return 返回结果封装类 */ - R saveTest(TestEntity testEntity); + R saveTest(TestDTO testEntity); /** * 根据编码查询考试记录 @@ -65,7 +65,7 @@ public interface ITestService extends IService { * @param testEntity 考试记录实体类 * @return true-成功,false-失败 */ - boolean updateTest(TestEntity testEntity); + boolean updateTest(TestDTO testEntity); /** * 考试记录分页 diff --git a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/TestScoreServiceImpl.java b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/TestScoreServiceImpl.java index 6e6b952..29d1b33 100644 --- a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/TestScoreServiceImpl.java +++ b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/TestScoreServiceImpl.java @@ -1,6 +1,7 @@ package com.hnac.hzims.safeproduct.service.impl; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.hnac.hzims.safeproduct.dto.TestScoreDTO; import com.hnac.hzims.safeproduct.entity.TestEntity; @@ -10,8 +11,14 @@ import com.hnac.hzims.safeproduct.mapper.TestScoreMapper; import com.hnac.hzims.safeproduct.service.ITestScoreService; import com.hnac.hzims.safeproduct.vo.TestScoreSumVO; import com.hnac.hzims.safeproduct.vo.TestScoreVO; +import com.hnac.hzinfo.inspect.ai.entity.RobotTaskEntity; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang.StringUtils; +import org.springblade.core.tool.api.R; +import org.springblade.core.tool.utils.ObjectUtil; +import org.springblade.system.feign.ISysClient; import org.springframework.beans.BeanUtils; import org.springframework.stereotype.Service; @@ -27,15 +34,19 @@ import java.util.stream.Collectors; * @date 2023-12-25 */ @Service +@RequiredArgsConstructor +@Slf4j public class TestScoreServiceImpl extends ServiceImpl implements ITestScoreService { + private final ISysClient sysClient; @Resource TestMapper testMapper; + /** * 查询考试成绩列表 */ @Override - public List testScoreList(Long testId, String name) { - return baseMapper.testScoreList(testId, name); + public List testScoreList(Long testId, String name) { + return baseMapper.selectList(Wrappers.lambdaQuery().eq(TestScoreEntity::getTestId, testId)); } /** @@ -43,15 +54,27 @@ public class TestScoreServiceImpl extends ServiceImpl scoreList = testScoreDTO.getScoreList(); - List testScoreEntities = new ArrayList<>(); - scoreList.forEach(score -> { - TestScoreEntity testScoreEntity = new TestScoreEntity(); - BeanUtils.copyProperties(score, testScoreEntity); - testScoreEntity.setTestId(testScoreDTO.getTestId()); - testScoreEntities.add(testScoreEntity); - }); - return this.updateBatchById(testScoreEntities); + boolean b = this.removeRelativeTestScore(testScoreDTO.getTestId()); + if (b) { + List scoreList = testScoreDTO.getScoreList(); + List testScoreEntities = new ArrayList<>(); + scoreList.forEach(score -> { + TestScoreEntity testScoreEntity = new TestScoreEntity(); + BeanUtils.copyProperties(score, testScoreEntity); + testScoreEntity.setTestId(testScoreDTO.getTestId()); + if (!"^".equals(score.getUserId())&&ObjectUtil.isNotEmpty(score.getDept())) { + R deptNameR = sysClient.getDeptName(score.getDept()); + if (deptNameR.isSuccess()&&StringUtils.isNotBlank(deptNameR.getData())){ + testScoreEntity.setDeptName(deptNameR.getData()); + } + }else { + testScoreEntity.setUserId(""); + } + testScoreEntities.add(testScoreEntity); + }); + return this.saveOrUpdateBatch(testScoreEntities); + } + return false; } /** @@ -87,20 +110,20 @@ public class TestScoreServiceImpl extends ServiceImpl queryWrapper = new QueryWrapper<>(); queryWrapper.lambda().eq(TestScoreEntity::getTestId, testId); List list = this.list(queryWrapper); - if (CollectionUtils.isNotEmpty(list)){ - testScoreSumVO.setPeopleNum( list.size()); + if (CollectionUtils.isNotEmpty(list)) { + testScoreSumVO.setPeopleNum(list.size()); List collect = list.stream().filter(s -> s.getScore() > 60).collect(Collectors.toList()); - if (CollectionUtils.isNotEmpty(list)) { - testScoreSumVO.setPercentage(new Double(collect.size() / list.size())); - } + if (CollectionUtils.isNotEmpty(list)) { + testScoreSumVO.setPercentage(new Double(collect.size() / list.size())); + } } return testScoreSumVO; } diff --git a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/TestServiceImpl.java b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/TestServiceImpl.java index 09cc4df..5d2b0d5 100644 --- a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/TestServiceImpl.java +++ b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/TestServiceImpl.java @@ -1,6 +1,7 @@ package com.hnac.hzims.safeproduct.service.impl; import cn.hutool.core.date.DatePattern; +import cn.hutool.core.util.ObjectUtil; import com.alibaba.excel.util.CollectionUtils; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; @@ -16,8 +17,14 @@ import com.hnac.hzims.safeproduct.mapper.TrainPlanMapper; import com.hnac.hzims.safeproduct.service.ITestScoreService; import com.hnac.hzims.safeproduct.service.ITestService; import com.hnac.hzims.safeproduct.utils.BaseUtil; +import lombok.RequiredArgsConstructor; +import org.apache.commons.lang.ObjectUtils; +import org.apache.commons.lang.StringUtils; import org.springblade.core.mp.support.Query; import org.springblade.core.tool.api.R; +import org.springblade.system.feign.ISysClient; +import org.springblade.system.user.cache.UserCache; +import org.springblade.system.user.entity.User; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -36,8 +43,9 @@ import java.util.stream.Collectors; * @date 2023-12-25 */ @Service +@RequiredArgsConstructor public class TestServiceImpl extends ServiceImpl implements ITestService { - + private final ISysClient sysClient; @Autowired ITestScoreService testScoreService; @@ -49,7 +57,7 @@ public class TestServiceImpl extends ServiceImpl impleme */ @Transactional(rollbackFor = Exception.class) @Override - public R saveTest(TestEntity testEntity) { + public R saveTest(TestDTO testEntity) { // 判断培训计划是否需要考试,若不需要,则无法新增考试记录 TrainPlanEntity trainPlanEntity = trainPlanMapper.selectById(testEntity.getTrainPlanId()); if (trainPlanEntity.getIsTest().equals(SafeProductConstant.TRAIN_PLAN_HAS_NO_TEST)) { @@ -69,10 +77,12 @@ public class TestServiceImpl extends ServiceImpl impleme // 查询考试记录 TestEntity test = getTestByCode(testEntity.getCode()); // 获取姓名数组 - String people = test.getPeopleName(); + String people = testEntity.getPeopleName(); + String peopleId = testEntity.getPeopleId(); String[] person = people.split(","); + String[] peopleIds = peopleId.split(","); // 新增参考人员成绩数据 - List scoreList = getReferenceTestScore(test, person); + List scoreList = getReferenceTestScore(test, person,peopleIds); return R.status(testScoreService.saveBatch(scoreList)); } return R.fail("新增考试记录失败"); @@ -153,7 +163,7 @@ public class TestServiceImpl extends ServiceImpl impleme */ @Transactional(rollbackFor = Exception.class) @Override - public boolean updateTest(TestEntity testEntity) { + public boolean updateTest(TestDTO testEntity) { // 判断考试人员是否有变化 TestEntity oldTest = getTestByCode(testEntity.getCode()); // 更新考试记录 @@ -170,8 +180,9 @@ public class TestServiceImpl extends ServiceImpl impleme // 若删除成功,新增新的考试成绩数据 if (removeByIds) { String[] person = testEntity.getPeopleName().split(","); + String[] personId = testEntity.getPeopleId().split(","); // 新增参考人员成绩数据 - List scoreList = getReferenceTestScore(testEntity, person); + List scoreList = getReferenceTestScore(testEntity, person,personId); return testScoreService.saveBatch(scoreList); } } @@ -193,12 +204,25 @@ public class TestServiceImpl extends ServiceImpl impleme * @param person 参考人员 * @return 成绩列表 */ - private List getReferenceTestScore(TestEntity testEntity, String[] person) { + private List getReferenceTestScore(TestEntity testEntity, String[] person,String[] personId) { List res = new ArrayList<>(); - for (String name : person) { + for (int i = 0; i < person.length; i++) { TestScoreEntity testScoreEntity = new TestScoreEntity(); testScoreEntity.setTestId(testEntity.getId()); - testScoreEntity.setName(name); + testScoreEntity.setName(person[i]); + if (!"^".equals(personId[i])) { + testScoreEntity.setUserId(personId[i]); + User user = UserCache.getUser(Long.valueOf(personId[i])); + if (ObjectUtil.isNotEmpty(user)) { + testScoreEntity.setDeptId(user.getDeptId()); + R deptNameR = sysClient.getDeptName(Long.valueOf(personId[i])); + if (deptNameR.isSuccess() && StringUtils.isNotBlank(deptNameR.getData())) { + testScoreEntity.setDeptName(deptNameR.getData()); + } + } + }else { + testScoreEntity.setUserId(""); + } res.add(testScoreEntity); } return res;