123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192 |
- package system
- import (
- "eta_gn/eta_api/global"
- "eta_gn/eta_api/utils"
- "fmt"
- "strings"
- "time"
- )
- type LoginReq struct {
- Username string `description:"账号"`
- Password string `description:"密码"`
- IsRemember bool `description:"是否属于受信设备"`
- }
- type LoginResp struct {
- Authorization string
- AdminName string `description:"系统用户名称"`
- RealName string `description:"系统用户姓名"`
- RoleName string `description:"角色名称"`
- RoleTypeCode string `description:"角色类型编码"`
- SysRoleTypeCode string `description:"角色类型编码"`
- AdminId int `description:"系统用户id"`
- ProductName string `description:"产品名称:admin,ficc,权益"`
- Authority int `description:"管理权限,0:无,1:部门负责人,2:小组负责人,或者ficc销售主管,4:ficc销售组长"`
- }
- type Admin struct {
- //AdminId int `grm:"column:admin_id;identity:true" description:"系统用户id"`
- AdminId int `gorm:"primaryKey;autoIncrement;column:admin_id"`
- AdminName string `gorm:"column:admin_name" description:"系统用户名称"`
- AdminAvatar string `grom:"admin_avatar" description:"用户头像"`
- RealName string `grom:"real_name" description:"系统用户姓名"`
- Password string `json:"-"`
- LastUpdatedPasswordTime string `json:"-"`
- Enabled int `gorm:"column:enabled"`
- Email string `gorm:"column:email" description:"系统用户邮箱"`
- LastLoginTime string
- CreatedTime time.Time
- LastUpdatedTime string
- Role string `gorm:"column:role" description:"系统用户角色"`
- Mobile string `gorm:"column:mobile" description:"手机号"`
- RoleType int `gorm:"role_type" description:"角色类型:1需要录入指标,0:不需要"`
- RoleId int `gorm:"role_id" description:"角色ID"`
- RoleName string `gorm:"column:role_name" description:"角色名称"`
- RoleTypeCode string `gorm:"column:role_type_code" description:"角色类型编码"`
- DepartmentId int `gorm:"column:department_id" description:"部门id"`
- DepartmentName string `gorm:"column:department_name" description:"部门名称"`
- GroupId int `gorm:"column:group_id" description:"分组id"`
- GroupName string `gorm:"column:group_name" description:"分组名称"`
- Authority int `gorm:"column:authority" description:"管理权限,0:无,1:部门负责人,2:小组负责人,或者ficc销售主管,3:超级管理员,4:ficc销售组长"`
- Position string `gorm:"column:position" description:"职位"`
- DisableTime time.Time `gorm:"column:disable_time" description:"禁用时间"`
- ChartPermission int8 `gorm:"column:chart_permission" description:"图表权限id"`
- OpenId string `gorm:"column:open_id" description:"国能部门公众号的openid"`
- UnionId string `gorm:"column:union_id" description:"微信公众平台唯一标识"`
- EdbPermission int8 `gorm:"column:edb_permission" description:"指标库操作权限,0:只能操作 自己的,1:所有指标可操作"`
- MysteelChemicalPermission int8 `gorm:"column:mysteel_chemical_permission" description:"钢联化工指标操作权限,0:只能操作 自己的,1:所有指标可操作"`
- PredictEdbPermission int8 `gorm:"column:predict_edb_permission" description:"预测指标库操作权限,0:只能操作 自己的,1:所有预测指标可操作"`
- Province string `gorm:"column:province" description:"省"`
- ProvinceCode string `gorm:"column:province_code" description:"省编码"`
- City string `gorm:"column:city" description:"市"`
- CityCode string `gorm:"column:city_code" description:"市编码"`
- EmployeeId string `gorm:"column:employee_id" description:"员工工号(钉钉/每刻报销)"`
- TelAreaCode string `gorm:"column:tel_area_code" description:"手机区号"`
- IsLdap int `gorm:"column:is_ldap" description:"是否为域用户:0-系统账户;1-域用户"`
- }
- // Update 更新用户基础信息
- func (item *Admin) Update(cols []string) (err error) {
- err = global.DEFAULT_DmSQL.Select(cols).Updates(*item).Error
- return
- }
- func CheckSysUser(userName, password string) (item *Admin, err error) {
- sql := ` SELECT a.*,b.role_type_code FROM "admin" AS a
- INNER JOIN sys_role AS b ON a.role_id=b.role_id WHERE a.admin_name=? AND a.password=? LIMIT 1`
- err = global.DEFAULT_DmSQL.Raw(sql, userName, password).First(&item).Error
- return
- }
- func GetSysUserById(sysUserId int) (item *Admin, err error) {
- sql := `SELECT * FROM "admin" WHERE admin_id=? LIMIT 1`
- err = global.DEFAULT_DmSQL.Raw(sql, sysUserId).First(&item).Error
- return
- }
- func ModifyPwd(sysUserId int, newPwd string) (err error) {
- sql := `UPDATE "admin" SET password=?,last_updated_time=NOW() WHERE admin_id=? `
- err = global.DEFAULT_DmSQL.Exec(sql, newPwd, sysUserId).Error
- return
- }
- type ModifyPwdReq struct {
- OldPwd string `description:"旧密码"`
- NewPwd string `description:"新密码"`
- }
- // AdminWxUserRelation 管理员-微信用户关联
- type AdminWxUserRelation struct {
- AdminId int `json:"admin_id"`
- AdminName string `json:"admin_name"`
- RealName string `json:"real_name"`
- UserId int `json:"user_id"`
- }
- // GetAdminListByIdList 根据用户id列表获取系统用户列表
- func GetAdminListByIdList(idList []int) (items []*Admin, err error) {
- lenNum := len(idList)
- if lenNum <= 0 {
- return
- }
- sql := `SELECT * FROM "admin" WHERE admin_id in (` + utils.GetOrmInReplace(lenNum) + `) and enabled=1 `
- err = global.DEFAULT_DmSQL.Raw(sql, idList).Find(&items).Error
- return
- }
- // GetAdminListByIdListWithoutEnable 根据用户id列表获取系统用户列表
- func GetAdminListByIdListWithoutEnable(idList []int) (items []*Admin, err error) {
- lenNum := len(idList)
- if lenNum <= 0 {
- return
- }
- sql := `SELECT * FROM "admin" WHERE admin_id in (` + utils.GetOrmInReplace(lenNum) + `) `
- err = global.DEFAULT_DmSQL.Raw(sql, idList).Find(&items).Error
- return
- }
- func (item *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.DEFAULT_DmSQL.Raw(sql, pars...).Scan(&count).Error
- return
- }
- func (item *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.DEFAULT_DmSQL.Raw(sql, pars...).Find(&items).Error
- return
- }
- // GetSysUserByMobile 手机号获取用户
- func GetSysUserByMobile(mobile string) (item *Admin, err error) {
- sql := `SELECT
- a.*, b.role_type_code
- FROM
- "admin" AS a
- INNER JOIN sys_role AS b ON a.role_id = b.role_id
- WHERE
- a.mobile = ?
- LIMIT 1`
- err = global.DEFAULT_DmSQL.Raw(sql, mobile).First(&item).Error
- return
- }
- // GetSysUserByEmail 邮箱获取用户
- func GetSysUserByEmail(email string) (item *Admin, err error) {
- sql := `SELECT
- a.*, b.role_type_code
- FROM
- "admin" AS a
- INNER JOIN sys_role AS b ON a.role_id = b.role_id
- WHERE
- a.email = ?
- LIMIT 1`
- err = global.DEFAULT_DmSQL.Raw(sql, email).First(&item).Error
- return
- }
- // GetSysUserByAdminName 账号获取用户
- func GetSysUserByAdminName(adminName string) (item *Admin, err error) {
- o := global.DEFAULT_DmSQL
- sql := `SELECT
- a.*, b.role_type_code
- FROM
- "admin" AS a
- INNER JOIN sys_role AS b ON a.role_id = b.role_id
- WHERE
- a.admin_name = ?
- LIMIT 1`
- err = o.Raw(sql, adminName).Find(&item).Error
- return
- }
|