Administrator
2021-08-23 bf93d530532a5910dae6676d23e13aed607baef9
数据同步修改
7 files modified
224 ■■■■■ changed files
src/main/java/org/springblade/common/constant/FtpConstant.java 31 ●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/FTP/FtpUtil.java 6 ●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/FTP/MysqlCenlint.java 29 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/FTP/monitor.java 27 ●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/apply/controller/ApplyController.java 100 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/apply/service/impl/ApplyServiceImpl.java 23 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/information/controller/InformationController.java 8 ●●●● patch | view | raw | blame | history
src/main/java/org/springblade/common/constant/FtpConstant.java
@@ -6,9 +6,24 @@
public interface FtpConstant {
    /**
     * sql connect
     */
//    String sql_connect_dev = "jdbc:mysql://223.82.109.183:2083/zhbaw";
    /**
     * sql connect
     */
    String sql_connect_dev = "jdbc:mysql://localhost:2083/zhbaw";
    /**
     * ftp服务器IP地址
     */
    String ftpHost = "192.168.0.105";
//    String ftpHost_dev = "192.168.0.105";
    /**
     * ftp服务器IP地址
     */
    String ftpHost_dev = "172.19.1.30";
    /**
     * ftp服务器端口
@@ -25,13 +40,15 @@
     */
    String ftpPassword = "Yly@123";
    /**
     * ftp服务器路径
     */
    String ftpPath = "yly/anbao/";
    /**
     * 本地路径
     */
    String localPath = "D:\\anbao";
    /**
     * 文件名
     */
    String fileName = "wsql.json";
    String localPath = "/home/zhongsong/anbao";
//    String localPath = "D:\\anbao";
}
src/main/java/org/springblade/modules/FTP/FtpUtil.java
@@ -295,14 +295,14 @@
    public static void sqlFileUpload(String s1){
        String json1 = JSON.toJSONString(s1);
        String response1 = String.valueOf((new Date()).getTime());
        OutJson.createJsonFile(json1, "d:/", "w"+response1);
        OutJson.createJsonFile(json1, localPath, "w"+response1);
        FileInputStream in1 = null;
        try {
            in1 = new FileInputStream(new File("D:\\" + "w"+response1+".json"));
            in1 = new FileInputStream(new File(localPath + "w"+response1+".json"));
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
        FtpUtil.uploadFile(ftpHost, ftpPort, ftpUserName, ftpPassword, "anbao/", "/",  "w"+response1+".json", in1);
        FtpUtil.uploadFile(ftpHost_dev, ftpPort, ftpUserName, ftpPassword, ftpPath, "/",  "w"+response1+".json", in1);
    }
}
src/main/java/org/springblade/modules/FTP/MysqlCenlint.java
@@ -7,6 +7,9 @@
import java.sql.PreparedStatement;
import java.sql.SQLException;
import static org.springblade.common.constant.FtpConstant.localPath;
import static org.springblade.common.constant.FtpConstant.sql_connect_dev;
public class MysqlCenlint {
    /**
@@ -18,7 +21,7 @@
            int ColumnCount;
            //int RowCount;
            String driver = "com.mysql.jdbc.Driver";
            String url = "jdbc:mysql://223.82.109.183:2083/zhba"; //换成要连接的数据库信息
            String url = sql_connect_dev; //换成要连接的数据库信息
            String user = "root";
            String password = "zhba0728";
            Class.forName ( driver );
@@ -47,7 +50,7 @@
            int ColumnCount;
            //int RowCount;
            String driver = "com.mysql.jdbc.Driver";
            String url = "jdbc:mysql://223.82.109.183:2083/zhba"; //换成要连接的数据库信息
            String url = sql_connect_dev; //换成要连接的数据库信息
            String user = "root";
            String password = "zhba0728";
            Class.forName ( driver );
@@ -76,7 +79,7 @@
            int ColumnCount;
            //int RowCount;
            String driver = "com.mysql.jdbc.Driver";
            String url = "jdbc:mysql://223.82.109.183:2083/zhba"; //换成要连接的数据库信息
            String url = sql_connect_dev; //换成要连接的数据库信息
            String user = "root";
            String password = "zhba0728";
            Class.forName ( driver );
@@ -96,17 +99,17 @@
        }
    }
    /**
     * 删除本地文件
     */
    public  static  void deletes(String fileName){
        File file = new File("D:\\"+fileName);
        if (file.isFile() && file.exists()) {
            file.delete();
        }
    }
//    /**
//     * 删除本地文件
//     */
//    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("D:\\anbao\\"+fileName);
        File file = new File(localPath+fileName);
        if (file.isFile() && file.exists()) {
            file.delete();
        }
src/main/java/org/springblade/modules/FTP/monitor.java
@@ -10,25 +10,12 @@
import java.io.IOException;
import java.io.InputStream;
import static org.springblade.common.constant.FtpConstant.*;
@Component
public class monitor {
    //ftp服务器IP地址
    private static String ftpHost = "192.168.0.105";
    //ftp服务器端口
    private static int ftpPort = 21;
    //ftp服务器用户名
    private static String ftpUserName = "yly";
    //ftp服务器密码
    private static String ftpPassword = "Yly@123";
    //ftp服务器路径
    private static String ftpPath = "anbao/";
    //本地路径
    private static String localPath = "D:\\anbao";
    //文件名
    //private static String fileName = "nsql.json";
    @Scheduled(cron = "*/30 * * * * ?")
//    @Scheduled(cron = "*/30 * * * * ?")
    public static boolean isFTPFileExist() {
        FTPClient ftp = new FTPClient();
@@ -37,7 +24,7 @@
            // 连接ftp服务器
            ftp.connect(ftpHost, ftpPort);
            ftp.connect(ftpHost_dev, ftpPort);
            // 登陆
@@ -87,7 +74,7 @@
                    String substring1 = fileName.substring(0, 1);
                    if (substring1.equals("n")){
                        //把文件下载到本地
                        FtpUtil.downloadFtpFile(ftpHost, ftpUserName, ftpPassword, ftpPort, ftpPath, localPath, fileName);
                        FtpUtil.downloadFtpFile(ftpHost_dev, ftpUserName, ftpPassword, ftpPort, ftpPath, localPath, fileName);
                        //
                        String s = OutJson.TestJson(fileName);
                        //sql语句
@@ -111,9 +98,9 @@
                            }
                        }
                        //删除本地文件
                        MysqlCenlint.deletes(fileName);
                        //MysqlCenlint.deletes(fileName);
                        MysqlCenlint.deletess(fileName);
                        FtpUtil.deleteFile(ftpHost, ftpPort, ftpUserName, ftpPassword, "anbao/", fileName);
                        FtpUtil.deleteFile(ftpHost_dev, ftpPort, ftpUserName, ftpPassword, "anbao/", fileName);
                        is.close();
                        ftp.completePendingCommand();
                    }
src/main/java/org/springblade/modules/apply/controller/ApplyController.java
@@ -19,7 +19,6 @@
import org.springblade.core.tool.utils.Func;
import org.springblade.modules.FTP.FtpUtil;
import org.springblade.modules.FTP.OutJson;
import org.springblade.modules.FTP.monitor;
import org.springblade.modules.apply.entity.Apply;
import org.springblade.modules.apply.excel.ApplyExcel;
import org.springblade.modules.apply.excel.ApplyImporter;
@@ -147,16 +146,7 @@
            "values(" + "'" + id + "'" + "," + "'" + apply.getUserId() + "'" + "," + "'" + formatStr +
            "'" + "," + "'" + apply.getApplyStatus() + "'" + "," +"'" + apply.getIsExam() + "'" + ");" +
            "update blade_user set is_apply = " + user1.getIsApply() + " " +"where id = " + "'" + user1.getId() + "'";
        String json = JSON.toJSONString(s);
        String response = String.valueOf((new Date()).getTime());
        OutJson.createJsonFile(json, "d:/", "w"+response);
        FileInputStream in = null;
        try {
            in = new FileInputStream(new File("D:\\" + "w"+response+".json"));
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
        FtpUtil.uploadFile(ftpHost, ftpPort, ftpUserName, ftpPassword, "anbao/", "/",  "w"+response+".json", in);
        FtpUtil.sqlFileUpload(s);
    }
@@ -463,16 +453,7 @@
        String s =
            "update sys_apply set apply_status = " + apply.getApplyStatus() + " " +"where id = " + "'" + apply.getId() + "';" +
                "update blade_user set is_apply = " + user.getIsApply() + " " +"where id = " + "'" + user.getId() + "'";
        String json = JSON.toJSONString(s);
        String response = String.valueOf((new Date()).getTime());
        OutJson.createJsonFile(json, "d:/", "w"+response);
        FileInputStream in = null;
        try {
            in = new FileInputStream(new File("D:\\" + "w"+response+".json"));
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
        FtpUtil.uploadFile(ftpHost, ftpPort, ftpUserName, ftpPassword, "anbao/", "/",  "w"+response+".json", in);
        FtpUtil.sqlFileUpload(s);
    }
@@ -642,16 +623,7 @@
                String s = "insert into ksxt_exam(id,exam_name,exam_type,start_time) " +
                    "values(" + "'" + sid + "'" + "," + "'" + examPaper.getExamName() + "'" + "," + "'" + examPaper.getExamType() +
                    "'" + ","  +"'" + format + "'" + ")";
                String json = JSON.toJSONString(s);
                String response = String.valueOf((new Date()).getTime());
                OutJson.createJsonFile(json, "d:/", "w"+response);
                FileInputStream in = null;
                try {
                    in = new FileInputStream(new File("D:\\" + "w"+response+".json"));
                } catch (FileNotFoundException e) {
                    e.printStackTrace();
                }
                FtpUtil.uploadFile(ftpHost, ftpPort, ftpUserName, ftpPassword, "anbao/", "/",  "w"+response+".json", in);
                FtpUtil.sqlFileUpload(s);
                //修改报名信息
                list.forEach(id ->{
@@ -664,16 +636,7 @@
                    String s1 =
                        "update sys_apply set exam_id = " + apply.getExamId() + "candidate_no = " + "'" + apply.getCandidateNo() + "'" +
                            " " +"where id = " + "'" + apply.getId() + "'";
                    String json1 = JSON.toJSONString(s1);
                    String response1 = String.valueOf((new Date()).getTime());
                    OutJson.createJsonFile(json1, "d:/", "w"+response1);
                    FileInputStream in1 = null;
                    try {
                        in1 = new FileInputStream(new File("D:\\" + "w"+response1+".json"));
                    } catch (FileNotFoundException e) {
                        e.printStackTrace();
                    }
                    FtpUtil.uploadFile(ftpHost, ftpPort, ftpUserName, ftpPassword, "anbao/", "/",  "w"+response1+".json", in1);
                    FtpUtil.sqlFileUpload(s1);
                });
            }
@@ -702,16 +665,7 @@
                String s = "insert into ksxt_exam(id,exam_name,exam_type,start_time) " +
                    "values(" + "'" + sid + "'" + "," + "'" + examPaper.getExamName() + "'" + "," + "'" + examPaper.getExamType() +
                    "'" + ","  +"'" + format + "'" + ")";
                String json = JSON.toJSONString(s);
                String response = String.valueOf((new Date()).getTime());
                OutJson.createJsonFile(json, "d:/", "w"+response);
                FileInputStream in = null;
                try {
                    in = new FileInputStream(new File("D:\\" + "w"+response+".json"));
                } catch (FileNotFoundException e) {
                    e.printStackTrace();
                }
                FtpUtil.uploadFile(ftpHost, ftpPort, ftpUserName, ftpPassword, "anbao/", "/",  "w"+response+".json", in);
                FtpUtil.sqlFileUpload(s);
                //修改报名信息
@@ -725,16 +679,7 @@
                    String s1 =
                        "update sys_apply set exam_id = " + apply.getExamId() + ",candidate_no = " + "'" + apply.getCandidateNo() + "'" +
                            " " +"where id = " + "'" + apply.getId() + "'";
                    String json1 = JSON.toJSONString(s1);
                    String response1 = String.valueOf((new Date()).getTime());
                    OutJson.createJsonFile(json1, "d:/", "w"+response1);
                    FileInputStream in1 = null;
                    try {
                        in1 = new FileInputStream(new File("D:\\" + "w"+response1+".json"));
                    } catch (FileNotFoundException e) {
                        e.printStackTrace();
                    }
                    FtpUtil.uploadFile(ftpHost, ftpPort, ftpUserName, ftpPassword, "anbao/", "/",  "w"+response1+".json", in1);
                    FtpUtil.sqlFileUpload(s1);
                });
            }
        }
@@ -783,23 +728,40 @@
        //内网同步
        Long sid = examScore.getId();
        String format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(examScore.getExamTime());
        String s = "insert into ksxt_exam(id,exam_time,user_id,exam_id,apply_id) " +
        String s = "insert into exam_score(id,exam_time,user_id,exam_id,apply_id) " +
            "values(" + "'" + sid + "'" + "," + "'" +
            format + "'" + "," + "'" +
            examScore.getUserId() +"'" + ","  +"'" +
            examScore.getExamId() +"'" + ","  +"'" +
            examScore.getApplyId() + "'" + ")";
        String json = JSON.toJSONString(s);
        String response = String.valueOf((new Date()).getTime());
        OutJson.createJsonFile(json, "d:/", "w"+response);
        FileInputStream in = null;
        FtpUtil.sqlFileUpload(s);
        return examScore;
    }
    /**
     * test
     * @return
     */
    @GetMapping("/test")
    public Object test(){
        String s1 = "insert into exam_score(id,exam_id,apply_id) values(223,88,315)";
        String s2 = "111222333";
        String s3 = "select * from ksxt_exam";
        FtpUtil.sqlFileUpload(s1);
        FtpUtil.sqlFileUpload(s2);
        String json1 = JSON.toJSONString(s3);
        String response1 = String.valueOf((new Date()).getTime());
        OutJson.createJsonFile(json1, localPath, "f"+response1);
        FileInputStream in1 = null;
        try {
            in = new FileInputStream(new File("D:\\" + "w"+response+".json"));
            in1 = new FileInputStream(new File(localPath + "f"+response1+".json"));
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
        FtpUtil.uploadFile(ftpHost, ftpPort, ftpUserName, ftpPassword, "anbao/", "/",  "w"+response+".json", in);
        return examScore;
        FtpUtil.uploadFile(ftpHost_dev, ftpPort, ftpUserName, ftpPassword, ftpPath, "/",  "f"+response1+".json", in1);
        return "成功";
    }
src/main/java/org/springblade/modules/apply/service/impl/ApplyServiceImpl.java
@@ -41,7 +41,6 @@
import java.util.*;
import static org.springblade.common.constant.FtpConstant.*;
import static org.springblade.common.constant.FtpConstant.fileName;
/**
 * 考试报名服务实现类
@@ -132,16 +131,7 @@
                        "values(" + "'" + id + "'" + "," + "'" + apply1.getUserId() + "'" + "," + "'" + formatStr +
                        "'" + "," + "'" + apply1.getApplyStatus() + "'" + "," +"'" + apply1.getIsExam() + "'" + ");" +
                        "update blade_user set is_apply = " + "'" + user1.getIsApply() + "'" +"where id = " + "'" + user1.getId() + "'";
                    String json = JSON.toJSONString(s);
                    String response = String.valueOf((new Date()).getTime());
                    OutJson.createJsonFile(json, "d:/", "w"+response);
                    FileInputStream in = null;
                    try {
                        in = new FileInputStream(new File("D:\\" + "w"+response+".json"));
                    } catch (FileNotFoundException e) {
                        e.printStackTrace();
                    }
                    FtpUtil.uploadFile(ftpHost, ftpPort, ftpUserName, ftpPassword, "anbao/", "/",  "w"+response+".json", in);
                    FtpUtil.sqlFileUpload(s);
                }else {
                    if (user1.getIsApply()!=1) {
                        Apply apply1 = new Apply();
@@ -162,16 +152,7 @@
                            "values(" + "'" + id + "'" + "," + "'" + apply1.getUserId() + "'" + "," + "'" + formatStr +
                            "'" + "," + "'" + apply1.getApplyStatus() + "'" + "," +"'" + apply1.getIsExam() + "'" + ");" +
                            "update blade_user set is_apply = " + "'" + user1.getIsApply() + "'" +"where id = " + "'" + user1.getId() + "'";
                        String json = JSON.toJSONString(s);
                        String response = String.valueOf((new Date()).getTime());
                        OutJson.createJsonFile(json, "d:/", "w"+response);
                        FileInputStream in = null;
                        try {
                            in = new FileInputStream(new File("D:\\" + "w"+response+".json"));
                        } catch (FileNotFoundException e) {
                            e.printStackTrace();
                        }
                        FtpUtil.uploadFile(ftpHost, ftpPort, ftpUserName, ftpPassword, "anbao/", "/",  "w"+response+".json", in);
                        FtpUtil.sqlFileUpload(s);
                    }
                }
            }
src/main/java/org/springblade/modules/information/controller/InformationController.java
@@ -197,13 +197,7 @@
            "'" + information.getContacts() + "'" + "," + "'" + information.getContactscell() + "'" + ");" +
            "insert into blade_dept(id,parent_id,tenant_id,dept_name,ancestors,dept_category) values(" + "'" + information.getDepartmentid() + "'" + "," + "'" + dept.getParentId() + "'" + ","
            + "'" + dept.getTenantId() + "'" + "," + "'" + information.getEnterprisename() + "'" + "," + "'" + dept.getAncestors() + "'" + "," + "'" + dept.getDeptCategory() + "'" + ")";
        Object o = s;
        String json = JSON.toJSONString(o);
        //转换提日期输出格式
        String response = String.valueOf((new Date()).getTime());
        OutJson.createJsonFile(json, "d:/", "w"+response);
        FileInputStream in = new FileInputStream(new File("D:\\" + "w"+response+".json"));
        FtpUtil.uploadFile(ftpHost, ftpPort, ftpUserName, ftpPassword, "anbao/", "/",  "w"+response+".json", in);
        FtpUtil.sqlFileUpload(s);
        return R.success("成功");
    }