package com.jy.business.contract.dao;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jy.business.contract.mapper.ContractDetailMapper;
import com.jy.business.contract.model.dto.ContractDetailSelectDto;
import com.jy.business.contract.model.entity.ContractDetail;
import com.jy.business.contract.model.table.ContractDetailTable;
import com.jy.business.contract.model.vo.ContractDetailVo;
import com.jy.framework.model.base.BaseDao;
import com.jy.system.service.AuthService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ContractDetailDao extends BaseDao<ContractDetailMapper, ContractDetail> {

    @Resource
    private AuthService authService;

    /**
     * 合同明细列表
     */
    public List<ContractDetailVo> getList(ContractDetailSelectDto dto) {
        ContractDetailTable cd = ContractDetailTable.cd;

        return sql(ContractDetailVo.class)
                .select(
                        cd.all
                )
                .from(cd)
                .where(
                        cd.createUser.in(authService.getUserPermissionSet())
                )
                .orderBy(
                    cd.id.desc()
                )
                .list();
    }

    /**
     * 合同明细明细
     */
    public ContractDetailVo getDetail(Long id) {
        ContractDetailTable cd = ContractDetailTable.cd;

        return sql(ContractDetailVo.class)
                .select(
                        cd.all
                )
                .from(cd)
                .where(
                        cd.id.eq(id)
                )
                .one();
    }

}
