<?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.zzgl.ZzglLogDgjlMapper">

	<resultMap id="BaseResultMap"
		type="cn.timer.api.bean.zzgl.ZzglLogDgjl">
		<id column="id" property="id" />
		<result column="org_code" property="orgCode" />
		<result column="emp_num" property="empNum" />
		<result column="obmgw_id" property="obmgwId" />
		<result column="nbmgw_id" property="nbmgwId" />
		<result column="update_id" property="updateId" />
		<result column="create_time" property="createTime" />
	</resultMap>

	<sql id="Base_Column_List">
		a.id,
		a.org_code,
		a.emp_num,
		a.obmgw_id,
		a.nbmgw_id,
		a.update_id,
		a.create_time
	</sql>

	<sql id="Base_Column_List_Alias">
		id ZzglLogDgjl_id,
		org_code ZzglLogDgjl_org_code,
		emp_num
		ZzglLogDgjl_emp_num,
		obmgw_id ZzglLogDgjl_obmgw_id,
		nbmgw_id
		ZzglLogDgjl_nbmgw_id,
		update_id ZzglLogDgjl_update_id,
		create_time
		ZzglLogDgjl_create_time
	</sql>

	<select id="selectListdgjl"
		resultType="cn.timer.api.dto.zzgl.ZzglLogDgjlDto"
		parameterType="cn.timer.api.dto.zzgl.ZzglLogDgjlQueryDto">
		SELECT
		<include refid="Base_Column_List" />
		,b.name username
		FROM
		zzgl_log_dgjl a,yggl_main_emp b
		<where>
			a.emp_num = b.emp_num
			<if test="orgCode != null and orgCode != ''">
				and a.org_code = #{orgCode}
			</if>
			<if test="query != null and query != ''">
				and b.name like CONCAT(#{query},'%')
			</if>
			<if test="startTime != null and startTime != ''">
				and a.create_time <![CDATA[ >= ]]>
				#{startTime}
			</if>
			<if test="endTime != null and endTime != ''">
				and a.create_time <![CDATA[ <= ]]>
				#{endTime}
			</if>
		</where>
	</select>

	<select id="selectListdgjls"
		resultType="cn.timer.api.dto.zzgl.LogDgjlsDto"
		parameterType="cn.timer.api.dto.zzgl.LogDgjlsQueryDto">
		SELECT
				c.name `name`,b.name `obmgw`,e.name `nbmgw`,a.emp_num `empNum`,d.name `updateMen`,
				a.create_time `createTime`
			FROM
				zzgl_log_dgjl a
			LEFT JOIN yggl_main_emp c ON a.emp_num = c.emp_num
			LEFT JOIN zzgl_bmgw_m b ON a.obmgw_id = b.id
			LEFT JOIN zzgl_bmgw_m e ON a.nbmgw_id = e.id
			LEFT JOIN yggl_main_emp d ON a.update_id = d.emp_num 
		<where>
			a.org_code = #{param.orgCode} AND c.org_code = #{param.orgCode} AND b.org_code = #{param.orgCode}
			 AND e.org_code = #{param.orgCode} AND d.org_code = #{param.orgCode}
			<if test="null != param.query and param.query != ''">
				and (c.name like CONCAT('%',#{param.query},'%') or
				a.emp_num like CONCAT('%',#{param.query},'%') or 
				c.phone like CONCAT('%',#{param.query},'%'))
			</if>
			<if test="param.deptIdList != null">
				and a.nbmgw_id in
				<foreach item="item" index="index"
					collection="param.deptIdList.toArray()" open="(" separator="," close=")">
					#{item}
				</foreach>
			</if>
		</where>
		GROUP BY `createTime` order by a.create_time DESC
	</select>




	<insert id="insertbydeldept">
		insert into zzgl_log_dgjl
		(create_time,emp_num,nbmgw_id,obmgw_id,org_code,update_id,comment)
		select NOW(),emp_num,null,bmgw_id,org_code,#{uid},'删除岗位调岗' from
		yggl_main_emp where bmgw_id in
		<foreach item="item" index="index" collection="ids" open="("
			separator="," close=")">#{item}</foreach>
	</insert>
	<insert id="insertbyaddemp">
		insert into zzgl_log_dgjl
		(create_time,emp_num,nbmgw_id,obmgw_id,org_code,update_id,comment)
		select NOW(),emp_num,#{gwid},bmgw_id,org_code,#{uid},#{comm} from
		yggl_main_emp where org_code=#{orgc} and emp_num in
		<foreach item="item" index="index" collection="ids" open="("
			separator="," close=")">#{item}</foreach>
	</insert>
	<!-- <insert id="insert" useGeneratedKeys="true" keyColumn="id" parameterType="cn.timer.api.bean.zzgl.ZzglLogDgjl"> 
		INSERT INTO zzgl_log_dgjl <trim prefix="(" suffix=")" suffixOverrides=","> 
		<if test ='null != orgCode'> org_code, </if> <if test ='null != empNum'> 
		emp_num, </if> <if test ='null != obmgwId'> obmgw_id, </if> <if test ='null 
		!= nbmgwId'> nbmgw_id, </if> <if test ='null != updateId'> update_id, </if> 
		<if test ='null != createTime'> create_time </if> </trim> <trim prefix="values 
		(" suffix=")" suffixOverrides=","> <if test ='null != orgCode'> #{orgCode}, 
		</if> <if test ='null != empNum'> #{empNum}, </if> <if test ='null != obmgwId'> 
		#{obmgwId}, </if> <if test ='null != nbmgwId'> #{nbmgwId}, </if> <if test 
		='null != updateId'> #{updateId}, </if> <if test ='null != createTime'> #{createTime} 
		</if> </trim> </insert> <delete id="delete" > DELETE FROM zzgl_log_dgjl WHERE 
		id = #{id} </delete> <update id="update" parameterType="cn.timer.api.bean.zzgl.ZzglLogDgjl"> 
		UPDATE zzgl_log_dgjl <set> <if test ='null != orgCode'>org_code = #{orgCode},</if> 
		<if test ='null != empNum'>emp_num = #{empNum},</if> <if test ='null != obmgwId'>obmgw_id 
		= #{obmgwId},</if> <if test ='null != nbmgwId'>nbmgw_id = #{nbmgwId},</if> 
		<if test ='null != updateId'>update_id = #{updateId},</if> <if test ='null 
		!= createTime'>create_time = #{createTime}</if> </set> WHERE id = #{id} </update> 
		<select id="load" resultMap="BaseResultMap"> SELECT <include refid="Base_Column_List" 
		/> FROM zzgl_log_dgjl WHERE id = #{id} </select> <select id="pageList" resultMap="BaseResultMap"> 
		SELECT <include refid="Base_Column_List" /> FROM zzgl_log_dgjl LIMIT #{offset}, 
		#{pageSize} </select> <select id="pageListCount" resultType="java.lang.Integer"> 
		SELECT count(1) FROM zzgl_log_dgjl </select> -->

</mapper>