Merge branch 'Four-Way-Rack' of http://47.97.1.152:5880/r/zy-asrs-master into Four-Way-Rack
| | |
| | | for (const menu of children) { |
| | | if (menu.component !== null && menu.component !== undefined) { |
| | | // children |
| | | const Component = require(`@/pages${menu.path}/index.jsx`).default |
| | | const newRoute = { |
| | | name: menu.name, |
| | | path: menu.path, |
| | | element: <Component />, |
| | | let Component; |
| | | try { |
| | | Component = require(`@/pages${menu.path}/index.jsx`).default |
| | | } catch (error) { |
| | | console.error('An error has occurred: ', error); |
| | | } |
| | | parent.routes.push(newRoute); |
| | | parent.children.push(newRoute); |
| | | if (Component) { |
| | | const newRoute = { |
| | | name: menu.name, |
| | | path: menu.path, |
| | | element: <Component />, |
| | | } |
| | | parent.routes.push(newRoute); |
| | | parent.children.push(newRoute); |
| | | } |
| | | } else { |
| | | // parent |
| | | const newRoute = { |
| | |
| | | <version>5.2.5.RELEASE</version> |
| | | </dependency> |
| | | |
| | | <dependency> |
| | | <groupId>org.springframework.boot</groupId> |
| | | <artifactId>spring-boot-starter-data-redis</artifactId> |
| | | </dependency> |
| | | |
| | | </dependencies> |
| | | |
| | | <build> |
| | |
| | | |
| | | @Override |
| | | public boolean ignoreTable(String tableName) { |
| | | return Arrays.asList( |
| | | "sys_host", |
| | | "sys_user_role", |
| | | "sys_role_menu" |
| | | ).contains(tableName); |
| | | if (getTenantId() == null) { |
| | | return true; |
| | | }else { |
| | | return Arrays.asList( |
| | | "sys_host", |
| | | "sys_user_role", |
| | | "sys_role_menu" |
| | | ).contains(tableName); |
| | | } |
| | | } |
| | | |
| | | }; |
| | |
| | | } catch (Exception e) { |
| | | System.out.println(e.getMessage()); |
| | | } |
| | | return new NullValue(); |
| | | return null; |
| | | } |
| | | |
| | | } |
New file |
| | |
| | | package com.zy.asrs.wcs.core; |
| | | |
| | | import com.zy.asrs.wcs.core.service.impl.MainServiceImpl; |
| | | import lombok.Data; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import javax.annotation.PreDestroy; |
| | | |
| | | /** |
| | | * WCS主流程 |
| | | * Created by vincent on 2020/8/6 |
| | | */ |
| | | @Data |
| | | @Slf4j |
| | | @Component |
| | | public class MainProcess { |
| | | |
| | | @Autowired |
| | | private MainServiceImpl mainService; |
| | | // 所属线程 |
| | | private Thread thread; |
| | | // 频率 |
| | | private int i = 0; |
| | | |
| | | /** |
| | | * =====>> 开始工作 |
| | | */ |
| | | public void start(){ |
| | | thread = new Thread(() -> { |
| | | while (!Thread.currentThread().isInterrupted()) { |
| | | try { |
| | | |
| | | // 间隔 |
| | | Thread.sleep(300); |
| | | |
| | | // // 系统运行状态判断 |
| | | // if (!SystemProperties.WCS_RUNNING_STATUS.get()) { |
| | | // continue; |
| | | // } |
| | | // |
| | | // // 入库 ===>> 入库站到堆垛机站,根据条码扫描生成入库工作档 |
| | | // mainService.generateInboundWrk(); // 组托 |
| | | // |
| | | // // 间隔 |
| | | // Thread.sleep(500); |
| | | // |
| | | // //初始化实时地图 |
| | | // mainService.initRealtimeBasMap(); |
| | | // // 拣料、并板、盘点再入库 |
| | | //// mainService.stnToCrnStnPick(); |
| | | // // 出库 =====>> |
| | | // mainService.generateOutboundWrkMast(); |
| | | // // 解析入库工作档 |
| | | // mainService.analyzeInBoundWrk(); |
| | | // // 异常信息记录 |
| | | // mainService.recErr(); |
| | | // // 入库 ===>> 空栈板初始化入库,叉车入库站放货 |
| | | // mainService.storeEmptyPlt(); |
| | | // // 出库 ===>> 工作档信息写入led显示器 |
| | | // mainService.ledExecute(); |
| | | // // 其他 ===>> LED显示器复位,显示默认信息 |
| | | // mainService.ledReset(); |
| | | // // 穿梭车 ===>> 小车电量检测充电 |
| | | // mainService.loopShuttleCharge(); |
| | | // // 穿梭车 ===>> 小车电量满电后回待机位 |
| | | // mainService.loopShuttleToStandbyCauseCharge(); |
| | | // // 扫描已经在出库口的货物 => 呼叫agv至放货站点 |
| | | // mainService.scanOutCallAgv(); |
| | | |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | }); |
| | | thread.start(); |
| | | } |
| | | |
| | | @PreDestroy |
| | | public void shutDown(){ |
| | | if (thread != null) thread.interrupt(); |
| | | } |
| | | |
| | | } |
New file |
| | |
| | | package com.zy.asrs.wcs.core; |
| | | |
| | | 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; |
| | | } |
| | | } |
| | | |
| | | } |
New file |
| | |
| | | package com.zy.asrs.wcs.core; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.zy.asrs.wcs.core.cache.MessageQueue; |
| | | import com.zy.asrs.wcs.core.model.enums.SlaveType; |
| | | import com.zy.asrs.wcs.core.utils.RedisUtil; |
| | | import com.zy.asrs.wcs.rcs.entity.Device; |
| | | import com.zy.asrs.wcs.rcs.entity.DeviceType; |
| | | import com.zy.asrs.wcs.rcs.service.DeviceService; |
| | | import com.zy.asrs.wcs.rcs.service.DeviceTypeService; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.scheduling.annotation.Async; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import javax.annotation.PostConstruct; |
| | | import javax.annotation.PreDestroy; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * Created by vincent on 2020/8/4 |
| | | */ |
| | | @Slf4j |
| | | @Component |
| | | public class ServerBootstrap { |
| | | |
| | | @Autowired |
| | | private MainProcess mainProcess; |
| | | @Autowired |
| | | private RedisUtil redisUtil; |
| | | @Autowired |
| | | private DeviceService deviceService; |
| | | @Autowired |
| | | private DeviceTypeService deviceTypeService; |
| | | |
| | | @PostConstruct |
| | | @Async |
| | | public void init() throws InterruptedException { |
| | | News.info("核心控制层开始初始化..............................................."); |
| | | Thread.sleep(2000); |
| | | // 初始化消息队列 |
| | | initMq(); |
| | | // 初始化下位机线程 |
| | | initThread(); |
| | | // 开始主流程进程 |
| | | mainProcess.start(); |
| | | News.info("核心控制层已启动..............................................."); |
| | | } |
| | | |
| | | private void initMq(){ |
| | | // 初始化设备mq |
| | | for (Device device : deviceService.list()) { |
| | | DeviceType type = deviceTypeService.getById(device.getDeviceType()); |
| | | SlaveType slaveType = SlaveType.findInstance(type.getFlag()); |
| | | if (slaveType != null) { |
| | | MessageQueue.init(slaveType, device.getId().intValue()); |
| | | } |
| | | } |
| | | } |
| | | |
| | | private void initThread(){ |
| | | List<DeviceType> list1 = deviceTypeService.list(); |
| | | for (DeviceType type : deviceTypeService.list()) { |
| | | List<Device> list = deviceService.list(new LambdaQueryWrapper<Device>() |
| | | .eq(Device::getDeviceType, type.getId()) |
| | | .eq(Device::getStatus, 1) |
| | | ); |
| | | if (list.isEmpty()) { |
| | | continue; |
| | | } |
| | | |
| | | News.info("初始化{}线程...................................................", type.getName()); |
| | | } |
| | | |
| | | |
| | | // // 初始化输送线线程 |
| | | // News.info("初始化输送线线程..................................................."); |
| | | // for (DevpSlave devp : slaveProperties.getDevp()) { |
| | | // DevpThread devpThread = new SiemensDevpThread(devp); |
| | | // new Thread((Runnable) devpThread).start(); |
| | | // SlaveConnection.put(SlaveType.Devp, devp.getId(), devpThread); |
| | | // } |
| | | // // 初始化提升机 |
| | | // News.info("初始化提升机........................................................"); |
| | | // for (LiftSlave liftSlave : slaveProperties.getLift()) { |
| | | // SiemensLiftThread liftThread = new SiemensLiftThread(liftSlave, redisUtil); |
| | | // new Thread(liftThread).start(); |
| | | // SlaveConnection.put(SlaveType.Lift, liftSlave.getId(), liftThread); |
| | | // } |
| | | // // 初始化四向穿梭车 |
| | | // News.info("初始化四向穿梭车......................................................"); |
| | | // for (ShuttleSlave shuttleSlave : slaveProperties.getShuttle()) { |
| | | // ShuttleThread shuttleThread = new ShuttleThread(shuttleSlave,redisUtil); |
| | | // new Thread(shuttleThread).start(); |
| | | // SlaveConnection.put(SlaveType.Shuttle, shuttleSlave.getId(), shuttleThread); |
| | | // } |
| | | // // 初始化条码扫描仪线程 |
| | | // News.info("初始化条码扫描仪线程..................................................."); |
| | | // for (Slave barcode : slaveProperties.getBarcode()) { |
| | | // BarcodeThread barcodeThread = new BarcodeThread(barcode); |
| | | // new Thread(barcodeThread).start(); |
| | | // SlaveConnection.put(SlaveType.Barcode, barcode.getId(), barcodeThread); |
| | | // } |
| | | // // 初始化LED线程 |
| | | // News.info("初始化LED线程..................................................."); |
| | | // for (LedSlave led : slaveProperties.getLed()) { |
| | | // LedThread ledThread = new LedThread(led); |
| | | // new Thread(ledThread).start(); |
| | | // SlaveConnection.put(SlaveType.Led, led.getId(), ledThread); |
| | | // } |
| | | // 初始化磅秤线程 |
| | | // News.info("初始化磅秤线程..................................................."); |
| | | // for (Slave scale : slaveProperties.getScale()) { |
| | | // ScaleThread barcodeThread = new ScaleThread(scale); |
| | | // new Thread(barcodeThread).start(); |
| | | // SlaveConnection.put(SlaveType.Scale, scale.getId(), barcodeThread); |
| | | // } |
| | | } |
| | | |
| | | |
| | | @PreDestroy |
| | | public void destroy() { |
| | | } |
| | | |
| | | |
| | | } |
New file |
| | |
| | | package com.zy.asrs.wcs.core.cache; |
| | | |
| | | import com.zy.asrs.wcs.core.model.Task; |
| | | import com.zy.asrs.wcs.core.model.enums.SlaveType; |
| | | |
| | | import java.util.Map; |
| | | import java.util.concurrent.ConcurrentHashMap; |
| | | import java.util.concurrent.ConcurrentLinkedQueue; |
| | | import java.util.concurrent.LinkedBlockingQueue; |
| | | |
| | | /** |
| | | * 消息队列 |
| | | * Created by vincent on 2020/8/5 |
| | | */ |
| | | public class MessageQueue { |
| | | |
| | | // 输送线mq交换机 |
| | | private static final Map<Integer, ConcurrentLinkedQueue<Task>> DEVP_EXCHANGE = new ConcurrentHashMap<>(); |
| | | // 条码扫描仪mq交换机 |
| | | private static final Map<Integer, ConcurrentLinkedQueue<Task>> BARCODE_EXCHANGE = new ConcurrentHashMap<>(); |
| | | // Led灯 mq交换机 |
| | | private static final Map<Integer, LinkedBlockingQueue<Task>> LED_EXCHANGE = new ConcurrentHashMap<>(); |
| | | // 磅称mq交换机 |
| | | private static final Map<Integer, ConcurrentLinkedQueue<Task>> SCALE_EXCHANGE = new ConcurrentHashMap<>(); |
| | | // 台车mq交换机 |
| | | private static final Map<Integer, ConcurrentLinkedQueue<Task>> CAR_EXCHANGE = new ConcurrentHashMap<>(); |
| | | //四向穿梭车mq交换机 |
| | | private static final Map<Integer, ConcurrentLinkedQueue<Task>> SHUTTLE_EXCHANGE = new ConcurrentHashMap<>(); |
| | | //提升机mq交换机 |
| | | private static final Map<Integer, ConcurrentLinkedQueue<Task>> LIFT_EXCHANGE = new ConcurrentHashMap<>(); |
| | | |
| | | /** |
| | | * mq 交换机初始化 |
| | | */ |
| | | public static void init(SlaveType type, Integer id) { |
| | | switch (type) { |
| | | case Devp: |
| | | DEVP_EXCHANGE.put(id, new ConcurrentLinkedQueue<>()); |
| | | break; |
| | | case Barcode: |
| | | BARCODE_EXCHANGE.put(id, new ConcurrentLinkedQueue<>()); |
| | | break; |
| | | case Led: |
| | | LED_EXCHANGE.put(id, new LinkedBlockingQueue<>(1)); |
| | | break; |
| | | case Scale: |
| | | SCALE_EXCHANGE.put(id, new ConcurrentLinkedQueue<>()); |
| | | break; |
| | | case Shuttle: |
| | | SHUTTLE_EXCHANGE.put(id, new ConcurrentLinkedQueue<>()); |
| | | break; |
| | | case Lift: |
| | | LIFT_EXCHANGE.put(id, new ConcurrentLinkedQueue<>()); |
| | | break; |
| | | default: |
| | | break; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 添加元素 |
| | | * 如果发现队列已满无法添加的话,会直接返回false。 |
| | | */ |
| | | public static boolean offer(SlaveType type, Integer id, Task task) { |
| | | switch (type) { |
| | | case Devp: |
| | | return DEVP_EXCHANGE.get(id).offer(task); |
| | | case Barcode: |
| | | return BARCODE_EXCHANGE.get(id).offer(task); |
| | | case Led: |
| | | return LED_EXCHANGE.get(id).offer(task); |
| | | case Scale: |
| | | return SCALE_EXCHANGE.get(id).offer(task); |
| | | case Shuttle: |
| | | return SHUTTLE_EXCHANGE.get(id).offer(task); |
| | | case Lift: |
| | | return LIFT_EXCHANGE.get(id).offer(task); |
| | | default: |
| | | return false; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 移除元素 |
| | | * 若队列为空,返回null。 |
| | | */ |
| | | public static Task poll(SlaveType type, Integer id) { |
| | | switch (type) { |
| | | case Devp: |
| | | return DEVP_EXCHANGE.get(id).poll(); |
| | | case Barcode: |
| | | return BARCODE_EXCHANGE.get(id).poll(); |
| | | case Led: |
| | | return LED_EXCHANGE.get(id).poll(); |
| | | case Scale: |
| | | return SCALE_EXCHANGE.get(id).poll(); |
| | | case Shuttle: |
| | | return SHUTTLE_EXCHANGE.get(id).poll(); |
| | | case Lift: |
| | | return LIFT_EXCHANGE.get(id).poll(); |
| | | default: |
| | | return null; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 取出元素,并不删除. |
| | | */ |
| | | public static Task peek(SlaveType type, Integer id) { |
| | | switch (type) { |
| | | case Devp: |
| | | return DEVP_EXCHANGE.get(id).peek(); |
| | | case Barcode: |
| | | return BARCODE_EXCHANGE.get(id).peek(); |
| | | case Led: |
| | | return LED_EXCHANGE.get(id).peek(); |
| | | case Scale: |
| | | return SCALE_EXCHANGE.get(id).peek(); |
| | | case Shuttle: |
| | | return SHUTTLE_EXCHANGE.get(id).peek(); |
| | | case Lift: |
| | | return LIFT_EXCHANGE.get(id).peek(); |
| | | default: |
| | | return null; |
| | | } |
| | | } |
| | | |
| | | public static void clear(SlaveType type, Integer id){ |
| | | switch (type) { |
| | | case Devp: |
| | | DEVP_EXCHANGE.get(id).clear(); |
| | | break; |
| | | case Barcode: |
| | | BARCODE_EXCHANGE.get(id).clear(); |
| | | break; |
| | | case Led: |
| | | LED_EXCHANGE.get(id).clear(); |
| | | break; |
| | | case Scale: |
| | | SCALE_EXCHANGE.get(id).clear(); |
| | | break; |
| | | case Shuttle: |
| | | SHUTTLE_EXCHANGE.get(id).clear(); |
| | | break; |
| | | case Lift: |
| | | LIFT_EXCHANGE.get(id).clear(); |
| | | break; |
| | | default: |
| | | break; |
| | | } |
| | | } |
| | | |
| | | } |
New file |
| | |
| | | package com.zy.asrs.wcs.core.model; |
| | | |
| | | import lombok.Data; |
| | | |
| | | /** |
| | | * Created by vincent on 2020/8/5 |
| | | */ |
| | | @Data |
| | | public class Task { |
| | | |
| | | private Integer step; |
| | | |
| | | private Object data; |
| | | |
| | | public Task() { |
| | | } |
| | | |
| | | public Task(Integer step, Object data) { |
| | | this.step = step; |
| | | this.data = data; |
| | | } |
| | | } |
New file |
| | |
| | | package com.zy.asrs.wcs.core.service.impl; |
| | | |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | /** |
| | | * 立体仓库WCS系统主流程业务 |
| | | * Created by vincent on 2020/8/6 |
| | | */ |
| | | @Slf4j |
| | | @Service("mainService") |
| | | @Transactional |
| | | public class MainServiceImpl { |
| | | |
| | | |
| | | |
| | | } |
New file |
| | |
| | | package com.zy.asrs.wcs.core.utils; |
| | | |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.data.redis.core.RedisTemplate; |
| | | import org.springframework.stereotype.Component; |
| | | import org.springframework.util.CollectionUtils; |
| | | |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Set; |
| | | import java.util.concurrent.TimeUnit; |
| | | |
| | | /** |
| | | * redisTemplate封装 |
| | | * |
| | | */ |
| | | @Component |
| | | public class RedisUtil { |
| | | |
| | | // @Autowired |
| | | // private RedisTemplate<String, Object> redisTemplate; |
| | | |
| | | @Autowired |
| | | private RedisTemplate redisTemplate; |
| | | |
| | | public RedisTemplate getRedisTemplate() { |
| | | return redisTemplate; |
| | | } |
| | | |
| | | public RedisUtil(RedisTemplate redisTemplate) { |
| | | this.redisTemplate = redisTemplate; |
| | | } |
| | | |
| | | /** |
| | | * 指定缓存失效时间 |
| | | * |
| | | * @param key 键 |
| | | * @param time 时间(秒) |
| | | * @return |
| | | */ |
| | | public boolean expire(String key, long time) { |
| | | try { |
| | | if (time > 0) { |
| | | redisTemplate.expire(key, time, TimeUnit.SECONDS); |
| | | } |
| | | return true; |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | return false; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 根据key 获取过期时间 |
| | | * |
| | | * @param key 键 不能为null |
| | | * @return 时间(秒) 返回0代表为永久有效 |
| | | */ |
| | | public long getExpire(String key) { |
| | | return redisTemplate.getExpire(key, TimeUnit.SECONDS); |
| | | } |
| | | |
| | | /** |
| | | * 判断key是否存在 |
| | | * |
| | | * @param key 键 |
| | | * @return true 存在 false不存在 |
| | | */ |
| | | public boolean hasKey(String key) { |
| | | try { |
| | | return redisTemplate.hasKey(key); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | return false; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 删除缓存 |
| | | * |
| | | * @param key 可以传一个值 或多个 |
| | | */ |
| | | @SuppressWarnings("unchecked") |
| | | public void del(String... key) { |
| | | if (key != null && key.length > 0) { |
| | | if (key.length == 1) { |
| | | redisTemplate.delete(key[0]); |
| | | } else { |
| | | redisTemplate.delete(CollectionUtils.arrayToList(key)); |
| | | } |
| | | } |
| | | } |
| | | |
| | | //============================ String ============================= |
| | | |
| | | /** |
| | | * 普通缓存获取 |
| | | * |
| | | * @param key 键 |
| | | * @return 值 |
| | | */ |
| | | public Object get(String key) { |
| | | return key == null ? null : redisTemplate.opsForValue().get(key); |
| | | } |
| | | |
| | | /** |
| | | * 获取全部数据 |
| | | * @return |
| | | */ |
| | | public HashMap<Object, Object> getRedis() { |
| | | Set<String> keys = redisTemplate.keys("*"); |
| | | HashMap<Object, Object> map = new HashMap<>(); |
| | | for (String key : keys) { |
| | | Object value = redisTemplate.opsForValue().get(key); |
| | | map.put(key, value); |
| | | } |
| | | |
| | | return map;//返回全部数据集合 |
| | | } |
| | | |
| | | /** |
| | | * 普通缓存放入 |
| | | * |
| | | * @param key 键 |
| | | * @param value 值 |
| | | * @return true成功 false失败 |
| | | */ |
| | | public boolean set(String key, Object value) { |
| | | try { |
| | | redisTemplate.opsForValue().set(key, value); |
| | | return true; |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | return false; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 普通缓存放入并设置时间 |
| | | * |
| | | * @param key 键 |
| | | * @param value 值 |
| | | * @param time 时间(秒) time要大于0 如果time小于等于0 将设置无限期 |
| | | * @return true成功 false 失败 |
| | | */ |
| | | public boolean set(String key, Object value, long time) { |
| | | try { |
| | | if (time > 0) { |
| | | redisTemplate.opsForValue().set(key, value, time, TimeUnit.SECONDS); |
| | | } else { |
| | | set(key, value); |
| | | } |
| | | return true; |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | return false; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 递增 |
| | | * |
| | | * @param key 键 |
| | | * @param delta 要增加几(大于0) |
| | | * @return |
| | | */ |
| | | public long incr(String key, long delta) { |
| | | if (delta < 0) { |
| | | throw new RuntimeException("递增因子必须大于0"); |
| | | } |
| | | return redisTemplate.opsForValue().increment(key, delta); |
| | | } |
| | | |
| | | /** |
| | | * 递减 |
| | | * |
| | | * @param key 键 |
| | | * @param delta 要减少几(小于0) |
| | | * @return |
| | | */ |
| | | public long decr(String key, long delta) { |
| | | if (delta < 0) { |
| | | throw new RuntimeException("递减因子必须大于0"); |
| | | } |
| | | return redisTemplate.opsForValue().increment(key, -delta); |
| | | } |
| | | |
| | | //================================ Hash ================================= |
| | | |
| | | /** |
| | | * HashGet |
| | | * |
| | | * @param key 键 不能为null |
| | | * @param item 项 不能为null |
| | | * @return 值 |
| | | */ |
| | | public Object hget(String key, String item) { |
| | | return redisTemplate.opsForHash().get(key, item); |
| | | } |
| | | |
| | | /** |
| | | * 获取hashKey对应的所有键值 |
| | | * |
| | | * @param key 键 |
| | | * @return 对应的多个键值 |
| | | */ |
| | | public Map<Object, Object> hmget(String key) { |
| | | return redisTemplate.opsForHash().entries(key); |
| | | } |
| | | |
| | | /** |
| | | * HashSet |
| | | * |
| | | * @param key 键 |
| | | * @param map 对应多个键值 |
| | | * @return true 成功 false 失败 |
| | | */ |
| | | public boolean hmset(String key, Map<String, Object> map) { |
| | | try { |
| | | redisTemplate.opsForHash().putAll(key, map); |
| | | return true; |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | return false; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * HashSet 并设置时间 |
| | | * |
| | | * @param key 键 |
| | | * @param map 对应多个键值 |
| | | * @param time 时间(秒) |
| | | * @return true成功 false失败 |
| | | */ |
| | | public boolean hmset(String key, Map<String, Object> map, long time) { |
| | | try { |
| | | redisTemplate.opsForHash().putAll(key, map); |
| | | if (time > 0) { |
| | | expire(key, time); |
| | | } |
| | | return true; |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | return false; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 向一张hash表中放入数据,如果不存在将创建 |
| | | * |
| | | * @param key 键 |
| | | * @param item 项 |
| | | * @param value 值 |
| | | * @return true 成功 false失败 |
| | | */ |
| | | public boolean hset(String key, String item, Object value) { |
| | | try { |
| | | redisTemplate.opsForHash().put(key, item, value); |
| | | return true; |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | return false; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 向一张hash表中放入数据,如果不存在将创建 |
| | | * |
| | | * @param key 键 |
| | | * @param item 项 |
| | | * @param value 值 |
| | | * @param time 时间(秒) 注意:如果已存在的hash表有时间,这里将会替换原有的时间 |
| | | * @return true 成功 false失败 |
| | | */ |
| | | public boolean hset(String key, String item, Object value, long time) { |
| | | try { |
| | | redisTemplate.opsForHash().put(key, item, value); |
| | | if (time > 0) { |
| | | expire(key, time); |
| | | } |
| | | return true; |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | return false; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 删除hash表中的值 |
| | | * |
| | | * @param key 键 不能为null |
| | | * @param item 项 可以使多个 不能为null |
| | | */ |
| | | public void hdel(String key, Object... item) { |
| | | redisTemplate.opsForHash().delete(key, item); |
| | | } |
| | | |
| | | /** |
| | | * 判断hash表中是否有该项的值 |
| | | * |
| | | * @param key 键 不能为null |
| | | * @param item 项 不能为null |
| | | * @return true 存在 false不存在 |
| | | */ |
| | | public boolean hHasKey(String key, String item) { |
| | | return redisTemplate.opsForHash().hasKey(key, item); |
| | | } |
| | | |
| | | /** |
| | | * hash递增 如果不存在,就会创建一个 并把新增后的值返回 |
| | | * |
| | | * @param key 键 |
| | | * @param item 项 |
| | | * @param by 要增加几(大于0) |
| | | * @return |
| | | */ |
| | | public double hincr(String key, String item, double by) { |
| | | return redisTemplate.opsForHash().increment(key, item, by); |
| | | } |
| | | |
| | | /** |
| | | * hash递减 |
| | | * |
| | | * @param key 键 |
| | | * @param item 项 |
| | | * @param by 要减少记(小于0) |
| | | * @return |
| | | */ |
| | | public double hdecr(String key, String item, double by) { |
| | | return redisTemplate.opsForHash().increment(key, item, -by); |
| | | } |
| | | |
| | | //============================ set ============================= |
| | | |
| | | /** |
| | | * 根据key获取Set中的所有值 |
| | | * |
| | | * @param key 键 |
| | | * @return |
| | | */ |
| | | public Set<Object> sGet(String key) { |
| | | try { |
| | | return redisTemplate.opsForSet().members(key); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | return null; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 根据value从一个set中查询,是否存在 |
| | | * |
| | | * @param key 键 |
| | | * @param value 值 |
| | | * @return true 存在 false不存在 |
| | | */ |
| | | public boolean sHasKey(String key, Object value) { |
| | | try { |
| | | return redisTemplate.opsForSet().isMember(key, value); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | return false; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 将数据放入set缓存 |
| | | * |
| | | * @param key 键 |
| | | * @param values 值 可以是多个 |
| | | * @return 成功个数 |
| | | */ |
| | | public long sSet(String key, Object... values) { |
| | | try { |
| | | return redisTemplate.opsForSet().add(key, values); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | return 0; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 将set数据放入缓存 |
| | | * |
| | | * @param key 键 |
| | | * @param time 时间(秒) |
| | | * @param values 值 可以是多个 |
| | | * @return 成功个数 |
| | | */ |
| | | public long sSetAndTime(String key, long time, Object... values) { |
| | | try { |
| | | Long count = redisTemplate.opsForSet().add(key, values); |
| | | if (time > 0) { |
| | | expire(key, time); |
| | | } |
| | | return count; |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | return 0; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 获取set缓存的长度 |
| | | * |
| | | * @param key 键 |
| | | * @return |
| | | */ |
| | | public long sGetSetSize(String key) { |
| | | try { |
| | | return redisTemplate.opsForSet().size(key); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | return 0; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 移除值为value的 |
| | | * |
| | | * @param key 键 |
| | | * @param values 值 可以是多个 |
| | | * @return 移除的个数 |
| | | */ |
| | | public long setRemove(String key, Object... values) { |
| | | try { |
| | | Long count = redisTemplate.opsForSet().remove(key, values); |
| | | return count; |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | return 0; |
| | | } |
| | | } |
| | | //===============================list================================= |
| | | |
| | | /** |
| | | * 获取list缓存的内容 |
| | | * |
| | | * @param key 键 |
| | | * @param start 开始 |
| | | * @param end 结束 0 到 -1代表所有值 |
| | | * @return |
| | | */ |
| | | public List<Object> lGet(String key, long start, long end) { |
| | | try { |
| | | return redisTemplate.opsForList().range(key, start, end); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | return null; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 获取list缓存的长度 |
| | | * |
| | | * @param key 键 |
| | | * @return |
| | | */ |
| | | public long lGetListSize(String key) { |
| | | try { |
| | | return redisTemplate.opsForList().size(key); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | return 0; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 通过索引 获取list中的值 |
| | | * |
| | | * @param key 键 |
| | | * @param index 索引 index>=0时, 0 表头,1 第二个元素,依次类推;index<0时,-1,表尾,-2倒数第二个元素,依次类推 |
| | | * @return |
| | | */ |
| | | public Object lGetIndex(String key, long index) { |
| | | try { |
| | | return redisTemplate.opsForList().index(key, index); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | return null; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 将list放入缓存 |
| | | * |
| | | * @param key 键 |
| | | * @param value 值 |
| | | * @return |
| | | */ |
| | | public boolean lSet(String key, Object value) { |
| | | try { |
| | | redisTemplate.opsForList().rightPush(key, value); |
| | | return true; |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | return false; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 将list放入缓存 |
| | | * |
| | | * @param key 键 |
| | | * @param value 值 |
| | | * @param time 时间(秒) |
| | | * @return |
| | | */ |
| | | public boolean lSet(String key, Object value, long time) { |
| | | try { |
| | | redisTemplate.opsForList().rightPush(key, value); |
| | | if (time > 0) { |
| | | expire(key, time); |
| | | } |
| | | return true; |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | return false; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 将list放入缓存 |
| | | * |
| | | * @param key 键 |
| | | * @param value 值 |
| | | * @return |
| | | */ |
| | | public boolean lSet(String key, List<Object> value) { |
| | | try { |
| | | redisTemplate.opsForList().rightPushAll(key, value); |
| | | return true; |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | return false; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 将list放入缓存 |
| | | * |
| | | * @param key 键 |
| | | * @param value 值 |
| | | * @param time 时间(秒) |
| | | * @return |
| | | */ |
| | | public boolean lSet(String key, List<Object> value, long time) { |
| | | try { |
| | | redisTemplate.opsForList().rightPushAll(key, value); |
| | | if (time > 0) { |
| | | expire(key, time); |
| | | } |
| | | return true; |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | return false; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 根据索引修改list中的某条数据 |
| | | * |
| | | * @param key 键 |
| | | * @param index 索引 |
| | | * @param value 值 |
| | | * @return |
| | | */ |
| | | public boolean lUpdateIndex(String key, long index, Object value) { |
| | | try { |
| | | redisTemplate.opsForList().set(key, index, value); |
| | | return true; |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | return false; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 移除N个值为value |
| | | * |
| | | * @param key 键 |
| | | * @param count 移除多少个 |
| | | * @param value 值 |
| | | * @return 移除的个数 |
| | | */ |
| | | public long lRemove(String key, long count, Object value) { |
| | | try { |
| | | Long remove = redisTemplate.opsForList().remove(key, count, value); |
| | | return remove; |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | return 0; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 模糊查询获取key值 |
| | | * |
| | | * @param pattern |
| | | * @return |
| | | */ |
| | | public Set keys(String pattern) { |
| | | return redisTemplate.keys(pattern); |
| | | } |
| | | |
| | | /** |
| | | * 使用Redis的消息队列 |
| | | * |
| | | * @param channel |
| | | * @param message 消息内容 |
| | | */ |
| | | public void convertAndSend(String channel, Object message) { |
| | | redisTemplate.convertAndSend(channel, message); |
| | | } |
| | | |
| | | |
| | | } |
| | | |
| | |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.zy.asrs.framework.common.Cools; |
| | | import com.zy.asrs.framework.common.R; |
| | | import com.zy.asrs.framework.common.SnowflakeIdWorker; |
| | | import com.zy.asrs.wcs.common.annotation.OperationLog; |
| | | import com.zy.asrs.wcs.common.domain.BaseParam; |
| | | import com.zy.asrs.wcs.common.domain.KeyValVo; |
| | |
| | | |
| | | @Autowired |
| | | private DeviceService deviceService; |
| | | @Autowired |
| | | private SnowflakeIdWorker snowflakeIdWorker; |
| | | |
| | | @PreAuthorize("hasAuthority('rcs:device:list')") |
| | | @PostMapping("/device/page") |
| | |
| | | if (!deviceService.save(device)) { |
| | | return R.error("添加失败"); |
| | | } |
| | | device.setUuid(String.valueOf(snowflakeIdWorker.nextId())); |
| | | return R.ok("添加成功"); |
| | | } |
| | | |
| | |
| | | DeviceTypeService service = SpringUtils.getBean(DeviceTypeService.class); |
| | | DeviceType deviceType = service.getById(this.deviceType); |
| | | if (!Cools.isEmpty(deviceType)){ |
| | | return String.valueOf(deviceType.getFlag()); |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | public String getDeviceTypeName$(){ |
| | | DeviceTypeService service = SpringUtils.getBean(DeviceTypeService.class); |
| | | DeviceType deviceType = service.getById(this.deviceType); |
| | | if (!Cools.isEmpty(deviceType)){ |
| | | return String.valueOf(deviceType.getName()); |
| | | } |
| | | return null; |