package com.hfkj.dao;

import com.hfkj.entity.BsTradeOrder;
import com.hfkj.entity.BsTradeOrderExample.Criteria;
import com.hfkj.entity.BsTradeOrderExample.Criterion;
import com.hfkj.entity.BsTradeOrderExample;
import java.util.List;
import java.util.Map;
import org.apache.ibatis.jdbc.SQL;

public class BsTradeOrderSqlProvider {

    public String countByExample(BsTradeOrderExample example) {
        SQL sql = new SQL();
        sql.SELECT("count(*)").FROM("bs_trade_order");
        applyWhere(sql, example, false);
        return sql.toString();
    }

    public String deleteByExample(BsTradeOrderExample example) {
        SQL sql = new SQL();
        sql.DELETE_FROM("bs_trade_order");
        applyWhere(sql, example, false);
        return sql.toString();
    }

    public String insertSelective(BsTradeOrder record) {
        SQL sql = new SQL();
        sql.INSERT_INTO("bs_trade_order");
        
        if (record.getCompanyId() != null) {
            sql.VALUES("company_id", "#{companyId,jdbcType=BIGINT}");
        }
        
        if (record.getAgentId() != null) {
            sql.VALUES("agent_id", "#{agentId,jdbcType=BIGINT}");
        }
        
        if (record.getSalesmanId() != null) {
            sql.VALUES("salesman_id", "#{salesmanId,jdbcType=BIGINT}");
        }
        
        if (record.getSalesmanName() != null) {
            sql.VALUES("salesman_name", "#{salesmanName,jdbcType=VARCHAR}");
        }
        
        if (record.getMerId() != null) {
            sql.VALUES("mer_id", "#{merId,jdbcType=BIGINT}");
        }
        
        if (record.getMerName() != null) {
            sql.VALUES("mer_name", "#{merName,jdbcType=VARCHAR}");
        }
        
        if (record.getMerAbbreviate() != null) {
            sql.VALUES("mer_abbreviate", "#{merAbbreviate,jdbcType=VARCHAR}");
        }
        
        if (record.getMerNo() != null) {
            sql.VALUES("mer_no", "#{merNo,jdbcType=VARCHAR}");
        }
        
        if (record.getStoreId() != null) {
            sql.VALUES("store_id", "#{storeId,jdbcType=BIGINT}");
        }
        
        if (record.getStoreName() != null) {
            sql.VALUES("store_name", "#{storeName,jdbcType=VARCHAR}");
        }
        
        if (record.getDeviceId() != null) {
            sql.VALUES("device_id", "#{deviceId,jdbcType=BIGINT}");
        }
        
        if (record.getDeviceSn() != null) {
            sql.VALUES("device_sn", "#{deviceSn,jdbcType=VARCHAR}");
        }
        
        if (record.getQrCodeId() != null) {
            sql.VALUES("qr_code_id", "#{qrCodeId,jdbcType=BIGINT}");
        }
        
        if (record.getQrCodeSn() != null) {
            sql.VALUES("qr_code_sn", "#{qrCodeSn,jdbcType=VARCHAR}");
        }
        
        if (record.getPlatformType() != null) {
            sql.VALUES("platform_type", "#{platformType,jdbcType=INTEGER}");
        }
        
        if (record.getPlatformMerNo() != null) {
            sql.VALUES("platform_mer_no", "#{platformMerNo,jdbcType=VARCHAR}");
        }
        
        if (record.getPlatformTradeNo() != null) {
            sql.VALUES("platform_trade_no", "#{platformTradeNo,jdbcType=VARCHAR}");
        }
        
        if (record.getPlatformLogNo() != null) {
            sql.VALUES("platform_log_no", "#{platformLogNo,jdbcType=VARCHAR}");
        }
        
        if (record.getPlatformAppid() != null) {
            sql.VALUES("platform_appid", "#{platformAppid,jdbcType=VARCHAR}");
        }
        
        if (record.getPlatformRate() != null) {
            sql.VALUES("platform_rate", "#{platformRate,jdbcType=DECIMAL}");
        }
        
        if (record.getPlatformCommission() != null) {
            sql.VALUES("platform_commission", "#{platformCommission,jdbcType=DECIMAL}");
        }
        
        if (record.getPayAppid() != null) {
            sql.VALUES("pay_appid", "#{payAppid,jdbcType=VARCHAR}");
        }
        
        if (record.getPayUserId() != null) {
            sql.VALUES("pay_user_id", "#{payUserId,jdbcType=VARCHAR}");
        }
        
        if (record.getPayMode() != null) {
            sql.VALUES("pay_mode", "#{payMode,jdbcType=VARCHAR}");
        }
        
        if (record.getOutTradeNo() != null) {
            sql.VALUES("out_trade_no", "#{outTradeNo,jdbcType=VARCHAR}");
        }
        
        if (record.getTradeAmount() != null) {
            sql.VALUES("trade_amount", "#{tradeAmount,jdbcType=DECIMAL}");
        }
        
        if (record.getStoreDiscountSatisfy() != null) {
            sql.VALUES("store_discount_satisfy", "#{storeDiscountSatisfy,jdbcType=BIT}");
        }
        
        if (record.getStoreDiscountId() != null) {
            sql.VALUES("store_discount_id", "#{storeDiscountId,jdbcType=BIGINT}");
        }
        
        if (record.getStoreDiscountName() != null) {
            sql.VALUES("store_discount_name", "#{storeDiscountName,jdbcType=VARCHAR}");
        }
        
        if (record.getStoreDiscountType() != null) {
            sql.VALUES("store_discount_type", "#{storeDiscountType,jdbcType=INTEGER}");
        }
        
        if (record.getStoreDiscountCondition() != null) {
            sql.VALUES("store_discount_condition", "#{storeDiscountCondition,jdbcType=DECIMAL}");
        }
        
        if (record.getStoreDiscountPrice() != null) {
            sql.VALUES("store_discount_price", "#{storeDiscountPrice,jdbcType=DECIMAL}");
        }
        
        if (record.getStoreDiscountFinalCostPrice() != null) {
            sql.VALUES("store_discount_final_cost_price", "#{storeDiscountFinalCostPrice,jdbcType=DECIMAL}");
        }
        
        if (record.getStoreDiscountActualPrice() != null) {
            sql.VALUES("store_discount_actual_price", "#{storeDiscountActualPrice,jdbcType=DECIMAL}");
        }
        
        if (record.getStoreDiscountProfitPrice() != null) {
            sql.VALUES("store_discount_profit_price", "#{storeDiscountProfitPrice,jdbcType=DECIMAL}");
        }
        
        if (record.getUserId() != null) {
            sql.VALUES("user_id", "#{userId,jdbcType=INTEGER}");
        }
        
        if (record.getUserPhone() != null) {
            sql.VALUES("user_phone", "#{userPhone,jdbcType=VARCHAR}");
        }
        
        if (record.getUserDiscountId() != null) {
            sql.VALUES("user_discount_id", "#{userDiscountId,jdbcType=BIGINT}");
        }
        
        if (record.getUserDiscountName() != null) {
            sql.VALUES("user_discount_name", "#{userDiscountName,jdbcType=VARCHAR}");
        }
        
        if (record.getUserDiscountType() != null) {
            sql.VALUES("user_discount_type", "#{userDiscountType,jdbcType=INTEGER}");
        }
        
        if (record.getUserDiscountPrice() != null) {
            sql.VALUES("user_discount_price", "#{userDiscountPrice,jdbcType=DECIMAL}");
        }
        
        if (record.getUserDiscountActualPrice() != null) {
            sql.VALUES("user_discount_actual_price", "#{userDiscountActualPrice,jdbcType=DECIMAL}");
        }
        
        if (record.getTradeActualAmount() != null) {
            sql.VALUES("trade_actual_amount", "#{tradeActualAmount,jdbcType=DECIMAL}");
        }
        
        if (record.getIncomeAmount() != null) {
            sql.VALUES("income_amount", "#{incomeAmount,jdbcType=DECIMAL}");
        }
        
        if (record.getAccTradeNo() != null) {
            sql.VALUES("acc_trade_no", "#{accTradeNo,jdbcType=VARCHAR}");
        }
        
        if (record.getAccSettleAmount() != null) {
            sql.VALUES("acc_settle_amount", "#{accSettleAmount,jdbcType=DECIMAL}");
        }
        
        if (record.getAccMdiscountAmount() != null) {
            sql.VALUES("acc_mdiscount_amount", "#{accMdiscountAmount,jdbcType=DECIMAL}");
        }
        
        if (record.getAccDiscountAmount() != null) {
            sql.VALUES("acc_discount_amount", "#{accDiscountAmount,jdbcType=DECIMAL}");
        }
        
        if (record.getShdFeeAmt() != null) {
            sql.VALUES("shd_fee_amt", "#{shdFeeAmt,jdbcType=DECIMAL}");
        }
        
        if (record.getFeeRate() != null) {
            sql.VALUES("fee_rate", "#{feeRate,jdbcType=DECIMAL}");
        }
        
        if (record.getSettleAmount() != null) {
            sql.VALUES("settle_amount", "#{settleAmount,jdbcType=DECIMAL}");
        }
        
        if (record.getSettleDate() != null) {
            sql.VALUES("settle_date", "#{settleDate,jdbcType=DATE}");
        }
        
        if (record.getAccPaymentCode() != null) {
            sql.VALUES("acc_payment_code", "#{accPaymentCode,jdbcType=VARCHAR}");
        }
        
        if (record.getCardType() != null) {
            sql.VALUES("card_type", "#{cardType,jdbcType=VARCHAR}");
        }
        
        if (record.getStatus() != null) {
            sql.VALUES("`status`", "#{status,jdbcType=INTEGER}");
        }
        
        if (record.getProfitSharingStatus() != null) {
            sql.VALUES("profit_sharing_status", "#{profitSharingStatus,jdbcType=BIT}");
        }
        
        if (record.getPayTime() != null) {
            sql.VALUES("pay_time", "#{payTime,jdbcType=TIMESTAMP}");
        }
        
        if (record.getTimeoutExpress() != null) {
            sql.VALUES("timeout_express", "#{timeoutExpress,jdbcType=INTEGER}");
        }
        
        if (record.getSubject() != null) {
            sql.VALUES("subject", "#{subject,jdbcType=VARCHAR}");
        }
        
        if (record.getPayNotifyUrl() != null) {
            sql.VALUES("pay_notify_url", "#{payNotifyUrl,jdbcType=VARCHAR}");
        }
        
        if (record.getAttach() != null) {
            sql.VALUES("attach", "#{attach,jdbcType=VARCHAR}");
        }
        
        if (record.getSpecialField() != null) {
            sql.VALUES("special_field", "#{specialField,jdbcType=VARCHAR}");
        }
        
        if (record.getRefundType() != null) {
            sql.VALUES("refund_type", "#{refundType,jdbcType=INTEGER}");
        }
        
        if (record.getRefundPrice() != null) {
            sql.VALUES("refund_price", "#{refundPrice,jdbcType=DECIMAL}");
        }
        
        if (record.getCreateType() != null) {
            sql.VALUES("create_type", "#{createType,jdbcType=INTEGER}");
        }
        
        if (record.getTransType() != null) {
            sql.VALUES("trans_type", "#{transType,jdbcType=VARCHAR}");
        }
        
        if (record.getCreateTime() != null) {
            sql.VALUES("create_time", "#{createTime,jdbcType=TIMESTAMP}");
        }
        
        if (record.getCancelTime() != null) {
            sql.VALUES("cancel_time", "#{cancelTime,jdbcType=TIMESTAMP}");
        }
        
        if (record.getUpdateTime() != null) {
            sql.VALUES("update_time", "#{updateTime,jdbcType=TIMESTAMP}");
        }
        
        if (record.getRequestIp() != null) {
            sql.VALUES("request_ip", "#{requestIp,jdbcType=VARCHAR}");
        }
        
        if (record.getExt1() != null) {
            sql.VALUES("ext_1", "#{ext1,jdbcType=VARCHAR}");
        }
        
        if (record.getExt2() != null) {
            sql.VALUES("ext_2", "#{ext2,jdbcType=VARCHAR}");
        }
        
        if (record.getExt3() != null) {
            sql.VALUES("ext_3", "#{ext3,jdbcType=VARCHAR}");
        }
        
        return sql.toString();
    }

    public String selectByExample(BsTradeOrderExample example) {
        SQL sql = new SQL();
        if (example != null && example.isDistinct()) {
            sql.SELECT_DISTINCT("id");
        } else {
            sql.SELECT("id");
        }
        sql.SELECT("company_id");
        sql.SELECT("agent_id");
        sql.SELECT("salesman_id");
        sql.SELECT("salesman_name");
        sql.SELECT("mer_id");
        sql.SELECT("mer_name");
        sql.SELECT("mer_abbreviate");
        sql.SELECT("mer_no");
        sql.SELECT("store_id");
        sql.SELECT("store_name");
        sql.SELECT("device_id");
        sql.SELECT("device_sn");
        sql.SELECT("qr_code_id");
        sql.SELECT("qr_code_sn");
        sql.SELECT("platform_type");
        sql.SELECT("platform_mer_no");
        sql.SELECT("platform_trade_no");
        sql.SELECT("platform_log_no");
        sql.SELECT("platform_appid");
        sql.SELECT("platform_rate");
        sql.SELECT("platform_commission");
        sql.SELECT("pay_appid");
        sql.SELECT("pay_user_id");
        sql.SELECT("pay_mode");
        sql.SELECT("out_trade_no");
        sql.SELECT("trade_amount");
        sql.SELECT("store_discount_satisfy");
        sql.SELECT("store_discount_id");
        sql.SELECT("store_discount_name");
        sql.SELECT("store_discount_type");
        sql.SELECT("store_discount_condition");
        sql.SELECT("store_discount_price");
        sql.SELECT("store_discount_final_cost_price");
        sql.SELECT("store_discount_actual_price");
        sql.SELECT("store_discount_profit_price");
        sql.SELECT("user_id");
        sql.SELECT("user_phone");
        sql.SELECT("user_discount_id");
        sql.SELECT("user_discount_name");
        sql.SELECT("user_discount_type");
        sql.SELECT("user_discount_price");
        sql.SELECT("user_discount_actual_price");
        sql.SELECT("trade_actual_amount");
        sql.SELECT("income_amount");
        sql.SELECT("acc_trade_no");
        sql.SELECT("acc_settle_amount");
        sql.SELECT("acc_mdiscount_amount");
        sql.SELECT("acc_discount_amount");
        sql.SELECT("shd_fee_amt");
        sql.SELECT("fee_rate");
        sql.SELECT("settle_amount");
        sql.SELECT("settle_date");
        sql.SELECT("acc_payment_code");
        sql.SELECT("card_type");
        sql.SELECT("`status`");
        sql.SELECT("profit_sharing_status");
        sql.SELECT("pay_time");
        sql.SELECT("timeout_express");
        sql.SELECT("subject");
        sql.SELECT("pay_notify_url");
        sql.SELECT("attach");
        sql.SELECT("special_field");
        sql.SELECT("refund_type");
        sql.SELECT("refund_price");
        sql.SELECT("create_type");
        sql.SELECT("trans_type");
        sql.SELECT("create_time");
        sql.SELECT("cancel_time");
        sql.SELECT("update_time");
        sql.SELECT("request_ip");
        sql.SELECT("ext_1");
        sql.SELECT("ext_2");
        sql.SELECT("ext_3");
        sql.FROM("bs_trade_order");
        applyWhere(sql, example, false);
        
        if (example != null && example.getOrderByClause() != null) {
            sql.ORDER_BY(example.getOrderByClause());
        }
        
        return sql.toString();
    }

    public String updateByExampleSelective(Map<String, Object> parameter) {
        BsTradeOrder record = (BsTradeOrder) parameter.get("record");
        BsTradeOrderExample example = (BsTradeOrderExample) parameter.get("example");
        
        SQL sql = new SQL();
        sql.UPDATE("bs_trade_order");
        
        if (record.getId() != null) {
            sql.SET("id = #{record.id,jdbcType=BIGINT}");
        }
        
        if (record.getCompanyId() != null) {
            sql.SET("company_id = #{record.companyId,jdbcType=BIGINT}");
        }
        
        if (record.getAgentId() != null) {
            sql.SET("agent_id = #{record.agentId,jdbcType=BIGINT}");
        }
        
        if (record.getSalesmanId() != null) {
            sql.SET("salesman_id = #{record.salesmanId,jdbcType=BIGINT}");
        }
        
        if (record.getSalesmanName() != null) {
            sql.SET("salesman_name = #{record.salesmanName,jdbcType=VARCHAR}");
        }
        
        if (record.getMerId() != null) {
            sql.SET("mer_id = #{record.merId,jdbcType=BIGINT}");
        }
        
        if (record.getMerName() != null) {
            sql.SET("mer_name = #{record.merName,jdbcType=VARCHAR}");
        }
        
        if (record.getMerAbbreviate() != null) {
            sql.SET("mer_abbreviate = #{record.merAbbreviate,jdbcType=VARCHAR}");
        }
        
        if (record.getMerNo() != null) {
            sql.SET("mer_no = #{record.merNo,jdbcType=VARCHAR}");
        }
        
        if (record.getStoreId() != null) {
            sql.SET("store_id = #{record.storeId,jdbcType=BIGINT}");
        }
        
        if (record.getStoreName() != null) {
            sql.SET("store_name = #{record.storeName,jdbcType=VARCHAR}");
        }
        
        if (record.getDeviceId() != null) {
            sql.SET("device_id = #{record.deviceId,jdbcType=BIGINT}");
        }
        
        if (record.getDeviceSn() != null) {
            sql.SET("device_sn = #{record.deviceSn,jdbcType=VARCHAR}");
        }
        
        if (record.getQrCodeId() != null) {
            sql.SET("qr_code_id = #{record.qrCodeId,jdbcType=BIGINT}");
        }
        
        if (record.getQrCodeSn() != null) {
            sql.SET("qr_code_sn = #{record.qrCodeSn,jdbcType=VARCHAR}");
        }
        
        if (record.getPlatformType() != null) {
            sql.SET("platform_type = #{record.platformType,jdbcType=INTEGER}");
        }
        
        if (record.getPlatformMerNo() != null) {
            sql.SET("platform_mer_no = #{record.platformMerNo,jdbcType=VARCHAR}");
        }
        
        if (record.getPlatformTradeNo() != null) {
            sql.SET("platform_trade_no = #{record.platformTradeNo,jdbcType=VARCHAR}");
        }
        
        if (record.getPlatformLogNo() != null) {
            sql.SET("platform_log_no = #{record.platformLogNo,jdbcType=VARCHAR}");
        }
        
        if (record.getPlatformAppid() != null) {
            sql.SET("platform_appid = #{record.platformAppid,jdbcType=VARCHAR}");
        }
        
        if (record.getPlatformRate() != null) {
            sql.SET("platform_rate = #{record.platformRate,jdbcType=DECIMAL}");
        }
        
        if (record.getPlatformCommission() != null) {
            sql.SET("platform_commission = #{record.platformCommission,jdbcType=DECIMAL}");
        }
        
        if (record.getPayAppid() != null) {
            sql.SET("pay_appid = #{record.payAppid,jdbcType=VARCHAR}");
        }
        
        if (record.getPayUserId() != null) {
            sql.SET("pay_user_id = #{record.payUserId,jdbcType=VARCHAR}");
        }
        
        if (record.getPayMode() != null) {
            sql.SET("pay_mode = #{record.payMode,jdbcType=VARCHAR}");
        }
        
        if (record.getOutTradeNo() != null) {
            sql.SET("out_trade_no = #{record.outTradeNo,jdbcType=VARCHAR}");
        }
        
        if (record.getTradeAmount() != null) {
            sql.SET("trade_amount = #{record.tradeAmount,jdbcType=DECIMAL}");
        }
        
        if (record.getStoreDiscountSatisfy() != null) {
            sql.SET("store_discount_satisfy = #{record.storeDiscountSatisfy,jdbcType=BIT}");
        }
        
        if (record.getStoreDiscountId() != null) {
            sql.SET("store_discount_id = #{record.storeDiscountId,jdbcType=BIGINT}");
        }
        
        if (record.getStoreDiscountName() != null) {
            sql.SET("store_discount_name = #{record.storeDiscountName,jdbcType=VARCHAR}");
        }
        
        if (record.getStoreDiscountType() != null) {
            sql.SET("store_discount_type = #{record.storeDiscountType,jdbcType=INTEGER}");
        }
        
        if (record.getStoreDiscountCondition() != null) {
            sql.SET("store_discount_condition = #{record.storeDiscountCondition,jdbcType=DECIMAL}");
        }
        
        if (record.getStoreDiscountPrice() != null) {
            sql.SET("store_discount_price = #{record.storeDiscountPrice,jdbcType=DECIMAL}");
        }
        
        if (record.getStoreDiscountFinalCostPrice() != null) {
            sql.SET("store_discount_final_cost_price = #{record.storeDiscountFinalCostPrice,jdbcType=DECIMAL}");
        }
        
        if (record.getStoreDiscountActualPrice() != null) {
            sql.SET("store_discount_actual_price = #{record.storeDiscountActualPrice,jdbcType=DECIMAL}");
        }
        
        if (record.getStoreDiscountProfitPrice() != null) {
            sql.SET("store_discount_profit_price = #{record.storeDiscountProfitPrice,jdbcType=DECIMAL}");
        }
        
        if (record.getUserId() != null) {
            sql.SET("user_id = #{record.userId,jdbcType=INTEGER}");
        }
        
        if (record.getUserPhone() != null) {
            sql.SET("user_phone = #{record.userPhone,jdbcType=VARCHAR}");
        }
        
        if (record.getUserDiscountId() != null) {
            sql.SET("user_discount_id = #{record.userDiscountId,jdbcType=BIGINT}");
        }
        
        if (record.getUserDiscountName() != null) {
            sql.SET("user_discount_name = #{record.userDiscountName,jdbcType=VARCHAR}");
        }
        
        if (record.getUserDiscountType() != null) {
            sql.SET("user_discount_type = #{record.userDiscountType,jdbcType=INTEGER}");
        }
        
        if (record.getUserDiscountPrice() != null) {
            sql.SET("user_discount_price = #{record.userDiscountPrice,jdbcType=DECIMAL}");
        }
        
        if (record.getUserDiscountActualPrice() != null) {
            sql.SET("user_discount_actual_price = #{record.userDiscountActualPrice,jdbcType=DECIMAL}");
        }
        
        if (record.getTradeActualAmount() != null) {
            sql.SET("trade_actual_amount = #{record.tradeActualAmount,jdbcType=DECIMAL}");
        }
        
        if (record.getIncomeAmount() != null) {
            sql.SET("income_amount = #{record.incomeAmount,jdbcType=DECIMAL}");
        }
        
        if (record.getAccTradeNo() != null) {
            sql.SET("acc_trade_no = #{record.accTradeNo,jdbcType=VARCHAR}");
        }
        
        if (record.getAccSettleAmount() != null) {
            sql.SET("acc_settle_amount = #{record.accSettleAmount,jdbcType=DECIMAL}");
        }
        
        if (record.getAccMdiscountAmount() != null) {
            sql.SET("acc_mdiscount_amount = #{record.accMdiscountAmount,jdbcType=DECIMAL}");
        }
        
        if (record.getAccDiscountAmount() != null) {
            sql.SET("acc_discount_amount = #{record.accDiscountAmount,jdbcType=DECIMAL}");
        }
        
        if (record.getShdFeeAmt() != null) {
            sql.SET("shd_fee_amt = #{record.shdFeeAmt,jdbcType=DECIMAL}");
        }
        
        if (record.getFeeRate() != null) {
            sql.SET("fee_rate = #{record.feeRate,jdbcType=DECIMAL}");
        }
        
        if (record.getSettleAmount() != null) {
            sql.SET("settle_amount = #{record.settleAmount,jdbcType=DECIMAL}");
        }
        
        if (record.getSettleDate() != null) {
            sql.SET("settle_date = #{record.settleDate,jdbcType=DATE}");
        }
        
        if (record.getAccPaymentCode() != null) {
            sql.SET("acc_payment_code = #{record.accPaymentCode,jdbcType=VARCHAR}");
        }
        
        if (record.getCardType() != null) {
            sql.SET("card_type = #{record.cardType,jdbcType=VARCHAR}");
        }
        
        if (record.getStatus() != null) {
            sql.SET("`status` = #{record.status,jdbcType=INTEGER}");
        }
        
        if (record.getProfitSharingStatus() != null) {
            sql.SET("profit_sharing_status = #{record.profitSharingStatus,jdbcType=BIT}");
        }
        
        if (record.getPayTime() != null) {
            sql.SET("pay_time = #{record.payTime,jdbcType=TIMESTAMP}");
        }
        
        if (record.getTimeoutExpress() != null) {
            sql.SET("timeout_express = #{record.timeoutExpress,jdbcType=INTEGER}");
        }
        
        if (record.getSubject() != null) {
            sql.SET("subject = #{record.subject,jdbcType=VARCHAR}");
        }
        
        if (record.getPayNotifyUrl() != null) {
            sql.SET("pay_notify_url = #{record.payNotifyUrl,jdbcType=VARCHAR}");
        }
        
        if (record.getAttach() != null) {
            sql.SET("attach = #{record.attach,jdbcType=VARCHAR}");
        }
        
        if (record.getSpecialField() != null) {
            sql.SET("special_field = #{record.specialField,jdbcType=VARCHAR}");
        }
        
        if (record.getRefundType() != null) {
            sql.SET("refund_type = #{record.refundType,jdbcType=INTEGER}");
        }
        
        if (record.getRefundPrice() != null) {
            sql.SET("refund_price = #{record.refundPrice,jdbcType=DECIMAL}");
        }
        
        if (record.getCreateType() != null) {
            sql.SET("create_type = #{record.createType,jdbcType=INTEGER}");
        }
        
        if (record.getTransType() != null) {
            sql.SET("trans_type = #{record.transType,jdbcType=VARCHAR}");
        }
        
        if (record.getCreateTime() != null) {
            sql.SET("create_time = #{record.createTime,jdbcType=TIMESTAMP}");
        }
        
        if (record.getCancelTime() != null) {
            sql.SET("cancel_time = #{record.cancelTime,jdbcType=TIMESTAMP}");
        }
        
        if (record.getUpdateTime() != null) {
            sql.SET("update_time = #{record.updateTime,jdbcType=TIMESTAMP}");
        }
        
        if (record.getRequestIp() != null) {
            sql.SET("request_ip = #{record.requestIp,jdbcType=VARCHAR}");
        }
        
        if (record.getExt1() != null) {
            sql.SET("ext_1 = #{record.ext1,jdbcType=VARCHAR}");
        }
        
        if (record.getExt2() != null) {
            sql.SET("ext_2 = #{record.ext2,jdbcType=VARCHAR}");
        }
        
        if (record.getExt3() != null) {
            sql.SET("ext_3 = #{record.ext3,jdbcType=VARCHAR}");
        }
        
        applyWhere(sql, example, true);
        return sql.toString();
    }

    public String updateByExample(Map<String, Object> parameter) {
        SQL sql = new SQL();
        sql.UPDATE("bs_trade_order");
        
        sql.SET("id = #{record.id,jdbcType=BIGINT}");
        sql.SET("company_id = #{record.companyId,jdbcType=BIGINT}");
        sql.SET("agent_id = #{record.agentId,jdbcType=BIGINT}");
        sql.SET("salesman_id = #{record.salesmanId,jdbcType=BIGINT}");
        sql.SET("salesman_name = #{record.salesmanName,jdbcType=VARCHAR}");
        sql.SET("mer_id = #{record.merId,jdbcType=BIGINT}");
        sql.SET("mer_name = #{record.merName,jdbcType=VARCHAR}");
        sql.SET("mer_abbreviate = #{record.merAbbreviate,jdbcType=VARCHAR}");
        sql.SET("mer_no = #{record.merNo,jdbcType=VARCHAR}");
        sql.SET("store_id = #{record.storeId,jdbcType=BIGINT}");
        sql.SET("store_name = #{record.storeName,jdbcType=VARCHAR}");
        sql.SET("device_id = #{record.deviceId,jdbcType=BIGINT}");
        sql.SET("device_sn = #{record.deviceSn,jdbcType=VARCHAR}");
        sql.SET("qr_code_id = #{record.qrCodeId,jdbcType=BIGINT}");
        sql.SET("qr_code_sn = #{record.qrCodeSn,jdbcType=VARCHAR}");
        sql.SET("platform_type = #{record.platformType,jdbcType=INTEGER}");
        sql.SET("platform_mer_no = #{record.platformMerNo,jdbcType=VARCHAR}");
        sql.SET("platform_trade_no = #{record.platformTradeNo,jdbcType=VARCHAR}");
        sql.SET("platform_log_no = #{record.platformLogNo,jdbcType=VARCHAR}");
        sql.SET("platform_appid = #{record.platformAppid,jdbcType=VARCHAR}");
        sql.SET("platform_rate = #{record.platformRate,jdbcType=DECIMAL}");
        sql.SET("platform_commission = #{record.platformCommission,jdbcType=DECIMAL}");
        sql.SET("pay_appid = #{record.payAppid,jdbcType=VARCHAR}");
        sql.SET("pay_user_id = #{record.payUserId,jdbcType=VARCHAR}");
        sql.SET("pay_mode = #{record.payMode,jdbcType=VARCHAR}");
        sql.SET("out_trade_no = #{record.outTradeNo,jdbcType=VARCHAR}");
        sql.SET("trade_amount = #{record.tradeAmount,jdbcType=DECIMAL}");
        sql.SET("store_discount_satisfy = #{record.storeDiscountSatisfy,jdbcType=BIT}");
        sql.SET("store_discount_id = #{record.storeDiscountId,jdbcType=BIGINT}");
        sql.SET("store_discount_name = #{record.storeDiscountName,jdbcType=VARCHAR}");
        sql.SET("store_discount_type = #{record.storeDiscountType,jdbcType=INTEGER}");
        sql.SET("store_discount_condition = #{record.storeDiscountCondition,jdbcType=DECIMAL}");
        sql.SET("store_discount_price = #{record.storeDiscountPrice,jdbcType=DECIMAL}");
        sql.SET("store_discount_final_cost_price = #{record.storeDiscountFinalCostPrice,jdbcType=DECIMAL}");
        sql.SET("store_discount_actual_price = #{record.storeDiscountActualPrice,jdbcType=DECIMAL}");
        sql.SET("store_discount_profit_price = #{record.storeDiscountProfitPrice,jdbcType=DECIMAL}");
        sql.SET("user_id = #{record.userId,jdbcType=INTEGER}");
        sql.SET("user_phone = #{record.userPhone,jdbcType=VARCHAR}");
        sql.SET("user_discount_id = #{record.userDiscountId,jdbcType=BIGINT}");
        sql.SET("user_discount_name = #{record.userDiscountName,jdbcType=VARCHAR}");
        sql.SET("user_discount_type = #{record.userDiscountType,jdbcType=INTEGER}");
        sql.SET("user_discount_price = #{record.userDiscountPrice,jdbcType=DECIMAL}");
        sql.SET("user_discount_actual_price = #{record.userDiscountActualPrice,jdbcType=DECIMAL}");
        sql.SET("trade_actual_amount = #{record.tradeActualAmount,jdbcType=DECIMAL}");
        sql.SET("income_amount = #{record.incomeAmount,jdbcType=DECIMAL}");
        sql.SET("acc_trade_no = #{record.accTradeNo,jdbcType=VARCHAR}");
        sql.SET("acc_settle_amount = #{record.accSettleAmount,jdbcType=DECIMAL}");
        sql.SET("acc_mdiscount_amount = #{record.accMdiscountAmount,jdbcType=DECIMAL}");
        sql.SET("acc_discount_amount = #{record.accDiscountAmount,jdbcType=DECIMAL}");
        sql.SET("shd_fee_amt = #{record.shdFeeAmt,jdbcType=DECIMAL}");
        sql.SET("fee_rate = #{record.feeRate,jdbcType=DECIMAL}");
        sql.SET("settle_amount = #{record.settleAmount,jdbcType=DECIMAL}");
        sql.SET("settle_date = #{record.settleDate,jdbcType=DATE}");
        sql.SET("acc_payment_code = #{record.accPaymentCode,jdbcType=VARCHAR}");
        sql.SET("card_type = #{record.cardType,jdbcType=VARCHAR}");
        sql.SET("`status` = #{record.status,jdbcType=INTEGER}");
        sql.SET("profit_sharing_status = #{record.profitSharingStatus,jdbcType=BIT}");
        sql.SET("pay_time = #{record.payTime,jdbcType=TIMESTAMP}");
        sql.SET("timeout_express = #{record.timeoutExpress,jdbcType=INTEGER}");
        sql.SET("subject = #{record.subject,jdbcType=VARCHAR}");
        sql.SET("pay_notify_url = #{record.payNotifyUrl,jdbcType=VARCHAR}");
        sql.SET("attach = #{record.attach,jdbcType=VARCHAR}");
        sql.SET("special_field = #{record.specialField,jdbcType=VARCHAR}");
        sql.SET("refund_type = #{record.refundType,jdbcType=INTEGER}");
        sql.SET("refund_price = #{record.refundPrice,jdbcType=DECIMAL}");
        sql.SET("create_type = #{record.createType,jdbcType=INTEGER}");
        sql.SET("trans_type = #{record.transType,jdbcType=VARCHAR}");
        sql.SET("create_time = #{record.createTime,jdbcType=TIMESTAMP}");
        sql.SET("cancel_time = #{record.cancelTime,jdbcType=TIMESTAMP}");
        sql.SET("update_time = #{record.updateTime,jdbcType=TIMESTAMP}");
        sql.SET("request_ip = #{record.requestIp,jdbcType=VARCHAR}");
        sql.SET("ext_1 = #{record.ext1,jdbcType=VARCHAR}");
        sql.SET("ext_2 = #{record.ext2,jdbcType=VARCHAR}");
        sql.SET("ext_3 = #{record.ext3,jdbcType=VARCHAR}");
        
        BsTradeOrderExample example = (BsTradeOrderExample) parameter.get("example");
        applyWhere(sql, example, true);
        return sql.toString();
    }

    public String updateByPrimaryKeySelective(BsTradeOrder record) {
        SQL sql = new SQL();
        sql.UPDATE("bs_trade_order");
        
        if (record.getCompanyId() != null) {
            sql.SET("company_id = #{companyId,jdbcType=BIGINT}");
        }
        
        if (record.getAgentId() != null) {
            sql.SET("agent_id = #{agentId,jdbcType=BIGINT}");
        }
        
        if (record.getSalesmanId() != null) {
            sql.SET("salesman_id = #{salesmanId,jdbcType=BIGINT}");
        }
        
        if (record.getSalesmanName() != null) {
            sql.SET("salesman_name = #{salesmanName,jdbcType=VARCHAR}");
        }
        
        if (record.getMerId() != null) {
            sql.SET("mer_id = #{merId,jdbcType=BIGINT}");
        }
        
        if (record.getMerName() != null) {
            sql.SET("mer_name = #{merName,jdbcType=VARCHAR}");
        }
        
        if (record.getMerAbbreviate() != null) {
            sql.SET("mer_abbreviate = #{merAbbreviate,jdbcType=VARCHAR}");
        }
        
        if (record.getMerNo() != null) {
            sql.SET("mer_no = #{merNo,jdbcType=VARCHAR}");
        }
        
        if (record.getStoreId() != null) {
            sql.SET("store_id = #{storeId,jdbcType=BIGINT}");
        }
        
        if (record.getStoreName() != null) {
            sql.SET("store_name = #{storeName,jdbcType=VARCHAR}");
        }
        
        if (record.getDeviceId() != null) {
            sql.SET("device_id = #{deviceId,jdbcType=BIGINT}");
        }
        
        if (record.getDeviceSn() != null) {
            sql.SET("device_sn = #{deviceSn,jdbcType=VARCHAR}");
        }
        
        if (record.getQrCodeId() != null) {
            sql.SET("qr_code_id = #{qrCodeId,jdbcType=BIGINT}");
        }
        
        if (record.getQrCodeSn() != null) {
            sql.SET("qr_code_sn = #{qrCodeSn,jdbcType=VARCHAR}");
        }
        
        if (record.getPlatformType() != null) {
            sql.SET("platform_type = #{platformType,jdbcType=INTEGER}");
        }
        
        if (record.getPlatformMerNo() != null) {
            sql.SET("platform_mer_no = #{platformMerNo,jdbcType=VARCHAR}");
        }
        
        if (record.getPlatformTradeNo() != null) {
            sql.SET("platform_trade_no = #{platformTradeNo,jdbcType=VARCHAR}");
        }
        
        if (record.getPlatformLogNo() != null) {
            sql.SET("platform_log_no = #{platformLogNo,jdbcType=VARCHAR}");
        }
        
        if (record.getPlatformAppid() != null) {
            sql.SET("platform_appid = #{platformAppid,jdbcType=VARCHAR}");
        }
        
        if (record.getPlatformRate() != null) {
            sql.SET("platform_rate = #{platformRate,jdbcType=DECIMAL}");
        }
        
        if (record.getPlatformCommission() != null) {
            sql.SET("platform_commission = #{platformCommission,jdbcType=DECIMAL}");
        }
        
        if (record.getPayAppid() != null) {
            sql.SET("pay_appid = #{payAppid,jdbcType=VARCHAR}");
        }
        
        if (record.getPayUserId() != null) {
            sql.SET("pay_user_id = #{payUserId,jdbcType=VARCHAR}");
        }
        
        if (record.getPayMode() != null) {
            sql.SET("pay_mode = #{payMode,jdbcType=VARCHAR}");
        }
        
        if (record.getOutTradeNo() != null) {
            sql.SET("out_trade_no = #{outTradeNo,jdbcType=VARCHAR}");
        }
        
        if (record.getTradeAmount() != null) {
            sql.SET("trade_amount = #{tradeAmount,jdbcType=DECIMAL}");
        }
        
        if (record.getStoreDiscountSatisfy() != null) {
            sql.SET("store_discount_satisfy = #{storeDiscountSatisfy,jdbcType=BIT}");
        }
        
        if (record.getStoreDiscountId() != null) {
            sql.SET("store_discount_id = #{storeDiscountId,jdbcType=BIGINT}");
        }
        
        if (record.getStoreDiscountName() != null) {
            sql.SET("store_discount_name = #{storeDiscountName,jdbcType=VARCHAR}");
        }
        
        if (record.getStoreDiscountType() != null) {
            sql.SET("store_discount_type = #{storeDiscountType,jdbcType=INTEGER}");
        }
        
        if (record.getStoreDiscountCondition() != null) {
            sql.SET("store_discount_condition = #{storeDiscountCondition,jdbcType=DECIMAL}");
        }
        
        if (record.getStoreDiscountPrice() != null) {
            sql.SET("store_discount_price = #{storeDiscountPrice,jdbcType=DECIMAL}");
        }
        
        if (record.getStoreDiscountFinalCostPrice() != null) {
            sql.SET("store_discount_final_cost_price = #{storeDiscountFinalCostPrice,jdbcType=DECIMAL}");
        }
        
        if (record.getStoreDiscountActualPrice() != null) {
            sql.SET("store_discount_actual_price = #{storeDiscountActualPrice,jdbcType=DECIMAL}");
        }
        
        if (record.getStoreDiscountProfitPrice() != null) {
            sql.SET("store_discount_profit_price = #{storeDiscountProfitPrice,jdbcType=DECIMAL}");
        }
        
        if (record.getUserId() != null) {
            sql.SET("user_id = #{userId,jdbcType=INTEGER}");
        }
        
        if (record.getUserPhone() != null) {
            sql.SET("user_phone = #{userPhone,jdbcType=VARCHAR}");
        }
        
        if (record.getUserDiscountId() != null) {
            sql.SET("user_discount_id = #{userDiscountId,jdbcType=BIGINT}");
        }
        
        if (record.getUserDiscountName() != null) {
            sql.SET("user_discount_name = #{userDiscountName,jdbcType=VARCHAR}");
        }
        
        if (record.getUserDiscountType() != null) {
            sql.SET("user_discount_type = #{userDiscountType,jdbcType=INTEGER}");
        }
        
        if (record.getUserDiscountPrice() != null) {
            sql.SET("user_discount_price = #{userDiscountPrice,jdbcType=DECIMAL}");
        }
        
        if (record.getUserDiscountActualPrice() != null) {
            sql.SET("user_discount_actual_price = #{userDiscountActualPrice,jdbcType=DECIMAL}");
        }
        
        if (record.getTradeActualAmount() != null) {
            sql.SET("trade_actual_amount = #{tradeActualAmount,jdbcType=DECIMAL}");
        }
        
        if (record.getIncomeAmount() != null) {
            sql.SET("income_amount = #{incomeAmount,jdbcType=DECIMAL}");
        }
        
        if (record.getAccTradeNo() != null) {
            sql.SET("acc_trade_no = #{accTradeNo,jdbcType=VARCHAR}");
        }
        
        if (record.getAccSettleAmount() != null) {
            sql.SET("acc_settle_amount = #{accSettleAmount,jdbcType=DECIMAL}");
        }
        
        if (record.getAccMdiscountAmount() != null) {
            sql.SET("acc_mdiscount_amount = #{accMdiscountAmount,jdbcType=DECIMAL}");
        }
        
        if (record.getAccDiscountAmount() != null) {
            sql.SET("acc_discount_amount = #{accDiscountAmount,jdbcType=DECIMAL}");
        }
        
        if (record.getShdFeeAmt() != null) {
            sql.SET("shd_fee_amt = #{shdFeeAmt,jdbcType=DECIMAL}");
        }
        
        if (record.getFeeRate() != null) {
            sql.SET("fee_rate = #{feeRate,jdbcType=DECIMAL}");
        }
        
        if (record.getSettleAmount() != null) {
            sql.SET("settle_amount = #{settleAmount,jdbcType=DECIMAL}");
        }
        
        if (record.getSettleDate() != null) {
            sql.SET("settle_date = #{settleDate,jdbcType=DATE}");
        }
        
        if (record.getAccPaymentCode() != null) {
            sql.SET("acc_payment_code = #{accPaymentCode,jdbcType=VARCHAR}");
        }
        
        if (record.getCardType() != null) {
            sql.SET("card_type = #{cardType,jdbcType=VARCHAR}");
        }
        
        if (record.getStatus() != null) {
            sql.SET("`status` = #{status,jdbcType=INTEGER}");
        }
        
        if (record.getProfitSharingStatus() != null) {
            sql.SET("profit_sharing_status = #{profitSharingStatus,jdbcType=BIT}");
        }
        
        if (record.getPayTime() != null) {
            sql.SET("pay_time = #{payTime,jdbcType=TIMESTAMP}");
        }
        
        if (record.getTimeoutExpress() != null) {
            sql.SET("timeout_express = #{timeoutExpress,jdbcType=INTEGER}");
        }
        
        if (record.getSubject() != null) {
            sql.SET("subject = #{subject,jdbcType=VARCHAR}");
        }
        
        if (record.getPayNotifyUrl() != null) {
            sql.SET("pay_notify_url = #{payNotifyUrl,jdbcType=VARCHAR}");
        }
        
        if (record.getAttach() != null) {
            sql.SET("attach = #{attach,jdbcType=VARCHAR}");
        }
        
        if (record.getSpecialField() != null) {
            sql.SET("special_field = #{specialField,jdbcType=VARCHAR}");
        }
        
        if (record.getRefundType() != null) {
            sql.SET("refund_type = #{refundType,jdbcType=INTEGER}");
        }
        
        if (record.getRefundPrice() != null) {
            sql.SET("refund_price = #{refundPrice,jdbcType=DECIMAL}");
        }
        
        if (record.getCreateType() != null) {
            sql.SET("create_type = #{createType,jdbcType=INTEGER}");
        }
        
        if (record.getTransType() != null) {
            sql.SET("trans_type = #{transType,jdbcType=VARCHAR}");
        }
        
        if (record.getCreateTime() != null) {
            sql.SET("create_time = #{createTime,jdbcType=TIMESTAMP}");
        }
        
        if (record.getCancelTime() != null) {
            sql.SET("cancel_time = #{cancelTime,jdbcType=TIMESTAMP}");
        }
        
        if (record.getUpdateTime() != null) {
            sql.SET("update_time = #{updateTime,jdbcType=TIMESTAMP}");
        }
        
        if (record.getRequestIp() != null) {
            sql.SET("request_ip = #{requestIp,jdbcType=VARCHAR}");
        }
        
        if (record.getExt1() != null) {
            sql.SET("ext_1 = #{ext1,jdbcType=VARCHAR}");
        }
        
        if (record.getExt2() != null) {
            sql.SET("ext_2 = #{ext2,jdbcType=VARCHAR}");
        }
        
        if (record.getExt3() != null) {
            sql.SET("ext_3 = #{ext3,jdbcType=VARCHAR}");
        }
        
        sql.WHERE("id = #{id,jdbcType=BIGINT}");
        
        return sql.toString();
    }

    protected void applyWhere(SQL sql, BsTradeOrderExample example, boolean includeExamplePhrase) {
        if (example == null) {
            return;
        }
        
        String parmPhrase1;
        String parmPhrase1_th;
        String parmPhrase2;
        String parmPhrase2_th;
        String parmPhrase3;
        String parmPhrase3_th;
        if (includeExamplePhrase) {
            parmPhrase1 = "%s #{example.oredCriteria[%d].allCriteria[%d].value}";
            parmPhrase1_th = "%s #{example.oredCriteria[%d].allCriteria[%d].value,typeHandler=%s}";
            parmPhrase2 = "%s #{example.oredCriteria[%d].allCriteria[%d].value} and #{example.oredCriteria[%d].criteria[%d].secondValue}";
            parmPhrase2_th = "%s #{example.oredCriteria[%d].allCriteria[%d].value,typeHandler=%s} and #{example.oredCriteria[%d].criteria[%d].secondValue,typeHandler=%s}";
            parmPhrase3 = "#{example.oredCriteria[%d].allCriteria[%d].value[%d]}";
            parmPhrase3_th = "#{example.oredCriteria[%d].allCriteria[%d].value[%d],typeHandler=%s}";
        } else {
            parmPhrase1 = "%s #{oredCriteria[%d].allCriteria[%d].value}";
            parmPhrase1_th = "%s #{oredCriteria[%d].allCriteria[%d].value,typeHandler=%s}";
            parmPhrase2 = "%s #{oredCriteria[%d].allCriteria[%d].value} and #{oredCriteria[%d].criteria[%d].secondValue}";
            parmPhrase2_th = "%s #{oredCriteria[%d].allCriteria[%d].value,typeHandler=%s} and #{oredCriteria[%d].criteria[%d].secondValue,typeHandler=%s}";
            parmPhrase3 = "#{oredCriteria[%d].allCriteria[%d].value[%d]}";
            parmPhrase3_th = "#{oredCriteria[%d].allCriteria[%d].value[%d],typeHandler=%s}";
        }
        
        StringBuilder sb = new StringBuilder();
        List<Criteria> oredCriteria = example.getOredCriteria();
        boolean firstCriteria = true;
        for (int i = 0; i < oredCriteria.size(); i++) {
            Criteria criteria = oredCriteria.get(i);
            if (criteria.isValid()) {
                if (firstCriteria) {
                    firstCriteria = false;
                } else {
                    sb.append(" or ");
                }
                
                sb.append('(');
                List<Criterion> criterions = criteria.getAllCriteria();
                boolean firstCriterion = true;
                for (int j = 0; j < criterions.size(); j++) {
                    Criterion criterion = criterions.get(j);
                    if (firstCriterion) {
                        firstCriterion = false;
                    } else {
                        sb.append(" and ");
                    }
                    
                    if (criterion.isNoValue()) {
                        sb.append(criterion.getCondition());
                    } else if (criterion.isSingleValue()) {
                        if (criterion.getTypeHandler() == null) {
                            sb.append(String.format(parmPhrase1, criterion.getCondition(), i, j));
                        } else {
                            sb.append(String.format(parmPhrase1_th, criterion.getCondition(), i, j,criterion.getTypeHandler()));
                        }
                    } else if (criterion.isBetweenValue()) {
                        if (criterion.getTypeHandler() == null) {
                            sb.append(String.format(parmPhrase2, criterion.getCondition(), i, j, i, j));
                        } else {
                            sb.append(String.format(parmPhrase2_th, criterion.getCondition(), i, j, criterion.getTypeHandler(), i, j, criterion.getTypeHandler()));
                        }
                    } else if (criterion.isListValue()) {
                        sb.append(criterion.getCondition());
                        sb.append(" (");
                        List<?> listItems = (List<?>) criterion.getValue();
                        boolean comma = false;
                        for (int k = 0; k < listItems.size(); k++) {
                            if (comma) {
                                sb.append(", ");
                            } else {
                                comma = true;
                            }
                            if (criterion.getTypeHandler() == null) {
                                sb.append(String.format(parmPhrase3, i, j, k));
                            } else {
                                sb.append(String.format(parmPhrase3_th, i, j, k, criterion.getTypeHandler()));
                            }
                        }
                        sb.append(')');
                    }
                }
                sb.append(')');
            }
        }
        
        if (sb.length() > 0) {
            sql.WHERE(sb.toString());
        }
    }
}