fuwencai 4 年之前
父节点
当前提交
a5df63c015
共有 7 个文件被更改,包括 165 次插入13 次删除
  1. 1 0
      conf/dev/base.toml
  2. 1 0
      model/user.go
  3. 4 1
      router/pageRouter.go
  4. 6 1
      service/callLog.go
  5. 94 0
      static/templates/callLog.html
  6. 52 6
      static/templates/login.html
  7. 7 5
      utils/api_util.go

+ 1 - 0
conf/dev/base.toml

@@ -19,3 +19,4 @@
     log-in-console= true
 [session]
     redis_token = "token=39.107.203.162:10079,limit=192.168.3.128:1712"
+    interface_call_rate = 20

+ 1 - 0
model/user.go

@@ -62,6 +62,7 @@ func (p *UserBuyRecord) TableName() string {
 type UserCallRecord struct {
 	ID            int       `json:"id" gorm:"primaryKey"`
 	AppID         string    `json:"app_id"`
+	ProductId     int       `json:"product_id"`
 	UserProductId int       `json:"user_product_id"`
 	Status        int       `json:"status"`
 	Ip            string    `json:"ip"`

+ 4 - 1
router/pageRouter.go

@@ -17,6 +17,7 @@ func pageRouterRegister(router *gin.Engine) {
 		pageRouterGroup.GET("/projectListDetail", projectListDetailPage)
 		pageRouterGroup.GET("/interfaceListPage", interfaceListPage)
 		pageRouterGroup.GET("/moneyRechargePage", moneyRechargePage)
+		pageRouterGroup.GET("/callLogPage", callLogPage)
 	}
 }
 
@@ -56,4 +57,6 @@ func moneyRechargePage(context *gin.Context) {
 	context.HTML(200, "moneyRecharge.html", nil)
 }
 
-
+func callLogPage(context *gin.Context) {
+	context.HTML(200, "callLog.html", nil)
+}

+ 6 - 1
service/callLog.go

@@ -4,6 +4,7 @@ import (
 	"log"
 	"sfis/db"
 	"sfis/model"
+	"sfis/utils"
 	"strings"
 	"time"
 )
@@ -31,11 +32,15 @@ func CallLog(appid, startTime, endTime string) ([]map[string]interface{}, error)
 		return nil, err
 	} else {
 		for _, v := range userCallRecord {
+			productname := ""
+			if product, ok := utils.ProductCaches.Map.Load(v.ProductId); ok {
+				productname = product.(*model.Product).Name
+			}
 			dataMap := map[string]interface{}{
 				"app_id":     v.AppID,
 				"invok_time": v.CreateAt.Local().Format("2006-01-02 15:04:05"),
 				"ip":         v.Ip,
-				//TODO
+				"name":       productname,
 			}
 			datas = append(datas, dataMap)
 		}

+ 94 - 0
static/templates/callLog.html

@@ -0,0 +1,94 @@
+{{define "callLog.html"}}
+    <!DOCTYPE html>
+    <html lang="en">
+    <head>
+        <meta charset="UTF-8">
+        <title>项目列表页面</title>
+        <script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
+        <script src="https://cdn.bootcss.com/blueimp-md5/2.10.0/js/md5.js"></script>
+    </head>
+    <body>
+    <div id="tableDiv" hidden>
+        <table border="0" id="tableId">
+            <thead>
+            <tr class="tableTitle">
+                {{/*                <th style="width: 20px"><input type="checkbox" name="item"></td></th>*/}}
+                <th style="width: 5%;">序号</th>
+                <th style="width: 20%">接口名称</th>
+                <th style="width: 10%">ip</th>
+                <th style="width: 20%">调用时间</th>
+            </tr>
+            </thead>
+            <tbody class="box">
+
+            </tbody>
+        </table>
+    </div>
+
+    </body>
+    <style>
+        .box tr .td {
+            text-align: center;
+        }
+    </style>
+    <script>
+        var LocString = String(window.document.location.href);
+
+        // 获取页面跳转传过来的参数
+        function GetQueryString(name) {
+            var rs = new RegExp("(^|)" + name + "=([^&]*)(&|$)", "gi").exec(LocString);
+            var tmp;
+            if (tmp = rs) {
+                return decodeURI(tmp[2])
+            }
+            return "";
+        }
+
+        var appid = GetQueryString("appId");
+        var key = GetQueryString("key");
+        
+        var param = {
+            "app_id": appid
+        };
+        var url = "/sfis/api/v1/callLog";
+        var rType = "post";
+        var now = new Date().getTime();
+        var token = md5(appid + Math.round(now / 1000) + key);
+        var hearders = {
+            "timestamp": "" + Math.round(now / 1000),
+            "token": token
+        }
+        $("#tableDiv").hide();
+        submit(param, rType, url, hearders, "callLog");
+
+        function submit(param, rType, url, hearders, str) {
+            $.ajax({
+                url: url,
+                type: rType,
+                headers: hearders,
+                data: param,
+                success: function (r) {
+                    $("#resultContent").text("");
+                    if (r.data) {
+                        $("#tableDiv").show();
+                        var str = "";
+                        for (var i = 0; i < r.data.length; i++) {
+                            var item = r.data[i]
+                            str += '<tr >';
+                            // str += '<td style="width: 20px"></td>';
+                            str += '<td class="td">' + (i + 1) + '</td>';
+                            str += '<td class="td">' + item.name + '</td>';
+                            str += '<td class="td">' + item.ip + '</td>';
+                            str += '<td class="td">' + item.invok_time + '</td>';
+                            str += '</tr>';
+                        }
+                        $(".box").html(str);
+                    } else {
+                        $("#resultContent").text(r.msg);
+                    }
+                }
+            })
+        }
+    </script>
+    </html>
+{{end}}

+ 52 - 6
static/templates/login.html

@@ -234,12 +234,58 @@
                 async: false,
                 data: param,
                 success: function (r) {
-                    // if (r.code === 0) {
-                    alert(JSON.stringify(r))
-                    // $(".result").html(r)
-                    // } else {
-                    //
-                    // }
+                    if (r.code === 0) {
+                        var str = "";
+                        console.log(r.data)
+                        if (r.data.length != 0) {
+                            $(".nodata").html("");
+                            $(".userProductDiv").show();
+                            $(".userProTbody").html("");
+                            for (var i = 0; i < r.data.length; i++) {
+                                var item = r.data[i];
+                                str += "<tr>";
+                                str += "<td>" + (i + 1) + "</td>";
+                                str += "<td>" + item.product_id + "</td>";
+                                str += "<td>" + item.app_id + "</td>";
+                                str += "<td>" + item.left_num + "</td>";
+                                if (item.cost_model == 0) {
+                                    str += "<td>扣量</td>";
+                                } else {
+                                    str += "<td>扣余额</td>";
+                                }
+                                if (item.interface_status == 0) {
+                                    str += "<td>开启</td>";
+                                } else {
+                                    str += "<td>关闭</td>";
+                                }
+                                str += "<td>" + item.call_times_limit_day + "</td>";
+                                str += "<td>" + item.data_num_limit_one_times + "</td>";
+                                if (item.product_id === 1000 || item.product_id === 1001) {
+                                    str += "<td class='handle' style='width: 100px ;'><a href=\"/page/projectListPage?appId=" + appId + "&key=" + key + "\" >测试接口</a>";
+                                } else {
+                                    str += "<td class='handle' style='width: 100px;'><a href=\"/page/projectListDetail?appId=" + appId + "&key=" + key + "\"  >测试接口</a>";
+                                }
+                                if (item.cost_model == 0) {
+                                    str += "<a href=\"/page/userRecharge?appId=" + appId + "\"  >剩余量充值</a>"
+                                }
+                                str += "<a href=\"/page/callLogPage?appId=" + appId + "&key=" + key + "\"  >调用记录</a>";
+                                str += "<a onclick=\"myFunction('" + appId + "','" + key + "','" + item.product_id + "')\"  href='javascript:void(0);' style='pointer:hand;'>并发测试</a>"
+                                // else {
+                                //
+                                // }
+                                str += "</td>";
+                                str += "</tr>";
+                            }
+                            // console.log(str);
+                            let trBody = $(str);
+                            $(".userProTbody").append(trBody);
+                        } else {
+                            $(".userProductDiv").hide();
+                        }
+
+                    } else {
+                        $(".userProductList").html(r.msg);
+                    }
                 }
             })
 

+ 7 - 5
utils/api_util.go

@@ -61,11 +61,13 @@ func Check(appID string, productID int, c *gin.Context, getData func() ([]map[st
 			redis.Put("limit", limittodaykey, 0, int(max-now))
 		}
 	}
-	//
-	limitrate := fmt.Sprintf("limitrate_%d_%s", userProduct.ProductID, userProduct.AppID)
-	Exists, _ := redis.Exists("limit", limitrate)
-	if Exists {
-		response.FailWithDetailed(response.CallRate, nil, "请求频率过快,请稍后重试", c)
+	//请求频率限制
+	if !concurrentTest {
+		limitrate := fmt.Sprintf("limitrate_%d_%s", userProduct.ProductID, userProduct.AppID)
+		Exists, _ := redis.Exists("limit", limitrate)
+		if Exists {
+			response.FailWithDetailed(response.CallRate, nil, "请求频率过快,请稍后重试", c)
+		}
 	}
 	//2.2 取用户(产品余量|钱包账户余额)校验-必须加锁
 	costModel := userProduct.CostModel //扣费模式 0扣余量,1-扣余额