738 lines
22 KiB
Go
738 lines
22 KiB
Go
package jdshopapi
|
||
|
||
import (
|
||
"bytes"
|
||
"crypto/aes"
|
||
"crypto/cipher"
|
||
"encoding/base64"
|
||
"fmt"
|
||
"math"
|
||
"sort"
|
||
"testing"
|
||
|
||
"git.rosy.net.cn/baseapi/utils"
|
||
)
|
||
|
||
func TestCreateShopCategory(t *testing.T) {
|
||
var CreateShopCategoryParams = []*CreateShopCategoryParam{
|
||
&CreateShopCategoryParam{
|
||
HomeShow: "0",
|
||
ID: "1",
|
||
Open: "",
|
||
OrderNo: "0",
|
||
ParentID: "",
|
||
Title: "测试1",
|
||
Type: "3",
|
||
},
|
||
}
|
||
result, _ := api.CreateShopCategory(CreateShopCategoryParams)
|
||
fmt.Println(result)
|
||
}
|
||
|
||
func TestUpdateStoreStatus(t *testing.T) {
|
||
err := api.UpdateStoreStatus(24332466, 1)
|
||
if err != nil {
|
||
t.Fatal(err)
|
||
}
|
||
}
|
||
|
||
func TestNewInfoList(t *testing.T) {
|
||
result, err := api.NewInfoList(1)
|
||
if err != nil {
|
||
t.Fatal(err)
|
||
}
|
||
t.Log(utils.Format4Output(result, false))
|
||
}
|
||
|
||
func Test11(t *testing.T) {
|
||
change := func(s ...string) {
|
||
s[0] = "Go"
|
||
s = append(s, "playground")
|
||
fmt.Println(s)
|
||
}
|
||
|
||
welcome := []string{"hello", "world"}
|
||
change(welcome...)
|
||
fmt.Println(welcome)
|
||
|
||
}
|
||
|
||
func TestAllOrders(t *testing.T) {
|
||
result, err := api.AllOrders(&AllOrdersParam{
|
||
Current: 1,
|
||
PageSize: 1,
|
||
OrderID: "118793082128",
|
||
})
|
||
if err != nil {
|
||
t.Fatal(err)
|
||
}
|
||
t.Log(utils.Format4Output(result, false))
|
||
}
|
||
|
||
func TestOrderDetail(t *testing.T) {
|
||
result, err := api.OrderDetail("125138699851")
|
||
if err != nil {
|
||
t.Fatal(err)
|
||
}
|
||
t.Log(utils.Format4Output(result, false))
|
||
}
|
||
|
||
func TestPhoneSensltiveInfo(t *testing.T) {
|
||
result, err := api.PhoneSensltiveInfo("124396047880", "10b1707dc87755373d488a7a4f422f7d")
|
||
if err != nil {
|
||
t.Fatal(err)
|
||
}
|
||
t.Log(utils.Format4Output(result, false))
|
||
}
|
||
|
||
func TestUpdateWaybill(t *testing.T) {
|
||
err := api.UpdateWaybill("123076499052", "1274", "88328977356545 ")
|
||
if err != nil {
|
||
t.Fatal(err)
|
||
}
|
||
// t.Log(utils.Format4Output(result, false))
|
||
}
|
||
|
||
func TestTryGetCookie(t *testing.T) {
|
||
result, err := api.TryGetCookie()
|
||
if err != nil {
|
||
t.Fatal(err)
|
||
}
|
||
t.Log(utils.Format4Output(result, false))
|
||
}
|
||
|
||
func TestAAADS(t *testing.T) {
|
||
str := "AASWvkdk5a60bjm3lFqaoCyzBFIjrHQjoKSY+LN5VcswOzDkqjbjxVyK1Psdqcj3ci0+4I9v3evrtrJHLuUSo3eEfT3+psX6DF45CILeq0VbKxwxkE+AS1WTxr9RTHqaM3g="
|
||
data, _ := base64.StdEncoding.DecodeString(str)
|
||
data2, _ := base64.StdEncoding.DecodeString("XsGNdyDyDHnR79iKU6d5LTSJYaQyWAEssDoD7VM5Kks=")
|
||
b := bytes.NewBuffer(data)
|
||
b.Next(18)
|
||
iv := make([]byte, 16)
|
||
b.Read(iv)
|
||
main := make([]byte, len(data)-18-16)
|
||
b.Read(main)
|
||
decryptedData, err := utils.AESCBCDecpryt(main, data2[:16], iv)
|
||
// decryptedData, err := Decrypt(main, data2[:16], iv)
|
||
if err != nil {
|
||
t.Fatal(err)
|
||
}
|
||
fmt.Println("data", string(decryptedData))
|
||
}
|
||
|
||
func Decrypt(decryptBytes, key, iv []byte) ([]byte, error) {
|
||
block, err := aes.NewCipher(key)
|
||
if err != nil {
|
||
return nil, err
|
||
}
|
||
blockMode := cipher.NewCBCDecrypter(block, iv)
|
||
blockMode.CryptBlocks(decryptBytes, decryptBytes)
|
||
return PKCS5UnPadding(decryptBytes), nil
|
||
}
|
||
|
||
func PKCS5UnPadding(decrypted []byte) []byte {
|
||
length := len(decrypted)
|
||
unPadding := int(decrypted[length-1])
|
||
return decrypted[:(length - unPadding)]
|
||
}
|
||
|
||
func TestShopDetail(t *testing.T) {
|
||
result, err := api.ShopDetail(24562992)
|
||
if err != nil {
|
||
t.Fatal(err)
|
||
}
|
||
t.Log(utils.Format4Output(result, false))
|
||
}
|
||
|
||
func TestSubmitBasic(t *testing.T) {
|
||
result, err := api.SubmitBasic(&UpdateBasicParam{
|
||
StoreName: "京西菜市石犀市场生鲜店",
|
||
CategoryID2: 62,
|
||
Coordinate: "30.692941,103.858781",
|
||
BussinessBeginTime: "08:30",
|
||
BussinessEndTime: "20:00",
|
||
ImgURL: "jfs/t1/141918/10/14803/148865/5fb4e8cbE95a606cb/08a8dc277eb97a16.png",
|
||
StorePhone: "13706546496",
|
||
AddName: "四川成都市温江区@!温江区锦泉街116号(优取舍)",
|
||
// AddCode1: 22,
|
||
// AddCode2: 1930,
|
||
AddCode3: 49315,
|
||
CategoryID1: 34,
|
||
QualificationRequests: []*QualificationRequests{
|
||
&QualificationRequests{
|
||
QualificationID: 41,
|
||
QualificationName: "营业执照",
|
||
QualificationNo: "11111",
|
||
QualificationURL: "jfs/t1/148622/37/14846/10266/5fb4e3e2Ef2f61870/a7cfba9c1513d95e.png",
|
||
StartTime: "2020-11-04 00:00:00",
|
||
EndingTime: "2020-11-06 23:59:59",
|
||
Time: []string{"2020-11-04 00:00:00", "2020-11-06 23:59:59"},
|
||
},
|
||
},
|
||
})
|
||
if err != nil {
|
||
t.Fatal(err)
|
||
}
|
||
t.Log(utils.Format4Output(result, false))
|
||
}
|
||
|
||
func TestUpdateBasic(t *testing.T) {
|
||
shop, _ := api.ShopList(1)
|
||
for _, v := range shop.List {
|
||
detail, _ := api.ShopDetail(v.StoreID)
|
||
api.UpdateBasic(&UpdateBasicParam{
|
||
StoreID: detail.StoreID,
|
||
StoreName: detail.StoreName,
|
||
CategoryID2: 62,
|
||
Coordinate: detail.Coordinate,
|
||
BussinessBeginTime: detail.BussinessBeginTime,
|
||
BussinessEndTime: detail.BussinessEndTime,
|
||
ImgURL: detail.ImgURL,
|
||
StorePhone: detail.StorePhone,
|
||
AddName: utils.LimitUTF8StringLen(detail.AddName, 100),
|
||
AddCode1: detail.AddCode1,
|
||
AddCode2: detail.AddCode2,
|
||
AddCode3: detail.AddCode3,
|
||
CategoryID1: 34,
|
||
QualificationRequests: []*QualificationRequests{
|
||
&QualificationRequests{
|
||
QualificationID: 41,
|
||
QualificationName: "营业执照",
|
||
QualificationNo: "91510106MA62QYUK9X",
|
||
QualificationURL: "jfs/t1/140863/13/17145/275844/5fc9ac7aE9a5f8d68/f9d459176d463cb5.jpg",
|
||
StartTime: "2017-03-01 00:00:00",
|
||
EndingTime: "2027-03-01 00:00:00",
|
||
Time: []string{"2017-03-01 00:00:00", "2027-03-01 00:00:00"},
|
||
},
|
||
},
|
||
})
|
||
}
|
||
// t.Log(utils.Format4Output(result, false))
|
||
}
|
||
|
||
func TestUpdateExpand(t *testing.T) {
|
||
err := api.UpdateExpand(24563694)
|
||
if err != nil {
|
||
t.Fatal(err)
|
||
}
|
||
// t.Log(utils.Format4Output(result, false))
|
||
}
|
||
|
||
func TestCreateGisFence(t *testing.T) {
|
||
err := api.CreateGisFence(1000069001, "3")
|
||
if err != nil {
|
||
t.Fatal(err)
|
||
}
|
||
// t.Log(utils.Format4Output(result, false))
|
||
}
|
||
|
||
func TestUpdateDeliveryPromise(t *testing.T) {
|
||
err := api.UpdateDeliveryPromise("09:00", "20:00", 1000070127)
|
||
if err != nil {
|
||
t.Fatal(err)
|
||
}
|
||
// t.Log(utils.Format4Output(result, false))
|
||
}
|
||
|
||
func TestUploadImageNew(t *testing.T) {
|
||
i := []int{103075, 100129, 100117, 102726, 666677, 666997, 100156, 666987, 100118, 103113, 100144, 101039, 100153, 100881, 667142, 102630, 101897, 102613, 666799, 103177, 100766, 103035, 103090, 102167, 100326, 100454, 102416, 102789, 103037, 101176, 102713, 667057, 102482, 102938, 100920, 102614, 102624, 102675, 102902, 102956, 666748, 666876, 100115, 100141, 100524, 100670, 102671, 102987, 103022, 100206, 100274, 101780, 102138, 102206, 102255, 102785, 102951, 102996, 103111, 667058, 100610, 101099, 102293, 102819, 102824, 102857, 102865, 666751, 100654, 101111, 101945, 101960, 102795, 667093, 100121, 100193, 100230, 102481, 102772, 102969, 103063, 103094, 100126, 100175, 100210, 100270, 102706, 102930, 103116, 666672, 666712, 101840, 102241, 102595, 102686, 102736, 102973, 666735, 666790, 666792, 100205, 100453, 100905, 102147, 102320, 102767, 102925, 102937, 102962, 102994, 103002, 100409, 101956, 102353, 102475, 102794, 102852, 102921, 102928, 102980, 103183, 666669, 666733, 666861, 100204, 100225, 100476, 100699, 102354, 102915, 102923, 102929, 102952, 103069, 100215, 100279, 100458, 100517, 100664, 101013, 101666, 103093, 103191, 103425, 666996, 100132, 100278, 100328, 101032, 102022, 102355, 102364, 102436, 102763, 102776, 102893, 102924, 102966, 666779, 666906, 667110, 100290, 100455, 100471, 101875, 102126, 102479, 103103, 103199, 666767, 666992, 103003, 103088, 666667, 666711, 666930, 101979, 102046, 103201, 666819, 666879, 100116, 100157, 100712, 101061, 101736, 101755, 102561, 102960, 103193, 666905, 666993, 100299, 100334, 100987, 101112, 102264, 102278, 102704, 102752, 102771, 102997, 666828, 666863, 100501, 100681, 101012, 102002, 666746, 666853, 666898, 666985, 667109, 100336, 100543, 102426, 102933, 103194, 100366, 101942, 102186, 102533, 103151, 103200, 666729, 666820, 666854, 666954, 667033, 667064, 100361, 101750, 102374, 102977, 102991, 103015, 103170, 666864, 666890, 666933, 100840, 101983, 102648, 102932, 103018, 103050, 103065, 103171, 666932, 667091, 100002, 100140, 100150, 100828, 100853, 100867, 101000, 102488, 102782, 102807, 102995, 103029, 100124, 102172, 102637, 102705, 102934, 103098, 666855, 667014, 667076, 100714, 102480, 102519, 102594, 102600, 103089, 103189, 667113, 667136, 100134, 100451, 101078, 102047, 103033, 103085, 103127, 666739, 666784, 666891, 666975, 100167, 100782, 101042, 102424, 102723, 102741, 102793, 102883, 102888, 666852, 667003, 100433, 102742, 102836, 103112, 666740, 666835, 666887, 667007, 100130, 100487, 100546, 100982, 102181, 666782, 666961, 666973, 667005, 667038, 667075, 100145, 100369, 100444, 100720, 100741, 101028, 102853, 102953, 103057, 103082, 100032, 100041, 100396, 100837, 102371, 102473, 102718, 102998, 103361, 103408, 666788, 666800, 666948, 666980, 667001, 667006, 100650, 102498, 102676, 666812, 666826, 666929, 666955, 667028, 667094, 667125, 100529, 102720, 102749, 102882, 103032, 666775, 666803, 666927, 666944, 100065, 100162, 100296, 103036, 103055, 103184, 666707, 666839, 666964, 667067, 100470, 102068, 102358, 102733, 103181, 100015, 100549, 100849, 101732, 101763, 102074, 102780, 102821, 102859, 103083, 103118, 103416, 666771, 666802, 102562, 102856, 103160, 666811, 666818, 666850, 666984, 666988, 667071, 100267, 100309, 101916, 103051, 103165, 666783, 666889, 666900, 101008, 102300, 102750, 102958, 103161, 666756, 666786, 666836, 666840, 666880, 666977, 666983, 100123, 100165, 100351, 100548, 100767, 102670, 102711, 102876, 103009, 666823, 666834, 666917, 667051, 100217, 100883, 100971, 102483, 102981, 666793, 666858, 666940, 666945, 667112, 667133, 100935, 101031, 103179, 100024, 100190, 102955, 103143, 103176, 103198, 666825, 666869, 667135, 103074, 100221, 100325, 100463, 100477, 100600, 100661, 100827, 100945, 100946, 101712, 101722, 101815, 101834, 101887, 101896, 101935, 101948, 101997, 102012, 102016, 102023, 102063, 102092, 102180, 102245, 102267, 102275, 102280, 102383, 102405, 102411, 102443, 102444, 102531, 102557, 102652, 102661, 102691, 102721, 102735, 102740, 102759, 102808, 102815, 102858, 102896, 102901, 102906, 102911, 102926, 102946, 102954, 102971, 102974, 102976, 103001, 103008, 103028, 103095, 103106, 103115, 103119, 103145, 103168, 103178, 103188, 103414, 103433, 666705, 666738, 666745, 666747, 666772, 666776, 666785, 666791, 666821, 666822, 666873, 666885, 666888, 666919, 666942, 667010, 667055, 667059, 667117, 667157, 667158, 667176, 667145, 100022, 667234, 667206, 667273, 102788, 102150, 101097, 102379, 100943, 666916, 100273, 666884, 667114, 667205, 667202, 667370, 667366, 667365, 667359, 667356, 667352, 667351, 667349, 667339, 667338, 667336, 667335, 667334, 667332, 667331, 667329, 667324, 667321, 667315, 667312, 667310, 667309, 667308, 667307, 667305, 667304, 667303, 667302, 667296, 667297, 667294, 667292, 667291, 667288, 667284, 667280, 667278, 667277, 667266, 667264, 667263, 667257, 667245, 667242, 667240, 667236, 667223, 667220, 667211, 667208, 667204, 667201, 667200, 667177, 667166, 667159, 667155, 667154, 667147, 667139, 667134, 667129, 667128, 667080, 667029, 667016, 666907, 666862, 666842, 666838, 666770, 666765, 666715, 103136, 100601, 667333, 667381, 667363, 667340, 667386, 667423, 667040, 667419, 667395, 667388, 667443, 667355, 667394, 667390, 667420, 667364, 667389, 667383, 667361, 103182, 667414, 667476, 667465, 667481, 667510, 102377, 101088, 102642, 667469, 666921}
|
||
fmt.Println(len(i))
|
||
}
|
||
|
||
//给定一个包含正整数、加(+)、减(-)、乘(*)、除(/)的算数表达式(括号除外),计算其结果。
|
||
//表达式仅包含非负整数,+, - ,*,/ 四种运算符和空格 。 整数除法仅保留整数部分。
|
||
func calculate(s string) int {
|
||
return 1
|
||
}
|
||
|
||
//输入一个矩阵,按照从外向里以顺时针的顺序依次打印出每一个数字。
|
||
func spiralOrder(matrix [][]int) []int {
|
||
var result []int
|
||
if len(matrix) == 0 {
|
||
return result
|
||
} else {
|
||
if len(matrix[0]) == 0 {
|
||
return result
|
||
}
|
||
}
|
||
l, h := len(matrix[0]), len(matrix)
|
||
left, right, top, bottom := 0, l-1, 0, h-1
|
||
lmax, tmax := 0, 0
|
||
if l%2 == 0 {
|
||
lmax = l / 2
|
||
} else {
|
||
lmax = l/2 + 1
|
||
}
|
||
if h%2 == 0 {
|
||
tmax = l / 2
|
||
} else {
|
||
tmax = l/2 + 1
|
||
}
|
||
|
||
for left <= lmax && top+1 <= tmax {
|
||
for left1 := left; left1 <= right; left1++ {
|
||
if len(result) >= l*h {
|
||
break
|
||
}
|
||
result = append(result, matrix[top][left1])
|
||
}
|
||
if h > 1 {
|
||
for top1 := top + 1; top1 <= bottom; top1++ {
|
||
if len(result) >= l*h {
|
||
break
|
||
}
|
||
result = append(result, matrix[top1][right])
|
||
}
|
||
if right > 0 {
|
||
for right1 := right - 1; right1 >= left; right1-- {
|
||
if len(result) >= l*h {
|
||
break
|
||
}
|
||
result = append(result, matrix[bottom][right1])
|
||
}
|
||
}
|
||
if bottom > 0 {
|
||
for bottom1 := bottom - 1; bottom1 >= top+1; bottom1-- {
|
||
if len(result) >= l*h {
|
||
break
|
||
}
|
||
result = append(result, matrix[bottom1][left])
|
||
}
|
||
}
|
||
}
|
||
left++
|
||
top++
|
||
right--
|
||
bottom--
|
||
}
|
||
return result
|
||
}
|
||
|
||
func addToArrayForm(A []int, K int) (a []int) {
|
||
B := []int{}
|
||
lengthK := 0
|
||
for i := 10; ; i = i * 10 {
|
||
if K/i == 0 {
|
||
lengthK++
|
||
break
|
||
}
|
||
lengthK++
|
||
}
|
||
for i := lengthK; i > 0; i-- {
|
||
if i == lengthK {
|
||
B = append(B, K/int(math.Pow10(i-1)))
|
||
} else if i == 1 {
|
||
gw := K
|
||
for j := lengthK; j > 1; j-- {
|
||
gw = gw % int(math.Pow10(j-1))
|
||
}
|
||
B = append(B, gw)
|
||
} else {
|
||
qtw := K
|
||
for j := lengthK; j > 1; j-- {
|
||
if j == i {
|
||
qtw = qtw / int(math.Pow10(j-1))
|
||
break
|
||
} else {
|
||
qtw = qtw % int(math.Pow10(j-1))
|
||
}
|
||
}
|
||
B = append(B, qtw)
|
||
}
|
||
}
|
||
flag := false
|
||
in := 0
|
||
for k := len(A) - 1; k >= 0; {
|
||
if flag {
|
||
break
|
||
}
|
||
for k1 := len(B) - 1; k1 >= 0; {
|
||
if A[k]+B[k1]+in < 10 {
|
||
if in == 0 {
|
||
a = append(a, A[k]+B[k1])
|
||
} else {
|
||
a = append(a, A[k]+B[k1]+in)
|
||
}
|
||
in = 0
|
||
} else {
|
||
if in == 0 {
|
||
a = append(a, (A[k]+B[k1])%10)
|
||
} else {
|
||
a = append(a, (A[k]+B[k1]+in)%10)
|
||
}
|
||
in = 0
|
||
in++
|
||
}
|
||
k--
|
||
k1--
|
||
if k == -1 && k1 == -1 && in != 0 {
|
||
a = append(a, 1)
|
||
}
|
||
if k < 0 {
|
||
in2 := 0
|
||
for i := k1; i >= 0; i-- {
|
||
if B[i]+in+in2 < 10 {
|
||
if in2 == 0 {
|
||
a = append(a, B[i]+in)
|
||
} else {
|
||
a = append(a, B[i]+in2+in)
|
||
}
|
||
in = 0
|
||
in2 = 0
|
||
} else {
|
||
if in2 == 0 {
|
||
a = append(a, (B[i]+in)%10)
|
||
} else {
|
||
a = append(a, (B[i]+in+in2)%10)
|
||
}
|
||
in = 0
|
||
in2 = 0
|
||
in2++
|
||
}
|
||
if i == 0 && in2 != 0 {
|
||
a = append(a, 1)
|
||
}
|
||
}
|
||
flag = true
|
||
break
|
||
}
|
||
if k1 < 0 {
|
||
in2 := 0
|
||
for i := k; i >= 0; i-- {
|
||
if A[i]+in+in2 < 10 {
|
||
if in2 == 0 {
|
||
a = append(a, A[i]+in)
|
||
} else {
|
||
a = append(a, A[i]+in2+in)
|
||
}
|
||
in = 0
|
||
in2 = 0
|
||
} else {
|
||
if in2 == 0 {
|
||
a = append(a, (A[i]+in)%10)
|
||
} else {
|
||
a = append(a, (A[i]+in+in2)%10)
|
||
}
|
||
in = 0
|
||
in2 = 0
|
||
in2++
|
||
}
|
||
if i == 0 && in2 != 0 {
|
||
a = append(a, 1)
|
||
}
|
||
}
|
||
flag = true
|
||
break
|
||
}
|
||
}
|
||
}
|
||
for i := 0; i < len(a)/2; i++ {
|
||
temp := a[i]
|
||
a[i] = a[len(a)-i-1]
|
||
a[len(a)-i-1] = temp
|
||
}
|
||
return a
|
||
}
|
||
|
||
func maximumProduct(nums []int) int {
|
||
sort.Ints(nums)
|
||
n := len(nums)
|
||
fmt.Println(nums)
|
||
return max(nums[0]*nums[1]*nums[n-1], nums[n-3]*nums[n-2]*nums[n-1])
|
||
}
|
||
|
||
func max(a, b int) int {
|
||
if a > b {
|
||
return a
|
||
}
|
||
return b
|
||
}
|
||
|
||
func accountsMerge(accounts [][]string) (ans [][]string) {
|
||
emailToIndex := map[string]int{}
|
||
emailToName := map[string]string{}
|
||
for _, account := range accounts {
|
||
name := account[0]
|
||
for _, email := range account[1:] {
|
||
if _, has := emailToIndex[email]; !has {
|
||
emailToIndex[email] = len(emailToIndex)
|
||
emailToName[email] = name
|
||
}
|
||
}
|
||
}
|
||
fmt.Println(emailToIndex)
|
||
fmt.Println()
|
||
|
||
fmt.Println(emailToName)
|
||
parent := make([]int, len(emailToIndex))
|
||
for i := range parent {
|
||
parent[i] = i
|
||
}
|
||
var find func(int) int
|
||
find = func(x int) int {
|
||
if parent[x] != x {
|
||
parent[x] = find(parent[x])
|
||
}
|
||
return parent[x]
|
||
}
|
||
union := func(from, to int) {
|
||
parent[find(from)] = find(to)
|
||
}
|
||
|
||
for _, account := range accounts {
|
||
firstIndex := emailToIndex[account[1]]
|
||
for _, email := range account[2:] {
|
||
union(emailToIndex[email], firstIndex)
|
||
}
|
||
}
|
||
|
||
fmt.Println(parent)
|
||
fmt.Println()
|
||
fmt.Println(accounts)
|
||
|
||
indexToEmails := map[int][]string{}
|
||
for email, index := range emailToIndex {
|
||
index = find(index)
|
||
indexToEmails[index] = append(indexToEmails[index], email)
|
||
}
|
||
fmt.Println(indexToEmails)
|
||
|
||
for _, emails := range indexToEmails {
|
||
sort.Strings(emails)
|
||
account := append([]string{emailToName[emails[0]]}, emails...)
|
||
ans = append(ans, account)
|
||
}
|
||
return
|
||
}
|
||
|
||
func findRedundantConnection(edges [][]int) []int {
|
||
parent := make([]int, len(edges)+1)
|
||
for i := range parent {
|
||
parent[i] = i
|
||
}
|
||
fmt.Println("edges ", edges)
|
||
fmt.Println("parent ", parent)
|
||
var find func(int) int
|
||
find = func(x int) int {
|
||
if parent[x] != x {
|
||
parent[x] = find(parent[x])
|
||
}
|
||
return parent[x]
|
||
}
|
||
union := func(from, to int) bool {
|
||
fmt.Println(from, to)
|
||
x, y := find(from), find(to)
|
||
fmt.Println(x, y)
|
||
if x == y {
|
||
return false
|
||
}
|
||
parent[x] = y
|
||
fmt.Println(parent)
|
||
fmt.Println("-------------------------------")
|
||
return true
|
||
}
|
||
for _, e := range edges {
|
||
if !union(e[0], e[1]) {
|
||
return e
|
||
}
|
||
}
|
||
return nil
|
||
}
|
||
|
||
func removeStones(stones [][]int) int {
|
||
fa := map[int]int{}
|
||
var find func(int) int
|
||
find = func(x int) int {
|
||
if _, has := fa[x]; !has {
|
||
fa[x] = x
|
||
}
|
||
if fa[x] != x {
|
||
fa[x] = find(fa[x])
|
||
}
|
||
fmt.Println(fa[x])
|
||
return fa[x]
|
||
}
|
||
union := func(x, y int) {
|
||
fmt.Println(x, y)
|
||
fx, fy := find(x), find(y)
|
||
if fx == fy {
|
||
return
|
||
}
|
||
fa[fy] = fx
|
||
fmt.Println(fa)
|
||
}
|
||
for _, p := range stones {
|
||
union(p[0], p[1]+10000)
|
||
}
|
||
ans := len(stones)
|
||
for x, fx := range fa {
|
||
if x == fx {
|
||
ans--
|
||
}
|
||
}
|
||
return ans
|
||
}
|
||
|
||
//动态规划
|
||
func maxUncrossedLines(A []int, B []int) (s int) {
|
||
var dynamic = make([][]int, len(A)+1, len(A)+1)
|
||
for index := range dynamic {
|
||
dynamic[index] = make([]int, len(B)+1, len(B)+1) //多创建一列,因为 index = 0 的时候,没有前置匹配
|
||
}
|
||
for _, v := range dynamic {
|
||
fmt.Println(v)
|
||
}
|
||
fmt.Println("---------------------")
|
||
for index, a := range A {
|
||
for i, b := range B {
|
||
if a == b {
|
||
dynamic[index+1][i+1] = dynamic[index][i] + 1
|
||
for _, v := range dynamic {
|
||
fmt.Println(v)
|
||
}
|
||
fmt.Println("---------------------")
|
||
} else {
|
||
dynamic[index+1][i+1] = dynamic[index][i+1]
|
||
if dynamic[index+1][i+1] < dynamic[index+1][i] {
|
||
dynamic[index+1][i+1] = dynamic[index+1][i] //判断大小,取大值
|
||
}
|
||
for _, v := range dynamic {
|
||
fmt.Println(v)
|
||
}
|
||
fmt.Println("---------------------")
|
||
}
|
||
}
|
||
}
|
||
return dynamic[len(A)][len(B)]
|
||
}
|
||
|
||
func TestShopList(t *testing.T) {
|
||
result, err := api.ShopList(25)
|
||
if err != nil {
|
||
t.Fatal(err)
|
||
}
|
||
fmt.Println("aaaaaaa", len(result.List))
|
||
t.Log(utils.Format4Output(result, false))
|
||
}
|
||
|
||
func TestWareSave(t *testing.T) {
|
||
// desc := `<p>因生鲜比较脆弱,发货途中如果有磕碰损坏,请收到联系客服,闪电赔付。请核对好地址,发货后不可修改地址,因改地址导致损坏不能赔付,谢谢理解</p><p><img style="width:auto;height:auto;max-width:100%;" src="//img10.360buyimg.com/imgzone/jfs/t1/126814/22/1326/472568/5ebb888dEa2cfb5f6/c0c81db660994246.jpg"><br></p><p><br></p>`
|
||
params := &WareSaveParam{
|
||
WareID: 0,
|
||
Height: 100,
|
||
CategoryID: 13574,
|
||
LastCategoryID: 13574,
|
||
VenderID: 10569615,
|
||
BrandID: 44259,
|
||
Length: 200,
|
||
Wide: 100,
|
||
WareStatus: 8,
|
||
Title: "散养土鸡蛋新鲜鸡蛋草鸡蛋柴鸡蛋顺丰包邮测试",
|
||
Weight: "1",
|
||
ShopCategorys: []int{15602325},
|
||
Notes: `
|
||
<p><img src="//img10.360buyimg.com/imgzone/jfs/t1/152741/14/7416/273609/5fbf645aEa1f7d6b7/dc1d9d997fe346b7.jpg" style="width: auto; height: auto; max-width: 100%;"><br></p><p><br></p>
|
||
`,
|
||
Skus: []*WareSaveSkus{
|
||
&WareSaveSkus{
|
||
// SkuID: 10024685331653,
|
||
JdPrice: "25",
|
||
StockNum: 9999,
|
||
Props: []*WareSaveSkusProp{
|
||
&WareSaveSkusProp{
|
||
AttrID: 1001027603,
|
||
AttrValues: 2517633718,
|
||
AttrValueAlias: "20个",
|
||
},
|
||
},
|
||
OuterID: "6045735",
|
||
},
|
||
// &WareSaveSkus{
|
||
// JdPrice: "31",
|
||
// StockNum: 5,
|
||
// Props: []*WareSaveSkusProp{
|
||
// &WareSaveSkusProp{
|
||
// AttrID: 1000022043,
|
||
// AttrValues: 2515430634,
|
||
// AttrValueAlias: "500g",
|
||
// },
|
||
// },
|
||
// },
|
||
},
|
||
PromiseID: 0,
|
||
MultiCateProps: []interface{}{},
|
||
PropsSet: []interface{}{},
|
||
SaleAttrs: []interface{}{},
|
||
TransparentImageAudit: []interface{}{},
|
||
OptionType: 1,
|
||
AvailableFeatures: []interface{}{},
|
||
CharacteristicService: []interface{}{},
|
||
ExtendFeatures: []interface{}{},
|
||
TempID: "10569615110055200", //必须要这个东西,不知道是啥
|
||
}
|
||
params.ImageMap.Num0000000000 = append(params.ImageMap.Num0000000000, &CreateSkuParamImages{
|
||
ColorID: "0000000000",
|
||
ImgIndex: 1,
|
||
ImgURL: "jfs/t1/149724/17/15786/39416/5fbf645aE948e4d7a/b13bcaee129676b2.jpg",
|
||
// ImgZoneID: "0000000000",
|
||
})
|
||
// , &CreateSkuParamImages{
|
||
// ColorID: "0000000000",
|
||
// ImgIndex: 2,
|
||
// ImgURL: "jfs/t1/142006/30/15024/504060/5fb636d4Ef12079f7/2adad323cbcf7c52.jpg",
|
||
// // ImgZoneID: "0000000000",
|
||
// })
|
||
result, err := api.WareSave(params)
|
||
if err != nil {
|
||
t.Fatal(err)
|
||
}
|
||
t.Log(utils.Format4Output(result, false))
|
||
}
|
||
|
||
func TestWareDoUpdate(t *testing.T) {
|
||
err := api.WareDoUpdate("up", "10020536451427")
|
||
if err != nil {
|
||
t.Fatal(err)
|
||
}
|
||
// t.Log(utils.Format4Output(result, false))
|
||
}
|
||
|
||
func TestStoreWareDoUpdate(t *testing.T) {
|
||
err := api.StoreWareDoUpdate(1, 10024685331653, "1000063128")
|
||
if err != nil {
|
||
t.Fatal(err)
|
||
}
|
||
// t.Log(utils.Format4Output(result, false))
|
||
}
|
||
|
||
func TestStoreUpdatePrice(t *testing.T) {
|
||
// err := api.StoreUpdatePrice(80, 10024685331653, "1000063128")
|
||
// if err != nil {
|
||
// t.Fatal(err)
|
||
// }
|
||
// t.Log(utils.Format4Output(result, false))
|
||
}
|
||
|
||
func TestStoreUpdateStock(t *testing.T) {
|
||
err := api.StoreUpdateStock(80, 10024685331653, "1000063128")
|
||
if err != nil {
|
||
t.Fatal(err)
|
||
}
|
||
// t.Log(utils.Format4Output(result, false))
|
||
}
|
||
|
||
func TestStoreSkuBindStore(t *testing.T) {
|
||
err := api.StoreSkuBindStore(false, []string{"10024685331653"}, []string{"1000063128"})
|
||
if err != nil {
|
||
t.Fatal(err)
|
||
}
|
||
// t.Log(utils.Format4Output(result, false))
|
||
}
|
||
|
||
func TestSetOrderStateToWait(t *testing.T) {
|
||
err := api.SetOrderStateToWait(1)
|
||
if err != nil {
|
||
t.Fatal(err)
|
||
}
|
||
// t.Log(utils.Format4Output(result, false))
|
||
}
|