cbmsgmodel.go 932 B

1234567891011121314151617181920212223242526272829303132333435
  1. package model
  2. import (
  3. "fmt"
  4. "github.com/zeromicro/go-zero/core/stores/sqlx"
  5. )
  6. var _ CbMsgModel = (*customCbMsgModel)(nil)
  7. type (
  8. // CbMsgModel is an interface to be customized, add more methods here,
  9. // and implement the added methods in customCbMsgModel.
  10. CbMsgModel interface {
  11. cbMsgModel
  12. GetCustomerLastMsg(openKfid, externalUserid string) (CbMsg, error)
  13. }
  14. customCbMsgModel struct {
  15. *defaultCbMsgModel
  16. }
  17. )
  18. // NewCbMsgModel returns a model for the database table.
  19. func NewCbMsgModel(conn sqlx.SqlConn) CbMsgModel {
  20. return &customCbMsgModel{
  21. defaultCbMsgModel: newCbMsgModel(conn),
  22. }
  23. }
  24. func (c *customCbMsgModel) GetCustomerLastMsg(openKfid, externalUserid string) (msg CbMsg, err error) {
  25. query := fmt.Sprintf("select * from %s where id IN (select MAX(id) from %s where `open_kfid` = ? AND `external_userid` = ?)", c.table, c.table)
  26. err = c.conn.QueryRow(&msg, query, openKfid, externalUserid)
  27. return
  28. }