wangchuanjin 1 gadu atpakaļ
vecāks
revīzija
a3a6281f2d
2 mainītis faili ar 32 papildinājumiem un 0 dzēšanām
  1. 26 0
      public/entity/base_ent_wait_empower.go
  2. 6 0
      public/service/power.go

+ 26 - 0
public/entity/base_ent_wait_empower.go

@@ -1,6 +1,8 @@
 package entity
 
 import (
+	"strings"
+
 	. "app.yhyue.com/moapp/jybase/common"
 	. "app.yhyue.com/moapp/jybase/date"
 	. "bp.jydev.jianyu360.cn/BaseService/resourceCenter/public/db"
@@ -27,6 +29,30 @@ func (b *base_ent_wait_empower) WaitEmpowers(appid, function_code string, ent_id
 	return JsonUnmarshal(list, &[]*base_ent_wait_empower{}).(*[]*base_ent_wait_empower)
 }
 
+//所有待授权记录
+func (b *base_ent_wait_empower) AllWaitEmpowers(appid string, ent_id int64) *[]*base_ent_wait_empower {
+	list := Mysql_BaseService.SelectBySql(`select * from base_ent_wait_empower where appid=? and ent_id=? and end_time>?`, appid, ent_id, NowFormat(Date_Full_Layout))
+	return JsonUnmarshal(list, &[]*base_ent_wait_empower{}).(*[]*base_ent_wait_empower)
+}
+
+//校验功能代码
+func (b *base_ent_wait_empower) CheckFunctionCode(appid, function_code string, ent_id int64) bool {
+	list := b.AllWaitEmpowers(appid, ent_id)
+	if list == nil {
+		return false
+	}
+	m := map[string]bool{}
+	for _, v := range *list {
+		m[v.Function_code] = true
+	}
+	for _, v := range strings.Split(function_code, ",") {
+		if !m[v] {
+			return false
+		}
+	}
+	return true
+}
+
 //是否全部授权
 func (b *base_ent_wait_empower) IsAllEmpower(appid, function_code string, ent_id int64) bool {
 	return Mysql_BaseService.CountBySql(`select count(1) as count from base_ent_wait_empower where appid=? and function_code=? and ent_id=? and end_time>? and empower_count=-1`, appid, function_code, ent_id, NowFormat(Date_Full_Layout)) > 0

+ 6 - 0
public/service/power.go

@@ -147,6 +147,8 @@ func ReEmpower(appid, function_code string, ent_id int64, ent_user_id []int64) (
 		return 0, errors.New("无效的参数ent_id")
 	} else if len(ent_user_id) == 0 {
 		return 0, errors.New("无效的参数ent_user_id")
+	} else if !Base_ent_wait_empower.CheckFunctionCode(appid, function_code, ent_id) {
+		return 0, errors.New("无效的参数function_code")
 	}
 	bewes := Base_ent_wait_empower.WaitEmpowers(appid, function_code, ent_id)
 	if bewes == nil {
@@ -186,6 +188,8 @@ func Empower(appid, function_code string, ent_id int64, ent_user_id []int64) (in
 		return 0, errors.New("无效的参数ent_id")
 	} else if len(ent_user_id) == 0 {
 		return 0, errors.New("无效的参数ent_user_id")
+	} else if !Base_ent_wait_empower.CheckFunctionCode(appid, function_code, ent_id) {
+		return 0, errors.New("无效的参数function_code")
 	}
 	if Base_ent_empower.Empower(appid, function_code, ent_id, ent_user_id) {
 		return 1, nil
@@ -210,6 +214,8 @@ func CancelEmpower(appid, function_code string, ent_id int64, ent_user_id []int6
 		return 0, errors.New("无效的参数ent_id")
 	} else if len(ent_user_id) == 0 {
 		return 0, errors.New("无效的参数ent_user_id")
+	} else if !Base_ent_wait_empower.CheckFunctionCode(appid, function_code, ent_id) {
+		return 0, errors.New("无效的参数function_code")
 	}
 	if Base_ent_empower.CancelEmpower(appid, function_code, ent_id, ent_user_id) {
 		return 1, nil