<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.xjrsoft.module.evaluate.mapper.EvaluateTemplateMapper">
    <select id="getPage" parameterType="com.xjrsoft.module.evaluate.dto.EvaluateTemplatePageDto" resultType="com.xjrsoft.module.evaluate.vo.EvaluateTemplatePageVo">
        SELECT t.id, t.name, t.sort_code,
        t2.name AS evaluate_type,
        t.dept_ids, t.total, t.remark, t.status
        FROM evaluate_template t
        left join xjr_dictionary_detail t2 on t.evaluate_type = t2.code and t2.item_id = 1746831039385366530
        WHERE t.delete_mark = 0
        <if test="dto.deptIds != null and dto.deptIds != ''">
            <choose>
                <when test="dto.deptIds == 0">
                    AND JSON_CONTAINS(t.dept_ids, JSON_ARRAY(0))
                </when>
                <otherwise>
                    AND t.dept_ids like concat('%',#{dto.deptIds},'%')
                </otherwise>
            </choose>
        </if>
        <if test="dto.evaluateType != null and dto.evaluateType != ''">
            AND t.evaluate_type = #{dto.evaluateType}
        </if>
        <if test="dto.name != null">
            AND t.name like concat('%',#{dto.name},'%')
        </if>
        <if test="dto.status != null">
            AND t.status = #{dto.status}
        </if>
        ORDER BY t.id
    </select>

</mapper>


        <!--    SELECT t.id, t.name,-->
        <!--    (SELECT t1.name-->
        <!--    FROM xjr_dictionary_detail t1-->
        <!--    JOIN xjr_dictionary_item t2 ON t1.item_id = t2.id-->
        <!--    WHERE t2.code = 'evaluate_type'-->
        <!--    AND t1.code = t.evaluate_type) AS evaluate_type,-->
        <!--    t.dept_ids, t.total, t.remark, t.status-->
        <!--    FROM evaluate_template t-->
        <!--    WHERE t.delete_mark = 0-->
        <!--    <if test="dto.deptIds != null and dto.deptIds != ''">-->
        <!--        AND t.dept_ids = #{dto.deptIds}-->
        <!--    </if>-->
        <!--    <if test="dto.evaluateType != null and dto.evaluateType != ''">-->
        <!--        AND t.evaluate_type = #{dto.evaluateType}-->
        <!--    </if>-->
        <!--    <if test="dto.name != null">-->
        <!--        AND t.name = #{dto.name}-->
        <!--    </if>-->
        <!--    <if test="dto.status != null">-->
        <!--        AND t.status = #{dto.status}-->
        <!--    </if>-->
        <!--    ORDER BY t.id-->
        <!--</select>-->