From 19908d620129a4f414d3375f33a968ee91511172 Mon Sep 17 00:00:00 2001 From: haungxing <1203316822@qq.com> Date: Fri, 21 Jun 2024 14:25:40 +0800 Subject: [PATCH] =?UTF-8?q?fix=EF=BC=9A=E5=A4=A7=E6=A8=A1=E5=9E=8B?= =?UTF-8?q?=E9=89=B4=E6=9D=83=E6=8E=A5=E5=8F=A3=E4=BF=AE=E6=94=B9=20fix?= =?UTF-8?q?=EF=BC=9A=E5=A4=A7=E6=A8=A1=E5=9E=8B=E5=8E=86=E5=8F=B2=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E6=9F=A5=E8=AF=A2=E6=8E=A5=E5=8F=A3=E6=8A=A5=E9=94=99?= =?UTF-8?q?=E6=8F=90=E7=A4=BA=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../interactive/constants/DataAuthTypeEnum.java | 27 ++++++++++ .../controller/HznlmInteractiveController.java | 41 +++++++++++++++ .../controller/InteractiveController.java | 1 + .../bigmodel/interactive/dto/AuthDataDTO.java | 36 ++++++++++++++ .../service/IHznlmInteractiveService.java | 18 +++++++ .../service/impl/AnalyseDataServiceImpl.java | 57 +++++++++++++-------- .../service/impl/ExtraResolveStrategyService.java | 1 + .../service/impl/HzllmInteractiveServiceImpl.java | 58 ++++++++++++++++++++++ .../hzims/bigmodel/interactive/vo/AuthDataVO.java | 27 ++++++++++ .../interactive/vo/HistoryDataSearchVO.java | 2 + .../hzims/simulate/mapper/DeviceFieldGapMapper.xml | 18 ------- .../simulate/mapper/IHzllmInteractiveService.xml | 18 +++++++ 12 files changed, 264 insertions(+), 40 deletions(-) create mode 100644 hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/constants/DataAuthTypeEnum.java create mode 100644 hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/controller/HznlmInteractiveController.java create mode 100644 hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/dto/AuthDataDTO.java create mode 100644 hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/IHznlmInteractiveService.java create mode 100644 hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/HzllmInteractiveServiceImpl.java create mode 100644 hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/AuthDataVO.java delete mode 100644 hzims-service/hzims-simulate/src/main/java/com/hnac/hzims/simulate/mapper/DeviceFieldGapMapper.xml create mode 100644 hzims-service/hzims-simulate/src/main/java/com/hnac/hzims/simulate/mapper/IHzllmInteractiveService.xml diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/constants/DataAuthTypeEnum.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/constants/DataAuthTypeEnum.java new file mode 100644 index 0000000..ad3bb77 --- /dev/null +++ b/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 typeEnumOptional = Arrays.stream(DataAuthTypeEnum.class.getEnumConstants()).filter(e -> e.getType().equals(type)).findFirst(); + return typeEnumOptional.orElse(null); + } +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/controller/HznlmInteractiveController.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/controller/HznlmInteractiveController.java new file mode 100644 index 0000000..2b125a9 --- /dev/null +++ b/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> getAuthData(@RequestBody @Valid AuthDataDTO req) { + return R.data(interactiveService.getAuthData(req)); + } + +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/controller/InteractiveController.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/controller/InteractiveController.java index 26edbdf..7305f78 100644 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/controller/InteractiveController.java +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/controller/InteractiveController.java @@ -48,6 +48,7 @@ public class InteractiveController { @ApiOperation("站点、菜单鉴权") @ApiOperationSupport(order = 3) + @Deprecated @RequestMapping(value = "/authentication",method = {RequestMethod.GET,RequestMethod.POST}) public R authentication(@RequestParam(required = false) @ApiParam("站点编号") String stationId, @RequestParam @ApiParam("用户ID") String userId, diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/dto/AuthDataDTO.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/dto/AuthDataDTO.java new file mode 100644 index 0000000..3d4fba5 --- /dev/null +++ b/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; + +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/IHznlmInteractiveService.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/IHznlmInteractiveService.java new file mode 100644 index 0000000..f134480 --- /dev/null +++ b/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 getAuthData(@RequestBody @Valid AuthDataDTO req); + +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/AnalyseDataServiceImpl.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/AnalyseDataServiceImpl.java index aac20c6..1d574b1 100644 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/AnalyseDataServiceImpl.java +++ b/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 org.springblade.core.log.exception.ServiceException; 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.Func; import org.springblade.core.tool.utils.StringUtil; @@ -63,30 +64,46 @@ public class AnalyseDataServiceImpl implements IAnalyseDataService { extraVO.setType(FuncRouteEnum.HISTORY_DATA.getType().getType()); extraVO.setFuncCode(FuncRouteEnum.HISTORY_DATA.getFuncCode()); Map params = new HashMap<>(1); - ReductionDataVO dataVO = this.getPolymerizationData(searchVO); - List datalist = dataVO.getDataList().stream().map(m -> { - m.put("val", m.get(searchVO.getSignage())); - m.remove(searchVO.getSignage()); - return m; - }).collect(Collectors.toList()); - DataMethodEnum enumByMethod = DataMethodEnum.getEnumByMethod(searchVO.getMethod()); - String 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) - + ":"; + Result reductionDataVOR = this.getPolymerizationData(searchVO); + String label; + if(!reductionDataVOR.isSuccess()) { + params.put("errorInfo",reductionDataVOR.getMsg()); + label = "查询数据失败!"; + } + else { + ReductionDataVO dataVO = reductionDataVOR.getData(); + label = "暂未查到数据"; + params.put("data",Lists.newArrayList()); + if(Func.isNotEmpty(dataVO) && CollectionUtil.isNotEmpty(dataVO.getDataList())) { + List datalist = dataVO.getDataList().stream().map(m -> { + 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); - params.put("data",datalist); 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("beginTime",searchVO.getStartTime()); + params.put("endTime",searchVO.getEndTime()); extraVO.setParams(params); return extraVO; } - private ReductionDataVO getPolymerizationData(HistoryDataSearchVO searchVO) { + private Result getPolymerizationData(HistoryDataSearchVO searchVO) { DataMethodEnum enumByMethod = DataMethodEnum.getEnumByMethod(searchVO.getMethod()); Assert.isTrue(Func.isNotEmpty(enumByMethod),() -> { throw new ServiceException("数据查询聚合方式传参有误,查询失败!"); @@ -106,11 +123,7 @@ public class AnalyseDataServiceImpl implements IAnalyseDataService { dataDTO.setTimeInterval(1); dataDTO.setDtos(Lists.newArrayList(reductionAttrData)); logger.info("interactive:getPolymerizationData","config传参为:" + JSON.toJSONString(dataDTO)); - Result dataVO = deviceDataClient.pageDeviceCodeAndSignages(dataDTO); - Assert.isTrue(dataVO.isSuccess(),() -> { - throw new ServiceException("聚合历史数据查询失败!"); - }); - return dataVO.getData(); + return deviceDataClient.pageDeviceCodeAndSignages(dataDTO); } private DateEnum getDateEnumByDuration(String startTime,String endTime,DateEnum dateEnum) { diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/ExtraResolveStrategyService.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/ExtraResolveStrategyService.java index 26f047e..2a59476 100644 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/ExtraResolveStrategyService.java +++ b/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(); HistoryDataSearchVO searchVO = new HistoryDataSearchVO(); searchVO.setDataType(data.getDataType()); + searchVO.setAttrName(item.getAttrName()); searchVO.setDeviceCode(item.getDeviceId()); searchVO.setDeviceName(item.getDeviceName()); searchVO.setStationName(item.getProjectName()); diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/HzllmInteractiveServiceImpl.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/HzllmInteractiveServiceImpl.java new file mode 100644 index 0000000..668bd66 --- /dev/null +++ b/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 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 getDeptAuthData(String userId) { + List deptStationDTOs = authenticationService.getStationPermissionsById(userId); + return deptStationDTOs.stream().map(this::convertDeptAuthData).collect(Collectors.toList()); + } + + public List getStationAuthData(String userId) { + List 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()); + } +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/AuthDataVO.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/AuthDataVO.java new file mode 100644 index 0000000..a74f920 --- /dev/null +++ b/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; + +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/HistoryDataSearchVO.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/HistoryDataSearchVO.java index b6ea2f9..0728206 100644 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/HistoryDataSearchVO.java +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/HistoryDataSearchVO.java @@ -23,6 +23,8 @@ public class HistoryDataSearchVO { @NotBlank private String signage; + private String attrName; + @NotBlank private String method; diff --git a/hzims-service/hzims-simulate/src/main/java/com/hnac/hzims/simulate/mapper/DeviceFieldGapMapper.xml b/hzims-service/hzims-simulate/src/main/java/com/hnac/hzims/simulate/mapper/DeviceFieldGapMapper.xml deleted file mode 100644 index 7a4fff8..0000000 --- a/hzims-service/hzims-simulate/src/main/java/com/hnac/hzims/simulate/mapper/DeviceFieldGapMapper.xml +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - UPDATE HZINFO_FAC_DEVICE_ATTR_GAP - SET max_val = #{maxValue}, - min_val = #{minValue} - WHERE id = #{id} - - diff --git a/hzims-service/hzims-simulate/src/main/java/com/hnac/hzims/simulate/mapper/IHzllmInteractiveService.xml b/hzims-service/hzims-simulate/src/main/java/com/hnac/hzims/simulate/mapper/IHzllmInteractiveService.xml new file mode 100644 index 0000000..7a4fff8 --- /dev/null +++ b/hzims-service/hzims-simulate/src/main/java/com/hnac/hzims/simulate/mapper/IHzllmInteractiveService.xml @@ -0,0 +1,18 @@ + + + + + + + UPDATE HZINFO_FAC_DEVICE_ATTR_GAP + SET max_val = #{maxValue}, + min_val = #{minValue} + WHERE id = #{id} + +