<?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="cn.cordys.crm.system.mapper.ExtOrganizationConfigMapper">

    <select id="getOrganizationConfig" parameterType="cn.cordys.crm.system.domain.OrganizationConfig" resultType="cn.cordys.crm.system.domain.OrganizationConfig">
        SELECT * FROM sys_organization_config WHERE organization_id = #{organizationId} AND type = #{type} limit 1;
    </select>

     <update id="updateSyncFlag">
        update sys_organization_config
        set sync = #{syncStatus},
            sync_resource = #{syncResource}
        where organization_id = #{orgId} and type = #{type}
    </update>


    <select id="getSyncFlag" resultType="java.lang.Integer">
        select count(socd.id)
        from sys_organization_config soc
        INNER JOIN sys_organization_config_detail socd on socd.config_id = soc.id
            where soc.organization_id = #{organizationId} and socd.enable = 1 and socd.type = #{type}
    </select>

    <select id="getSyncStatus" resultType="cn.cordys.crm.system.domain.OrganizationConfig">
        SELECT id, sync FROM sys_organization_config WHERE organization_id = #{organizationId} AND type = #{type} AND sync_resource = #{syncResource} limit 1;
    </select>
</mapper>