package services import ( "errors" "eta_gn/eta_bridge/models/eta" "eta_gn/eta_bridge/models/response" "eta_gn/eta_bridge/utils" "time" ) func CreateEtaSession(sysUser *eta.Admin) (login response.LoginResp, session *eta.SysSession, err error, errMsg string) { errMsg = `登录失败` login = response.LoginResp{} var token string account := utils.MD5(sysUser.AdminName) token = utils.GenToken(account) session = new(eta.SysSession) session.UserName = sysUser.AdminName session.SysUserId = sysUser.AdminId session.ExpiredTime = time.Now().AddDate(0, 0, 90) session.IsRemember = 1 session.CreatedTime = time.Now() session.LastUpdatedTime = time.Now() session.AccessToken = token if e := eta.AddSysSession(session); e != nil { errMsg = "新增session失败, err: " err = errors.New("新增session失败, err: " + e.Error()) return } login.Authorization = token login.Authorization = "authorization=" + token login.RealName = sysUser.RealName login.AdminId = sysUser.AdminId login.AdminName = sysUser.AdminName login.RoleName = sysUser.RoleName login.SysRoleTypeCode = sysUser.RoleTypeCode //系统角色编码 login.RoleTypeCode = sysUser.RoleTypeCode login.Authority = sysUser.Authority if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP { login.RoleTypeCode = utils.ROLE_TYPE_CODE_FICC_SELLER } if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_TEAM { login.RoleTypeCode = utils.ROLE_TYPE_CODE_FICC_SELLER } if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_DEPARTMENT { login.RoleTypeCode = utils.ROLE_TYPE_CODE_FICC_SELLER } if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP { login.RoleTypeCode = utils.ROLE_TYPE_CODE_RAI_SELLER } if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_DEPARTMENT { login.RoleTypeCode = utils.ROLE_TYPE_CODE_RAI_SELLER } if sysUser.RoleName == utils.ROLE_NAME_FICC_DIRECTOR { login.RoleTypeCode = utils.ROLE_TYPE_CODE_FICC_SELLER } productId := GetProductId(sysUser.RoleTypeCode) productIdName := map[int]string{ 0: "admin", utils.COMPANY_PRODUCT_FICC_ID: utils.COMPANY_PRODUCT_FICC_NAME, utils.COMPANY_PRODUCT_RAI_ID: utils.COMPANY_PRODUCT_RAI_NAME, } login.ProductName = productIdName[productId] return }