Przeglądaj źródła

feat:授权数量校验

wangchuanjin 1 rok temu
rodzic
commit
c30b5ad3c8

+ 2 - 2
public/entity/base_ent_empower.go

@@ -145,8 +145,8 @@ func (b *base_ent_empower) CheckEmpowerCount(tx *sql.Tx, appid string, function_
 		}
 	}
 	c := map[string]int64{}
-	list := Mysql_BaseService.SelectBySqlByTx(tx, `SELECT function_code,SUM(1) AS SUM FROM base_ent_empower WHERE appid=? and ent_id=? GROUP BY function_code`, appid, ent_id)
-	if list != nil {
+	list := Mysql_BaseService.SelectBySqlByTx(tx, `SELECT function_code,SUM(1) AS sum FROM base_ent_empower WHERE appid=? and ent_id=? GROUP BY function_code`, appid, ent_id)
+	if list == nil {
 		return -3, errors.New(fmt.Sprintf("企业%d查询已授权数量失败", ent_id))
 	}
 	for _, v := range *list {

+ 20 - 6
public/service/power.go

@@ -183,10 +183,18 @@ func ReEmpower(appid string, function_code []string, ent_id int64, ent_user_id [
 	} else if status, err := Base_ent_wait_empower.CheckFunctionCode(appid, function_code, ent_id); err != nil {
 		return status, err
 	}
-	if Base_ent_empower.ReEmpower(appid, function_code, ent_id, ent_user_id) {
-		return 1, nil
+	var err error
+	var status int64
+	if Mysql_BaseService.ExecTx("先把有权限的人清空,再把权益授权给新的人", func(tx *sql.Tx) bool {
+		ok1 := Base_ent_empower.ReEmpower(appid, function_code, ent_id, ent_user_id)
+		if status, err = Base_ent_empower.CheckEmpowerCount(tx, appid, function_code, ent_id); err != nil {
+			return false
+		}
+		return ok1
+	}) {
+		status = 1
 	}
-	return 0, nil
+	return status, err
 }
 
 /*
@@ -247,13 +255,19 @@ func Empower(appid string, function_code []string, ent_id int64, ent_user_id []i
 	} else if status, err := Base_ent_wait_empower.CheckFunctionCode(appid, function_code, ent_id); err != nil {
 		return status, err
 	}
+	var err error
+	var status int64
 	if Mysql_BaseService.ExecTx("授权", func(tx *sql.Tx) bool {
 		Base_ent_empower.CancelEmpower(tx, appid, function_code, ent_id, ent_user_id)
-		return Base_ent_empower.Empower(tx, appid, function_code, ent_id, ent_user_id)
+		ok1 := Base_ent_empower.Empower(tx, appid, function_code, ent_id, ent_user_id)
+		if status, err = Base_ent_empower.CheckEmpowerCount(tx, appid, function_code, ent_id); err != nil {
+			return false
+		}
+		return ok1
 	}) {
-		return 1, nil
+		status = 1
 	}
-	return 0, nil
+	return status, err
 }
 
 /*

+ 6 - 5
public/service/power_test.go

@@ -34,8 +34,8 @@ func TestHasPowers(t *testing.T) {
 	t.Log(powers)
 }
 
-func TestReEmpower(t *testing.T) {
-	v, err := ReEmpower("10000", []string{"bi_dx_yjtj", "bi_dx_zxdx", "bi_dx_rcgl", "bi_dx_wjsgjkh", "bi_dx_shxs", "bi_dx_xszl"}, 1, []int64{3870})
+func TestCfReEmpower(t *testing.T) {
+	v, err := ReEmpower("10000", []string{"bi_dx_yjtj", "bi_dx_zxdx", "bi_dx_rcgl", "bi_dx_wjsgjkh", "bi_dx_shxs", "bi_dx_xszl"}, 1, []int64{3870, 123, 456})
 	assert.Nil(t, err)
 	assert.Equal(t, int64(1), v)
 	//v, err = ReEmpower("10000", "znsj_jqr_use", 14184, []int64{4271})
@@ -44,7 +44,7 @@ func TestReEmpower(t *testing.T) {
 }
 
 func TestCrReEmpower(t *testing.T) {
-	v, err := CrReEmpower("10000", []string{"bi_电销菜单管理"}, []string{"bi_dx_yjtj", "bi_dx_qbxs", "bi_dx_zxdx"}, 1, []int64{123})
+	v, err := CrReEmpower("10000", []string{"bi_电销菜单管理"}, []string{"bi_dx_yjtj", "bi_dx_qbxs", "bi_dx_zxdx"}, 1, []int64{3870, 123, 456})
 	assert.Nil(t, err)
 	assert.Equal(t, int64(1), v)
 	//v, err = ReEmpower("10000", "znsj_jqr_use", 14184, []int64{4271})
@@ -53,13 +53,14 @@ func TestCrReEmpower(t *testing.T) {
 }
 
 func TestEmpower(t *testing.T) {
-	v, err := Empower("10000", []string{"bi_dx_yjtj", "bi_dx_zxdx", "bi_dx_rcgl", "bi_dx_wjsgjkh", "bi_dx_shxs", "bi_dx_xszl"}, 1, []int64{3870})
+	v, err := Empower("10000", []string{"bi_dx_ghxs", "bi_dx_zxdx", "bi_dx_rcgl", "bi_dx_wjsgjkh", "bi_dx_shxs", "bi_dx_xszl"}, 1, []int64{3870, 123, 456})
 	assert.Nil(t, err)
 	assert.Equal(t, int64(1), v)
 }
 
 func TestCancelEmpower(t *testing.T) {
-	v, err := CancelEmpower("10000", []string{"bi_dx_rcgl", "bi_dx_shxs"}, 1, []int64{3870})
+	//v, err := CancelEmpower("10000", []string{"bi_dx_ghxs", "bi_dx_zxdx", "bi_dx_rcgl", "bi_dx_wjsgjkh", "bi_dx_shxs", "bi_dx_xszl"}, 1, []int64{3870, 123, 456})
+	v, err := CancelEmpower("10000", []string{"bi_dx_wjsgjkh", "bi_dx_rcgl", "bi_dx_yjtj"}, 1, []int64{3870})
 	assert.Nil(t, err)
 	assert.Equal(t, int64(1), v)
 }