package com.elab.core.dao.params;

import org.junit.Test;
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
import org.springframework.jdbc.core.namedparam.SqlParameterSource;

import java.util.HashMap;
import java.util.Map;

/**
 * 测试用例
 *
 * @author : liukx
 * @create : 2018/7/6 14:29
 * @email : liukx@elab-plus.com
 */
public class NamedParameterUtils2Test {

    @Test
    public void parseSqlStatement() {
    }

    @Test
    public void substituteNamedParameters() {
    }

    @Test
    public void replaceDynamic() {
    }

    @Test
    public void validFirstCheckSql() {
    }

    @Test
    public void buildValueArray() {
    }

    @Test
    public void buildSqlTypeArray() {
    }

    @Test
    public void buildSqlParameterList() {
    }

    @Test
    public void parseSqlStatementIntoString() {
        String sql = "select count(1) count from account_adviser where status = 1 and mobile = :mobile";
        String s = NamedParameterUtils2.parseSqlStatementIntoString(sql);
        System.out.println(s);
    }

    @Test
    public void substituteNamedParameters1() {
        String sql = "update customer_source s inner join recommend r on s.mobile =r.mobile and s.house_id = r.house_id\n" +
                "        set channel=:channel,\n" +
                "        ref_mobile=:refMobile\n" +
                "        where r.customer_id = :customerId and s.house_id = :houseId;";

//        String sql = "select id,house_id,worker_name,mobile,worker_pwd,sex,head,brief,online_status,video_online_status,\n" +
//                "        wxno,province,city, district,token,status,created,updated,creator,updator,\n" +
//                "        agent,video_adviser,im_adviser,relation_id\n" +
//                "        from account_adviser where status = 1 and mobile = :mobile and worker_pwd = :workerPwd";
        Map<String, Object> map = new HashMap<>();
        map.put("houseId", "10064");
        map.put("refMobile", "17602135201");
        map.put("channel", "个人-17602135201");
        map.put("customerId", "26928");
        SqlParameterSource sqlParameterSource = new MapSqlParameterSource(map);
        String s = NamedParameterUtils2.substituteNamedParameters(sql, sqlParameterSource);
        System.out.println(s);


    }

    @Test
    public void buildValueArray1() {
    }
}