package com.cf.imes.module.system.dal.mysql.systemconfig;


import com.cf.imes.framework.mybatis.core.mapper.BaseMapperX;
import com.cf.imes.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.cf.imes.framework.organ.core.context.OrganContextHolder;
import com.cf.imes.module.system.dal.dataobject.systemconfig.SystemConfigDO;
import com.cf.imes.module.system.dal.dataobject.systemconfig.SystemConfigDataDO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.util.List;

/**
 * @author 优化数据配置 Mapper
 */

@Mapper
public interface SystemConfigDataMapper extends BaseMapperX<SystemConfigDataDO> {

    default List<SystemConfigDataDO> selectSystemConfigList(Integer type, Integer status) {
        return selectList(new LambdaQueryWrapperX<SystemConfigDataDO>()
                .eqIfPresent(SystemConfigDataDO::getOrganId, OrganContextHolder.getOrganId())
                .eq(SystemConfigDataDO::getDeleted,false)
                .eq(SystemConfigDataDO::getType, type)
                .eqIfPresent(SystemConfigDataDO::getStatus,status)
                .orderByAsc(SystemConfigDataDO::getSort, SystemConfigDO::getCreateTime));
    }

    @Delete("delete from system_config_data where  organ_id = #{organId} and id = #{id}")
    void deleteConfig(@Param("id") Long id, @Param("organId") Long organId);
}
