53 lines
2.0 KiB
Java
53 lines
2.0 KiB
Java
package com.ecep.contract.service;
|
|
|
|
import java.io.IOException;
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
|
|
import com.ecep.contract.vo.DepartmentVo;
|
|
import javafx.collections.ObservableList;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
import com.ecep.contract.vm.EmployeeRoleViewModel;
|
|
import com.ecep.contract.vo.EmployeeRoleVo;
|
|
import com.ecep.contract.vo.FunctionVo;
|
|
|
|
@Service
|
|
public class EmployeeRoleService extends QueryService<EmployeeRoleVo, EmployeeRoleViewModel> {
|
|
|
|
public List<FunctionVo> getFunctionsByRole(EmployeeRoleVo role) {
|
|
try {
|
|
return async("getFunctionsByRoleId", role.getId(), Integer.class).handle((response, ex) -> {
|
|
if (ex != null) {
|
|
throw new RuntimeException("远程方法+getFunctionsByRoleId+调用失败", ex);
|
|
}
|
|
List<FunctionVo> list = new ArrayList<>();
|
|
try {
|
|
objectMapper.readerForUpdating(list)
|
|
.forType(objectMapper.getTypeFactory().constructCollectionType(List.class, FunctionVo.class))
|
|
.readValue(response);
|
|
} catch (IOException e) {
|
|
throw new RuntimeException(e);
|
|
}
|
|
return list;
|
|
}).get();
|
|
} catch (Exception e) {
|
|
throw new RuntimeException("查询实体失败, Function#" + role.getId(), e);
|
|
}
|
|
}
|
|
|
|
|
|
public void saveRoleFunctions(EmployeeRoleVo role, List<FunctionVo> functions) {
|
|
try {
|
|
async("saveRoleFunctions", new Object[]{role.getId(), functions.stream().mapToInt(FunctionVo::getId).toArray()}, new Object[]{Integer.class, Integer[].class}).handle((response, ex) -> {
|
|
if (ex != null) {
|
|
throw new RuntimeException("远程方法+saveRoleFunctions+调用失败", ex);
|
|
}
|
|
return null;
|
|
}).get();
|
|
} catch (Exception e) {
|
|
throw new RuntimeException("保存角色的功能失败, 角色#" + role.getId(), e);
|
|
}
|
|
}
|
|
}
|