SJA APS后端代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

124 lines
2.8 KiB

package db
import (
"fmt"
"github.com/go-xorm/xorm"
"leit.com/leit_seat_aps/common"
"testing"
"time"
"xorm.io/core"
)
func TestReader(t *testing.T) {
var (
connstring string
projecttab Me_project
err error
)
// 连接数据库
connstring = fmt.Sprintf("server=%s;user id=%s;password=%s;database=%s;port=%d;encrypt=disable",
`DESKTOP-S4G95G5\\MLINK`, "lapp", "123fis", "LAPP_JITS", 1433)
if err = InitMssqlDb(connstring); err != nil {
t.Errorf("Failed to connect db due to: %v", err)
return
}
defer G_DbEngine.Close()
// 获取项目数据行
if _, err = G_DbEngine.Id(core.PK{G_FINR, "G38"}).Get(&projecttab); err != nil {
t.Errorf("Failed to get project G18 data due to: %v", err)
} else {
fmt.Println("==>", projecttab.Projectid)
}
}
// 测试Session操作
func TestSession(t *testing.T) {
var (
connstring string
session *xorm.Session
mattab Pln_material
err error
)
// 连接数据库
connstring = fmt.Sprintf("server=%s;user id=%s;password=%s;database=%s;port=%d;encrypt=disable",
`DESKTOP-S4G95G5\\MLINK`, "lapp", "123fis", "LAPP_JITS", 1433)
if err = InitMssqlDb(connstring); err != nil {
t.Errorf("Failed to connect db due to: %v", err)
return
}
defer G_DbEngine.Close()
// 获取项目数据行
session = G_DbEngine.NewSession()
defer session.Close()
if err := session.Begin(); err != nil {
return
}
mattab = Pln_material{}
mattab.Finr = G_FINR
mattab.Materialid = "Dora"
if _, err = session.Insert(mattab); err != nil {
session.Rollback()
t.Errorf("Failed to insert mattab due to %v", err)
return
}
mattab = Pln_material{}
mattab.Finr = G_FINR
mattab.Materialid = "Leo"
if _, err = session.Insert(mattab); err != nil {
session.Rollback()
t.Errorf("Failed to insert mattab due to %v", err)
return
}
session.Commit()
fmt.Println("Success to insert into Plan_material!")
return
}
func TestStructToMap(t *testing.T) {
results := []interface{}{} //这里必须定义成[]interface{}{}
u1 := Pln_pickorder{
Finr: 100,
Pickorderid: "PIK_10001",
}
u2 := Pln_pickorder{
Finr: 100,
Pickorderid: "PIK_10002",
}
u3 := Pln_pickorder{
Finr: 100,
Pickorderid: "PIK_10003",
}
u4 := Pln_pickorder{
Finr: 100,
Pickorderid: "PIK_10004",
}
results = append(results, u1)
results = append(results, u2)
results = append(results, u3)
results = append(results, u4)
kv := common.StructToMap(results)
for key, val := range kv {
fmt.Println(key, "==>", val)
}
}
func TestInitMongoDb(t *testing.T) {
//日志
info := new(Recordlog)
info.Servername = "tod服务"
info.File = "tod/Todtask.go"
info.Debuglevel = "medium"
info.Message = "测试"
info.Location = "tod/Todtask.go: 692行"
info.Function = "Failed to Save CO: workorder!"
info.TimeStamp = common.TimeFormat(time.Now(), "yyyyMMddHHmmss")
result := info.InsertRecord()
t.Log(result)
}