package com.ruoyi.system.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.core.domain.model.UserExtendInfo;
import com.ruoyi.common.core.service.SensitiveService;
import com.ruoyi.common.enums.LoginUserTypeEnum;
import com.ruoyi.common.helper.LoginHelper;
import com.ruoyi.framework.interceptor.UserContext;
import com.ruoyi.user.domain.User;
import org.springframework.stereotype.Service;

/**
 * 脱敏服务
 * 默认管理员不过滤
 * 需自行根据业务重写实现
 *
 * @author Lion Li
 * @version 3.6.0
 */
@Service
public class SysSensitiveServiceImpl implements SensitiveService {

    /**
     * 是否脱敏
     */
    @Override
    public boolean isSensitive() {
        try {
            LoginUser loginUser = LoginHelper.getLoginUser();
            return ObjectUtil.isNotNull(loginUser);
        } catch (Exception e) {
            // C端
            User user = UserContext.currentUser();
            if (ObjectUtil.isNotNull(user)) {
                UserExtendInfo userExtendInfo = user.getUserExtendInfo();
                if (ObjectUtil.isNotNull(userExtendInfo)) {
                    return LoginUserTypeEnum.ORDINARY.getKey().equals(userExtendInfo.getLoginUserType());
                }
            }
            return false;
        }
    }

}
