package com.zcxk.rmcp.core.dao.mongo;

import com.zcxk.core.common.pojo.UserCondition;
import org.springframework.data.mongodb.core.query.Criteria;

import java.util.List;

/**
 * @author Andy
 * @version V1.0
 * @description: BaseMongoDao
 * @date 2021/7/23
 **/
public interface BaseMongoDao {

     /**
     * 设置用户权限
     * @author Andy
     * @date 10:44 2021/8/12
     * @param userCondition:
     * @param criteria:
     * @return void
     **/
     default void criteriaUserCondition(UserCondition userCondition, Criteria criteria){
         if (userCondition.checkAuthority()) {
             List<Integer> orgIds = userCondition.getOrgIds();
             if (userCondition.getPermissionType() == 2 || userCondition.getPermissionType() == 5)  {
                 Criteria criteria1 = Criteria.where("company_org_id").in(orgIds);
                 Criteria criteria2 = Criteria.where("dept_org_id").in(orgIds);
                 criteria.orOperator(criteria1, criteria2);
             }
             if (userCondition.getPermissionType() == 4 || userCondition.getPermissionType() == 3)  {
                 criteria.and("dept_org_id").in(orgIds);
             }
             if (userCondition.getPermissionType() == 1)  {
                 criteria.and("company_org_id").in(orgIds);
                 criteria.and("dept_org_id").is(0);
             }
         }
     }
}
