package com.yuchen.saas.park.service.service.property;

import com.yuchen.saas.park.api.entity.park.PmgBatParkInfo;
import com.yuchen.saas.park.service.service.PmgBatParkInfoService;
import org.nest.springwrap.core.secure.ContextUser;
import org.nest.springwrap.core.secure.utils.AuthUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

@Service
public class PropertySearchParkInfoService {
    @Lazy
    @Autowired
    private PmgBatParkInfoService pmgBatParkInfoService;

    /**
     * 获取后台用户所拥有的园区数据权限
     * 当查不到数据时数组返回 -1
     * @return
     */
    public List<Long> getParkIdsByCurrUser() {
        List<Long> parkIdList = new ArrayList<>();
        ContextUser user = AuthUtil.getUser();
        if (user == null) {
            parkIdList.add(-1L);
            return parkIdList;
        }
        List<PmgBatParkInfo> parkInfoList = pmgBatParkInfoService.getAllParkV1(user.getRoleId(),user.getIsAdmin()
                ,user.getDeptId(),user.getTenantId(),user.getOrgUserId());
        if (parkInfoList.size() == 0) {
            parkIdList.add(-1L);
            return parkIdList;
        }
        parkIdList.addAll(parkInfoList.stream().map(PmgBatParkInfo::getId).collect(Collectors.toList()));
        return parkIdList;
    }


}
