Device.go 89 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279
  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_, _ := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  2027. if !b_ {
  2028. c.Ctx.Redirect(302, "Login")
  2029. return
  2030. }
  2031. id, _ := c.GetInt("T_id")
  2032. T, _ := Device.Read_Class_ById(id)
  2033. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: Device.DeviceClassToDeviceClass_R(T)}
  2034. c.ServeJSON()
  2035. return
  2036. }
  2037. func (c *DeviceController) DeviceClass_Post() {
  2038. // 验证登录
  2039. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  2040. if !b_ {
  2041. c.Ctx.Redirect(302, "Login")
  2042. return
  2043. }
  2044. Id, _ := c.GetInt("Id")
  2045. T_name := c.GetString("T_name")
  2046. T_Notice_wx := c.GetString("T_Notice_wx")
  2047. T_Notice_wx2 := c.GetString("T_Notice_wx2")
  2048. T_Notice_phone := c.GetString("T_Notice_phone")
  2049. T_Notice_message := c.GetString("T_Notice_message")
  2050. T_Notice_mailbox := c.GetString("T_Notice_mailbox")
  2051. T_Notice_mechanism := c.GetString("T_Notice_mechanism")
  2052. t_c := Device.DeviceClass{
  2053. Id: Id,
  2054. T_name: T_name,
  2055. T_Notice_wx: T_Notice_wx,
  2056. T_Notice_wx2: T_Notice_wx2,
  2057. T_Notice_phone: T_Notice_phone,
  2058. T_Notice_message: T_Notice_message,
  2059. T_Notice_mailbox: T_Notice_mailbox,
  2060. T_Notice_mechanism: T_Notice_mechanism,
  2061. }
  2062. if Id == 0 {
  2063. t_c.T_State = 1
  2064. t_c.T_uuid = admin_r.Admin_uuid
  2065. t_c.T_Notice_wx = ""
  2066. t_c.T_Notice_wx2 = ""
  2067. t_c.T_Notice_phone = ""
  2068. t_c.T_Notice_message = ""
  2069. t_c.T_Notice_mailbox = ""
  2070. t_c.T_Notice_mechanism = Device.Read_DeviceWarningList_All_T_Notice_mechanism()
  2071. Device.Add_Class(t_c)
  2072. } else {
  2073. t_c.T_uuid = admin_r.Admin_uuid
  2074. Device.Update_Class_ById(t_c)
  2075. }
  2076. System.Add_UserLogs_T(admin_r.Admin_uuid, "设备管理", "分类操作", t_c)
  2077. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  2078. c.ServeJSON()
  2079. return
  2080. }
  2081. func (c *DeviceController) V2_Class_Add() {
  2082. // 验证登录
  2083. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  2084. if !b_ {
  2085. c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  2086. c.ServeJSON()
  2087. return
  2088. }
  2089. T_name := c.GetString("T_name")
  2090. t_c := Device.DeviceClass{
  2091. T_uuid: admin_r.Admin_uuid,
  2092. T_name: T_name,
  2093. T_Notice_mechanism: Device.Read_DeviceWarningList_All_T_Notice_mechanism(),
  2094. T_State: 1,
  2095. }
  2096. Device.Add_Class(t_c)
  2097. System.Add_UserLogs_T(admin_r.Admin_uuid, "分类管理", "分类添加", t_c)
  2098. // 同步分类
  2099. DataList, _ := Admin.Read_v2_Admin_List(admin_r.Id, "", 0, 9999)
  2100. for _, v := range DataList {
  2101. V2_Class_Syn(admin_r, v)
  2102. }
  2103. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  2104. c.ServeJSON()
  2105. return
  2106. }
  2107. func (c *DeviceController) V2_Class_Edit() {
  2108. // 验证登录
  2109. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  2110. if !b_ {
  2111. c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  2112. c.ServeJSON()
  2113. return
  2114. }
  2115. Id, _ := c.GetInt("T_id")
  2116. T_name := c.GetString("T_name")
  2117. T_Notice_wx := c.GetString("T_Notice_wx")
  2118. T_Notice_wx2 := c.GetString("T_Notice_wx2")
  2119. T_Notice_phone := c.GetString("T_Notice_phone")
  2120. T_Notice_message := c.GetString("T_Notice_message")
  2121. T_Notice_mailbox := c.GetString("T_Notice_mailbox")
  2122. T_Notice_mechanism := c.GetString("T_Notice_mechanism")
  2123. R_DeviceClass, err := Device.Read_Class_ById(Id)
  2124. if err != nil {
  2125. c.Data["json"] = lib.JSONS{Code: 203, Msg: "T_id Err!"}
  2126. c.ServeJSON()
  2127. return
  2128. }
  2129. if R_DeviceClass.T_uuid != admin_r.Admin_uuid {
  2130. c.Data["json"] = lib.JSONS{Code: 203, Msg: "T_id Err!"}
  2131. c.ServeJSON()
  2132. return
  2133. }
  2134. R_DeviceClass.Id = Id
  2135. R_DeviceClass.T_name = T_name
  2136. R_DeviceClass.T_Notice_wx = T_Notice_wx
  2137. R_DeviceClass.T_Notice_wx2 = T_Notice_wx2
  2138. R_DeviceClass.T_Notice_phone = T_Notice_phone
  2139. R_DeviceClass.T_Notice_message = T_Notice_message
  2140. R_DeviceClass.T_Notice_mailbox = T_Notice_mailbox
  2141. R_DeviceClass.T_Notice_mechanism = T_Notice_mechanism
  2142. 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")
  2143. System.Add_UserLogs_T(admin_r.Admin_uuid, "设备管理", "分类操作", R_DeviceClass)
  2144. // 同步分类
  2145. DataList, _ := Admin.Read_v2_Admin_List(admin_r.Id, "", 0, 9999)
  2146. for _, v := range DataList {
  2147. V2_Class_Syn(admin_r, v)
  2148. }
  2149. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  2150. c.ServeJSON()
  2151. return
  2152. }
  2153. func (c *DeviceController) DeviceWarningList_T_Tips() {
  2154. // 验证登录
  2155. b_, _ := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  2156. if !b_ {
  2157. c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  2158. c.ServeJSON()
  2159. return
  2160. }
  2161. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: Device.Read_DeviceWarningList_All_T_Notice_mechanism()}
  2162. c.ServeJSON()
  2163. return
  2164. }
  2165. func (c *DeviceController) DeviceClass_Del() {
  2166. // 验证登录
  2167. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  2168. if !b_ {
  2169. c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  2170. c.ServeJSON()
  2171. return
  2172. }
  2173. id, _ := c.GetInt("Id")
  2174. class_r, err := Device.Read_Class_ById(id)
  2175. if err != nil {
  2176. c.Data["json"] = lib.JSONS{Code: 202, Msg: "id Err!"}
  2177. c.ServeJSON()
  2178. return
  2179. }
  2180. if class_r.T_uuid != admin_r.Admin_uuid {
  2181. c.Data["json"] = lib.JSONS{Code: 203, Msg: "T_uuid Err!"}
  2182. c.ServeJSON()
  2183. return
  2184. }
  2185. Device.Delete_Class_ById(id)
  2186. DeviceSensor_class_list := Device.Read_DeviceSensor_ALL_class_1(id)
  2187. for _, v := range DeviceSensor_class_list {
  2188. Device.DeviceSensor_Bind_Del(v.T_sn, v.T_id, id)
  2189. }
  2190. System.Add_UserLogs(admin_r.Admin_uuid, "设备管理", "删除分类操作", strconv.Itoa(id))
  2191. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  2192. c.ServeJSON()
  2193. return
  2194. }
  2195. func (c *DeviceController) V2_Class_Del() {
  2196. // 验证登录
  2197. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  2198. if !b_ {
  2199. c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  2200. c.ServeJSON()
  2201. return
  2202. }
  2203. id, _ := c.GetInt("T_id")
  2204. class_r, err := Device.Read_Class_ById(id)
  2205. if err != nil {
  2206. c.Data["json"] = lib.JSONS{Code: 202, Msg: "id Err!"}
  2207. c.ServeJSON()
  2208. return
  2209. }
  2210. if class_r.T_uuid != admin_r.Admin_uuid {
  2211. c.Data["json"] = lib.JSONS{Code: 203, Msg: "T_uuid Err!"}
  2212. c.ServeJSON()
  2213. return
  2214. }
  2215. Device.Delete_Class_ById(id)
  2216. DeviceSensor_class_list := Device.Read_DeviceSensor_ALL_class_1(id)
  2217. for _, v := range DeviceSensor_class_list {
  2218. Device.DeviceSensor_Bind_Del(v.T_sn, v.T_id, id)
  2219. }
  2220. System.Add_UserLogs(admin_r.Admin_uuid, "设备管理", "删除分类操作", strconv.Itoa(id))
  2221. // 同步分类
  2222. DataList, _ := Admin.Read_v2_Admin_List(admin_r.Id, "", 0, 9999)
  2223. for _, v := range DataList {
  2224. V2_Class_Syn(admin_r, v)
  2225. }
  2226. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  2227. c.ServeJSON()
  2228. return
  2229. }
  2230. func (c *DeviceController) DeviceClass_Syn() {
  2231. // 验证登录
  2232. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  2233. if !b_ {
  2234. c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  2235. c.ServeJSON()
  2236. return
  2237. }
  2238. s_, user_r := Admin.Read_Admin_ByAdmin_uuid(c.GetString("Admin_uuid"))
  2239. if s_ != nil {
  2240. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Admin_uuid Err!"}
  2241. c.ServeJSON()
  2242. return
  2243. }
  2244. // 先全部 清掉
  2245. Device.Device_Bind_ALL_Del(user_r)
  2246. class_r := Device.Read_DeviceClass_ALL_T_uuid_1(user_r.Admin_uuid)
  2247. for _, v := range class_r {
  2248. fmt.Println("清掉:", v.Id)
  2249. // 删除分类
  2250. Device.Delete_Class_ById(v.Id)
  2251. // 删除 传感器分类
  2252. Device.DeviceSensor_T_Calss_ALL_Del(v.Id)
  2253. //Device.DeviceSensor_T_Bind_ALL_Del(user_r)
  2254. }
  2255. // 重新插入 分类
  2256. num_x := 0
  2257. class_r = Device.Read_DeviceClass_ALL_T_uuid_1(admin_r.Admin_uuid)
  2258. for _, v := range class_r {
  2259. fmt.Println("插入:", v.Id)
  2260. t_c := Device.DeviceClass{
  2261. T_uuid: user_r.Admin_uuid,
  2262. T_name: v.T_name,
  2263. T_Notice_wx: "",
  2264. T_Notice_phone: "",
  2265. T_Notice_message: "",
  2266. T_Notice_mailbox: "",
  2267. T_State: 1,
  2268. }
  2269. num_x = num_x + 1
  2270. // 添加分类
  2271. cid, err := Device.Add_Class(t_c)
  2272. if err != nil {
  2273. c.Data["json"] = lib.JSONS{Code: 200, Msg: "Add_Class E!"}
  2274. c.ServeJSON()
  2275. return
  2276. }
  2277. fmt.Println("cid:", cid)
  2278. // 添加 传感器分类
  2279. DeviceSensor_class_list := Device.Read_DeviceSensor_ALL_class_1(int(v.Id))
  2280. for _, v_c := range DeviceSensor_class_list {
  2281. // 绑定所有分类
  2282. Device.DeviceSensor_T_Calss_Add(v_c.T_sn, v_c.T_id, int(cid))
  2283. // 绑定所有权限
  2284. //Device_r, _ := Device.Read_Device_ByT_sn(v_c.T_sn)
  2285. //Device.DeviceSensor_T_Bind_Add(v_c.T_sn, v_c.T_id, user_r)
  2286. T_Bind := Device.Device_Bind_Add(v_c.T_sn, user_r)
  2287. Device.DeviceSensor_T_Bind_ALL(v_c.T_sn, T_Bind)
  2288. }
  2289. //
  2290. }
  2291. System.Add_UserLogs(admin_r.Admin_uuid, "设备管理", "同步分类操作", "->"+user_r.Admin_uuid)
  2292. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: num_x}
  2293. c.ServeJSON()
  2294. return
  2295. }
  2296. func V2_Class_Syn(admin_r Admin.Admin, user_r Admin.Admin) {
  2297. //验证登录
  2298. //b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  2299. //if !b_ {
  2300. // c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  2301. // c.ServeJSON()
  2302. // return
  2303. //}
  2304. //s_, user_r := Admin.Read_Admin_ByAdmin_uuid(c.GetString("T_uuid"))
  2305. //if s_ != nil {
  2306. // c.Data["json"] = lib.JSONS{Code: 202, Msg: "Admin_uuid Err!"}
  2307. // c.ServeJSON()
  2308. // return
  2309. //}
  2310. // 先全部 清掉
  2311. Device.Device_Bind_ALL_Del(user_r)
  2312. class_r := Device.Read_DeviceClass_ALL_T_uuid_1(user_r.Admin_uuid)
  2313. for _, v := range class_r {
  2314. fmt.Println("清掉:", v.Id)
  2315. // 删除分类
  2316. Device.Delete_Class_ById(v.Id)
  2317. // 删除 传感器分类
  2318. Device.DeviceSensor_T_Calss_ALL_Del(v.Id)
  2319. //Device.DeviceSensor_T_Bind_ALL_Del(user_r)
  2320. }
  2321. // 重新插入 分类
  2322. num_x := 0
  2323. class_r = Device.Read_DeviceClass_ALL_T_uuid_1(admin_r.Admin_uuid)
  2324. for _, v := range class_r {
  2325. fmt.Println("插入:", v.Id)
  2326. t_c := Device.DeviceClass{
  2327. T_uuid: user_r.Admin_uuid,
  2328. T_name: v.T_name,
  2329. T_Notice_wx: "",
  2330. T_Notice_phone: "",
  2331. T_Notice_message: "",
  2332. T_Notice_mailbox: "",
  2333. T_State: 1,
  2334. }
  2335. num_x = num_x + 1
  2336. // 添加分类
  2337. cid, err := Device.Add_Class(t_c)
  2338. if err != nil {
  2339. return
  2340. }
  2341. fmt.Println("cid:", cid)
  2342. // 添加 传感器分类
  2343. DeviceSensor_class_list := Device.Read_DeviceSensor_ALL_class_1(int(v.Id))
  2344. for _, v_c := range DeviceSensor_class_list {
  2345. // 绑定所有分类
  2346. Device.DeviceSensor_T_Calss_Add(v_c.T_sn, v_c.T_id, int(cid))
  2347. // 绑定所有权限
  2348. //Device_r, _ := Device.Read_Device_ByT_sn(v_c.T_sn)
  2349. //Device.DeviceSensor_T_Bind_Add(v_c.T_sn, v_c.T_id, user_r)
  2350. T_Bind := Device.Device_Bind_Add(v_c.T_sn, user_r)
  2351. Device.DeviceSensor_T_Bind_ALL(v_c.T_sn, T_Bind)
  2352. }
  2353. //
  2354. }
  2355. System.Add_UserLogs(admin_r.Admin_uuid, "设备管理", "同步分类操作", "->"+user_r.Admin_uuid)
  2356. return
  2357. }
  2358. func (c *DeviceController) DeviceClassBind_html_() {
  2359. // 验证登录
  2360. b_, _ := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  2361. if !b_ {
  2362. c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  2363. c.ServeJSON()
  2364. return
  2365. }
  2366. c.TplName = "Device/DeviceClassBind-.html"
  2367. }
  2368. func (c *DeviceController) DeviceClassBind_List() {
  2369. // 验证登录
  2370. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  2371. if !b_ {
  2372. c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  2373. c.ServeJSON()
  2374. return
  2375. }
  2376. type R_JSONS struct {
  2377. //必须的大写开头
  2378. DeviceSensor_lite []Device.DeviceSensor_R
  2379. Num int
  2380. Page int
  2381. Page_size int
  2382. Pages []lib.Page_T
  2383. }
  2384. var r_jsons R_JSONS
  2385. page, _ := c.GetInt("page")
  2386. println(page)
  2387. if page < 1 {
  2388. page = 1
  2389. }
  2390. Name := c.GetString("Name")
  2391. T_sn := c.GetString("T_sn")
  2392. T_calss_id, _ := c.GetInt("T_calss_id")
  2393. page_z, _ := c.GetInt("page_z")
  2394. if page_z == 0 {
  2395. page_z = conf.Page_size
  2396. }
  2397. //Name := c.GetString("Name")
  2398. //T_sn := c.GetString("T_sn")
  2399. //c.Data["Class_1"] = Class_1
  2400. ////c.Data["Name"] = Name
  2401. //c.Data["T_sn"] = T_sn
  2402. R_DeviceClass, err := Device.Read_Class_ById(T_calss_id)
  2403. if err != nil {
  2404. c.Data["json"] = lib.JSONS{Code: 205, Msg: "T_class_id Err!"}
  2405. c.ServeJSON()
  2406. return
  2407. }
  2408. if R_DeviceClass.T_uuid != admin_r.Admin_uuid {
  2409. c.Data["json"] = lib.JSONS{Code: 205, Msg: "T_class_id != Admin_uuid Err!"}
  2410. c.ServeJSON()
  2411. return
  2412. }
  2413. var cnt int64
  2414. Device_lite, cnt := Device.Read_DeviceSensor_class_ALL_1(admin_r, T_calss_id, page, page_z, T_sn, Name, "")
  2415. r_jsons.DeviceSensor_lite = Device_lite
  2416. page_size := math.Ceil(float64(cnt) / float64(page_z))
  2417. r_jsons.Page = page
  2418. r_jsons.Page_size = int(page_size)
  2419. r_jsons.Pages = lib.Func_page(int64(page), int64(page_size))
  2420. r_jsons.Num = int(cnt)
  2421. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
  2422. c.ServeJSON()
  2423. return
  2424. }
  2425. func (c *DeviceController) DeviceSensor_v2_List() {
  2426. // 验证登录
  2427. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  2428. if !b_ {
  2429. c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  2430. c.ServeJSON()
  2431. return
  2432. }
  2433. type R_JSONS struct {
  2434. //必须的大写开头
  2435. Data []Device.DeviceSensor_R
  2436. Num int64
  2437. Page int
  2438. Page_size int
  2439. }
  2440. var r_jsons R_JSONS
  2441. page, _ := c.GetInt("page")
  2442. println(page)
  2443. if page < 1 {
  2444. page = 1
  2445. }
  2446. page_z, _ := c.GetInt("page_z")
  2447. if page_z < 1 {
  2448. page_z = conf.Page_size
  2449. }
  2450. T_sn := c.GetString("T_sn")
  2451. Name := c.GetString("T_name") // 包含 T_name、T_sn
  2452. T_calss_id, _ := c.GetInt("T_calssid")
  2453. if T_calss_id > 0 {
  2454. R_DeviceClass, err := Device.Read_Class_ById(T_calss_id)
  2455. if err != nil {
  2456. c.Data["json"] = lib.JSONS{Code: 205, Msg: "T_class_id Err!"}
  2457. c.ServeJSON()
  2458. return
  2459. }
  2460. if R_DeviceClass.T_uuid != admin_r.Admin_uuid {
  2461. c.Data["json"] = lib.JSONS{Code: 205, Msg: "T_class_id != Admin_uuid Err!"}
  2462. c.ServeJSON()
  2463. return
  2464. }
  2465. }
  2466. r_jsons.Data, r_jsons.Num = Device.Read_DeviceSensor_v2_List(admin_r, T_sn, Name, T_calss_id, page, page_z)
  2467. r_jsons.Page = page
  2468. r_jsons.Page_size = int(math.Ceil(float64(r_jsons.Num) / float64(page_z)))
  2469. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
  2470. c.ServeJSON()
  2471. return
  2472. }
  2473. func (c *DeviceController) DeviceClassBind_Add() {
  2474. // 验证登录
  2475. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  2476. if !b_ {
  2477. c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  2478. c.ServeJSON()
  2479. return
  2480. }
  2481. T_class_id, _ := c.GetInt("T_class_id")
  2482. T_sn := c.GetString("T_sn")
  2483. T_id, _ := c.GetInt("T_id")
  2484. if T_class_id == 0 || T_id == 0 || len(T_sn) == 0 {
  2485. c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_sn T_id T_class_id Err!"}
  2486. c.ServeJSON()
  2487. return
  2488. }
  2489. if _, err := Device.Read_Device_ByT_sn(T_sn); err != nil {
  2490. c.Data["json"] = lib.JSONS{Code: 204, Msg: "T_id Err!"}
  2491. c.ServeJSON()
  2492. return
  2493. }
  2494. R_DeviceClass, err := Device.Read_Class_ById(T_class_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. DeviceSensor_class_list := Device.Read_DeviceSensor_ALL_T_sn_T_id_class_1(T_sn, T_id, T_class_id)
  2506. if len(DeviceSensor_class_list) > 0 {
  2507. c.Data["json"] = lib.JSONS{Code: 203, Msg: "ok!"}
  2508. c.ServeJSON()
  2509. return
  2510. }
  2511. Device.DeviceSensor_T_Calss_Add(T_sn, T_id, T_class_id)
  2512. System.Add_UserLogs(admin_r.Admin_uuid, "设备管理", "分类绑定操作", strconv.Itoa(T_class_id)+"+>"+T_sn+"-"+strconv.Itoa(T_id))
  2513. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  2514. c.ServeJSON()
  2515. return
  2516. }
  2517. func (c *DeviceController) V2_ClassBind_Add() {
  2518. // 验证登录
  2519. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  2520. if !b_ {
  2521. c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  2522. c.ServeJSON()
  2523. return
  2524. }
  2525. T_class_id, _ := c.GetInt("T_class_id")
  2526. T_sn := c.GetString("T_sn")
  2527. T_id, _ := c.GetInt("T_id")
  2528. if T_class_id == 0 || T_id == 0 || len(T_sn) == 0 {
  2529. c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_sn T_id T_class_id Err!"}
  2530. c.ServeJSON()
  2531. return
  2532. }
  2533. if _, err := Device.Read_Device_ByT_sn(T_sn); err != nil {
  2534. c.Data["json"] = lib.JSONS{Code: 204, Msg: "T_id Err!"}
  2535. c.ServeJSON()
  2536. return
  2537. }
  2538. R_DeviceClass, err := Device.Read_Class_ById(T_class_id)
  2539. if err != nil {
  2540. c.Data["json"] = lib.JSONS{Code: 205, Msg: "T_class_id Err!"}
  2541. c.ServeJSON()
  2542. return
  2543. }
  2544. if R_DeviceClass.T_uuid != admin_r.Admin_uuid {
  2545. c.Data["json"] = lib.JSONS{Code: 205, Msg: "T_class_id != Admin_uuid Err!"}
  2546. c.ServeJSON()
  2547. return
  2548. }
  2549. DeviceSensor_class_list := Device.Read_DeviceSensor_ALL_T_sn_T_id_class_1(T_sn, T_id, T_class_id)
  2550. if len(DeviceSensor_class_list) > 0 {
  2551. c.Data["json"] = lib.JSONS{Code: 203, Msg: "ok!"}
  2552. c.ServeJSON()
  2553. return
  2554. }
  2555. Device.DeviceSensor_T_Calss_Add(T_sn, T_id, T_class_id)
  2556. System.Add_UserLogs(admin_r.Admin_uuid, "设备管理", "分类绑定操作", strconv.Itoa(T_class_id)+"+>"+T_sn+"-"+strconv.Itoa(T_id))
  2557. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  2558. c.ServeJSON()
  2559. return
  2560. }
  2561. func (c *DeviceController) DeviceClassBind_Del() {
  2562. // 验证登录
  2563. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  2564. if !b_ {
  2565. c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  2566. c.ServeJSON()
  2567. return
  2568. }
  2569. T_class_id, _ := c.GetInt("T_class_id")
  2570. T_sn := c.GetString("T_sn")
  2571. T_id, _ := c.GetInt("T_id")
  2572. if T_class_id == 0 || T_id == 0 || len(T_sn) == 0 {
  2573. c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_sn T_id T_class_id Err!"}
  2574. c.ServeJSON()
  2575. return
  2576. }
  2577. if _, err := Device.Read_Device_ByT_sn(T_sn); err != nil {
  2578. c.Data["json"] = lib.JSONS{Code: 204, Msg: "T_id Err!"}
  2579. c.ServeJSON()
  2580. return
  2581. }
  2582. R_DeviceClass, err := Device.Read_Class_ById(T_class_id)
  2583. if err != nil {
  2584. c.Data["json"] = lib.JSONS{Code: 205, Msg: "T_class_id Err!"}
  2585. c.ServeJSON()
  2586. return
  2587. }
  2588. if R_DeviceClass.T_uuid != admin_r.Admin_uuid {
  2589. c.Data["json"] = lib.JSONS{Code: 205, Msg: "T_class_id != Admin_uuid Err!"}
  2590. c.ServeJSON()
  2591. return
  2592. }
  2593. DeviceSensor_class_list := Device.Read_DeviceSensor_ALL_T_sn_T_id_class_1(T_sn, T_id, T_class_id)
  2594. if len(DeviceSensor_class_list) == 0 {
  2595. c.Data["json"] = lib.JSONS{Code: 203, Msg: "ok!"}
  2596. c.ServeJSON()
  2597. return
  2598. }
  2599. Device.DeviceSensor_Bind_Del(T_sn, T_id, T_class_id)
  2600. System.Add_UserLogs(admin_r.Admin_uuid, "设备管理", "分类删除绑定操作", strconv.Itoa(T_class_id)+"->"+T_sn+"-"+strconv.Itoa(T_id))
  2601. // 同步分类
  2602. DataList, _ := Admin.Read_v2_Admin_List(admin_r.Id, "", 0, 9999)
  2603. for _, v := range DataList {
  2604. V2_Class_Syn(admin_r, v)
  2605. }
  2606. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  2607. c.ServeJSON()
  2608. return
  2609. }
  2610. func (c *DeviceController) V2_ClassBind_Del() {
  2611. // 验证登录
  2612. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  2613. if !b_ {
  2614. c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  2615. c.ServeJSON()
  2616. return
  2617. }
  2618. T_class_id, _ := c.GetInt("T_class_id")
  2619. T_sn := c.GetString("T_sn")
  2620. T_id, _ := c.GetInt("T_id")
  2621. if T_class_id == 0 || T_id == 0 || len(T_sn) == 0 {
  2622. c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_sn T_id T_class_id Err!"}
  2623. c.ServeJSON()
  2624. return
  2625. }
  2626. if _, err := Device.Read_Device_ByT_sn(T_sn); err != nil {
  2627. c.Data["json"] = lib.JSONS{Code: 204, Msg: "T_id Err!"}
  2628. c.ServeJSON()
  2629. return
  2630. }
  2631. R_DeviceClass, err := Device.Read_Class_ById(T_class_id)
  2632. if err != nil {
  2633. c.Data["json"] = lib.JSONS{Code: 205, Msg: "T_class_id Err!"}
  2634. c.ServeJSON()
  2635. return
  2636. }
  2637. if R_DeviceClass.T_uuid != admin_r.Admin_uuid {
  2638. c.Data["json"] = lib.JSONS{Code: 205, Msg: "T_class_id != Admin_uuid Err!"}
  2639. c.ServeJSON()
  2640. return
  2641. }
  2642. DeviceSensor_class_list := Device.Read_DeviceSensor_ALL_T_sn_T_id_class_1(T_sn, T_id, T_class_id)
  2643. if len(DeviceSensor_class_list) == 0 {
  2644. c.Data["json"] = lib.JSONS{Code: 203, Msg: "ok!"}
  2645. c.ServeJSON()
  2646. return
  2647. }
  2648. Device.DeviceSensor_Bind_Del(T_sn, T_id, T_class_id)
  2649. System.Add_UserLogs(admin_r.Admin_uuid, "设备管理", "分类删除绑定操作", strconv.Itoa(T_class_id)+"->"+T_sn+"-"+strconv.Itoa(T_id))
  2650. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  2651. c.ServeJSON()
  2652. return
  2653. }
  2654. func (c *DeviceController) Get_DeviceClassId() {
  2655. // 验证登录
  2656. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  2657. if !b_ {
  2658. c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  2659. c.ServeJSON()
  2660. return
  2661. }
  2662. T_class_id, _ := c.GetInt("T_class_id")
  2663. R_DeviceClass, err := Device.Read_Class_ById(T_class_id)
  2664. if err != nil {
  2665. c.Data["json"] = lib.JSONS{Code: 201, Msg: "T_class_id Err!"}
  2666. c.ServeJSON()
  2667. return
  2668. }
  2669. if R_DeviceClass.T_uuid != admin_r.Admin_uuid {
  2670. c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_class_id != T_uuid Err!"}
  2671. c.ServeJSON()
  2672. return
  2673. }
  2674. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: R_DeviceClass}
  2675. c.ServeJSON()
  2676. return
  2677. }
  2678. // 任务列表
  2679. func (c *DeviceController) DeviceTask_List() {
  2680. // 验证登录
  2681. b_, _ := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  2682. if !b_ {
  2683. c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  2684. c.ServeJSON()
  2685. return
  2686. }
  2687. T_sn := c.GetString("T_sn")
  2688. Time_end := c.GetString("Time_end")
  2689. Time_start := c.GetString("Time_start")
  2690. DeviceTask_lite, _ := Device.Read_DeviceTask_All_50(T_sn, Time_end, Time_start)
  2691. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: DeviceTask_lite}
  2692. c.ServeJSON()
  2693. return
  2694. }
  2695. // 任务列表
  2696. func (c *DeviceController) DeviceTask_Post() {
  2697. // 验证登录
  2698. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  2699. if !b_ {
  2700. c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  2701. c.ServeJSON()
  2702. return
  2703. }
  2704. T_sn := c.GetString("T_sn")
  2705. T_task := c.GetString("T_task")
  2706. NatsServer.Set_DeviceTask(Device.Device_task{
  2707. T_sn: T_sn,
  2708. T_task: T_task,
  2709. })
  2710. System.Add_UserLogs(admin_r.Admin_uuid, "设备管理", "远程启停", T_sn+"-"+T_task)
  2711. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  2712. c.ServeJSON()
  2713. return
  2714. }
  2715. func (c *DeviceController) Get_DeviceClassId_QRCode() {
  2716. // 验证登录
  2717. b_, _ := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  2718. if !b_ {
  2719. c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  2720. c.ServeJSON()
  2721. return
  2722. }
  2723. T_calss_id := c.GetString("T_class_id")
  2724. if len(T_calss_id) == 0 {
  2725. c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_calss_id Err!"}
  2726. c.ServeJSON()
  2727. return
  2728. }
  2729. T_calss_id_str, _ := NatsServer.Wx_GenerateQRCode("-|" + lib.AesEncryptCBC(T_calss_id, "0123456789012345") + "|- @宝智达 微信公众号通知")
  2730. if len(T_calss_id_str) == 0 {
  2731. c.Data["json"] = lib.JSONS{Code: 201, Msg: "Err!"}
  2732. c.ServeJSON()
  2733. return
  2734. }
  2735. type Text struct {
  2736. QR string
  2737. Code string
  2738. }
  2739. T_calss_id_str = "https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=" + T_calss_id_str
  2740. Text_r := Text{
  2741. QR: T_calss_id_str,
  2742. Code: "请将本内容发送到 深圳市宝智达科技有限公司 微信公众号-|" + lib.AesEncryptCBC(T_calss_id, "0123456789012345") + "|- @宝智达 微信公众号通知 ",
  2743. }
  2744. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: Text_r}
  2745. c.ServeJSON()
  2746. return
  2747. }
  2748. func (c *DeviceController) Get_DeviceClassId_QRCode2() {
  2749. // 验证登录
  2750. b_, _ := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  2751. if !b_ {
  2752. c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  2753. c.ServeJSON()
  2754. return
  2755. }
  2756. T_calss_id := c.GetString("T_class_id")
  2757. if len(T_calss_id) == 0 {
  2758. c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_calss_id Err!"}
  2759. c.ServeJSON()
  2760. return
  2761. }
  2762. T_calss_id_str, _ := NatsServer.Wx_GenerateQRCode2("-|" + lib.AesEncryptCBC(T_calss_id, "0123456789012345") + "|- @宝智达 微信公众号通知")
  2763. if len(T_calss_id_str) == 0 {
  2764. c.Data["json"] = lib.JSONS{Code: 201, Msg: "Err!"}
  2765. c.ServeJSON()
  2766. return
  2767. }
  2768. type Text struct {
  2769. QR string
  2770. Code string
  2771. }
  2772. T_calss_id_str = "https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=" + T_calss_id_str
  2773. Text_r := Text{
  2774. QR: T_calss_id_str,
  2775. Code: "请将本内容发送到 宝智达冷链科技有限公司 微信公众号-|" + lib.AesEncryptCBC(T_calss_id, "0123456789012345") + "|- @宝智达 微信公众号通知 ",
  2776. }
  2777. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: Text_r}
  2778. c.ServeJSON()
  2779. return
  2780. }
  2781. func (c *DeviceController) DeviceData_Add() {
  2782. // 验证登录
  2783. if c.GetString("Tokey") != "1f9db553" {
  2784. c.Data["json"] = lib.JSONS{Code: 201, Msg: "Tokey Err!"}
  2785. c.ServeJSON()
  2786. return
  2787. }
  2788. T_sn := c.GetString("T_sn")
  2789. T_name := c.GetString("T_name")
  2790. T_id, _ := c.GetInt("T_id")
  2791. T_t, _ := c.GetFloat("T_t")
  2792. T_rh, _ := c.GetFloat("T_rh")
  2793. T_Tlower, _ := c.GetFloat("T_Tlower")
  2794. T_Tupper, _ := c.GetFloat("T_Tupper")
  2795. T_RHlower, _ := c.GetFloat("T_RHlower")
  2796. T_RHupper, _ := c.GetFloat("T_RHupper")
  2797. T_Site := c.GetString("T_Site")
  2798. T_Dattery, _ := c.GetInt("T_Dattery")
  2799. T_time, err := time.Parse("2006-01-02 15:04:05", c.GetString("T_time"))
  2800. if err != nil {
  2801. c.Data["json"] = lib.JSONS{Code: 201, Msg: "T_time Err!"}
  2802. c.ServeJSON()
  2803. return
  2804. }
  2805. //// 更新记录 - 缓存
  2806. DeviceData_t := Device.DeviceData_T{
  2807. T_name: T_name,
  2808. T_id: T_id,
  2809. T_t: float32(T_t),
  2810. T_rh: float32(T_rh),
  2811. T_Tlower: float32(T_Tlower),
  2812. T_Tupper: float32(T_Tupper),
  2813. T_RHlower: float32(T_RHlower),
  2814. T_RHupper: float32(T_RHupper),
  2815. T_Site: T_Site,
  2816. T_Dattery: T_Dattery,
  2817. T_time: T_time,
  2818. }
  2819. if !Device.Add_DeviceData(T_sn, DeviceData_t) {
  2820. c.Data["json"] = lib.JSONS{Code: 201, Msg: "Err!"}
  2821. c.ServeJSON()
  2822. return
  2823. }
  2824. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  2825. c.ServeJSON()
  2826. return
  2827. }
  2828. // 列表 - 设备日志
  2829. func (c *DeviceController) DeviceLogs() {
  2830. page, _ := c.GetInt("page")
  2831. println(page)
  2832. if page < 1 {
  2833. page = 1
  2834. }
  2835. T_sn := c.GetString("T_sn")
  2836. c.Data["T_sn"] = T_sn
  2837. var cnt int64
  2838. c.Data["List"], cnt = System.Read_DeviceLogs_ALL(page, T_sn)
  2839. page_size := math.Ceil(float64(cnt) / float64(conf.Page_size))
  2840. c.Data["Page"] = page
  2841. c.Data["Page_size"] = page_size
  2842. c.Data["Pages"] = lib.Func_page(int64(page), int64(page_size))
  2843. c.Data["cnt"] = cnt
  2844. c.TplName = "Device/DeviceLogs.html"
  2845. }