Procházet zdrojové kódy

同步管理员账号信息

xyxie před 10 měsíci
rodič
revize
f1759a02b4
3 změnil soubory, kde provedl 59 přidání a 10 odebrání
  1. 2 2
      controllers/admin.go
  2. 41 0
      models/system/admin.go
  3. 16 8
      services/admin.go

+ 2 - 2
controllers/admin.go

@@ -24,7 +24,7 @@ func (this *AdminController) Save() {
 		this.Data["json"] = br
 		this.ServeJSON()
 	}()
-	var req system.Admin
+	var req system.AddAdminReq
 	err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
 	if err != nil {
 		br.Msg = "参数解析异常!"
@@ -41,7 +41,7 @@ func (this *AdminController) Save() {
 		br.IsSendEmail = false
 		return
 	}
-	err, isSendEmail := services.AddOrUpdateAdmin(req)
+	err, isSendEmail := services.AddOrUpdateAdmin(&req)
 	if err != nil {
 		br.Msg = "新增或者更新用户失败"
 		br.ErrMsg = "新增或者更新用户失败, Err:" + err.Error()

+ 41 - 0
models/system/admin.go

@@ -67,6 +67,47 @@ type Admin struct {
 	BusinessCode              string    `description:"商家编码"`
 }
 
+type AddAdminReq struct {
+	AdminId                   int    `description:"系统用户id"`
+	AdminName                 string `description:"系统用户名称"`
+	AdminAvatar               string `description:"用户头像"`
+	RealName                  string `description:"系统用户姓名"`
+	Password                  string `json:"-"`
+	LastUpdatedPasswordTime   string `json:"-"`
+	Enabled                   int
+	Email                     string `description:"系统用户邮箱"`
+	LastLoginTime             string
+	CreatedTime               string
+	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               string `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-域用户"`
+	BusinessCode              string `description:"商家编码"`
+}
+
 // Update 更新用户基础信息
 func (item *Admin) Update(cols []string) (err error) {
 	o := orm.NewOrm()

+ 16 - 8
services/admin.go

@@ -2,6 +2,7 @@ package services
 
 import (
 	"eta/eta_forum_hub/models/system"
+	"eta/eta_forum_hub/services/alarm_msg"
 	"eta/eta_forum_hub/utils"
 	"fmt"
 	"strings"
@@ -9,20 +10,27 @@ import (
 )
 
 // 新增或者更新用户
-func AddOrUpdateAdmin(req system.Admin) (err error, isSendEmail bool) {
+func AddOrUpdateAdmin(req *system.AddAdminReq) (err error, isSendEmail bool) {
+	defer func() {
+		if err != nil {
+			utils.FileLog.Info("添加管理员账号失败, AddOrUpdateAdmin  Err: " + err.Error())
+			go alarm_msg.SendAlarmMsg("添加管理员账号失败, AddOrUpdateAdmin  Err: "+err.Error(), 3)
+		}
+	}()
 	isSendEmail = true
 	isAdd := true
 	admin := new(system.Admin)
-	admin, e := system.GetAdminByAdminName(req.AdminName)
+	adminInfo, e := system.GetAdminByAdminName(req.AdminName)
 	if e != nil {
 		if e.Error() != utils.ErrNoRow() {
 			err = fmt.Errorf("获取数据失败,%v", e)
 			return
 		}
 	}
-	if e == nil && admin.AdminId > 0 {
+	if e == nil && adminInfo.AdminId > 0 {
 		isAdd = false
-		if admin.BusinessCode != req.BusinessCode {
+		admin = adminInfo
+		if adminInfo.BusinessCode != req.BusinessCode {
 			err = fmt.Errorf("商户编码不同,不允许更新")
 			return
 		}
@@ -35,7 +43,7 @@ func AddOrUpdateAdmin(req system.Admin) (err error, isSendEmail bool) {
 		return
 	}
 	if req.Mobile != "" {
-		if isAdd || (!isAdd && req.Mobile != admin.Mobile) {
+		if isAdd || (!isAdd && req.Mobile != adminInfo.Mobile) {
 			if req.TelAreaCode == "86" {
 				if !utils.ValidateMobileFormatat(req.Mobile) {
 					err = fmt.Errorf("手机号格式有误, 请检查")
@@ -56,7 +64,7 @@ func AddOrUpdateAdmin(req system.Admin) (err error, isSendEmail bool) {
 
 	}
 	if req.Email != "" {
-		if isAdd || (!isAdd && req.Mobile != admin.Mobile) {
+		if isAdd || (!isAdd && req.Mobile != adminInfo.Mobile) {
 			if !utils.ValidateEmailFormatat(req.Email) {
 				err = fmt.Errorf("邮箱格式有误, 请检查")
 				return
@@ -81,8 +89,6 @@ func AddOrUpdateAdmin(req system.Admin) (err error, isSendEmail bool) {
 	admin.Password = req.Password
 	admin.LastUpdatedPasswordTime = time.Now().Format(utils.FormatDateTime)
 	admin.Enabled = req.Enabled
-	admin.LastLoginTime = time.Now().Format(utils.FormatDateTime)
-	admin.CreatedTime = time.Now()
 	admin.LastUpdatedTime = time.Now().Format(utils.FormatDateTime)
 	admin.Mobile = req.Mobile
 	admin.RoleType = req.RoleType
@@ -108,6 +114,8 @@ func AddOrUpdateAdmin(req system.Admin) (err error, isSendEmail bool) {
 	admin.IsLdap = req.IsLdap
 	admin.BusinessCode = req.BusinessCode
 	if isAdd {
+		admin.CreatedTime = time.Now()
+		admin.LastLoginTime = time.Now().Format(utils.FormatDateTime)
 		err = system.AddAdmin(admin)
 		if err != nil {
 			err = fmt.Errorf("新增失败,Err:%s", err.Error())