package company

import (
	"github.com/beego/beego/v2/client/orm"
	"hongze/hz_crm_api/utils"
	"time"
)

// WxUserOpLog 联系人操作日志表
type WxUserMoveLog struct {
	Id              int       `orm:"column(id);pk"`
	UserId          int       `description:"联系人id"`
	RealName        string    `description:"联系人姓名"`
	Mobile          string    `description:"当前手机号"`
	Email           string    `description:"当前邮箱"`
	CompanyId       int       `description:"当前客户id"`
	CompanyName     string    `description:"当前客户名称"`
	SysUserId       int       `description:"操作人ID"`
	SysUserRealName string    `description:"操作人姓名"`
	CompanyIdMove   int       `description:"移动后客户id"`
	CompanyNameMove string    `description:"移动后客户名称"`
	CreateTime      time.Time `description:"日志创建时间"`
}

// AddWxUserOpLog 联系人移动日志记录
func AddWxUserMoveLog(item *WxUserMoveLog) (err error) {
	o := orm.NewOrm()
	_, err = o.Insert(item)
	return
}

// 列表
func GetWxUserMoveLogListmByMobiles(mobiles []string) (items []*WxUserMoveLog, err error) {
	lenarr := len(mobiles)
	if lenarr == 0 {
		return
	}
	o := orm.NewOrm()
	sql := `SELECT mobile FROM wx_user_move_log   WHERE  mobile	 IN (` + utils.GetOrmInReplace(lenarr) + `)  GROUP BY mobile   `
	_, err = o.Raw(sql, mobiles).QueryRows(&items)
	return
}

// 列表
func GetWxUserMoveLogListmByMobile(mobile string) (items []*WxUserMoveLog, err error) {
	o := orm.NewOrm()
	sql := `SELECT * FROM wx_user_move_log   WHERE  mobile	 = ?  ORDER BY   id  ASC    `
	_, err = o.Raw(sql, mobile).QueryRows(&items)
	return
}

type WxUserMoveLogResp struct {
	UserName        string `description:"联系人姓名"`
	Mobile          string `description:"手机号"`
	Email           string `description:"邮箱地址"`
	CompanyId       int    `description:"当前客户id"`
	CompanyName     string `description:"当前客户名称"`
	CompanyIdMove   int    `description:"移动后客户id"`
	CompanyNameMove string `description:"移动后客户名称"`
	CreateTime      string `description:"日志创建时间"`
}

type WxUserMoveLogListResp struct {
	List []*WxUserMoveLogResp
}
