<?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.xunmei.core.resumption.mapper.AppRuleMapper">
    <select id="selectPageByCondition" resultType="com.xunmei.core.resumption.vo.appRule.AppRulePageVo">
        select a.id as id,
        a.name,
        a.type,
        a.org_type as orgType,
        a.status as status,
        a.remark as remark,
        a.org_id as orgId,
        org.name as orgName
        from core_resumption_rule a
        inner join sys_org org on a.org_id = org.id
        <where>
            <if test="appRule.name != null and appRule.name != ''">
                and a.name like CONCAT('%',#{appRule.name},'%')
            </if>
            <if test="appRule.type != null and appRule.type != ''">
                and a.type = #{appRule.type}
            </if>
            <if test="appRule.orgType != null">
                and a.org_type = #{appRule.orgType}
            </if>
            <if test="appRule.checkSub==false">
                and a.org_id=#{appRule.orgId}
            </if>
        </where>
        order by a.create_time desc
    </select>

    <select id="getRuleGroupList" resultType="com.xunmei.core.resumption.vo.appRule.AppRuleGroupVo">
        select r.id       as ruleId,
               r.name     as name,
               d.name     as orgType,
               r.org_type as orgTypeId
        from core_resumption_rule r
                 inner join sys_dict_data d on r.type = d.id and d.dict_code = 'sys_org_type'
        where status = 0
    </select>

    <!--    <select id="get" resultType="com.xunmei.core.resumption.vo.appRule.AppRuleInfoVo">-->
    <!--        select r.id,-->
    <!--               r.name     as name,-->
    <!--               r.type     as type,-->
    <!--               r.org_type as orgType,-->
    <!--               r.status   as status,-->
    <!--               r.remark   as remark-->
    <!--        from core_resumption_rule r-->
    <!--                 inner join sys_dict_data d on r.type = d.code and d.dict_code = 'rule_type'-->
    <!--        where r.id = #{id}-->
    <!--    </select>-->

    <select id="checkRuleNameRepeat" resultType="java.lang.Integer">
        select count(id) from core_resumption_rule where name=#{name}
        <if test="id != null">
            and id != #{id}
        </if>
    </select>


    <!--    <select id="checkRuleTypeUniformity" resultType="java.lang.Integer">-->
    <!--        SELECT SUM(c) as c from (-->
    <!--              SELECT count(0) as c FROM core_resumption_rule_item WHERE rule_id=#{id} and type!= #{ruletype}-->
    <!--              UNION-->
    <!--              SELECT count(0) as c FROM core_resumption_rule_point WHERE rule_id=#{id} and type!= #{ruletype} )a-->
    <!--    </select>-->

    <!--    <update id="updateItemRuleType">-->
    <!--        update core_resumption_rule_item-->
    <!--        set type=#{ruletype}-->
    <!--        where rule_id = #{id}-->
    <!--          and type != #{ruletype}-->
    <!--    </update>-->

    <!--    <update id="updatePointRuleType">-->
    <!--        update core_resumption_rule_point-->
    <!--        set type=#{ruletype}-->
    <!--        where rule_id = #{id}-->
    <!--          and type != #{ruletype}-->
    <!--    </update>-->
</mapper>
