<?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.BaseEquipmentProductMapper">
	
	<resultMap type="BaseEquipmentProduct" id="BaseEquipmentProductResult">
		<result property="equipmentId"	column="equipment_id"	/>
		<result property="equipmentCode"	column="equipment_code"	/>
		<result property="equipmentName"	column="equipment_name"	/>
		<result property="productCode"	column="product_code"	/>
		<result property="productDescZh"	column="product_desc_zh"	/>
		<result property="equipmentTypeId"	column="equipment_type_id"	/>
		<result property="equipmentTypeCode"	column="equipment_type_code"	/>
		<result property="equipmentTypeName"	column="equipment_type_name"	/>
		<result property="workshopId"	column="workshop_id"	/>
		<result property="workshopCode"	column="workshop_code"	/>
		<result property="workshopName"	column="workshop_name"	/>
		<result property="status"	column="status"	/>
		<result property="remark"	column="remark"	/>
		<result property="attr1"	column="attr1"	/>
		<result property="attr2"	column="attr2"	/>
		<result property="attr3"	column="attr3"	/>
		<result property="attr4"	column="attr4"	/>
		<result property="createBy"	column="create_by"	/>
		<result property="createTime"	column="create_time"	/>
		<result property="updateBy"	column="update_by"	/>
		<result property="updateTime"	column="update_time"	/>
	</resultMap>

	<sql id="selectBaseEquipmentProductVo">
		select equipment_id, equipment_code, equipment_name, product_code, product_desc_zh, equipment_type_id, equipment_type_code, equipment_type_name, workshop_id, workshop_code, workshop_name, status, remark, attr1, attr2, attr3, attr4, create_by, create_time, update_by, update_time from base_equipment_product
	</sql>

	<select id="selectBaseEquipmentProductList" parameterType="BaseEquipmentProduct" resultMap="BaseEquipmentProductResult">
		<include refid="selectBaseEquipmentProductVo"/>
		<where>  
			<if test="equipmentCode != null  and equipmentCode != ''"> and equipment_code = #{equipmentCode}</if>
			<if test="equipmentName != null  and equipmentName != ''"> and equipment_name like concat('%', #{equipmentName}, '%')</if>
			<if test="productCode != null  and productCode != ''"> and product_code = #{productCode}</if>
			<if test="productDescZh != null  and productDescZh != ''"> and product_desc_zh = #{productDescZh}</if>
			<if test="equipmentTypeId != null "> and equipment_type_id = #{equipmentTypeId}</if>
			<if test="equipmentTypeCode != null  and equipmentTypeCode != ''"> and equipment_type_code = #{equipmentTypeCode}</if>
			<if test="equipmentTypeName != null  and equipmentTypeName != ''"> and equipment_type_name like concat('%', #{equipmentTypeName}, '%')</if>
			<if test="workshopId != null "> and workshop_id = #{workshopId}</if>
			<if test="workshopCode != null  and workshopCode != ''"> and workshop_code = #{workshopCode}</if>
			<if test="workshopName != null  and workshopName != ''"> and workshop_name like concat('%', #{workshopName}, '%')</if>
			<if test="status != null  and status != ''"> and status = #{status}</if>
			<if test="attr1 != null  and attr1 != ''"> and attr1 = #{attr1}</if>
			<if test="attr2 != null  and attr2 != ''"> and attr2 = #{attr2}</if>
			<if test="attr3 != null "> and attr3 = #{attr3}</if>
			<if test="attr4 != null "> and attr4 = #{attr4}</if>
		</where>
	</select>
	
	<select id="selectBaseEquipmentProductByEquipmentId" parameterType="Long" resultMap="BaseEquipmentProductResult">
		<include refid="selectBaseEquipmentProductVo"/>
		where equipment_id = #{equipmentId}
	</select>
		
	<insert id="insertBaseEquipmentProduct" parameterType="BaseEquipmentProduct" useGeneratedKeys="true" keyProperty="equipmentId">
		insert into base_equipment_product
		<trim prefix="(" suffix=")" suffixOverrides=",">
			<if test="equipmentCode != null and equipmentCode != ''">equipment_code,</if>
			<if test="equipmentName != null">equipment_name,</if>
			<if test="productCode != null and productCode != ''">product_code,</if>
			<if test="productDescZh != null and productDescZh != ''">product_desc_zh,</if>
			<if test="equipmentTypeId != null">equipment_type_id,</if>
			<if test="equipmentTypeCode != null">equipment_type_code,</if>
			<if test="equipmentTypeName != null">equipment_type_name,</if>
			<if test="workshopId != null">workshop_id,</if>
			<if test="workshopCode != null">workshop_code,</if>
			<if test="workshopName != null">workshop_name,</if>
			<if test="status != null">status,</if>
			<if test="remark != null">remark,</if>
			<if test="attr1 != null">attr1,</if>
			<if test="attr2 != null">attr2,</if>
			<if test="attr3 != null">attr3,</if>
			<if test="attr4 != null">attr4,</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>
		 </trim>
		<trim prefix="values (" suffix=")" suffixOverrides=",">
			<if test="equipmentCode != null and equipmentCode != ''">#{equipmentCode},</if>
			<if test="equipmentName != null">#{equipmentName},</if>
			<if test="productCode != null and productCode != ''">#{productCode},</if>
			<if test="productDescZh != null and productDescZh != ''">#{productDescZh},</if>
			<if test="equipmentTypeId != null">#{equipmentTypeId},</if>
			<if test="equipmentTypeCode != null">#{equipmentTypeCode},</if>
			<if test="equipmentTypeName != null">#{equipmentTypeName},</if>
			<if test="workshopId != null">#{workshopId},</if>
			<if test="workshopCode != null">#{workshopCode},</if>
			<if test="workshopName != null">#{workshopName},</if>
			<if test="status != null">#{status},</if>
			<if test="remark != null">#{remark},</if>
			<if test="attr1 != null">#{attr1},</if>
			<if test="attr2 != null">#{attr2},</if>
			<if test="attr3 != null">#{attr3},</if>
			<if test="attr4 != null">#{attr4},</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>
		 </trim>
	</insert>

	<update id="updateBaseEquipmentProduct" parameterType="BaseEquipmentProduct">
		update base_equipment_product
		<trim prefix="SET" suffixOverrides=",">
			<if test="equipmentCode != null and equipmentCode != ''">equipment_code = #{equipmentCode},</if>
			<if test="equipmentName != null">equipment_name = #{equipmentName},</if>
			<if test="productCode != null and productCode != ''">product_code = #{productCode},</if>
			<if test="productDescZh != null and productDescZh != ''">product_desc_zh = #{productDescZh},</if>
			<if test="equipmentTypeId != null">equipment_type_id = #{equipmentTypeId},</if>
			<if test="equipmentTypeCode != null">equipment_type_code = #{equipmentTypeCode},</if>
			<if test="equipmentTypeName != null">equipment_type_name = #{equipmentTypeName},</if>
			<if test="workshopId != null">workshop_id = #{workshopId},</if>
			<if test="workshopCode != null">workshop_code = #{workshopCode},</if>
			<if test="workshopName != null">workshop_name = #{workshopName},</if>
			<if test="status != null">status = #{status},</if>
			<if test="remark != null">remark = #{remark},</if>
			<if test="attr1 != null">attr1 = #{attr1},</if>
			<if test="attr2 != null">attr2 = #{attr2},</if>
			<if test="attr3 != null">attr3 = #{attr3},</if>
			<if test="attr4 != null">attr4 = #{attr4},</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>
		</trim>
		where equipment_id = #{equipmentId}
	</update>

	<delete id="deleteBaseEquipmentProductByEquipmentId" parameterType="Long">
		delete from base_equipment_product where equipment_id = #{equipmentId}
	</delete>

	<delete id="deleteBaseEquipmentProductByEquipmentIds" parameterType="String">
		delete from base_equipment_product where equipment_id in 
		<foreach item="equipmentId" collection="array" open="(" separator="," close=")">
			#{equipmentId}
		</foreach>
	</delete>
</mapper>