自动化立体仓库 - WCS系统
#
whycq
2023-02-23 07bf4e02409eb63ee83c4f7e178505ff4de26186
#
1个文件已添加
1个文件已修改
288 ■■■■ 已修改文件
src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java 105 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/common/utils/News.java 183 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java
@@ -21,6 +21,7 @@
import com.zy.common.service.CommonService;
import com.zy.common.utils.CollectionUtils;
import com.zy.common.utils.HttpHandler;
import com.zy.common.utils.News;
import com.zy.core.CrnThread;
import com.zy.core.DevpThread;
import com.zy.core.cache.MessageQueue;
@@ -337,10 +338,10 @@
                if (inSta.getStaNo() == 201 && devpThread.ioModeOf2F2 != IoModeType.PAKOUT_MODE) {
                    continue;
                }
                if (inSta.getStaNo() == 304 && devpThread.ioModeOf3F1 != IoModeType.PAKOUT_MODE) {
                if (inSta.getStaNo() == 301 && devpThread.ioModeOf3F1 != IoModeType.PAKOUT_MODE) {
                    continue;
                }
                if (inSta.getStaNo() == 301 && devpThread.ioModeOf3F2 != IoModeType.PAKOUT_MODE) {
                if (inSta.getStaNo() == 304 && devpThread.ioModeOf3F2 != IoModeType.PAKOUT_MODE) {
                    continue;
                }
@@ -1452,10 +1453,7 @@
                }
                // 获取工作档数据
                WrkMast wrkMast = wrkMastMapper.selectById(staProtocol.getWorkNo());
//                if (null == wrkMast || wrkMast.getWrkSts() < 14 || wrkMast.getIoType() < 100) { continue; }
                if (null == wrkMast) {
                    continue;
                }
                if (null == wrkMast || wrkMast.getWrkSts() < 14 || wrkMast.getIoType() < 100) { continue; }
                wrkMasts.add(wrkMast);
                // 组装命令
                LedCommand ledCommand = new LedCommand();
@@ -1463,12 +1461,6 @@
                ledCommand.setIoType(wrkMast.getIoType());
                // 出库模式
                switch (wrkMast.getIoType()) {
                    case 1:
                        ledCommand.setTitle("全板入库");
                        break;
                    case 10:
                        ledCommand.setTitle("空板入库");
                        break;
                    case 101:
                        ledCommand.setTitle("全板出库");
                        break;
@@ -1486,16 +1478,24 @@
                        ledCommand.setEmptyMk(true);
                        break;
                    default:
                        log.error("任务入出库类型错误!!![工作号:{}] [入出库类型:{}]", wrkMast.getWrkNo(), wrkMast.getIoType());
                        News.error("任务入出库类型错误!!![工作号:{}] [入出库类型:{}]", wrkMast.getWrkNo(), wrkMast.getIoType());
                        break;
                }
                ledCommand.setSourceLocNo(wrkMast.getSourceLocNo());
                ledCommand.setLocNo(wrkMast.getLocNo());
                ledCommand.setStaNo(wrkMast.getStaNo());
//                ledCommand.setSourceStaNo(wrkMast.getSourceStaNo());
                if (wrkMast.getIoType() != 110 && wrkMast.getIoType() != 10) {
                if (wrkMast.getIoType() != 110) {
                    List<WrkDetl> wrkDetls = wrkDetlService.findByWorkNo(wrkMast.getWrkNo());
                    wrkDetls.forEach(wrkDetl -> ledCommand.getMatDtos().add(new MatDto(wrkDetl.getMatnr(), wrkDetl.getMaktx(), wrkDetl.getAnfme())));
                    wrkDetls.forEach(wrkDetl -> {
                        if (wrkMast.getIoType() == 101) {
                            ledCommand.getMatDtos().add(new MatDto(wrkDetl.getMatnr(), wrkDetl.getMaktx(), wrkDetl.getAnfme()));
                        }
                        if (wrkMast.getIoType() == 103 && (null == wrkDetl.getInspect() || 0 == wrkDetl.getInspect())) {
                            ledCommand.getMatDtos().add(new MatDto(wrkDetl.getMatnr(), wrkDetl.getMaktx(),  wrkDetl.getAnfme()));
                        }
                        if (wrkMast.getIoType() == 107) {
                            ledCommand.getMatDtos().add(new MatDto(wrkDetl.getMatnr(), wrkDetl.getMaktx(), wrkDetl.getAnfme()));
                        }
                    });
                }
                commands.add(ledCommand);
            }
@@ -1508,22 +1508,10 @@
            }
            // 命令下发 -------------------------------------------------------------------------------
            if (!commands.isEmpty()) {
                if (led.getId() == 7) {
                    if (!MessageQueue.offer(SlaveType.Led, led.getId(), new Task(3, commands))) {
                        log.error("{}号LED命令下发失败!!![ip:{}] [port:{}]", led.getId(), led.getIp(), led.getPort());
                        continue;
                    } else {
                        ledThread.setLedMk(false);
                    }
                } else {
                    if (!MessageQueue.offer(SlaveType.Led, led.getId(), new Task(1, commands))) {
                        log.error("{}号LED命令下发失败!!![ip:{}] [port:{}]", led.getId(), led.getIp(), led.getPort());
                        continue;
                    } else {
                        ledThread.setLedMk(false);
                    }
                if (!MessageQueue.offer(SlaveType.Led, led.getId(), new Task(1, commands))) {
                    News.error("{}号LED命令下发失败!!![ip:{}] [port:{}]", led.getId(), led.getIp(), led.getPort());
                    continue;
                }
            }
            try {
@@ -1551,33 +1539,6 @@
     * 其他  ===>> LED显示器复位,显示默认信息
     */
    public synchronized void ledReset() {
//        for (LedSlave led : slaveProperties.getLed()) {
//            // 获取输送线plc线程
//            DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, led.getDevpPlcId());
//            // 命令集合
//            boolean reset = true;
//            for (Integer staNo : led.getStaArr()) {
//                // 获取叉车站点
//                StaProtocol staProtocol = devpThread.getStation().get(staNo);
//                if (staProtocol == null) {
//                    continue;
//                } else {
//                    staProtocol = staProtocol.clone();
//                }
//                if (staProtocol.getWorkNo() != 0) {
//                    reset = false;
//                    break;
//                }
//            }
//            // 获取led线程
//            LedThread ledThread = (LedThread) SlaveConnection.get(SlaveType.Led, led.getDevpPlcId());
//            // led显示默认内容
//            if (reset) {
//                if (!MessageQueue.offer(SlaveType.Led, led.getId(), new Task(2, new ArrayList<>()))) {
//                    log.error("{}号LED命令下发失败!!![ip:{}] [port:{}]", led.getId(), led.getIp(), led.getPort());
//                }
//            }
//        }
        for (LedSlave led : slaveProperties.getLed()) {
            // 获取输送线plc线程
            DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, led.getDevpPlcId());
@@ -1586,32 +1547,18 @@
            for (Integer staNo : led.getStaArr()) {
                // 获取叉车站点
                StaProtocol staProtocol = devpThread.getStation().get(staNo);
                if (staProtocol == null) {
                    continue;
                }
                if (staProtocol.getWorkNo() != 0 && staProtocol.isLoading()) {
                if (staProtocol == null) { continue; }
                if (staProtocol.getWorkNo() != 0) {
                    reset = false;
                    break;
                }
            }
            // 获取led线程
            LedThread ledThread = (LedThread) SlaveConnection.get(SlaveType.Led, led.getId());
            LedThread ledThread = (LedThread) SlaveConnection.get(SlaveType.Led, led.getDevpPlcId());
            // led显示默认内容
            if (reset && !ledThread.isLedMk()) {
                if (led.getId() == 7) {
                    ledThread.setLedMk(true);
                    if (!MessageQueue.offer(SlaveType.Led, led.getId(), new Task(4, new ArrayList<>()))) {
                        log.error("{}号LED命令下发失败!!![ip:{}] [port:{}]", led.getId(), led.getIp(), led.getPort());
                    } else {
                    }
                } else {
                    ledThread.setLedMk(true);
                    if (!MessageQueue.offer(SlaveType.Led, led.getId(), new Task(2, new ArrayList<>()))) {
                        log.error("{}号LED命令下发失败!!![ip:{}] [port:{}]", led.getId(), led.getIp(), led.getPort());
                    } else {
                    }
            if (reset) {
                if (!MessageQueue.offer(SlaveType.Led, led.getId(), new Task(2, new ArrayList<>()))) {
                    News.error("{}号LED命令下发失败!!![ip:{}] [port:{}]", led.getId(), led.getIp(), led.getPort());
                }
            }
        }
src/main/java/com/zy/common/utils/News.java
New file
@@ -0,0 +1,183 @@
package com.zy.common.utils;
import lombok.extern.slf4j.Slf4j;
import java.lang.reflect.Array;
import java.text.SimpleDateFormat;
import java.util.*;
/**
 * news stories for zoneyung
 * Created by vincent on 2022/12/22
 */
@Slf4j
public class News {
    public static void main(String[] args) {
        News.info("info{}", 1);
        News.warn("warn{}", 2);
        News.error("error{}", 3);
        System.out.println(News.print());
    }
    interface NewsSupport<T> { boolean execute(T t); }
    private static final NewsQueue<NewsDomain> NEWS_QUEUE = new NewsQueue<>(NewsDomain.class, 1024);
    @SuppressWarnings({"unchecked"})
    static class NewsQueue<T> {
        private final transient Class<T> cls;
        private final T[] arr;
        private final int capacity;
        private int head;
        private int tail;
        { this.head = 0; this.tail = 0; }
        public NewsQueue(Class<T> cls, int capacity) {
            this.cls = cls;
            this.arr = (T[]) Array.newInstance(cls, capacity);
            this.capacity = capacity;
        }
        public synchronized boolean offer(T t) {
            if (this.tail == this.capacity) {
                this.peek();
            }
            this.reform();
            this.arr[this.tail] = t;
            this.tail ++;
            return true;
        }
        public synchronized boolean put(T t) {
            if (this.tail == this.capacity) {
                return false;
            } else {
                this.reform();
            }
            this.arr[this.tail] = t;
            this.tail ++;
            return true;
        }
        public synchronized T peek() {
            if (this.head == this.tail) {
                return null;
            }
            T t = this.arr[this.head];
            this.head ++;
            this.reform();
            return t;
        }
        private void reform() {
            for (int i = this.head; i < this.tail; i++) {
                this.arr[i-this.head] = this.arr[i];
            }
            this.tail -= this.head;
            this.head = 0;
        }
        public synchronized int size() {
            return this.tail - this.head;
        }
        public synchronized List<T> data() {
            T[] ts = (T[]) Array.newInstance(this.cls, size());
            if (this.tail - this.head >= 0) {
                System.arraycopy(this.arr, this.head, ts, 0, this.tail - this.head);
            }
            return Arrays.asList(ts);
        }
    }
    public static void info(String format, Object... arguments) {
        log.info(format, arguments);
        offer(NewsLevel.INFO, format, arguments);
    }
    public static void warn(String format, Object... arguments) {
        log.warn(format, arguments);
        offer(NewsLevel.WARN, format, arguments);
    }
    public static void error(String format, Object... arguments) {
        log.error(format, arguments);
        offer(NewsLevel.ERROR, format, arguments);
    }
    public static String printStr() {
        StringBuilder sb = new StringBuilder("[");
        List<NewsDomain> domains = NEWS_QUEUE.data();
        for (int i = 0; i < domains.size(); i++) {
            NewsDomain domain = domains.get(i);
            sb.append("{");
            sb.append("\"l\":").append(domain.level.idx).append(",");
            sb.append("\"v\":\"").append(domain.content).append("\"").append(",");
            sb.append("\"t\":\"").append(domain.date).append("\"");
            sb.append("}");
            if (i < domains.size() - 1) {
                sb.append(",");
            }
        }
        sb.append("]");
        return sb.toString();
    }
    public static List<Map<String, Object>> print() {
        List<Map<String, Object>> res = new ArrayList<>();
        for (NewsDomain datum : NEWS_QUEUE.data()) {
            Map<String, Object> map = new HashMap<>();
            map.put("l", datum.level.idx);
            map.put("v", datum.content);
            map.put("t", datum.date);
            res.add(map);
        }
        return res;
    }
    private static boolean offer(NewsLevel level, String msg, Object[] args) {
        return NEWS_QUEUE.offer(new NewsDomain(level, replace(msg, args), (new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")).format(new Date())));
    }
    private static String replace(String str, Object[] objs){
        if (null == objs || objs.length == 0 || null == str || "".equals(str.trim())) {
            return str;
        } else {
            StringBuilder sb = new StringBuilder(str);
            for (Object obj : objs) {
                int idx = sb.indexOf("{}");
                if (idx == -1) { break; }
                sb.replace(idx, idx + 2, String.valueOf(obj));
            }
            return sb.toString();
        }
    }
    static class NewsDomain {
        public NewsLevel level;
        public String content;
        public String date;
        public NewsDomain(NewsLevel level, String content, String date) {
            this.level = level;
            this.content = content;
            this.date = date;
        }
    }
    enum NewsLevel {
        INFO(1),
        WARN(2),
        ERROR(3),
        ;
        public int idx;
        NewsLevel(int idx) {
            this.idx = idx;
        }
    }
}