engineerper 1 년 전
부모
커밋
79fd4e18a4
12개의 변경된 파일152개의 추가작업 그리고 55개의 파일을 삭제
  1. 13 5
      api/v1/app/gateway.go
  2. 4 4
      api/v1/isapi/system.go
  3. 1 1
      config.yaml
  4. 0 5
      gatewayServer/c2s.go
  5. 13 2
      go.mod
  6. 28 0
      go.sum
  7. 34 12
      isapi/client.go
  8. 5 5
      isapi/response.go
  9. 21 4
      isapi/sip.go
  10. 25 6
      main.go
  11. 6 9
      service/app/gateway.go
  12. 2 2
      service/isapi/sipServer.go

+ 13 - 5
api/v1/app/gateway.go

@@ -1,12 +1,14 @@
 package app
 
 import (
+	"fmt"
 	"github.com/gin-gonic/gin"
-	"github.com/sirupsen/logrus"
 	"lc-fangdaosha/model/app"
 	"lc-fangdaosha/model/app/request"
 	"lc-fangdaosha/model/common/response"
 	"lc-fangdaosha/service"
+	"lc-fangdaosha/utils"
+	"strconv"
 )
 
 type GatewayApi struct {
@@ -17,10 +19,16 @@ var gs = service.ServiceGroupApp.AppServiceGroup.GatewayService
 // List 获取网关列表
 func (api *GatewayApi) List(c *gin.Context) {
 	var req request.GatewayRequest
-	err := c.ShouldBindJSON(&req)
-	if err != nil {
-		logrus.Error("请求数据绑定错误", err)
-	}
+	id := utils.GetUserID(c)
+	req.Uid = int(id)
+	req.Name = c.Query("gatewayName")
+	req.Osn = c.Query("osn")
+	req.CameraSn = c.Query("cameraSn")
+	v2 := c.Query("pageSize")
+	req.PageSize, _ = strconv.Atoi(v2)
+	v3 := c.Query("page")
+	req.Page, _ = strconv.Atoi(v3)
+	fmt.Printf("参数:%+v\n", req)
 	list, err := gs.List(req)
 	if err != nil {
 		response.FailWithMessage(err.Error(), c)

+ 4 - 4
api/v1/isapi/system.go

@@ -50,11 +50,11 @@ func (i SystemApi) PutEmail(c *gin.Context) {
 
 // GetHost 获取设备连接的host
 func GetHost(c *gin.Context) (string, error) {
-	devId := c.Query("devId")
-	if devId == "" {
-		return "", errors.New("设备Id为空")
+	isn := c.GetHeader("isn")
+	if isn == "" {
+		return "", errors.New("网关isn为空")
 	}
-	conn, ok := gatewayServer.ConnMap[devId]
+	conn, ok := gatewayServer.ConnMap[isn]
 	if !ok {
 		return "", errors.New("获取设备Id对应连接失败")
 	}

+ 1 - 1
config.yaml

@@ -1,4 +1,4 @@
-#系统/后台相关
+ #系统/后台相关
 system:
   env: public
   addr: 9000

+ 0 - 5
gatewayServer/c2s.go

@@ -27,7 +27,6 @@ func ParseAndResponse(adu AppDataUnit, c net.Conn) {
 	case CmdCodeServerC2S:
 		c2s4000(adu, c)
 	case CmdCodeUpdateC2S:
-		//更新固件
 	default:
 		fmt.Println(adu.String())
 	}
@@ -67,7 +66,6 @@ func c2s4001(adu AppDataUnit, c net.Conn) {
 	gs := service.ServiceGroupApp.AppServiceGroup.GatewayService
 	gw, err := gs.CreateIfNotExist(adu.DevId)
 	if err != nil {
-		//if errors.Is(err, appService.ExistError) {
 		if err == appService.ExistError {
 			logrus.Infof("网关[%s]登录成功", adu.DevId)
 		} else {
@@ -119,7 +117,6 @@ func c2s4002(adu AppDataUnit, c net.Conn) {
 	if err != nil {
 		logrus.Errorf("写入数据错误 %e\n", err)
 	}
-	//todo 网关注册后,网关再接入摄像头如何注册摄像头--
 }
 
 // 查询参数响应
@@ -145,12 +142,10 @@ func setServer(host string) uint {
 		logrus.Error("配置监听主机错误", err)
 	}
 	var resp = data.(isapi.ResponseStatus)
-	//err = xml.Unmarshal(bytes, &resp)
 	if err != nil || (resp.StatusCode != 0 && resp.StatusCode != 1) {
 		logrus.Errorf("配置监听服务器响应 err:%s,StatusCode:%d,StatusString:%s", err.Error(), resp.StatusCode, resp.StatusString)
 		return 0
 	}
-	//logrus.Info("配置监听主机响应", string(bytes))
 	return 1
 }
 

+ 13 - 2
go.mod

@@ -25,11 +25,22 @@ require (
 	gorm.io/gorm v1.25.5
 )
 
+require (
+	github.com/lestrrat/go-file-rotatelogs v0.0.0-20180223000712-d3151e2a480f // indirect
+	github.com/lestrrat/go-strftime v0.0.0-20180220042222-ba3bf9c1d042 // indirect
+	github.com/pkg/errors v0.9.1 // indirect
+	github.com/tencentcloud/tencentcloud-sdk-go v1.0.782 // indirect
+	github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.782 // indirect
+	github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.782 // indirect
+	github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ocr v1.0.780 // indirect
+	gocv.io/x/gocv v0.35.0 // indirect
+)
+
 require (
 	github.com/Knetic/govaluate v3.0.1-0.20171022003610-9aa49832a739+incompatible // indirect
-	github.com/bytedance/sonic v1.9.1 // indirect
+	//github.com/bytedance/sonic v1.9.1 // indirect
 	github.com/cespare/xxhash/v2 v2.2.0 // indirect
-	github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect
+	//github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect
 	github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
 	github.com/dustin/go-humanize v1.0.1 // indirect
 	github.com/fsnotify/fsnotify v1.6.0 // indirect

+ 28 - 0
go.sum

@@ -204,6 +204,7 @@ github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ
 github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
 github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=
 github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
+github.com/hybridgroup/mjpeg v0.0.0-20140228234708-4680f319790e/go.mod h1:eagM805MRKrioHYuU7iKLUyFPVKqVV6um5DAvCkUtXs=
 github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
 github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
 github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM=
@@ -243,6 +244,10 @@ github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+
 github.com/leodido/go-urn v1.2.0/go.mod h1:+8+nEpDfqqsY+g338gtMEUOtuK+4dEMhiQEgxpxOKII=
 github.com/leodido/go-urn v1.2.4 h1:XlAE/cm/ms7TE/VMVoduSpNBoyc2dOxHs5MZSwAN63Q=
 github.com/leodido/go-urn v1.2.4/go.mod h1:7ZrI8mTSeBSHl/UaRyKQW1qZeMgak41ANeCNaVckg+4=
+github.com/lestrrat/go-file-rotatelogs v0.0.0-20180223000712-d3151e2a480f h1:sgUSP4zdTUZYZgAGGtN5Lxk92rK+JUFOwf+FT99EEI4=
+github.com/lestrrat/go-file-rotatelogs v0.0.0-20180223000712-d3151e2a480f/go.mod h1:UGmTpUd3rjbtfIpwAPrcfmGf/Z1HS95TATB+m57TPB8=
+github.com/lestrrat/go-strftime v0.0.0-20180220042222-ba3bf9c1d042 h1:Bvq8AziQ5jFF4BHGAEDSqwPW1NJS3XshxbRCxtjFAZc=
+github.com/lestrrat/go-strftime v0.0.0-20180220042222-ba3bf9c1d042/go.mod h1:TPpsiPUEh0zFL1Snz4crhMlBe60PYxRHr5oFF3rRYg0=
 github.com/lib/pq v1.10.2 h1:AqzbZs4ZoCBp+GtejcpCpcxM3zlSMx29dXbUSeVtJb8=
 github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0VQdvPDY=
 github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0=
@@ -266,9 +271,11 @@ github.com/montanaflynn/stats v0.7.0/go.mod h1:etXPPgVO6n31NxCd9KQUMvCM+ve0ruNzt
 github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE=
 github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE=
 github.com/onsi/gomega v1.18.1 h1:M1GfJqGRrBrrGGsbxzV5dqM2U2ApXefZCQpkukxYRLE=
+github.com/pascaldekloe/goe v0.1.0/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc=
 github.com/pelletier/go-toml/v2 v2.0.8 h1:0ctb6s9mE31h0/lhu+J6OPmVeDxJn+kYnJc2jZR9tGQ=
 github.com/pelletier/go-toml/v2 v2.0.8/go.mod h1:vuYfssBdrU2XDZ9bYydBu6t+6a6PYNcZljzZR9VXg+4=
 github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8/go.mod h1:HKlIX3XHQyzLZPlr7++PzdhaXEj94dEiJgZDTsxEqUI=
+github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
 github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
 github.com/pkg/sftp v1.13.1/go.mod h1:3HaPG6Dq1ILlpPZRO0HVMrsydcdLt6HRDccSgb87qRg=
 github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
@@ -317,6 +324,25 @@ github.com/stretchr/testify v1.8.3/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXl
 github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
 github.com/subosito/gotenv v1.4.2 h1:X1TuBLAMDFbaTAChgCBLu3DU3UPyELpnF2jjJ2cz/S8=
 github.com/subosito/gotenv v1.4.2/go.mod h1:ayKnFf/c6rvx/2iiLrJUk1e6plDbT3edrFNGqEflhK0=
+github.com/tencentcloud/tencentcloud-sdk-go v1.0.780 h1:Fqg1bt8jbUhu4cJ3wSvJoENd1vpLj7pIGkfUdEScoh0=
+github.com/tencentcloud/tencentcloud-sdk-go v1.0.780/go.mod h1:0PfYow01SHPMhKY31xa+EFz2RStxIqj6JFAJS+IkCi4=
+github.com/tencentcloud/tencentcloud-sdk-go v1.0.781 h1:pMIp/w7JZdz8kxrFjqbZCA83xQeyOe+okJSzaqm0kQg=
+github.com/tencentcloud/tencentcloud-sdk-go v1.0.781/go.mod h1:0PfYow01SHPMhKY31xa+EFz2RStxIqj6JFAJS+IkCi4=
+github.com/tencentcloud/tencentcloud-sdk-go v1.0.782 h1:3CH0kg/M+UbB0FPozvFcfTHNC+zLZlkai0UiCGPWYJ4=
+github.com/tencentcloud/tencentcloud-sdk-go v1.0.782/go.mod h1:0PfYow01SHPMhKY31xa+EFz2RStxIqj6JFAJS+IkCi4=
+github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.780/go.mod h1:r5r4xbfxSaeR04b166HGsBa/R4U3SueirEUpXGuw+Q0=
+github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.781 h1:ZLcrm4Mp3pWZnlHh61oKx4LrNeZ6Dmdu4RxWMloULJw=
+github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.781/go.mod h1:r5r4xbfxSaeR04b166HGsBa/R4U3SueirEUpXGuw+Q0=
+github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.782 h1:du/bh8RvkLIHjpmpXtOT0lhwhPUdiobmxr32Sv6xAtA=
+github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.782/go.mod h1:r5r4xbfxSaeR04b166HGsBa/R4U3SueirEUpXGuw+Q0=
+github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.780 h1:TH1Yue6/avkQylkzbNf4qsyYdnxxZ6u88wC9l7HJqMo=
+github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.780/go.mod h1:zivJtasCyOpsjkLG45LPZfVZCMT3qzQNJ+yL/FPK/S8=
+github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.781 h1:t3meBdyVJhuU7MKTtcz3qAbvjcfuCjcbmMa4af4IjlM=
+github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.781/go.mod h1:P3kN49ZZCl/CiYUzyW9XU9e7EoWlSeZvtE1mMhLn7OA=
+github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.782 h1:KWOG2mTArNdoBhc8Y17lKTe6cjiXCDp2Bj+teyvJic0=
+github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.782/go.mod h1:ZIjKSDw6BqRyUOnIr+Wwzr8NXIppxcdUJM2hwhw+CtA=
+github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ocr v1.0.780 h1:hiH/tc3y1p4hIWNJdvxzZBBSjh07PLj6GjHRS/u4rD0=
+github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ocr v1.0.780/go.mod h1:E5tmeQ3bIO+spB5Rdgw8pcD/ZR7WqslfOAyzA1J5XLs=
 github.com/tidwall/gjson v1.14.4 h1:uo0p8EbA09J7RQaflQ1aBRffTR7xedD2bcIVSYxLnkM=
 github.com/tidwall/gjson v1.14.4/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
 github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA=
@@ -363,6 +389,8 @@ go.uber.org/multierr v1.10.0 h1:S0h4aNzvfcFsC3dRF1jLoaov7oRaKqRGC/pUEJ2yvPQ=
 go.uber.org/multierr v1.10.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
 go.uber.org/zap v1.26.0 h1:sI7k6L95XOKS281NhVKOFCUNIvv9e0w4BF8N3u+tCRo=
 go.uber.org/zap v1.26.0/go.mod h1:dtElttAiwGvoJ/vj4IwHBS/gXsEu/pZ50mUIRWuG0so=
+gocv.io/x/gocv v0.35.0 h1:Qaxb5KdVyy8Spl4S4K0SMZ6CVmKtbfoSGQAxRD3FZlw=
+gocv.io/x/gocv v0.35.0/go.mod h1:oc6FvfYqfBp99p+yOEzs9tbYF9gOrAQSeL/dyIPefJU=
 golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8=
 golang.org/x/arch v0.3.0 h1:02VY4/ZcO/gBOH6PUaoiptASxtXU10jazRCP865E97k=
 golang.org/x/arch v0.3.0/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8=

+ 34 - 12
isapi/client.go

@@ -24,7 +24,6 @@ type Client struct {
 	BaseURL string
 }
 
-// NewClient 获取新的连接
 func NewClient(host, username, password string) (*Client, error) {
 	u, err := url.Parse("http://" + host)
 	if err != nil {
@@ -38,23 +37,32 @@ func NewClient(host, username, password string) (*Client, error) {
 	}, nil
 }
 
-// TouChuan 透传
-func TouChuan(host string, o Operation, data []byte, c *gin.Context) ([]byte, error) {
-	info, err := Com(host, o, data)
+func TouChuan(host string, o Operation, data []byte, c *gin.Context) (resp any, err error) {
+	resp, err = Com(host, o, data)
 	if err != nil {
-		return nil, fmt.Errorf("TouChuan错误: %e", err)
+		logrus.Error(err)
+		response.FailWithDetailed(resp.(ResponseStatus), err.Error(), c)
+		return
 	}
-	if err != nil {
-		response.FailWithMessage(err.Error(), c)
-		logrus.Errorf("%s error: %e", o, err)
-		return nil, err
+	//断言成功,说明是配置响应,检查配置结果
+	r, ok := resp.(ResponseStatus)
+	if ok {
+		if r.StatusCode == 0 || r.StatusCode == 1 {
+			response.OkWithDetailed(resp, "操作成功", c)
+			return
+		} else {
+			response.FailWithDetailed(resp, "操作失败,请联系管理员", c)
+			return
+		}
 	}
-	c.Data(200, `application/xml; charset="UTF-8"`, info)
-	return info, nil
+	//断言失败,说明是查询响应,直接返回数据
+	response.OkWithData(resp, c)
+	return
 }
 
 // Com 透传
-func Com(host string, o Operation, data []byte) ([]byte, error) {
+func Com(host string, o Operation, data []byte) (any, error) {
+	//TODO 应该使用公共的http client
 	c, err := NewClient(host, "admin", "kk176@lc")
 	if err != nil {
 		return nil, err
@@ -66,6 +74,16 @@ func Com(host string, o Operation, data []byte) ([]byte, error) {
 		return c.GetSystemCap()
 	case GetChanCap:
 		return c.GetOneChanEventCap()
+	//遮盖侦测
+	//case GetTamperDetection:
+	//	return c.GetTamperDetection("1")
+	//case PutTamperDetection:
+	//	return c.PutTamperDetection("1", data)
+	//移动侦测
+	//case GetMotionDetection:
+	//	return c.GetMotionDetection("1")
+	//case PutMotionDetection:
+	//	return c.PutMotionDetection("1", data)
 	//越界侦测
 	case GetLineDetectionCap:
 		return c.GetLineDetectionCap()
@@ -100,6 +118,10 @@ func Com(host string, o Operation, data []byte) ([]byte, error) {
 	case PutRegionEntrance:
 		return c.PutRegionEntrance(data)
 		//离开区域
+		//case GetRegionExiting:
+		//	return c.GetRegionExiting()
+		//case PutRegionExiting:
+		//	return c.PutRegionExiting(data)
 	case SetHosts:
 		return c.PutHost(data)
 	case SetSIP:

+ 5 - 5
isapi/response.go

@@ -1,9 +1,9 @@
 package isapi
 
 type ResponseStatus struct {
-	ResponseUrl   string `xml:"responseUrl"`
-	StatusCode    int    `xml:"statusCode"`
-	StatusString  string `xml:"statusString"`
-	SubStatusCode string `xml:"subStatusCode"`
-	Description   string `xml:"description"`
+	ResponseUrl   string `xml:"responseUrl"json:"responseURL"`
+	StatusCode    int    `xml:"statusCode"json:"statusCode"`
+	StatusString  string `xml:"statusString"json:"statusString"`
+	SubStatusCode string `xml:"subStatusCode"json:"subStatusCode"`
+	Description   string `xml:"description"json:"description"`
 }

+ 21 - 4
isapi/sip.go

@@ -1,5 +1,10 @@
 package isapi
 
+import (
+	"encoding/xml"
+	"github.com/sirupsen/logrus"
+)
+
 type SIPServerList struct {
 	SIPServer []struct {
 		ID        string `xml:"id" yaml:"ID"`
@@ -43,12 +48,24 @@ type SIPServerList struct {
 	} `xml:"SIPServer"`
 }
 
-func (c *Client) PutSip(data []byte) ([]byte, error) {
-	return c.CommonPut(data, "/ISAPI/System/Network/SIP")
+func (c *Client) PutSip(data []byte) (resp ResponseStatus, err error) {
+	bytes, err := c.CommonPut(data, "/ISAPI/System/Network/SIP")
+	if err != nil {
+		logrus.Error("请求出错", err)
+		return
+	}
+	err = xml.Unmarshal(bytes, &resp)
+	return
 }
 
-func (c *Client) PutSipInfo(data []byte) ([]byte, error) {
-	return c.CommonPut(data, "/ISAPI/System/Network/SIP/1/SIPInfo")
+func (c *Client) PutSipInfo(data []byte) (resp ResponseStatus, err error) {
+	bytes, err := c.CommonPut(data, "/ISAPI/System/Network/SIP/1/SIPInfo")
+	if err != nil {
+		logrus.Error("请求出错", err)
+		return
+	}
+	err = xml.Unmarshal(bytes, &resp)
+	return
 }
 
 type SIPInfo struct {

+ 25 - 6
main.go

@@ -3,25 +3,27 @@ package main
 import (
 	"fmt"
 	"github.com/gin-gonic/gin"
+	rotatelogs "github.com/lestrrat/go-file-rotatelogs"
 	"github.com/sirupsen/logrus"
-
+	"lc-fangdaosha/eventServer"
+	"lc-fangdaosha/gatewayServer"
 	"lc-fangdaosha/global"
 	"lc-fangdaosha/initialize"
 	"lc-fangdaosha/service/system"
 	"net/http"
 	"os"
+	"path"
 	"time"
 )
 
 func main() {
-	logrus.SetLevel(logrus.DebugLevel)
-	logrus.SetOutput(os.Stdout)
-	logrus.SetReportCaller(true)
-	initialize.OtherInit() //初始化缓存
+	initLogrus()
+	go eventServer.StartEventServer() //摄像头事件监听服务端
+	go gatewayServer.GatewayServe()   //网关服务端
+	initialize.OtherInit()            //初始化缓存
 	//initialize.Redis()
 	global.Db = initialize.Gorm() //初始化数据库orm
 	if global.Db != nil {
-		//initialize.RegisterTables() //初始化表
 		// 程序结束前关闭数据库链接
 		db, _ := global.Db.DB()
 		defer db.Close()
@@ -54,3 +56,20 @@ func initServer(address string, router *gin.Engine) server {
 		MaxHeaderBytes: 1 << 20,
 	}
 }
+
+func initLogrus() {
+	err := os.MkdirAll("./log", os.ModeDir)
+	if err != nil {
+		panic(err)
+	}
+	fileName := path.Join("./log", "info")
+	writer, _ := rotatelogs.New(
+		fileName+".%Y%m%d.log",
+		rotatelogs.WithMaxAge(15*24*time.Hour),    // 文件最大保存时间
+		rotatelogs.WithRotationTime(24*time.Hour), // 日志切割时间间隔
+	)
+	logrus.SetLevel(logrus.DebugLevel)
+	logrus.SetOutput(os.Stdout)
+	logrus.SetReportCaller(true)
+	logrus.SetOutput(writer)
+}

+ 6 - 9
service/app/gateway.go

@@ -15,7 +15,6 @@ var ExistError = errors.New("已存在")
 type GatewayService struct {
 }
 
-// CreateIfNotExist 创建
 func (gs *GatewayService) CreateIfNotExist(isn string) (*app.Gateway, error) {
 	var gate *app.Gateway
 	err := global.Db.Select("id, isn").Model(&app.Gateway{}).Where("isn = ? AND is_deleted = 0", isn).Scan(&gate).Debug().Error
@@ -36,7 +35,7 @@ func (gs *GatewayService) CreateIfNotExist(isn string) (*app.Gateway, error) {
 
 // List 该用户下所有设备数据
 func (gs *GatewayService) List(req request.GatewayRequest) (list []response.Gateways, err error) {
-	db := global.Db.Select("g.id,g.gateway_name,g.osn,g.description,c.name AS camera_name, RIGHT(c.sn,9) AS camera_sn,c.stream_id,c.stream_url,i.device_id AS ipcast_id,i.state AS ipcast_state").
+	db := global.Db.Select("g.id,g.gateway_name,g.osn,g.description,c.name AS camera_name, RIGHT(c.sn,9) AS camera_sn,c.stream_id,c.stream_url").
 		Table("gateway g LEFT JOIN camera c ON g.id = c.gid").
 		Where("g.is_deleted = 0")
 	//条件查询设备,网关名,网关osn,摄像头sn
@@ -47,7 +46,7 @@ func (gs *GatewayService) List(req request.GatewayRequest) (list []response.Gate
 		db.Where("g.osn = ?", req.Osn)
 	}
 	if req.CameraSn != "" {
-		db.Where("c.camera_sn LIKE ?", "%"+req.CameraSn)
+		db.Where("c.sn LIKE ?", "%"+req.CameraSn)
 	}
 	if req.Name != "" {
 		db.Where("gateway_name LIKE ?", "%"+req.Name+"%")
@@ -104,7 +103,6 @@ func (gs *GatewayService) DeleteGateways(gw app.Gateway) (err error) {
 			logrus.Error("删除摄像头失败", err)
 		}
 	}
-
 	return err
 }
 
@@ -118,18 +116,17 @@ func (gs *GatewayService) UnbindGateways(gw app.Gateway) error {
 			err = errors.Join(err1)
 		}
 	}
-
 	if err == nil {
 		logrus.WithFields(logrus.Fields{"网关": devs.Osn, "摄像头": devs.Csn}).Info("解绑成功")
 	}
 	return err
 }
 
-// DevIds 获取设备的id
+// DevIds 查询网关及关联设备的id
 func (gs *GatewayService) DevIds(id uint) (devs app.Devices) {
-	//查询网关及关联设备的id
-	global.Db.Select("g.id AS gid,g.osn,c.id AS cid,RIGHT(c.sn,9) AS csn,i.id AS iid").
+	global.Db.Select("g.id AS gid,g.osn,c.id AS cid,RIGHT(c.sn,9) AS csn").
 		Table("gateway g LEFT JOIN camera c ON g.id = c.gid").
-		Where("g.id = ?", id).Find(&devs)
+		Where("g.id = ?", id).
+		Find(&devs)
 	return
 }

+ 2 - 2
service/isapi/sipServer.go

@@ -14,7 +14,7 @@ type IsApiService struct {
 func GetSipUserID() (int, error) {
 	var is isapi.SipId
 	var is2 isapi.SipId
-	erro := global.Db.Debug().Transaction(func(tx *gorm.DB) error {
+	err := global.Db.Debug().Transaction(func(tx *gorm.DB) error {
 		err := tx.Select("id, user_id").Model(&is).First(&is).Debug().Error
 		if err != nil {
 			return err
@@ -26,5 +26,5 @@ func GetSipUserID() (int, error) {
 		fmt.Println("user_id ", is.UserId)
 		return nil
 	})
-	return is.UserId, erro
+	return is.UserId, err
 }