8 files modified
2 files added
| | |
| | | */ |
| | | public static String minioPath; |
| | | |
| | | /** |
| | | * 数据库连接用户名 |
| | | */ |
| | | public static String sqlUsername; |
| | | |
| | | |
| | | /** |
| | | * 数据库连接密码 |
| | | */ |
| | | public static String sqlPassword; |
| | | |
| | | |
| | | public static String jsonUrl; |
| | | public static List list; |
| | |
| | | FtpConfig.jsonUrl = jsonUrl; |
| | | } |
| | | |
| | | |
| | | public void setSqlUsername(String sqlUsername) { |
| | | FtpConfig.sqlUsername = sqlUsername; |
| | | } |
| | | |
| | | public void setSqlPassword(String sqlPassword) { |
| | | FtpConfig.sqlPassword = sqlPassword; |
| | | } |
| | | |
| | | public void setList(List list){ |
| | | FtpConfig.list=list; |
| | | } |
| New file |
| | |
| | | package org.springblade.modules.FTP; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import liquibase.pro.packaged.M; |
| | | import org.springblade.core.mp.support.Condition; |
| | | import org.springblade.core.tool.api.R; |
| | | import org.springblade.modules.system.entity.User; |
| | | import org.springblade.modules.system.service.IUserService; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import javax.annotation.PostConstruct; |
| | | import java.util.Arrays; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | @Component |
| | | public class DataHanlder { |
| | | |
| | | @Autowired |
| | | private IUserService userService; |
| | | |
| | | //声明对象 |
| | | private static DataHanlder hanlder; |
| | | |
| | | /** |
| | | * 初始化 |
| | | */ |
| | | @PostConstruct |
| | | public void init(){ |
| | | hanlder = this; |
| | | hanlder.userService = this.userService; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 数据处理 |
| | | * @param json |
| | | */ |
| | | public static void handler(String json){ |
| | | //以分号分割 |
| | | List<String> list = Arrays.asList(json.split(";")); |
| | | //对象转换 |
| | | for (String s : list) { |
| | | Map map = JSON.parseObject(s, Map.class); |
| | | Object user = map.get("user"); |
| | | User user1 = JSON.parseObject(user.toString(), User.class); |
| | | //获取 uuid |
| | | String uuid = user1.getReasonForLeav(); |
| | | //用户数据校验 |
| | | R result = userCheckOut(user1); |
| | | //创建返回对象 |
| | | Result result1 = new Result(); |
| | | if (result.getCode()==200){ |
| | | user1.setReasonForLeav(""); |
| | | //去新增 |
| | | hanlder.userService.save(user1); |
| | | //设置返回结果 |
| | | result1.setCode(200); |
| | | result1.setUserId(user1.getId()); |
| | | result1.setMsg("新增成功"); |
| | | }else if (result.getCode()==201){ |
| | | //去修改 |
| | | user1.setReasonForLeav(""); |
| | | User data =(User) result.getData(); |
| | | user1.setId(data.getId()); |
| | | hanlder.userService.updateById(user1); |
| | | //设置返回结果 |
| | | result1.setCode(201); |
| | | result1.setUserId(user1.getId()); |
| | | result1.setMsg("修改成功"); |
| | | }else { |
| | | //不新增,不修改 |
| | | //设置返回结果 |
| | | result1.setCode(400); |
| | | result1.setUserId(null); |
| | | result1.setMsg(result.getMsg()); |
| | | } |
| | | Map<String, Object> map1 = new HashMap<>(1); |
| | | map1.put(uuid,result1); |
| | | //向外网发送数据 |
| | | FtpUtil.objectFileUpload(map1); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 用户校验 |
| | | * @param user |
| | | */ |
| | | private static R userCheckOut(User user) { |
| | | //1. 校验是否有重复导入 |
| | | User user1 = new User(); |
| | | user1.setCardid(user.getCardid()); |
| | | user1.setStatus(1); |
| | | user1.setIsDeleted(0); |
| | | User one = hanlder.userService.getOne(Condition.getQueryWrapper(user1)); |
| | | if (null!=one){ |
| | | //判断单位是否一致 |
| | | if (one.getDeptId().equals(user.getDeptId())){ |
| | | R.data(400,null,user.getRealName() + "已在其他单位导入"); |
| | | }else { |
| | | R.data(201,one,"已在本单位导入"); |
| | | } |
| | | } |
| | | return R.data(200,null,""); |
| | | } |
| | | |
| | | |
| | | } |
| | |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 执行 对象数据(用户,报名对象信息等) 上传 |
| | | * @param obj 对象信息 |
| | | */ |
| | | public static void objectFileUpload(Object obj){ |
| | | String json1 = JSON.toJSONString(obj); |
| | | String response1 = String.valueOf((new Date()).getTime()); |
| | | OutJson.createJsonFile(json1, localPath, "n"+response1); |
| | | FileInputStream in1 = null; |
| | | try { |
| | | in1 = new FileInputStream(new File(localPath + "n"+response1+".json")); |
| | | } catch (FileNotFoundException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | FtpUtil.uploadFile(ftpHost, ftpPort, ftpUserName, ftpPassword, ftpPath, "/", "n"+response1+".json", in1); |
| | | // MysqlCenlint.deletess("n"+response1+".json"); |
| | | } |
| | | |
| | | |
| | | |
| | | } |
| | |
| | | import java.sql.SQLException; |
| | | import java.util.Date; |
| | | |
| | | import static org.springblade.common.config.FtpConfig.localPath; |
| | | import static org.springblade.common.config.FtpConfig.sqlConnect; |
| | | import static org.springblade.common.config.FtpConfig.*; |
| | | |
| | | @Component |
| | | public class MysqlCenlint { |
| | |
| | | public static void sqlConnect(String sql,Integer type){ |
| | | String driver = "com.mysql.cj.jdbc.Driver"; |
| | | String url = sqlConnect; //换成要连接的数据库信息 |
| | | String user = "root"; |
| | | String password = "zhba0728"; |
| | | String user = sqlUsername; |
| | | String password = sqlPassword; |
| | | Connection conn = null; |
| | | PreparedStatement ps = null; |
| | | try { |
| | | Class.forName ( driver ); |
| | | conn = (Connection) DriverManager.getConnection ( url, user, password ); |
| | | conn = DriverManager.getConnection ( url, user, password ); |
| | | if (!conn.isClosed ()) { |
| | | System.out.println ( "数据库连接成功:" ); |
| | | String sqls = sql; |
| | |
| | | return result.toString(); |
| | | } |
| | | /** |
| | | * 删除文件 |
| | | * 去除空格 \ 等 |
| | | * @param str |
| | | * @return |
| | | */ |
| New file |
| | |
| | | package org.springblade.modules.FTP; |
| | | |
| | | import lombok.Data; |
| | | |
| | | /** |
| | | * 响应对象 |
| | | * @author zhongrj |
| | | * @since 2022-04-26 |
| | | */ |
| | | @Data |
| | | public class Result { |
| | | private Integer code; |
| | | |
| | | private Long userId; |
| | | |
| | | private String msg; |
| | | } |
| | |
| | | //private static String fileName = "nsql.json"; |
| | | |
| | | |
| | | @Scheduled(cron = "*/30 * * * * ?") |
| | | @Scheduled(cron = "*/1 * * * * ?") |
| | | public static boolean isFTPFileExist() { |
| | | |
| | | FTPClient ftp = new FTPClient(); |
| | | String fileName = null; |
| | | try { |
| | | |
| | | // System.out.println("ftpHost = " + ftpHost); |
| | | // 连接ftp服务器 |
| | | |
| | | ftp.connect(ftpHost, ftpPort); |
| | | |
| | | // 登陆 |
| | | |
| | | ftp.login(ftpUserName, ftpPassword); |
| | | |
| | | // System.out.println("ftp.getReplyCode() = " + ftp.getReplyCode()); |
| | | |
| | | // 检验登陆操作的返回码是否正确 |
| | | if (!FTPReply.isPositiveCompletion(ftp.getReplyCode())) { |
| | | |
| | | ftp.disconnect(); |
| | | |
| | | return false; |
| | | |
| | | } |
| | | |
| | | //被动模式,文件上传不成功会有提示 |
| | | ftp.enterLocalActiveMode(); |
| | | |
| | | // 设置文件类型为二进制,与ASCII有区别 |
| | | |
| | | ftp.setFileType(FTP.BINARY_FILE_TYPE); |
| | | |
| | | // 设置编码格式 |
| | | |
| | | ftp.setControlEncoding("GBK"); |
| | | // 提取绝对地址的目录以及文件名 |
| | | |
| | |
| | | return false; |
| | | } else { |
| | | String substring1 = fileName.substring(0, 1); |
| | | //把文件下载到本地 |
| | | FtpUtil.downloadFtpFile(ftpHost, ftpUserName, ftpPassword, ftpPort, ftpPath, localPath, fileName); |
| | | if (substring1.equals("w")) { |
| | | //把文件下载到本地 |
| | | FtpUtil.downloadFtpFile(ftpHost, ftpUserName, ftpPassword, ftpPort, ftpPath, localPath, fileName); |
| | | // |
| | | String s = OutJson.TestJson(fileName); |
| | | //sql语句 |
| | | String sql = OutJson.stringReplace(s); |
| | |
| | | } |
| | | } |
| | | //删除本地文件 |
| | | // MysqlCenlint.deletes(fileName); |
| | | MysqlCenlint.deletess(fileName); |
| | | FtpUtil.deleteFile(ftpHost, ftpPort, ftpUserName, ftpPassword, "anbao/", fileName); |
| | | is.close(); |
| | | ftp.completePendingCommand(); |
| | | } |
| | | else { |
| | | //把文件下载到本地 |
| | | FtpUtil.downloadFtpFile(ftpHost, ftpUserName, ftpPassword, ftpPort, ftpPath, minioPath, fileName); |
| | | //MysqlCenlint.deletess(fileName); |
| | | }else if(substring1.equals("o")){ |
| | | //获取对象字符串 |
| | | String json = OutJson.TestJson(fileName); |
| | | //数据处理 |
| | | DataHanlder.handler(json); |
| | | //删除本地文件 |
| | | MysqlCenlint.deletess(fileName); |
| | | FtpUtil.deleteFile(ftpHost, ftpPort, ftpUserName, ftpPassword, "anbao/", fileName); |
| | | is.close(); |
| | | ftp.completePendingCommand(); |
| | | } |
| | | is.close(); |
| | | ftp.completePendingCommand(); |
| | | } |
| | | } |
| | | return true; |
| | |
| | | @ApiModelProperty(value = "入职时间") |
| | | @JsonFormat(pattern = "yyyy-MM-dd",timezone = "GMT+8") |
| | | @DateTimeFormat(pattern = "yyyy-MM-dd") |
| | | private String rtime; |
| | | private Date rtime; |
| | | |
| | | |
| | | private String hold; |
| | | private String jurisdiction; |
| | | private String securitynumber; |
| | |
| | | localPath: D:\anbao\ |
| | | minioPath: D:\ftptp\ |
| | | jsonUrl: D:\anbao\ |
| | | sqlUsername: root |
| | | sqlPassword: zhba0728 |
| | | |
| | | # PostgreSQL |
| | | #url: jdbc:postgresql://127.0.0.1:5432/bladex_boot |
| | |
| | | |
| | | datasource: |
| | | # MySql |
| | | url: jdbc:mysql://223.82.109.183:2083/zhba-test?useSSL=false&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true&serverTimezone=GMT%2B8&nullCatalogMeansCurrent=true&allowPublicKeyRetrieval=true |
| | | username: root |
| | | password: ZHba@0112 |
| | | url: jdbc:mysql://122.112.189.74:3306/zhba?useSSL=false&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true&serverTimezone=GMT%2B8&nullCatalogMeansCurrent=true&allowPublicKeyRetrieval=true |
| | | username: zhbaw |
| | | password: Zhba@0426 |
| | | |
| | | #ftp 设置 |
| | | ftp: |
| | | sqlConnect: jdbc:mysql://223.82.109.183:2083/zhba-test?useSSL=false&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true&serverTimezone=GMT%2B8&nullCatalogMeansCurrent=true&allowPublicKeyRetrieval=true |
| | | sqlConnect: jdbc:mysql://122.112.189.74:3306/zhba?useSSL=false&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true&serverTimezone=GMT%2B8&nullCatalogMeansCurrent=true&allowPublicKeyRetrieval=true |
| | | ftpHost: 192.168.0.198 |
| | | ftpPort: 21 |
| | | ftpUserName: arsn |
| | |
| | | localPath: D:\anbao\ |
| | | minioPath: D:\ftptp\ |
| | | jsonUrl: D:\anbao\ |
| | | sqlUsername: zhbaw |
| | | sqlPassword: Zhba@0426 |
| | | |
| | | #公共配置 |
| | | common: |