123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- package services
- import (
- "errors"
- "eta/eta_bridge/models/eta"
- "eta/eta_bridge/models/response"
- "eta/eta_bridge/utils"
- "time"
- )
- // CreateEtaSession
- // @Description: 创建ETA会话session
- // @author: Roc
- // @datetime 2024-01-23 17:42:54
- // @param sysUser *eta.Admin
- // @return login *response.LoginResp
- // @return err error
- // @return errMsg string
- 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)
- //// 获取用户未过期的session, 避免过于频繁生成token
- //expired := time.Now().AddDate(0, 0, 1).Format(utils.FormatDateTime)
- //session, _ = eta.GetUserUnexpiredSysSession(sysUser.AdminName, expired)
- //if session != nil && session.AccessToken != "" {
- // token = session.AccessToken
- //} else {
- // 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
- // }
- //}
- 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
- }
- // 角色产品ID
- 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
- }
|