package com.hai.dao;

import com.hai.entity.HighOrderRefund;
import com.hai.entity.HighOrderRefundExample.Criteria;
import com.hai.entity.HighOrderRefundExample.Criterion;
import com.hai.entity.HighOrderRefundExample;
import java.util.List;
import java.util.Map;
import org.apache.ibatis.jdbc.SQL;

public class HighOrderRefundSqlProvider {

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

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

    public String insertSelective(HighOrderRefund record) {
        SQL sql = new SQL();
        sql.INSERT_INTO("high_order_refund");
        
        if (record.getOrderId() != null) {
            sql.VALUES("order_id", "#{orderId,jdbcType=BIGINT}");
        }
        
        if (record.getOrderNo() != null) {
            sql.VALUES("order_no", "#{orderNo,jdbcType=VARCHAR}");
        }
        
        if (record.getOrderChildId() != null) {
            sql.VALUES("order_child_id", "#{orderChildId,jdbcType=BIGINT}");
        }
        
        if (record.getOrderChildNo() != null) {
            sql.VALUES("order_child_no", "#{orderChildNo,jdbcType=VARCHAR}");
        }
        
        if (record.getMemId() != null) {
            sql.VALUES("mem_id", "#{memId,jdbcType=BIGINT}");
        }
        
        if (record.getMemName() != null) {
            sql.VALUES("mem_name", "#{memName,jdbcType=VARCHAR}");
        }
        
        if (record.getMemPhone() != null) {
            sql.VALUES("mem_phone", "#{memPhone,jdbcType=VARCHAR}");
        }
        
        if (record.getGoodsType() != null) {
            sql.VALUES("goods_type", "#{goodsType,jdbcType=INTEGER}");
        }
        
        if (record.getGoodsId() != null) {
            sql.VALUES("goods_id", "#{goodsId,jdbcType=BIGINT}");
        }
        
        if (record.getGoodsName() != null) {
            sql.VALUES("goods_name", "#{goodsName,jdbcType=VARCHAR}");
        }
        
        if (record.getGoodsDesc() != null) {
            sql.VALUES("goods_desc", "#{goodsDesc,jdbcType=VARCHAR}");
        }
        
        if (record.getGoodsImg() != null) {
            sql.VALUES("goods_img", "#{goodsImg,jdbcType=VARCHAR}");
        }
        
        if (record.getGoodsSpecName() != null) {
            sql.VALUES("goods_spec_name", "#{goodsSpecName,jdbcType=VARCHAR}");
        }
        
        if (record.getGoodsCount() != null) {
            sql.VALUES("goods_count", "#{goodsCount,jdbcType=INTEGER}");
        }
        
        if (record.getRefundOrder() != null) {
            sql.VALUES("refund_order", "#{refundOrder,jdbcType=VARCHAR}");
        }
        
        if (record.getReturnTotalPrice() != null) {
            sql.VALUES("return_total_price", "#{returnTotalPrice,jdbcType=DECIMAL}");
        }
        
        if (record.getRefundPrice() != null) {
            sql.VALUES("refund_price", "#{refundPrice,jdbcType=DECIMAL}");
        }
        
        if (record.getRefundGold() != null) {
            sql.VALUES("refund_gold", "#{refundGold,jdbcType=INTEGER}");
        }
        
        if (record.getRefundRemark() != null) {
            sql.VALUES("refund_remark", "#{refundRemark,jdbcType=VARCHAR}");
        }
        
        if (record.getRefundStatus() != null) {
            sql.VALUES("refund_status", "#{refundStatus,jdbcType=INTEGER}");
        }
        
        if (record.getRefundFailReason() != null) {
            sql.VALUES("refund_fail_reason", "#{refundFailReason,jdbcType=VARCHAR}");
        }
        
        if (record.getCreateTime() != null) {
            sql.VALUES("create_time", "#{createTime,jdbcType=TIMESTAMP}");
        }
        
        if (record.getUpdateTime() != null) {
            sql.VALUES("update_time", "#{updateTime,jdbcType=TIMESTAMP}");
        }
        
        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}");
        }
        
        if (record.getExt4() != null) {
            sql.VALUES("ext_4", "#{ext4,jdbcType=VARCHAR}");
        }
        
        if (record.getExt5() != null) {
            sql.VALUES("ext_5", "#{ext5,jdbcType=VARCHAR}");
        }
        
        if (record.getExt6() != null) {
            sql.VALUES("ext_6", "#{ext6,jdbcType=VARCHAR}");
        }
        
        return sql.toString();
    }

    public String selectByExample(HighOrderRefundExample example) {
        SQL sql = new SQL();
        if (example != null && example.isDistinct()) {
            sql.SELECT_DISTINCT("id");
        } else {
            sql.SELECT("id");
        }
        sql.SELECT("order_id");
        sql.SELECT("order_no");
        sql.SELECT("order_child_id");
        sql.SELECT("order_child_no");
        sql.SELECT("mem_id");
        sql.SELECT("mem_name");
        sql.SELECT("mem_phone");
        sql.SELECT("goods_type");
        sql.SELECT("goods_id");
        sql.SELECT("goods_name");
        sql.SELECT("goods_desc");
        sql.SELECT("goods_img");
        sql.SELECT("goods_spec_name");
        sql.SELECT("goods_count");
        sql.SELECT("refund_order");
        sql.SELECT("return_total_price");
        sql.SELECT("refund_price");
        sql.SELECT("refund_gold");
        sql.SELECT("refund_remark");
        sql.SELECT("refund_status");
        sql.SELECT("refund_fail_reason");
        sql.SELECT("create_time");
        sql.SELECT("update_time");
        sql.SELECT("ext_1");
        sql.SELECT("ext_2");
        sql.SELECT("ext_3");
        sql.SELECT("ext_4");
        sql.SELECT("ext_5");
        sql.SELECT("ext_6");
        sql.FROM("high_order_refund");
        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) {
        HighOrderRefund record = (HighOrderRefund) parameter.get("record");
        HighOrderRefundExample example = (HighOrderRefundExample) parameter.get("example");
        
        SQL sql = new SQL();
        sql.UPDATE("high_order_refund");
        
        if (record.getId() != null) {
            sql.SET("id = #{record.id,jdbcType=BIGINT}");
        }
        
        if (record.getOrderId() != null) {
            sql.SET("order_id = #{record.orderId,jdbcType=BIGINT}");
        }
        
        if (record.getOrderNo() != null) {
            sql.SET("order_no = #{record.orderNo,jdbcType=VARCHAR}");
        }
        
        if (record.getOrderChildId() != null) {
            sql.SET("order_child_id = #{record.orderChildId,jdbcType=BIGINT}");
        }
        
        if (record.getOrderChildNo() != null) {
            sql.SET("order_child_no = #{record.orderChildNo,jdbcType=VARCHAR}");
        }
        
        if (record.getMemId() != null) {
            sql.SET("mem_id = #{record.memId,jdbcType=BIGINT}");
        }
        
        if (record.getMemName() != null) {
            sql.SET("mem_name = #{record.memName,jdbcType=VARCHAR}");
        }
        
        if (record.getMemPhone() != null) {
            sql.SET("mem_phone = #{record.memPhone,jdbcType=VARCHAR}");
        }
        
        if (record.getGoodsType() != null) {
            sql.SET("goods_type = #{record.goodsType,jdbcType=INTEGER}");
        }
        
        if (record.getGoodsId() != null) {
            sql.SET("goods_id = #{record.goodsId,jdbcType=BIGINT}");
        }
        
        if (record.getGoodsName() != null) {
            sql.SET("goods_name = #{record.goodsName,jdbcType=VARCHAR}");
        }
        
        if (record.getGoodsDesc() != null) {
            sql.SET("goods_desc = #{record.goodsDesc,jdbcType=VARCHAR}");
        }
        
        if (record.getGoodsImg() != null) {
            sql.SET("goods_img = #{record.goodsImg,jdbcType=VARCHAR}");
        }
        
        if (record.getGoodsSpecName() != null) {
            sql.SET("goods_spec_name = #{record.goodsSpecName,jdbcType=VARCHAR}");
        }
        
        if (record.getGoodsCount() != null) {
            sql.SET("goods_count = #{record.goodsCount,jdbcType=INTEGER}");
        }
        
        if (record.getRefundOrder() != null) {
            sql.SET("refund_order = #{record.refundOrder,jdbcType=VARCHAR}");
        }
        
        if (record.getReturnTotalPrice() != null) {
            sql.SET("return_total_price = #{record.returnTotalPrice,jdbcType=DECIMAL}");
        }
        
        if (record.getRefundPrice() != null) {
            sql.SET("refund_price = #{record.refundPrice,jdbcType=DECIMAL}");
        }
        
        if (record.getRefundGold() != null) {
            sql.SET("refund_gold = #{record.refundGold,jdbcType=INTEGER}");
        }
        
        if (record.getRefundRemark() != null) {
            sql.SET("refund_remark = #{record.refundRemark,jdbcType=VARCHAR}");
        }
        
        if (record.getRefundStatus() != null) {
            sql.SET("refund_status = #{record.refundStatus,jdbcType=INTEGER}");
        }
        
        if (record.getRefundFailReason() != null) {
            sql.SET("refund_fail_reason = #{record.refundFailReason,jdbcType=VARCHAR}");
        }
        
        if (record.getCreateTime() != null) {
            sql.SET("create_time = #{record.createTime,jdbcType=TIMESTAMP}");
        }
        
        if (record.getUpdateTime() != null) {
            sql.SET("update_time = #{record.updateTime,jdbcType=TIMESTAMP}");
        }
        
        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}");
        }
        
        if (record.getExt4() != null) {
            sql.SET("ext_4 = #{record.ext4,jdbcType=VARCHAR}");
        }
        
        if (record.getExt5() != null) {
            sql.SET("ext_5 = #{record.ext5,jdbcType=VARCHAR}");
        }
        
        if (record.getExt6() != null) {
            sql.SET("ext_6 = #{record.ext6,jdbcType=VARCHAR}");
        }
        
        applyWhere(sql, example, true);
        return sql.toString();
    }

    public String updateByExample(Map<String, Object> parameter) {
        SQL sql = new SQL();
        sql.UPDATE("high_order_refund");
        
        sql.SET("id = #{record.id,jdbcType=BIGINT}");
        sql.SET("order_id = #{record.orderId,jdbcType=BIGINT}");
        sql.SET("order_no = #{record.orderNo,jdbcType=VARCHAR}");
        sql.SET("order_child_id = #{record.orderChildId,jdbcType=BIGINT}");
        sql.SET("order_child_no = #{record.orderChildNo,jdbcType=VARCHAR}");
        sql.SET("mem_id = #{record.memId,jdbcType=BIGINT}");
        sql.SET("mem_name = #{record.memName,jdbcType=VARCHAR}");
        sql.SET("mem_phone = #{record.memPhone,jdbcType=VARCHAR}");
        sql.SET("goods_type = #{record.goodsType,jdbcType=INTEGER}");
        sql.SET("goods_id = #{record.goodsId,jdbcType=BIGINT}");
        sql.SET("goods_name = #{record.goodsName,jdbcType=VARCHAR}");
        sql.SET("goods_desc = #{record.goodsDesc,jdbcType=VARCHAR}");
        sql.SET("goods_img = #{record.goodsImg,jdbcType=VARCHAR}");
        sql.SET("goods_spec_name = #{record.goodsSpecName,jdbcType=VARCHAR}");
        sql.SET("goods_count = #{record.goodsCount,jdbcType=INTEGER}");
        sql.SET("refund_order = #{record.refundOrder,jdbcType=VARCHAR}");
        sql.SET("return_total_price = #{record.returnTotalPrice,jdbcType=DECIMAL}");
        sql.SET("refund_price = #{record.refundPrice,jdbcType=DECIMAL}");
        sql.SET("refund_gold = #{record.refundGold,jdbcType=INTEGER}");
        sql.SET("refund_remark = #{record.refundRemark,jdbcType=VARCHAR}");
        sql.SET("refund_status = #{record.refundStatus,jdbcType=INTEGER}");
        sql.SET("refund_fail_reason = #{record.refundFailReason,jdbcType=VARCHAR}");
        sql.SET("create_time = #{record.createTime,jdbcType=TIMESTAMP}");
        sql.SET("update_time = #{record.updateTime,jdbcType=TIMESTAMP}");
        sql.SET("ext_1 = #{record.ext1,jdbcType=VARCHAR}");
        sql.SET("ext_2 = #{record.ext2,jdbcType=VARCHAR}");
        sql.SET("ext_3 = #{record.ext3,jdbcType=VARCHAR}");
        sql.SET("ext_4 = #{record.ext4,jdbcType=VARCHAR}");
        sql.SET("ext_5 = #{record.ext5,jdbcType=VARCHAR}");
        sql.SET("ext_6 = #{record.ext6,jdbcType=VARCHAR}");
        
        HighOrderRefundExample example = (HighOrderRefundExample) parameter.get("example");
        applyWhere(sql, example, true);
        return sql.toString();
    }

    public String updateByPrimaryKeySelective(HighOrderRefund record) {
        SQL sql = new SQL();
        sql.UPDATE("high_order_refund");
        
        if (record.getOrderId() != null) {
            sql.SET("order_id = #{orderId,jdbcType=BIGINT}");
        }
        
        if (record.getOrderNo() != null) {
            sql.SET("order_no = #{orderNo,jdbcType=VARCHAR}");
        }
        
        if (record.getOrderChildId() != null) {
            sql.SET("order_child_id = #{orderChildId,jdbcType=BIGINT}");
        }
        
        if (record.getOrderChildNo() != null) {
            sql.SET("order_child_no = #{orderChildNo,jdbcType=VARCHAR}");
        }
        
        if (record.getMemId() != null) {
            sql.SET("mem_id = #{memId,jdbcType=BIGINT}");
        }
        
        if (record.getMemName() != null) {
            sql.SET("mem_name = #{memName,jdbcType=VARCHAR}");
        }
        
        if (record.getMemPhone() != null) {
            sql.SET("mem_phone = #{memPhone,jdbcType=VARCHAR}");
        }
        
        if (record.getGoodsType() != null) {
            sql.SET("goods_type = #{goodsType,jdbcType=INTEGER}");
        }
        
        if (record.getGoodsId() != null) {
            sql.SET("goods_id = #{goodsId,jdbcType=BIGINT}");
        }
        
        if (record.getGoodsName() != null) {
            sql.SET("goods_name = #{goodsName,jdbcType=VARCHAR}");
        }
        
        if (record.getGoodsDesc() != null) {
            sql.SET("goods_desc = #{goodsDesc,jdbcType=VARCHAR}");
        }
        
        if (record.getGoodsImg() != null) {
            sql.SET("goods_img = #{goodsImg,jdbcType=VARCHAR}");
        }
        
        if (record.getGoodsSpecName() != null) {
            sql.SET("goods_spec_name = #{goodsSpecName,jdbcType=VARCHAR}");
        }
        
        if (record.getGoodsCount() != null) {
            sql.SET("goods_count = #{goodsCount,jdbcType=INTEGER}");
        }
        
        if (record.getRefundOrder() != null) {
            sql.SET("refund_order = #{refundOrder,jdbcType=VARCHAR}");
        }
        
        if (record.getReturnTotalPrice() != null) {
            sql.SET("return_total_price = #{returnTotalPrice,jdbcType=DECIMAL}");
        }
        
        if (record.getRefundPrice() != null) {
            sql.SET("refund_price = #{refundPrice,jdbcType=DECIMAL}");
        }
        
        if (record.getRefundGold() != null) {
            sql.SET("refund_gold = #{refundGold,jdbcType=INTEGER}");
        }
        
        if (record.getRefundRemark() != null) {
            sql.SET("refund_remark = #{refundRemark,jdbcType=VARCHAR}");
        }
        
        if (record.getRefundStatus() != null) {
            sql.SET("refund_status = #{refundStatus,jdbcType=INTEGER}");
        }
        
        if (record.getRefundFailReason() != null) {
            sql.SET("refund_fail_reason = #{refundFailReason,jdbcType=VARCHAR}");
        }
        
        if (record.getCreateTime() != null) {
            sql.SET("create_time = #{createTime,jdbcType=TIMESTAMP}");
        }
        
        if (record.getUpdateTime() != null) {
            sql.SET("update_time = #{updateTime,jdbcType=TIMESTAMP}");
        }
        
        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}");
        }
        
        if (record.getExt4() != null) {
            sql.SET("ext_4 = #{ext4,jdbcType=VARCHAR}");
        }
        
        if (record.getExt5() != null) {
            sql.SET("ext_5 = #{ext5,jdbcType=VARCHAR}");
        }
        
        if (record.getExt6() != null) {
            sql.SET("ext_6 = #{ext6,jdbcType=VARCHAR}");
        }
        
        sql.WHERE("id = #{id,jdbcType=BIGINT}");
        
        return sql.toString();
    }

    protected void applyWhere(SQL sql, HighOrderRefundExample 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());
        }
    }
}