<?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.op.wms.mapper.SysFactoryMapper">
	
	<resultMap type="SysFactory" id="SysFactoryResult">
		<result property="factoryId"	column="factory_id"	/>
		<result property="parentId"	column="parent_id"	/>
		<result property="ancestors"	column="ancestors"	/>
		<result property="factoryName"	column="factory_name"	/>
		<result property="orderNum"	column="order_num"	/>
		<result property="leader"	column="leader"	/>
		<result property="phone"	column="phone"	/>
		<result property="email"	column="email"	/>
		<result property="status"	column="status"	/>
		<result property="delFlag"	column="del_flag"	/>
		<result property="createBy"	column="create_by"	/>
		<result property="createTime"	column="create_time"	/>
		<result property="updateBy"	column="update_by"	/>
		<result property="updateTime"	column="update_time"	/>
		<result property="factoryCode"	column="factory_code"	/>
	</resultMap>

	<sql id="selectSysFactoryVo">
		select factory_id, parent_id, ancestors, factory_name, order_num, leader, phone, email, status, del_flag, create_by, create_time, update_by, update_time, factory_code from sys_factory
	</sql>

	<select id="selectSysFactoryList" parameterType="SysFactory" resultMap="SysFactoryResult">
		<include refid="selectSysFactoryVo"/>
		<where>  
			<if test="parentId != null "> and parent_id = #{parentId}</if>
			<if test="ancestors != null  and ancestors != ''"> and ancestors = #{ancestors}</if>
			<if test="factoryName != null  and factoryName != ''"> and factory_name like concat('%', #{factoryName}, '%')</if>
			<if test="orderNum != null "> and order_num = #{orderNum}</if>
			<if test="leader != null  and leader != ''"> and leader = #{leader}</if>
			<if test="phone != null  and phone != ''"> and phone = #{phone}</if>
			<if test="email != null  and email != ''"> and email = #{email}</if>
			<if test="status != null  and status != ''"> and status = #{status}</if>
		</where>
	</select>
	
	<select id="selectSysFactoryByFactoryId" parameterType="Long" resultMap="SysFactoryResult">
		<include refid="selectSysFactoryVo"/>
		where factory_id = #{factoryId}
	</select>
		
	<insert id="insertSysFactory" parameterType="SysFactory" useGeneratedKeys="true" keyProperty="factoryId">
		insert into sys_factory
		<trim prefix="(" suffix=")" suffixOverrides=",">
			<if test="parentId != null">parent_id,</if>
			<if test="ancestors != null">ancestors,</if>
			<if test="factoryName != null">factory_name,</if>
			<if test="orderNum != null">order_num,</if>
			<if test="leader != null">leader,</if>
			<if test="phone != null">phone,</if>
			<if test="email != null">email,</if>
			<if test="status != null">status,</if>
			<if test="delFlag != null">del_flag,</if>
			<if test="createBy != null">create_by,</if>
			<if test="createTime != null">create_time,</if>
			<if test="updateBy != null">update_by,</if>
			<if test="updateTime != null">update_time,</if>
			<if test="factoryCode != null">factory_code,</if>
		 </trim>
		<trim prefix="values (" suffix=")" suffixOverrides=",">
			<if test="parentId != null">#{parentId},</if>
			<if test="ancestors != null">#{ancestors},</if>
			<if test="factoryName != null">#{factoryName},</if>
			<if test="orderNum != null">#{orderNum},</if>
			<if test="leader != null">#{leader},</if>
			<if test="phone != null">#{phone},</if>
			<if test="email != null">#{email},</if>
			<if test="status != null">#{status},</if>
			<if test="delFlag != null">#{delFlag},</if>
			<if test="createBy != null">#{createBy},</if>
			<if test="createTime != null">#{createTime},</if>
			<if test="updateBy != null">#{updateBy},</if>
			<if test="updateTime != null">#{updateTime},</if>
			<if test="factoryCode != null">#{factoryCode},</if>
		 </trim>
	</insert>

	<update id="updateSysFactory" parameterType="SysFactory">
		update sys_factory
		<trim prefix="SET" suffixOverrides=",">
			<if test="parentId != null">parent_id = #{parentId},</if>
			<if test="ancestors != null">ancestors = #{ancestors},</if>
			<if test="factoryName != null">factory_name = #{factoryName},</if>
			<if test="orderNum != null">order_num = #{orderNum},</if>
			<if test="leader != null">leader = #{leader},</if>
			<if test="phone != null">phone = #{phone},</if>
			<if test="email != null">email = #{email},</if>
			<if test="status != null">status = #{status},</if>
			<if test="delFlag != null">del_flag = #{delFlag},</if>
			<if test="createBy != null">create_by = #{createBy},</if>
			<if test="createTime != null">create_time = #{createTime},</if>
			<if test="updateBy != null">update_by = #{updateBy},</if>
			<if test="updateTime != null">update_time = #{updateTime},</if>
			<if test="factoryCode != null">factory_code = #{factoryCode},</if>
		</trim>
		where factory_id = #{factoryId}
	</update>

	<delete id="deleteSysFactoryByFactoryId" parameterType="Long">
		delete from sys_factory where factory_id = #{factoryId}
	</delete>

	<delete id="deleteSysFactoryByFactoryIds" parameterType="String">
		delete from sys_factory where factory_id in
		<foreach item="factoryId" collection="array" open="(" separator="," close=")">
			#{factoryId}
		</foreach>
	</delete>
</mapper>