Bladeren bron

设备图上传

sixian 2 jaren geleden
bovenliggende
commit
a7c5641792

+ 51 - 8
app/device/dao/gatewayRelationDao.go

@@ -1,19 +1,22 @@
 package dao
 
 import (
+	"fmt"
 	"time"
 )
 
 //GatewayRelation 网关挂载设备关联信息表
 type GatewayRelation struct {
-	ID                 int       `gorm:"type:int;primary_key"`                //编号 网关ID
-	LightControlCount  int       `gorm:"type:int;default 0"`                  //灯控数量
-	InfoBoardCount     int       `gorm:"type:int;default 0"`                  //信息屏数量
-	OptoSensorCount    int       `gorm:"type:int;default 0"`                  //环境传感器数量
-	ZigbeeCount        int       `gorm:"type:int;default 0"`                  //Zigbee设备数量
-	AlarmTerminalCount int       `gorm:"type:int;default 0"`                  //告警终端数量
-	CaptureUnitCount   int       `gorm:"type:int;default 0"`                  //抓拍单元数量
-	IpBroadcastCount   int       `gorm:"type:int;default 0"`                  //IP音柱数量
+	ID                 int       `gorm:"type:int;primary_key"` //编号 网关ID
+	CameraCount        int       `gorm:"type:int;default 0" comment:"球机数量"`
+	LightControlCount  int       `gorm:"type:int;default 0"` //灯控数量
+	InfoBoardCount     int       `gorm:"type:int;default 0"` //信息屏数量
+	OptoSensorCount    int       `gorm:"type:int;default 0"` //环境传感器数量
+	ZigbeeCount        int       `gorm:"type:int;default 0"` //Zigbee设备数量
+	AlarmTerminalCount int       `gorm:"type:int;default 0"` //告警终端数量
+	CaptureUnitCount   int       `gorm:"type:int;default 0"` //抓拍单元数量
+	IpBroadcastCount   int       `gorm:"type:int;default 0"` //IP音柱数量
+	CurveSensorCount   int       `gorm:"type:int;default 0" comment:"信息屏"`
 	Total              int       `gorm:"type:int;default 0"`                  //总数
 	TenantId           int       `gorm:"type:int" json:"tenantId"`            //租户ID
 	CreateTime         time.Time `gorm:"type:datetime" json:"createTime"`     //新增时间
@@ -28,3 +31,43 @@ func (GatewayRelation) TableName() string {
 func (c *GatewayRelation) Get() error {
 	return Db.Debug().Model(&c).Where("id = ?", c.ID).Find(&c).Error
 }
+
+// 2022-12-08 dsx 查出所有数据更新进去
+func (c *GatewayRelation) Update(gatewayId int64) error {
+	relation := GatewayRelation{}
+	sql := `SELECT * from (
+				(SELECT count(1) camera_count from device_camera where is_deleted=0 and gateway_id in (48)) as camera_count,
+				(SELECT count(1) light_control_count from device_light_control where is_deleted=0 and gateway_id in (48)) as light_control_count,
+				(SELECT count(1) info_board_count from device_info_board where is_deleted=0 and gateway_id in (48)) as info_board_count,
+				(SELECT count(1) opto_sensor_count from device_opto_sensor where is_deleted=0 and gateway_id in (48)) as opto_sensor_count,
+				(SELECT count(1) zigbee_count from device_zigbee where is_deleted=0 and gateway_id in (48)) as zigbee_count,
+				(SELECT count(1) alarm_terminal_count from device_a_key_alarm_terminal where is_deleted=0 and gateway_id in (48)) as alarm_terminal_count,
+				(SELECT count(1) capture_unit_count from device_capture_unit where is_deleted=0 and gateway_id in (48)) as capture_unit_count,
+				(SELECT count(1) ip_broadcast_count from device_ip_broadcast where is_deleted=0 and gateway_id in (48)) as ip_broadcast_count,
+				(SELECT count(1) curve_sensor_count from device_curve_sensor where is_deleted=0 and gateway_id in (48)) as curve_sensor_count
+            ) limit 1`
+	//fmt.Printf("gatewayId = %v", gatewayId)
+	//sql = strings.ReplaceAll(sql, "@id", string(gatewayId))
+	//fmt.Printf("sql = %v", sql)
+	//Db.Model(&c).Debug().Exec(sql, gatewayId, gatewayId, gatewayId, gatewayId, gatewayId, gatewayId, gatewayId, gatewayId, gatewayId).Scan(&relation)
+	Db.Model(&c).Debug().Exec(sql).Scan(&relation)
+	fmt.Printf("relation1 = %v", relation)
+	return nil
+	relation.Total = relation.CameraCount + relation.LightControlCount + relation.InfoBoardCount +
+		relation.OptoSensorCount + relation.ZigbeeCount + relation.AlarmTerminalCount +
+		relation.CaptureUnitCount + relation.IpBroadcastCount + relation.CurveSensorCount
+	fmt.Printf("relation2 = %v", relation)
+	//return nil
+	var count int64
+	_ = Db.Debug().Model(&c).Where(" id = ? ", gatewayId).Count(&count)
+	fmt.Printf("count = %v", count)
+	if count > 0 {
+		relation.UpdateTime = time.Now()
+		return Db.Debug().Model(&c).Where(" id = ? ", gatewayId).Updates(&relation).Error
+	} else {
+		relation.ID = int(gatewayId)
+		relation.UpdateTime = time.Now()
+		relation.CreateTime = time.Now()
+		return Db.Debug().Model(&c).Create(&relation).Error
+	}
+}

+ 1 - 1
app/device/dao/optoSensoDao.go

@@ -128,7 +128,7 @@ func (c OptoSensor) getList(optoSensor OptoSensor) []OptoSensorVO {
 	if optoSensor.IsDefault == 1 {
 		where = "and a.is_default=1"
 	}
-	Db.Debug().Raw("SELECT a.*, v3.id brand, v4.id model, lamp.district_name FROM device_opto_sensor a LEFT JOIN device_vendor v3 ON v3.id = a.brand_id LEFT JOIN device_vendor v4 ON v4.id = a.model_id LEFT JOIN device_lamp_pole lamp ON lamp.id = a.lamp_pole_id WHERE a.is_deleted = 0 " + where).Scan(&optoSensorVO)
+	Db.Model(&c).Debug().Raw("SELECT a.*, v3.id brand, v4.id model, lamp.district_name FROM device_opto_sensor a LEFT JOIN device_vendor v3 ON v3.id = a.brand_id LEFT JOIN device_vendor v4 ON v4.id = a.model_id LEFT JOIN device_lamp_pole lamp ON lamp.id = a.lamp_pole_id WHERE a.is_deleted = 0 " + where).Scan(&optoSensorVO)
 
 	return optoSensorVO
 }

+ 1 - 0
app/device/service/gatewayRelationService.go

@@ -16,6 +16,7 @@ func (s *gatewayRelationService) Get(id int) (*dao.GatewayRelation, *common.Erro
 		ID: id,
 	}
 	err := relation.Get()
+	//relation.Update() //临时 处理
 	if err != nil {
 		return nil, common.FailResponse(err.Error(), nil)
 	}

+ 7 - 0
app/device/service/gatewayService.go

@@ -105,9 +105,16 @@ func (s *gatewayService) List(searchValue string, current, size int) ([]model.Ga
 	for _, d := range devices {
 		detail := model.GatewayDetail{Gateway: d}
 		relation, _ := GatewayRelationService.Get(d.ID)
+
+		fmt.Printf("d.ID = %v", d.ID)
+		//查数据
+		relation2 := dao.GatewayRelation{}
+		relation2.Update(int64(d.ID)) //临时 处理
+
 		if relation != nil {
 			detail.CountLampPole = relation.Total
 		}
+
 		endTime, state := cache.GetDeviceState(d.GatewaySn)
 		detail.RunState = state
 		detail.EndLineTime = endTime

+ 25 - 0
doc/db_upgrade/upgrade_20221208.sql

@@ -0,0 +1,25 @@
+CREATE TABLE `device_curve_sensor` (
+                                       `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '编号',
+                                       `sensor_name` varchar(64) DEFAULT NULL COMMENT '传感器名称',
+                                       `sensor_sn` varchar(32) DEFAULT NULL COMMENT '传感器编码',
+                                       `lamp_pole_id` int(11) DEFAULT NULL COMMENT '灯杆ID',
+                                       `gateway_id` int(11) DEFAULT NULL COMMENT '网关id',
+                                       `is_deleted` int(11) DEFAULT '0' COMMENT '是否删除:0=未删除,1=删除',
+                                       `install_time` date DEFAULT NULL COMMENT '安装时间',
+                                       `terrain_clearance` double(10,1) DEFAULT '0.0' COMMENT '离地高度(米)',
+  `direction` int(11) DEFAULT NULL COMMENT '抓拍方位',
+  `suggest_speed` int(11) DEFAULT NULL COMMENT '路段建议速度',
+  `resolution` int(11) DEFAULT NULL COMMENT '分辨率',
+  `brand_id` int(11) DEFAULT NULL COMMENT '设备品牌',
+  `model_id` int(11) DEFAULT NULL COMMENT '设备型号',
+  `info_size` int(11) DEFAULT NULL COMMENT '信息屏尺寸',
+  `setting_ip` varchar(60) DEFAULT NULL COMMENT '设备ip',
+  `setting_port` int(11) DEFAULT NULL COMMENT '设备端口',
+  `tenant_id` varchar(12) DEFAULT NULL COMMENT '租户ID',
+  `create_time` datetime DEFAULT NULL COMMENT '新增时间',
+  `create_user` varchar(30) DEFAULT NULL COMMENT '新增记录操作用户ID',
+  `update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '修改时间',
+  `update_user` varchar(30) DEFAULT NULL COMMENT '修改用户',
+  `state` int(2) DEFAULT '1' COMMENT '启用状态:1启用,0禁用',
+  PRIMARY KEY (`id`)
+) ENGINE=MyISAM AUTO_INCREMENT=40 DEFAULT CHARSET=utf8 COMMENT='弯道传感器';

+ 7 - 0
router/router.go

@@ -468,6 +468,13 @@ func InitRouter(engine *gin.Engine) {
 		multimediaGroup.POST("/putFile", multimedia.Library.UploadFile)
 		multimediaGroup.POST("/submit", multimedia.Library.Submit)
 	}
+
+	//上传设备图
+	systemGroup := engine.Group("/api/longchi/system/public")
+	{
+		systemGroup.POST("/putFile", multimedia.Library.UploadFile)
+	}
+
 	// 媒体节目
 	programGroup := engine.Group("/api/longchi/multimedia/programlibraries")
 	{