Эх сурвалжийг харах

Merge branch 'master' of http://192.168.3.207:10080/group3/SwordFish_Interface_Service

jiaojiao7 4 жил өмнө
parent
commit
1f0535da95

+ 9 - 2
api/v1/projects.go

@@ -99,17 +99,24 @@ func callLog(c *gin.Context) {
 	productId := c.PostForm("product_id")
 	startTime := c.PostForm("start_time")
 	endTime := c.PostForm("end_time")
+	isSelf := c.PostForm("isSelf")
+	isSelfs := false
+	if isSelf != "" {
+		isSelfs = true
+	}
 	datas := []map[string]interface{}{}
 	var err error
 	p := gin.H{
 		"appID":     appID,
 		"startTime": startTime,
 		"endTime":   endTime,
+		"productId": productId,
+		"isSelf":    isSelf,
 	}
 	global.Logger.Info("api callLog:", zap.Any("param:", p))
-	datas, err = service.CallLog(appID, productId, startTime, endTime)
+	datas, err = service.CallLog(appID, productId, startTime, endTime, isSelfs)
 	if err == nil {
-		response.FailWithDetailed(response.SUCCESS, datas, "OK", c)
+		response.FailWithDetailed(response.SUCCESS, datas, "", c)
 	} else {
 		response.FailWithDetailed(response.QueryError, datas, "系统查询异常", c)
 	}

+ 18 - 0
model/user.go

@@ -74,3 +74,21 @@ type UserCallRecord struct {
 func (p *UserCallRecord) TableName() string {
 	return "user_call_record"
 }
+
+type InterfaceOrder struct {
+	ID            int       `json:"id" gorm:"primaryKey"`
+	AppID         string    `json:"app_id"`
+	ProductId     int       `json:"product_id"`
+	UserProductId int       `json:"user_product_id"`
+	OrderCode     string    `json:"order_code"`
+	OrderType     string    `json:"order_type"`
+	Before        int       `json:"before"`
+	After         int       `json:"after"`
+	CostModel     int       `json:"cost_model"`
+	TradeNum      int       `json:"trade_num"`
+	CreateAt      time.Time `json:"-" gorm:"autoCreateTime"`
+}
+
+func (p *InterfaceOrder) TableName() string {
+	return "interface_order"
+}

+ 28 - 7
service/callLog.go

@@ -9,7 +9,7 @@ import (
 	"time"
 )
 
-func CallLog(appid, productId, startTime, endTime string) ([]map[string]interface{}, error) {
+func CallLog(appid, productId, startTime, endTime string, isSelf bool) ([]map[string]interface{}, error) {
 	key := []string{}
 	param := []interface{}{}
 	datas := []map[string]interface{}{}
@@ -40,13 +40,34 @@ func CallLog(appid, productId, startTime, endTime string) ([]map[string]interfac
 			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,
-				"name":       productname,
+			if isSelf {
+				interfaceOrder := model.InterfaceOrder{}
+				err := db.GetSFISDB().First(&interfaceOrder, &model.InterfaceOrder{AppID: v.AppID, OrderCode: v.OrderCode}).Error
+				if err == nil {
+					dataMap := map[string]interface{}{
+						"app_id":     v.AppID,
+						"invok_time": v.CreateAt.Local().Format("2006-01-02 15:04:05"),
+						"ip":         v.Ip,
+						"name":       productname,
+						"param":      v.Param,
+						"order_code": v.OrderCode,
+						"before":     interfaceOrder.Before,
+						"after":      interfaceOrder.After,
+						"cost_model": interfaceOrder.CostModel,
+						"trade_num":  interfaceOrder.TradeNum,
+					}
+					datas = append(datas, dataMap)
+				}
+			} else {
+				dataMap := map[string]interface{}{
+					"app_id":     v.AppID,
+					"invok_time": v.CreateAt.Local().Format("2006-01-02 15:04:05"),
+					"ip":         v.Ip,
+					"name":       productname,
+					"param":      v.Param,
+				}
+				datas = append(datas, dataMap)
 			}
-			datas = append(datas, dataMap)
 		}
 	}
 	return datas, nil

+ 4 - 0
service/concurrentTest.go

@@ -19,5 +19,9 @@ func GetConcurrentData(appid string, productId int, c *gin.Context) {
 		utils.Check(appid, productId, c, func() ([]map[string]interface{}, int, error) {
 			return ProjectListData(productId, appid, "", "中铁十五局集团有限公司", "", true)
 		}, "", "", true)
+	} else {
+		utils.Check(appid, productId, c, func() ([]map[string]interface{}, int, error) {
+			return []map[string]interface{}{}, 200, nil
+		}, "", "", true)
 	}
 }

+ 27 - 7
static/templates/callLog.html

@@ -3,7 +3,7 @@
     <html lang="en">
     <head>
         <meta charset="UTF-8">
-        <title>项目列表页面</title>
+        <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>
@@ -13,10 +13,16 @@
             <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>
+                <th style="width: 3%;">序号</th>
+                <th style="width: 10%">接口名称</th>
+                <th style="width: 10%">调用时间</th>
+                <th style="width: 8%">ip</th>
+                <th style="width: 15%">参数</th>
+                <th style="width: 10%">订单编号</th>
+                <th style="width: 5%">调用前次数|金额</th>
+                <th style="width: 5%">调用后次数|金额</th>
+                <th style="width: 5%">扣费类型</th>
+                <th style="width: 5%">扣费次数|金额</th>
             </tr>
             </thead>
             <tbody class="box">
@@ -50,7 +56,8 @@
         
         var param = {
             "app_id": appid,
-            "product_id":product_id
+            "product_id":product_id,
+            "isSelf": "1"
         };
         var url = "/sfis/api/v1/callLog";
         var rType = "post";
@@ -80,8 +87,21 @@
                             // 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 += '<td class="td">' + item.ip + '</td>';
+                            str += '<td class="td">' + item.param + '</td>';
+                            str += '<td class="td">' + item.order_code + '</td>';
+                            if (item.cost_model === 0){
+                                str += '<td class="td">' + item.before + '</td>';
+                                str += '<td class="td">' + item.after + '</td>';
+                                str += '<td class="td">按剩余量扣除</td>';
+                                str += '<td class="td">' + item.trade_num + '</td>';
+                            }else if (item.cost_model === 1){
+                                str += '<td class="td">' + Math.round(item.before/100) + '</td>';
+                                str += '<td class="td">' + Math.round(item.after/100) + '</td>';
+                                str += '<td class="td">按余额扣除</td>';
+                                str += '<td class="td">' + Math.round(item.trade_num/100) + '</td>';
+                            }
                             str += '</tr>';
                         }
                         $(".box").html(str);