package cn.iocoder.yudao.module.system.dal.mysql.dictTenant;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;

import cn.iocoder.yudao.module.system.controller.admin.dictTenant.vo.type.DictTypeTenantPageReqVO;
import cn.iocoder.yudao.module.system.dal.dataobject.dict.DictTypeDO;
import cn.iocoder.yudao.module.system.dal.dataobject.dictTenant.DictTypeTenantDO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;

import java.time.LocalDateTime;


/**
 * 租户字典类型 Mapper
 *
 * @author 芋道源码
 */
@Mapper
public interface DictTypeTenantMapper extends BaseMapperX<DictTypeTenantDO> {

    default PageResult<DictTypeTenantDO> selectPage(DictTypeTenantPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<DictTypeTenantDO>()
                .likeIfPresent(DictTypeTenantDO::getName, reqVO.getName())
                .eqIfPresent(DictTypeTenantDO::getType, reqVO.getType())
                .eqIfPresent(DictTypeTenantDO::getStatus, reqVO.getStatus())
                .eqIfPresent(DictTypeTenantDO::getRemark, reqVO.getRemark())
                .betweenIfPresent(DictTypeTenantDO::getCreateTime, reqVO.getCreateTime())
                .betweenIfPresent(DictTypeTenantDO::getDeletedTime, reqVO.getDeletedTime())
                .orderByDesc(DictTypeTenantDO::getId));
    }

    default DictTypeTenantDO selectByType(String type) {
        return selectOne(DictTypeTenantDO::getType, type);
    }

    default DictTypeTenantDO selectByName(String name) {
        return selectOne(DictTypeTenantDO::getName, name);
    }

    @Update("UPDATE system_dict_type SET deleted = 1, deleted_time = #{deletedTime} WHERE id = #{id}")
    void updateToDelete(@Param("id") Long id, @Param("deletedTime") LocalDateTime deletedTime);


}