|
|
@@ -1,13 +1,27 @@ |
|
|
|
package com.ningdatech.pmapi.todocenter; |
|
|
|
|
|
|
|
import com.ningdatech.basic.exception.BizException; |
|
|
|
import com.ningdatech.pmapi.AppTests; |
|
|
|
import com.ningdatech.pmapi.beanconfig.BeanConfig; |
|
|
|
import com.ningdatech.pmapi.todocenter.bean.entity.WorkNoticeInfo; |
|
|
|
import com.ningdatech.pmapi.todocenter.manage.TodoCenterManage; |
|
|
|
import com.ningdatech.pmapi.user.entity.UserInfo; |
|
|
|
import com.ningdatech.pmapi.user.service.IUserInfoService; |
|
|
|
import com.ningdatech.zwdd.client.ZwddClient; |
|
|
|
import liquibase.pro.packaged.U; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.junit.Test; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.context.ApplicationContext; |
|
|
|
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.function.Supplier; |
|
|
|
|
|
|
|
import static com.ningdatech.pmapi.todocenter.constant.WorkNotice.PASS_MSG_TEMPLATE; |
|
|
|
|
|
|
@@ -21,16 +35,64 @@ import static com.ningdatech.pmapi.todocenter.constant.WorkNotice.PASS_MSG_TEMPL |
|
|
|
public class TodoCenterTest extends AppTests { |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private TaskExecutor taskExecutor; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private TodoCenterManage todoCenterManage; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private IUserInfoService userInfoService; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private ZwddClient zwddClient; |
|
|
|
@Test |
|
|
|
public void sendWorkNoticeTest(){ |
|
|
|
String msg = String.format(PASS_MSG_TEMPLATE, "发改委", "0216-7-测试项目"); |
|
|
|
log.info("开始发送工作通知"); |
|
|
|
zwddClient.sendWorkNotice("846085","0216-8",msg); |
|
|
|
// zwddClient.sendWorkNotice("829728","0216-5",msg); |
|
|
|
log.info("发送工作通知结束"); |
|
|
|
public void sendWorkNoticeTest() { |
|
|
|
//String msg = String.format(PASS_MSG_TEMPLATE, "发改委", "0223-00-测试项目"); |
|
|
|
//log.info("开始发送工作通知"); |
|
|
|
//zwddClient.sendWorkNotice("846085", "0223-00", msg); |
|
|
|
//// zwddClient.sendWorkNotice("829728","0216-5",msg); |
|
|
|
//log.info("发送工作通知结束"); |
|
|
|
|
|
|
|
//ApplicationContext ac = new AnnotationConfigApplicationContext(BeanConfig.class); |
|
|
|
// |
|
|
|
////若没有指定属性名,则默认为方法名 |
|
|
|
//TaskExecutor taskExecutor = (TaskExecutor) ac.getBean("executor"); |
|
|
|
|
|
|
|
Long userId = 4L; |
|
|
|
UserInfo auditUserInfo = userInfoService.getById(userId); |
|
|
|
// 获取发送浙政钉工作通知必要信息 |
|
|
|
WorkNoticeInfo workNoticeInfo = todoCenterManage.getSendWorkNoticeInfo(auditUserInfo); |
|
|
|
String msg = String.format(PASS_MSG_TEMPLATE, "发改委", "0223-01-测试项目"); |
|
|
|
|
|
|
|
// 先创建1个活动线程的线程池 |
|
|
|
ExecutorService executor = Executors.newFixedThreadPool(1); |
|
|
|
|
|
|
|
// 将发送工作通知交给异步任务Future |
|
|
|
CompletableFuture<String> future = CompletableFuture.supplyAsync(() -> { |
|
|
|
// 调用浙政钉的接口发送工作通知 |
|
|
|
try { |
|
|
|
long startTime = System.currentTimeMillis(); |
|
|
|
zwddClient.sendWorkNotice(workNoticeInfo.getReceiverUserId(), workNoticeInfo.getBizMsgId(), msg); |
|
|
|
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); |
|
|
|
} |
|
|
|
log.info(result); |
|
|
|
log.info("发送工作通知成功!"); |
|
|
|
} |
|
|
|
} |
|
|
|
} |