| | |
| | | import org.apache.commons.net.ftp.FTP; |
| | | import org.apache.commons.net.ftp.FTPClient; |
| | | import org.apache.commons.net.ftp.FTPReply; |
| | | import org.springblade.modules.system.entity.User; |
| | | |
| | | import java.io.*; |
| | | import java.net.SocketException; |
| | | import java.util.Date; |
| | | import java.util.Map; |
| | | |
| | | import static org.springblade.common.constant.FtpConstant.*; |
| | | import static org.springblade.common.constant.FtpConstant.ftpPassword; |
| | | import static org.springblade.common.config.FtpConfig.*; |
| | | |
| | | /** |
| | | * ftp工具类 |
| | |
| | | FTPClient ftpClient = null; |
| | | try { |
| | | ftpClient = new FTPClient(); |
| | | //设置传输超时时间为60秒 |
| | | ftpClient.setDataTimeout(10000); |
| | | //连接超时为60秒 |
| | | ftpClient.setConnectTimeout(10000); |
| | | ftpClient.connect(ftpHost, ftpPort);// 连接FTP服务器 |
| | | ftpClient.login(ftpUserName, ftpPassword);// 登陆FTP服务器 |
| | | if (!FTPReply.isPositiveCompletion(ftpClient.getReplyCode())) { |
| | |
| | | } catch (FileNotFoundException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | FtpUtil.uploadFile(ftpHost_dev, ftpPort, ftpUserName, ftpPassword, ftpPath, "/", "w"+response1+".json", in1); |
| | | FtpUtil.uploadFile(ftpHost, ftpPort, ftpUserName, ftpPassword, ftpPath, "/", "w"+response1+".json", in1); |
| | | MysqlCenlint.deletess("w"+response1+".json"); |
| | | } |
| | | |
| | | /** |
| | | * 执行 对象数据(用户,报名对象信息等) 上传 |
| | | * @param obj 对象信息 |
| | | */ |
| | | public static void objectFileUpload(Object obj){ |
| | | String json1 = JSON.toJSONString(obj); |
| | | String response1 = String.valueOf((new Date()).getTime()); |
| | | OutJson.createJsonFile(json1, localPath, "o"+response1); |
| | | FileInputStream in1 = null; |
| | | try { |
| | | in1 = new FileInputStream(new File(localPath + "o"+response1+".json")); |
| | | } catch (FileNotFoundException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | FtpUtil.uploadFile(ftpHost, ftpPort, ftpUserName, ftpPassword, ftpPath, "/", "o"+response1+".json", in1); |
| | | MysqlCenlint.deletess("o"+response1+".json"); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 文件 file 上传(word,图片的文件的传输) |
| | | * @param obj 对象信息 |
| | | */ |
| | | public static void fileUpload(Object obj){ |
| | | String json1 = JSON.toJSONString(obj); |
| | | String response1 = String.valueOf((new Date()).getTime()); |
| | | OutJson.createJsonFile(json1, localPath, "f"+response1); |
| | | FileInputStream in1 = null; |
| | | try { |
| | | in1 = new FileInputStream(new File(localPath + "f"+response1+".json")); |
| | | } catch (FileNotFoundException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | FtpUtil.uploadFile(ftpHost, ftpPort, ftpUserName, ftpPassword, ftpPath, "/", "f"+response1+".json", in1); |
| | | MysqlCenlint.deletess("f"+response1+".json"); |
| | | } |
| | | |
| | | /** |
| | | * 用户集合 |
| | | * @param map |
| | | */ |
| | | public static void objectFileUploadList(Map<String, Object> map) { |
| | | String json1 = JSON.toJSONString(map); |
| | | String response1 = String.valueOf((new Date()).getTime()); |
| | | OutJson.createJsonFile(json1, localPath, "l"+response1); |
| | | FileInputStream in1 = null; |
| | | try { |
| | | in1 = new FileInputStream(new File(localPath + "l"+response1+".json")); |
| | | } catch (FileNotFoundException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | FtpUtil.uploadFile(ftpHost, ftpPort, ftpUserName, ftpPassword, ftpPath, "/", "l"+response1+".json", in1); |
| | | MysqlCenlint.deletess("l"+response1+".json"); |
| | | } |
| | | |
| | | /** |
| | | * 报名信息查验 |
| | | * @param map |
| | | */ |
| | | public static void objectFileUploadListUserId(Map<String, Object> map){ |
| | | String json1 = JSON.toJSONString(map); |
| | | String response1 = String.valueOf((new Date()).getTime()); |
| | | OutJson.createJsonFile(json1, localPath, "t"+response1); |
| | | FileInputStream in1 = null; |
| | | try { |
| | | in1 = new FileInputStream(new File(localPath + "t"+response1+".json")); |
| | | } catch (FileNotFoundException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | FtpUtil.uploadFile(ftpHost, ftpPort, ftpUserName, ftpPassword, ftpPath, "/", "t"+response1+".json", in1); |
| | | MysqlCenlint.deletess("t"+response1+".json"); |
| | | } |
| | | |
| | | /** |
| | | * 查询保安员证编号位数 |
| | | * @param map |
| | | */ |
| | | public static void getSecurityNumberBit(Map<String, Object> map) { |
| | | String json1 = JSON.toJSONString(map); |
| | | String response1 = String.valueOf((new Date()).getTime()); |
| | | OutJson.createJsonFile(json1, localPath, "s"+response1); |
| | | FileInputStream in1 = null; |
| | | try { |
| | | in1 = new FileInputStream(new File(localPath + "s"+response1+".json")); |
| | | } catch (FileNotFoundException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | FtpUtil.uploadFile(ftpHost, ftpPort, ftpUserName, ftpPassword, ftpPath, "/", "s"+response1+".json", in1); |
| | | MysqlCenlint.deletess("s"+response1+".json"); |
| | | } |
| | | |
| | | /** |
| | | * 用户审查 |
| | | * @param user |
| | | */ |
| | | public static void sqlFileUploadUserExamine(User user) { |
| | | String json1 = JSON.toJSONString(user); |
| | | String response1 = String.valueOf((new Date()).getTime()); |
| | | OutJson.createJsonFile(json1, localPath, "u"+response1); |
| | | FileInputStream in1 = null; |
| | | try { |
| | | in1 = new FileInputStream(new File(localPath + "u"+response1+".json")); |
| | | } catch (FileNotFoundException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | FtpUtil.uploadFile(ftpHost, ftpPort, ftpUserName, ftpPassword, ftpPath, "/", "u"+response1+".json", in1); |
| | | MysqlCenlint.deletess("u"+response1+".json"); |
| | | } |
| | | |
| | | /** |
| | | * 考试实操成绩推送内网导入 |
| | | * @param map |
| | | */ |
| | | public static void objectFileUploadExamScore(Map<String, Object> map) { |
| | | String json1 = JSON.toJSONString(map); |
| | | String response1 = String.valueOf((new Date()).getTime()); |
| | | OutJson.createJsonFile(json1, localPath, "e"+response1); |
| | | FileInputStream in1 = null; |
| | | try { |
| | | in1 = new FileInputStream(new File(localPath + "e"+response1+".json")); |
| | | } catch (FileNotFoundException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | FtpUtil.uploadFile(ftpHost, ftpPort, ftpUserName, ftpPassword, ftpPath, "/", "e"+response1+".json", in1); |
| | | MysqlCenlint.deletess("e"+response1+".json"); |
| | | } |
| | | |
| | | /** |
| | | * 管理员导入保安人员并创建保安证编号 |
| | | * @param map |
| | | */ |
| | | public static void getSecurityPaperAndUserImport(Map<String, Object> map) { |
| | | String json = JSON.toJSONString(map); |
| | | String response = String.valueOf((new Date()).getTime()); |
| | | OutJson.createJsonFile(json, localPath, "p"+response); |
| | | FileInputStream in = null; |
| | | try { |
| | | in = new FileInputStream(new File(localPath + "p"+response+".json")); |
| | | } catch (FileNotFoundException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | FtpUtil.uploadFile(ftpHost, ftpPort, ftpUserName, ftpPassword, ftpPath, "/", "p"+response+".json", in); |
| | | MysqlCenlint.deletess("p"+response+".json"); |
| | | } |
| | | } |