107个文件已删除
7个文件已添加
14个文件已修改
| | |
| | | <relativePath/> <!-- lookup parent from repository --> |
| | | </parent> |
| | | <groupId>com.zy</groupId> |
| | | <artifactId>rcs</artifactId> |
| | | <artifactId>gateway</artifactId> |
| | | <version>1.0.0</version> |
| | | <packaging>war</packaging> |
| | | |
| | | <properties> |
| | | <java.version>1.8</java.version> |
| | | <cool.version>3.4.0</cool.version> |
| | | <mysql-driver.version>5.1.47</mysql-driver.version> |
| | | <mybatis-plus.version>2.3.2</mybatis-plus.version> |
| | | <fastjson.version>1.2.58</fastjson.version> |
| | | <springfox.version>2.7.0</springfox.version> |
| | | </properties> |
| | | |
| | | <dependencies> |
| | |
| | | <artifactId>spring-boot-starter-data-redis</artifactId> |
| | | </dependency> |
| | | <dependency> |
| | | <groupId>cn.cool</groupId> |
| | | <artifactId>framework</artifactId> |
| | | <version>${cool.version}</version> |
| | | </dependency> |
| | | <dependency> |
| | | <groupId>mysql</groupId> |
| | | <artifactId>mysql-connector-java</artifactId> |
| | | <version>5.1.46</version> |
| | | </dependency> |
| | | <dependency> |
| | | <groupId>com.microsoft.sqlserver</groupId> |
| | | <artifactId>mssql-jdbc</artifactId> |
| | | <version>8.2.2.jre8</version> |
| | | </dependency> |
| | | <dependency> |
| | | <groupId>com.baomidou</groupId> |
| | | <artifactId>mybatis-plus-boot-starter</artifactId> |
| | | <version>${mybatis-plus.version}</version> |
| | | </dependency> |
| | | <dependency> |
| | | <groupId>com.alibaba</groupId> |
| | | <artifactId>fastjson</artifactId> |
| | | <version>${fastjson.version}</version> |
| | | </dependency> |
| | | <dependency> |
| | | <groupId>io.springfox</groupId> |
| | | <artifactId>springfox-swagger2</artifactId> |
| | | <version>${springfox.version}</version> |
| | | </dependency> |
| | | <dependency> |
| | | <groupId>io.springfox</groupId> |
| | | <artifactId>springfox-swagger-ui</artifactId> |
| | | <version>${springfox.version}</version> |
| | | </dependency> |
| | | <dependency> |
| | | <groupId>com.github.xiaoymin</groupId> |
| | | <artifactId>swagger-bootstrap-ui</artifactId> |
| | | <version>1.8.9</version> |
| | | </dependency> |
| | | <dependency> |
| | | <groupId>com.google.zxing</groupId> |
| | |
| | | </dependency> |
| | | <dependency> |
| | | <groupId>org.springframework.boot</groupId> |
| | | <artifactId>spring-boot-starter-websocket</artifactId> |
| | | </dependency> |
| | | <dependency> |
| | | <groupId>org.springframework.boot</groupId> |
| | | <artifactId>spring-boot-starter-aop</artifactId> |
| | | </dependency> |
| | | </dependencies> |
| | | |
| | | <build> |
| | | <finalName>rcs</finalName> |
| | | <plugins> |
| | | <plugin> |
| | | <groupId>org.springframework.boot</groupId> |
| | | <artifactId>spring-boot-maven-plugin</artifactId> |
| | | </plugin> |
| | | <plugin> |
| | | <groupId>org.apache.maven.plugins</groupId> |
| | | <artifactId>maven-war-plugin</artifactId> |
| | | <configuration> |
| | | <webResources> |
| | | <resource> |
| | | <directory>src/main/resources/lib</directory> |
| | | <targetPath>WEB-INF/lib/</targetPath> |
| | | <includes> |
| | | <include>**/*.jar</include> |
| | | </includes> |
| | | </resource> |
| | | </webResources> |
| | | </configuration> |
| | | </plugin> |
| | | </plugins> |
| | | <finalName>gateway</finalName> |
| | | </build> |
| | | |
| | | </project> |
| | |
| | | package com.zy; |
| | | |
| | | import com.zy.common.SpringUtils; |
| | | import com.zy.common.utils.RandomValidateCodeUtil; |
| | | import org.springframework.boot.SpringApplication; |
| | | import org.springframework.boot.autoconfigure.SpringBootApplication; |
| | | import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; |
| | | import org.springframework.context.ConfigurableApplicationContext; |
| | | import org.springframework.scheduling.annotation.EnableAsync; |
| | | import org.springframework.scheduling.annotation.EnableScheduling; |
| | | |
| | |
| | | |
| | | public static void main(String[] args) { |
| | | RandomValidateCodeUtil.init(); |
| | | SpringApplication.run(Boot.class, args); |
| | | // new Thread(()-> { |
| | | // ServerBootstrap serverBootstrap = SpringUtils.getBean(ServerBootstrap.class); |
| | | // serverBootstrap.init(); |
| | | // }).start(); |
| | | |
| | | ConfigurableApplicationContext applicationContext = SpringApplication.run(Boot.class, args); |
| | | SpringUtils.init(applicationContext); |
| | | } |
| | | |
| | | // @Override |
| | | // protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) { |
| | | // return builder.sources(Boot.class); |
| | | // } |
| | | |
| | | } |
| New file |
| | |
| | | package com.zy.common; |
| | | |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Set; |
| | | |
| | | public class Cools { |
| | | private static char[] hexDigits = new char[]{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'}; |
| | | |
| | | public static boolean isEmpty(Object... objects) { |
| | | for(Object obj : objects) { |
| | | if (isEmpty(obj)) { |
| | | return true; |
| | | } |
| | | } |
| | | |
| | | return false; |
| | | } |
| | | |
| | | public static boolean isEmpty(Object o) { |
| | | if (o == null) { |
| | | return true; |
| | | } else { |
| | | if (o instanceof String) { |
| | | if (o.toString().trim().equals("")) { |
| | | return true; |
| | | } |
| | | } else if (o instanceof List) { |
| | | if (((List)o).size() == 0) { |
| | | return true; |
| | | } |
| | | } else if (o instanceof Map) { |
| | | if (((Map)o).size() == 0) { |
| | | return true; |
| | | } |
| | | } else if (o instanceof Set) { |
| | | if (((Set)o).size() == 0) { |
| | | return true; |
| | | } |
| | | } else if (o instanceof Object[]) { |
| | | if (((Object[])((Object[])o)).length == 0) { |
| | | return true; |
| | | } |
| | | } else if (o instanceof int[]) { |
| | | if (((int[])((int[])o)).length == 0) { |
| | | return true; |
| | | } |
| | | } else if (o instanceof long[] && ((long[])((long[])o)).length == 0) { |
| | | return true; |
| | | } |
| | | |
| | | return false; |
| | | } |
| | | } |
| | | } |
| New file |
| | |
| | | package com.zy.common; |
| | | |
| | | import java.util.HashMap; |
| | | |
| | | public class R extends HashMap<String, Object> { |
| | | private static final long serialVersionUID = 1L; |
| | | private static final String CODE = "code"; |
| | | private static final String MSG = "msg"; |
| | | private static final String DATA = "data"; |
| | | |
| | | public R(Integer code, String msg) { |
| | | super.put("code", code); |
| | | super.put("msg", msg); |
| | | } |
| | | |
| | | public static R ok() { |
| | | return parse("200-操作成功"); |
| | | } |
| | | |
| | | public static R ok(String msg) { |
| | | R r = ok(); |
| | | r.put("msg", msg); |
| | | return r; |
| | | } |
| | | |
| | | public static R ok(Object obj) { |
| | | return parse("200-操作成功").add(obj); |
| | | } |
| | | |
| | | public static R error() { |
| | | return parse("500-服务器错误"); |
| | | } |
| | | |
| | | public static R error(String msg) { |
| | | R r = error(); |
| | | r.put("msg", msg); |
| | | return r; |
| | | } |
| | | |
| | | public R add(Object obj) { |
| | | this.put("data", obj); |
| | | return this; |
| | | } |
| | | |
| | | public static R parse(String message) { |
| | | if (Cools.isEmpty(message)) { |
| | | return parse("500-服务器错误"); |
| | | } else { |
| | | String[] msg = message.split("-"); |
| | | return msg.length == 2 ? new R(Integer.parseInt(msg[0]), msg[1]) : parse("500-".concat(message)); |
| | | } |
| | | } |
| | | } |
| New file |
| | |
| | | package com.zy.common; |
| | | |
| | | import com.zy.common.exception.CoolException; |
| | | import org.springframework.beans.BeansException; |
| | | import org.springframework.context.ApplicationContext; |
| | | import org.springframework.context.ApplicationContextAware; |
| | | |
| | | public class SpringUtils implements ApplicationContextAware { |
| | | private static ApplicationContext application; |
| | | |
| | | public static void init(ApplicationContext context) { |
| | | application = context; |
| | | } |
| | | |
| | | public void setApplicationContext(ApplicationContext context) throws BeansException { |
| | | application = context; |
| | | } |
| | | |
| | | private static ApplicationContext getApplicationContext() { |
| | | if (application == null) { |
| | | throw new CoolException("500-服务器错误"); |
| | | } else { |
| | | return application; |
| | | } |
| | | } |
| | | |
| | | public static <T> T getBean(Class<T> prototype) { |
| | | return (T)getApplicationContext().getBean(prototype); |
| | | } |
| | | |
| | | public static Object getBean(String name) { |
| | | return getApplicationContext().getBean(name); |
| | | } |
| | | } |
| | |
| | | package com.zy.common.config; |
| | | |
| | | import com.core.common.R; |
| | | import com.core.exception.CoolException; |
| | | import com.zy.common.R; |
| | | import com.zy.common.exception.CoolException; |
| | | import org.springframework.web.HttpRequestMethodNotSupportedException; |
| | | import org.springframework.web.bind.annotation.ExceptionHandler; |
| | | import org.springframework.web.bind.annotation.RestControllerAdvice; |
| New file |
| | |
| | | package com.zy.common.exception; |
| | | |
| | | public class CoolException extends RuntimeException { |
| | | public CoolException(Throwable e) { |
| | | super(e); |
| | | } |
| | | |
| | | public CoolException(String message) { |
| | | super(message); |
| | | } |
| | | } |
| New file |
| | |
| | | package com.zy.common.utils; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.math.RoundingMode; |
| | | |
| | | public class Arith { |
| | | public static double add(int dot, Number... numbers) { |
| | | return getAirth(dot, Arith.ArithType.ADD.getValue(), numbers); |
| | | } |
| | | |
| | | public static double subtract(int dot, Number... numbers) { |
| | | return getAirth(dot, Arith.ArithType.SUBTRACT.getValue(), numbers); |
| | | } |
| | | |
| | | public static double multiplys(int dot, Number... numbers) { |
| | | return getAirth(dot, Arith.ArithType.MULTIPLY.getValue(), numbers); |
| | | } |
| | | |
| | | public static double divides(int dot, Number... numbers) { |
| | | return getAirth(dot, Arith.ArithType.DIVIDE.getValue(), numbers); |
| | | } |
| | | |
| | | public static int percentage(Number... numbers) { |
| | | return (int) (divides(2, numbers) * (double) 100.0F); |
| | | } |
| | | |
| | | public static double remainder(Number... numbers) { |
| | | return (new BigDecimal(numbers[0].toString())).remainder(new BigDecimal(String.valueOf(numbers[1]))).doubleValue(); |
| | | } |
| | | |
| | | private static double getAirth(int dot, int arithType, Number... numbers) { |
| | | if (numbers != null && numbers.length != 0) { |
| | | BigDecimal bigDecimal = new BigDecimal(numbers[0].toString()); |
| | | |
| | | for (int i = 1; i < numbers.length; ++i) { |
| | | switch (arithType) { |
| | | case 0: |
| | | bigDecimal = bigDecimal.add(new BigDecimal(String.valueOf(numbers[i]))); |
| | | break; |
| | | case 1: |
| | | bigDecimal = bigDecimal.divide(new BigDecimal(String.valueOf(numbers[i])), dot, RoundingMode.HALF_UP); |
| | | break; |
| | | case 2: |
| | | bigDecimal = bigDecimal.subtract(new BigDecimal(String.valueOf(numbers[i]))); |
| | | break; |
| | | case 3: |
| | | bigDecimal = bigDecimal.multiply(new BigDecimal(String.valueOf(numbers[i]))); |
| | | break; |
| | | default: |
| | | return (double) 0.0F; |
| | | } |
| | | } |
| | | |
| | | return bigDecimal.setScale(dot, RoundingMode.HALF_UP).doubleValue(); |
| | | } else { |
| | | return (double) 0.0F; |
| | | } |
| | | } |
| | | |
| | | private static enum ArithType { |
| | | ADD("add", 0), |
| | | DIVIDE("divide", 1), |
| | | SUBTRACT("subtract", 2), |
| | | MULTIPLY("multiply", 3); |
| | | |
| | | private String key; |
| | | private int value; |
| | | |
| | | private ArithType(String key, int value) { |
| | | this.key = key; |
| | | this.value = value; |
| | | } |
| | | |
| | | public int getValue() { |
| | | return this.value; |
| | | } |
| | | } |
| | | } |
| New file |
| | |
| | | package com.zy.common.utils; |
| | | |
| | | import java.text.ParseException; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.Calendar; |
| | | import java.util.Date; |
| | | import java.util.Objects; |
| | | import java.util.concurrent.TimeUnit; |
| | | |
| | | public class DateUtils { |
| | | public static final String yyyyMMdd_C = "yyyy年MM月dd日"; |
| | | public static final String yyyyMM_F = "yyyy-MM"; |
| | | public static final String yyyyMMdd_F = "yyyy-MM-dd"; |
| | | public static final String yyyyMMddHHmmss_F = "yyyy-MM-dd HH:mm:ss"; |
| | | public static final String yyyyMMddHHmmsssss_F = "yyyy-MM-dd HH:mm:ss,SSS"; |
| | | public static final String yyyy = "yyyy"; |
| | | public static final String yyyyMM = "yyyyMM"; |
| | | public static final String yyyyMMdd = "yyyyMMdd"; |
| | | public static final String yyyyMMddHH = "yyyyMMddHH"; |
| | | public static final String yyyyMMddHHmmss = "yyyyMMddHHmmss"; |
| | | public static final String YYMMDDHHMMSS = "YYMMDDHHMMSS"; |
| | | public static final String yyyyMMddHHmmsssss = "yyyyMMddHHmmssSSS"; |
| | | |
| | | public static String convert(Date date, String pattern) { |
| | | return (new SimpleDateFormat(pattern)).format(date); |
| | | } |
| | | |
| | | public static String convert(Date date) { |
| | | return convert(date, "yyyy-MM-dd HH:mm:ss"); |
| | | } |
| | | |
| | | public static Date convert(String str, String pattern) { |
| | | if (str.length() < pattern.length()) { |
| | | throw new RuntimeException("时间解析失败 ==>> " + str); |
| | | } else { |
| | | if (str.length() > pattern.length()) { |
| | | str = str.substring(0, pattern.length()); |
| | | } |
| | | |
| | | SimpleDateFormat format = new SimpleDateFormat(pattern); |
| | | |
| | | try { |
| | | Date date = format.parse(str); |
| | | return date; |
| | | } catch (ParseException var5) { |
| | | throw new RuntimeException("时间解析失败 ==>> " + str); |
| | | } |
| | | } |
| | | } |
| | | |
| | | public static Date convert(String str) { |
| | | return convert(str, "yyyy-MM-dd HH:mm:ss"); |
| | | } |
| | | |
| | | public static int diff(Date date1, Date date2) { |
| | | return getDaysByTimestamp(Math.abs(date2.getTime() - date1.getTime())); |
| | | } |
| | | |
| | | public static long diffToMinute(Date date1, Date date2) { |
| | | return Math.abs(date2.getTime() - date1.getTime()) / 1000L / 60L; |
| | | } |
| | | |
| | | public static long diffToSeconds(Date date1, Date date2) { |
| | | return Math.abs(date2.getTime() - date1.getTime()) / 1000L; |
| | | } |
| | | |
| | | private static int getDaysByTimestamp(long timestamp) { |
| | | double daysPoint = Arith.divides(2, new Number[]{timestamp, 86400000}); |
| | | int daysPoint1 = (int)daysPoint; |
| | | double daysPoint2 = (double)daysPoint1; |
| | | return daysPoint > daysPoint2 ? daysPoint1 + 1 : daysPoint1; |
| | | } |
| | | |
| | | public static int diffToNow(Date date) { |
| | | long diff = (new Date()).getTime() - date.getTime(); |
| | | return (int)(Math.abs(diff) / 1000L); |
| | | } |
| | | |
| | | public static String createTimeStamp() { |
| | | return Long.toString(System.currentTimeMillis() / 1000L); |
| | | } |
| | | |
| | | public static Date calculate(Date date, Long val, TimeUnit timeUnit, boolean subtraction) { |
| | | return !Objects.isNull(date) && !Objects.isNull(val) && !Objects.isNull(timeUnit) ? new Date(subtraction ? date.getTime() - timeUnit.toMillis(val) : date.getTime() + timeUnit.toMillis(val)) : null; |
| | | } |
| | | |
| | | public static Date calculate(Date date, Long val, TimeUnit timeUnit) { |
| | | return calculate(date, val, timeUnit, false); |
| | | } |
| | | |
| | | public static DateEntity getDateEntity(Date date) { |
| | | Calendar cal = Calendar.getInstance(); |
| | | cal.setTime(date); |
| | | DateEntity dateEntity = new DateEntity(); |
| | | dateEntity.setYear(cal.get(1)); |
| | | dateEntity.setMonth(cal.get(2)); |
| | | dateEntity.setDay(cal.get(5)); |
| | | dateEntity.setHour(cal.get(11)); |
| | | dateEntity.setMinute(cal.get(12)); |
| | | dateEntity.setSecond(cal.get(13)); |
| | | return dateEntity; |
| | | } |
| | | |
| | | static class DateEntity { |
| | | int year; |
| | | int month; |
| | | int day; |
| | | int hour; |
| | | int minute; |
| | | int second; |
| | | |
| | | public int getYear() { |
| | | return this.year; |
| | | } |
| | | |
| | | public void setYear(int year) { |
| | | this.year = year; |
| | | } |
| | | |
| | | public int getMonth() { |
| | | return this.month; |
| | | } |
| | | |
| | | public void setMonth(int month) { |
| | | this.month = month + 1; |
| | | } |
| | | |
| | | public int getDay() { |
| | | return this.day; |
| | | } |
| | | |
| | | public void setDay(int day) { |
| | | this.day = day; |
| | | } |
| | | |
| | | public int getHour() { |
| | | return this.hour; |
| | | } |
| | | |
| | | public void setHour(int hour) { |
| | | this.hour = hour; |
| | | } |
| | | |
| | | public int getMinute() { |
| | | return this.minute; |
| | | } |
| | | |
| | | public void setMinute(int minute) { |
| | | this.minute = minute; |
| | | } |
| | | |
| | | public int getSecond() { |
| | | return this.second; |
| | | } |
| | | |
| | | public void setSecond(int second) { |
| | | this.second = second; |
| | | } |
| | | } |
| | | } |
| | |
| | | public class RandomValidateCodeUtil { |
| | | |
| | | public static final Map<String, String> code = new ConcurrentHashMap<>(); |
| | | |
| | | |
| | | private static String randString = "0123456789ABCDEFGHJKLMNPRSTUVWXYZ";//随机产生数字与字母组合的字符串 |
| | | private static int width = 60;// 图片宽 |
| | | private static int height = 27;// 图片高 |
| | |
| | | package com.zy.common.utils; |
| | | |
| | | import com.core.exception.CoolException; |
| | | import com.zy.common.exception.CoolException; |
| | | |
| | | import java.beans.BeanInfo; |
| | | import java.beans.Introspector; |
| | |
| | | package com.zy.core; |
| | | |
| | | import com.core.common.SpringUtils; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | |
| | | import java.lang.reflect.Array; |
| | |
| | | package com.zy.core; |
| | | |
| | | import com.core.exception.CoolException; |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.zy.common.exception.CoolException; |
| | | import com.zy.common.utils.RedisUtil; |
| | | import com.zy.core.cache.MessageQueue; |
| | | import com.zy.core.cache.SlaveConnection; |
| | | import com.zy.core.enums.SlaveType; |
| | | import com.zy.core.model.*; |
| | | import com.zy.core.properties.SlaveProperties; |
| | | import com.zy.core.thread.*; |
| | | import com.zy.core.properties.DeviceConfig; |
| | | import com.zy.core.thread.impl.LfdZyForkLiftMasterThread; |
| | | import com.zy.core.thread.impl.NyShuttleThread; |
| | | import com.zy.core.utils.DeviceMsgUtils; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.scheduling.annotation.Async; |
| | |
| | | |
| | | import javax.annotation.PostConstruct; |
| | | import javax.annotation.PreDestroy; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * Created by vincent on 2020/8/4 |
| | |
| | | public class ServerBootstrap { |
| | | |
| | | @Autowired |
| | | private SlaveProperties slaveProperties; |
| | | @Autowired |
| | | private RedisUtil redisUtil; |
| | | @Autowired |
| | | private DeviceMsgUtils deviceMsgUtils; |
| | | |
| | | |
| | | @PostConstruct |
| | |
| | | } |
| | | |
| | | private void initMq(){ |
| | | // 初始化货叉提升机mq |
| | | for (Slave forkLift : slaveProperties.getForkLift()) { |
| | | MessageQueue.init(SlaveType.ForkLift, forkLift); |
| | | // 初始化设备mq |
| | | String deviceConfig = deviceMsgUtils.getDeviceConfig(); |
| | | if(null == deviceConfig){ |
| | | News.error("初始化设备时未检测到配置文件..................."); |
| | | return; |
| | | } |
| | | // 初始化四向穿梭车mq |
| | | for (Slave shuttle : slaveProperties.getShuttle()) { |
| | | MessageQueue.init(SlaveType.Shuttle, shuttle); |
| | | |
| | | List<DeviceConfig> deviceConfigs = JSON.parseArray(deviceConfig, DeviceConfig.class); |
| | | for (DeviceConfig device : deviceConfigs) { |
| | | SlaveType type = SlaveType.findInstance(device.getDeviceType()); |
| | | if(null == type){ |
| | | continue; |
| | | } |
| | | MessageQueue.init(type, device.getDeviceNo()); |
| | | } |
| | | } |
| | | |
| | | private void initThread(){ |
| | | // 初始化货叉提升机 |
| | | for (ForkLiftSlave forkLiftSlave : slaveProperties.getForkLiftMaster()) { |
| | | News.info("初始化货叉提升机Master........................................................"); |
| | | ThreadHandler thread = null; |
| | | if (forkLiftSlave.getThreadImpl().equals("LfdZyForkLiftMasterThread")) { |
| | | thread = new LfdZyForkLiftMasterThread(forkLiftSlave, redisUtil); |
| | | } else { |
| | | throw new CoolException("未知的线程实现"); |
| | | } |
| | | |
| | | new Thread(thread).start(); |
| | | SlaveConnection.put(SlaveType.ForkLiftMaster, forkLiftSlave.getId(), thread); |
| | | String deviceConfig = deviceMsgUtils.getDeviceConfig(); |
| | | if(null == deviceConfig){ |
| | | News.error("初始化设备时未检测到配置文件..................."); |
| | | return; |
| | | } |
| | | |
| | | // 初始化四向穿梭车 |
| | | for (ShuttleSlave shuttleSlave : slaveProperties.getShuttle()) { |
| | | News.info("初始化四向穿梭车......................................................"); |
| | | ThreadHandler thread = null; |
| | | if (shuttleSlave.getThreadImpl().equals("NyShuttleThread")) { |
| | | thread = new NyShuttleThread(shuttleSlave, redisUtil); |
| | | } else { |
| | | throw new CoolException("未知的线程实现"); |
| | | List<DeviceConfig> deviceConfigs = JSON.parseArray(deviceConfig, DeviceConfig.class); |
| | | for (DeviceConfig device : deviceConfigs) { |
| | | if (device.getDeviceType().equals(String.valueOf(SlaveType.ForkLift))) { |
| | | initForkLiftThread(device); |
| | | } else if (device.getDeviceType().equals(String.valueOf(SlaveType.Shuttle))) { |
| | | initShuttleThread(device); |
| | | } |
| | | |
| | | new Thread(thread).start(); |
| | | SlaveConnection.put(SlaveType.Shuttle, shuttleSlave.getId(), thread); |
| | | } |
| | | } |
| | | |
| | |
| | | public void destroy() { |
| | | } |
| | | |
| | | private void initForkLiftThread(DeviceConfig deviceConfig) { |
| | | ThreadHandler thread = null; |
| | | if (deviceConfig.getThreadImpl().equals("LfdZyForkLiftMasterThread")) { |
| | | thread = new LfdZyForkLiftMasterThread(deviceConfig, redisUtil); |
| | | } else { |
| | | throw new CoolException("未知的线程实现"); |
| | | } |
| | | |
| | | new Thread(thread).start(); |
| | | SlaveConnection.put(SlaveType.ForkLiftMaster, deviceConfig.getDeviceNo(), thread); |
| | | } |
| | | |
| | | private void initShuttleThread(DeviceConfig deviceConfig) { |
| | | ThreadHandler thread = null; |
| | | if (deviceConfig.getThreadImpl().equals("NyShuttleThread")) { |
| | | thread = new NyShuttleThread(deviceConfig, redisUtil); |
| | | } else { |
| | | throw new CoolException("未知的线程实现"); |
| | | } |
| | | |
| | | new Thread(thread).start(); |
| | | SlaveConnection.put(SlaveType.Shuttle, deviceConfig.getDeviceNo(), thread); |
| | | } |
| | | |
| | | |
| | | } |
| | |
| | | package com.zy.core.cache; |
| | | |
| | | import com.zy.core.Slave; |
| | | import com.zy.core.enums.SlaveType; |
| | | import com.zy.core.model.Task; |
| | | |
| | |
| | | /** |
| | | * mq 交换机初始化 |
| | | */ |
| | | public static void init(SlaveType type, Slave slave) { |
| | | public static void init(SlaveType type, Integer id) { |
| | | switch (type) { |
| | | case Shuttle: |
| | | SHUTTLE_EXCHANGE.put(slave.getId(), new ConcurrentLinkedQueue<>()); |
| | | SHUTTLE_EXCHANGE.put(id, new ConcurrentLinkedQueue<>()); |
| | | break; |
| | | case ForkLift: |
| | | FORK_LIFT_EXCHANGE.put(slave.getId(), new ConcurrentLinkedQueue<>()); |
| | | FORK_LIFT_EXCHANGE.put(id, new ConcurrentLinkedQueue<>()); |
| | | break; |
| | | case ForkLiftMaster: |
| | | FORK_LIFT_MASTER_EXCHANGE.put(slave.getId(), new ConcurrentLinkedQueue<>()); |
| | | FORK_LIFT_MASTER_EXCHANGE.put(id, new ConcurrentLinkedQueue<>()); |
| | | break; |
| | | case Lift: |
| | | LIFT_EXCHANGE.put(slave.getId(), new ConcurrentLinkedQueue<>()); |
| | | LIFT_EXCHANGE.put(id, new ConcurrentLinkedQueue<>()); |
| | | break; |
| | | default: |
| | | break; |
| | |
| | | package com.zy.core.cache; |
| | | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | |
| | | import java.util.concurrent.ArrayBlockingQueue; |
| | | |
| | | /** |
| | |
| | | //设备指令消息KEY |
| | | DEVICE_SHUTTLE_COMMAND_MSG_KEY("deviceShuttleCommandMsgKey_"), |
| | | DEVICE_FORK_LIFT_COMMAND_MSG_KEY("deviceForkLiftCommandMsgKey_"), |
| | | |
| | | //设备配置文件 |
| | | DEVICE_CONFIG("deviceConfig"), |
| | | ; |
| | | |
| | | public String key; |
| New file |
| | |
| | | package com.zy.core.properties; |
| | | |
| | | import lombok.Data; |
| | | |
| | | @Data |
| | | public class DeviceConfig { |
| | | |
| | | private String ip; |
| | | |
| | | private Integer port; |
| | | |
| | | private String threadImpl; |
| | | |
| | | private String deviceType; |
| | | |
| | | private Integer deviceNo; |
| | | |
| | | } |
| | |
| | | import HslCommunication.Core.Types.OperateResultExOne; |
| | | import HslCommunication.Profinet.Siemens.SiemensPLCS; |
| | | import HslCommunication.Profinet.Siemens.SiemensS7Net; |
| | | import com.core.common.DateUtils; |
| | | import com.zy.common.utils.DateUtils; |
| | | import com.zy.common.utils.RedisUtil; |
| | | import com.zy.core.News; |
| | | import com.zy.core.ThreadHandler; |
| | | import com.zy.core.cache.OutputQueue; |
| | | import com.zy.core.model.ForkLiftSlave; |
| | | import com.zy.core.properties.DeviceConfig; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | |
| | | import java.text.MessageFormat; |
| | |
| | | @SuppressWarnings("all") |
| | | public class LfdZyForkLiftMasterThread implements ThreadHandler { |
| | | |
| | | private ForkLiftSlave slave; |
| | | private DeviceConfig deviceConfig; |
| | | private RedisUtil redisUtil; |
| | | private SiemensS7Net siemensS7Net; |
| | | private List<HashMap<String,Object>> slaveAddressList = null; |
| | | private boolean connect = false; |
| | | |
| | | public LfdZyForkLiftMasterThread(ForkLiftSlave slave, RedisUtil redisUtil) { |
| | | this.slave = slave; |
| | | public LfdZyForkLiftMasterThread(DeviceConfig deviceConfig, RedisUtil redisUtil) { |
| | | this.deviceConfig = deviceConfig; |
| | | this.redisUtil = redisUtil; |
| | | ArrayList<HashMap<String, Object>> addressList = new ArrayList<>(); |
| | | |
| | |
| | | @Override |
| | | public boolean connect() { |
| | | boolean result = false; |
| | | siemensS7Net = new SiemensS7Net(SiemensPLCS.S1200, slave.getIp()); |
| | | siemensS7Net.setRack(slave.getRack().byteValue()); |
| | | siemensS7Net.setSlot(slave.getSlot().byteValue()); |
| | | siemensS7Net = new SiemensS7Net(SiemensPLCS.S1200, deviceConfig.getIp()); |
| | | siemensS7Net.setRack(Integer.valueOf(0).byteValue()); |
| | | siemensS7Net.setSlot(Integer.valueOf(0).byteValue()); |
| | | OperateResult connect = siemensS7Net.ConnectServer(); |
| | | if(connect.IsSuccess){ |
| | | result = true; |
| | | OutputQueue.FORKLIFT.offer(MessageFormat.format( "【{0}】货叉提升机连接成功 ===>> [id:{1}] [ip:{2}] [port:{3}] [rack:{4}] [slot:{5}]", DateUtils.convert(new Date()), slave.getId(), slave.getIp(), slave.getPort(), slave.getRack(), slave.getSlot())); |
| | | News.info("货叉提升机连接成功 ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort()); |
| | | OutputQueue.FORKLIFT.offer(MessageFormat.format( "【{0}】货叉提升机连接成功 ===>> [id:{1}] [ip:{2}] [port:{3}] [rack:{4}] [slot:{5}]", DateUtils.convert(new Date()), deviceConfig.getDeviceNo(), deviceConfig.getIp(), deviceConfig.getPort(), 0, 0)); |
| | | News.info("货叉提升机连接成功 ===>> [id:{}] [ip:{}] [port:{}]", deviceConfig.getDeviceNo(), deviceConfig.getIp(), deviceConfig.getPort()); |
| | | } else { |
| | | OutputQueue.FORKLIFT.offer(MessageFormat.format( "【{0}】货叉提升机连接失败!!! ===>> [id:{1}] [ip:{2}] [port:{3}] [rack:{4}] [slot:{5}]", DateUtils.convert(new Date()), slave.getId(), slave.getIp(), slave.getPort(), slave.getRack(), slave.getSlot())); |
| | | News.error("货叉提升机连接失败!!! ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort()); |
| | | OutputQueue.FORKLIFT.offer(MessageFormat.format( "【{0}】货叉提升机连接失败!!! ===>> [id:{1}] [ip:{2}] [port:{3}] [rack:{4}] [slot:{5}]", DateUtils.convert(new Date()), deviceConfig.getDeviceNo(), deviceConfig.getIp(), deviceConfig.getPort(), 0, 0)); |
| | | News.error("货叉提升机连接失败!!! ===>> [id:{}] [ip:{}] [port:{}]", deviceConfig.getDeviceNo(), deviceConfig.getIp(), deviceConfig.getPort()); |
| | | } |
| | | // siemensS7Net.ConnectClose(); |
| | | this.connect = result; |
| | |
| | | |
| | | @Override |
| | | public void run() { |
| | | News.info("{}号货叉提升机Master线程启动", slave.getId()); |
| | | News.info("{}号货叉提升机Master线程启动", deviceConfig.getDeviceNo()); |
| | | this.connect(); |
| | | while (true) { |
| | | try { |
| | |
| | | OperateResultExOne<byte[]> result = siemensS7Net.Read(dbData.dbAddress, dbData.dbAddressLength); |
| | | return result; |
| | | } catch (Exception e) { |
| | | OutputQueue.FORKLIFT.offer(MessageFormat.format("【{0}】读取提升机状态信息失败 ===>> [id:{1}] [ip:{2}] [port:{3}]", DateUtils.convert(new Date()), slave.getId(), slave.getIp(), slave.getPort())); |
| | | OutputQueue.FORKLIFT.offer(MessageFormat.format("【{0}】读取提升机状态信息失败 ===>> [id:{1}] [ip:{2}] [port:{3}]", DateUtils.convert(new Date()), deviceConfig.getDeviceNo(), deviceConfig.getIp(), deviceConfig.getPort())); |
| | | } |
| | | return null; |
| | | } |
| | |
| | | OperateResult result = siemensS7Net.Write(dbData.dbAddress, array); |
| | | return result; |
| | | } catch (Exception e) { |
| | | OutputQueue.FORKLIFT.offer(MessageFormat.format("【{0}】写入提升机状态信息失败 ===>> [id:{1}] [ip:{2}] [port:{3}]", DateUtils.convert(new Date()), slave.getId(), slave.getIp(), slave.getPort())); |
| | | OutputQueue.FORKLIFT.offer(MessageFormat.format("【{0}】写入提升机状态信息失败 ===>> [id:{1}] [ip:{2}] [port:{3}]", DateUtils.convert(new Date()), deviceConfig.getDeviceNo(), deviceConfig.getIp(), deviceConfig.getPort())); |
| | | } |
| | | return null; |
| | | } |
| | |
| | | OperateResult result = siemensS7Net.Write(dbData.dbAddress, val); |
| | | return result; |
| | | } catch (Exception e) { |
| | | OutputQueue.FORKLIFT.offer(MessageFormat.format("【{0}】写入提升机状态信息失败 ===>> [id:{1}] [ip:{2}] [port:{3}]", DateUtils.convert(new Date()), slave.getId(), slave.getIp(), slave.getPort())); |
| | | OutputQueue.FORKLIFT.offer(MessageFormat.format("【{0}】写入提升机状态信息失败 ===>> [id:{1}] [ip:{2}] [port:{3}]", DateUtils.convert(new Date()), deviceConfig.getDeviceNo(), deviceConfig.getIp(), deviceConfig.getPort())); |
| | | } |
| | | return null; |
| | | } |
| | |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.core.common.DateUtils; |
| | | import com.core.common.SpringUtils; |
| | | import com.zy.common.SpringUtils; |
| | | import com.zy.common.utils.DateUtils; |
| | | import com.zy.common.utils.RedisUtil; |
| | | import com.zy.core.News; |
| | | import com.zy.core.model.DeviceCommandMsgModel; |
| | | import com.zy.core.model.DeviceMsgModel; |
| | | import com.zy.core.properties.DeviceConfig; |
| | | import com.zy.core.utils.DeviceMsgUtils; |
| | | import com.zy.core.cache.OutputQueue; |
| | | import com.zy.core.enums.SlaveType; |
| | | import com.zy.core.model.ShuttleSlave; |
| | | import com.zy.core.thread.ShuttleThread; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | |
| | |
| | | @SuppressWarnings("all") |
| | | public class NyShuttleThread implements ShuttleThread { |
| | | |
| | | private ShuttleSlave slave; |
| | | private DeviceConfig deviceConfig; |
| | | private RedisUtil redisUtil; |
| | | private Socket socket; |
| | | |
| | | private static final boolean DEBUG = false;//调试模式 |
| | | |
| | | public NyShuttleThread(ShuttleSlave slave, RedisUtil redisUtil) { |
| | | this.slave = slave; |
| | | public NyShuttleThread(DeviceConfig deviceConfig, RedisUtil redisUtil) { |
| | | this.deviceConfig = deviceConfig; |
| | | this.redisUtil = redisUtil; |
| | | } |
| | | |
| | | @Override |
| | | public void run() { |
| | | News.info("{}号四向车线程启动", slave.getId()); |
| | | News.info("{}号四向车线程启动", deviceConfig.getDeviceNo()); |
| | | this.connect(); |
| | | |
| | | //监听消息 |
| | |
| | | Thread executeThread = new Thread(() -> { |
| | | while (true) { |
| | | try { |
| | | DeviceMsgUtils deviceMsgUtils = SpringUtils.getBean(DeviceMsgUtils.class); |
| | | DeviceCommandMsgModel deviceCommandMsg = deviceMsgUtils.getDeviceCommandMsg(SlaveType.Shuttle, slave.getId()); |
| | | DeviceMsgUtils deviceMsgUtils = null; |
| | | try { |
| | | deviceMsgUtils = SpringUtils.getBean(DeviceMsgUtils.class); |
| | | }catch (Exception e){} |
| | | if (deviceMsgUtils == null) { |
| | | continue; |
| | | } |
| | | DeviceCommandMsgModel deviceCommandMsg = deviceMsgUtils.getDeviceCommandMsg(SlaveType.Shuttle, deviceConfig.getDeviceNo()); |
| | | if (deviceCommandMsg == null) { |
| | | continue; |
| | | } |
| | |
| | | return; |
| | | } |
| | | |
| | | DeviceMsgUtils deviceMsgUtils = SpringUtils.getBean(DeviceMsgUtils.class); |
| | | DeviceMsgUtils deviceMsgUtils = null; |
| | | try { |
| | | deviceMsgUtils = SpringUtils.getBean(DeviceMsgUtils.class); |
| | | }catch (Exception e){ |
| | | } |
| | | if(deviceMsgUtils == null) { |
| | | return; |
| | | } |
| | |
| | | JSONObject data = parseSocketResult(body); |
| | | |
| | | DeviceMsgModel deviceMsgModel = new DeviceMsgModel(); |
| | | deviceMsgModel.setDeviceId(slave.getId()); |
| | | deviceMsgModel.setDeviceId(deviceConfig.getDeviceNo()); |
| | | deviceMsgModel.setDeviceMsgType("status"); |
| | | deviceMsgModel.setDeviceMsg(data); |
| | | deviceMsgModel.setDeviceOriginMsg(sb.toString()); |
| | | deviceMsgUtils.sendDeviceMsg(SlaveType.Shuttle, slave.getId(), deviceMsgModel); |
| | | deviceMsgUtils.sendDeviceMsg(SlaveType.Shuttle, deviceConfig.getDeviceNo(), deviceMsgModel); |
| | | return; |
| | | } |
| | | } |
| | | |
| | | DeviceMsgModel deviceMsgModel = new DeviceMsgModel(); |
| | | deviceMsgModel.setDeviceId(slave.getId()); |
| | | deviceMsgModel.setDeviceId(deviceConfig.getDeviceNo()); |
| | | deviceMsgModel.setDeviceMsgType("command"); |
| | | deviceMsgModel.setDeviceMsg(result); |
| | | deviceMsgModel.setDeviceOriginMsg(sb.toString()); |
| | | deviceMsgUtils.sendDeviceMsg(SlaveType.Shuttle, slave.getId(), deviceMsgModel); |
| | | deviceMsgUtils.sendDeviceMsg(SlaveType.Shuttle, deviceConfig.getDeviceNo(), deviceMsgModel); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | |
| | | @Override |
| | | public boolean connect() { |
| | | try { |
| | | InetAddress address = InetAddress.getByName(slave.getIp()); |
| | | InetAddress address = InetAddress.getByName(deviceConfig.getIp()); |
| | | if (address.isReachable(10000)) { |
| | | Socket socket = new Socket(slave.getIp(), slave.getPort()); |
| | | Socket socket = new Socket(deviceConfig.getIp(), deviceConfig.getPort()); |
| | | socket.setSoTimeout(10000); |
| | | socket.setKeepAlive(true); |
| | | this.socket = socket; |
| | | log.info(MessageFormat.format("【{0}】四向穿梭车Socket链接成功 ===>> [id:{1}] [ip:{2}] [port:{3}]", DateUtils.convert(new Date()), slave.getId(), slave.getIp(), slave.getPort())); |
| | | log.info(MessageFormat.format("【{0}】四向穿梭车Socket链接成功 ===>> [id:{1}] [ip:{2}] [port:{3}]", DateUtils.convert(new Date()), deviceConfig.getDeviceNo(), deviceConfig.getIp(), deviceConfig.getPort())); |
| | | } |
| | | } catch (Exception e) { |
| | | OutputQueue.SHUTTLE.offer(MessageFormat.format("【{0}】四向穿梭车Socket链接失败 ===>> [id:{1}] [ip:{2}] [port:{3}]", DateUtils.convert(new Date()), slave.getId(), slave.getIp(), slave.getPort())); |
| | | OutputQueue.SHUTTLE.offer(MessageFormat.format("【{0}】四向穿梭车Socket链接失败 ===>> [id:{1}] [ip:{2}] [port:{3}]", DateUtils.convert(new Date()), deviceConfig.getDeviceNo(), deviceConfig.getIp(), deviceConfig.getPort())); |
| | | return false; |
| | | } |
| | | |
| | |
| | | package com.zy.core.utils; |
| | | |
| | | import com.core.exception.CoolException; |
| | | import com.zy.common.exception.CoolException; |
| | | import com.zy.common.utils.RedisUtil; |
| | | import com.zy.core.enums.RedisKeyType; |
| | | import com.zy.core.enums.SlaveType; |
| | |
| | | |
| | | @Autowired |
| | | private RedisUtil redisUtil; |
| | | |
| | | public String getDeviceConfig() { |
| | | Object obj = redisUtil.get(RedisKeyType.DEVICE_CONFIG.key); |
| | | if(null == obj){ |
| | | return null; |
| | | } |
| | | return obj.toString(); |
| | | } |
| | | |
| | | public DeviceCommandMsgModel getDeviceCommandMsg(SlaveType deviceType, Integer deviceId) { |
| | | TreeSet<String> listKey = getDeviceCommandMsgListKey(deviceType, deviceId); |
| | |
| | | return key; |
| | | } |
| | | |
| | | public void sendDeviceConfig(String allDevices) { |
| | | redisUtil.set(RedisKeyType.DEVICE_CONFIG.key, allDevices); |
| | | } |
| | | |
| | | public TreeSet<String> getDeviceMsgListKey(SlaveType deviceType, Integer deviceId) { |
| | | String listKey = parseDeviceMsgKey(deviceType, deviceId); |
| | | Set<String> keys = redisUtil.searchKeys(listKey); |
| | |
| | | spring: |
| | | application: |
| | | name: @pom.build.finalName@ |
| | | datasource: |
| | | hikari: |
| | | validation-timeout: 3000 |
| | | connection-test-query: select 1 |
| | | driver-class-name: com.mysql.jdbc.Driver |
| | | url: jdbc:mysql://127.0.0.1:3306/shuttle_rcs?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=Asia/Shanghai |
| | | username: root |
| | | password: root |
| | | jmx: |
| | | enabled: false |
| | | mvc: |
| | | static-path-pattern: /** |
| | | redis: |
| | |
| | | database: 0 |
| | | # password: 123456 |
| | | |
| | | mybatis-plus: |
| | | mapper-locations: classpath:mapper/*.xml |
| | | # global-config: |
| | | # field-strategy: 0 |
| | | # configuration: |
| | | # log-impl: org.apache.ibatis.logging.stdout.StdOutImpl |
| | | |
| | | |
| | | logging: |
| | | path: ./stock/out/@pom.build.finalName@/logs |
| | | |
| | | super: |
| | | pwd: xltys1995 |
| | | |
| | | swagger: |
| | | enable: false |
| | | |
| | | pythonCalcPath: D:\\path\\cpu.py |
| | | pythonCalcSimilarity: D:\\path\\similarity.py |
| | | |
| | | deviceMsgConfig: |
| | | # 读取数据后自动删除 |
| | | destroyAfterReading: true |
| | | |
| | | # 下位机配置 |
| | | wcs-slave: |
| | | # 四向穿梭车1 |
| | | shuttle[0]: |
| | | id: 1 |
| | | ip: 192.168.4.77 |
| | | port: 8888 |
| | | rack: 0 |
| | | slot: 0 |
| | | threadImpl: NyShuttleThread |
| | | # # 四向穿梭车2 |
| | | # shuttle[1]: |
| | | # id: 2 |
| | | # ip: 10.10.20.12 |
| | | # port: 8888 |
| | | # rack: 0 |
| | | # slot: 0 |
| | | # threadImpl: NyShuttleThread |
| | | # # 货叉提升机主线程 |
| | | # forkLiftMaster[0]: |
| | | # id: 99 |
| | | # ip: 10.10.20.20 |
| | | # port: 102 |
| | | # rack: 0 |
| | | # slot: 0 |
| | | # threadImpl: LfdZyForkLiftMasterThread |
| | | # # 货叉提升机1 |
| | | # forkLift[0]: |
| | | # id: 1 |
| | | # ip: 10.10.20.20 |
| | | # port: 102 |
| | | # rack: 0 |
| | | # slot: 0 |
| | | # threadImpl: LfdZyForkLiftSlaveThread |
| | | # masterId: 99 |
| | | # staRow: 9 |
| | | # staBay: 6 |
| | | # sta[0]: |
| | | # staNo: 1001 |
| | | # lev: 1 |
| | | # liftNo: ${wcs-slave.forkLift[0].id} |
| | | # sta[1]: |
| | | # staNo: 1002 |
| | | # lev: 2 |
| | | # liftNo: ${wcs-slave.forkLift[0].id} |
| | | # sta[2]: |
| | | # staNo: 1003 |
| | | # lev: 3 |
| | | # liftNo: ${wcs-slave.forkLift[0].id} |
| | | # sta[3]: |
| | | # staNo: 1004 |
| | | # lev: 4 |
| | | # liftNo: ${wcs-slave.forkLift[0].id} |
| | | destroyAfterReading: true |