package com.rongwei.sfcommon.sys.dao;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.rongwe.scentity.domian.CheckItemsDo;
import com.rongwe.scentity.vo.CheckItemsTypeVo;
import com.rongwei.rwcommon.base.BaseDao;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 检查对象表
 *
 * @author chglee
 * @email 1992lcg@163.com
 * @date 2020-07-17 09:33:23
 */
public interface CheckItemsDao extends BaseDao<CheckItemsDo> {

    @Select("select *  from asp_check_items WHERE DELETED='0' and STANDBY='y' and (ENABLED is NULL  or ENABLED ='enable' or ENABLED='')")
    IPage<CheckItemsDo> spareList(Page page);

    @Select("SELECT\n" +
            "\taci.*,\n" +
            "\tb.`NAME` AS typeName \n" +
            "FROM\n" +
            "\tasp_check_items aci\n" +
            "\tLEFT JOIN ( SELECT * FROM sys_dict WHERE DELETED = 0 AND DICTTYPE = 'asp_check_item_type' ) b ON aci.CHECKITEMTYPE = b.`VALUE` \n" +
            "WHERE\n" +
            "\taci.DELETED = 0 \n" +
            "\tAND DATE_FORMAT( aci.WARNDATE, '%Y-%m-%d' ) <= DATE_FORMAT(\n" +
            "\tNOW(),\n" +
            "\t'%Y-%m-%d')")
    List<CheckItemsTypeVo> selectNeedReportEqu();

    //特种设备管理员的ID：08e111e9dbc04706a3eb8367a65a3dc5
    @Select("SELECT\n" +
            "\tsu.ID \n" +
            "FROM\n" +
            "\tsys_user su\n" +
            "\tLEFT JOIN sys_user_role sur ON su.ID = sur.USERID \n" +
            "\tAND sur.DELETED = 0\n" +
            "\tLEFT JOIN sys_user_org suo ON suo.USERID = su.ID \n" +
            "\tAND suo.DELETED = 0\n" +
            "\tLEFT JOIN sys_organization so ON suo.ORGID = so.ID \n" +
            "\tAND so.DELETED = 0 \n" +
            "WHERE\n" +
            "\tsu.DELETED = 0 \n" +
            "\tAND sur.ROLEID = '08e111e9dbc04706a3eb8367a65a3dc5' \n" +
            "\tAND (\n" +
            "\tso.ID = #{tenantId} \n" +
            "\tOR so.FULLPID LIKE CONCAT( '%', #{tenantId}, '%' ))")
    List<String> selectUserByTenantId(String tenantId);
}