严智鑫
2024-05-10 211cd083bc9fc1871779802650dfe0e607d8ca77
hangzhoumesParent/moduleService/CacheGlassModule/src/main/java/com/mes/common/PlcHomeEdg.java
@@ -1,8 +1,9 @@
package com.mes.common;
import cn.hutool.core.date.DateTime;
import cn.hutool.json.JSONObject;
import com.github.yulichang.query.MPJLambdaQueryWrapper;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.mes.device.PlcParameterObject;
import com.mes.edgstoragecage.entity.EdgStorageCage;
import com.mes.edgstoragecage.entity.EdgStorageCageDetails;
import com.mes.edgstoragecage.mapper.EdgStorageCageDetailsMapper;
@@ -11,12 +12,12 @@
import com.mes.glassinfo.entity.GlassInfo;
import com.mes.glassinfo.service.GlassInfoService;
import com.mes.taskcache.entity.TaskCache;
import com.mes.taskcache.mapper.TaskCacheMapper;
import com.mes.taskcache.service.TaskCacheService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@@ -27,7 +28,6 @@
public class PlcHomeEdg extends Thread {
    @Autowired
    TaskCacheService taskCacheService;
    @Autowired
@@ -36,37 +36,15 @@
    EdgStorageCageService edgStorageCageService;
    @Autowired
    EdgStorageCageDetailsService edgStorageCageDetailsService;
    @Autowired
    @Resource
    private EdgStorageCageDetailsMapper edgStorageCageDetailsMapper;
    private Map<String,String> mapParameter=new HashMap<String,String>();
    private Map<String,String> mapValue=new HashMap<String,String>();
    private Map<String, String> mapType = new HashMap<String, String>();
    private Map<String,Object> mapSettings=new HashMap<String,Object>();
    private void initialize(){
        mapParameter.put("A06_request_word","DB11.0");//请求字
        mapParameter.put("A05_scanning_ID","DB11.2");//请求ID
        mapParameter.put("MES_confirmation_word","DB11.40");//MES发送字
        mapParameter.put("A09_glass_status","DB11.70");//A09玻璃状态
        mapParameter.put("A10_glass_status","DB11.72");//A10玻璃状态
        mapParameter.put("A09_prohibit_film_production","DB11.74");//A9禁止出片
        mapParameter.put("A10_prohibit_film_production","DB11.76");//A10禁止出片
        mapSettings.put("territoryPoor",3);
//        mapValue.put("A06_request_word","1");//请求字
//        mapValue.put("A05_scanning_ID","7");//请求ID
//        mapValue.put("MES_confirmation_word","0");//MES发送字
//        mapValue.put("A09_glass_status","0");//A09玻璃状态
//        mapValue.put("A10_glass_status","0");//A09玻璃状态
//        mapValue.put("A09_prohibit_film_production","0");//A9禁止出片
//        mapValue.put("A10_prohibit_film_production","0");//A10禁止出片
        for (String key:mapParameter.keySet()){
            String value=S7object.getinstance().plccontrol.readString(mapParameter.get(key));
            mapValue.put(key,value);
        }
    }
    private boolean inTo(){
    private void inTo() {
        List<GlassInfo> glassInfos=glassInfoService.selectId(mapValue.get("A05_scanning_ID"));
        if(glassInfos.size()<1){
            log.info("此玻璃编号不存在");
@@ -90,16 +68,16 @@
                taskCache.setCreateTime(new DateTime());
                edgStorageCageDetailsMapper.updateById(edgStorageCageDetails);
                taskCacheService.insertTaskCache(taskCache);
                return true;
                S7object.getinstance().plccontrol.WriteWord(mapParameter.get("MES_confirmation_word"), (short)1);
            }else{
                log.info("不存在空格");
            }
        }else{
            log.info("此玻璃编号存在多个");
        }
        return false;
    }
    private boolean outTo(int line){
    private void outTo(int line) {
        int endcell=0;
        EdgStorageCageDetails outEdgStorageCageDetails=new EdgStorageCageDetails();
        TaskCache taskCacheA09=taskCacheService.selectLastOutCacheInfo(2001);
@@ -127,57 +105,53 @@
            taskCache.setTaskType(2);
            taskCache.setCreateTime(new DateTime());
            taskCacheService.insertTaskCache(taskCache);
            return true;
        }
        return false;
    }
    @Override
    public void run() {
        boolean start=false;
        boolean isSend=false;
        while (this != null&&start) {
            JSONObject jsonObject = new JSONObject();
            try {
                Thread.sleep(1000);
                taskCacheService  = WebSocketServer.applicationContext.getBean(TaskCacheService.class);
                glassInfoService  = WebSocketServer.applicationContext.getBean(GlassInfoService.class);
                edgStorageCageService  = WebSocketServer.applicationContext.getBean(EdgStorageCageService.class);
                edgStorageCageDetailsMapper  = WebSocketServer.applicationContext.getBean(EdgStorageCageDetailsMapper.class);
                initialize();//初始化数据
                log.info("当前参数值:{}",mapValue);
                if("0".equals(mapValue.get("A06_request_word"))){
                    //清除
                    //S7object.getinstance().plccontrol.WriteWord(mapParameter.get("MES_confirmation_word"),(short) 0);
                }else if("1".equals(mapValue.get("A06_request_word"))&&
                         "0".equals(mapValue.get("MES_confirmation_word")))
                {
                    //进片任务  查找是否存在此片玻璃  存在则生成任务
                    isSend=inTo();
                }else if("2".equals(mapValue.get("A06_request_word"))&&
                         "0".equals(mapValue.get("MES_confirmation_word"))&&
                        (
                         "0".equals(mapValue.get("A09_glass_status"))||
                         "0".equals(mapValue.get("A10_glass_status"))
                        )
                ){
                    //出片任务 查找两条线上一次任务的尺寸
                    isSend=outTo(3);
                }else if("3".equals(mapValue.get("A06_request_word"))&&
                         "0".equals(mapValue.get("MES_confirmation_word"))){
                    //先出后进
                    if("0".equals(mapValue.get("A09_glass_status"))||"0".equals(mapValue.get("A10_glass_status"))){
                        isSend=outTo(3);
                    }else{
                        isSend=inTo();
                    }
                }
                if(isSend){
                    S7object.getinstance().plccontrol.WriteWord(mapParameter.get("MES_confirmation_word"),(short)1);
                }
    }
    @Override
    public void run() {
        boolean start = true;
        log.info("当前参数值:{}", mapValue);
        while (this != null && start) {
            JSONObject jsonObject = new JSONObject();
            for (String key : mapParameter.keySet()) {
                String value = "";
                if ("String".equals(mapType.get(key))) {
                    value = S7object.getinstance().plccontrol.readString(mapParameter.get(key));
                } else {
                    value = S7object.getinstance().plccontrol.readWord(mapParameter.get(key)) + "";
                }
                mapValue.put(key, value);
            }
            S7object.getinstance().plccontrol.WriteWord(S7object.getinstance().PlcMesObject.getPlcParameter("A06_request_word").getAddress(), (short)1);
            try {
                Thread.sleep(1000);
//                initialize();//初始化数据
                if ("0".equals(S7object.getinstance().PlcMesObject.getPlcParameter("A06_request_word"))) {
                    //清除
                    S7object.getinstance().plccontrol.WriteWord(mapParameter.get("MES_confirmation_word"), (short) 0);
                } else if ("1".equals(S7object.getinstance().PlcMesObject.getPlcParameter("A06_request_word")) &&
                        "0".equals(S7object.getinstance().PlcMesObject.getPlcParameter("MES_confirmation_word"))) {
                    inTo();
                } else if ("2".equals(mapValue.get("A06_request_word")) &&
                        "0".equals(mapValue.get("MES_confirmation_word")) && !"0".equals(mapValue.get("A09_glass_status"))) {
                    //09空闲 :1      10空闲 :2        都空闲:3    其他0
                    outTo(Integer.parseInt(mapValue.get("A09_glass_status")));
                } else if ("3".equals(mapValue.get("A06_request_word")) &&
                        "0".equals(mapValue.get("MES_confirmation_word"))) {
                    if ("0".equals(mapValue.get("A09_glass_status")) || "0".equals(mapValue.get("A10_glass_status"))) {
                        outTo(Integer.parseInt(mapValue.get("A09_glass_status")));
                    } else {
                        inTo();
                    }
                }
            } catch (InterruptedException e) {
                e.printStackTrace();
            }