package Account import ( "ERP_user/logs" "github.com/beego/beego/v2/adapter/orm" menulibs "gogs.baozhida.cn/zoie/ERP_libs/Menu" powerlibs "gogs.baozhida.cn/zoie/ERP_libs/Power" "gogs.baozhida.cn/zoie/ERP_libs/lib" ) func init() { //注册模型 //orm.RegisterModel(new(powerlibs.Power)) } // 添加 func Add_Power(r powerlibs.Power) (id string, err error) { o := orm.NewOrm() powerDao := powerlibs.NewPower(o) _, err = powerDao.Add_Power(r) if err != nil { logs.Error(lib.FuncName(), err) return id, err } return r.T_id, err } // 获取 ById func Read_Power_ByT_id(T_id string) (r powerlibs.Power, err error) { o := orm.NewOrm() powerDao := powerlibs.NewPower(o) power, err := powerDao.Read_Power_ByT_id(T_id) if err != nil { logs.Error(lib.FuncName(), err) return r, err } return power, nil } // 修改 func Update_Power(r powerlibs.Power) (id int, err error) { o := orm.NewOrm() powerDao := powerlibs.NewPower(o) _, err = powerDao.Update_Power(r) if err != nil { logs.Error(lib.FuncName(), err) } id = r.Id APIDao := menulibs.NewAPI(o, redisCache_API) APIDao.Redis_API_DelK(r.T_id) return } // 删除 func Delete_Power(r powerlibs.Power) (id int, err error) { o := orm.NewOrm() powerDao := powerlibs.NewPower(o) _, err = powerDao.Delete_Power(r) if err != nil { logs.Error(lib.FuncName(), err) } id = r.Id APIDao := menulibs.NewAPI(o, redisCache_API) APIDao.Redis_API_DelK(r.T_id) return } // 获取列表 func Read_Power_List(T_name string, page int, page_z int) (r_ []powerlibs.Power_R, cnt int64) { o := orm.NewOrm() // 也可以直接使用 Model 结构体作为表名 powerDao := powerlibs.NewPower(o) r_, err := powerDao.Read_Power_List(T_name, page, page_z) if err != nil { logs.Error(lib.FuncName(), err) return } cnt, err = powerDao.Read_Power_Count(T_name) if err != nil { logs.Error(lib.FuncName(), err) return } return r_, cnt }