@@ -0,0 +1,57 @@ | |||
package com.ningdatech.pmapi.common.util; | |||
import com.ningdatech.basic.exception.BizException; | |||
import com.ningdatech.basic.model.GenericResult; | |||
import com.ningdatech.pmapi.todocenter.bean.entity.WorkNoticeInfo; | |||
import com.ningdatech.zwdd.client.ZwddClient; | |||
import lombok.extern.slf4j.Slf4j; | |||
import java.util.concurrent.*; | |||
/** | |||
* 异步发送工作通知工具类 | |||
* | |||
* @author CMM | |||
* @since 2023/02/23 13:50 | |||
*/ | |||
@Slf4j | |||
public class SendWorkNoticeUtil { | |||
private SendWorkNoticeUtil(){ | |||
} | |||
public static void sendWorkNotice(ZwddClient zwddClient, WorkNoticeInfo workNoticeInfo, String msg){ | |||
// 初始化线程池 | |||
ThreadPoolExecutor threadPool = new ThreadPoolExecutor(10, 20, | |||
60, TimeUnit.SECONDS, new ArrayBlockingQueue(20), new ThreadPoolExecutor.AbortPolicy()); | |||
// 将发送工作通知交给异步任务Future | |||
CompletableFuture<String> future = CompletableFuture.supplyAsync(() -> { | |||
// 调用浙政钉的接口发送工作通知 | |||
long startTime = System.currentTimeMillis(); | |||
GenericResult<Void> result = | |||
zwddClient.sendWorkNotice(workNoticeInfo.getReceiverUserId(), workNoticeInfo.getBizMsgId(), msg); | |||
String resultMsg = result.getMsg(); | |||
if (resultMsg.equals("success")) { | |||
log.info("异步任务执行完成, " + workNoticeInfo.getBizMsgId() + " 当前线程:" + Thread.currentThread().getName()); | |||
long endTime = System.currentTimeMillis(); | |||
log.info("方法执行完成返回,耗时:" + (endTime - startTime)); | |||
}else { | |||
return "发送工作通知失败!"; | |||
} | |||
return "发送工作通知成功!"; | |||
}, threadPool); | |||
String s; | |||
try { | |||
s = future.get(); | |||
} catch (Exception e) { | |||
throw new BizException("获取异步线程处理结果失败!"); | |||
} | |||
threadPool.shutdown(); | |||
while (threadPool.isTerminated()) { | |||
log.info(s); | |||
break; | |||
} | |||
} | |||
} |
@@ -5,12 +5,14 @@ import cn.hutool.core.util.StrUtil; | |||
import com.baomidou.mybatisplus.core.toolkit.Wrappers; | |||
import com.google.common.collect.Sets; | |||
import com.ningdatech.basic.exception.BizException; | |||
import com.ningdatech.basic.model.GenericResult; | |||
import com.ningdatech.basic.model.PageVo; | |||
import com.ningdatech.pmapi.common.constant.CommonConstant; | |||
import com.ningdatech.pmapi.common.model.entity.ExcelExportWriter; | |||
import com.ningdatech.pmapi.common.statemachine.event.ProjectStatusChangeEvent; | |||
import com.ningdatech.pmapi.common.statemachine.util.StateMachineUtils; | |||
import com.ningdatech.pmapi.common.util.ExcelDownUtil; | |||
import com.ningdatech.pmapi.common.util.SendWorkNoticeUtil; | |||
import com.ningdatech.pmapi.organization.model.entity.DingEmployeeInfo; | |||
import com.ningdatech.pmapi.organization.model.entity.DingOrganization; | |||
import com.ningdatech.pmapi.organization.service.IDingEmployeeInfoService; | |||
@@ -36,6 +38,7 @@ import com.wflow.contants.HisProInsEndActId; | |||
import com.wflow.workflow.bean.dto.ProcessInstanceUserDto; | |||
import com.wflow.workflow.bean.dto.ReqProcessHandlerDTO; | |||
import com.wflow.workflow.bean.process.ProgressNode; | |||
import com.wflow.workflow.bean.process.enums.NodeTypeEnum; | |||
import com.wflow.workflow.bean.vo.ProcessInstanceVo; | |||
import com.wflow.workflow.bean.vo.ProcessProgressVo; | |||
import com.wflow.workflow.bean.vo.ProcessTaskVo; | |||
@@ -53,6 +56,10 @@ import org.springframework.stereotype.Component; | |||
import javax.servlet.http.HttpServletResponse; | |||
import java.time.LocalDateTime; | |||
import java.util.*; | |||
import java.util.concurrent.CompletableFuture; | |||
import java.util.concurrent.ExecutionException; | |||
import java.util.concurrent.ExecutorService; | |||
import java.util.concurrent.Executors; | |||
import java.util.stream.Collectors; | |||
import static cn.hutool.core.collection.CollUtil.isEmpty; | |||
@@ -221,7 +228,16 @@ public class TodoCenterManage { | |||
// 获取流程通过后当前审核人信息,向其发送工作通知 | |||
List<ProgressNode> newProgressInfo = newInstanceDetail.getProgressInfo(); | |||
ProgressNode currentNode = newProgressInfo.get(newProgressInfo.size() - 1); | |||
UserInfo auditUserInfo = userInfoService.getById(Long.valueOf(currentNode.getUserId())); | |||
UserInfo auditUserInfo = null; | |||
// 说明当前节点是子流程节点 | |||
if (currentNode.getNodeType().name().equals(NodeTypeEnum.SUB.name())){ | |||
List<ProgressNode> children = currentNode.getChildren(); | |||
// 获取子流程当前审核人节点 | |||
ProgressNode subCurrentNode = children.get(children.size() - 1); | |||
auditUserInfo = userInfoService.getById(Long.valueOf(subCurrentNode.getUserId())); | |||
}else { | |||
auditUserInfo = userInfoService.getById(Long.valueOf(currentNode.getUserId())); | |||
} | |||
// 如果流程状态是被退回状态,流程通过后,进入下一个审核人, | |||
// 当前通过审核人一定不是最后一个审核人(下一个审核人至多是最后一个),更新流程状态为审核中 | |||
@@ -233,8 +249,9 @@ public class TodoCenterManage { | |||
projectService.updateById(declaredProject); | |||
// 获取发送浙政钉工作通知必要信息 | |||
WorkNoticeInfo passWorkNoticeInfo = getSendWorkNoticeInfo(auditUserInfo); | |||
String passMsg = String.format(PASS_MSG_TEMPLATE, null, projectName); | |||
// zwddClient.sendWorkNotice(passWorkNoticeInfo.getReceiverUserId(),passWorkNoticeInfo.getBizMsgId(),passMsg); | |||
String passMsg = String.format(PASS_MSG_TEMPLATE, passWorkNoticeInfo.getOrganizationName(), projectName); | |||
// 异步发送工作通知 | |||
// SendWorkNoticeUtil.sendWorkNotice(zwddClient,passWorkNoticeInfo,passMsg); | |||
return; | |||
} | |||
// 若不是被退回状态,流程通过后,判断当前登录用户是不是最后一个审核人 | |||
@@ -263,14 +280,16 @@ public class TodoCenterManage { | |||
} | |||
WorkNoticeInfo passWorkNoticeInfo2 = getSendWorkNoticeInfo(startUserInfo); | |||
String passMsg2 = String.format(PASS_MSG_TEMPLATE2, projectName, processDefinitionName); | |||
// zwddClient.sendWorkNotice(passWorkNoticeInfo2.getReceiverUserId(),passWorkNoticeInfo2.getBizMsgId(),passMsg2); | |||
// 异步发送工作通知 | |||
// SendWorkNoticeUtil.sendWorkNotice(zwddClient,passWorkNoticeInfo2,passMsg2); | |||
}else { | |||
// 若有下一个审核人(当前节点的用户), | |||
// 向其发送浙政钉工作通知:标题:审核任务 内容:【单位名称】的【项目名称】需要您审核。 | |||
// 获取发送浙政钉工作通知必要信息 | |||
WorkNoticeInfo sendWorkNoticeInfo = getSendWorkNoticeInfo(auditUserInfo); | |||
String msg = String.format(PASS_MSG_TEMPLATE, null, projectName); | |||
// zwddClient.sendWorkNotice(sendWorkNoticeInfo.getReceiverUserId(),sendWorkNoticeInfo.getBizMsgId(),msg); | |||
// 异步发送工作通知 | |||
// SendWorkNoticeUtil.sendWorkNotice(zwddClient,sendWorkNoticeInfo,msg); | |||
} | |||
break; | |||
// 盖章并通过 | |||
@@ -285,7 +304,8 @@ public class TodoCenterManage { | |||
processTaskService.handleTask(param, userId); | |||
WorkNoticeInfo rejectWorkNoticeInfo = getSendWorkNoticeInfo(startUserInfo); | |||
String rejectMsg = String.format(REJECT_MSG_TEMPLATE, projectName, processDefinitionName); | |||
// zwddClient.sendWorkNotice(rejectWorkNoticeInfo.getReceiverUserId(),rejectWorkNoticeInfo.getBizMsgId(),rejectMsg); | |||
// 异步发送工作通知 | |||
// SendWorkNoticeUtil.sendWorkNotice(zwddClient,rejectWorkNoticeInfo,rejectMsg); | |||
// 更新项目状态和流程状态 | |||
updateRejectProjectStatus(userId, declaredProject); | |||
break; | |||
@@ -301,7 +321,8 @@ public class TodoCenterManage { | |||
// 给项目创建人、流程发起人发送浙政钉工作通知:【项目名称】的【流程名称】被退回,请及时处理。 | |||
WorkNoticeInfo backWorkNoticeInfo = getSendWorkNoticeInfo(startUserInfo); | |||
String backMsg = String.format(BACK_MSG_TEMPLATE, projectName, processDefinitionName); | |||
// zwddClient.sendWorkNotice(backWorkNoticeInfo.getReceiverUserId(),backWorkNoticeInfo.getBizMsgId(),backMsg); | |||
// 异步发送工作通知 | |||
// SendWorkNoticeUtil.sendWorkNotice(zwddClient,backWorkNoticeInfo,backMsg); | |||
break; | |||
// 撤回(流程发起人和当前流程审核人的前一个审核人操作) | |||
case WITHDRAW: | |||
@@ -15,24 +15,17 @@ import com.ningdatech.pmapi.sys.model.entity.Role; | |||
import com.ningdatech.pmapi.sys.model.entity.UserRole; | |||
import com.ningdatech.pmapi.sys.service.IRoleService; | |||
import com.ningdatech.pmapi.sys.service.IUserRoleService; | |||
import com.ningdatech.pmapi.user.constant.LoginTypeEnum; | |||
import com.ningdatech.pmapi.user.constant.UserAvailableEnum; | |||
import com.ningdatech.pmapi.user.entity.UserInfo; | |||
import com.ningdatech.pmapi.user.model.po.*; | |||
import com.ningdatech.pmapi.user.model.vo.ResUserDetailVO; | |||
import com.ningdatech.pmapi.user.model.vo.ResUserInfoListVO; | |||
import com.ningdatech.pmapi.user.model.vo.UserRoleVO; | |||
import com.ningdatech.pmapi.user.security.auth.constants.UserDeatilsServiceConstant; | |||
import com.ningdatech.pmapi.user.security.auth.credential.CredentialAuthToken; | |||
import com.ningdatech.pmapi.user.security.auth.model.UserFullInfoDTO; | |||
import com.ningdatech.pmapi.user.service.IUserInfoService; | |||
import com.ningdatech.pmapi.user.util.LoginUserUtil; | |||
import lombok.RequiredArgsConstructor; | |||
import org.springframework.security.core.AuthenticationException; | |||
import org.springframework.security.core.context.SecurityContextHolder; | |||
import org.springframework.security.core.userdetails.UserDetailsService; | |||
import org.springframework.security.web.authentication.WebAuthenticationDetails; | |||
import org.springframework.security.web.context.HttpSessionSecurityContextRepository; | |||
import org.springframework.stereotype.Component; | |||
import org.springframework.transaction.annotation.Transactional; | |||
@@ -232,8 +225,32 @@ public class UserInfoManage { | |||
public ResUserDetailVO currentUserInfo() { | |||
Long userId = LoginUserUtil.getUserId(); | |||
UserFullInfoDTO userFullInfo = userInfoHelper.getUserFullInfo(userId); | |||
return null; | |||
UserInfo userInfo = iUserInfoService.getById(userId); | |||
if (Objects.isNull(userInfo)) { | |||
return null; | |||
} | |||
ResUserDetailVO resUserDetailVO = new ResUserDetailVO(); | |||
resUserDetailVO.setRealName(userInfo.getRealName()); | |||
resUserDetailVO.setUserId(userInfo.getId()); | |||
resUserDetailVO.setPhoneNo(userInfo.getMobile()); | |||
resUserDetailVO.setStatus(userInfo.getAvailable()); | |||
// 装配用户角色信息列表 | |||
List<UserRole> userRoleList = iUserRoleService.list(Wrappers.lambdaQuery(UserRole.class) | |||
.eq(UserRole::getUserId, userId)); | |||
List<UserRoleVO> userRoleInfoList = new ArrayList<>(); | |||
if (CollUtil.isNotEmpty(userRoleList)) { | |||
List<Long> roleIdList = userRoleList.stream().map(UserRole::getRoleId).collect(Collectors.toList()); | |||
List<Role> roleList = iRoleService.list(Wrappers.lambdaQuery(Role.class).in(Role::getId, roleIdList)); | |||
userRoleInfoList = roleList.stream().map(r -> { | |||
UserRoleVO userRoleVO = new UserRoleVO(); | |||
userRoleVO.setId(r.getId()); | |||
userRoleVO.setName(r.getName()); | |||
return userRoleVO; | |||
}).collect(Collectors.toList()); | |||
} | |||
resUserDetailVO.setUserRoleInfoList(userRoleInfoList); | |||
return resUserDetailVO; | |||
} | |||
public void generationLogin(ReqGenerationLoginPO reqGenerationLoginPO) { | |||
@@ -4,6 +4,7 @@ import io.swagger.annotations.ApiModel; | |||
import io.swagger.annotations.ApiModelProperty; | |||
import lombok.Data; | |||
import java.time.LocalDateTime; | |||
import java.util.List; | |||
/** | |||
@@ -23,9 +24,27 @@ public class ResUserDetailVO { | |||
@ApiModelProperty("手机号") | |||
private String phoneNo; | |||
@ApiModelProperty("用户角色信息列表") | |||
private List<UserRoleVO> userRoleInfoList; | |||
@ApiModelProperty("浙政钉 用户编码") | |||
private String employeeCode; | |||
@ApiModelProperty("所在单位(主职)") | |||
private String orgName; | |||
@ApiModelProperty("所在单位(主职)code") | |||
private String orgCode; | |||
@ApiModelProperty("所属区域") | |||
private Long regionId; | |||
@ApiModelProperty("用户角色") | |||
private List<UserRoleVO> userRoleList; | |||
@ApiModelProperty("状态 启用 ENABLE/禁用 DISABLE") | |||
private String status; | |||
@ApiModelProperty("用户角色信息列表") | |||
private List<UserRoleVO> userRoleInfoList; | |||
@ApiModelProperty("更新时间") | |||
private LocalDateTime updateTime; | |||
} |
@@ -23,11 +23,11 @@ public class BeanConfig { | |||
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); | |||
// 设置核心线程数 | |||
executor.setCorePoolSize(50); | |||
executor.setCorePoolSize(2); | |||
// 设置最大线程数 | |||
executor.setMaxPoolSize(200); | |||
executor.setMaxPoolSize(10); | |||
// 设置队列容量 | |||
executor.setQueueCapacity(200); | |||
executor.setQueueCapacity(10); | |||
// 设置线程活跃时间(秒) | |||
executor.setKeepAliveSeconds(800); | |||
// 设置默认线程名称 | |||
@@ -1,6 +1,7 @@ | |||
package com.ningdatech.pmapi.todocenter; | |||
import com.ningdatech.basic.exception.BizException; | |||
import com.ningdatech.basic.model.GenericResult; | |||
import com.ningdatech.pmapi.AppTests; | |||
import com.ningdatech.pmapi.beanconfig.BeanConfig; | |||
import com.ningdatech.pmapi.todocenter.bean.entity.WorkNoticeInfo; | |||
@@ -17,10 +18,7 @@ import org.springframework.context.annotation.AnnotationConfigApplicationContext | |||
import org.springframework.core.task.TaskExecutor; | |||
import javax.annotation.Resource; | |||
import java.util.concurrent.CompletableFuture; | |||
import java.util.concurrent.ExecutionException; | |||
import java.util.concurrent.ExecutorService; | |||
import java.util.concurrent.Executors; | |||
import java.util.concurrent.*; | |||
import java.util.function.Supplier; | |||
import static com.ningdatech.pmapi.todocenter.constant.WorkNotice.PASS_MSG_TEMPLATE; | |||
@@ -34,8 +32,8 @@ import static com.ningdatech.pmapi.todocenter.constant.WorkNotice.PASS_MSG_TEMPL | |||
@Slf4j | |||
public class TodoCenterTest extends AppTests { | |||
@Autowired | |||
private TaskExecutor taskExecutor; | |||
//@Autowired | |||
//private TaskExecutor executor; | |||
@Autowired | |||
private TodoCenterManage todoCenterManage; | |||
@@ -46,7 +44,7 @@ public class TodoCenterTest extends AppTests { | |||
@Autowired | |||
private ZwddClient zwddClient; | |||
@Test | |||
public void sendWorkNoticeTest() { | |||
public void sendWorkNoticeTest() throws ExecutionException, InterruptedException { | |||
//String msg = String.format(PASS_MSG_TEMPLATE, "发改委", "0223-00-测试项目"); | |||
//log.info("开始发送工作通知"); | |||
//zwddClient.sendWorkNotice("846085", "0223-00", msg); | |||
@@ -62,37 +60,37 @@ public class TodoCenterTest extends AppTests { | |||
UserInfo auditUserInfo = userInfoService.getById(userId); | |||
// 获取发送浙政钉工作通知必要信息 | |||
WorkNoticeInfo workNoticeInfo = todoCenterManage.getSendWorkNoticeInfo(auditUserInfo); | |||
String msg = String.format(PASS_MSG_TEMPLATE, "发改委", "0223-01-测试项目"); | |||
// workNoticeInfo.setBizMsgId("1"); | |||
String msg = String.format(PASS_MSG_TEMPLATE, "发改委", "0223-02-测试项目"); | |||
//// 先创建1个活动线程的线程池 | |||
//ExecutorService executor = Executors.newFixedThreadPool(1); | |||
// 先创建1个活动线程的线程池 | |||
ExecutorService executor = Executors.newFixedThreadPool(1); | |||
// 初始化线程池 | |||
ThreadPoolExecutor threadPool = new ThreadPoolExecutor(10, 20, | |||
60, TimeUnit.SECONDS, new ArrayBlockingQueue(20), new ThreadPoolExecutor.AbortPolicy()); | |||
// 将发送工作通知交给异步任务Future | |||
CompletableFuture<String> future = CompletableFuture.supplyAsync(() -> { | |||
// 调用浙政钉的接口发送工作通知 | |||
try { | |||
long startTime = System.currentTimeMillis(); | |||
long startTime = System.currentTimeMillis(); | |||
GenericResult<Void> result = | |||
zwddClient.sendWorkNotice(workNoticeInfo.getReceiverUserId(), workNoticeInfo.getBizMsgId(), msg); | |||
String resultMsg = result.getMsg(); | |||
if (resultMsg.equals("success")) { | |||
log.info("异步任务执行完成, " + workNoticeInfo.getBizMsgId() + " 当前线程:" + Thread.currentThread().getName()); | |||
long endTime = System.currentTimeMillis(); | |||
log.info("方法执行完成返回,耗时:" + (endTime - startTime)); | |||
} catch (Exception e) { | |||
throw new BizException("发送工作通知失败!"); | |||
} | |||
return "task finished!"; | |||
}, executor); | |||
executor.shutdown(); | |||
while (executor.isTerminated()) { | |||
String result = null; | |||
try { | |||
result = future.get(); | |||
} catch (Exception e) { | |||
throw new RuntimeException(e); | |||
}else { | |||
return "发送工作通知失败!"; | |||
} | |||
log.info(result); | |||
log.info("发送工作通知成功!"); | |||
return "发送工作通知成功!"; | |||
}, threadPool); | |||
String s = future.get(); | |||
threadPool.shutdown(); | |||
while (threadPool.isTerminated()) { | |||
log.info(s); | |||
break; | |||
} | |||
} | |||
} |