<?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.goafanti.common.dao.TechWebsiteMapper" >
  <resultMap id="BaseResultMap" type="com.goafanti.common.model.TechWebsite" >
    <id column="id" property="id" jdbcType="VARCHAR" />
    <result column="uid" property="uid" jdbcType="VARCHAR" />
    <result column="department" property="department" jdbcType="VARCHAR" />
    <result column="website" property="website" jdbcType="VARCHAR" />
    <result column="account_number" property="accountNumber" jdbcType="VARCHAR" />
    <result column="password" property="password" jdbcType="VARCHAR" />
    <result column="create_time" property="createTime" jdbcType="TIMESTAMP" />
    <result column="deleted_sign" property="deletedSign" jdbcType="INTEGER" />
  </resultMap>
  <sql id="Base_Column_List" >
    id, uid, department, website, account_number, password, create_time, deleted_sign
  </sql>
  <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.String" >
    select 
    <include refid="Base_Column_List" />
    from tech_website
    where id = #{id,jdbcType=VARCHAR}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.String" >
    delete from tech_website
    where id = #{id,jdbcType=VARCHAR}
  </delete>
  <insert id="insert" parameterType="com.goafanti.common.model.TechWebsite" >
    insert into tech_website (id, uid, department, 
      website, account_number, password, 
      create_time, deleted_sign)
    values (#{id,jdbcType=VARCHAR}, #{uid,jdbcType=VARCHAR}, #{department,jdbcType=VARCHAR}, 
      #{website,jdbcType=VARCHAR}, #{accountNumber,jdbcType=VARCHAR}, #{password,jdbcType=VARCHAR}, 
      #{createTime,jdbcType=TIMESTAMP}, #{deletedSign,jdbcType=INTEGER})
  </insert>
  <insert id="insertSelective" parameterType="com.goafanti.common.model.TechWebsite" >
    insert into tech_website
    <trim prefix="(" suffix=")" suffixOverrides="," >
      <if test="id != null" >
        id,
      </if>
      <if test="uid != null" >
        uid,
      </if>
      <if test="department != null" >
        department,
      </if>
      <if test="website != null" >
        website,
      </if>
      <if test="accountNumber != null" >
        account_number,
      </if>
      <if test="password != null" >
        password,
      </if>
      <if test="createTime != null" >
        create_time,
      </if>
      <if test="deletedSign != null" >
        deleted_sign,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides="," >
      <if test="id != null" >
        #{id,jdbcType=VARCHAR},
      </if>
      <if test="uid != null" >
        #{uid,jdbcType=VARCHAR},
      </if>
      <if test="department != null" >
        #{department,jdbcType=VARCHAR},
      </if>
      <if test="website != null" >
        #{website,jdbcType=VARCHAR},
      </if>
      <if test="accountNumber != null" >
        #{accountNumber,jdbcType=VARCHAR},
      </if>
      <if test="password != null" >
        #{password,jdbcType=VARCHAR},
      </if>
      <if test="createTime != null" >
        #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="deletedSign != null" >
        #{deletedSign,jdbcType=INTEGER},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKeySelective" parameterType="com.goafanti.common.model.TechWebsite" >
    update tech_website
    <set >
      <if test="uid != null" >
        uid = #{uid,jdbcType=VARCHAR},
      </if>
      <if test="department != null" >
        department = #{department,jdbcType=VARCHAR},
      </if>
      <if test="website != null" >
        website = #{website,jdbcType=VARCHAR},
      </if>
      <if test="accountNumber != null" >
        account_number = #{accountNumber,jdbcType=VARCHAR},
      </if>
      <if test="password != null" >
        password = #{password,jdbcType=VARCHAR},
      </if>
      <if test="createTime != null" >
        create_time = #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="deletedSign != null" >
        deleted_sign = #{deletedSign,jdbcType=INTEGER},
      </if>
    </set>
    where id = #{id,jdbcType=VARCHAR}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.goafanti.common.model.TechWebsite" >
    update tech_website
    set uid = #{uid,jdbcType=VARCHAR},
      department = #{department,jdbcType=VARCHAR},
      website = #{website,jdbcType=VARCHAR},
      account_number = #{accountNumber,jdbcType=VARCHAR},
      password = #{password,jdbcType=VARCHAR},
      create_time = #{createTime,jdbcType=TIMESTAMP},
      deleted_sign = #{deletedSign,jdbcType=INTEGER}
    where id = #{id,jdbcType=VARCHAR}
  </update>
  
  <select id="selectTechWebsiteByUid" resultMap="BaseResultMap" parameterType="java.lang.String" >
    select 
    <include refid="Base_Column_List" />
    from tech_website
    where uid = #{uid,jdbcType=VARCHAR} and deleted_sign = 0
  </select>
  
   <select id="findTechWebsiteListByPage" resultType="com.goafanti.techproject.bo.TechWebsiteListBo" parameterType="java.lang.String" >
   select 
   		w.id, 
   		w.uid, 
   		i.unit_name as unitName, 
   		i.licence_province as province, 
		w.department, 
		w.website, 
		w.account_number as accountNumber,
		w.password
		from tech_website w 
	LEFT JOIN organization_identity i on w.uid = i.uid 
	where w.deleted_sign = 0 
    <if test="province != null">
    	and i.licence_province = #{province,jdbcType=INTEGER}
    </if>
    <if test="unitName != null" >
    	and i.unit_name like CONCAT('%', #{unitName,jdbcType=VARCHAR}, '%')  
    </if>
    order by w.create_time desc
   <if test="page_sql!=null">
		${page_sql}
	</if>
  </select>
  
  <select id="findTechWebsiteCount" resultType="java.lang.Integer" parameterType="String">
  	select count(1)
		from tech_website w 
	LEFT JOIN organization_identity i on w.uid = i.uid 
	where w.deleted_sign = 0 
    <if test="province != null">
    	and i.licence_province = #{province,jdbcType=INTEGER}
    </if>
   <if test="unitName != null" >
    	and i.unit_name like CONCAT('%', #{unitName,jdbcType=VARCHAR}, '%')  
    </if>
  </select>
  
   <update id="batchDeleteByPrimaryKey" parameterType="java.util.List">
  	update tech_website set deleted_sign = 1
  	where  id in 
	<foreach item="item" index="index" collection="list" open="(" separator="," close=")">
		#{item}
	</foreach>
  </update>
  
  <select id="selectTechWebsiteDetail" resultType="com.goafanti.techproject.bo.TechWebsiteDetailBo" parameterType="java.lang.String" >
   SELECT t.id, t.account_number as accountNumber, t.department,t.password, t.uid, t.website, i.unit_name as unitName
		from tech_website t LEFT JOIN organization_identity i on t.uid = i.uid 
    where t.id = #{id,jdbcType=VARCHAR}
  </select>
</mapper>