package com.cf.imes.module.executor.dal.mysql.order;

import java.util.*;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.cf.imes.framework.common.pojo.PageResult;
import com.cf.imes.framework.mybatis.core.mapper.BaseMapperX;
import com.cf.imes.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.cf.imes.module.executor.controller.admin.order.vo.order.OrderPageReqVO;
import com.cf.imes.module.executor.controller.admin.plan.vo.OrderRespVO;
import com.cf.imes.module.executor.dal.dataobject.order.OrderDO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

/**
 * 生产单表 order_{N} Mapper
 *
 * @author 晨丰科技
 */
@Mapper
public interface OrderMapper extends BaseMapperX<OrderDO> {

    default PageResult<OrderDO> selectPage(OrderPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<OrderDO>()
                .eqIfPresent(OrderDO::getParentNo, reqVO.getParentNo())
                .betweenIfPresent(OrderDO::getDeliveryDate, reqVO.getDeliveryDate())
                .eqIfPresent(OrderDO::getType, reqVO.getType())
                .eqIfPresent(OrderDO::getSort, reqVO.getSort())
                .eqIfPresent(OrderDO::getDataType, reqVO.getDataType())
                .eqIfPresent(OrderDO::getStatus, reqVO.getStatus())
                .eqIfPresent(OrderDO::getCustomOrderNo, reqVO.getCustomOrderNo())
                .eqIfPresent(OrderDO::getCustomer, reqVO.getCustomer())
                .eqIfPresent(OrderDO::getAddress, reqVO.getAddress())
                .eqIfPresent(OrderDO::getPhoneNumber, reqVO.getPhoneNumber())
                .eqIfPresent(OrderDO::getDealer, reqVO.getDealer())
                .eqIfPresent(OrderDO::getDealerPhoneNumber, reqVO.getDealerPhoneNumber())
                .eqIfPresent(OrderDO::getSalesman, reqVO.getSalesman())
                .eqIfPresent(OrderDO::getSplitter, reqVO.getSplitter())
                .eqIfPresent(OrderDO::getRemark, reqVO.getRemark())
                .betweenIfPresent(OrderDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(OrderDO::getId));
    }


    IPage<OrderRespVO> selectOrderPage(@Param("page") IPage page, @Param(Constants.WRAPPER) Wrapper<OrderDO> wrapper);
}
