需要的注解
@Configuration //1.主要用于标记配置类,兼备Component的效果。
@EnableScheduling // 2.开启定时任务@Scheduled(fixedRate = 3000000) 定时 30分钟
package com.czxy.conllonter;import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.czxy.Administrator;
import com.czxy.config.BaseResult;
import com.czxy.config.JwtProperTies;
import com.czxy.mapper.UserMapper;
import com.czxy.servise.Userservise;
import com.czxy.untils.CodeUtil;
import com.czxy.untils.JwtUtils;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.*;import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.sql.Time;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;@RestController
@RequestMapping("/administrator")
@Configuration //1.主要用于标记配置类,兼备Component的效果。
@EnableScheduling // 2.开启定时任务
//@Component
public class UserConlleter {@Resourceprivate Userservise userservise;@Resourceprivate UserMapper userMapper;@Resourceprivate JwtProperTies jwtProperTies;@Resourceprivate HttpServletRequest httpServletRequest;//生成随机校验码用于注册@PostMapping("Invitationcode/{id}")private BaseResult<String> getCode(@PathVariable Integer id){String code = CodeUtil.toSerialCode(id);//设置权限码Administrator administrator = userMapper.selectById(id);administrator.setCode(code);userservise.updateById(administrator);return BaseResult.ok("请求成功",code);}//30分钟刷新校验码@Scheduled(fixedRate = 3000000)@GetMapping("updateCode")private void updateCode(){List<Administrator> administratorList = userservise.list();for (Administrator administrator:administratorList){//获取codeBaseResult<String> code = getCode(administrator.getAid());//设置校验码administrator.setCode(code.getData());//更新userservise.updateById(administrator);}}
}