package com.zt.plat.module.qms.common.data.dal.mapper;

import com.zt.plat.framework.common.pojo.PageResult;
import com.zt.plat.framework.mybatis.core.mapper.BaseMapperX;
import com.zt.plat.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.zt.plat.module.qms.common.data.controller.vo.DataCollectionPageReqVO;
import com.zt.plat.module.qms.common.data.dal.dataobject.DataCollectionDO;
import org.apache.ibatis.annotations.Mapper;

/**
 * 数据集 Mapper
 *
 * @author 后台管理
 */
@Mapper
public interface DataCollectionMapper extends BaseMapperX<DataCollectionDO> {

    default PageResult<DataCollectionDO> selectPage(DataCollectionPageReqVO reqVO) {

        LambdaQueryWrapperX<DataCollectionDO> wrapper = new LambdaQueryWrapperX<>();
        wrapper.ne(DataCollectionDO::getCancelFlag, -1);    //-1为临时数据
        wrapper.eqIfPresent(DataCollectionDO::getParentId, reqVO.getParentId());
        wrapper.eqIfPresent(DataCollectionDO::getMainId, reqVO.getMainId());
        wrapper.eqIfPresent(DataCollectionDO::getIdPath, reqVO.getIdPath());
        wrapper.likeIfPresent(DataCollectionDO::getName, reqVO.getName());
        wrapper.eqIfPresent(DataCollectionDO::getNodeType, reqVO.getNodeType());
        wrapper.eqIfPresent(DataCollectionDO::getDataKey, reqVO.getDataKey());
        wrapper.eqIfPresent(DataCollectionDO::getVersion, reqVO.getVersion());
        wrapper.eqIfPresent(DataCollectionDO::getCurrentFlag, reqVO.getCurrentFlag());
        wrapper.eqIfPresent(DataCollectionDO::getCancelFlag, reqVO.getCancelFlag());
        wrapper.eqIfPresent(DataCollectionDO::getFlowFlag, reqVO.getFlowFlag());
        wrapper.eqIfPresent(DataCollectionDO::getFormKey, reqVO.getFormKey());
        wrapper.eqIfPresent(DataCollectionDO::getFormVersionId, reqVO.getFormVersionId());
        wrapper.eqIfPresent(DataCollectionDO::getFlowKey, reqVO.getFlowKey());
        wrapper.eqIfPresent(DataCollectionDO::getFlowVersionId, reqVO.getFlowVersionId());
        wrapper.eqIfPresent(DataCollectionDO::getSortNo, reqVO.getSortNo());
        wrapper.eqIfPresent(DataCollectionDO::getCustomConfig, reqVO.getCustomConfig());
        wrapper.eqIfPresent(DataCollectionDO::getSystemDepartmentCode, reqVO.getSystemDepartmentCode());
        wrapper.eqIfPresent(DataCollectionDO::getRemark, reqVO.getRemark());
        wrapper.betweenIfPresent(DataCollectionDO::getCreateTime, reqVO.getCreateTime());

        if(reqVO.getMainId() != null){
            wrapper.orderByDesc(DataCollectionDO::getVersion);
        }
        wrapper.orderByAsc(DataCollectionDO::getSortNo);

        return selectPage(reqVO, wrapper);
    }

}