123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- package autoreply
-
- import (
- "strconv"
- "time"
- "wechat-conf/models"
- "wechat-conf/models/model"
- "wechat-conf/utils"
-
- "github.com/go-xorm/xorm"
- )
-
- // AutoreplyDAO 当前数据库操作对象
- type AutoreplyDAO struct {
- ctx *utils.Context
- db *xorm.Session
- }
-
- // NewAutoreplyDAO New Inst
- func NewAutoreplyDAO(ctx *utils.Context) *AutoreplyDAO {
- return &AutoreplyDAO{
- ctx: ctx,
- db: ctx.DB,
- }
- }
- func (m *AutoreplyDAO) GetAutoReplyList(orgId, autoType string, page, pagesize int) ([]model.TaAutoReply, error) {
- var autoreply []model.TaAutoReply
- sql := `SELECT
- *
- FROM
- ta_auto_reply
- WHERE
- org_id = '` + orgId + `'
- AND auto_type = '` + autoType + `'
- and status >`+ strconv.Itoa(models.STATUS_DEL)
- sql += ` order by create_date desc limit ` + strconv.Itoa((page-1)*pagesize) + `, ` + strconv.Itoa(pagesize)
- err := m.db.Sql(sql).Find(&autoreply)
- return autoreply, err
- }
- func (m *AutoreplyDAO) GetAutoReplyListCount(orgId, autoType string) (int, error) {
- var autoreply []model.TaAutoReply
- sql := `SELECT
- *
- FROM
- ta_auto_reply
- WHERE
- org_id = '` + orgId + `'
- AND auto_type = '` + autoType + `'`
- err := m.db.Sql(sql).Find(&autoreply)
- return len(autoreply), err
- }
- func (m *AutoreplyDAO) AddAutoReply(auto model.TaAutoReply) (*model.TaAutoReply, error) {
- auto.CreateDate = time.Now()
- auto.Status = models.STATUS_NORMAL
- auto.AutoReplyId = utils.GetGUID()
- _, err := m.db.Insert(auto)
- return &auto, err
- }
- func (m *AutoreplyDAO) AddKeyword(keyword model.TaAutoReplyKeywords) error {
- keyword.KeywordsId = utils.GetGUID()
- keyword.Status = models.STATUS_NORMAL
- _, err := m.db.Insert(keyword)
- return err
- }
- func (m *AutoreplyDAO) UpdateAutoRelpy(auto model.TaAutoReply) error {
- var cols = []string{
- "auto_type",
- "rule_name",
- "pair_type",
- "message_type",
- "message_paragraph",
- "message_img",
- "message_content",
- "keywords",
- }
- _, err := m.db.Cols(cols...).Where("auto_reply_id = ?", auto.AutoReplyId).Update(auto)
- return err
- }
- func (m *AutoreplyDAO) DeleteKeywords(autoReplyId string) error {
- _, err := m.db.Delete(&model.TaAutoReplyKeywords{AutoReplyId: autoReplyId})
- return err
- }
- func (m *AutoreplyDAO) DeleteAutoReply(autoReplyId string) error {
- var auto = model.TaAutoReply{
- AutoReplyId: autoReplyId,
- Status: models.STATUS_DEL,
- }
- var cols = []string{
- "status",
- }
- _, err := m.db.Cols(cols...).Where("auto_reply_id = ?", auto.AutoReplyId).Update(auto)
- return err
- }
- func (m *AutoreplyDAO) GetAutoReplyById(autoReplyId string) (*model.TaAutoReply, error) {
- var autoReply []model.TaAutoReply
- sql := `SELECT
- *
- FROM
- ta_auto_reply
- WHERE
- auto_reply_id = '` + autoReplyId + `'`
- err := m.db.Sql(sql).Find(&autoReply)
- if len(autoReply) > 0 {
- return &autoReply[0], err
- }
- return nil, err
- }
|