|
|
@ -1,6 +1,7 @@ |
|
|
|
package com.hnac.hzims.safeproduct.service.impl; |
|
|
|
package com.hnac.hzims.safeproduct.service.impl; |
|
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.date.DatePattern; |
|
|
|
import cn.hutool.core.date.DatePattern; |
|
|
|
|
|
|
|
import cn.hutool.core.util.ObjectUtil; |
|
|
|
import com.alibaba.excel.util.CollectionUtils; |
|
|
|
import com.alibaba.excel.util.CollectionUtils; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
|
|
|
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.ITestScoreService; |
|
|
|
import com.hnac.hzims.safeproduct.service.ITestService; |
|
|
|
import com.hnac.hzims.safeproduct.service.ITestService; |
|
|
|
import com.hnac.hzims.safeproduct.utils.BaseUtil; |
|
|
|
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.mp.support.Query; |
|
|
|
import org.springblade.core.tool.api.R; |
|
|
|
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.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
@ -36,8 +43,9 @@ import java.util.stream.Collectors; |
|
|
|
* @date 2023-12-25 |
|
|
|
* @date 2023-12-25 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@Service |
|
|
|
@Service |
|
|
|
|
|
|
|
@RequiredArgsConstructor |
|
|
|
public class TestServiceImpl extends ServiceImpl<TestMapper, TestEntity> implements ITestService { |
|
|
|
public class TestServiceImpl extends ServiceImpl<TestMapper, TestEntity> implements ITestService { |
|
|
|
|
|
|
|
private final ISysClient sysClient; |
|
|
|
@Autowired |
|
|
|
@Autowired |
|
|
|
ITestScoreService testScoreService; |
|
|
|
ITestScoreService testScoreService; |
|
|
|
|
|
|
|
|
|
|
@ -49,7 +57,7 @@ public class TestServiceImpl extends ServiceImpl<TestMapper, TestEntity> impleme |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public R saveTest(TestEntity testEntity) { |
|
|
|
public R saveTest(TestDTO testEntity) { |
|
|
|
// 判断培训计划是否需要考试,若不需要,则无法新增考试记录
|
|
|
|
// 判断培训计划是否需要考试,若不需要,则无法新增考试记录
|
|
|
|
TrainPlanEntity trainPlanEntity = trainPlanMapper.selectById(testEntity.getTrainPlanId()); |
|
|
|
TrainPlanEntity trainPlanEntity = trainPlanMapper.selectById(testEntity.getTrainPlanId()); |
|
|
|
if (trainPlanEntity.getIsTest().equals(SafeProductConstant.TRAIN_PLAN_HAS_NO_TEST)) { |
|
|
|
if (trainPlanEntity.getIsTest().equals(SafeProductConstant.TRAIN_PLAN_HAS_NO_TEST)) { |
|
|
@ -69,10 +77,12 @@ public class TestServiceImpl extends ServiceImpl<TestMapper, TestEntity> impleme |
|
|
|
// 查询考试记录
|
|
|
|
// 查询考试记录
|
|
|
|
TestEntity test = getTestByCode(testEntity.getCode()); |
|
|
|
TestEntity test = getTestByCode(testEntity.getCode()); |
|
|
|
// 获取姓名数组
|
|
|
|
// 获取姓名数组
|
|
|
|
String people = test.getPeopleName(); |
|
|
|
String people = testEntity.getPeopleName(); |
|
|
|
|
|
|
|
String peopleId = testEntity.getPeopleId(); |
|
|
|
String[] person = people.split(","); |
|
|
|
String[] person = people.split(","); |
|
|
|
|
|
|
|
String[] peopleIds = peopleId.split(","); |
|
|
|
// 新增参考人员成绩数据
|
|
|
|
// 新增参考人员成绩数据
|
|
|
|
List<TestScoreEntity> scoreList = getReferenceTestScore(test, person); |
|
|
|
List<TestScoreEntity> scoreList = getReferenceTestScore(test, person,peopleIds); |
|
|
|
return R.status(testScoreService.saveBatch(scoreList)); |
|
|
|
return R.status(testScoreService.saveBatch(scoreList)); |
|
|
|
} |
|
|
|
} |
|
|
|
return R.fail("新增考试记录失败"); |
|
|
|
return R.fail("新增考试记录失败"); |
|
|
@ -153,7 +163,7 @@ public class TestServiceImpl extends ServiceImpl<TestMapper, TestEntity> impleme |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public boolean updateTest(TestEntity testEntity) { |
|
|
|
public boolean updateTest(TestDTO testEntity) { |
|
|
|
// 判断考试人员是否有变化
|
|
|
|
// 判断考试人员是否有变化
|
|
|
|
TestEntity oldTest = getTestByCode(testEntity.getCode()); |
|
|
|
TestEntity oldTest = getTestByCode(testEntity.getCode()); |
|
|
|
// 更新考试记录
|
|
|
|
// 更新考试记录
|
|
|
@ -170,8 +180,9 @@ public class TestServiceImpl extends ServiceImpl<TestMapper, TestEntity> impleme |
|
|
|
// 若删除成功,新增新的考试成绩数据
|
|
|
|
// 若删除成功,新增新的考试成绩数据
|
|
|
|
if (removeByIds) { |
|
|
|
if (removeByIds) { |
|
|
|
String[] person = testEntity.getPeopleName().split(","); |
|
|
|
String[] person = testEntity.getPeopleName().split(","); |
|
|
|
|
|
|
|
String[] personId = testEntity.getPeopleId().split(","); |
|
|
|
// 新增参考人员成绩数据
|
|
|
|
// 新增参考人员成绩数据
|
|
|
|
List<TestScoreEntity> scoreList = getReferenceTestScore(testEntity, person); |
|
|
|
List<TestScoreEntity> scoreList = getReferenceTestScore(testEntity, person,personId); |
|
|
|
return testScoreService.saveBatch(scoreList); |
|
|
|
return testScoreService.saveBatch(scoreList); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -193,12 +204,25 @@ public class TestServiceImpl extends ServiceImpl<TestMapper, TestEntity> impleme |
|
|
|
* @param person 参考人员 |
|
|
|
* @param person 参考人员 |
|
|
|
* @return 成绩列表 |
|
|
|
* @return 成绩列表 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private List<TestScoreEntity> getReferenceTestScore(TestEntity testEntity, String[] person) { |
|
|
|
private List<TestScoreEntity> getReferenceTestScore(TestEntity testEntity, String[] person,String[] personId) { |
|
|
|
List<TestScoreEntity> res = new ArrayList<>(); |
|
|
|
List<TestScoreEntity> res = new ArrayList<>(); |
|
|
|
for (String name : person) { |
|
|
|
for (int i = 0; i < person.length; i++) { |
|
|
|
TestScoreEntity testScoreEntity = new TestScoreEntity(); |
|
|
|
TestScoreEntity testScoreEntity = new TestScoreEntity(); |
|
|
|
testScoreEntity.setTestId(testEntity.getId()); |
|
|
|
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<String> deptNameR = sysClient.getDeptName(Long.valueOf(personId[i])); |
|
|
|
|
|
|
|
if (deptNameR.isSuccess() && StringUtils.isNotBlank(deptNameR.getData())) { |
|
|
|
|
|
|
|
testScoreEntity.setDeptName(deptNameR.getData()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}else { |
|
|
|
|
|
|
|
testScoreEntity.setUserId(""); |
|
|
|
|
|
|
|
} |
|
|
|
res.add(testScoreEntity); |
|
|
|
res.add(testScoreEntity); |
|
|
|
} |
|
|
|
} |
|
|
|
return res; |
|
|
|
return res; |
|
|
|