当前位置: 首页 > news >正文

福州专业网站制作设计银川做网站哪家好

福州专业网站制作设计,银川做网站哪家好,龙华公司做网站,织梦cms网站数据越积越多&#xff0c;过于冗余&#xff1b;数据库定期删除指定时间前的数据&#xff1b;文件生成的删除指定时间前端文件 SFTP文件定期删除 java sftp 定时清理指定文件中固定时间 依赖 <!-- ftp文件上传/下载Jar包 --> <dependency><groupId>com.jc…

数据越积越多,过于冗余;数据库定期删除指定时间前的数据;文件生成的删除指定时间前端文件

SFTP文件定期删除

java sftp 定时清理指定文件中固定时间

  • 依赖
<!-- ftp文件上传/下载Jar包 -->
<dependency><groupId>com.jcraft</groupId><artifactId>jsch</artifactId><version>0.1.54</version>
</dependency>
  • 代码

import com.jcraft.jsch.*;import java.util.Vector;/*** java sftp 定时清理指定文件中固定时间*/
public class SftpCleanup {public static void main(String[] args) throws JSchException {String host = "127.0.0.1"; // SFTP主机地址int port = 22; // SFTP端口号String username = "xxx"; // SFTP登录用户名String password = "xxxx"; // SFTP登录密码Session session = null;ChannelSftp channelSftp = null;try {JSch jsch = new JSch();// 创建Session对象session = jsch.getSession(username, host, port);session.setPassword(password);session.setConfig("StrictHostKeyChecking", "no");session.connect();// 打开ChannelSftp通道channelSftp = (ChannelSftp) session.openChannel("sftp");channelSftp.connect();// 设置删除目标文件的路径及过期时间(单位为分钟)// 默认为当前日期之前的24小时内的文件将被删除//long expireTimeInMinutes = 60 * 24;long currentTimeMillis = System.currentTimeMillis();//long threeMonthsAgoInMillis = currentTimeMillis - 2 * 7 * 60 * 60 * 1000L; // 当前时间减去N个天的毫秒数long threeMonthsAgoInMillis = currentTimeMillis - 90 * 24 * 60 * 60 * 1000L; // 当前时间减去3个月(3*30)的毫秒数String targetPath = "/data/file/hi/"; // 目标文件路径Vector<ChannelSftp.LsEntry> fileList = channelSftp.ls(targetPath); // 要清理的目标文件所在路径for (ChannelSftp.LsEntry entry : fileList) {if (!entry.getAttrs().isDir()) {long fileCreationTime = entry.getAttrs().getMTime() * 1000L;printTimeDifference(true, fileCreationTime, threeMonthsAgoInMillis);if (fileCreationTime < threeMonthsAgoInMillis) {channelSftp.rm(targetPath + entry.getFilename()); // 删除符合条件的文件System.out.println("成功删除文件:" + targetPath + entry.getFilename());} else {System.out.println("未到达过期时间,不处理文件:" + targetPath + entry.getFilename());}}}} catch (JSchException | SftpException e) {e.printStackTrace();} finally {// 关闭ChannelSftp通道和会话if (channelSftp != null && channelSftp.isConnected()) {channelSftp.disconnect();}if (session != null && session.isConnected()) {session.disconnect();}}}/*** 打印计算时间差** @param fileCreationTime  sftpFileTime* @param presetsTimeMillis threeMonthsAgoInMillis*/private static void printTimeDifference(boolean debugger, long fileCreationTime, long presetsTimeMillis) {// 计算两者之间的差值(单位:微秒)long diffMicroseconds = (fileCreationTime - presetsTimeMillis);// 将差值转化为小时、分钟和秒int days = (int) (diffMicroseconds / (24 * 60 * 60 * 1000));int hours = (int) (diffMicroseconds / (60 * 60 * 1000));int minutes = (int) ((diffMicroseconds % (60 * 60 * 1000)) / (60 * 1000));int seconds = (int) ((diffMicroseconds % (60 * 1000)) / 1000);// 输出结果//System.out.println("差值为 " + diffMicroseconds + " 微秒");if (debugger) {System.out.println("差值为 " + days + " 天 " + hours + " 小时 " + minutes + " 分钟 " + seconds + " 秒");}}
}

mysql保存N个月的数据

mysql中保存3个月的数据,当超过3个月之后定时清除3个月之前的数据

  • Mysql
-- 至少保留一个月数据量 delete from table_name
SELECT DATE_SUB(NOW(), INTERVAL 1 MONTH);
select count(*) from table_name where create_time < DATE_SUB(NOW(), INTERVAL 1 MONTH);
  • Api
    public void deleteCustomerTouch(String monthNum) {if (StringUtils.isBlank(monthNum)) {monthNum = YsConst.Month.THREE;}//值不为空,且值为数值,且值要大于等于1if (NumberUtil.isNumber(monthNum) && NumberUtil.parseInt(monthNum) >= 1) {apiService.deleteByTime(monthNum);} else {logger.error("【apiService】其他的,参数错误 monthNum={}", monthNum);}}
  • Mapper
    <!-- 小于等于 --><delete id="deleteByTime">delete from table_name where create_time &lt;= DATE_SUB(NOW(), INTERVAL #{monthNum} MONTH)</delete>
http://www.yayakq.cn/news/679102/

相关文章:

  • 网站建设前的问卷2网站制作
  • 基本网站建设知识网站建设公司对父亲节宣传口号
  • 北京建站者公司网站的开发技术
  • 企业网站建设的意义和效果宝格丽网站建设
  • 怎样使用网站后台的模板wordpress 管理员账号在哪里查询
  • 网站的制作wordpress重定向代码
  • 个人网站模板flash网站建设营业执照
  • wordpress网站登录被篡改深圳燃气公司
  • 郑州华久做网站合肥网站优化软件
  • 福建建设部网站thinkphp可以做网站吗
  • 凡客建站登陆建设企业网站的常见成本有哪些
  • 国外黄冈网站推广软件代发关键词包收录
  • dede一键更新网站出错白银网站运行
  • 工商企业信息查询网站南昌 定制网站
  • 小浣熊做单网站平面设计和网页设计哪个好
  • 做网站建设销售辛苦吗商务网站专题页
  • 哪个网站可以卖自己的设计永久3e38cos
  • 免费建设网站抽取佣金免费网站建设企业
  • 长沙营销型网站建设制作淘宝客网站做百度推广
  • 医生可以自己做网站吗高端网站开发费用
  • 设计公司企业站优化前网站现状分析
  • 网站开发 文件上传慢用asp.net做后台网站
  • 现在建设一个网站多少钱什么网站做h5做得好
  • 做网站能挣多少钱宣传片的拍摄思路
  • 网站建设开发软件有哪些wordpress 会员下载
  • 杭州商城网站建设网站推广的软文
  • 辽阳网站开发汽车建设网站开发流程
  • 深州网站深圳富通做网站
  • 怎么做网站app杭州市上城区建设局网站
  • 哈尔滨模板做网站软件开发联系电话