<?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.SecretSettingMapper">
  <resultMap id="BaseResultMap" type="com.gic.haoban.manage.service.entity.TabSecretSetting">
    <id column="secret_id" jdbcType="VARCHAR" property="secretId" />
    <result column="wx_enterprise_id" jdbcType="VARCHAR" property="wxEnterpriseId" />
    <result column="secret_name" jdbcType="VARCHAR" property="secretName" />
    <result column="secret_val" jdbcType="VARCHAR" property="secretVal" />
    <result column="enterprise_id" jdbcType="VARCHAR" property="enterpriseId" />
    <result column="secret_type" jdbcType="INTEGER" property="secretType" />
    <result column="check_flag" jdbcType="INTEGER" property="checkFlag" />
    <result column="status_flag" jdbcType="INTEGER" property="statusFlag" />
    <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
    <result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
  </resultMap>
  <sql id="Base_Column_List">
    secret_id, wx_enterprise_id, secret_name, secret_val, enterprise_id, secret_type, 
    check_flag, status_flag, create_time, update_time
  </sql>
  <select id="selectByPrimaryKey" parameterType="java.lang.String" resultMap="BaseResultMap">
    select 
    <include refid="Base_Column_List" />
    from tab_haoban_secret_setting
    where secret_id = #{secretId,jdbcType=VARCHAR}
  </select>
  
  <insert id="insert" parameterType="com.gic.haoban.manage.service.entity.TabSecretSetting">
    insert into tab_haoban_secret_setting (secret_id, wx_enterprise_id, secret_name, 
      secret_val, enterprise_id, secret_type, 
      check_flag, status_flag, create_time, 
      update_time)
    values (#{secretId,jdbcType=VARCHAR}, #{wxEnterpriseId,jdbcType=VARCHAR}, #{secretName,jdbcType=VARCHAR}, 
      #{secretVal,jdbcType=VARCHAR}, #{enterpriseId,jdbcType=VARCHAR}, #{secretType,jdbcType=INTEGER}, 
      #{checkFlag,jdbcType=INTEGER}, #{statusFlag,jdbcType=INTEGER}, #{createTime,jdbcType=TIMESTAMP}, 
      #{updateTime,jdbcType=TIMESTAMP})
  </insert>
  
  <update id="updateByPrimaryKeySelective" parameterType="com.gic.haoban.manage.service.entity.TabSecretSetting">
    update tab_haoban_secret_setting
    <set>
      <if test="wxEnterpriseId != null">
        wx_enterprise_id = #{wxEnterpriseId,jdbcType=VARCHAR},
      </if>
      <if test="secretName != null">
        secret_name = #{secretName,jdbcType=VARCHAR},
      </if>
      <if test="secretVal != null">
        secret_val = #{secretVal,jdbcType=VARCHAR},
      </if>
      <if test="enterpriseId != null">
        enterprise_id = #{enterpriseId,jdbcType=VARCHAR},
      </if>
      <if test="secretType != null">
        secret_type = #{secretType,jdbcType=INTEGER},
      </if>
      <if test="checkFlag != null">
        check_flag = #{checkFlag,jdbcType=INTEGER},
      </if>
      <if test="statusFlag != null">
        status_flag = #{statusFlag,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 secret_id = #{secretId,jdbcType=VARCHAR}
  </update>

  <select id="listSecretSetting"  resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List" />
    from tab_haoban_secret_setting
    where wx_enterprise_id = #{wxEnterpriseId,jdbcType=VARCHAR} and status_flag=1
  </select>

  <select id="getSecretSetting"  resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List" />
    from tab_haoban_secret_setting
    where wx_enterprise_id = #{wxEnterpriseId,jdbcType=VARCHAR}
    and status_flag=1
    and secret_type=#{secretType}
    <if test="enterpriseId!=null">
      and  enterprise_id = #{enterpriseId,jdbcType=VARCHAR}
    </if>
    ORDER BY create_time desc LIMIT 1
  </select>
  
  <select id="exsitGicEidMemberApp" resultType="com.gic.haoban.manage.api.dto.SecretSettingDTO">
  	select enterprise_id enterpriseId , secret_id secretId  from tab_haoban_secret_setting where wx_enterprise_id = #{wxEnterpriseId,jdbcType=VARCHAR} 
  	and status_flag = 1 and secret_type = 4 and enterprise_id is not null
  </select>
  
</mapper>