forked from I3-YF/i3plus-mes-pcn-yfai
opc link
parent
f346405d5d
commit
c40ecb6c16
@ -0,0 +1,18 @@
|
|||||||
|
package cn.estsh.i3plus.ext.mes.pcn.api.busi;
|
||||||
|
|
||||||
|
import cn.estsh.i3plus.pojo.mes.model.MesEquipVariableRwModel;
|
||||||
|
import cn.estsh.i3plus.pojo.mes.model.MesEquipVariableRwResult;
|
||||||
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
|
||||||
|
public interface IMesEquipVariableRwExtService {
|
||||||
|
|
||||||
|
@ApiOperation(value = "读写访问地址")
|
||||||
|
MesEquipVariableRwModel getRwRequestUrl(MesEquipVariableRwModel equipVariableRwModel);
|
||||||
|
|
||||||
|
@ApiOperation(value = "写值")
|
||||||
|
MesEquipVariableRwResult writeVariable(MesEquipVariableRwModel equipVariableRwModel);
|
||||||
|
|
||||||
|
@ApiOperation(value = "读取")
|
||||||
|
MesEquipVariableRwResult readVariable(MesEquipVariableRwModel equipVariableRwModel);
|
||||||
|
|
||||||
|
}
|
@ -1,33 +0,0 @@
|
|||||||
package cn.estsh.i3plus.ext.mes.pcn.api.busi;
|
|
||||||
|
|
||||||
import cn.estsh.i3plus.pojo.mes.model.MesOpcLinkModel;
|
|
||||||
import cn.estsh.i3plus.pojo.mes.model.MesOpcLinkReturnModel;
|
|
||||||
import cn.estsh.impp.framework.boot.util.ResultBean;
|
|
||||||
import io.swagger.annotations.ApiOperation;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @Description :
|
|
||||||
* @Reference :
|
|
||||||
* @Author :
|
|
||||||
* @CreateDate : 2024-05-29 10:37
|
|
||||||
* @Modify:
|
|
||||||
**/
|
|
||||||
public interface IWriteOPCEquipmentService {
|
|
||||||
|
|
||||||
@ApiOperation(value = "查询工单")
|
|
||||||
ResultBean doOPCEquipment(List<Map<String, Object>> listData,String xmlString);
|
|
||||||
|
|
||||||
@ApiOperation(value = "writeVariableHttp")
|
|
||||||
String writeVariableHttp(String equipmentId,String channel,String clientHandle,String v, String wsUrl)throws Exception;
|
|
||||||
|
|
||||||
@ApiOperation(value = "写值")
|
|
||||||
MesOpcLinkReturnModel writeVariable(MesOpcLinkModel mesOpcLinkModel);
|
|
||||||
|
|
||||||
@ApiOperation(value = "读取")
|
|
||||||
MesOpcLinkReturnModel readVariable(MesOpcLinkModel mesOpcLinkModel);
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
@ -0,0 +1,118 @@
|
|||||||
|
package cn.estsh.i3plus.ext.mes.pcn.apiservice.serviceimpl.equiplog;
|
||||||
|
|
||||||
|
import cn.estsh.i3plus.ext.mes.pcn.api.busi.IMesEquipVariableRwExtService;
|
||||||
|
import cn.estsh.i3plus.ext.mes.pcn.pojo.util.MesPcnExtConstWords;
|
||||||
|
import cn.estsh.i3plus.mes.pcn.api.iservice.base.IConfigService;
|
||||||
|
import cn.estsh.i3plus.platform.common.tool.HttpClientTool;
|
||||||
|
import cn.estsh.i3plus.platform.common.tool.JsonUtilTool;
|
||||||
|
import cn.estsh.i3plus.pojo.base.enumutil.CommonEnumUtil;
|
||||||
|
import cn.estsh.i3plus.pojo.mes.bean.MesConfig;
|
||||||
|
import cn.estsh.i3plus.pojo.mes.model.MesEquipVariableRwModel;
|
||||||
|
import cn.estsh.i3plus.pojo.mes.model.MesEquipVariableRwResult;
|
||||||
|
import cn.estsh.i3plus.pojo.mes.util.MesExtEnumUtil;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.util.CollectionUtils;
|
||||||
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@Service
|
||||||
|
public class MesEquipmentRwExtServiceImpl implements IMesEquipVariableRwExtService {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private IConfigService configService;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MesEquipVariableRwModel getRwRequestUrl(MesEquipVariableRwModel equipVariableRwModel) {
|
||||||
|
|
||||||
|
if (StringUtils.isEmpty(equipVariableRwModel.getOrganizeCode())) return equipVariableRwModel;
|
||||||
|
|
||||||
|
//根据cfgCode查询缓存的配置数据
|
||||||
|
List<MesConfig> configList = configService.doCachedConfigList(MesPcnExtConstWords.EQUIP_VARIABLE_RW_CFG, equipVariableRwModel.getOrganizeCode());
|
||||||
|
|
||||||
|
//根据设备标识分组
|
||||||
|
Map<String, List<MesConfig>> requestUrlMap = getConfigMap(configList, MesPcnExtConstWords.KEPWARE_FLAG_CFG);
|
||||||
|
//根据读写标志分组
|
||||||
|
Map<String, List<MesConfig>> rwApiMap = getConfigMap(configList, MesPcnExtConstWords.RW_API_CFG);
|
||||||
|
|
||||||
|
if (CollectionUtils.isEmpty(requestUrlMap) || CollectionUtils.isEmpty(rwApiMap)) return equipVariableRwModel;
|
||||||
|
if (!rwApiMap.containsKey(MesExtEnumUtil.READ_WRITE_FLAG.READ.getValueStr()) || !rwApiMap.containsKey(MesExtEnumUtil.READ_WRITE_FLAG.WRITE.getValueStr())) return equipVariableRwModel;
|
||||||
|
|
||||||
|
List<MesConfig> requestUrlList = (StringUtils.isEmpty(equipVariableRwModel.getKepwareFlag()) || !requestUrlMap.containsKey(equipVariableRwModel.getKepwareFlag())) ? requestUrlMap.get(MesPcnExtConstWords.DEFAULT_URL) : requestUrlMap.get(equipVariableRwModel.getKepwareFlag());
|
||||||
|
if (CollectionUtils.isEmpty(requestUrlList)) return equipVariableRwModel;
|
||||||
|
|
||||||
|
//赋值读/写访问地址
|
||||||
|
return equipVariableRwModel.readRequestUrl(requestUrlList.get(0).getCfgValue() + rwApiMap.get(MesExtEnumUtil.READ_WRITE_FLAG.READ.getValueStr()).get(0).getCfgValue()).
|
||||||
|
writeRequestUrl(requestUrlList.get(0).getCfgValue() + rwApiMap.get(MesExtEnumUtil.READ_WRITE_FLAG.WRITE.getValueStr()).get(0).getCfgValue());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private Map<String, List<MesConfig>> getConfigMap(List<MesConfig> configList, String cfgType) {
|
||||||
|
List<MesConfig> filterList = CollectionUtils.isEmpty(configList) ? null :
|
||||||
|
configList.stream().filter(o -> (null != o && !StringUtils.isEmpty(o.getCfgType()) && !StringUtils.isEmpty(o.getCfgKey()) && o.getCfgType().equals(MesPcnExtConstWords.RW_API_CFG))).collect(Collectors.toList());
|
||||||
|
return CollectionUtils.isEmpty(filterList) ? null : filterList.stream().filter(o -> null != o).collect(Collectors.groupingBy(MesConfig::getCfgKey));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MesEquipVariableRwResult writeVariable(MesEquipVariableRwModel equipVariableRwModel) {
|
||||||
|
|
||||||
|
MesEquipVariableRwResult result = checkBefore(equipVariableRwModel);
|
||||||
|
|
||||||
|
if (!result.getIsSuccessed()) return result;
|
||||||
|
|
||||||
|
if (StringUtils.isEmpty(equipVariableRwModel.getValue())) return new MesEquipVariableRwResult(false).message("入参缺失必要参数[value]!");
|
||||||
|
|
||||||
|
Map<String, String> params = new HashMap<>();
|
||||||
|
params.put(MesPcnExtConstWords.VALUE, equipVariableRwModel.getValue());
|
||||||
|
params.put(MesPcnExtConstWords.CLIENT_HANDLE, equipVariableRwModel.getClientHandle());
|
||||||
|
params.put(MesPcnExtConstWords.CHANNEL, equipVariableRwModel.getChannel());
|
||||||
|
params.put(MesPcnExtConstWords.EQUIPMENT_ID, equipVariableRwModel.getEquipId());
|
||||||
|
|
||||||
|
String data = HttpClientTool.doHttpUrl(CommonEnumUtil.HTTP_METHOD_TYPE.POST, false, equipVariableRwModel.getWriteRequestUrl(), params, null, null);
|
||||||
|
if (!StringUtils.isEmpty(data)) return JsonUtilTool.decode(data, MesEquipVariableRwResult.class);
|
||||||
|
else return result.isSuccessed(false).message(String.format("设备数据变量写值失败! 数据信息:[%s]", JSONObject.toJSONString(equipVariableRwModel)));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private MesEquipVariableRwResult checkBefore(MesEquipVariableRwModel equipVariableRwModel) {
|
||||||
|
|
||||||
|
if (null == equipVariableRwModel) return new MesEquipVariableRwResult(false).message("入参为空!");
|
||||||
|
|
||||||
|
if (StringUtils.isEmpty(equipVariableRwModel.getOrganizeCode()) || StringUtils.isEmpty(equipVariableRwModel.getChannel()) || StringUtils.isEmpty(equipVariableRwModel.getEquipId()) || StringUtils.isEmpty(equipVariableRwModel.getClientHandle()))
|
||||||
|
return new MesEquipVariableRwResult(false).message("入参缺失必要参数,请检查参数[organizeCode][channel][equipId][clientHandle]是否缺失!");
|
||||||
|
|
||||||
|
if (StringUtils.isEmpty(equipVariableRwModel.getWriteRequestUrl()) || StringUtils.isEmpty(equipVariableRwModel.getReadRequestUrl())) getRwRequestUrl(equipVariableRwModel);
|
||||||
|
|
||||||
|
if (StringUtils.isEmpty(equipVariableRwModel.getWriteRequestUrl()) || StringUtils.isEmpty(equipVariableRwModel.getReadRequestUrl()))
|
||||||
|
return new MesEquipVariableRwResult(false).message(String.format("工厂[%s]缺失系统配置信息[%s]!", equipVariableRwModel.getOrganizeCode(), MesPcnExtConstWords.EQUIP_VARIABLE_RW_CFG));
|
||||||
|
|
||||||
|
return new MesEquipVariableRwResult(true);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MesEquipVariableRwResult readVariable(MesEquipVariableRwModel equipVariableRwModel) {
|
||||||
|
|
||||||
|
MesEquipVariableRwResult result = checkBefore(equipVariableRwModel);
|
||||||
|
|
||||||
|
if (!result.getIsSuccessed()) return result;
|
||||||
|
|
||||||
|
Map<String, String> params = new HashMap<>();
|
||||||
|
params.put(MesPcnExtConstWords.CLIENT_HANDLE, equipVariableRwModel.getClientHandle());
|
||||||
|
params.put(MesPcnExtConstWords.CHANNEL, equipVariableRwModel.getChannel());
|
||||||
|
params.put(MesPcnExtConstWords.EQUIPMENT_ID, equipVariableRwModel.getEquipId());
|
||||||
|
|
||||||
|
String data = HttpClientTool.doHttpUrl(CommonEnumUtil.HTTP_METHOD_TYPE.POST, false, equipVariableRwModel.getReadRequestUrl(), params, null, null);
|
||||||
|
if (!StringUtils.isEmpty(data)) return JsonUtilTool.decode(data, MesEquipVariableRwResult.class);
|
||||||
|
else return result.isSuccessed(false).message(String.format("设备数据变量读值失败! 数据信息:[%s]", JSONObject.toJSONString(equipVariableRwModel)));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue