package com.yc.ship.module.trade.dal.mysql.contract;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.yc.ship.framework.common.pojo.PageResult;
import com.yc.ship.framework.mybatis.core.mapper.BaseMapperX;
import com.yc.ship.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.yc.ship.module.trade.controller.admin.contract.vo.ContractPageReqVO;
import com.yc.ship.module.trade.dal.dataobject.contract.ContractDO;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

/**
 * 合同 Mapper
 *
 * @author 管理员
 */
@Mapper
public interface ContractMapper extends BaseMapperX<ContractDO> {

    default PageResult<ContractDO> selectPage(ContractPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<ContractDO>()
                .eqIfPresent(ContractDO::getOrderId, reqVO.getOrderId())
                .eqIfPresent(ContractDO::getOrderNo, reqVO.getOrderNo())
                .eqIfPresent(ContractDO::getContractNo, reqVO.getContractNo())
                .eqIfPresent(ContractDO::getErpContractId, reqVO.getErpContractId())
                .eqIfPresent(ContractDO::getContractUrl, reqVO.getContractUrl())
                .eqIfPresent(ContractDO::getStatus, reqVO.getStatus())
                .eqIfPresent(ContractDO::getTouristsCount, reqVO.getTouristsCount())
                .likeIfPresent(ContractDO::getSignerName, reqVO.getSignerName())
                .eqIfPresent(ContractDO::getSignerMobile, reqVO.getSignerMobile())
                .betweenIfPresent(ContractDO::getSigningTime, reqVO.getSigningTime())
                .likeIfPresent(ContractDO::getOperateName, reqVO.getOperateName())
                .eqIfPresent(ContractDO::getOperateMobile, reqVO.getOperateMobile())
                .betweenIfPresent(ContractDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(ContractDO::getId));
    }

    default List<ContractDO> selectContractList( String contractNumber){
        return selectList(new LambdaQueryWrapperX<ContractDO>().eq(ContractDO::getContractNo,contractNumber));
    }

    default void updateAddOrderId(Long orderId,Long mainOrderId) {
        LambdaUpdateWrapper<ContractDO> wrapper = new LambdaUpdateWrapper<>();
        wrapper.eq(ContractDO::getOrderId, orderId);
        wrapper.set(ContractDO::getOrderId, mainOrderId);
        update(wrapper);
    }
}