package com.ningdatech.pmapi.datascope.provider.impl;

import com.ningdatech.pmapi.common.helper.UserInfoHelper;
import com.ningdatech.pmapi.datascope.model.DataScopeDTO;
import com.ningdatech.pmapi.datascope.provider.DataScopeProvider;
import com.ningdatech.pmapi.user.entity.enumeration.RoleEnum;
import com.ningdatech.pmapi.user.security.auth.model.UserFullInfoDTO;
import com.ningdatech.pmapi.user.util.LoginUserUtil;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import java.util.Optional;

/**
 * <p>
 * 数据权限 单位管理员
 * </p>
 *
 * @author ZPF
 * @since 2023/3/27 23:29
 */
@Slf4j
@RequiredArgsConstructor
@Component("COMPANY_MANAGER")
public class OrgAdminDataScopeProviderImpl implements DataScopeProvider {

    private final UserInfoHelper userInfoHelper;

    @Override
    public Optional<DataScopeDTO> findDataFieldProperty() {
        UserFullInfoDTO userFullInfo = userInfoHelper.getUserFullInfo(LoginUserUtil.getUserId());
        DataScopeDTO ds = new DataScopeDTO();
        ds.setOrgCode(userFullInfo.getEmpPosUnitCode());
        ds.setUserId(userFullInfo.getUserId());
        ds.setEmployeeCode(userFullInfo.getEmployeeCode());
        ds.setRole(RoleEnum.COMPANY_MANAGER);
        return Optional.of(ds);
    }

}
