<?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="cn.timer.api.dao.kqmk.KqglAssoYhsbMapper">

    <resultMap id="BaseResultMap" type="cn.timer.api.bean.kqmk.KqglAssoYhsb" >
                <id column="id" property="id" />
                <result column="user_id" property="userId" />
                <result column="kqjid" property="kqjid" />
                <result column="type" property="type" />
                <result column="is_gly" property="isGly" />
    </resultMap>
    
    <resultMap id="MachinememberMap" type="cn.timer.api.dto.kqmk.MachinememberDto" >
    <result column="dept" property="dept" jdbcType="VARCHAR" />
    <result column="post" property="post" jdbcType="VARCHAR" />
    <result column="name" property="name" jdbcType="VARCHAR" />
    <result column="id" property="id" jdbcType="INTEGER" />
    <result column="user_id" property="userId" jdbcType="INTEGER" />
    <result column="kqjid" property="kqjid" jdbcType="INTEGER" />
    <result column="type" property="type" jdbcType="INTEGER" />
    <result column="isgly" property="isgly" jdbcType="INTEGER" />
  </resultMap>

    <sql id="Base_Column_List">
                id,
                user_id,
                kqjid,
                type,
                is_gly
    </sql>
    
    <sql id="Base_Column_List_Alias">
                id KqglAssoYhsb_id,
                user_id KqglAssoYhsb_user_id,
                kqjid KqglAssoYhsb_kqjid,
                type KqglAssoYhsb_type,
                is_gly KqglAssoYhsb_is_gly
    </sql>
    
    <select id="selectAircraftMembers" resultMap="MachinememberMap">
			select bmgw.dept,
			 	 bmgw.post,
				emp.`name`,
				yhsb.id,
				yhsb.kqjid,
				yhsb.type,
				yhsb.user_id,
				yhsb.is_gly as isgly
		from kqgl_asso_yhsb yhsb
	LEFT JOIN yggl_main_emp as emp on emp.emp_num = yhsb.user_id and emp.org_code = #{orgcode}
	LEFT JOIN (select m.name as post,um.name as dept,m.id as mid
					 from zzgl_bmgw_m m 
					 left join zzgl_bmgw_m um on um.id = m.up_id  
				) as bmgw on bmgw.mid = emp.bmgw_id
		where yhsb.kqjid = #{kqjid}
	</select>	

	<!-- 

    <insert id="insert" useGeneratedKeys="true" keyColumn="id" parameterType="cn.timer.api.bean.kqmk.KqglAssoYhsb">
        INSERT INTO kqgl_asso_yhsb
        <trim prefix="(" suffix=")" suffixOverrides=",">
                        <if test ='null != userId'>
                        user_id,
                        </if>
                        <if test ='null != kqjid'>
                        kqjid,
                        </if>
                        <if test ='null != type'>
                        type,
                        </if>
                        <if test ='null != isGly'>
                        is_gly
                        </if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
                        <if test ='null != userId'>
                        #{userId},
                        </if>
                        <if test ='null != kqjid'>
                        #{kqjid},
                        </if>
                        <if test ='null != type'>
                        #{type},
                        </if>
                        <if test ='null != isGly'>
                        #{isGly}
                        </if>
        </trim>
    </insert>

    <delete id="delete" >
        DELETE FROM kqgl_asso_yhsb
        WHERE id = #{id}
    </delete>

    <update id="update" parameterType="cn.timer.api.bean.kqmk.KqglAssoYhsb">
        UPDATE kqgl_asso_yhsb
        <set>
                    <if test ='null != userId'>user_id = #{userId},</if>
                    <if test ='null != kqjid'>kqjid = #{kqjid},</if>
                    <if test ='null != type'>type = #{type},</if>
                    <if test ='null != isGly'>is_gly = #{isGly}</if>
        </set>
        WHERE id = #{id}
    </update>


    <select id="load" resultMap="BaseResultMap">
        SELECT <include refid="Base_Column_List" />
        FROM kqgl_asso_yhsb
        WHERE id = #{id}
    </select>

    <select id="pageList" resultMap="BaseResultMap">
        SELECT <include refid="Base_Column_List" />
        FROM kqgl_asso_yhsb
        LIMIT #{offset}, #{pageSize}
    </select>

    <select id="pageListCount" resultType="java.lang.Integer">
        SELECT count(1)
        FROM kqgl_asso_yhsb
    </select>

	 -->

</mapper>