package models import ( "eta_gn/eta_report/global" "fmt" "strings" "time" ) type Admin struct { AdminId int `gorm:"primaryKey;autoIncrement;column:admin_id"` AdminName string `description:"系统用户名称"` AdminAvatar string `description:"用户头像"` RealName string `description:"系统用户姓名"` Password string `json:"-"` LastUpdatedPasswordTime string `json:"-"` Enabled int 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 `description:"部门名称"` GroupId int `description:"分组id"` GroupName string `description:"分组名称"` Authority int `description:"管理权限,0:无,1:部门负责人,2:小组负责人,或者ficc销售主管,3:超级管理员,4:ficc销售组长"` Position string `description:"职位"` DisableTime time.Time `description:"禁用时间"` ChartPermission int8 `description:"图表权限id"` OpenId string `description:"国能部门公众号的openid"` UnionId string `description:"微信公众平台唯一标识"` EdbPermission int8 `description:"指标库操作权限,0:只能操作 自己的,1:所有指标可操作"` MysteelChemicalPermission int8 `description:"钢联化工指标操作权限,0:只能操作 自己的,1:所有指标可操作"` PredictEdbPermission int8 `description:"预测指标库操作权限,0:只能操作 自己的,1:所有预测指标可操作"` Province string `description:"省"` ProvinceCode string `description:"省编码"` City string `description:"市"` CityCode string `description:"市编码"` EmployeeId string `description:"员工工号(钉钉/每刻报销)"` TelAreaCode string `description:"手机区号"` IsLdap int `description:"是否为域用户:0-系统账户;1-域用户"` OutId string `description:"外部ID"` } func (m *Admin) TableName() string { return "admin" } func (m *Admin) GetAdminByOutId(outId string) (item *Admin, err error) { sql := fmt.Sprintf(`SELECT * FROM "admin" WHERE %s = ? LIMIT 1`, "out_id") err = global.DmSQL["eta"].Raw(sql, outId).First(&item).Error return } func (m *Admin) GetItemById(id int) (item *Admin, err error) { sql := fmt.Sprintf(`SELECT * FROM "admin" WHERE %s = ? LIMIT 1`, "admin_id") err = global.DmSQL["eta"].Raw(sql, id).First(&item).Error return } func (m *Admin) GetItemByCondition(condition string, pars []interface{}, orderRule string) (item *Admin, err error) { order := `` if orderRule != "" { order = ` ORDER BY ` + orderRule } sql := fmt.Sprintf(`SELECT * FROM "admin" WHERE 1=1 %s %s LIMIT 1`, condition, order) err = global.DmSQL["eta"].Raw(sql, pars...).First(&item).Error return } func (m *Admin) GetCountByCondition(condition string, pars []interface{}) (count int, err error) { sql := fmt.Sprintf(`SELECT COUNT(1) FROM "admin" WHERE 1=1 %s`, condition) err = global.DmSQL["eta"].Raw(sql, pars...).Scan(&count).Error return } func (m *Admin) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*Admin, err error) { fields := strings.Join(fieldArr, ",") if len(fieldArr) == 0 { fields = `*` } order := `ORDER BY created_time DESC` if orderRule != "" { order = ` ORDER BY ` + orderRule } sql := fmt.Sprintf(`SELECT %s FROM "admin" WHERE 1=1 %s %s`, fields, condition, order) err = global.DmSQL["eta"].Raw(sql, pars...).Find(&items).Error return }