haungxing
6 months ago
3 changed files with 136 additions and 29 deletions
@ -0,0 +1,22 @@ |
|||||||
|
package com.hnac.hzims.bigmodel.interactive.constants; |
||||||
|
|
||||||
|
import lombok.AllArgsConstructor; |
||||||
|
import lombok.Getter; |
||||||
|
|
||||||
|
/** |
||||||
|
* @Author: huangxing |
||||||
|
* @Date: 2024/05/21 16:34 |
||||||
|
*/ |
||||||
|
@AllArgsConstructor |
||||||
|
public enum ProjectRemoteTypeEnum { |
||||||
|
/**不允许发送遥控**/ |
||||||
|
NOT_ALLOW(0), |
||||||
|
/**运行发送遥控并且需要校验权限**/ |
||||||
|
VALID(1), |
||||||
|
/**运行发送遥控并免校验权限**/ |
||||||
|
ALLOW(2), |
||||||
|
; |
||||||
|
@Getter |
||||||
|
private Integer ctrlType; |
||||||
|
|
||||||
|
} |
@ -0,0 +1,100 @@ |
|||||||
|
package com.hnac.hzims.bigmodel.interactive.service.impl; |
||||||
|
|
||||||
|
import com.hnac.hzims.bigmodel.entity.FunctionEntity; |
||||||
|
import com.hnac.hzims.bigmodel.function.service.IFunctionService; |
||||||
|
import com.hnac.hzims.bigmodel.interactive.constants.ProjectRemoteTypeEnum; |
||||||
|
import com.hnac.hzinfo.sdk.core.response.Result; |
||||||
|
import com.hnac.hzinfo.sdk.v5.project.ProjectClient; |
||||||
|
import com.hnac.hzinfo.sdk.v5.project.vo.ProjectVO; |
||||||
|
import lombok.AllArgsConstructor; |
||||||
|
import org.springblade.core.log.exception.ServiceException; |
||||||
|
import org.springblade.core.tool.api.R; |
||||||
|
import org.springblade.core.tool.utils.CollectionUtil; |
||||||
|
import org.springblade.core.tool.utils.Func; |
||||||
|
import org.springblade.core.tool.utils.StringUtil; |
||||||
|
import org.springblade.system.dto.DeptStationDTO; |
||||||
|
import org.springblade.system.feign.IDeptClient; |
||||||
|
import org.springblade.system.feign.IRemoteClient; |
||||||
|
import org.springblade.system.user.feign.IUserClient; |
||||||
|
import org.springframework.stereotype.Service; |
||||||
|
import org.springframework.util.Assert; |
||||||
|
|
||||||
|
import java.util.List; |
||||||
|
import java.util.stream.Collectors; |
||||||
|
|
||||||
|
/** |
||||||
|
* @Author: huangxing |
||||||
|
* @Date: 2024/05/21 16:10 |
||||||
|
*/ |
||||||
|
@Service |
||||||
|
@AllArgsConstructor |
||||||
|
public class AuthenticationService { |
||||||
|
|
||||||
|
private final IDeptClient deptClient; |
||||||
|
private final IFunctionService functionService; |
||||||
|
private final IUserClient userClient; |
||||||
|
private final ProjectClient projectClient; |
||||||
|
private final IRemoteClient remoteClient; |
||||||
|
|
||||||
|
/** |
||||||
|
* 站点鉴权 |
||||||
|
* @param stationId 站点ID |
||||||
|
* @param userId 用户ID |
||||||
|
*/ |
||||||
|
public void stationAuthentication(String stationId, String userId) { |
||||||
|
List<String> stations = this.getStationPermissionsById(userId).stream().map(DeptStationDTO::getStationId) |
||||||
|
.filter(StringUtil::isNotBlank).filter(Func::isNotEmpty).collect(Collectors.toList()); |
||||||
|
Assert.isTrue(stations.contains(stationId),() -> { |
||||||
|
throw new ServiceException("人员站点鉴权失败!"); |
||||||
|
}); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 菜单鉴权 |
||||||
|
* @param stationId 站点ID |
||||||
|
* @param userId 用户ID |
||||||
|
* @param func 函数编号 |
||||||
|
*/ |
||||||
|
public void menuAuthentication(String stationId, String userId, String func) { |
||||||
|
FunctionEntity function = functionService.getFunctionByCode(func); |
||||||
|
if(Func.isNotEmpty(function) && Func.isNotEmpty(function.getRoute()) && StringUtil.isNotBlank(function.getRoute())) { |
||||||
|
R<Boolean> authenticationR = userClient.permissionMenuById(Long.valueOf(userId), function.getRoute()); |
||||||
|
Assert.isTrue(authenticationR.isSuccess() && authenticationR.getData(), () -> { |
||||||
|
throw new ServiceException("人员菜单鉴权失败!"); |
||||||
|
}); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 遥控鉴权 |
||||||
|
* @param stationId 站点ID |
||||||
|
* @param userId 用户ID |
||||||
|
* @param func 函数编号 |
||||||
|
*/ |
||||||
|
public void remoteAuthentication(String stationId, String userId, String func) { |
||||||
|
// 查询数据平台站点是否可被遥控
|
||||||
|
Result<ProjectVO> projectR = projectClient.getProjectByPid(stationId); |
||||||
|
Assert.isTrue(projectR.isSuccess() && Func.isNotEmpty(projectR.getData()),() -> { |
||||||
|
throw new ServiceException("未查询到站点,鉴权失败!"); |
||||||
|
}); |
||||||
|
ProjectVO project = projectR.getData(); |
||||||
|
if(ProjectRemoteTypeEnum.NOT_ALLOW.getCtrlType().equals(project.getCtrlType())) { |
||||||
|
// 不允许发送遥控
|
||||||
|
throw new ServiceException("该站点不允许发送遥控指令,校验失败!"); |
||||||
|
} |
||||||
|
else if(ProjectRemoteTypeEnum.VALID.getCtrlType().equals(project.getCtrlType())) { |
||||||
|
// 运行发送遥控并且需要校验权限
|
||||||
|
//remoteClient.sendCtrlCheckParam();
|
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
public List<DeptStationDTO> getStationPermissionsById(String userId) { |
||||||
|
R<List<DeptStationDTO>> deptSattionR = deptClient.getStationPermissionsById(Long.valueOf(userId)); |
||||||
|
Assert.isTrue(deptSattionR.isSuccess() && CollectionUtil.isNotEmpty(deptSattionR.getData()),() -> { |
||||||
|
throw new ServiceException("获取人员站点权限失败!"); |
||||||
|
}); |
||||||
|
return deptSattionR.getData(); |
||||||
|
} |
||||||
|
|
||||||
|
} |
Loading…
Reference in new issue