package Panel import ( "Cold_Api/conf" "Cold_Api/logs" "encoding/json" "fmt" "github.com/astaxie/beego/cache" _ "github.com/astaxie/beego/cache/redis" "github.com/beego/beego/v2/adapter/orm" _ "github.com/go-sql-driver/mysql" "strconv" "time" ) // 模板 type ConfiglibImg struct { Id int `orm:"column(ID);size(11);auto;pk"` T_img0 string `orm:"size(256);null"` // 图片 T_str0 string `orm:"size(256);null"` // 提示文本 } //INSERT INTO `ProductConfiglibImg` VALUES (24,NULL,'2022-02-25 14:02:59',NULL,'https://standardoss.baozhida.cn/ConfiglibImg/c1dc79540b042f71e5416a3789b184c3.png','https://standardoss.baozhida.cn/ConfiglibImg/7bbaad0dc661ba4268a71536a9f15e21.png','https://standardoss.baozhida.cn/ConfiglibImg/2ea1606f9891137d2054c416618bc70d.png','','',''),(25,NULL,'2022-02-25 14:03:26',NULL,'https://standardoss.baozhida.cn/ConfiglibImg/f55b91cd3044a0294d6137c3f3ecbc38.png','https://standardoss.baozhida.cn/ConfiglibImg/f495dcadfae1eced6a0ca43f3e1618a6.png','https://standardoss.baozhida.cn/ConfiglibImg/1bad9d66625ea51dff8447897f49db23.png','','',''),(26,NULL,'2022-02-25 14:03:42',NULL,'https://standardoss.baozhida.cn/ConfiglibImg/48fc784ae77fc126114ffe1b9f8184b2.png','https://standardoss.baozhida.cn/ConfiglibImg/904df97113f0b4d53bd81c1fc4bd73db.png','https://standardoss.baozhida.cn/ConfiglibImg/ff9beaa73eca8eab3b6430d4cb68ef19.png','','',''),(27,NULL,'2022-02-25 14:03:52',NULL,'https://standardoss.baozhida.cn/ConfiglibImg/bd9f7e8e754cc010d2d9dc0b991fc14e.png','https://standardoss.baozhida.cn/ConfiglibImg/83a5dee3cd0bd95597701ba9f68dc7c6.png','https://standardoss.baozhida.cn/ConfiglibImg/3b4b5df0ef9821bd24a7151ed9432399.png','','',''),(28,NULL,'2022-02-25 14:04:05',NULL,'https://standardoss.baozhida.cn/ConfiglibImg/8255f092d497fc5e9418d7474b711e4f.png','https://standardoss.baozhida.cn/ConfiglibImg/a4b5622d7be160607d42f0e28a853c57.png','https://standardoss.baozhida.cn/ConfiglibImg/f1cb2b0b3ab403c6b6291c0876f597c9.png','','',''),(29,NULL,'2022-02-25 14:04:24',NULL,'https://standardoss.baozhida.cn/ConfiglibImg/fd0512ebdc4f5291c1df41eaaadeeb52.png','https://standardoss.baozhida.cn/ConfiglibImg/f68d6259f10299d34d18cfe186af73b9.png','https://standardoss.baozhida.cn/ConfiglibImg/04894a064ba803cc4f1f260260a239bc.png','','',''),(30,NULL,'2022-02-25 14:04:43',NULL,'https://standardoss.baozhida.cn/ConfiglibImg/5201691226c58bfef93b7bfed2f16d52.png','https://standardoss.baozhida.cn/ConfiglibImg/c2d379d6b1c0c6a618d2e13f22a4d7f2.png','https://standardoss.baozhida.cn/ConfiglibImg/35a4c2e0f46f9f9ac848007d6fc96892.png','','',''),(31,NULL,'2022-02-25 14:05:04',NULL,'https://standardoss.baozhida.cn/ConfiglibImg/7379573b58871748150d28e42d311d4f.png','https://standardoss.baozhida.cn/ConfiglibImg/9f944f8ea4e4b3dd2b01e75279e00e6f.png','https://standardoss.baozhida.cn/ConfiglibImg/bc850ec94724a06386958898e63e686c.png','','',''),(32,NULL,'2022-02-25 14:05:15',NULL,'https://standardoss.baozhida.cn/ConfiglibImg/e6591afdcb2787afca86ff9960ee3429.png','https://standardoss.baozhida.cn/ConfiglibImg/98d5cca6ead7ef62798cf947a54b1e83.png','https://standardoss.baozhida.cn/ConfiglibImg/3c69f8ae5b80b91f02498ac13c611a8b.png','','',''),(33,NULL,'2022-02-25 14:05:36',NULL,'https://standardoss.baozhida.cn/ConfiglibImg/15d0bad6f07d133301aef897b0484762.png','https://standardoss.baozhida.cn/ConfiglibImg/4a607bc3abaea243ac3a1da4b3d8422a.png','https://standardoss.baozhida.cn/ConfiglibImg/8040f817850797a4b1c8f1d6770ecab3.png','','',''),(34,NULL,'2022-02-25 14:06:20',NULL,'https://standardoss.baozhida.cn/ConfiglibImg/eb9481fc92dc78f36463723da66d36bb.png','https://standardoss.baozhida.cn/ConfiglibImg/76992e069ac26f530ee2c3ff58f68e14.png','https://standardoss.baozhida.cn/ConfiglibImg/feb793592b619b4b0ce9718e1d411a85.png','','',''),(35,NULL,'2022-02-25 14:06:34',NULL,'https://standardoss.baozhida.cn/ConfiglibImg/34d5b40206473c6ef49892b5684c5823.png','https://standardoss.baozhida.cn/ConfiglibImg/3a00508f0208a72c4329c68f6d183dfc.png','https://standardoss.baozhida.cn/ConfiglibImg/1cd2da29d463cf39114c3dfa247208f9.png','','',''),(36,NULL,'2022-02-25 14:06:53',NULL,'https://standardoss.baozhida.cn/ConfiglibImg/ce1a1b1871f76f2cb7377a01553e1752.png','https://standardoss.baozhida.cn/ConfiglibImg/38eeb5d80894683ef20d82d9a7d60557.png','https://standardoss.baozhida.cn/ConfiglibImg/3ee36a04824209504584f5d941b75a08.png','','',''),(37,NULL,'2022-02-25 14:07:15',NULL,'https://standardoss.baozhida.cn/ConfiglibImg/a5f643c58aeeb3acf305c2e3ebc6435f.png','https://standardoss.baozhida.cn/ConfiglibImg/1028836d862a96710c77e266a7d6e323.png','https://standardoss.baozhida.cn/ConfiglibImg/6d80b06d35763ec84b987a5466e33715.png','','',''),(38,NULL,'2022-02-25 14:07:30',NULL,'https://standardoss.baozhida.cn/ConfiglibImg/e913af1ef9a70da88de3ba061ff8b3f6.png','https://standardoss.baozhida.cn/ConfiglibImg/833a06591b7565bf0ce89509eff8fec6.png','https://standardoss.baozhida.cn/ConfiglibImg/ea9855988e2947f1c476d94d0525555d.png','','',''),(39,NULL,'2022-02-25 14:07:49',NULL,'https://standardoss.baozhida.cn/ConfiglibImg/ba9d17552fe7e1ead8dbcf7e18ad3733.png','https://standardoss.baozhida.cn/ConfiglibImg/130be01a6ec111381664121605189b30.png','https://standardoss.baozhida.cn/ConfiglibImg/387aa67f2c324266cd236901d2b57059.png','','',''),(40,NULL,'2022-02-25 14:08:28',NULL,'https://standardoss.baozhida.cn/ConfiglibImg/3b8e34d532ca2dadf7ac62b94c2788c3.png','https://standardoss.baozhida.cn/ConfiglibImg/618509f6ff64a9c39e9934dc785c595e.png','https://standardoss.baozhida.cn/ConfiglibImg/94aa48db3f7ff87676c734a376c8e2eb.png','','',''),(41,NULL,'2022-02-25 14:12:33',NULL,'https://standardoss.baozhida.cn/ConfiglibImg/a59b83758221607750042793409d9362.png','https://standardoss.baozhida.cn/ConfiglibImg/8e921514d3d91d59ad8de835cca76e2b.png','https://standardoss.baozhida.cn/ConfiglibImg/7cab99390abe94575dfb6b336a718c4d.png','','',''); func (t *ConfiglibImg) TableName() string { return "ConfiglibImg" // 数据库名称 // ************** 替换 FormulaList ************** } var redisCache_ConfiglibImg cache.Cache func init() { //注册模型 orm.RegisterModel(new(ConfiglibImg)) config := fmt.Sprintf(`{"key":"%s","conn":"%s","dbNum":"%s","password":"%s"}`, "redis_"+"ConfiglibImg", conf.Redis_address, conf.Redis_dbNum, conf.Redis_password) logs.Println(config) var err error redisCache_ConfiglibImg, err = cache.NewCache("redis", config) if err != nil || redisCache_ConfiglibImg == nil { errMsg := "failed to init redis" logs.Println(errMsg, err) } } // ---------------- Redis ------------------- //Redis_Set(m.T_sn,m) // Redis 更新缓存 func Redis_ConfiglibImg_Set(key string, r ConfiglibImg) (err error) { //json序列化 str, err := json.Marshal(r) if err != nil { logs.Println(err) return } err = redisCache_ConfiglibImg.Put(key, str, 24*time.Hour) if err != nil { logs.Println("set key:", key, ",value:", str, err) } return } //if r,is :=Redis_Get(T_sn);is{ //return r,nil //} func Redis_ConfiglibImg_Get(key string) (r ConfiglibImg, is bool) { if !redisCache_ConfiglibImg.IsExist(key) { return r, false } v := redisCache_ConfiglibImg.Get(key) json.Unmarshal(v.([]byte), &r) return r, true } func Redis_ConfiglibImg_DelK(key string) (err error) { err = redisCache_ConfiglibImg.Delete(key) return } // ---------------- 特殊方法 ------------------- // 获取 ById func Read_ConfiglibImg_ById(id int) (r ConfiglibImg, is bool) { if r, is = Redis_ConfiglibImg_Get(strconv.Itoa(id)); is == true { return r, true } o := orm.NewOrm() r = ConfiglibImg{Id: id} err := o.Read(&r) // o.Read(&r,"Tokey") 如果不是 主键 就得指定字段名 if err != nil { logs.Println(err) return r, false } Redis_ConfiglibImg_Set(strconv.Itoa(id), r) return r, true } // 添加 func Add_ConfiglibImg(v ConfiglibImg) (id int64, is bool) { o := orm.NewOrm() id, err := o.Insert(&v) if err != nil { logs.Println(err) return 0, false } Redis_ConfiglibImg_Set(strconv.Itoa(v.Id), v) return id, true } // 删除 func Delete_ConfiglibImg_ById(v ConfiglibImg) bool { o := orm.NewOrm() if num, err := o.Delete(&v); err == nil { logs.Println("Number of records deleted in database:", num) } else { return false } Redis_ConfiglibImg_DelK(strconv.Itoa(v.Id)) return true } // 修改 func Update_ConfiglibImg_ById(m ConfiglibImg) bool { o := orm.NewOrm() v := ConfiglibImg{Id: m.Id} if err := o.Read(&v); err == nil { var num int64 v.T_img0 = m.T_img0 v.T_str0 = m.T_str0 if num, err = o.Update(&m, "T_img0", "T_str0"); err == nil { fmt.Println("Number of records updated in database:", num) } Redis_ConfiglibImg_Set(strconv.Itoa(v.Id), v) return true } return false } // 获取列表 func Read_ConfiglibImg_1(T_str0 string,page int, page_z int) (r []ConfiglibImg, cnt int64) { o := orm.NewOrm() // 也可以直接使用 Model 结构体作为表名 qs := o.QueryTable(new(ConfiglibImg)) var offset int64 if page <= 1 { offset = 0 } else { offset = int64((page - 1) * page_z) } qs.Limit(page_z, offset).Filter("T_str0__icontains",T_str0).OrderBy("-Id").All(&r) cnt, _ = qs.Count() return r, cnt }