一、基本属性准备
1、主题注解
2、解析报文协议
二、自动创建维修工单
1、根据算法获取前一天维修工单最少的人,获取其用户id
其中最主要的是 为该工单分配一个 执行人,该执行人(前一天维修工单最少的人) 所以算出这个人的Id,就迎刃而解了
private Integer getMinCountUserId(Long regionId) {
List<UserVO> userVOList = userService.getOperators(regionId + "");
if (CollectionUtils.isEmpty(userVOList)) {
throw new LogicException("该区域没有运维人员");
}
ArrayList<Integer> userIdList = new ArrayList<>();
for (UserVO vo : userVOList) {
userIdList.add(vo.getUserId());
}
DateTime begin = DateUtil.beginOfDay(new Date());
DateTime end = DateUtil.endOfDay(new Date());
List<TaskEntity> taskEntityList= taskService.getUserTask(begin,end);
Map<Integer, List<TaskEntity>> userCount = taskEntityList.stream().collect(Collectors.groupingBy(TaskEntity::getUserId));
List<UserTaskCount> userTaskCountList = userIdList.stream().map(userId -> {
UserTaskCount userTaskCount = new UserTaskCount();
userTaskCount.setUserId(userId);
List<TaskEntity> taskEntityListNow = userCount.get(userId);
if (CollectionUtils.isEmpty(taskEntityListNow)) {
userTaskCount.setCount(0);
} else {
userTaskCount.setCount(taskEntityListNow.size());
}
return userTaskCount;
}).sorted(((o1, o2) -> o1.getCount() - o2.getCount())).limit(1).collect(Collectors.toList());
Integer userId = userTaskCountList.get(0).getUserId();
return userId;
}
2、自动创建工单
@Override
public boolean AutoSaveTask(VmStatusContract vmStatusContract) {
TaskEntity taskEntity = new TaskEntity();
String taskCode = getId();
taskEntity.setTaskCode(taskCode);
taskEntity.setTaskStatus(VMSystem.TASK_STATUS_CREATE);
taskEntity.setCreateType(VMSystem.ORDER_STATUS_CREATE);
String innerCode = vmStatusContract.getInnerCode();
taskEntity.setInnerCode(innerCode);
VmVO vmInfo = vmService.getVMInfo(innerCode);
Long regionId = vmInfo.getRegionId();
if (regionId==null){
throw new LogicException("区域Id不存在");
}
taskEntity.setRegionId(regionId);
taskEntity.setDesc("自动创建");
taskEntity.setProductTypeId(VMSystem.TASK_TYPE_REPAIR);
String nodeAddr = vmInfo.getNodeAddr();
taskEntity.setAddr(nodeAddr);
Integer userId = getMinCountUserId(regionId);
UserVO user = userService.getUser(userId);
taskEntity.setUserName(user.getUserName());
taskEntity.setUserId(userId);
taskService.save(taskEntity);
return true;
}
|