钟日健
2022-04-27 ac120f258131bbc3a91f784345b19fb88dbca33e
从业记录新增修改,ftp 配置修改
4 files modified
1 files renamed
136 ■■■■■ changed files
src/main/java/org/springblade/modules/FTP/DataHanlder.java 8 ●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/FTP/FtpUtil.java 37 ●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/FTP/Monitor.java 32 ●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/FTP/MyAsyncService.java 55 ●●●●● patch | view | raw | blame | history
src/main/resources/application-test.yml 4 ●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/FTP/DataHanlder.java
@@ -88,6 +88,8 @@
                //去新增
                boolean save = hanlder.userService.save(user2);
                if (save){
                    //异步新增从业记录
                    hanlder.myAsyncService.insertExperience(user2);
                    //异步审查
                    hanlder.myAsyncService.checkUserExamineByCardNo(user2);
                }
@@ -248,8 +250,8 @@
            //内网同步
            String s = "insert into sys_experience(id,name,entryTime,departureTime,leaving,cardId,companyname,securityId) " +
                "values(" + "'" + experience.getId() + "'" + "," +
                "'" + experience.getName() + "'" + "," +
                "values(" + "'" + experience.getId() + "'" +
                "," + "'" + experience.getName() + "'" +
                "," + "'" + new SimpleDateFormat("yyyy-MM-dd").format(experience.getEntrytime()) + "'" +
                "," + "'" + new SimpleDateFormat("yyyy-MM-dd").format(experience.getDeparturetime()) + "'" +
                "," + "'" + experience.getLeaving() + "'" +
@@ -289,6 +291,8 @@
                states = false;
                user.setHold("2");
            }
        }else {
            states = true;
        }
        if (!states) {
src/main/java/org/springblade/modules/FTP/FtpUtil.java
@@ -288,23 +288,7 @@
            }
        }
    }
    /**
     * 执行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, "nsql"+response1);
        FileInputStream in1 = null;
        try {
            in1 = new FileInputStream(new File(localPath + "nsql"+response1+".json"));
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
        FtpUtil.uploadFile(ftpHost, ftpPort, ftpUserName, ftpPassword, ftpPath, "/",  "nsql"+response1+".json", in1);
//        MysqlCenlint.deletess("nsql"+response1+".json");
    }
    /**
     *
     * 解压zip 包
@@ -357,6 +341,23 @@
        }
    }
    /**
     * 执行sql 上传
     * @param obj sql
     */
    public static void sqlFileUpload(String obj){
        String json1 = JSON.toJSONString(obj);
        String response1 = String.valueOf((new Date()).getTime());
        OutJson.createJsonFile(json1, localPath, "nsql"+response1);
        FileInputStream in1 = null;
        try {
            in1 = new FileInputStream(new File(localPath + "nsql"+response1+".json"));
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
        FtpUtil.uploadFile(ftpHost, ftpPort, ftpUserName, ftpPassword, ftpPath, "/",  "nsql"+response1+".json", in1);
        MysqlCenlint.deletess("nsql"+response1+".json");
    }
    /**
     * 执行 对象数据(用户,报名对象信息等) 上传
@@ -373,7 +374,7 @@
            e.printStackTrace();
        }
        FtpUtil.uploadFile(ftpHost, ftpPort, ftpUserName, ftpPassword, ftpPath, "/",  "n"+response1+".json", in1);
//        MysqlCenlint.deletess("n"+response1+".json");
        MysqlCenlint.deletess("n"+response1+".json");
    }
src/main/java/org/springblade/modules/FTP/Monitor.java
File was renamed from src/main/java/org/springblade/modules/FTP/monitor.java
@@ -14,11 +14,7 @@
@Component
public class monitor {
    //文件名
    //private static String fileName = "nsql.json";
public class Monitor {
    @Scheduled(cron = "*/1 * * * * ?")
    public static boolean isFTPFileExist() {
@@ -46,17 +42,6 @@
            // 设置编码格式
            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);
@@ -97,6 +82,7 @@
                            }
                            //删除本地文件
                            MysqlCenlint.deletess(fileName);
                            //删除 ftp 文件
                            FtpUtil.deleteFile(ftpHost, ftpPort, ftpUserName, ftpPassword, "anbao/", fileName);
                        }else if(substring1.equals("o")){
                            //获取对象字符串
@@ -105,8 +91,11 @@
                            DataHanlder.handler(json);
                            //删除本地文件
                            MysqlCenlint.deletess(fileName);
                            //删除 ftp 文件
                            FtpUtil.deleteFile(ftpHost, ftpPort, ftpUserName, ftpPassword, "anbao/", fileName);
                        }
                        //删除本地文件,ftp 文件没有对应读取的不删除
                        MysqlCenlint.deletess(fileName);
                        is.close();
                        ftp.completePendingCommand();
                    }
@@ -118,26 +107,15 @@
            MysqlCenlint.deletess(fileName);
            FtpUtil.deleteFile(ftpHost, ftpPort, ftpUserName, ftpPassword, "anbao/", fileName);
            e.printStackTrace();
        } finally {
            if (ftp != null) {
                try {
                    ftp.disconnect();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        return false;
    }
}
src/main/java/org/springblade/modules/FTP/MyAsyncService.java
@@ -2,14 +2,20 @@
import org.json.JSONArray;
import org.json.JSONObject;
import org.springblade.common.utils.DesensitizedUtil;
import org.springblade.common.utils.InvestigateUtil;
import org.springblade.modules.experience.entity.Experience;
import org.springblade.modules.experience.service.IExperienceService;
import org.springblade.modules.system.entity.Dept;
import org.springblade.modules.system.entity.User;
import org.springblade.modules.system.service.IDeptService;
import org.springblade.modules.system.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import javax.annotation.PostConstruct;
import java.text.SimpleDateFormat;
import java.util.Date;
/**
@@ -21,7 +27,11 @@
    @Autowired
    private IUserService userService;
    @Autowired
    private IDeptService iDeptService;
    @Autowired
    private IExperienceService experienceService;
    /**
     * FTP
@@ -38,11 +48,8 @@
     */
    @Async
    public void checkUserExamineByCardNo(User user0){
        User byId = userService.getById(user0.getId());
        //如果是保安员
        if (user0.getRoleId().equals("1412226235153731586")){
            //读取身份证号
            String cardid = user0.getCardid();
            //创建用户对象
            User user = new User();
            user.setId(user.getId());
@@ -103,4 +110,46 @@
    }
    /**
     * 异步新增用户从业记录
     * @param user
     */
    @Async
    public void insertExperience(User user) {
        //根据公司名查询单位
        Dept dept = iDeptService.getById(user.getDeptId());
        Experience experience = new Experience();
        experience.setCompanyname(dept.getDeptName());
        //新增
        if (null != user.getRtime()) {
            experience.setEntrytime(user.getRtime());
        } else {
            experience.setEntrytime(new Date());
        }
        experience.setDeparturetime(new Date());
        experience.setName(user.getRealName());
        if (null != user.getReasonForLeav() && !user.getReasonForLeav().equals("")) {
            experience.setLeaving(user.getReasonForLeav());
        }
        experience.setCardid(user.getCardid());
        experience.setSecurityid(user.getId().toString());
        //新增
        experienceService.save(experience);
        // 身份证号脱敏
        String cardid = DesensitizedUtil.desensitizedIdNumberBy4(user.getCardid());
        //内网同步
        String s = "insert into sys_experience(id,name,entryTime,departureTime,leaving,cardId,companyname,securityId) " +
            "values(" + "'" + experience.getId() + "'" +
            "," + "'" + experience.getName() + "'" +
            "," + "'" + new SimpleDateFormat("yyyy-MM-dd").format(experience.getEntrytime()) + "'" +
            "," + "'" + new SimpleDateFormat("yyyy-MM-dd").format(experience.getDeparturetime()) + "'" +
            "," + "'" + experience.getLeaving() + "'" +
            "," + "'" + cardid + "'" +
            "," + "'" + experience.getCompanyname() + "'" +
            "," + "'" + experience.getSecurityid() + "'"
            + ")";
        //向外网推送
        FTP(s);
    }
}
src/main/resources/application-test.yml
@@ -28,9 +28,9 @@
  ftpUserName: arsn
  ftpPassword: 123456
  ftpPath: anbao/
  localPath: D:\anbao\
  localPath: E:\anbao\
  minioPath: D:\ftptp\
  jsonUrl: D:\anbao\
  jsonUrl: E:\anbao\
  sqlUsername: zhbaw
  sqlPassword: Zhba@0426