package com.hz.pm.api.sys.utils;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.hz.pm.api.projectlib.model.entity.Project;
import com.hz.pm.api.sys.model.entity.WflowEarlyWarningRecords;
import com.hz.pm.api.user.security.model.UserFullInfoDTO;
import com.hz.pm.api.user.security.model.UserInfoDetails;

/**
 * @Classname EarlyWarningUtil
 * @Description
 * @Date 2023/12/7 14:14
 * @Author PoffyZhang
 */
public class EarlyWarningUtil {

    private EarlyWarningUtil() {
    }

    public static void buildPermissionWrapper(LambdaQueryWrapper<WflowEarlyWarningRecords> wrapper,
                                              UserInfoDetails user) {
        //如果是超管的话
        if (user.getSuperAdmin() || user.getRegionAdmin()) {
            // 可以看所有
        } else if (user.getIsOrgAdmin()) {
            wrapper.eq(WflowEarlyWarningRecords::getBuildOrgCode, user.getMhUnitId());
        } else {
            //否则都只能看自己单位的
            wrapper.eq(WflowEarlyWarningRecords::getBuildOrgCode, user.getMhUnitId());
        }
    }

    public static void buildPermissionFullWrapper(LambdaQueryWrapper<WflowEarlyWarningRecords> wrapper,
                                                  UserFullInfoDTO user) {
        //如果是超管的话
        if (user.getSuperAdmin() || user.getRegionAdmin()) {
            // 可以看所有
        } else if (user.getIsOrgAdmin()) {
            wrapper.eq(WflowEarlyWarningRecords::getBuildOrgCode, user.getMhUnitId());
        } else {
            //否则都只能看自己单位的
            wrapper.eq(WflowEarlyWarningRecords::getBuildOrgCode, user.getMhUnitId());
        }
    }

    public static void buildPermissionProjectWrapper(LambdaQueryWrapper<Project> wrapper,
                                                     UserFullInfoDTO user) {
        //如果是超管的话
        if (user.getSuperAdmin()) {
            // 看所有
        } else if (user.getIsOrgAdmin()) {
            wrapper.eq(Project::getBuildOrgCode, user.getMhUnitIdStr());
        } else {
            //否则都只能看自己单位的
            wrapper.eq(Project::getBuildOrgCode, user.getMhUnitIdStr());
        }
    }

}
