wang
2024-03-28 04adb88a2ed54cdf4c2958c79972c30109b9b5b6
UnLoadGlassModule/src/main/java/com/mes/service/PlcService.java
New file
@@ -0,0 +1,139 @@
package com.mes.service;
import com.mes.entity.DownGlassInfo;
import com.mes.entity.DownStorageCageDetails;
import com.mes.entity.DownWorkstation;
import com.mes.entity.device.PlcParameterObject;
import com.mes.mapper.DownGlassInfoMapper;
import com.mes.mapper.DownWorkstationMapper;
import com.mes.tools.WebSocketServer;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Data
@Service
public class PlcService {
    @Autowired
    private DownWorkstationMapper downWorkstationMapper;
    private DownGlassInfo downGlassInfo;
    private DownWorkstation downWorkstation;
    private DownGlassInfoMapper downGlassInfoMapper;
    private DownGlassInfoService downGlassInfoService;
    private List<DownGlassInfo> glassList; // 存放待处理的玻璃信息
    private List<DownStorageCageDetails> cageDetailsList; // 存放玻璃放置在缓存笼中的详细信息
    PlcParameterObject plcread=PLCAutoMes.PlcReadObject;
    String Robot1PLCrequestword=plcread.getPlcParameter("A01Position").getValue();// 机械手1PLC请求字
    String Robot2PLCrequestword=plcread.getPlcParameter("A01Position").getValue();// 机械手2PLC请求字
    String GlassID=plcread.getPlcParameter("A01Position").getValue();// 玻璃id
    String Glasswidth=plcread.getPlcParameter("A01Position").getValue();//玻璃宽度
    String Glassheight=plcread.getPlcParameter("A01Position").getValue();//玻璃高度
    String Glassthickness=plcread.getPlcParameter("A01Position").getValue();//厚度
    String PLCwancheng = plcread.getPlcParameter("A01Position").getValue();// plc完成字
    //当下片任务表状态为1时候将数据插入到下片玻璃信息表
    public void insertdownglassinfo() {
        downWorkstationMapper = WebSocketServer.applicationContext.getBean(DownWorkstationMapper.class);
        downGlassInfoService = WebSocketServer.applicationContext.getBean(DownGlassInfoService.class);
        downGlassInfoMapper = WebSocketServer.applicationContext.getBean(DownGlassInfoMapper.class);
        List<DownGlassInfo> taskdownGlassInf = downGlassInfoMapper.selectunloadingtaskstate();
//
        if (taskdownGlassInf != null && !taskdownGlassInf.isEmpty()) {
            for (DownGlassInfo downGlassInfo : taskdownGlassInf) {
                // 创建新的 DownGlassInfo 对象并设置相关属性
                DownGlassInfo newdownGlassInfo = new DownGlassInfo();
                newdownGlassInfo.setFlowCardId(downGlassInfo.getFlowCardId());
                Integer maxSequence = downGlassInfoMapper.getMaxSequenceByFlowCardId(downGlassInfo.getFlowCardId());
                int sequence = maxSequence != null ? maxSequence + 1 : 1; // 初始化顺序字段值
                newdownGlassInfo.setWidth(downGlassInfo.getWidth());
                newdownGlassInfo.setHeight(downGlassInfo.getHeight());
                newdownGlassInfo.setThickness(downGlassInfo.getThickness());
                newdownGlassInfo.setFilmsid(downGlassInfo.getFilmsid());
                newdownGlassInfo.setSequence(sequence); // 设置顺序字段值
                // 插入数据到下片玻璃信息表
                downGlassInfoMapper.insert(newdownGlassInfo);
                //插入数据到机械手任务表
                downWorkstationMapper.insertdownWorkstationtask(newdownGlassInfo);
                //更新任务表状态为0
                downGlassInfoMapper.updateTaskStateToZero(downGlassInfo.getFlowCardId());
                sequence++; // 递增顺序字段值
            }
        }
    }
    //当机械手任务表中状态为1,工位表流程卡绑定了架子 更新已经落架数量,并且把下片任务表的对应记录删掉
    public void down_workstation(){
        //downWorkstationMapper = WebSocketServer.applicationContext.getBean(DownWorkstationMapper.class);
        //downGlassInfoMapper = WebSocketServer.applicationContext.getBean(DownGlassInfoMapper.class);
        try {
            List<DownWorkstation> taskdownWorkstation = downWorkstationMapper.selectdownWorkstationstate();
            if (taskdownWorkstation != null && !taskdownWorkstation.isEmpty()) {
                //查询下片工位表中是否绑定了架子是否绑定了流程卡号,如果已经绑定则更新已落架数量,并且删除下片任务表中的记录
                for (DownWorkstation downWorkstation : taskdownWorkstation) {
                    downWorkstationMapper.update_racks_number(downWorkstation.getFlowCardId(),6 );
                    downGlassInfoMapper.deletetask(downWorkstation.getFlowCardId());
                }
            }
        } catch (Exception e) {
            // 打印异常信息
            e.printStackTrace();
            // 或者可以进行其他异常处理,比如记录日志或者返回特定的错误信息
        }
    }
    //绑定流程卡号架子
    public void bindingshelf(DownWorkstation downWorkstation){
        String FlowCardId=downWorkstation.getFlowCardId();
        int WorkstationId=downWorkstation.getWorkstationId();
    }
}