package com.sy.coinage.sys.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sy.coinage.core.constants.Constants;
import com.sy.coinage.core.vo.OptVO;
import com.sy.coinage.sys.dao.OrgDao;
import com.sy.coinage.sys.model.*;
import com.sy.coinage.sys.req.*;
import com.sy.coinage.sys.service.IOrgService;
import com.sy.coinage.sys.vo.*;
import java.util.List;
import org.springframework.stereotype.Service;

/**
 * 组织机构ServiceImpl
 */
@Service
public class OrgServiceImpl extends ServiceImpl<OrgDao, Org> implements IOrgService {

    @Override
    public IPage<OrgListVO> queryPageList(OrgListReq req, Integer tenantId) {
        LambdaQueryWrapper<Org> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Org::getTenantId, tenantId);
        queryWrapper.eq(Org::getDelFlag, Constants.STATUS_USABLE);
        queryWrapper.orderByAsc(Org::getSorted);
        Page<OrgListVO> page = new Page<>(req.getPage(), req.getRows());
        IPage<OrgListVO> resp = this.baseMapper.queryPageList(page, queryWrapper);
        return resp;
    }

    @Override
    public List<OptVO> opt(Integer tenantId) {
        LambdaQueryWrapper<Org> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Org::getTenantId, tenantId);
        queryWrapper.eq(Org::getStatus, Constants.STATUS_USABLE).eq(Org::getDelFlag, Constants.STATUS_USABLE);
        queryWrapper.orderByAsc(Org::getSorted);
        List<OptVO> resp = this.baseMapper.queryOptList(queryWrapper);
        return resp;
    }

}
