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.ThemeCheckItemDo;
import com.rongwe.scentity.vo.ThemeCheckItemVo;
import com.rongwei.rwcommon.base.BaseDao;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

/**
 * 主题检查检查任务表
 *
 * @author chglee
 * @email 1992lcg@163.com
 * @date 2020-07-17 09:33:23
 */
public interface ThemeCheckItemDao extends BaseDao<ThemeCheckItemDo> {

    @Select("<script>select DISTINCT a.USERID,a.ROLEID,c.NAME AS USERNAME,d.CODE,d.NAME AS ROLENAME,c.EMAIL from sys_user_role a left join sys_user_org b on a.USERID=b.USERID " +
            "left join sys_user c on a.USERID=c.ID left join sys_role d on a.ROLEID=d.ID " +
            "where a.DELETED='0' and b.DELETED='0' and c.DELETED='0' and d.DELETED='0' " +
            "<if test='orgId!=null'>" +
            "and b.ORGID=#{orgId}" +
            "</if>" +
            "<if test='roleCode!=null'>" +
            "and d.CODE=#{roleCode}" +
            "</if>" +
            "</script>")
    List<Map<String, Object>> getGdzgByUserId(@Param("orgId") String orgId, @Param("roleCode") String roleCode);

    @Select("select * from asp_theme_check_item where (GROUPLEADER like '%${userid}%' or GROUPUSERS like '%${userid}%') and CHECKSTATUS = 'prepare' and DELETED = '0' order by CREATEDATE desc")
    IPage<ThemeCheckItemVo> themeChecktodoList(Page page, @Param("userid") String userid);

    @Select("select * from asp_theme_check_item where (GROUPLEADER like '%${userid}%' or GROUPUSERS like '%${userid}%') and CHECKSTATUS = 'done' and DELETED = '0' order by CREATEDATE desc")
    IPage<ThemeCheckItemVo> themeCheckdoneList(Page page, @Param("userid") String userid);


    @Select("SELECT\n" +
            "\tcount(atci.ID) as count\n" +
            "FROM\n" +
            "\t asp_theme_check_item atci \n" +
            "\tLEFT JOIN  asp_theme_check atc on atci.THEMECHECKID =atc.ID\n" +
            "WHERE\n" +
            "\tatci.DELETED = '0' \n" +
            "\tAND atci.ID in ('${id}') \n" +
            "\tAND atc.CHECKTYPE='20'")
    int checkSendMail(@Param("id") String id);
}
