Jelajahi Sumber

一键求助记录 完成

sixian 2 tahun lalu
induk
melakukan
33688a8b86

+ 9 - 3
Makefile

@@ -1,15 +1,21 @@
 BINARY="build/iot_service"
 VERSION=1.0.0
-BASH_PATH=D:\Programs\Git\bin\bash.exe
 export GOARCH=amd64
 export GOOS=linux
+SHELL := D:\Programs\Git\bin\bash.exe
 
 clear:
-	$(RM) ${BINARY}
+	@$(RM) ${BINARY}
 
 build:
 	@go build -o ${BINARY} ./
 
 push-test:build
-	${BASH_PATH} ./push.sh
+	@$(push_test)
 .PHONY: build push-test
+
+define push_test
+	ssh root@110.40.223.170 "service  go-iot_service stop;/usr/bin/rm -rf /opt/lc/iot_svr/iot_service"
+    scp -r build/* root@110.40.223.170:/opt/lc/iot_svr/
+    ssh root@110.40.223.170 "chmod +x /opt/lc/iot_svr/iot_service;service  go-iot_service start;sleep 3;service  go-iot_service status"
+endef

+ 10 - 0
app/record/controller/lightRecordController.go

@@ -64,3 +64,13 @@ func (c *lightRecordCtl) Refresh(ctx *gin.Context) {
 	}()
 	ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, nil))
 }
+
+func (c *lightRecordCtl) Detail(ctx *gin.Context) {
+	id, _ := strconv.Atoi(ctx.Query("id"))
+	record, err := service.LightRecordService.Detail(id)
+	if err != nil {
+		ctx.JSON(http.StatusOK, err)
+		return
+	}
+	ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, record))
+}

+ 107 - 0
app/record/dao/aKeyAlarmDao.go

@@ -0,0 +1,107 @@
+package dao
+
+import (
+	"iot_manager_service/app/record/edge_service"
+	"time"
+)
+
+type AkeyAlarmRecord struct {
+	ID             int       `gorm:"column:id;type:int(11);primary_key;AUTO_INCREMENT" json:"id" :"ID"`
+	ServeId        int       `gorm:"column:serve_id;type:int(11);comment:管理端ID" json:"serveId" :"serveId"`
+	ServeName      string    `gorm:"column:serve_name;type:varchar(60);comment:管理端名称" json:"serveName" :"serveName"`
+	ServeSn        string    `gorm:"column:serve_sn;type:varchar(60);comment:管理端编码" json:"serveSn" :"serveSn"`
+	TerminalId     int       `gorm:"column:terminal_id;type:int(11);comment:客户端ID" json:"terminalId" :"terminalId"`
+	TerminalName   string    `gorm:"column:terminal_name;type:varchar(60);comment:客户端名称" json:"terminalName" :"terminalName"`
+	TerminalSn     string    `gorm:"column:terminal_sn;type:varchar(60);comment:客户端编码" json:"terminalSn"`
+	LocalAddress   string    `gorm:"column:local_address;type:varchar(255);comment:灯杆地址" json:"localAddress"`
+	AlarmStartTime time.Time `gorm:"column:alarm_start_time;type:datetime;comment:报警开始时间" json:"alarmStartTime"`
+	AlarmEndTime   time.Time `gorm:"column:alarm_end_time;type:datetime;comment:报警结束时间" json:"alarmEndTime"`
+	AlarmCountTime int       `gorm:"column:alarm_count_time;type:int(11);default:0;comment:报警时长(秒)" json:"alarmCountTime"`
+	IsDispose      int       `gorm:"column:is_dispose;type:int(11);default:0;comment:是否处理:0-未处理,1-已处理" json:"isDispose"`
+	Remark         string    `gorm:"column:remark;type:varchar(1000);comment:备注" json:"remark"`
+	TenantId       string    `gorm:"column:tenant_id;type:varchar(12);comment:租户ID" json:"tenantId"`
+	CreateTime     time.Time `gorm:"column:create_time;type:datetime;comment:创建时间" json:"createTime"`
+	UpdateTime     time.Time `gorm:"column:update_time;type:timestamp;comment:更新时间" json:"updateTime"`
+	UpdateUser     string    `gorm:"column:update_user;type:varchar(255);comment:修改用户ID" json:"updateUser"`
+	IsDeleted      int       `gorm:"column:is_deleted;type:int(11);default:0;comment:是否删除:0-否-1删除" json:"isDeleted"`
+}
+
+func (a AkeyAlarmRecord) TableName() string {
+	return "device_a_key_alarm_record_his"
+}
+
+func (a AkeyAlarmRecord) GetRecords(offset int, limit int, start string, end string, searchValue string, serveId int) ([]AkeyAlarmRecord, error) {
+	var records []AkeyAlarmRecord
+	db := Db.Debug().Model(&a)
+	if serveId > 0 {
+		db.Where("serve_id=?", serveId)
+	}
+	if searchValue != "" {
+		db = db.Where("terminal_sn like ? or terminal_name like ?", "%"+searchValue+"%", "%"+searchValue+"%")
+	}
+	if start != "" {
+		start = start + " 00:00:00"
+		end = end + " 23:59:59"
+		db = db.Where("alarm_start_time >=? and  alarm_end_time <= ?", start, end)
+	}
+	err := db.Where("is_deleted = 0").Offset(offset).Limit(limit).Find(&records).Error
+	return records, err
+}
+
+func (a AkeyAlarmRecord) GetMaxIdAndUpDateTime() (int64, string) {
+	var record AkeyAlarmRecord
+	err := Db.Debug().Order("id desc").First(&record).Error
+	if err != nil {
+		return 0, "2020-01-01 00:00:00"
+	}
+	return int64(record.ID), record.CreateTime.Format("2006-01-02 15:04:05")
+}
+
+func (a AkeyAlarmRecord) BatchCreate(record []edge_service.RecordAlarmSosData) error {
+	his, err := a.assembleRecordHis(record)
+	//fmt.Printf("his = %v", his)
+	if err != nil {
+		return err
+	}
+	return Db.Debug().CreateInBatches(his, 1000).Error
+}
+
+func (a AkeyAlarmRecord) assembleRecordHis(records []edge_service.RecordAlarmSosData) ([]AkeyAlarmRecord, error) {
+	var temRecords []AkeyAlarmRecord
+	Db.Debug().Raw("select a.tenant_id,a.id terminal_id,a.terminal_name,a.terminal_sn, a.lamp_pole_location local_address,a.serve_id, b.serve_name,b.serve_sn FROM device_a_key_alarm_terminal a LEFT JOIN device_a_key_alarm_serve b ON a.serve_id=b.id WHERE a.is_deleted=0").
+		Scan(&temRecords)
+
+	m := make(map[string]AkeyAlarmRecord)
+	for _, temSosRecord := range temRecords {
+		m[temSosRecord.TerminalSn] = temSosRecord
+	}
+	var realLightRecords []AkeyAlarmRecord
+	for _, record := range records {
+		lightRecord := m[record.Code]
+		if lightRecord.ServeId == 0 {
+			continue
+		}
+		lightRecord.ID = record.ID
+		lightRecord.AlarmStartTime, _ = time.ParseInLocation("2006-01-02 15:04:05", record.Tstart, time.Local)
+		lightRecord.AlarmEndTime, _ = time.ParseInLocation("2006-01-02 15:04:05", record.Tend, time.Local)
+		lightRecord.AlarmCountTime = int(record.Duration)
+		lightRecord.IsDeleted = 0
+		lightRecord.IsDispose = 0
+		lightRecord.TerminalSn = record.Code
+		lightRecord.CreateTime = time.Now()
+		lightRecord.UpdateTime = time.Now()
+		realLightRecords = append(realLightRecords, lightRecord)
+	}
+	return realLightRecords, nil
+}
+
+func (a AkeyAlarmRecord) Get() (*AkeyAlarmRecord, error) {
+	var record AkeyAlarmRecord
+	err := Db.Debug().Model(&a).First(&record).Error
+	return &record, err
+}
+
+func (a AkeyAlarmRecord) Update() error {
+	err := Db.Debug().Model(&a).Updates(&a).Error
+	return err
+}

+ 11 - 5
app/record/dao/common.go

@@ -3,16 +3,22 @@ package dao
 import (
 	"fmt"
 	"gorm.io/gorm"
+	"iot_manager_service/util/common"
 )
 
 var Db *gorm.DB
 
 func InitDB(db *gorm.DB) {
 	Db = db
-	err := Db.AutoMigrate(
-		&LightRecord{},
-	)
-	if err != nil {
-		panic(fmt.Sprintf("AutoMigrate err : %v", err))
+	models := []common.TableModelAuto{
+		{&LightRecord{}, "亮灯记录表"},
+		{&AkeyAlarmRecord{}, "一键求助记录表"},
+	}
+	for _, val := range models {
+		//fmt.Println(val.Model)
+		err := Db.Set("gorm:table_options", "comment '"+val.Comment+"'").AutoMigrate(val.Model)
+		if err != nil {
+			panic(fmt.Sprintf("AutoMigrate err : %v", err))
+		}
 	}
 }

+ 10 - 1
app/record/dao/lightRecordDao.go

@@ -50,9 +50,12 @@ func (l LightRecord) BatchCreate(record []edge_service.RecordLightUpData) error
 }
 
 // GetRecords 查记录
-func (c LightRecord) GetRecords(offset int, limit int, start, end, searchValue string) ([]LightRecord, error) {
+func (c LightRecord) GetRecords(offset int, limit int, start, end, searchValue string, groupId int) ([]LightRecord, error) {
 	var LightRecords []LightRecord
 	db := Db.Debug().Model(&c)
+	if groupId > 0 {
+		db.Where("group_id=?", groupId)
+	}
 	if searchValue != "" {
 		db = db.Where("light_control_sn like ? or lamp_pole_name like ?", "%"+searchValue+"%", "%"+searchValue+"%")
 	}
@@ -92,3 +95,9 @@ func (l LightRecord) assembleRecordHis(records []edge_service.RecordLightUpData)
 	}
 	return realLightRecords, nil
 }
+
+func (l LightRecord) Get() (LightRecord, error) {
+	var lightRecord LightRecord
+	err := Db.Debug().Model(&l).First(&lightRecord).Error
+	return lightRecord, err
+}

+ 52 - 0
app/record/service/aKeyAlarmRecordService.go

@@ -0,0 +1,52 @@
+package service
+
+import (
+	"fmt"
+	"iot_manager_service/app/record/dao"
+	"iot_manager_service/app/record/edge_service"
+)
+
+var AKeyAlarmRecordService = new(aKeyAlarmRecordService)
+
+type aKeyAlarmRecordService struct{}
+
+func (s aKeyAlarmRecordService) List(searchValue string, start string, end string, id int, current int, size int) ([]dao.AkeyAlarmRecord, error) {
+	var record dao.AkeyAlarmRecord
+	offset := (current - 1) * size
+	limit := size
+	records, err := record.GetRecords(offset, limit, start, end, searchValue, id)
+	if err != nil {
+		return nil, err
+	}
+	return records, nil
+}
+
+func (s aKeyAlarmRecordService) Detail(id int) (*dao.AkeyAlarmRecord, error) {
+	record := &dao.AkeyAlarmRecord{
+		ID: id,
+	}
+	return record.Get()
+}
+
+func (s aKeyAlarmRecordService) Refresh() {
+	// TODO:边缘数据
+	up := edge_service.RecordAlarmSos{}
+	maxId, maxUpDateTime := dao.AkeyAlarmRecord{}.GetMaxIdAndUpDateTime()
+	recordLightUpDatas, err := up.SyncRecord(maxId, maxUpDateTime)
+	//fmt.Printf("recordLightUpDatas = %v", recordLightUpDatas)
+	dao.AkeyAlarmRecord{}.BatchCreate(recordLightUpDatas)
+	if err != nil {
+		fmt.Printf("Refresh err.Error() = %v", err)
+		return
+	}
+}
+
+func (s aKeyAlarmRecordService) UpdateRemark(id int, remark string) error {
+	record := dao.AkeyAlarmRecord{ID: id}
+	record.Remark = remark
+	err := record.Update()
+	if err != nil {
+		return err
+	}
+	return nil
+}

+ 8 - 1
app/record/service/lightRecordService.go

@@ -15,7 +15,7 @@ func (s *lightRecordService) List(searchValue, start, end string, id int, curren
 	var record dao.LightRecord
 	offset := (current - 1) * size
 	limit := size
-	records, err := record.GetRecords(offset, limit, start, end, searchValue)
+	records, err := record.GetRecords(offset, limit, start, end, searchValue, id)
 	if err != nil {
 		return nil, common.FailResponse(err.Error(), nil)
 	}
@@ -35,3 +35,10 @@ func (s *lightRecordService) Refresh() {
 		return
 	}
 }
+
+func (s *lightRecordService) Detail(id int) (dao.LightRecord, error) {
+	record := &dao.LightRecord{
+		Id: id,
+	}
+	return record.Get()
+}

+ 2 - 4
app/security/edge_service/forRewindService.go

@@ -8,7 +8,7 @@ import (
 	"net/url"
 )
 
-// Rewind 回放记录
+// ForRewindService  回放记录
 type ForRewindService struct {
 }
 
@@ -40,12 +40,10 @@ func (f *ForRewindService) getRewindApi(url string) (string, error) {
 	return string(body), err
 }
 
+// GetRewindText 请求回话加密数据
 func (f *ForRewindService) GetRewindText(streamId string, date string) (string, error) {
-	//fmt.Printf("streamId = %v", streamId)
 	cfg := config.Instance()
 	api := cfg.Foreign.SecurityRewindUrl + "/list/%v/%v"
 	url2 := fmt.Sprintf(api, (streamId), url.QueryEscape(date))
-	//fmt.Printf("url2 = %v", url2)
-	//return "", nil
 	return f.getRewindApi(url2)
 }

+ 0 - 6
push.sh

@@ -1,6 +0,0 @@
-#!/bin/bash
-ssh root@110.40.223.170 "service  go-iot_service stop;/usr/bin/rm -r /opt/lc/iot_svr/iot_service"
-scp -r build/* root@110.40.223.170:/opt/lc/iot_svr/
-ssh root@110.40.223.170 "chmod +x /opt/lc/iot_svr/iot_service;service  go-iot_service start;sleep 3;service  go-iot_service status"
-
-

+ 16 - 4
router/router.go

@@ -445,12 +445,24 @@ func InitRouter(engine *gin.Engine) {
 		workbench.GET("light-pandect", device.Workbench.LightRate)
 	}
 
-	//数据统计记录
+	//记录
 	recordGroup := engine.Group("/api/longchi/record")
-	lightRecord := recordGroup.Group("/lighting/lightingrecordhis")
 	{
-		lightRecord.GET("/list", record.LightRecord.List)
-		lightRecord.POST("/refresh", record.LightRecord.Refresh)
+		//灯控
+		lightRecord := recordGroup.Group("/lighting/lightingrecordhis")
+		{
+			lightRecord.GET("/list", record.LightRecord.List)
+			lightRecord.GET("/detail", record.LightRecord.Detail)
+			lightRecord.POST("/refresh", record.LightRecord.Refresh)
+		}
+
+		akeyalarmRecord := recordGroup.Group("/akeyalarm/keyalarmrecondhis")
+		{
+			akeyalarmRecord.GET("/list", record.AKeyAlarmRecord.List)
+			akeyalarmRecord.GET("/detail", record.AKeyAlarmRecord.Detail)
+			akeyalarmRecord.GET("/refresh", record.AKeyAlarmRecord.Refresh)
+			akeyalarmRecord.POST("/dispose", record.AKeyAlarmRecord.Dispose)
+		}
 	}
 
 	//安防

+ 1 - 0
util/common/common.go

@@ -149,6 +149,7 @@ func IsAdmin(roleId int64) bool {
 	return roleId == 1
 }
 
+// TableModelAuto 给表命名字
 type TableModelAuto struct {
 	Model   interface{}
 	Comment string