|
|
|
@ -10,6 +10,9 @@ import com.hnac.gglm.bigmodel.interactive.vo.ExtraVO;
|
|
|
|
|
import com.hnac.hzims.operational.station.entity.StationEntity; |
|
|
|
|
import com.hnac.hzims.operational.station.feign.IStationClient; |
|
|
|
|
import com.hnac.hzinfo.exception.HzServiceException; |
|
|
|
|
import com.hnac.hzinfo.sdk.core.response.Result; |
|
|
|
|
import com.hnac.hzinfo.sdk.v5.scada.ScadaClient; |
|
|
|
|
import com.hnac.hzinfo.sdk.v5.scada.vo.CanvasVO; |
|
|
|
|
import lombok.AllArgsConstructor; |
|
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
|
import org.springblade.core.log.exception.ServiceException; |
|
|
|
@ -34,6 +37,7 @@ import java.util.stream.IntStream;
|
|
|
|
|
public class CanvasResolveServiceImpl implements IResolveService { |
|
|
|
|
|
|
|
|
|
private final IStationClient stationClient; |
|
|
|
|
private final ScadaClient scadaClient; |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public ExtraVO resolve(ModelFunctionReq req) { |
|
|
|
@ -49,41 +53,57 @@ public class CanvasResolveServiceImpl implements IResolveService {
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public ExtraVO resolve(String id) { |
|
|
|
|
List<String> params = Func.toStrList("\\^", id); |
|
|
|
|
Long scadaId; |
|
|
|
|
if(params.size() == 1) { |
|
|
|
|
scadaId = Long.valueOf(id); |
|
|
|
|
} else if(params.size() == 7) { |
|
|
|
|
scadaId = Long.valueOf(params.get(6)); |
|
|
|
|
} else { |
|
|
|
|
throw new HzServiceException("画面id格式错误,解析失败"); |
|
|
|
|
} |
|
|
|
|
Result<CanvasVO> canvasById = scadaClient.getCanvasById(null, scadaId); |
|
|
|
|
if(!canvasById.isSuccess()) { |
|
|
|
|
throw new HzServiceException("获取画面信息失败"); |
|
|
|
|
} |
|
|
|
|
CanvasVO canvasVO = canvasById.getData(); |
|
|
|
|
if(canvasVO == null) { |
|
|
|
|
throw new HzServiceException("获取画面信息失败"); |
|
|
|
|
} |
|
|
|
|
ExtraVO extraVO = new ExtraVO(); |
|
|
|
|
extraVO.setImmediatelyJump(true); |
|
|
|
|
extraVO.setFunc(FuncRouteEnum.OPEN_CANVAS.getFunc()); |
|
|
|
|
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")); |
|
|
|
|
int picResource = Integer.parseInt(resolveMap.get("picResource")); |
|
|
|
|
Map<String,Object> extraParams = new HashMap<>(1); |
|
|
|
|
extraParams.put("picResource",picResource); |
|
|
|
|
extraVO.setParams(extraParams); |
|
|
|
|
int picSource = canvasVO.getPicSource(); |
|
|
|
|
// 将 canvasVO 转换为 Map
|
|
|
|
|
Map<String, String> resolveMap = JSON.parseObject(JSON.toJSONString(canvasVO), Map.class); |
|
|
|
|
// 云组态
|
|
|
|
|
if(picResource == 0) { |
|
|
|
|
if(picSource == 0) { |
|
|
|
|
String path = this.replacePath(ParamCache.getValue(ParamKeyConstants.CANVAS_YZT_PATH), resolveMap); |
|
|
|
|
extraVO.setRoute(canvasHost + path); |
|
|
|
|
} |
|
|
|
|
// v3.0
|
|
|
|
|
else if(picResource == 1) { |
|
|
|
|
else if(picSource == 1) { |
|
|
|
|
String path = this.replacePath(ParamCache.getValue(ParamKeyConstants.CANVAS_V3_PATH), resolveMap); |
|
|
|
|
extraVO.setRoute(canvasHost + path); |
|
|
|
|
} |
|
|
|
|
// v4.0
|
|
|
|
|
else if (picResource == 2) { |
|
|
|
|
else if (picSource == 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}&itemName={itemName}", resolveMap)); |
|
|
|
|
extraVO.setRoute(canvasHost + 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 HzServiceException(ResultCode.FAILURE,"解析出来的画面类型在云组态、v3、v4类型之外,无法解析路由"); |
|
|
|
|
} |
|
|
|
|
R<StationEntity> stationR = stationClient.getStationByCode(canvasVO.getProjectId()); |
|
|
|
|
extraVO.setLabel(Optional.ofNullable(stationR).filter(r -> r.isSuccess()).map(R::getData).map(StationEntity::getName).orElse("") + "_" + resolveMap.get("name")); |
|
|
|
|
Map<String,Object> extraParams = new HashMap<>(1); |
|
|
|
|
extraParams.put("picResource", picSource); |
|
|
|
|
extraVO.setParams(extraParams); |
|
|
|
|
return extraVO; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -102,7 +122,7 @@ public class CanvasResolveServiceImpl implements IResolveService {
|
|
|
|
|
// 替换path中变量
|
|
|
|
|
for (Map.Entry<String, String> entry : entries) { |
|
|
|
|
String replaceVariables = "{" + entry.getKey() + "}"; |
|
|
|
|
path = StringUtil.replace(path,replaceVariables,entry.getValue()); |
|
|
|
|
path = StringUtil.replace(path,replaceVariables,String.valueOf(entry.getValue())); |
|
|
|
|
} |
|
|
|
|
return path; |
|
|
|
|
} |
|
|
|
|