|
|
@@ -0,0 +1,157 @@ |
|
|
|
package db |
|
|
|
|
|
|
|
import ( |
|
|
|
"code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/db/model" |
|
|
|
zhios_order_relate_utils "code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/utils" |
|
|
|
zhios_order_relate_logx "code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/utils/logx" |
|
|
|
"errors" |
|
|
|
"fmt" |
|
|
|
"reflect" |
|
|
|
"xorm.io/xorm" |
|
|
|
) |
|
|
|
|
|
|
|
// BatchSelectBlockCoinPlatformGuidePriceForCoinRecords 批量查询数据 TODO::和下面的方法重复了,建议采用下面的 `BlockCoinPlatformGuidePriceForCoinRecordsFindByParams` 方法 |
|
|
|
func BatchSelectBlockCoinPlatformGuidePriceForCoinRecords(Db *xorm.Engine, params map[string]interface{}) (*[]model.BlockCoinPlatformGuidePriceForCoinRecords, error) { |
|
|
|
var BlockCoinPlatformGuidePriceForCoinRecordsData []model.BlockCoinPlatformGuidePriceForCoinRecords |
|
|
|
if err := Db.In(zhios_order_relate_utils.AnyToString(params["key"]), params["value"]). |
|
|
|
Find(&BlockCoinPlatformGuidePriceForCoinRecordsData); err != nil { |
|
|
|
return nil, zhios_order_relate_logx.Warn(err) |
|
|
|
} |
|
|
|
return &BlockCoinPlatformGuidePriceForCoinRecordsData, nil |
|
|
|
} |
|
|
|
|
|
|
|
// BlockCoinPlatformGuidePriceForCoinRecordsInsert 插入单条数据 |
|
|
|
func BlockCoinPlatformGuidePriceForCoinRecordsInsert(session *xorm.Session, BlockCoinPlatformGuidePriceForCoinRecords *model.BlockCoinPlatformGuidePriceForCoinRecords) (int, error) { |
|
|
|
_, err := session.InsertOne(BlockCoinPlatformGuidePriceForCoinRecords) |
|
|
|
if err != nil { |
|
|
|
return 0, err |
|
|
|
} |
|
|
|
return BlockCoinPlatformGuidePriceForCoinRecords.Id, nil |
|
|
|
} |
|
|
|
|
|
|
|
// BatchAddBlockCoinPlatformGuidePriceForCoinRecords 批量新增数据 |
|
|
|
func BatchAddBlockCoinPlatformGuidePriceForCoinRecords(Db *xorm.Engine, BlockCoinPlatformGuidePriceForCoinRecordsData []*model.BlockCoinPlatformGuidePriceForCoinRecords) (int64, error) { |
|
|
|
affected, err := Db.Insert(BlockCoinPlatformGuidePriceForCoinRecordsData) |
|
|
|
if err != nil { |
|
|
|
return 0, err |
|
|
|
} |
|
|
|
return affected, nil |
|
|
|
} |
|
|
|
|
|
|
|
func GetBlockCoinPlatformGuidePriceForCoinRecordsCount(Db *xorm.Engine) int { |
|
|
|
var BlockCoinPlatformGuidePriceForCoinRecords model.BlockCoinPlatformGuidePriceForCoinRecords |
|
|
|
session := Db.Where("") |
|
|
|
count, err := session.Count(&BlockCoinPlatformGuidePriceForCoinRecords) |
|
|
|
if err != nil { |
|
|
|
return 0 |
|
|
|
} |
|
|
|
return int(count) |
|
|
|
} |
|
|
|
|
|
|
|
// BlockCoinPlatformGuidePriceForCoinRecordsDelete 删除记录 |
|
|
|
func BlockCoinPlatformGuidePriceForCoinRecordsDelete(Db *xorm.Engine, id interface{}) (int64, error) { |
|
|
|
if reflect.TypeOf(id).Kind() == reflect.Slice { |
|
|
|
return Db.In("id", id).Delete(model.BlockCoinPlatformGuidePriceForCoinRecords{}) |
|
|
|
} else { |
|
|
|
return Db.Where("id = ?", id).Delete(model.BlockCoinPlatformGuidePriceForCoinRecords{}) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// BlockCoinPlatformGuidePriceForCoinRecordsUpdate 更新记录 |
|
|
|
func BlockCoinPlatformGuidePriceForCoinRecordsUpdate(session *xorm.Session, id interface{}, BlockCoinPlatformGuidePriceForCoinRecords *model.BlockCoinPlatformGuidePriceForCoinRecords, forceColums ...string) (int64, error) { |
|
|
|
var ( |
|
|
|
affected int64 |
|
|
|
err error |
|
|
|
) |
|
|
|
if forceColums != nil { |
|
|
|
affected, err = session.Where("id=?", id).Cols(forceColums...).Update(BlockCoinPlatformGuidePriceForCoinRecords) |
|
|
|
} else { |
|
|
|
affected, err = session.Where("id=?", id).Update(BlockCoinPlatformGuidePriceForCoinRecords) |
|
|
|
} |
|
|
|
if err != nil { |
|
|
|
return 0, err |
|
|
|
} |
|
|
|
return affected, nil |
|
|
|
} |
|
|
|
|
|
|
|
// BlockCoinPlatformGuidePriceForCoinRecordsGetOneByParams 通过传入的参数查询数据(单条) |
|
|
|
func BlockCoinPlatformGuidePriceForCoinRecordsGetOneByParams(session *xorm.Session, params map[string]interface{}) (*model.BlockCoinPlatformGuidePriceForCoinRecords, error) { |
|
|
|
var m model.BlockCoinPlatformGuidePriceForCoinRecords |
|
|
|
var query = fmt.Sprintf("%s =?", params["key"]) |
|
|
|
has, err := session.Where(query, params["value"]).Get(&m) |
|
|
|
if err != nil { |
|
|
|
return nil, zhios_order_relate_logx.Error(err) |
|
|
|
} |
|
|
|
if has == false { |
|
|
|
return nil, errors.New("未查询到相应的 block_star_chain 记录") |
|
|
|
} |
|
|
|
return &m, nil |
|
|
|
} |
|
|
|
|
|
|
|
// BlockCoinPlatformGuidePriceForCoinRecordsFindByParams 通过传入的参数查询数据(多条) |
|
|
|
func BlockCoinPlatformGuidePriceForCoinRecordsFindByParams(Db *xorm.Engine, params map[string]interface{}) (*[]model.BlockCoinPlatformGuidePriceForCoinRecords, error) { |
|
|
|
var m []model.BlockCoinPlatformGuidePriceForCoinRecords |
|
|
|
if params["value"] == nil { |
|
|
|
return nil, errors.New("参数有误") |
|
|
|
} |
|
|
|
if params["key"] == nil { |
|
|
|
//查询全部数据 |
|
|
|
err := Db.Find(&m) |
|
|
|
if err != nil { |
|
|
|
return nil, zhios_order_relate_logx.Error(err) |
|
|
|
} |
|
|
|
return &m, nil |
|
|
|
} else { |
|
|
|
if reflect.TypeOf(params["value"]).Kind() == reflect.Slice { |
|
|
|
//指定In查询 |
|
|
|
if err := Db.In(zhios_order_relate_utils.AnyToString(params["key"]), params["value"]).Find(&m); err != nil { |
|
|
|
return nil, zhios_order_relate_logx.Warn(err) |
|
|
|
} |
|
|
|
return &m, nil |
|
|
|
} else { |
|
|
|
var query = fmt.Sprintf("%s =?", params["key"]) |
|
|
|
err := Db.Where(query, params["value"]).Find(&m) |
|
|
|
if err != nil { |
|
|
|
return nil, zhios_order_relate_logx.Error(err) |
|
|
|
} |
|
|
|
return &m, nil |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
func BlockCoinPlatformGuidePriceForCoinRecordsFindByParamsByPage(Db *xorm.Engine, params map[string]interface{}, page, pageSize int) (*[]model.BlockCoinPlatformGuidePriceForCoinRecords, error) { |
|
|
|
var m []model.BlockCoinPlatformGuidePriceForCoinRecords |
|
|
|
if params["value"] == nil { |
|
|
|
return nil, errors.New("参数有误") |
|
|
|
} |
|
|
|
if page == 0 && pageSize == 0 { |
|
|
|
page = 1 |
|
|
|
pageSize = 10 |
|
|
|
} |
|
|
|
|
|
|
|
if params["key"] == nil { |
|
|
|
//查询全部数据 |
|
|
|
err := Db.Limit(pageSize, (page-1)*pageSize).Find(&m) |
|
|
|
if err != nil { |
|
|
|
return nil, zhios_order_relate_logx.Error(err) |
|
|
|
} |
|
|
|
return &m, nil |
|
|
|
} else { |
|
|
|
if reflect.TypeOf(params["value"]).Kind() == reflect.Slice { |
|
|
|
//指定In查询 |
|
|
|
if err := Db.In(zhios_order_relate_utils.AnyToString(params["key"]), params["value"]).Limit(pageSize, (page-1)*pageSize).Find(&m); err != nil { |
|
|
|
return nil, zhios_order_relate_logx.Warn(err) |
|
|
|
} |
|
|
|
return &m, nil |
|
|
|
} else { |
|
|
|
var query = fmt.Sprintf("%s =?", params["key"]) |
|
|
|
err := Db.Where(query, params["value"]).Limit(pageSize, (page-1)*pageSize).Find(&m) |
|
|
|
if err != nil { |
|
|
|
return nil, zhios_order_relate_logx.Error(err) |
|
|
|
} |
|
|
|
return &m, nil |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |