<?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.iamberry.wechat.service.mapper.OrderCustomizedMapper">
    <resultMap  id="BaseResultMap" type="OrderCustomized" >
        <result    column="customized_id"    property="customizedId" />
        <result    column="sales_order_id"    property="salesOrderId" />
        <result    column="customized_external_id"    property="customizedExternalId" />
        <result    column="customized_color_id"    property="customizedColorId" />
        <result    column="customized_color_value"    property="customizedColorValue" />
        <result    column="customized_color_name"    property="customizedColorName" />
        <result    column="customized_pattern_id"    property="customizedPatternId" />
        <result    column="customized_pattern_name"    property="customizedPatternName" />
        <result    column="customized_pattern_img"    property="customizedPatternImg" />
        <result    column="customized_position_id"    property="customizedPositionId" />
        <result    column="customized_position_type"    property="customizedPositionType" />
        <result    column="customized_position_pattern_x"    property="customizedPositionPatternX" />
        <result    column="customized_position_pattern_y"    property="customizedPositionPatternY" />
        <result    column="customized_position_text_x"    property="customizedPositionTextX" />
        <result    column="customized_position_text_y"    property="customizedPositionTextY" />
        <result    column="customized_position_avatar_x"    property="customizedPositionAvatarX" />
        <result    column="customized_position_avatar_y"    property="customizedPositionAvatarY" />
        <result    column="customized_text"    property="customizedText" />
        <result    column="customized_avatar_img"    property="customizedAvatarImg" />
        <result    column="customized_img"    property="customizedImg" />
        <result    column="customized_code_img"    property="customizedCodeImg" />
        <result    column="customized_type"    property="customizedType" />
        <result    column="customized_status"    property="customizedStatus" />
        <result    column="customized_create_time"    property="customizedCreateTime" />
    </resultMap>
    <sql    id="Base_List" >
        t.customized_id,
        t.sales_order_id,
        t.customized_external_id,
        t.customized_color_id,
        t.customized_color_value,
        t.customized_color_name,
        t.customized_pattern_id,
        t.customized_pattern_name,
        t.customized_pattern_img,
        t.customized_position_id,
        t.customized_position_type,
        t.customized_position_pattern_x,
        t.customized_position_pattern_y,
        t.customized_position_text_x,
        t.customized_position_text_y,
        t.customized_position_avatar_x,
        t.customized_position_avatar_y,
        t.customized_text,
        t.customized_avatar_img,
        t.customized_img,
        t.customized_code_img,
        t.customized_type,
        t.customized_status,
        t.customized_create_time
    </sql>
    <select id="getOrderCustomizedList" resultMap="BaseResultMap" parameterType="OrderCustomized" >
        select
        <include refid="Base_List" />
        from tb_iamberry_order_customized t
        <where>
            <if test="customizedId != null ">
                AND t.customized_id = #{customizedId}
            </if >
            <if test="salesOrderId != null and salesOrderId != ''">
                AND t.sales_order_id = #{salesOrderId}
            </if >
            <if test="customizedExternalId != null and customizedExternalId != ''">
                AND t.customized_external_id = #{customizedExternalId}
            </if >
            <if test="customizedColorId != null ">
                AND t.customized_color_id = #{customizedColorId}
            </if >
            <if test="customizedPatternId != null ">
                AND t.customized_pattern_id = #{customizedPatternId}
            </if >
            <if test="customizedPositionId != null ">
                AND t.customized_position_id = #{customizedPositionId}
            </if >
            <if test="customizedPositionType != null ">
                AND t.customized_position_type = #{customizedPositionType}
            </if >
            <if test="customizedType != null ">
                AND t.customized_type = #{customizedType}
            </if >
            <if test="customizedStatus != null ">
                AND t.customized_status = #{customizedStatus}
            </if >
        </where>
    </select>

    <resultMap  id="BaseResultOrderMap" type="OrderCustomized" >
        <result    column="customized_id"    property="customizedId" />
        <result    column="sales_order_id"    property="salesOrderId" />
        <result    column="customized_external_id"    property="customizedExternalId" />
        <result    column="customized_color_id"    property="customizedColorId" />
        <result    column="customized_color_value"    property="customizedColorValue" />
        <result    column="customized_color_name"    property="customizedColorName" />
        <result    column="customized_pattern_id"    property="customizedPatternId" />
        <result    column="customized_pattern_name"    property="customizedPatternName" />
        <result    column="customized_pattern_img"    property="customizedPatternImg" />
        <result    column="customized_position_id"    property="customizedPositionId" />
        <result    column="customized_position_type"    property="customizedPositionType" />
        <result    column="customized_position_pattern_x"    property="customizedPositionPatternX" />
        <result    column="customized_position_pattern_y"    property="customizedPositionPatternY" />
        <result    column="customized_position_text_x"    property="customizedPositionTextX" />
        <result    column="customized_position_text_y"    property="customizedPositionTextY" />
        <result    column="customized_position_avatar_x"    property="customizedPositionAvatarX" />
        <result    column="customized_position_avatar_y"    property="customizedPositionAvatarY" />
        <result    column="customized_text"    property="customizedText" />
        <result    column="customized_avatar_img"    property="customizedAvatarImg" />
        <result    column="customized_img"    property="customizedImg" />
        <result    column="customized_code_img"    property="customizedCodeImg" />
        <result    column="customized_type"    property="customizedType" />
        <result    column="customized_status"    property="customizedStatus" />
        <result    column="customized_create_time"    property="customizedCreateTime" />
        <association property="orderInfo" javaType="com.iamberry.wechat.core.entity.order.Order">
            <id    column="sales_orderid"    property="salesOrderid" />
            <result    column="sales_openid"    property="salesOpenid" />
            <result    column="sales_yet_amount"    property="salesYetAmount" />
            <result    column="sales_amount"    property="salesAmount" />
            <result    column="sales_integral_num"    property="salesIntegralNum" />
            <result    column="sales_rate_amount"    property="salesRateAmount" />
            <result    column="sales_create_date"    property="salesCreateDate" />
            <result    column="sales_reward_integral_num"    property="salesRewardIntegralNum" />
            <result    column="sales_post_num"    property="salesPostNum" />
            <result    column="sales_post_firm"    property="salesPostFirm" />
            <result    column="sales_status"    property="salesStatus" />
            <result    column="sales_send_date"    property="salesSendDate" />
            <result    column="sales_return_date"    property="salesReturnDate" />
            <result    column="sales_address_info"    property="salesAddressInfo" />
            <result    column="sales_address_postnum"    property="salesAddressPostnum" />
            <result    column="sales_address_tel"    property="salesAddressTel" />
            <result    column="sales_address_name"    property="salesAddressName" />
            <result    column="sales_return_des"    property="salesReturnDes" />
            <result    column="sales_admin_remark"    property="salesAdminRemark" />
            <result    column="sales_user_remark"    property="salesUserRemark" />
            <result    column="sales_transaction_id"    property="salesTransactionId" />
            <result    column="sales_transaction_date"    property="salesTransactionDate" />
            <result    column="sales_refund_no"    property="salesRefundNo" />
            <result    column="sales_transaction_refund_id"    property="salesTransactionRefundId" />
            <result    column="sales_color_type"    property="salesColorType" />
            <result    column="sales_proxy_reward"    property="salesProxyReward" />
            <result    column="Sales_coupon_receive_id"    property="couponId" />
            <result    column="sales_is_rfund"    property="salesIsRfund" />
            <result    column="sales_audit_remark"    property="salesAuditRemark" />
            <result    column="sales_is_customized"    property="salesIsCustomized" />
        </association>
    </resultMap>
    <select id="listOrderCustomizedPage" resultMap="BaseResultOrderMap" parameterType="OrderCustomized" >
        select
            t.customized_id,
            t.sales_order_id,
            t.customized_external_id,
            t.customized_color_id,
            t.customized_color_value,
            t.customized_color_name,
            t.customized_pattern_id,
            t.customized_pattern_name,
            t.customized_pattern_img,
            t.customized_position_id,
            t.customized_position_type,
            t.customized_position_pattern_x,
            t.customized_position_pattern_y,
            t.customized_position_text_x,
            t.customized_position_text_y,
            t.customized_position_avatar_x,
            t.customized_position_avatar_y,
            t.customized_text,
            t.customized_avatar_img,
            t.customized_img,
            t.customized_code_img,
            t.customized_type,
            t.customized_status,
            t.customized_create_time,
            so.sales_orderid,
            so.sales_openid,
            so.sales_yet_amount,
            so.sales_amount,
            so.sales_reward_num,
            so.sales_integral_num,
            so.sales_rate_amount,
            so.sales_create_date,
            so.sales_reward_integral_num,
            so.sales_post_num,
            so.sales_post_firm,
            so.sales_status,
            so.sales_send_date,
            so.sales_return_date,
            so.sales_address_info,
            so.sales_address_postnum,
            so.sales_address_tel,
            so.sales_address_name,
            so.sales_return_des,
            so.sales_admin_remark,
            so.sales_user_remark,
            so.sales_transaction_id,
            so.sales_transaction_date,
            so.sales_refund_no,
            so.sales_transaction_refund_id,
            so.sales_color_type,
            so.sales_proxy_reward,
            so.Sales_coupon_receive_id,
            so.sales_is_rfund,
            so.sales_audit_remark,
            so.sales_is_customized
        from tb_iamberry_order_customized t
        LEFT JOIN tb_iamberry_shop_sales_order so ON t.sales_order_id = so.SALES_ORDERID
        <where>
            <if test="customizedId != null ">
                AND t.customized_id = #{customizedId}
            </if >
            <if test="salesOrderId != null and salesOrderId != ''">
                AND t.sales_order_id = #{salesOrderId}
            </if >
            <if test="customizedExternalId != null and customizedExternalId != ''">
                AND t.customized_external_id = #{customizedExternalId}
            </if >
            <if test="customizedColorId != null ">
                AND t.customized_color_id = #{customizedColorId}
            </if >
            <if test="customizedPatternId != null ">
                AND t.customized_pattern_id = #{customizedPatternId}
            </if >
            <if test="customizedPositionId != null ">
                AND t.customized_position_id = #{customizedPositionId}
            </if >
            <if test="customizedPositionType != null ">
                AND t.customized_position_type = #{customizedPositionType}
            </if >
            <if test="customizedType != null ">
                AND t.customized_type = #{customizedType}
            </if >
            <if test="customizedStatus != null ">
                AND t.customized_status = #{customizedStatus}
            </if >
        </where>
    </select>

    <select id="getOrderCustomizedById" resultMap="BaseResultMap" parameterType="Integer" >
        select
        <include refid="Base_List" />
        from tb_iamberry_order_customized t
        where t.customized_id= #{customizedId}
    </select>
    <insert id="save" parameterType="OrderCustomized" >
        insert into
        tb_iamberry_order_customized
        (
        sales_order_id,
        customized_external_id,
        customized_color_id,
        customized_color_value,
        customized_color_name,
        customized_pattern_id,
        customized_pattern_name,
        customized_pattern_img,
        customized_position_id,
        customized_position_type,
        customized_position_pattern_x,
        customized_position_pattern_y,
        customized_position_text_x,
        customized_position_text_y,
        customized_position_avatar_x,
        customized_position_avatar_y,
        customized_text,
        customized_avatar_img,
        customized_img,
        customized_code_img,
        customized_type,
        customized_status
        )
        values
        (
        #{salesOrderId},
        #{customizedExternalId},
        #{customizedColorId},
        #{customizedColorValue},
        #{customizedColorName},
        #{customizedPatternId},
        #{customizedPatternName},
        #{customizedPatternImg},
        #{customizedPositionId},
        #{customizedPositionType},
        #{customizedPositionPatternX},
        #{customizedPositionPatternY},
        #{customizedPositionTextX},
        #{customizedPositionTextY},
        #{customizedPositionAvatarX},
        #{customizedPositionAvatarY},
        #{customizedText},
        #{customizedAvatarImg},
        #{customizedImg},
        #{customizedCodeImg},
        #{customizedType},
        #{customizedStatus}
        )
    </insert>
    <update id="update" parameterType="OrderCustomized" >
        update
        tb_iamberry_order_customized
        <set >
            <if test="salesOrderId != null and salesOrderId != ''">
                sales_order_id = #{salesOrderId},
            </if >
            <if test="customizedExternalId != null and customizedExternalId != ''">
                customized_external_id = #{customizedExternalId},
            </if >
            <if test="customizedColorId != null ">
                customized_color_id = #{customizedColorId},
            </if >
            <if test="customizedColorValue != null and customizedColorValue != ''">
                customized_color_value = #{customizedColorValue},
            </if >
            <if test="customizedColorName != null and customizedColorName != ''">
                customized_color_name = #{customizedColorName},
            </if >
            <if test="customizedPatternId != null ">
                customized_pattern_id = #{customizedPatternId},
            </if >
            <if test="customizedPatternName != null and customizedPatternName != ''">
                customized_pattern_name = #{customizedPatternName},
            </if >
            <if test="customizedPatternImg != null and customizedPatternImg != ''">
                customized_pattern_img = #{customizedPatternImg},
            </if >
            <if test="customizedPositionId != null ">
                customized_position_id = #{customizedPositionId},
            </if >
            <if test="customizedPositionType != null ">
                customized_position_type = #{customizedPositionType},
            </if >
            <if test="customizedPositionPatternX != null ">
                customized_position_pattern_x = #{customizedPositionPatternX},
            </if >
            <if test="customizedPositionPatternY != null ">
                customized_position_pattern_y = #{customizedPositionPatternY},
            </if >
            <if test="customizedPositionTextX != null ">
                customized_position_text_x = #{customizedPositionTextX},
            </if >
            <if test="customizedPositionTextY != null ">
                customized_position_text_y = #{customizedPositionTextY},
            </if >
            <if test="customizedPositionAvatarX != null ">
                customized_position_avatar_x = #{customizedPositionAvatarX},
            </if >
            <if test="customizedPositionAvatarY != null ">
                customized_position_avatar_y = #{customizedPositionAvatarY},
            </if >
            <if test="customizedText != null and customizedText != ''">
                customized_text = #{customizedText},
            </if >
            <if test="customizedAvatarImg != null and customizedAvatarImg != ''">
                customized_avatar_img = #{customizedAvatarImg},
            </if >
            <if test="customizedImg != null and customizedImg != ''">
                customized_img = #{customizedImg},
            </if >
            <if test="customizedType != null ">
                customized_type = #{customizedType},
            </if >
            <if test="customizedStatus != null ">
                customized_status = #{customizedStatus},
            </if >
        </set >
        where customized_id= #{customizedId}
    </update>
</mapper>