data2minio/model/dataset.go

68 lines
1.7 KiB
Go

package model
import (
"data_minio/global"
"fmt"
)
type Dataset struct {
DatasetId int64 `xorm:"not null pk autoincr INT(11)" json:"datasetId"`
DatasetName string `xorm:"varchar(200) not null" json:"datasetName"`
DatasetDesc string `xorm:"varchar(200)" json:"datasetDesc"`
StoreName string `xorm:"varchar(200)" json:"storeName"`
CategoryId int `xorm:"not null SMALLINT default 1" json:"categoryId"` //业务分类, 1:道路 2:桥梁 3:隧道 4:边坡
ProjectId int64 `xorm:"INT(11) not null default 0 index" json:"projectId"`
OwnerId int64 `xorm:"INT(11) not null default 0 index" json:"ownerId"`
Creator int64 `xorm:"INT(11) not null default 0 index" json:"creator"`
Status int `xorm:"SMALLINT not null default 1" json:"status"`
CreateAt int64 `xorm:"created" json:"createAt"`
UpdateAt int64 `xorm:"updated" json:"updateAt"`
}
func GetDatasetById(id int64) (data *Dataset, err error) {
data = new(Dataset)
b, err := global.DB.ID(id).Get(data)
if err != nil {
return nil, err
}
if !b {
return nil, fmt.Errorf("未能找到对应的数据集")
}
return data, nil
}
func GetDatasetScene(categoryId int) string {
switch categoryId {
case 1:
return "road"
case 2:
return "bridge"
case 3:
return "tunnel"
case 4:
return "sideSlope"
default:
return "other"
}
}
func GetDatasetByName(name string, dataType int) (data *Dataset, err error) {
data = new(Dataset)
b, err := global.DB.Where("dataset_name = ?", name).
And("category_id=?", dataType).Get(data)
if err != nil {
return nil, err
}
if !b {
item := new(Dataset)
item.DatasetName = name
item.CategoryId = dataType
_, err = global.DB.Insert(item)
if err != nil {
return nil, err
}
return item, err
}
return data, nil
}