chore: 并入 iotlcm-admin-svr 历史到 admin-svr/(原提交 49818c6)
This commit is contained in:
@@ -0,0 +1,79 @@
|
||||
package common
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"git.5iot.com/iotlcm-public/iotlcm-admin-svr/internal/consts"
|
||||
"git.5iot.com/iotlcm-public/iotlcm-admin-svr/internal/model"
|
||||
"git.5iot.com/iotlcm-public/iotlcm-admin-svr/internal/model/request"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestBatchManagementAllocationUnits(t *testing.T) {
|
||||
ctx := setupBatchExecutionLogListDB(t)
|
||||
for _, statement := range []string{
|
||||
"ALTER TABLE batch_main ADD target_dept_id INTEGER DEFAULT 0",
|
||||
"ALTER TABLE batch_main ADD dept_id INTEGER DEFAULT 0",
|
||||
"ALTER TABLE batch_main ADD updated_by INTEGER DEFAULT 0",
|
||||
"ALTER TABLE batch_main ADD batch_async_status INTEGER DEFAULT 3",
|
||||
"CREATE TABLE sys_dept(dept_id INTEGER,tenant_id TEXT,dept_key TEXT,dept_name TEXT,deleted_at TEXT)",
|
||||
"INSERT INTO sys_dept VALUES(10,'','source','当前划拨名称',NULL),(20,'','target','当前接收名称',NULL)",
|
||||
`INSERT INTO batch_main(batch_no,batch_type,batch_info,created_dept,target_dept_id,total_count,run_result) VALUES('ALC-PARENT',3,'{"jobRole":"allocate_parent","sourceDeptId":10,"targetDeptId":20,"sourceDeptName":"历史划拨单位","targetDeptName":"历史接收单位"}',10,20,1,2),('ALC-LEGACY',3,'{}',10,20,1,2),('ALC-PER-ROW',3,'{"sourceDeptId":10,"sourceDeptName":"历史划拨单位","targetDeptMode":"per_row"}',10,0,1,2)`,
|
||||
`INSERT INTO batch_main(batch_no,batch_type,source_batch_no,batch_info,created_dept,target_dept_id,total_count,run_result) VALUES('ALC-CHILD',3,'ALC-PARENT','{"jobRole":"allocate_chunk"}',10,20,1,2)`,
|
||||
`INSERT INTO batch_detail(batch_no,batch_type,item_id,snapshot,created_dept) VALUES('ALC-CHILD',3,'card','{}',10)`,
|
||||
} {
|
||||
if _, err := g.DB().Exec(ctx, statement); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
service := NewCommonBatchMain()
|
||||
rows, _, err := service.SuccessList(ctx, &model.BatchMainSuccessListParam{BatchType: consts.BatchTypeAllocate, PageInfo: request.PageInfo{Page: 1, PageSize: 20}})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
seen := map[string]bool{}
|
||||
for _, row := range rows {
|
||||
seen[row.BatchNo] = true
|
||||
switch row.BatchNo {
|
||||
case "ALC-PARENT":
|
||||
if row.SourceDeptName != "历史划拨单位" || row.TargetDeptName != "历史接收单位" {
|
||||
t.Fatal(row)
|
||||
}
|
||||
encoded, err := json.Marshal(row)
|
||||
if err != nil || !strings.Contains(string(encoded), `"targetDeptId":20`) || strings.Contains(string(encoded), "StoredTargetDeptId") {
|
||||
t.Fatal("接口契约错误", string(encoded), err)
|
||||
}
|
||||
case "ALC-LEGACY":
|
||||
if row.SourceDeptName != "当前划拨名称" || row.TargetDeptName != "当前接收名称" {
|
||||
t.Fatal(row)
|
||||
}
|
||||
case "ALC-PER-ROW":
|
||||
if row.TargetDeptMode != "per_row" || row.TargetDeptName != "" {
|
||||
t.Fatal(row)
|
||||
}
|
||||
}
|
||||
}
|
||||
if !seen["ALC-PARENT"] || !seen["ALC-LEGACY"] || !seen["ALC-PER-ROW"] {
|
||||
t.Fatal(seen)
|
||||
}
|
||||
all, _, err := service.List(ctx, &model.BatchMainListParam{BatchNo: "ALC-PARENT", PageInfo: request.PageInfo{Page: 1, PageSize: 20}})
|
||||
if err != nil || len(all) != 1 || all[0].TargetDeptName != "历史接收单位" {
|
||||
t.Fatal("主表列表单位缺失", all, err)
|
||||
}
|
||||
view, err := service.View(ctx, &model.BatchMainViewParam{Id: all[0].Id})
|
||||
if err != nil || view.SourceDeptName != "历史划拨单位" || view.TargetDeptName != "历史接收单位" {
|
||||
t.Fatal("批次详情单位缺失", view, err)
|
||||
}
|
||||
cards, total, err := service.ListCards(ctx, &model.BatchCardListParam{BatchNo: "ALC-PARENT", PageInfo: request.PageInfo{Page: 1, PageSize: 20}})
|
||||
if err != nil || total != 1 || len(cards) != 1 {
|
||||
t.Fatal("父批次未展示子批次卡清单", total, err)
|
||||
}
|
||||
if cards[0].Iccid != "card" || cards[0].SourceDeptName != "历史划拨单位" || cards[0].TargetDeptName != "历史接收单位" {
|
||||
t.Fatal(cards[0])
|
||||
}
|
||||
if _, _, err := service.ListCards(context.Background(), &model.BatchCardListParam{BatchNo: "missing"}); err == nil {
|
||||
t.Fatal("不存在批次被放行")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user