Explorar el Código

角色有效期

liwei19941102 hace 2 años
padre
commit
abb4d1bef0

+ 40 - 0
ruoyi-admin/src/main/java/com/ruoyi/RoleTask.java

@@ -0,0 +1,40 @@
+package com.ruoyi;
+
+import com.ruoyi.common.core.domain.entity.SysRole;
+import com.ruoyi.common.utils.StringUtils;
+import com.ruoyi.system.mapper.SysRoleMapper;
+import com.ruoyi.system.service.ISysRoleService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.scheduling.annotation.Scheduled;
+import org.springframework.stereotype.Component;
+
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.List;
+
+@Component
+public class RoleTask {
+
+    @Autowired
+    private SysRoleMapper sysRoleMapper;
+
+    @Scheduled(cron="0 0 0 * * ?")   //每日00:00执行数据
+//    @Scheduled(cron="0/10 * * * * ?")   //每日00:00执行数据
+    public void execute() throws ParseException {
+        List<SysRole> list =sysRoleMapper.selectRoleAllList();
+        Date date = new Date();
+        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); //设置日期格式
+        for(SysRole sysRole:list){
+              if(sysRole.getRemark() != null && StringUtils.isNotBlank(sysRole.getRemark()) && sysRole.getRoleId() != 1){
+                  Date youxiaoqi = df.parse(sysRole.getRemark());
+                  if(youxiaoqi.getTime() < date.getTime()){
+                      sysRole.setStatus("1");
+                      sysRoleMapper.updateById(sysRole);
+                  }
+              }
+        }
+    }
+
+
+}

+ 2 - 0
ruoyi-admin/src/main/java/com/ruoyi/RuoYiApplication.java

@@ -3,6 +3,7 @@ package com.ruoyi;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
 import org.springframework.boot.context.metrics.buffering.BufferingApplicationStartup;
+import org.springframework.scheduling.annotation.EnableScheduling;
 
 /**
  * 启动程序
@@ -11,6 +12,7 @@ import org.springframework.boot.context.metrics.buffering.BufferingApplicationSt
  */
 
 @SpringBootApplication
+@EnableScheduling
 public class RuoYiApplication {
 
     public static void main(String[] args) {

+ 2 - 0
ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysRoleMapper.java

@@ -44,6 +44,8 @@ public interface SysRoleMapper extends BaseMapperPlus<SysRoleMapper, SysRole, Sy
      */
     List<SysRole> selectRolePermissionByUserId(Long userId);
 
+    List<SysRole> selectRoleAllList();
+
 
     /**
      * 根据用户ID获取角色选择框列表

+ 4 - 0
ruoyi-system/src/main/resources/mapper/system/SysRoleMapper.xml

@@ -50,6 +50,10 @@
         ${ew.getCustomSqlSegment}
     </select>
 
+    <select id="selectRoleAllList" resultMap="SysRoleResult">
+       select * from sys_role WHERE del_flag = '0'
+    </select>
+
     <select id="selectRolePermissionByUserId" parameterType="Long" resultMap="SysRoleResult">
         <include refid="selectRoleVo"/>
         WHERE r.del_flag = '0' and sur.user_id = #{userId}

+ 2 - 1
ruoyi-ui-vue3/src/views/system/role/index.vue

@@ -132,7 +132,7 @@
           <el-form-item label="角色有效期">
           <!-- <el-input v-model="form.remark" type="textarea" placeholder="请输入内容"></el-input> -->
           <el-date-picker v-model="form.remark" type="date" placeholder="Pick a day" :disabled-date="disabledDate"
-            :shortcuts="shortcuts" :size="size" />
+            :shortcuts="shortcuts" :size="size" value-format="YYYY-MM-DD 00:00:00"/>
         </el-form-item>
       </el-form>
       <template #footer>
@@ -426,6 +426,7 @@ function getMenuAllCheckedKeys() {
 }
 /** 提交按钮 */
 function submitForm() {
+  console.log(form.value)
   proxy.$refs["roleRef"].validate(valid => {
     if (valid) {
       if (form.value.roleId != undefined) {

+ 1 - 1
ruoyi-ui-vue3/src/views/warnRole/index.vue

@@ -119,7 +119,7 @@
         <!-- <el-form-item label="备注"> -->
         <el-form-item label="角色有效期">
           <!-- <el-input v-model="form.remark" type="textarea" placeholder="请输入内容"></el-input> -->
-          <el-date-picker v-model="form.remark" type="date" placeholder="Pick a day" :disabled-date="disabledDate"
+          <el-date-picker v-model="form.remark" type="date" placeholder="Pick a day" :disabled-date="disabledDate" value-format="YYYY-MM-DD"
             :shortcuts="shortcuts" :size="size" />
         </el-form-item>
       </el-form>