|
|
|
@ -1,14 +1,30 @@
|
|
|
|
|
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 |
|
|
|
@ -19,15 +35,101 @@ import org.springframework.stereotype.Service;
|
|
|
|
|
@Slf4j |
|
|
|
|
public class CanvasResolveServiceImpl implements IResolveService { |
|
|
|
|
|
|
|
|
|
private final ScadaClient scadaClient; |
|
|
|
|
private final IStationClient stationClient; |
|
|
|
|
private final BladeLogger logger; |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public ResolveResultVO resolve(ModelFunctionReq req) { |
|
|
|
|
return null; |
|
|
|
|
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(Long id) { |
|
|
|
|
return null; |
|
|
|
|
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; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|