<?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.BaseProductMapper">
	
	<resultMap type="BaseProduct" id="BaseProductResult">
		<result property="productId"	column="product_id"	/>
		<result property="productCode"	column="product_code"	/>
		<result property="productDescZh"	column="product_desc_zh"	/>
		<result property="productModel"	column="product_model"	/>
		<result property="productDescEn"	column="product_desc_en"	/>
		<result property="ruleCode"	column="rule_code"	/>
		<result property="oldProductCode"	column="old_product_code"	/>
		<result property="partsProductCode"	column="parts_product_code"	/>
		<result property="skuBarcode"	column="sku_barcode"	/>
		<result property="length"	column="length"	/>
		<result property="width"	column="width"	/>
		<result property="height"	column="height"	/>
		<result property="grossWeight"	column="gross_weight"	/>
		<result property="netWeight"	column="net_weight"	/>
		<result property="tareWeight"	column="tare_weight"	/>
		<result property="volume"	column="volume"	/>
		<result property="unitPrice"	column="unit_price"	/>
		<result property="productGroup"	column="product_group"	/>
		<result property="productGroupName"	column="product_group_name"	/>
		<result property="userDefined1"	column="user_defined1"	/>
		<result property="userDefined2"	column="user_defined2"	/>
		<result property="userDefined3"	column="user_defined3"	/>
		<result property="userDefined4"	column="user_defined4"	/>
		<result property="userDefined5"	column="user_defined5"	/>
		<result property="userDefined6"	column="user_defined6"	/>
		<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"	/>
		<result property="activeFlag"	column="active_flag"	/>
		<result property="syncFlag"	column="sync_flag"	/>
		<result property="primaryUom"	column="primary_uom"	/>
		<result property="delFlag"	column="del_flag"	/>
		<result property="bstme"	column="bstme"	/>
		<result property="basicOrder"	column="basic_order"	/>
		<result property="convOrder"	column="conv_order"	/>
		<result property="ausme"	column="ausme"	/>
		<result property="basicIssue"	column="basic_issue"	/>
		<result property="convIssue"	column="conv_issue"	/>
		<result property="appendFlag"	column="append_flag"	/>
		<result property="appendPercent"	column="append_percent"	/>
	</resultMap>

	<sql id="selectBaseProductVo">
		select product_id, product_code, product_desc_zh, product_model,product_desc_en, rule_code, old_product_code, parts_product_code, sku_barcode, length, width, height, gross_weight, net_weight, tare_weight, volume, unit_price, product_group, product_group_name, user_defined1, user_defined2, user_defined3, user_defined4, user_defined5, user_defined6, create_by, create_time, update_by, update_time, factory_code, active_flag, sync_flag, primary_uom, del_flag, bstme, basic_order, conv_order, ausme, basic_issue, conv_issue, append_flag, append_percent from base_product
	</sql>

	<select id="selectBaseProductList" parameterType="BaseProduct" resultMap="BaseProductResult">
		<include refid="selectBaseProductVo"/>
		<where>  
			<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="productModel != null  and productModel != ''"> and product_model = #{productModel}</if>
			<if test="productDescEn != null  and productDescEn != ''"> and product_desc_en = #{productDescEn}</if>
			<if test="ruleCode != null  and ruleCode != ''"> and rule_code = #{ruleCode}</if>
			<if test="oldProductCode != null  and oldProductCode != ''"> and old_product_code = #{oldProductCode}</if>
			<if test="partsProductCode != null  and partsProductCode != ''"> and parts_product_code = #{partsProductCode}</if>
			<if test="skuBarcode != null  and skuBarcode != ''"> and sku_barcode = #{skuBarcode}</if>
			<if test="length != null "> and length = #{length}</if>
			<if test="width != null "> and width = #{width}</if>
			<if test="height != null "> and height = #{height}</if>
			<if test="grossWeight != null "> and gross_weight = #{grossWeight}</if>
			<if test="netWeight != null "> and net_weight = #{netWeight}</if>
			<if test="tareWeight != null "> and tare_weight = #{tareWeight}</if>
			<if test="volume != null "> and volume = #{volume}</if>
			<if test="unitPrice != null "> and unit_price = #{unitPrice}</if>
			<if test="productGroup != null  and productGroup != ''"> and product_group = #{productGroup}</if>
			<if test="productGroupName != null  and productGroupName != ''"> and product_group_name like concat('%', #{productGroupName}, '%')</if>
			<if test="userDefined1 != null  and userDefined1 != ''"> and user_defined1 = #{userDefined1}</if>
			<if test="userDefined2 != null  and userDefined2 != ''"> and user_defined2 = #{userDefined2}</if>
			<if test="userDefined3 != null  and userDefined3 != ''"> and user_defined3 = #{userDefined3}</if>
			<if test="userDefined4 != null  and userDefined4 != ''"> and user_defined4 = #{userDefined4}</if>
			<if test="userDefined5 != null  and userDefined5 != ''"> and user_defined5 = #{userDefined5}</if>
			<if test="userDefined6 != null  and userDefined6 != ''"> and user_defined6 = #{userDefined6}</if>
			<if test="factoryCode != null  and factoryCode != ''"> and factory_code = #{factoryCode}</if>
			<if test="activeFlag != null  and activeFlag != ''"> and active_flag = #{activeFlag}</if>
			<if test="syncFlag != null  and syncFlag != ''"> and sync_flag = #{syncFlag}</if>
			<if test="primaryUom != null  and primaryUom != ''"> and primary_uom = #{primaryUom}</if>
			<if test="bstme != null  and bstme != ''"> and bstme = #{bstme}</if>
			<if test="basicOrder != null "> and basic_order = #{basicOrder}</if>
			<if test="convOrder != null "> and conv_order = #{convOrder}</if>
			<if test="ausme != null  and ausme != ''"> and ausme = #{ausme}</if>
			<if test="basicIssue != null "> and basic_issue = #{basicIssue}</if>
			<if test="convIssue != null "> and conv_issue = #{convIssue}</if>
			<if test="appendFlag != null  and appendFlag != ''"> and append_flag = #{appendFlag}</if>
			<if test="appendPercent != null  and appendPercent != ''"> and append_percent = #{appendPercent}</if>
		</where>
	</select>
	
	<select id="selectBaseProductByProductId" parameterType="String" resultMap="BaseProductResult">
		<include refid="selectBaseProductVo"/>
		where product_id = #{productId}
	</select>
		
	<insert id="insertBaseProduct" parameterType="BaseProduct">
		insert into base_product
		<trim prefix="(" suffix=")" suffixOverrides=",">
			<if test="productId != null">product_id,</if>
			<if test="productCode != null and productCode != ''">product_code,</if>
			<if test="productDescZh != null">product_desc_zh,</if>
			<if test="productModel != null">product_model,</if>
			<if test="productDescEn != null">product_desc_en,</if>
			<if test="ruleCode != null">rule_code,</if>
			<if test="oldProductCode != null">old_product_code,</if>
			<if test="partsProductCode != null">parts_product_code,</if>
			<if test="skuBarcode != null">sku_barcode,</if>
			<if test="length != null">length,</if>
			<if test="width != null">width,</if>
			<if test="height != null">height,</if>
			<if test="grossWeight != null">gross_weight,</if>
			<if test="netWeight != null">net_weight,</if>
			<if test="tareWeight != null">tare_weight,</if>
			<if test="volume != null">volume,</if>
			<if test="unitPrice != null">unit_price,</if>
			<if test="productGroup != null">product_group,</if>
			<if test="productGroupName != null">product_group_name,</if>
			<if test="userDefined1 != null">user_defined1,</if>
			<if test="userDefined2 != null">user_defined2,</if>
			<if test="userDefined3 != null">user_defined3,</if>
			<if test="userDefined4 != null">user_defined4,</if>
			<if test="userDefined5 != null">user_defined5,</if>
			<if test="userDefined6 != null">user_defined6,</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>
			<if test="activeFlag != null">active_flag,</if>
			<if test="syncFlag != null">sync_flag,</if>
			<if test="primaryUom != null">primary_uom,</if>
			<if test="delFlag != null">del_flag,</if>
			<if test="bstme != null">bstme,</if>
			<if test="basicOrder != null">basic_order,</if>
			<if test="convOrder != null">conv_order,</if>
			<if test="ausme != null">ausme,</if>
			<if test="basicIssue != null">basic_issue,</if>
			<if test="convIssue != null">conv_issue,</if>
			<if test="appendFlag != null">append_flag,</if>
			<if test="appendPercent != null">append_percent,</if>
		 </trim>
		<trim prefix="values (" suffix=")" suffixOverrides=",">
			<if test="productId != null">#{productId},</if>
			<if test="productCode != null and productCode != ''">#{productCode},</if>
			<if test="productDescZh != null">#{productDescZh},</if>
			<if test="productModel != null">#{productModel},</if>
			<if test="productDescEn != null">#{productDescEn},</if>
			<if test="ruleCode != null">#{ruleCode},</if>
			<if test="oldProductCode != null">#{oldProductCode},</if>
			<if test="partsProductCode != null">#{partsProductCode},</if>
			<if test="skuBarcode != null">#{skuBarcode},</if>
			<if test="length != null">#{length},</if>
			<if test="width != null">#{width},</if>
			<if test="height != null">#{height},</if>
			<if test="grossWeight != null">#{grossWeight},</if>
			<if test="netWeight != null">#{netWeight},</if>
			<if test="tareWeight != null">#{tareWeight},</if>
			<if test="volume != null">#{volume},</if>
			<if test="unitPrice != null">#{unitPrice},</if>
			<if test="productGroup != null">#{productGroup},</if>
			<if test="productGroupName != null">#{productGroupName},</if>
			<if test="userDefined1 != null">#{userDefined1},</if>
			<if test="userDefined2 != null">#{userDefined2},</if>
			<if test="userDefined3 != null">#{userDefined3},</if>
			<if test="userDefined4 != null">#{userDefined4},</if>
			<if test="userDefined5 != null">#{userDefined5},</if>
			<if test="userDefined6 != null">#{userDefined6},</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>
			<if test="activeFlag != null">#{activeFlag},</if>
			<if test="syncFlag != null">#{syncFlag},</if>
			<if test="primaryUom != null">#{primaryUom},</if>
			<if test="delFlag != null">#{delFlag},</if>
			<if test="bstme != null">#{bstme},</if>
			<if test="basicOrder != null">#{basicOrder},</if>
			<if test="convOrder != null">#{convOrder},</if>
			<if test="ausme != null">#{ausme},</if>
			<if test="basicIssue != null">#{basicIssue},</if>
			<if test="convIssue != null">#{convIssue},</if>
			<if test="appendFlag != null">#{appendFlag},</if>
			<if test="appendPercent != null">#{appendPercent},</if>
		 </trim>
	</insert>

	<update id="updateBaseProduct" parameterType="BaseProduct">
		update base_product
		<trim prefix="SET" suffixOverrides=",">
			<if test="productCode != null and productCode != ''">product_code = #{productCode},</if>
			<if test="productDescZh != null">product_desc_zh = #{productDescZh},</if>
			<if test="productModel != null">product_model = #{productModel},</if>
			<if test="productDescEn != null">product_desc_en = #{productDescEn},</if>
			<if test="ruleCode != null">rule_code = #{ruleCode},</if>
			<if test="oldProductCode != null">old_product_code = #{oldProductCode},</if>
			<if test="partsProductCode != null">parts_product_code = #{partsProductCode},</if>
			<if test="skuBarcode != null">sku_barcode = #{skuBarcode},</if>
			<if test="length != null">length = #{length},</if>
			<if test="width != null">width = #{width},</if>
			<if test="height != null">height = #{height},</if>
			<if test="grossWeight != null">gross_weight = #{grossWeight},</if>
			<if test="netWeight != null">net_weight = #{netWeight},</if>
			<if test="tareWeight != null">tare_weight = #{tareWeight},</if>
			<if test="volume != null">volume = #{volume},</if>
			<if test="unitPrice != null">unit_price = #{unitPrice},</if>
			<if test="productGroup != null">product_group = #{productGroup},</if>
			<if test="productGroupName != null">product_group_name = #{productGroupName},</if>
			<if test="userDefined1 != null">user_defined1 = #{userDefined1},</if>
			<if test="userDefined2 != null">user_defined2 = #{userDefined2},</if>
			<if test="userDefined3 != null">user_defined3 = #{userDefined3},</if>
			<if test="userDefined4 != null">user_defined4 = #{userDefined4},</if>
			<if test="userDefined5 != null">user_defined5 = #{userDefined5},</if>
			<if test="userDefined6 != null">user_defined6 = #{userDefined6},</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>
			<if test="activeFlag != null">active_flag = #{activeFlag},</if>
			<if test="syncFlag != null">sync_flag = #{syncFlag},</if>
			<if test="primaryUom != null">primary_uom = #{primaryUom},</if>
			<if test="delFlag != null">del_flag = #{delFlag},</if>
			<if test="bstme != null">bstme = #{bstme},</if>
			<if test="basicOrder != null">basic_order = #{basicOrder},</if>
			<if test="convOrder != null">conv_order = #{convOrder},</if>
			<if test="ausme != null">ausme = #{ausme},</if>
			<if test="basicIssue != null">basic_issue = #{basicIssue},</if>
			<if test="convIssue != null">conv_issue = #{convIssue},</if>
			<if test="appendFlag != null">append_flag = #{appendFlag},</if>
			<if test="appendPercent != null">append_percent = #{appendPercent},</if>
		</trim>
		where product_id = #{productId}
	</update>

	<delete id="deleteBaseProductByProductId" parameterType="String">
		delete from base_product where product_id = #{productId}
	</delete>

	<delete id="deleteBaseProductByProductIds" parameterType="String">
		delete from base_product where product_id in 
		<foreach item="productId" collection="array" open="(" separator="," close=")">
			#{productId}
		</foreach>
	</delete>
</mapper>