1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325 |
- package controllers
- import (
- "Cold_Api/Nats/NatsServer"
- "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)
- var Device_lite_r []Device.R_Device
- page, _ := c.GetInt("page")
- println(page)
- if page < 1 {
- page = 1
- }
- page_z := 4
- Class_1 := c.GetString("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, "", "")
- for _, v := range Device_lite {
- r_Device := Device.R_Device{}
- 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_online_4g = v.T_online_4g
- r_Device.T_monitor = v.T_monitor
- r_Device.T_Dattery = v.T_Dattery
- r_Device.T_protocol = v.T_protocol
- r_Device.T_sensor_list, r_Device.T_sensor = Device.Read_DeviceSensor_ByTsn(v.T_sn)
- Device_lite_r = append(Device_lite_r, r_Device)
- }
- c.Data["Device_lite"] = Device_lite_r
- page_size := math.Ceil(float64(cnt) / float64(page_z))
- 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 {
- NatsServer.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) Device_v2_Parameter_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
- }
- Sn := c.GetString("T_sn")
- DeviceParameter_lite := Device.Read_DeviceParameter_SN_List(Sn)
- if len(DeviceParameter_lite) == 0 {
- NatsServer.Read_DeviceParameter(Sn)
- c.Data["json"] = lib.JSONS{Code: 203, Msg: "未同步参数,请检查设备是否正常!"}
- c.ServeJSON()
- return
- }
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: DeviceParameter_lite}
- c.ServeJSON()
- return
- }
- 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) DeviceSensor_v2_Parameter_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
- }
- Sn := c.GetString("T_sn")
- Id, _ := c.GetInt("T_id")
- //c.Data["DeviceSensor"], _ = Device.Read_DeviceSensor_ByTsn_Tid(Sn, Id)
- DeviceSensorParameter_lite := Device.Read_DeviceSensorParameter_List(Sn, Id)
- if len(DeviceSensorParameter_lite) == 0 {
- NatsServer.Read_DeviceSensorParameter(Sn)
- c.Data["json"] = lib.JSONS{Code: 203, Msg: "未同步参数,请检查设备是否正常!"}
- c.ServeJSON()
- return
- }
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: DeviceSensorParameter_lite}
- c.ServeJSON()
- return
- }
- 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)
- NatsServer.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) DeviceSensor_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("T_sn")
- Id, _ := c.GetInt("T_id")
- if admin_r.Admin_power > 6 {
- c.Data["json"] = lib.JSONS{Code: 204, Msg: "没有权限!"}
- c.ServeJSON()
- return
- }
- _, is := Device.Read_DeviceSensor_ByT_sn(Sn, Id)
- if !is {
- c.Data["json"] = lib.JSONS{Code: 205, Msg: "信息错误!"}
- c.ServeJSON()
- return
- }
- // 0默认:从数据库删除 1:从设备删除
- T_mode, _ := c.GetInt("T_mode")
- if T_mode == 1 {
- Device.Delete_DeviceSensor_ById(Sn, Id)
- NatsServer.Del_DeviceSensor(Device.DeviceSensor_Del{
- T_sn: Sn, T_id: Id,
- })
- System.Add_UserLogs_T(admin_r.Admin_uuid, "设备管理", "传感器 删除操作", "SN:"+Sn+" ["+strconv.Itoa(Id)+"]")
- } else {
- Device.Delete_DeviceSensor_ById(Sn, Id)
- System.Add_UserLogs_T(admin_r.Admin_uuid, "设备管理", "传感器 删除操作", "SN:"+Sn+" ["+strconv.Itoa(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) DeviceSensor_Edit() {
- // 验证登录
- 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("T_sn")
- Id, _ := c.GetInt("T_id")
- DeviceSensor, is := Device.Read_DeviceSensor_ByT_sn(Sn, Id)
- if !is {
- c.Data["json"] = lib.JSONS{Code: 201, Msg: "信息错误!"}
- c.ServeJSON()
- return
- }
- // 实时数据显示排序
- if v, err := c.GetInt("T_sort"); err == nil {
- DeviceSensor.T_sort = v
- Device.Update_DeviceSensor(DeviceSensor, "T_sort")
- System.Add_UserLogs_T(admin_r.Admin_uuid, "设备管理", "传感器 排序操作", "SN:"+Sn+" ["+strconv.Itoa(Id)+"]"+strconv.Itoa(v))
- }
- // 屏蔽数据展示 0:屏蔽数据展示 1:正常数据展示
- if v, err := c.GetInt("T_datashow"); err == nil {
- DeviceSensor.T_datashow = v
- Device.Update_DeviceSensor(DeviceSensor, "T_datashow")
- System.Add_UserLogs_T(admin_r.Admin_uuid, "设备管理", "传感器 数据展示(0 屏蔽数据展示 1 正常数据展示)", "SN:"+Sn+" ["+strconv.Itoa(Id)+"]"+strconv.Itoa(v))
- }
- // 3D视图ID (内部运维)
- if v := c.GetString("T_3dview"); len(v) > 0 {
- if admin_r.Admin_power <= 6 { // 内部运维以上
- DeviceSensor.T_3dview = v
- Device.Update_DeviceSensor(DeviceSensor, "T_3dview")
- System.Add_UserLogs_T(admin_r.Admin_uuid, "设备管理", "3D 视图ID操作", "SN:"+Sn+" ["+strconv.Itoa(Id)+"]"+v)
- }
- }
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "OK"}
- c.ServeJSON()
- return
- }
- func (c *DeviceController) UpDeviceSensor_T3dview() {
- // 验证登录
- 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_3dview := c.GetString("T_3dview")
- DeviceSensor, is := Device.Read_DeviceSensor_ByT_sn(Sn, Id)
- if !is {
- c.Data["json"] = lib.JSONS{Code: 201, Msg: "信息错误!"}
- c.ServeJSON()
- return
- }
- DeviceSensor.T_3dview = T_3dview
- //c.Data["Device_lite"] = Device.Read_DeviceParameter_SN(Sn)
- Device.Update_DeviceSensor(DeviceSensor, "T_3dview")
- System.Add_UserLogs_T(admin_r.Admin_uuid, "设备管理", "3D 视图ID操作", "SN:"+Sn+" ["+strconv.Itoa(Id)+"]"+T_3dview)
- 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.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
- c.ServeJSON()
- 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.Id != 1 {
- c.Data["json"] = lib.JSONS{Code: 202, 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: 202, 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_JSONS struct {
- //必须的大写开头
- Device_lite []Device.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")
- T_online := c.GetString("T_online")
- //
- //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, "", T_online)
- for _, v := range Device_lite {
- r_Device := Device.R_Device{}
- 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_protocol = v.T_protocol
- r_Device.T_sensor_list, r_Device.T_sensor = Device.Read_DeviceSensor_ByTsn(v.T_sn)
- 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) Device_v2_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 {
- //必须的大写开头
- Device_lite []Device.R2_Device
- Num int64
- Page int
- Page_size int
- }
- var r_jsons R_JSONS
- page, _ := c.GetInt("page")
- println(page)
- if page < 1 {
- page = 1
- }
- page_z, _ := c.GetInt("page_z")
- if page_z < 1 {
- page_z = conf.Page_size
- }
- if len(c.GetString("User_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
- }
- Name := c.GetString("T_name")
- T_online := c.GetString("T_online")
- T_monitor := c.GetString("T_monitor")
- r_jsons.Device_lite, r_jsons.Num = Device.Read_Device_v2_List(admin_r, Name, T_monitor, T_online, page, page_z)
- r_jsons.Page = page
- r_jsons.Page_size = int(math.Ceil(float64(r_jsons.Num) / float64(page_z)))
- 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_R
- 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")
- if page_z == 0 {
- page_z = conf.Page_size
- }
- 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_sn(T_sn, page, page_z)
- page_size := math.Ceil(float64(cnt) / float64(page_z))
- 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
- ////}
- NatsServer.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
- ////}
- NatsServer.Read_DeviceSensorParameter(T_SN)
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
- c.ServeJSON()
- return
- }
- func (c *DeviceController) Read_v2_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("T_sn")
- NatsServer.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_Device_Parameter_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)
- NatsServer.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) Device_v2_Parameter_Pu() {
- // 验证登录
- 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_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_Device_Parameter_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)
- NatsServer.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) Device_Edit() {
- // 验证登录
- 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")
- 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
- }
- // 0:默认 1:物流 2:药店 (内部运维)
- if v, err := c.GetInt("T_l_p"); err == nil {
- if admin_r.Admin_power <= 6 { // 内部运维以上
- Device_r.T_l_p = v
- Device.Update_Device(Device_r, "T_l_p")
- Device.DeviceSensor_T_l_p_ALL(T_SN, v)
- System.Add_UserLogs(admin_r.Admin_uuid, "设备管理", "设备参数操作", "类型选择(1物流端 2药店端):"+string(v))
- }
- }
- // 1:开启设备 0:放弃设备 (内部运维)
- if v, err := c.GetInt("T_give"); err == nil {
- if admin_r.Admin_power <= 6 { // 内部运维以上
- Device_r.T_give = v
- Device.Update_Device(Device_r, "T_give")
- Device.DeviceSensor_t_give_ALL(T_SN, v)
- System.Add_UserLogs(admin_r.Admin_uuid, "设备管理", "设备丢弃参数操作", "设备丢弃( 0 丢弃 1 正常):"+string(v))
- }
- }
- 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_Parameter_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)
- NatsServer.Pu_DeviceParameter_Sensor(Devicesensorparameter)
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
- c.ServeJSON()
- return
- }
- func (c *DeviceController) DeviceSensor_v2_Parameter_Pu() {
- // 验证登录
- 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_Parameter_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)
- NatsServer.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) V2_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 {
- //必须的大写开头
- Data []Device.DeviceWarning
- Num int64
- Page int
- Page_size int
- }
- var r_jsons R_JSONS
- page, _ := c.GetInt("page")
- println(page)
- if page < 1 {
- page = 1
- }
- page_z, _ := c.GetInt("page_z")
- if page_z < 1 {
- page_z = conf.Page_size
- }
- T_sn := c.GetString("T_sn")
- T_id := c.GetString("T_id")
- T_title := c.GetString("T_title")
- 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
- //}
- r_jsons.Data, r_jsons.Num = Device.Read_DeviceWarning(admin_r, T_sn, T_id, T_title, Time_start, Time_end, page, page_z)
- r_jsons.Page = page
- r_jsons.Page_size = int(math.Ceil(float64(r_jsons.Num) / float64(page_z)))
- 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 := NatsServer.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) V2_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")
- T_sn := c.GetString("T_sn")
- T_id := c.GetString("T_id")
- T_title := c.GetString("T_title")
- Time_start := c.GetString("Time_start")
- Time_end := c.GetString("Time_end")
- Device_data, _ := Device.Read_DeviceWarning(admin_r, T_sn, T_id, T_title, Time_start, Time_end, 0, 9999)
- 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 := NatsServer.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_log() {
- id, _ := c.GetInt("id")
- T_Log := Device.Read_DeviceWarning_ById(id).T_Log
- T_Log = strings.Replace(T_Log, "\n", "<hr>", -1)
- c.Data["T_Log"] = T_Log
- c.TplName = "Device/DeviceWarning-log.html"
- }
- func (c *DeviceController) V2_DeviceWarning_Get() {
- // 验证登录
- 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
- }
- id, _ := c.GetInt("T_id")
- T := Device.Read_DeviceWarning_ById(id)
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: Device.DeviceWarningToDeviceWarning_R(T)}
- c.ServeJSON()
- return
- }
- 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) V2_DeviceWarning_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
- }
- Id, _ := c.GetInt("T_id")
- T_Text := c.GetString("T_Text")
- T := Device.Read_DeviceWarning_ById(Id)
- if T.Id == 0 {
- c.Data["json"] = lib.JSONS{Code: 206, Msg: "T_id Err!"}
- c.ServeJSON()
- return
- }
- T.T_Text = T_Text
- T.T_State = 2
- Device.Update_DeviceWarning(T, "T_Text", "T_State")
- 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) V2_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("T_id")
- T := Device.Read_DeviceWarning_ById(Id)
- if T.Id == 0 {
- c.Data["json"] = lib.JSONS{Code: 206, Msg: "T_id Err!"}
- c.ServeJSON()
- return
- }
- T.T_State = 0
- Device.Update_DeviceWarning(T, "T_State")
- 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")
- T_online := c.GetString("T_online")
- //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, T_online)
- 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_JSONS struct {
- //必须的大写开头
- Device_lite []Device.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
- }
- 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")
- T_online := c.GetString("T_online")
- //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, T_online)
- for _, v := range Device_lite {
- r_Device := Device.R_Device{}
- 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_protocol = v.T_protocol
- r_Device.T_sensor_list, r_Device.T_sensor = Device.Read_DeviceSensor_ByTsn(v.T_sn)
- 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) V2_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("T_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) V2_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("T_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) V2_Class_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 {
- //必须的大写开头
- Data []Device.DeviceClass
- Num int64
- Page int
- Page_size int
- }
- var r_jsons R_JSONS
- page, _ := c.GetInt("page")
- println(page)
- if page < 1 {
- page = 1
- }
- page_z, _ := c.GetInt("page_z")
- if page_z < 1 {
- page_z = conf.Page_size
- }
- Name := c.GetString("T_name")
- r_jsons.Data, r_jsons.Num = Device.Read_DeviceClass_ALL_1(admin_r.Admin_uuid, page, Name)
- r_jsons.Page = page
- r_jsons.Page_size = int(math.Ceil(float64(r_jsons.Num) / float64(page_z)))
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
- c.ServeJSON()
- return
- }
- func (c *DeviceController) DeviceClass_() {
- // 验证登录
- 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")
- c.Data["T"], _ = Device.Read_Class_ById(id)
- c.Data["id"] = id
- c.Data["Admin_r"] = admin_r
- c.TplName = "Device/DeviceClass-.html"
- }
- func (c *DeviceController) V2_Class_Get() {
- // 验证登录
- 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("T_id")
- T, err := Device.Read_Class_ById(id)
- if err != nil {
- c.Data["json"] = lib.JSONS{Code: 203, Msg: "T_id Err!"}
- c.ServeJSON()
- return
- }
- if admin_r.Admin_uuid != T.T_uuid {
- c.Data["json"] = lib.JSONS{Code: 204, Msg: "没有权限!"}
- c.ServeJSON()
- return
- }
- type DeviceClass_R struct {
- T_name string // 分类
- T_Notice_wx string //w微信公众号 appid/名字|
- T_Notice_wx2 string //w微信公众号 appid/名字|
- T_Notice_phone string //p手机 1111111|
- T_Notice_message string //m短信 1111111|
- T_Notice_mailbox string //e邮箱 1111111|
- T_Notice_mechanism string // 报警机制
- // 湿度超下限预警,处理,w启用,数量,上限,~|
- // 湿度超下限预警,0,0,0,0,0,0,0,0,0,0,0,0|
- T_QRCode string // 微信二维码
- T_QRCode2 string // 微信二维码(冷链)
- }
- var r_jsons DeviceClass_R
- r_jsons.T_name = T.T_name
- r_jsons.T_Notice_wx = T.T_Notice_wx
- r_jsons.T_Notice_wx2 = T.T_Notice_wx2
- r_jsons.T_Notice_phone = T.T_Notice_phone
- r_jsons.T_Notice_message = T.T_Notice_message
- r_jsons.T_Notice_mailbox = T.T_Notice_mailbox
- r_jsons.T_Notice_mechanism = T.T_Notice_mechanism
- T_calss_id_str, _ := NatsServer.Wx_GenerateQRCode("-|" + lib.AesEncryptCBC(strconv.Itoa(T.Id), "0123456789012345") + "|- @宝智达 微信公众号通知")
- if len(T_calss_id_str) > 0 {
- r_jsons.T_QRCode = "https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=" + T_calss_id_str
- }
- T_calss_id_str, _ = NatsServer.Wx_GenerateQRCode2("-|" + lib.AesEncryptCBC(strconv.Itoa(T.Id), "0123456789012345") + "|- @宝智达 微信公众号通知")
- if len(T_calss_id_str) > 0 {
- r_jsons.T_QRCode2 = "https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=" + T_calss_id_str
- }
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
- c.ServeJSON()
- return
- }
- 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 {
- t_c.T_uuid = admin_r.Admin_uuid
- 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) V2_Class_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_name := c.GetString("T_name")
- t_c := Device.DeviceClass{
- T_uuid: admin_r.Admin_uuid,
- T_name: T_name,
- T_Notice_mechanism: Device.Read_DeviceWarningList_All_T_Notice_mechanism(),
- T_State: 1,
- }
- Device.Add_Class(t_c)
- System.Add_UserLogs_T(admin_r.Admin_uuid, "分类管理", "分类添加", t_c)
- // 同步分类
- DataList, _ := Admin.Read_v2_Admin_List(admin_r.Id, "", 0, 9999)
- for _, v := range DataList {
- V2_Class_Syn(admin_r, v)
- }
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
- c.ServeJSON()
- return
- }
- func (c *DeviceController) V2_Class_Edit() {
- // 验证登录
- 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("T_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")
- R_DeviceClass, err := Device.Read_Class_ById(Id)
- if err != nil {
- c.Data["json"] = lib.JSONS{Code: 203, Msg: "T_id Err!"}
- c.ServeJSON()
- return
- }
- if R_DeviceClass.T_uuid != admin_r.Admin_uuid {
- c.Data["json"] = lib.JSONS{Code: 203, Msg: "T_id Err!"}
- c.ServeJSON()
- return
- }
- R_DeviceClass.Id = Id
- R_DeviceClass.T_name = T_name
- R_DeviceClass.T_Notice_wx = T_Notice_wx
- R_DeviceClass.T_Notice_wx2 = T_Notice_wx2
- R_DeviceClass.T_Notice_phone = T_Notice_phone
- R_DeviceClass.T_Notice_message = T_Notice_message
- R_DeviceClass.T_Notice_mailbox = T_Notice_mailbox
- R_DeviceClass.T_Notice_mechanism = T_Notice_mechanism
- Device.Update_Class(R_DeviceClass, "T_name", "T_Notice_wx", "T_Notice_wx2", "T_Notice_phone", "T_Notice_message", "T_Notice_mailbox", "T_Notice_mechanism")
- System.Add_UserLogs_T(admin_r.Admin_uuid, "设备管理", "分类操作", R_DeviceClass)
- // 同步分类
- DataList, _ := Admin.Read_v2_Admin_List(admin_r.Id, "", 0, 9999)
- for _, v := range DataList {
- V2_Class_Syn(admin_r, v)
- }
- 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) V2_Class_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("T_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))
- // 同步分类
- DataList, _ := Admin.Read_v2_Admin_List(admin_r.Id, "", 0, 9999)
- for _, v := range DataList {
- V2_Class_Syn(admin_r, v)
- }
- 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 V2_Class_Syn(admin_r Admin.Admin, user_r Admin.Admin) {
- //验证登录
- //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("T_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 {
- 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)
- 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_R
- 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) DeviceSensor_v2_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 {
- //必须的大写开头
- Data []Device.DeviceSensor_R
- Num int64
- Page int
- Page_size int
- }
- var r_jsons R_JSONS
- page, _ := c.GetInt("page")
- println(page)
- if page < 1 {
- page = 1
- }
- page_z, _ := c.GetInt("page_z")
- if page_z < 1 {
- page_z = conf.Page_size
- }
- T_sn := c.GetString("T_sn")
- Name := c.GetString("T_name") // 包含 T_name、T_sn
- T_calss_id, _ := c.GetInt("T_calssid")
- if T_calss_id > 0 {
- 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
- }
- }
- r_jsons.Data, r_jsons.Num = Device.Read_DeviceSensor_v2_List(admin_r, T_sn, Name, T_calss_id, page, page_z)
- r_jsons.Page = page
- r_jsons.Page_size = int(math.Ceil(float64(r_jsons.Num) / float64(page_z)))
- 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) V2_ClassBind_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))
- // 同步分类
- DataList, _ := Admin.Read_v2_Admin_List(admin_r.Id, "", 0, 9999)
- for _, v := range DataList {
- V2_Class_Syn(admin_r, v)
- }
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
- c.ServeJSON()
- return
- }
- func (c *DeviceController) V2_ClassBind_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")
- NatsServer.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, _ := NatsServer.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) Get_DeviceClassId_QRCode2() {
- // 验证登录
- 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, _ := NatsServer.Wx_GenerateQRCode2("-|" + 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) DeviceData_Add() {
- // 验证登录
- if c.GetString("Tokey") != "1f9db553" {
- c.Data["json"] = lib.JSONS{Code: 201, Msg: "Tokey Err!"}
- c.ServeJSON()
- return
- }
- T_sn := c.GetString("T_sn")
- T_name := c.GetString("T_name")
- T_id, _ := c.GetInt("T_id")
- T_t, _ := c.GetFloat("T_t")
- T_rh, _ := c.GetFloat("T_rh")
- 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_Site := c.GetString("T_Site")
- T_Dattery, _ := c.GetInt("T_Dattery")
- T_time, err := time.Parse("2006-01-02 15:04:05", c.GetString("T_time"))
- if err != nil {
- c.Data["json"] = lib.JSONS{Code: 201, Msg: "T_time Err!"}
- c.ServeJSON()
- return
- }
- //// 更新记录 - 缓存
- DeviceData_t := Device.DeviceData_T{
- T_name: T_name,
- T_id: T_id,
- T_t: float32(T_t),
- T_rh: float32(T_rh),
- T_Tlower: float32(T_Tlower),
- T_Tupper: float32(T_Tupper),
- T_RHlower: float32(T_RHlower),
- T_RHupper: float32(T_RHupper),
- T_Site: T_Site,
- T_Dattery: T_Dattery,
- T_time: T_time,
- }
- if !Device.Add_DeviceData(T_sn, DeviceData_t) {
- c.Data["json"] = lib.JSONS{Code: 201, Msg: "Err!"}
- c.ServeJSON()
- return
- }
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
- 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"
- }
|