You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
156 lines
5.3 KiB
156 lines
5.3 KiB
|
4 years ago
|
package systemuser
|
||
|
|
|
||
|
|
import (
|
||
|
|
"strconv"
|
||
|
|
|
||
|
|
"github.com/flipped-aurora/gin-vue-admin/server/api/v1/assessment"
|
||
|
|
"github.com/flipped-aurora/gin-vue-admin/server/commonus"
|
||
|
|
"github.com/flipped-aurora/gin-vue-admin/server/global"
|
||
|
|
"github.com/flipped-aurora/gin-vue-admin/server/model/common/response"
|
||
|
|
"github.com/flipped-aurora/gin-vue-admin/server/model/systemuser"
|
||
|
|
"github.com/gin-gonic/gin"
|
||
|
|
)
|
||
|
|
|
||
|
|
//系统相关
|
||
|
|
func (s *SystemUserApi) Index(c *gin.Context) {
|
||
|
|
outPut := commonus.MapOut()
|
||
|
|
response.Result(0, outPut, "获取成功", c)
|
||
|
|
}
|
||
|
|
|
||
|
|
//管理员列表
|
||
|
|
func (s *SystemUserApi) AdminList(c *gin.Context) {
|
||
|
|
var requestData adminRequest
|
||
|
|
c.ShouldBindJSON(&requestData)
|
||
|
|
if requestData.PageSize == 0 {
|
||
|
|
requestData.PageSize = 20
|
||
|
|
}
|
||
|
|
if requestData.Page <= 0 {
|
||
|
|
requestData.Page = 1
|
||
|
|
}
|
||
|
|
offSetPage := commonus.CalculatePages(requestData.Page, requestData.PageSize)
|
||
|
|
gormDb := global.GVA_DB_Master.Model(&systemuser.SystemUser{}).Select("system_user.*,system_user_attribute.*").Joins("left join system_user_attribute on system_user.u_key = system_user_attribute.ua_id")
|
||
|
|
|
||
|
|
if requestData.GroupId != 0 {
|
||
|
|
gormDb = gormDb.Where("`u_group` = ?", requestData.GroupId)
|
||
|
|
}
|
||
|
|
|
||
|
|
if requestData.BranchFactoryId != 0 {
|
||
|
|
gormDb = gormDb.Where("`u_attribute` = ?", requestData.BranchFactoryId)
|
||
|
|
}
|
||
|
|
|
||
|
|
if requestData.RoleId != 0 {
|
||
|
|
gormDb = gormDb.Where("`u_role` = ?", requestData.RoleId)
|
||
|
|
}
|
||
|
|
|
||
|
|
if requestData.State != 0 {
|
||
|
|
gormDb = gormDb.Where("`u_set` = ?", requestData.State)
|
||
|
|
} else {
|
||
|
|
gormDb = gormDb.Where("`u_set` IN ?", []int{1, 2})
|
||
|
|
}
|
||
|
|
|
||
|
|
if requestData.UserName != "" {
|
||
|
|
gormDb = gormDb.Where("(`u_name` LIKE ? OR `ua_name` LIKE ?)", "%"+requestData.UserName+"%", "%"+requestData.UserName+"%")
|
||
|
|
}
|
||
|
|
var total int64
|
||
|
|
totalErr := gormDb.Count(&total).Error
|
||
|
|
if totalErr != nil {
|
||
|
|
total = 0
|
||
|
|
}
|
||
|
|
var systemAdminList []systemuser.SystemAdminDetails
|
||
|
|
systemAdminListerr := gormDb.Limit(requestData.PageSize).Offset(offSetPage).Order("u_id desc").Find(&systemAdminList).Error
|
||
|
|
if systemAdminListerr != nil {
|
||
|
|
response.Result(101, systemAdminListerr, "数据获取失败!", c)
|
||
|
|
return
|
||
|
|
}
|
||
|
|
var sysAdminList []adminOutInfo
|
||
|
|
for _, val := range systemAdminList {
|
||
|
|
var sysAdminInfo adminOutInfo
|
||
|
|
sysAdminInfo.Id = val.Id
|
||
|
|
sysAdminInfo.Name = val.Name
|
||
|
|
sysAdminInfo.PassWord = val.PassWord
|
||
|
|
sysAdminInfo.Role = val.Role
|
||
|
|
sysAdminInfo.State = val.State
|
||
|
|
sysAdminInfo.Attribute = val.Attribute
|
||
|
|
sysAdminInfo.Time = val.Time
|
||
|
|
sysAdminInfo.EiteTime = val.EiteTime
|
||
|
|
sysAdminInfo.Key = val.Key
|
||
|
|
sysAdminInfo.Group = val.Group
|
||
|
|
sysAdminInfo.Wand = val.Wand
|
||
|
|
sysAdminInfo.IdAttr = val.IdAttr
|
||
|
|
sysAdminInfo.NameAttr = val.NameAttr
|
||
|
|
sysAdminInfo.Tel = val.Tel
|
||
|
|
sysAdminInfo.TimeAttr = val.TimeAttr
|
||
|
|
|
||
|
|
isTrueGroup, groupCont := assessment.GetGroupCont(val.Group)
|
||
|
|
if isTrueGroup == true {
|
||
|
|
sysAdminInfo.GroupName = groupCont.Name
|
||
|
|
}
|
||
|
|
isTrueBranFact, branFactCont := assessment.GetBranchFactory(val.Attribute)
|
||
|
|
if isTrueBranFact == true {
|
||
|
|
sysAdminInfo.BranchFactoryName = branFactCont.Name
|
||
|
|
}
|
||
|
|
|
||
|
|
isTrueRole, adminRoleCont := GetAdminRoleInfo(val.Role)
|
||
|
|
if isTrueRole == true {
|
||
|
|
sysAdminInfo.RoleName = adminRoleCont.Title
|
||
|
|
sysAdminInfo.Jurisdiction = adminRoleCont.Jurisdiction
|
||
|
|
sysAdminInfo.MenuOper = adminRoleCont.MenuOper
|
||
|
|
sysAdminInfo.Wand = adminRoleCont.Wand
|
||
|
|
}
|
||
|
|
sysAdminInfo.KeyStr = strconv.FormatInt(val.Key, 10)
|
||
|
|
|
||
|
|
sysAdminList = append(sysAdminList, sysAdminInfo)
|
||
|
|
}
|
||
|
|
countSum := len(sysAdminList)
|
||
|
|
printData := commonus.OutPutList(total, int64(countSum), requestData.Page, requestData.PageSize, sysAdminList)
|
||
|
|
response.Result(0, printData, "查询成功!", c)
|
||
|
|
}
|
||
|
|
|
||
|
|
//获取管理员详细内容登录
|
||
|
|
func GetSysAdminLoginInfo(userName, userPwd string) (isTrue bool, sysAdminInfo adminOutInfo) {
|
||
|
|
isTrue = false
|
||
|
|
var md5JiaMi commonus.Md5Encryption
|
||
|
|
md5JiaMi.Md5EncryptionInit(userPwd)
|
||
|
|
md5Token := md5JiaMi.Md5EncryptionAlgorithm()
|
||
|
|
var userInfo systemuser.SystemAdminDetails
|
||
|
|
userErr := global.GVA_DB_Master.Model(&systemuser.SystemUser{}).Select("system_user.*,system_user_attribute.*").Joins("left join system_user_attribute on system_user.u_key = system_user_attribute.ua_id").Where("`u_name` = ? AND `u_password` = ?", userName, md5Token).First(&userInfo).Error
|
||
|
|
if userErr != nil {
|
||
|
|
return
|
||
|
|
}
|
||
|
|
sysAdminInfo.Id = userInfo.Id
|
||
|
|
sysAdminInfo.Name = userInfo.Name
|
||
|
|
sysAdminInfo.PassWord = userInfo.PassWord
|
||
|
|
sysAdminInfo.Role = userInfo.Role
|
||
|
|
sysAdminInfo.State = userInfo.State
|
||
|
|
sysAdminInfo.Attribute = userInfo.Attribute
|
||
|
|
sysAdminInfo.Time = userInfo.Time
|
||
|
|
sysAdminInfo.EiteTime = userInfo.EiteTime
|
||
|
|
sysAdminInfo.Key = userInfo.Key
|
||
|
|
sysAdminInfo.Group = userInfo.Group
|
||
|
|
sysAdminInfo.Wand = userInfo.Wand
|
||
|
|
sysAdminInfo.IdAttr = userInfo.IdAttr
|
||
|
|
sysAdminInfo.NameAttr = userInfo.NameAttr
|
||
|
|
sysAdminInfo.Tel = userInfo.Tel
|
||
|
|
sysAdminInfo.TimeAttr = userInfo.TimeAttr
|
||
|
|
|
||
|
|
isTrueGroup, groupCont := assessment.GetGroupCont(userInfo.Group)
|
||
|
|
if isTrueGroup == true {
|
||
|
|
sysAdminInfo.GroupName = groupCont.Name
|
||
|
|
}
|
||
|
|
isTrueBranFact, branFactCont := assessment.GetBranchFactory(userInfo.Attribute)
|
||
|
|
if isTrueBranFact == true {
|
||
|
|
sysAdminInfo.BranchFactoryName = branFactCont.Name
|
||
|
|
}
|
||
|
|
|
||
|
|
isTrueRole, adminRoleCont := GetAdminRoleInfo(userInfo.Role)
|
||
|
|
if isTrueRole == true {
|
||
|
|
sysAdminInfo.RoleName = adminRoleCont.Title
|
||
|
|
sysAdminInfo.Jurisdiction = adminRoleCont.Jurisdiction
|
||
|
|
sysAdminInfo.MenuOper = adminRoleCont.MenuOper
|
||
|
|
sysAdminInfo.Wand = adminRoleCont.Wand
|
||
|
|
}
|
||
|
|
sysAdminInfo.KeyStr = strconv.FormatInt(userInfo.Key, 10)
|
||
|
|
isTrue = true
|
||
|
|
return
|
||
|
|
}
|