keyvalue.go 1.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. package keyvalue
  2. import (
  3. "strconv"
  4. "wechat-conf/models"
  5. "wechat-conf/models/model"
  6. "wechat-conf/utils"
  7. "github.com/astaxie/beego"
  8. "github.com/go-xorm/xorm"
  9. )
  10. // KeyvalueDAO 当前数据库操作对象
  11. type KeyvalueDAO struct {
  12. ctx *utils.Context
  13. db *xorm.Session
  14. }
  15. // NewKeyvalueDAO New Inst
  16. func NewKeyvalueDAO(ctx *utils.Context) *KeyvalueDAO {
  17. return &KeyvalueDAO{
  18. ctx: ctx,
  19. db: ctx.DB,
  20. }
  21. }
  22. func (m *KeyvalueDAO) GetValueByKey(key string) (*model.TaWechatKeyValue, error) {
  23. var keyvalue []model.TaWechatKeyValue
  24. sql := `SELECT
  25. *
  26. FROM
  27. ta_wechat_key_value
  28. WHERE
  29. key_id = '` + key + `'
  30. and status > ` + strconv.Itoa(models.STATUS_DEL)
  31. err := m.db.Sql(sql).Find(&keyvalue)
  32. beego.Info(sql)
  33. beego.Info("______________________这里是model key——————————————————————————————————")
  34. beego.Info(keyvalue)
  35. if len(keyvalue) > 0 {
  36. return &keyvalue[0], err
  37. }
  38. return nil, err
  39. }
  40. func (m *KeyvalueDAO) AddValueKey(valueKey model.TaWechatKeyValue) error {
  41. valueKey.Status = models.STATUS_NORMAL
  42. utils.LogInfo("↓↓↓↓_________________________↓↓↓↓keyId button(model)↓↓↓↓___________________↓↓↓↓")
  43. utils.LogInfo(valueKey.KeyId)
  44. _, err := m.db.Insert(valueKey)
  45. return err
  46. }
  47. func (m *KeyvalueDAO) DeleteByOrgId(orgId string) error {
  48. _, err := m.db.Delete(&model.TaWechatKeyValue{OrgId: orgId})
  49. return err
  50. }