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