<?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.gic.haoban.manage.service.dao.mapper.ApplicationSettingMapper">
    <resultMap id="BaseResultMap" type="com.gic.haoban.manage.service.entity.TabHaobanApplicationSetting">
        <id column="setting_id" property="settingId" jdbcType="VARCHAR"/>
        <result column="application_id" property="applicationId" jdbcType="VARCHAR"/>
        <result column="wx_enterprise_id" property="wxEnterpriseId" jdbcType="VARCHAR"/>
        <result column="status_flag" property="statusFlag" jdbcType="INTEGER"/>
        <result column="open_flag" property="openFlag" jdbcType="INTEGER"/>
        <result column="create_time" property="createTime" jdbcType="TIMESTAMP"/>
        <result column="update_time" property="updateTime" jdbcType="TIMESTAMP"/>
    </resultMap>
    <sql id="Base_Column_List">
        setting_id
        , application_id, wx_enterprise_id, status_flag, open_flag, create_time,
    update_time
    </sql>
    <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.String">
        select
        <include refid="Base_Column_List"/>
        from tab_haoban_application_setting
        where setting_id = #{settingId,jdbcType=VARCHAR}
    </select>
    <delete id="deleteByPrimaryKey" parameterType="java.lang.String">
        delete
        from tab_haoban_application_setting
        where setting_id = #{settingId,jdbcType=VARCHAR}
    </delete>
    <insert id="insert" parameterType="com.gic.haoban.manage.service.entity.TabHaobanApplicationSetting">
        insert into tab_haoban_application_setting (setting_id, application_id, wx_enterprise_id,
                                                    status_flag, open_flag, create_time,
                                                    update_time)
        values (#{settingId,jdbcType=VARCHAR}, #{applicationId,jdbcType=VARCHAR}, #{wxEnterpriseId,jdbcType=VARCHAR},
                #{statusFlag,jdbcType=INTEGER}, #{openFlag,jdbcType=INTEGER}, #{createTime,jdbcType=TIMESTAMP},
                #{updateTime,jdbcType=TIMESTAMP})
    </insert>
    <insert id="insertSelective" parameterType="com.gic.haoban.manage.service.entity.TabHaobanApplicationSetting">
        insert into tab_haoban_application_setting
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="settingId != null">
                setting_id,
            </if>
            <if test="applicationId != null">
                application_id,
            </if>
            <if test="wxEnterpriseId != null">
                wx_enterprise_id,
            </if>
            <if test="statusFlag != null">
                status_flag,
            </if>
            <if test="openFlag != null">
                open_flag,
            </if>
            <if test="createTime != null">
                create_time,
            </if>
            <if test="updateTime != null">
                update_time,
            </if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="settingId != null">
                #{settingId,jdbcType=VARCHAR},
            </if>
            <if test="applicationId != null">
                #{applicationId,jdbcType=VARCHAR},
            </if>
            <if test="wxEnterpriseId != null">
                #{wxEnterpriseId,jdbcType=VARCHAR},
            </if>
            <if test="statusFlag != null">
                #{statusFlag,jdbcType=INTEGER},
            </if>
            <if test="openFlag != null">
                #{openFlag,jdbcType=INTEGER},
            </if>
            <if test="createTime != null">
                #{createTime,jdbcType=TIMESTAMP},
            </if>
            <if test="updateTime != null">
                #{updateTime,jdbcType=TIMESTAMP},
            </if>
        </trim>
    </insert>
    <update id="updateByPrimaryKeySelective"
            parameterType="com.gic.haoban.manage.service.entity.TabHaobanApplicationSetting">
        update tab_haoban_application_setting
        <set>
            <if test="applicationId != null">
                application_id = #{applicationId,jdbcType=VARCHAR},
            </if>
            <if test="wxEnterpriseId != null">
                wx_enterprise_id = #{wxEnterpriseId,jdbcType=VARCHAR},
            </if>
            <if test="statusFlag != null">
                status_flag = #{statusFlag,jdbcType=INTEGER},
            </if>
            <if test="openFlag != null">
                open_flag = #{openFlag,jdbcType=INTEGER},
            </if>
            <if test="createTime != null">
                create_time = #{createTime,jdbcType=TIMESTAMP},
            </if>
            <if test="updateTime != null">
                update_time = #{updateTime,jdbcType=TIMESTAMP},
            </if>
        </set>
        where setting_id = #{settingId,jdbcType=VARCHAR}
    </update>
    <update id="updateByPrimaryKey" parameterType="com.gic.haoban.manage.service.entity.TabHaobanApplicationSetting">
        update tab_haoban_application_setting
        set application_id   = #{applicationId,jdbcType=VARCHAR},
            wx_enterprise_id = #{wxEnterpriseId,jdbcType=VARCHAR},
            status_flag      = #{statusFlag,jdbcType=INTEGER},
            open_flag        = #{openFlag,jdbcType=INTEGER},
            create_time      = #{createTime,jdbcType=TIMESTAMP},
            update_time      = #{updateTime,jdbcType=TIMESTAMP}
        where setting_id = #{settingId,jdbcType=VARCHAR}
    </update>
    <update id="saveSetting" parameterType="com.gic.haoban.manage.service.entity.TabHaobanApplicationSetting">
        update tab_haoban_application_setting
        set update_time = NOW(),
        <if test="openFlag != null">
            open_flag = #{openFlag,jdbcType=INTEGER}
        </if>
        where wx_enterprise_id = #{wxEnterpriseId,jdbcType=VARCHAR}
        and application_id = #{applicationId,jdbcType=VARCHAR}
        and status_flag = 1
    </update>

    <select id="findSetting" resultMap="BaseResultMap" parameterType="java.lang.String">
        select
        <include refid="Base_Column_List"/>
        from tab_haoban_application_setting
        where application_id = #{applicationId,jdbcType=VARCHAR}
        and wx_enterprise_id = #{wxEnterpriseId,jdbcType=VARCHAR}
    </select>

    <select id="listOpenByWxEnterpriseIdAndApplicationIds" resultMap="BaseResultMap" parameterType="java.lang.String">
        select
        <include refid="Base_Column_List"/>
        from tab_haoban_application_setting
        where
        wx_enterprise_id = #{wxEnterpriseId,jdbcType=VARCHAR}
        and open_flag = 1
        <if test="applicationIds != null and applicationIds.size() > 0">
            and application_id IN
            <foreach collection="applicationIds" item="id" index="index" open="(" close=")" separator=",">
                #{id,jdbcType=VARCHAR}
            </foreach>
        </if>
    </select>

    <select id="findMenuCodes" resultType="java.lang.String">
        select b.menu_code
        from tab_haoban_application_setting a
                 left join tab_haoban_application b on a.application_id = b.application_id
        where a.wx_enterprise_id = #{wxEnterpriseId,jdbcType=VARCHAR}
          AND a.status_flag = 1
          <if test="openFlag != null ">
              AND a.open_flag = #{openFlag}
          </if>
          and b.status_flag = 1
          and b.menu_code is not null;
    </select>


</mapper>