Browse Source

新增时控开关设置

chengqian 4 months ago
parent
commit
74b357a4e5

+ 4 - 2
server/api/v1/devices/dev_screens.go

@@ -93,6 +93,7 @@ func (s *ScreensApi) AddScreens(c *gin.Context) {
 		Shunt:         sc.Shunt,
 		ShuntDescribe: sc.ShuntDescribe,
 		InstallTime:   sc.InstallTime,
+		SwitchSn:      sc.SwitchSn,
 	}
 	err = ScreensService.AddScreens(screens)
 	if err != nil {
@@ -131,6 +132,7 @@ func (s *ScreensApi) UpdateScreens(c *gin.Context) {
 		Shunt:         sc.Shunt,
 		ShuntDescribe: sc.ShuntDescribe,
 		InstallTime:   sc.InstallTime,
+		SwitchSn:      sc.SwitchSn,
 	}
 	err = ScreensService.UpdateScreens(screens)
 	if err != nil {
@@ -206,14 +208,14 @@ func (s *ScreensApi) VoiceBroad(c *gin.Context) {
 }
 
 // 调节亮度
-func (s *ScreensApi) SetBright(c *gin.Context) {
+func (s *ScreensApi) SetBrightAudio(c *gin.Context) {
 	var sb model.ReqBrightness
 	err := c.ShouldBindJSON(&sb)
 	if err != nil {
 		response.FailWithMessage(err.Error(), c)
 		return
 	}
-	err = ScreensService.SetBright(sb)
+	err = ScreensService.SetBrightAudio(sb)
 	if err != nil {
 		global.GVA_LOG.Error("操作失败!", zap.Error(err))
 		response.FailWithMessage("操作失败", c)

+ 10 - 4
server/dao/devices/dev_screens.go

@@ -32,6 +32,9 @@ type Screens struct {
 	LastOnlineTime  time.Time      `gorm:"type:datetime;default:NULL" json:"lastOnlineTime"`  //最近在线时间
 	LastOfflineTime time.Time      `gorm:"type:datetime;default:NULL" json:"lastOfflineTime"` //最近离线时间
 	IsLogin         int            `gorm:"type:int;default:0" json:"isLogin"`                 //是否登录 0=未登录,1=登录
+	SwitchSn        string         `gorm:"type:varchar(25)" json:"switchSn"`                  //时控开关sn
+	AudioOn         string         `gorm:"type:varchar(10);default:'00:00'" json:"audioOn"`   //开时间
+	AudioOff        string         `gorm:"type:varchar(10);default:'00:00'" json:"audioOff"`  //关时间
 
 	GateWay     GateWay     `gorm:"foreignkey:GatewayId"`
 	Resolution  Resolution  `gorm:"foreignkey:ResolutionId"`
@@ -57,7 +60,7 @@ func (s Screens) AddScreens() error {
 
 func (s Screens) UpdateScreens() error {
 	err := global.GVA_DB.Model(&s).
-		Select("screens_name", "screens_code", "sn", "network", "gateway_id", "screens_brand", "screens_model", "ip_address", "install_time", "shunt", "shunt_describe", "resolution_id", "screens_size_id").
+		Select("screens_name", "screens_code", "sn", "network", "gateway_id", "screens_brand", "screens_model", "ip_address", "install_time", "shunt", "shunt_describe", "resolution_id", "screens_size_id", "switch_sn").
 		Where("id=?", s.ID).
 		Updates(map[string]interface{}{
 			"screens_name":    s.ScreensName,
@@ -73,6 +76,7 @@ func (s Screens) UpdateScreens() error {
 			"shunt_describe":  s.ShuntDescribe,
 			"resolution_id":   s.ResolutionId,
 			"screens_size_id": s.ScreensSizeId,
+			"switch_sn":       s.SwitchSn,
 		}).Error
 	return err
 }
@@ -80,7 +84,7 @@ func (s Screens) UpdateScreens() error {
 func QueryScreensInfoList(limit, offset int, keyword, shunt string) (screensList []Screens, total int64, err error) {
 	db := global.GVA_DB.Model(&Screens{})
 	if keyword != "" {
-		db.Where("screens_name like ? or screens_code like ?", "%"+keyword+"%", "%"+keyword+"%")
+		db.Where("screens_name like ? or sn like ?", "%"+keyword+"%", "%"+keyword+"%")
 	}
 	if shunt != "" {
 		db.Where("shunt = ?", shunt)
@@ -160,13 +164,15 @@ func QueryScreenBySn(sn string) (screens Screens, err error) {
 }
 
 // 根据sn更新白天晚上亮度
-func (s Screens) UpdateBrightnessBySn(sn string, dayBright, nightBright int) error {
+func (s Screens) UpdateBrightAudioBySn(sn string, dayBright, nightBright int, audioOn, audioOff string) error {
 	err := global.GVA_DB.Model(&s).
-		Select("day_bright", "night_bright").
+		Select("day_bright", "night_bright", "audio_on", "audio_off").
 		Where("sn = ?", sn).
 		Updates(map[string]interface{}{
 			"day_bright":   dayBright,
 			"night_bright": nightBright,
+			"audio_on":     audioOn,
+			"audio_off":    audioOff,
 		}).Error
 	return err
 }

+ 16 - 0
server/model/devices/dev_screens.go

@@ -26,6 +26,7 @@ type ReqScreens struct {
 	Shunt         int       `json:"shunt"`         //所属分路 1主路,2支路
 	ShuntDescribe string    `json:"shuntDescribe"` //分路描述
 	InstallTime   time.Time `json:"installTime"`   //安装时间
+	SwitchSn      string    `json:"switchSn"`      //时控开关sn
 }
 
 type ReqInCode struct {
@@ -43,4 +44,19 @@ type ReqBrightness struct {
 	Sn          string `json:"sn"`
 	DayBright   int    `json:"dayBright"`
 	NightBright int    `json:"nightBright"`
+	AudioOn     string `json:"audioOn"`
+	AudioOff    string `json:"audioOff"`
+	SwitchSn    string `json:"switchSn"`
+}
+
+type BatchUpdateDeviceTime struct {
+	DeviceSn    []string    `json:"deviceSn"`
+	TimeSetData DeviceRelay `json:"timeSetData"`
+}
+
+type DeviceRelay struct {
+	TimeCondition1OnTime  string `json:"timeCondition1OnTime"`
+	TimeCondition1OffTime string `json:"timeCondition1OffTime" `
+	TimeCondition2OnTime  string `json:"timeCondition2OnTime" `
+	TimeCondition2OffTime string `json:"timeCondition2OffTime" `
 }

+ 1 - 1
server/router/devices/dev_screens.go

@@ -22,7 +22,7 @@ func (l *ScreensRouter) InitScreensRouter(Router *gin.RouterGroup, RouterPub *gi
 		screensRouter.POST("switchScreens", baseApi.SwitchScreens)       // 熄屏-亮屏
 		screensRouter.POST("sendInternalCode", baseApi.SendInternalCode) // 发送内码文字
 		screensRouter.POST("voiceBroad", baseApi.VoiceBroad)             // 远程喊话
-		screensRouter.POST("setBright", baseApi.SetBright)               // 调节亮度
+		screensRouter.POST("setBrightAudio", baseApi.SetBrightAudio)     // 调节亮度和声音开关时间
 	}
 	{
 		screensRouterWithoutRecord.POST("getScreensList", baseApi.ScreensList) // 分页获取网关列表

+ 70 - 20
server/service/devices/dev_screens.go

@@ -1,8 +1,11 @@
 package devices
 
 import (
+	"bytes"
+	"encoding/json"
 	"errors"
 	"gorm.io/gorm"
+	"net/http"
 	"server/dao/devices"
 	promodel "server/model/common/devices"
 	"server/model/common/request"
@@ -68,15 +71,10 @@ func (screensService *ScreensService) UpdateScreens(screens devices.Screens) err
 // 开关屏
 func (screensService *ScreensService) SwitchScreens(swatch promodel.SwitchScreens) error {
 	//判断组网方式 0代表网关 1代表4G模块
-	if swatch.Network == 1 {
-		err := tcp.SwitchScreen(swatch.Sn, swatch.Flag)
-		if err != nil {
-			logger.Logger.Errorf("SwitchScreens faild \n")
-			return errors.New("开关屏幕失败!")
-		}
-	} else {
-		//	TODO 通过mqtt发送指令开关屏
-		return nil
+	err := tcp.SwitchScreen(swatch.Sn, swatch.Flag)
+	if err != nil {
+		logger.Logger.Errorf("SwitchScreens faild,error: %v \n", err)
+		return errors.New("开关屏幕失败!")
 	}
 	return nil
 }
@@ -85,7 +83,7 @@ func (screensService *ScreensService) SwitchScreens(swatch promodel.SwitchScreen
 func (screensService *ScreensService) SendInternalCode(sn string, content []promodel.InternalCodeContent) error {
 	err := tcp.SendInternalCode(sn, content)
 	if err != nil {
-		logger.Logger.Errorf("SendInternalCode faild \n")
+		logger.Logger.Errorf("SendInternalCode faild,error: %v \n", err)
 		return errors.New("发送内码文字失败!")
 	}
 	return nil
@@ -95,25 +93,24 @@ func (screensService *ScreensService) SendInternalCode(sn string, content []prom
 func (screensService *ScreensService) VoiceBroad(sn string, content string) error {
 	err := tcp.VoiceBroad(sn, content)
 	if err != nil {
-		logger.Logger.Errorf("SendInternalCode faild \n")
+		logger.Logger.Errorf("SendInternalCode faild,error: %v \n", err)
 		return errors.New("远程喊话失败!")
 	}
 	return nil
 }
 
-func (screensService *ScreensService) SetBright(sb model.ReqBrightness) error {
-	//先将白天、晚上亮度更新到数据库
+// 设置屏幕亮度和声音开关时间
+func (screensService *ScreensService) SetBrightAudio(sb model.ReqBrightness) error {
+	//先将白天、晚上亮度 声音开关时间 更新到数据库
 	screens := devices.Screens{}
-	err := screens.UpdateBrightnessBySn(sb.Sn, sb.DayBright, sb.NightBright)
+	err := screens.UpdateBrightAudioBySn(sb.Sn, sb.DayBright, sb.NightBright, sb.AudioOn, sb.AudioOff)
 	if err != nil {
-		logger.Logger.Errorf("SetBright faild \n")
+		logger.Logger.Errorf("SetBright faild,error: %v \n", err)
 		return errors.New("亮度更新数据库失败!")
 	}
 
-	//判断当前时间是白天还是晚上(立马去更改当前所处时间的亮度)
+	//修改屏幕亮度   判断当前时间是白天还是晚上(立马去更改当前所处时间的亮度)
 	currentTime := time.Now()
-
-	// 获取当前小时和分钟
 	hour := currentTime.Hour()
 	minute := currentTime.Minute()
 
@@ -122,16 +119,69 @@ func (screensService *ScreensService) SetBright(sb model.ReqBrightness) error {
 		//白天
 		err = tcp.SetBrightness(sb.Sn, sb.DayBright)
 		if err != nil {
-			logger.Logger.Errorf("SetBright[白天] faild \n")
+			logger.Logger.Errorf("SetBright[白天] faild,error: %v \n", err)
 			return errors.New("设置白天亮度失败!")
 		}
 	} else {
 		//晚上
 		err = tcp.SetBrightness(sb.Sn, sb.NightBright)
 		if err != nil {
-			logger.Logger.Errorf("SetBright[晚上] faild \n")
+			logger.Logger.Errorf("SetBright[晚上] faild,error: %v \n", err)
 			return errors.New("设置晚上亮度失败!")
 		}
 	}
+
+	//修改时控开关时间
+	err = SetSwitchClock([]string{sb.SwitchSn}, sb.AudioOn, sb.AudioOff)
+	if err != nil {
+		logger.Logger.Errorf("SetSwitchClock faild,error: %v \n", err)
+		return err
+	}
+	return nil
+}
+
+func SetSwitchClock(switchSn []string, audioOn, audioOff string) error {
+	//目标接口的 URL
+	url := "https://cloud.long-chi.com/lczh_wxapp_api/dev/batchUpdateDeviceTime"
+
+	token := "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJVVUlEIjoiYjFkZDU2MGItM2RmNC00MTg0LWE2NzktODYyM2M1Y2I3ZDVkIiwiSUQiOjI0MCwiVXNlcm5hbWUiOiJzbWFydEludGVyc2VjdGlvbiIsIk5pY2tOYW1lIjoi5pm65oWn6Lev5Y-jIiwiQXV0aG9yaXR5SWQiOjk5OTk5LCJPcGVuaWQiOiIiLCJCdWZmZXJUaW1lIjo4NjQwMCwiaXNzIjoicW1QbHVzIiwiZXhwIjo0MTAyMzI5NjAwLCJhdWQiOiJHVkEiLCJuYmYiOjE3MzE5OTc5MDl9.DTWzlXPNbQ9bT7pX_X_tvJ06oW9bngPLKXsFNb54uV4"
+
+	params := model.BatchUpdateDeviceTime{
+		DeviceSn: switchSn,
+		TimeSetData: model.DeviceRelay{
+			TimeCondition1OnTime:  audioOn,  //声音开时间
+			TimeCondition1OffTime: audioOff, //声音关时间
+		},
+	}
+
+	buf, err := json.Marshal(&params)
+	if err != nil {
+		logger.Logger.Errorf("Fail to marshal [SetSwitchClock], error: %v \n", err)
+		return err
+	}
+	req, err := http.NewRequest("PUT", url, bytes.NewBuffer(buf))
+	if err != nil {
+		logger.Logger.Errorf("Fail to create request [SetSwitchClock], error: %v \n", err)
+		return err
+	}
+
+	// 在请求头中添加x-token字段,值为<Token>
+	req.Header.Add("x-token", token)
+	req.Header.Add("Content-Type", "application/json")
+
+	// 创建一个 HTTP 客户端
+	client := &http.Client{}
+
+	// 发送请求
+	resp, err := client.Do(req)
+	if err != nil {
+		logger.Logger.Errorf("Fail to Do request [SetSwitchClock], error: %v \n", err)
+		return err
+	}
+	defer resp.Body.Close()
+
+	if resp.StatusCode != 200 {
+		return errors.New("设置声音时控 fail")
+	}
 	return nil
 }

+ 3 - 2
server/service/tcp/deviceMgr.go

@@ -136,9 +136,10 @@ func (s *Device) Handle() {
 				s.conn.Close()
 				close(s.stopChan)          // 通知协程停止
 				delete(devices, s.info.Sn) //从内存中移除连接
-				return                     // 结束 Handle 协程
+				logger.Logger.Debugf("设备 [%v] 离线了...", s.info.ScreensName)
+				return // 结束 Handle 协程
 			} else {
-				logger.Logger.Debugf("%s在线", s.info.ScreensCode)
+				logger.Logger.Debugf("设备 [%s] 在线", s.info.ScreensCode)
 			}
 			//修改数据库状态
 			err := Dev.UpdateScreensStatus(s.info.ScreensCode, state)

+ 2 - 2
web/src/api/screens.js

@@ -63,9 +63,9 @@ export const voiceBroad = (data) => {
     })
 }
 
-export const setBright = (data) => {
+export const setBrightAudio = (data) => {
     return service({
-        url: '/screens/setBright',
+        url: '/screens/setBrightAudio',
         method: 'post',
         data: data
     })

+ 66 - 7
web/src/view/devicesAdmin/screens/screens.vue

@@ -9,7 +9,7 @@
         <el-form-item label="名称或编码">
           <el-input
               v-model="searchInfo.keyword"
-              placeholder="搜索名称或编码"
+              placeholder="搜索名称或SN"
           />
         </el-form-item>
         <el-form-item label="所属分路">
@@ -238,6 +238,11 @@
                 />
               </el-form-item>
             </el-col>
+            <el-col :span="12">
+              <el-form-item label="时控开关Sn:" :inline="false">
+                <el-input v-model="screensInfo.switchSn"></el-input>
+              </el-form-item>
+            </el-col>
           </el-row>
         </el-form>
         <template #footer>
@@ -447,9 +452,10 @@
         </template>
       </el-dialog>
 
-<!--设置亮度弹窗-->
+<!--设置亮度和时控弹窗-->
       <el-dialog v-model="setBrightDialog" title="设置" width="500">
           <el-form ref="dataForm" :model="setBrightForm" style="padding: 15px">
+            <el-divider content-position="left">亮度</el-divider>
             <el-row>
               <el-col :span="21">
                 <el-form-item label="白天:" :inline="false" prop="broadContent">
@@ -464,6 +470,29 @@
                 </el-form-item>
               </el-col>
             </el-row>
+            <el-divider content-position="left">声音</el-divider>
+            <el-row :gutter="25">
+              <el-col :span="11">
+                <el-form-item label="开:" :inline="false">
+                  <el-select v-model="setBrightForm.audioOn" placeholder="请设置时间">
+                    <template #prefix>
+                      <span style="padding-left: 3px;padding-top: 4px;"><el-icon><Clock /></el-icon></span>
+                    </template>
+                    <el-option v-for=" x in timeArr" :label="x" :value="x" />
+                  </el-select>
+                </el-form-item>
+              </el-col>
+              <el-col :span="11">
+                <el-form-item label="关:" :inline="false">
+                  <el-select v-model="setBrightForm.audioOff" placeholder="请设置时间">
+                    <template #prefix>
+                    <span style="padding-left: 3px;padding-top: 4px;"><el-icon><Clock /></el-icon></span>
+                    </template>
+                    <el-option v-for=" x in timeArr" :label="x" :value="x" />
+                  </el-select>
+                </el-form-item>
+              </el-col>
+            </el-row>
           </el-form>
         <template #footer>
           <div class="dialog-footer">
@@ -485,7 +514,7 @@ import {
   setScreensInfo,
   addScreens,
   switchScreens,
-  sendInternalCode, voiceBroad, setBright
+  sendInternalCode, voiceBroad, setBrightAudio
 } from "@/api/screens";
 import { ref,reactive} from 'vue'
 import {ElMessage, ElMessageBox} from "element-plus";
@@ -497,6 +526,31 @@ const tableData = ref([])
 const searchInfo = ref({})
 const screensInfo = ref({})
 const nowSn = ref("")
+const timeArr = ref([
+  '00:00', '00:10', '00:20', '00:30', '00:40', '00:50',
+  '01:00', '01:10', '01:20', '01:30', '01:40', '01:50',
+  '02:00', '02:10', '02:20', '02:30', '02:40', '02:50',
+  '03:00', '03:10', '03:20', '03:30', '03:40', '03:50',
+  '04:00', '04:10', '04:20', '04:30', '04:40', '04:50',
+  '05:00', '05:10', '05:20', '05:30', '05:40', '05:50',
+  '06:00', '06:10', '06:20', '06:30', '06:40', '06:50',
+  '07:00', '07:10', '07:20', '07:30', '07:40', '07:50',
+  '08:00', '08:10', '08:20', '08:30', '08:40', '08:50',
+  '09:00', '09:10', '09:20', '09:30', '09:40', '09:50',
+  '10:00', '10:10', '10:20', '10:30', '10:40', '10:50',
+  '11:00', '11:10', '11:20', '11:30', '11:40', '11:50',
+  '12:00', '12:10', '12:20', '12:30', '12:40', '12:50',
+  '13:00', '13:10', '13:20', '13:30', '13:40', '13:50',
+  '14:00', '14:10', '14:20', '14:30', '14:40', '14:50',
+  '15:00', '15:10', '15:20', '15:30', '15:40', '15:50',
+  '16:00', '16:10', '16:20', '16:30', '16:40', '16:50',
+  '17:00', '17:10', '17:20', '17:30', '17:40', '17:50',
+  '18:00', '18:10', '18:20', '18:30', '18:40', '18:50',
+  '19:00', '19:10', '19:20', '19:30', '19:40', '19:50',
+  '20:00', '20:10', '20:20', '20:30', '20:40', '20:50',
+  '21:00', '21:10', '21:20', '21:30', '21:40', '21:50',
+  '22:00', '22:10', '22:20', '22:30', '22:40', '22:50',
+  '23:00', '23:10', '23:20', '23:30', '23:40', '23:50'])
 const dataForms = ref([
   {
     text:'',
@@ -711,7 +765,6 @@ const deleteScreens = (obj) => {
     type: 'warning',
   })
       .then(async() => {
-        console.log(obj)
         const res = await deleteBaseScreens({ ID:obj.ID })
         if (res.code === 0) {
           ElMessage({
@@ -842,7 +895,8 @@ const openSetBrightDialog = async (obj)=>{
     })
     return
   }
-  setBrightForm.value = {dayBright:obj.dayBright,nightBright:obj.nightBright}
+  console.log("=====",obj)
+  setBrightForm.value = {dayBright:obj.dayBright,nightBright:obj.nightBright,audioOn:obj.audioOn,audioOff:obj.audioOff,switchSn:obj.switchSn}
   setBrightDialog.value = true
   nowSn.value = obj.sn
 }
@@ -850,13 +904,17 @@ const openSetBrightDialog = async (obj)=>{
 const closeSetBrightDialog = ()=>{
   setBrightDialog.value = false
   nowSn.value = ""
+  getTableData()
 }
 
 const enterSetBrightDialog = async () => {
-  var res = await setBright({
+  var res = await setBrightAudio({
     sn: nowSn.value,
     dayBright: setBrightForm.value.dayBright,
-    nightBright: setBrightForm.value.nightBright
+    nightBright: setBrightForm.value.nightBright,
+    audioOn: setBrightForm.value.audioOn,
+    audioOff: setBrightForm.value.audioOff,
+    switchSn: setBrightForm.value.switchSn
   });
   if (res.code === 0) {
     ElMessage({
@@ -864,6 +922,7 @@ const enterSetBrightDialog = async () => {
       message: '操作成功!',
     })
   }
+  closeSetBrightDialog()
 }