Device.go 91 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325
  1. package controllers
  2. import (
  3. "Cold_Api/Nats/NatsServer"
  4. "Cold_Api/conf"
  5. "Cold_Api/controllers/lib"
  6. "Cold_Api/models/Admin"
  7. "Cold_Api/models/Device"
  8. "Cold_Api/models/System"
  9. "fmt"
  10. beego "github.com/beego/beego/v2/server/web"
  11. "github.com/xuri/excelize/v2"
  12. "math"
  13. "strconv"
  14. "strings"
  15. "time"
  16. )
  17. //Handle
  18. type DeviceController struct {
  19. beego.Controller
  20. }
  21. // 列表 -
  22. func (c *DeviceController) Device_html() {
  23. // 验证登录
  24. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  25. if !b_ {
  26. c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  27. c.ServeJSON()
  28. return
  29. }
  30. c.Data["Admin_r"] = admin_r
  31. c.Data["Admin_Power"], _ = Admin.Read_AdminPower_ById(admin_r.Admin_power)
  32. var Device_lite_r []Device.R_Device
  33. page, _ := c.GetInt("page")
  34. println(page)
  35. if page < 1 {
  36. page = 1
  37. }
  38. page_z := 4
  39. Class_1 := c.GetString("Class_1")
  40. Name := c.GetString("Name")
  41. T_sn := c.GetString("T_sn")
  42. c.Data["Class_1"] = Class_1
  43. c.Data["Name"] = Name
  44. c.Data["T_sn"] = T_sn
  45. var cnt int64
  46. Device_lite, cnt := Device.Read_Device_ALL_bind_1(admin_r, page, page_z, T_sn, Name, Class_1, "", "")
  47. for _, v := range Device_lite {
  48. r_Device := Device.R_Device{}
  49. r_Device.T_sn = v.T_sn
  50. r_Device.T_MSISDN = v.T_MSISDN
  51. r_Device.T_devName = v.T_devName
  52. r_Device.T_give = v.T_give
  53. r_Device.T_online = v.T_online
  54. r_Device.T_online_4g = v.T_online_4g
  55. r_Device.T_monitor = v.T_monitor
  56. r_Device.T_Dattery = v.T_Dattery
  57. r_Device.T_protocol = v.T_protocol
  58. r_Device.T_sensor_list, r_Device.T_sensor = Device.Read_DeviceSensor_ByTsn(v.T_sn)
  59. Device_lite_r = append(Device_lite_r, r_Device)
  60. }
  61. c.Data["Device_lite"] = Device_lite_r
  62. page_size := math.Ceil(float64(cnt) / float64(page_z))
  63. c.Data["Page"] = page
  64. c.Data["Page_size"] = page_size
  65. c.Data["Pages"] = lib.Func_page(int64(page), int64(page_size))
  66. c.Data["cnt"] = cnt
  67. c.TplName = "Device/Device.html"
  68. }
  69. func (c *DeviceController) Device_() {
  70. id, _ := c.GetInt("id")
  71. c.Data["id"] = id
  72. if id > 0 {
  73. c.Data["Date"] = Device.Read_Device_ById(id)
  74. //c.Data["FormulaList"] = Formula.ReadFormulaListByid_List(id)
  75. }
  76. c.Data["DeviceSnOld_List"] = Device.Read_DeviceSnOld_1()
  77. c.TplName = "Device/Device-.html"
  78. }
  79. func (c *DeviceController) Device_Parameter_html() {
  80. // 验证登录
  81. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  82. if !b_ {
  83. c.Ctx.Redirect(302, "Login")
  84. return
  85. }
  86. c.Data["Admin_Power"], _ = Admin.Read_AdminPower_ById(admin_r.Admin_power)
  87. c.Data["Admin"] = admin_r
  88. Sn := c.GetString("Sn")
  89. DeviceParameter_lite := Device.Read_DeviceParameter_SN(Sn)
  90. if len(DeviceParameter_lite) > 0 {
  91. c.Data["DeviceParameter"] = DeviceParameter_lite[0]
  92. } else {
  93. NatsServer.Read_DeviceParameter(Sn)
  94. }
  95. c.Data["DeviceParameter_lite_z"] = len(DeviceParameter_lite)
  96. c.Data["DeviceParameter_lite_SendState_z"] = len(Device.Read_DeviceParameter_SN_T_SendState_0(Sn))
  97. DeviceParameter_lite_s_1 := Device.Read_DeviceParameter_SN_T_State_1(Sn)
  98. c.Data["DeviceParameter_lite"] = DeviceParameter_lite_s_1
  99. c.Data["Device"], _ = Device.Read_Device_ByT_sn(Sn)
  100. c.TplName = "Device/Device_Parameter-.html"
  101. }
  102. func (c *DeviceController) Device_v2_Parameter_List() {
  103. // 验证登录
  104. b_, _ := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  105. if !b_ {
  106. c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  107. c.ServeJSON()
  108. return
  109. }
  110. Sn := c.GetString("T_sn")
  111. DeviceParameter_lite := Device.Read_DeviceParameter_SN_List(Sn)
  112. if len(DeviceParameter_lite) == 0 {
  113. NatsServer.Read_DeviceParameter(Sn)
  114. c.Data["json"] = lib.JSONS{Code: 203, Msg: "未同步参数,请检查设备是否正常!"}
  115. c.ServeJSON()
  116. return
  117. }
  118. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: DeviceParameter_lite}
  119. c.ServeJSON()
  120. return
  121. }
  122. func (c *DeviceController) DeviceSensor_List_html() {
  123. // 验证登录
  124. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  125. if !b_ {
  126. c.Ctx.Redirect(302, "Login")
  127. return
  128. }
  129. c.Data["Admin_Power"], _ = Admin.Read_AdminPower_ById(admin_r.Admin_power)
  130. Sn := c.GetString("Sn")
  131. Id, _ := c.GetInt("Id")
  132. //
  133. //c.Data["Device_lite"] = Device.Read_DeviceParameter_SN(Sn)
  134. c.Data["DeviceSensor"], _ = Device.Read_DeviceSensor_ByTsn_Tid(Sn, Id)
  135. DeviceSensorParameter_list := Device.Read_DeviceSensorParameter_SN_T_id(Sn, Id)
  136. c.Data["DeviceSensorParameter_lite"] = DeviceSensorParameter_list
  137. c.Data["DeviceSensorParameter_T_SendState_0"] = 0
  138. if len(DeviceSensorParameter_list) > 0 {
  139. if DeviceSensorParameter_list[0].T_SendState == 0 {
  140. c.Data["DeviceSensorParameter_T_SendState_0"] = 1
  141. }
  142. }
  143. c.Data["Device"], _ = Device.Read_Device_ByT_sn(Sn)
  144. c.TplName = "Device/Device_Sensor-.html"
  145. }
  146. func (c *DeviceController) DeviceSensor_v2_Parameter_List() {
  147. // 验证登录
  148. b_, _ := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  149. if !b_ {
  150. c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  151. c.ServeJSON()
  152. return
  153. }
  154. Sn := c.GetString("T_sn")
  155. Id, _ := c.GetInt("T_id")
  156. //c.Data["DeviceSensor"], _ = Device.Read_DeviceSensor_ByTsn_Tid(Sn, Id)
  157. DeviceSensorParameter_lite := Device.Read_DeviceSensorParameter_List(Sn, Id)
  158. if len(DeviceSensorParameter_lite) == 0 {
  159. NatsServer.Read_DeviceSensorParameter(Sn)
  160. c.Data["json"] = lib.JSONS{Code: 203, Msg: "未同步参数,请检查设备是否正常!"}
  161. c.ServeJSON()
  162. return
  163. }
  164. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: DeviceSensorParameter_lite}
  165. c.ServeJSON()
  166. return
  167. }
  168. func (c *DeviceController) Device_Parameter_Del_Device() {
  169. // 验证登录
  170. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  171. if !b_ {
  172. c.Ctx.Redirect(302, "Login")
  173. return
  174. }
  175. Sn := c.GetString("Sn")
  176. Id, _ := c.GetInt("Id")
  177. System.Add_UserLogs_T(admin_r.Admin_uuid, "设备管理", "传感器 删除操作", "SN:"+Sn+" ["+strconv.Itoa(Id)+"]")
  178. //c.Data["Device_lite"] = Device.Read_DeviceParameter_SN(Sn)
  179. Device.Delete_DeviceSensor_ById(Sn, Id)
  180. NatsServer.Del_DeviceSensor(Device.DeviceSensor_Del{
  181. T_sn: Sn, T_id: Id,
  182. })
  183. c.Data["json"] = lib.JSONS{Code: 200, Msg: "OK"}
  184. c.ServeJSON()
  185. return
  186. }
  187. func (c *DeviceController) Device_Parameter_Del() {
  188. // 验证登录
  189. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  190. if !b_ {
  191. c.Ctx.Redirect(302, "Login")
  192. return
  193. }
  194. Sn := c.GetString("Sn")
  195. Id, _ := c.GetInt("Id")
  196. System.Add_UserLogs_T(admin_r.Admin_uuid, "设备管理", "传感器 删除操作", "SN:"+Sn+" ["+strconv.Itoa(Id)+"]")
  197. //c.Data["Device_lite"] = Device.Read_DeviceParameter_SN(Sn)
  198. Device.Delete_DeviceSensor_ById(Sn, Id)
  199. c.Data["json"] = lib.JSONS{Code: 200, Msg: "OK"}
  200. c.ServeJSON()
  201. return
  202. }
  203. func (c *DeviceController) DeviceSensor_Del() {
  204. // 验证登录
  205. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  206. if !b_ {
  207. c.Ctx.Redirect(302, "Login")
  208. return
  209. }
  210. Sn := c.GetString("T_sn")
  211. Id, _ := c.GetInt("T_id")
  212. if admin_r.Admin_power > 6 {
  213. c.Data["json"] = lib.JSONS{Code: 204, Msg: "没有权限!"}
  214. c.ServeJSON()
  215. return
  216. }
  217. _, is := Device.Read_DeviceSensor_ByT_sn(Sn, Id)
  218. if !is {
  219. c.Data["json"] = lib.JSONS{Code: 205, Msg: "信息错误!"}
  220. c.ServeJSON()
  221. return
  222. }
  223. // 0默认:从数据库删除 1:从设备删除
  224. T_mode, _ := c.GetInt("T_mode")
  225. if T_mode == 1 {
  226. Device.Delete_DeviceSensor_ById(Sn, Id)
  227. NatsServer.Del_DeviceSensor(Device.DeviceSensor_Del{
  228. T_sn: Sn, T_id: Id,
  229. })
  230. System.Add_UserLogs_T(admin_r.Admin_uuid, "设备管理", "传感器 删除操作", "SN:"+Sn+" ["+strconv.Itoa(Id)+"]")
  231. } else {
  232. Device.Delete_DeviceSensor_ById(Sn, Id)
  233. System.Add_UserLogs_T(admin_r.Admin_uuid, "设备管理", "传感器 删除操作", "SN:"+Sn+" ["+strconv.Itoa(Id)+"]")
  234. }
  235. c.Data["json"] = lib.JSONS{Code: 200, Msg: "OK"}
  236. c.ServeJSON()
  237. return
  238. }
  239. func (c *DeviceController) UpDeviceSensor_Tsort() {
  240. // 验证登录
  241. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  242. if !b_ {
  243. c.Ctx.Redirect(302, "Login")
  244. return
  245. }
  246. Sn := c.GetString("Sn")
  247. Id, _ := c.GetInt("Id")
  248. T_sort, _ := c.GetInt("T_sort")
  249. DeviceSensor, is := Device.Read_DeviceSensor_ByT_sn(Sn, Id)
  250. if !is {
  251. c.Data["json"] = lib.JSONS{Code: 201, Msg: "信息错误!"}
  252. c.ServeJSON()
  253. return
  254. }
  255. DeviceSensor.T_sort = T_sort
  256. //c.Data["Device_lite"] = Device.Read_DeviceParameter_SN(Sn)
  257. Device.Update_DeviceSensor(DeviceSensor, "T_sort")
  258. System.Add_UserLogs_T(admin_r.Admin_uuid, "设备管理", "传感器 排序操作", "SN:"+Sn+" ["+strconv.Itoa(Id)+"]"+strconv.Itoa(T_sort))
  259. c.Data["json"] = lib.JSONS{Code: 200, Msg: "OK"}
  260. c.ServeJSON()
  261. return
  262. }
  263. func (c *DeviceController) DeviceSensor_Edit() {
  264. // 验证登录
  265. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  266. if !b_ {
  267. c.Ctx.Redirect(302, "Login")
  268. return
  269. }
  270. Sn := c.GetString("T_sn")
  271. Id, _ := c.GetInt("T_id")
  272. DeviceSensor, is := Device.Read_DeviceSensor_ByT_sn(Sn, Id)
  273. if !is {
  274. c.Data["json"] = lib.JSONS{Code: 201, Msg: "信息错误!"}
  275. c.ServeJSON()
  276. return
  277. }
  278. // 实时数据显示排序
  279. if v, err := c.GetInt("T_sort"); err == nil {
  280. DeviceSensor.T_sort = v
  281. Device.Update_DeviceSensor(DeviceSensor, "T_sort")
  282. System.Add_UserLogs_T(admin_r.Admin_uuid, "设备管理", "传感器 排序操作", "SN:"+Sn+" ["+strconv.Itoa(Id)+"]"+strconv.Itoa(v))
  283. }
  284. // 屏蔽数据展示 0:屏蔽数据展示 1:正常数据展示
  285. if v, err := c.GetInt("T_datashow"); err == nil {
  286. DeviceSensor.T_datashow = v
  287. Device.Update_DeviceSensor(DeviceSensor, "T_datashow")
  288. System.Add_UserLogs_T(admin_r.Admin_uuid, "设备管理", "传感器 数据展示(0 屏蔽数据展示 1 正常数据展示)", "SN:"+Sn+" ["+strconv.Itoa(Id)+"]"+strconv.Itoa(v))
  289. }
  290. // 3D视图ID (内部运维)
  291. if v := c.GetString("T_3dview"); len(v) > 0 {
  292. if admin_r.Admin_power <= 6 { // 内部运维以上
  293. DeviceSensor.T_3dview = v
  294. Device.Update_DeviceSensor(DeviceSensor, "T_3dview")
  295. System.Add_UserLogs_T(admin_r.Admin_uuid, "设备管理", "3D 视图ID操作", "SN:"+Sn+" ["+strconv.Itoa(Id)+"]"+v)
  296. }
  297. }
  298. c.Data["json"] = lib.JSONS{Code: 200, Msg: "OK"}
  299. c.ServeJSON()
  300. return
  301. }
  302. func (c *DeviceController) UpDeviceSensor_T3dview() {
  303. // 验证登录
  304. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  305. if !b_ {
  306. c.Ctx.Redirect(302, "Login")
  307. return
  308. }
  309. Sn := c.GetString("Sn")
  310. Id, _ := c.GetInt("Id")
  311. T_3dview := c.GetString("T_3dview")
  312. DeviceSensor, is := Device.Read_DeviceSensor_ByT_sn(Sn, Id)
  313. if !is {
  314. c.Data["json"] = lib.JSONS{Code: 201, Msg: "信息错误!"}
  315. c.ServeJSON()
  316. return
  317. }
  318. DeviceSensor.T_3dview = T_3dview
  319. //c.Data["Device_lite"] = Device.Read_DeviceParameter_SN(Sn)
  320. Device.Update_DeviceSensor(DeviceSensor, "T_3dview")
  321. System.Add_UserLogs_T(admin_r.Admin_uuid, "设备管理", "3D 视图ID操作", "SN:"+Sn+" ["+strconv.Itoa(Id)+"]"+T_3dview)
  322. c.Data["json"] = lib.JSONS{Code: 200, Msg: "OK"}
  323. c.ServeJSON()
  324. return
  325. }
  326. func (c *DeviceController) UpDeviceSensor_T_datashow() {
  327. // 验证登录
  328. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  329. if !b_ {
  330. c.Ctx.Redirect(302, "Login")
  331. return
  332. }
  333. Sn := c.GetString("Sn")
  334. Id, _ := c.GetInt("Id")
  335. T_datashow, _ := c.GetInt("T_datashow")
  336. DeviceSensor, is := Device.Read_DeviceSensor_ByT_sn(Sn, Id)
  337. if !is {
  338. c.Data["json"] = lib.JSONS{Code: 201, Msg: "信息错误!"}
  339. c.ServeJSON()
  340. return
  341. }
  342. DeviceSensor.T_datashow = T_datashow
  343. Device.Update_DeviceSensor(DeviceSensor, "T_datashow")
  344. System.Add_UserLogs_T(admin_r.Admin_uuid, "设备管理", "传感器 数据展示(0 屏蔽数据展示 1 正常数据展示)", "SN:"+Sn+" ["+strconv.Itoa(Id)+"]"+strconv.Itoa(T_datashow))
  345. c.Data["json"] = lib.JSONS{Code: 200, Msg: "OK"}
  346. c.ServeJSON()
  347. return
  348. }
  349. func (c *DeviceController) Device_Post() {
  350. /// 验证登录
  351. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  352. if !b_ {
  353. c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  354. c.ServeJSON()
  355. return
  356. }
  357. var err error
  358. T_sn := c.GetString("T_sn")
  359. T_MSISDN := c.GetString("T_MSISDN")
  360. var_ := Device.Device{
  361. T_sn: T_sn,
  362. T_MSISDN: T_MSISDN,
  363. T_Bind: "U" + strconv.Itoa(admin_r.Id) + "|",
  364. T_l_p: 0,
  365. T_give: 1,
  366. T_monitor: 1,
  367. T_State: 1,
  368. }
  369. if len(T_sn) < 8 {
  370. c.Data["json"] = lib.JSONS{Code: 303, Msg: "SN 太短 必须8个字符以上"}
  371. c.ServeJSON()
  372. return
  373. }
  374. if !(strings.Contains(T_sn, "KF") || strings.Contains(T_sn, "YD")) {
  375. c.Data["json"] = lib.JSONS{Code: 303, Msg: "必须包含 KF或YD!"}
  376. c.ServeJSON()
  377. return
  378. }
  379. _, err = Device.Read_Device_ByT_sn(T_sn)
  380. if err == nil {
  381. c.Data["json"] = lib.JSONS{Code: 303, Msg: "重复SN!"}
  382. c.ServeJSON()
  383. return
  384. }
  385. var_.T_devName = "等待设备上线.."
  386. // 创建数据库
  387. if !Device.CREATE_DeviceData(T_sn) {
  388. c.Data["json"] = lib.JSONS{Code: 302, Msg: "添加失败!"}
  389. c.ServeJSON()
  390. return
  391. }
  392. _, err = Device.Add_Device(var_)
  393. if err != nil {
  394. c.Data["json"] = lib.JSONS{Code: 301, Msg: "添加失败!"}
  395. c.ServeJSON()
  396. return
  397. }
  398. System.Add_UserLogs_T(admin_r.Admin_uuid, "设备管理", "设备添加", var_)
  399. //MqttServer.Get_Device_Realtime(T_sn) // 更新传感器 !!!
  400. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  401. c.ServeJSON()
  402. return
  403. }
  404. func (c *DeviceController) Device_Del() {
  405. // 验证登录
  406. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  407. if !b_ {
  408. c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  409. c.ServeJSON()
  410. return
  411. }
  412. if admin_r.Id != 1 {
  413. c.Data["json"] = lib.JSONS{Code: 202, Msg: "没有权限!"}
  414. c.ServeJSON()
  415. return
  416. }
  417. T_sn := c.GetString("T_sn")
  418. Device_r, err := Device.Read_Device_ByT_sn(T_sn)
  419. if err != nil {
  420. c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_sn Err!"}
  421. c.ServeJSON()
  422. return
  423. }
  424. Device.Delete_Device(Device_r)
  425. DeviceSensor_list, _ := Device.Read_DeviceSensor_ByTsn(Device_r.T_sn)
  426. for _, v := range DeviceSensor_list {
  427. Device.Delete_DeviceSensor_ById(Device_r.T_sn, v.T_id)
  428. }
  429. Device.DELETE_DeviceSensor(Device_r.T_sn)
  430. Device.DELETE_DeviceDatar(Device_r.T_sn)
  431. Device.DELETE_DeviceParameter(Device_r.T_sn)
  432. Device.DELETE_DeviceSensorParameter(Device_r.T_sn)
  433. System.Add_UserLogs(admin_r.Admin_uuid, "设备管理", "设备删除", T_sn)
  434. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  435. c.ServeJSON()
  436. return
  437. }
  438. // 设备弃用
  439. func (c *DeviceController) Device_Give() {
  440. // 验证登录
  441. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  442. if !b_ {
  443. c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  444. c.ServeJSON()
  445. return
  446. }
  447. if admin_r.Admin_master != 1 {
  448. c.Data["json"] = lib.JSONS{Code: 201, Msg: "没有权限!"}
  449. c.ServeJSON()
  450. return
  451. }
  452. T_sn := c.GetString("T_sn")
  453. Device_r, err := Device.Read_Device_ByT_sn(T_sn)
  454. if err != nil {
  455. c.Data["json"] = lib.JSONS{Code: 201, Msg: "T_sn Err!"}
  456. c.ServeJSON()
  457. return
  458. }
  459. if Device_r.T_give == 0 {
  460. Device_r.T_give = 1
  461. System.Add_UserLogs(admin_r.Admin_uuid, "设备管理", "设备开启", T_sn)
  462. } else {
  463. Device_r.T_give = 0
  464. System.Add_UserLogs(admin_r.Admin_uuid, "设备管理", "设备弃用", T_sn)
  465. }
  466. Device.Update_Device(Device_r, "T_give")
  467. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  468. c.ServeJSON()
  469. return
  470. }
  471. //-------------------------------
  472. func (c *DeviceController) Device_List() {
  473. // 验证登录
  474. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  475. if !b_ {
  476. c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  477. c.ServeJSON()
  478. return
  479. }
  480. type R_JSONS struct {
  481. //必须的大写开头
  482. Device_lite []Device.R_Device
  483. Num int
  484. Page int
  485. Page_size int
  486. Pages []lib.Page_T
  487. }
  488. var r_jsons R_JSONS
  489. page, _ := c.GetInt("page")
  490. println(page)
  491. if page < 1 {
  492. page = 1
  493. }
  494. Class_1 := c.GetString("Class_1")
  495. Name := c.GetString("Name")
  496. T_sn := c.GetString("T_sn")
  497. T_online := c.GetString("T_online")
  498. //
  499. //c.Data["Class_1"] = Class_1
  500. //c.Data["T_sn"] = T_sn
  501. //c.Data["Class_List"] = Device.Read_Class_All_1()
  502. Device_r, err := Device.Read_Device_ByT_sn(T_sn)
  503. if err != nil {
  504. c.Data["json"] = lib.JSONS{Code: 206, Msg: "T_sn Err!"}
  505. c.ServeJSON()
  506. return
  507. }
  508. if !strings.Contains(Device_r.T_Bind, "U"+strconv.Itoa(admin_r.Id)+"|") && admin_r.Admin_master != 0 {
  509. c.Data["json"] = lib.JSONS{Code: 202, Msg: "! U" + strconv.Itoa(admin_r.Id)}
  510. c.ServeJSON()
  511. return
  512. }
  513. var cnt int64
  514. Device_lite, cnt := Device.Read_Device_ALL_bind_1(admin_r, page, 0, T_sn, Name, Class_1, "", T_online)
  515. for _, v := range Device_lite {
  516. r_Device := Device.R_Device{}
  517. r_Device.T_sn = v.T_sn
  518. r_Device.T_MSISDN = v.T_MSISDN
  519. r_Device.T_devName = v.T_devName
  520. r_Device.T_give = v.T_give
  521. r_Device.T_online = v.T_online
  522. r_Device.T_monitor = v.T_monitor
  523. r_Device.T_Dattery = v.T_Dattery
  524. r_Device.T_protocol = v.T_protocol
  525. r_Device.T_sensor_list, r_Device.T_sensor = Device.Read_DeviceSensor_ByTsn(v.T_sn)
  526. r_jsons.Device_lite = append(r_jsons.Device_lite, r_Device)
  527. }
  528. page_size := math.Ceil(float64(cnt) / float64(conf.Page_size))
  529. r_jsons.Page = int(page)
  530. r_jsons.Page_size = int(page_size)
  531. r_jsons.Pages = lib.Func_page(int64(page), int64(page_size))
  532. r_jsons.Num = int(cnt)
  533. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
  534. c.ServeJSON()
  535. return
  536. }
  537. func (c *DeviceController) Device_v2_List() {
  538. // 验证登录
  539. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  540. if !b_ {
  541. c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  542. c.ServeJSON()
  543. return
  544. }
  545. type R_JSONS struct {
  546. //必须的大写开头
  547. Device_lite []Device.R2_Device
  548. Num int64
  549. Page int
  550. Page_size int
  551. }
  552. var r_jsons R_JSONS
  553. page, _ := c.GetInt("page")
  554. println(page)
  555. if page < 1 {
  556. page = 1
  557. }
  558. page_z, _ := c.GetInt("page_z")
  559. if page_z < 1 {
  560. page_z = conf.Page_size
  561. }
  562. if len(c.GetString("User_uuid")) > 1 {
  563. s_, user_r := Admin.Read_Admin_ByAdmin_uuid(c.GetString("Admin_uuid"))
  564. if s_ != nil {
  565. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Admin_uuid Err!"}
  566. c.ServeJSON()
  567. return
  568. }
  569. admin_r = user_r
  570. }
  571. Name := c.GetString("T_name")
  572. T_online := c.GetString("T_online")
  573. T_monitor := c.GetString("T_monitor")
  574. r_jsons.Device_lite, r_jsons.Num = Device.Read_Device_v2_List(admin_r, Name, T_monitor, T_online, page, page_z)
  575. r_jsons.Page = page
  576. r_jsons.Page_size = int(math.Ceil(float64(r_jsons.Num) / float64(page_z)))
  577. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
  578. c.ServeJSON()
  579. return
  580. }
  581. func (c *DeviceController) DeviceSensor_List() {
  582. // 验证登录
  583. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  584. if !b_ {
  585. c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  586. c.ServeJSON()
  587. return
  588. }
  589. type R_JSONS struct {
  590. //必须的大写开头
  591. DeviceSensor_lite []Device.DeviceSensor_R
  592. Num int
  593. Page int
  594. Page_size int
  595. Pages []lib.Page_T
  596. }
  597. var r_jsons R_JSONS
  598. page, _ := c.GetInt("page")
  599. println(page)
  600. if page < 1 {
  601. page = 1
  602. }
  603. page_z, _ := c.GetInt("page_z")
  604. if page_z == 0 {
  605. page_z = conf.Page_size
  606. }
  607. T_sn := c.GetString("Sn")
  608. Device_r, err := Device.Read_Device_ByT_sn(T_sn)
  609. if err != nil {
  610. c.Data["json"] = lib.JSONS{Code: 206, Msg: "T_sn Err!"}
  611. c.ServeJSON()
  612. return
  613. }
  614. if admin_r.Admin_master > 1 {
  615. if !strings.Contains(Device_r.T_Bind, "U"+strconv.Itoa(admin_r.Id)+"|") && admin_r.Admin_master != 0 {
  616. c.Data["json"] = lib.JSONS{Code: 202, Msg: "! U" + strconv.Itoa(admin_r.Id)}
  617. c.ServeJSON()
  618. return
  619. }
  620. }
  621. //c.Data["Class_List"] = Device.Read_Class_All_1()
  622. var cnt int64
  623. r_jsons.DeviceSensor_lite, cnt = Device.Read_DeviceSensor_ALL_T_sn(T_sn, page, page_z)
  624. page_size := math.Ceil(float64(cnt) / float64(page_z))
  625. r_jsons.Page = int(page)
  626. r_jsons.Page_size = int(page_size)
  627. r_jsons.Pages = lib.Func_page(int64(page), int64(page_size))
  628. r_jsons.Num = int(cnt)
  629. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
  630. c.ServeJSON()
  631. return
  632. }
  633. // ------------------------------------------
  634. func (c *DeviceController) Read_DeviceParameter() {
  635. // 验证登录
  636. b_, _ := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  637. if !b_ {
  638. c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  639. c.ServeJSON()
  640. return
  641. }
  642. T_SN := c.GetString("SN")
  643. //Device_r, err := Device.Read_Device_ByT_sn(T_SN)
  644. //if err != nil {
  645. // c.Data["json"] = lib.JSONS{Code: 206, Msg: "T_sn Err!"}
  646. // c.ServeJSON()
  647. // return
  648. //}
  649. ////if !strings.Contains(Device_r.T_Bind, "U"+strconv.Itoa(r_admin.Id)) {
  650. //// c.Data["json"] = lib.JSONS{Code: 202, Msg: "! U" + strconv.Itoa(r_admin.Id)}
  651. //// c.ServeJSON()
  652. //// return
  653. ////}
  654. NatsServer.Read_DeviceParameter(T_SN)
  655. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  656. c.ServeJSON()
  657. return
  658. }
  659. func (c *DeviceController) Read_DeviceSensorParameter() {
  660. // 验证登录
  661. b_, _ := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  662. if !b_ {
  663. c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  664. c.ServeJSON()
  665. return
  666. }
  667. T_SN := c.GetString("SN")
  668. //Device_r, err := Device.Read_Device_ByT_sn(T_SN)
  669. //if err != nil {
  670. // c.Data["json"] = lib.JSONS{Code: 206, Msg: "T_sn Err!"}
  671. // c.ServeJSON()
  672. // return
  673. //}
  674. ////if !strings.Contains(Device_r.T_Bind, "U"+strconv.Itoa(r_admin.Id)) {
  675. //// c.Data["json"] = lib.JSONS{Code: 202, Msg: "! U" + strconv.Itoa(r_admin.Id)}
  676. //// c.ServeJSON()
  677. //// return
  678. ////}
  679. NatsServer.Read_DeviceSensorParameter(T_SN)
  680. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  681. c.ServeJSON()
  682. return
  683. }
  684. func (c *DeviceController) Read_v2_DeviceSensorParameter() {
  685. // 验证登录
  686. b_, _ := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  687. if !b_ {
  688. c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  689. c.ServeJSON()
  690. return
  691. }
  692. T_SN := c.GetString("T_sn")
  693. NatsServer.Read_DeviceSensorParameter(T_SN)
  694. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  695. c.ServeJSON()
  696. return
  697. }
  698. //
  699. func (c *DeviceController) Pu_DeviceParameter() {
  700. // 验证登录
  701. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  702. if !b_ {
  703. c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  704. c.ServeJSON()
  705. return
  706. }
  707. T_SN := c.GetString("SN")
  708. T_devName := c.GetString("T_devName")
  709. T_saveTime, _ := c.GetInt("T_saveTime")
  710. T_overrunSave, _ := c.GetInt("T_overrunSave")
  711. T_overrunAlarm, _ := c.GetInt("T_overrunAlarm")
  712. T_outageAlarm, _ := c.GetInt("T_outageAlarm")
  713. T_warningDelay, _ := c.GetInt("T_warningDelay")
  714. T_lostAlarm, _ := c.GetInt("T_lostAlarm")
  715. T_batteryLimit, _ := c.GetInt("T_batteryLimit")
  716. T_warningTime, _ := c.GetInt("T_warningTime")
  717. T_tempPre, _ := c.GetFloat("T_tempPre")
  718. T_humPre, _ := c.GetFloat("T_humPre")
  719. T_enwarning, _ := c.GetInt("T_enwarning")
  720. T_decTotal, _ := c.GetInt("T_decTotal")
  721. T_chDecTotal := c.GetString("T_chDecTotal")
  722. T_company := c.GetString("T_company")
  723. T_btname := c.GetString("T_btname")
  724. T_btserverID, _ := c.GetInt("T_btserverID")
  725. T_btchar, _ := c.GetInt("T_btchar")
  726. Device_r, err := Device.Read_Device_ByT_sn(T_SN)
  727. if err != nil {
  728. c.Data["json"] = lib.JSONS{Code: 206, Msg: "T_sn Err!"}
  729. c.ServeJSON()
  730. return
  731. }
  732. Admin_Power_, _ := Admin.Read_AdminPower_ById(admin_r.Admin_power)
  733. if Admin_Power_.Power_Device_Parameter_e == 0 {
  734. c.Data["json"] = lib.JSONS{Code: 202, Msg: "! U" + strconv.Itoa(admin_r.Id)}
  735. c.ServeJSON()
  736. return
  737. }
  738. Deviceparameter := Device.DeviceParameter{
  739. T_uuid: admin_r.Admin_uuid,
  740. T_SendState: 0,
  741. T_State: 2,
  742. T_sn: T_SN,
  743. T_devName: T_devName,
  744. T_saveTime: T_saveTime,
  745. T_overrunSave: T_overrunSave,
  746. T_overrunAlarm: T_overrunAlarm,
  747. T_outageAlarm: T_outageAlarm,
  748. T_lostAlarm: T_lostAlarm,
  749. T_warningTime: T_warningTime,
  750. T_warningDelay: T_warningDelay,
  751. T_batteryLimit: T_batteryLimit,
  752. T_tempPre: float32(T_tempPre),
  753. T_humPre: float32(T_humPre),
  754. T_chDecTotal: T_chDecTotal,
  755. T_decTotal: strconv.Itoa(T_decTotal),
  756. T_enwarning: T_enwarning,
  757. T_company: T_company,
  758. T_btname: T_btname,
  759. T_btserverID: strconv.Itoa(T_btserverID),
  760. T_btchar: strconv.Itoa(T_btchar),
  761. }
  762. Deviceparameter, is := Device.Add_DeviceParameter(Deviceparameter)
  763. if !is {
  764. c.Data["json"] = lib.JSONS{Code: 203, Msg: "Add_DeviceParameter ERR"}
  765. c.ServeJSON()
  766. return
  767. }
  768. System.Add_UserLogs_T(admin_r.Admin_uuid, "设备管理", "设备参数操作", Deviceparameter)
  769. NatsServer.Pu_DeviceParameter(Deviceparameter)
  770. Device_r.T_devName = Deviceparameter.T_devName
  771. Device.Update_Device(Device_r, "T_devName")
  772. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  773. c.ServeJSON()
  774. return
  775. }
  776. //
  777. func (c *DeviceController) Device_v2_Parameter_Pu() {
  778. // 验证登录
  779. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  780. if !b_ {
  781. c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  782. c.ServeJSON()
  783. return
  784. }
  785. T_SN := c.GetString("T_sn")
  786. T_devName := c.GetString("T_devName")
  787. T_saveTime, _ := c.GetInt("T_saveTime")
  788. T_overrunSave, _ := c.GetInt("T_overrunSave")
  789. T_overrunAlarm, _ := c.GetInt("T_overrunAlarm")
  790. T_outageAlarm, _ := c.GetInt("T_outageAlarm")
  791. T_warningDelay, _ := c.GetInt("T_warningDelay")
  792. T_lostAlarm, _ := c.GetInt("T_lostAlarm")
  793. T_batteryLimit, _ := c.GetInt("T_batteryLimit")
  794. T_warningTime, _ := c.GetInt("T_warningTime")
  795. T_tempPre, _ := c.GetFloat("T_tempPre")
  796. T_humPre, _ := c.GetFloat("T_humPre")
  797. T_enwarning, _ := c.GetInt("T_enwarning")
  798. T_decTotal, _ := c.GetInt("T_decTotal")
  799. T_chDecTotal := c.GetString("T_chDecTotal")
  800. T_company := c.GetString("T_company")
  801. T_btname := c.GetString("T_btname")
  802. T_btserverID, _ := c.GetInt("T_btserverID")
  803. T_btchar, _ := c.GetInt("T_btchar")
  804. Device_r, err := Device.Read_Device_ByT_sn(T_SN)
  805. if err != nil {
  806. c.Data["json"] = lib.JSONS{Code: 206, Msg: "T_sn Err!"}
  807. c.ServeJSON()
  808. return
  809. }
  810. Admin_Power_, _ := Admin.Read_AdminPower_ById(admin_r.Admin_power)
  811. if Admin_Power_.Power_Device_Parameter_e == 0 {
  812. c.Data["json"] = lib.JSONS{Code: 202, Msg: "! U" + strconv.Itoa(admin_r.Id)}
  813. c.ServeJSON()
  814. return
  815. }
  816. Deviceparameter := Device.DeviceParameter{
  817. T_uuid: admin_r.Admin_uuid,
  818. T_SendState: 0,
  819. T_State: 2,
  820. T_sn: T_SN,
  821. T_devName: T_devName,
  822. T_saveTime: T_saveTime,
  823. T_overrunSave: T_overrunSave,
  824. T_overrunAlarm: T_overrunAlarm,
  825. T_outageAlarm: T_outageAlarm,
  826. T_lostAlarm: T_lostAlarm,
  827. T_warningTime: T_warningTime,
  828. T_warningDelay: T_warningDelay,
  829. T_batteryLimit: T_batteryLimit,
  830. T_tempPre: float32(T_tempPre),
  831. T_humPre: float32(T_humPre),
  832. T_chDecTotal: T_chDecTotal,
  833. T_decTotal: strconv.Itoa(T_decTotal),
  834. T_enwarning: T_enwarning,
  835. T_company: T_company,
  836. T_btname: T_btname,
  837. T_btserverID: strconv.Itoa(T_btserverID),
  838. T_btchar: strconv.Itoa(T_btchar),
  839. }
  840. Deviceparameter, is := Device.Add_DeviceParameter(Deviceparameter)
  841. if !is {
  842. c.Data["json"] = lib.JSONS{Code: 203, Msg: "Add_DeviceParameter ERR"}
  843. c.ServeJSON()
  844. return
  845. }
  846. System.Add_UserLogs_T(admin_r.Admin_uuid, "设备管理", "设备参数操作", Deviceparameter)
  847. NatsServer.Pu_DeviceParameter(Deviceparameter)
  848. Device_r.T_devName = Deviceparameter.T_devName
  849. Device.Update_Device(Device_r, "T_devName")
  850. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  851. c.ServeJSON()
  852. return
  853. }
  854. //
  855. func (c *DeviceController) Pu_DeviceParameter_T_l_p() {
  856. // 验证登录
  857. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  858. if !b_ {
  859. c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  860. c.ServeJSON()
  861. return
  862. }
  863. T_SN := c.GetString("SN")
  864. T_l_p, _ := c.GetInt("T_l_p")
  865. Device_r, err := Device.Read_Device_ByT_sn(T_SN)
  866. if err != nil {
  867. c.Data["json"] = lib.JSONS{Code: 206, Msg: "T_sn Err!"}
  868. c.ServeJSON()
  869. return
  870. }
  871. // // 1物流端 2药店端
  872. Device_r.T_l_p = T_l_p
  873. Device.Update_Device(Device_r, "T_l_p")
  874. Device.DeviceSensor_T_l_p_ALL(T_SN, T_l_p)
  875. System.Add_UserLogs(admin_r.Admin_uuid, "设备管理", "设备参数操作", "类型选择(1物流端 2药店端):"+string(T_l_p))
  876. c.Data["json"] = lib.JSONS{Code: 222, Msg: "ok!"}
  877. c.ServeJSON()
  878. return
  879. }
  880. //
  881. func (c *DeviceController) Device_Edit() {
  882. // 验证登录
  883. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  884. if !b_ {
  885. c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  886. c.ServeJSON()
  887. return
  888. }
  889. T_SN := c.GetString("T_sn")
  890. Device_r, err := Device.Read_Device_ByT_sn(T_SN)
  891. if err != nil {
  892. c.Data["json"] = lib.JSONS{Code: 206, Msg: "T_sn Err!"}
  893. c.ServeJSON()
  894. return
  895. }
  896. // 0:默认 1:物流 2:药店 (内部运维)
  897. if v, err := c.GetInt("T_l_p"); err == nil {
  898. if admin_r.Admin_power <= 6 { // 内部运维以上
  899. Device_r.T_l_p = v
  900. Device.Update_Device(Device_r, "T_l_p")
  901. Device.DeviceSensor_T_l_p_ALL(T_SN, v)
  902. System.Add_UserLogs(admin_r.Admin_uuid, "设备管理", "设备参数操作", "类型选择(1物流端 2药店端):"+string(v))
  903. }
  904. }
  905. // 1:开启设备 0:放弃设备 (内部运维)
  906. if v, err := c.GetInt("T_give"); err == nil {
  907. if admin_r.Admin_power <= 6 { // 内部运维以上
  908. Device_r.T_give = v
  909. Device.Update_Device(Device_r, "T_give")
  910. Device.DeviceSensor_t_give_ALL(T_SN, v)
  911. System.Add_UserLogs(admin_r.Admin_uuid, "设备管理", "设备丢弃参数操作", "设备丢弃( 0 丢弃 1 正常):"+string(v))
  912. }
  913. }
  914. c.Data["json"] = lib.JSONS{Code: 222, Msg: "ok!"}
  915. c.ServeJSON()
  916. return
  917. }
  918. //
  919. func (c *DeviceController) Pu_DeviceParameter_T_give() {
  920. // 验证登录
  921. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  922. if !b_ {
  923. c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  924. c.ServeJSON()
  925. return
  926. }
  927. T_SN := c.GetString("SN")
  928. T_give, _ := c.GetInt("T_give")
  929. Device_r, err := Device.Read_Device_ByT_sn(T_SN)
  930. if err != nil {
  931. c.Data["json"] = lib.JSONS{Code: 206, Msg: "T_sn Err!"}
  932. c.ServeJSON()
  933. return
  934. }
  935. // // 1物流端 2药店端
  936. Device_r.T_give = T_give
  937. Device.Update_Device(Device_r, "T_give")
  938. Device.DeviceSensor_t_give_ALL(T_SN, T_give)
  939. System.Add_UserLogs(admin_r.Admin_uuid, "设备管理", "设备丢弃参数操作", "设备丢弃( 0 丢弃 1 正常):"+string(T_give))
  940. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  941. c.ServeJSON()
  942. return
  943. }
  944. //
  945. //func (c *DeviceController) Pu_DeviceParameter_Sensor_() {
  946. // // 验证登录
  947. // b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  948. // if !b_ {
  949. // c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  950. // c.ServeJSON()
  951. // return
  952. // }
  953. //
  954. // T_SN := c.GetString("SN")
  955. // _, err := Device.Read_Device_ByT_sn(T_SN)
  956. // if err != nil {
  957. // c.Data["json"] = lib.JSONS{Code: 206, Msg: "T_sn Err!"}
  958. // c.ServeJSON()
  959. // return
  960. // }
  961. // Admin_Power_, _ := Admin.Read_AdminPower_ById(admin_r.Admin_power)
  962. // if Admin_Power_.Power_DeviceSensor_Compensate_e == 0 {
  963. // c.Data["json"] = lib.JSONS{Code: 202, Msg: "! U" + strconv.Itoa(admin_r.Id)}
  964. // c.ServeJSON()
  965. // return
  966. // }
  967. //
  968. // T_sensor_list := c.GetString("T_sensor_list")
  969. // jsonStu_map_ := strings.Replace(string(T_sensor_list), "\"{", "{", -1)
  970. // jsonStu_map_ = strings.Replace(jsonStu_map_, "}\"", "}", -1)
  971. // jsonStu_map_ = strings.Replace(jsonStu_map_, "\\\"", "\"", -1)
  972. // println("jsonStu_map_:", jsonStu_map_)
  973. // var Rt_parameter_sensor_ []MqttServer.Rt_Parameter_Sensor_
  974. // err = json.Unmarshal([]byte(jsonStu_map_), &Rt_parameter_sensor_)
  975. // if err != nil {
  976. // c.Data["json"] = lib.JSONS{Code: 204, Msg: "T_sensor_list Err!"}
  977. // c.ServeJSON()
  978. // return
  979. // }
  980. //
  981. // Handle.Pu_DeviceParameter_Sensor(admin_r.Admin_uuid, T_SN, Rt_parameter_sensor_)
  982. // System.Add_UserLogs(admin_r.Admin_uuid,"设备管理", "传感器参数操作", jsonStu_map_)
  983. //
  984. // DeviceSensor,is := Device.Read_DeviceSensor_ByT_sn(T_SN, Rt_parameter_sensor_[0].T_id)
  985. // if is {
  986. // DeviceSensor.T_name = Rt_parameter_sensor_[0].T_name
  987. // Device.Update_TDeviceSensor(DeviceSensor,"T_name")
  988. // }
  989. //
  990. //
  991. // c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  992. // c.ServeJSON()
  993. // return
  994. //
  995. //}
  996. //
  997. func (c *DeviceController) Pu_DeviceParameter_Sensor() {
  998. // 验证登录
  999. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  1000. if !b_ {
  1001. c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  1002. c.ServeJSON()
  1003. return
  1004. }
  1005. T_SN := c.GetString("T_SN")
  1006. T_name := c.GetString("T_name")
  1007. T_id, _ := c.GetInt("T_id")
  1008. T_Tlower, _ := c.GetFloat("T_Tlower")
  1009. T_Tupper, _ := c.GetFloat("T_Tupper")
  1010. T_RHlower, _ := c.GetFloat("T_RHlower")
  1011. T_RHupper, _ := c.GetFloat("T_RHupper")
  1012. T_en, _ := c.GetInt("T_en")
  1013. T_free, _ := c.GetInt("T_free")
  1014. // 权限 过滤
  1015. Admin_Power_, _ := Admin.Read_AdminPower_ById(admin_r.Admin_power)
  1016. if Admin_Power_.Power_DeviceSensor_Parameter_e == 0 {
  1017. c.Data["json"] = lib.JSONS{Code: 202, Msg: "! U" + strconv.Itoa(admin_r.Id)}
  1018. c.ServeJSON()
  1019. return
  1020. }
  1021. _, err := Device.Read_Device_ByT_sn(T_SN)
  1022. if err != nil {
  1023. c.Data["json"] = lib.JSONS{Code: 206, Msg: "T_sn Err!"}
  1024. c.ServeJSON()
  1025. return
  1026. }
  1027. DeviceSensor, is := Device.Read_DeviceSensor_ByT_sn(T_SN, T_id)
  1028. if !is {
  1029. c.Data["json"] = lib.JSONS{Code: 208, Msg: "T_sn T_id Err!"}
  1030. c.ServeJSON()
  1031. return
  1032. }
  1033. Devicesensorparameter := Device.DeviceSensorParameter{
  1034. T_sn: T_SN,
  1035. T_id: T_id,
  1036. T_name: T_name,
  1037. T_Tlower: float32(T_Tlower),
  1038. T_Tupper: float32(T_Tupper),
  1039. T_RHlower: float32(T_RHlower),
  1040. T_RHupper: float32(T_RHupper),
  1041. T_en: T_en,
  1042. T_free: T_free,
  1043. T_uuid: admin_r.Admin_uuid,
  1044. T_SendState: 0,
  1045. T_State: 2,
  1046. }
  1047. dsp_id, is := Device.Add_DeviceSensorParameter(Devicesensorparameter)
  1048. if !is {
  1049. c.Data["json"] = lib.JSONS{Code: 209, Msg: "添加失败!"}
  1050. c.ServeJSON()
  1051. return
  1052. }
  1053. Devicesensorparameter.Id = int(dsp_id)
  1054. // 更新名称
  1055. DeviceSensor.T_name = T_name
  1056. Device.Update_DeviceSensor(DeviceSensor, "T_name")
  1057. System.Add_UserLogs_T(admin_r.Admin_uuid, "设备管理", "传感器参数操作", Devicesensorparameter)
  1058. NatsServer.Pu_DeviceParameter_Sensor(Devicesensorparameter)
  1059. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  1060. c.ServeJSON()
  1061. return
  1062. }
  1063. func (c *DeviceController) DeviceSensor_v2_Parameter_Pu() {
  1064. // 验证登录
  1065. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  1066. if !b_ {
  1067. c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  1068. c.ServeJSON()
  1069. return
  1070. }
  1071. T_SN := c.GetString("T_sn")
  1072. T_name := c.GetString("T_name")
  1073. T_id, _ := c.GetInt("T_id")
  1074. T_Tlower, _ := c.GetFloat("T_Tlower")
  1075. T_Tupper, _ := c.GetFloat("T_Tupper")
  1076. T_RHlower, _ := c.GetFloat("T_RHlower")
  1077. T_RHupper, _ := c.GetFloat("T_RHupper")
  1078. T_en, _ := c.GetInt("T_en")
  1079. T_free, _ := c.GetInt("T_free")
  1080. // 权限 过滤
  1081. Admin_Power_, _ := Admin.Read_AdminPower_ById(admin_r.Admin_power)
  1082. if Admin_Power_.Power_DeviceSensor_Parameter_e == 0 {
  1083. c.Data["json"] = lib.JSONS{Code: 202, Msg: "! U" + strconv.Itoa(admin_r.Id)}
  1084. c.ServeJSON()
  1085. return
  1086. }
  1087. _, err := Device.Read_Device_ByT_sn(T_SN)
  1088. if err != nil {
  1089. c.Data["json"] = lib.JSONS{Code: 206, Msg: "T_sn Err!"}
  1090. c.ServeJSON()
  1091. return
  1092. }
  1093. DeviceSensor, is := Device.Read_DeviceSensor_ByT_sn(T_SN, T_id)
  1094. if !is {
  1095. c.Data["json"] = lib.JSONS{Code: 208, Msg: "T_sn T_id Err!"}
  1096. c.ServeJSON()
  1097. return
  1098. }
  1099. Devicesensorparameter := Device.DeviceSensorParameter{
  1100. T_sn: T_SN,
  1101. T_id: T_id,
  1102. T_name: T_name,
  1103. T_Tlower: float32(T_Tlower),
  1104. T_Tupper: float32(T_Tupper),
  1105. T_RHlower: float32(T_RHlower),
  1106. T_RHupper: float32(T_RHupper),
  1107. T_en: T_en,
  1108. T_free: T_free,
  1109. T_uuid: admin_r.Admin_uuid,
  1110. T_SendState: 0,
  1111. T_State: 2,
  1112. }
  1113. dsp_id, is := Device.Add_DeviceSensorParameter(Devicesensorparameter)
  1114. if !is {
  1115. c.Data["json"] = lib.JSONS{Code: 209, Msg: "添加失败!"}
  1116. c.ServeJSON()
  1117. return
  1118. }
  1119. Devicesensorparameter.Id = int(dsp_id)
  1120. // 更新名称
  1121. DeviceSensor.T_name = T_name
  1122. Device.Update_DeviceSensor(DeviceSensor, "T_name")
  1123. System.Add_UserLogs_T(admin_r.Admin_uuid, "设备管理", "传感器参数操作", Devicesensorparameter)
  1124. NatsServer.Pu_DeviceParameter_Sensor(Devicesensorparameter)
  1125. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  1126. c.ServeJSON()
  1127. return
  1128. }
  1129. ////
  1130. //func (c *DeviceController) Pu_DeviceParameter_Sensor_Cache() {
  1131. // // 验证登录
  1132. // b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  1133. // if !b_ {
  1134. // c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  1135. // c.ServeJSON()
  1136. // return
  1137. // }
  1138. //
  1139. // T_SN := c.GetString("SN")
  1140. // T_id := c.GetString("T_id")
  1141. // _, err := Device.Read_Device_ByT_sn(T_SN)
  1142. // if err != nil {
  1143. // c.Data["json"] = lib.JSONS{Code: 206, Msg: "T_sn Err!"}
  1144. // c.ServeJSON()
  1145. // return
  1146. // }
  1147. // Admin_Power_, _ := Admin.Read_AdminPower_ById(admin_r.Admin_power)
  1148. // if Admin_Power_.Power_DeviceSensor_Compensate_e == 0 {
  1149. // c.Data["json"] = lib.JSONS{Code: 202, Msg: "! U" + strconv.Itoa(admin_r.Id)}
  1150. // c.ServeJSON()
  1151. // return
  1152. // }
  1153. //
  1154. // T_sensor_list := c.GetString("T_sensor_list")
  1155. // jsonStu_map_ := strings.Replace(string(T_sensor_list), "\"{", "{", -1)
  1156. // jsonStu_map_ = strings.Replace(jsonStu_map_, "}\"", "}", -1)
  1157. // jsonStu_map_ = strings.Replace(jsonStu_map_, "\\\"", "\"", -1)
  1158. // println("jsonStu_map_:", jsonStu_map_)
  1159. // var Rt_parameter_sensor_ []MqttServer.Rt_Parameter_Sensor_
  1160. // err = json.Unmarshal([]byte(jsonStu_map_), &Rt_parameter_sensor_)
  1161. // if err != nil {
  1162. // c.Data["json"] = lib.JSONS{Code: 204, Msg: "T_sensor_list Err!"}
  1163. // c.ServeJSON()
  1164. // return
  1165. // }
  1166. // DeviceSensor,is := Device.Read_DeviceSensor_ByT_sn(T_SN, Rt_parameter_sensor_[0].T_id)
  1167. // if is {
  1168. // DeviceSensor.T_name = Rt_parameter_sensor_[0].T_name
  1169. // Device.Update_TDeviceSensor(DeviceSensor,"T_name")
  1170. // }
  1171. //
  1172. // Device.Redis_DeviceSensorParameterCache_Set(T_SN+"_"+T_id,jsonStu_map_)
  1173. // //Handle.Pu_DeviceParameter_Sensor(admin_r.Admin_uuid, T_SN, Rt_parameter_sensor_)
  1174. // System.Add_UserLogs(admin_r.Admin_uuid,"设备管理", "传感器参数操作-离线操作", jsonStu_map_)
  1175. // c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  1176. // c.ServeJSON()
  1177. // return
  1178. //
  1179. //}
  1180. // 列表 -
  1181. func (c *DeviceController) DeviceWarning_List_html() {
  1182. // 验证登录
  1183. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  1184. if !b_ {
  1185. c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  1186. c.ServeJSON()
  1187. return
  1188. }
  1189. c.Data["Admin_r"] = admin_r
  1190. page, _ := c.GetInt("page")
  1191. println(page)
  1192. if page < 1 {
  1193. page = 1
  1194. }
  1195. c.Data["Admin_r"] = admin_r
  1196. T_Name := c.GetString("T_Name")
  1197. //T_sn := c.GetString("T_sn")
  1198. Time_start := c.GetString("Time_start")
  1199. Time_end := c.GetString("Time_end")
  1200. if len(Time_start) == 0 && len(Time_end) == 0 {
  1201. Time_start = time.Now().Format("2006-01-02") + " 00:00:00"
  1202. Time_end = time.Now().Format("2006-01-02") + " 23:59:59"
  1203. }
  1204. c.Data["Time_start"] = Time_start
  1205. c.Data["Time_end"] = Time_end
  1206. c.Data["T_Name"] = T_Name
  1207. //c.Data["Class_List"] = Device.Read_DeviceWarningList_All_1()
  1208. //T_Title := ""
  1209. //if Class_1 > 0 {
  1210. // T_Title = Device.Read_DeviceWarningList_ById(Class_1).T_name
  1211. //}
  1212. var cnt int64
  1213. DeviceWarning_List, cnt := Device.Read_DeviceWarning_1(admin_r, page, "", T_Name, Time_start, Time_end)
  1214. //for i, v := range DeviceWarning_List {
  1215. // DeviceWarning_List[i].T_State = 0
  1216. // if strings.Contains(v.T_sn, "YD") {
  1217. // DeviceWarning_List[i].T_State = 1
  1218. // }
  1219. //}
  1220. c.Data["List"] = DeviceWarning_List
  1221. page_size := math.Ceil(float64(cnt) / float64(conf.Page_size))
  1222. c.Data["Page"] = page
  1223. c.Data["Page_size"] = page_size
  1224. c.Data["Pages"] = lib.Func_page(int64(page), int64(page_size))
  1225. c.Data["cnt"] = cnt
  1226. c.TplName = "Device/DeviceWarning.html"
  1227. }
  1228. // 列表 -
  1229. func (c *DeviceController) DeviceWarning_List() {
  1230. // 验证登录
  1231. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  1232. if !b_ {
  1233. c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  1234. c.ServeJSON()
  1235. return
  1236. }
  1237. type R_JSONS struct {
  1238. //必须的大写开头
  1239. DeviceWarning []Device.DeviceWarning
  1240. //DeviceWarningclass []Device.DeviceWarningList
  1241. Num int
  1242. Page int
  1243. Page_size int
  1244. Pages []lib.Page_T
  1245. }
  1246. var r_jsons R_JSONS
  1247. page, _ := c.GetInt("page")
  1248. println(page)
  1249. if page < 1 {
  1250. page = 1
  1251. }
  1252. T_sn := c.GetString("T_sn")
  1253. //T_sn := c.GetString("Sn")
  1254. //Class_1, _ := c.GetInt("Class_1")
  1255. T_Name := c.GetString("T_Name")
  1256. Time_start := c.GetString("Time_start")
  1257. Time_end := c.GetString("Time_end")
  1258. //r_jsons.DeviceWarningclass = Device.Read_DeviceWarningList_All_1()
  1259. //T_Title := ""
  1260. //if Class_1 > 0 {
  1261. // T_Title = Device.Read_DeviceWarningList_ById(Class_1).T_name
  1262. //}
  1263. var cnt int64
  1264. r_jsons.DeviceWarning, cnt = Device.Read_DeviceWarning_1(admin_r, page, T_sn, T_Name, Time_start, Time_end)
  1265. page_size := math.Ceil(float64(cnt) / float64(conf.Page_size))
  1266. r_jsons.Page = int(page)
  1267. r_jsons.Page_size = int(page_size)
  1268. r_jsons.Pages = lib.Func_page(int64(page), int64(page_size))
  1269. r_jsons.Num = int(cnt)
  1270. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
  1271. c.ServeJSON()
  1272. return
  1273. }
  1274. // 列表 -
  1275. func (c *DeviceController) V2_DeviceWarning_List() {
  1276. // 验证登录
  1277. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  1278. if !b_ {
  1279. c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  1280. c.ServeJSON()
  1281. return
  1282. }
  1283. type R_JSONS struct {
  1284. //必须的大写开头
  1285. Data []Device.DeviceWarning
  1286. Num int64
  1287. Page int
  1288. Page_size int
  1289. }
  1290. var r_jsons R_JSONS
  1291. page, _ := c.GetInt("page")
  1292. println(page)
  1293. if page < 1 {
  1294. page = 1
  1295. }
  1296. page_z, _ := c.GetInt("page_z")
  1297. if page_z < 1 {
  1298. page_z = conf.Page_size
  1299. }
  1300. T_sn := c.GetString("T_sn")
  1301. T_id := c.GetString("T_id")
  1302. T_title := c.GetString("T_title")
  1303. Time_start := c.GetString("Time_start")
  1304. Time_end := c.GetString("Time_end")
  1305. //r_jsons.DeviceWarningclass = Device.Read_DeviceWarningList_All_1()
  1306. //T_Title := ""
  1307. //if Class_1 > 0 {
  1308. // T_Title = Device.Read_DeviceWarningList_ById(Class_1).T_name
  1309. //}
  1310. r_jsons.Data, r_jsons.Num = Device.Read_DeviceWarning(admin_r, T_sn, T_id, T_title, Time_start, Time_end, page, page_z)
  1311. r_jsons.Page = page
  1312. r_jsons.Page_size = int(math.Ceil(float64(r_jsons.Num) / float64(page_z)))
  1313. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
  1314. c.ServeJSON()
  1315. return
  1316. }
  1317. // 列表 -
  1318. func (c *DeviceController) DeviceWarning_Data_Excel() {
  1319. // 验证登录
  1320. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  1321. if !b_ {
  1322. c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  1323. c.ServeJSON()
  1324. return
  1325. }
  1326. //T_sn := c.GetString("T_sn")
  1327. Class_1, _ := c.GetInt("Class_1")
  1328. T_Name := c.GetString("T_Name")
  1329. Time_start := c.GetString("Time_start")
  1330. Time_end := c.GetString("Time_end")
  1331. c.Data["Class_1"] = Class_1
  1332. if len(Time_start) == 0 && len(Time_end) == 0 {
  1333. Time_start = time.Now().Format("2006-01-02") + " 00:00:00"
  1334. Time_end = time.Now().Format("2006-01-02") + " 23:59:59"
  1335. }
  1336. //
  1337. //T_Title := ""
  1338. //if Class_1 > 0 {
  1339. // T_Title = Device.Read_DeviceWarningList_ById(Class_1).T_name
  1340. //}
  1341. Device_data, _ := Device.Read_DeviceWarning_1(admin_r, 9999, "", T_Name, Time_start, Time_end)
  1342. f := excelize.NewFile() // 设置单元格的值
  1343. // 这里设置表头
  1344. f.SetCellValue("Sheet1", "A1", "报警类型")
  1345. f.SetCellValue("Sheet1", "B1", "Sn")
  1346. f.SetCellValue("Sheet1", "C1", "设备名称")
  1347. f.SetCellValue("Sheet1", "D1", "传感器")
  1348. f.SetCellValue("Sheet1", "E1", "温度℃")
  1349. f.SetCellValue("Sheet1", "F1", "湿度%")
  1350. f.SetCellValue("Sheet1", "G1", "报警内容")
  1351. f.SetCellValue("Sheet1", "H1", "记录时间")
  1352. f.SetCellValue("Sheet1", "I1", "处理")
  1353. f.SetCellValue("Sheet1", "J1", "处理时间")
  1354. // 设置列宽
  1355. f.SetColWidth("Sheet1", "A", "A", 20)
  1356. f.SetColWidth("Sheet1", "B", "B", 25)
  1357. f.SetColWidth("Sheet1", "C", "C", 30)
  1358. f.SetColWidth("Sheet1", "D", "D", 30)
  1359. f.SetColWidth("Sheet1", "E", "E", 10)
  1360. f.SetColWidth("Sheet1", "F", "F", 10)
  1361. f.SetColWidth("Sheet1", "G", "G", 30)
  1362. f.SetColWidth("Sheet1", "H", "H", 15)
  1363. f.SetColWidth("Sheet1", "I", "I", 30)
  1364. f.SetColWidth("Sheet1", "J", "J", 15)
  1365. line := 1
  1366. // 循环写入数据
  1367. for _, v := range Device_data {
  1368. line++
  1369. f.SetCellValue("Sheet1", fmt.Sprintf("A%d", line), v.T_Title)
  1370. f.SetCellValue("Sheet1", fmt.Sprintf("B%d", line), v.T_sn+"["+strconv.Itoa(v.T_Id)+"]")
  1371. f.SetCellValue("Sheet1", fmt.Sprintf("C%d", line), v.T_Addr)
  1372. f.SetCellValue("Sheet1", fmt.Sprintf("D%d", line), v.T_Name)
  1373. f.SetCellValue("Sheet1", fmt.Sprintf("E%d", line), v.T_T)
  1374. f.SetCellValue("Sheet1", fmt.Sprintf("F%d", line), v.T_RH)
  1375. f.SetCellValue("Sheet1", fmt.Sprintf("G%d", line), v.T_Remark)
  1376. f.SetCellValue("Sheet1", fmt.Sprintf("H%d", line), v.T_Ut)
  1377. f.SetCellValue("Sheet1", fmt.Sprintf("I%d", line), v.T_Text)
  1378. f.SetCellValue("Sheet1", fmt.Sprintf("J%d", line), v.UpdateTime)
  1379. }
  1380. timeStr := time.Now().Format("20060102150405")
  1381. // 保存文件
  1382. if err := f.SaveAs("ofile/" + timeStr + ".xlsx"); err != nil {
  1383. fmt.Println(err)
  1384. }
  1385. url, is := NatsServer.Qiniu_UploadFile(lib.GetCurrentDirectory()+"/ofile/"+timeStr+".xlsx", "ofile/"+timeStr+".xlsx")
  1386. if !is {
  1387. c.Data["json"] = lib.JSONS{Code: 203, Msg: "oss!"}
  1388. c.ServeJSON()
  1389. return
  1390. }
  1391. //删除文件
  1392. //err := os.Remove("ofile/" + timeStr + ".xlsx")
  1393. //if err != nil {
  1394. // fmt.Println(err)
  1395. //}
  1396. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: url}
  1397. c.ServeJSON()
  1398. return
  1399. }
  1400. // 列表 -
  1401. func (c *DeviceController) V2_DeviceWarning_Data_Excel() {
  1402. // 验证登录
  1403. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  1404. if !b_ {
  1405. c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  1406. c.ServeJSON()
  1407. return
  1408. }
  1409. //T_sn := c.GetString("T_sn")
  1410. T_sn := c.GetString("T_sn")
  1411. T_id := c.GetString("T_id")
  1412. T_title := c.GetString("T_title")
  1413. Time_start := c.GetString("Time_start")
  1414. Time_end := c.GetString("Time_end")
  1415. Device_data, _ := Device.Read_DeviceWarning(admin_r, T_sn, T_id, T_title, Time_start, Time_end, 0, 9999)
  1416. f := excelize.NewFile() // 设置单元格的值
  1417. // 这里设置表头
  1418. f.SetCellValue("Sheet1", "A1", "报警类型")
  1419. f.SetCellValue("Sheet1", "B1", "Sn")
  1420. f.SetCellValue("Sheet1", "C1", "设备名称")
  1421. f.SetCellValue("Sheet1", "D1", "传感器")
  1422. f.SetCellValue("Sheet1", "E1", "温度℃")
  1423. f.SetCellValue("Sheet1", "F1", "湿度%")
  1424. f.SetCellValue("Sheet1", "G1", "报警内容")
  1425. f.SetCellValue("Sheet1", "H1", "记录时间")
  1426. f.SetCellValue("Sheet1", "I1", "处理")
  1427. f.SetCellValue("Sheet1", "J1", "处理时间")
  1428. // 设置列宽
  1429. f.SetColWidth("Sheet1", "A", "A", 20)
  1430. f.SetColWidth("Sheet1", "B", "B", 25)
  1431. f.SetColWidth("Sheet1", "C", "C", 30)
  1432. f.SetColWidth("Sheet1", "D", "D", 30)
  1433. f.SetColWidth("Sheet1", "E", "E", 10)
  1434. f.SetColWidth("Sheet1", "F", "F", 10)
  1435. f.SetColWidth("Sheet1", "G", "G", 30)
  1436. f.SetColWidth("Sheet1", "H", "H", 15)
  1437. f.SetColWidth("Sheet1", "I", "I", 30)
  1438. f.SetColWidth("Sheet1", "J", "J", 15)
  1439. line := 1
  1440. // 循环写入数据
  1441. for _, v := range Device_data {
  1442. line++
  1443. f.SetCellValue("Sheet1", fmt.Sprintf("A%d", line), v.T_Title)
  1444. f.SetCellValue("Sheet1", fmt.Sprintf("B%d", line), v.T_sn+"["+strconv.Itoa(v.T_Id)+"]")
  1445. f.SetCellValue("Sheet1", fmt.Sprintf("C%d", line), v.T_Addr)
  1446. f.SetCellValue("Sheet1", fmt.Sprintf("D%d", line), v.T_Name)
  1447. f.SetCellValue("Sheet1", fmt.Sprintf("E%d", line), v.T_T)
  1448. f.SetCellValue("Sheet1", fmt.Sprintf("F%d", line), v.T_RH)
  1449. f.SetCellValue("Sheet1", fmt.Sprintf("G%d", line), v.T_Remark)
  1450. f.SetCellValue("Sheet1", fmt.Sprintf("H%d", line), v.T_Ut)
  1451. f.SetCellValue("Sheet1", fmt.Sprintf("I%d", line), v.T_Text)
  1452. f.SetCellValue("Sheet1", fmt.Sprintf("J%d", line), v.UpdateTime)
  1453. }
  1454. timeStr := time.Now().Format("20060102150405")
  1455. // 保存文件
  1456. if err := f.SaveAs("ofile/" + timeStr + ".xlsx"); err != nil {
  1457. fmt.Println(err)
  1458. }
  1459. url, is := NatsServer.Qiniu_UploadFile(lib.GetCurrentDirectory()+"/ofile/"+timeStr+".xlsx", "ofile/"+timeStr+".xlsx")
  1460. if !is {
  1461. c.Data["json"] = lib.JSONS{Code: 203, Msg: "oss!"}
  1462. c.ServeJSON()
  1463. return
  1464. }
  1465. //删除文件
  1466. //err := os.Remove("ofile/" + timeStr + ".xlsx")
  1467. //if err != nil {
  1468. // fmt.Println(err)
  1469. //}
  1470. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: url}
  1471. c.ServeJSON()
  1472. return
  1473. }
  1474. func (c *DeviceController) DeviceWarning_() {
  1475. id, _ := c.GetInt("id")
  1476. c.Data["T"] = Device.Read_DeviceWarning_ById(id)
  1477. c.Data["id"] = id
  1478. c.TplName = "Device/DeviceWarning-.html"
  1479. }
  1480. func (c *DeviceController) DeviceWarning_log() {
  1481. id, _ := c.GetInt("id")
  1482. T_Log := Device.Read_DeviceWarning_ById(id).T_Log
  1483. T_Log = strings.Replace(T_Log, "\n", "<hr>", -1)
  1484. c.Data["T_Log"] = T_Log
  1485. c.TplName = "Device/DeviceWarning-log.html"
  1486. }
  1487. func (c *DeviceController) V2_DeviceWarning_Get() {
  1488. // 验证登录
  1489. b_, _ := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  1490. if !b_ {
  1491. c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  1492. c.ServeJSON()
  1493. return
  1494. }
  1495. id, _ := c.GetInt("T_id")
  1496. T := Device.Read_DeviceWarning_ById(id)
  1497. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: Device.DeviceWarningToDeviceWarning_R(T)}
  1498. c.ServeJSON()
  1499. return
  1500. }
  1501. func (c *DeviceController) DeviceWarning_M() {
  1502. id := c.GetString("id")
  1503. c.Data["id"] = id
  1504. c.TplName = "Device/DeviceWarning-M.html"
  1505. }
  1506. func (c *DeviceController) DeviceWarning_Post() {
  1507. // 验证登录
  1508. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  1509. if !b_ {
  1510. c.Ctx.Redirect(302, "Login")
  1511. return
  1512. }
  1513. Id, _ := c.GetInt("Id")
  1514. T_Text := c.GetString("T_Text")
  1515. t_c := Device.DeviceWarning{
  1516. Id: Id,
  1517. T_Text: T_Text,
  1518. }
  1519. Device.Update_DeviceWarning_ById(t_c)
  1520. System.Add_UserLogs(admin_r.Admin_uuid, "设备管理", "报警处理操作", strconv.Itoa(Id)+"->"+T_Text)
  1521. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  1522. c.ServeJSON()
  1523. return
  1524. }
  1525. func (c *DeviceController) V2_DeviceWarning_Post() {
  1526. // 验证登录
  1527. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  1528. if !b_ {
  1529. c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  1530. c.ServeJSON()
  1531. return
  1532. }
  1533. Id, _ := c.GetInt("T_id")
  1534. T_Text := c.GetString("T_Text")
  1535. T := Device.Read_DeviceWarning_ById(Id)
  1536. if T.Id == 0 {
  1537. c.Data["json"] = lib.JSONS{Code: 206, Msg: "T_id Err!"}
  1538. c.ServeJSON()
  1539. return
  1540. }
  1541. T.T_Text = T_Text
  1542. T.T_State = 2
  1543. Device.Update_DeviceWarning(T, "T_Text", "T_State")
  1544. System.Add_UserLogs(admin_r.Admin_uuid, "设备管理", "报警处理操作", strconv.Itoa(Id)+"->"+T_Text)
  1545. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  1546. c.ServeJSON()
  1547. return
  1548. }
  1549. func (c *DeviceController) DeviceWarning_Del() {
  1550. // 验证登录
  1551. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  1552. if !b_ {
  1553. c.Ctx.Redirect(302, "Login")
  1554. return
  1555. }
  1556. Id, _ := c.GetInt("Id")
  1557. t_c := Device.DeviceWarning{
  1558. Id: Id,
  1559. }
  1560. Device.Update_DeviceWarning_Delete(t_c)
  1561. System.Add_UserLogs(admin_r.Admin_uuid, "设备管理", "报警删除操作", strconv.Itoa(Id))
  1562. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  1563. c.ServeJSON()
  1564. return
  1565. }
  1566. func (c *DeviceController) V2_DeviceWarning_Del() {
  1567. // 验证登录
  1568. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  1569. if !b_ {
  1570. c.Ctx.Redirect(302, "Login")
  1571. return
  1572. }
  1573. Id, _ := c.GetInt("T_id")
  1574. T := Device.Read_DeviceWarning_ById(Id)
  1575. if T.Id == 0 {
  1576. c.Data["json"] = lib.JSONS{Code: 206, Msg: "T_id Err!"}
  1577. c.ServeJSON()
  1578. return
  1579. }
  1580. T.T_State = 0
  1581. Device.Update_DeviceWarning(T, "T_State")
  1582. System.Add_UserLogs(admin_r.Admin_uuid, "设备管理", "报警删除操作", strconv.Itoa(Id))
  1583. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  1584. c.ServeJSON()
  1585. return
  1586. }
  1587. // 用户管理
  1588. func (c *DeviceController) DeviceBind_html() {
  1589. // 验证登录
  1590. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  1591. if !b_ {
  1592. c.Ctx.Redirect(302, "Login")
  1593. return
  1594. }
  1595. c.Data["Admin_Power"], _ = Admin.Read_AdminPower_ById(admin_r.Admin_power)
  1596. page, _ := c.GetInt("page")
  1597. println(page)
  1598. if page < 1 {
  1599. page = 1
  1600. }
  1601. Name := c.GetString("Name")
  1602. c.Data["Name"] = Name
  1603. c.Data["Power_List"] = Admin.Read_Power_List_ALL_Power_Administration(0)
  1604. Adminpower, _ := Admin.Read_AdminPower_ById(admin_r.Admin_power)
  1605. var cnt int64
  1606. if Adminpower.Power_User_r != 1 {
  1607. c.Ctx.Redirect(302, "Login")
  1608. return
  1609. }
  1610. c.Data["List"], cnt = Admin.Read_Admin_List_ALL_User(page, Name, admin_r.Id)
  1611. fmt.Println("cnt:", cnt)
  1612. page_size := math.Ceil(float64(cnt) / float64(conf.Page_size))
  1613. c.Data["Page"] = page
  1614. c.Data["Page_size"] = page_size
  1615. c.Data["Pages"] = lib.Func_page(int64(page), int64(page_size))
  1616. c.Data["cnt"] = cnt
  1617. c.TplName = "Device/DeviceBind.html"
  1618. }
  1619. func (c *DeviceController) DeviceBind_List() {
  1620. // 验证登录
  1621. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  1622. if !b_ {
  1623. c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  1624. c.ServeJSON()
  1625. return
  1626. }
  1627. if len(c.GetString("Admin_uuid")) > 1 {
  1628. s_, user_r := Admin.Read_Admin_ByAdmin_uuid(c.GetString("Admin_uuid"))
  1629. if s_ != nil {
  1630. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Admin_uuid Err!"}
  1631. c.ServeJSON()
  1632. return
  1633. }
  1634. admin_r = user_r
  1635. }
  1636. type R_JSONS struct {
  1637. //必须的大写开头
  1638. Device_lite []Device.Device
  1639. Num int
  1640. Page int
  1641. Page_size int
  1642. Pages []lib.Page_T
  1643. }
  1644. var r_jsons R_JSONS
  1645. page, _ := c.GetInt("page")
  1646. println(page)
  1647. if page < 1 {
  1648. page = 1
  1649. }
  1650. page_z, _ := c.GetInt("page_z")
  1651. println(page_z)
  1652. if page_z == 0 {
  1653. page_z = conf.Page_size
  1654. }
  1655. Class_1 := c.GetString("Class_1")
  1656. Name := c.GetString("Name")
  1657. T_sn := c.GetString("T_sn")
  1658. T_monitor := c.GetString("T_monitor")
  1659. T_online := c.GetString("T_online")
  1660. //Class_1, _ := c.GetInt("Class_1")
  1661. //Name := c.GetString("Name")
  1662. //T_sn := c.GetString("T_sn")
  1663. //c.Data["Class_1"] = Class_1
  1664. ////c.Data["Name"] = Name
  1665. //c.Data["T_sn"] = T_sn
  1666. var cnt int64
  1667. Device_lite, cnt := Device.Read_Device_ALL_bind_1(admin_r, page, page_z, T_sn, Name, Class_1, T_monitor, T_online)
  1668. r_jsons.Device_lite = Device_lite
  1669. page_size := math.Ceil(float64(cnt) / float64(page_z))
  1670. r_jsons.Page = page
  1671. r_jsons.Page_size = int(page_size)
  1672. r_jsons.Pages = lib.Func_page(int64(page), int64(page_size))
  1673. r_jsons.Num = int(cnt)
  1674. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
  1675. c.ServeJSON()
  1676. return
  1677. }
  1678. func (c *DeviceController) DeviceBind_Sensor_List() {
  1679. // 验证登录
  1680. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  1681. if !b_ {
  1682. c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  1683. c.ServeJSON()
  1684. return
  1685. }
  1686. if len(c.GetString("Admin_uuid")) > 1 {
  1687. s_, user_r := Admin.Read_Admin_ByAdmin_uuid(c.GetString("Admin_uuid"))
  1688. if s_ != nil {
  1689. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Admin_uuid Err!"}
  1690. c.ServeJSON()
  1691. return
  1692. }
  1693. admin_r = user_r
  1694. }
  1695. type R_JSONS struct {
  1696. //必须的大写开头
  1697. Device_lite []Device.R_Device
  1698. Num int
  1699. Page int
  1700. Page_size int
  1701. Pages []lib.Page_T
  1702. }
  1703. var r_jsons R_JSONS
  1704. page, _ := c.GetInt("page")
  1705. println(page)
  1706. if page < 1 {
  1707. page = 1
  1708. }
  1709. page_z, _ := c.GetInt("page_z")
  1710. println(page_z)
  1711. if page_z == 0 {
  1712. page_z = conf.Page_size
  1713. }
  1714. Class_1 := c.GetString("Class_1")
  1715. Name := c.GetString("Name")
  1716. T_sn := c.GetString("T_sn")
  1717. T_monitor := c.GetString("T_monitor")
  1718. T_online := c.GetString("T_online")
  1719. //Class_1, _ := c.GetInt("Class_1")
  1720. //Name := c.GetString("Name")
  1721. //T_sn := c.GetString("T_sn")
  1722. //c.Data["Class_1"] = Class_1
  1723. ////c.Data["Name"] = Name
  1724. //c.Data["T_sn"] = T_sn
  1725. var cnt int64
  1726. Device_lite, cnt := Device.Read_Device_ALL_bind_1(admin_r, page, page_z, T_sn, Name, Class_1, T_monitor, T_online)
  1727. for _, v := range Device_lite {
  1728. r_Device := Device.R_Device{}
  1729. r_Device.T_sn = v.T_sn
  1730. r_Device.T_MSISDN = v.T_MSISDN
  1731. r_Device.T_devName = v.T_devName
  1732. r_Device.T_give = v.T_give
  1733. r_Device.T_online = v.T_online
  1734. r_Device.T_monitor = v.T_monitor
  1735. r_Device.T_Dattery = v.T_Dattery
  1736. r_Device.T_protocol = v.T_protocol
  1737. r_Device.T_sensor_list, r_Device.T_sensor = Device.Read_DeviceSensor_ByTsn(v.T_sn)
  1738. r_jsons.Device_lite = append(r_jsons.Device_lite, r_Device)
  1739. }
  1740. page_size := math.Ceil(float64(cnt) / float64(page_z))
  1741. r_jsons.Page = page
  1742. r_jsons.Page_size = int(page_size)
  1743. r_jsons.Pages = lib.Func_page(int64(page), int64(page_size))
  1744. r_jsons.Num = int(cnt)
  1745. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
  1746. c.ServeJSON()
  1747. return
  1748. }
  1749. func (c *DeviceController) DeviceBind_html_() {
  1750. // 验证登录
  1751. b_, _ := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  1752. if !b_ {
  1753. c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  1754. c.ServeJSON()
  1755. return
  1756. }
  1757. c.TplName = "Device/DeviceBind-.html"
  1758. }
  1759. func (c *DeviceController) DeviceBind_Add_All() {
  1760. // 验证登录
  1761. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  1762. if !b_ {
  1763. c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  1764. c.ServeJSON()
  1765. return
  1766. }
  1767. s_, user_r := Admin.Read_Admin_ByAdmin_uuid(c.GetString("Admin_uuid"))
  1768. if s_ != nil {
  1769. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Admin_uuid Err!"}
  1770. c.ServeJSON()
  1771. return
  1772. }
  1773. Name := c.GetString("Name")
  1774. T_sn := c.GetString("T_sn")
  1775. num_x := 0
  1776. Device_l := Device.Read_Device_ALL_T_sn_T_devName_bind_1(T_sn, Name, admin_r)
  1777. fmt.Println("len(Device_l):", len(Device_l))
  1778. for _, v := range Device_l {
  1779. Device_bind_list := Device.Read_Device_ALL_T_sn_bind_1(v.T_sn, user_r)
  1780. if len(Device_bind_list) > 0 {
  1781. continue
  1782. }
  1783. T_Bind := Device.Device_Bind_Add(v.T_sn, user_r)
  1784. Device.DeviceSensor_T_Bind_ALL(v.T_sn, T_Bind)
  1785. System.Add_UserLogs(admin_r.Admin_uuid, "设备管理", "设备绑定", v.T_sn+"+>"+c.GetString("Admin_uuid"))
  1786. num_x = num_x + 1
  1787. }
  1788. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: num_x}
  1789. c.ServeJSON()
  1790. return
  1791. }
  1792. func (c *DeviceController) DeviceBind_Add() {
  1793. // 验证登录
  1794. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  1795. if !b_ {
  1796. c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  1797. c.ServeJSON()
  1798. return
  1799. }
  1800. s_, user_r := Admin.Read_Admin_ByAdmin_uuid(c.GetString("Admin_uuid"))
  1801. if s_ != nil {
  1802. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Admin_uuid Err!"}
  1803. c.ServeJSON()
  1804. return
  1805. }
  1806. T_sn := c.GetString("T_sn")
  1807. if len(T_sn) < 5 {
  1808. c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_sn Err!"}
  1809. c.ServeJSON()
  1810. return
  1811. }
  1812. _, err := Device.Read_Device_ByT_sn(T_sn)
  1813. if err != nil {
  1814. c.Data["json"] = lib.JSONS{Code: 206, Msg: "T_sn Err!"}
  1815. c.ServeJSON()
  1816. return
  1817. }
  1818. Device_bind_list := Device.Read_Device_ALL_T_sn_bind_1(T_sn, user_r)
  1819. if len(Device_bind_list) > 0 {
  1820. c.Data["json"] = lib.JSONS{Code: 203, Msg: "ok!"}
  1821. c.ServeJSON()
  1822. return
  1823. }
  1824. // 同步权限
  1825. T_Bind := Device.Device_Bind_Add(T_sn, user_r)
  1826. Device.DeviceSensor_T_Bind_ALL(T_sn, T_Bind)
  1827. System.Add_UserLogs(admin_r.Admin_uuid, "设备管理", "设备绑定", T_sn+"+>"+c.GetString("Admin_uuid"))
  1828. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  1829. c.ServeJSON()
  1830. return
  1831. }
  1832. func (c *DeviceController) V2_DeviceBind_Add() {
  1833. // 验证登录
  1834. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  1835. if !b_ {
  1836. c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  1837. c.ServeJSON()
  1838. return
  1839. }
  1840. s_, user_r := Admin.Read_Admin_ByAdmin_uuid(c.GetString("T_uuid"))
  1841. if s_ != nil {
  1842. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Admin_uuid Err!"}
  1843. c.ServeJSON()
  1844. return
  1845. }
  1846. T_sn := c.GetString("T_sn")
  1847. if len(T_sn) < 5 {
  1848. c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_sn Err!"}
  1849. c.ServeJSON()
  1850. return
  1851. }
  1852. _, err := Device.Read_Device_ByT_sn(T_sn)
  1853. if err != nil {
  1854. c.Data["json"] = lib.JSONS{Code: 206, Msg: "T_sn Err!"}
  1855. c.ServeJSON()
  1856. return
  1857. }
  1858. Device_bind_list := Device.Read_Device_ALL_T_sn_bind_1(T_sn, user_r)
  1859. if len(Device_bind_list) > 0 {
  1860. c.Data["json"] = lib.JSONS{Code: 203, Msg: "ok!"}
  1861. c.ServeJSON()
  1862. return
  1863. }
  1864. // 同步权限
  1865. T_Bind := Device.Device_Bind_Add(T_sn, user_r)
  1866. Device.DeviceSensor_T_Bind_ALL(T_sn, T_Bind)
  1867. System.Add_UserLogs(admin_r.Admin_uuid, "设备管理", "设备绑定", T_sn+"+>"+c.GetString("Admin_uuid"))
  1868. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  1869. c.ServeJSON()
  1870. return
  1871. }
  1872. func (c *DeviceController) DeviceBind_Del() {
  1873. // 验证登录
  1874. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  1875. if !b_ {
  1876. c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  1877. c.ServeJSON()
  1878. return
  1879. }
  1880. s_, user_r := Admin.Read_Admin_ByAdmin_uuid(c.GetString("Admin_uuid"))
  1881. if s_ != nil {
  1882. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Admin_uuid Err!"}
  1883. c.ServeJSON()
  1884. return
  1885. }
  1886. T_sn := c.GetString("T_sn")
  1887. if len(T_sn) < 5 {
  1888. c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_sn Err!"}
  1889. c.ServeJSON()
  1890. return
  1891. }
  1892. _, err := Device.Read_Device_ByT_sn(T_sn)
  1893. if err != nil {
  1894. c.Data["json"] = lib.JSONS{Code: 206, Msg: "T_sn Err!"}
  1895. c.ServeJSON()
  1896. return
  1897. }
  1898. Device_bind_list := Device.Read_Device_ALL_T_sn_bind_1(T_sn, user_r)
  1899. if len(Device_bind_list) == 0 {
  1900. c.Data["json"] = lib.JSONS{Code: 204, Msg: "ok!"}
  1901. c.ServeJSON()
  1902. return
  1903. }
  1904. // 同步权限
  1905. T_Bind := Device.Device_Bind_Del(T_sn, user_r)
  1906. Device.DeviceSensor_T_Bind_ALL(T_sn, T_Bind)
  1907. System.Add_UserLogs(admin_r.Admin_uuid, "设备管理", "设备解除绑定", T_sn+"->"+c.GetString("Admin_uuid"))
  1908. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  1909. c.ServeJSON()
  1910. return
  1911. }
  1912. func (c *DeviceController) V2_DeviceBind_Del() {
  1913. // 验证登录
  1914. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  1915. if !b_ {
  1916. c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  1917. c.ServeJSON()
  1918. return
  1919. }
  1920. s_, user_r := Admin.Read_Admin_ByAdmin_uuid(c.GetString("T_uuid"))
  1921. if s_ != nil {
  1922. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Admin_uuid Err!"}
  1923. c.ServeJSON()
  1924. return
  1925. }
  1926. T_sn := c.GetString("T_sn")
  1927. if len(T_sn) < 5 {
  1928. c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_sn Err!"}
  1929. c.ServeJSON()
  1930. return
  1931. }
  1932. _, err := Device.Read_Device_ByT_sn(T_sn)
  1933. if err != nil {
  1934. c.Data["json"] = lib.JSONS{Code: 206, Msg: "T_sn Err!"}
  1935. c.ServeJSON()
  1936. return
  1937. }
  1938. Device_bind_list := Device.Read_Device_ALL_T_sn_bind_1(T_sn, user_r)
  1939. if len(Device_bind_list) == 0 {
  1940. c.Data["json"] = lib.JSONS{Code: 204, Msg: "ok!"}
  1941. c.ServeJSON()
  1942. return
  1943. }
  1944. // 同步权限
  1945. T_Bind := Device.Device_Bind_Del(T_sn, user_r)
  1946. Device.DeviceSensor_T_Bind_ALL(T_sn, T_Bind)
  1947. System.Add_UserLogs(admin_r.Admin_uuid, "设备管理", "设备解除绑定", T_sn+"->"+c.GetString("Admin_uuid"))
  1948. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  1949. c.ServeJSON()
  1950. return
  1951. }
  1952. // 设备分类
  1953. func (c *DeviceController) DeviceClass_html() {
  1954. // 验证登录
  1955. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  1956. if !b_ {
  1957. c.Ctx.Redirect(302, "Login")
  1958. return
  1959. }
  1960. page, _ := c.GetInt("page")
  1961. println(page)
  1962. if page < 1 {
  1963. page = 1
  1964. }
  1965. Name := c.GetString("Name")
  1966. c.Data["Name"] = Name
  1967. var cnt int64
  1968. c.Data["List"], cnt = Device.Read_DeviceClass_ALL_1(admin_r.Admin_uuid, page, Name)
  1969. fmt.Println("cnt:", cnt)
  1970. page_size := math.Ceil(float64(cnt) / float64(conf.Page_size))
  1971. c.Data["Page"] = page
  1972. c.Data["Page_size"] = page_size
  1973. c.Data["Pages"] = lib.Func_page(int64(page), int64(page_size))
  1974. c.Data["cnt"] = cnt
  1975. c.TplName = "Device/DeviceClass.html"
  1976. }
  1977. // 分类
  1978. func (c *DeviceController) V2_Class_List() {
  1979. // 验证登录
  1980. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  1981. if !b_ {
  1982. c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  1983. c.ServeJSON()
  1984. return
  1985. }
  1986. type R_JSONS struct {
  1987. //必须的大写开头
  1988. Data []Device.DeviceClass
  1989. Num int64
  1990. Page int
  1991. Page_size int
  1992. }
  1993. var r_jsons R_JSONS
  1994. page, _ := c.GetInt("page")
  1995. println(page)
  1996. if page < 1 {
  1997. page = 1
  1998. }
  1999. page_z, _ := c.GetInt("page_z")
  2000. if page_z < 1 {
  2001. page_z = conf.Page_size
  2002. }
  2003. Name := c.GetString("T_name")
  2004. r_jsons.Data, r_jsons.Num = Device.Read_DeviceClass_ALL_1(admin_r.Admin_uuid, page, Name)
  2005. r_jsons.Page = page
  2006. r_jsons.Page_size = int(math.Ceil(float64(r_jsons.Num) / float64(page_z)))
  2007. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
  2008. c.ServeJSON()
  2009. return
  2010. }
  2011. func (c *DeviceController) DeviceClass_() {
  2012. // 验证登录
  2013. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  2014. if !b_ {
  2015. c.Ctx.Redirect(302, "Login")
  2016. return
  2017. }
  2018. id, _ := c.GetInt("id")
  2019. c.Data["T"], _ = Device.Read_Class_ById(id)
  2020. c.Data["id"] = id
  2021. c.Data["Admin_r"] = admin_r
  2022. c.TplName = "Device/DeviceClass-.html"
  2023. }
  2024. func (c *DeviceController) V2_Class_Get() {
  2025. // 验证登录
  2026. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  2027. if !b_ {
  2028. c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  2029. c.ServeJSON()
  2030. return
  2031. }
  2032. id, _ := c.GetInt("T_id")
  2033. T, err := Device.Read_Class_ById(id)
  2034. if err != nil {
  2035. c.Data["json"] = lib.JSONS{Code: 203, Msg: "T_id Err!"}
  2036. c.ServeJSON()
  2037. return
  2038. }
  2039. if admin_r.Admin_uuid != T.T_uuid {
  2040. c.Data["json"] = lib.JSONS{Code: 204, Msg: "没有权限!"}
  2041. c.ServeJSON()
  2042. return
  2043. }
  2044. type DeviceClass_R struct {
  2045. T_name string // 分类
  2046. T_Notice_wx string //w微信公众号 appid/名字|
  2047. T_Notice_wx2 string //w微信公众号 appid/名字|
  2048. T_Notice_phone string //p手机 1111111|
  2049. T_Notice_message string //m短信 1111111|
  2050. T_Notice_mailbox string //e邮箱 1111111|
  2051. T_Notice_mechanism string // 报警机制
  2052. // 湿度超下限预警,处理,w启用,数量,上限,~|
  2053. // 湿度超下限预警,0,0,0,0,0,0,0,0,0,0,0,0|
  2054. T_QRCode string // 微信二维码
  2055. T_QRCode2 string // 微信二维码(冷链)
  2056. }
  2057. var r_jsons DeviceClass_R
  2058. r_jsons.T_name = T.T_name
  2059. r_jsons.T_Notice_wx = T.T_Notice_wx
  2060. r_jsons.T_Notice_wx2 = T.T_Notice_wx2
  2061. r_jsons.T_Notice_phone = T.T_Notice_phone
  2062. r_jsons.T_Notice_message = T.T_Notice_message
  2063. r_jsons.T_Notice_mailbox = T.T_Notice_mailbox
  2064. r_jsons.T_Notice_mechanism = T.T_Notice_mechanism
  2065. T_calss_id_str, _ := NatsServer.Wx_GenerateQRCode("-|" + lib.AesEncryptCBC(strconv.Itoa(T.Id), "0123456789012345") + "|- @宝智达 微信公众号通知")
  2066. if len(T_calss_id_str) > 0 {
  2067. r_jsons.T_QRCode = "https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=" + T_calss_id_str
  2068. }
  2069. T_calss_id_str, _ = NatsServer.Wx_GenerateQRCode2("-|" + lib.AesEncryptCBC(strconv.Itoa(T.Id), "0123456789012345") + "|- @宝智达 微信公众号通知")
  2070. if len(T_calss_id_str) > 0 {
  2071. r_jsons.T_QRCode2 = "https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=" + T_calss_id_str
  2072. }
  2073. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
  2074. c.ServeJSON()
  2075. return
  2076. }
  2077. func (c *DeviceController) DeviceClass_Post() {
  2078. // 验证登录
  2079. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  2080. if !b_ {
  2081. c.Ctx.Redirect(302, "Login")
  2082. return
  2083. }
  2084. Id, _ := c.GetInt("Id")
  2085. T_name := c.GetString("T_name")
  2086. T_Notice_wx := c.GetString("T_Notice_wx")
  2087. T_Notice_wx2 := c.GetString("T_Notice_wx2")
  2088. T_Notice_phone := c.GetString("T_Notice_phone")
  2089. T_Notice_message := c.GetString("T_Notice_message")
  2090. T_Notice_mailbox := c.GetString("T_Notice_mailbox")
  2091. T_Notice_mechanism := c.GetString("T_Notice_mechanism")
  2092. t_c := Device.DeviceClass{
  2093. Id: Id,
  2094. T_name: T_name,
  2095. T_Notice_wx: T_Notice_wx,
  2096. T_Notice_wx2: T_Notice_wx2,
  2097. T_Notice_phone: T_Notice_phone,
  2098. T_Notice_message: T_Notice_message,
  2099. T_Notice_mailbox: T_Notice_mailbox,
  2100. T_Notice_mechanism: T_Notice_mechanism,
  2101. }
  2102. if Id == 0 {
  2103. t_c.T_State = 1
  2104. t_c.T_uuid = admin_r.Admin_uuid
  2105. t_c.T_Notice_wx = ""
  2106. t_c.T_Notice_wx2 = ""
  2107. t_c.T_Notice_phone = ""
  2108. t_c.T_Notice_message = ""
  2109. t_c.T_Notice_mailbox = ""
  2110. t_c.T_Notice_mechanism = Device.Read_DeviceWarningList_All_T_Notice_mechanism()
  2111. Device.Add_Class(t_c)
  2112. } else {
  2113. t_c.T_uuid = admin_r.Admin_uuid
  2114. Device.Update_Class_ById(t_c)
  2115. }
  2116. System.Add_UserLogs_T(admin_r.Admin_uuid, "设备管理", "分类操作", t_c)
  2117. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  2118. c.ServeJSON()
  2119. return
  2120. }
  2121. func (c *DeviceController) V2_Class_Add() {
  2122. // 验证登录
  2123. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  2124. if !b_ {
  2125. c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  2126. c.ServeJSON()
  2127. return
  2128. }
  2129. T_name := c.GetString("T_name")
  2130. t_c := Device.DeviceClass{
  2131. T_uuid: admin_r.Admin_uuid,
  2132. T_name: T_name,
  2133. T_Notice_mechanism: Device.Read_DeviceWarningList_All_T_Notice_mechanism(),
  2134. T_State: 1,
  2135. }
  2136. Device.Add_Class(t_c)
  2137. System.Add_UserLogs_T(admin_r.Admin_uuid, "分类管理", "分类添加", t_c)
  2138. // 同步分类
  2139. DataList, _ := Admin.Read_v2_Admin_List(admin_r.Id, "", 0, 9999)
  2140. for _, v := range DataList {
  2141. V2_Class_Syn(admin_r, v)
  2142. }
  2143. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  2144. c.ServeJSON()
  2145. return
  2146. }
  2147. func (c *DeviceController) V2_Class_Edit() {
  2148. // 验证登录
  2149. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  2150. if !b_ {
  2151. c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  2152. c.ServeJSON()
  2153. return
  2154. }
  2155. Id, _ := c.GetInt("T_id")
  2156. T_name := c.GetString("T_name")
  2157. T_Notice_wx := c.GetString("T_Notice_wx")
  2158. T_Notice_wx2 := c.GetString("T_Notice_wx2")
  2159. T_Notice_phone := c.GetString("T_Notice_phone")
  2160. T_Notice_message := c.GetString("T_Notice_message")
  2161. T_Notice_mailbox := c.GetString("T_Notice_mailbox")
  2162. T_Notice_mechanism := c.GetString("T_Notice_mechanism")
  2163. R_DeviceClass, err := Device.Read_Class_ById(Id)
  2164. if err != nil {
  2165. c.Data["json"] = lib.JSONS{Code: 203, Msg: "T_id Err!"}
  2166. c.ServeJSON()
  2167. return
  2168. }
  2169. if R_DeviceClass.T_uuid != admin_r.Admin_uuid {
  2170. c.Data["json"] = lib.JSONS{Code: 203, Msg: "T_id Err!"}
  2171. c.ServeJSON()
  2172. return
  2173. }
  2174. R_DeviceClass.Id = Id
  2175. R_DeviceClass.T_name = T_name
  2176. R_DeviceClass.T_Notice_wx = T_Notice_wx
  2177. R_DeviceClass.T_Notice_wx2 = T_Notice_wx2
  2178. R_DeviceClass.T_Notice_phone = T_Notice_phone
  2179. R_DeviceClass.T_Notice_message = T_Notice_message
  2180. R_DeviceClass.T_Notice_mailbox = T_Notice_mailbox
  2181. R_DeviceClass.T_Notice_mechanism = T_Notice_mechanism
  2182. 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")
  2183. System.Add_UserLogs_T(admin_r.Admin_uuid, "设备管理", "分类操作", R_DeviceClass)
  2184. // 同步分类
  2185. DataList, _ := Admin.Read_v2_Admin_List(admin_r.Id, "", 0, 9999)
  2186. for _, v := range DataList {
  2187. V2_Class_Syn(admin_r, v)
  2188. }
  2189. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  2190. c.ServeJSON()
  2191. return
  2192. }
  2193. func (c *DeviceController) DeviceWarningList_T_Tips() {
  2194. // 验证登录
  2195. b_, _ := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  2196. if !b_ {
  2197. c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  2198. c.ServeJSON()
  2199. return
  2200. }
  2201. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: Device.Read_DeviceWarningList_All_T_Notice_mechanism()}
  2202. c.ServeJSON()
  2203. return
  2204. }
  2205. func (c *DeviceController) DeviceClass_Del() {
  2206. // 验证登录
  2207. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  2208. if !b_ {
  2209. c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  2210. c.ServeJSON()
  2211. return
  2212. }
  2213. id, _ := c.GetInt("Id")
  2214. class_r, err := Device.Read_Class_ById(id)
  2215. if err != nil {
  2216. c.Data["json"] = lib.JSONS{Code: 202, Msg: "id Err!"}
  2217. c.ServeJSON()
  2218. return
  2219. }
  2220. if class_r.T_uuid != admin_r.Admin_uuid {
  2221. c.Data["json"] = lib.JSONS{Code: 203, Msg: "T_uuid Err!"}
  2222. c.ServeJSON()
  2223. return
  2224. }
  2225. Device.Delete_Class_ById(id)
  2226. DeviceSensor_class_list := Device.Read_DeviceSensor_ALL_class_1(id)
  2227. for _, v := range DeviceSensor_class_list {
  2228. Device.DeviceSensor_Bind_Del(v.T_sn, v.T_id, id)
  2229. }
  2230. System.Add_UserLogs(admin_r.Admin_uuid, "设备管理", "删除分类操作", strconv.Itoa(id))
  2231. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  2232. c.ServeJSON()
  2233. return
  2234. }
  2235. func (c *DeviceController) V2_Class_Del() {
  2236. // 验证登录
  2237. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  2238. if !b_ {
  2239. c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  2240. c.ServeJSON()
  2241. return
  2242. }
  2243. id, _ := c.GetInt("T_id")
  2244. class_r, err := Device.Read_Class_ById(id)
  2245. if err != nil {
  2246. c.Data["json"] = lib.JSONS{Code: 202, Msg: "id Err!"}
  2247. c.ServeJSON()
  2248. return
  2249. }
  2250. if class_r.T_uuid != admin_r.Admin_uuid {
  2251. c.Data["json"] = lib.JSONS{Code: 203, Msg: "T_uuid Err!"}
  2252. c.ServeJSON()
  2253. return
  2254. }
  2255. Device.Delete_Class_ById(id)
  2256. DeviceSensor_class_list := Device.Read_DeviceSensor_ALL_class_1(id)
  2257. for _, v := range DeviceSensor_class_list {
  2258. Device.DeviceSensor_Bind_Del(v.T_sn, v.T_id, id)
  2259. }
  2260. System.Add_UserLogs(admin_r.Admin_uuid, "设备管理", "删除分类操作", strconv.Itoa(id))
  2261. // 同步分类
  2262. DataList, _ := Admin.Read_v2_Admin_List(admin_r.Id, "", 0, 9999)
  2263. for _, v := range DataList {
  2264. V2_Class_Syn(admin_r, v)
  2265. }
  2266. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  2267. c.ServeJSON()
  2268. return
  2269. }
  2270. func (c *DeviceController) DeviceClass_Syn() {
  2271. // 验证登录
  2272. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  2273. if !b_ {
  2274. c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  2275. c.ServeJSON()
  2276. return
  2277. }
  2278. s_, user_r := Admin.Read_Admin_ByAdmin_uuid(c.GetString("Admin_uuid"))
  2279. if s_ != nil {
  2280. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Admin_uuid Err!"}
  2281. c.ServeJSON()
  2282. return
  2283. }
  2284. // 先全部 清掉
  2285. Device.Device_Bind_ALL_Del(user_r)
  2286. class_r := Device.Read_DeviceClass_ALL_T_uuid_1(user_r.Admin_uuid)
  2287. for _, v := range class_r {
  2288. fmt.Println("清掉:", v.Id)
  2289. // 删除分类
  2290. Device.Delete_Class_ById(v.Id)
  2291. // 删除 传感器分类
  2292. Device.DeviceSensor_T_Calss_ALL_Del(v.Id)
  2293. //Device.DeviceSensor_T_Bind_ALL_Del(user_r)
  2294. }
  2295. // 重新插入 分类
  2296. num_x := 0
  2297. class_r = Device.Read_DeviceClass_ALL_T_uuid_1(admin_r.Admin_uuid)
  2298. for _, v := range class_r {
  2299. fmt.Println("插入:", v.Id)
  2300. t_c := Device.DeviceClass{
  2301. T_uuid: user_r.Admin_uuid,
  2302. T_name: v.T_name,
  2303. T_Notice_wx: "",
  2304. T_Notice_phone: "",
  2305. T_Notice_message: "",
  2306. T_Notice_mailbox: "",
  2307. T_State: 1,
  2308. }
  2309. num_x = num_x + 1
  2310. // 添加分类
  2311. cid, err := Device.Add_Class(t_c)
  2312. if err != nil {
  2313. c.Data["json"] = lib.JSONS{Code: 200, Msg: "Add_Class E!"}
  2314. c.ServeJSON()
  2315. return
  2316. }
  2317. fmt.Println("cid:", cid)
  2318. // 添加 传感器分类
  2319. DeviceSensor_class_list := Device.Read_DeviceSensor_ALL_class_1(int(v.Id))
  2320. for _, v_c := range DeviceSensor_class_list {
  2321. // 绑定所有分类
  2322. Device.DeviceSensor_T_Calss_Add(v_c.T_sn, v_c.T_id, int(cid))
  2323. // 绑定所有权限
  2324. //Device_r, _ := Device.Read_Device_ByT_sn(v_c.T_sn)
  2325. //Device.DeviceSensor_T_Bind_Add(v_c.T_sn, v_c.T_id, user_r)
  2326. T_Bind := Device.Device_Bind_Add(v_c.T_sn, user_r)
  2327. Device.DeviceSensor_T_Bind_ALL(v_c.T_sn, T_Bind)
  2328. }
  2329. //
  2330. }
  2331. System.Add_UserLogs(admin_r.Admin_uuid, "设备管理", "同步分类操作", "->"+user_r.Admin_uuid)
  2332. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: num_x}
  2333. c.ServeJSON()
  2334. return
  2335. }
  2336. func V2_Class_Syn(admin_r Admin.Admin, user_r Admin.Admin) {
  2337. //验证登录
  2338. //b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  2339. //if !b_ {
  2340. // c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  2341. // c.ServeJSON()
  2342. // return
  2343. //}
  2344. //s_, user_r := Admin.Read_Admin_ByAdmin_uuid(c.GetString("T_uuid"))
  2345. //if s_ != nil {
  2346. // c.Data["json"] = lib.JSONS{Code: 202, Msg: "Admin_uuid Err!"}
  2347. // c.ServeJSON()
  2348. // return
  2349. //}
  2350. // 先全部 清掉
  2351. Device.Device_Bind_ALL_Del(user_r)
  2352. class_r := Device.Read_DeviceClass_ALL_T_uuid_1(user_r.Admin_uuid)
  2353. for _, v := range class_r {
  2354. fmt.Println("清掉:", v.Id)
  2355. // 删除分类
  2356. Device.Delete_Class_ById(v.Id)
  2357. // 删除 传感器分类
  2358. Device.DeviceSensor_T_Calss_ALL_Del(v.Id)
  2359. //Device.DeviceSensor_T_Bind_ALL_Del(user_r)
  2360. }
  2361. // 重新插入 分类
  2362. num_x := 0
  2363. class_r = Device.Read_DeviceClass_ALL_T_uuid_1(admin_r.Admin_uuid)
  2364. for _, v := range class_r {
  2365. fmt.Println("插入:", v.Id)
  2366. t_c := Device.DeviceClass{
  2367. T_uuid: user_r.Admin_uuid,
  2368. T_name: v.T_name,
  2369. T_Notice_wx: "",
  2370. T_Notice_phone: "",
  2371. T_Notice_message: "",
  2372. T_Notice_mailbox: "",
  2373. T_State: 1,
  2374. }
  2375. num_x = num_x + 1
  2376. // 添加分类
  2377. cid, err := Device.Add_Class(t_c)
  2378. if err != nil {
  2379. return
  2380. }
  2381. fmt.Println("cid:", cid)
  2382. // 添加 传感器分类
  2383. DeviceSensor_class_list := Device.Read_DeviceSensor_ALL_class_1(int(v.Id))
  2384. for _, v_c := range DeviceSensor_class_list {
  2385. // 绑定所有分类
  2386. Device.DeviceSensor_T_Calss_Add(v_c.T_sn, v_c.T_id, int(cid))
  2387. // 绑定所有权限
  2388. //Device_r, _ := Device.Read_Device_ByT_sn(v_c.T_sn)
  2389. //Device.DeviceSensor_T_Bind_Add(v_c.T_sn, v_c.T_id, user_r)
  2390. T_Bind := Device.Device_Bind_Add(v_c.T_sn, user_r)
  2391. Device.DeviceSensor_T_Bind_ALL(v_c.T_sn, T_Bind)
  2392. }
  2393. //
  2394. }
  2395. System.Add_UserLogs(admin_r.Admin_uuid, "设备管理", "同步分类操作", "->"+user_r.Admin_uuid)
  2396. return
  2397. }
  2398. func (c *DeviceController) DeviceClassBind_html_() {
  2399. // 验证登录
  2400. b_, _ := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  2401. if !b_ {
  2402. c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  2403. c.ServeJSON()
  2404. return
  2405. }
  2406. c.TplName = "Device/DeviceClassBind-.html"
  2407. }
  2408. func (c *DeviceController) DeviceClassBind_List() {
  2409. // 验证登录
  2410. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  2411. if !b_ {
  2412. c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  2413. c.ServeJSON()
  2414. return
  2415. }
  2416. type R_JSONS struct {
  2417. //必须的大写开头
  2418. DeviceSensor_lite []Device.DeviceSensor_R
  2419. Num int
  2420. Page int
  2421. Page_size int
  2422. Pages []lib.Page_T
  2423. }
  2424. var r_jsons R_JSONS
  2425. page, _ := c.GetInt("page")
  2426. println(page)
  2427. if page < 1 {
  2428. page = 1
  2429. }
  2430. Name := c.GetString("Name")
  2431. T_sn := c.GetString("T_sn")
  2432. T_calss_id, _ := c.GetInt("T_calss_id")
  2433. page_z, _ := c.GetInt("page_z")
  2434. if page_z == 0 {
  2435. page_z = conf.Page_size
  2436. }
  2437. //Name := c.GetString("Name")
  2438. //T_sn := c.GetString("T_sn")
  2439. //c.Data["Class_1"] = Class_1
  2440. ////c.Data["Name"] = Name
  2441. //c.Data["T_sn"] = T_sn
  2442. R_DeviceClass, err := Device.Read_Class_ById(T_calss_id)
  2443. if err != nil {
  2444. c.Data["json"] = lib.JSONS{Code: 205, Msg: "T_class_id Err!"}
  2445. c.ServeJSON()
  2446. return
  2447. }
  2448. if R_DeviceClass.T_uuid != admin_r.Admin_uuid {
  2449. c.Data["json"] = lib.JSONS{Code: 205, Msg: "T_class_id != Admin_uuid Err!"}
  2450. c.ServeJSON()
  2451. return
  2452. }
  2453. var cnt int64
  2454. Device_lite, cnt := Device.Read_DeviceSensor_class_ALL_1(admin_r, T_calss_id, page, page_z, T_sn, Name, "")
  2455. r_jsons.DeviceSensor_lite = Device_lite
  2456. page_size := math.Ceil(float64(cnt) / float64(page_z))
  2457. r_jsons.Page = page
  2458. r_jsons.Page_size = int(page_size)
  2459. r_jsons.Pages = lib.Func_page(int64(page), int64(page_size))
  2460. r_jsons.Num = int(cnt)
  2461. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
  2462. c.ServeJSON()
  2463. return
  2464. }
  2465. func (c *DeviceController) DeviceSensor_v2_List() {
  2466. // 验证登录
  2467. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  2468. if !b_ {
  2469. c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  2470. c.ServeJSON()
  2471. return
  2472. }
  2473. type R_JSONS struct {
  2474. //必须的大写开头
  2475. Data []Device.DeviceSensor_R
  2476. Num int64
  2477. Page int
  2478. Page_size int
  2479. }
  2480. var r_jsons R_JSONS
  2481. page, _ := c.GetInt("page")
  2482. println(page)
  2483. if page < 1 {
  2484. page = 1
  2485. }
  2486. page_z, _ := c.GetInt("page_z")
  2487. if page_z < 1 {
  2488. page_z = conf.Page_size
  2489. }
  2490. T_sn := c.GetString("T_sn")
  2491. Name := c.GetString("T_name") // 包含 T_name、T_sn
  2492. T_calss_id, _ := c.GetInt("T_calssid")
  2493. if T_calss_id > 0 {
  2494. R_DeviceClass, err := Device.Read_Class_ById(T_calss_id)
  2495. if err != nil {
  2496. c.Data["json"] = lib.JSONS{Code: 205, Msg: "T_class_id Err!"}
  2497. c.ServeJSON()
  2498. return
  2499. }
  2500. if R_DeviceClass.T_uuid != admin_r.Admin_uuid {
  2501. c.Data["json"] = lib.JSONS{Code: 205, Msg: "T_class_id != Admin_uuid Err!"}
  2502. c.ServeJSON()
  2503. return
  2504. }
  2505. }
  2506. r_jsons.Data, r_jsons.Num = Device.Read_DeviceSensor_v2_List(admin_r, T_sn, Name, T_calss_id, page, page_z)
  2507. r_jsons.Page = page
  2508. r_jsons.Page_size = int(math.Ceil(float64(r_jsons.Num) / float64(page_z)))
  2509. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
  2510. c.ServeJSON()
  2511. return
  2512. }
  2513. func (c *DeviceController) DeviceClassBind_Add() {
  2514. // 验证登录
  2515. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  2516. if !b_ {
  2517. c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  2518. c.ServeJSON()
  2519. return
  2520. }
  2521. T_class_id, _ := c.GetInt("T_class_id")
  2522. T_sn := c.GetString("T_sn")
  2523. T_id, _ := c.GetInt("T_id")
  2524. if T_class_id == 0 || T_id == 0 || len(T_sn) == 0 {
  2525. c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_sn T_id T_class_id Err!"}
  2526. c.ServeJSON()
  2527. return
  2528. }
  2529. if _, err := Device.Read_Device_ByT_sn(T_sn); err != nil {
  2530. c.Data["json"] = lib.JSONS{Code: 204, Msg: "T_id Err!"}
  2531. c.ServeJSON()
  2532. return
  2533. }
  2534. R_DeviceClass, err := Device.Read_Class_ById(T_class_id)
  2535. if err != nil {
  2536. c.Data["json"] = lib.JSONS{Code: 205, Msg: "T_class_id Err!"}
  2537. c.ServeJSON()
  2538. return
  2539. }
  2540. if R_DeviceClass.T_uuid != admin_r.Admin_uuid {
  2541. c.Data["json"] = lib.JSONS{Code: 205, Msg: "T_class_id != Admin_uuid Err!"}
  2542. c.ServeJSON()
  2543. return
  2544. }
  2545. DeviceSensor_class_list := Device.Read_DeviceSensor_ALL_T_sn_T_id_class_1(T_sn, T_id, T_class_id)
  2546. if len(DeviceSensor_class_list) > 0 {
  2547. c.Data["json"] = lib.JSONS{Code: 203, Msg: "ok!"}
  2548. c.ServeJSON()
  2549. return
  2550. }
  2551. Device.DeviceSensor_T_Calss_Add(T_sn, T_id, T_class_id)
  2552. System.Add_UserLogs(admin_r.Admin_uuid, "设备管理", "分类绑定操作", strconv.Itoa(T_class_id)+"+>"+T_sn+"-"+strconv.Itoa(T_id))
  2553. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  2554. c.ServeJSON()
  2555. return
  2556. }
  2557. func (c *DeviceController) V2_ClassBind_Add() {
  2558. // 验证登录
  2559. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  2560. if !b_ {
  2561. c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  2562. c.ServeJSON()
  2563. return
  2564. }
  2565. T_class_id, _ := c.GetInt("T_class_id")
  2566. T_sn := c.GetString("T_sn")
  2567. T_id, _ := c.GetInt("T_id")
  2568. if T_class_id == 0 || T_id == 0 || len(T_sn) == 0 {
  2569. c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_sn T_id T_class_id Err!"}
  2570. c.ServeJSON()
  2571. return
  2572. }
  2573. if _, err := Device.Read_Device_ByT_sn(T_sn); err != nil {
  2574. c.Data["json"] = lib.JSONS{Code: 204, Msg: "T_id Err!"}
  2575. c.ServeJSON()
  2576. return
  2577. }
  2578. R_DeviceClass, err := Device.Read_Class_ById(T_class_id)
  2579. if err != nil {
  2580. c.Data["json"] = lib.JSONS{Code: 205, Msg: "T_class_id Err!"}
  2581. c.ServeJSON()
  2582. return
  2583. }
  2584. if R_DeviceClass.T_uuid != admin_r.Admin_uuid {
  2585. c.Data["json"] = lib.JSONS{Code: 205, Msg: "T_class_id != Admin_uuid Err!"}
  2586. c.ServeJSON()
  2587. return
  2588. }
  2589. DeviceSensor_class_list := Device.Read_DeviceSensor_ALL_T_sn_T_id_class_1(T_sn, T_id, T_class_id)
  2590. if len(DeviceSensor_class_list) > 0 {
  2591. c.Data["json"] = lib.JSONS{Code: 203, Msg: "ok!"}
  2592. c.ServeJSON()
  2593. return
  2594. }
  2595. Device.DeviceSensor_T_Calss_Add(T_sn, T_id, T_class_id)
  2596. System.Add_UserLogs(admin_r.Admin_uuid, "设备管理", "分类绑定操作", strconv.Itoa(T_class_id)+"+>"+T_sn+"-"+strconv.Itoa(T_id))
  2597. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  2598. c.ServeJSON()
  2599. return
  2600. }
  2601. func (c *DeviceController) DeviceClassBind_Del() {
  2602. // 验证登录
  2603. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  2604. if !b_ {
  2605. c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  2606. c.ServeJSON()
  2607. return
  2608. }
  2609. T_class_id, _ := c.GetInt("T_class_id")
  2610. T_sn := c.GetString("T_sn")
  2611. T_id, _ := c.GetInt("T_id")
  2612. if T_class_id == 0 || T_id == 0 || len(T_sn) == 0 {
  2613. c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_sn T_id T_class_id Err!"}
  2614. c.ServeJSON()
  2615. return
  2616. }
  2617. if _, err := Device.Read_Device_ByT_sn(T_sn); err != nil {
  2618. c.Data["json"] = lib.JSONS{Code: 204, Msg: "T_id Err!"}
  2619. c.ServeJSON()
  2620. return
  2621. }
  2622. R_DeviceClass, err := Device.Read_Class_ById(T_class_id)
  2623. if err != nil {
  2624. c.Data["json"] = lib.JSONS{Code: 205, Msg: "T_class_id Err!"}
  2625. c.ServeJSON()
  2626. return
  2627. }
  2628. if R_DeviceClass.T_uuid != admin_r.Admin_uuid {
  2629. c.Data["json"] = lib.JSONS{Code: 205, Msg: "T_class_id != Admin_uuid Err!"}
  2630. c.ServeJSON()
  2631. return
  2632. }
  2633. DeviceSensor_class_list := Device.Read_DeviceSensor_ALL_T_sn_T_id_class_1(T_sn, T_id, T_class_id)
  2634. if len(DeviceSensor_class_list) == 0 {
  2635. c.Data["json"] = lib.JSONS{Code: 203, Msg: "ok!"}
  2636. c.ServeJSON()
  2637. return
  2638. }
  2639. Device.DeviceSensor_Bind_Del(T_sn, T_id, T_class_id)
  2640. System.Add_UserLogs(admin_r.Admin_uuid, "设备管理", "分类删除绑定操作", strconv.Itoa(T_class_id)+"->"+T_sn+"-"+strconv.Itoa(T_id))
  2641. // 同步分类
  2642. DataList, _ := Admin.Read_v2_Admin_List(admin_r.Id, "", 0, 9999)
  2643. for _, v := range DataList {
  2644. V2_Class_Syn(admin_r, v)
  2645. }
  2646. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  2647. c.ServeJSON()
  2648. return
  2649. }
  2650. func (c *DeviceController) V2_ClassBind_Del() {
  2651. // 验证登录
  2652. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  2653. if !b_ {
  2654. c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  2655. c.ServeJSON()
  2656. return
  2657. }
  2658. T_class_id, _ := c.GetInt("T_class_id")
  2659. T_sn := c.GetString("T_sn")
  2660. T_id, _ := c.GetInt("T_id")
  2661. if T_class_id == 0 || T_id == 0 || len(T_sn) == 0 {
  2662. c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_sn T_id T_class_id Err!"}
  2663. c.ServeJSON()
  2664. return
  2665. }
  2666. if _, err := Device.Read_Device_ByT_sn(T_sn); err != nil {
  2667. c.Data["json"] = lib.JSONS{Code: 204, Msg: "T_id Err!"}
  2668. c.ServeJSON()
  2669. return
  2670. }
  2671. R_DeviceClass, err := Device.Read_Class_ById(T_class_id)
  2672. if err != nil {
  2673. c.Data["json"] = lib.JSONS{Code: 205, Msg: "T_class_id Err!"}
  2674. c.ServeJSON()
  2675. return
  2676. }
  2677. if R_DeviceClass.T_uuid != admin_r.Admin_uuid {
  2678. c.Data["json"] = lib.JSONS{Code: 205, Msg: "T_class_id != Admin_uuid Err!"}
  2679. c.ServeJSON()
  2680. return
  2681. }
  2682. DeviceSensor_class_list := Device.Read_DeviceSensor_ALL_T_sn_T_id_class_1(T_sn, T_id, T_class_id)
  2683. if len(DeviceSensor_class_list) == 0 {
  2684. c.Data["json"] = lib.JSONS{Code: 203, Msg: "ok!"}
  2685. c.ServeJSON()
  2686. return
  2687. }
  2688. Device.DeviceSensor_Bind_Del(T_sn, T_id, T_class_id)
  2689. System.Add_UserLogs(admin_r.Admin_uuid, "设备管理", "分类删除绑定操作", strconv.Itoa(T_class_id)+"->"+T_sn+"-"+strconv.Itoa(T_id))
  2690. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  2691. c.ServeJSON()
  2692. return
  2693. }
  2694. func (c *DeviceController) Get_DeviceClassId() {
  2695. // 验证登录
  2696. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  2697. if !b_ {
  2698. c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  2699. c.ServeJSON()
  2700. return
  2701. }
  2702. T_class_id, _ := c.GetInt("T_class_id")
  2703. R_DeviceClass, err := Device.Read_Class_ById(T_class_id)
  2704. if err != nil {
  2705. c.Data["json"] = lib.JSONS{Code: 201, Msg: "T_class_id Err!"}
  2706. c.ServeJSON()
  2707. return
  2708. }
  2709. if R_DeviceClass.T_uuid != admin_r.Admin_uuid {
  2710. c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_class_id != T_uuid Err!"}
  2711. c.ServeJSON()
  2712. return
  2713. }
  2714. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: R_DeviceClass}
  2715. c.ServeJSON()
  2716. return
  2717. }
  2718. // 任务列表
  2719. func (c *DeviceController) DeviceTask_List() {
  2720. // 验证登录
  2721. b_, _ := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  2722. if !b_ {
  2723. c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  2724. c.ServeJSON()
  2725. return
  2726. }
  2727. T_sn := c.GetString("T_sn")
  2728. Time_end := c.GetString("Time_end")
  2729. Time_start := c.GetString("Time_start")
  2730. DeviceTask_lite, _ := Device.Read_DeviceTask_All_50(T_sn, Time_end, Time_start)
  2731. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: DeviceTask_lite}
  2732. c.ServeJSON()
  2733. return
  2734. }
  2735. // 任务列表
  2736. func (c *DeviceController) DeviceTask_Post() {
  2737. // 验证登录
  2738. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  2739. if !b_ {
  2740. c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  2741. c.ServeJSON()
  2742. return
  2743. }
  2744. T_sn := c.GetString("T_sn")
  2745. T_task := c.GetString("T_task")
  2746. NatsServer.Set_DeviceTask(Device.Device_task{
  2747. T_sn: T_sn,
  2748. T_task: T_task,
  2749. })
  2750. System.Add_UserLogs(admin_r.Admin_uuid, "设备管理", "远程启停", T_sn+"-"+T_task)
  2751. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  2752. c.ServeJSON()
  2753. return
  2754. }
  2755. func (c *DeviceController) Get_DeviceClassId_QRCode() {
  2756. // 验证登录
  2757. b_, _ := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  2758. if !b_ {
  2759. c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  2760. c.ServeJSON()
  2761. return
  2762. }
  2763. T_calss_id := c.GetString("T_class_id")
  2764. if len(T_calss_id) == 0 {
  2765. c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_calss_id Err!"}
  2766. c.ServeJSON()
  2767. return
  2768. }
  2769. T_calss_id_str, _ := NatsServer.Wx_GenerateQRCode("-|" + lib.AesEncryptCBC(T_calss_id, "0123456789012345") + "|- @宝智达 微信公众号通知")
  2770. if len(T_calss_id_str) == 0 {
  2771. c.Data["json"] = lib.JSONS{Code: 201, Msg: "Err!"}
  2772. c.ServeJSON()
  2773. return
  2774. }
  2775. type Text struct {
  2776. QR string
  2777. Code string
  2778. }
  2779. T_calss_id_str = "https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=" + T_calss_id_str
  2780. Text_r := Text{
  2781. QR: T_calss_id_str,
  2782. Code: "请将本内容发送到 深圳市宝智达科技有限公司 微信公众号-|" + lib.AesEncryptCBC(T_calss_id, "0123456789012345") + "|- @宝智达 微信公众号通知 ",
  2783. }
  2784. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: Text_r}
  2785. c.ServeJSON()
  2786. return
  2787. }
  2788. func (c *DeviceController) Get_DeviceClassId_QRCode2() {
  2789. // 验证登录
  2790. b_, _ := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  2791. if !b_ {
  2792. c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  2793. c.ServeJSON()
  2794. return
  2795. }
  2796. T_calss_id := c.GetString("T_class_id")
  2797. if len(T_calss_id) == 0 {
  2798. c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_calss_id Err!"}
  2799. c.ServeJSON()
  2800. return
  2801. }
  2802. T_calss_id_str, _ := NatsServer.Wx_GenerateQRCode2("-|" + lib.AesEncryptCBC(T_calss_id, "0123456789012345") + "|- @宝智达 微信公众号通知")
  2803. if len(T_calss_id_str) == 0 {
  2804. c.Data["json"] = lib.JSONS{Code: 201, Msg: "Err!"}
  2805. c.ServeJSON()
  2806. return
  2807. }
  2808. type Text struct {
  2809. QR string
  2810. Code string
  2811. }
  2812. T_calss_id_str = "https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=" + T_calss_id_str
  2813. Text_r := Text{
  2814. QR: T_calss_id_str,
  2815. Code: "请将本内容发送到 宝智达冷链科技有限公司 微信公众号-|" + lib.AesEncryptCBC(T_calss_id, "0123456789012345") + "|- @宝智达 微信公众号通知 ",
  2816. }
  2817. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: Text_r}
  2818. c.ServeJSON()
  2819. return
  2820. }
  2821. func (c *DeviceController) DeviceData_Add() {
  2822. // 验证登录
  2823. if c.GetString("Tokey") != "1f9db553" {
  2824. c.Data["json"] = lib.JSONS{Code: 201, Msg: "Tokey Err!"}
  2825. c.ServeJSON()
  2826. return
  2827. }
  2828. T_sn := c.GetString("T_sn")
  2829. T_name := c.GetString("T_name")
  2830. T_id, _ := c.GetInt("T_id")
  2831. T_t, _ := c.GetFloat("T_t")
  2832. T_rh, _ := c.GetFloat("T_rh")
  2833. T_Tlower, _ := c.GetFloat("T_Tlower")
  2834. T_Tupper, _ := c.GetFloat("T_Tupper")
  2835. T_RHlower, _ := c.GetFloat("T_RHlower")
  2836. T_RHupper, _ := c.GetFloat("T_RHupper")
  2837. T_Site := c.GetString("T_Site")
  2838. T_Dattery, _ := c.GetInt("T_Dattery")
  2839. T_time, err := time.Parse("2006-01-02 15:04:05", c.GetString("T_time"))
  2840. if err != nil {
  2841. c.Data["json"] = lib.JSONS{Code: 201, Msg: "T_time Err!"}
  2842. c.ServeJSON()
  2843. return
  2844. }
  2845. //// 更新记录 - 缓存
  2846. DeviceData_t := Device.DeviceData_T{
  2847. T_name: T_name,
  2848. T_id: T_id,
  2849. T_t: float32(T_t),
  2850. T_rh: float32(T_rh),
  2851. T_Tlower: float32(T_Tlower),
  2852. T_Tupper: float32(T_Tupper),
  2853. T_RHlower: float32(T_RHlower),
  2854. T_RHupper: float32(T_RHupper),
  2855. T_Site: T_Site,
  2856. T_Dattery: T_Dattery,
  2857. T_time: T_time,
  2858. }
  2859. if !Device.Add_DeviceData(T_sn, DeviceData_t) {
  2860. c.Data["json"] = lib.JSONS{Code: 201, Msg: "Err!"}
  2861. c.ServeJSON()
  2862. return
  2863. }
  2864. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  2865. c.ServeJSON()
  2866. return
  2867. }
  2868. // 列表 - 设备日志
  2869. func (c *DeviceController) DeviceLogs() {
  2870. page, _ := c.GetInt("page")
  2871. println(page)
  2872. if page < 1 {
  2873. page = 1
  2874. }
  2875. T_sn := c.GetString("T_sn")
  2876. c.Data["T_sn"] = T_sn
  2877. var cnt int64
  2878. c.Data["List"], cnt = System.Read_DeviceLogs_ALL(page, T_sn)
  2879. page_size := math.Ceil(float64(cnt) / float64(conf.Page_size))
  2880. c.Data["Page"] = page
  2881. c.Data["Page_size"] = page_size
  2882. c.Data["Pages"] = lib.Func_page(int64(page), int64(page_size))
  2883. c.Data["cnt"] = cnt
  2884. c.TplName = "Device/DeviceLogs.html"
  2885. }