package cn.iocoder.yudao.module.asset.dal.mysql.delivery;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.asset.controller.admin.delivery.vo.DeliveryTaskPageReqVO;
import cn.iocoder.yudao.module.asset.dal.dataobject.delivery.DeliveryTaskDO;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

@Mapper
public interface DeliveryTaskMapper extends BaseMapperX<DeliveryTaskDO> {

    default PageResult<DeliveryTaskDO> selectPage(DeliveryTaskPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<DeliveryTaskDO>()
                .likeIfPresent(DeliveryTaskDO::getTaskCode, reqVO.getTaskCode())
                .likeIfPresent(DeliveryTaskDO::getContractCode, reqVO.getContractCode())
                .likeIfPresent(DeliveryTaskDO::getProjectName, reqVO.getProjectName())
                .likeIfPresent(DeliveryTaskDO::getCustomerName, reqVO.getCustomerName())
                .eqIfPresent(DeliveryTaskDO::getTaskStatus, reqVO.getTaskStatus())
                .eqIfPresent(DeliveryTaskDO::getDeliveryStatus, reqVO.getDeliveryStatus())
                .betweenIfPresent(DeliveryTaskDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(DeliveryTaskDO::getId));
    }

    default long selectCountByContractId(Long contractId) {
        return selectCount(DeliveryTaskDO::getContractId, contractId);
    }

    default List<DeliveryTaskDO> selectListByFilters(DeliveryTaskPageReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<DeliveryTaskDO>()
                .likeIfPresent(DeliveryTaskDO::getTaskCode, reqVO.getTaskCode())
                .likeIfPresent(DeliveryTaskDO::getContractCode, reqVO.getContractCode())
                .likeIfPresent(DeliveryTaskDO::getProjectName, reqVO.getProjectName())
                .likeIfPresent(DeliveryTaskDO::getCustomerName, reqVO.getCustomerName())
                .eqIfPresent(DeliveryTaskDO::getTaskStatus, reqVO.getTaskStatus())
                .eqIfPresent(DeliveryTaskDO::getDeliveryStatus, reqVO.getDeliveryStatus())
                .betweenIfPresent(DeliveryTaskDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(DeliveryTaskDO::getId));
    }

}
