123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197 |
- package system
- import (
- "context"
- "hongze/fms_api/global"
- "hongze/fms_api/models/base"
- "time"
- )
- // 管理员表
- type SysAdmin struct {
- AdminId uint64 `gorm:"primaryKey;column:admin_id" json:"admin_id"` //账号ID
- AdminName string `gorm:"column:admin_name" json:"admin_name"` //账号名
- AdminAvatar string `gorm:"column:admin_avatar" json:"admin_avatar"` //用户头像
- RealName string `gorm:"column:real_name" json:"real_name"` //真实姓名
- Password string `gorm:"column:password" json:"password"` //密码
- Enabled int8 `gorm:"column:enabled" json:"enabled"` //1:有效,0:禁用
- Email string `gorm:"column:email" json:"email"`
- LastLoginTime time.Time `gorm:"column:last_login_time" json:"last_login_time"` //最近登陆时间
- Mobile string `gorm:"column:mobile" json:"mobile"` //手机号
- DeptId int64 `gorm:"column:dept_id" json:"dept_id"` //部门id
- DisableTime time.Time `gorm:"column:disable_time" json:"disable_time"` //禁用时间
- RoleId int64 `gorm:"column:role_id" json:"role_id"` //角色ID
- Position string `gorm:"column:position" json:"position"` //职位
- Remark string `gorm:"column:remark" json:"remark"` //备注
- base.TimeBase
- }
- // TableName get sql table name.获取数据库表名
- func (a *SysAdmin) TableName() string {
- return "sys_admin"
- }
- // Add 新增
- func (a *SysAdmin) Add() (err error) {
- err = global.DEFAULT_MYSQL.Create(a).Error
- return
- }
- type SysAdminAddReq struct {
- AdminName string `json:"admin_name" binding:"required"` //账号名
- RealName string `json:"real_name" binding:"required"` //真实姓名
- Password string `json:"password" binding:"required"` //密码
- Enabled int8 `json:"enabled" binding:"oneof=0 1"` //账号状态:1:有效,0:禁用
- Email string `json:"email" binding:"omitempty,email"` //邮箱
- Mobile string `json:"mobile" binding:"required,number,len=11"` //手机号
- DeptId int64 `json:"dept_id" binding:"required,gte=1"` //部门id
- RoleId int64 `json:"role_id" binding:"gte=1"` //角色ID
- Position string `json:"position"` //职位
- Remark string `json:"remark"` //备注
- }
- type SysAdminEditReq struct {
- AdminId uint64 `json:"admin_id" binding:"required,gte=1"` //账号ID
- AdminName string `json:"admin_name" binding:"required"` //账号名
- RealName string `json:"real_name" binding:"required"` //真实姓名
- Enabled int8 `json:"enabled" binding:"oneof=0 1"` //账号状态:1:有效,0:禁用
- Email string `json:"email" binding:"omitempty,email"` //邮箱
- Mobile string `json:"mobile" binding:"required,number,len=11"` //手机号
- DeptId int64 `json:"dept_id" binding:"required,gte=1"` //部门id
- RoleId int64 `json:"role_id" binding:"gte=1"` //角色ID
- Position string `json:"position"` //职位
- Remark string `json:"remark"` //备注
- }
- func (a *SysAdmin) GetAdminByAdminName(adminName string) (item *SysAdmin, err error) {
- err = global.DEFAULT_MYSQL.Model(a).Where("admin_name = ?", adminName).First(&item).Error
- return
- }
- func (a *SysAdmin) GetAdminByMobile(mobile string) (item *SysAdmin, err error) {
- err = global.DEFAULT_MYSQL.Model(a).Where("mobile = ?", mobile).First(&item).Error
- return
- }
- // 修改
- func (a *SysAdmin) Update(updateCols []string) (err error) {
- err = global.DEFAULT_MYSQL.Model(a).Select(updateCols).Updates(a).Error
- return
- }
- func (a *SysAdmin) UpdateByCondition(condition string, pars []interface{}, updates map[string]interface{}) (err error) {
- err = global.DEFAULT_MYSQL.Model(a).Where(condition, pars...).Updates(updates).Error
- return
- }
- // SelectPage 分页查询
- func (a *SysAdmin) SelectPage(page base.IPage, condition string, pars []interface{}) (count int64, results []SysAdminListTmpItem, err error) {
- query := global.DEFAULT_MYSQL.WithContext(context.TODO()).Model(a).
- Select("sys_admin.*, r.role_name").
- Joins("Left JOIN sys_role r ON r.role_id = sys_admin.role_id").
- Where(condition, pars...)
- query.Count(&count)
- if len(page.GetOrderItemsString()) > 0 {
- query = query.Order(page.GetOrderItemsString())
- }
- err = query.Limit(int(page.GetPageSize())).Offset(int(page.Offset())).Find(&results).Error
- return
- }
- type SysAdminListReq struct {
- DeptId int64 `json:"dept_id" form:"dept_id"` //部门id
- KeyWord string `json:"key_word" form:"key_word"`
- Enabled string `json:"enabled" form:"enabled"` //-1全部,1:有效,0:禁用
- base.PageReq
- }
- type SysAdminListTmpItem struct {
- AdminId uint64 `json:"admin_id"` //账号id
- AdminName string `json:"admin_name"` //账号名
- RealName string `json:"real_name"` //真实姓名
- Enabled int8 `json:"enabled"` //1:有效,0:禁用
- Email string `json:"email"` //邮箱
- CreateTime time.Time `json:"create_time"` //创建时间
- ModifyTime time.Time `json:"modify_time"` //最后更新时间
- Mobile string `json:"mobile"` //手机号
- DeptId int64 `json:"dept_id"` //部门id
- RoleId int64 `json:"role_id"` //角色ID
- RoleName string `json:"role_name"` //角色名称
- DeptFullName string `json:"dept_full_name"` //部门全称
- Position string `json:"position"` //职位
- Remark string `json:"remark"` //备注
- }
- type SysAdminListItem struct {
- AdminId uint64 `json:"admin_id"` //账号id
- AdminName string `json:"admin_name"` //账号名
- RealName string `json:"real_name"` //真实姓名
- Enabled int8 `json:"enabled"` //1:有效,0:禁用
- Email string `json:"email"` //邮箱
- Mobile string `json:"mobile"` //手机号
- DeptId int64 `json:"dept_id"` //部门id
- RoleId int64 `json:"role_id"` //角色ID
- RoleName string `json:"role_name"` //角色名称
- DeptFullName string `json:"dept_full_name"` //部门全称
- CreateTime string `json:"create_time"` //创建时间
- ModifyTime string `json:"modify_time"` //最后更新时间
- Position string `json:"position"` //职位
- Remark string `json:"remark"` //备注
- }
- // GetAdminByAdminId 根据adminId获取用户信息
- func (a *SysAdmin) GetAdminByAdminId(adminId uint64) (item *SysAdmin, err error) {
- err = global.DEFAULT_MYSQL.Model(a).Where("admin_id = ? ", adminId).First(&item).Error
- return
- }
- type LoginReq struct {
- AdminName string `json:"admin_name" binding:"required"` //账号名
- Password string `json:"password" binding:"required"` //密码
- IsRemember bool `json:"is_remember"` //是否属于受信设备
- }
- type LoginResp struct {
- AdminId uint64 `json:"admin_id"` //账号id
- AdminName string `json:"admin_name"` //账号名
- RealName string `json:"real_name"` //真实姓名
- Token string `json:"token"` //登录token
- ChangePwd bool `json:"change_pwd"` //是否需要修改密码
- }
- type ModifyPwdReq struct {
- AdminId uint64 `json:"admin_id" binding:"required,gte=1"` //账号ID
- Pwd string `json:"pwd" binding:"required"` //原密码
- ConfirmPwd string `json:"confirm_pwd" binding:"required,eqcsfield=Pwd"` //新密码
- }
- type ModifyMyPwdReq struct {
- OldPwd string `json:"old_pwd" binding:"required"` //原密码
- NewPwd string `json:"new_pwd" binding:"required"` //新密码
- ConfirmPwd string `json:"confirm_pwd" binding:"required,eqcsfield=NewPwd"` //新密码确认
- }
- type ModifyMyInitPwdReq struct {
- NewPwd string `json:"new_pwd" binding:"required"` //新密码
- ConfirmPwd string `json:"confirm_pwd" binding:"required,eqcsfield=NewPwd"` //新密码确认
- }
- type SysAdminReq struct {
- AdminId uint64 `json:"admin_id" binding:"required,gte=1"` //账号ID
- }
- type SysAdminModifyEnabledReq struct {
- AdminId uint64 `json:"admin_id" binding:"required,gte=1"` //账号ID
- Enabled int8 `json:"enabled" binding:"oneof=0 1"` //1:有效,0:禁用
- }
- // 删除
- func (a *SysAdmin) Delete() (err error) {
- err = global.DEFAULT_MYSQL.Delete(a).Error
- return
- }
- func (a *SysAdmin) GetAdminListByCondition(condition string, pars []interface{}) (list []*SysAdmin, err error) {
- err = global.DEFAULT_MYSQL.WithContext(context.TODO()).Model(a).
- Where(condition, pars...).Order("admin_id desc").Find(&list).Error
- return
- }
|