|
package implments
|
|
|
|
import (
|
|
"LAPP_LF_MOM_BACKEND/conf"
|
|
"LAPP_LF_MOM_BACKEND/db"
|
|
model "LAPP_LF_MOM_BACKEND/models/cache"
|
|
"LAPP_LF_MOM_BACKEND/web/middleware/glog"
|
|
"context"
|
|
"go.mongodb.org/mongo-driver/bson"
|
|
"go.mongodb.org/mongo-driver/bson/primitive"
|
|
)
|
|
|
|
/******************************************************************************
|
|
*
|
|
* @Struct Name : SchedulerCache
|
|
*-----------------------------------------------------------------------------
|
|
*
|
|
* @Description : SchedulerCache的数据访问对象实现
|
|
*
|
|
* @Author : 娄文智
|
|
*
|
|
* @Date : 2021-05-20 14:37:20
|
|
*
|
|
******************************************************************************/
|
|
type SchedulerCache struct {
|
|
TaskId string `bson:"taskId" json:"taskId"` //任务Id
|
|
WorkLineId string `bson:"workLineId" json:"workLineId"` //产线ID
|
|
Data string `bson:"data" json:"data"` //保存的数据
|
|
CreateBy string `bson:"createBy" json:"createBy"` //创建人
|
|
CreateTime string `bson:"createTime" json:"createTime"` //创建时间
|
|
}
|
|
|
|
/******************************************************************************
|
|
*
|
|
* @Function Name : NewSchedulerCacheDAOImplement
|
|
*-----------------------------------------------------------------------------
|
|
*
|
|
* @Description : 创建一个SchedulerCache实例
|
|
*
|
|
* @Function Parameters : xorm会话
|
|
*
|
|
* @Function Parameters : 基本主键
|
|
*
|
|
* @Return Value : SchedulerCache实例
|
|
*
|
|
* @Author : 代码生成器创建
|
|
*
|
|
* @Date : 2021-05-20 14:37:20
|
|
*
|
|
******************************************************************************/
|
|
func NewSchedulerCacheDAOImplement() *SchedulerCache {
|
|
return &SchedulerCache{}
|
|
}
|
|
|
|
/******************************************************************************
|
|
*
|
|
* @Reference LAPP_LF_MOM_BACKEND/dao/om/SchedulerCache.InsertOne
|
|
*
|
|
******************************************************************************/
|
|
func (impl *SchedulerCache) InsertOne(entity *model.SchedulerCache) (insertID primitive.ObjectID, err error) {
|
|
//1.初始化链接
|
|
client := db.MgoDb()
|
|
//2.选择数据库,数据表
|
|
collect := client.Database(conf.DbConfig.Mongdbname).Collection("SchedulerCache")
|
|
insertRest, err := collect.InsertOne(context.TODO(), entity)
|
|
if err != nil {
|
|
glog.InfoExtln("buffer 数据导入", "err", err)
|
|
return
|
|
}
|
|
insertID = insertRest.InsertedID.(primitive.ObjectID)
|
|
return insertID, err
|
|
}
|
|
|
|
/******************************************************************************
|
|
*
|
|
* @Reference LAPP_LF_MOM_BACKEND/dao/om/SchedulerCache.DeleteOne
|
|
*
|
|
******************************************************************************/
|
|
func (impl *SchedulerCache) DeleteOne(entity *model.SchedulerCache) error {
|
|
//1.初始化链接
|
|
client := db.MgoDb()
|
|
//2.选择数据库,数据表
|
|
collect := client.Database(conf.DbConfig.Mongdbname).Collection("SchedulerCache")
|
|
_, err := collect.DeleteOne(context.Background(), bson.M{"taskId": entity.TaskId})
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
}
|
|
|
|
/******************************************************************************
|
|
*
|
|
* @Reference LAPP_LF_MOM_BACKEND/dao/om/SchedulerCache.SelectOne
|
|
*
|
|
******************************************************************************/
|
|
func (impl *SchedulerCache) SelectOne(entity *model.SchedulerCache) (model.SchedulerCache, error) {
|
|
//1.初始化链接
|
|
client := db.MgoDb()
|
|
//2.选择数据库,数据表
|
|
collect := client.Database(conf.DbConfig.Mongdbname).Collection("SchedulerCache")
|
|
record := model.SchedulerCache{}
|
|
err := collect.FindOne(context.Background(), bson.M{"taskId": entity.TaskId}).Decode(&record)
|
|
|
|
if err != nil {
|
|
return record, err
|
|
}
|
|
|
|
return record, nil
|
|
}
|
|
|
|
/******************************************************************************
|
|
*
|
|
* @Reference LAPP_LF_MOM_BACKEND/dao/om/SchedulerCache.UpdateOne
|
|
*
|
|
******************************************************************************/
|
|
func (impl *SchedulerCache) UpdateOne(entity *model.SchedulerCache) error {
|
|
//1.初始化链接
|
|
client := db.MgoDb()
|
|
//2.选择数据库,数据表
|
|
collect := client.Database(conf.DbConfig.Mongdbname).Collection("SchedulerCache")
|
|
|
|
new := &model.SchedulerCache{
|
|
TaskId: entity.TaskId,
|
|
WorkLineId: entity.WorkLineId,
|
|
Data: entity.Data,
|
|
CreateBy: entity.CreateBy,
|
|
CreateTime: entity.CreateTime,
|
|
}
|
|
update := bson.M{"$set": new}
|
|
_, err := collect.UpdateOne(context.Background(), bson.M{"taskId": new.TaskId}, update)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
}
|