package com.jy.business.contract.dao;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jy.business.contract.mapper.ContractInfoMapper;
import com.jy.business.contract.model.dto.ContractInfoSelectDto;
import com.jy.business.contract.model.entity.ContractInfo;
import com.jy.business.contract.model.table.ContractInfoTable;
import com.jy.business.contract.model.vo.ContractInfoVo;
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 ContractInfoDao extends BaseDao<ContractInfoMapper, ContractInfo> {

    @Resource
    private AuthService authService;

    /**
     * 合同分页
     */
    public Page<ContractInfoVo> getPage(ContractInfoSelectDto dto) {
        ContractInfoTable ci = ContractInfoTable.ci;

        return sql(ContractInfoVo.class)
                .select(
                        ci.all
                )
                .from(ci)
                .where(
                        ci.createUser.in(authService.getUserPermissionSet())
                )
                .orderBy(
                        ci.id.desc()
                )
                .page(dto.getPage());
    }

    /**
     * 合同明细
     */
    public ContractInfoVo getDetail(Long id) {
        ContractInfoTable ci = ContractInfoTable.ci;

        return sql(ContractInfoVo.class)
                .select(
                        ci.all
                )
                .from(ci)
                .where(
                        ci.id.eq(id)
                )
                .one();
    }

}
