package com.zt.plat.module.qms.resource.clientManage.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.module.qms.resource.clientManage.dal.dataobject.VersionManagementDO;
import com.zt.plat.module.qms.resource.clientManage.controller.vo.VersionManagementPageReqVO;
import org.apache.ibatis.annotations.Mapper;

import java.util.Collections;
import java.util.List;

/**
 * 客户端版本管理 Mapper
 *
 * @author 后台管理
 */
@Mapper
public interface VersionManagementMapper extends BaseMapperX<VersionManagementDO> {

    default PageResult<VersionManagementDO> selectPage(VersionManagementPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<VersionManagementDO>()
                .eqIfPresent(VersionManagementDO::getApplicationCode, reqVO.getApplicationCode())
                .eqIfPresent(VersionManagementDO::getApplicationName, reqVO.getApplicationName())
                .eqIfPresent(VersionManagementDO::getUpdateTitle, reqVO.getUpdateTitle())
                .eqIfPresent(VersionManagementDO::getUpdateContent, reqVO.getUpdateContent())
                .eqIfPresent(VersionManagementDO::getUpdatePlatform, reqVO.getUpdatePlatform())
                .eqIfPresent(VersionManagementDO::getPublishFlag, reqVO.getPublishFlag())
                .eqIfPresent(VersionManagementDO::getSystemDepartmentCode, reqVO.getSystemDepartmentCode())
                .eqIfPresent(VersionManagementDO::getCreator, reqVO.getCreator())
                .betweenIfPresent(VersionManagementDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(VersionManagementDO::getId));
    }


    default PageResult<VersionManagementDO> selectList(VersionManagementPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<VersionManagementDO>()
                .eqIfPresent(VersionManagementDO::getUpdatePlatform, reqVO.getUpdatePlatform())
                .eqIfPresent(VersionManagementDO::getUpdateType, reqVO.getUpdateType())
                .eqIfPresent(VersionManagementDO::getApplicationCode, reqVO.getApplicationCode())
                .eq(VersionManagementDO::getPublishFlag,1)
                .orderByDesc(VersionManagementDO::getCreateTime)
//                .last("LIMIT 1")
        );
    }
}