<?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.boco.nbd.wios.manage.mapper.def.SupplierStaffMapper">
  
<resultMap id="BaseResultMap" type="com.boco.nbd.wios.manage.entity.bo.SupplierStaff">
  <id column="id" jdbcType="INTEGER" property="id" />
  <result column="name" jdbcType="VARCHAR" property="name" />
  <result column="supplier_id" jdbcType="INTEGER" property="supplierId" />
  <result column="phone" jdbcType="VARCHAR" property="phone" />
  <result column="cert_level" jdbcType="INTEGER" property="certLevel" />
  <result column="cert_expire" jdbcType="DATE" property="certExpire" />
  <result column="is_insure" jdbcType="INTEGER" property="isInsure" />
  <result column="status" jdbcType="INTEGER" property="status" />
  <result column="data_auth" jdbcType="INTEGER" property="dataAuth" />
  <result column="cert_files" jdbcType="VARCHAR" property="certFiles" />
  <result column="account_id" jdbcType="INTEGER" property="accountId" />
  <result column="create_account" jdbcType="VARCHAR" property="createAccount" />
  <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
  <result column="modify_account" jdbcType="VARCHAR" property="modifyAccount" />
  <result column="modify_time" jdbcType="TIMESTAMP" property="modifyTime" />
  <result column="insure_files" jdbcType="VARCHAR" property="insureFiles" />
  <result column="idcard_files" jdbcType="VARCHAR" property="idcardFiles" />
</resultMap>

  
<sql id="Base_Column_List">
  id, name, supplier_id, phone, cert_level, cert_expire, is_insure, status, data_auth, 
  cert_files, account_id, create_account, create_time, modify_account, modify_time,
  insure_files,idcard_files
</sql>

  
<delete id="delete" parameterType="java.lang.Integer">
  delete from t_supplier_staff
  where id = #{id,jdbcType=INTEGER}
</delete>

  
<insert id="insert" parameterType="com.boco.nbd.wios.manage.entity.bo.SupplierStaff">
  insert into t_supplier_staff (id, name, supplier_id, 
    phone, cert_level, cert_expire, 
    is_insure, status, data_auth, 
    cert_files, account_id, create_account, 
    create_time, modify_account, modify_time,insure_files,idcard_files
    )
  values (#{id,jdbcType=INTEGER}, #{name,jdbcType=VARCHAR}, #{supplierId,jdbcType=INTEGER}, 
    #{phone,jdbcType=VARCHAR}, #{certLevel,jdbcType=INTEGER}, #{certExpire,jdbcType=DATE}, 
    #{isInsure,jdbcType=INTEGER}, #{status,jdbcType=INTEGER}, #{dataAuth,jdbcType=INTEGER}, 
    #{certFiles,jdbcType=VARCHAR}, #{accountId,jdbcType=INTEGER}, #{createAccount,jdbcType=VARCHAR}, 
    #{createTime,jdbcType=TIMESTAMP}, #{modifyAccount,jdbcType=VARCHAR}, #{modifyTime,jdbcType=TIMESTAMP},
          #{insureFiles,jdbcType=VARCHAR},#{idcardFiles,jdbcType=VARCHAR}
    )
</insert>

  
<insert id="insertDynamic" parameterType="com.boco.nbd.wios.manage.entity.bo.SupplierStaff">
  insert into t_supplier_staff
  <trim prefix="(" suffix=")" suffixOverrides=",">
    <if test="id != null">
      id,
    </if>
    <if test="name != null">
      name,
    </if>
    <if test="supplierId != null">
      supplier_id,
    </if>
    <if test="phone != null">
      phone,
    </if>
    <if test="certLevel != null">
      cert_level,
    </if>
    <if test="certExpire != null">
      cert_expire,
    </if>
    <if test="isInsure != null">
      is_insure,
    </if>
    <if test="status != null">
      status,
    </if>
    <if test="dataAuth != null">
      data_auth,
    </if>
    <if test="certFiles != null">
      cert_files,
    </if>
    <if test="accountId != null">
      account_id,
    </if>
    <if test="createAccount != null">
      create_account,
    </if>
    <if test="createTime != null">
      create_time,
    </if>
    <if test="modifyAccount != null">
      modify_account,
    </if>
    <if test="modifyTime != null">
      modify_time,
    </if>
    <if test="insureFiles != null">
      insure_files,
    </if>
    <if test="idcardFiles != null">
      idcard_files,
    </if>
  </trim>
  <trim prefix="values (" suffix=")" suffixOverrides=",">
    <if test="id != null">
      #{id,jdbcType=INTEGER},
    </if>
    <if test="name != null">
      #{name,jdbcType=VARCHAR},
    </if>
    <if test="supplierId != null">
      #{supplierId,jdbcType=INTEGER},
    </if>
    <if test="phone != null">
      #{phone,jdbcType=VARCHAR},
    </if>
    <if test="certLevel != null">
      #{certLevel,jdbcType=INTEGER},
    </if>
    <if test="certExpire != null">
      #{certExpire,jdbcType=DATE},
    </if>
    <if test="isInsure != null">
      #{isInsure,jdbcType=INTEGER},
    </if>
    <if test="status != null">
      #{status,jdbcType=INTEGER},
    </if>
    <if test="dataAuth != null">
      #{dataAuth,jdbcType=INTEGER},
    </if>
    <if test="certFiles != null">
      #{certFiles,jdbcType=VARCHAR},
    </if>
    <if test="accountId != null">
      #{accountId,jdbcType=INTEGER},
    </if>
    <if test="createAccount != null">
      #{createAccount,jdbcType=VARCHAR},
    </if>
    <if test="createTime != null">
      #{createTime,jdbcType=TIMESTAMP},
    </if>
    <if test="modifyAccount != null">
      #{modifyAccount,jdbcType=VARCHAR},
    </if>
    <if test="modifyTime != null">
      #{modifyTime,jdbcType=TIMESTAMP},
    </if>
    <if test="insureFiles != null">
      #{insureFiles,jdbcType=VARCHAR},
    </if>
    <if test="idcardFiles != null">
      #{idcardFiles,jdbcType=VARCHAR},
    </if>
  </trim>
</insert>

  
<update id="updateDynamic" parameterType="com.boco.nbd.wios.manage.entity.bo.SupplierStaff">
  update t_supplier_staff
  <set>
    <if test="name != null">
      name = #{name,jdbcType=VARCHAR},
    </if>
    <if test="supplierId != null">
      supplier_id = #{supplierId,jdbcType=INTEGER},
    </if>
    <if test="phone != null">
      phone = #{phone,jdbcType=VARCHAR},
    </if>
    <if test="certLevel != null">
      cert_level = #{certLevel,jdbcType=INTEGER},
    </if>
    <if test="certExpire != null">
      cert_expire = #{certExpire,jdbcType=DATE},
    </if>
    <if test="isInsure != null">
      is_insure = #{isInsure,jdbcType=INTEGER},
    </if>
    <if test="status != null">
      status = #{status,jdbcType=INTEGER},
    </if>
    <if test="dataAuth != null">
      data_auth = #{dataAuth,jdbcType=INTEGER},
    </if>
    <if test="certFiles != null">
      cert_files = #{certFiles,jdbcType=VARCHAR},
    </if>
    <if test="accountId != null">
      account_id = #{accountId,jdbcType=INTEGER},
    </if>
    <if test="createAccount != null">
      create_account = #{createAccount,jdbcType=VARCHAR},
    </if>
    <if test="createTime != null">
      create_time = #{createTime,jdbcType=TIMESTAMP},
    </if>
    <if test="modifyAccount != null">
      modify_account = #{modifyAccount,jdbcType=VARCHAR},
    </if>
    <if test="modifyTime != null">
      modify_time = #{modifyTime,jdbcType=TIMESTAMP},
    </if>
    <if test="insureFiles != null">
      insure_files = #{insureFiles,jdbcType=VARCHAR},
    </if>
    <if test="idcardFiles != null">
      idcard_files = #{idcardFiles,jdbcType=VARCHAR},
    </if>
  </set>
  where id = #{id,jdbcType=INTEGER}
</update>

  
<update id="update" parameterType="com.boco.nbd.wios.manage.entity.bo.SupplierStaff">
  update t_supplier_staff
  set name = #{name,jdbcType=VARCHAR},
    supplier_id = #{supplierId,jdbcType=INTEGER},
    phone = #{phone,jdbcType=VARCHAR},
    cert_level = #{certLevel,jdbcType=INTEGER},
    cert_expire = #{certExpire,jdbcType=DATE},
    is_insure = #{isInsure,jdbcType=INTEGER},
    status = #{status,jdbcType=INTEGER},
    data_auth = #{dataAuth,jdbcType=INTEGER},
    cert_files = #{certFiles,jdbcType=VARCHAR},
    account_id = #{accountId,jdbcType=INTEGER},
    create_account = #{createAccount,jdbcType=VARCHAR},
    create_time = #{createTime,jdbcType=TIMESTAMP},
    modify_account = #{modifyAccount,jdbcType=VARCHAR},
    modify_time = #{modifyTime,jdbcType=TIMESTAMP},
    insure_files = #{insureFiles,jdbcType=VARCHAR},
    idcard_files = #{idcardFiles,jdbcType=VARCHAR}
  where id = #{id,jdbcType=INTEGER}
</update>

  
<select id="selectById" parameterType="java.lang.Integer" resultMap="BaseResultMap">
  select
	<include refid="Base_Column_List" />
  from  t_supplier_staff
  where id = #{id,jdbcType=INTEGER}
</select>

<select id="selectByAccountId" parameterType="java.lang.Integer" resultMap="BaseResultMap">
  select
  <include refid="Base_Column_List" />
  from  t_supplier_staff
  where account_id = #{accountId,jdbcType=INTEGER}
</select>

<select id="selectByExample" parameterType="com.boco.nbd.wios.manage.entity.bo.SupplierStaffBo"
        resultType="com.boco.nbd.wios.manage.entity.bo.SupplierStaffVo">
   select t.*,wr.name as roleName,wr.id as roleId,wa.account as loginAccount,s.name as supplierName from t_supplier_staff t
   left join wb_account_role war on t.account_id=war.account_id
   left join wb_role wr on war.role_id=wr.id
   left join wb_account wa on t.account_id=wa.id
   left join t_supplier s on t.supplier_id=s.id
   <where>
   		<if test="id != null">
	        and t.id = #{id}
	    </if>
	    <if test="name != null and name != ''">
	        <bind name="nameLike" value="'%' + name + '%'"/>
	        and t.name like #{nameLike}
	    </if>
	    <if test="account != null and account != ''">
	        and wa.account = #{account}
	    </if>
	    <if test="supplierId != null and supplierId != ''">
	        and t.supplier_id = #{supplierId}
	    </if>
	    <if test="showCertExpired != null and showCertExpired == 0">
	        and t.cert_expire &gt;= now()
	    </if>
   </where>
   order by t.create_time desc
</select>
  <select id="selectAll" resultType="com.boco.nbd.wios.manage.entity.bo.SupplierStaffVo">
    select * from t_supplier_staff
  </select>

</mapper>