洪城义警-正式版后台
zengh
2021-11-02 6514a3c58c63988d86b1904bf8100bbf00824a92
资格审查内网穿透
10 files modified
6 files added
1099 ■■■■■ changed files
pom.xml 5 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/common/config/FtpConfig.java 99 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/FTP/FtpMain.java 38 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/FTP/FtpUtil.java 308 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/FTP/MysqlCenlint.java 118 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/FTP/OutJson.java 229 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/FTP/monitor.java 180 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/system/controller/UserController.java 54 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/system/mapper/UserMapper.java 8 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/system/mapper/UserMapper.xml 10 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/system/service/IUserService.java 7 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/system/service/impl/UserServiceImpl.java 12 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/zc/controller/ZcController.java 1 ●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/zc/entity/Zc.java 5 ●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/zc/mapper/ZcMapper.xml 1 ●●●● patch | view | raw | blame | history
src/main/resources/application-dev.yml 24 ●●●● patch | view | raw | blame | history
pom.xml
@@ -75,6 +75,11 @@
            <artifactId>blade-starter-http</artifactId>
        </dependency>
        <dependency>
            <groupId>commons-net</groupId>
            <artifactId>commons-net</artifactId>
            <version>1.4.1</version>
        </dependency>
        <dependency>
            <groupId>org.springblade</groupId>
            <artifactId>blade-starter-api-crypto</artifactId>
        </dependency>
src/main/java/org/springblade/common/config/FtpConfig.java
New file
@@ -0,0 +1,99 @@
package org.springblade.common.config;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
/**
 * ftp 配置路径
 * @author zhongrj
 * @since 2021-9-24
 */
@ConfigurationProperties(prefix = "ftp")
@Component
public class FtpConfig {
    /**
     * sql connect
     */
    public static String sqlConnect;
    /**
     * ftp服务器IP地址
     */
    public static String ftpHost;
    /**
     * ftp服务器端口
     */
    public static int ftpPort;
    /**
     * ftp服务器用户名
     */
    public static String ftpUserName;
    /**
     * ftp服务器密码
     */
    public static String ftpPassword;
    /**
     * ftp服务器路径
     */
    public static String ftpPath;
    /**
     * 本地路径
     */
    public static String localPath;
    /**
     * minio内网ip
     */
    public static String ip;
    public static String jsonUrl;
    public void setSqlConnect(String sqlConnect) {
        FtpConfig.sqlConnect = sqlConnect;
    }
    public void setFtpHost(String ftpHost) {
        FtpConfig.ftpHost = ftpHost;
    }
    public void setFtpPort(int ftpPort) {
        FtpConfig.ftpPort = ftpPort;
    }
    public void setFtpUserName(String ftpUserName) {
        FtpConfig.ftpUserName = ftpUserName;
    }
    public void setFtpPassword(String ftpPassword) {
        FtpConfig.ftpPassword = ftpPassword;
    }
    public void setFtpPath(String ftpPath) {
        FtpConfig.ftpPath = ftpPath;
    }
    public void setLocalPath(String localPath) {
        FtpConfig.localPath = localPath;
    }
    public void setIp(String ip) {
        FtpConfig.ip = ip;
    }
    public void setJsonUrl(String jsonUrl) {
        FtpConfig.jsonUrl = jsonUrl;
    }
}
src/main/java/org/springblade/modules/FTP/FtpMain.java
New file
@@ -0,0 +1,38 @@
package org.springblade.modules.FTP;
import java.io.FileNotFoundException;
public class FtpMain {
    public static void main(String[] args) throws FileNotFoundException {
        //ftp服务器IP地址
        String ftpHost = "192.168.0.105";
        //ftp服务器端口
        int ftpPort = 21;
        //ftp服务器用户名
        String ftpUserName = "yly";
        //ftp服务器密码
        String ftpPassword = "Yly@123";
        //ftp服务器路径
        String ftpPath = "";
        //本地路径
        String localPath = "D:\\anbao";
        //文件名
        String fileName = "sql.json";
        //下载
        //将ftp根目录下的文件下载至E盘
        //FtpUtil.downloadFtpFile(ftpHost, ftpUserName, ftpPassword, ftpPort, ftpPath, localPath, fileName);
        //上传
        //将E盘的文件上传至ftp根目录
        //FileInputStream in=new FileInputStream(new File("D:\\" + fileName));
        //FtpUtil.uploadFile(ftpHost, ftpPort, ftpUserName, ftpPassword, "anbao/", "/", fileName, in);
        //删除
        //删除ftp根目录下的文件
        //FtpUtil.deleteFile(ftpHost, ftpPort, ftpUserName, ftpPassword, "anbao/", "fz.py");
    }
}
src/main/java/org/springblade/modules/FTP/FtpUtil.java
New file
@@ -0,0 +1,308 @@
package org.springblade.modules.FTP;
import com.alibaba.fastjson.JSON;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.commons.net.ftp.FTP;
import org.apache.commons.net.ftp.FTPClient;
import org.apache.commons.net.ftp.FTPReply;
import java.io.*;
import java.net.SocketException;
import java.util.Date;
import static org.springblade.common.config.FtpConfig.*;
/**
 * ftp工具类
 *
 * @author lijj
 */
public class FtpUtil {
    private final static Log logger = LogFactory.getLog(FtpUtil.class);
    /**
     * 本地字符编码
     */
    private static String LOCAL_CHARSET = "GBK";
    // FTP协议里面,规定文件名编码为iso-8859-1
    private static String SERVER_CHARSET = "ISO-8859-1";
    /**
     * 获取FTPClient对象
     *
     * @param ftpHost     FTP主机服务器
     * @param ftpPassword FTP 登录密码
     * @param ftpUserName FTP登录用户名
     * @param ftpPort     FTP端口 默认为21
     * @return
     */
    public static FTPClient getFTPClient(String ftpHost, int ftpPort, String ftpUserName, String ftpPassword) {
        FTPClient ftpClient = null;
        try {
            ftpClient = new FTPClient();
            ftpClient.connect(ftpHost, ftpPort);// 连接FTP服务器
            ftpClient.login(ftpUserName, ftpPassword);// 登陆FTP服务器
            if (!FTPReply.isPositiveCompletion(ftpClient.getReplyCode())) {
                logger.info("未连接到FTP,用户名或密码错误。");
                ftpClient.disconnect();
            } else {
                logger.info("FTP连接成功。");
            }
        } catch (SocketException e) {
            e.printStackTrace();
            logger.info("FTP的IP地址可能错误,请正确配置。");
        } catch (IOException e) {
            e.printStackTrace();
            logger.info("FTP的端口错误,请正确配置。");
        }
        return ftpClient;
    }
    /**
     * 从FTP服务器下载文件
     *
     * @param ftpHost     FTP IP地址
     * @param ftpUserName FTP 用户名
     * @param ftpPassword FTP用户名密码
     * @param ftpPort     FTP端口
     * @param ftpPath     FTP服务器中文件所在路径 格式: ftptest/aa
     * @param localPath   下载到本地的位置 格式:H:/download
     * @param fileName    文件名称
     */
    public static void downloadFtpFile(String ftpHost, String ftpUserName, String ftpPassword, int ftpPort,
                                       String ftpPath, String localPath, String fileName) {
        FTPClient ftpClient = null;
        try {
            ftpClient = getFTPClient(ftpHost, ftpPort, ftpUserName, ftpPassword);
            // 设置上传文件的类型为二进制类型
            if (FTPReply.isPositiveCompletion(ftpClient.sendCommand("OPTS UTF8", "ON"))) {// 开启服务器对UTF-8的支持,如果服务器支持就用UTF-8编码,否则就使用本地编码(GBK).
                LOCAL_CHARSET = "UTF-8";
            }
            ftpClient.setControlEncoding(LOCAL_CHARSET);
            ftpClient.enterLocalPassiveMode();// 设置被动模式
            ftpClient.setFileType(FTP.BINARY_FILE_TYPE);// 设置传输的模式
            // 上传文件
            //对中文文件名进行转码,否则中文名称的文件下载失败
            String fileNameTemp = new String(fileName.getBytes(LOCAL_CHARSET), SERVER_CHARSET);
            ftpClient.changeWorkingDirectory(ftpPath);
            InputStream retrieveFileStream = ftpClient.retrieveFileStream(fileNameTemp);
            // 第一种方式下载文件(推荐)
            //File localFile = new File(localPath + File.separatorChar + fileName);
            //OutputStream os = new FileOutputStream(localFile);
            //ftpClient.retrieveFile(fileName, os); os.close();
            // 第二种方式下载:将输入流转成字节,再生成文件,这种方式方便将字节数组直接返回给前台jsp页面
            byte[] input2byte = input2byte(retrieveFileStream);
            byte2File(input2byte, localPath, fileName);
            if (null != retrieveFileStream) {
                retrieveFileStream.close();
            }
        } catch (FileNotFoundException e) {
            logger.error("没有找到" + ftpPath + "文件");
            e.printStackTrace();
        } catch (SocketException e) {
            logger.error("连接FTP失败.");
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
            logger.error("文件读取错误。");
            e.printStackTrace();
        } finally {
            if (ftpClient.isConnected()) {
                try {
                    //退出登录
                    ftpClient.logout();
                    //关闭连接
                    ftpClient.disconnect();
                } catch (IOException e) {
                }
            }
        }
    }
    public static boolean uploadFile(String ftpHost, int ftpPort, String ftpUserName, String ftpPassword,
                                     String basePath, String filePath, String filename, InputStream input) {
        boolean result = false;
        FTPClient ftpClient = null;
        try {
            int reply;
            ftpClient = getFTPClient(ftpHost, ftpPort, ftpUserName, ftpPassword);
            reply = ftpClient.getReplyCode();
            if (!FTPReply.isPositiveCompletion(reply)) {
                ftpClient.disconnect();
                return result;
            }
            // 切换到上传目录
            if (!ftpClient.changeWorkingDirectory(basePath + filePath)) {
                // 如果目录不存在创建目录
                String[] dirs = filePath.split("/");
                String tempPath = basePath;
                for (String dir : dirs) {
                    if (null == dir || "".equals(dir))
                        continue;
                    tempPath += "/" + dir;
                    if (!ftpClient.changeWorkingDirectory(tempPath)) {
                        if (!ftpClient.makeDirectory(tempPath)) {
                            return result;
                        } else {
                            ftpClient.changeWorkingDirectory(tempPath);
                        }
                    }
                }
            }
            // 设置上传文件的类型为二进制类型
            if (FTPReply.isPositiveCompletion(ftpClient.sendCommand("OPTS UTF8", "ON"))) {// 开启服务器对UTF-8的支持,如果服务器支持就用UTF-8编码,否则就使用本地编码(GBK).
                LOCAL_CHARSET = "UTF-8";
            }
            ftpClient.setControlEncoding(LOCAL_CHARSET);
            ftpClient.enterLocalPassiveMode();// 设置被动模式
            ftpClient.setFileType(FTP.BINARY_FILE_TYPE);// 设置传输的模式
            // 上传文件
            filename = new String(filename.getBytes(LOCAL_CHARSET), SERVER_CHARSET);
            if (!ftpClient.storeFile(filename, input)) {
                return result;
            }
            if (null != input) {
                input.close();
            }
            result = true;
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (ftpClient.isConnected()) {
                try {
                    //退出登录
                    ftpClient.logout();
                    //关闭连接
                    ftpClient.disconnect();
                } catch (IOException ioe) {
                }
            }
        }
        return result;
    }
    public static boolean deleteFile(String ftpHost, int ftpPort, String ftpUserName, String ftpPassword, String pathname,
                                     String filename) {
        boolean flag = false;
        FTPClient ftpClient = new FTPClient();
        try {
            ftpClient = getFTPClient(ftpHost, ftpPort, ftpUserName, ftpPassword);
            // 验证FTP服务器是否登录成功
            int replyCode = ftpClient.getReplyCode();
            if (!FTPReply.isPositiveCompletion(replyCode)) {
                return flag;
            }
            // 切换FTP目录
            ftpClient.changeWorkingDirectory(pathname);
            // 设置上传文件的类型为二进制类型
            if (FTPReply.isPositiveCompletion(ftpClient.sendCommand("OPTS UTF8", "ON"))) {// 开启服务器对UTF-8的支持,如果服务器支持就用UTF-8编码,否则就使用本地编码(GBK).
                LOCAL_CHARSET = "UTF-8";
            }
            ftpClient.setControlEncoding(LOCAL_CHARSET);
            ftpClient.enterLocalPassiveMode();// 设置被动模式
            ftpClient.setFileType(FTP.BINARY_FILE_TYPE);// 设置传输的模式
            //对中文名称进行转码
            filename = new String(filename.getBytes(LOCAL_CHARSET), SERVER_CHARSET);
            ftpClient.dele(filename);
            flag = true;
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (ftpClient.isConnected()) {
                try {
                    //退出登录
                    ftpClient.logout();
                    //关闭连接
                    ftpClient.disconnect();
                } catch (IOException e) {
                }
            }
        }
        return flag;
    }
    // 将字节数组转换为输入流
    public static final InputStream byte2Input(byte[] buf) {
        return new ByteArrayInputStream(buf);
    }
    // 将输入流转为byte[]
    public static final byte[] input2byte(InputStream inStream) throws IOException {
        ByteArrayOutputStream swapStream = new ByteArrayOutputStream();
        byte[] buff = new byte[100];
        int rc = 0;
        while ((rc = inStream.read(buff, 0, 100)) > 0) {
            swapStream.write(buff, 0, rc);
        }
        byte[] in2b = swapStream.toByteArray();
        return in2b;
    }
    // 将byte[]转为文件
    public static void byte2File(byte[] buf, String filePath, String fileName) {
        BufferedOutputStream bos = null;
        FileOutputStream fos = null;
        File file = null;
        try {
            File dir = new File(filePath);
            if (!dir.exists() && dir.isDirectory()) {
                dir.mkdirs();
            }
            file = new File(filePath + File.separator + fileName);
            fos = new FileOutputStream(file);
            bos = new BufferedOutputStream(fos);
            bos.write(buf);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (bos != null) {
                try {
                    bos.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            if (fos != null) {
                try {
                    fos.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
    /**
     * 执行sql 上传
     * @param s1 sql
     */
    public static void sqlFileUpload(String s1){
        String json1 = JSON.toJSONString(s1);
        String response1 = String.valueOf((new Date()).getTime());
        OutJson.createJsonFile(json1, localPath, "w"+response1);
        FileInputStream in1 = null;
        try {
            in1 = new FileInputStream(new File(localPath + "w"+response1+".json"));
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
        FtpUtil.uploadFile(ftpHost, ftpPort, ftpUserName, ftpPassword, ftpPath, "/",  "w"+response1+".json", in1);
        MysqlCenlint.deletess("w"+response1+".json");
    }
}
src/main/java/org/springblade/modules/FTP/MysqlCenlint.java
New file
@@ -0,0 +1,118 @@
package org.springblade.modules.FTP;
import java.io.File;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import static org.springblade.common.config.FtpConfig.localPath;
import static org.springblade.common.config.FtpConfig.sqlConnect;
public class MysqlCenlint {
    /**
     * 连接mysql数据库 新增
     * @param sql
     */
    public static void inster(String sql) {
        try {
            int ColumnCount;
            //int RowCount;
            String driver = "com.mysql.jdbc.Driver";
            String url = sqlConnect; //换成要连接的数据库信息
            String user = "root";
            String password = "zhba0728";
            Class.forName ( driver );
            Connection conn = (Connection) DriverManager.getConnection ( url, user, password );
            if (!conn.isClosed ()) {
                System.out.println ( "数据库连接成功:" );
                String sqls = sql; //sql
                PreparedStatement ps = conn.prepareStatement ( sqls );
                boolean execute = ps.execute();
                ps.close ();
                conn.close ();
            }
        } catch (ClassNotFoundException e) {
            e.printStackTrace ();
        } catch (SQLException e) {
            e.printStackTrace ();
        }
    }
    /**
     * 连接mysql数据库 修改
     * @param sql
     */
    public static void update(String sql) {
        try {
            int ColumnCount;
            //int RowCount;
            String driver = "com.mysql.jdbc.Driver";
            String url = sqlConnect; //换成要连接的数据库信息
            String user = "root";
            String password = "zhba0728";
            Class.forName ( driver );
            Connection conn = (Connection) DriverManager.getConnection ( url, user, password );
            if (!conn.isClosed ()) {
                System.out.println ( "数据库连接成功:" );
                String sqls = sql; //sql
                PreparedStatement ps = conn.prepareStatement ( sqls );
                ps.executeUpdate();
                ps.close ();
                conn.close ();
            }
        } catch (ClassNotFoundException e) {
            e.printStackTrace ();
        } catch (SQLException e) {
            e.printStackTrace ();
        }
    }
    /**
     * 连接mysql数据库 删除
     * @param sql
     */
    public static void delete(String sql) {
        try {
            int ColumnCount;
            //int RowCount;
            String driver = "com.mysql.jdbc.Driver";
            String url = sqlConnect; //换成要连接的数据库信息
            String user = "root";
            String password = "zhba0728";
            Class.forName ( driver );
            Connection conn = (Connection) DriverManager.getConnection ( url, user, password );
            if (!conn.isClosed ()) {
                System.out.println ( "数据库连接成功:" );
                String sqls = sql; //sql
                PreparedStatement ps = conn.prepareStatement ( sqls );
                ps.executeUpdate();
                ps.close ();
                conn.close ();
            }
        } catch (ClassNotFoundException e) {
            e.printStackTrace ();
        } catch (SQLException e) {
            e.printStackTrace ();
        }
    }
//    /**
//     * 删除本地文件
//     */
//    public  static  void deletes(String fileName){
//        File file = new File("D:\\"+fileName);
//        if (file.isFile() && file.exists()) {
//            file.delete();
//        }
//    }
    public  static  void deletess(String fileName){
        File file = new File(localPath+fileName);
        if (file.isFile() && file.exists()) {
            file.delete();
        }
    }
}
src/main/java/org/springblade/modules/FTP/OutJson.java
New file
@@ -0,0 +1,229 @@
package org.springblade.modules.FTP;
import org.springblade.common.config.FtpConfig;
import java.io.*;
public class OutJson {
    /**
     * 生成.json格式文件
     */
    public static boolean createJsonFile(String jsonString, String filePath, String fileName) {
        // 标记文件生成是否成功
        boolean flag = true;
        // 拼接文件完整路径
        String fullPath = filePath + File.separator + fileName + ".json";
        // 生成json格式文件
        try {
            // 保证创建一个新文件
            File file = new File(fullPath);
            if (!file.getParentFile().exists()) { // 如果父目录不存在,创建父目录
                file.getParentFile().mkdirs();
            }
            if (file.exists()) { // 如果已存在,删除旧文件
                file.delete();
            }
            file.createNewFile();
            // 格式化json字符串
            jsonString = OutJson.formatJson(jsonString);
            // 将格式化后的字符串写入文件
            Writer write = new OutputStreamWriter(new FileOutputStream(file), "UTF-8");
            write.write(jsonString);
            write.flush();
            write.close();
        } catch (Exception e) {
            flag = false;
            e.printStackTrace();
        }
        // 返回是否成功的标记
        return flag;
    }
    /**
     * 单位缩进字符串。
     */
    private static String SPACE = "   ";
    /**
     * 返回格式化JSON字符串。
     *
     * @param json 未格式化的JSON字符串。
     * @return 格式化的JSON字符串。
     */
    public static String formatJson(String json) {
        StringBuffer result = new StringBuffer();
        int length = json.length();
        int number = 0;
        char key = 0;
        // 遍历输入字符串。
        for (int i = 0; i < length; i++) {
            // 1、获取当前字符。
            key = json.charAt(i);
            // 2、如果当前字符是前方括号、前花括号做如下处理:
            if ((key == '[') || (key == '{')) {
                // (1)如果前面还有字符,并且字符为“:”,打印:换行和缩进字符字符串。
                if ((i - 1 > 0) && (json.charAt(i - 1) == ':')) {
                    result.append('\n');
                    result.append(indent(number));
                }
                // (2)打印:当前字符。
                result.append(key);
                // (3)前方括号、前花括号,的后面必须换行。打印:换行。
                result.append('\n');
                // (4)每出现一次前方括号、前花括号;缩进次数增加一次。打印:新行缩进。
                number++;
                result.append(indent(number));
                // (5)进行下一次循环。
                continue;
            }
            // 3、如果当前字符是后方括号、后花括号做如下处理:
            if ((key == ']') || (key == '}')) {
                // (1)后方括号、后花括号,的前面必须换行。打印:换行。
                result.append('\n');
                // (2)每出现一次后方括号、后花括号;缩进次数减少一次。打印:缩进。
                number--;
                result.append(indent(number));
                // (3)打印:当前字符。
                result.append(key);
                // (4)如果当前字符后面还有字符,并且字符不为“,”,打印:换行。
                if (((i + 1) < length) && (json.charAt(i + 1) != ',')) {
                    result.append('\n');
                }
                // (5)继续下一次循环。
                continue;
            }
            // 4、如果当前字符是逗号。逗号后面换行,并缩进,不改变缩进次数。
            if ((key == ',')) {
                result.append(key);
                result.append('\n');
                result.append(indent(number));
                continue;
            }
            // 5、打印:当前字符。
            result.append(key);
        }
        return result.toString();
    }
    /**
     * 返回指定次数的缩进字符串。每一次缩进三个空格,即SPACE。
     *
     * @param number 缩进次数。
     * @return 指定缩进次数的字符串。
     */
    private static String indent(int number) {
        StringBuffer result = new StringBuffer();
        for (int i = 0; i < number; i++) {
            result.append(SPACE);
        }
        return result.toString();
    }
    /**
     * 删除文件
     * @param str
     * @return
     */
    public static String stringReplace(String str) {
        //去掉" "号
        String strs= str.replace("\"", "");
        return strs ;
    }
    /**
     * 读取json文件并解析
     * @return
     */
    public static String TestJson(String fileName){
        //File file = new File(FtpConstant.jsonUrl+fileName);
        File file = new File(FtpConfig.jsonUrl +fileName);
        StringBuilder localStrBulider = new StringBuilder();
        if(file.isFile() && file.exists()) {
            try {
                InputStreamReader inputStreamReader = new InputStreamReader(new FileInputStream(file), "utf-8");
                BufferedReader bufferReader = new BufferedReader(inputStreamReader);
                String lineStr = null;
                try {
                    while((lineStr = bufferReader.readLine()) != null) {
                        localStrBulider.append(lineStr);
                    }
                    bufferReader.close();
                    inputStreamReader.close();
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    System.out.println("file read error!");
                    e.printStackTrace();
                }
            } catch (UnsupportedEncodingException e) {
                // TODO Auto-generated catch block
                System.out.println("file catch unsupported encoding!");
                e.printStackTrace();
            } catch (FileNotFoundException e) {
                // TODO Auto-generated catch block
                System.out.println("file not found!");
                e.printStackTrace();
            }
        }else {
            System.out.println("file is not a file or file is not existing!");
        }
        return  localStrBulider.toString();
    }
    /**
     * 读取json文件并解析
     * @return
     */
    public static String TestJsons(String urls){
        File file = new File(urls);
        StringBuilder localStrBulider = new StringBuilder();
        if(file.isFile() && file.exists()) {
            try {
                InputStreamReader inputStreamReader = new InputStreamReader(new FileInputStream(file), "utf-8");
                BufferedReader bufferReader = new BufferedReader(inputStreamReader);
                String lineStr = null;
                try {
                    while((lineStr = bufferReader.readLine()) != null) {
                        localStrBulider.append(lineStr);
                    }
                    bufferReader.close();
                    inputStreamReader.close();
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    System.out.println("file read error!");
                    e.printStackTrace();
                }
            } catch (UnsupportedEncodingException e) {
                // TODO Auto-generated catch block
                System.out.println("file catch unsupported encoding!");
                e.printStackTrace();
            } catch (FileNotFoundException e) {
                // TODO Auto-generated catch block
                System.out.println("file not found!");
                e.printStackTrace();
            }
        }else {
            System.out.println("file is not a file or file is not existing!");
        }
        return  localStrBulider.toString();
    }
}
src/main/java/org/springblade/modules/FTP/monitor.java
New file
@@ -0,0 +1,180 @@
package org.springblade.modules.FTP;
import org.apache.commons.net.ftp.FTP;
import org.apache.commons.net.ftp.FTPClient;
import org.apache.commons.net.ftp.FTPFile;
import org.apache.commons.net.ftp.FTPReply;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.io.IOException;
import java.io.InputStream;
import static org.springblade.common.config.FtpConfig.*;
@Component
public class monitor {
    @Scheduled(cron = "*/30 * * * * ?")
    public static boolean isFTPFileExist() {
        FTPClient ftp = new FTPClient();
        try {
            // 连接ftp服务器
//            System.out.println("ftpHost = " + ftpHost);
            ftp.connect(ftpHost, ftpPort);
            // 登陆
            ftp.login(ftpUserName, ftpPassword);
            // 检验登陆操作的返回码是否正确
            if (!FTPReply.isPositiveCompletion(ftp.getReplyCode())) {
                ftp.disconnect();
                return false;
            }
            ftp.enterLocalActiveMode();
            // 设置文件类型为二进制,与ASCII有区别
            ftp.setFileType(FTP.BINARY_FILE_TYPE);
            // 设置编码格式
            ftp.setControlEncoding("GBK");
            // 提取绝对地址的目录以及文件名
            //ftpPath = ftpPath.replace("ftp://" + ftpHost + ":" + ftpPort + "/", "");
            //String dir = ftpPath.substring(0, ftpPath.lastIndexOf("/"));
            // file = ftpPath.substring(ftpPath.lastIndexOf("/") + 1);
            // 进入文件所在目录,注意编码格式,以能够正确识别中文目录
            //ftp.changeWorkingDirectory(new String(dir.getBytes("GBK"), FTP.DEFAULT_CONTROL_ENCODING));
            // 检验文件是否存在
            ftp.changeWorkingDirectory(ftpPath);
            FTPFile[] files = ftp.listFiles();
            if (files.length==0){
                return false;
            }
            else {
                for (FTPFile file : files){
                    String fileName = file.getName();
                    InputStream is = ftp.retrieveFileStream(new String(fileName.getBytes("GBK"), FTP.DEFAULT_CONTROL_ENCODING));
                    String substring1 = fileName.substring(0, 1);
                    if (substring1.equals("n")){
                        //把文件下载到本地
                        FtpUtil.downloadFtpFile(ftpHost, ftpUserName, ftpPassword, ftpPort, ftpPath, localPath, fileName);
                        //
                        String s = OutJson.TestJson(fileName);
                        //sql语句
                        String sql = OutJson.stringReplace(s);
                        String[] split = sql.split(";");//以逗号分割
                        for (String sqls : split) {
                            //判断是否是新增,删除,修改
                            String substring = sqls.substring(0, 2);
                            //新增
                            if (substring.equals("in")) {
                                //运行sql语句
                                MysqlCenlint.inster(sqls);
                            }
                            //修改
                            else if (substring.equals("up")) {
                                MysqlCenlint.update(sqls);
                            }
                            //删除
                            else {
                                MysqlCenlint.delete(sqls);
                            }
                        }
                        //删除本地文件
                        //MysqlCenlint.deletes(fileName);
                        MysqlCenlint.deletess(fileName);
                        FtpUtil.deleteFile(ftpHost, ftpPort, ftpUserName, ftpPassword, ftpPath, fileName);
                        is.close();
                        ftp.completePendingCommand();
                    }
                }
                return true;
            }
            //InputStream is = ftp.retrieveFileStream(new String(file.getBytes("GBK"), FTP.DEFAULT_CONTROL_ENCODING));
//            if (is == null || ftp.getReplyCode() == FTPReply.FILE_UNAVAILABLE) {
//                return false;
//
//            }
//
//            if (is != null) {
//                //把文件下载到本地
//                FtpUtil.downloadFtpFile(ftpHost, ftpUserName, ftpPassword, ftpPort, ftpPath, localPath, fileName);
//                //
//                String s = OutJson.TestJson();
//                //sql语句
//                String sql = OutJson.stringReplace(s);
//                String[] split = sql.split(";");//以逗号分割
//                for (String sqls : split) {
//                    //判断是否是新增,删除,修改
//                    String substring = sqls.substring(0, 2);
//                    //新增
//                    if (substring.equals("in")) {
//                        //运行sql语句
//                        MysqlCenlint.inster(sqls);
//                    }
//                    //修改
//                    else if (substring.equals("up")) {
//                        MysqlCenlint.update(sqls);
//                    }
//                    //删除
//                    else {
//                        MysqlCenlint.delete(sqls);
//                    }
//                }
//                //删除本地文件
//                MysqlCenlint.delete();
//                FtpUtil.deleteFile(ftpHost, ftpPort, ftpUserName, ftpPassword, "anbao/", "nsql.json");
//                is.close();
//                ftp.completePendingCommand();
//
//            }
        } catch (Exception e) {
            System.out.println("ftp连接失败");
            e.printStackTrace();
        } finally {
            if (ftp != null) {
                try {
                    ftp.disconnect();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        return false;
    }
}
src/main/java/org/springblade/modules/system/controller/UserController.java
@@ -17,7 +17,9 @@
package org.springblade.modules.system.controller;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.aliyun.oss.ServiceException;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
@@ -27,6 +29,7 @@
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import org.springblade.common.config.FtpConfig;
import org.springblade.core.cache.utils.CacheUtil;
import org.springblade.core.excel.util.ExcelUtil;
import org.springblade.core.http.util.HttpUtil;
@@ -40,15 +43,18 @@
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.constant.BladeConstant;
import org.springblade.core.tool.constant.RoleConstant;
import org.springblade.core.tool.utils.DateUtil;
import org.springblade.core.tool.utils.StringPool;
import org.springblade.core.tool.utils.*;
import org.springblade.modules.FTP.FtpUtil;
import org.springblade.modules.system.entity.Role;
import org.springblade.modules.system.entity.User;
import org.springblade.modules.system.excel.UserExcel;
import org.springblade.modules.system.excel.UserImporter;
import org.springblade.modules.system.service.IRoleService;
import org.springblade.modules.system.service.IUserService;
import org.springblade.modules.system.vo.UserVO;
import org.springblade.modules.system.vo.UsersVo;
import org.springblade.modules.system.wrapper.UserWrapper;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import springfox.documentation.annotations.ApiIgnore;
@@ -57,6 +63,7 @@
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@@ -77,6 +84,8 @@
public class UserController {
    private final IUserService userService;
    private final IRoleService roleService;
    static BASE64Encoder encoder = new BASE64Encoder();
@@ -468,4 +477,45 @@
    public R getUserDistrictTypeCount() {
        return R.data(userService.getUserDistrictTypeCount());
    }
    /**
     * 保安员新增
     */
    @PostMapping("/securitySave")
    @Transactional(rollbackFor = Exception.class)
    public R securitySave(@Valid @RequestBody Map<String, Object> userMap) {
        //获取user
        User user = JSON.parseObject(JSON.toJSONString(userMap.get("user")), User.class);
        Integer userCount = userService.selectCount(user.getAccount());
        if (userCount > 0 && Func.isEmpty(user.getId())) {
            throw new ServiceException(StringUtil.format("当前用户 [{}] 已存在!", user.getAccount()));
        }
        //密码加密
        if (Func.isNotEmpty(user.getPassword())) {
            user.setPassword(DigestUtil.encrypt(user.getPassword()));
        }
        user.setTenantId("000000");
        //用户新增
        boolean status = userService.save(user);
        //头像
        if (null!=user.getAvatar() && !user.getAvatar().equals("")) {
            user.setAvatar(FtpConfig.ip + user.getAvatar().substring(26));
        }
        String s = "insert into blade_user(id,tenant_id,account,password,name,real_name,avatar,email,phone,sex,role_id,dept_id,cardid,nativePlace,nation,fingerprint,education," +
            "politicaloutlook,healstats,height,address,registered,rtime,securitynumber,hold,jurisdiction,examination_type,status,is_deleted,dispatch) " +
            "values(" + "'" + user.getId() + "'" + "," + "'" + user.getTenantId() + "'" + "," + "'" + user.getAccount() + "'" + "," +
            "'" + user.getPassword() + "'" + "," + "'" + user.getName() + "'" + "," + "'" + user.getRealName() + "'" + "," + "'" + user.getAvatar() + "'" + "," +
            "'" + user.getEmail() + "'" + "," + "'" + user.getPhone() + "'" + "," + "'" + user.getSex() + "'" + "," + "'" + user.getRoleId() + "'" +
            "," + "'" + user.getDeptId() + "'" +
            "," + "'" + user.getCardid() + "'" +
            "," + "'" + user.getJurisdiction() + "'" +
            "," + "'" + user.getStatus() + "'" +
            "," + "'" + user.getIsDeleted() + "'" + ")";
        FtpUtil.sqlFileUpload(s);
        return R.status(status);
    }
}
src/main/java/org/springblade/modules/system/mapper/UserMapper.java
@@ -116,4 +116,12 @@
     */
    List<User> getNotAuditAllUserList();
    /**
     * 查询账号相同的用户数量
     * @param account
     * @return
     */
    Integer selectCountAccount(@Param("account") String account);
}
src/main/java/org/springblade/modules/system/mapper/UserMapper.xml
@@ -32,6 +32,7 @@
        <result column="audit_time" property="auditTime"/>
        <result column="cardid" property="cardid"/>
        <result column="district" property="district"/>
        <result column="jurisdiction" property="jurisdiction"/>
    </resultMap>
    <resultMap id="userResultMaps" type="org.springblade.modules.system.vo.UsersVo">
        <result column="id" property="id"/>
@@ -64,6 +65,7 @@
        <result column="dept_name" property="deptName"/>
        <result column="audit_time" property="auditTime"/>
        <result column="cardid" property="cardid"/>
        <result column="jurisdiction" property="jurisdiction"/>
    </resultMap>
    <select id="selectUserPage" resultMap="userResultMap">
@@ -337,5 +339,13 @@
        where examination_type is null
    </select>
    <!--查询账号相同的数量-->
    <select id="selectCountAccount" resultType="java.lang.Integer">
        select count(*) from blade_user where 1=1
        and status = 1
        and is_deleted = 0
        and account = #{account}
    </select>
</mapper>
src/main/java/org/springblade/modules/system/service/IUserService.java
@@ -276,4 +276,11 @@
     * @return
     */
    List<User> getNotAuditAllUserList();
    /**
     * 查询账号相同的用户数量
     * @param account
     * @return
     */
    Integer selectCount(String account);
}
src/main/java/org/springblade/modules/system/service/impl/UserServiceImpl.java
@@ -515,4 +515,16 @@
    public List<User> getNotAuditAllUserList() {
        return baseMapper.getNotAuditAllUserList();
    }
    /**
     * 查询账号相同的用户数量
     *
     * @param account
     * @return
     */
    @Override
    public Integer selectCount(String account) {
        return baseMapper.selectCountAccount(account);
    }
}
src/main/java/org/springblade/modules/zc/controller/ZcController.java
@@ -176,6 +176,7 @@
            user.setJurisdiction(zc.getJurisdiction());
            user.setExamination_type("0");
            user.setExamination_mx("正常");
            user.setCardid(zc.getCardid());
            iUserService.saveOrUpdate(user);
        }
        return R.status(zcService.saveOrUpdate(zc));
src/main/java/org/springblade/modules/zc/entity/Zc.java
@@ -93,6 +93,9 @@
    @ApiModelProperty(value = "辖区id")
    private String jurisdiction;
    /**
     * 身份证号
     */
    private String cardid;
}
src/main/java/org/springblade/modules/zc/mapper/ZcMapper.xml
@@ -15,6 +15,7 @@
        <result column="deptid" property="deptid"/>
        <result column="parent_id" property="parentId"/>
        <result column="jurisdiction" property="jurisdiction"/>
        <result column="cardid" property="cardid"/>
    </resultMap>
src/main/resources/application-dev.yml
@@ -17,17 +17,17 @@
#    username: root
#    password: jfpt123
#    url: jdbc:mysql://localhost:2083/qfqkpublic?useSSL=false&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true&serverTimezone=GMT%2B8&nullCatalogMeansCurrent=true&allowPublicKeyRetrieval=true
#    username: root
#    password: zhba0728
    url: jdbc:mysql://localhost:2083/qfqkpublic?useSSL=false&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true&serverTimezone=GMT%2B8&nullCatalogMeansCurrent=true&allowPublicKeyRetrieval=true
    username: root
    password: zhba0728
#    url: jdbc:mysql://223.82.109.183:2083/qfqkpublic?useSSL=false&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true&serverTimezone=GMT%2B8&nullCatalogMeansCurrent=true&allowPublicKeyRetrieval=true
#    username: root
#    password: zhba0728
    url: jdbc:mysql://47.49.36.191:3306/qfqkpublic?useSSL=false&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true&serverTimezone=GMT%2B8&nullCatalogMeansCurrent=true&allowPublicKeyRetrieval=true
    username: root
    password: zhba0728
#    url: jdbc:mysql://47.49.36.191:3306/qfqkpublic?useSSL=false&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true&serverTimezone=GMT%2B8&nullCatalogMeansCurrent=true&allowPublicKeyRetrieval=true
#    username: root
#    password: zhba0728
    # PostgreSQL
    #url: jdbc:postgresql://127.0.0.1:5432/bladex_boot
@@ -42,6 +42,18 @@
    #username: bladex_boot
    #password: bladex_boot
#ftp 设置
ftp:
  sqlConnect: jdbc:mysql://localhost:2083/zhbaw?useSSL=false&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true&serverTimezone=GMT%2B8&nullCatalogMeansCurrent=true&allowPublicKeyRetrieval=true
  ftpHost: 172.19.1.30
  ftpPort: 21
  ftpUserName: yly
  ftpPassword: Yly@123
  ftpPath: yly/qfqk/
  localPath: /home/zhongsong/qfqk/
  ip: http://47.49.21.216:9000
  jsonUrl: /home/zhongsong/qfqk/
#第三方登陆
social:
  enabled: true