haungxing
5 months ago
12 changed files with 264 additions and 40 deletions
@ -0,0 +1,27 @@ |
|||||||
|
package com.hnac.hzims.bigmodel.interactive.constants; |
||||||
|
|
||||||
|
import lombok.AllArgsConstructor; |
||||||
|
import lombok.Data; |
||||||
|
import lombok.Getter; |
||||||
|
|
||||||
|
import java.util.Arrays; |
||||||
|
import java.util.Optional; |
||||||
|
|
||||||
|
/** |
||||||
|
* @Author: huangxing |
||||||
|
* @Date: 2024/06/21 10:49 |
||||||
|
*/ |
||||||
|
@AllArgsConstructor |
||||||
|
@Getter |
||||||
|
public enum DataAuthTypeEnum { |
||||||
|
/**站点鉴权**/ |
||||||
|
STATION("station"), |
||||||
|
DEPT("dept"), |
||||||
|
; |
||||||
|
private final String type; |
||||||
|
|
||||||
|
public static DataAuthTypeEnum getEnumByType(String type) { |
||||||
|
Optional<DataAuthTypeEnum> typeEnumOptional = Arrays.stream(DataAuthTypeEnum.class.getEnumConstants()).filter(e -> e.getType().equals(type)).findFirst(); |
||||||
|
return typeEnumOptional.orElse(null); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,41 @@ |
|||||||
|
package com.hnac.hzims.bigmodel.interactive.controller; |
||||||
|
|
||||||
|
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; |
||||||
|
import com.hnac.hzims.bigmodel.BigModelConstants; |
||||||
|
import com.hnac.hzims.bigmodel.interactive.dto.AuthDataDTO; |
||||||
|
import com.hnac.hzims.bigmodel.interactive.service.IHznlmInteractiveService; |
||||||
|
import com.hnac.hzims.bigmodel.interactive.vo.AuthDataVO; |
||||||
|
import com.hnac.hzinfo.log.annotation.Business; |
||||||
|
import io.swagger.annotations.Api; |
||||||
|
import io.swagger.annotations.ApiOperation; |
||||||
|
import lombok.AllArgsConstructor; |
||||||
|
import org.springblade.core.tool.api.R; |
||||||
|
import org.springframework.web.bind.annotation.RequestBody; |
||||||
|
import org.springframework.web.bind.annotation.RequestMapping; |
||||||
|
import org.springframework.web.bind.annotation.RequestMethod; |
||||||
|
import org.springframework.web.bind.annotation.RestController; |
||||||
|
|
||||||
|
import javax.validation.Valid; |
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
/** |
||||||
|
* @Author: huangxing |
||||||
|
* @Date: 2024/06/21 10:21 |
||||||
|
*/ |
||||||
|
@RestController |
||||||
|
@AllArgsConstructor |
||||||
|
@Api(value = "HZLLM大模型交互层",tags = "HZLLM大模型交互层") |
||||||
|
@RequestMapping("/hzn_lm/interactive") |
||||||
|
@Business(module = BigModelConstants.MODULE_NAME,value = "HZLLM大模型交互层") |
||||||
|
public class HznlmInteractiveController { |
||||||
|
|
||||||
|
private final IHznlmInteractiveService interactiveService; |
||||||
|
|
||||||
|
@RequestMapping(value = "/get_auth_data",method = {RequestMethod.GET,RequestMethod.POST}) |
||||||
|
@ApiOperation("获取鉴权数据") |
||||||
|
@ApiOperationSupport(order = 1) |
||||||
|
public R<List<AuthDataVO>> getAuthData(@RequestBody @Valid AuthDataDTO req) { |
||||||
|
return R.data(interactiveService.getAuthData(req)); |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,36 @@ |
|||||||
|
package com.hnac.hzims.bigmodel.interactive.dto; |
||||||
|
|
||||||
|
import com.alibaba.fastjson.annotation.JSONField; |
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty; |
||||||
|
import io.swagger.annotations.ApiModel; |
||||||
|
import io.swagger.annotations.ApiModelProperty; |
||||||
|
import lombok.Data; |
||||||
|
import lombok.EqualsAndHashCode; |
||||||
|
|
||||||
|
import javax.validation.constraints.NotBlank; |
||||||
|
import java.io.Serializable; |
||||||
|
|
||||||
|
/** |
||||||
|
* @Author: huangxing |
||||||
|
* @Date: 2024/06/21 10:39 |
||||||
|
*/ |
||||||
|
@Data |
||||||
|
@ApiModel(value = "获取权限接口传参格式",description = "获取权限接口传参格式") |
||||||
|
@EqualsAndHashCode |
||||||
|
public class AuthDataDTO implements Serializable { |
||||||
|
|
||||||
|
@JsonProperty("chat_id") |
||||||
|
@ApiModelProperty("问答ID,用于获取前端发起问答传入缓存中数据") |
||||||
|
@NotBlank |
||||||
|
private String sessionId; |
||||||
|
|
||||||
|
@JsonProperty("user_id") |
||||||
|
@ApiModelProperty("提问用户ID") |
||||||
|
@NotBlank |
||||||
|
private String userId; |
||||||
|
|
||||||
|
@ApiModelProperty("鉴权类型") |
||||||
|
@NotBlank |
||||||
|
private String type; |
||||||
|
|
||||||
|
} |
@ -0,0 +1,18 @@ |
|||||||
|
package com.hnac.hzims.bigmodel.interactive.service; |
||||||
|
|
||||||
|
import com.hnac.hzims.bigmodel.interactive.dto.AuthDataDTO; |
||||||
|
import com.hnac.hzims.bigmodel.interactive.vo.AuthDataVO; |
||||||
|
import org.springframework.web.bind.annotation.RequestBody; |
||||||
|
|
||||||
|
import javax.validation.Valid; |
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
/** |
||||||
|
* @Author: huangxing |
||||||
|
* @Date: 2024/06/21 10:23 |
||||||
|
*/ |
||||||
|
public interface IHznlmInteractiveService { |
||||||
|
|
||||||
|
List<AuthDataVO> getAuthData(@RequestBody @Valid AuthDataDTO req); |
||||||
|
|
||||||
|
} |
@ -0,0 +1,58 @@ |
|||||||
|
package com.hnac.hzims.bigmodel.interactive.service.impl; |
||||||
|
|
||||||
|
import com.hnac.hzims.bigmodel.interactive.constants.DataAuthTypeEnum; |
||||||
|
import com.hnac.hzims.bigmodel.interactive.dto.AuthDataDTO; |
||||||
|
import com.hnac.hzims.bigmodel.interactive.service.IHznlmInteractiveService; |
||||||
|
import com.hnac.hzims.bigmodel.interactive.vo.AuthDataVO; |
||||||
|
import groovy.util.logging.Slf4j; |
||||||
|
import lombok.AllArgsConstructor; |
||||||
|
import org.springblade.core.log.exception.ServiceException; |
||||||
|
import org.springblade.core.tool.utils.Func; |
||||||
|
import org.springblade.system.dto.DeptStationDTO; |
||||||
|
import org.springframework.stereotype.Service; |
||||||
|
|
||||||
|
import java.util.List; |
||||||
|
import java.util.stream.Collectors; |
||||||
|
|
||||||
|
/** |
||||||
|
* @Author: huangxing |
||||||
|
* @Date: 2024/06/21 10:24 |
||||||
|
*/ |
||||||
|
@Service |
||||||
|
@AllArgsConstructor |
||||||
|
@Slf4j |
||||||
|
public class HzllmInteractiveServiceImpl implements IHznlmInteractiveService { |
||||||
|
|
||||||
|
private final AuthenticationService authenticationService; |
||||||
|
|
||||||
|
@Override |
||||||
|
public List<AuthDataVO> getAuthData(AuthDataDTO req) { |
||||||
|
DataAuthTypeEnum authTypeEnum = DataAuthTypeEnum.getEnumByType(req.getType()); |
||||||
|
switch(authTypeEnum) { |
||||||
|
case STATION: |
||||||
|
return this.getStationAuthData(req.getUserId()); |
||||||
|
case DEPT: |
||||||
|
return this.getDeptAuthData(req.getUserId()); |
||||||
|
default: |
||||||
|
throw new ServiceException(req.getType() + "改类型获取权限数据暂不支持"); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public List<AuthDataVO> getDeptAuthData(String userId) { |
||||||
|
List<DeptStationDTO> deptStationDTOs = authenticationService.getStationPermissionsById(userId); |
||||||
|
return deptStationDTOs.stream().map(this::convertDeptAuthData).collect(Collectors.toList()); |
||||||
|
} |
||||||
|
|
||||||
|
public List<AuthDataVO> getStationAuthData(String userId) { |
||||||
|
List<DeptStationDTO> deptStationDTOs = authenticationService.getStationPermissionsById(userId); |
||||||
|
return deptStationDTOs.stream().map(this::convertStationAuthData).filter(d -> Func.isNotBlank(d.getId())).collect(Collectors.toList()); |
||||||
|
} |
||||||
|
|
||||||
|
private AuthDataVO convertStationAuthData(DeptStationDTO req) { |
||||||
|
return new AuthDataVO(req.getStationId(),req.getDeptName()); |
||||||
|
} |
||||||
|
|
||||||
|
private AuthDataVO convertDeptAuthData(DeptStationDTO req) { |
||||||
|
return new AuthDataVO(String.valueOf(req.getDeptId()),req.getDeptName()); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,27 @@ |
|||||||
|
package com.hnac.hzims.bigmodel.interactive.vo; |
||||||
|
|
||||||
|
import io.swagger.annotations.ApiModel; |
||||||
|
import io.swagger.annotations.ApiModelProperty; |
||||||
|
import lombok.AllArgsConstructor; |
||||||
|
import lombok.Data; |
||||||
|
import lombok.EqualsAndHashCode; |
||||||
|
|
||||||
|
import java.io.Serializable; |
||||||
|
|
||||||
|
/** |
||||||
|
* @Author: huangxing |
||||||
|
* @Date: 2024/06/21 10:26 |
||||||
|
*/ |
||||||
|
@Data |
||||||
|
@AllArgsConstructor |
||||||
|
@ApiModel(value = "鉴权数据VO",description = "鉴权数据VO,包含站点、机构、遥控权限") |
||||||
|
@EqualsAndHashCode |
||||||
|
public class AuthDataVO implements Serializable { |
||||||
|
|
||||||
|
@ApiModelProperty("数据ID") |
||||||
|
private String id; |
||||||
|
|
||||||
|
@ApiModelProperty("数据名称") |
||||||
|
private String name; |
||||||
|
|
||||||
|
} |
Loading…
Reference in new issue