package com.cf.imes.module.manage.dal.mysql.query;


import com.baomidou.mybatisplus.core.metadata.IPage;
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.manage.controller.admin.pack.vo.PackPageReqVO;
import com.cf.imes.module.manage.controller.admin.pack.vo.PackRespVO;
import com.cf.imes.module.manage.controller.admin.pack.vo.PrintOrderPackRespVO;
import com.cf.imes.module.manage.controller.admin.query.vo.productionStatus.OrderPlatePageReqVO;
import com.cf.imes.module.manage.controller.admin.query.vo.pack.PrintOrderRespVO;
import com.cf.imes.module.manage.dal.dataobject.process.OrderDO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.util.List;

import static com.cf.imes.framework.security.core.util.SecurityFrameworkUtils.getUserOrganId;

@Mapper
public interface ProductionStatusMapper extends BaseMapperX<OrderDO> {


    default PageResult<OrderDO> selectProductionPage(OrderPlatePageReqVO pageReqVO) {
        return selectPage(pageReqVO, new LambdaQueryWrapperX<OrderDO>()
                .eqIfPresent(OrderDO::getId, pageReqVO.getOrderNo())
                .eqIfPresent(OrderDO::getCustomOrderNo, pageReqVO.getCustomOrderNo())
                .likeIfPresent(OrderDO::getCustomer, pageReqVO.getCustomer())
                .likeIfPresent(OrderDO::getAddress, pageReqVO.getAddress())
                .and(wrapper -> {
                    for (Long status : pageReqVO.getStatusList()) {
                        wrapper.or().eq(OrderDO::getStatus, status);
                    }
                })
                .orderByDesc(OrderDO::getCreateTime));
    }






    PrintOrderRespVO selectPrintOrder(@Param("orderNo") Long orderNo,@Param("organId")Long organId);


    default List<OrderDO> selectPackPage(PackPageReqVO pageReqVO,Long organId) {
        return selectList(new LambdaQueryWrapperX<OrderDO>()
                .eq(OrderDO::getOrganId,organId)
                .eqIfPresent(OrderDO::getOrganId,getUserOrganId())
                .eqIfPresent(OrderDO::getId, pageReqVO.getOrderNo())
                .eqIfPresent(OrderDO::getCustomOrderNo, pageReqVO.getCustomOrderNo())
                .likeIfPresent(OrderDO::getCustomer, pageReqVO.getCustomer())
                .likeIfPresent(OrderDO::getAddress, pageReqVO.getAddress())
                .eqIfPresent(OrderDO::getStatus, pageReqVO.getStatus())
                .orderByDesc(OrderDO::getCreateTime));
    }

    IPage<PackRespVO> selectOrderPlate( @Param("page") IPage page, @Param("collect") List<Long> collect, @Param("organId")  Long organId);




    PrintOrderPackRespVO selectOrderPack(@Param("orderNo")Long orderNo,@Param("packageNo") Long packageNo, @Param("organId")  Long organId);



}
