package com.winsun.TimingTask;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.winsun.bean.SysUser;
import com.winsun.mapper.SysUserMapper;
import com.winsun.utils.MD5Utils;

import lombok.extern.slf4j.Slf4j;

@Slf4j
@RestController
@Configuration
@EnableScheduling
public class UserTask {
	@Autowired
	private SysUserMapper sysUserMapper;
	
	
    //@Scheduled(cron = "0 */1 * * * ? ")
    @PostMapping("/userTask")
    public void updateUser()  {
    	Wrapper<SysUser> wrapper = new EntityWrapper<SysUser>();
    	wrapper.isNull("salt");
    	
    	List<SysUser> list = sysUserMapper.selectList(wrapper);
    	for(SysUser user : list) {
    		String salt = MD5Utils.getRandomString(5);
    		String password = user.getAccount();
    		password = MD5Utils.md5(password, salt);
    		
    		user.setPassword(password);
    		user.setSalt(salt);
    		
    		sysUserMapper.updateById(user);
    	}
    	
    }
}
