This commit is contained in:
parent
52c4715b8f
commit
20c21aabf7
|
@ -1,9 +1,7 @@
|
|||
package io.renren.common.annotation;
|
||||
|
||||
|
||||
import java.lang.annotation.*;
|
||||
|
||||
|
||||
/**
|
||||
* 流程流转消息通知
|
||||
*/
|
||||
|
@ -14,20 +12,16 @@ public @interface ActivitiNoticeOperation {
|
|||
|
||||
/**
|
||||
* 节点名称
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
String value() default "";
|
||||
|
||||
/**
|
||||
* 流程名称
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
String process() default "";
|
||||
|
||||
/**
|
||||
* @return activiti 监听器类型 1:TaskListener 任务监听器; 2:ExecutionListener 执行监听器;
|
||||
* activiti 监听器类型 1:TaskListener 任务监听器; 2:ExecutionListener 执行监听器;
|
||||
*/
|
||||
int type() default 1;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package io.renren.common.aspect;
|
||||
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import io.renren.common.annotation.ActivitiNoticeOperation;
|
||||
import io.renren.modules.notice.dto.SysNoticeDTO;
|
||||
|
@ -44,9 +43,9 @@ import java.util.concurrent.Executors;
|
|||
@Component
|
||||
public class ActivitiNoticeAspect {
|
||||
|
||||
private static final Integer cpuNUm = Runtime.getRuntime().availableProcessors();
|
||||
private static final ExecutorService executor = Executors.newFixedThreadPool(cpuNUm * 3);
|
||||
private static final Logger logger = LoggerFactory.getLogger(ActivitiNoticeAspect.class);
|
||||
private static final Integer CPU_NUM = Runtime.getRuntime().availableProcessors();
|
||||
private static final ExecutorService EXECUTOR = Executors.newFixedThreadPool(CPU_NUM * 3);
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(ActivitiNoticeAspect.class);
|
||||
|
||||
@Autowired
|
||||
private SysNoticeService sysNoticeService;
|
||||
|
@ -59,7 +58,7 @@ public class ActivitiNoticeAspect {
|
|||
@Autowired
|
||||
private SysRoleService sysRoleService;
|
||||
|
||||
private Set<String> work_ = new CopyOnWriteArraySet<>();
|
||||
private Set<String> work = new CopyOnWriteArraySet<>();
|
||||
|
||||
@Value("${big_date.name}")
|
||||
private String bigDateDeptName; // 大数据局名称
|
||||
|
@ -67,28 +66,28 @@ public class ActivitiNoticeAspect {
|
|||
private String roleName; // 具备审批的角色名称
|
||||
|
||||
public ActivitiNoticeAspect() {
|
||||
logger.error("构造:ActivitiNoticeAspect");
|
||||
LOGGER.error("构造:ActivitiNoticeAspect");
|
||||
}
|
||||
|
||||
@Pointcut("@annotation(io.renren.common.annotation.ActivitiNoticeOperation)")
|
||||
public void activitiNoticePointCut() {
|
||||
logger.error("切面:ActivitiNoticeAspect");
|
||||
LOGGER.error("切面:ActivitiNoticeAspect");
|
||||
}
|
||||
|
||||
@After(value = "activitiNoticePointCut()")
|
||||
public void notice(JoinPoint joinPoint) throws NoSuchMethodException {
|
||||
logger.error("-------------------------------进入流程流转消息切面---------------------------------");
|
||||
LOGGER.error("-------------------------------进入流程流转消息切面---------------------------------");
|
||||
long beginTime = System.currentTimeMillis();
|
||||
MethodSignature signature = (MethodSignature) joinPoint.getSignature();
|
||||
Method method = joinPoint.getTarget().getClass().getDeclaredMethod(signature.getName(), signature.getParameterTypes());
|
||||
final ActivitiNoticeOperation activitiNoticeOperation = method.getAnnotation(ActivitiNoticeOperation.class);
|
||||
logger.error("切面类型:" + activitiNoticeOperation.type());
|
||||
LOGGER.error("切面类型:{}", activitiNoticeOperation.type());
|
||||
switch (activitiNoticeOperation.type()) {
|
||||
case 1: {
|
||||
Arrays.asList(joinPoint.getArgs()).stream().findFirst().ifPresent(arg -> {
|
||||
Arrays.stream(joinPoint.getArgs()).findFirst().ifPresent(arg -> {
|
||||
final DelegateTask delegateTask = (DelegateTask) arg;
|
||||
final String eventName = delegateTask.getEventName();
|
||||
logger.error("任务监听器事件:" + eventName);
|
||||
LOGGER.error("任务监听器事件:{}", eventName);
|
||||
switch (eventName) {
|
||||
case TaskListener.EVENTNAME_ASSIGNMENT: // 节点被委派给某人
|
||||
assignment_notice(delegateTask, activitiNoticeOperation);
|
||||
|
@ -105,20 +104,19 @@ public class ActivitiNoticeAspect {
|
|||
Arrays.asList(joinPoint.getArgs()).stream().findFirst().ifPresent(arg -> {
|
||||
final DelegateExecution execution = (DelegateExecution) arg;
|
||||
final String eventName = execution.getEventName();
|
||||
logger.error("执行监听器事件:" + eventName);
|
||||
switch (eventName) {
|
||||
case ExecutionListener.EVENTNAME_END: // 流程完成
|
||||
end_notice(execution, activitiNoticeOperation);
|
||||
break;
|
||||
default:
|
||||
LOGGER.error("执行监听器事件:{}", eventName);
|
||||
if (ExecutionListener.EVENTNAME_END.equals(eventName)) { // 流程完成
|
||||
end_notice(execution, activitiNoticeOperation);
|
||||
}
|
||||
});
|
||||
} // 执行监听器
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
//执行时长(毫秒)
|
||||
long time = System.currentTimeMillis() - beginTime;
|
||||
logger.error("执行时长{} ms", time);
|
||||
LOGGER.error("执行时长{} ms", time);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -129,12 +127,12 @@ public class ActivitiNoticeAspect {
|
|||
*/
|
||||
private void task_complete_notice(final DelegateTask delegateTask, final ActivitiNoticeOperation activitiNoticeOperation) {
|
||||
Map<String, Object> kv = delegateTask.getVariables();
|
||||
logger.error("表单:" + JSON.toJSONString(kv));
|
||||
if (work_.contains(TaskListener.EVENTNAME_COMPLETE + kv.get("id").toString())) {
|
||||
logger.error("------------出现重放------------");
|
||||
LOGGER.error("表单:" + JSON.toJSONString(kv));
|
||||
if (work.contains(TaskListener.EVENTNAME_COMPLETE + kv.get("id").toString())) {
|
||||
LOGGER.error("------------出现重放------------");
|
||||
return;
|
||||
}
|
||||
work_.add(TaskListener.EVENTNAME_COMPLETE + kv.get("id").toString());
|
||||
work.add(TaskListener.EVENTNAME_COMPLETE + kv.get("id").toString());
|
||||
String creator = null;
|
||||
if (kv.containsKey("creator")) { // 表单存在创建者
|
||||
creator = kv.get("creator").toString();
|
||||
|
@ -182,9 +180,9 @@ public class ActivitiNoticeAspect {
|
|||
dto.setCreateDate(new Date());
|
||||
dto.setFrom("通知");
|
||||
sysNoticeService.save(dto);
|
||||
}, executor);
|
||||
}, EXECUTOR);
|
||||
} catch (Exception e) {
|
||||
logger.error("发送通知消息异常", e);
|
||||
LOGGER.error("发送通知消息异常", e);
|
||||
} finally {
|
||||
// 防止重放
|
||||
new Thread(() -> {
|
||||
|
@ -193,7 +191,7 @@ public class ActivitiNoticeAspect {
|
|||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
} finally {
|
||||
work_.remove(TaskListener.EVENTNAME_COMPLETE + kv.get("id").toString());
|
||||
work.remove(TaskListener.EVENTNAME_COMPLETE + kv.get("id").toString());
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
@ -207,12 +205,12 @@ public class ActivitiNoticeAspect {
|
|||
*/
|
||||
private void end_notice(final DelegateExecution execution, final ActivitiNoticeOperation activitiNoticeOperation) {
|
||||
Map<String, Object> kv = execution.getVariables();
|
||||
logger.error("表单:" + JSON.toJSONString(kv));
|
||||
if (work_.contains(ExecutionListener.EVENTNAME_END + kv.get("id").toString())) {
|
||||
logger.error("------------出现重放------------");
|
||||
LOGGER.error("表单:" + JSON.toJSONString(kv));
|
||||
if (work.contains(ExecutionListener.EVENTNAME_END + kv.get("id").toString())) {
|
||||
LOGGER.error("------------出现重放------------");
|
||||
return;
|
||||
}
|
||||
work_.add(ExecutionListener.EVENTNAME_END + kv.get("id").toString());
|
||||
work.add(ExecutionListener.EVENTNAME_END + kv.get("id").toString());
|
||||
String creator = null;
|
||||
if (kv.containsKey("creator")) { // 表单存在创建者
|
||||
creator = kv.get("creator").toString();
|
||||
|
@ -262,12 +260,12 @@ public class ActivitiNoticeAspect {
|
|||
dto.setCreateDate(new Date());
|
||||
dto.setFrom("通知");
|
||||
sysNoticeService.save(dto);
|
||||
}, executor).thenRunAsync(() -> {
|
||||
logger.error("大数据局名称:" + bigDateDeptName);
|
||||
}, EXECUTOR).thenRunAsync(() -> {
|
||||
LOGGER.error("大数据局名称:" + bigDateDeptName);
|
||||
SysDeptDTO deptDTO = sysDeptService.getByName(bigDateDeptName);
|
||||
logger.error("deptDTOId:" + deptDTO.getId());
|
||||
LOGGER.error("deptDTOId:" + deptDTO.getId());
|
||||
SysRoleDTO roleDTO = sysRoleService.getByName(roleName);
|
||||
logger.error("roleDTOId:" + roleDTO.getId());
|
||||
LOGGER.error("roleDTOId:" + roleDTO.getId());
|
||||
Optional<SysUserDTO> userDTO = Optional.ofNullable(sysUserService.getByDeptIdAndRoleId(deptDTO.getId(), roleDTO.getId()));
|
||||
userDTO.ifPresent(user -> {
|
||||
SysUserDTO creatorDTO = sysUserService.get(Long.valueOf(finalCreator));
|
||||
|
@ -286,9 +284,9 @@ public class ActivitiNoticeAspect {
|
|||
dto.setFrom("通知");
|
||||
sysNoticeService.save(dto);
|
||||
});
|
||||
}, executor);
|
||||
}, EXECUTOR);
|
||||
} catch (Exception exception) {
|
||||
logger.error("发送通知消息异常", exception);
|
||||
LOGGER.error("发送通知消息异常", exception);
|
||||
} finally {
|
||||
// 防止重放
|
||||
new Thread(() -> {
|
||||
|
@ -297,7 +295,7 @@ public class ActivitiNoticeAspect {
|
|||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
} finally {
|
||||
work_.remove(ExecutionListener.EVENTNAME_END + kv.get("id").toString());
|
||||
work.remove(ExecutionListener.EVENTNAME_END + kv.get("id").toString());
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
@ -312,12 +310,12 @@ public class ActivitiNoticeAspect {
|
|||
*/
|
||||
private void assignment_notice(final DelegateTask delegateTask, final ActivitiNoticeOperation activitiNoticeOperation) {
|
||||
Map<String, Object> kv = delegateTask.getVariables();
|
||||
logger.error("表单:" + JSON.toJSONString(kv));
|
||||
if (work_.contains(TaskListener.EVENTNAME_ASSIGNMENT + kv.get("id").toString())) {
|
||||
logger.error("------------出现重放------------");
|
||||
LOGGER.error("表单:" + JSON.toJSONString(kv));
|
||||
if (work.contains(TaskListener.EVENTNAME_ASSIGNMENT + kv.get("id").toString())) {
|
||||
LOGGER.error("------------出现重放------------");
|
||||
return;
|
||||
}
|
||||
work_.add(TaskListener.EVENTNAME_ASSIGNMENT + kv.get("id").toString());
|
||||
work.add(TaskListener.EVENTNAME_ASSIGNMENT + kv.get("id").toString());
|
||||
String creator = null;
|
||||
if (kv.containsKey("creator")) { // 表单存在创建者
|
||||
creator = kv.get("creator").toString();
|
||||
|
@ -332,9 +330,9 @@ public class ActivitiNoticeAspect {
|
|||
CompletableFuture.runAsync(() -> { // 发起人
|
||||
try {
|
||||
SysUserDTO assignee = sysUserService.get(Long.valueOf(delegateTask.getAssignee()));
|
||||
logger.error("审核人:" + assignee.getId());
|
||||
LOGGER.error("审核人:" + assignee.getId());
|
||||
String content = "【通知】您发起的流程 " + activitiNoticeOperation.process() + " 当前审核节点为:" + activitiNoticeOperation.value() + ";当前审核人为:\"" + assignee.getDeptName() + "\"审核负责人\"" + assignee.getRealName() + "\"";
|
||||
logger.info("通知内容:" + content);
|
||||
LOGGER.info("通知内容:" + content);
|
||||
SysNoticeDTO dto = new SysNoticeDTO();
|
||||
dto.setType(2);
|
||||
dto.setTitle("流程流转系统通知");
|
||||
|
@ -349,9 +347,9 @@ public class ActivitiNoticeAspect {
|
|||
dto.setFrom("通知");
|
||||
sysNoticeService.save(dto);
|
||||
} catch (Exception exception) {
|
||||
logger.error("通知发起人失败", exception);
|
||||
LOGGER.error("通知发起人失败", exception);
|
||||
}
|
||||
}, executor).thenRunAsync(() -> { // 审批者
|
||||
}, EXECUTOR).thenRunAsync(() -> { // 审批者
|
||||
try {
|
||||
SysUserDTO owner = sysUserService.get(Long.valueOf(finalCreator));
|
||||
String content = "【通知】" + owner.getRealName() + "发起的流程" + activitiNoticeOperation.process() + " 已进入审核节点:" + activitiNoticeOperation.value() + ";当前审核人指派为您";
|
||||
|
@ -369,16 +367,16 @@ public class ActivitiNoticeAspect {
|
|||
dto.setFrom("通知");
|
||||
sysNoticeService.save(dto);
|
||||
} catch (Exception exception) {
|
||||
logger.error("通知审批人失败", exception);
|
||||
LOGGER.error("通知审批人失败", exception);
|
||||
}
|
||||
}, executor);
|
||||
}, EXECUTOR);
|
||||
} catch (Exception e) {
|
||||
logger.error("发送通知消息异常", e);
|
||||
LOGGER.error("发送通知消息异常", e);
|
||||
} finally {
|
||||
new Thread(() -> {
|
||||
try {
|
||||
Thread.sleep(200);
|
||||
work_.remove(TaskListener.EVENTNAME_ASSIGNMENT + kv.get("id").toString());
|
||||
work.remove(TaskListener.EVENTNAME_ASSIGNMENT + kv.get("id").toString());
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
|
|
@ -1889,7 +1889,7 @@ public class ResourceServiceImpl extends CrudServiceImpl<ResourceDao, ResourceEn
|
|||
Map<String, Object> componentMap = new HashMap<>();
|
||||
componentMap.put("title", "组件服务");
|
||||
Map<String, List> map = new ConcurrentHashMap<>();
|
||||
CompletableFuture.allOf(resourceTypeMap.get("组件服务").stream().map(it -> CompletableFuture.runAsync(() -> selectAttrsByResourceId(Long.parseLong(it.get("id").toString())).stream()
|
||||
CompletableFuture[] completableFutures = resourceTypeMap.get("组件服务").stream().map(it -> CompletableFuture.runAsync(() -> selectAttrsByResourceId(Long.parseLong(it.get("id").toString())).stream()
|
||||
.filter(temp -> "组件类型".equals(temp.getAttrType())).forEach(attr -> {
|
||||
if (map.get(attr.getAttrValue()) != null) {
|
||||
map.get(attr.getAttrValue()).add(it);
|
||||
|
@ -1898,7 +1898,10 @@ public class ResourceServiceImpl extends CrudServiceImpl<ResourceDao, ResourceEn
|
|||
add(it);
|
||||
}}));
|
||||
}
|
||||
}), executor)).toArray(CompletableFuture[]::new)).join();
|
||||
}), executor))
|
||||
.collect(Collectors.toList())
|
||||
.toArray(new CompletableFuture[resourceTypeMap.get("组件服务").size()]);
|
||||
CompletableFuture.allOf(completableFutures).join();
|
||||
componentMap.put("children", map.entrySet().stream().map(it -> new HashMap<String, Object>() {{
|
||||
put("title", it.getKey());
|
||||
put("children", it.getValue());
|
||||
|
|
Loading…
Reference in New Issue