| | |
| | | import com.jcdm.main.da.opcuaconfig.domain.NodeEntity; |
| | | import com.jcdm.main.da.opcuaconfig.init.BeanUtils; |
| | | import com.jcdm.main.da.paramCollection.domain.DaParamCollection; |
| | | import com.jcdm.main.da.paramCollection.service.IDaParamCollectionService; |
| | | import com.jcdm.main.da.passingStationCollection.domain.DaPassingStationCollection; |
| | | import com.jcdm.main.da.passingStationCollection.service.IDaPassingStationCollectionService; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.eclipse.milo.opcua.stack.core.types.builtin.DataValue; |
| | | import org.eclipse.milo.opcua.stack.core.types.builtin.NodeId; |
| | | |
| | | import java.time.Duration; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | |
| | | @Slf4j |
| | | public class MethodName { |
| | | private IDaCollectionParamConfService collectionParamConfService = BeanUtils.getBean(IDaCollectionParamConfService.class); |
| | | private IDaParamCollectionService daParamCollectionService = BeanUtils.getBean(IDaParamCollectionService.class); |
| | | private IDaPassingStationCollectionService daPassingStationCollectionService = BeanUtils.getBean(IDaPassingStationCollectionService.class); |
| | | private List<DataValue> s=null; |
| | | public void getSn(String Node, String value) throws Exception { |
| | | log.info(Node+":"+value); |
| | | String[] parts = Node.split("[.]"); |
| | | ClientHandler clientHandler=new ClientHandler(); |
| | | NodeEntity SN_node= NodeEntity.builder().index(2).identifier(parts[0]+"."+parts[1]+".SNCode").value("").type("").build(); |
| | | String SNCode=clientHandler.read(SN_node); |
| | | log.info("读取节点:{},结果:{}", SN_node.getIdentifier(),SNCode); |
| | | switch (value) { |
| | | case "0": //初始 |
| | | NodeEntity node= NodeEntity.builder().index(2).identifier(parts[0]+"."+parts[1]+".RecordDataDone").value("0").type("short").build(); |
| | |
| | | case "1": //请求下发进站状态 |
| | | NodeEntity node1= NodeEntity.builder().index(2).identifier(parts[0]+"."+parts[1]+".RecordDataDone").value("11").type("short").build(); |
| | | Boolean out1=clientHandler.write(node1); |
| | | DaPassingStationCollection PassingStationCollection=new DaPassingStationCollection(); |
| | | PassingStationCollection.setSfcCode(SNCode); |
| | | PassingStationCollection.setLocationCode(parts[1]); |
| | | PassingStationCollection.setInboundTime(new Date()); |
| | | daPassingStationCollectionService.insertDaPassingStationCollection(PassingStationCollection); |
| | | log.info("节点:{},响应结果:{}", node1.getIdentifier(),out1); |
| | | break; |
| | | case "2": //请求记录工位数据 |
| | | List<DaCollectionParamConf> b; |
| | | DaCollectionParamConf daCollectionParamConf=new DaCollectionParamConf(); |
| | | daCollectionParamConf.setCollectParameterId(parts[0]+"."+parts[1]); |
| | | daCollectionParamConf.setGatherAddress(parts[0]+"."+parts[1]); |
| | | b=collectionParamConfService.selectDaCollectionParamConfList(daCollectionParamConf); |
| | | List<String> ids = b.stream().map(e -> e.getCollectParameterId()).collect(Collectors.toList()); |
| | | Set<String> de=ListToSet(ids); |
| | | List<DataValue> s=readValues(de); |
| | | // s.forEach(element->{ |
| | | // DaParamCollection Config=new DaParamCollection(); |
| | | // String[] q = element.getIdentifier().split("[.]"); |
| | | // Config.setParamCode(q[2]); |
| | | // Config.setLocationCode(q[1]); |
| | | // Config.setParamValue(element.getValue().toString()); |
| | | // daParamCollectionService.insertDaParamCollection(Config); |
| | | // }); |
| | | |
| | | List<NodeId> nodeId = b.stream().map(info -> { |
| | | NodeId nodeid = new NodeId(2,info.getGatherAddress()); |
| | | return nodeid; |
| | | }).collect(Collectors.toList()); |
| | | List<DataValue> s=readValues(nodeId); |
| | | //保存PLC采集数据 |
| | | for(int i=0;i<nodeId.size();i++) |
| | | { |
| | | DaParamCollection Config=new DaParamCollection(); |
| | | Config.setParamCode(nodeId.get(i).getIdentifier().toString().split("[.]")[2]); |
| | | Config.setLocationCode(nodeId.get(i).getIdentifier().toString().split("[.]")[1]); |
| | | Config.setParamValue(s.get(i).getValue().getValue().toString()); |
| | | Config.setSfcCode(SNCode); |
| | | Config.setParamName(b.get(i).getGatherAddress()); |
| | | daParamCollectionService.insertDaParamCollection(Config); |
| | | } |
| | | //更新出站时间,计算节拍。 |
| | | DaPassingStationCollection PSC=new DaPassingStationCollection(); |
| | | PSC.setSfcCode(SNCode); |
| | | List<DaPassingStationCollection> LPSC=daPassingStationCollectionService.selectDaPassingStationCollectionList(PSC); |
| | | if(LPSC != null && LPSC.size() > 0){ |
| | | LPSC.get(0).setOutboundTime(new Date()); |
| | | LPSC.get(0).setCollectionTime(new Date()); |
| | | LPSC.get(0).setBeatTime(Long.toString(Math.abs(new Date().getTime() - LPSC.get(0).getInboundTime().getTime()))); |
| | | daPassingStationCollectionService.updateDaPassingStationCollection(LPSC.get(0)); |
| | | } |
| | | //更新PLC节点状态 |
| | | NodeEntity node2= NodeEntity.builder().index(2).identifier(parts[0]+"."+parts[1]+".RecordDataDone").value("21").type("short").build(); |
| | | Boolean out2=clientHandler.write(node2); |
| | | log.info("节点:{},响应结果:{}", node2.getIdentifier(),out2); |
| | |
| | | default: |
| | | break; |
| | | } |
| | | } |
| | | |
| | | public Set<String> ListToSet(List<String> list) { |
| | | Object[] objects = list.toArray();// 返回Object数组 |
| | | String[] strings1 = new String[list.size()]; |
| | | list.toArray(strings1);// 将转化后的数组放入已经创建好的对象中 |
| | | String[] strings2 = list.toArray(new String[0]);// 将转化后的数组赋给新对象 |
| | | Set<String> set = new HashSet<String>(Arrays.asList(strings2)); |
| | | return set; |
| | | } |
| | | } |