智慧保安后台管理-外网
Administrator
2022-04-27 dd899673f3ff75ad59ae43afd124ef8ef0fc0180
ftp 同步修改调整
4 files modified
140 ■■■■■ changed files
src/main/java/org/springblade/modules/FTP/DataHandler.java 3 ●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/FTP/Monitor.java 128 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/system/controller/UserController.java 7 ●●●●● patch | view | raw | blame | history
src/main/resources/application.yml 2 ●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/FTP/DataHandler.java
@@ -65,6 +65,7 @@
                //用户数处理
                User user = handlerUserInfo(uuid);
                user.setId(result.getUserId());
                user.setStatus(1);
                //插入数据库
//                boolean save = handler.userService.insert(user);
                boolean save = handler.userService.save(user);
@@ -93,7 +94,7 @@
                //插入数据库
                boolean save = handler.userService.save(user);
                //失败,返回保安员证编号校验失败消息
                return new Result(202,null,result.getMsg(),null);
                return new Result(203,null,result.getMsg(),null);
            }else if (result.getCode()==204){
                //修改
                //用户数处理
src/main/java/org/springblade/modules/FTP/Monitor.java
@@ -21,8 +21,6 @@
@Component
public class Monitor {
    /**
     * 读取文件(对象)
     * @param uuid 随机数
@@ -85,6 +83,10 @@
                            //返回
                            return new Result(202,null,result.getMsg(),null);
                        }
                        if (result.getCode()==203) {
                            //返回
                            return new Result(203,null,result.getMsg(),null);
                        }
                    }
                }
                return new Result(400,null,"未读取到对应的文件",null);
@@ -105,10 +107,10 @@
    }
    /**
     * 读取文件
     * 读取内外推送的文件,每30秒读取一次
     * @return
     */
    //    @Scheduled(cron = "*/30 * * * * ?")
    @Scheduled(cron = "*/30 * * * * ?")
    public static boolean isFTPFileExist() {
        FTPClient ftp = new FTPClient();
        try {
@@ -137,110 +139,62 @@
                return false;
            }
            else {
                for (FTPFile file : files){
                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);
                    if (null == is) {
                        return false;
                    } else {
                        String substring1 = fileName.substring(0, 4);
                        if (substring1.equals("nsql")) {
                            //把文件下载到本地
                            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);
                                }
                            }
                            //修改
                            else if (substring.equals("up")) {
                                MysqlCenlint.update(sqls);
                            }
                            //删除
                            else {
                                MysqlCenlint.delete(sqls);
                            }
                            //删除本地服务器文件
                            MysqlCenlint.deletess(fileName);
                            //删除 ftp 服务器文件
                            FtpUtil.deleteFile(ftpHost, ftpPort, ftpUserName, ftpPassword, ftpPath, fileName);
                        }
                        //删除本地文件
                        //MysqlCenlint.deletes(fileName);
                        MysqlCenlint.deletess(fileName);
                        FtpUtil.deleteFile(ftpHost, ftpPort, ftpUserName, ftpPassword, ftpPath, fileName);
                        //关闭流
                        is.close();
                        ftp.completePendingCommand();
                    }
                    return true;
                }
                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
@@ -1391,6 +1391,7 @@
        user.setDispatch("1");
        user.setExaminationType("0");
        user.setAccount(user.getRealName());
        user.setStatus(1);
        //密码加密
        if (Func.isNotEmpty(user.getCardid())) {
@@ -1450,6 +1451,9 @@
            }else if (result.getCode()==202){
                flag = 3;
                break;
            }else if (result.getCode()==203){
                flag = 4;
                break;
            }else{
                //计数
                count++;
@@ -1464,6 +1468,9 @@
            return R.data(200, null, "新增成功!");
        }else if (flag==3){
            throw new ServiceException(result.getMsg());
        }else if (flag==4){
//            return R.data(201, null, "保安证编号不匹配,请核实!也可通过提供保安证件信息提交核实申请!");
            return R.data(201, null, "保安证编号不匹配,请核实!");
        }else{
            //返回
            return R.data(400, null, "新增失败!");
src/main/resources/application.yml
@@ -116,7 +116,7 @@
#报表配置
report:
  enabled: true
  enabled: false
  database:
    provider:
      prefix: blade-