package com.jy.business.corporation.dao;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jy.business.corporation.mapper.CorporationMapper;
import com.jy.business.corporation.model.dto.CorporationSelectDto;
import com.jy.business.corporation.model.entity.Corporation;
import com.jy.business.corporation.model.table.CorporationTable;
import com.jy.business.corporation.model.vo.CorporationVo;
import com.jy.framework.model.base.BaseDao;
import com.jy.system.service.AuthService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

@Service
public class CorporationDao extends BaseDao<CorporationMapper, Corporation> {

    @Resource
    private AuthService authService;

    /**
     * 公司信息分页
     */
    public Page<CorporationVo> getPage(CorporationSelectDto dto) {
        CorporationTable c = CorporationTable.c;

        return sql(CorporationVo.class)
                .select(
                        c.all
                )
                .from(c)
                .where(
                        c.createUser.in(authService.getUserPermissionSet()),
                        c.name.like(dto.getName()),
                        c.type.eq(dto.getType()),
                        c.uscCode.like(dto.getUscCode())
                )
                .orderBy(
                        c.id.desc()
                )
                .page(dto.getPage());
    }

    /**
     * 公司信息明细
     */
    public CorporationVo getDetail(Long id) {
        CorporationTable c = CorporationTable.c;

        return sql(CorporationVo.class)
                .select(
                        c.all
                )
                .from(c)
                .where(
                        c.id.eq(id)
                )
                .one();
    }

}
