Browse Source
# Conflicts: # hzims-service/hzims-alarm/pom.xml # hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/service/AlarmService.java # hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/service/impl/AlarmServiceImpl.java # hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/source/service/impl/MessageServiceImpl.java # hzims-service/hzims-big-model/pom.xml # hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/HzimsBigModelApplication.java # hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/task/service/impl/TaskServiceImpl.java # hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/feign/StationVideoTypeClient.java # pom.xmlzhongwei
yang_shj
5 months ago
153 changed files with 5475 additions and 439 deletions
@ -0,0 +1,32 @@
|
||||
package com.hnac.hzims.alarm.show.vo; |
||||
|
||||
import io.swagger.annotations.ApiModelProperty; |
||||
import lombok.Data; |
||||
import org.springblade.core.mp.support.QueryField; |
||||
import org.springblade.core.mp.support.SqlCondition; |
||||
|
||||
/** |
||||
* @author ysj |
||||
* @date 2023/03/17 10:02:33 |
||||
* @version 4.0.0 |
||||
*/ |
||||
@Data |
||||
public class AlarmVideoVo { |
||||
|
||||
@ApiModelProperty("视频设备编码") |
||||
private String pointCode; |
||||
|
||||
@ApiModelProperty("视频名称") |
||||
@QueryField(condition = SqlCondition.LIKE) |
||||
private String videoName; |
||||
|
||||
@ApiModelProperty("视频服务器host") |
||||
private String videoHost; |
||||
|
||||
@ApiModelProperty("运管中心appSecret") |
||||
private String videoAppSecret; |
||||
|
||||
@ApiModelProperty("运管中心appKey") |
||||
private String videoAppKey; |
||||
} |
||||
|
@ -0,0 +1,28 @@
|
||||
package com.hnac.hzims.alarm.show.vo; |
||||
|
||||
import io.swagger.annotations.ApiModelProperty; |
||||
import lombok.Data; |
||||
|
||||
import java.util.Date; |
||||
|
||||
/** |
||||
* @author ysj |
||||
* @date 2023/03/17 10:02:33 |
||||
* @version 4.0.0 |
||||
*/ |
||||
@Data |
||||
public class ShowQueryVo { |
||||
|
||||
@ApiModelProperty(value = "站点编号") |
||||
private String stationId; |
||||
|
||||
@ApiModelProperty(value = "站点类型") |
||||
private Integer serveType; |
||||
|
||||
@ApiModelProperty(value = "告警类型 :0- HZ3000告警 1 -等级告警 2 -条件告警 3-FDP智能预警 4-视频预警 5-开关机告警") |
||||
private Integer alarmSource; |
||||
|
||||
@ApiModelProperty(value = "告警子类") |
||||
private Integer alarmType; |
||||
} |
||||
|
@ -0,0 +1,21 @@
|
||||
package com.hnac.hzims.business.ws.alart.vo; |
||||
|
||||
import io.swagger.annotations.ApiModel; |
||||
import io.swagger.annotations.ApiModelProperty; |
||||
import lombok.Data; |
||||
|
||||
import java.util.List; |
||||
|
||||
/** |
||||
* @author ysj |
||||
*/ |
||||
@Data |
||||
@ApiModel(value = "告警弹框参数", description = "") |
||||
public class AlartParamVo { |
||||
|
||||
@ApiModelProperty("站点类型: 2-云服务 1-代运维") |
||||
private Integer serveType; |
||||
|
||||
@ApiModelProperty("用户权限机构集合") |
||||
private List<Long> depts; |
||||
} |
@ -0,0 +1,24 @@
|
||||
package com.hnac.hzims.bigmodel.entity; |
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName; |
||||
import io.swagger.annotations.ApiModel; |
||||
import io.swagger.annotations.ApiModelProperty; |
||||
import lombok.Data; |
||||
import lombok.EqualsAndHashCode; |
||||
import org.springblade.core.tenant.mp.TenantEntity; |
||||
|
||||
/** |
||||
* @author ysj |
||||
*/ |
||||
@EqualsAndHashCode(callSuper = true) |
||||
@TableName("hzims_whitelist") |
||||
@ApiModel(value = "白名单实体类",description = "大模型白名单") |
||||
@Data |
||||
public class WhitelistEntity extends TenantEntity { |
||||
|
||||
@ApiModelProperty(value = "用户Id") |
||||
private Long userId; |
||||
|
||||
@ApiModelProperty(value = "用户登录账号") |
||||
private String account; |
||||
} |
@ -0,0 +1,14 @@
|
||||
package com.hnac.hzims.bigmodel.interactive.vo; |
||||
|
||||
import lombok.Data; |
||||
|
||||
import java.io.Serializable; |
||||
|
||||
/** |
||||
* @Author: huangxing |
||||
* @Date: 2024/05/24 15:55 |
||||
*/ |
||||
@Data |
||||
public class AttrSelectionVO extends SelectionVO implements Serializable { |
||||
private DataItemVO item; |
||||
} |
@ -0,0 +1,40 @@
|
||||
package com.hnac.hzims.bigmodel.interactive.vo; |
||||
|
||||
import com.alibaba.fastjson.annotation.JSONField; |
||||
import lombok.Data; |
||||
|
||||
import java.io.Serializable; |
||||
|
||||
/** |
||||
* @Author: huangxing |
||||
* @Date: 2024/05/22 10:20 |
||||
*/ |
||||
@Data |
||||
public class DataItemVO implements Serializable { |
||||
|
||||
private String name; |
||||
|
||||
@JSONField(name = "id") |
||||
private String attrId; |
||||
|
||||
@JSONField(name = "record_name") |
||||
private String attrName; |
||||
|
||||
@JSONField(name = "device_name") |
||||
private String deviceName; |
||||
|
||||
@JSONField(name = "device_id") |
||||
private String deviceId; |
||||
|
||||
@JSONField(name = "station_id") |
||||
private String projectId; |
||||
|
||||
@JSONField(name = "station_name") |
||||
private String projectName; |
||||
|
||||
@JSONField(name = "record_id") |
||||
private String signage; |
||||
|
||||
private String units; |
||||
|
||||
} |
@ -0,0 +1,35 @@
|
||||
package com.hnac.hzims.bigmodel.interactive.vo; |
||||
|
||||
import com.alibaba.fastjson.annotation.JSONField; |
||||
import lombok.Data; |
||||
|
||||
import java.io.Serializable; |
||||
|
||||
/** |
||||
* @Author: huangxing |
||||
* @Date: 2024/05/22 10:28 |
||||
*/ |
||||
@Data |
||||
public class DataVO implements Serializable { |
||||
|
||||
/**数据查询类型:实时、历史**/ |
||||
private String type; |
||||
|
||||
@JSONField(name = "time_begin") |
||||
private String startTime; |
||||
|
||||
@JSONField(name = "time_end") |
||||
private String endTime; |
||||
|
||||
/**实时数据结果集**/ |
||||
private RealDataVO real; |
||||
|
||||
private DataItemVO item; |
||||
|
||||
/**包括:"其它"、"最大值"、"最小值"、"总和值"、"平均值"**/ |
||||
private String method; |
||||
|
||||
@JSONField(name = "data_type") |
||||
private String dataType; |
||||
|
||||
} |
@ -0,0 +1,18 @@
|
||||
package com.hnac.hzims.bigmodel.interactive.vo; |
||||
|
||||
import lombok.Data; |
||||
import lombok.EqualsAndHashCode; |
||||
|
||||
import java.io.Serializable; |
||||
|
||||
/** |
||||
* @Author: huangxing |
||||
* @Date: 2024/05/16 15:10 |
||||
*/ |
||||
@Data |
||||
@EqualsAndHashCode |
||||
public class FaultSelectionVO extends SelectionVO implements Serializable { |
||||
|
||||
private Object item; |
||||
|
||||
} |
@ -0,0 +1,20 @@
|
||||
package com.hnac.hzims.bigmodel.interactive.vo; |
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat; |
||||
import lombok.Data; |
||||
import org.springblade.core.tool.utils.DateUtil; |
||||
|
||||
import java.io.Serializable; |
||||
|
||||
/** |
||||
* @Author: huangxing |
||||
* @Date: 2024/05/24 10:26 |
||||
*/ |
||||
@Data |
||||
public class RealDataVO implements Serializable { |
||||
|
||||
private String time; |
||||
|
||||
private String value; |
||||
|
||||
} |
@ -0,0 +1,13 @@
|
||||
package com.hnac.hzims.bigmodel.interactive.vo; |
||||
|
||||
import java.io.Serializable; |
||||
|
||||
/** |
||||
* @Author: huangxing |
||||
* @Date: 2024/05/31 09:15 |
||||
*/ |
||||
public class RemoteSelectionVO extends SelectionVO implements Serializable { |
||||
|
||||
private Object item; |
||||
|
||||
} |
@ -0,0 +1,18 @@
|
||||
package com.hnac.hzims.bigmodel.interactive.vo; |
||||
|
||||
import lombok.Data; |
||||
import lombok.EqualsAndHashCode; |
||||
|
||||
import java.io.Serializable; |
||||
|
||||
/** |
||||
* @Author: huangxing |
||||
* @Date: 2024/05/11 16:21 |
||||
*/ |
||||
@Data |
||||
@EqualsAndHashCode |
||||
public class ScadaSelectionVO extends SelectionVO implements Serializable { |
||||
|
||||
private Object item; |
||||
|
||||
} |
@ -0,0 +1,20 @@
|
||||
package com.hnac.hzims.bigmodel.interactive.vo; |
||||
|
||||
import lombok.Data; |
||||
|
||||
import java.io.Serializable; |
||||
|
||||
/** |
||||
* @Author: huangxing |
||||
* @Date: 2024/05/09 16:30 |
||||
*/ |
||||
@Data |
||||
public class SelectionVO implements Serializable { |
||||
|
||||
/**选项ID**/ |
||||
private String id; |
||||
|
||||
/**选项名称**/ |
||||
private String name; |
||||
|
||||
} |
@ -0,0 +1,15 @@
|
||||
package com.hnac.hzims.bigmodel.interactive.vo; |
||||
|
||||
import com.hnac.hzims.bigmodel.interactive.vo.SelectionVO; |
||||
import lombok.Data; |
||||
|
||||
import java.io.Serializable; |
||||
|
||||
/** |
||||
* @Author: huangxing |
||||
* @Date: 2024/05/09 16:32 |
||||
*/ |
||||
@Data |
||||
public class StationSelectionVO extends SelectionVO implements Serializable { |
||||
|
||||
} |
@ -0,0 +1,16 @@
|
||||
package com.hnac.hzims.bigmodel.interactive.vo; |
||||
|
||||
import lombok.Data; |
||||
import lombok.EqualsAndHashCode; |
||||
|
||||
import java.io.Serializable; |
||||
|
||||
/** |
||||
* @Author: huangxing |
||||
* @Date: 2024/05/11 16:20 |
||||
*/ |
||||
@Data |
||||
@EqualsAndHashCode |
||||
public class VideoSelectionVO extends SelectionVO implements Serializable { |
||||
|
||||
} |
@ -0,0 +1,43 @@
|
||||
package com.hnac.hzims.equipment.entity; |
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName; |
||||
import io.swagger.annotations.ApiModel; |
||||
import io.swagger.annotations.ApiModelProperty; |
||||
import lombok.Data; |
||||
import lombok.EqualsAndHashCode; |
||||
import org.springblade.core.tenant.mp.TenantEntity; |
||||
|
||||
import java.math.BigDecimal; |
||||
|
||||
/** |
||||
* 实体类 |
||||
* |
||||
* @author Chill |
||||
*/ |
||||
@Data |
||||
@TableName("hzims_em_thirty_generate") |
||||
@EqualsAndHashCode(callSuper = true) |
||||
@ApiModel(value = "设备30天发电量对象", description = "") |
||||
public class ThirtyGenerationEntity extends TenantEntity { |
||||
|
||||
@ApiModelProperty(value = "站点编码") |
||||
private String stationId; |
||||
|
||||
@ApiModelProperty(value = "站点名称") |
||||
private String stationName; |
||||
|
||||
@ApiModelProperty(value = "设备编号") |
||||
private String deviceCode; |
||||
|
||||
@ApiModelProperty(value = "设备名称") |
||||
private String deviceName; |
||||
|
||||
@ApiModelProperty(value = "月份 : String") |
||||
private String strDay; |
||||
|
||||
@ApiModelProperty(value = "月份 : Int") |
||||
private Integer day; |
||||
|
||||
@ApiModelProperty(value = "发电量") |
||||
private BigDecimal generate; |
||||
} |
@ -0,0 +1,43 @@
|
||||
package com.hnac.hzims.equipment.entity; |
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName; |
||||
import io.swagger.annotations.ApiModel; |
||||
import io.swagger.annotations.ApiModelProperty; |
||||
import lombok.Data; |
||||
import lombok.EqualsAndHashCode; |
||||
import org.springblade.core.tenant.mp.TenantEntity; |
||||
|
||||
import java.math.BigDecimal; |
||||
|
||||
/** |
||||
* 实体类 |
||||
* |
||||
* @author Chill |
||||
*/ |
||||
@Data |
||||
@TableName("hzims_em_three_generate") |
||||
@EqualsAndHashCode(callSuper = true) |
||||
@ApiModel(value = "设备3年发电量对象", description = "") |
||||
public class ThreeGenerationEntity extends TenantEntity { |
||||
|
||||
@ApiModelProperty(value = "站点编码") |
||||
private String stationId; |
||||
|
||||
@ApiModelProperty(value = "站点名称") |
||||
private String stationName; |
||||
|
||||
@ApiModelProperty(value = "设备编号") |
||||
private String deviceCode; |
||||
|
||||
@ApiModelProperty(value = "设备名称") |
||||
private String deviceName; |
||||
|
||||
@ApiModelProperty(value = "月份 : String") |
||||
private String strMonth; |
||||
|
||||
@ApiModelProperty(value = "月份 : Int") |
||||
private Integer month; |
||||
|
||||
@ApiModelProperty(value = "发电量") |
||||
private BigDecimal generate; |
||||
} |
@ -0,0 +1,26 @@
|
||||
package com.hnac.hzims.operational.fill.feign; |
||||
|
||||
import com.hnac.hzims.operational.OperationalConstants; |
||||
import org.springframework.cloud.openfeign.FeignClient; |
||||
import org.springframework.web.bind.annotation.GetMapping; |
||||
import org.springframework.web.bind.annotation.RequestParam; |
||||
|
||||
/** |
||||
* @author ysj |
||||
*/ |
||||
@FeignClient( |
||||
value = OperationalConstants.APP_NAME, |
||||
fallback = IGenerateClientFallback.class |
||||
) |
||||
public interface IGenerateClient { |
||||
|
||||
String API_PREFIX = "/feign/generate/"; |
||||
|
||||
String STATION_GENERATE_BY_TIME = API_PREFIX + "/stationGenerateByTime"; |
||||
|
||||
|
||||
@GetMapping(STATION_GENERATE_BY_TIME) |
||||
Double stationGenerateByTime(@RequestParam("stationId") String stationId, |
||||
@RequestParam("startTime") String startTime, |
||||
@RequestParam("endTime") String endTime); |
||||
} |
@ -0,0 +1,15 @@
|
||||
package com.hnac.hzims.operational.fill.feign; |
||||
|
||||
import org.springframework.stereotype.Component; |
||||
|
||||
/** |
||||
* @author hx |
||||
*/ |
||||
@Component |
||||
public class IGenerateClientFallback implements IGenerateClient { |
||||
|
||||
@Override |
||||
public Double stationGenerateByTime(String stationId, String startTime, String endTime) { |
||||
return 0.0; |
||||
} |
||||
} |
@ -0,0 +1,14 @@
|
||||
package com.hnac.hzims.operational.main.constant; |
||||
|
||||
/** |
||||
* 定时任务JobHandler名称 |
||||
* @author 11423 |
||||
*/ |
||||
public interface ScheduledConstant { |
||||
|
||||
String THREE_YEAR_POWER_GENERATION = "threeYearPowerGeneration"; |
||||
|
||||
String THIRTY_DAY_POWER_GENERATION = "thirtyDayPowerGeneration"; |
||||
|
||||
String THIS_DAY_POWER_GENERATION = "thisDayPowerGeneration"; |
||||
} |
@ -0,0 +1,37 @@
|
||||
package com.hnac.hzims.bigmodel.data.controller; |
||||
|
||||
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; |
||||
import com.hnac.hzims.bigmodel.BigModelConstants; |
||||
import com.hnac.hzims.bigmodel.data.service.RemoteService; |
||||
import com.hnac.hzinfo.log.annotation.Business; |
||||
import io.swagger.annotations.Api; |
||||
import io.swagger.annotations.ApiOperation; |
||||
import lombok.AllArgsConstructor; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
import org.springblade.core.tool.api.R; |
||||
import org.springblade.system.dto.ControlDTO; |
||||
import org.springframework.web.bind.annotation.PostMapping; |
||||
import org.springframework.web.bind.annotation.RequestMapping; |
||||
import org.springframework.web.bind.annotation.RestController; |
||||
|
||||
/** |
||||
* @Author: huangxing |
||||
* @Date: 2024/06/24 14:42 |
||||
*/ |
||||
@AllArgsConstructor |
||||
@RequestMapping("/remote") |
||||
@RestController |
||||
@Api(value = "数据平台遥控指令管理",tags = "数据平台遥控指令管理") |
||||
@Business(module = BigModelConstants.APP_NAME,value = "数据平台遥控指令管理") |
||||
public class RemoteController { |
||||
|
||||
private final RemoteService remoteService; |
||||
|
||||
@ApiOperation("下发遥控指令") |
||||
@ApiOperationSupport(order = 1) |
||||
@PostMapping("/sendRemoteControl") |
||||
public R<Object> sendRemoteControl(ControlDTO controlDTO) { |
||||
return remoteService.sendRemoteControl(controlDTO); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,97 @@
|
||||
package com.hnac.hzims.bigmodel.data.service; |
||||
|
||||
import com.alibaba.fastjson.JSON; |
||||
import com.google.common.collect.Lists; |
||||
import com.hnac.hzims.bigmodel.interactive.constants.DataMethodEnum; |
||||
import com.hnac.hzims.bigmodel.interactive.constants.DateEnum; |
||||
import com.hnac.hzims.bigmodel.interactive.vo.HistoryDataSearchVO; |
||||
import com.hnac.hzinfo.sdk.core.response.Result; |
||||
import com.hnac.hzinfo.sdk.v5.device.DeviceDataClient; |
||||
import com.hnac.hzinfo.sdk.v5.device.dto.ReductionAttrDataDTO; |
||||
import com.hnac.hzinfo.sdk.v5.device.dto.ReductionDataDTO; |
||||
import com.hnac.hzinfo.sdk.v5.device.vo.ReductionDataVO; |
||||
import lombok.AllArgsConstructor; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
import org.springblade.core.log.exception.ServiceException; |
||||
import org.springblade.core.log.logger.BladeLogger; |
||||
import org.springblade.core.tool.utils.DateUtil; |
||||
import org.springblade.core.tool.utils.Func; |
||||
import org.springframework.stereotype.Service; |
||||
import org.springframework.util.Assert; |
||||
|
||||
import java.time.Duration; |
||||
import java.time.LocalDateTime; |
||||
import java.time.temporal.ChronoUnit; |
||||
|
||||
/** |
||||
* @Author: huangxing |
||||
* @Date: 2024/06/24 14:57 |
||||
*/ |
||||
@Service |
||||
@Slf4j |
||||
@AllArgsConstructor |
||||
public class HistoryDataService { |
||||
|
||||
private final DeviceDataClient deviceDataClient; |
||||
private final BladeLogger logger; |
||||
public static final int DATA_COUNT_MAX = 1000; |
||||
|
||||
public Result<ReductionDataVO> getPolymerizationData(HistoryDataSearchVO searchVO) { |
||||
DataMethodEnum enumByMethod = DataMethodEnum.getEnumByMethod(searchVO.getMethod()); |
||||
Assert.isTrue(Func.isNotEmpty(enumByMethod),() -> { |
||||
throw new ServiceException("数据查询聚合方式传参有误,查询失败!"); |
||||
}); |
||||
// 聚合数据方式处理
|
||||
DateEnum dateEnum = DateEnum.getDateEnumByType(searchVO.getDataType()); |
||||
ReductionDataDTO dataDTO = new ReductionDataDTO(); |
||||
ReductionAttrDataDTO reductionAttrData = new ReductionAttrDataDTO(); |
||||
reductionAttrData.setSignage(searchVO.getSignage()); |
||||
reductionAttrData.setAccessRules(enumByMethod.getAccessRule()); |
||||
reductionAttrData.setKeepFigures(2); |
||||
dataDTO.setBeginTime(LocalDateTime.parse(searchVO.getStartTime(), DateUtil.DATETIME_FORMATTER)); |
||||
dataDTO.setEndTime(LocalDateTime.parse(searchVO.getEndTime(),DateUtil.DATETIME_FORMATTER)); |
||||
dataDTO.setDeviceCode(searchVO.getDeviceCode()); |
||||
dataDTO.setNeedPage(false); |
||||
dataDTO.setSaveTimeType(dateEnum.getSaveTimeType()); |
||||
dataDTO.setTimeInterval(1); |
||||
dataDTO.setDtos(Lists.newArrayList(reductionAttrData)); |
||||
logger.info("interactive:getPolymerizationData","config传参为:" + JSON.toJSONString(dataDTO)); |
||||
return deviceDataClient.pageDeviceCodeAndSignages(dataDTO); |
||||
} |
||||
|
||||
public DateEnum getDateEnumByDuration(String startTime,String endTime,DateEnum dateEnum) { |
||||
LocalDateTime start = LocalDateTime.parse(startTime, DateUtil.DATETIME_FORMATTER); |
||||
LocalDateTime end = LocalDateTime.parse(endTime, DateUtil.DATETIME_FORMATTER); |
||||
Duration duration = Duration.between(start, end); |
||||
int count; |
||||
switch(dateEnum) { |
||||
case YEAR: |
||||
count = Long.valueOf(ChronoUnit.YEARS.between(start.toLocalDate(), end.toLocalDate())).intValue(); |
||||
break; |
||||
case MONTH: |
||||
count = Long.valueOf(ChronoUnit.MONTHS.between(start.toLocalDate(), end.toLocalDate())).intValue(); |
||||
break; |
||||
case DAY: |
||||
count = Long.valueOf(ChronoUnit.DAYS.between(start.toLocalDate(), end.toLocalDate())).intValue(); |
||||
break; |
||||
case HOUR: |
||||
count = Long.valueOf(duration.toHours()).intValue(); |
||||
break; |
||||
case MINUTE: |
||||
count = Long.valueOf(duration.toMinutes()).intValue(); |
||||
break; |
||||
case SECOND: |
||||
count = Long.valueOf(duration.getSeconds()).intValue(); |
||||
break; |
||||
default: |
||||
throw new ServiceException("未找到相关时间类型,查询失败!"); |
||||
} |
||||
if(count <= DATA_COUNT_MAX) { |
||||
return dateEnum; |
||||
} |
||||
else { |
||||
return getDateEnumByDuration(startTime, endTime, DateEnum.getDateEnumByOrder(dateEnum.getOrder() + 1)); |
||||
} |
||||
} |
||||
|
||||
} |
@ -0,0 +1,31 @@
|
||||
package com.hnac.hzims.bigmodel.data.service; |
||||
|
||||
import lombok.AllArgsConstructor; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
import org.springblade.core.tool.api.R; |
||||
import org.springblade.system.dto.ControlDTO; |
||||
import org.springblade.system.feign.IRemoteClient; |
||||
import org.springframework.stereotype.Service; |
||||
|
||||
/** |
||||
* @Author: huangxing |
||||
* @Date: 2024/06/24 14:36 |
||||
* @Descirbe: 数据平台 - 遥控服务类 |
||||
*/ |
||||
@Service |
||||
@Slf4j |
||||
@AllArgsConstructor |
||||
public class RemoteService { |
||||
|
||||
private final IRemoteClient remoteClient; |
||||
|
||||
/** |
||||
* 发送遥控指令 |
||||
* @param controlDTO 遥控指令 |
||||
* @return 结果 |
||||
*/ |
||||
public R<Object> sendRemoteControl(ControlDTO controlDTO) { |
||||
return remoteClient.sendCtrl(controlDTO); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,26 @@
|
||||
package com.hnac.hzims.bigmodel.datasource.controller; |
||||
|
||||
import com.hnac.hzims.bigmodel.datasource.service.DataSourceService; |
||||
import lombok.AllArgsConstructor; |
||||
import org.springblade.core.tool.api.R; |
||||
import org.springframework.web.bind.annotation.GetMapping; |
||||
import org.springframework.web.bind.annotation.RequestMapping; |
||||
import org.springframework.web.bind.annotation.RestController; |
||||
|
||||
/** |
||||
* @Author: huangxing |
||||
* @Date: 2024/06/28 14:07 |
||||
*/ |
||||
@RestController |
||||
@RequestMapping("/dataSource/execute") |
||||
@AllArgsConstructor |
||||
public class DataSourceExecuteController { |
||||
|
||||
private final DataSourceService dataSourceService; |
||||
|
||||
@GetMapping("/executeQuery") |
||||
public R executeQuery(String sql,String dataSourceName) { |
||||
return R.data(dataSourceService.queryListOnSpecificDataSource(sql,dataSourceName)); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,62 @@
|
||||
package com.hnac.hzims.bigmodel.datasource.service; |
||||
|
||||
import com.baomidou.dynamic.datasource.toolkit.DynamicDataSourceContextHolder; |
||||
import lombok.AllArgsConstructor; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
import org.springframework.jdbc.core.JdbcTemplate; |
||||
import org.springframework.stereotype.Service; |
||||
|
||||
import java.util.List; |
||||
import java.util.Map; |
||||
import java.util.regex.Pattern; |
||||
|
||||
/** |
||||
* @Author: huangxing |
||||
* @Date: 2024/06/28 15:24 |
||||
*/ |
||||
@Service |
||||
@AllArgsConstructor |
||||
@Slf4j |
||||
public class DataSourceService { |
||||
|
||||
private final JdbcTemplate jdbcTemplate; |
||||
|
||||
private static final Pattern UPDATE_PATTERN = Pattern.compile("^UPDATE\\s", Pattern.CASE_INSENSITIVE); |
||||
private static final Pattern DELETE_PATTERN = Pattern.compile("^DELETE\\s", Pattern.CASE_INSENSITIVE); |
||||
|
||||
/** |
||||
* 指定 |
||||
* @param sql |
||||
* @param dataSourceName |
||||
* @return |
||||
*/ |
||||
public List<Map<String, Object>> queryListOnSpecificDataSource(String sql,String dataSourceName) { |
||||
// 切换到指定的数据源
|
||||
DynamicDataSourceContextHolder.push(dataSourceName); |
||||
try { |
||||
return jdbcTemplate.queryForList(sql); |
||||
} finally { |
||||
// 清除,恢复默认数据源
|
||||
DynamicDataSourceContextHolder.clear(); |
||||
} |
||||
} |
||||
|
||||
public Integer updateOnSpecificDataSource(String sql,String dataSourceName) { |
||||
// 切换到指定的数据源
|
||||
DynamicDataSourceContextHolder.push(dataSourceName); |
||||
try { |
||||
return jdbcTemplate.update(sql); |
||||
} finally { |
||||
// 清除,恢复默认数据源
|
||||
DynamicDataSourceContextHolder.clear(); |
||||
} |
||||
} |
||||
|
||||
public static boolean isUpdateOrDelete(String sql) { |
||||
if (sql == null) { |
||||
return false; |
||||
} |
||||
return UPDATE_PATTERN.matcher(sql).find() || DELETE_PATTERN.matcher(sql).find(); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,14 @@
|
||||
package com.hnac.hzims.bigmodel.datasource.service; |
||||
|
||||
import java.util.List; |
||||
import java.util.Map; |
||||
|
||||
/** |
||||
* @Author: huangxing |
||||
* @Date: 2024/06/28 14:22 |
||||
*/ |
||||
public interface IDataSourceService { |
||||
|
||||
List<Map<String,Object>> queryList(String sql); |
||||
|
||||
} |
@ -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,36 @@
|
||||
package com.hnac.hzims.bigmodel.interactive.constants; |
||||
|
||||
import lombok.AllArgsConstructor; |
||||
import lombok.Getter; |
||||
|
||||
import java.util.Arrays; |
||||
|
||||
/** |
||||
* @Author: huangxing |
||||
* @Date: 2024/05/29 08:31 |
||||
*/ |
||||
@AllArgsConstructor |
||||
public enum DataMethodEnum { |
||||
USUAL("详情",6,"详情"), |
||||
EARLIEST("最早值",0,"最早值"), |
||||
MAX("最大值",1,"最大值"), |
||||
MIN("最小值",2,"最小值"), |
||||
AVERAGE("平均值",3,"平均值"), |
||||
SUM("累计值/和值",4,"总和值"), |
||||
DIFFERENCE("变化值/差值",5,"变化值"), |
||||
LATEST("最新值",6,"最新值"), |
||||
; |
||||
@Getter |
||||
private String name; |
||||
@Getter |
||||
private Integer accessRule; |
||||
@Getter |
||||
private String method; |
||||
|
||||
public static DataMethodEnum getEnumByMethod(String method) { |
||||
return Arrays.stream(DataMethodEnum.class.getEnumConstants()) |
||||
.filter(e -> e.getMethod().equals(method)) |
||||
.findFirst().orElse(null); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,41 @@
|
||||
package com.hnac.hzims.bigmodel.interactive.constants; |
||||
|
||||
import lombok.AllArgsConstructor; |
||||
import lombok.Getter; |
||||
|
||||
import java.util.Arrays; |
||||
|
||||
/** |
||||
* @Author: huangxing |
||||
* @Date: 2024/05/28 11:37 |
||||
*/ |
||||
@AllArgsConstructor |
||||
public enum DateEnum { |
||||
YEAR("year","每年","按年",5,6), |
||||
MONTH("month","每月","按月",4,5), |
||||
DAY("day","每天","按天",3,3), |
||||
HOUR("hour","每小时","按小时",2,2), |
||||
MINUTE("minute","每分钟","按分钟",1,1), |
||||
SECOND("second","每秒","按秒",0,0), |
||||
USUAL("usual","详情","按秒",0,0) |
||||
; |
||||
@Getter |
||||
private String code; |
||||
@Getter |
||||
private String name; |
||||
@Getter |
||||
private String dateType; |
||||
@Getter |
||||
private int order; |
||||
@Getter |
||||
private Integer saveTimeType; |
||||
|
||||
public static DateEnum getDateEnumByType(String dateType) { |
||||
return Arrays.stream(DateEnum.class.getEnumConstants()).filter(d -> d.getDateType().equals(dateType)).findFirst().orElse(null); |
||||
} |
||||
|
||||
public static DateEnum getDateEnumByOrder(int order) { |
||||
return Arrays.stream(DateEnum.class.getEnumConstants()).filter(d -> d.getOrder() == order).findFirst().orElse(null); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,11 @@
|
||||
package com.hnac.hzims.bigmodel.interactive.constants; |
||||
|
||||
/** |
||||
* @Author: huangxing |
||||
* @Date: 2024/06/21 16:35 |
||||
*/ |
||||
public interface InfoMessageConstant { |
||||
|
||||
String ERROR_MESSAGE = "非常抱歉,系统在处理您的请求时遇到了问题。请稍后再试或联系我们的客服团队。"; |
||||
|
||||
} |
@ -0,0 +1,19 @@
|
||||
package com.hnac.hzims.bigmodel.interactive.constants; |
||||
|
||||
/** |
||||
* @Author: huangxing |
||||
* @Date: 2024/07/01 14:26 |
||||
* @Describe: 参数key管理 |
||||
*/ |
||||
public interface ParamKeyConstants { |
||||
|
||||
/**实时画面host**/ |
||||
String CANVAS_HOST = "hzims:bigModel:canvas:host"; |
||||
/**实时画面v3路径 {context}&stationNum={stationNum}&projectId={projectId}**/ |
||||
String CANVAS_V3_PATH = "hzims:bigModel:canvas:v3:path"; |
||||
/**实时画面v4路径 other/v4/canvas/index.html?hzinfowebkit=true&taskId={taskId}&stationNum={stationNum}&projectId={projectId}&source=app&picName={context}&name={name}**/ |
||||
String CANVAS_V4_PATH = "hzims:bigModel:canvas:v4:path"; |
||||
/**实时画面云组态路径 hzinfo-data-scada/view/{projectId}/{id}?source=app**/ |
||||
String CANVAS_YZT_PATH = "hzims:bigModel:canvas:yzt:path"; |
||||
|
||||
} |
@ -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,44 @@
|
||||
package com.hnac.hzims.bigmodel.interactive.constants; |
||||
|
||||
import lombok.AllArgsConstructor; |
||||
import lombok.Getter; |
||||
|
||||
import java.util.Arrays; |
||||
|
||||
/** |
||||
* @Author: huangxing |
||||
* @Date: 2024/05/24 17:14 |
||||
*/ |
||||
@AllArgsConstructor |
||||
public enum SearchStationTypeEnum { |
||||
STATION_TOTAL("电站总数量",null,"智能运维平台接入电站总数为:%s"), |
||||
SET_TOTAL("站点总数量",null,"智能运维平台接入站点总数为:%s"), |
||||
HYDROPOWER_TOTAL("水电站总数量","0","智能运维平台接入水电站总数为:%s"), |
||||
WIND_POWER_TOTAL("风电场总数量","1","智能运维平台接入风电场总数为:%s"), |
||||
ENERGY_STORAGE_TOTAL("储能站总数量","3","智能运维平台接入储能站总数为:%s"), |
||||
PHOTOVOLTAIC_TOTAL("光伏站总数量","5","智能运维平台接入光伏站总数为:%s"), |
||||
CHARGE_TOTAL("充电站总数量","7","智能运维平台接入充电站总数为:%s"), |
||||
STATION_NUM("电站接入量",null,"智能运维平台接入电站总数为:%s"), |
||||
SET_NUM("站点接入量",null,"智能运维平台接入站点总数为:%s"), |
||||
HYDROPOWER_NUM("水电站接入量","0","智能运维平台接入水电站接入量为:%s"), |
||||
WIND_POWER_NUM("风电场接入量","1","智能运维平台接入风电场接入量为:%s"), |
||||
ENERGY_STORAGE_NUM("储能站接入量","3","智能运维平台接入储能站接入量为:%s"), |
||||
PHOTOVOLTAIC_NUM("光伏站接入量","5","智能运维平台接入光伏站接入量为:%s"), |
||||
CHARGE_NUM("充电站接入量","7","智能运维平台接入充电站接入量为:%s"), |
||||
; |
||||
|
||||
@Getter |
||||
private String searchStationType; |
||||
@Getter |
||||
private String stationType; |
||||
@Getter |
||||
private String label; |
||||
|
||||
public static SearchStationTypeEnum getTypeEnum(String searchStationType) { |
||||
return Arrays.stream(SearchStationTypeEnum.class.getEnumConstants()) |
||||
.filter(e -> e.getSearchStationType().equals(searchStationType)) |
||||
.findFirst() |
||||
.orElse(null); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,28 @@
|
||||
package com.hnac.hzims.bigmodel.interactive.constants; |
||||
|
||||
import lombok.AllArgsConstructor; |
||||
import lombok.Data; |
||||
import lombok.Getter; |
||||
|
||||
import java.util.Arrays; |
||||
|
||||
/** |
||||
* @Author: huangxing |
||||
* @Date: 2024/05/24 17:13 |
||||
*/ |
||||
@AllArgsConstructor |
||||
public enum SearchTypeEnum { |
||||
REAL("实时"), |
||||
HISTORY("历史") |
||||
; |
||||
@Getter |
||||
private String searchType; |
||||
|
||||
public static SearchTypeEnum getSearchType(String searchType) { |
||||
return Arrays.stream(SearchTypeEnum.class.getEnumConstants()) |
||||
.filter(e -> e.getSearchType().equals(searchType)) |
||||
.findFirst() |
||||
.orElse(null); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,34 @@
|
||||
package com.hnac.hzims.bigmodel.interactive.controller; |
||||
|
||||
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; |
||||
import com.hnac.hzims.bigmodel.interactive.service.IAnalyseDataService; |
||||
import com.hnac.hzims.bigmodel.interactive.vo.HistoryDataSearchVO; |
||||
import io.swagger.annotations.Api; |
||||
import io.swagger.annotations.ApiOperation; |
||||
import lombok.AllArgsConstructor; |
||||
import org.springblade.core.tool.api.R; |
||||
import org.springframework.validation.annotation.Validated; |
||||
import org.springframework.web.bind.annotation.GetMapping; |
||||
import org.springframework.web.bind.annotation.RequestMapping; |
||||
import org.springframework.web.bind.annotation.RestController; |
||||
|
||||
/** |
||||
* @Author: huangxing |
||||
* @Date: 2024/05/29 09:22 |
||||
*/ |
||||
@RequestMapping("/analyse/data") |
||||
@AllArgsConstructor |
||||
@Api(value = "数据查询管理",tags = "数据查询管理") |
||||
@RestController |
||||
@Deprecated |
||||
public class AnalyseDataController { |
||||
|
||||
private final IAnalyseDataService analyseDataService; |
||||
|
||||
@GetMapping("/getHistoryData") |
||||
@ApiOperation("获取历史数据") |
||||
@ApiOperationSupport(order = 1) |
||||
public R getHistoryData(@Validated HistoryDataSearchVO searchVO) { |
||||
return R.data(analyseDataService.getHistoryData(searchVO)); |
||||
} |
||||
} |
@ -0,0 +1,63 @@
|
||||
package com.hnac.hzims.bigmodel.interactive.controller; |
||||
|
||||
import com.baomidou.mybatisplus.core.toolkit.IdWorker; |
||||
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; |
||||
import com.google.common.collect.Lists; |
||||
import com.hnac.hzims.bigmodel.BigModelConstants; |
||||
import com.hnac.hzims.bigmodel.interactive.service.IHznlmInvokeService; |
||||
import com.hnac.hzinfo.log.annotation.Business; |
||||
import io.swagger.annotations.Api; |
||||
import io.swagger.annotations.ApiOperation; |
||||
import io.swagger.annotations.ApiParam; |
||||
import lombok.AllArgsConstructor; |
||||
import org.springblade.core.tool.api.R; |
||||
import org.springframework.web.bind.annotation.GetMapping; |
||||
import org.springframework.web.bind.annotation.RequestMapping; |
||||
import org.springframework.web.bind.annotation.RequestParam; |
||||
import org.springframework.web.bind.annotation.RestController; |
||||
|
||||
import java.util.List; |
||||
|
||||
/** |
||||
* @Author: huangxing |
||||
* @Date: 2024/06/24 14:19 |
||||
*/ |
||||
@RestController |
||||
@RequestMapping("/fontEnd/interactive") |
||||
@Api(value = "前端交互控制层",tags = "前端交互控制层") |
||||
@AllArgsConstructor |
||||
@Business(module = BigModelConstants.APP_NAME,value = "前端交互层管理",ignore = false) |
||||
public class FontEndInteractiveController { |
||||
|
||||
private final IHznlmInvokeService hznlmInvokeService; |
||||
|
||||
@ApiOperation("提问") |
||||
@ApiOperationSupport(order = 1) |
||||
@GetMapping("/ask") |
||||
public R ask(@RequestParam @ApiParam("用户提出问题") String question, @RequestParam @ApiParam("问答sessionId") String sessionId, @RequestParam @ApiParam("用户Id") String userId) { |
||||
hznlmInvokeService.ask(question, sessionId, userId); |
||||
return R.success("操作成功!"); |
||||
} |
||||
|
||||
@ApiOperation("删除对话sessionId") |
||||
@ApiOperationSupport(order = 2) |
||||
@GetMapping("/removeSessionId") |
||||
public R<Boolean> removeSessionId(@RequestParam(value = "id") String sessionId) { |
||||
hznlmInvokeService.removeSessionId(sessionId); |
||||
return R.success("操作成功!"); |
||||
} |
||||
|
||||
@ApiOperation("获取热点问题") |
||||
@ApiOperationSupport(order = 3) |
||||
@GetMapping("/hotQuestions") |
||||
public R<List<String>> hotQuestions() { |
||||
return R.data(hznlmInvokeService.hotQuestions()); |
||||
} |
||||
|
||||
@ApiOperation("获取问答sessionId") |
||||
@ApiOperationSupport(order = 4) |
||||
@GetMapping("/getSessionId") |
||||
public R<String> getSessionId() { |
||||
return R.data(IdWorker.get32UUID()); |
||||
} |
||||
} |
@ -0,0 +1,47 @@
|
||||
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.req.ModelFunctionReq; |
||||
import com.hnac.hzims.bigmodel.interactive.service.IHznlmInteractiveService; |
||||
import com.hnac.hzims.bigmodel.interactive.vo.AuthDataVO; |
||||
import com.hnac.hzims.bigmodel.interactive.vo.ExtraVO; |
||||
import com.hnac.hzims.bigmodel.interactive.vo.ResolveResultVO; |
||||
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.*; |
||||
|
||||
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; |
||||
|
||||
@PostMapping(value = "/get_auth_data") |
||||
@ApiOperation("获取鉴权数据") |
||||
@ApiOperationSupport(order = 1) |
||||
public R<List<AuthDataVO>> getAuthData(@RequestBody AuthDataDTO req) { |
||||
return R.data(interactiveService.getAuthData(req)); |
||||
} |
||||
|
||||
@ApiOperation("解析大模型函数") |
||||
@ApiOperationSupport(order = 2) |
||||
@PostMapping("/resolve") |
||||
public R<ExtraVO> resolve(@RequestBody ModelFunctionReq req) { |
||||
return R.data(interactiveService.resolve(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,55 @@
|
||||
package com.hnac.hzims.bigmodel.interactive.factory; |
||||
|
||||
import com.alibaba.fastjson.JSON; |
||||
import com.alibaba.fastjson.JSONObject; |
||||
import com.hnac.hzims.bigmodel.interactive.constants.FuncRouteEnum; |
||||
import com.hnac.hzims.bigmodel.interactive.service.IAnswerResolveService; |
||||
import com.hnac.hzims.bigmodel.interactive.service.IResolveService; |
||||
import com.hnac.hzims.bigmodel.interactive.vo.AnswerVO; |
||||
import org.springblade.core.log.exception.ServiceException; |
||||
import org.springblade.core.log.logger.BladeLogger; |
||||
import org.springblade.core.tool.utils.Func; |
||||
import org.springblade.core.tool.utils.SpringUtil; |
||||
|
||||
/** |
||||
* @Author: huangxing |
||||
* @Date: 2024/06/21 18:44 |
||||
*/ |
||||
public class AnswerResolveFactory { |
||||
|
||||
public static final String DIAGNOSE_ANSWER_SERVICE = "diagnoseAnswerResolveService"; |
||||
public static final String CHOICE_ANSWER_SERVICE = "choiceAnswerResolveService"; |
||||
public static final String REMOTE_ANSWER_SERVICE = "remoteAnswerResolveService"; |
||||
public static final String PARAM_ANSWER_SERVICE = "paramAnswerResolveService"; |
||||
public static final String PRE_ANSWER_SERVICE = "preAnswerResolveService"; |
||||
|
||||
public static IAnswerResolveService getResolveService(Object extra) { |
||||
String funcCode = JSONObject.parseObject(JSON.toJSONString(extra)).getString("func"); |
||||
return AnswerResolveFactory.getResolveService(funcCode); |
||||
} |
||||
|
||||
public static IAnswerResolveService getResolveService(String funcCode) { |
||||
FuncRouteEnum funcRouteEnum = FuncRouteEnum.getEnumByFuncCode(funcCode); |
||||
if(Func.isNotEmpty(funcRouteEnum)) { |
||||
switch (funcRouteEnum) { |
||||
case DIAGNOSE: |
||||
return SpringUtil.getBean(DIAGNOSE_ANSWER_SERVICE); |
||||
case CHOOSE_VIDEO: |
||||
case CHOOSE_CANVAS: |
||||
case CHOOSE_STATION: |
||||
case CHOOSE_FAULT: |
||||
case CHOOSE_YC: |
||||
case CHOOSE_YK: |
||||
return SpringUtil.getBean(CHOICE_ANSWER_SERVICE); |
||||
case CONFIRM_YK: |
||||
return SpringUtil.getBean(REMOTE_ANSWER_SERVICE); |
||||
case SHOW_PARAM: |
||||
return SpringUtil.getBean(PARAM_ANSWER_SERVICE); |
||||
default: |
||||
return null; |
||||
} |
||||
} |
||||
throw new ServiceException("service解析失败!"); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,44 @@
|
||||
package com.hnac.hzims.bigmodel.interactive.factory; |
||||
|
||||
import com.hnac.hzims.bigmodel.entity.FunctionEntity; |
||||
import com.hnac.hzims.bigmodel.function.service.IFunctionService; |
||||
import com.hnac.hzims.bigmodel.interactive.constants.FuncRouteEnum; |
||||
import com.hnac.hzims.bigmodel.interactive.constants.FunctionConstants; |
||||
import com.hnac.hzims.bigmodel.interactive.service.IResolveService; |
||||
import org.springblade.core.log.exception.ServiceException; |
||||
import org.springblade.core.log.logger.BladeLogger; |
||||
import org.springblade.core.tool.utils.Func; |
||||
import org.springblade.core.tool.utils.SpringUtil; |
||||
|
||||
/** |
||||
* @Author: huangxing |
||||
* @Date: 2024/06/21 15:53 |
||||
*/ |
||||
public class ResolveFactory { |
||||
|
||||
public static final String CANVAS_RESOLVE_SERVICE = "canvasResolveService"; |
||||
public static final String VIDEO_RESOLVE_SERVICE = "videoResolveService"; |
||||
|
||||
/** |
||||
* 获取解析函数需要的service |
||||
* @param funcCode 函数编号 |
||||
* @return 解析函数所需service |
||||
*/ |
||||
public static IResolveService getResolveService(String funcCode) { |
||||
BladeLogger logger = SpringUtil.getBean(BladeLogger.class); |
||||
FuncRouteEnum funcRouteEnum = FuncRouteEnum.getEnumByFuncCode(funcCode); |
||||
if(Func.isNotEmpty(funcRouteEnum)) { |
||||
switch(funcRouteEnum) { |
||||
case OPEN_CANVAS: |
||||
return SpringUtil.getBean("canvasResolveService"); |
||||
case OPEN_VIDEO: |
||||
return SpringUtil.getBean("videoResolveService"); |
||||
default: |
||||
logger.error("hzims:bigModel:getResolveService","函数解析失败,函数编号为:" + funcCode); |
||||
throw new ServiceException("service解析失败"); |
||||
} |
||||
} |
||||
throw new ServiceException("service解析失败"); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,16 @@
|
||||
package com.hnac.hzims.bigmodel.interactive.service; |
||||
|
||||
import com.alibaba.fastjson.JSONObject; |
||||
import com.hnac.hzims.bigmodel.interactive.vo.AnswerVO; |
||||
import com.hnac.hzims.bigmodel.interactive.vo.ExtraVO; |
||||
import com.hnac.hzims.bigmodel.interactive.vo.HistoryDataSearchVO; |
||||
|
||||
/** |
||||
* @Author: huangxing |
||||
* @Date: 2024/05/28 11:29 |
||||
*/ |
||||
public interface IAnalyseDataService { |
||||
|
||||
ExtraVO getHistoryData(HistoryDataSearchVO searchVO); |
||||
|
||||
} |
@ -0,0 +1,34 @@
|
||||
package com.hnac.hzims.bigmodel.interactive.service; |
||||
|
||||
import com.alibaba.fastjson.JSON; |
||||
import com.alibaba.fastjson.JSONObject; |
||||
import com.hnac.hzims.bigmodel.interactive.vo.AnswerVO; |
||||
import com.hnac.hzims.bigmodel.interactive.vo.ExtraVO; |
||||
|
||||
import java.util.Arrays; |
||||
import java.util.stream.Stream; |
||||
|
||||
/** |
||||
* @Author: huangxing |
||||
* @Date: 2024/06/21 18:39 |
||||
*/ |
||||
public interface IAnswerResolveService { |
||||
|
||||
AnswerVO resolve(AnswerVO answer); |
||||
|
||||
/** |
||||
* 解析 extra |
||||
* @param originExtra 大模型传入 extra |
||||
* @return 解析后的 extra |
||||
*/ |
||||
ExtraVO getExtra(JSONObject originExtra); |
||||
|
||||
/*** |
||||
* |
||||
* @param answer |
||||
* @return |
||||
*/ |
||||
default Stream<JSONObject> extraStream(AnswerVO answer) { |
||||
return Arrays.stream(answer.getExtras()).map(JSON::toJSONString).map(JSONObject::parseObject); |
||||
} |
||||
} |
@ -0,0 +1,22 @@
|
||||
package com.hnac.hzims.bigmodel.interactive.service; |
||||
|
||||
import com.hnac.hzims.bigmodel.interactive.dto.AuthDataDTO; |
||||
import com.hnac.hzims.bigmodel.interactive.req.ModelFunctionReq; |
||||
import com.hnac.hzims.bigmodel.interactive.vo.AuthDataVO; |
||||
import com.hnac.hzims.bigmodel.interactive.vo.ExtraVO; |
||||
import com.hnac.hzims.bigmodel.interactive.vo.ResolveResultVO; |
||||
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); |
||||
|
||||
ExtraVO resolve(ModelFunctionReq req); |
||||
} |
@ -0,0 +1,63 @@
|
||||
package com.hnac.hzims.bigmodel.interactive.service; |
||||
|
||||
import com.hnac.hzims.bigmodel.interactive.vo.AnswerVO; |
||||
import org.springblade.core.tool.api.R; |
||||
|
||||
import java.util.List; |
||||
import java.util.Map; |
||||
|
||||
/** |
||||
* @Author: huangxing |
||||
* @Date: 2024/06/21 17:20 |
||||
*/ |
||||
public interface IHznlmInvokeService { |
||||
|
||||
/** |
||||
* 基础问题 |
||||
* @param question 提问问题 |
||||
* @param sessionId 会话ID |
||||
* @param userId 提问人ID |
||||
* @return 提问结果 |
||||
*/ |
||||
void ask(String question, String sessionId, String userId); |
||||
|
||||
/** |
||||
* 特殊问题 |
||||
* @param sessionId 会话ID |
||||
* @param userId 提问人ID |
||||
* @param extra 特殊问题内容 |
||||
* @return 提问结果 |
||||
*/ |
||||
void specialAsk(String sessionId, String userId, Map<String,Object> extra); |
||||
|
||||
/** |
||||
* 知识库问题 |
||||
* @param question 问题名称 |
||||
* @param sessionId 会话ID |
||||
* @param userId 提问人ID |
||||
* @param knowledge 知识库名称 |
||||
*/ |
||||
void knowledgeAsk(String question, String sessionId, String userId, String knowledge); |
||||
|
||||
/** |
||||
* 删除对话记录 |
||||
* @param sessionId 会话ID |
||||
*/ |
||||
void removeSessionId(String sessionId); |
||||
|
||||
/** |
||||
* 获取热点问题 |
||||
* @return 热点问题 |
||||
*/ |
||||
List hotQuestions(); |
||||
|
||||
/** |
||||
* 查询问答状态 |
||||
* @param sessionIds 会话ID,按逗号分隔 |
||||
* @return 答案列表 |
||||
*/ |
||||
List<AnswerVO> getAnswerBySessionIds(String sessionIds); |
||||
|
||||
|
||||
|
||||
} |
@ -0,0 +1,15 @@
|
||||
package com.hnac.hzims.bigmodel.interactive.service; |
||||
|
||||
import com.hnac.hzims.bigmodel.entity.FunctionEntity; |
||||
|
||||
import java.util.Map; |
||||
|
||||
/** |
||||
* @Author: huangxing |
||||
* @Date: 2024/05/09 08:50 |
||||
*/ |
||||
@Deprecated |
||||
public interface IParamsService { |
||||
String dealJumpTypeFunction(FunctionEntity function, Map<String,String> args); |
||||
|
||||
} |
@ -0,0 +1,17 @@
|
||||
package com.hnac.hzims.bigmodel.interactive.service; |
||||
|
||||
import com.hnac.hzims.bigmodel.interactive.req.ModelFunctionReq; |
||||
import com.hnac.hzims.bigmodel.interactive.vo.ExtraVO; |
||||
import com.hnac.hzims.bigmodel.interactive.vo.ResolveResultVO; |
||||
|
||||
/** |
||||
* @Author: huangxing |
||||
* @Date: 2024/06/21 15:39 |
||||
*/ |
||||
public interface IResolveService { |
||||
|
||||
ExtraVO resolve(String id); |
||||
|
||||
ExtraVO resolve(ModelFunctionReq req); |
||||
|
||||
} |
@ -0,0 +1,100 @@
|
||||
package com.hnac.hzims.bigmodel.interactive.service.impl; |
||||
|
||||
import com.alibaba.fastjson.JSON; |
||||
import com.google.common.collect.Lists; |
||||
import com.hnac.hzims.bigmodel.data.service.HistoryDataService; |
||||
import com.hnac.hzims.bigmodel.interactive.constants.DataMethodEnum; |
||||
import com.hnac.hzims.bigmodel.interactive.constants.DateEnum; |
||||
import com.hnac.hzims.bigmodel.interactive.constants.FuncRouteEnum; |
||||
import com.hnac.hzims.bigmodel.interactive.service.IAnalyseDataService; |
||||
import com.hnac.hzims.bigmodel.interactive.vo.ExtraVO; |
||||
import com.hnac.hzims.bigmodel.interactive.vo.HistoryDataSearchVO; |
||||
import com.hnac.hzinfo.sdk.core.response.Result; |
||||
import com.hnac.hzinfo.sdk.v5.device.DeviceDataClient; |
||||
import com.hnac.hzinfo.sdk.v5.device.dto.ReductionAttrDataDTO; |
||||
import com.hnac.hzinfo.sdk.v5.device.dto.ReductionDataDTO; |
||||
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; |
||||
import org.springframework.stereotype.Service; |
||||
import org.springframework.util.Assert; |
||||
|
||||
import java.time.Duration; |
||||
import java.time.LocalDateTime; |
||||
import java.time.temporal.ChronoUnit; |
||||
import java.util.HashMap; |
||||
import java.util.List; |
||||
import java.util.Map; |
||||
import java.util.stream.Collectors; |
||||
|
||||
/** |
||||
* @Author: huangxing |
||||
* @Date: 2024/05/28 11:29 |
||||
*/ |
||||
@Service |
||||
@AllArgsConstructor |
||||
public class AnalyseDataServiceImpl implements IAnalyseDataService { |
||||
|
||||
private final HistoryDataService historyDataService; |
||||
|
||||
@Override |
||||
public ExtraVO getHistoryData(HistoryDataSearchVO searchVO) { |
||||
if(Func.isEmpty(searchVO.getDataType()) || StringUtil.isBlank(searchVO.getDataType()) |
||||
|| DataMethodEnum.USUAL.getMethod().equals(searchVO.getMethod())) { |
||||
searchVO.setDataType(DateEnum.SECOND.getDateType()); |
||||
} |
||||
// 聚合数据方式处理
|
||||
DateEnum dateEnum = DateEnum.getDateEnumByType(searchVO.getDataType()); |
||||
searchVO.setDataType(dateEnum.getDateType()); |
||||
// 获取最适配时间段
|
||||
DateEnum adapterDate = historyDataService.getDateEnumByDuration(searchVO.getStartTime(), searchVO.getEndTime(), dateEnum); |
||||
String note = adapterDate.getDateType().equals(searchVO.getDataType()) ? "" : "(由于数据量过大,只能帮您" + adapterDate.getDateType() + "查询)"; |
||||
searchVO.setDataType(adapterDate.getDateType()); |
||||
ExtraVO extraVO = new ExtraVO(); |
||||
extraVO.setType(FuncRouteEnum.HISTORY_DATA.getType().getType()); |
||||
extraVO.setFunc(FuncRouteEnum.HISTORY_DATA.getFuncCode()); |
||||
Map<String,Object> params = new HashMap<>(1); |
||||
Result<ReductionDataVO> reductionDataVOR = historyDataService.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<Map> 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("deviceName",searchVO.getDeviceName()); |
||||
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; |
||||
} |
||||
} |
@ -0,0 +1,128 @@
|
||||
package com.hnac.hzims.bigmodel.interactive.service.impl; |
||||
|
||||
import com.google.common.collect.Lists; |
||||
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.hzims.bigmodel.interactive.vo.SessionContentVO; |
||||
import com.hnac.hzims.bigmodel.websocket.constants.RedisKeyConstants; |
||||
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.entity.CtrlAuth; |
||||
import org.springblade.system.feign.IDeptClient; |
||||
import org.springblade.system.feign.IRemoteClient; |
||||
import org.springblade.system.user.feign.IUserClient; |
||||
import org.springframework.data.redis.core.RedisTemplate; |
||||
import org.springframework.stereotype.Service; |
||||
import org.springframework.util.Assert; |
||||
|
||||
import java.util.List; |
||||
import java.util.Optional; |
||||
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; |
||||
private final RedisTemplate redisTemplate; |
||||
|
||||
/** |
||||
* 站点鉴权 |
||||
* @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 userId 用户ID |
||||
* @param func 函数编号 |
||||
*/ |
||||
public void menuAuthentication(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 |
||||
*/ |
||||
public void remoteAuthentication(String stationId, String userId,String sessionId) { |
||||
// 查询数据平台站点是否可被遥控
|
||||
Result<List<ProjectVO>> projectR = projectClient.getProjectIds(Lists.newArrayList(stationId)); |
||||
Assert.isTrue(projectR.isSuccess() && CollectionUtil.isNotEmpty(projectR.getData()) && projectR.getData().size() == 1,() -> { |
||||
throw new ServiceException("未查询到站点,鉴权失败!"); |
||||
}); |
||||
ProjectVO project = projectR.getData().get(0); |
||||
if(ProjectRemoteTypeEnum.NOT_ALLOW.getCtrlType().equals(project.getCtrlType())) { |
||||
// 不允许发送遥控
|
||||
throw new ServiceException("该站点不允许发送遥控指令,校验失败!"); |
||||
} |
||||
else if(ProjectRemoteTypeEnum.VALID.getCtrlType().equals(project.getCtrlType())) { |
||||
// 运行发送遥控并且需要校验权限
|
||||
R<List<CtrlAuth>> ctrlAuthR = remoteClient.getCtrlAuth(Optional.ofNullable(userId).filter(StringUtil::isNotBlank).map(Long::parseLong).orElse(null)); |
||||
Assert.isTrue(ctrlAuthR.isSuccess(),() -> { |
||||
throw new ServiceException("该站点未设置鉴权用户,校验失败!"); |
||||
}); |
||||
List<CtrlAuth> ctrlAuthList = ctrlAuthR.getData(); |
||||
Optional<CtrlAuth> authOptional = ctrlAuthList.stream().filter(c -> c.getProjectId().equals(stationId)).findFirst(); |
||||
Assert.isTrue(authOptional.isPresent() && Func.isNotEmpty(authOptional.get().getIsLimitMachine()), () -> { |
||||
throw new ServiceException("该用户不存在相应站点权限,校验不通过!"); |
||||
}); |
||||
CtrlAuth ctrlAuth = authOptional.get(); |
||||
// 如限制机器发送遥控指令
|
||||
if(ctrlAuth.getIsLimitMachine().intValue() == 1) { |
||||
SessionContentVO sessionContent = (SessionContentVO) redisTemplate.opsForHash().get(RedisKeyConstants.SESSION_CONTENT_KEY, sessionId); |
||||
Assert.isTrue(Func.isNotEmpty(sessionContent),() -> { |
||||
throw new ServiceException("获取问题机器码失败,校验不通过!"); |
||||
}); |
||||
String machineCode = sessionContent.getMachineCode(); |
||||
Assert.isTrue(StringUtil.isNotBlank(machineCode) && Func.isNotEmpty(machineCode) ,() -> { |
||||
throw new ServiceException("获取问题机器码失败,校验不通过!"); |
||||
}); |
||||
Assert.isTrue(machineCode.equals(ctrlAuth.getMachineCode()),() -> { |
||||
throw new ServiceException("站点校验码校验失败,校验不通过!"); |
||||
}); |
||||
} |
||||
} |
||||
|
||||
} |
||||
|
||||
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(); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,135 @@
|
||||
package com.hnac.hzims.bigmodel.interactive.service.impl; |
||||
|
||||
import com.alibaba.fastjson.JSON; |
||||
import com.hnac.hzims.bigmodel.interactive.constants.FuncRouteEnum; |
||||
import com.hnac.hzims.bigmodel.interactive.constants.ParamKeyConstants; |
||||
import com.hnac.hzims.bigmodel.interactive.factory.ResolveFactory; |
||||
import com.hnac.hzims.bigmodel.interactive.req.ModelFunctionReq; |
||||
import com.hnac.hzims.bigmodel.interactive.service.IResolveService; |
||||
import com.hnac.hzims.bigmodel.interactive.vo.ExtraVO; |
||||
import com.hnac.hzims.bigmodel.interactive.vo.ResolveResultVO; |
||||
import com.hnac.hzims.operational.station.entity.StationEntity; |
||||
import com.hnac.hzims.operational.station.feign.IStationClient; |
||||
import com.hnac.hzinfo.sdk.v5.scada.ScadaClient; |
||||
import groovy.util.logging.Slf4j; |
||||
import lombok.AllArgsConstructor; |
||||
import lombok.RequiredArgsConstructor; |
||||
import org.springblade.core.log.exception.ServiceException; |
||||
import org.springblade.core.log.logger.BladeLogger; |
||||
import org.springblade.core.tool.api.R; |
||||
import org.springblade.core.tool.utils.Func; |
||||
import org.springblade.core.tool.utils.StringUtil; |
||||
import org.springblade.system.cache.ParamCache; |
||||
import org.springframework.stereotype.Service; |
||||
import org.springframework.util.Assert; |
||||
|
||||
import java.util.*; |
||||
import java.util.stream.IntStream; |
||||
|
||||
/** |
||||
* @Author: huangxing |
||||
* @Date: 2024/06/21 15:39 |
||||
*/ |
||||
@Service(ResolveFactory.CANVAS_RESOLVE_SERVICE) |
||||
@AllArgsConstructor |
||||
@Slf4j |
||||
public class CanvasResolveServiceImpl implements IResolveService { |
||||
|
||||
private final IStationClient stationClient; |
||||
private final BladeLogger logger; |
||||
|
||||
@Override |
||||
public ExtraVO resolve(ModelFunctionReq req) { |
||||
Map<String, String> args = req.getFunctionArgs(); |
||||
String id = args.get("id"); |
||||
String name = args.get("name"); |
||||
Assert.isTrue(StringUtil.isNotBlank(id) && StringUtil.isNotBlank(name),() -> { |
||||
logger.error("hzims:video:resolve","解析传参错误,缺少必要参数video_id,传参内容为:" + JSON.toJSONString(req)); |
||||
throw new ServiceException("解析传参错误,缺少必要参数video_id"); |
||||
}); |
||||
return this.resolve(id); |
||||
// ExtraVO extra = this.resolve(id);
|
||||
// String message = "已成功打开" + name + ";";
|
||||
// return new ResolveResultVO(message,extra);
|
||||
} |
||||
|
||||
@Override |
||||
public ExtraVO resolve(String id) { |
||||
ExtraVO extraVO = new ExtraVO(); |
||||
extraVO.setImmediatelyJump(true); |
||||
extraVO.setFunc(FuncRouteEnum.OPEN_CANVAS.getFuncCode()); |
||||
final String[] SCADA_PARAMS_SOLVE = new String[]{"picResource","context","stationNum","projectId","taskId","name","id"}; |
||||
String canvasHost = ParamCache.getValue(ParamKeyConstants.CANVAS_HOST); |
||||
// 将ID解析为
|
||||
Map<String, String> resolveMap = this.resolve(id, SCADA_PARAMS_SOLVE); |
||||
R<StationEntity> stationR = stationClient.getStationByCode(resolveMap.get("projectId")); |
||||
extraVO.setLabel(Optional.ofNullable(stationR).filter(r -> r.isSuccess()).map(R::getData).map(StationEntity::getName).orElse("") + "_" + resolveMap.get("name")); |
||||
Integer picResource = Integer.valueOf(resolveMap.get("picResource")); |
||||
Map<String,Object> extraParams = new HashMap<>(1); |
||||
extraParams.put("picResource",picResource); |
||||
extraVO.setParams(extraParams); |
||||
// 云组态
|
||||
if(picResource == 0) { |
||||
String path = this.replacePath(ParamCache.getValue(ParamKeyConstants.CANVAS_YZT_PATH), resolveMap); |
||||
extraVO.setRoute(canvasHost + path); |
||||
} |
||||
// v3.0
|
||||
else if(picResource == 1) { |
||||
String path = this.replacePath(ParamCache.getValue(ParamKeyConstants.CANVAS_V3_PATH), resolveMap); |
||||
extraVO.setRoute(canvasHost + path); |
||||
} |
||||
// v4.0
|
||||
else if (picResource == 2) { |
||||
// pic_name 去掉头部的/ 以及尾部的.js
|
||||
String context = resolveMap.get("context"); |
||||
context = this.removeHeadChars(context,"/"); |
||||
context = this.removeTailChars(context,".js"); |
||||
resolveMap.put("context",context); |
||||
extraVO.setRoute(this.replacePath("other/v4/canvas/index.html?hzinfowebkit=true&taskId={taskId}&stationNum={stationNum}&projectId={projectId}&source=app&picName={context}&name={name}", resolveMap)); |
||||
} |
||||
else { |
||||
throw new ServiceException("解析出来的画面类型在云组态、v3、v4类型之外,无法解析路由"); |
||||
} |
||||
return extraVO; |
||||
} |
||||
|
||||
public Map<String,String> resolve(String paramsStr, String... keys) { |
||||
Map<String,String> result = new HashMap<>(); |
||||
List<String> params = Func.toStrList("\\^", paramsStr); |
||||
Assert.isTrue(params.size() == keys.length, () -> { |
||||
throw new ServiceException("大模型传参params长度错误,传参为:" + paramsStr); |
||||
}); |
||||
IntStream.iterate(0, index -> index + 1).limit(params.size()).forEach(index -> result.put(keys[index],params.get(index))); |
||||
return result; |
||||
} |
||||
|
||||
private String replacePath(String path,Map<String,String> params) { |
||||
Set<Map.Entry<String, String>> entries = params.entrySet(); |
||||
// 替换path中变量
|
||||
for (Map.Entry<String, String> entry : entries) { |
||||
String replaceVariables = "{" + entry.getKey() + "}"; |
||||
path = StringUtil.replace(path,replaceVariables,entry.getValue()); |
||||
} |
||||
return path; |
||||
} |
||||
|
||||
public String removeHeadChars(String str, String charsToRemove) { |
||||
if (str == null || charsToRemove == null || charsToRemove.isEmpty()) { |
||||
return str; |
||||
} |
||||
while (str.startsWith(charsToRemove)) { |
||||
str = str.substring(charsToRemove.length()); |
||||
} |
||||
return str; |
||||
} |
||||
|
||||
public String removeTailChars(String str, String charsToRemove) { |
||||
if (str == null || charsToRemove == null || charsToRemove.isEmpty()) { |
||||
return str; |
||||
} |
||||
while (str.endsWith(charsToRemove)) { |
||||
str = str.substring(0, str.length() - charsToRemove.length()); |
||||
} |
||||
return str; |
||||
} |
||||
} |
@ -0,0 +1,47 @@
|
||||
package com.hnac.hzims.bigmodel.interactive.service.impl; |
||||
|
||||
import com.alibaba.fastjson.JSON; |
||||
import com.alibaba.fastjson.JSONArray; |
||||
import com.alibaba.fastjson.JSONObject; |
||||
import com.hnac.hzims.bigmodel.interactive.constants.FuncRouteEnum; |
||||
import com.hnac.hzims.bigmodel.interactive.factory.AnswerResolveFactory; |
||||
import com.hnac.hzims.bigmodel.interactive.service.IAnswerResolveService; |
||||
import com.hnac.hzims.bigmodel.interactive.vo.AnswerVO; |
||||
import com.hnac.hzims.bigmodel.interactive.vo.ExtraVO; |
||||
import groovy.util.logging.Slf4j; |
||||
import lombok.AllArgsConstructor; |
||||
import org.springframework.stereotype.Service; |
||||
|
||||
import java.util.Arrays; |
||||
import java.util.List; |
||||
import java.util.stream.Collectors; |
||||
|
||||
/** |
||||
* @Author: huangxing |
||||
* @Date: 2024/06/21 19:02 |
||||
* @Describe 选项答案解析服务层 |
||||
*/ |
||||
@AllArgsConstructor |
||||
@Service(AnswerResolveFactory.CHOICE_ANSWER_SERVICE) |
||||
@Slf4j |
||||
public class ChoiceAnswerResolveServiceImpl implements IAnswerResolveService { |
||||
|
||||
@Override |
||||
public AnswerVO resolve(AnswerVO answer) { |
||||
Object[] extraArray = this.extraStream(answer).map(this::getExtra).toArray(); |
||||
answer.setExtras(extraArray); |
||||
return answer; |
||||
} |
||||
|
||||
@Override |
||||
public ExtraVO getExtra(JSONObject originExtra) { |
||||
ExtraVO result = JSONObject.parseObject(JSON.toJSONString(originExtra),ExtraVO.class); |
||||
result.setSpecial(true); |
||||
String funcCode = originExtra.getString("func"); |
||||
result.setFunc(funcCode); |
||||
result.setType(FuncRouteEnum.getEnumByFuncCode(funcCode).getType().getType()); |
||||
JSONArray selections = JSONArray.parseArray(JSON.toJSONString(originExtra.get("data"))); |
||||
result.setSelection(selections); |
||||
return result; |
||||
} |
||||
} |
@ -0,0 +1,50 @@
|
||||
package com.hnac.hzims.bigmodel.interactive.service.impl; |
||||
|
||||
import com.alibaba.fastjson.JSON; |
||||
import com.alibaba.fastjson.JSONObject; |
||||
import com.hnac.hzims.bigmodel.interactive.constants.FuncRouteEnum; |
||||
import com.hnac.hzims.bigmodel.interactive.constants.FunctionConstants; |
||||
import com.hnac.hzims.bigmodel.interactive.factory.AnswerResolveFactory; |
||||
import com.hnac.hzims.bigmodel.interactive.service.IAnswerResolveService; |
||||
import com.hnac.hzims.bigmodel.interactive.vo.AnswerVO; |
||||
import com.hnac.hzims.bigmodel.interactive.vo.ExtraVO; |
||||
import groovy.util.logging.Slf4j; |
||||
import lombok.AllArgsConstructor; |
||||
import org.springframework.stereotype.Service; |
||||
|
||||
import java.util.HashMap; |
||||
import java.util.Map; |
||||
|
||||
/** |
||||
* @Author: huangxing |
||||
* @Date: 2024/06/21 18:59 |
||||
*/ |
||||
@Service(AnswerResolveFactory.DIAGNOSE_ANSWER_SERVICE) |
||||
@Slf4j |
||||
@AllArgsConstructor |
||||
public class DiagnoseAnswerResolveServiceImpl implements IAnswerResolveService { |
||||
|
||||
@Override |
||||
public AnswerVO resolve(AnswerVO answer) { |
||||
Object[] extraArray = this.extraStream(answer).map(this::getExtra).toArray(); |
||||
answer.setExtras(extraArray); |
||||
return answer; |
||||
} |
||||
|
||||
@Override |
||||
public ExtraVO getExtra(JSONObject originExtra) { |
||||
ExtraVO result = new ExtraVO(); |
||||
JSONObject data = JSONObject.parseObject(JSON.toJSONString(originExtra.get("data"))); |
||||
Map<String,Object> params = new HashMap<>(5); |
||||
params.put("faultId",data.getString("fault_id")); |
||||
params.put("name",data.getString("fault_name")); |
||||
params.put("station",data.getString("station_id")); |
||||
params.put("fdpDeviceName",data.getString("device_name")); |
||||
params.put("fdpOrd",data.getString("ord")); |
||||
result.setParams(params); |
||||
String funcCode = originExtra.getString("func"); |
||||
result.setFunc(funcCode); |
||||
result.setType(FuncRouteEnum.getEnumByFuncCode(funcCode).getType().getType()); |
||||
return result; |
||||
} |
||||
} |
@ -0,0 +1,259 @@
|
||||
package com.hnac.hzims.bigmodel.interactive.service.impl; |
||||
|
||||
import com.alibaba.fastjson.JSON; |
||||
import com.alibaba.fastjson.JSONArray; |
||||
import com.alibaba.fastjson.JSONObject; |
||||
import com.hnac.hzims.bigmodel.interactive.constants.FuncRouteEnum; |
||||
import com.hnac.hzims.bigmodel.interactive.constants.FunctionConstants; |
||||
import com.hnac.hzims.bigmodel.interactive.constants.SearchTypeEnum; |
||||
import com.hnac.hzims.bigmodel.interactive.service.IAnalyseDataService; |
||||
import com.hnac.hzims.bigmodel.interactive.vo.*; |
||||
import com.hnac.hzims.operational.station.entity.StationVideoTypeEntity; |
||||
import com.hnac.hzims.operational.station.feign.IStationClient; |
||||
import com.hnac.hzims.operational.station.feign.IStationVideoTypeClient; |
||||
import com.hnac.hzinfo.sdk.v5.device.client.DeviceClient; |
||||
import com.hnac.hzinfo.sdk.v5.device.vo.DeviceInstanceFuncVO; |
||||
import com.xxl.job.core.log.XxlJobLogger; |
||||
import lombok.AllArgsConstructor; |
||||
import org.springblade.core.tool.api.R; |
||||
import org.springblade.core.tool.utils.*; |
||||
import org.springframework.stereotype.Service; |
||||
|
||||
import java.time.format.DateTimeFormatter; |
||||
import java.util.*; |
||||
import java.util.stream.Collectors; |
||||
|
||||
/** |
||||
* @Author: huangxing |
||||
* @Date: 2024/05/08 16:19 |
||||
*/ |
||||
@Service |
||||
@AllArgsConstructor |
||||
@Deprecated |
||||
public class ExtraResolveStrategyService { |
||||
|
||||
public static final String PATTERN_DATETIME = "yyyy-MM-dd HH:mm:ss.SSS"; |
||||
|
||||
public static final DateTimeFormatter formatter = DateTimeFormatter.ofPattern(PATTERN_DATETIME); |
||||
|
||||
private final IStationClient stationClient; |
||||
private final IStationVideoTypeClient videoTypeClient; |
||||
private final JumpRouteJoinStrategy jumpRouteJoinStrategy; |
||||
private final DeviceClient deviceClient; |
||||
private final IAnalyseDataService analyseDataService; |
||||
|
||||
/** |
||||
* 解析DFP返回extra |
||||
* @param extraStr DFP返回extra |
||||
* @return 与前端交互extra |
||||
*/ |
||||
public ExtraVO resolve(String extraStr) { |
||||
JSONObject extra = JSONObject.parseObject(extraStr); |
||||
String functionCode = Optional.ofNullable(extra.get("func")).map(String::valueOf).orElse(""); |
||||
if(StringUtil.isNotBlank(functionCode)) { |
||||
XxlJobLogger.log("函数编号为:" + functionCode); |
||||
FuncRouteEnum funcRouteEnum = FuncRouteEnum.getEnumByFuncCode(functionCode); |
||||
if(Func.isNotEmpty(funcRouteEnum)) { |
||||
switch (funcRouteEnum) { |
||||
case DIAGNOSE: |
||||
return this.resolveDiagnose(extra); |
||||
case CHOOSE_VIDEO: |
||||
case CHOOSE_CANVAS: |
||||
case CHOOSE_STATION: |
||||
case CHOOSE_FAULT: |
||||
case CHOOSE_YC: |
||||
case CHOOSE_YK: |
||||
return this.resolveChooseSelection(extra,funcRouteEnum); |
||||
case CONFIRM_YK: |
||||
return this.resolveConfirmRemote(extra); |
||||
case SHOW_PARAM: |
||||
return this.resolveShowParam(extra); |
||||
default: |
||||
break; |
||||
} |
||||
} |
||||
} |
||||
else if(extra.containsKey("extra")){ |
||||
return extra.getObject("extra",ExtraVO.class); |
||||
} |
||||
return JSONObject.parseObject(JSON.toJSONString(extra),ExtraVO.class); |
||||
} |
||||
|
||||
private ExtraVO resolveChooseSelection(JSONObject extra,FuncRouteEnum funcRouteEnum) { |
||||
ExtraVO result = new ExtraVO(); |
||||
JSONArray selections = JSONArray.parseArray(JSON.toJSONString(extra.get("data"))); |
||||
result.setFunc(funcRouteEnum.getFuncCode()); |
||||
result.setSpecial(true); |
||||
result.setSelection(selections); |
||||
result.setType(funcRouteEnum.getType().getType()); |
||||
return result; |
||||
} |
||||
|
||||
// private ExtraVO resolveChooseYc(JSONObject extra) {
|
||||
// ExtraVO result = new ExtraVO();
|
||||
// JSONObject data = JSONObject.parseObject(JSON.toJSONString(extra.get("data")));
|
||||
// if(data.containsKey("yks")) {
|
||||
//
|
||||
//
|
||||
// List<AttrSelectionVO> attrs = JSONArray.parseArray(JSON.toJSONString(data.get("yks")), AttrSelectionVO.class);
|
||||
// result.setSelection(attrs);
|
||||
// }
|
||||
// result.setFuncCode(FuncRouteEnum.CHOOSE_YC.getFuncCode());
|
||||
// result.setSpecial(true);
|
||||
// result.setType(FuncRouteEnum.CHOOSE_YC.getType().getType());
|
||||
// return result;
|
||||
// }
|
||||
|
||||
private ExtraVO resolveShowParam(Map<String,Object> extra) { |
||||
DataVO data = JSONObject.parseObject(JSON.toJSONString(extra.get("data")),DataVO.class); |
||||
if(Func.isNotEmpty(data)) { |
||||
if(Func.isNotEmpty(data.getReal())) { |
||||
if(Func.isNotEmpty(data.getReal().getTime()) && StringUtil.isNotBlank(data.getReal().getTime())) { |
||||
RealDataVO real = data.getReal(); |
||||
Date date = DateUtil.parse(real.getTime(), PATTERN_DATETIME); |
||||
real.setTime(DateUtil.format(date,DateUtil.PATTERN_DATETIME)); |
||||
} |
||||
} |
||||
if(Func.isNotEmpty(data.getItem()) && StringUtil.isNotBlank(data.getMethod())) { |
||||
if(SearchTypeEnum.HISTORY.getSearchType().equals(data.getType()) && Func.isNotEmpty(data.getItem())) { |
||||
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()); |
||||
searchVO.setMethod(data.getMethod()); |
||||
searchVO.setSignage(item.getSignage()); |
||||
searchVO.setStartTime(data.getStartTime()); |
||||
searchVO.setEndTime(data.getEndTime()); |
||||
return analyseDataService.getHistoryData(searchVO); |
||||
} |
||||
} |
||||
} |
||||
ExtraVO result = new ExtraVO(); |
||||
result.setFunc(FuncRouteEnum.SHOW_PARAM.getFuncCode()); |
||||
result.setType(FuncRouteEnum.SHOW_PARAM.getType().getType()); |
||||
Map<String,Object> param = new HashMap(1); |
||||
param.put("data", data); |
||||
result.setParams(param); |
||||
return result; |
||||
} |
||||
|
||||
@Deprecated |
||||
private ExtraVO resolveConfirmRemote(Map<String,Object> extra) { |
||||
ExtraVO result = new ExtraVO(); |
||||
RemoteParamVO remoteParam = JSONObject.parseObject(JSON.toJSONString(extra.get("data")), RemoteParamVO.class); |
||||
result.setFunc(FuncRouteEnum.CONFIRM_YK.getFuncCode()); |
||||
result.setType(FuncRouteEnum.CONFIRM_YK.getType().getType()); |
||||
R<DeviceInstanceFuncVO> funcVOR = deviceClient.getFuncById(remoteParam.getFuncId()); |
||||
if(funcVOR.isSuccess()) { |
||||
Map<String,Object> param = new HashMap(); |
||||
param.put("control",funcVOR.getData()); |
||||
param.put("deviceName",remoteParam.getDeviceName()); |
||||
param.put("projectName",remoteParam.getProjectName()); |
||||
param.put("deviceCode",remoteParam.getDeviceId()); |
||||
param.put("value",remoteParam.getValue()); |
||||
result.setParams(param); |
||||
} |
||||
return result; |
||||
} |
||||
|
||||
// private ExtraVO resolveChooseFault(Map<String,Object> extra) {
|
||||
// ExtraVO result = new ExtraVO();
|
||||
// JSONObject data = JSONObject.parseObject(JSON.toJSONString(extra.get("data")));
|
||||
// if(data.containsKey("faults")) {
|
||||
// List<FaultSelectionVO> faults = JSONArray.parseArray(JSON.toJSONString(data.get("faults")), FaultSelectionVO.class);
|
||||
// result.setSelection(faults);
|
||||
// }
|
||||
// result.setFuncCode(FuncRouteEnum.CHOOSE_FAULT.getFuncCode());
|
||||
// result.setSpecial(true);
|
||||
// result.setType(FunctionConstants.TypeEnum.CHOOSE.getType());
|
||||
// return result;
|
||||
// }
|
||||
|
||||
private ExtraVO resolveDiagnose(Map<String,Object> extra) { |
||||
ExtraVO result = new ExtraVO(); |
||||
JSONObject data = JSONObject.parseObject(JSON.toJSONString(extra.get("data"))); |
||||
Map<String,Object> params = new HashMap<>(5); |
||||
params.put("faultId",data.getString("fault_id")); |
||||
params.put("name",data.getString("fault_name")); |
||||
params.put("station",data.getString("station_id")); |
||||
params.put("fdpDeviceName",data.getString("device_name")); |
||||
params.put("fdpOrd",data.getString("ord")); |
||||
result.setParams(params); |
||||
result.setFunc(FuncRouteEnum.DIAGNOSE.getFuncCode()); |
||||
result.setType(FunctionConstants.TypeEnum.PARAMS.getType()); |
||||
return result; |
||||
} |
||||
|
||||
/** |
||||
* |
||||
* @param extra |
||||
* @return |
||||
*/ |
||||
// private ExtraVO resolveChooseStation(Map<String,Object> extra) {
|
||||
// ExtraVO result = new ExtraVO();
|
||||
// JSONObject data = JSONObject.parseObject(JSON.toJSONString(extra.get("data")));
|
||||
// if(data.containsKey("stations")) {
|
||||
// List<String> stations = JSONArray.parseArray(JSON.toJSONString(data.get("stations")), String.class);
|
||||
// List<StationSelectionVO> selectionList = stations.stream().map(stationId -> {
|
||||
// StationSelectionVO selectionVO = new StationSelectionVO();
|
||||
// R<StationEntity> stationR = stationClient.getStationByCode(stationId);
|
||||
// if (stationR.isSuccess() && Func.isNotEmpty(stationR.getData())) {
|
||||
// selectionVO.setId(stationId);
|
||||
// selectionVO.setName(stationR.getData().getName());
|
||||
// }
|
||||
// return selectionVO;
|
||||
// }).collect(Collectors.toList());
|
||||
// result.setSelection(selectionList);
|
||||
// result.setFuncCode(FuncRouteEnum.CHOOSE_STATION.getFuncCode());
|
||||
// result.setSpecial(true);
|
||||
// result.setType(FunctionConstants.TypeEnum.CHOOSE.getType());
|
||||
// }
|
||||
// result.setType(FunctionConstants.TypeEnum.CHOOSE.getType());
|
||||
// return result;
|
||||
// }
|
||||
|
||||
private ExtraVO resolveChooseVideo(Map<String,Object> extra) { |
||||
ExtraVO result = new ExtraVO(); |
||||
JSONObject data = JSONObject.parseObject(JSON.toJSONString(extra.get("data"))); |
||||
if(data.containsKey("videos")) { |
||||
List<JSONObject> videoIds = JSONArray.parseArray(JSON.toJSONString(data.get("videos")), JSONObject.class); |
||||
List<VideoSelectionVO> selections = videoIds.stream().map(video -> { |
||||
R<StationVideoTypeEntity> videoR = videoTypeClient.getById(Long.valueOf(video.getString("id"))); |
||||
VideoSelectionVO selectionVO = new VideoSelectionVO(); |
||||
if (videoR.isSuccess() && Func.isNotEmpty(videoR.getData())) { |
||||
selectionVO.setId(video.getString("id")); |
||||
selectionVO.setName(videoR.getData().getName()); |
||||
} |
||||
return selectionVO; |
||||
}).collect(Collectors.toList()); |
||||
result.setFunc(FuncRouteEnum.CHOOSE_VIDEO.getFuncCode()); |
||||
result.setSpecial(true); |
||||
result.setSelection(selections); |
||||
} |
||||
result.setType(FunctionConstants.TypeEnum.CHOOSE.getType()); |
||||
return result; |
||||
} |
||||
|
||||
private ExtraVO resolveChooseScada(Map<String,Object> extra) { |
||||
ExtraVO result = new ExtraVO(); |
||||
JSONObject data = JSONObject.parseObject(JSON.toJSONString(extra.get("data"))); |
||||
if(data.containsKey("canvases")) { |
||||
List<JSONObject> canvases = JSONArray.parseArray(JSON.toJSONString(data.get("canvases")), JSONObject.class); |
||||
List<ScadaSelectionVO> selections = canvases.stream().map(canvas -> { |
||||
ScadaSelectionVO selectionVO = new ScadaSelectionVO(); |
||||
Map<String, String> resolve = jumpRouteJoinStrategy.resolve(canvas.getString("id"), JumpRouteJoinStrategy.SCADA_PARAMS_SOLVE); |
||||
selectionVO.setId(canvas.getString("id")); |
||||
selectionVO.setName(resolve.get("name")); |
||||
return selectionVO; |
||||
}).collect(Collectors.toList()); |
||||
result.setFunc(FuncRouteEnum.CHOOSE_CANVAS.getFuncCode()); |
||||
result.setSpecial(true); |
||||
result.setSelection(selections); |
||||
} |
||||
result.setType(FunctionConstants.TypeEnum.CHOOSE.getType()); |
||||
return result; |
||||
} |
||||
} |
@ -0,0 +1,69 @@
|
||||
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.factory.ResolveFactory; |
||||
import com.hnac.hzims.bigmodel.interactive.req.ModelFunctionReq; |
||||
import com.hnac.hzims.bigmodel.interactive.service.IHznlmInteractiveService; |
||||
import com.hnac.hzims.bigmodel.interactive.service.IResolveService; |
||||
import com.hnac.hzims.bigmodel.interactive.vo.AuthDataVO; |
||||
import com.hnac.hzims.bigmodel.interactive.vo.ExtraVO; |
||||
import com.hnac.hzims.bigmodel.interactive.vo.ResolveResultVO; |
||||
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 HznlmInteractiveServiceImpl 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() + "改类型获取权限数据暂不支持"); |
||||
} |
||||
} |
||||
|
||||
@Override |
||||
public ExtraVO resolve(ModelFunctionReq req) { |
||||
IResolveService resolveService = ResolveFactory.getResolveService(req.getFunctionName()); |
||||
return resolveService.resolve(req); |
||||
} |
||||
|
||||
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,131 @@
|
||||
package com.hnac.hzims.bigmodel.interactive.service.impl; |
||||
|
||||
import cn.hutool.http.HttpRequest; |
||||
import cn.hutool.http.HttpResponse; |
||||
import com.alibaba.fastjson.JSON; |
||||
import com.alibaba.fastjson.JSONArray; |
||||
import com.alibaba.fastjson.TypeReference; |
||||
import com.google.common.collect.Lists; |
||||
import com.hnac.hzims.bigmodel.configuration.BigModelInvokeUrl; |
||||
import com.hnac.hzims.bigmodel.interactive.service.IHznlmInvokeService; |
||||
import com.hnac.hzims.bigmodel.interactive.vo.AnswerVO; |
||||
import com.hnac.hzims.bigmodel.manager.SessionRedisManager; |
||||
import com.hnac.hzims.bigmodel.utils.RequestClientUtil; |
||||
import com.hnac.hzims.bigmodel.websocket.sessionManager.InteractiveSessionManager; |
||||
import com.xxl.job.core.log.XxlJobLogger; |
||||
import lombok.AllArgsConstructor; |
||||
import lombok.RequiredArgsConstructor; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
import org.springblade.core.log.exception.ServiceException; |
||||
import org.springblade.core.log.logger.BladeLogger; |
||||
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.springframework.beans.factory.annotation.Value; |
||||
import org.springframework.stereotype.Service; |
||||
import org.springframework.util.Assert; |
||||
|
||||
import javax.servlet.http.HttpServletResponse; |
||||
import java.util.HashMap; |
||||
import java.util.List; |
||||
import java.util.Map; |
||||
|
||||
/** |
||||
* @Author: huangxing |
||||
* @Date: 2024/06/21 17:20 |
||||
* @Describe HZN_LM大模型接口调用服务层 |
||||
*/ |
||||
@Service |
||||
@RequiredArgsConstructor |
||||
@Slf4j |
||||
public class HznlmInvokeServiceImpl implements IHznlmInvokeService { |
||||
|
||||
private final AuthenticationService authenticationService; |
||||
private final BigModelInvokeUrl bigModelInvokeUrl; |
||||
private final BladeLogger logger; |
||||
private final SessionRedisManager sessionRedisManager; |
||||
|
||||
@Value("${fdp.host}") |
||||
private String fdpHost; |
||||
|
||||
@Override |
||||
public void ask(String question, String sessionId, String userId) { |
||||
Map<String,Object> params = new HashMap<>(); |
||||
params.put("id",sessionId); |
||||
params.put("userid", userId); |
||||
params.put("query",question); |
||||
Map<String, String[]> authDataIds = this.getAuthDataIds(userId); |
||||
params.putAll(authDataIds); |
||||
RequestClientUtil.postCall(fdpHost + bigModelInvokeUrl.getAssistantAsk(), params); |
||||
sessionRedisManager.addSessionId(sessionId); |
||||
} |
||||
|
||||
@Override |
||||
public void specialAsk(String sessionId, String userId, Map<String, Object> extra) { |
||||
Map<String,Object> params = new HashMap<>(); |
||||
params.put("id",sessionId); |
||||
params.put("userid", userId); |
||||
params.put("extra",extra); |
||||
Map<String, String[]> authDataIds = this.getAuthDataIds(userId); |
||||
params.putAll(authDataIds); |
||||
log.info("调用大模型接口:{},传参为:{}",fdpHost + bigModelInvokeUrl.getAssistantSpecialAsk(),JSON.toJSONString(params)); |
||||
RequestClientUtil.postCall(fdpHost + bigModelInvokeUrl.getAssistantSpecialAsk(), params); |
||||
sessionRedisManager.addSessionId(sessionId); |
||||
} |
||||
|
||||
@Override |
||||
public void knowledgeAsk(String question, String sessionId, String userId, String knowledge) { |
||||
Map<String,Object> params = new HashMap<>(); |
||||
params.put("id", sessionId); |
||||
params.put("userid", userId); |
||||
params.put("query", question); |
||||
params.put("knowledge", knowledge); |
||||
Map<String, String[]> authDataIds = this.getAuthDataIds(userId); |
||||
params.putAll(authDataIds); |
||||
RequestClientUtil.postCall(fdpHost + bigModelInvokeUrl.getAssistantKnowledgeAsk(), params); |
||||
sessionRedisManager.addSessionId(sessionId); |
||||
} |
||||
|
||||
@Override |
||||
public void removeSessionId(String sessionId) { |
||||
Map<String,Object> params = new HashMap<>(); |
||||
params.put("id",sessionId); |
||||
RequestClientUtil.postCall(fdpHost + bigModelInvokeUrl.getAskAbort(), params); |
||||
// 移除内存sessionId
|
||||
InteractiveSessionManager.SESSION_POOL.remove(sessionId); |
||||
sessionRedisManager.removeSessionId(sessionId); |
||||
} |
||||
|
||||
@Override |
||||
public List hotQuestions() { |
||||
try { |
||||
return RequestClientUtil.postCall(fdpHost + bigModelInvokeUrl.getHotQuestion(), null, new TypeReference<List<String>>(){}); |
||||
} |
||||
catch (Exception e) { |
||||
log.error("An error occurred",e); |
||||
return Lists.newArrayList(); |
||||
} |
||||
} |
||||
|
||||
@Override |
||||
public List<AnswerVO> getAnswerBySessionIds(String sessionIds) { |
||||
Map<String,Object> params = new HashMap<>(); |
||||
params.put("ids",Func.toStrList(",",sessionIds).toArray()); |
||||
List<AnswerVO> answerVOList = RequestClientUtil.postCall(fdpHost + bigModelInvokeUrl.getAssistantStatus(), params, new TypeReference<List<AnswerVO>>(){}); |
||||
return answerVOList; |
||||
} |
||||
|
||||
private Map<String,String[]> getAuthDataIds(String userId) { |
||||
List<DeptStationDTO> authDatas = authenticationService.getStationPermissionsById(userId); |
||||
Map<String, String[]> result = new HashMap<>(2); |
||||
String[] stationIds = authDatas.stream().map(DeptStationDTO::getStationId) |
||||
.filter(StringUtil::isNotBlank).toArray(String[]::new); |
||||
String[] projectIds = authDatas.stream().map(DeptStationDTO::getDeptId) |
||||
.filter(Func::isNotEmpty).map(String::valueOf).toArray(String[]::new); |
||||
result.put("stationids", stationIds); |
||||
result.put("projectids", projectIds); |
||||
return result; |
||||
} |
||||
} |
@ -0,0 +1,106 @@
|
||||
package com.hnac.hzims.bigmodel.interactive.service.impl; |
||||
|
||||
import com.alibaba.fastjson.JSON; |
||||
import com.alibaba.fastjson.JSONObject; |
||||
import com.hnac.hzims.bigmodel.interactive.constants.FuncRouteEnum; |
||||
import com.hnac.hzims.bigmodel.interactive.constants.SearchTypeEnum; |
||||
import com.hnac.hzims.bigmodel.interactive.factory.AnswerResolveFactory; |
||||
import com.hnac.hzims.bigmodel.interactive.service.IAnalyseDataService; |
||||
import com.hnac.hzims.bigmodel.interactive.service.IAnswerResolveService; |
||||
import com.hnac.hzims.bigmodel.interactive.vo.*; |
||||
import com.xxl.job.core.log.XxlJobLogger; |
||||
import groovy.util.logging.Slf4j; |
||||
import lombok.AllArgsConstructor; |
||||
import org.springblade.core.log.exception.ServiceException; |
||||
import org.springblade.core.tool.utils.DateUtil; |
||||
import org.springblade.core.tool.utils.Func; |
||||
import org.springblade.core.tool.utils.StringUtil; |
||||
import org.springframework.stereotype.Service; |
||||
import org.springframework.util.Assert; |
||||
|
||||
import java.util.Date; |
||||
import java.util.HashMap; |
||||
import java.util.Map; |
||||
|
||||
/** |
||||
* @Author: huangxing |
||||
* @Date: 2024/06/21 19:02 |
||||
*/ |
||||
@Service(AnswerResolveFactory.PARAM_ANSWER_SERVICE) |
||||
@Slf4j |
||||
@AllArgsConstructor |
||||
public class ParamAnswerResolveServiceImpl implements IAnswerResolveService { |
||||
|
||||
private final IAnalyseDataService analyseDataService; |
||||
|
||||
public static final String PATTERN_DATETIME = "yyyy-MM-dd HH:mm:ss.SSS"; |
||||
|
||||
@Override |
||||
public AnswerVO resolve(AnswerVO answer) { |
||||
Object[] extraArray = this.extraStream(answer).map(this::getExtra).toArray(); |
||||
answer.setExtras(extraArray); |
||||
return answer; |
||||
} |
||||
|
||||
@Override |
||||
public ExtraVO getExtra(JSONObject originExtra) { |
||||
DataVO data = JSONObject.parseObject(JSON.toJSONString(originExtra.get("data")),DataVO.class); |
||||
Assert.isTrue(Func.isNotEmpty(data),() -> { |
||||
XxlJobLogger.log("解析参数答案失败,extra不能为空!"); |
||||
throw new ServiceException("解析参数答案失败,extra不能为空!"); |
||||
}); |
||||
if(Func.isNotEmpty(data.getReal())) { |
||||
// 处理查询实时数据
|
||||
RealDataVO real = data.getReal(); |
||||
Date date = DateUtil.parse(real.getTime(), PATTERN_DATETIME); |
||||
real.setTime(DateUtil.format(date,DateUtil.PATTERN_DATETIME)); |
||||
} |
||||
else if(StringUtil.isNotBlank(data.getType()) && SearchTypeEnum.HISTORY.getSearchType().equals(data.getType())) { |
||||
// 处理查询历史数据
|
||||
return this.getHistoryData(data); |
||||
} |
||||
String funcCode = originExtra.getString("func"); |
||||
ExtraVO result = new ExtraVO(); |
||||
result.setFunc(funcCode); |
||||
result.setType(FuncRouteEnum.getEnumByFuncCode(funcCode).getType().getType()); |
||||
Map<String,Object> param = new HashMap(1); |
||||
param.put("data", data); |
||||
result.setParams(param); |
||||
return result; |
||||
} |
||||
|
||||
/** |
||||
* 查询历史数据 |
||||
* @param data 大模型识别数据信息 |
||||
* @return 历史数据 |
||||
*/ |
||||
private ExtraVO getHistoryData(DataVO data) { |
||||
// 确认查询聚合方式传入
|
||||
Assert.isTrue(Func.isNotEmpty(data.getItem()) && StringUtil.isNotBlank(data.getMethod()),() -> { |
||||
XxlJobLogger.log("历史数据查询方式为空,查询失败!"); |
||||
throw new ServiceException("历史数据查询方式为空,查询失败!"); |
||||
}); |
||||
return analyseDataService.getHistoryData(this.convertHistoryDataSearch(data)); |
||||
} |
||||
|
||||
/** |
||||
* 获取历史数据查询对象 |
||||
* @param data 大模型解析点位信息 |
||||
* @return 历史数据查询对象 |
||||
*/ |
||||
private HistoryDataSearchVO convertHistoryDataSearch(DataVO data) { |
||||
HistoryDataSearchVO searchVO = new HistoryDataSearchVO(); |
||||
DataItemVO item = data.getItem(); |
||||
searchVO.setDataType(data.getDataType()); |
||||
searchVO.setAttrName(item.getAttrName()); |
||||
searchVO.setDeviceCode(item.getDeviceId()); |
||||
searchVO.setDeviceName(item.getDeviceName()); |
||||
searchVO.setStationName(item.getProjectName()); |
||||
searchVO.setMethod(data.getMethod()); |
||||
searchVO.setSignage(item.getSignage()); |
||||
searchVO.setStartTime(data.getStartTime()); |
||||
searchVO.setEndTime(data.getEndTime()); |
||||
return searchVO; |
||||
} |
||||
|
||||
} |
@ -0,0 +1,73 @@
|
||||
package com.hnac.hzims.bigmodel.interactive.service.impl; |
||||
|
||||
import com.hnac.hzims.bigmodel.entity.FunctionEntity; |
||||
import com.hnac.hzims.bigmodel.interactive.constants.FuncRouteEnum; |
||||
import com.hnac.hzims.bigmodel.interactive.constants.FunctionConstants; |
||||
import com.hnac.hzims.bigmodel.interactive.vo.ExtraVO; |
||||
import com.hnac.hzims.operational.station.entity.StationVideoTypeEntity; |
||||
import com.hnac.hzims.operational.station.feign.IStationVideoTypeClient; |
||||
import lombok.AllArgsConstructor; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
import org.springblade.core.tool.api.R; |
||||
import org.springblade.core.tool.utils.Func; |
||||
import org.springblade.core.tool.utils.StringUtil; |
||||
import org.springframework.stereotype.Component; |
||||
|
||||
import java.util.HashMap; |
||||
import java.util.Map; |
||||
|
||||
/** |
||||
* @Author: huangxing |
||||
* @Date: 2024/05/09 08:56 |
||||
*/ |
||||
@Component |
||||
@Slf4j |
||||
@AllArgsConstructor |
||||
@Deprecated |
||||
public class ParamStrategy { |
||||
|
||||
private final IStationVideoTypeClient videoClient; |
||||
|
||||
/** |
||||
* 解析发送参数方式函数 |
||||
* @param function 函数 |
||||
* @param args 大模型识别参数 |
||||
* @return 前端传参EXTRA |
||||
*/ |
||||
public ExtraVO resolve(FunctionEntity function, Map<String,String> args) { |
||||
FuncRouteEnum routeEnum = FuncRouteEnum.getEnumByFuncCode(function.getCode()); |
||||
if(Func.isNotEmpty(routeEnum)) { |
||||
switch(routeEnum) { |
||||
case OPEN_VIDEO: |
||||
return this.getVideoExtra(args); |
||||
default: |
||||
break; |
||||
} |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
public ExtraVO getVideoExtra(Map<String,String> args) { |
||||
// 跳转页面逻辑
|
||||
ExtraVO extraVO = new ExtraVO(); |
||||
String id = args.get("canvas_id"); |
||||
if(StringUtil.isNotBlank(id) && Func.isNotEmpty(id)) { |
||||
R<StationVideoTypeEntity> videoR = videoClient.getById(Long.valueOf(id)); |
||||
if(videoR.isSuccess()) { |
||||
StationVideoTypeEntity video = videoR.getData(); |
||||
extraVO.setType(FunctionConstants.TypeEnum.PARAMS.getType()); |
||||
extraVO.setImmediatelyJump(true); |
||||
extraVO.setFunc(FuncRouteEnum.OPEN_VIDEO.getFuncCode()); |
||||
Map<String,Object> params = new HashMap<>(); |
||||
params.put("name", video.getName()); |
||||
params.put("videoHost", video.getVideoHost()); |
||||
params.put("pointCode", video.getPointCode()); |
||||
params.put("appKey", video.getAppKey()); |
||||
params.put("appSecret", video.getAppSecret()); |
||||
params.put("liveSourceAddress",video.getLiveSourceAddress()); |
||||
extraVO.setParams(params); |
||||
} |
||||
} |
||||
return extraVO; |
||||
} |
||||
} |
@ -0,0 +1,36 @@
|
||||
package com.hnac.hzims.bigmodel.interactive.service.impl; |
||||
|
||||
import com.alibaba.fastjson.JSON; |
||||
import com.hnac.hzims.bigmodel.entity.FuncParamEntity; |
||||
import com.hnac.hzims.bigmodel.entity.FunctionEntity; |
||||
import com.hnac.hzims.bigmodel.interactive.service.IParamsService; |
||||
import com.hnac.hzims.bigmodel.interactive.vo.ExtraVO; |
||||
import lombok.AllArgsConstructor; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
import org.springblade.core.log.exception.ServiceException; |
||||
import org.springframework.stereotype.Service; |
||||
import org.springframework.util.Assert; |
||||
|
||||
import java.util.List; |
||||
import java.util.Map; |
||||
import java.util.Optional; |
||||
|
||||
/** |
||||
* @Author: huangxing |
||||
* @Date: 2024/05/09 08:51 |
||||
*/ |
||||
@Service |
||||
@Slf4j |
||||
@AllArgsConstructor |
||||
@Deprecated |
||||
public class ParamsServiceImpl implements IParamsService { |
||||
|
||||
private final ParamStrategy strategy; |
||||
|
||||
@Override |
||||
public String dealJumpTypeFunction(FunctionEntity function, Map<String, String> args) { |
||||
// 跳转页面逻辑
|
||||
ExtraVO extraVO = strategy.resolve(function,args); |
||||
return JSON.toJSONString(extraVO); |
||||
} |
||||
} |
@ -0,0 +1,59 @@
|
||||
package com.hnac.hzims.bigmodel.interactive.service.impl; |
||||
|
||||
import com.alibaba.fastjson.JSON; |
||||
import com.alibaba.fastjson.JSONArray; |
||||
import com.alibaba.fastjson.JSONObject; |
||||
import com.hnac.hzims.bigmodel.interactive.constants.FuncRouteEnum; |
||||
import com.hnac.hzims.bigmodel.interactive.factory.AnswerResolveFactory; |
||||
import com.hnac.hzims.bigmodel.interactive.service.IAnswerResolveService; |
||||
import com.hnac.hzims.bigmodel.interactive.vo.AnswerVO; |
||||
import com.hnac.hzims.bigmodel.interactive.vo.ExtraVO; |
||||
import com.hnac.hzims.bigmodel.interactive.vo.RemoteParamVO; |
||||
import com.hnac.hzinfo.sdk.v5.device.client.DeviceClient; |
||||
import com.hnac.hzinfo.sdk.v5.device.vo.DeviceInstanceFuncVO; |
||||
import groovy.util.logging.Slf4j; |
||||
import lombok.AllArgsConstructor; |
||||
import org.springblade.core.tool.api.R; |
||||
import org.springframework.stereotype.Service; |
||||
|
||||
import java.util.HashMap; |
||||
import java.util.Map; |
||||
|
||||
/** |
||||
* @Author: huangxing |
||||
* @Date: 2024/06/21 19:02 |
||||
*/ |
||||
@Service(AnswerResolveFactory.REMOTE_ANSWER_SERVICE) |
||||
@Slf4j |
||||
@AllArgsConstructor |
||||
public class RemoteAnswerResolveServiceImpl implements IAnswerResolveService { |
||||
|
||||
private final DeviceClient deviceClient; |
||||
|
||||
@Override |
||||
public AnswerVO resolve(AnswerVO answer) { |
||||
Object[] extraArray = this.extraStream(answer).map(this::getExtra).toArray(); |
||||
answer.setExtras(extraArray); |
||||
return answer; |
||||
} |
||||
|
||||
@Override |
||||
public ExtraVO getExtra(JSONObject originExtra) { |
||||
ExtraVO result = new ExtraVO(); |
||||
RemoteParamVO remoteParam = JSONObject.parseObject(JSON.toJSONString(originExtra.get("data")), RemoteParamVO.class); |
||||
String funcCode = originExtra.getString("func"); |
||||
result.setFunc(funcCode); |
||||
result.setType(FuncRouteEnum.getEnumByFuncCode(funcCode).getType().getType()); |
||||
R<DeviceInstanceFuncVO> funcVOR = deviceClient.getFuncById(remoteParam.getFuncId()); |
||||
if(funcVOR.isSuccess()) { |
||||
Map<String,Object> param = new HashMap(); |
||||
param.put("control",funcVOR.getData()); |
||||
param.put("deviceName",remoteParam.getDeviceName()); |
||||
param.put("projectName",remoteParam.getProjectName()); |
||||
param.put("deviceCode",remoteParam.getDeviceId()); |
||||
param.put("value",remoteParam.getValue()); |
||||
result.setParams(param); |
||||
} |
||||
return result; |
||||
} |
||||
} |
@ -0,0 +1,75 @@
|
||||
package com.hnac.hzims.bigmodel.interactive.service.impl; |
||||
|
||||
import com.alibaba.fastjson.JSON; |
||||
import com.hnac.hzims.bigmodel.interactive.constants.FuncRouteEnum; |
||||
import com.hnac.hzims.bigmodel.interactive.constants.FunctionConstants; |
||||
import com.hnac.hzims.bigmodel.interactive.factory.ResolveFactory; |
||||
import com.hnac.hzims.bigmodel.interactive.req.ModelFunctionReq; |
||||
import com.hnac.hzims.bigmodel.interactive.service.IResolveService; |
||||
import com.hnac.hzims.bigmodel.interactive.vo.ExtraVO; |
||||
import com.hnac.hzims.bigmodel.interactive.vo.ResolveResultVO; |
||||
import com.hnac.hzims.operational.station.entity.StationVideoTypeEntity; |
||||
import com.hnac.hzims.operational.station.feign.IStationVideoTypeClient; |
||||
import groovy.util.logging.Slf4j; |
||||
import lombok.AllArgsConstructor; |
||||
import org.springblade.core.log.exception.ServiceException; |
||||
import org.springblade.core.log.logger.BladeLogger; |
||||
import org.springblade.core.tool.api.R; |
||||
import org.springblade.core.tool.utils.Func; |
||||
import org.springblade.core.tool.utils.StringUtil; |
||||
import org.springframework.stereotype.Service; |
||||
import org.springframework.util.Assert; |
||||
|
||||
import java.util.HashMap; |
||||
import java.util.Map; |
||||
|
||||
/** |
||||
* @Author: huangxing |
||||
* @Date: 2024/06/21 16:17 |
||||
*/ |
||||
@Service(ResolveFactory.VIDEO_RESOLVE_SERVICE) |
||||
@AllArgsConstructor |
||||
@Slf4j |
||||
public class VideoResolveServiceImpl implements IResolveService { |
||||
|
||||
private final IStationVideoTypeClient videoClient; |
||||
private final BladeLogger logger; |
||||
|
||||
@Override |
||||
public ExtraVO resolve(ModelFunctionReq req) { |
||||
Map<String, String> args = req.getFunctionArgs(); |
||||
String id = args.get("id"); |
||||
String name = args.get("name"); |
||||
Assert.isTrue(StringUtil.isNotBlank(id) && StringUtil.isNotBlank(name),() -> { |
||||
logger.error("hzims:video:resolve","解析传参错误,缺少必要参数video_id,传参内容为:" + JSON.toJSONString(req)); |
||||
throw new ServiceException("解析传参错误,缺少必要参数video_id"); |
||||
}); |
||||
return this.resolve(id); |
||||
// ExtraVO extra = this.resolve(id);
|
||||
// String message = "已成功打开" + name + ";";
|
||||
// return new ResolveResultVO(message,extra);
|
||||
} |
||||
|
||||
@Override |
||||
public ExtraVO resolve(String idStr) { |
||||
Long id = Long.valueOf(idStr); |
||||
// 跳转页面逻辑
|
||||
ExtraVO extraVO = new ExtraVO(); |
||||
R<StationVideoTypeEntity> videoR = videoClient.getById(Long.valueOf(id)); |
||||
if(videoR.isSuccess()) { |
||||
StationVideoTypeEntity video = videoR.getData(); |
||||
extraVO.setType(FunctionConstants.TypeEnum.PARAMS.getType()); |
||||
extraVO.setImmediatelyJump(true); |
||||
extraVO.setFunc(FuncRouteEnum.OPEN_VIDEO.getFuncCode()); |
||||
Map<String,Object> params = new HashMap<>(); |
||||
params.put("name", video.getName()); |
||||
params.put("videoHost", video.getVideoHost()); |
||||
params.put("pointCode", video.getPointCode()); |
||||
params.put("appKey", video.getAppKey()); |
||||
params.put("appSecret", video.getAppSecret()); |
||||
params.put("liveSourceAddress",video.getLiveSourceAddress()); |
||||
extraVO.setParams(params); |
||||
} |
||||
return extraVO; |
||||
} |
||||
} |
@ -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; |
||||
|
||||
} |
@ -0,0 +1,37 @@
|
||||
package com.hnac.hzims.bigmodel.interactive.vo; |
||||
|
||||
import lombok.Data; |
||||
|
||||
import javax.validation.constraints.NotBlank; |
||||
|
||||
/** |
||||
* @Author: huangxing |
||||
* @Date: 2024/05/28 11:48 |
||||
*/ |
||||
@Data |
||||
public class HistoryDataSearchVO { |
||||
|
||||
@NotBlank |
||||
private String startTime; |
||||
|
||||
@NotBlank |
||||
private String endTime; |
||||
|
||||
@NotBlank |
||||
private String deviceCode; |
||||
|
||||
@NotBlank |
||||
private String signage; |
||||
|
||||
private String attrName; |
||||
|
||||
@NotBlank |
||||
private String method; |
||||
|
||||
private String dataType; |
||||
|
||||
private String stationName; |
||||
|
||||
private String deviceName; |
||||
|
||||
} |
@ -0,0 +1,39 @@
|
||||
package com.hnac.hzims.bigmodel.interactive.vo; |
||||
|
||||
import com.alibaba.fastjson.annotation.JSONField; |
||||
import lombok.Data; |
||||
import lombok.EqualsAndHashCode; |
||||
|
||||
import java.io.Serializable; |
||||
|
||||
/** |
||||
* @Author: huangxing |
||||
* @Date: 2024/05/20 14:46 |
||||
*/ |
||||
@Data |
||||
@EqualsAndHashCode |
||||
public class RemoteParamVO implements Serializable { |
||||
|
||||
@JSONField(name = "id") |
||||
private String funcId; |
||||
|
||||
@JSONField(name = "yk_name") |
||||
private String remoteName; |
||||
|
||||
@JSONField(name = "device_id") |
||||
private String deviceId; |
||||
|
||||
@JSONField(name = "device_name") |
||||
private String deviceName; |
||||
|
||||
@JSONField(name = "station_id") |
||||
private String projectId; |
||||
|
||||
@JSONField(name = "station_name") |
||||
private String projectName; |
||||
|
||||
private String signage; |
||||
|
||||
private String value; |
||||
|
||||
} |
@ -0,0 +1,29 @@
|
||||
package com.hnac.hzims.bigmodel.interactive.vo; |
||||
|
||||
import com.hnac.hzims.bigmodel.interactive.constants.InfoMessageConstant; |
||||
import io.swagger.annotations.ApiModel; |
||||
import lombok.AllArgsConstructor; |
||||
import lombok.Data; |
||||
import lombok.EqualsAndHashCode; |
||||
|
||||
import java.io.Serializable; |
||||
|
||||
/** |
||||
* @Author: huangxing |
||||
* @Date: 2024/06/21 16:31 |
||||
*/ |
||||
@EqualsAndHashCode |
||||
@Data |
||||
@AllArgsConstructor |
||||
@ApiModel(value = "解析结果",description = "解析结果") |
||||
public class ResolveResultVO implements Serializable { |
||||
|
||||
private String content; |
||||
|
||||
private ExtraVO extraVO; |
||||
|
||||
public static ResolveResultVO error() { |
||||
return new ResolveResultVO(InfoMessageConstant.ERROR_MESSAGE,null); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,19 @@
|
||||
package com.hnac.hzims.bigmodel.interactive.vo; |
||||
|
||||
import lombok.Data; |
||||
import lombok.EqualsAndHashCode; |
||||
|
||||
import java.io.Serializable; |
||||
|
||||
/** |
||||
* @Author: huangxing |
||||
* @Date: 2024/05/20 19:31 |
||||
*/ |
||||
@Data |
||||
@EqualsAndHashCode |
||||
public class SessionContentVO implements Serializable { |
||||
|
||||
/**机器码**/ |
||||
private String machineCode; |
||||
|
||||
} |
@ -0,0 +1,24 @@
|
||||
package com.hnac.hzims.bigmodel.interactive.vo; |
||||
|
||||
import lombok.Data; |
||||
|
||||
import javax.validation.constraints.NotBlank; |
||||
import java.io.Serializable; |
||||
|
||||
/** |
||||
* @Author: huangxing |
||||
* @Date: 2024/05/25 14:03 |
||||
*/ |
||||
@Data |
||||
public class StationSearchVO implements Serializable { |
||||
|
||||
private String startTime; |
||||
|
||||
private String endTime; |
||||
|
||||
@NotBlank(message = "查询类型不能为空") |
||||
private String type; |
||||
|
||||
private String enumType; |
||||
|
||||
} |
@ -0,0 +1,20 @@
|
||||
package com.hnac.hzims.bigmodel.interactive.vo; |
||||
|
||||
import lombok.Data; |
||||
|
||||
import java.io.Serializable; |
||||
|
||||
/** |
||||
* @Author: huangxing |
||||
* @Date: 2024/05/09 09:50 |
||||
*/ |
||||
@Data |
||||
public class UpdateStationVO implements Serializable { |
||||
|
||||
/**站点ID**/ |
||||
private String id; |
||||
|
||||
/**站点名称**/ |
||||
private String name; |
||||
|
||||
} |
@ -0,0 +1,25 @@
|
||||
package com.hnac.hzims.bigmodel.interactive.vo; |
||||
|
||||
import com.alibaba.fastjson.annotation.JSONField; |
||||
import lombok.Data; |
||||
|
||||
import java.io.Serializable; |
||||
|
||||
/** |
||||
* @Author: huangxing |
||||
* @Date: 2024/05/09 09:53 |
||||
*/ |
||||
@Data |
||||
public class UpdateUsualVO implements Serializable { |
||||
|
||||
/**站点ID**/ |
||||
@JSONField(name = "station_id") |
||||
private String stationId; |
||||
|
||||
/**业务ID**/ |
||||
private String id; |
||||
|
||||
/**业务名称**/ |
||||
private String name; |
||||
|
||||
} |
@ -0,0 +1,34 @@
|
||||
package com.hnac.hzims.bigmodel.manager; |
||||
|
||||
import com.hnac.hzims.bigmodel.interactive.vo.AnswerVO; |
||||
import lombok.AllArgsConstructor; |
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.data.redis.core.RedisTemplate; |
||||
import org.springframework.stereotype.Component; |
||||
|
||||
import java.util.List; |
||||
|
||||
import static com.hnac.hzims.bigmodel.schedule.XxlJobHandlerConstant.HZIMS_BIGMODEL_ASK_KEY; |
||||
|
||||
/** |
||||
* @Author: huangxing |
||||
* @Date: 2024/06/21 18:23 |
||||
*/ |
||||
@Component |
||||
public class SessionRedisManager { |
||||
|
||||
@Autowired |
||||
private RedisTemplate redisTemplate; |
||||
|
||||
public void addSessionId(String sessionId) { |
||||
redisTemplate.opsForList().leftPush(HZIMS_BIGMODEL_ASK_KEY,sessionId); |
||||
} |
||||
|
||||
public void removeSessionId(String sessionId) { |
||||
redisTemplate.opsForList().remove(HZIMS_BIGMODEL_ASK_KEY,1,sessionId); |
||||
} |
||||
|
||||
public List<String> getSessionIds() { |
||||
return redisTemplate.opsForList().range(HZIMS_BIGMODEL_ASK_KEY, 0, -1); |
||||
} |
||||
} |
@ -0,0 +1,88 @@
|
||||
package com.hnac.hzims.bigmodel.schedule; |
||||
|
||||
import com.alibaba.fastjson.JSON; |
||||
import com.alibaba.fastjson.JSONObject; |
||||
import com.hnac.hzims.bigmodel.interactive.factory.AnswerResolveFactory; |
||||
import com.hnac.hzims.bigmodel.interactive.service.IAnswerResolveService; |
||||
import com.hnac.hzims.bigmodel.interactive.service.IHznlmInteractiveService; |
||||
import com.hnac.hzims.bigmodel.interactive.service.IHznlmInvokeService; |
||||
import com.hnac.hzims.bigmodel.interactive.service.IResolveService; |
||||
import com.hnac.hzims.bigmodel.interactive.vo.AnswerVO; |
||||
import com.hnac.hzims.bigmodel.manager.SessionRedisManager; |
||||
import com.hnac.hzims.bigmodel.websocket.service.InteractiveWsService; |
||||
import com.hnac.hzims.bigmodel.websocket.sessionManager.InteractiveSessionManager; |
||||
import com.xxl.job.core.biz.model.ReturnT; |
||||
import com.xxl.job.core.handler.annotation.XxlJob; |
||||
import com.xxl.job.core.log.XxlJobLogger; |
||||
import lombok.AllArgsConstructor; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
import org.springblade.core.log.logger.BladeLogger; |
||||
import org.springblade.core.tool.utils.CollectionUtil; |
||||
import org.springblade.core.tool.utils.Func; |
||||
import org.springblade.core.tool.utils.ObjectUtil; |
||||
import org.springframework.stereotype.Component; |
||||
import org.springframework.web.socket.TextMessage; |
||||
import org.springframework.web.socket.WebSocketSession; |
||||
|
||||
import java.util.Arrays; |
||||
import java.util.List; |
||||
import java.util.concurrent.CompletableFuture; |
||||
import java.util.concurrent.ThreadPoolExecutor; |
||||
import java.util.stream.Collectors; |
||||
|
||||
import static com.hnac.hzims.bigmodel.schedule.XxlJobHandlerConstant.*; |
||||
|
||||
/** |
||||
* @Author: huangxing |
||||
* @Date: 2024/06/24 09:53 |
||||
*/ |
||||
@Component |
||||
@AllArgsConstructor |
||||
@Slf4j |
||||
public class FrontEndInteractiveSchedule { |
||||
|
||||
private final SessionRedisManager sessionRedisManager; |
||||
private final InteractiveWsService wsService; |
||||
private final ThreadPoolExecutor getAnswerPoolExecutor; |
||||
private final IHznlmInvokeService hznlmInvokeService; |
||||
private final BladeLogger logger; |
||||
|
||||
@XxlJob(GET_INTERACTIVE_RESULT) |
||||
public ReturnT getInteractiveResult(String params) { |
||||
List<String> sessionIds = sessionRedisManager.getSessionIds(); |
||||
if(CollectionUtil.isEmpty(sessionIds)){ |
||||
XxlJobLogger.log("问题都已经回答完毕!"); |
||||
return ReturnT.SUCCESS; |
||||
} |
||||
List<AnswerVO> answerList = hznlmInvokeService.getAnswerBySessionIds(String.join(",", sessionIds)); |
||||
answerList.stream().parallel().forEach(answerVO -> CompletableFuture.runAsync(() -> { |
||||
// 如果已经获取到答案 则删除缓存
|
||||
if(answerVO.getRunning() == 0) { |
||||
logger.info("hzims:bigmodel:getInteractiveResult:answer","获取大模型解析答案:" + JSON.toJSONString(answerVO)); |
||||
sessionRedisManager.removeSessionId(answerVO.getSessionId()); |
||||
} |
||||
Object[] extras = answerVO.getExtras(); |
||||
if(ObjectUtil.isNotEmpty(answerVO.getExtras()) && extras.length > 0){ |
||||
try { |
||||
// 解析答案
|
||||
Object[] resolveExtras = Arrays.stream(extras).map(extra -> { |
||||
IAnswerResolveService answerResolveService = AnswerResolveFactory.getResolveService(extra); |
||||
if(Func.isNotEmpty(answerResolveService)) { |
||||
JSONObject extraObject = JSONObject.parseObject(JSON.toJSONString(extra)); |
||||
return answerResolveService.getExtra(extraObject); |
||||
} |
||||
return extra; |
||||
}).map(JSON::toJSONString).toArray(); |
||||
answerVO.setExtras(resolveExtras); |
||||
} |
||||
catch(Exception e) { |
||||
log.error("An error occurred",e); |
||||
AnswerVO.error(answerVO.getSessionId(), answerVO.getUserId(), answerVO.getQuery()); |
||||
} |
||||
} |
||||
TextMessage message = InteractiveSessionManager.getTextMessage("1",JSON.toJSONString(answerVO)); |
||||
wsService.sendMessage(answerVO.getSessionId(),message); |
||||
}, getAnswerPoolExecutor)); |
||||
return ReturnT.SUCCESS; |
||||
} |
||||
} |
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue