package com.gci.boot.modules.system.service;

import com.gci.boot.common.util.JsonUtil;
import com.gci.boot.common.util.RedisUtil;
import com.gci.boot.constant.CacheConstant;
import com.gci.boot.modules.system.entity.LoginTimesValidate;
import org.springframework.stereotype.Service;

import java.util.Objects;

/**
 * @Author: lyz
 * @Description: TODO:(用一句话描述该文件做什么)
 * @version: v1.0
 * @Modified by:
 **/
@Service
public class LoginTimesValidateService
{
    public LoginTimesValidate getManageTimes(String loginUser){
        LoginTimesValidate act = null;
        Object timesJson = RedisUtil.get(CacheConstant.LOGIN_TIMES_VALIDATE_PC+loginUser);
        if(Objects.nonNull(timesJson)){
            act = JsonUtil.json2Object(timesJson.toString(),LoginTimesValidate.class);
        }else{
            act = new LoginTimesValidate(loginUser);
        }
        return act;
    }

    public void saveManageTimes(LoginTimesValidate at) {
        at.addTimes();
        String timesJson = JsonUtil.object2Json(at);
        RedisUtil.set(CacheConstant.LOGIN_TIMES_VALIDATE_PC+at.getLoginUser(),timesJson,at.getSecond());
    }
}
