wangchuanjin 1 жил өмнө
parent
commit
da4d08566b

+ 28 - 0
api/internal/handler/empowerlisthandler.go

@@ -0,0 +1,28 @@
+package handler
+
+import (
+	"net/http"
+
+	"bp.jydev.jianyu360.cn/BaseService/resourceCenter/api/internal/logic"
+	"bp.jydev.jianyu360.cn/BaseService/resourceCenter/api/internal/svc"
+	"bp.jydev.jianyu360.cn/BaseService/resourceCenter/api/internal/types"
+	"github.com/zeromicro/go-zero/rest/httpx"
+)
+
+func empowerListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
+	return func(w http.ResponseWriter, r *http.Request) {
+		var req types.Req
+		if err := httpx.Parse(r, &req); err != nil {
+			httpx.Error(w, err)
+			return
+		}
+
+		l := logic.NewEmpowerListLogic(r.Context(), svcCtx)
+		resp, err := l.EmpowerList(&req)
+		if err != nil {
+			httpx.Error(w, err)
+		} else {
+			httpx.OkJson(w, resp)
+		}
+	}
+}

+ 5 - 0
api/internal/handler/routes.go

@@ -27,6 +27,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
 				Path:    "/resourceCenter/waitEmpowerDetail",
 				Handler: waitEmpowerDetailHandler(serverCtx),
 			},
+			{
+				Method:  http.MethodPost,
+				Path:    "/resourceCenter/empowerList",
+				Handler: empowerListHandler(serverCtx),
+			},
 		},
 	)
 }

+ 40 - 0
api/internal/logic/empowerlistlogic.go

@@ -0,0 +1,40 @@
+package logic
+
+import (
+	"context"
+	"fmt"
+
+	"bp.jydev.jianyu360.cn/BaseService/resourceCenter/api/internal/svc"
+	"bp.jydev.jianyu360.cn/BaseService/resourceCenter/api/internal/types"
+	. "bp.jydev.jianyu360.cn/BaseService/resourceCenter/public/service"
+	"github.com/zeromicro/go-zero/core/logx"
+)
+
+type EmpowerListLogic struct {
+	logx.Logger
+	ctx    context.Context
+	svcCtx *svc.ServiceContext
+}
+
+func NewEmpowerListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *EmpowerListLogic {
+	return &EmpowerListLogic{
+		Logger: logx.WithContext(ctx),
+		ctx:    ctx,
+		svcCtx: svcCtx,
+	}
+}
+
+func (l *EmpowerListLogic) EmpowerList(req *types.Req) (resp *types.Reply, err error) {
+	resp = &types.Reply{}
+	count, datas, err := EmpowerList(req.AppId, req.Function_code, req.Ent_id, 0, 0)
+	if err != nil {
+		resp.Error_msg = err.Error()
+		l.Error(fmt.Sprintf("%+v", req), err)
+	}
+	resp.Error_code = 0
+	resp.Data = map[string]interface{}{
+		"count":      count,
+		"entUserIds": datas,
+	}
+	return
+}

+ 3 - 0
api/resource.api

@@ -33,4 +33,7 @@ service resource {
 	@doc "获取待授权详情"
 	@handler waitEmpowerDetail
 	post /resourceCenter/waitEmpowerDetail (Req) returns (Reply)
+	@doc "获取授权列表"
+	@handler empowerList
+	post /resourceCenter/empowerList (Req) returns (Reply)
 }

+ 18 - 0
openPower/config.json

@@ -109,6 +109,24 @@
             "GoodsCode": "special_nosale_goods",
             "GoodsSpecId": 26,
             "All": {"bi_客户成功查看": "bi_kc_ck"}
+        },
+		"bi_sf_dz": {
+			"Name": "bi_数服_数据定制",
+			"GoodsCode": "special_nosale_goods",
+			"GoodsSpecId": 29,
+			"All": {"bi_数服_数据导入": "bi_sf_sjdr","bi_数服_数据清单": "bi_sf_sjqd","bi_数服_数据分析": "bi_sf_sjfx"}
+		},
+		"bi_sj_dz": {
+			"Name": "bi_数据_数据定制",
+			"GoodsCode": "special_nosale_goods",
+			"GoodsSpecId": 30,
+			"All": {"bi_数据_数据清单": "bi_sj_sjqk","bi_数据_数据分析": "bi_sj_sjfx"}
+		},
+        "bi_sj_yyszs": {
+            "Name": "bi_数据_运营商专属",
+            "GoodsCode": "special_nosale_goods",
+            "GoodsSpecId": 31,
+            "All": {"bi_数据_运营商专属": "bi_sj_yyszs"}
         }
 	}
 }

+ 3 - 0
public/entity/base_ent_empower.go

@@ -39,6 +39,9 @@ func (b *base_ent_empower) Count(appid, function_code string, ent_id int64) int6
 
 //是否授权
 func (b *base_ent_empower) HasEmpower(appid, function_code string, ent_id, ent_user_id int64) bool {
+	if Base_ent_wait_empower.IsAllEmpower(appid, function_code, ent_id) {
+		return true
+	}
 	empower := b.List(appid, function_code, ent_id, 0, 0)
 	if empower != nil {
 		if len(*empower) == 1 && (*empower)[0].Ent_user_id == 0 {

+ 6 - 3
public/entity/base_ent_wait_empower.go

@@ -17,14 +17,17 @@ type base_ent_wait_empower struct {
 	Ent_id              int64  //企业id
 	Start_time          string //开始时间
 	End_time            string //结束时间
-	Use_count           int    //使用数量
 	Empower_count       int    //授权数量
 	Limit_strategy      string //限制频率;1d:1天 1m:1个月
 }
 
 //待授权记录
 func (b *base_ent_wait_empower) WaitEmpowers(appid, function_code string, ent_id int64) *[]*base_ent_wait_empower {
-	now := NowFormat(Date_Full_Layout)
-	list := Mysql_BaseService.SelectBySql(`select * from base_ent_wait_empower where appid=? and function_code=? and ent_id=? and end_time>?`, appid, function_code, ent_id, now)
+	list := Mysql_BaseService.SelectBySql(`select * from base_ent_wait_empower where appid=? and function_code=? and ent_id=? and end_time>?`, appid, function_code, ent_id, NowFormat(Date_Full_Layout))
 	return JsonUnmarshal(list, &[]*base_ent_wait_empower{}).(*[]*base_ent_wait_empower)
 }
+
+//是否全部授权
+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
+}

+ 4 - 15
public/entity/base_power.go

@@ -2,7 +2,6 @@ package entity
 
 import (
 	"database/sql"
-	"log"
 	"strings"
 	"time"
 
@@ -69,7 +68,7 @@ func (b *base_power) OpenPower(goods_spec_id int64, appid, goods_code string, ac
 			on (a.appid=? and a.account_id=? and a.status=1 and b.appid=? and b.goods_code=? and b.spec_id=? and a.function_code=b.function_code) 
 			inner join base_function c on (c.appid=? and c.status=1 and c.power_type=1 and c.code=a.function_code) 
 			set a.status=0,update_time=?`, appid, account_id, appid, goods_code, goods_spec_id, appid, NowFormat(Date_Full_Layout)) > -1
-		power_values, empower_values, wait_empower_values := []interface{}{}, []interface{}{}, []interface{}{}
+		power_values, wait_empower_values := []interface{}{}, []interface{}{}
 		if start_time == "" {
 			start_time = NowFormat(Date_Full_Layout)
 		}
@@ -126,11 +125,7 @@ func (b *base_power) OpenPower(goods_spec_id int64, appid, goods_code string, ac
 				power_values = append(power_values, use_count, surplus_count, v.Limit_strategy, v.Strategy_count, 1, start_time, start_time)
 				//
 				if v.Power_type == 2 {
-					if v.Power_count == -1 && Base_ent_empower.Count(appid, v.Function_code, ent_id) == 0 {
-						empower_values = append(empower_values, appid, ent_id, 0, v.Function_code, start_time)
-					} else if v.Power_count > 0 {
-						wait_empower_values = append(wait_empower_values, appid, v.Id, v.Function_code, ent_id, start_time, end_time, use_count, v.Power_count, v.Limit_strategy, start_time)
-					}
+					wait_empower_values = append(wait_empower_values, appid, v.Id, v.Function_code, ent_id, start_time, end_time, use_count, v.Power_count, v.Limit_strategy, start_time)
 				}
 			}
 		}
@@ -140,17 +135,11 @@ func (b *base_power) OpenPower(goods_spec_id int64, appid, goods_code string, ac
 		}
 		v1, v2 := Mysql_BaseService.InsertBatchByTx(tx, "base_power", []string{"appid", "goods_spec_power_id", "function_code", "power_type", "account_id", "start_time", "end_time", "use_count", "surplus_count", "limit_strategy", "strategy_count", "status", "create_time", "update_time"}, power_values)
 		ok2 := true
-		if len(empower_values) > 0 {
-			v3, v4 := Mysql_BaseService.InsertBatchByTx(tx, "base_ent_empower", []string{"appid", "ent_id", "ent_user_id", "function_code", "create_time"}, empower_values)
-			ok2 = v3 > 0 && v4 > 0
-		}
-		ok3 := true
 		if len(wait_empower_values) > 0 {
 			v5, v6 := Mysql_BaseService.InsertBatchByTx(tx, "base_ent_wait_empower", []string{"appid", "goods_spec_power_id", "function_code", "ent_id", "start_time", "end_time", "use_count", "empower_count", "limit_strategy", "create_time"}, wait_empower_values)
-			ok3 = v5 > 0 && v6 > 0
+			ok2 = v5 > 0 && v6 > 0
 		}
-		log.Println(ok1 && ok2 && v1 > 0 && v2 > 0 && ok3)
-		return ok1 && ok2 && v1 > 0 && v2 > 0 && ok3
+		return ok1 && ok2 && v1 > 0 && v2 > 0
 	})
 }
 

+ 21 - 14
public/service/power.go

@@ -91,7 +91,6 @@ func WaitEmpowerDetail(appid, function_code string, ent_id int64) (*WaitEmpowerD
 			result.Limit_strategy = v.Limit_strategy
 			result.Start_time = v.Start_time
 			result.End_time = v.End_time
-			result.Use_count = v.Use_count
 			break
 		}
 	}
@@ -154,9 +153,13 @@ func ReEmpower(appid, function_code string, ent_id int64, ent_user_id []int64) (
 	}
 	count := 0
 	for _, v := range *bewes {
+		if v.Empower_count == -1 {
+			count = -1
+			break
+		}
 		count += v.Empower_count
 	}
-	if len(ent_user_id) > count {
+	if count != -1 && len(ent_user_id) > count {
 		return -2, nil
 	}
 	if Base_ent_empower.ReEmpower(appid, function_code, ent_id, ent_user_id) {
@@ -209,18 +212,22 @@ func EmpowerList(appid, function_code string, ent_id, page_num, page_size int64)
 	} else if ent_id == 0 {
 		return count, result, errors.New("无效的参数ent_id")
 	}
-	list := Base_ent_empower.List(appid, function_code, ent_id, page_num, page_size)
-	if list != nil {
-		if len(*list) == 1 && (*list)[0].Ent_user_id == 0 {
-			count = -1
-		} else {
-			for _, v := range *list {
-				result = append(result, &pb.Empower{
-					EntUserId: v.Ent_user_id,
-				})
-			}
-			if page_num == 1 {
-				count = Base_ent_empower.Count(appid, function_code, ent_id)
+	if Base_ent_wait_empower.IsAllEmpower(appid, function_code, ent_id) {
+		count = -1
+	} else {
+		list := Base_ent_empower.List(appid, function_code, ent_id, page_num, page_size)
+		if list != nil {
+			if len(*list) == 1 && (*list)[0].Ent_user_id == 0 {
+				count = -1
+			} else {
+				for _, v := range *list {
+					result = append(result, &pb.Empower{
+						EntUserId: v.Ent_user_id,
+					})
+				}
+				if page_num == 1 {
+					count = Base_ent_empower.Count(appid, function_code, ent_id)
+				}
 			}
 		}
 	}