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

电子商务网站设计与开发案例教程电子贺卡制作软件app

电子商务网站设计与开发案例教程,电子贺卡制作软件app,wordpress建站事项,可以做360度全景图的网站数据越积越多&#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/881143/

相关文章:

  • 网站如何添加认证联盟商场设计与商品陈列
  • 网站顶部地图代码怎么做的耒阳市建设局网站
  • 合肥建设网站公司安徽建设工程有限公司
  • 苏州专业高端网站建设机构做商城外贸网站
  • 专门做宠物食品的网站做暖暖免费视频网站
  • archigo建筑网站阿里企业邮箱后缀
  • 网站开发可以自学吗给周杰伦做网站
  • 网站怎么做弹窗网站设计与开发期末考试题
  • 如何制作自己的网站 可放广告wordpress横向导航
  • 衡水市住房和城乡建设局网站阿里云服务器可以做彩票网站吗
  • 合肥生态丽景网站建设网页设计师考试
  • 阜阳网站开发自己做一个网站一年的费用
  • 长沙制作公园仿竹围栏哪家便宜常州网站制作优化
  • 徐州网站建设哪家专业在线做六级阅读网站
  • 福建福清市住房和建设局网站外贸做中英文网站
  • 医院网站解决方案微商代运营
  • 网站的建设特色WordPress小程序论坛
  • 彩投网站建设中英文切换网站开发
  • 网站建设怎么谈wordpress设置收费下载
  • wap网站域名申请wordpress 首页显示全文
  • 黄岩城市建设发展集团网站wordpress页面背景图片
  • php网站开发发展趋势wordpress html 单页
  • 做彩票网站技术网站对域名
  • 外边做一个网站要多少钱百度网站抓取时间查询
  • 网站建设又叫什么专业营销网站开发
  • 湛江市律师网站建设品牌北京市基础建设质量监督局网站
  • 制造网站开发教学网站模板
  • 石碣镇网站仿做网站建设公司代理商
  • 坪山网站建设流程检测WordPress网站的安全性
  • 服务网站设计案例住建网是个什么网站