12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126 |
- package controllers
- import (
- "Cold_Api/Nats"
- "Cold_Api/conf"
- "Cold_Api/controllers/lib"
- "Cold_Api/models/Admin"
- "Cold_Api/models/Device"
- "Cold_Api/models/System"
- "fmt"
- beego "github.com/beego/beego/v2/server/web"
- "github.com/xuri/excelize/v2"
- "math"
- "strconv"
- "strings"
- "time"
- )
- //Handle
- type DeviceController struct {
- beego.Controller
- }
- // 列表 -
- func (c *DeviceController) Device_html() {
- // 验证登录
- b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
- if !b_ {
- c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
- c.ServeJSON()
- return
- }
- c.Data["Admin_r"] = admin_r
- c.Data["Admin_Power"], _ = Admin.Read_AdminPower_ById(admin_r.Admin_power)
- // 模板
- type R_Device struct {
- T_sn string // 设备序列号 KF开头,环境监测主机。 YD开头,温途监测主机
- T_devName string //设备名称
- T_sensor int // 传感器数量
- T_monitor int // 监控状态 1 监控 0 未监控
- T_sn_yd int // 湿度显示
- T_give int // 0 丢弃 1 正常
- T_online int // 在线状态 1 在线 0 离线
- T_Dattery int //电量
- T_sensor_list []Device.DeviceSensor_R // 传感器List
- T_MSISDN string //设备名称
- UpdateTime time.Time //auto_now 每次 model 保存时都会对时间自动更新
- }
- var Device_lite_r []R_Device
- page, _ := c.GetInt("page")
- println(page)
- if page < 1 {
- page = 1
- }
- Class_1 := c.GetString("Class_1")
- Name := c.GetString("Name")
- T_sn := c.GetString("T_sn")
- //Class_1, _ := c.GetInt("Class_1")
- //Name := c.GetString("Name")
- //T_sn := c.GetString("T_sn")
- c.Data["Class_1"] = Class_1
- c.Data["Name"] = Name
- c.Data["T_sn"] = T_sn
- var cnt int64
- Device_lite, cnt := Device.Read_Device_ALL_bind_1(admin_r, page, 0, T_sn, Name, Class_1, "")
- for _, v := range Device_lite {
- r_Device := R_Device{}
- // 湿度显示
- if admin_r.Admin_rh == 0 {
- r_Device.T_sn_yd = 0
- if strings.Contains(v.T_sn, "YD") {
- r_Device.T_sn_yd = 1
- }
- }
- r_Device.T_sn = v.T_sn
- r_Device.T_MSISDN = v.T_MSISDN
- r_Device.T_devName = v.T_devName
- r_Device.T_give = v.T_give
- r_Device.T_online = v.T_online
- r_Device.T_monitor = v.T_monitor
- r_Device.T_Dattery = v.T_Dattery
- r_Device.T_sensor_list, r_Device.T_sensor = Device.Read_DeviceSensor_ByTsn(v.T_sn)
- ////监控状态
- //r_Device.T_monitor = 1
- //if(strings.Contains(r_Device.T_sn, "YD")){
- // DeviceTask_r,DeviceTask_is := Device.Read_DeviceTask_All_Limit_1(r_Device.T_sn)
- // r_Device.T_monitor = 0
- //
- // if(DeviceTask_is){
- // if(DeviceTask_r.T_Ut_end.IsZero()){
- // r_Device.T_monitor = 1
- // }
- // }
- //}
- // 更新 异常
- //for di,_ := range r_Device.T_sensor_list{
- // //println( r_Device.T_sensor_list[di].T_id ,time.Now().Unix() , r_Device.T_sensor_list[di].T_time.Unix(),time.Now().Unix() - r_Device.T_sensor_list[di].T_time.Unix())
- // // 是否异常
- // if(r_Device.T_sensor_list[di].T_err == 0){
- // // 再次 确定传感器 时间 状态
- // if(time.Now().Unix() - r_Device.T_sensor_list[di].T_time.Unix() > 60 * 10){
- // r_Device.T_sensor_list[di].T_err = 1
- // Device.Update_DeviceSensor_ByTsn_T_err(v.T_sn,r_Device.T_sensor_list[di].T_id,1)
- // }
- // }
- //
- //
- //}
- Device_lite_r = append(Device_lite_r, r_Device)
- }
- c.Data["Device_lite"] = Device_lite_r
- page_size := math.Ceil(float64(cnt) / float64(conf.Page_size))
- c.Data["Page"] = page
- c.Data["Page_size"] = page_size
- c.Data["Pages"] = lib.Func_page(int64(page), int64(page_size))
- c.Data["cnt"] = cnt
- c.TplName = "Device/Device.html"
- }
- func (c *DeviceController) Device_() {
- id, _ := c.GetInt("id")
- c.Data["id"] = id
- if id > 0 {
- c.Data["Date"] = Device.Read_Device_ById(id)
- //c.Data["FormulaList"] = Formula.ReadFormulaListByid_List(id)
- }
- c.Data["DeviceSnOld_List"] = Device.Read_DeviceSnOld_1()
- c.TplName = "Device/Device-.html"
- }
- func (c *DeviceController) Device_Parameter_html() {
- // 验证登录
- b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
- if !b_ {
- c.Ctx.Redirect(302, "Login")
- return
- }
- c.Data["Admin_Power"], _ = Admin.Read_AdminPower_ById(admin_r.Admin_power)
- c.Data["Admin"] = admin_r
- Sn := c.GetString("Sn")
- DeviceParameter_lite := Device.Read_DeviceParameter_SN(Sn)
- if len(DeviceParameter_lite) > 0 {
- c.Data["DeviceParameter"] = DeviceParameter_lite[0]
- } else {
- Nats.Read_DeviceParameter(Sn)
- }
- c.Data["DeviceParameter_lite_z"] = len(DeviceParameter_lite)
- c.Data["DeviceParameter_lite_SendState_z"] = len(Device.Read_DeviceParameter_SN_T_SendState_0(Sn))
- DeviceParameter_lite_s_1 := Device.Read_DeviceParameter_SN_T_State_1(Sn)
- c.Data["DeviceParameter_lite"] = DeviceParameter_lite_s_1
- c.Data["Device"], _ = Device.Read_Device_ByT_sn(Sn)
- c.TplName = "Device/Device_Parameter-.html"
- }
- func (c *DeviceController) DeviceSensor_List_html() {
- // 验证登录
- b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
- if !b_ {
- c.Ctx.Redirect(302, "Login")
- return
- }
- c.Data["Admin_Power"], _ = Admin.Read_AdminPower_ById(admin_r.Admin_power)
- Sn := c.GetString("Sn")
- Id, _ := c.GetInt("Id")
- //
- //c.Data["Device_lite"] = Device.Read_DeviceParameter_SN(Sn)
- c.Data["DeviceSensor"], _ = Device.Read_DeviceSensor_ByTsn_Tid(Sn, Id)
- DeviceSensorParameter_list := Device.Read_DeviceSensorParameter_SN_T_id(Sn, Id)
- c.Data["DeviceSensorParameter_lite"] = DeviceSensorParameter_list
- c.Data["DeviceSensorParameter_T_SendState_0"] = 0
- if len(DeviceSensorParameter_list) > 0 {
- if DeviceSensorParameter_list[0].T_SendState == 0 {
- c.Data["DeviceSensorParameter_T_SendState_0"] = 1
- }
- }
- c.Data["Device"], _ = Device.Read_Device_ByT_sn(Sn)
- c.TplName = "Device/Device_Sensor-.html"
- }
- func (c *DeviceController) Device_Parameter_Del_Device() {
- // 验证登录
- b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
- if !b_ {
- c.Ctx.Redirect(302, "Login")
- return
- }
- Sn := c.GetString("Sn")
- Id, _ := c.GetInt("Id")
- System.Add_UserLogs_T(admin_r.Admin_uuid, "设备管理", "传感器 删除操作", "SN:"+Sn+" ["+strconv.Itoa(Id)+"]")
- //c.Data["Device_lite"] = Device.Read_DeviceParameter_SN(Sn)
- Device.Delete_DeviceSensor_ById(Sn, Id)
- Nats.Del_DeviceSensor(Device.DeviceSensor_Del{
- T_sn: Sn, T_id: Id,
- })
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "OK"}
- c.ServeJSON()
- return
- }
- func (c *DeviceController) Device_Parameter_Del() {
- // 验证登录
- b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
- if !b_ {
- c.Ctx.Redirect(302, "Login")
- return
- }
- Sn := c.GetString("Sn")
- Id, _ := c.GetInt("Id")
- System.Add_UserLogs_T(admin_r.Admin_uuid, "设备管理", "传感器 删除操作", "SN:"+Sn+" ["+strconv.Itoa(Id)+"]")
- //c.Data["Device_lite"] = Device.Read_DeviceParameter_SN(Sn)
- Device.Delete_DeviceSensor_ById(Sn, Id)
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "OK"}
- c.ServeJSON()
- return
- }
- func (c *DeviceController) UpDeviceSensor_Tsort() {
- // 验证登录
- b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
- if !b_ {
- c.Ctx.Redirect(302, "Login")
- return
- }
- Sn := c.GetString("Sn")
- Id, _ := c.GetInt("Id")
- T_sort, _ := c.GetInt("T_sort")
- DeviceSensor, is := Device.Read_DeviceSensor_ByT_sn(Sn, Id)
- if !is {
- c.Data["json"] = lib.JSONS{Code: 201, Msg: "信息错误!"}
- c.ServeJSON()
- return
- }
- DeviceSensor.T_sort = T_sort
- //c.Data["Device_lite"] = Device.Read_DeviceParameter_SN(Sn)
- Device.Update_DeviceSensor(DeviceSensor, "T_sort")
- System.Add_UserLogs_T(admin_r.Admin_uuid, "设备管理", "传感器 排序操作", "SN:"+Sn+" ["+strconv.Itoa(Id)+"]"+strconv.Itoa(T_sort))
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "OK"}
- c.ServeJSON()
- return
- }
- func (c *DeviceController) UpDeviceSensor_T_datashow() {
- // 验证登录
- b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
- if !b_ {
- c.Ctx.Redirect(302, "Login")
- return
- }
- Sn := c.GetString("Sn")
- Id, _ := c.GetInt("Id")
- T_datashow, _ := c.GetInt("T_datashow")
- DeviceSensor, is := Device.Read_DeviceSensor_ByT_sn(Sn, Id)
- if !is {
- c.Data["json"] = lib.JSONS{Code: 201, Msg: "信息错误!"}
- c.ServeJSON()
- return
- }
- DeviceSensor.T_datashow = T_datashow
- Device.Update_DeviceSensor(DeviceSensor, "T_datashow")
- System.Add_UserLogs_T(admin_r.Admin_uuid, "设备管理", "传感器 数据展示(0 屏蔽数据展示 1 正常数据展示)", "SN:"+Sn+" ["+strconv.Itoa(Id)+"]"+strconv.Itoa(T_datashow))
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "OK"}
- c.ServeJSON()
- return
- }
- func (c *DeviceController) Device_Post() {
- /// 验证登录
- b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
- if !b_ {
- c.Ctx.Redirect(302, "Login")
- return
- }
- var err error
- T_sn := c.GetString("T_sn")
- T_MSISDN := c.GetString("T_MSISDN")
- var_ := Device.Device{
- T_sn: T_sn,
- T_MSISDN: T_MSISDN,
- T_Bind: "U" + strconv.Itoa(admin_r.Id) + "|",
- T_l_p: 0,
- T_give: 1,
- T_monitor: 1,
- T_State: 1,
- }
- if len(T_sn) < 8 {
- c.Data["json"] = lib.JSONS{Code: 303, Msg: "SN 太短 必须8个字符以上"}
- c.ServeJSON()
- return
- }
- if !(strings.Contains(T_sn, "KF") || strings.Contains(T_sn, "YD")) {
- c.Data["json"] = lib.JSONS{Code: 303, Msg: "必须包含 KF或YD!"}
- c.ServeJSON()
- return
- }
- _, err = Device.Read_Device_ByT_sn(T_sn)
- if err == nil {
- c.Data["json"] = lib.JSONS{Code: 303, Msg: "重复SN!"}
- c.ServeJSON()
- return
- }
- var_.T_devName = "等待设备上线.."
- // 创建数据库
- if !Device.CREATE_DeviceData(T_sn) {
- c.Data["json"] = lib.JSONS{Code: 302, Msg: "添加失败!"}
- c.ServeJSON()
- return
- }
- _, err = Device.Add_Device(var_)
- if err != nil {
- c.Data["json"] = lib.JSONS{Code: 301, Msg: "添加失败!"}
- c.ServeJSON()
- return
- }
- System.Add_UserLogs_T(admin_r.Admin_uuid, "设备管理", "设备添加", var_)
- //MqttServer.Get_Device_Realtime(T_sn) // 更新传感器 !!!
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
- c.ServeJSON()
- return
- }
- func (c *DeviceController) Device_Del() {
- // 验证登录
- b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
- if !b_ {
- c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
- c.ServeJSON()
- return
- }
- if admin_r.Admin_master != 1 {
- c.Data["json"] = lib.JSONS{Code: 201, Msg: "没有权限!"}
- c.ServeJSON()
- return
- }
- T_sn := c.GetString("T_sn")
- Device_r, err := Device.Read_Device_ByT_sn(T_sn)
- if err != nil {
- c.Data["json"] = lib.JSONS{Code: 201, Msg: "T_sn Err!"}
- c.ServeJSON()
- return
- }
- Device.Delete_Device(Device_r)
- DeviceSensor_list, _ := Device.Read_DeviceSensor_ByTsn(Device_r.T_sn)
- for _, v := range DeviceSensor_list {
- Device.Delete_DeviceSensor_ById(Device_r.T_sn, v.T_id)
- }
- Device.DELETE_DeviceSensor(Device_r.T_sn)
- Device.DELETE_DeviceDatar(Device_r.T_sn)
- Device.DELETE_DeviceParameter(Device_r.T_sn)
- Device.DELETE_DeviceSensorParameter(Device_r.T_sn)
- System.Add_UserLogs(admin_r.Admin_uuid, "设备管理", "设备删除", T_sn)
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
- c.ServeJSON()
- return
- }
- // 设备弃用
- func (c *DeviceController) Device_Give() {
- // 验证登录
- b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
- if !b_ {
- c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
- c.ServeJSON()
- return
- }
- if admin_r.Admin_master != 1 {
- c.Data["json"] = lib.JSONS{Code: 201, Msg: "没有权限!"}
- c.ServeJSON()
- return
- }
- T_sn := c.GetString("T_sn")
- Device_r, err := Device.Read_Device_ByT_sn(T_sn)
- if err != nil {
- c.Data["json"] = lib.JSONS{Code: 201, Msg: "T_sn Err!"}
- c.ServeJSON()
- return
- }
- if Device_r.T_give == 0 {
- Device_r.T_give = 1
- System.Add_UserLogs(admin_r.Admin_uuid, "设备管理", "设备开启", T_sn)
- } else {
- Device_r.T_give = 0
- System.Add_UserLogs(admin_r.Admin_uuid, "设备管理", "设备弃用", T_sn)
- }
- Device.Update_Device(Device_r, "T_give")
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
- c.ServeJSON()
- return
- }
- //-------------------------------
- func (c *DeviceController) Device_List() {
- // 验证登录
- b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
- if !b_ {
- c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
- c.ServeJSON()
- return
- }
- // 模板
- type R_Device struct {
- T_sn string // 设备序列号 KF开头,环境监测主机。 YD开头,温途监测主机
- T_devName string //设备名称
- T_sensor int // 传感器数量
- T_monitor int // 监控状态
- T_give int // 0 丢弃 1 正常
- T_sensor_list []Device.DeviceSensor_R // 传感器List
- UpdateTime time.Time //auto_now 每次 model 保存时都会对时间自动更新
- }
- type R_JSONS struct {
- //必须的大写开头
- Device_lite []R_Device
- Num int
- Page int
- Page_size int
- Pages []lib.Page_T
- }
- var r_jsons R_JSONS
- page, _ := c.GetInt("page")
- println(page)
- if page < 1 {
- page = 1
- }
- Class_1 := c.GetString("Class_1")
- Name := c.GetString("Name")
- T_sn := c.GetString("T_sn")
- //
- //c.Data["Class_1"] = Class_1
- //c.Data["T_sn"] = T_sn
- //c.Data["Class_List"] = Device.Read_Class_All_1()
- Device_r, err := Device.Read_Device_ByT_sn(T_sn)
- if err != nil {
- c.Data["json"] = lib.JSONS{Code: 206, Msg: "T_sn Err!"}
- c.ServeJSON()
- return
- }
- if !strings.Contains(Device_r.T_Bind, "U"+strconv.Itoa(admin_r.Id)+"|") && admin_r.Admin_master != 0 {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "! U" + strconv.Itoa(admin_r.Id)}
- c.ServeJSON()
- return
- }
- var cnt int64
- Device_lite, cnt := Device.Read_Device_ALL_bind_1(admin_r, page, 0, T_sn, Name, Class_1, "")
- for _, v := range Device_lite {
- r_Device := R_Device{}
- r_Device.T_sn = v.T_sn
- r_Device.T_devName = v.T_devName
- r_Device.T_sensor_list, r_Device.T_sensor = Device.Read_DeviceSensor_ByTsn(v.T_sn)
- r_Device.T_give = v.T_give
- r_Device.T_monitor = v.T_monitor
- //监控状态
- //r_Device.T_monitor = 1
- //if(strings.Contains(r_Device.T_sn, "YD")){
- // DeviceTask_r,DeviceTask_is := Device.Read_DeviceTask_All_Limit_1(r_Device.T_sn)
- // r_Device.T_monitor = 0
- //
- // if(DeviceTask_is){
- // if(DeviceTask_r.T_Ut_end.IsZero()){
- // r_Device.T_monitor = 1
- // }
- // }
- //}
- //for di, _ := range r_Device.T_sensor_list {
- // //println( r_Device.T_sensor_list[di].T_id ,time.Now().Unix() , r_Device.T_sensor_list[di].T_time.Unix(),time.Now().Unix() - r_Device.T_sensor_list[di].T_time.Unix())
- // // 是否异常
- // if r_Device.T_sensor_list[di].T_err == 0 {
- // // 再次 确定传感器 时间 状态
- // if time.Now().Unix()-r_Device.T_sensor_list[di].T_time.Unix() > 60*10 {
- // r_Device.T_sensor_list[di].T_err = 1
- // Device.Update_DeviceSensor_ByTsn_T_err(v.T_sn, r_Device.T_sensor_list[di].T_id, 1)
- // }
- // }
- //}
- r_jsons.Device_lite = append(r_jsons.Device_lite, r_Device)
- }
- page_size := math.Ceil(float64(cnt) / float64(conf.Page_size))
- r_jsons.Page = int(page)
- r_jsons.Page_size = int(page_size)
- r_jsons.Pages = lib.Func_page(int64(page), int64(page_size))
- r_jsons.Num = int(cnt)
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
- c.ServeJSON()
- return
- }
- func (c *DeviceController) DeviceSensor_List() {
- // 验证登录
- b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
- if !b_ {
- c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
- c.ServeJSON()
- return
- }
- type R_JSONS struct {
- //必须的大写开头
- DeviceSensor_lite []Device.DeviceSensor
- Num int
- Page int
- Page_size int
- Pages []lib.Page_T
- }
- var r_jsons R_JSONS
- page, _ := c.GetInt("page")
- println(page)
- if page < 1 {
- page = 1
- }
- T_sn := c.GetString("Sn")
- Device_r, err := Device.Read_Device_ByT_sn(T_sn)
- if err != nil {
- c.Data["json"] = lib.JSONS{Code: 206, Msg: "T_sn Err!"}
- c.ServeJSON()
- return
- }
- if admin_r.Admin_master > 1 {
- if !strings.Contains(Device_r.T_Bind, "U"+strconv.Itoa(admin_r.Id)+"|") && admin_r.Admin_master != 0 {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "! U" + strconv.Itoa(admin_r.Id)}
- c.ServeJSON()
- return
- }
- }
- //c.Data["Class_List"] = Device.Read_Class_All_1()
- var cnt int64
- r_jsons.DeviceSensor_lite, cnt = Device.Read_DeviceSensor_ALL_T_del_x(page, T_sn)
- page_size := math.Ceil(float64(cnt) / float64(conf.Page_size))
- r_jsons.Page = int(page)
- r_jsons.Page_size = int(page_size)
- r_jsons.Pages = lib.Func_page(int64(page), int64(page_size))
- r_jsons.Num = int(cnt)
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
- c.ServeJSON()
- return
- }
- // ------------------------------------------
- func (c *DeviceController) Read_DeviceParameter() {
- // 验证登录
- b_, _ := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
- if !b_ {
- c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
- c.ServeJSON()
- return
- }
- T_SN := c.GetString("SN")
- //Device_r, err := Device.Read_Device_ByT_sn(T_SN)
- //if err != nil {
- // c.Data["json"] = lib.JSONS{Code: 206, Msg: "T_sn Err!"}
- // c.ServeJSON()
- // return
- //}
- ////if !strings.Contains(Device_r.T_Bind, "U"+strconv.Itoa(r_admin.Id)) {
- //// c.Data["json"] = lib.JSONS{Code: 202, Msg: "! U" + strconv.Itoa(r_admin.Id)}
- //// c.ServeJSON()
- //// return
- ////}
- Nats.Read_DeviceParameter(T_SN)
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
- c.ServeJSON()
- return
- }
- func (c *DeviceController) Read_DeviceSensorParameter() {
- // 验证登录
- b_, _ := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
- if !b_ {
- c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
- c.ServeJSON()
- return
- }
- T_SN := c.GetString("SN")
- //Device_r, err := Device.Read_Device_ByT_sn(T_SN)
- //if err != nil {
- // c.Data["json"] = lib.JSONS{Code: 206, Msg: "T_sn Err!"}
- // c.ServeJSON()
- // return
- //}
- ////if !strings.Contains(Device_r.T_Bind, "U"+strconv.Itoa(r_admin.Id)) {
- //// c.Data["json"] = lib.JSONS{Code: 202, Msg: "! U" + strconv.Itoa(r_admin.Id)}
- //// c.ServeJSON()
- //// return
- ////}
- Nats.Read_DeviceSensorParameter(T_SN)
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
- c.ServeJSON()
- return
- }
- //
- func (c *DeviceController) Pu_DeviceParameter() {
- // 验证登录
- b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
- if !b_ {
- c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
- c.ServeJSON()
- return
- }
- T_SN := c.GetString("SN")
- T_devName := c.GetString("T_devName")
- T_saveTime, _ := c.GetInt("T_saveTime")
- T_overrunSave, _ := c.GetInt("T_overrunSave")
- T_overrunAlarm, _ := c.GetInt("T_overrunAlarm")
- T_outageAlarm, _ := c.GetInt("T_outageAlarm")
- T_warningDelay, _ := c.GetInt("T_warningDelay")
- T_lostAlarm, _ := c.GetInt("T_lostAlarm")
- T_batteryLimit, _ := c.GetInt("T_batteryLimit")
- T_warningTime, _ := c.GetInt("T_warningTime")
- T_tempPre, _ := c.GetFloat("T_tempPre")
- T_humPre, _ := c.GetFloat("T_humPre")
- T_enwarning, _ := c.GetInt("T_enwarning")
- T_decTotal, _ := c.GetInt("T_decTotal")
- T_chDecTotal := c.GetString("T_chDecTotal")
- T_company := c.GetString("T_company")
- T_btname := c.GetString("T_btname")
- T_btserverID, _ := c.GetInt("T_btserverID")
- T_btchar, _ := c.GetInt("T_btchar")
- Device_r, err := Device.Read_Device_ByT_sn(T_SN)
- if err != nil {
- c.Data["json"] = lib.JSONS{Code: 206, Msg: "T_sn Err!"}
- c.ServeJSON()
- return
- }
- Admin_Power_, _ := Admin.Read_AdminPower_ById(admin_r.Admin_power)
- if Admin_Power_.Power_DeviceSensor_Compensate_e == 0 {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "! U" + strconv.Itoa(admin_r.Id)}
- c.ServeJSON()
- return
- }
- Deviceparameter := Device.DeviceParameter{
- T_uuid: admin_r.Admin_uuid,
- T_SendState: 0,
- T_State: 2,
- T_sn: T_SN,
- T_devName: T_devName,
- T_saveTime: T_saveTime,
- T_overrunSave: T_overrunSave,
- T_overrunAlarm: T_overrunAlarm,
- T_outageAlarm: T_outageAlarm,
- T_lostAlarm: T_lostAlarm,
- T_warningTime: T_warningTime,
- T_warningDelay: T_warningDelay,
- T_batteryLimit: T_batteryLimit,
- T_tempPre: float32(T_tempPre),
- T_humPre: float32(T_humPre),
- T_chDecTotal: T_chDecTotal,
- T_decTotal: strconv.Itoa(T_decTotal),
- T_enwarning: T_enwarning,
- T_company: T_company,
- T_btname: T_btname,
- T_btserverID: strconv.Itoa(T_btserverID),
- T_btchar: strconv.Itoa(T_btchar),
- }
- Deviceparameter, is := Device.Add_DeviceParameter(Deviceparameter)
- if !is {
- c.Data["json"] = lib.JSONS{Code: 203, Msg: "Add_DeviceParameter ERR"}
- c.ServeJSON()
- return
- }
- System.Add_UserLogs_T(admin_r.Admin_uuid, "设备管理", "设备参数操作", Deviceparameter)
- Nats.Pu_DeviceParameter(Deviceparameter)
- Device_r.T_devName = Deviceparameter.T_devName
- Device.Update_Device(Device_r, "T_devName")
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
- c.ServeJSON()
- return
- }
- //
- func (c *DeviceController) Pu_DeviceParameter_T_l_p() {
- // 验证登录
- b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
- if !b_ {
- c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
- c.ServeJSON()
- return
- }
- T_SN := c.GetString("SN")
- T_l_p, _ := c.GetInt("T_l_p")
- Device_r, err := Device.Read_Device_ByT_sn(T_SN)
- if err != nil {
- c.Data["json"] = lib.JSONS{Code: 206, Msg: "T_sn Err!"}
- c.ServeJSON()
- return
- }
- // // 1物流端 2药店端
- Device_r.T_l_p = T_l_p
- Device.Update_Device(Device_r, "T_l_p")
- Device.DeviceSensor_T_l_p_ALL(T_SN, T_l_p)
- System.Add_UserLogs(admin_r.Admin_uuid, "设备管理", "设备参数操作", "类型选择(1物流端 2药店端):"+string(T_l_p))
- c.Data["json"] = lib.JSONS{Code: 222, Msg: "ok!"}
- c.ServeJSON()
- return
- }
- //
- func (c *DeviceController) Pu_DeviceParameter_T_give() {
- // 验证登录
- b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
- if !b_ {
- c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
- c.ServeJSON()
- return
- }
- T_SN := c.GetString("SN")
- T_give, _ := c.GetInt("T_give")
- Device_r, err := Device.Read_Device_ByT_sn(T_SN)
- if err != nil {
- c.Data["json"] = lib.JSONS{Code: 206, Msg: "T_sn Err!"}
- c.ServeJSON()
- return
- }
- // // 1物流端 2药店端
- Device_r.T_give = T_give
- Device.Update_Device(Device_r, "T_give")
- Device.DeviceSensor_t_give_ALL(T_SN, T_give)
- System.Add_UserLogs(admin_r.Admin_uuid, "设备管理", "设备丢弃参数操作", "设备丢弃( 0 丢弃 1 正常):"+string(T_give))
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
- c.ServeJSON()
- return
- }
- //
- //func (c *DeviceController) Pu_DeviceParameter_Sensor_() {
- // // 验证登录
- // b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
- // if !b_ {
- // c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
- // c.ServeJSON()
- // return
- // }
- //
- // T_SN := c.GetString("SN")
- // _, err := Device.Read_Device_ByT_sn(T_SN)
- // if err != nil {
- // c.Data["json"] = lib.JSONS{Code: 206, Msg: "T_sn Err!"}
- // c.ServeJSON()
- // return
- // }
- // Admin_Power_, _ := Admin.Read_AdminPower_ById(admin_r.Admin_power)
- // if Admin_Power_.Power_DeviceSensor_Compensate_e == 0 {
- // c.Data["json"] = lib.JSONS{Code: 202, Msg: "! U" + strconv.Itoa(admin_r.Id)}
- // c.ServeJSON()
- // return
- // }
- //
- // T_sensor_list := c.GetString("T_sensor_list")
- // jsonStu_map_ := strings.Replace(string(T_sensor_list), "\"{", "{", -1)
- // jsonStu_map_ = strings.Replace(jsonStu_map_, "}\"", "}", -1)
- // jsonStu_map_ = strings.Replace(jsonStu_map_, "\\\"", "\"", -1)
- // println("jsonStu_map_:", jsonStu_map_)
- // var Rt_parameter_sensor_ []MqttServer.Rt_Parameter_Sensor_
- // err = json.Unmarshal([]byte(jsonStu_map_), &Rt_parameter_sensor_)
- // if err != nil {
- // c.Data["json"] = lib.JSONS{Code: 204, Msg: "T_sensor_list Err!"}
- // c.ServeJSON()
- // return
- // }
- //
- // Handle.Pu_DeviceParameter_Sensor(admin_r.Admin_uuid, T_SN, Rt_parameter_sensor_)
- // System.Add_UserLogs(admin_r.Admin_uuid,"设备管理", "传感器参数操作", jsonStu_map_)
- //
- // DeviceSensor,is := Device.Read_DeviceSensor_ByT_sn(T_SN, Rt_parameter_sensor_[0].T_id)
- // if is {
- // DeviceSensor.T_name = Rt_parameter_sensor_[0].T_name
- // Device.Update_TDeviceSensor(DeviceSensor,"T_name")
- // }
- //
- //
- // c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
- // c.ServeJSON()
- // return
- //
- //}
- //
- func (c *DeviceController) Pu_DeviceParameter_Sensor() {
- // 验证登录
- b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
- if !b_ {
- c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
- c.ServeJSON()
- return
- }
- T_SN := c.GetString("T_SN")
- T_name := c.GetString("T_name")
- T_id, _ := c.GetInt("T_id")
- T_Tlower, _ := c.GetFloat("T_Tlower")
- T_Tupper, _ := c.GetFloat("T_Tupper")
- T_RHlower, _ := c.GetFloat("T_RHlower")
- T_RHupper, _ := c.GetFloat("T_RHupper")
- T_en, _ := c.GetInt("T_en")
- T_free, _ := c.GetInt("T_free")
- // 权限 过滤
- Admin_Power_, _ := Admin.Read_AdminPower_ById(admin_r.Admin_power)
- if Admin_Power_.Power_DeviceSensor_Compensate_e == 0 {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "! U" + strconv.Itoa(admin_r.Id)}
- c.ServeJSON()
- return
- }
- _, err := Device.Read_Device_ByT_sn(T_SN)
- if err != nil {
- c.Data["json"] = lib.JSONS{Code: 206, Msg: "T_sn Err!"}
- c.ServeJSON()
- return
- }
- DeviceSensor, is := Device.Read_DeviceSensor_ByT_sn(T_SN, T_id)
- if !is {
- c.Data["json"] = lib.JSONS{Code: 208, Msg: "T_sn T_id Err!"}
- c.ServeJSON()
- return
- }
- Devicesensorparameter := Device.DeviceSensorParameter{
- T_sn: T_SN,
- T_id: T_id,
- T_name: T_name,
- T_Tlower: float32(T_Tlower),
- T_Tupper: float32(T_Tupper),
- T_RHlower: float32(T_RHlower),
- T_RHupper: float32(T_RHupper),
- T_en: T_en,
- T_free: T_free,
- T_uuid: admin_r.Admin_uuid,
- T_SendState: 0,
- T_State: 2,
- }
- dsp_id, is := Device.Add_DeviceSensorParameter(Devicesensorparameter)
- if !is {
- c.Data["json"] = lib.JSONS{Code: 209, Msg: "添加失败!"}
- c.ServeJSON()
- return
- }
- Devicesensorparameter.Id = int(dsp_id)
- // 更新名称
- DeviceSensor.T_name = T_name
- Device.Update_DeviceSensor(DeviceSensor, "T_name")
- System.Add_UserLogs_T(admin_r.Admin_uuid, "设备管理", "传感器参数操作", Devicesensorparameter)
- Nats.Pu_DeviceParameter_Sensor(Devicesensorparameter)
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
- c.ServeJSON()
- return
- }
- ////
- //func (c *DeviceController) Pu_DeviceParameter_Sensor_Cache() {
- // // 验证登录
- // b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
- // if !b_ {
- // c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
- // c.ServeJSON()
- // return
- // }
- //
- // T_SN := c.GetString("SN")
- // T_id := c.GetString("T_id")
- // _, err := Device.Read_Device_ByT_sn(T_SN)
- // if err != nil {
- // c.Data["json"] = lib.JSONS{Code: 206, Msg: "T_sn Err!"}
- // c.ServeJSON()
- // return
- // }
- // Admin_Power_, _ := Admin.Read_AdminPower_ById(admin_r.Admin_power)
- // if Admin_Power_.Power_DeviceSensor_Compensate_e == 0 {
- // c.Data["json"] = lib.JSONS{Code: 202, Msg: "! U" + strconv.Itoa(admin_r.Id)}
- // c.ServeJSON()
- // return
- // }
- //
- // T_sensor_list := c.GetString("T_sensor_list")
- // jsonStu_map_ := strings.Replace(string(T_sensor_list), "\"{", "{", -1)
- // jsonStu_map_ = strings.Replace(jsonStu_map_, "}\"", "}", -1)
- // jsonStu_map_ = strings.Replace(jsonStu_map_, "\\\"", "\"", -1)
- // println("jsonStu_map_:", jsonStu_map_)
- // var Rt_parameter_sensor_ []MqttServer.Rt_Parameter_Sensor_
- // err = json.Unmarshal([]byte(jsonStu_map_), &Rt_parameter_sensor_)
- // if err != nil {
- // c.Data["json"] = lib.JSONS{Code: 204, Msg: "T_sensor_list Err!"}
- // c.ServeJSON()
- // return
- // }
- // DeviceSensor,is := Device.Read_DeviceSensor_ByT_sn(T_SN, Rt_parameter_sensor_[0].T_id)
- // if is {
- // DeviceSensor.T_name = Rt_parameter_sensor_[0].T_name
- // Device.Update_TDeviceSensor(DeviceSensor,"T_name")
- // }
- //
- // Device.Redis_DeviceSensorParameterCache_Set(T_SN+"_"+T_id,jsonStu_map_)
- // //Handle.Pu_DeviceParameter_Sensor(admin_r.Admin_uuid, T_SN, Rt_parameter_sensor_)
- // System.Add_UserLogs(admin_r.Admin_uuid,"设备管理", "传感器参数操作-离线操作", jsonStu_map_)
- // c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
- // c.ServeJSON()
- // return
- //
- //}
- // 列表 -
- func (c *DeviceController) DeviceWarning_List_html() {
- // 验证登录
- b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
- if !b_ {
- c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
- c.ServeJSON()
- return
- }
- c.Data["Admin_r"] = admin_r
- page, _ := c.GetInt("page")
- println(page)
- if page < 1 {
- page = 1
- }
- c.Data["Admin_r"] = admin_r
- T_Name := c.GetString("T_Name")
- //T_sn := c.GetString("T_sn")
- Time_start := c.GetString("Time_start")
- Time_end := c.GetString("Time_end")
- if len(Time_start) == 0 && len(Time_end) == 0 {
- Time_start = time.Now().Format("2006-01-02") + " 00:00:00"
- Time_end = time.Now().Format("2006-01-02") + " 23:59:59"
- }
- c.Data["Time_start"] = Time_start
- c.Data["Time_end"] = Time_end
- c.Data["T_Name"] = T_Name
- //c.Data["Class_List"] = Device.Read_DeviceWarningList_All_1()
- //T_Title := ""
- //if Class_1 > 0 {
- // T_Title = Device.Read_DeviceWarningList_ById(Class_1).T_name
- //}
- var cnt int64
- DeviceWarning_List, cnt := Device.Read_DeviceWarning_1(admin_r, page, "", T_Name, Time_start, Time_end)
- //for i, v := range DeviceWarning_List {
- // DeviceWarning_List[i].T_State = 0
- // if strings.Contains(v.T_sn, "YD") {
- // DeviceWarning_List[i].T_State = 1
- // }
- //}
- c.Data["List"] = DeviceWarning_List
- page_size := math.Ceil(float64(cnt) / float64(conf.Page_size))
- c.Data["Page"] = page
- c.Data["Page_size"] = page_size
- c.Data["Pages"] = lib.Func_page(int64(page), int64(page_size))
- c.Data["cnt"] = cnt
- c.TplName = "Device/DeviceWarning.html"
- }
- // 列表 -
- func (c *DeviceController) DeviceWarning_List() {
- // 验证登录
- b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
- if !b_ {
- c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
- c.ServeJSON()
- return
- }
- type R_JSONS struct {
- //必须的大写开头
- DeviceWarning []Device.DeviceWarning
- //DeviceWarningclass []Device.DeviceWarningList
- Num int
- Page int
- Page_size int
- Pages []lib.Page_T
- }
- var r_jsons R_JSONS
- page, _ := c.GetInt("page")
- println(page)
- if page < 1 {
- page = 1
- }
- T_sn := c.GetString("T_sn")
- //T_sn := c.GetString("Sn")
- //Class_1, _ := c.GetInt("Class_1")
- T_Name := c.GetString("T_Name")
- Time_start := c.GetString("Time_start")
- Time_end := c.GetString("Time_end")
- //r_jsons.DeviceWarningclass = Device.Read_DeviceWarningList_All_1()
- //T_Title := ""
- //if Class_1 > 0 {
- // T_Title = Device.Read_DeviceWarningList_ById(Class_1).T_name
- //}
- var cnt int64
- r_jsons.DeviceWarning, cnt = Device.Read_DeviceWarning_1(admin_r, page, T_sn, T_Name, Time_start, Time_end)
- page_size := math.Ceil(float64(cnt) / float64(conf.Page_size))
- r_jsons.Page = int(page)
- r_jsons.Page_size = int(page_size)
- r_jsons.Pages = lib.Func_page(int64(page), int64(page_size))
- r_jsons.Num = int(cnt)
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
- c.ServeJSON()
- return
- }
- // 列表 -
- func (c *DeviceController) DeviceWarning_Data_Excel() {
- // 验证登录
- b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
- if !b_ {
- c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
- c.ServeJSON()
- return
- }
- //T_sn := c.GetString("T_sn")
- Class_1, _ := c.GetInt("Class_1")
- T_Name := c.GetString("T_Name")
- Time_start := c.GetString("Time_start")
- Time_end := c.GetString("Time_end")
- c.Data["Class_1"] = Class_1
- if len(Time_start) == 0 && len(Time_end) == 0 {
- Time_start = time.Now().Format("2006-01-02") + " 00:00:00"
- Time_end = time.Now().Format("2006-01-02") + " 23:59:59"
- }
- //
- //T_Title := ""
- //if Class_1 > 0 {
- // T_Title = Device.Read_DeviceWarningList_ById(Class_1).T_name
- //}
- Device_data, _ := Device.Read_DeviceWarning_1(admin_r, 9999, "", T_Name, Time_start, Time_end)
- f := excelize.NewFile() // 设置单元格的值
- // 这里设置表头
- f.SetCellValue("Sheet1", "A1", "报警类型")
- f.SetCellValue("Sheet1", "B1", "Sn")
- f.SetCellValue("Sheet1", "C1", "设备名称")
- f.SetCellValue("Sheet1", "D1", "传感器")
- f.SetCellValue("Sheet1", "E1", "温度℃")
- f.SetCellValue("Sheet1", "F1", "湿度%")
- f.SetCellValue("Sheet1", "G1", "报警内容")
- f.SetCellValue("Sheet1", "H1", "记录时间")
- f.SetCellValue("Sheet1", "I1", "处理")
- f.SetCellValue("Sheet1", "J1", "处理时间")
- // 设置列宽
- f.SetColWidth("Sheet1", "A", "A", 20)
- f.SetColWidth("Sheet1", "B", "B", 25)
- f.SetColWidth("Sheet1", "C", "C", 30)
- f.SetColWidth("Sheet1", "D", "D", 30)
- f.SetColWidth("Sheet1", "E", "E", 10)
- f.SetColWidth("Sheet1", "F", "F", 10)
- f.SetColWidth("Sheet1", "G", "G", 30)
- f.SetColWidth("Sheet1", "H", "H", 15)
- f.SetColWidth("Sheet1", "I", "I", 30)
- f.SetColWidth("Sheet1", "J", "J", 15)
- line := 1
- // 循环写入数据
- for _, v := range Device_data {
- line++
- f.SetCellValue("Sheet1", fmt.Sprintf("A%d", line), v.T_Title)
- f.SetCellValue("Sheet1", fmt.Sprintf("B%d", line), v.T_sn+"["+strconv.Itoa(v.T_Id)+"]")
- f.SetCellValue("Sheet1", fmt.Sprintf("C%d", line), v.T_Addr)
- f.SetCellValue("Sheet1", fmt.Sprintf("D%d", line), v.T_Name)
- f.SetCellValue("Sheet1", fmt.Sprintf("E%d", line), v.T_T)
- f.SetCellValue("Sheet1", fmt.Sprintf("F%d", line), v.T_RH)
- f.SetCellValue("Sheet1", fmt.Sprintf("G%d", line), v.T_Remark)
- f.SetCellValue("Sheet1", fmt.Sprintf("H%d", line), v.T_Ut)
- f.SetCellValue("Sheet1", fmt.Sprintf("I%d", line), v.T_Text)
- f.SetCellValue("Sheet1", fmt.Sprintf("J%d", line), v.UpdateTime)
- }
- timeStr := time.Now().Format("20060102150405")
- // 保存文件
- if err := f.SaveAs("ofile/" + timeStr + ".xlsx"); err != nil {
- fmt.Println(err)
- }
- url, is := Nats.Qiniu_UploadFile(lib.GetCurrentDirectory()+"ofile/"+timeStr+".xlsx", "ofile/"+timeStr+".xlsx")
- if !is {
- c.Data["json"] = lib.JSONS{Code: 203, Msg: "oss!"}
- c.ServeJSON()
- return
- }
- //删除目录
- //err := os.Remove("ofile/" + timeStr + ".xlsx")
- //if err != nil {
- // fmt.Println(err)
- //}
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: url}
- c.ServeJSON()
- return
- }
- func (c *DeviceController) DeviceWarning_() {
- id, _ := c.GetInt("id")
- c.Data["T"] = Device.Read_DeviceWarning_ById(id)
- c.Data["id"] = id
- c.TplName = "Device/DeviceWarning-.html"
- }
- func (c *DeviceController) DeviceWarning_M() {
- id := c.GetString("id")
- c.Data["id"] = id
- c.TplName = "Device/DeviceWarning-M.html"
- }
- func (c *DeviceController) DeviceWarning_Post() {
- // 验证登录
- b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
- if !b_ {
- c.Ctx.Redirect(302, "Login")
- return
- }
- Id, _ := c.GetInt("Id")
- T_Text := c.GetString("T_Text")
- t_c := Device.DeviceWarning{
- Id: Id,
- T_Text: T_Text,
- }
- Device.Update_DeviceWarning_ById(t_c)
- System.Add_UserLogs(admin_r.Admin_uuid, "设备管理", "报警处理操作", strconv.Itoa(Id)+"->"+T_Text)
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
- c.ServeJSON()
- return
- }
- func (c *DeviceController) DeviceWarning_Del() {
- // 验证登录
- b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
- if !b_ {
- c.Ctx.Redirect(302, "Login")
- return
- }
- Id, _ := c.GetInt("Id")
- t_c := Device.DeviceWarning{
- Id: Id,
- }
- Device.Update_DeviceWarning_Delete(t_c)
- System.Add_UserLogs(admin_r.Admin_uuid, "设备管理", "报警删除操作", strconv.Itoa(Id))
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
- c.ServeJSON()
- return
- }
- // 用户管理
- func (c *DeviceController) DeviceBind_html() {
- // 验证登录
- b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
- if !b_ {
- c.Ctx.Redirect(302, "Login")
- return
- }
- c.Data["Admin_Power"], _ = Admin.Read_AdminPower_ById(admin_r.Admin_power)
- page, _ := c.GetInt("page")
- println(page)
- if page < 1 {
- page = 1
- }
- Name := c.GetString("Name")
- c.Data["Name"] = Name
- c.Data["Power_List"] = Admin.Read_Power_List_ALL_Power_Administration(0)
- Adminpower, _ := Admin.Read_AdminPower_ById(admin_r.Admin_power)
- var cnt int64
- if Adminpower.Power_User_r != 1 {
- c.Ctx.Redirect(302, "Login")
- return
- }
- c.Data["List"], cnt = Admin.Read_Admin_List_ALL_User(page, Name, admin_r.Id)
- fmt.Println("cnt:", cnt)
- page_size := math.Ceil(float64(cnt) / float64(conf.Page_size))
- c.Data["Page"] = page
- c.Data["Page_size"] = page_size
- c.Data["Pages"] = lib.Func_page(int64(page), int64(page_size))
- c.Data["cnt"] = cnt
- c.TplName = "Device/DeviceBind.html"
- }
- func (c *DeviceController) DeviceBind_List() {
- // 验证登录
- b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
- if !b_ {
- c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
- c.ServeJSON()
- return
- }
- if len(c.GetString("Admin_uuid")) > 1 {
- s_, user_r := Admin.Read_Admin_ByAdmin_uuid(c.GetString("Admin_uuid"))
- if s_ != nil {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "Admin_uuid Err!"}
- c.ServeJSON()
- return
- }
- admin_r = user_r
- }
- type R_JSONS struct {
- //必须的大写开头
- Device_lite []Device.Device
- Num int
- Page int
- Page_size int
- Pages []lib.Page_T
- }
- var r_jsons R_JSONS
- page, _ := c.GetInt("page")
- println(page)
- if page < 1 {
- page = 1
- }
- page_z, _ := c.GetInt("page_z")
- println(page_z)
- if page_z == 0 {
- page_z = conf.Page_size
- }
- Class_1 := c.GetString("Class_1")
- Name := c.GetString("Name")
- T_sn := c.GetString("T_sn")
- T_monitor := c.GetString("T_monitor")
- //Class_1, _ := c.GetInt("Class_1")
- //Name := c.GetString("Name")
- //T_sn := c.GetString("T_sn")
- //c.Data["Class_1"] = Class_1
- ////c.Data["Name"] = Name
- //c.Data["T_sn"] = T_sn
- var cnt int64
- Device_lite, cnt := Device.Read_Device_ALL_bind_1(admin_r, page, page_z, T_sn, Name, Class_1, T_monitor)
- //for i, _ := range Device_lite {
- //
- // //监控状态
- // Device_lite[i].T_monitor = 1
- // if(strings.Contains(Device_lite[i].T_sn, "YD")){
- // DeviceTask_r,DeviceTask_is := Device.Read_DeviceTask_All_Limit_1(Device_lite[i].T_sn)
- // Device_lite[i].T_monitor = 0
- //
- // if(DeviceTask_is){
- // if(DeviceTask_r.T_Ut_end.IsZero()){
- // Device_lite[i].T_monitor = 1
- // }
- // }
- // }
- //
- //}
- r_jsons.Device_lite = Device_lite
- page_size := math.Ceil(float64(cnt) / float64(page_z))
- r_jsons.Page = page
- r_jsons.Page_size = int(page_size)
- r_jsons.Pages = lib.Func_page(int64(page), int64(page_size))
- r_jsons.Num = int(cnt)
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
- c.ServeJSON()
- return
- }
- func (c *DeviceController) DeviceBind_Sensor_List() {
- // 验证登录
- b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
- if !b_ {
- c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
- c.ServeJSON()
- return
- }
- if len(c.GetString("Admin_uuid")) > 1 {
- s_, user_r := Admin.Read_Admin_ByAdmin_uuid(c.GetString("Admin_uuid"))
- if s_ != nil {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "Admin_uuid Err!"}
- c.ServeJSON()
- return
- }
- admin_r = user_r
- }
- // 模板
- type R_DeviceSensor struct {
- T_sn string // 设备序列号 KF开头,环境监测主机。 YD开头,温途监测主机
- T_devName string //设备名称
- T_sensor int // 传感器数量
- T_monitor int // 监控状态 1 监控 0 未监控
- T_sn_yd int // 湿度显示
- T_battery int // 电量
- T_sensor_list []Device.DeviceSensor_R // 传感器List
- T_MSISDN string //设备名称
- UpdateTime time.Time //auto_now 每次 model 保存时都会对时间自动更新
- }
- type R_JSONS struct {
- //必须的大写开头
- Device_lite []R_DeviceSensor
- Num int
- Page int
- Page_size int
- Pages []lib.Page_T
- }
- var r_jsons R_JSONS
- page, _ := c.GetInt("page")
- println(page)
- if page < 1 {
- page = 1
- }
- page_z, _ := c.GetInt("page_z")
- println(page_z)
- if page_z == 0 {
- page_z = conf.Page_size
- }
- Class_1 := c.GetString("Class_1")
- Name := c.GetString("Name")
- T_sn := c.GetString("T_sn")
- T_monitor := c.GetString("T_monitor")
- //Class_1, _ := c.GetInt("Class_1")
- //Name := c.GetString("Name")
- //T_sn := c.GetString("T_sn")
- //c.Data["Class_1"] = Class_1
- ////c.Data["Name"] = Name
- //c.Data["T_sn"] = T_sn
- var cnt int64
- Device_lite, cnt := Device.Read_Device_ALL_bind_1(admin_r, page, page_z, T_sn, Name, Class_1, T_monitor)
- for _, v := range Device_lite {
- r_Device := R_DeviceSensor{}
- r_Device.T_sn_yd = 0
- if strings.Contains(v.T_sn, "YD") {
- r_Device.T_sn_yd = 1
- }
- r_Device.T_sn = v.T_sn
- r_Device.T_MSISDN = v.T_MSISDN
- r_Device.T_devName = v.T_devName
- r_Device.T_sensor_list, r_Device.T_sensor = Device.Read_DeviceSensor_ByTsn(v.T_sn)
- r_Device.T_monitor = v.T_monitor
- // 电量
- DeviceSensorData, is := Device.Read_DeviceSensorData_ById_New(v.T_sn, 0)
- if is {
- r_Device.T_battery = DeviceSensorData.T_Dattery
- }
- r_jsons.Device_lite = append(r_jsons.Device_lite, r_Device)
- }
- page_size := math.Ceil(float64(cnt) / float64(page_z))
- r_jsons.Page = page
- r_jsons.Page_size = int(page_size)
- r_jsons.Pages = lib.Func_page(int64(page), int64(page_size))
- r_jsons.Num = int(cnt)
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
- c.ServeJSON()
- return
- }
- func (c *DeviceController) DeviceBind_html_() {
- // 验证登录
- b_, _ := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
- if !b_ {
- c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
- c.ServeJSON()
- return
- }
- c.TplName = "Device/DeviceBind-.html"
- }
- func (c *DeviceController) DeviceBind_Add_All() {
- // 验证登录
- b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
- if !b_ {
- c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
- c.ServeJSON()
- return
- }
- s_, user_r := Admin.Read_Admin_ByAdmin_uuid(c.GetString("Admin_uuid"))
- if s_ != nil {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "Admin_uuid Err!"}
- c.ServeJSON()
- return
- }
- Name := c.GetString("Name")
- T_sn := c.GetString("T_sn")
- num_x := 0
- Device_l := Device.Read_Device_ALL_T_sn_T_devName_bind_1(T_sn, Name, admin_r)
- fmt.Println("len(Device_l):", len(Device_l))
- for _, v := range Device_l {
- Device_bind_list := Device.Read_Device_ALL_T_sn_bind_1(v.T_sn, user_r)
- if len(Device_bind_list) > 0 {
- continue
- }
- T_Bind := Device.Device_Bind_Add(v.T_sn, user_r)
- Device.DeviceSensor_T_Bind_ALL(v.T_sn, T_Bind)
- System.Add_UserLogs(admin_r.Admin_uuid, "设备管理", "设备绑定", v.T_sn+"+>"+c.GetString("Admin_uuid"))
- num_x = num_x + 1
- }
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: num_x}
- c.ServeJSON()
- return
- }
- func (c *DeviceController) DeviceBind_Add() {
- // 验证登录
- b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
- if !b_ {
- c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
- c.ServeJSON()
- return
- }
- s_, user_r := Admin.Read_Admin_ByAdmin_uuid(c.GetString("Admin_uuid"))
- if s_ != nil {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "Admin_uuid Err!"}
- c.ServeJSON()
- return
- }
- T_sn := c.GetString("T_sn")
- if len(T_sn) < 5 {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_sn Err!"}
- c.ServeJSON()
- return
- }
- _, err := Device.Read_Device_ByT_sn(T_sn)
- if err != nil {
- c.Data["json"] = lib.JSONS{Code: 206, Msg: "T_sn Err!"}
- c.ServeJSON()
- return
- }
- Device_bind_list := Device.Read_Device_ALL_T_sn_bind_1(T_sn, user_r)
- if len(Device_bind_list) > 0 {
- c.Data["json"] = lib.JSONS{Code: 203, Msg: "ok!"}
- c.ServeJSON()
- return
- }
- // 同步权限
- T_Bind := Device.Device_Bind_Add(T_sn, user_r)
- Device.DeviceSensor_T_Bind_ALL(T_sn, T_Bind)
- System.Add_UserLogs(admin_r.Admin_uuid, "设备管理", "设备绑定", T_sn+"+>"+c.GetString("Admin_uuid"))
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
- c.ServeJSON()
- return
- }
- func (c *DeviceController) DeviceBind_Del() {
- // 验证登录
- b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
- if !b_ {
- c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
- c.ServeJSON()
- return
- }
- s_, user_r := Admin.Read_Admin_ByAdmin_uuid(c.GetString("Admin_uuid"))
- if s_ != nil {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "Admin_uuid Err!"}
- c.ServeJSON()
- return
- }
- T_sn := c.GetString("T_sn")
- if len(T_sn) < 5 {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_sn Err!"}
- c.ServeJSON()
- return
- }
- _, err := Device.Read_Device_ByT_sn(T_sn)
- if err != nil {
- c.Data["json"] = lib.JSONS{Code: 206, Msg: "T_sn Err!"}
- c.ServeJSON()
- return
- }
- Device_bind_list := Device.Read_Device_ALL_T_sn_bind_1(T_sn, user_r)
- if len(Device_bind_list) == 0 {
- c.Data["json"] = lib.JSONS{Code: 204, Msg: "ok!"}
- c.ServeJSON()
- return
- }
- // 同步权限
- T_Bind := Device.Device_Bind_Del(T_sn, user_r)
- Device.DeviceSensor_T_Bind_ALL(T_sn, T_Bind)
- System.Add_UserLogs(admin_r.Admin_uuid, "设备管理", "设备解除绑定", T_sn+"->"+c.GetString("Admin_uuid"))
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
- c.ServeJSON()
- return
- }
- // 设备分类
- func (c *DeviceController) DeviceClass_html() {
- // 验证登录
- b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
- if !b_ {
- c.Ctx.Redirect(302, "Login")
- return
- }
- page, _ := c.GetInt("page")
- println(page)
- if page < 1 {
- page = 1
- }
- Name := c.GetString("Name")
- c.Data["Name"] = Name
- var cnt int64
- c.Data["List"], cnt = Device.Read_DeviceClass_ALL_1(admin_r.Admin_uuid, page, Name)
- fmt.Println("cnt:", cnt)
- page_size := math.Ceil(float64(cnt) / float64(conf.Page_size))
- c.Data["Page"] = page
- c.Data["Page_size"] = page_size
- c.Data["Pages"] = lib.Func_page(int64(page), int64(page_size))
- c.Data["cnt"] = cnt
- c.TplName = "Device/DeviceClass.html"
- }
- func (c *DeviceController) DeviceClass_() {
- id, _ := c.GetInt("id")
- c.Data["T"], _ = Device.Read_Class_ById(id)
- c.Data["id"] = id
- c.TplName = "Device/DeviceClass-.html"
- }
- func (c *DeviceController) DeviceClass_Post() {
- // 验证登录
- b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
- if !b_ {
- c.Ctx.Redirect(302, "Login")
- return
- }
- Id, _ := c.GetInt("Id")
- T_name := c.GetString("T_name")
- T_Notice_wx := c.GetString("T_Notice_wx")
- T_Notice_wx2 := c.GetString("T_Notice_wx2")
- T_Notice_phone := c.GetString("T_Notice_phone")
- T_Notice_message := c.GetString("T_Notice_message")
- T_Notice_mailbox := c.GetString("T_Notice_mailbox")
- T_Notice_mechanism := c.GetString("T_Notice_mechanism")
- t_c := Device.DeviceClass{
- Id: Id,
- T_name: T_name,
- T_Notice_wx: T_Notice_wx,
- T_Notice_wx2: T_Notice_wx2,
- T_Notice_phone: T_Notice_phone,
- T_Notice_message: T_Notice_message,
- T_Notice_mailbox: T_Notice_mailbox,
- T_Notice_mechanism: T_Notice_mechanism,
- }
- if Id == 0 {
- t_c.T_State = 1
- t_c.T_uuid = admin_r.Admin_uuid
- t_c.T_Notice_wx = ""
- t_c.T_Notice_wx2 = ""
- t_c.T_Notice_phone = ""
- t_c.T_Notice_message = ""
- t_c.T_Notice_mailbox = ""
- t_c.T_Notice_mechanism = Device.Read_DeviceWarningList_All_T_Notice_mechanism()
- Device.Add_Class(t_c)
- } else {
- Device.Update_Class_ById(t_c)
- }
- System.Add_UserLogs_T(admin_r.Admin_uuid, "设备管理", "分类操作", t_c)
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
- c.ServeJSON()
- return
- }
- func (c *DeviceController) DeviceWarningList_T_Tips() {
- // 验证登录
- b_, _ := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
- if !b_ {
- c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
- c.ServeJSON()
- return
- }
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: Device.Read_DeviceWarningList_All_T_Notice_mechanism()}
- c.ServeJSON()
- return
- }
- func (c *DeviceController) DeviceClass_Del() {
- // 验证登录
- b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
- if !b_ {
- c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
- c.ServeJSON()
- return
- }
- id, _ := c.GetInt("Id")
- class_r, err := Device.Read_Class_ById(id)
- if err != nil {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "id Err!"}
- c.ServeJSON()
- return
- }
- if class_r.T_uuid != admin_r.Admin_uuid {
- c.Data["json"] = lib.JSONS{Code: 203, Msg: "T_uuid Err!"}
- c.ServeJSON()
- return
- }
- Device.Delete_Class_ById(id)
- DeviceSensor_class_list := Device.Read_DeviceSensor_ALL_class_1(id)
- for _, v := range DeviceSensor_class_list {
- Device.DeviceSensor_Bind_Del(v.T_sn, v.T_id, id)
- }
- System.Add_UserLogs(admin_r.Admin_uuid, "设备管理", "删除分类操作", strconv.Itoa(id))
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
- c.ServeJSON()
- return
- }
- func (c *DeviceController) DeviceClass_Syn() {
- // 验证登录
- b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
- if !b_ {
- c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
- c.ServeJSON()
- return
- }
- s_, user_r := Admin.Read_Admin_ByAdmin_uuid(c.GetString("Admin_uuid"))
- if s_ != nil {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "Admin_uuid Err!"}
- c.ServeJSON()
- return
- }
- // 先全部 清掉
- Device.Device_Bind_ALL_Del(user_r)
- class_r := Device.Read_DeviceClass_ALL_T_uuid_1(user_r.Admin_uuid)
- for _, v := range class_r {
- fmt.Println("清掉:", v.Id)
- // 删除分类
- Device.Delete_Class_ById(v.Id)
- // 删除 传感器分类
- Device.DeviceSensor_T_Calss_ALL_Del(v.Id)
- //Device.DeviceSensor_T_Bind_ALL_Del(user_r)
- }
- // 重新插入 分类
- num_x := 0
- class_r = Device.Read_DeviceClass_ALL_T_uuid_1(admin_r.Admin_uuid)
- for _, v := range class_r {
- fmt.Println("插入:", v.Id)
- t_c := Device.DeviceClass{
- T_uuid: user_r.Admin_uuid,
- T_name: v.T_name,
- T_Notice_wx: "",
- T_Notice_phone: "",
- T_Notice_message: "",
- T_Notice_mailbox: "",
- T_State: 1,
- }
- num_x = num_x + 1
- // 添加分类
- cid, err := Device.Add_Class(t_c)
- if err != nil {
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "Add_Class E!"}
- c.ServeJSON()
- return
- }
- fmt.Println("cid:", cid)
- // 添加 传感器分类
- DeviceSensor_class_list := Device.Read_DeviceSensor_ALL_class_1(int(v.Id))
- for _, v_c := range DeviceSensor_class_list {
- // 绑定所有分类
- Device.DeviceSensor_T_Calss_Add(v_c.T_sn, v_c.T_id, int(cid))
- // 绑定所有权限
- //Device_r, _ := Device.Read_Device_ByT_sn(v_c.T_sn)
- //Device.DeviceSensor_T_Bind_Add(v_c.T_sn, v_c.T_id, user_r)
- T_Bind := Device.Device_Bind_Add(v_c.T_sn, user_r)
- Device.DeviceSensor_T_Bind_ALL(v_c.T_sn, T_Bind)
- }
- //
- }
- System.Add_UserLogs(admin_r.Admin_uuid, "设备管理", "同步分类操作", "->"+user_r.Admin_uuid)
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: num_x}
- c.ServeJSON()
- return
- }
- func (c *DeviceController) DeviceClassBind_html_() {
- // 验证登录
- b_, _ := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
- if !b_ {
- c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
- c.ServeJSON()
- return
- }
- c.TplName = "Device/DeviceClassBind-.html"
- }
- func (c *DeviceController) DeviceClassBind_List() {
- // 验证登录
- b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
- if !b_ {
- c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
- c.ServeJSON()
- return
- }
- type R_JSONS struct {
- //必须的大写开头
- DeviceSensor_lite []Device.DeviceSensor
- Num int
- Page int
- Page_size int
- Pages []lib.Page_T
- }
- var r_jsons R_JSONS
- page, _ := c.GetInt("page")
- println(page)
- if page < 1 {
- page = 1
- }
- Name := c.GetString("Name")
- T_sn := c.GetString("T_sn")
- T_calss_id, _ := c.GetInt("T_calss_id")
- page_z, _ := c.GetInt("page_z")
- if page_z == 0 {
- page_z = conf.Page_size
- }
- //Name := c.GetString("Name")
- //T_sn := c.GetString("T_sn")
- //c.Data["Class_1"] = Class_1
- ////c.Data["Name"] = Name
- //c.Data["T_sn"] = T_sn
- R_DeviceClass, err := Device.Read_Class_ById(T_calss_id)
- if err != nil {
- c.Data["json"] = lib.JSONS{Code: 205, Msg: "T_class_id Err!"}
- c.ServeJSON()
- return
- }
- if R_DeviceClass.T_uuid != admin_r.Admin_uuid {
- c.Data["json"] = lib.JSONS{Code: 205, Msg: "T_class_id != Admin_uuid Err!"}
- c.ServeJSON()
- return
- }
- var cnt int64
- Device_lite, cnt := Device.Read_DeviceSensor_class_ALL_1(admin_r, T_calss_id, page, page_z, T_sn, Name, "")
- r_jsons.DeviceSensor_lite = Device_lite
- page_size := math.Ceil(float64(cnt) / float64(page_z))
- r_jsons.Page = page
- r_jsons.Page_size = int(page_size)
- r_jsons.Pages = lib.Func_page(int64(page), int64(page_size))
- r_jsons.Num = int(cnt)
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
- c.ServeJSON()
- return
- }
- func (c *DeviceController) DeviceClassBind_Add() {
- // 验证登录
- b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
- if !b_ {
- c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
- c.ServeJSON()
- return
- }
- T_class_id, _ := c.GetInt("T_class_id")
- T_sn := c.GetString("T_sn")
- T_id, _ := c.GetInt("T_id")
- if T_class_id == 0 || T_id == 0 || len(T_sn) == 0 {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_sn T_id T_class_id Err!"}
- c.ServeJSON()
- return
- }
- if _, err := Device.Read_Device_ByT_sn(T_sn); err != nil {
- c.Data["json"] = lib.JSONS{Code: 204, Msg: "T_id Err!"}
- c.ServeJSON()
- return
- }
- R_DeviceClass, err := Device.Read_Class_ById(T_class_id)
- if err != nil {
- c.Data["json"] = lib.JSONS{Code: 205, Msg: "T_class_id Err!"}
- c.ServeJSON()
- return
- }
- if R_DeviceClass.T_uuid != admin_r.Admin_uuid {
- c.Data["json"] = lib.JSONS{Code: 205, Msg: "T_class_id != Admin_uuid Err!"}
- c.ServeJSON()
- return
- }
- DeviceSensor_class_list := Device.Read_DeviceSensor_ALL_T_sn_T_id_class_1(T_sn, T_id, T_class_id)
- if len(DeviceSensor_class_list) > 0 {
- c.Data["json"] = lib.JSONS{Code: 203, Msg: "ok!"}
- c.ServeJSON()
- return
- }
- Device.DeviceSensor_T_Calss_Add(T_sn, T_id, T_class_id)
- System.Add_UserLogs(admin_r.Admin_uuid, "设备管理", "分类绑定操作", strconv.Itoa(T_class_id)+"+>"+T_sn+"-"+strconv.Itoa(T_id))
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
- c.ServeJSON()
- return
- }
- func (c *DeviceController) DeviceClassBind_Del() {
- // 验证登录
- b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
- if !b_ {
- c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
- c.ServeJSON()
- return
- }
- T_class_id, _ := c.GetInt("T_class_id")
- T_sn := c.GetString("T_sn")
- T_id, _ := c.GetInt("T_id")
- if T_class_id == 0 || T_id == 0 || len(T_sn) == 0 {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_sn T_id T_class_id Err!"}
- c.ServeJSON()
- return
- }
- if _, err := Device.Read_Device_ByT_sn(T_sn); err != nil {
- c.Data["json"] = lib.JSONS{Code: 204, Msg: "T_id Err!"}
- c.ServeJSON()
- return
- }
- R_DeviceClass, err := Device.Read_Class_ById(T_class_id)
- if err != nil {
- c.Data["json"] = lib.JSONS{Code: 205, Msg: "T_class_id Err!"}
- c.ServeJSON()
- return
- }
- if R_DeviceClass.T_uuid != admin_r.Admin_uuid {
- c.Data["json"] = lib.JSONS{Code: 205, Msg: "T_class_id != Admin_uuid Err!"}
- c.ServeJSON()
- return
- }
- DeviceSensor_class_list := Device.Read_DeviceSensor_ALL_T_sn_T_id_class_1(T_sn, T_id, T_class_id)
- if len(DeviceSensor_class_list) == 0 {
- c.Data["json"] = lib.JSONS{Code: 203, Msg: "ok!"}
- c.ServeJSON()
- return
- }
- Device.DeviceSensor_Bind_Del(T_sn, T_id, T_class_id)
- System.Add_UserLogs(admin_r.Admin_uuid, "设备管理", "分类删除绑定操作", strconv.Itoa(T_class_id)+"->"+T_sn+"-"+strconv.Itoa(T_id))
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
- c.ServeJSON()
- return
- }
- func (c *DeviceController) Get_DeviceClassId() {
- // 验证登录
- b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
- if !b_ {
- c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
- c.ServeJSON()
- return
- }
- T_class_id, _ := c.GetInt("T_class_id")
- R_DeviceClass, err := Device.Read_Class_ById(T_class_id)
- if err != nil {
- c.Data["json"] = lib.JSONS{Code: 201, Msg: "T_class_id Err!"}
- c.ServeJSON()
- return
- }
- if R_DeviceClass.T_uuid != admin_r.Admin_uuid {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_class_id != T_uuid Err!"}
- c.ServeJSON()
- return
- }
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: R_DeviceClass}
- c.ServeJSON()
- return
- }
- // 任务列表
- func (c *DeviceController) DeviceTask_List() {
- // 验证登录
- b_, _ := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
- if !b_ {
- c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
- c.ServeJSON()
- return
- }
- T_sn := c.GetString("T_sn")
- Time_end := c.GetString("Time_end")
- Time_start := c.GetString("Time_start")
- DeviceTask_lite, _ := Device.Read_DeviceTask_All_50(T_sn, Time_end, Time_start)
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: DeviceTask_lite}
- c.ServeJSON()
- return
- }
- // 任务列表
- func (c *DeviceController) DeviceTask_Post() {
- // 验证登录
- b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
- if !b_ {
- c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
- c.ServeJSON()
- return
- }
- T_sn := c.GetString("T_sn")
- T_task := c.GetString("T_task")
- Nats.Set_DeviceTask(Device.Device_task{
- T_sn: T_sn,
- T_task: T_task,
- })
- System.Add_UserLogs(admin_r.Admin_uuid, "设备管理", "远程启停", T_sn+"-"+T_task)
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
- c.ServeJSON()
- return
- }
- func (c *DeviceController) Get_DeviceClassId_QRCode() {
- // 验证登录
- b_, _ := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
- if !b_ {
- c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
- c.ServeJSON()
- return
- }
- T_calss_id := c.GetString("T_class_id")
- if len(T_calss_id) == 0 {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_calss_id Err!"}
- c.ServeJSON()
- return
- }
- T_calss_id_str, _ := Nats.Wx_GenerateQRCode("-|" + lib.AesEncryptCBC(T_calss_id, "0123456789012345") + "|- @宝智达 微信公众号通知")
- if len(T_calss_id_str) == 0 {
- c.Data["json"] = lib.JSONS{Code: 201, Msg: "Err!"}
- c.ServeJSON()
- return
- }
- type Text struct {
- QR string
- Code string
- }
- T_calss_id_str = "https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=" + T_calss_id_str
- Text_r := Text{
- QR: T_calss_id_str,
- Code: "请将本内容发送到 深圳市宝智达科技有限公司 微信公众号-|" + lib.AesEncryptCBC(T_calss_id, "0123456789012345") + "|- @宝智达 微信公众号通知 ",
- }
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: Text_r}
- c.ServeJSON()
- return
- }
- // 列表 - 设备日志
- func (c *DeviceController) DeviceLogs() {
- page, _ := c.GetInt("page")
- println(page)
- if page < 1 {
- page = 1
- }
- T_sn := c.GetString("T_sn")
- c.Data["T_sn"] = T_sn
- var cnt int64
- c.Data["List"], cnt = System.Read_DeviceLogs_ALL(page, T_sn)
- page_size := math.Ceil(float64(cnt) / float64(conf.Page_size))
- c.Data["Page"] = page
- c.Data["Page_size"] = page_size
- c.Data["Pages"] = lib.Func_page(int64(page), int64(page_size))
- c.Data["cnt"] = cnt
- c.TplName = "Device/DeviceLogs.html"
- }
|