infoService.go 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. package service
  2. import (
  3. "encoding/base64"
  4. "encoding/json"
  5. "app.yhyue.com/moapp/jybase/common"
  6. "app.yhyue.com/moapp/jybase/redis"
  7. "bp.jydev.jianyu360.cn/BaseService/biService/entity"
  8. "github.com/gogf/gf/v2/util/gconv"
  9. "github.com/tjfoc/gmsm/sm4"
  10. )
  11. type InfoService struct {
  12. }
  13. func (l *InfoService) Myinfo(sid string) []byte {
  14. infoMap := map[string]string{}
  15. info_i := redis.Get("session", sid)
  16. if info_i != nil {
  17. info_m, _ := info_i.(map[string]interface{})
  18. entNicheDis := common.Int64All(info_m["entNicheDis"])
  19. depIDArr := ""
  20. if entNicheDis > 0 {
  21. //查询所有部门标识
  22. entId := gconv.String(info_m["entId"])
  23. entDeptId := gconv.String(info_m["entDeptId"])
  24. deptArr := entity.JyMysql.SelectBySql("select GROUP_CONCAT(DISTINCT b.id) as depIDArr from entniche_department_parent a"+
  25. " INNER JOIN entniche_department b "+
  26. "on (b.ent_id=? and (b.id=? or (a.pid=? and a.id=b.id)))", entId, entDeptId, entDeptId)
  27. if len(*deptArr) > 0 {
  28. depIDArr = common.InterfaceToStr((*deptArr)[0]["depIDArr"])
  29. }
  30. }
  31. infoMap = map[string]string{
  32. "nickName": RsaEncrypt([]byte(gconv.String(info_m["s_nickname"]))),
  33. "entRole": RsaEncrypt([]byte(gconv.String(common.Int64All(info_m["entRole"])))),
  34. "entNicheDis": RsaEncrypt([]byte(gconv.String(entNicheDis))),
  35. "positionId": RsaEncrypt([]byte(gconv.String(info_m["positionId"]))),
  36. "accountId": RsaEncrypt([]byte(gconv.String(info_m["accountId"]))),
  37. "entAccountId": RsaEncrypt([]byte(gconv.String(common.Int64All(info_m["entAccountId"])))),
  38. "entId": RsaEncrypt([]byte(gconv.String(common.Int64All(info_m["entId"])))),
  39. "entName": RsaEncrypt([]byte(gconv.String(info_m["entName"]))),
  40. "entUserName": RsaEncrypt([]byte(gconv.String(info_m["entUserName"]))),
  41. "entUserId": RsaEncrypt([]byte(gconv.String(common.Int64All(info_m["entUserId"])))),
  42. "userId": RsaEncrypt([]byte(gconv.String(common.Int64All(info_m["base_user_id"])))),
  43. "entDeptId": RsaEncrypt([]byte(gconv.String(common.Int64All(info_m["entDeptId"])))),
  44. "entChildDept": RsaEncrypt([]byte(depIDArr)),
  45. }
  46. }
  47. infoByte, _ := json.Marshal(infoMap)
  48. return infoByte
  49. }
  50. // 加密
  51. func RsaEncrypt(data []byte) string {
  52. key := []byte(entity.PublicKey)
  53. //加密
  54. b, _ := sm4.Sm4Ecb(key, data, true)
  55. return base64.StdEncoding.EncodeToString(b)
  56. }