From c5f2ab160bfb1308cbd08513225e0241374cf3dc Mon Sep 17 00:00:00 2001 From: gaoben Date: Mon, 12 Aug 2024 16:36:12 +0800 Subject: [PATCH] =?UTF-8?q?v10,redis=E7=BC=93=E5=AD=98=E9=BB=98=E8=AE=A4?= =?UTF-8?q?=E6=94=B9=E4=B8=BA120=E7=A7=92=EF=BC=8C=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E5=BA=93=E5=A4=87=E4=BB=BD=E5=A2=9E=E5=8A=A0=E4=BF=9D=E7=95=99?= =?UTF-8?q?=E6=97=B6=E9=97=B4=EF=BC=8C=E6=A0=87=E7=AD=BE=E5=88=A0=E9=99=A4?= =?UTF-8?q?=E5=90=8C=E6=97=B6=E5=88=A0=E9=99=A4=E8=AE=BE=E5=A4=87=E5=85=B3?= =?UTF-8?q?=E8=81=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../modules/job/task/DbBakTask.java | 33 +++++++++++++++---- .../ten/controller/TenLabelController.java | 14 +++++--- .../shapelight/common/config/RedisConfig.java | 2 +- 3 files changed, 37 insertions(+), 12 deletions(-) diff --git a/shapelight-admin/src/main/java/net/shapelight/modules/job/task/DbBakTask.java b/shapelight-admin/src/main/java/net/shapelight/modules/job/task/DbBakTask.java index c62cd37..4638794 100644 --- a/shapelight-admin/src/main/java/net/shapelight/modules/job/task/DbBakTask.java +++ b/shapelight-admin/src/main/java/net/shapelight/modules/job/task/DbBakTask.java @@ -1,13 +1,10 @@ - - package net.shapelight.modules.job.task; import lombok.Data; +import lombok.extern.slf4j.Slf4j; import net.shapelight.common.utils.DateUtils; import net.shapelight.modules.sys.entity.SysDbBakEntity; import net.shapelight.modules.sys.service.SysDbBakService; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; @@ -20,8 +17,8 @@ import java.util.Date; */ @Component("dbBakTask") @Data +@Slf4j public class DbBakTask implements ITask { - private Logger logger = LoggerFactory.getLogger(getClass()); @Autowired private SysDbBakService sysDbBakService; @@ -43,7 +40,7 @@ public class DbBakTask implements ITask { @Override public void run(String params){ - logger.debug("dbBakTask定时任务正在执行,参数为:{}", params); + log.debug("dbBakTask定时任务正在执行,参数为:{}", params); //System.out.println("执行定时任务》》》"+new Date()); /*File uploadDir = new File(dbFilePath); if (!uploadDir.exists()) @@ -90,7 +87,7 @@ public class DbBakTask implements ITask { //System.out.println("备份数据库成功!!!"); } catch (Exception e) { // TODO Auto-generated catch block - logger.debug("备份数据库失败", params); + log.debug("备份数据库失败", params); e.printStackTrace(); }finally { @@ -105,6 +102,28 @@ public class DbBakTask implements ITask { e.printStackTrace(); } } + //删除历史文件 + int days = 30;//默认30天 + if(params != null){ + days = Integer.parseInt(params); + } + File[] files = fileDir.listFiles(); + if (files != null){ + for(File file: files){ + if(file.isFile()){ + String fileName = file.getName(); + long time = file.lastModified(); + Date upDate = new Date(time); + Date now = new Date(); + long msNum = now.getTime()-upDate.getTime(); + long dayNum = msNum/(24*60*60*1000); + if(dayNum > days){ + file.delete(); + log.debug("删除过期文件:"+fileName); + } + } + } + } } diff --git a/shapelight-admin/src/main/java/net/shapelight/modules/ten/controller/TenLabelController.java b/shapelight-admin/src/main/java/net/shapelight/modules/ten/controller/TenLabelController.java index d5ddb07..9d8dd71 100644 --- a/shapelight-admin/src/main/java/net/shapelight/modules/ten/controller/TenLabelController.java +++ b/shapelight-admin/src/main/java/net/shapelight/modules/ten/controller/TenLabelController.java @@ -1,9 +1,6 @@ package net.shapelight.modules.ten.controller; -import java.util.Arrays; -import java.util.Date; -import java.util.List; -import java.util.Map; +import java.util.*; import com.baomidou.mybatisplus.annotation.TableLogic; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; @@ -12,7 +9,10 @@ import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiOperation; import net.shapelight.common.annotation.SysLog; +import net.shapelight.common.utils.Constant; import net.shapelight.modules.sys.controller.AbstractController; +import net.shapelight.modules.ten.entity.TenDeviceLabelEntity; +import net.shapelight.modules.ten.service.TenDeviceLabelService; import net.shapelight.modules.ten.service.TenPersonService; import org.apache.shiro.authz.annotation.RequiresPermissions; import org.springframework.beans.factory.annotation.Autowired; @@ -37,6 +37,8 @@ public class TenLabelController extends AbstractController { private TenLabelService tenLabelService; @Autowired private TenPersonService tenPersonService; + @Autowired + private TenDeviceLabelService tenDeviceLabelService; /** * 列表 @@ -141,6 +143,10 @@ public class TenLabelController extends AbstractController { if(pCount>0){ return R.error("此标签已使用"); } + + //删除设备绑定关系: + tenDeviceLabelService.remove(new QueryWrapper() + .eq("label_id",id)); tenLabelService.removeByIds(Arrays.asList(labelIds)); return R.ok(); } diff --git a/shapelight-common/src/main/java/net/shapelight/common/config/RedisConfig.java b/shapelight-common/src/main/java/net/shapelight/common/config/RedisConfig.java index 4fc286c..e024463 100644 --- a/shapelight-common/src/main/java/net/shapelight/common/config/RedisConfig.java +++ b/shapelight-common/src/main/java/net/shapelight/common/config/RedisConfig.java @@ -163,7 +163,7 @@ public class RedisConfig { public CacheManager cacheManager(RedisConnectionFactory redisConnectionFactory) { return new RedisCacheManager( RedisCacheWriter.nonLockingRedisCacheWriter(redisConnectionFactory), - this.getRedisCacheConfigurationWithTtl(600), // 默认策略,未配置的 key 会使用这个 + this.getRedisCacheConfigurationWithTtl(120), // 默认策略,未配置的 key 会使用这个 this.getRedisCacheConfigurationMap() // 指定 key 策略 ); }