SystemParam.java 1.57 KB
package com.bsth.entity;

import com.bsth.common.Constants;
import com.bsth.data.BasicData;
import com.bsth.entity.sys.Role;
import com.bsth.security.util.SecurityUtils;

import javax.persistence.*;
import java.util.Set;

/**
 * @author Hill
 */
@Entity
@Table(name = "bsth_c_sys_param")
public class SystemParam {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer id;

    /**
     * 键名(唯一)
     */
    private String key;

    /**
     * 值
     */
    private String value;

    /**
     * 备注
     */
    private String remark;

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getKey() {
        return key;
    }

    public void setKey(String key) {
        this.key = key;
    }

    public String getValue() {
        return value;
    }

    public void setValue(String value) {
        this.value = value;
    }

    public String getRemark() {
        return remark;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }

    public static int getHistorySaveDays() {
        Set<Role> roles = SecurityUtils.getCurrentUser().getRoles();
        SystemParam param = BasicData.getSystemParam().get(Constants.SPECIAL_ROLES);
        int days = 4;
        if (param != null && param.getValue() != null) {
            for (Role role : roles) {
                if (param.getValue().contains(String.format(",%s,", role.getCodeName()))) {
                    days = 5;
                }
            }
        }

        return days;
    }
}