ZengTao
2024-04-01 bd456a3fca8cb8e8c1a15fa21ca02117512f3c5c
springboot-vue3/src/main/java/com/example/springboot/component/PlcHoldNew.java
@@ -1,25 +1,21 @@
package com.example.springboot.component;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import com.example.springboot.service.JdbcConnections;
import com.example.springboot.service.SpianServiceNew;
import com.example.springboot.entity.north_glass_buffer1;
import com.example.springboot.service.StorageCageService;
import com.example.springboot.entity.GlassInfo;
import com.example.springboot.entity.device.PlcParameterObject;
import com.example.springboot.mapper.AlarmMapper;
import com.example.springboot.mapper.AlbaniaMapper;
import com.example.springboot.mapper.SpianMapper;
public class PlcHoldNew extends Thread {
  private AlarmMapper alarmMapper;
  @Autowired
  private JdbcConnections jdbcConnections;
  private AlbaniaMapper albaniaMapper;
  private SpianServiceNew spianService;
  private StorageCageService storageCageService;
  int aaa;
  @Override
@@ -30,66 +26,93 @@
        Thread.sleep(100);
      } catch (InterruptedException e) {
        // \\ TODO Auto-generated catch block
        e.printStackTrace();
      }
      storageCageService = WebSocketServer.applicationContext.getBean(StorageCageService.class);
      spianService = WebSocketServer.applicationContext.getBean(SpianServiceNew.class);
      albaniaMapper = WebSocketServer.applicationContext.getBean(AlbaniaMapper.class);
      //spianService.selectAll(albaniaMapper.SelectGlass());
      //读取DB14区文件
      PlcParameterObject plcmes=PLCAutoMes.PlcMesObject;
      if(plcmes.getPlcParameter("PLCToMES").getValue()!=null){
      // spianService.Mestast("NG0001-1",0,3,1,"MESID1",1);
      //  S7control.getinstance().WriteWord(plcmes.getPlcParameter("MESToPLC").getAddress(), (short)1);//出片任务启动
    
      String ExportTOMES1=plcmes.getPlcParameter("ExportTOMES1").getValue();//出片请求一线
      String ExportToMES2=plcmes.getPlcParameter("ExportToMES2").getValue();//出片请求二线
      String PLCToMES=plcmes.getPlcParameter("PLCToMES").getValue();//进片请求
      String B01State=plcmes.getPlcParameter("B01State").getValue();//运送车请求
      String TastState=plcmes.getPlcParameter("MESToPLCStatus1").getValue();//任务完成
      String PLCToMES=plcmes.getPlcParameter("PLCToMES").getValue();//运送车请求
      String IDStatus1=plcmes.getPlcParameter("IDStatus1").getValue();//1号任务完成
      String MESToPLCStatus1=plcmes.getPlcParameter("MESToPLCStatus1").getValue();//1号确认字
      
      //一号线请求
      if (ExportTOMES1.equals("1") == true&&B01State.equals("0")==true) {
      if(ExportTOMES1!=null){
      if (ExportTOMES1.equals("1") == true&&PLCToMES.equals("1")==true) {
        //将运输车状态改为忙碌
        S7control.getinstance().WriteWord(plcmes.getPlcParameter("B01report").getAddress(), (short) 1);
        spianService.selectout(1);
      }
    }
      // //二线号请求时
      if (ExportToMES2.equals("1") == true&&B01State.equals("0")==true) {
      if(ExportToMES2!=null ){
      if (ExportToMES2.equals("1") == true&&PLCToMES.equals("1")==true) {
        //将运输车状态改为忙碌
        S7control.getinstance().WriteWord(plcmes.getPlcParameter("B01report").getAddress(), (short) 1);
        spianService.selectout(2);
      }
    }
      //进片请求时
      if(PLCToMES!=null && B01State!=null){
      if(PLCToMES.equals("1")==true&&B01State.equals("0")==true){
        //将运输车状态改为忙碌
        //S7control.getinstance().WriteWord(plcmes.getPlcParameter("B01report").getAddress(), (short) 1);
        spianService.selectAll(albaniaMapper.SelectGlass());
      GlassInfo glass=albaniaMapper.SelectGlass();
      if(PLCToMES!=null && glass!=null){
      if(PLCToMES.equals("1")==true&&glass!=null){
        spianService.selectAll(glass);
      }
    }
    
      //任务完成时
      if(TastState.equals("1")==true){
      if(IDStatus1.equals("1")==true && MESToPLCStatus1.equals("0")==true){
        //完成确认字
        for(int i=1;i<7;i++){
          String Tastover=plcmes.getPlcParameter("IDStatus"+i).getValue();//依次获取任务类型
          String Glassid=plcmes.getPlcParameter("MESID"+i).getValue();//依次获取任务类型
          if(Tastover.equals("1")){
            //调用完成任务 Glassid
            S7control.getinstance().WriteWord(plcmes.getPlcParameter("MESToPLCStatus"+i).getAddress(), (short) 1);//完成确认字
          String Tastover=plcmes.getPlcParameter("IDStatus"+i).getValue();//PLC理片任务状态汇报
          String Glassid=plcmes.getPlcParameter("MESID"+i).getValueString();//MES玻璃ID
          GlassInfo id=albaniaMapper.SelectTaskId(Glassid);
            if(id!=null&&Tastover.equals("1")){
              //调用完成任务 Glassid
              storageCageService.FinishTask(id.getId());
            }
              S7control.getinstance().WriteWord(plcmes.getPlcParameter("MESToPLC").getAddress(), (short) 0);//清除任务字
              S7control.getinstance().WriteWord(plcmes.getPlcParameter("MESToPLCStatus"+i).getAddress(), (short) 1);//完成确认字
            }
          }
      //汇报取消时
      if(IDStatus1.equals("0")==true &&MESToPLCStatus1.equals("1")){
        //取消确认字
        for(int i=1;i<7;i++){
          String Tastover=plcmes.getPlcParameter("IDStatus"+i).getValue();//依次获取任务汇报
          if(Tastover.equals("0")){
            S7control.getinstance().WriteWord(plcmes.getPlcParameter("MESToPLCStatus"+i).getAddress(), (short) 0);//清除确认字
          }
        }
      }
    }
  }
  
      // 查询数据库
      // 推送到前端
      // }
    }
  }