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.SystemConfigSchemeDO;
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 SystemConfigSchemeMapper extends BaseMapperX<SystemConfigSchemeDO> {


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


    default List<SystemConfigSchemeDO> selectOrganConfig(Long organId) {
        return selectList(new LambdaQueryWrapperX<SystemConfigSchemeDO>()
                .eq(SystemConfigSchemeDO::getOrganId, organId)
                .eq(SystemConfigSchemeDO::getDeleted,false));
    }


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

}
