73 lines
1.7 KiB
Go
73 lines
1.7 KiB
Go
|
package test
|
||
|
|
||
|
import (
|
||
|
"context"
|
||
|
"testing"
|
||
|
|
||
|
"github.com/gogf/gf/v2/database/gdb"
|
||
|
"github.com/gogf/gf/v2/frame/g"
|
||
|
"github.com/tiger1103/gfast/v3/internal/app/system/dao"
|
||
|
"github.com/tiger1103/gfast/v3/third/solaranalyzer"
|
||
|
)
|
||
|
|
||
|
// 测试更新
|
||
|
func TestUpdate(t *testing.T) {
|
||
|
ctx := context.Background()
|
||
|
|
||
|
// 根据任务ID查询出所有的 PV Module ID
|
||
|
var pvlist []struct {
|
||
|
PvID int `orm:"pv_id"`
|
||
|
FangZhenID int `orm:"fangzhen_id"`
|
||
|
WorkID string `orm:"work_id"`
|
||
|
TypeID int `orm:"type_id"`
|
||
|
}
|
||
|
|
||
|
// 查询出基本信息
|
||
|
err := dao.PvModule.Ctx(ctx).As("pv").Fields("pv.id as pv_id", "pv.fangzhen_id", "pv.work_id", "pv.type").
|
||
|
LeftJoin("manage_task_result as mts", "pv.id = mts.pv_id").
|
||
|
Where("mts.task_id = ?", 518).Scan(&pvlist)
|
||
|
if err != nil {
|
||
|
t.Fatal(err)
|
||
|
}
|
||
|
|
||
|
for _, v := range pvlist {
|
||
|
if v.TypeID == 15 { // 光伏板
|
||
|
if err := solaranalyzer.ProcessMatchedRectangles([]int{v.PvID}); err != nil {
|
||
|
t.Fatal(err)
|
||
|
}
|
||
|
return
|
||
|
}
|
||
|
|
||
|
// 更新 PV Module 表
|
||
|
lastID, err := dao.PvModule.Ctx(ctx).Where(dao.PvModule.Columns().Id, v.PvID).
|
||
|
Where(dao.PvModule.Columns().FangzhenId, v.FangZhenID).
|
||
|
Where(dao.PvModule.Columns().Type, v.TypeID).
|
||
|
Data(g.Map{
|
||
|
dao.PvModule.Columns().Status: 2,
|
||
|
}).Update()
|
||
|
if err != nil {
|
||
|
t.Fatal(err)
|
||
|
}
|
||
|
|
||
|
rows, err := lastID.RowsAffected()
|
||
|
if err != nil {
|
||
|
t.Fatal(err)
|
||
|
}
|
||
|
|
||
|
if rows > 0 {
|
||
|
// 更新 work_status 表
|
||
|
_, err := dao.WorkStatus.Ctx(ctx).Where(dao.WorkStatus.Columns().FangzhenId, v.FangZhenID).
|
||
|
Where(dao.WorkStatus.Columns().Type, v.TypeID).
|
||
|
Data(g.Map{
|
||
|
dao.WorkStatus.Columns().Finished: gdb.Raw(
|
||
|
"finished + 1",
|
||
|
),
|
||
|
}).Update()
|
||
|
if err != nil {
|
||
|
t.Fatal(err)
|
||
|
}
|
||
|
|
||
|
}
|
||
|
}
|
||
|
}
|