package dal

import (
	"encoding/json"
	"fmt"
	"testing"

	"xiaoniaokuaiyan.com/xiaoniao/entity"
)

func TestList(t *testing.T) {
	dataList := []entity.OrderDB{}
	strSql := "select * from t_order"
	orderStr := " order by id desc"
	whereStr := ""
	wv := []interface{}{}
	pinfo := Pager{
		PageSize:  15,
		PageIndex: 1,
	}
	result, err := List(&dataList, "t_order", strSql, orderStr, whereStr, wv, pinfo)
	if err != nil {
		t.Fatal(err)
	}
	buf, _ := json.Marshal(result)
	fmt.Println(string(buf))
}

func TestJsonOrder(t *testing.T) {
	jsonStr := `[{"Id":"BJ16051114094402806","Name":"liuguiqi","Gender":1,"Age":27,"Address":"望京南","DetailAddress":"北京嘉美中心写字楼1211","VisitDate":"2016-05-06","VisitTimeRange":"10:30-11:30","Source":"web","Status":1,"WorkFee":0,"Payment":162.9,"ActualPayment":null,"PaymentTime":null,"PayType":null,"CustomManagerId":null,"NourseId":null,"IsOthers":0,"IsMerged":0,"BloodCodes":null,"AssayTime":null,"CustomId":"1","CustomMobile":"","Mobile":"18310412106","Remark":null,"UpdatedAt":"2016-05-11 14:09:46","CreatedAt":"2016-05-11 14:09:44","ProductIds":null,"ItemIds":null,"Coupons":null},{"Id":"BJ16051113541605448","Name":"liuguiqi","Gender":1,"Age":27,"Address":"望京南","DetailAddress":"北京嘉美中心写字楼1211","VisitDate":"2016-05-06","VisitTimeRange":"10:30-11:30","Source":"web","Status":1,"WorkFee":0,"Payment":null,"ActualPayment":null,"PaymentTime":null,"PayType":null,"CustomManagerId":null,"NourseId":null,"IsOthers":0,"IsMerged":0,"BloodCodes":null,"AssayTime":null,"CustomId":"1","CustomMobile":"18310412106","Mobile":"18310412106","Remark":"nothing remark","UpdatedAt":"2016-05-13 10:43:34","CreatedAt":"2016-05-11 13:54:16","ProductIds":null,"ItemIds":null,"Coupons":null},{"Id":"BJ16050415050900582","Name":"liuguiqi","Gender":1,"Age":27,"Address":"望京南","DetailAddress":"北京嘉美中心写字楼1211","VisitDate":"2016-05-06","VisitTimeRange":"10:30-11:30","Source":"web","Status":1,"WorkFee":0,"Payment":92.4,"ActualPayment":null,"PaymentTime":"2016-05-11 11:55:08","PayType":0,"CustomManagerId":null,"NourseId":null,"IsOthers":0,"IsMerged":0,"BloodCodes":null,"AssayTime":null,"CustomId":"1","CustomMobile":"18310412106","Mobile":"18310412106","Remark":"test remark","UpdatedAt":"2016-05-12 15:42:32","CreatedAt":"2016-05-04 15:05:10","ProductIds":null,"ItemIds":null,"Coupons":null}]`
	dataList := []entity.Order{}
	err := json.Unmarshal([]byte(jsonStr), &dataList)
	if err != nil {
		t.Fatal(err)
	}
	fmt.Println(dataList)
}

func TestGetDeliverOrderList(t *testing.T) {
	r, err := DefaultDeliverUserDal.GetOrderList("onNpDwxvv-JO3StYjyJaIFHGYMXA", 2, 1, 10) // onNpDwyIAu5ViXz-zLrnYAFaSsuo
	if err != nil {
		t.Fatal(err)
	}
	buf, _ := json.Marshal(r)
	fmt.Println(string(buf))
}