严智鑫
2024-03-18 ef47083c90ff7e70362a32741a0a4d5770037e7f
springboot-vue3/src/main/java/com/example/springboot/service/SpianServiceNew.java
@@ -8,10 +8,9 @@
import com.example.springboot.component.S7control;
import com.example.springboot.entity.GlassInfo;
import com.example.springboot.entity.StorageCage;
import com.example.springboot.entity.glassinfo;
import com.example.springboot.entity.GlassInfo;
import com.example.springboot.entity.device.PlcParameterObject;
import com.example.springboot.mapper.AlbaniaMapper;
import com.example.springboot.mapper.SpianMapper;
import com.google.common.primitives.Bytes;
@@ -24,29 +23,75 @@
public Short selectAll(GlassInfo glassInfo) {
    //定义初始字段
    int cageid;
    String glassid=glassInfo.getGlassid();
    Double width=glassInfo.getWidth();
    //int mateid=glassInfo.getMateid();
    String flowcard=glassInfo.getFlowcard();
    int glasstype=glassInfo.getGlasstype();
    //判断是否有同类型的
     cageid=albaniaMapper.SelectCage(glassInfo.getGlasstype(), glassInfo.getWidth(), 50);
     cageid=albaniaMapper.SelectCage(glasstype,width, 50);
    //如果有同类型时直接增加
    if(cageid!=Integer.MIN_VALUE){
        albaniaMapper.UpdateCageNumberAdd(cageid);
    }else{
        //发送plc任务
        //Mestast(glassid,1001,cageid,1);
    }else{
         //判断玻璃是否进入大片笼
        if(glassInfo.getThickness()>=15){
            cageid=albaniaMapper.SelectNewCell(3,5);
        }else{
            cageid=albaniaMapper.SelectNewCell(3,5);
            //发送plc任务
        }
        //当返回的格子号为空时,返回400笼子已满
        if(cageid==Integer.MIN_VALUE){
        if(cageid!=Integer.MIN_VALUE){
            Mestast(glassid,1001,cageid,1);
            //发送plc任务
        }else{
            return(400);
        }
    }
    //增加任务记录
    albaniaMapper.Inserttask(0, 0, 1001, cageid, glassid,glasstype, flowcard,0,0);
    return(200);
}
    public Short selectout2(String glassid) {
    //出片
    public Short selectout(int line) {
        int mateid;
        int glasstype;
        int tier;
        int sumid;
        String flowcard;
        GlassInfo glassmate=new GlassInfo();
            for(int i=1;i<=7;i++){
                glassmate= albaniaMapper.SelectOutGlass(line);
                mateid=glassmate.getMateid();
                glasstype=glassmate.getGlasstype();
                tier=glassmate.getTier();
                sumid=glassmate.getId();
                flowcard=glassmate.getFlowcard();
                    StorageCage glass= albaniaMapper.SelectCageGlass(glasstype);
                    //发送配片数据
                    Mestast(glassmate.getGlasstype()+"i", glass.getId(),2002, 0);
                    albaniaMapper.AddFinishNumber(flowcard, mateid, tier);
                    albaniaMapper.Inserttask(1, 0, glass.getId(), 2002, glassmate.getGlassid()+i, glasstype,glass.getFlowcard(),mateid,tier);
                    if(tier==sumid){
                        //本次配片完成发送启动命令
                        S7control.getinstance().WriteWord(plcmes.getPlcParameter("MESToPLC").getAddress(), (short)2);//出片任务启动
                        return (200);//结束
                    }
            }
       
        return(200);// 结束
    }
@@ -63,7 +108,7 @@
        }
        byte[] bytes = Bytes.toArray(glassidlist);
        System.out.println("outmesidbytes:" + bytes.length);
        S7control.getinstance().WriteByte(plcmes.getPlcParameter(address).getAddress(plcmes.getPlcParameter(address).getAddressIndex()),bytes);
        S7control.getinstance().WriteByte(plcmes.getPlcParameter(address).getAddress(),bytes);
        //S7control.getinstance().WriteByte(address, bytes);// 派发出片id
    }
@@ -78,7 +123,7 @@
                writedstrIdOut.append((char) iditem);
            }
        }
        return writedstrIdOut;
        return writedstrIdOut;
    }
    // char数组转化成bit数组
@@ -100,15 +145,16 @@
        return listbool;
    }
    // 根据玻璃id完成在进行中的任务
    public void overtask(String glassid) {
        // spianMapper.UpdatetaskOut(glassid.toString());// 完成上一次 出片或者进片任务
        // spianMapper.OverOutSlice(glassid.toString(), 2, 1);// 完成出片队列任务
        // spianMapper.UpdataGlassCage(glassid.toString(), 0);// 清除出片格子玻璃信息
        // spianMapper.UpdateCageOver(glassid.toString(), 0);// 更改笼子表出片状态
        // spianMapper.UpdateCageadd(glassid.toString(), 1);// 更改笼子表进片状态
        // spianMapper.UpdateAddQueue(glassid.toString());// 把进片的玻璃更新到出片队列中
    //下发理片任务
    public void Mestast(String glassid,int MESToPLCStart1,int MESToPLCTarget1,int MESToPLC) {
        outmesid(glassid, "MESID1");//下发玻璃id
        S7control.getinstance().WriteWord(plcmes.getPlcParameter("MESToPLCStart1").getAddress(), (short) MESToPLCStart1);//起始位置
        S7control.getinstance().WriteWord(plcmes.getPlcParameter("MESToPLCTarget1").getAddress(), (short) MESToPLCTarget1);//目标位置
        if(MESToPLC!=0){
            S7control.getinstance().WriteWord(plcmes.getPlcParameter("MESToPLC").getAddress(), (short)MESToPLC);//mes理片任务类型
        }
    }
}