فهرست منبع

临时提交代码

zhoutg 5 سال پیش
والد
کامیت
f16fa4b991

+ 15 - 0
docs/027.20191220病历质控维护/init_mrqc.sql

@@ -0,0 +1,15 @@
+use `sys-mrqc`;
+
+DROP TABLE IF EXISTS `mrqc_item`;
+CREATE TABLE `mrqc_item` (
+  `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键',
+  `is_deleted` char(1)  NOT NULL DEFAULT 'N' COMMENT '是否删除,N:未删除,Y:删除',
+  `gmt_create` datetime NOT NULL DEFAULT '1970-01-01 12:00:00' COMMENT '记录创建时间',
+  `gmt_modified` datetime NOT NULL DEFAULT '1970-01-01 12:00:00' COMMENT '记录修改时间,如果时间是1970年则表示纪录未修改',
+  `creator` varchar(20)  NOT NULL DEFAULT '' COMMENT '创建人姓名',
+  `modifier` varchar(20)  NOT NULL DEFAULT '' COMMENT '修改人姓名',
+  `name` varchar(255)  NOT NULL COMMENT '质控条目',
+    `remark` varchar(255)  NOT NULL DEFAULT '' COMMENT '备注',
+  PRIMARY KEY (`id`)
+) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8  COMMENT='病历质控条目';
+

+ 188 - 0
mrqcman-service/src/main/java/com/diagbot/web/IpUtil.java

@@ -0,0 +1,188 @@
+package com.diagbot.web;
+
+import java.net.InetAddress;
+import java.net.NetworkInterface;
+import java.net.SocketException;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.List;
+import java.util.UUID;
+
+/**
+ * @description:
+ * @author: zhoutg
+ * @time: 2019/12/23 9:33
+ */
+public class IpUtil {
+    private IpUtil(){}
+    /**
+     * 此方法描述的是:获得服务器的IP地址
+     * @author:  zhangyang33@sinopharm.com
+     * @version: 2014年9月5日 下午4:57:15
+     */
+    public static String getLocalIP() {
+        String sIP = "";
+        InetAddress ip = null;
+        try {
+            boolean bFindIP = false;
+            Enumeration<NetworkInterface> netInterfaces = (Enumeration<NetworkInterface>) NetworkInterface
+                    .getNetworkInterfaces();
+            while (netInterfaces.hasMoreElements()) {
+                if (bFindIP) {
+                    break;
+                }
+                NetworkInterface ni = (NetworkInterface) netInterfaces
+                        .nextElement();
+
+                Enumeration<InetAddress> ips = ni.getInetAddresses();
+                while (ips.hasMoreElements()) {
+                    ip = (InetAddress) ips.nextElement();
+                    if (!ip.isLoopbackAddress()
+                            && ip.getHostAddress().matches(
+                            "(\\d{1,3}\\.){3}\\d{1,3}")) {
+                        bFindIP = true;
+                        break;
+                    }
+                }
+            }
+        } catch (Exception e) {
+            System.out.println(e.getMessage());
+        }
+        if (null != ip) {
+            sIP = ip.getHostAddress();
+        }
+        return sIP;
+    }
+
+    /**
+     * 此方法描述的是:获得服务器的IP地址(多网卡)
+     * @author:  zhangyang33@sinopharm.com
+     * @version: 2014年9月5日 下午4:57:15
+     */
+    public static List<String> getLocalIPS() {
+        InetAddress ip = null;
+        List<String> ipList = new ArrayList<String>();
+        try {
+            Enumeration<NetworkInterface> netInterfaces = (Enumeration<NetworkInterface>) NetworkInterface
+                    .getNetworkInterfaces();
+            while (netInterfaces.hasMoreElements()) {
+                NetworkInterface ni = (NetworkInterface) netInterfaces
+                        .nextElement();
+                Enumeration<InetAddress> ips = ni.getInetAddresses();
+                while (ips.hasMoreElements()) {
+                    ip = (InetAddress) ips.nextElement();
+                    if (!ip.isLoopbackAddress()
+                            && ip.getHostAddress().matches(
+                            "(\\d{1,3}\\.){3}\\d{1,3}")) {
+                        ipList.add(ip.getHostAddress());
+                    }
+                }
+            }
+        } catch (Exception e) {
+            System.out.println(e.getMessage());
+        }
+        return ipList;
+    }
+
+    /**
+     * 此方法描述的是:获得服务器的MAC地址
+     * @author:  zhangyang33@sinopharm.com
+     * @version: 2014年9月5日 下午1:27:25
+     */
+    public static String getMacId() {
+        String macId = "";
+        InetAddress ip = null;
+        NetworkInterface ni = null;
+        try {
+            boolean bFindIP = false;
+            Enumeration<NetworkInterface> netInterfaces = (Enumeration<NetworkInterface>) NetworkInterface
+                    .getNetworkInterfaces();
+            while (netInterfaces.hasMoreElements()) {
+                if (bFindIP) {
+                    break;
+                }
+                ni = (NetworkInterface) netInterfaces
+                        .nextElement();
+                // ----------特定情况,可以考虑用ni.getName判断
+                // 遍历所有ip
+                Enumeration<InetAddress> ips = ni.getInetAddresses();
+                while (ips.hasMoreElements()) {
+                    ip = (InetAddress) ips.nextElement();
+                    if (!ip.isLoopbackAddress() // 非127.0.0.1
+                            && ip.getHostAddress().matches(
+                            "(\\d{1,3}\\.){3}\\d{1,3}")) {
+                        bFindIP = true;
+                        break;
+                    }
+                }
+            }
+        } catch (Exception e) {
+            System.out.println(e.getMessage());
+        }
+        if (null != ip) {
+            try {
+                macId = getMacFromBytes(ni.getHardwareAddress());
+            } catch (SocketException e) {
+                System.out.println(e.getMessage());
+            }
+        }
+        return macId;
+    }
+
+    /**
+     * 此方法描述的是:获得服务器的MAC地址(多网卡)
+     * @author:  zhangyang33@sinopharm.com
+     * @version: 2014年9月5日 下午1:27:25
+     */
+    public static List<String> getMacIds() {
+        InetAddress ip = null;
+        NetworkInterface ni = null;
+        List<String> macList = new ArrayList<String>();
+        try {
+            Enumeration<NetworkInterface> netInterfaces = (Enumeration<NetworkInterface>) NetworkInterface
+                    .getNetworkInterfaces();
+            while (netInterfaces.hasMoreElements()) {
+                ni = (NetworkInterface) netInterfaces
+                        .nextElement();
+                // ----------特定情况,可以考虑用ni.getName判断
+                // 遍历所有ip
+                Enumeration<InetAddress> ips = ni.getInetAddresses();
+                while (ips.hasMoreElements()) {
+                    ip = (InetAddress) ips.nextElement();
+                    if (!ip.isLoopbackAddress() // 非127.0.0.1
+                            && ip.getHostAddress().matches(
+                            "(\\d{1,3}\\.){3}\\d{1,3}")) {
+                        macList.add(getMacFromBytes(ni.getHardwareAddress()));
+                    }
+                }
+            }
+        } catch (Exception e) {
+            System.out.println(e.getMessage());
+        }
+        return macList;
+    }
+
+    private static String getMacFromBytes(byte[] bytes) {
+        StringBuffer mac = new StringBuffer();
+        byte currentByte;
+        boolean first = false;
+        for (byte b : bytes) {
+            if (first) {
+                mac.append("-");
+            }
+            currentByte = (byte) ((b & 240) >> 4);
+            mac.append(Integer.toHexString(currentByte));
+            currentByte = (byte) (b & 15);
+            mac.append(Integer.toHexString(currentByte));
+            first = true;
+        }
+        return mac.toString().toUpperCase();
+    }
+
+    public static void main(String[] args) {
+        String uuid = UUID.randomUUID().toString();
+        System.out.println(uuid);
+        uuid = uuid.replace("-", "");
+        System.out.println(uuid);
+    }
+}

+ 57 - 0
mrqcman-service/src/main/java/com/diagbot/web/MrqcmanController.java

@@ -7,6 +7,13 @@ import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Properties;
+
 /**
  * @Description: 日志操作控制层
  * @author: gaodm
@@ -26,5 +33,55 @@ public class MrqcmanController {
         return RespDTO.onSuc("测试");
     }
 
+
+    public static String getLinuxMACAddress() {
+        String mac = null;
+        BufferedReader bufferedReader = null;
+        Process process = null;
+        try {
+            process = Runtime.getRuntime().exec("ifconfig enp4s0");
+            bufferedReader = new BufferedReader(new InputStreamReader(
+                    process.getInputStream()));
+            String line = null;
+            int index = -1;
+            while ((line = bufferedReader.readLine()) != null) {
+                index = line.toLowerCase().indexOf("硬件地址");
+
+                if (index != -1) {
+
+                    mac = line.substring(index + 4).trim();
+                    break;
+                }
+            }
+        } catch (IOException e) {
+            e.printStackTrace();
+        } finally {
+            try {
+                if (bufferedReader != null) {
+                    bufferedReader.close();
+                }
+            } catch (IOException e1) {
+                e1.printStackTrace();
+            }
+            bufferedReader = null;
+            process = null;
+        }
+        return mac;
+    }
+    public static void main(String[] argc) {
+
+        Properties properties = System.getProperties();
+        Iterator it = properties.entrySet().iterator();
+        while(it.hasNext()){
+            Map.Entry entry=(Map.Entry)it.next();
+            Object key = entry.getKey();
+            Object value = entry.getValue();
+            System.out.println(key +":"+value);
+        }
+
+        String mac = getLinuxMACAddress();
+        System.out.println("本地是Linux系统, MAC地址是:" + mac);
+
+    }
 }
 

+ 300 - 0
mrqcman-service/src/main/java/com/diagbot/web/SerialNumberUtil.java

@@ -0,0 +1,300 @@
+package com.diagbot.web;
+
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileWriter;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.net.Inet4Address;
+import java.net.InetAddress;
+import java.net.NetworkInterface;
+import java.net.SocketException;
+import java.net.UnknownHostException;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @description:
+ * @author: zhoutg
+ * @time: 2019/12/23 10:40
+ */
+public class SerialNumberUtil {
+    static Logger log = LogManager.getLogger(SerialNumberUtil.class);
+
+    /**
+     * 获取主板序列号
+     *
+     * @return
+     */
+    public static String getMotherboardSN() {
+        String result = "";
+        try {
+            File file = File.createTempFile("realhowto", ".vbs");
+            file.deleteOnExit();
+            FileWriter fw = new java.io.FileWriter(file);
+
+            String vbs = "Set objWMIService = GetObject(\"winmgmts:\\\\.\\root\\cimv2\")\n"
+                    + "Set colItems = objWMIService.ExecQuery _ \n"
+                    + "   (\"Select * from Win32_BaseBoard\") \n"
+                    + "For Each objItem in colItems \n"
+                    + "    Wscript.Echo objItem.SerialNumber \n"
+                    + "    exit for  ' do the first cpu only! \n" + "Next \n";
+
+            fw.write(vbs);
+            fw.close();
+            String path = file.getPath().replace("%20", " ");
+            Process p = Runtime.getRuntime().exec(
+                    "cscript //NoLogo " + path);
+            BufferedReader input = new BufferedReader(new InputStreamReader(
+                    p.getInputStream()));
+            String line;
+            while ((line = input.readLine()) != null) {
+                result += line;
+            }
+            input.close();
+        } catch (Exception e) {
+            System.out.println(e.getMessage());
+            log.error(e.getMessage());
+        }
+        return result.trim();
+    }
+
+    /**
+     * 获取硬盘序列号(该方法获取的是硬盘本身的序列号)
+     * @return
+     */
+    public static String getHardDiskSN() {
+        String result = "";
+        try {
+            File file = File.createTempFile("realhowto", ".vbs");
+            file.deleteOnExit();
+            FileWriter fw = new java.io.FileWriter(file);
+            String vbs = "Set objWMIService = GetObject(\"winmgmts:\\\\.\\root\\cimv2\")\n"
+                    + "Set colItems = objWMIService.ExecQuery _ \n"
+                    + "   (\"Select * from Win32_DiskDrive\") \n"
+                    + "For Each objItem in colItems \n"
+                    + "    Wscript.Echo objItem.SerialNumber \n"
+                    + "    exit for  ' do the first cpu only! \n" + "Next \n";
+
+            fw.write(vbs);
+            fw.close();
+            String path = file.getPath().replace("%20", " ");
+            Process p = Runtime.getRuntime().exec(
+                    "cscript //NoLogo " + path);
+            BufferedReader input = new BufferedReader(new InputStreamReader(
+                    p.getInputStream()));
+            String line;
+            while ((line = input.readLine()) != null) {
+                result += line;
+            }
+            input.close();
+        } catch (Exception e) {
+            log.error(e.getMessage());
+        }
+        return result.trim();
+    }
+
+    /**
+     * 获取CPU序列号
+     *
+     * @return
+     */
+    public static String getCPUSerial() {
+        String result = "";
+        try {
+            File file = File.createTempFile("tmp", ".vbs");
+            file.deleteOnExit();
+            FileWriter fw = new java.io.FileWriter(file);
+            String vbs = "Set objWMIService = GetObject(\"winmgmts:\\\\.\\root\\cimv2\")\n"
+                    + "Set colItems = objWMIService.ExecQuery _ \n"
+                    + "   (\"Select * from Win32_Processor\") \n"
+                    + "For Each objItem in colItems \n"
+                    + "    Wscript.Echo objItem.ProcessorId \n"
+                    + "    exit for  ' do the first cpu only! \n" + "Next \n";
+
+            // + "    exit for  \r\n" + "Next";
+            fw.write(vbs);
+            fw.close();
+            String path = file.getPath().replace("%20", " ");
+            Process p = Runtime.getRuntime().exec(
+                    "cscript //NoLogo " + path);
+            BufferedReader input = new BufferedReader(new InputStreamReader(
+                    p.getInputStream()));
+            String line;
+            while ((line = input.readLine()) != null) {
+                result += line;
+            }
+            input.close();
+            file.delete();
+        } catch (Exception e) {
+            log.error(e.getMessage());
+        }
+        if (result.trim().length() < 1 || result == null) {
+            result = "无CPU_ID被读取";
+        }
+        return result.trim();
+    }
+
+    private static List<String> getLocalHostLANAddress() throws UnknownHostException, SocketException {
+        List<String> ips = new ArrayList<String>();
+        Enumeration<NetworkInterface> interfs = NetworkInterface.getNetworkInterfaces();
+        while (interfs.hasMoreElements()) {
+            NetworkInterface interf = interfs.nextElement();
+            Enumeration<InetAddress> addres = interf.getInetAddresses();
+            while (addres.hasMoreElements()) {
+                InetAddress in = addres.nextElement();
+                if (in instanceof Inet4Address) {
+                    System.out.println("v4:" + in.getHostAddress());
+                    if (!"127.0.0.1".equals(in.getHostAddress())) {
+                        ips.add(in.getHostAddress());
+                    }
+                }
+            }
+        }
+        return ips;
+    }
+
+    /**
+     * MAC
+     * 通过jdk自带的方法,先获取本机所有的ip,然后通过NetworkInterface获取mac地址
+     *
+     * @return
+     */
+    public static String getMac() {
+        try {
+            String resultStr = "";
+            List<String> ls = getLocalHostLANAddress();
+            for (String str : ls) {
+                InetAddress ia = InetAddress.getByName(str);// 获取本地IP对象
+                // 获得网络接口对象(即网卡),并得到mac地址,mac地址存在于一个byte数组中。
+                byte[] mac = NetworkInterface.getByInetAddress(ia)
+                        .getHardwareAddress();
+                // 下面代码是把mac地址拼装成String
+                StringBuilder sb = new StringBuilder();
+                for (int i = 0; i < mac.length; i++) {
+                    if (i != 0) {
+                        sb.append("-");
+                    }
+                    // mac[i] & 0xFF 是为了把byte转化为正整数
+                    String s = Integer.toHexString(mac[i] & 0xFF);
+                    sb.append(s.length() == 1 ? 0 + s : s);
+                }
+                // 把字符串所有小写字母改为大写成为正规的mac地址并返回
+                resultStr += sb.toString().toUpperCase() + ",";
+            }
+            return resultStr;
+        } catch (Exception e) {
+            log.error(e.getMessage());
+        }
+        return null;
+    }
+
+    /***************************linux*********************************/
+
+    public static String executeLinuxCmd(String cmd) {
+        try {
+            System.out.println("got cmd job : " + cmd);
+            Runtime run = Runtime.getRuntime();
+            Process process;
+            process = run.exec(cmd);
+            InputStream in = process.getInputStream();
+            BufferedReader bs = new BufferedReader(new InputStreamReader(in));
+            StringBuffer out = new StringBuffer();
+            byte[] b = new byte[8192];
+            for (int n; (n = in.read(b)) != -1; ) {
+                out.append(new String(b, 0, n));
+            }
+
+            in.close();
+            process.destroy();
+            return out.toString();
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return null;
+    }
+
+    /**
+     * @param cmd    命令语句
+     * @param record 要查看的字段
+     * @param symbol 分隔符
+     * @return
+     */
+    public static String getSerialNumber(String cmd, String record, String symbol) {
+        String execResult = executeLinuxCmd(cmd);
+        String[] infos = execResult.split("\n");
+
+        for (String info : infos) {
+            info = info.trim();
+            if (info.indexOf(record) != -1) {
+                info.replace(" ", "");
+                String[] sn = info.split(symbol);
+                return sn[1];
+            }
+        }
+
+        return null;
+    }
+
+    /**
+     * 获取CPUID、硬盘序列号、MAC地址、主板序列号
+     *
+     * @return
+     */
+    public static Map<String, String> getAllSn() {
+        String os = System.getProperty("os.name");
+        Map<String, String> snVo = new HashMap<String, String>();
+
+        if ("LINUX".equals(os)) {
+            System.out.println("=============>for linux");
+            String cpuid = getSerialNumber("dmidecode -t processor | grep 'ID'", "ID", ":");
+            System.out.println("cpuid : " + cpuid);
+            String mainboardNumber = getSerialNumber("dmidecode |grep 'Serial Number'", "Serial Number", ":");
+            System.out.println("mainboardNumber : " + mainboardNumber);
+            String diskNumber = getSerialNumber("fdisk -l", "Disk identifier", ":");
+            System.out.println("diskNumber : " + diskNumber);
+            String mac = getSerialNumber("ifconfig -a", "ether", " ");
+            snVo.put("cpuid", cpuid.toUpperCase().replace(" ", ""));
+            snVo.put("diskid", diskNumber.toUpperCase().replace(" ", ""));
+            snVo.put("mac", mac.toUpperCase().replace(" ", ""));
+            snVo.put("mainboard", mainboardNumber.toUpperCase().replace(" ", ""));
+        } else {
+            System.out.println("=============>for windows");
+            String cpuid = SerialNumberUtil.getCPUSerial();
+            String mainboard = SerialNumberUtil.getMotherboardSN();
+            String disk = SerialNumberUtil.getHardDiskSN();
+            String mac = SerialNumberUtil.getMac();
+
+            System.out.println("CPU  SN:" + cpuid);
+            System.out.println("主板  SN:" + mainboard);
+            System.out.println("C盘   SN:" + disk);
+            System.out.println("MAC  SN:" + mac);
+
+            snVo.put("cpuid", cpuid.toUpperCase().replace(" ", ""));
+            snVo.put("diskid", disk.toUpperCase().replace(" ", ""));
+            snVo.put("mac", mac.toUpperCase().replace(" ", ""));
+            snVo.put("mainboard", mainboard.toUpperCase().replace(" ", ""));
+        }
+
+        return snVo;
+    }
+
+    /**
+     * linux
+     * cpuid : dmidecode -t processor | grep 'ID'
+     * mainboard : dmidecode |grep 'Serial Number'
+     * disk : fdisk -l
+     * mac : ifconfig -a
+     *
+     * @param args
+     */
+    public static void main(String[] args) {
+        getAllSn();
+    }
+}