Browse Source

add:遥控鉴权接口

zhongwei
haungxing 6 months ago
parent
commit
0a2332f9b8
  1. 22
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/constants/ProjectRemoteTypeEnum.java
  2. 100
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/AuthenticationService.java
  3. 43
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/InteractiveServiceImpl.java

22
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/constants/ProjectRemoteTypeEnum.java

@ -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;
}

100
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/AuthenticationService.java

@ -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();
}
}

43
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/InteractiveServiceImpl.java

@ -8,6 +8,7 @@ import com.alibaba.fastjson.JSONObject;
import com.hnac.hzims.bigmodel.configuration.BigModelInvokeUrl; import com.hnac.hzims.bigmodel.configuration.BigModelInvokeUrl;
import com.hnac.hzims.bigmodel.entity.FunctionEntity; import com.hnac.hzims.bigmodel.entity.FunctionEntity;
import com.hnac.hzims.bigmodel.function.service.IFunctionService; import com.hnac.hzims.bigmodel.function.service.IFunctionService;
import com.hnac.hzims.bigmodel.interactive.constants.FuncRouteEnum;
import com.hnac.hzims.bigmodel.interactive.req.ModelFunctionReq; import com.hnac.hzims.bigmodel.interactive.req.ModelFunctionReq;
import com.hnac.hzims.bigmodel.interactive.service.IInteractiveService; import com.hnac.hzims.bigmodel.interactive.service.IInteractiveService;
import com.hnac.hzims.bigmodel.interactive.service.IJumpPageService; import com.hnac.hzims.bigmodel.interactive.service.IJumpPageService;
@ -57,9 +58,7 @@ public class InteractiveServiceImpl implements IInteractiveService {
private final BigModelInvokeUrl bigModelInvokeUrl; private final BigModelInvokeUrl bigModelInvokeUrl;
private final IDeptClient deptClient; private final AuthenticationService authenticationService;
private final IUserClient userClient;
private final RedisTemplate redisTemplate; private final RedisTemplate redisTemplate;
@ -98,8 +97,8 @@ public class InteractiveServiceImpl implements IInteractiveService {
params.put("id",sessionId); params.put("id",sessionId);
params.put("userid", userId); params.put("userid", userId);
params.put("query",question); params.put("query",question);
params.put("stationids",this.getStationPermissionsById(userId).stream().map(DeptStationDTO::getStationId).filter(StringUtil::isNotBlank).filter(Func::isNotEmpty).toArray()); params.put("stationids",authenticationService.getStationPermissionsById(userId).stream().map(DeptStationDTO::getStationId).filter(StringUtil::isNotBlank).filter(Func::isNotEmpty).toArray());
params.put("projectids",this.getStationPermissionsById(userId).stream().map(DeptStationDTO::getDeptId).filter(Func::isNotEmpty).map(String::valueOf).toArray()); params.put("projectids",authenticationService.getStationPermissionsById(userId).stream().map(DeptStationDTO::getDeptId).filter(Func::isNotEmpty).map(String::valueOf).toArray());
HttpResponse response = HttpRequest.post(fdpHost + bigModelInvokeUrl.getAssistantAsk()) HttpResponse response = HttpRequest.post(fdpHost + bigModelInvokeUrl.getAssistantAsk())
.body(JSON.toJSONString(params)).execute(); .body(JSON.toJSONString(params)).execute();
logger.info("interactive:ask","问答传参为:" + JSON.toJSONString(params) + "结果为:" + response.body()); logger.info("interactive:ask","问答传参为:" + JSON.toJSONString(params) + "结果为:" + response.body());
@ -132,8 +131,8 @@ public class InteractiveServiceImpl implements IInteractiveService {
params.put("id",sessionId); params.put("id",sessionId);
params.put("userid", userId); params.put("userid", userId);
params.put("extra",extra); params.put("extra",extra);
params.put("stationids",this.getStationPermissionsById(userId).stream().map(DeptStationDTO::getStationId).filter(StringUtil::isNotBlank).filter(Func::isNotEmpty).toArray()); params.put("stationids",authenticationService.getStationPermissionsById(userId).stream().map(DeptStationDTO::getStationId).filter(StringUtil::isNotBlank).filter(Func::isNotEmpty).toArray());
params.put("projectids",this.getStationPermissionsById(userId).stream().map(DeptStationDTO::getDeptId).filter(Func::isNotEmpty).map(String::valueOf).toArray()); params.put("projectids",authenticationService.getStationPermissionsById(userId).stream().map(DeptStationDTO::getDeptId).filter(Func::isNotEmpty).map(String::valueOf).toArray());
HttpResponse response = HttpRequest.post(fdpHost + bigModelInvokeUrl.getAssistantSpecialAsk()) HttpResponse response = HttpRequest.post(fdpHost + bigModelInvokeUrl.getAssistantSpecialAsk())
.body(JSON.toJSONString(params)).execute(); .body(JSON.toJSONString(params)).execute();
if(response.getStatus() != HttpServletResponse.SC_OK) { if(response.getStatus() != HttpServletResponse.SC_OK) {
@ -200,21 +199,15 @@ public class InteractiveServiceImpl implements IInteractiveService {
public Boolean authentication(String stationId, String userId, String func) { public Boolean authentication(String stationId, String userId, String func) {
// 站点鉴权 // 站点鉴权
if(StringUtil.isNotBlank(stationId)) { if(StringUtil.isNotBlank(stationId)) {
List<String> stations = this.getStationPermissionsById(userId).stream().map(DeptStationDTO::getStationId) authenticationService.stationAuthentication(stationId,userId);
.filter(StringUtil::isNotBlank).filter(Func::isNotEmpty).collect(Collectors.toList());
Assert.isTrue(stations.contains(stationId),() -> {
throw new ServiceException("人员站点鉴权失败!");
});
} }
// 菜单鉴权 // 菜单鉴权
if(StringUtil.isNotBlank(func) && StringUtil.isNotBlank(userId)) { if(StringUtil.isNotBlank(func) && StringUtil.isNotBlank(userId)) {
FunctionEntity function = functionService.getFunctionByCode(func); authenticationService.menuAuthentication(stationId,userId,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(), () -> { if(FuncRouteEnum.CONFIRM_YK.getFuncCode().equals(func)) {
throw new ServiceException("人员菜单鉴权失败!"); authenticationService.remoteAuthentication(stationId,userId,func);
});
}
} }
return true; return true;
} }
@ -256,9 +249,9 @@ public class InteractiveServiceImpl implements IInteractiveService {
params.put("userid", userId); params.put("userid", userId);
params.put("query", question); params.put("query", question);
params.put("knowledge", knowledge); params.put("knowledge", knowledge);
params.put("stationids", this.getStationPermissionsById(userId).stream().map(DeptStationDTO::getStationId) params.put("stationids", authenticationService.getStationPermissionsById(userId).stream().map(DeptStationDTO::getStationId)
.filter(StringUtil::isNotBlank).filter(Func::isNotEmpty).toArray()); .filter(StringUtil::isNotBlank).filter(Func::isNotEmpty).toArray());
params.put("projectids", this.getStationPermissionsById(userId).stream().map(DeptStationDTO::getDeptId) params.put("projectids", authenticationService.getStationPermissionsById(userId).stream().map(DeptStationDTO::getDeptId)
.filter(Func::isNotEmpty).map(String::valueOf).toArray()); .filter(Func::isNotEmpty).map(String::valueOf).toArray());
HttpResponse response = HttpRequest.post(fdpHost + bigModelInvokeUrl.getAssistantKnowledgeAsk()) HttpResponse response = HttpRequest.post(fdpHost + bigModelInvokeUrl.getAssistantKnowledgeAsk())
.body(JSON.toJSONString(params)).execute(); .body(JSON.toJSONString(params)).execute();
@ -270,12 +263,4 @@ public class InteractiveServiceImpl implements IInteractiveService {
this.addQuestionSessionId(sessionId); this.addQuestionSessionId(sessionId);
return R.success("消息发送成功"); return R.success("消息发送成功");
} }
private 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…
Cancel
Save