package system

import (
	"github.com/beego/beego/v2/client/orm"
	"strings"
	"time"
)

type AdminItem struct {
	AdminId                 int    `description:"系统用户id"`
	AdminName               string `description:"系统用户名称"`
	RealName                string `description:"系统用户姓名"`
	Password                string
	LastUpdatedPasswordTime string `json:"-"`
	Enabled                 int    `description:"1:有效，0:禁用"`
	Email                   string `description:"系统用户邮箱"`
	LastLoginTime           string
	CreatedTime             time.Time
	LastUpdatedTime         string
	Role                    string `description:"系统用户角色"`
	Mobile                  string `description:"手机号"`
	RoleType                int    `description:"角色类型:1需要录入指标,0:不需要"`
	RoleId                  int    `description:"角色id"`
	RoleName                string `description:"角色名称"`
	RoleTypeCode            string `description:"角色编码"`
	DepartmentId            int    `description:"部门id"`
	DepartmentName          string `json:"-" description:"部门名称"`
	TeamId                  int    `description:"三级id"`
	GroupId                 int    `description:"分组id"`
	GroupName               string `json:"-" description:"分组名称"`
	Authority               int    `description:"管理权限，0：无，1：部门负责人，2：小组负责人,或者ficc销售主管，4:ficc销售组长"`
	Position                string `description:"职位"`
	DepartmentGroup         string `description:"部门分组"`
	LabelVal                int    `description:"标签:1:超级管理员，2：管理员，3：部门经理，4：组长，5：ficc销售主管"`
	ResearchGroupName       string `description:"研究方向分组名称"`
	Province                string `description:"省"`
	ProvinceCode            string `description:"省编码"`
	City                    string `description:"市"`
	CityCode                string `description:"市编码"`
	EmployeeId              string `description:"员工工号(钉钉/每刻报销)"`
}

func GetSysAdminByName(adminName string) (item *Admin, err error) {
	sql := `SELECT * FROM admin WHERE admin_name=? `
	o := orm.NewOrm()
	err = o.Raw(sql, adminName).QueryRow(&item)
	return
}

func GetSysAdminById(adminId int) (item *Admin, err error) {
	sql := `SELECT * FROM admin WHERE admin_id=? `
	o := orm.NewOrm()
	err = o.Raw(sql, adminId).QueryRow(&item)
	return
}

// GetSysAdminByIdSlice 根据账户id列表获取账户信息列表
func GetSysAdminByIdSlice(adminIdList []string) (items []*Admin, err error) {
	if len(adminIdList) <= 0 {
		return
	}
	sql := `SELECT * FROM admin WHERE admin_id in (` + strings.Join(adminIdList, ",") + `) `
	o := orm.NewOrm()
	_, err = o.Raw(sql).QueryRows(&items)
	return
}

func GetAdminByGroupId(groupId int) (items []*AdminItem, err error) {
	o := orm.NewOrm()
	sql := `SELECT * FROM admin WHERE group_id=? ORDER BY created_time DESC`
	_, err = o.Raw(sql, groupId).QueryRows(&items)
	return
}
