package com.zt.plat.module.qms.resource.device.dal.mapper;

import com.zt.plat.framework.common.pojo.PageResult;
import com.zt.plat.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.zt.plat.framework.mybatis.core.mapper.BaseMapperX;
import com.zt.plat.framework.mybatis.core.query.MPJLambdaWrapperX;
import com.zt.plat.module.qms.resource.device.controller.vo.DeviceApplyDetailRespVO;
import com.zt.plat.module.qms.resource.device.dal.dataobject.DeviceApplyDetailDO;
import com.zt.plat.module.qms.resource.device.controller.vo.DeviceApplyDetailPageReqVO;
import com.zt.plat.module.qms.resource.device.dal.dataobject.DeviceInfomationDO;
import com.zt.plat.module.qms.resource.device.dal.dataobject.DeviceProductDO;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

/**
 * 设备通用流程明细 Mapper
 *
 * @author 后台管理-1
 */
@Mapper
public interface DeviceApplyDetailMapper extends BaseMapperX<DeviceApplyDetailDO> {

//    default PageResult<DeviceApplyDetailDO> selectPage(DeviceApplyDetailPageReqVO reqVO) {
//        return selectPage(reqVO, new LambdaQueryWrapperX<DeviceApplyDetailDO>()
//                .eqIfPresent(DeviceApplyDetailDO::getApplyId, reqVO.getApplyId())
//                .eqIfPresent(DeviceApplyDetailDO::getDeviceInfomationId, reqVO.getDeviceInfomationId())
//                .eqIfPresent(DeviceApplyDetailDO::getDeviceBorrowDetailId, reqVO.getDeviceBorrowDetailId())
//                .eqIfPresent(DeviceApplyDetailDO::getFormData, reqVO.getFormData())
//                .eqIfPresent(DeviceApplyDetailDO::getSystemDepartmentCode, reqVO.getSystemDepartmentCode())
//                .eqIfPresent(DeviceApplyDetailDO::getRemark, reqVO.getRemark())
//                .betweenIfPresent(DeviceApplyDetailDO::getCreateTime, reqVO.getCreateTime())
//                .orderByDesc(DeviceApplyDetailDO::getId));
//    }

    default PageResult<DeviceApplyDetailRespVO> selectPage(DeviceApplyDetailPageReqVO reqVO) {
        return selectJoinPage(reqVO, DeviceApplyDetailRespVO.class, new MPJLambdaWrapperX<DeviceApplyDetailDO>()
                .leftJoin(DeviceInfomationDO.class, DeviceInfomationDO::getId, DeviceApplyDetailDO::getDeviceInfomationId)
                .leftJoin(DeviceProductDO.class, DeviceProductDO::getId, DeviceInfomationDO::getProductId)
                .selectAll(DeviceApplyDetailDO.class)
                .selectAs(DeviceProductDO::getName, DeviceApplyDetailRespVO::getProductName)
                .selectAs(DeviceProductDO::getModelNo, DeviceApplyDetailRespVO::getModelNo)
                .selectAs(DeviceProductDO::getParameter, DeviceApplyDetailRespVO::getParameter)
                .selectAs(DeviceProductDO::getManufacturer, DeviceApplyDetailRespVO::getManufacturer)
                .selectAs(DeviceInfomationDO::getDeviceName, DeviceApplyDetailRespVO::getDeviceName)
                .selectAs(DeviceInfomationDO::getAlias, DeviceApplyDetailRespVO::getAlias)
                .selectAs(DeviceInfomationDO::getDeviceCode, DeviceApplyDetailRespVO::getDeviceCode)
                .selectAs(DeviceInfomationDO::getFactoryCode, DeviceApplyDetailRespVO::getFactoryCode)
                .selectAs(DeviceInfomationDO::getPosition, DeviceApplyDetailRespVO::getPosition)
                .selectAs(DeviceInfomationDO::getPurchaseDate, DeviceApplyDetailRespVO::getPurchaseDate)
                .selectAs(DeviceInfomationDO::getPurchasePrice, DeviceApplyDetailRespVO::getPurchasePrice)
                .eqIfPresent(DeviceApplyDetailDO::getApplyId, reqVO.getApplyId())
                .eqIfPresent(DeviceApplyDetailDO::getDeviceInfomationId, reqVO.getDeviceInfomationId())
                .inIfPresent(DeviceApplyDetailDO::getDeviceInfomationId, reqVO.getDeviceInfoIdList())
                .eqIfPresent(DeviceApplyDetailDO::getDeviceBorrowDetailId, reqVO.getDeviceBorrowDetailId())
                .eqIfPresent(DeviceApplyDetailDO::getFormData, reqVO.getFormData())
                .eqIfPresent(DeviceApplyDetailDO::getSystemDepartmentCode, reqVO.getSystemDepartmentCode())
                .eqIfPresent(DeviceApplyDetailDO::getRemark, reqVO.getRemark())
                .betweenIfPresent(DeviceApplyDetailDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(DeviceApplyDetailDO::getId)
        );
    }

    default List<DeviceApplyDetailDO> selectList(DeviceApplyDetailPageReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<DeviceApplyDetailDO>()
                .eqIfPresent(DeviceApplyDetailDO::getApplyId, reqVO.getApplyId())
                .eqIfPresent(DeviceApplyDetailDO::getDeviceInfomationId, reqVO.getDeviceInfomationId())
                .inIfPresent(DeviceApplyDetailDO::getDeviceInfomationId, reqVO.getDeviceInfoIdList())
                .eqIfPresent(DeviceApplyDetailDO::getDeviceBorrowDetailId, reqVO.getDeviceBorrowDetailId())
                .eqIfPresent(DeviceApplyDetailDO::getFormData, reqVO.getFormData())
                .eqIfPresent(DeviceApplyDetailDO::getSystemDepartmentCode, reqVO.getSystemDepartmentCode())
                .eqIfPresent(DeviceApplyDetailDO::getRemark, reqVO.getRemark())
                .betweenIfPresent(DeviceApplyDetailDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(DeviceApplyDetailDO::getId));
    }

    default List<DeviceApplyDetailRespVO> selectListWithDeviceInfo(DeviceApplyDetailPageReqVO reqVO) {
        return selectJoinList(DeviceApplyDetailRespVO.class, new MPJLambdaWrapperX<DeviceApplyDetailDO>()
                .leftJoin(DeviceInfomationDO.class, DeviceInfomationDO::getId, DeviceApplyDetailDO::getDeviceInfomationId)
                .leftJoin(DeviceProductDO.class, DeviceProductDO::getId, DeviceInfomationDO::getProductId)
                .selectAll(DeviceApplyDetailDO.class)
                .selectAs(DeviceProductDO::getName, DeviceApplyDetailRespVO::getProductName)
                .selectAs(DeviceProductDO::getModelNo, DeviceApplyDetailRespVO::getModelNo)
                .selectAs(DeviceProductDO::getParameter, DeviceApplyDetailRespVO::getParameter)
                .selectAs(DeviceProductDO::getManufacturer, DeviceApplyDetailRespVO::getManufacturer)
                .selectAs(DeviceInfomationDO::getDeviceName, DeviceApplyDetailRespVO::getDeviceName)
                .selectAs(DeviceInfomationDO::getAlias, DeviceApplyDetailRespVO::getAlias)
                .selectAs(DeviceInfomationDO::getDeviceCode, DeviceApplyDetailRespVO::getDeviceCode)
                .selectAs(DeviceInfomationDO::getFactoryCode, DeviceApplyDetailRespVO::getFactoryCode)
                .selectAs(DeviceInfomationDO::getPosition, DeviceApplyDetailRespVO::getPosition)
                .selectAs(DeviceInfomationDO::getPurchaseDate, DeviceApplyDetailRespVO::getPurchaseDate)
                .selectAs(DeviceInfomationDO::getPurchasePrice, DeviceApplyDetailRespVO::getPurchasePrice)
                .eqIfPresent(DeviceApplyDetailDO::getApplyId, reqVO.getApplyId())
                .eqIfPresent(DeviceApplyDetailDO::getDeviceInfomationId, reqVO.getDeviceInfomationId())
                .inIfPresent(DeviceApplyDetailDO::getDeviceInfomationId, reqVO.getDeviceInfoIdList())
                .eqIfPresent(DeviceApplyDetailDO::getDeviceBorrowDetailId, reqVO.getDeviceBorrowDetailId())
                .eqIfPresent(DeviceApplyDetailDO::getFormData, reqVO.getFormData())
                .eqIfPresent(DeviceApplyDetailDO::getSystemDepartmentCode, reqVO.getSystemDepartmentCode())
                .eqIfPresent(DeviceApplyDetailDO::getRemark, reqVO.getRemark())
                .betweenIfPresent(DeviceApplyDetailDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(DeviceApplyDetailDO::getId)
        );
    }


}