package com.yiqi.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yiqi.common.enums.SourceType;
import com.yiqi.system.domain.SysOrg;
import com.yiqi.system.domain.dto.weapp.WeAppOrgQueryDTO;
import com.yiqi.system.domain.vo.OrgVO;
import com.yiqi.system.mapper.SysOrgMapper;
import com.yiqi.system.service.ISysOrgService;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SysOrgServiceImpl extends ServiceImpl<SysOrgMapper, SysOrg> implements ISysOrgService {
    @Override
    public List<OrgVO> findPageOrderByDistance(WeAppOrgQueryDTO weAppOrgQueryDTO) {
        return baseMapper.findPageOrderByDistance(weAppOrgQueryDTO);
    }

    @Override
    public SysOrg findById(Long orgId, String sourceType) {
        if(sourceType.equals(SourceType.MANAGER.getCode())){
            return SysOrg.buildManagerOrg();
        }
        return getOne(new QueryWrapper<SysOrg>().lambda().eq(SysOrg::getId, orgId)
                .eq(SysOrg::getSourceType, sourceType));
    }
}
