package com.zt.plat.module.base.dal.mysql.base;

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.api.dto.ElementDTO;
import com.zt.plat.module.base.controller.admin.base.vo.ElementPageReqVO;
import com.zt.plat.module.base.dal.dataobject.base.ElementDO;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

/**
 * 金属元素 Mapper
 *
 * @author 后台管理
 */
@Mapper
public interface ElementMapper extends BaseMapperX<ElementDO> {

    default PageResult<ElementDO> selectPage(ElementPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<ElementDO>()
                .likeIfPresent(ElementDO::getAbbreviation, reqVO.getAbbreviation())
                .likeIfPresent(ElementDO::getName, reqVO.getName())
             //   .eqIfPresent(ElementDO::getDecimalValue, reqVO.getDecimalValue())
                .eqIfPresent(ElementDO::getIsEnable, reqVO.getIsEnable())
                .likeIfPresent(ElementDO::getCoding, reqVO.getCoding())
                .eqIfPresent(ElementDO::getGradeUnit, reqVO.getGradeUnit())
                .betweenIfPresent(ElementDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(ElementDO::getSort));
    }

    String selectMaxCode();

    default List<ElementDO> getElementNoPage() {
        return selectList(new LambdaQueryWrapperX<ElementDO>()
                .eq(ElementDO::getIsEnable, 1)
                .orderByDesc(ElementDO::getSort));
    }

    default ElementDO getElementName(String code){
        return selectOne(new LambdaQueryWrapperX<ElementDO>()
                .eq(ElementDO::getAbbreviation, code));
    };
}