智慧保安后台管理-外网项目备份
Administrator
2021-08-22 bce12a18795cbab7f5426161ba452d0a6c757d4b
内网数据同步
4 files modified
143 ■■■■■ changed files
src/main/java/org/springblade/modules/FTP/FtpUtil.java 22 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/apply/controller/ApplyController.java 91 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/apply/service/impl/ApplyServiceImpl.java 22 ●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/resource/endpoint/OssEndpoint.java 8 ●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/FTP/FtpUtil.java
@@ -1,5 +1,6 @@
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;
@@ -8,6 +9,10 @@
import java.io.*;
import java.net.SocketException;
import java.util.Date;
import static org.springblade.common.constant.FtpConstant.*;
import static org.springblade.common.constant.FtpConstant.ftpPassword;
/**
 * ftp工具类
@@ -283,4 +288,21 @@
        }
    }
    /**
     * 执行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, "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);
    }
}
src/main/java/org/springblade/modules/apply/controller/ApplyController.java
@@ -464,14 +464,15 @@
            "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);
        OutJson.createJsonFile(json, "d:/", "wsql");
        String response = String.valueOf((new Date()).getTime());
        OutJson.createJsonFile(json, "d:/", "w"+response);
        FileInputStream in = null;
        try {
            in = new FileInputStream(new File("D:\\" + fileName));
            in = new FileInputStream(new File("D:\\" + "w"+response+".json"));
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
        FtpUtil.uploadFile(ftpHost, ftpPort, ftpUserName, ftpPassword, "anbao/", "/", fileName, in);
        FtpUtil.uploadFile(ftpHost, ftpPort, ftpUserName, ftpPassword, "anbao/", "/",  "w"+response+".json", in);
    }
@@ -635,6 +636,23 @@
                examPaper.setExamName(examName);
                //生成考试
                examPaperService.save(examPaper);
                Long sid = examPaper.getId();
                String format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(examPaper.getStartTime());
                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);
                //修改报名信息
                list.forEach(id ->{
                    Apply apply = new Apply();
@@ -642,6 +660,20 @@
                    apply.setExamId(examPaper.getId());
                    apply.setCandidateNo(getCandidateNo(apply));
                    applyService.updateById(apply);
                    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);
                });
            }
@@ -664,6 +696,24 @@
                examPaper.setExamName(examName);
                //生成考试
                examPaperService.save(examPaper);
                Long sid = examPaper.getId();
                String format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(examPaper.getStartTime());
                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);
                //修改报名信息
                applyIds.forEach(id ->{
                    Apply apply = new Apply();
@@ -671,6 +721,20 @@
                    apply.setExamId(examPaper.getId());
                    apply.setCandidateNo(getCandidateNo(apply));
                    applyService.updateById(apply);
                    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);
                });
            }
        }
@@ -714,8 +778,27 @@
        examScore.setUserId(apply.getUserId().toString());
        examScore.setApplyId(apply.getId());
        examScore.setExamTime(new Date());
        //新增
        //新增考试成绩
        examScoreService.save(examScore);
        //内网同步
        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) " +
            "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;
        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);
        return examScore;
    }
src/main/java/org/springblade/modules/apply/service/impl/ApplyServiceImpl.java
@@ -133,14 +133,15 @@
                        "'" + "," + "'" + apply1.getApplyStatus() + "'" + "," +"'" + apply1.getIsExam() + "'" + ");" +
                        "update blade_user set is_apply = " + "'" + user1.getIsApply() + "'" +"where id = " + "'" + user1.getId() + "'";
                    String json = JSON.toJSONString(s);
                    OutJson.createJsonFile(json, "d:/", "wsql");
                    String response = String.valueOf((new Date()).getTime());
                    OutJson.createJsonFile(json, "d:/", "w"+response);
                    FileInputStream in = null;
                    try {
                        in = new FileInputStream(new File("D:\\" + fileName));
                        in = new FileInputStream(new File("D:\\" + "w"+response+".json"));
                    } catch (FileNotFoundException e) {
                        e.printStackTrace();
                    }
                    FtpUtil.uploadFile(ftpHost, ftpPort, ftpUserName, ftpPassword, "anbao/", "/", fileName, in);
                    FtpUtil.uploadFile(ftpHost, ftpPort, ftpUserName, ftpPassword, "anbao/", "/",  "w"+response+".json", in);
                }else {
                    if (user1.getIsApply()!=1) {
                        Apply apply1 = new Apply();
@@ -162,14 +163,15 @@
                            "'" + "," + "'" + apply1.getApplyStatus() + "'" + "," +"'" + apply1.getIsExam() + "'" + ");" +
                            "update blade_user set is_apply = " + "'" + user1.getIsApply() + "'" +"where id = " + "'" + user1.getId() + "'";
                        String json = JSON.toJSONString(s);
                        OutJson.createJsonFile(json, "d:/", "wsql");
                        String response = String.valueOf((new Date()).getTime());
                        OutJson.createJsonFile(json, "d:/", "w"+response);
                        FileInputStream in = null;
                        try {
                            in = new FileInputStream(new File("D:\\" + fileName));
                            in = new FileInputStream(new File("D:\\" + "w"+response+".json"));
                        } catch (FileNotFoundException e) {
                            e.printStackTrace();
                        }
                        FtpUtil.uploadFile(ftpHost, ftpPort, ftpUserName, ftpPassword, "anbao/", "/", fileName, in);
                        FtpUtil.uploadFile(ftpHost, ftpPort, ftpUserName, ftpPassword, "anbao/", "/",  "w"+response+".json", in);
                    }
                }
            }
@@ -456,6 +458,10 @@
            //考试中
            apply1.setIsExam(3);
            baseMapper.updateById(apply1);
            String s1 =
                "update sys_apply set is_exam = " + apply1.getIsExam() + " " +"where id = " + "'" + apply1.getId() + "'";
            FtpUtil.sqlFileUpload(s1);
        }
        //模拟考
        if (apply.getExamType()==2){
@@ -464,6 +470,10 @@
            //考试中
            trainingRegistration.setIsExam(3);
            trainingRegistrationService.updateById(trainingRegistration);
            String s1 =
                "update sys_training_registration set is_exam = " + trainingRegistration.getIsExam() + " " +"where id = " + "'" + trainingRegistration.getId() + "'";
            FtpUtil.sqlFileUpload(s1);
        }
    }
src/main/java/org/springblade/modules/resource/endpoint/OssEndpoint.java
@@ -180,9 +180,9 @@
    @PostMapping("put-file-app")
    public R putFileApp(@RequestParam MultipartFile file) throws IOException, ServerException, InsufficientDataException, InternalException, InvalidResponseException, InvalidKeyException, NoSuchAlgorithmException, XmlParserException, ErrorResponseException {
        //填写你文件上传的地址以及相应信息
        String url = "http://192.168.0.109:9000";
        String access = "minioadmin";
        String secret = "minioadmin";
        String url = "http://223.82.109.183:2081";
        String access = "zhbaadmin";
        String secret = "zhbapassword";
        String bucket = "zhba";
        MinioClient minioClient =
            MinioClient.builder()
@@ -211,7 +211,7 @@
                .headers(headers)
                .build());
        in.close();
        String urls = "http://192.168.0.109:9000/zhba/" + newName;
        String urls = "http://223.82.109.183:2081/zhba/" + newName;
        return R.data(urls);
    }