From 54c4b03976baced12fb81a62177f730f912c613a Mon Sep 17 00:00:00 2001
From: luxiaotao1123 <t1341870251@163.com>
Date: 星期二, 19 十二月 2023 16:21:38 +0800
Subject: [PATCH] #

---
 zy-asrs-common/src/main/java/com/zy/asrs/common/utils/RandomValidateCodeUtil.java |  122 +++++++
 zy-asrs-common/src/main/java/com/zy/asrs/common/domain/param/PageParam.java       |    2 
 zy-asrs-common/src/main/java/com/zy/asrs/common/web/AuthController.java           |  342 +++++++++++++++++++++
 zy-asrs-common/src/main/java/com/zy/asrs/common/domain/enums/HtmlNavIconType.java |   51 +++
 zy-asrs-common/src/main/java/com/zy/asrs/common/properties/SysOsType.java         |   49 +++
 zy-asrs-common/src/main/java/com/zy/asrs/common/domain/entity/Parameter.java      |   66 ++++
 zy-asrs-common/src/main/java/com/zy/asrs/common/properties/OSinfo.java            |  134 ++++++++
 zy-asrs-common/src/main/java/com/zy/asrs/common/domain/param/BaseParam.java       |    2 
 /dev/null                                                                         |   40 --
 zy-asrs-wms/src/main/java/com/zy/asrs/wms/WmsBoot.java                            |    2 
 zy-asrs-common/src/main/java/com/zy/asrs/common/properties/SystemProperties.java  |   79 ++++
 zy-asrs-common/src/main/java/com/zy/asrs/common/domain/dto/PowerDto.java          |   17 +
 zy-asrs-common/src/main/java/com/zy/asrs/common/domain/CodeRes.java               |   15 
 13 files changed, 879 insertions(+), 42 deletions(-)

diff --git a/zy-asrs-common/src/main/java/com/zy/asrs/common/domain/CodeRes.java b/zy-asrs-common/src/main/java/com/zy/asrs/common/domain/CodeRes.java
new file mode 100644
index 0000000..7221ef1
--- /dev/null
+++ b/zy-asrs-common/src/main/java/com/zy/asrs/common/domain/CodeRes.java
@@ -0,0 +1,15 @@
+package com.zy.asrs.common.domain;
+
+import com.zy.asrs.framework.common.BaseRes;
+
+public interface CodeRes extends BaseRes {
+
+    // user
+    String USER_10001 = "10001-璐﹀彿涓嶅瓨鍦�";
+    String USER_10002 = "10002-璐﹀彿宸茶绂佺敤";
+    String USER_10003 = "10003-瀵嗙爜閿欒";
+
+    String PICK_600 = "600-鎷f枡浠诲姟";
+    String NO_COMB_700 = "700-璇峰厛缁勬墭";
+
+}
diff --git a/zy-asrs-common/src/main/java/com/zy/asrs/common/domain/dto/PowerDto.java b/zy-asrs-common/src/main/java/com/zy/asrs/common/domain/dto/PowerDto.java
new file mode 100644
index 0000000..48f758a
--- /dev/null
+++ b/zy-asrs-common/src/main/java/com/zy/asrs/common/domain/dto/PowerDto.java
@@ -0,0 +1,17 @@
+package com.zy.asrs.common.domain.dto;
+
+import lombok.Data;
+
+import java.util.List;
+
+/**
+ * Created by vincent on 2020-05-12
+ */
+@Data
+public class PowerDto {
+
+    private String two;
+
+    private List<String> three;
+
+}
diff --git a/zy-asrs-common/src/main/java/com/zy/asrs/common/domain/entity/Parameter.java b/zy-asrs-common/src/main/java/com/zy/asrs/common/domain/entity/Parameter.java
new file mode 100644
index 0000000..9aa185d
--- /dev/null
+++ b/zy-asrs-common/src/main/java/com/zy/asrs/common/domain/entity/Parameter.java
@@ -0,0 +1,66 @@
+package com.zy.asrs.common.domain.entity;
+
+import com.alibaba.fastjson.JSON;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.zy.asrs.common.sys.entity.Config;
+import com.zy.asrs.common.sys.service.ConfigService;
+import com.zy.asrs.framework.common.Cools;
+import com.zy.asrs.framework.common.SpringUtils;
+import lombok.Data;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * 鍩虹閰嶇疆涓績銆傚彲閫氳繃鍒锋柊鎸囧畾鎺ュ彛鍒锋柊鐩稿叧閰嶇疆
+ */
+@Data
+public class Parameter {
+
+    private volatile static Parameter instance = null;
+
+    private Parameter(){
+    }
+
+    public static Parameter get(){
+        if (instance == null){
+            synchronized (Parameter.class){
+                instance = reset();
+                return instance;
+            }
+        }
+        return instance;
+    }
+
+	/**
+	 * 閲嶇疆
+	 */
+	public static Parameter reset() {
+        ConfigService configService = SpringUtils.getBean(ConfigService.class);
+        List<Config> configs = configService.list(new LambdaQueryWrapper<Config>().eq(Config::getStatus, "1"));
+        Map<String, Object> data = new HashMap<>();
+        for (Config config : configs) {
+            if (config.getType() == 1) {
+                data.put(config.getCode(), String.valueOf(config.getValue()));
+            } else {
+                data.put(config.getCode(), JSON.parse(config.getValue()));
+            }
+        }
+        instance = Cools.conver(data, Parameter.class);
+        return instance;
+    }
+
+    // 楠岃瘉鐮佸紑鍏�
+    private String codeSwitch;
+
+    // 搴撲綅鍒濆鍖栧彛浠�
+    private String locMastInitPwd;
+
+    // 鎵撳寘涓嬬嚎
+    private String packDown;
+
+    // erp涓婃姤
+    private String erpReport;
+
+}
diff --git a/zy-asrs-common/src/main/java/com/zy/asrs/common/domain/enums/HtmlNavIconType.java b/zy-asrs-common/src/main/java/com/zy/asrs/common/domain/enums/HtmlNavIconType.java
new file mode 100644
index 0000000..31fbf60
--- /dev/null
+++ b/zy-asrs-common/src/main/java/com/zy/asrs/common/domain/enums/HtmlNavIconType.java
@@ -0,0 +1,51 @@
+package com.zy.asrs.common.domain.enums;
+
+public enum HtmlNavIconType {
+
+    INDEX("index", "layui-icon-home"),
+    SYSTEM("system", "layui-icon-component"),
+    SET("set", "layui-icon-set"),
+    MERCHANT("merchant", "layui-icon-user"),
+    DEVELOP("develop", "layui-icon-util"),
+    STOCK("stock", "layui-icon-templeate-1"),
+    LOG_REPORT("logReport", "layui-icon-read"),
+    IO_WORK("ioWork", "layui-icon-flag"),
+    WORK_FLOW("workFlow", "layui-icon-form"),
+    BASE("base", "layui-icon-file"),
+    ORDER("erp", "layui-icon-senior"),
+    SENSOR("sensor", "layui-icon-engine"),
+    ;
+
+
+    private String code;
+    private String icon;
+    HtmlNavIconType(String code, String icon){
+        this.code = code;
+        this.icon = icon;
+    }
+
+    public static String get(String code) {
+        for (HtmlNavIconType type : HtmlNavIconType.values()){
+            if (type.code.equals(code)){
+                return type.icon;
+            }
+        }
+        return "layui-icon-file-b";
+    }
+
+    public String getCode() {
+        return code;
+    }
+
+    public void setCode(String code) {
+        this.code = code;
+    }
+
+    public String getIcon() {
+        return icon;
+    }
+
+    public void setIcon(String icon) {
+        this.icon = icon;
+    }
+}
diff --git a/zy-asrs-common/src/main/java/com/zy/asrs/common/domain/BaseParam.java b/zy-asrs-common/src/main/java/com/zy/asrs/common/domain/param/BaseParam.java
similarity index 93%
rename from zy-asrs-common/src/main/java/com/zy/asrs/common/domain/BaseParam.java
rename to zy-asrs-common/src/main/java/com/zy/asrs/common/domain/param/BaseParam.java
index fbc8bbe..17b7bf7 100644
--- a/zy-asrs-common/src/main/java/com/zy/asrs/common/domain/BaseParam.java
+++ b/zy-asrs-common/src/main/java/com/zy/asrs/common/domain/param/BaseParam.java
@@ -1,4 +1,4 @@
-package com.zy.asrs.common.domain;
+package com.zy.asrs.common.domain.param;
 
 import com.baomidou.mybatisplus.annotation.TableField;
 import io.swagger.annotations.ApiModelProperty;
diff --git a/zy-asrs-common/src/main/java/com/zy/asrs/common/domain/PageParam.java b/zy-asrs-common/src/main/java/com/zy/asrs/common/domain/param/PageParam.java
similarity index 96%
rename from zy-asrs-common/src/main/java/com/zy/asrs/common/domain/PageParam.java
rename to zy-asrs-common/src/main/java/com/zy/asrs/common/domain/param/PageParam.java
index 3b7ede3..9cee25c 100644
--- a/zy-asrs-common/src/main/java/com/zy/asrs/common/domain/PageParam.java
+++ b/zy-asrs-common/src/main/java/com/zy/asrs/common/domain/param/PageParam.java
@@ -1,4 +1,4 @@
-package com.zy.asrs.common.domain;
+package com.zy.asrs.common.domain.param;
 
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 
diff --git a/zy-asrs-common/src/main/java/com/zy/asrs/common/properties/OSinfo.java b/zy-asrs-common/src/main/java/com/zy/asrs/common/properties/OSinfo.java
new file mode 100644
index 0000000..d16dd66
--- /dev/null
+++ b/zy-asrs-common/src/main/java/com/zy/asrs/common/properties/OSinfo.java
@@ -0,0 +1,134 @@
+package com.zy.asrs.common.properties;
+
+/**
+ * Created by vincent on 2020/8/1
+ */
+public class OSinfo {
+
+    private static final String OS = System.getProperty("os.name").toLowerCase();
+
+    private static final OSinfo _instance = new OSinfo();
+
+    private SysOsType sysOsType;
+
+    private OSinfo(){}
+
+    public static boolean isLinux(){
+        return OS.contains("linux");
+    }
+
+    public static boolean isMacOS(){
+        return OS.contains("mac") &&OS.indexOf("os")>0&& !OS.contains("x");
+    }
+
+    public static boolean isMacOSX(){
+        return OS.contains("mac") &&OS.indexOf("os")>0&&OS.indexOf("x")>0;
+    }
+
+    public static boolean isWindows(){
+        return OS.contains("windows");
+    }
+
+    public static boolean isOS2(){
+        return OS.contains("os/2");
+    }
+
+    public static boolean isSolaris(){
+        return OS.contains("solaris");
+    }
+
+    public static boolean isSunOS(){
+        return OS.contains("sunos");
+    }
+
+    public static boolean isMPEiX(){
+        return OS.contains("mpe/ix");
+    }
+
+    public static boolean isHPUX(){
+        return OS.contains("hp-ux");
+    }
+
+    public static boolean isAix(){
+        return OS.contains("aix");
+    }
+
+    public static boolean isOS390(){
+        return OS.contains("os/390");
+    }
+
+    public static boolean isFreeBSD(){
+        return OS.contains("freebsd");
+    }
+
+    public static boolean isIrix(){
+        return OS.contains("irix");
+    }
+
+    public static boolean isDigitalUnix(){
+        return OS.contains("digital") &&OS.indexOf("unix")>0;
+    }
+
+    public static boolean isNetWare(){
+        return OS.contains("netware");
+    }
+
+    public static boolean isOSF1(){
+        return OS.contains("osf1");
+    }
+
+    public static boolean isOpenVMS(){
+        return OS.contains("openvms");
+    }
+
+    /**
+     * 鑾峰彇鎿嶄綔绯荤粺鍚嶅瓧
+     * @return 鎿嶄綔绯荤粺鍚�
+     */
+    public static SysOsType getOSname(){
+        if(isAix()){
+            _instance.sysOsType = SysOsType.AIX;
+        }else if (isDigitalUnix()) {
+            _instance.sysOsType = SysOsType.Digital_Unix;
+        }else if (isFreeBSD()) {
+            _instance.sysOsType = SysOsType.FreeBSD;
+        }else if (isHPUX()) {
+            _instance.sysOsType = SysOsType.HP_UX;
+        }else if (isIrix()) {
+            _instance.sysOsType = SysOsType.Irix;
+        }else if (isLinux()) {
+            _instance.sysOsType = SysOsType.Linux;
+        }else if (isMacOS()) {
+            _instance.sysOsType = SysOsType.Mac_OS;
+        }else if (isMacOSX()) {
+            _instance.sysOsType = SysOsType.Mac_OS_X;
+        }else if (isMPEiX()) {
+            _instance.sysOsType = SysOsType.MPEiX;
+        }else if (isNetWare()) {
+            _instance.sysOsType = SysOsType.NetWare_411;
+        }else if (isOpenVMS()) {
+            _instance.sysOsType = SysOsType.OpenVMS;
+        }else if (isOS2()) {
+            _instance.sysOsType = SysOsType.OS2;
+        }else if (isOS390()) {
+            _instance.sysOsType = SysOsType.OS390;
+        }else if (isOSF1()) {
+            _instance.sysOsType = SysOsType.OSF1;
+        }else if (isSolaris()) {
+            _instance.sysOsType = SysOsType.Solaris;
+        }else if (isSunOS()) {
+            _instance.sysOsType = SysOsType.SunOS;
+        }else if (isWindows()) {
+            _instance.sysOsType = SysOsType.Windows;
+        }else{
+            _instance.sysOsType = SysOsType.Others;
+        }
+        return _instance.sysOsType;
+    }
+
+    public static void main(String[] args) {
+        System.out.println(OSinfo.getOSname());// 鑾峰彇绯荤粺绫诲瀷
+        System.out.println(OSinfo.isWindows());// 鍒ゆ柇鏄惁涓簑indows绯荤粺
+    }
+
+}
diff --git a/zy-asrs-common/src/main/java/com/zy/asrs/common/properties/SysOsType.java b/zy-asrs-common/src/main/java/com/zy/asrs/common/properties/SysOsType.java
new file mode 100644
index 0000000..cc48f01
--- /dev/null
+++ b/zy-asrs-common/src/main/java/com/zy/asrs/common/properties/SysOsType.java
@@ -0,0 +1,49 @@
+package com.zy.asrs.common.properties;
+
+public enum SysOsType {
+
+    Any("any", null),
+    Linux("Linux", null),
+    Mac_OS("Mac OS", null),
+    Mac_OS_X("Mac OS X", null),
+    Windows("Windows", "D:\\licensed.txt"),
+    OS2("OS/2", null),
+    Solaris("Solaris", null),
+    SunOS("SunOS", null),
+    MPEiX("MPE/iX", null),
+    HP_UX("HP-UX", null),
+    AIX("AIX", null),
+    OS390("OS/390", null),
+    FreeBSD("FreeBSD", null),
+    Irix("Irix", null),
+    Digital_Unix("Digital Unix", null),
+    NetWare_411("NetWare", null),
+    OSF1("OSF1", null),
+    OpenVMS("OpenVMS", null),
+    Others("Others", null);
+
+    private String description;
+    private String activationCodePath;
+
+    SysOsType(String desc, String activationCodePath) {
+        this.description = desc;
+        this.activationCodePath = activationCodePath;
+    }
+
+    public String getDescription() {
+        return description;
+    }
+
+    public void setDescription(String description) {
+        this.description = description;
+    }
+
+    public String getActivationCodePath() {
+        return activationCodePath;
+    }
+
+    public void setActivationCodePath(String activationCodePath) {
+        this.activationCodePath = activationCodePath;
+    }
+
+}
diff --git a/zy-asrs-common/src/main/java/com/zy/asrs/common/properties/SystemProperties.java b/zy-asrs-common/src/main/java/com/zy/asrs/common/properties/SystemProperties.java
new file mode 100644
index 0000000..c1d6507
--- /dev/null
+++ b/zy-asrs-common/src/main/java/com/zy/asrs/common/properties/SystemProperties.java
@@ -0,0 +1,79 @@
+package com.zy.asrs.common.properties;
+
+
+import com.zy.asrs.framework.common.AesUtils;
+import com.zy.asrs.framework.common.DateUtils;
+
+import java.io.*;
+import java.util.Date;
+
+/**
+ * Created by vincent on 2020/8/1
+ */
+public class SystemProperties {
+
+    // 婵�娲荤爜鍔犲瘑鐩� -- 16浣�
+    public static final String SALT = "123456789qwertyu";
+
+    // 绯荤粺婵�娲荤姸鎬� (榛樿鏈縺娲�)
+    public static boolean SYSTEM_ACTIVATION = Boolean.FALSE;
+
+    public static String getActivationCode(String fileName){
+        StringBuilder activationCode = new StringBuilder();
+        try {
+            FileReader f = new FileReader(fileName);
+            BufferedReader buf = new BufferedReader(f);
+            String s;
+            while ((s = buf.readLine()) != null) {
+                activationCode.append(s);
+            }
+            f.close();
+            buf.close();
+        } catch (FileNotFoundException ignore) {
+
+        } catch (IOException e) {
+            e.printStackTrace();
+            throw new RuntimeException("璇诲彇WMS绯荤粺婵�娲荤爜澶辫触锛侊紒锛乗n璇诲彇璺緞 " + fileName);
+        }
+        return activationCode.toString();
+    }
+
+    public static boolean saveActivationCode(String filePath, String code){
+        try {
+            // 闃叉鏂囦欢寤虹珛鎴栬鍙栧け璐ワ紝鐢╟atch鎹曟崏閿欒骞舵墦鍗帮紝涔熷彲浠hrow
+            File file = new File(filePath);// 鐩稿璺緞锛屽鏋滄病鏈夊垯瑕佸缓绔嬩竴涓柊鐨刼utput銆倀xt鏂囦欢
+            if (file.exists()) {
+                file.delete();
+            }
+            boolean newFile = file.createNewFile();// 鍒涘缓鏂版枃浠�
+            if (newFile) {
+                String sets = "attrib +H \"" + file.getAbsolutePath() + "\"";
+                Runtime.getRuntime().exec(sets);
+                BufferedWriter out = new BufferedWriter(new FileWriter(file, true));
+                out.write(code); // \r\n鍗充负鎹㈣
+                out.flush(); // 鎶婄紦瀛樺尯鍐呭鍘嬪叆鏂囦欢
+                out.close(); // 鏈�鍚庤寰楀叧闂枃浠�
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+            throw new RuntimeException("鍐欏叆WMS绯荤粺婵�娲荤爜澶辫触锛侊紒锛乗n璺緞 " + filePath);
+        }
+        return true;
+    }
+
+
+    // 鐢熸垚婵�娲荤爜
+    public static void main(String[] args) {
+        String timeStr = "2021-08-01 17:48:35";
+        Date exprTime = DateUtils.convert(timeStr);
+        String code = AesUtils.encrypt(DateUtils.convert(exprTime, DateUtils.yyyyMMddHHmmss), SystemProperties.SALT);
+        System.out.println("婵�娲荤爜锛�"+code);
+        System.out.println("鏈夋晥鏈熻嚦锛�"+timeStr);
+//        saveActivationCode(SysOsType.Windows.getActivationCodePath(), code);
+//        String activationCode = getActivationCode(OSinfo.getOSname().getActivationCodePath());
+//        String decrypt = AesUtils.decrypt(activationCode, "123456789qwertyu");
+//        Date convert = DateUtils.convert(decrypt, DateUtils.yyyyMMddHHmmss);
+//        System.out.println(DateUtils.convert(convert));
+    }
+
+}
diff --git a/zy-asrs-common/src/main/java/com/zy/asrs/common/sys/controller/HostController.java b/zy-asrs-common/src/main/java/com/zy/asrs/common/sys/controller/HostController.java
deleted file mode 100644
index ab55ee0..0000000
--- a/zy-asrs-common/src/main/java/com/zy/asrs/common/sys/controller/HostController.java
+++ /dev/null
@@ -1,40 +0,0 @@
-package com.zy.asrs.common.sys.controller;
-
-import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
-import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
-import com.zy.asrs.common.domain.BaseParam;
-import com.zy.asrs.common.sys.entity.Host;
-import com.zy.asrs.common.sys.service.HostService;
-import com.zy.asrs.common.web.BaseController;
-import com.zy.asrs.framework.common.R;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.PathVariable;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
-
-@RestController
-public class HostController extends BaseController {
-
-    @Autowired
-    private HostService hostService;
-
-    @RequestMapping(value = "/host/{id}/auth")
-//    @ManagerAuth
-    public R get(@PathVariable("id") Long id) {
-        return R.ok(hostService.getById(String.valueOf(id)));
-    }
-
-    @RequestMapping(value = "/host/page/auth")
-//    @ManagerAuth
-    public R page(BaseParam param){
-        LambdaQueryWrapper<Host> wrapper = new LambdaQueryWrapper<>();
-        return R.ok().add(hostService.page(new Page<>(param.getCurr(), param.getLimit()), wrapper));
-    }
-
-    @RequestMapping(value = "/host/list/auth")
-//    @ManagerAuth
-    public R list(){
-        return R.ok().add(hostService.list(new LambdaQueryWrapper<>()));
-    }
-
-}
diff --git a/zy-asrs-common/src/main/java/com/zy/asrs/common/utils/RandomValidateCodeUtil.java b/zy-asrs-common/src/main/java/com/zy/asrs/common/utils/RandomValidateCodeUtil.java
new file mode 100644
index 0000000..7b3aeb4
--- /dev/null
+++ b/zy-asrs-common/src/main/java/com/zy/asrs/common/utils/RandomValidateCodeUtil.java
@@ -0,0 +1,122 @@
+package com.zy.asrs.common.utils;
+
+import javax.imageio.ImageIO;
+import javax.servlet.http.HttpServletResponse;
+import java.awt.*;
+import java.awt.image.BufferedImage;
+import java.util.Map;
+import java.util.Random;
+import java.util.concurrent.ConcurrentHashMap;
+
+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;// 鍥剧墖楂�
+    private static int lineSize = 40;// 骞叉壈绾挎暟閲�
+    private static int stringNum = 4;// 闅忔満浜х敓瀛楃鏁伴噺
+
+    private static Random random = new Random();
+
+    /**
+     * 鑾峰緱瀛椾綋
+     */
+    private static Font getFont() {
+        return new Font("Fixedsys", Font.CENTER_BASELINE, 18);
+    }
+
+    /**
+     * 鑾峰緱棰滆壊
+     */
+    private static Color getRandColor(int fc, int bc) {
+        if (fc > 255)
+            fc = 255;
+        if (bc > 255)
+            bc = 255;
+        int r = fc + random.nextInt(bc - fc - 16);
+        int g = fc + random.nextInt(bc - fc - 14);
+        int b = fc + random.nextInt(bc - fc - 18);
+        return new Color(r, g, b);
+    }
+
+    public static void init() {
+        BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_BGR);
+        Graphics g = image.getGraphics();// 浜х敓Image瀵硅薄鐨凣raphics瀵硅薄,鏀瑰璞″彲浠ュ湪鍥惧儚涓婅繘琛屽悇绉嶇粯鍒舵搷浣�
+        g.fillRect(0, 0, width, height);//鍥剧墖澶у皬
+        g.setFont(new Font("Times New Roman", Font.PLAIN, 18));//瀛椾綋澶у皬
+        g.setColor(getRandColor(110, 133));//瀛椾綋棰滆壊
+        // 缁樺埗骞叉壈绾�
+        for (int i = 0; i <= lineSize; i++) {
+            drowLine(g);
+        }
+        // 缁樺埗闅忔満瀛楃
+        String randomString = "";
+        for (int i = 1; i <= stringNum; i++) {
+            randomString = drowString(g, randomString, i);
+        }
+        g.dispose();
+    }
+
+    /**
+     * 鐢熸垚闅忔満鍥剧墖
+     */
+    public static void getRandcode(String sd, HttpServletResponse response) {
+        BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_BGR);
+        Graphics g = image.getGraphics();// 浜х敓Image瀵硅薄鐨凣raphics瀵硅薄,鏀瑰璞″彲浠ュ湪鍥惧儚涓婅繘琛屽悇绉嶇粯鍒舵搷浣�
+        g.fillRect(0, 0, width, height);//鍥剧墖澶у皬
+        g.setFont(new Font("Times New Roman", Font.PLAIN, 18));//瀛椾綋澶у皬
+        g.setColor(getRandColor(110, 133));//瀛椾綋棰滆壊
+        // 缁樺埗骞叉壈绾�
+        for (int i = 0; i <= lineSize; i++) {
+            drowLine(g);
+        }
+        // 缁樺埗闅忔満瀛楃
+        String randomString = "";
+        for (int i = 1; i <= stringNum; i++) {
+            randomString = drowString(g, randomString, i);
+        }
+        code.put(sd, randomString);
+        g.dispose();
+        try {
+            ImageIO.write(image, "JPEG", response.getOutputStream());
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+
+    /**
+     * 缁樺埗瀛楃涓�
+     */
+    private static String drowString(Graphics g, String randomString, int i) {
+        g.setFont(getFont());
+        g.setColor(new Color(random.nextInt(101), random.nextInt(111), random
+                .nextInt(121)));
+        String rand = String.valueOf(getRandomString(random.nextInt(randString
+                .length())));
+        randomString += rand;
+        g.translate(random.nextInt(3), random.nextInt(3));
+        g.drawString(rand, 13 * (i-1)+2, 16);
+        return randomString;
+    }
+
+    /**
+     * 缁樺埗骞叉壈绾�
+     */
+    private static void drowLine(Graphics g) {
+        int x = random.nextInt(width);
+        int y = random.nextInt(height);
+        int xl = random.nextInt(13);
+        int yl = random.nextInt(15);
+        g.drawLine(x, y, x + xl, y + yl);
+    }
+
+    /**
+     * 鑾峰彇闅忔満鐨勫瓧绗�
+     */
+    public static String getRandomString(int num) {
+        return String.valueOf(randString.charAt(num));
+    }
+
+}
diff --git a/zy-asrs-common/src/main/java/com/zy/asrs/common/web/AuthController.java b/zy-asrs-common/src/main/java/com/zy/asrs/common/web/AuthController.java
new file mode 100644
index 0000000..85d7974
--- /dev/null
+++ b/zy-asrs-common/src/main/java/com/zy/asrs/common/web/AuthController.java
@@ -0,0 +1,342 @@
+package com.zy.asrs.common.web;
+
+import com.alibaba.fastjson.JSON;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.zy.asrs.common.domain.CodeRes;
+import com.zy.asrs.common.domain.dto.PowerDto;
+import com.zy.asrs.common.domain.entity.Parameter;
+import com.zy.asrs.common.domain.enums.HtmlNavIconType;
+import com.zy.asrs.common.properties.OSinfo;
+import com.zy.asrs.common.properties.SystemProperties;
+import com.zy.asrs.common.sys.entity.*;
+import com.zy.asrs.common.sys.service.*;
+import com.zy.asrs.common.utils.RandomValidateCodeUtil;
+import com.zy.asrs.framework.annotations.ManagerAuth;
+import com.zy.asrs.framework.common.AesUtils;
+import com.zy.asrs.framework.common.Cools;
+import com.zy.asrs.framework.common.DateUtils;
+import com.zy.asrs.framework.common.R;
+import com.zy.asrs.framework.exception.CoolException;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.transaction.annotation.Transactional;
+import org.springframework.web.bind.annotation.*;
+
+import javax.servlet.http.HttpServletResponse;
+import java.util.*;
+
+/**
+ * Created by vincent on 2019-07-30
+ */
+@RestController
+public class AuthController extends BaseController {
+
+    @Value("${super.pwd}")
+    private String superPwd;
+    @Autowired
+    private UserService userService;
+    @Autowired
+    private RoleService roleService;
+    @Autowired
+    private UserLoginService userLoginService;
+    @Autowired
+    private ResourceService resourceService;
+    @Autowired
+    private RoleResourceService roleResourceService;
+
+    @RequestMapping("/login.action")
+    @ManagerAuth(value = ManagerAuth.Auth.NONE, memo = "鐧诲綍")
+    public R loginAction(String username, String password){
+        if (username.equals("super") && password.equals(Cools.md5(superPwd))) {
+            Map<String, Object> res = new HashMap<>();
+            res.put("username", username);
+            res.put("token", Cools.enToken(System.currentTimeMillis() + username, superPwd));
+            return R.ok(res);
+        }
+        LambdaQueryWrapper<User> userWrapper = new LambdaQueryWrapper<>();
+        userWrapper.eq(User::getUsername, username);
+        User user = userService.getOne(userWrapper);
+        if (Cools.isEmpty(user)){
+            return R.parse(CodeRes.USER_10001);
+        }
+        if (user.getStatus()!=1){
+            return R.parse(CodeRes.USER_10002);
+        }
+        if (!user.getPassword().equals(password)){
+            return R.parse(CodeRes.USER_10003);
+        }
+        String token = Cools.enToken(System.currentTimeMillis() + username, user.getPassword());
+        userLoginService.remove(new LambdaQueryWrapper<UserLogin>().eq(UserLogin::getUserId, user.getId()));
+        UserLogin userLogin = new UserLogin();
+        userLogin.setUserId(user.getId());
+        userLogin.setToken(token);
+        userLogin.setCreateTime(new Date());
+        userLoginService.save(userLogin);
+        Map<String, Object> res = new HashMap<>();
+        res.put("username", user.getUsername());
+        res.put("token", token);
+        return R.ok(res);
+    }
+
+    @RequestMapping("/code/switch.action")
+    public R code() {
+        return R.ok().add(Parameter.get().getCodeSwitch());
+    }
+
+    @RequestMapping("/code.action")
+    public void code(@RequestParam String sd, HttpServletResponse response) {
+        RandomValidateCodeUtil.getRandcode(sd, response);
+    }
+
+    @RequestMapping("/code.do")
+    public String codeDo(@RequestParam String sd) throws Exception {
+        String code = null;
+        int time = 0;
+        while (time < 3000) {
+            code = RandomValidateCodeUtil.code.get(sd);
+            if (!Cools.isEmpty(code)){
+                break;
+            } else {
+                Thread.sleep(10);
+                time = time + 100;
+            }
+        }
+        RandomValidateCodeUtil.code.remove(sd);
+        return code;
+    }
+
+    @RequestMapping("/user/detail/auth")
+    @ManagerAuth
+    public R userDetail(){
+        return R.ok(userService.getById(getUserId()));
+    }
+
+    @RequestMapping("/menu/auth")
+    @ManagerAuth
+    public R menu(){
+        // 鑾峰彇鎵�鏈変竴绾ц彍鍗�
+        List<Resource> oneLevel;
+        User user = null;
+        LambdaQueryWrapper<Resource> resourceWrapper;
+        if (getUserId() == 9527) {
+            oneLevel = resourceService.list(new LambdaQueryWrapper<Resource>().eq(Resource::getLevel, 1).orderByAsc(Resource::getSort));
+            resourceWrapper = new LambdaQueryWrapper<Resource>().eq(Resource::getLevel, 2).eq(Resource::getStatus, 1).orderByAsc(Resource::getSort);
+        } else {
+            // 婵�娲荤爜楠岃瘉
+            if (!SystemProperties.SYSTEM_ACTIVATION) {
+                return R.ok();
+            }
+            oneLevel = resourceService.list(new LambdaQueryWrapper<Resource>().eq(Resource::getLevel, 1).eq(Resource::getStatus, 1).orderByAsc(Resource::getSort));
+            // 鑾峰彇褰撳墠鐢ㄦ埛鐨勬墍鏈変簩绾ц彍鍗�
+            user = userService.getById(getUserId());
+            List<RoleResource> roleResources = roleResourceService.list(new LambdaQueryWrapper<RoleResource>().eq(RoleResource::getRoleId, user.getRoleId()));
+            List<Long> resourceIds = new ArrayList<>();
+            roleResources.forEach(roleResource -> resourceIds.add(roleResource.getResourceId()));
+            if (resourceIds.isEmpty()){
+                return R.ok();
+            }
+            resourceWrapper = new LambdaQueryWrapper<Resource>().in(Resource::getId, resourceIds).eq(Resource::getLevel, 2).eq(Resource::getStatus, 1).orderByAsc(Resource::getSort);
+        }
+        List<Resource> twoLevel = resourceService.list(resourceWrapper);
+        List<Map<String, Object>> result = new ArrayList<>();
+        for (Resource menu : oneLevel) {
+            Map<String, Object> map = new HashMap<>();
+            List<Resource> subMenu = new ArrayList<>();
+            Iterator<Resource> iterator = twoLevel.iterator();
+            while (iterator.hasNext()) {
+                Resource resource = iterator.next();
+                if (resource.getResourceId() != null && resource.getResourceId().equals(menu.getId())) {
+
+                    // 鏄惁鎷ユ湁鏌ョ湅鏉冮檺
+                    if (getUserId() != 9527) {
+                        Resource view = resourceService.getOne(new LambdaQueryWrapper<Resource>().eq(Resource::getResourceId, resource.getId()).like(Resource::getCode, "#view"));
+                        if (!Cools.isEmpty(view)){
+                            RoleResource param = new RoleResource();
+                            param.setResourceId(view.getId());
+                            param.setRoleId(user.getRoleId());
+                            if (null == roleResourceService.getOne(new LambdaQueryWrapper<>(param))){
+                                continue;
+                            }
+                        }
+                    }
+
+                    subMenu.add(resource);
+                    iterator.remove();
+                }
+            }
+            if (subMenu.isEmpty()) {
+                continue;
+            }
+            map.put("menuId", menu.getId());
+            map.put("menuCode", menu.getCode());
+            map.put("menuIcon", HtmlNavIconType.get(menu.getCode()));
+            map.put("menu", menu.getName());
+            map.put("subMenu", subMenu);
+            result.add(map);
+        }
+        return R.ok(result);
+    }
+
+    @RequestMapping("/power/list/auth")
+    @ManagerAuth
+    public R powerList(){
+        List<Resource> oneLevels = resourceService.list(new LambdaQueryWrapper<Resource>().eq(Resource::getLevel, 1).eq(Resource::getStatus, 1).orderByAsc(Resource::getSort));
+        List<Map> result = new ArrayList<>();
+        // 涓�绾�
+        for (Resource oneLevel : oneLevels){
+            List<Map> twoLevelsList = new ArrayList<>();
+            Map<String, Object> oneLevelMap = new HashMap<>();
+            oneLevelMap.put("title", oneLevel.getName());
+            oneLevelMap.put("id", oneLevel.getId());
+            oneLevelMap.put("spread", true);
+            oneLevelMap.put("children", twoLevelsList);
+            List<Resource> twoLevels = resourceService.list(new LambdaQueryWrapper<Resource>().eq(Resource::getResourceId, oneLevel.getId()).eq(Resource::getLevel, 2).eq(Resource::getStatus, 1).orderByAsc(Resource::getSort));
+            // 浜岀骇
+            for (Resource twoLevel : twoLevels){
+                Map<String, Object> twoLevelMap = new HashMap<>();
+                twoLevelMap.put("title", twoLevel.getName());
+                twoLevelMap.put("id", twoLevel.getId());
+                twoLevelMap.put("spread", false);
+
+                List<Map> threeLevelsList = new ArrayList<>();
+                twoLevelMap.put("children", threeLevelsList);
+                // 涓夌骇
+                List<Resource> threeLevels = resourceService.list(new LambdaQueryWrapper<Resource>().eq(Resource::getResourceId, twoLevel.getId()).eq(Resource::getLevel, 3).eq(Resource::getStatus, 1).orderByAsc(Resource::getSort));
+                for (Resource threeLevel : threeLevels){
+                    Map<String, Object> threeLevelMap = new HashMap<>();
+                    threeLevelMap.put("title", threeLevel.getName());
+                    threeLevelMap.put("id", threeLevel.getId());
+                    threeLevelMap.put("checked", false);
+                    threeLevelsList.add(threeLevelMap);
+                }
+
+                twoLevelsList.add(twoLevelMap);
+            }
+            result.add(oneLevelMap);
+        }
+
+        return R.ok(result);
+    }
+
+    @RequestMapping(value = "/power/{roleId}/auth")
+    @ManagerAuth
+    public R get(@PathVariable("roleId") Long roleId) {
+        List<Object> result = new ArrayList<>();
+        // 鑿滃崟
+        List<RoleResource> roleResources = roleResourceService.list(new LambdaQueryWrapper<RoleResource>().eq(RoleResource::getRoleId, roleId));
+        for (RoleResource roleResource : roleResources){
+            Resource resource = resourceService.getById(roleResource.getResourceId());
+            if (!Cools.isEmpty(resource)){
+                if (resource.getLevel() == 3){
+                    result.add(resource.getId());
+                }
+            }
+        }
+        return R.ok(result);
+    }
+
+    @RequestMapping("/power/auth")
+    @ManagerAuth(memo = "鎺堟潈")
+    @Transactional
+    public R power(Long roleId, String powers){
+        Role role = roleService.getById(roleId);
+        Long leaderId = role.getLeader();
+        roleResourceService.remove(new LambdaQueryWrapper<RoleResource>().eq(RoleResource::getRoleId, roleId));
+        if (!Cools.isEmpty(powers)){
+            List<PowerDto> dtos = JSON.parseArray(powers, PowerDto.class);
+            for (PowerDto dto : dtos) {
+                Resource resource = resourceService.getOne(new LambdaQueryWrapper<Resource>().eq(Resource::getId, dto.getTwo()).eq(Resource::getLevel, 2));
+                if (!Cools.isEmpty(resource)) {
+                    // 鏍¢獙涓婄骇鏉冮檺
+                    if (leaderId != null) {
+                        RoleResource roleResource = roleResourceService.getOne(new LambdaQueryWrapper<RoleResource>().eq(RoleResource::getRoleId, leaderId).eq(RoleResource::getResourceId, resource.getId()));
+                        if (null == roleResource) {
+                            throw new CoolException(resource.getName().concat("鏃犳硶鎺堟潈缁�").concat(role.getName()));
+                        }
+                    }
+                    RoleResource roleResource = new RoleResource();
+                    roleResource.setRoleId(roleId);
+                    roleResource.setResourceId(resource.getId());
+                    roleResourceService.save(roleResource);
+                }
+                for (String three : dto.getThree()){
+                    Resource resource1 = resourceService.getOne(new LambdaQueryWrapper<Resource>().eq(Resource::getId, three).eq(Resource::getLevel, 3));
+                    if (!Cools.isEmpty(resource1)) {
+                        // 鏍¢獙涓婄骇鏉冮檺
+                        if (leaderId != null) {
+                            RoleResource roleResource = roleResourceService.getOne(new LambdaQueryWrapper<RoleResource>().eq(RoleResource::getRoleId, leaderId).eq(RoleResource::getResourceId, resource1.getId()));
+                            if (null == roleResource) {
+                                throw new CoolException(resource.getName().concat("鐨�").concat(resource1.getName().concat("鏃犳硶鎺堟潈缁�").concat(role.getName())));
+                            }
+                        }
+                        RoleResource roleResource = new RoleResource();
+                        roleResource.setRoleId(roleId);
+                        roleResource.setResourceId(resource1.getId());
+                        roleResourceService.save(roleResource);
+                    }
+                }
+            }
+        }
+        return R.ok();
+    }
+
+    @RequestMapping(value = "/power/menu/{resourceId}/auth")
+    @ManagerAuth
+    public R buttonResource(@PathVariable("resourceId") Long resourceId) {
+        List<Resource> resources;
+        if (getUserId() == 9527) {
+            resources = resourceService.list(new LambdaQueryWrapper<Resource>().eq(Resource::getLevel, 3).eq(Resource::getResourceId, resourceId));
+        } else {
+            resources = roleResourceService.getMenuButtomResource(resourceId, getUserId());
+        }
+        for (Resource resource : resources) {
+            resource.setCode(resource.getCode().split("#")[1]);
+        }
+        return R.ok(resources);
+    }
+
+    @GetMapping(value = "/system/activation/auth")
+    public R activation() {
+        if (SystemProperties.SYSTEM_ACTIVATION) {
+            String activationCode = SystemProperties.getActivationCode(OSinfo.getOSname().getActivationCodePath());
+            String timeStr = AesUtils.decrypt(activationCode, SystemProperties.SALT);
+            if (null == timeStr) {
+                SystemProperties.SYSTEM_ACTIVATION = Boolean.FALSE;
+                return R.error();
+            }
+            Date exprTime = DateUtils.convert(timeStr, DateUtils.yyyyMMddHHmmss);
+            if (new Date().getTime() < exprTime.getTime()) {
+                return R.ok().add(DateUtils.convert(exprTime));
+            } else {
+                SystemProperties.SYSTEM_ACTIVATION = Boolean.FALSE;
+                return R.error();
+            }
+        } else {
+            return R.error();
+        }
+    }
+
+    @PostMapping(value = "/system/secret/auth")
+    @ManagerAuth
+    public R systemSecret(@RequestParam(value = "secret") String secret) {
+        if (Cools.isEmpty(secret)) {
+            return R.error("璇疯緭鍏ユ縺娲荤爜");
+        }
+        // 楠岃瘉婵�娲荤爜
+        String timeStr = AesUtils.decrypt(secret, SystemProperties.SALT);
+        if (null == timeStr) {
+            return R.error("婵�娲荤爜閿欒");
+        }
+        Date exprTime = DateUtils.convert(timeStr, DateUtils.yyyyMMddHHmmss);
+        if (new Date().getTime() >= exprTime.getTime()) {
+            return R.error("婵�娲荤爜宸插け鏁�");
+        }
+        boolean result = SystemProperties.saveActivationCode(OSinfo.getOSname().getActivationCodePath(), secret);
+        if (!result) {
+            return R.error("婵�娲诲け璐�");
+        }
+        SystemProperties.SYSTEM_ACTIVATION = Boolean.TRUE;
+        return R.ok("婵�娲绘垚鍔燂紝鏈夋晥鏈熻嚦"+DateUtils.convert(exprTime));
+    }
+
+}
diff --git a/zy-asrs-wms/src/main/java/com/zy/asrs/wms/WmsBoot.java b/zy-asrs-wms/src/main/java/com/zy/asrs/wms/WmsBoot.java
index 88e69a6..0b5dd39 100644
--- a/zy-asrs-wms/src/main/java/com/zy/asrs/wms/WmsBoot.java
+++ b/zy-asrs-wms/src/main/java/com/zy/asrs/wms/WmsBoot.java
@@ -1,5 +1,6 @@
 package com.zy.asrs.wms;
 
+import com.zy.asrs.common.utils.RandomValidateCodeUtil;
 import org.mybatis.spring.annotation.MapperScan;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
@@ -11,6 +12,7 @@
 public class WmsBoot {
 
     public static void main(String[] args) {
+        RandomValidateCodeUtil.init();
         SpringApplication.run(WmsBoot.class, args);
     }
 

--
Gitblit v1.9.1