base_ent_empower.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package entity
  2. import (
  3. . "app.yhyue.com/moapp/jybase/common"
  4. . "bp.jydev.jianyu360.cn/BaseService/resourceCenter/public/db"
  5. )
  6. var Base_ent_empower = base_ent_empower{}
  7. //企业授权表
  8. type base_ent_empower struct {
  9. Id int64
  10. Appid string
  11. Ent_id int64 //企业id
  12. Ent_user_id int64 //企业员工id
  13. Function_code string //功能代码
  14. }
  15. //授权记录
  16. func (b *base_ent_empower) FindMyEntId(appid, function_code string, ent_id int64) *[]*base_ent_empower {
  17. list := Mysql_BaseService.SelectBySql(`select * from base_ent_empower where appid=? and function_code=? and ent_id=?`, appid, function_code, ent_id)
  18. return JsonUnmarshal(list, &[]*base_ent_empower{}).(*[]*base_ent_empower)
  19. }
  20. //授权记录数量
  21. func (b *base_ent_empower) Count(appid, function_code string, ent_id int64) int64 {
  22. return Mysql_BaseService.CountBySql(`select count(1) as count from base_ent_empower where appid=? and function_code=? and ent_id=?`, appid, function_code, ent_id)
  23. }
  24. //是否授权
  25. func (b *base_ent_empower) HasEmpower(appid, function_code string, ent_id, ent_user_id int64) bool {
  26. empower := b.FindMyEntId(appid, function_code, ent_id)
  27. if empower != nil {
  28. if len(*empower) == 1 && (*empower)[0].Ent_user_id == 0 {
  29. return true
  30. } else {
  31. for _, vv := range *empower {
  32. if vv.Ent_id == ent_id && vv.Ent_user_id == ent_user_id {
  33. return true
  34. }
  35. }
  36. }
  37. }
  38. return false
  39. }