# URI-J-01~03 Product Alert
> [name=JasonWu, Hans]
###### tags: `電子報訂閱`
## 網址
- https://{domain}/taiwantradeAlert/subscribeCategory/
- ex: https://www.taiwantrade.com/taiwantradeAlert/subscribeCategory/
## 原版程式
- com.hyweb.tt.cms.front.rest.SubscribeResource.java
-
## 頁面功能說明
- 首先輸入 email,檢查相關訂閱資訊;如果已經登入,省略此動作,直接進入編輯畫面
- 成功之後,提供使用者輸入訂閱的相關資訊
- 輸入 keyword,將來可找出符合 keyword 的型錄
- 選擇後分類,提供使用者勾選並記錄相關後分類
- 最多可以選擇 100 項
- 需要有 google 的機器人驗證
- 送出後,記錄相關資料

## 相關 api 分析
- 預計應提供四隻 api
- subscribe category select api > 提供使用者找出符合的後分類
- 找出符合對應 cid 的分類結果
- 如果傳入的 type = 2,代表要拿到四碼的下拉選單
- 如果傳入的 type = 4,代表要拿到六碼的下拉選單
- 如果傳入的 type = 6,代表實際列出的結果
- subscribe keyword search api > 輸入查詢詞,找出符合的後分類
- 找出符合 keyword 符合前三多的四碼 taitra code 與對應的六碼 taitra code
- product alert save api > 點選送出後,儲存相關資料
- product alert remove api > 點選送出後,刪除相關資料
## URI-J-01 subscribe category select api
- https://www.taiwantrade.com/taiwantradeAlert/selectCategory6?cid=7060&did=2&languageId=42
### 規格
- path : ${TT-API網址}/subscriptions/product-catalog
- method : POST
- query :
### API 邏輯
- 依照查詢條件,找出後分類列表
- 如果 type = 2 > 代表組出二碼下拉選單
- 如果 type = 4 > 代表組出四碼下拉選單
- 如果 type = 6 > 代表組出可以選擇的四碼與六碼清單
### Input
```=json
{
"did" : {{ number }},
"type" : {{ number }},
"cid" : {{ number }}
}
```
Column | Type | Require | Desc
-----------------|----------|---------|---------
did | number | Y | domain id
type | number | Y | 是二碼、四碼或是四六碼
cid | number | Y | 查詢分類 id(查詢二碼給0)
### Output
- json 內容如下:
```=json
{
"code" : {{ number }} , // 代碼,0:ok、 < 0: error 使用
"errorMsg" : {{ string }}, // 錯誤訊息
"data" : [
{
"categoryName" : {{ string }} , // 第一層 taitra code name
"cid" : {{ number }} , // 第一層 taitra code id
"parentcid" : null, // 第一層不需特殊回傳 parent id
"count" : {{ number }} , // 數量
"subscribeCid" : {{ number }} // 第一層 taitra code 訂閱 cid
},
]
}
```
#### 輸出參數說明
<span id="subscribeCategorySelectVo">`subscribeCategorySelectVo`</span>
| 欄位名稱 | 欄位說明 | 型態 |
| -------- | -------- | -------- |
| categoryName | 產業別名稱 | String |
| cid | 產業別代碼<br>ex. 2碼50, 2碼下的4碼5001, 4碼下的6碼500101 | int |
| parentcid | 父層ID | int |
| count | 型錄數 | int |
| subscribeCid | CodeMeta流水號,用於 [Save-Api-catalogs](https://hackmd.io/3lN5tDL1TIiz4ySRfyQXLA?view#Input2) 儲存記錄 | int |
### 實際範例
<details>
<summary>
2碼Input(Click to Show/Hide Output)
```=json
{
"cid": 0,
"did": 2,
"type": 2
}
```
</summary>
2碼Output
```=json
{
"code": 0,
"errorMsg": "",
"data": [
{
"categoryName": "Aerospace",
"cid": 71,
"parentcid": null,
"count": 352,
"subscribeCid": 21
},
{
"categoryName": "Agricultural & Foods",
"cid": 51,
"parentcid": null,
"count": 13271,
"subscribeCid": 1
},
{
"categoryName": "Apparel & Accessories",
"cid": 56,
"parentcid": null,
"count": 9003,
"subscribeCid": 6
},
{
"categoryName": "Automobiles & Motorcycles",
"cid": 69,
"parentcid": null,
"count": 34360,
"subscribeCid": 19
},
{
"categoryName": "Beauty & Personal Care",
"cid": 54,
"parentcid": null,
"count": 6646,
"subscribeCid": 4
},
{
"categoryName": "Bicycles",
"cid": 70,
"parentcid": null,
"count": 6190,
"subscribeCid": 20
},
{
"categoryName": "Chemicals",
"cid": 53,
"parentcid": null,
"count": 4335,
"subscribeCid": 3
},
{
"categoryName": "Computer",
"cid": 67,
"parentcid": null,
"count": 9719,
"subscribeCid": 17
},
{
"categoryName": "Construction",
"cid": 76,
"parentcid": null,
"count": 6270,
"subscribeCid": 2
},
{
"categoryName": "Consumer Electronics",
"cid": 64,
"parentcid": null,
"count": 7276,
"subscribeCid": 14
},
{
"categoryName": "Electrical & Electronics",
"cid": 63,
"parentcid": null,
"count": 17216,
"subscribeCid": 13
},
{
"categoryName": "Furniture",
"cid": 77,
"parentcid": null,
"count": 5859,
"subscribeCid": 27
},
{
"categoryName": "Gifts & Crafts",
"cid": 83,
"parentcid": null,
"count": 4585,
"subscribeCid": 33
},
{
"categoryName": "Hardware",
"cid": 59,
"parentcid": null,
"count": 7693,
"subscribeCid": 9
},
{
"categoryName": "Home Appliances",
"cid": 65,
"parentcid": null,
"count": 2693,
"subscribeCid": 15
},
{
"categoryName": "Houseware",
"cid": 78,
"parentcid": null,
"count": 8068,
"subscribeCid": 28
},
{
"categoryName": "Lights & Lighting",
"cid": 66,
"parentcid": null,
"count": 5371,
"subscribeCid": 16
},
{
"categoryName": "Luggage, Bags & Cases",
"cid": 57,
"parentcid": null,
"count": 1837,
"subscribeCid": 7
},
{
"categoryName": "Machinery",
"cid": 61,
"parentcid": null,
"count": 22156,
"subscribeCid": 11
},
{
"categoryName": "Measurement & Analysis Instrument",
"cid": 75,
"parentcid": null,
"count": 2966,
"subscribeCid": 25
},
{
"categoryName": "Mechanical Parts",
"cid": 62,
"parentcid": null,
"count": 7228,
"subscribeCid": 12
},
{
"categoryName": "Medical & Health",
"cid": 74,
"parentcid": null,
"count": 6332,
"subscribeCid": 24
},
{
"categoryName": "Mineral & Metallurgy",
"cid": 52,
"parentcid": null,
"count": 1386,
"subscribeCid": 2
},
{
"categoryName": "Musical Instruments",
"cid": 81,
"parentcid": null,
"count": 331,
"subscribeCid": 31
},
{
"categoryName": "Office & School Supplies",
"cid": 82,
"parentcid": null,
"count": 3693,
"subscribeCid": 32
},
{
"categoryName": "Packaging, Printing & Advertising",
"cid": 84,
"parentcid": null,
"count": 4358,
"subscribeCid": 34
},
{
"categoryName": "Security & Protection",
"cid": 73,
"parentcid": null,
"count": 4513,
"subscribeCid": 23
},
{
"categoryName": "Services",
"cid": 85,
"parentcid": null,
"count": 1278,
"subscribeCid": 35
},
{
"categoryName": "Ships & Boats",
"cid": 72,
"parentcid": null,
"count": 811,
"subscribeCid": 22
},
{
"categoryName": "Sports",
"cid": 80,
"parentcid": null,
"count": 7779,
"subscribeCid": 30
},
{
"categoryName": "Telecom Products",
"cid": 68,
"parentcid": null,
"count": 2730,
"subscribeCid": 18
},
{
"categoryName": "Textile & Leather",
"cid": 55,
"parentcid": null,
"count": 1528,
"subscribeCid": 5
},
{
"categoryName": "Timepiece, Jewelry & Eyewear",
"cid": 58,
"parentcid": null,
"count": 3901,
"subscribeCid": 8
},
{
"categoryName": "Tools999",
"cid": 60,
"parentcid": null,
"count": 11855,
"subscribeCid": 10
},
{
"categoryName": "Toys, Baby & Pet Products",
"cid": 79,
"parentcid": null,
"count": 3608,
"subscribeCid": 29
}
]
}
```
</details>
<details>
<summary>
4碼Input(Click to Show/Hide Output)
```=json
{
"cid": 72,
"did": 2,
"type": 4
}
```
</summary>
4碼Output
```=json
{
"code": 0,
"errorMsg": "",
"data": [
{
"categoryName": "Boats & Ships",
"cid": 7210,
"parentcid": 72,
"count": 143,
"subscribeCid": 259
},
{
"categoryName": "Marine Supplies",
"cid": 7220,
"parentcid": 72,
"count": 668,
"subscribeCid": 260
}
]
}
```
</details>
<details>
<summary>
6碼Input(Click to Show/Hide Output)
```=json
{
"cid": 7220,
"did": 2,
"type": 6
}
```
</summary>
6碼Output
```=json
{
"code": 0,
"errorMsg": "",
"data": [
{
"categoryName": "Boat Engine",
"cid": 722010,
"parentcid": 7220,
"count": 2,
"subscribeCid": 2519
},
{
"categoryName": "Marine Buoy",
"cid": 722050,
"parentcid": 7220,
"count": 5,
"subscribeCid": 2523
},
{
"categoryName": "Marine Hardware",
"cid": 722040,
"parentcid": 7220,
"count": 612,
"subscribeCid": 2522
},
{
"categoryName": "Marine Propeller",
"cid": 722030,
"parentcid": 7220,
"count": 34,
"subscribeCid": 2521
},
{
"categoryName": "Marine Pump",
"cid": 722020,
"parentcid": 7220,
"count": 8,
"subscribeCid": 2520
},
{
"categoryName": "Other Marine Supplies",
"cid": 722099,
"parentcid": 7220,
"count": 7,
"subscribeCid": 2524
}
]
}
```
</details>
## URI-J-02 subscribe keyword search api
- https://www.taiwantrade.com/taiwantradeAlert/searchCategoryByKeyword?keyword=mp3&did=2&languageId=42
### 規格
- path : ${TT-API網址}/subscriptions/product-search
- method : POST
- query :
### API 邏輯
- 依照查詢詞條件呼叫IDOL查詢,取得所有資料後,依照四碼下涵蓋產品數量倒敘排序,排序完成後回傳前三筆四碼以及所屬六碼的結果。
### Input
```=json
{
"did" : {{ number }},
"keyword" : {{ string }}
}
```
Column | Type | Require | Desc
-----------------|----------|---------|---------
did | number | Y | domain id
keyword | String | Y | 查詢詞
### Output
- json 內容如下:
```=json
{
"code" : {{ number }} , // 代碼,0:ok、 < 0: error 使用
"errorMsg" : {{ string }}, // 錯誤訊息
"data" : [
{
"categoryName" : {{ string }} , // 四碼 taitra code name
"cid" : {{ number }} , // 四碼 taitra code id
"parentcid" : null, // 四碼沒有特別回傳 parent
"count" : {{ number }} , // 數量
"subscribeCid" : {{ number }} , // 四碼 taitra code 訂閱 cid
"subscribeCategorySelectVo" : [ // 子項目
{
"categoryName" : : {{ string }} , // 六碼 taitra code name
"cid" : {{ number }} , // 六碼 taitra code id
"parentcid" : {{ number }} , // 對應的四碼 taitra code id
"subscribeCid" : {{ number }} // 六碼 taitra code 訂閱 cid
]
},
]
},
]
}
```
#### 輸出參數說明
[`同上`](#subscribeCategorySelectVo)
### 實際範例
<details>
<summary>
Input(Click to Show/Hide Output)
```=json
{
"did": 2,
"keyword": "Robot"
}
```
</summary>
Output
```=json
{
"code": 0,
"errorMsg": "",
"data": [
{
"categoryName": "Industrial Automatic Equipment",
"cid": 6180,
"parentcid": null,
"count": 65,
"subscribeCid": 155,
"subscribeCategorySelectVo": [
{
"categoryName": "Robot",
"cid": 618005,
"parentcid": 6180,
"count": 57,
"subscribeCid": 1610
},
{
"categoryName": "Assembly Machine",
"cid": 618025,
"parentcid": 6180,
"count": 2,
"subscribeCid": 1614
},
{
"categoryName": "Automatic Feeding System",
"cid": 618040,
"parentcid": 6180,
"count": 2,
"subscribeCid": 1617
},
{
"categoryName": "Robotic Arm",
"cid": 618010,
"parentcid": 6180,
"count": 1,
"subscribeCid": 1611
},
{
"categoryName": "Automated & Industrial Controller Module",
"cid": 618015,
"parentcid": 6180,
"count": 1,
"subscribeCid": 1612
},
{
"categoryName": "Surface Mouting Technology Equipment(SMT)",
"cid": 618020,
"parentcid": 6180,
"count": 1,
"subscribeCid": 1613
},
{
"categoryName": "Automatic Material Handling Equipment",
"cid": 618030,
"parentcid": 6180,
"count": 1,
"subscribeCid": 1615
}
]
},
{
"categoryName": "Plastic Processing Machinery",
"cid": 6132,
"parentcid": null,
"count": 39,
"subscribeCid": 140,
"subscribeCategorySelectVo": [
{
"categoryName": "Plastic Injection Moulding Machine",
"cid": 613202,
"parentcid": 6132,
"count": 32,
"subscribeCid": 1288
},
{
"categoryName": "Plastic Blowing Moulding Machine",
"cid": 613206,
"parentcid": 6132,
"count": 6,
"subscribeCid": 1290
},
{
"categoryName": "Plastic Laminating Machine",
"cid": 613212,
"parentcid": 6132,
"count": 1,
"subscribeCid": 1293
}
]
},
{
"categoryName": "Machine Tools",
"cid": 6102,
"parentcid": null,
"count": 34,
"subscribeCid": 129,
"subscribeCategorySelectVo": [
{
"categoryName": "CNC Controller",
"cid": 610255,
"parentcid": 6102,
"count": 10,
"subscribeCid": 1143
},
{
"categoryName": "Machine Press",
"cid": 610235,
"parentcid": 6102,
"count": 7,
"subscribeCid": 1139
},
{
"categoryName": "CNC Machining Center",
"cid": 610270,
"parentcid": 6102,
"count": 6,
"subscribeCid": 1146
},
{
"categoryName": "Lathe",
"cid": 610205,
"parentcid": 6102,
"count": 5,
"subscribeCid": 1133
},
{
"categoryName": "Grinding Machine",
"cid": 610220,
"parentcid": 6102,
"count": 2,
"subscribeCid": 1136
},
{
"categoryName": "Tapping Machine",
"cid": 610275,
"parentcid": 6102,
"count": 2,
"subscribeCid": 1147
},
{
"categoryName": "Drilling Machine",
"cid": 610215,
"parentcid": 6102,
"count": 1,
"subscribeCid": 1135
},
{
"categoryName": "EDM Machine",
"cid": 610260,
"parentcid": 6102,
"count": 1,
"subscribeCid": 1144
}
]
}
]
}
```
</details>
## URI-J-03 product alert save api
-https://www.taiwantrade.com/taiwantradeAlert/subscribeByCatalogs?email=user@hyweb.com.tw&catalogs=2484,2489&did=2&languageId=42
### 規格
- path : ${TT-API網址}/subscriptions/product-save
- method : POST
- query :
### API 邏輯
- 儲存型錄後分類訂閱條件
### Input
```=josn
{
"email" : {{ string }},
"catalogs" : {{ string }},
"did" : {{ number }},
"method" : {{ string }}
}
```
Column | Type | Require | Desc
-----------------|----------|---------|---------
email | string | Y | 訂閱 email
catalogs | string | Y | 訂閱那些分類,以逗號分隔
did | number | Y | domain id
<span id="method">method</span> | string | Y | 儲存方式<br> `ADD` 依照參數逐筆新增,恭我的最愛 <br> `EDIT` 依照參數直接替換
### Output
- json 內容如下:
```=json
{
"code" : {{ number }} , // 代碼,0:ok、 < 0: error 使用
"errorMsg" : {{ string }}, // 錯誤訊息
"data" : null
}
```
### 實際範例
<details>
<summary>
Input(Click to Show/Hide Output)
```=json
{
"catalogs": "1147,1135,1144",
"did": 2,
"email": "hans.hsu@hyweb.com.tw",
"method": "EDIT"
}
```
</summary>
Output
```=json
{
"code": 0,
"errorMsg": "",
"data": null
}
```