<?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.CamsAccountMapper">

<resultMap id="BaseResultMap" type="com.boco.nbd.wios.manage.entity.bo.CamsAccount">
  <id column="id" jdbcType="INTEGER" property="id" />
  <result column="account_id" jdbcType="INTEGER" property="accountId" />
  <result column="department_id" jdbcType="INTEGER" property="departmentId" />
  <result column="region_id" jdbcType="VARCHAR" property="regionId" />
  <result column="status" jdbcType="INTEGER" property="status" />
  <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
  <result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
  <result column="create_account" jdbcType="INTEGER" property="createAccount" />
  <result column="update_account" jdbcType="INTEGER" property="updateAccount" />
  <result column="alarm_id" jdbcType="VARCHAR" property="alarmId" />
</resultMap>


<sql id="Base_Column_List">
  id, account_id, department_id, region_id, status, create_time, update_time, create_account,
  update_account,alarm_id
</sql>


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


<insert id="insert" parameterType="com.boco.nbd.wios.manage.entity.bo.CamsAccount">
  insert into t_cams_account (id, account_id, department_id,
    region_id, status, create_time,
    update_time, create_account, update_account,alarm_id
    )
  values (#{id,jdbcType=INTEGER}, #{accountId,jdbcType=INTEGER}, #{departmentId,jdbcType=INTEGER},
    #{regionId,jdbcType=VARCHAR}, #{status,jdbcType=INTEGER}, #{createTime,jdbcType=TIMESTAMP},
    #{updateTime,jdbcType=TIMESTAMP}, #{createAccount,jdbcType=INTEGER}, #{updateAccount,jdbcType=INTEGER},
    #{alarmId,jdbcType=INTEGER}
    )
</insert>


<insert id="insertDynamic" parameterType="com.boco.nbd.wios.manage.entity.bo.CamsAccount">
  insert into t_cams_account
  <trim prefix="(" suffix=")" suffixOverrides=",">
    <if test="id != null">
      id,
    </if>
    <if test="accountId != null">
      account_id,
    </if>
    <if test="departmentId != null">
      department_id,
    </if>
    <if test="regionId != null">
      region_id,
    </if>
    <if test="status != null">
      status,
    </if>
    <if test="createTime != null">
      create_time,
    </if>
    <if test="updateTime != null">
      update_time,
    </if>
    <if test="createAccount != null">
      create_account,
    </if>
    <if test="updateAccount != null">
      update_account,
    </if>
    <if test="alarmId != null">
      alarm_id,
    </if>
  </trim>
  <trim prefix="values (" suffix=")" suffixOverrides=",">
    <if test="id != null">
      #{id,jdbcType=INTEGER},
    </if>
    <if test="accountId != null">
      #{accountId,jdbcType=INTEGER},
    </if>
    <if test="departmentId != null">
      #{departmentId,jdbcType=INTEGER},
    </if>
    <if test="regionId != null">
      #{regionId,jdbcType=VARCHAR},
    </if>
    <if test="status != null">
      #{status,jdbcType=INTEGER},
    </if>
    <if test="createTime != null">
      #{createTime,jdbcType=TIMESTAMP},
    </if>
    <if test="updateTime != null">
      #{updateTime,jdbcType=TIMESTAMP},
    </if>
    <if test="createAccount != null">
      #{createAccount,jdbcType=INTEGER},
    </if>
    <if test="updateAccount != null">
      #{updateAccount,jdbcType=INTEGER},
    </if>
    <if test="alarmId != null">
      #{alarmId,jdbcType=VARCHAR},
    </if>
  </trim>
</insert>


<update id="updateDynamic" parameterType="com.boco.nbd.wios.manage.entity.bo.CamsAccount">
  update t_cams_account
  <set>
    <if test="accountId != null">
      account_id = #{accountId,jdbcType=INTEGER},
    </if>
    <if test="departmentId != null">
      department_id = #{departmentId,jdbcType=INTEGER},
    </if>
    <if test="regionId != null">
      region_id = #{regionId,jdbcType=VARCHAR},
    </if>
    <if test="status != null">
      status = #{status,jdbcType=INTEGER},
    </if>
    <if test="createTime != null">
      create_time = #{createTime,jdbcType=TIMESTAMP},
    </if>
    <if test="updateTime != null">
      update_time = #{updateTime,jdbcType=TIMESTAMP},
    </if>
    <if test="createAccount != null">
      create_account = #{createAccount,jdbcType=INTEGER},
    </if>
    <if test="updateAccount != null">
      update_account = #{updateAccount,jdbcType=INTEGER},
    </if>
    <if test="alarmId != null">
      alarm_id = #{alarmId,jdbcType=VARCHAR},
    </if>
  </set>
  where id = #{id,jdbcType=INTEGER}
</update>


<update id="update" parameterType="com.boco.nbd.wios.manage.entity.bo.CamsAccount">
  update t_cams_account
  set account_id = #{accountId,jdbcType=INTEGER},
    department_id = #{departmentId,jdbcType=INTEGER},
    region_id = #{regionId,jdbcType=VARCHAR},
    status = #{status,jdbcType=INTEGER},
    create_time = #{createTime,jdbcType=TIMESTAMP},
    update_time = #{updateTime,jdbcType=TIMESTAMP},
    create_account = #{createAccount,jdbcType=INTEGER},
    update_account = #{updateAccount,jdbcType=INTEGER},
    alarm_id = #{alarmId,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_cams_account
  where id = #{id,jdbcType=INTEGER}
</select>

  <select id="selectByAccountIdAndDeptId" parameterType="java.lang.Integer" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List" />
    from  t_cams_account
    where account_id = #{accountId,jdbcType=INTEGER}
    <if test="departmentId != null">
        and department_id = #{departmentId,jdbcType=INTEGER}
    </if>
  </select>


<select id="selectByExample" parameterType="com.boco.nbd.wios.manage.entity.bo.CamsAccount"
        resultType="com.boco.nbd.wios.manage.entity.bo.CamsAccountVo">
   select t.*,role.name as roleName,
   <!-- r.name as regionName, -->
   d.name as deptName,a.name as userName,a.email as userEmail,
   a.account as userAccount
   from t_cams_account t
   left join wb_account a on t.account_id=a.id
   left join t_department d on t.department_id=d.id
   <!-- left join t_region r on t.region_id = r.id -->
   left join wb_account_role ar on ar.account_id=a.id
   left join wb_role role on role.id=ar.role_id
   <where>
   		t.status != 3
   	    <if test="userName != null and userName != ''">
   	        and a.name = #{userName}
	    </if>
	    <if test="account != null and account != ''">
   	        and a.account = #{account}
	    </if>
	    <if test="roleId != null">
   	        and ar.role_id = #{roleId}
	    </if>
	    <if test="regionId != null">
   	        and find_in_set(#{regionId},t.region_id)
	    </if>
         <if test="alarmId != null">
           and find_in_set(#{alarmId},t.alarm_id)
         </if>
   </where>
   order by t.create_time desc
</select>

</mapper>