# TAK 2021Q2
## AS 機制前優化
### 為何需要優化
- Server資料需要有備援機制,以防正在運行的Server有問題時可以無痛快速地切換另一台主機,使原本的服務能夠正常
- 架構圖

## PC人數使用時間統計
### MSSQL語法
- 通用資料表運算式 (CTE)
- nest CASE WHEN

```mermaid
graph TB
A[Initial HOL] --> B[擷取當日所在月份,日期在月份以內的資料]
B[擷取當日所在月份,日期在月份以內的資料]-->C[起始時間與結束時間在同一日]
B[擷取當日所在月份,日期在月份以內的資料]-->D[起始時間與結束時間在不同日]
C[起始時間與結束時間在同一日]-->N
D[起始時間與結束時間在不同日]-->E
subgraph 不同日計算邏輯
direction TB
E[1 起始時間在開盤前, 結束時間盤中] --> F[2 起始時間在盤中, 結束時間在開盤前]
F[2 起始時間在盤中, 結束時間在開盤前] --> G[3 起始時間在盤中, 結束時間在盤中]
G[3 起始時間在盤中, 結束時間在盤中] --> H[4 起始時間在盤中, 結束時間在收盤後]
H[4 起始時間在盤中, 結束時間在收盤後] --> I[5 起始時間在開盤前, 結束時間在收盤後]
I[5 起始時間在開盤前, 結束時間在收盤後] --> J[6 起始時間與結束時間都在收盤後]
J[6 起始時間與結束時間都在收盤後] --> K[7 起始時間與結束時間 都在開盤前]
K[7 起始時間與結束時間 都在開盤前] --> L[8 起始時間在收盤後, 結束時間 在開盤後]
L[8 起始時間在收盤後, 結束時間 在開盤後]
end
subgraph 同日計算邏輯
direction TB
N[計算起始時間與結束時間]
end
L --> M
N --> M[當日每人總使用時間]
M --> O[存入每月資料表]
O --> P[提供給前端]
```
## Syslog API 串接
- syslogt 串接
```mermaid
graph LR
H[syslog] --> B[login_log]
H[syslog] --> C[use_time_log]
H[syslog] --> D[mitake_rainbow]
B[login_log] --> E[login_log format text parser]
C[use_time_log] --> F[use_time format text parser]
D[mitake_rainbow] --> G[mitake_rainbow json parser]
E[login_log format text parser] --> A[chogath]
F[use_time format text parser] --> A[chogath]
G[mitake_rainbow json parser] --> A[chogath]
A[chogath] --> I[MSSQL DB]
```
- 目前Amumu串連架構說明
```mermaid
graph LR
K:::someclass
classDef someclass fill:#f96;
F(Braum) --> B(Chogath)
B(Chogath) --> F(Braum)
B(Chogath) --> A[Amumu GW]
A[Amumu GW] --> B(Chogath)
B(Chogath) --> C(soryu)
K(Syslog) --> B(Chogath)
K(Syslog) --> H
D(PDA) -->|券商資料| B(Chogath)
B(Chogath) --> |多券商資料|D(PDA)
E(研本類股編輯,push alert) --> A[Amumu]
A[Amumu] --> E(研本類股編輯,push alert)
A[Amumu] --> G[前端UI]
H(Chogath Sync) --> B(Chogath)
F(Braum) -->|備份| I(LoginLogBak)
A[Amumu] -->|API| J[PLM]
J[PLM] -->|資料回傳| A[Amumu GW]
```
## goutility
### 建構目的
- 將golang共通性的方法放入此元件內,藉此減少專案間的共用程式碼
### 安裝方式
```
go get -u gitlab01.mitake.com.tw/RD1/GO/goutility.git
```
### golang test 介紹



### command line
- 測試package
```shell
go test -v -cover=true gitlab01.mitake.com.tw/RD1/GO/goutility.git/example
```
- 測試檔案
```shell
go test -v -cover=true example.go example_test.go
```
### gotests 介紹
#### 常用操作
1.進入對應的要被生成單元測試的目錄
2.在該目錄下執行命令
3.生成指定函式的單元測試,輸出到命令列,然後複製貼上到目標處。
```shell
gotests -only "函式名稱" 檔名稱.go
```
4.生成全部測試函式
```shell
gotests -all 檔名稱.go
```
```shell
gotests -only " 方法名稱" 檔名稱
```
```shell
gotests -all -w origin.go, origin_test.go
```
會自動建立在當前目錄下,並自動生成測試程式碼,只需要將不同的測試資料按照tests定義的結構寫在 <span style="color:green">//TODO:Add test cases</span>.下面,測試用例就完成了
- 網路文章參考
[github gotests](https://github.com/cweill/gotests)
[golang 测试gotests](https://studygolang.com/articles/26750)
## Amumu複委託API
* 串接研發本部提供的複委託API

## 習得工具或技術
- [gotests](https://github.com/cweill/gotests)
## 未來展望學習
- Portman unit test
- goutility unit test & CI
- mysql to mssql