...
|
...
|
@@ -3,10 +3,10 @@ package repository |
|
|
import (
|
|
|
"fmt"
|
|
|
"github.com/go-pg/pg/v10"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils"
|
|
|
|
|
|
"github.com/linmadan/egglib-go/persistent/pg/sqlbuilder"
|
|
|
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
|
|
|
"github.com/linmadan/egglib-go/utils/snowflake"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/pg/models"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/pg/transform"
|
...
|
...
|
@@ -17,18 +17,19 @@ type DeviceCollectionRepository struct { |
|
|
}
|
|
|
|
|
|
func (repository *DeviceCollectionRepository) nextIdentify() (int64, error) {
|
|
|
IdWorker, err := snowflake.NewIdWorker(1)
|
|
|
if err != nil {
|
|
|
return 0, err
|
|
|
}
|
|
|
id, err := IdWorker.NextId()
|
|
|
return id, err
|
|
|
//IdWorker, err := snowflake.NewIdWorker(1)
|
|
|
//if err != nil {
|
|
|
// return 0, err
|
|
|
//}
|
|
|
//id, err := IdWorker.NextId()
|
|
|
return utils.NewSnowflakeId()
|
|
|
}
|
|
|
func (repository *DeviceCollectionRepository) Save(deviceCollection *domain.DeviceCollection) (*domain.DeviceCollection, error) {
|
|
|
sqlBuildFields := []string{
|
|
|
"device_collection_id",
|
|
|
"work_shop_name",
|
|
|
"device_sn",
|
|
|
"device_type",
|
|
|
"startup_status",
|
|
|
"com_status",
|
|
|
"values",
|
...
|
...
|
@@ -36,7 +37,7 @@ func (repository *DeviceCollectionRepository) Save(deviceCollection *domain.Devi |
|
|
insertFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlBuildFields)
|
|
|
insertPlaceHoldersSnippet := sqlbuilder.SqlPlaceHoldersSnippet(sqlBuildFields)
|
|
|
returningFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlBuildFields)
|
|
|
updateFields := sqlbuilder.RemoveSqlFields(sqlBuildFields, "deviceCollection_id")
|
|
|
updateFields := sqlbuilder.RemoveSqlFields(sqlBuildFields, "device_collection_id")
|
|
|
updateFieldsSnippet := sqlbuilder.SqlUpdateFieldsSnippet(updateFields)
|
|
|
tx := repository.transactionContext.PgTx
|
|
|
if deviceCollection.Identify() == nil {
|
...
|
...
|
@@ -51,14 +52,16 @@ func (repository *DeviceCollectionRepository) Save(deviceCollection *domain.Devi |
|
|
&deviceCollection.DeviceCollectionId,
|
|
|
&deviceCollection.WorkShopName,
|
|
|
&deviceCollection.DeviceSn,
|
|
|
&deviceCollection.DeviceType,
|
|
|
&deviceCollection.StartupStatus,
|
|
|
&deviceCollection.ComStatus,
|
|
|
&deviceCollection.Values,
|
|
|
),
|
|
|
fmt.Sprintf("INSERT INTO device_collections (%s) VALUES (%s) RETURNING %s", insertFieldsSnippet, insertPlaceHoldersSnippet, returningFieldsSnippet),
|
|
|
fmt.Sprintf("INSERT INTO manufacture.device_collections (%s) VALUES (%s) RETURNING %s", insertFieldsSnippet, insertPlaceHoldersSnippet, returningFieldsSnippet),
|
|
|
deviceCollection.DeviceCollectionId,
|
|
|
deviceCollection.WorkShopName,
|
|
|
deviceCollection.DeviceSn,
|
|
|
deviceCollection.DeviceType,
|
|
|
deviceCollection.StartupStatus,
|
|
|
deviceCollection.ComStatus,
|
|
|
deviceCollection.Values,
|
...
|
...
|
@@ -71,14 +74,16 @@ func (repository *DeviceCollectionRepository) Save(deviceCollection *domain.Devi |
|
|
&deviceCollection.DeviceCollectionId,
|
|
|
&deviceCollection.WorkShopName,
|
|
|
&deviceCollection.DeviceSn,
|
|
|
&deviceCollection.DeviceType,
|
|
|
&deviceCollection.StartupStatus,
|
|
|
&deviceCollection.ComStatus,
|
|
|
&deviceCollection.Values,
|
|
|
),
|
|
|
fmt.Sprintf("UPDATE device_collections SET %s WHERE device_collection_id=? RETURNING %s", updateFieldsSnippet, returningFieldsSnippet),
|
|
|
deviceCollection.DeviceCollectionId,
|
|
|
fmt.Sprintf("UPDATE manufacture.device_collections SET %s WHERE device_collection_id=? RETURNING %s", updateFieldsSnippet, returningFieldsSnippet),
|
|
|
//deviceCollection.DeviceCollectionId,
|
|
|
deviceCollection.WorkShopName,
|
|
|
deviceCollection.DeviceSn,
|
|
|
deviceCollection.DeviceType,
|
|
|
deviceCollection.StartupStatus,
|
|
|
deviceCollection.ComStatus,
|
|
|
deviceCollection.Values,
|
...
|
...
|
@@ -123,6 +128,12 @@ func (repository *DeviceCollectionRepository) Find(queryOptions map[string]inter |
|
|
query := sqlbuilder.BuildQuery(tx.Model(&deviceCollectionModels), queryOptions)
|
|
|
query.SetOffsetAndLimit(20)
|
|
|
query.SetOrderDirect("device_collection_id", "DESC")
|
|
|
if deviceType,ok := queryOptions["deviceType"];ok && deviceType != "" {
|
|
|
query.SetWhereByQueryOption("device_type = ?", "deviceType")
|
|
|
}
|
|
|
if workShopName,ok := queryOptions["workShopName"];ok && workShopName.(string) != "" {
|
|
|
query.SetWhereByQueryOption("work_shop_name = ?", "workShopName")
|
|
|
}
|
|
|
if count, err := query.SelectAndCount(); err != nil {
|
|
|
return 0, deviceCollections, err
|
|
|
} else {
|
...
|
...
|
|