PanellibImg.go 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. package Panel
  2. import (
  3. "Cold_Api/conf"
  4. "Cold_Api/logs"
  5. "encoding/json"
  6. "fmt"
  7. "github.com/astaxie/beego/cache"
  8. _ "github.com/astaxie/beego/cache/redis"
  9. "github.com/beego/beego/v2/adapter/orm"
  10. _ "github.com/go-sql-driver/mysql"
  11. "strconv"
  12. "time"
  13. )
  14. // 模板
  15. type ConfiglibImg struct {
  16. Id int `orm:"column(ID);size(11);auto;pk"`
  17. T_img0 string `orm:"size(256);null"` // 图片
  18. T_str0 string `orm:"size(256);null"` // 提示文本
  19. }
  20. //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','','','');
  21. func (t *ConfiglibImg) TableName() string {
  22. return "ConfiglibImg" // 数据库名称 // ************** 替换 FormulaList **************
  23. }
  24. var redisCache_ConfiglibImg cache.Cache
  25. func init() {
  26. //注册模型
  27. orm.RegisterModel(new(ConfiglibImg))
  28. config := fmt.Sprintf(`{"key":"%s","conn":"%s","dbNum":"%s","password":"%s"}`,
  29. "redis_"+"ConfiglibImg", conf.Redis_address, conf.Redis_dbNum, conf.Redis_password)
  30. logs.Println(config)
  31. var err error
  32. redisCache_ConfiglibImg, err = cache.NewCache("redis", config)
  33. if err != nil || redisCache_ConfiglibImg == nil {
  34. errMsg := "failed to init redis"
  35. logs.Println(errMsg, err)
  36. }
  37. }
  38. // ---------------- Redis -------------------
  39. //Redis_Set(m.T_sn,m) // Redis 更新缓存
  40. func Redis_ConfiglibImg_Set(key string, r ConfiglibImg) (err error) {
  41. //json序列化
  42. str, err := json.Marshal(r)
  43. if err != nil {
  44. logs.Println(err)
  45. return
  46. }
  47. err = redisCache_ConfiglibImg.Put(key, str, 24*time.Hour)
  48. if err != nil {
  49. logs.Println("set key:", key, ",value:", str, err)
  50. }
  51. return
  52. }
  53. //if r,is :=Redis_Get(T_sn);is{
  54. //return r,nil
  55. //}
  56. func Redis_ConfiglibImg_Get(key string) (r ConfiglibImg, is bool) {
  57. if !redisCache_ConfiglibImg.IsExist(key) {
  58. return r, false
  59. }
  60. v := redisCache_ConfiglibImg.Get(key)
  61. json.Unmarshal(v.([]byte), &r)
  62. return r, true
  63. }
  64. func Redis_ConfiglibImg_DelK(key string) (err error) {
  65. err = redisCache_ConfiglibImg.Delete(key)
  66. return
  67. }
  68. // ---------------- 特殊方法 -------------------
  69. // 获取 ById
  70. func Read_ConfiglibImg_ById(id int) (r ConfiglibImg, is bool) {
  71. if r, is = Redis_ConfiglibImg_Get(strconv.Itoa(id)); is == true {
  72. return r, true
  73. }
  74. o := orm.NewOrm()
  75. r = ConfiglibImg{Id: id}
  76. err := o.Read(&r) // o.Read(&r,"Tokey") 如果不是 主键 就得指定字段名
  77. if err != nil {
  78. logs.Println(err)
  79. return r, false
  80. }
  81. Redis_ConfiglibImg_Set(strconv.Itoa(id), r)
  82. return r, true
  83. }
  84. // 添加
  85. func Add_ConfiglibImg(v ConfiglibImg) (id int64, is bool) {
  86. o := orm.NewOrm()
  87. id, err := o.Insert(&v)
  88. if err != nil {
  89. logs.Println(err)
  90. return 0, false
  91. }
  92. Redis_ConfiglibImg_Set(strconv.Itoa(v.Id), v)
  93. return id, true
  94. }
  95. // 删除
  96. func Delete_ConfiglibImg_ById(v ConfiglibImg) bool {
  97. o := orm.NewOrm()
  98. if num, err := o.Delete(&v); err == nil {
  99. logs.Println("Number of records deleted in database:", num)
  100. } else {
  101. return false
  102. }
  103. Redis_ConfiglibImg_DelK(strconv.Itoa(v.Id))
  104. return true
  105. }
  106. // 修改
  107. func Update_ConfiglibImg_ById(m ConfiglibImg) bool {
  108. o := orm.NewOrm()
  109. v := ConfiglibImg{Id: m.Id}
  110. if err := o.Read(&v); err == nil {
  111. var num int64
  112. v.T_img0 = m.T_img0
  113. v.T_str0 = m.T_str0
  114. if num, err = o.Update(&m, "T_img0", "T_str0"); err == nil {
  115. fmt.Println("Number of records updated in database:", num)
  116. }
  117. Redis_ConfiglibImg_Set(strconv.Itoa(v.Id), v)
  118. return true
  119. }
  120. return false
  121. }
  122. // 获取列表
  123. func Read_ConfiglibImg_1(T_str0 string,page int, page_z int) (r []ConfiglibImg, cnt int64) {
  124. o := orm.NewOrm()
  125. // 也可以直接使用 Model 结构体作为表名
  126. qs := o.QueryTable(new(ConfiglibImg))
  127. var offset int64
  128. if page <= 1 {
  129. offset = 0
  130. } else {
  131. offset = int64((page - 1) * page_z)
  132. }
  133. qs.Limit(page_z, offset).Filter("T_str0__icontains",T_str0).OrderBy("-Id").All(&r)
  134. cnt, _ = qs.Count()
  135. return r, cnt
  136. }