|
|
package BaseGlobalDao
|
|
|
|
|
|
import (
|
|
|
"dsBaseRpc/RpcService/BaseGlobal/BaseGlobalProto"
|
|
|
"dsBaseRpc/Utils/CommonUtil"
|
|
|
"dsBaseRpc/Utils/DbUtil"
|
|
|
"dsBaseRpc/Utils/SqlKit"
|
|
|
"dsBaseRpc/models"
|
|
|
"github.com/xormplus/builder"
|
|
|
)
|
|
|
|
|
|
var db = DbUtil.Engine
|
|
|
|
|
|
//增加
|
|
|
func AddBaseGlobal(model models.TBaseGlobal) (int64, error) {
|
|
|
return db.Insert(model)
|
|
|
}
|
|
|
|
|
|
//修改
|
|
|
func UpdateBaseGlobal(model models.TBaseGlobal, ForceUpdateFields []string) (int64, error) {
|
|
|
//1、清除Redis缓存
|
|
|
var ids = []string{model.GlobalId}
|
|
|
var selector = SqlKit.GetBean("t_base_global")
|
|
|
SqlKit.DeleteCacheByIds(ids, selector)
|
|
|
//2、计算本次操作,有哪些字段需要更新
|
|
|
NeedUpdateFields := CommonUtil.GetNeedUpdateFields(model)
|
|
|
//3、合并强制更新的字段
|
|
|
ForceUpdateFields = append(ForceUpdateFields, NeedUpdateFields...)
|
|
|
//4、去重
|
|
|
ForceUpdateFields = CommonUtil.RemoveDuplicatesAndEmpty(ForceUpdateFields)
|
|
|
//5、更新操作,强制更新这些列
|
|
|
affected, err := db.ID(model.GlobalId).Cols(ForceUpdateFields...).Update(model)
|
|
|
return affected, err
|
|
|
}
|
|
|
|
|
|
//分页查询
|
|
|
func PageBaseGlobal(in *BaseGlobalProto.QueryArg) ([]map[string]interface{}, int32, error) {
|
|
|
//接收传入参数
|
|
|
var limit = int(in.Limit)
|
|
|
var offset = int((in.Page - 1) * in.Limit)
|
|
|
var myBuilder = builder.Dialect(builder.MYSQL).Select("global_id").From("t_base_global")
|
|
|
myBuilder.Where(builder.Eq{"b_use": 1})
|
|
|
if in.GlobalTypeId > 0 {
|
|
|
myBuilder.And(builder.Eq{"global_type_id": in.GlobalTypeId})
|
|
|
}
|
|
|
//获取拼接完成的SQL语句
|
|
|
sql, _ := myBuilder.OrderBy("global_id asc").Limit(limit, offset).ToBoundSQL()
|
|
|
list, count, err := SqlKit.Query(sql)
|
|
|
return list, count, err
|
|
|
}
|
|
|
|
|
|
// 通过全局变量的代码获取全局变量的信息
|
|
|
func GetBaseGlobalByCodes(globalCodes []string) ([]map[string]interface{}, int32, error) {
|
|
|
var myBuilder = builder.Dialect(builder.MYSQL).Select("global_id").From("t_base_global")
|
|
|
myBuilder.Where(builder.Eq{"b_use": 1})
|
|
|
myBuilder.And(builder.In("global_code", globalCodes))
|
|
|
//获取拼接完成的SQL语句
|
|
|
sql, _ := myBuilder.ToBoundSQL()
|
|
|
list, count, err := SqlKit.Query(sql)
|
|
|
return list, count, err
|
|
|
}
|