浏览代码

Merge branch 'v2' of https://git.qianqiusoft.com/qianqiusoft/light-apiengine into v2

huangyh 5 年之前
父节点
当前提交
37e58c895c
共有 4 个文件被更改,包括 23 次插入14 次删除
  1. 16 6
      engine/auth/auth_client.go
  2. 1 3
      middleware/logger_cassandra.go
  3. 3 3
      third/amap/amap.go
  4. 3 2
      utils/tree_util.go

+ 16 - 6
engine/auth/auth_client.go

@@ -47,11 +47,11 @@ func (ap *authPackage)toBytes()[]byte{
 }
 
 type TcpClient struct {
-	conn    net.Conn
-	pchan   chan *authPackage
-	done    chan bool
-	exited bool
-	verified   bool
+	conn     net.Conn           // 连接
+	pchan    chan *authPackage  // 包chan
+	done     chan bool          // 是否done
+	exited   bool               // 退出
+	verified bool               // 验证是否
 }
 
 // 创建client
@@ -72,6 +72,9 @@ func(c *TcpClient)Start() {
 			if p := recover(); p != nil {
 				fmt.Println("ecover", p)
 			}
+			if c.conn != nil{
+				c.conn.Close()
+			}
 			c.restart()
 		}()
 
@@ -106,6 +109,7 @@ func(c *TcpClient)Start() {
 			for {
 				select {
 				case data := <-c.pchan:
+					glog.Infoln("写入数据")
 					c.conn.SetWriteDeadline(time.Now().Add(time.Second * 2))
 					_, err := c.conn.Write(data.toBytes())
 					if err != nil {
@@ -113,6 +117,7 @@ func(c *TcpClient)Start() {
 						return
 					}
 				case <-c.done:
+					glog.Infoln("发送数据done退出")
 					return
 				}
 			}
@@ -159,8 +164,11 @@ func(c *TcpClient)restart(){
 	}
 
 	go func(){
-		time.Sleep(3 * time.Second)
 		c.verified = false
+		c.done = make(chan bool)
+		c.pchan = make(chan *authPackage, 100)
+		c.exited = false
+		time.Sleep(3 * time.Second)
 		c.Start()
 	}()
 }
@@ -172,10 +180,12 @@ func(c *TcpClient)Send(cmd string, bytess []byte){
 		return
 	}
 
+	glog.Infoln("发送指令1", cmd)
 	c.pchan <- &authPackage{
 		Cmd: cmd,
 		Content: bytess,
 	}
+	glog.Infoln("发送指令2", cmd)
 }
 
 // 发送token

+ 1 - 3
middleware/logger_cassandra.go

@@ -148,7 +148,6 @@ func insertLogInfo(logInfo *logInfo){
 		Data interface{}
 	}
 	if logInfo.RespBody != ""{
-		fmt.Println(logInfo.RespBody)
 		err = json.Unmarshal([]byte(logInfo.RespBody), &respBodyObj)
 		if err != nil{
 			fmt.Println("json.Unmarshal 错误", err.Error())
@@ -165,7 +164,6 @@ func insertLogInfo(logInfo *logInfo){
 	}
 	logInfo.CostTime = float64(logInfo.RespTime.Sub(logInfo.ReqTime).Seconds())
 
-	// 保存轨迹
 	cqlformat := `insert into 
 		log_info(app_name, req_date, req_time, req_method, req_url, req_proto, req_ua, req_referer, req_post_data, resp_time, resp_body, resp_code, resp_msg, resp_data, cost_time) 
 		values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?);`
@@ -174,7 +172,7 @@ func insertLogInfo(logInfo *logInfo){
 	batch := session.NewBatch(gocql.UnloggedBatch)		// 应该批量插入多条,例如20条
 	batch.Query(cqlformat, __appName, reqDate, logInfo.ReqTime.Format("2006-01-02 15:04:05"), logInfo.ReqMethod, logInfo.ReqUrl, logInfo.ReqProto, logInfo.ReqUa, logInfo.ReqReferer, logInfo.ReqPostData, logInfo.RespTime.Format("2006-01-02 15:04:05"), logInfo.RespBody, logInfo.RespCode, logInfo.RespMsg, logInfo.RespData, logInfo.CostTime)
 	if err := session.ExecuteBatch(batch); err != nil {
-		fmt.Println("批量插入轨迹错误:", err)
+		fmt.Println("批量插入日志错误:", err)
 		return
 	}
 }

+ 3 - 3
third/amap/amap.go

@@ -94,9 +94,9 @@ func (a *AMapClient)ConvCoord(lngLats []string, coordType string)(*ConvCoordResu
  * @return1: 高德地图经度
  * @return2: 高德地图纬度
  */
-func (aa *AMapClient)ConvGpsToAMap(gpsLng, gpsLat float64)(float64, float64){
+func (aa *AMapClient)ConvGpsToAMap(gpsLng, gpsLat float64)(float64, float64, bool){
 	if outOfChinal(gpsLng, gpsLat){
-		return gpsLng, gpsLat
+		return gpsLng, gpsLat, false
 	}
 	dLat := transformLat(gpsLng - 105.0, gpsLat - 35.0)
 	dLon := transformLon(gpsLng - 105.0, gpsLat - 35.0)
@@ -106,7 +106,7 @@ func (aa *AMapClient)ConvGpsToAMap(gpsLng, gpsLat float64)(float64, float64){
 	sqrtMagic := math.Sqrt(magic)
 	dLat = (dLat * 180.0) / ((a * (1 - ee)) / (magic * sqrtMagic) * pi)
 	dLon = (dLon * 180.0) / (a / sqrtMagic * math.Cos(radLat) * pi)
-	return gpsLng + dLon, gpsLat + dLat
+	return gpsLng + dLon, gpsLat + dLat, true
 }
 
 /**

+ 3 - 2
utils/tree_util.go

@@ -38,8 +38,9 @@ func BuildTree(root string, treeSrcs []map[string]interface{}) ([]*models.TreeNo
 		text := toString(params[textFiled], "")
 		//json,_ := xorm.JSONString(params, true)
 		// 如果根节点root为空,则从parent为空中获取root节点数组
-		// 如果root不为空,则获取id等于的节点为root节点数组
-		if (parentValue == "" && parent == "") || value == parentValue {
+		// 如果root不为空且treeSrcs中包含id为root的,则获取id等于的节点为root节点数组(相当于显示root节点的树)
+		// 如果root不为空且treeSrcs中不包含id为root的,则获取parent等于的节点为root节点数组(相当于不显示root节点的树)
+		if (parentValue == "" && parent == "") || value == parentValue || parent == parentValue {
 			node := &models.TreeNode{
 				Id:     value,
 				Text:   text,