parent
1fff660e43
commit
e40233c426
|
|
@ -5,6 +5,7 @@ import com.jjb.saas.framework.auth.utils.AuthContext;
|
|||
import com.zcloud.edu.domain.gateway.training.TrainingApplyProcessGateway;
|
||||
import com.zcloud.edu.domain.gateway.training.TrainingApplyRecordGateway;
|
||||
import com.zcloud.edu.domain.gateway.training.TrainingApplyUserGateway;
|
||||
import com.zcloud.edu.domain.gateway.training.TrainingUserGateway;
|
||||
import com.zcloud.edu.domain.model.training.TrainingApplyRecordE;
|
||||
import com.zcloud.edu.domain.model.training.TrainingApplyUserE;
|
||||
import com.zcloud.edu.dto.training.TrainingApplyRecordAddCmd;
|
||||
|
|
@ -32,6 +33,7 @@ public class TrainingApplyRecordAddExe {
|
|||
|
||||
private final TrainingApplyUserGateway trainingApplyUserGateway;
|
||||
private final TrainingApplyProcessGateway trainingApplyProcessGateway;
|
||||
private final TrainingUserGateway trainingUserGateway;
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public String execute(TrainingApplyRecordAddCmd cmd) {
|
||||
|
|
@ -52,6 +54,14 @@ public class TrainingApplyRecordAddExe {
|
|||
}
|
||||
}
|
||||
|
||||
// 保存培训人员
|
||||
if (!CollectionUtils.isEmpty(record.getTrainingUsers())) {
|
||||
boolean trainingUserResult = trainingUserGateway.addBatch(record.getTrainingUsers());
|
||||
if (!trainingUserResult) {
|
||||
throw new BizException("培训人员保存失败");
|
||||
}
|
||||
}
|
||||
|
||||
// 保存流程记录
|
||||
if (!CollectionUtils.isEmpty(record.getProcesses())) {
|
||||
boolean processResult = trainingApplyProcessGateway.addBatch(record.getProcesses());
|
||||
|
|
|
|||
|
|
@ -1,24 +1,16 @@
|
|||
package com.zcloud.edu.command.training;
|
||||
|
||||
import com.alibaba.cola.exception.BizException;
|
||||
import com.jjb.saas.framework.auth.model.SSOUser;
|
||||
import com.jjb.saas.framework.auth.utils.AuthContext;
|
||||
import com.zcloud.edu.domain.gateway.training.TrainingApplyProcessGateway;
|
||||
import com.zcloud.edu.domain.gateway.training.TrainingApplyRecordGateway;
|
||||
import com.zcloud.edu.domain.gateway.training.TrainingApplyUserGateway;
|
||||
import com.zcloud.edu.domain.gateway.training.TrainingUserGateway;
|
||||
import com.zcloud.edu.domain.model.training.TrainingApplyRecordE;
|
||||
import com.zcloud.edu.dto.training.TrainingApplyRecordUpdateCmd;
|
||||
import com.zcloud.edu.persistence.dataobject.TrainingApplyRecordDO;
|
||||
import com.zcloud.edu.persistence.repository.training.TrainingUserRepository;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* web-app
|
||||
* @Author makejava
|
||||
|
|
@ -41,7 +33,6 @@ public class TrainingApplyRecordUpdateExe {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 审批
|
||||
*/
|
||||
|
|
@ -52,18 +43,21 @@ public class TrainingApplyRecordUpdateExe {
|
|||
BeanUtils.copyProperties(trainingApplyRecordUpdateCmd, trainingApplyRecordE);
|
||||
trainingApplyRecordE.approve(oldTrainingRecord.getApprovalStatus());
|
||||
trainingApplyRecordE.addTrainingUser();
|
||||
|
||||
// 修改申请人员状态
|
||||
boolean updateUserStatus = trainingApplyUserGateway.updateStatusByApprove(trainingApplyRecordE.getApplyUsers());
|
||||
if (!updateUserStatus) {
|
||||
throw new BizException("修改申请人员状态失败");
|
||||
}
|
||||
boolean addTrainingUser = trainingUserGateway.addBatch(trainingApplyRecordE.getTrainingUsers());
|
||||
if (!addTrainingUser) {
|
||||
throw new BizException("新增培训人员失败");
|
||||
// 修改培训人员状态
|
||||
boolean updateTrainingUserStatus = trainingUserGateway.updateStatusByApprove(trainingApplyRecordE.getTrainingUsers());
|
||||
if (!updateTrainingUserStatus) {
|
||||
throw new BizException("修改培训人员状态失败");
|
||||
}
|
||||
|
||||
boolean res = trainingApplyRecordGateway.update(trainingApplyRecordE);
|
||||
if (!res) {
|
||||
throw new BizException("修改失败");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -12,13 +12,18 @@ public interface TrainingUserGateway {
|
|||
/**
|
||||
* 新增
|
||||
*/
|
||||
Boolean add(TrainingUserE trainingUserE) ;
|
||||
Boolean add(TrainingUserE trainingUserE);
|
||||
|
||||
/**
|
||||
* 批量新增
|
||||
*/
|
||||
Boolean addBatch(java.util.List<TrainingUserE> trainingUserEList);
|
||||
|
||||
/**
|
||||
* 审批通过后更新培训人员状态
|
||||
*/
|
||||
Boolean updateStatusByApprove(java.util.List<TrainingUserE> trainingUserEList);
|
||||
|
||||
/**
|
||||
* 修改
|
||||
*/
|
||||
|
|
@ -30,4 +35,3 @@ public interface TrainingUserGateway {
|
|||
Boolean deletedTrainingUserById(Long id);
|
||||
Boolean deletedTrainingUserByIds(Long[] id);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -8,14 +8,14 @@ import com.jjb.saas.framework.domain.model.BaseE;
|
|||
import com.zcloud.edu.domain.enums.ApplyStatusEnum;
|
||||
import com.zcloud.edu.domain.enums.ApplyTypeEnum;
|
||||
import com.zcloud.edu.domain.enums.ApprovalStatusEnum;
|
||||
import com.zcloud.edu.domain.enums.ExamineStatusEnum;
|
||||
import com.zcloud.gbscommon.utils.Tools;
|
||||
import lombok.Data;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* web-domain
|
||||
|
|
@ -48,24 +48,24 @@ public class TrainingApplyRecordE extends BaseE {
|
|||
private Long approvalUserId;
|
||||
//审批用户名称
|
||||
private String approvalUserName;
|
||||
// 关联项目
|
||||
//关联项目
|
||||
private String projectName;
|
||||
//审批状态1:待审批2:审批中,3:审批完成
|
||||
//审批状态:1待审批,2审批中,3审批完成
|
||||
private Long approvalStatus;
|
||||
|
||||
// 申请人员列表
|
||||
//申请人员列表
|
||||
private List<TrainingApplyUserE> applyUsers = new ArrayList<>();
|
||||
|
||||
// 审批流程列表
|
||||
//审批流程列表
|
||||
private List<TrainingApplyProcessE> processes = new ArrayList<>();
|
||||
|
||||
// 审批人员列表
|
||||
//审批人员列表
|
||||
private List<TrainingApplyUserE> approvalUsers;
|
||||
|
||||
// 审批和委托信息
|
||||
//审批和委托信息
|
||||
private List<ApproveDetailE> approveDetails;
|
||||
|
||||
// 培训人员
|
||||
//培训人员
|
||||
private List<TrainingUserE> trainingUsers = new ArrayList<>();
|
||||
|
||||
/**
|
||||
|
|
@ -76,19 +76,31 @@ public class TrainingApplyRecordE extends BaseE {
|
|||
this.applyUserId = ssoUser.getUserId();
|
||||
this.applyDepartmentId = ssoUser.getOrgId();
|
||||
this.applyCorpinfoId = ssoUser.getTenantId();
|
||||
}else {
|
||||
} else {
|
||||
throw new BizException("参数异常");
|
||||
}
|
||||
this.trainingApplyRecordId = StrUtil.isNotBlank(this.trainingApplyRecordId) ? this.trainingApplyRecordId : IdUtil.simpleUUID();
|
||||
this.trainingApplyRecordId = StrUtil.isNotBlank(this.trainingApplyRecordId)
|
||||
? this.trainingApplyRecordId : IdUtil.simpleUUID();
|
||||
|
||||
this.approvalStatus = ApprovalStatusEnum.PENDING.getCode();
|
||||
|
||||
// 初始化申请人员
|
||||
if (!CollectionUtils.isEmpty(this.applyUsers)) {
|
||||
Set<String> trainingUserPhones = new HashSet<>();
|
||||
this.applyUsers.forEach(user -> {
|
||||
user.setTrainingApplyUserId(StrUtil.isBlank(user.getTrainingApplyUserId()) ? IdUtil.simpleUUID() : user.getTrainingApplyUserId());
|
||||
user.setTrainingApplyUserId(
|
||||
StrUtil.isBlank(user.getTrainingApplyUserId()) ? IdUtil.simpleUUID() : user.getTrainingApplyUserId());
|
||||
user.setTrainingApplyRecordId(this.trainingApplyRecordId);
|
||||
user.setApplyStatus(ApplyStatusEnum.PENDING.getCode());
|
||||
|
||||
String phone = user.getPhone();
|
||||
if (StrUtil.isNotBlank(phone) && trainingUserPhones.add(phone)) {
|
||||
TrainingUserE trainingUser = new TrainingUserE();
|
||||
trainingUser.setTrainingUserId(Tools.get32UUID());
|
||||
trainingUser.setPhone(phone);
|
||||
trainingUser.setApplyStatus(ApplyStatusEnum.PENDING.getCode());
|
||||
trainingUsers.add(trainingUser);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -117,7 +129,7 @@ public class TrainingApplyRecordE extends BaseE {
|
|||
/**
|
||||
* 审批通过
|
||||
*/
|
||||
public void approve(Long approvalStatus){
|
||||
public void approve(Long approvalStatus) {
|
||||
// 状态校验
|
||||
if (!ApprovalStatusEnum.PENDING.getCode().equals(approvalStatus)
|
||||
&& !ApprovalStatusEnum.APPROVING.getCode().equals(approvalStatus)) {
|
||||
|
|
@ -127,23 +139,26 @@ public class TrainingApplyRecordE extends BaseE {
|
|||
if (CollectionUtils.isEmpty(this.applyUsers)) {
|
||||
throw new BizException("申请人员列表不能为空");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加培训人员
|
||||
*/
|
||||
public void addTrainingUser() {
|
||||
if (this.applyUsers == null) return;
|
||||
if (this.applyUsers == null) {
|
||||
return;
|
||||
}
|
||||
applyUsers.forEach(user -> {
|
||||
if (user != null && user.getApplyStatus().equals(ApplyStatusEnum.APPROVED.getCode())) {
|
||||
TrainingUserE trainingUser = new TrainingUserE();
|
||||
trainingUser.setTrainingUserId(IdUtil.simpleUUID());
|
||||
trainingUser.setPhone(user.getPhone());
|
||||
trainingUser.setApplyStatus(user.getApplyStatus());
|
||||
this.trainingUsers.add(trainingUser);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量添加申请人员
|
||||
*/
|
||||
|
|
@ -161,7 +176,4 @@ public class TrainingApplyRecordE extends BaseE {
|
|||
this.approveDetails = approveDetails;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,6 +1,8 @@
|
|||
package com.zcloud.edu.gatewayimpl.training;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.zcloud.edu.domain.enums.ApplyStatusEnum;
|
||||
import com.zcloud.edu.domain.gateway.training.TrainingUserGateway;
|
||||
import com.zcloud.edu.domain.model.training.TrainingUserE;
|
||||
import com.zcloud.edu.persistence.dataobject.TrainingUserDO;
|
||||
|
|
@ -10,9 +12,8 @@ import com.zcloud.gbscommon.utils.Tools;
|
|||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.*;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
|
|
@ -36,22 +37,41 @@ public class TrainingUserGatewayImpl implements TrainingUserGateway {
|
|||
|
||||
@Override
|
||||
public Boolean addBatch(List<TrainingUserE> trainingUserEList) {
|
||||
if (trainingUserEList == null || trainingUserEList.isEmpty()) {
|
||||
List<String> phones = getPhoneList(trainingUserEList);
|
||||
if (phones.isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
List<String> phones = trainingUserEList.stream()
|
||||
.map(TrainingUserE::getPhone)
|
||||
.filter(StrUtil::isNotBlank)
|
||||
.distinct()
|
||||
.collect(Collectors.toList());
|
||||
|
||||
List<TrainingUserDO> existingUsers = trainingUserRepository.lambdaQuery()
|
||||
.select(TrainingUserDO::getPhone)
|
||||
.select(TrainingUserDO::getPhone, TrainingUserDO::getStartTime, TrainingUserDO::getEndTime)
|
||||
.in(TrainingUserDO::getPhone, phones)
|
||||
.list();
|
||||
Set<String> existingPhones = existingUsers.stream()
|
||||
.map(TrainingUserDO::getPhone)
|
||||
Map<String, TrainingUserDO> existingUserMap = existingUsers.stream()
|
||||
.collect(Collectors.toMap(TrainingUserDO::getPhone, u -> u, (a, b) -> a));
|
||||
Set<String> existingPhones = existingUserMap.keySet();
|
||||
|
||||
LocalDateTime submitTime = LocalDateTime.now();
|
||||
Set<String> resetPhones = trainingUserEList.stream()
|
||||
.map(TrainingUserE::getPhone)
|
||||
.filter(StrUtil::isNotBlank)
|
||||
.filter(existingPhones::contains)
|
||||
.filter(phone -> {
|
||||
TrainingUserDO user = existingUserMap.get(phone);
|
||||
return user != null
|
||||
&& user.getEndTime() != null
|
||||
&& submitTime.isAfter(user.getEndTime());
|
||||
})
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
for (String phone : resetPhones) {
|
||||
trainingUserRepository.lambdaUpdate()
|
||||
.set(TrainingUserDO::getStartTime, null)
|
||||
.set(TrainingUserDO::getEndTime, null)
|
||||
.set(TrainingUserDO::getApplyStatus, ApplyStatusEnum.PENDING.getCode())
|
||||
.eq(TrainingUserDO::getPhone, phone)
|
||||
.update();
|
||||
}
|
||||
|
||||
List<TrainingUserDO> doList = trainingUserEList.stream()
|
||||
.filter(e -> StrUtil.isNotBlank(e.getPhone())
|
||||
&& !existingPhones.contains(e.getPhone()))
|
||||
|
|
@ -69,6 +89,54 @@ public class TrainingUserGatewayImpl implements TrainingUserGateway {
|
|||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean updateStatusByApprove(List<TrainingUserE> trainingUserEList) {
|
||||
List<String> phones = getPhoneList(trainingUserEList);
|
||||
if (phones.isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
List<TrainingUserDO> existingUsers = trainingUserRepository.lambdaQuery()
|
||||
.select(TrainingUserDO::getId, TrainingUserDO::getPhone, TrainingUserDO::getApplyStatus)
|
||||
.in(TrainingUserDO::getPhone, phones)
|
||||
.list();
|
||||
if (existingUsers == null || existingUsers.isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
List<TrainingUserDO> needUpdateUsers = existingUsers.stream()
|
||||
.filter(u -> !ApplyStatusEnum.APPROVED.getCode().equals(u.getApplyStatus()))
|
||||
.map(u -> {
|
||||
TrainingUserDO d = new TrainingUserDO();
|
||||
d.setId(u.getId());
|
||||
d.setApplyStatus(ApplyStatusEnum.APPROVED.getCode());
|
||||
return d;
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
|
||||
if (needUpdateUsers.isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return trainingUserRepository.updateBatchById(needUpdateUsers);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取培训人员手机号
|
||||
* @param trainingUserEList
|
||||
* @return
|
||||
*/
|
||||
private List<String> getPhoneList(List<TrainingUserE> trainingUserEList) {
|
||||
if (CollUtil.isEmpty(trainingUserEList)) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return trainingUserEList.stream()
|
||||
.map(TrainingUserE::getPhone)
|
||||
.filter(StrUtil::isNotBlank)
|
||||
.distinct()
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean update(TrainingUserE trainingUserE) {
|
||||
TrainingUserDO d = new TrainingUserDO();
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@
|
|||
r.project_name,
|
||||
r.approval_status,
|
||||
r.version,
|
||||
u.username AS apply_user_name,
|
||||
u.name AS apply_user_name,
|
||||
COALESCE(tau_cnt.apply_user_count, 0) AS apply_user_count
|
||||
FROM
|
||||
training_apply_record r
|
||||
|
|
|
|||
Loading…
Reference in New Issue