Bläddra i källkod

feat:修改判断

wangchuanjin 1 år sedan
förälder
incheckning
36a111a6d6
2 ändrade filer med 17 tillägg och 11 borttagningar
  1. 15 9
      public/entity/base_ent_empower.go
  2. 2 2
      public/service/power_test.go

+ 15 - 9
public/entity/base_ent_empower.go

@@ -60,14 +60,19 @@ func (b *base_ent_empower) HasEmpower(appid, function_code string, ent_id, ent_u
 //重新授权
 //重新授权
 func (b *base_ent_empower) ReEmpower(appid, function_code string, ent_id int64, ent_user_id []int64) bool {
 func (b *base_ent_empower) ReEmpower(appid, function_code string, ent_id int64, ent_user_id []int64) bool {
 	return Mysql_BaseService.ExecTx("重新授权", func(tx *sql.Tx) bool {
 	return Mysql_BaseService.ExecTx("重新授权", func(tx *sql.Tx) bool {
-		r1 := Mysql_BaseService.UpdateOrDeleteBySqlByTx(tx, `delete from base_ent_empower where appid=? and ent_id=? and function_code=?`, appid, ent_id, function_code)
+		args := []interface{}{appid, ent_id}
+		wh := []string{}
+		for _, v := range strings.Split(function_code, ",") {
+			wh = append(wh, "?")
+			args = append(args, v)
+		}
+		r1 := Mysql_BaseService.UpdateOrDeleteBySqlByTx(tx, `delete from base_ent_empower where appid=? and ent_id=? and function_code in (`+strings.Join(wh, ",")+`)`, args...)
+		nowFormat := NowFormat(Date_Full_Layout)
 		values := []interface{}{}
 		values := []interface{}{}
-		now := NowFormat(Date_Full_Layout)
 		for _, v := range ent_user_id {
 		for _, v := range ent_user_id {
-			if v <= 0 {
-				continue
+			for _, vv := range strings.Split(function_code, ",") {
+				values = append(values, appid, ent_id, v, vv, nowFormat)
 			}
 			}
-			values = append(values, appid, ent_id, v, function_code, now)
 		}
 		}
 		r2, r3 := int64(-1), int64(-1)
 		r2, r3 := int64(-1), int64(-1)
 		if len(values) > 0 {
 		if len(values) > 0 {
@@ -79,17 +84,18 @@ func (b *base_ent_empower) ReEmpower(appid, function_code string, ent_id int64,
 
 
 //授权
 //授权
 func (b *base_ent_empower) Empower(appid, function_code string, ent_id int64, ent_user_id []int64) bool {
 func (b *base_ent_empower) Empower(appid, function_code string, ent_id int64, ent_user_id []int64) bool {
-	b.CancelEmpower(appid, function_code, ent_id, ent_user_id)
 	fields := []string{"appid", "ent_id", "ent_user_id", "function_code", "create_time"}
 	fields := []string{"appid", "ent_id", "ent_user_id", "function_code", "create_time"}
 	nowFormat := NowFormat(Date_Full_Layout)
 	nowFormat := NowFormat(Date_Full_Layout)
 	values := []interface{}{}
 	values := []interface{}{}
+	functionCodes := strings.Split(function_code, ",")
 	for _, v := range ent_user_id {
 	for _, v := range ent_user_id {
-		for _, vv := range strings.Split(function_code, ",") {
-			values = append(values, appid, ent_id, Int64All(v), vv, nowFormat)
+		for _, vv := range functionCodes {
+			values = append(values, appid, ent_id, v, vv, nowFormat)
 		}
 		}
 	}
 	}
+	b.CancelEmpower(appid, function_code, ent_id, ent_user_id)
 	r1, _ := Mysql_BaseService.InsertBatch("base_ent_empower", fields, values)
 	r1, _ := Mysql_BaseService.InsertBatch("base_ent_empower", fields, values)
-	return r1 == int64(len(ent_user_id))
+	return r1 == int64(len(functionCodes))*int64(len(ent_user_id))
 }
 }
 
 
 //取消授权
 //取消授权

+ 2 - 2
public/service/power_test.go

@@ -44,13 +44,13 @@ func TestReEmpower(t *testing.T) {
 }
 }
 
 
 func TestEmpower(t *testing.T) {
 func TestEmpower(t *testing.T) {
-	v, err := Empower("10000", "bi_sj_yyszs", 1, []int64{123})
+	v, err := Empower("10000", "bi_dx_rcgl,bi_dx_shxs", 1, []int64{3870, 22})
 	assert.Nil(t, err)
 	assert.Nil(t, err)
 	assert.Equal(t, int64(1), v)
 	assert.Equal(t, int64(1), v)
 }
 }
 
 
 func TestCancelEmpower(t *testing.T) {
 func TestCancelEmpower(t *testing.T) {
-	v, err := CancelEmpower("10000", "znsj_kf_use", 14184, []int64{4271, 123})
+	v, err := CancelEmpower("10000", "bi_dx_rcgl,bi_dx_shxs", 1, []int64{3870})
 	assert.Nil(t, err)
 	assert.Nil(t, err)
 	assert.Equal(t, int64(1), v)
 	assert.Equal(t, int64(1), v)
 }
 }