<?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.xintong.visualinspection.dao.master.TeamDao" >
    <resultMap id="BaseResultMap" type="com.xintong.visualinspection.bean.Team" >
        <id column="id" property="id" jdbcType="INTEGER" />
        <result column="name" property="name" jdbcType="VARCHAR" />
        <result column="dept_id" property="dept_id" jdbcType="INTEGER" />
        <result column="user_ids" property="user_ids" jdbcType="VARCHAR" />
    </resultMap>

    <select id="getAll" resultMap="BaseResultMap"  >
        SELECT *
        FROM sys_team
    </select>

    <select id="getOne" parameterType="java.lang.Long" resultMap="BaseResultMap" >
        SELECT *
        FROM sys_team
        WHERE id = #{id}
    </select>
    
    <select id="getByDeptId" parameterType="java.lang.Long" resultMap="BaseResultMap" >
        SELECT *
        FROM sys_team
        WHERE dept_id = #{dept_id}
    </select>
    
    
    <select id="getList" parameterType="java.lang.Long" resultMap="BaseResultMap" >
        SELECT *
        FROM sys_team
        WHERE 1=1 
        <if test="dept_id!=null">
        	AND dept_id = #{dept_id}
        </if>
        <if test="type!=null">
           AND type = #{type}
        </if>
    </select>
    
    <select id="getTeamByName" parameterType="com.xintong.visualinspection.bean.Team" resultMap="BaseResultMap" >
        SELECT *
        FROM sys_team
        WHERE 1=1 
        <if test="dept_id != null">AND dept_id = #{dept_id}</if>
        <if test="name != null and name != ''">AND name like CONCAT('%',#{name},'%') </if>
        <if test="type != null">AND type = #{type}</if>
    </select>

    <insert id="insert" parameterType="com.xintong.visualinspection.bean.Team" >
        INSERT INTO
        sys_team
        (name,dept_id,user_ids,type,monitor,sub_monitor)
        VALUES
        (#{name}, #{dept_id},#{user_ids},#{type},#{monitor},#{sub_monitor})
    </insert>

    <update id="update" parameterType="com.xintong.visualinspection.bean.Team" >
        UPDATE
        sys_team
        SET
        <if test="name != null">name = #{name}</if>
        <if test="dept_id != null">,dept_id = #{dept_id}</if>
        <if test="user_ids != null">,user_ids = #{user_ids}</if>
        <if test="monitor != null">,monitor = #{monitor}</if>
        <if test="sub_monitor != null">,sub_monitor = #{sub_monitor}</if>
        WHERE
        id = #{id}
    </update>

    <delete id="delete" parameterType="java.lang.Long" >
        DELETE FROM
        sys_team
        WHERE
        id =#{id}
    </delete>
</mapper>