重构Desktop类的浏览器和文件资源管理器功能到新的DesktopUtils工具类,提高代码可维护性 修改多处调用点使用新的工具类方法 更新数据库连接默认主机地址 为CurrentEmployee类添加@ToString注解
96 lines
3.3 KiB
Java
96 lines
3.3 KiB
Java
package com.ecep.contract.manager;
|
|
|
|
import java.util.List;
|
|
import java.util.Locale;
|
|
import java.util.concurrent.CompletableFuture;
|
|
import java.util.concurrent.ScheduledExecutorService;
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
import com.ecep.contract.manager.ds.other.model.Employee;
|
|
import com.ecep.contract.manager.ds.other.model.EmployeeRole;
|
|
import com.ecep.contract.manager.ds.other.service.EmployeeService;
|
|
import com.ecep.contract.manager.ds.other.vo.EmployeeViewModel;
|
|
|
|
import javafx.application.Platform;
|
|
import javafx.beans.property.SimpleListProperty;
|
|
import javafx.beans.property.SimpleObjectProperty;
|
|
import javafx.collections.FXCollections;
|
|
import lombok.ToString;
|
|
|
|
/**
|
|
* 当前登录用户
|
|
*/
|
|
@ToString(of = {"id", "name", "email", "phone", "roles"})
|
|
public class CurrentEmployee extends EmployeeViewModel {
|
|
private static final Logger logger = LoggerFactory.getLogger(CurrentEmployee.class);
|
|
/**
|
|
* 语言环境
|
|
*/
|
|
private SimpleObjectProperty<Locale> locale = new SimpleObjectProperty<>(Locale.getDefault());
|
|
/**
|
|
* 角色
|
|
*/
|
|
private SimpleListProperty<EmployeeRole> roles = new SimpleListProperty<>(FXCollections.observableArrayList());
|
|
/**
|
|
* 是否系统管理员
|
|
*/
|
|
public boolean isSystemAdministrator() {
|
|
return roles.stream().anyMatch(EmployeeRole::isSystemAdministrator);
|
|
}
|
|
/**
|
|
* 语言环境属性
|
|
*/
|
|
public SimpleObjectProperty<Locale> localeProperty() {
|
|
return locale;
|
|
}
|
|
/**
|
|
* 角色属性
|
|
*/
|
|
public SimpleListProperty<EmployeeRole> rolesProperty() {
|
|
return roles;
|
|
}
|
|
/**
|
|
* 初始化
|
|
*/
|
|
public CompletableFuture<Void> initialize() {
|
|
CompletableFuture<Void> future = new CompletableFuture<>();
|
|
ScheduledExecutorService executorService = Desktop.instance.getExecutorService();
|
|
/**
|
|
* 异步初始化当前用户
|
|
* 1. 从数据库中查询当前用户
|
|
* 2. 从数据库中查询当前用户的角色
|
|
* 3. 更新当前用户的信息
|
|
* 4. 更新当前用户的角色
|
|
*/
|
|
executorService.submit(() -> {
|
|
// issue #1 sss 2020-07-05
|
|
EmployeeService employeeService = SpringApp.getBean(EmployeeService.class);
|
|
Employee employee = employeeService.findById(Desktop.instance.getActiveEmployeeId());
|
|
List<EmployeeRole> roles = employeeService.getRolesByEmployeeId(employee.getId());
|
|
Platform.runLater(() -> {
|
|
update(employee);
|
|
rolesProperty().setAll(roles);
|
|
// 发布事件
|
|
SpringApp.context.publishEvent(new CurrentEmployeeInitialedEvent(this));
|
|
future.complete(null);
|
|
});
|
|
});
|
|
/**
|
|
* 定时更新用户活动状态
|
|
*/
|
|
executorService.scheduleWithFixedDelay(() -> {
|
|
try {
|
|
SpringApp.getBean(EmployeeService.class).updateActive(Desktop.instance.getSessionId());
|
|
} catch (Exception e) {
|
|
if (logger.isErrorEnabled()) {
|
|
logger.error("updateActive:{}", e.getMessage(), e);
|
|
}
|
|
}
|
|
}, 10, 10, TimeUnit.SECONDS);
|
|
return future;
|
|
}
|
|
}
|