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

featrue(mcs_api,sa_api): 大屏报警器,增加自定义显示排序支持

sunmiao 3 жил өмнө
parent
commit
ab84e2cf90

+ 1 - 1
backend/src/dashoo.cn/alertorapp/business/userchannels/channelsService.go

@@ -19,6 +19,7 @@ func GetChannelService(xormEngine *xorm.Engine) *ChannelService {
 	return s
 }
 
+// V2版大屏报警器 获取报警器绑定的传感器信息,包括传感器分类
 func (s *ChannelService) GetCnameByCodePage(pageIndex, itemsPerPage int64, order string, asc bool, where string) (int64, []Channels) {
 	var err error
 	var total int64 //获取总记录数
@@ -39,5 +40,4 @@ func (s *ChannelService) GetCnameByCodePage(pageIndex, itemsPerPage int64, order
 		}
 	}
 	return total, list
-
 }

+ 79 - 15
backend/src/dashoo.cn/alertorapp/controllers/home.go

@@ -184,6 +184,7 @@ func (this *HomeController) MainGrid6() {
 	// this.TplName = "homecontroller/maingrid6.tpl"
 }
 
+// V2版大屏报警器获取报警信息(兼容V1版)
 func (this *HomeController) TriggerPost() {
 	ccode := this.Ctx.Input.Param(":ccode")
 	list_history := GetHistory(ccode)
@@ -199,6 +200,7 @@ func (this *HomeController) TriggerPost() {
 	this.ServeJSON()
 }
 
+// V2版大屏报警器获取绑定的设备信息(兼容V1版)
 func (this *HomeController) ChannelPost() {
 	//获取分页信息
 	currentPage, _ := strconv.ParseInt(this.GetString("_currentPage"), 10, 64)
@@ -208,33 +210,92 @@ func (this *HomeController) ChannelPost() {
 	cmodels := make([]ChannelModel, 0)
 
 	var list []userchannels.Channels
-	var total int64 = 0
+	var total int = 0
 	if alertorstrs != "" {
-		codes := strings.Replace(alertorstrs, ",", "','", -1)
+		// channelstr := strings.Replace(alertorstrs, "c", "", -1)
+		channels := strings.Split(alertorstrs, ",")
+
+		total = len(channels)
+		// totalPage := int(math.Ceil(float64(total) / float64(size)))
+		beginIndex := (int(currentPage) - 1) * int(size)
+		endIndex := int(currentPage)*int(size) - 1
+
+		curPageChannels := make([]string, 10)
+		if total <= endIndex {
+			curPageChannels = channels[beginIndex:]
+		} else {
+			curPageChannels = channels[beginIndex : endIndex+1]
+		}
+
+		curPageChannelStr := strings.Join(curPageChannels, ",")
+		codes := strings.Replace(curPageChannelStr, ",", "','", -1)
 		svc := userchannels.GetChannelService(MCS_DBE)
 		where := "c.Code in ('" + codes + "')"
-		total, list = svc.GetCnameByCodePage(currentPage, size, "Id", false, where)
-		for _, v := range list {
-			t, h, o2, co2, cjtime, lv, ls, voltage, power := GetTH(v.Code)
-			//字符串分割
-			codde := strings.Replace(v.Code, "c", "", 1)
-			cdss := timeshijian(cjtime.Format("2006-01-02 15:04:05"))
-			online := 1
-			if cdss {
-				online = 1
-			} else {
-				online = 0
+		_, list = svc.GetCnameByCodePage(1, size, "Id", false, where)
+
+		count := len(list)
+		for i := 0; i < count; i++ {
+			code := curPageChannels[i]
+			for _, v := range list {
+				if code == v.Code {
+					t, h, o2, co2, cjtime, lv, ls, voltage, power := GetTH(v.Code)
+					codde := strings.Replace(v.Code, "c", "", 1)
+					cdss := timeshijian(cjtime.Format("2006-01-02 15:04:05"))
+					online := 0
+					if cdss {
+						online = 1
+					}
+					cmodels = append(cmodels, ChannelModel{t, h, o2, co2, cjtime.Format("2006-01-02 15:04:05"), v.MaxValue, v.MinValue, v.Title, codde, lv, ls, v.DataItem, online, v.EModelType, voltage, power})
+
+					break
+				}
 			}
-			cmodels = append(cmodels, ChannelModel{t, h, o2, co2, cjtime.Format("2006-01-02 15:04:05"), v.MaxValue, v.MinValue, v.Title, codde, lv, ls, v.DataItem, online, v.EModelType, voltage, power})
+
 		}
 	}
 	var datainfo DataInfo
 	datainfo.Items = cmodels
-	datainfo.CurrentItemCount = total
+	datainfo.CurrentItemCount = int64(total)
 	this.Data["json"] = datainfo
 	this.ServeJSON()
 }
 
+// func (this *HomeController) ChannelPost() {
+// 	//获取分页信息
+// 	currentPage, _ := strconv.ParseInt(this.GetString("_currentPage"), 10, 64)
+// 	size, _ := strconv.ParseInt(this.GetString("_size"), 10, 64)
+// 	ccode := this.Ctx.Input.Param(":ccode")
+// 	alertorstrs := GetAlertor(ccode)
+// 	cmodels := make([]ChannelModel, 0)
+
+// 	var list []userchannels.Channels
+// 	var total int64 = 0
+// 	if alertorstrs != "" {
+// 		codes := strings.Replace(alertorstrs, ",", "','", -1)
+// 		svc := userchannels.GetChannelService(MCS_DBE)
+// 		where := "c.Code in ('" + codes + "')"
+// 		total, list = svc.GetCnameByCodePage(currentPage, size, "Id", false, where)
+// 		for _, v := range list {
+// 			t, h, o2, co2, cjtime, lv, ls, voltage, power := GetTH(v.Code)
+// 			//字符串分割
+// 			codde := strings.Replace(v.Code, "c", "", 1)
+// 			cdss := timeshijian(cjtime.Format("2006-01-02 15:04:05"))
+// 			online := 1
+// 			if cdss {
+// 				online = 1
+// 			} else {
+// 				online = 0
+// 			}
+// 			cmodels = append(cmodels, ChannelModel{t, h, o2, co2, cjtime.Format("2006-01-02 15:04:05"), v.MaxValue, v.MinValue, v.Title, codde, lv, ls, v.DataItem, online, v.EModelType, voltage, power})
+// 		}
+// 	}
+// 	var datainfo DataInfo
+// 	datainfo.Items = cmodels
+// 	datainfo.CurrentItemCount = total
+// 	this.Data["json"] = datainfo
+// 	this.ServeJSON()
+// }
+
 func (this *HomeController) ChannelPost5() {
 	ccode := this.Ctx.Input.Param(":ccode")
 	alertorstrs := GetAlertor(ccode)
@@ -264,6 +325,8 @@ func EditSend(list []triggerhistory.Trigger_History) {
 	svc.EditSend(list)
 }
 
+// 获取报警器取绑定传感器信息(保存在缓存中) todo 持久化的DB中
+// RequestData示例数据  "RequestData": "c52021810,c52061395,c52063466,c52063465,c52063463"
 func GetAlertor(bbmac string) string {
 	selectstr := ""
 	lastdata, err := GetChannelLast("calert" + bbmac)
@@ -273,6 +336,7 @@ func GetAlertor(bbmac string) string {
 	return selectstr
 }
 
+// 获取传感器最新数据(从缓存中获取)
 func GetTH(code string) (t, h, o2, co2 float32, cjtime time.Time, levelv, levelsignal, v, p int) {
 	lastdata, err := GetChannelLast(code)
 	if err == nil && lastdata.Time.Unix() > 0 {

+ 8 - 4
backend/src/dashoo.cn/mcs_api/controllers/alerts.go

@@ -99,7 +99,6 @@ func (this *AlertsController) ValidCode() {
 // @Success	200	{object} controllers.Request
 // @router / [post]
 func (this *AlertsController) AddPost() {
-	fmt.Println("-------wowowowow-----")
 	var model AlertModel
 	var jsonblob = this.Ctx.Input.RequestBody
 	json.Unmarshal(jsonblob, &model)
@@ -114,7 +113,6 @@ func (this *AlertsController) AddPost() {
 	svc := device.GetDeviceService(utils.DBE)
 	var entity device.Device
 	strUrl := utils.Cfg.MustValue("server", "apiurl") + "/devices/serial?serial=" + devices.Serial
-	fmt.Println("-------strUrl111--------", strUrl)
 	json.Unmarshal(Apiget(strUrl), &entity)
 	if svc.VerifyDevice(entity.Id) {
 		errinfo.Message = "报警器已存在!"
@@ -235,7 +233,10 @@ func (this *AlertsController) AddPost() {
 								}
 							}
 							// 写入绑定缓存
-							WriteAlertBindValue("alert"+model.Serial, strings.Join(bindchannelcodes, ","))
+							for i, _ := range model.BindDevices {
+								model.BindDevices[i] = "c" + model.BindDevices[i]
+							}
+							WriteAlertBindValue("alert"+model.Serial, strings.Join(model.BindDevices, ","))
 							// 写入网关报警一体机下发数据
 							downdatas.AlarmBinds = downdatadetail
 							labsop.UpdateAlarmbinddata(model.Serial, downdatas)
@@ -418,7 +419,10 @@ func (this *AlertsController) EditPost() {
 			}
 			fmt.Println("-------downdatadetail-------", model.Serial, downdatadetail)
 			// 写入绑定缓存
-			WriteAlertBindValue("alert"+model.Serial, strings.Join(bindchannelcodes, ","))
+			for i, _ := range model.BindDevices {
+				model.BindDevices[i] = "c" + model.BindDevices[i]
+			}
+			WriteAlertBindValue("alert"+model.Serial, strings.Join(model.BindDevices, ","))
 			// 写入网关报警一体机下发数据
 			downdatas.AlarmBinds = downdatadetail
 			labsop.UpdateAlarmbinddata(model.Serial, downdatas)