package com.sys.bus.sys.task;

import com.jfinal.aop.Enhancer;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.cron4j.ITask;
import com.sys.bus.jx.service.WflogService;
import com.sys.bus.model.Entry;
import com.sys.bus.model.SysCode;
import com.sys.bus.syscode.service.SysCodeService;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import java.security.SecureRandom;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.List;

public class AutoSsoTask implements ITask {
	Log log = LogFactory.getLog(this.getClass());
	static SysCodeService sysCodeService = new SysCodeService();
	boolean flag = false;
	public void run() {
		if(flag)return;
		log.info("进入 AutoSsoTask 。。。。");
		try{
			SysCode sysCode = sysCodeService.getSysCodeName("shr单点秘钥");
			if(sysCode == null)return;
			SecureRandom secureRandom = new SecureRandom();
			String letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; // 包含所有大写字母
			StringBuilder sb = new StringBuilder(5);

			for (int i = 0; i < 5; i++) {
				int index = secureRandom.nextInt(letters.length());
				sb.append(letters.charAt(index));
			}
			sysCode.setSyscodeValue(sb.toString());
			sysCode.update();
			flag = true;
		} catch (Exception e) {
			log.error("自动更新sso任务异常",e);
		}

	}

	public void stop() {
		log.info("------AutoSsoTask stop-------------");
	}
}
