Browse Source

fix:大模型鉴权接口修改

fix:大模型历史数据查询接口报错提示处理
zhongwei
haungxing 5 months ago
parent
commit
19908d6201
  1. 27
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/constants/DataAuthTypeEnum.java
  2. 41
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/controller/HznlmInteractiveController.java
  3. 1
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/controller/InteractiveController.java
  4. 36
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/dto/AuthDataDTO.java
  5. 18
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/IHznlmInteractiveService.java
  6. 57
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/AnalyseDataServiceImpl.java
  7. 1
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/ExtraResolveStrategyService.java
  8. 58
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/HzllmInteractiveServiceImpl.java
  9. 27
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/AuthDataVO.java
  10. 2
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/HistoryDataSearchVO.java
  11. 0
      hzims-service/hzims-simulate/src/main/java/com/hnac/hzims/simulate/mapper/IHzllmInteractiveService.xml

27
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/constants/DataAuthTypeEnum.java

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

41
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/controller/HznlmInteractiveController.java

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

1
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/controller/InteractiveController.java

@ -48,6 +48,7 @@ public class InteractiveController {
@ApiOperation("站点、菜单鉴权") @ApiOperation("站点、菜单鉴权")
@ApiOperationSupport(order = 3) @ApiOperationSupport(order = 3)
@Deprecated
@RequestMapping(value = "/authentication",method = {RequestMethod.GET,RequestMethod.POST}) @RequestMapping(value = "/authentication",method = {RequestMethod.GET,RequestMethod.POST})
public R authentication(@RequestParam(required = false) @ApiParam("站点编号") String stationId, public R authentication(@RequestParam(required = false) @ApiParam("站点编号") String stationId,
@RequestParam @ApiParam("用户ID") String userId, @RequestParam @ApiParam("用户ID") String userId,

36
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/dto/AuthDataDTO.java

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

18
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/IHznlmInteractiveService.java

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

57
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/AnalyseDataServiceImpl.java

@ -19,6 +19,7 @@ import com.hnac.hzinfo.sdk.v5.device.vo.ReductionDataVO;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import org.springblade.core.log.exception.ServiceException; import org.springblade.core.log.exception.ServiceException;
import org.springblade.core.log.logger.BladeLogger; import org.springblade.core.log.logger.BladeLogger;
import org.springblade.core.tool.utils.CollectionUtil;
import org.springblade.core.tool.utils.DateUtil; import org.springblade.core.tool.utils.DateUtil;
import org.springblade.core.tool.utils.Func; import org.springblade.core.tool.utils.Func;
import org.springblade.core.tool.utils.StringUtil; import org.springblade.core.tool.utils.StringUtil;
@ -63,30 +64,46 @@ public class AnalyseDataServiceImpl implements IAnalyseDataService {
extraVO.setType(FuncRouteEnum.HISTORY_DATA.getType().getType()); extraVO.setType(FuncRouteEnum.HISTORY_DATA.getType().getType());
extraVO.setFuncCode(FuncRouteEnum.HISTORY_DATA.getFuncCode()); extraVO.setFuncCode(FuncRouteEnum.HISTORY_DATA.getFuncCode());
Map<String,Object> params = new HashMap<>(1); Map<String,Object> params = new HashMap<>(1);
ReductionDataVO dataVO = this.getPolymerizationData(searchVO); Result<ReductionDataVO> reductionDataVOR = this.getPolymerizationData(searchVO);
List<Map> datalist = dataVO.getDataList().stream().map(m -> { String label;
m.put("val", m.get(searchVO.getSignage())); if(!reductionDataVOR.isSuccess()) {
m.remove(searchVO.getSignage()); params.put("errorInfo",reductionDataVOR.getMsg());
return m; label = "查询数据失败!";
}).collect(Collectors.toList()); }
DataMethodEnum enumByMethod = DataMethodEnum.getEnumByMethod(searchVO.getMethod()); else {
String label = searchVO.getStationName() + "_" ReductionDataVO dataVO = reductionDataVOR.getData();
+ searchVO.getDeviceName() + "_" label = "暂未查到数据";
+ dataVO.getFieldMap().get(searchVO.getSignage()) + "_" params.put("data",Lists.newArrayList());
+ (DataMethodEnum.USUAL.getMethod().equals(enumByMethod.getMethod()) ? "" : adapterDate.getName()) if(Func.isNotEmpty(dataVO) && CollectionUtil.isNotEmpty(dataVO.getDataList())) {
+ enumByMethod.getMethod() List<Map> datalist = dataVO.getDataList().stream().map(m -> {
+ (DataMethodEnum.USUAL.getMethod().equals(enumByMethod.getMethod()) ? "" : note) m.put("val", m.get(searchVO.getSignage()));
+ ":"; m.remove(searchVO.getSignage());
return m;
}).collect(Collectors.toList());
DataMethodEnum enumByMethod = DataMethodEnum.getEnumByMethod(searchVO.getMethod());
if(CollectionUtil.isNotEmpty(datalist)) {
label = searchVO.getStationName() + "_"
+ searchVO.getDeviceName() + "_"
+ dataVO.getFieldMap().get(searchVO.getSignage()) + "_"
+ (DataMethodEnum.USUAL.getMethod().equals(enumByMethod.getMethod()) ? "" : adapterDate.getName())
+ enumByMethod.getMethod()
+ (DataMethodEnum.USUAL.getMethod().equals(enumByMethod.getMethod()) ? "" : note)
+ ":";
}
params.put("data",datalist);
}
}
extraVO.setLabel(label); extraVO.setLabel(label);
params.put("data",datalist);
params.put("deviceName",searchVO.getDeviceName()); params.put("deviceName",searchVO.getDeviceName());
params.put("attrName",dataVO.getFieldMap().get(searchVO.getSignage())); params.put("attrName",searchVO.getAttrName());
params.put("stationName",searchVO.getStationName()); params.put("stationName",searchVO.getStationName());
params.put("beginTime",searchVO.getStartTime());
params.put("endTime",searchVO.getEndTime());
extraVO.setParams(params); extraVO.setParams(params);
return extraVO; return extraVO;
} }
private ReductionDataVO getPolymerizationData(HistoryDataSearchVO searchVO) { private Result<ReductionDataVO> getPolymerizationData(HistoryDataSearchVO searchVO) {
DataMethodEnum enumByMethod = DataMethodEnum.getEnumByMethod(searchVO.getMethod()); DataMethodEnum enumByMethod = DataMethodEnum.getEnumByMethod(searchVO.getMethod());
Assert.isTrue(Func.isNotEmpty(enumByMethod),() -> { Assert.isTrue(Func.isNotEmpty(enumByMethod),() -> {
throw new ServiceException("数据查询聚合方式传参有误,查询失败!"); throw new ServiceException("数据查询聚合方式传参有误,查询失败!");
@ -106,11 +123,7 @@ public class AnalyseDataServiceImpl implements IAnalyseDataService {
dataDTO.setTimeInterval(1); dataDTO.setTimeInterval(1);
dataDTO.setDtos(Lists.newArrayList(reductionAttrData)); dataDTO.setDtos(Lists.newArrayList(reductionAttrData));
logger.info("interactive:getPolymerizationData","config传参为:" + JSON.toJSONString(dataDTO)); logger.info("interactive:getPolymerizationData","config传参为:" + JSON.toJSONString(dataDTO));
Result<ReductionDataVO> dataVO = deviceDataClient.pageDeviceCodeAndSignages(dataDTO); return deviceDataClient.pageDeviceCodeAndSignages(dataDTO);
Assert.isTrue(dataVO.isSuccess(),() -> {
throw new ServiceException("聚合历史数据查询失败!");
});
return dataVO.getData();
} }
private DateEnum getDateEnumByDuration(String startTime,String endTime,DateEnum dateEnum) { private DateEnum getDateEnumByDuration(String startTime,String endTime,DateEnum dateEnum) {

1
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/ExtraResolveStrategyService.java

@ -125,6 +125,7 @@ public class ExtraResolveStrategyService {
DataItemVO item = data.getItem(); DataItemVO item = data.getItem();
HistoryDataSearchVO searchVO = new HistoryDataSearchVO(); HistoryDataSearchVO searchVO = new HistoryDataSearchVO();
searchVO.setDataType(data.getDataType()); searchVO.setDataType(data.getDataType());
searchVO.setAttrName(item.getAttrName());
searchVO.setDeviceCode(item.getDeviceId()); searchVO.setDeviceCode(item.getDeviceId());
searchVO.setDeviceName(item.getDeviceName()); searchVO.setDeviceName(item.getDeviceName());
searchVO.setStationName(item.getProjectName()); searchVO.setStationName(item.getProjectName());

58
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/HzllmInteractiveServiceImpl.java

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

27
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/AuthDataVO.java

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

2
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/HistoryDataSearchVO.java

@ -23,6 +23,8 @@ public class HistoryDataSearchVO {
@NotBlank @NotBlank
private String signage; private String signage;
private String attrName;
@NotBlank @NotBlank
private String method; private String method;

0
hzims-service/hzims-simulate/src/main/java/com/hnac/hzims/simulate/mapper/DeviceFieldGapMapper.xml → hzims-service/hzims-simulate/src/main/java/com/hnac/hzims/simulate/mapper/IHzllmInteractiveService.xml

Loading…
Cancel
Save