Device.go 92 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395
  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("User_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. T_enprel, _ := c.GetInt("T_enprel")
  1081. T_tprel, _ := c.GetFloat("T_tprel")
  1082. T_tpreu, _ := c.GetFloat("T_tpreu")
  1083. T_hprel, _ := c.GetFloat("T_hprel")
  1084. T_hpreu, _ := c.GetFloat("T_hpreu")
  1085. // 权限 过滤
  1086. Admin_Power_, _ := Admin.Read_AdminPower_ById(admin_r.Admin_power)
  1087. if Admin_Power_.Power_DeviceSensor_Parameter_e == 0 {
  1088. c.Data["json"] = lib.JSONS{Code: 202, Msg: "! U" + strconv.Itoa(admin_r.Id)}
  1089. c.ServeJSON()
  1090. return
  1091. }
  1092. _, err := Device.Read_Device_ByT_sn(T_SN)
  1093. if err != nil {
  1094. c.Data["json"] = lib.JSONS{Code: 206, Msg: "T_sn Err!"}
  1095. c.ServeJSON()
  1096. return
  1097. }
  1098. DeviceSensor, is := Device.Read_DeviceSensor_ByT_sn(T_SN, T_id)
  1099. if !is {
  1100. c.Data["json"] = lib.JSONS{Code: 208, Msg: "T_sn T_id Err!"}
  1101. c.ServeJSON()
  1102. return
  1103. }
  1104. Devicesensorparameter := Device.DeviceSensorParameter{
  1105. T_sn: T_SN,
  1106. T_id: T_id,
  1107. T_name: T_name,
  1108. T_Tlower: float32(T_Tlower),
  1109. T_Tupper: float32(T_Tupper),
  1110. T_RHlower: float32(T_RHlower),
  1111. T_RHupper: float32(T_RHupper),
  1112. T_en: T_en,
  1113. T_free: T_free,
  1114. T_enprel: T_enprel,
  1115. T_tprel: float32(T_tprel),
  1116. T_tpreu: float32(T_tpreu),
  1117. T_hprel: float32(T_hprel),
  1118. T_hpreu: float32(T_hpreu),
  1119. T_uuid: admin_r.Admin_uuid,
  1120. T_SendState: 0,
  1121. T_State: 2,
  1122. }
  1123. dsp_id, is := Device.Add_DeviceSensorParameter(Devicesensorparameter)
  1124. if !is {
  1125. c.Data["json"] = lib.JSONS{Code: 209, Msg: "添加失败!"}
  1126. c.ServeJSON()
  1127. return
  1128. }
  1129. Devicesensorparameter.Id = int(dsp_id)
  1130. // 更新名称
  1131. DeviceSensor.T_name = T_name
  1132. Device.Update_DeviceSensor(DeviceSensor, "T_name")
  1133. System.Add_UserLogs_T(admin_r.Admin_uuid, "设备管理", "传感器参数操作", Devicesensorparameter)
  1134. NatsServer.Pu_DeviceParameter_Sensor(Devicesensorparameter)
  1135. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  1136. c.ServeJSON()
  1137. return
  1138. }
  1139. ////
  1140. //func (c *DeviceController) Pu_DeviceParameter_Sensor_Cache() {
  1141. // // 验证登录
  1142. // b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  1143. // if !b_ {
  1144. // c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  1145. // c.ServeJSON()
  1146. // return
  1147. // }
  1148. //
  1149. // T_SN := c.GetString("SN")
  1150. // T_id := c.GetString("T_id")
  1151. // _, err := Device.Read_Device_ByT_sn(T_SN)
  1152. // if err != nil {
  1153. // c.Data["json"] = lib.JSONS{Code: 206, Msg: "T_sn Err!"}
  1154. // c.ServeJSON()
  1155. // return
  1156. // }
  1157. // Admin_Power_, _ := Admin.Read_AdminPower_ById(admin_r.Admin_power)
  1158. // if Admin_Power_.Power_DeviceSensor_Compensate_e == 0 {
  1159. // c.Data["json"] = lib.JSONS{Code: 202, Msg: "! U" + strconv.Itoa(admin_r.Id)}
  1160. // c.ServeJSON()
  1161. // return
  1162. // }
  1163. //
  1164. // T_sensor_list := c.GetString("T_sensor_list")
  1165. // jsonStu_map_ := strings.Replace(string(T_sensor_list), "\"{", "{", -1)
  1166. // jsonStu_map_ = strings.Replace(jsonStu_map_, "}\"", "}", -1)
  1167. // jsonStu_map_ = strings.Replace(jsonStu_map_, "\\\"", "\"", -1)
  1168. // println("jsonStu_map_:", jsonStu_map_)
  1169. // var Rt_parameter_sensor_ []MqttServer.Rt_Parameter_Sensor_
  1170. // err = json.Unmarshal([]byte(jsonStu_map_), &Rt_parameter_sensor_)
  1171. // if err != nil {
  1172. // c.Data["json"] = lib.JSONS{Code: 204, Msg: "T_sensor_list Err!"}
  1173. // c.ServeJSON()
  1174. // return
  1175. // }
  1176. // DeviceSensor,is := Device.Read_DeviceSensor_ByT_sn(T_SN, Rt_parameter_sensor_[0].T_id)
  1177. // if is {
  1178. // DeviceSensor.T_name = Rt_parameter_sensor_[0].T_name
  1179. // Device.Update_TDeviceSensor(DeviceSensor,"T_name")
  1180. // }
  1181. //
  1182. // Device.Redis_DeviceSensorParameterCache_Set(T_SN+"_"+T_id,jsonStu_map_)
  1183. // //Handle.Pu_DeviceParameter_Sensor(admin_r.Admin_uuid, T_SN, Rt_parameter_sensor_)
  1184. // System.Add_UserLogs(admin_r.Admin_uuid,"设备管理", "传感器参数操作-离线操作", jsonStu_map_)
  1185. // c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  1186. // c.ServeJSON()
  1187. // return
  1188. //
  1189. //}
  1190. // 列表 -
  1191. func (c *DeviceController) DeviceWarning_List_html() {
  1192. // 验证登录
  1193. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  1194. if !b_ {
  1195. c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  1196. c.ServeJSON()
  1197. return
  1198. }
  1199. c.Data["Admin_r"] = admin_r
  1200. page, _ := c.GetInt("page")
  1201. println(page)
  1202. if page < 1 {
  1203. page = 1
  1204. }
  1205. c.Data["Admin_r"] = admin_r
  1206. T_Name := c.GetString("T_Name")
  1207. //T_sn := c.GetString("T_sn")
  1208. Time_start := c.GetString("Time_start")
  1209. Time_end := c.GetString("Time_end")
  1210. if len(Time_start) == 0 && len(Time_end) == 0 {
  1211. Time_start = time.Now().Format("2006-01-02") + " 00:00:00"
  1212. Time_end = time.Now().Format("2006-01-02") + " 23:59:59"
  1213. }
  1214. c.Data["Time_start"] = Time_start
  1215. c.Data["Time_end"] = Time_end
  1216. c.Data["T_Name"] = T_Name
  1217. //c.Data["Class_List"] = Device.Read_DeviceWarningList_All_1()
  1218. //T_Title := ""
  1219. //if Class_1 > 0 {
  1220. // T_Title = Device.Read_DeviceWarningList_ById(Class_1).T_name
  1221. //}
  1222. var cnt int64
  1223. DeviceWarning_List, cnt := Device.Read_DeviceWarning_1(admin_r, page, "", T_Name, Time_start, Time_end)
  1224. //for i, v := range DeviceWarning_List {
  1225. // DeviceWarning_List[i].T_State = 0
  1226. // if strings.Contains(v.T_sn, "YD") {
  1227. // DeviceWarning_List[i].T_State = 1
  1228. // }
  1229. //}
  1230. c.Data["List"] = DeviceWarning_List
  1231. page_size := math.Ceil(float64(cnt) / float64(conf.Page_size))
  1232. c.Data["Page"] = page
  1233. c.Data["Page_size"] = page_size
  1234. c.Data["Pages"] = lib.Func_page(int64(page), int64(page_size))
  1235. c.Data["cnt"] = cnt
  1236. c.TplName = "Device/DeviceWarning.html"
  1237. }
  1238. // 列表 -
  1239. func (c *DeviceController) DeviceWarning_List() {
  1240. // 验证登录
  1241. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  1242. if !b_ {
  1243. c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  1244. c.ServeJSON()
  1245. return
  1246. }
  1247. type R_JSONS struct {
  1248. //必须的大写开头
  1249. DeviceWarning []Device.DeviceWarning
  1250. //DeviceWarningclass []Device.DeviceWarningList
  1251. Num int
  1252. Page int
  1253. Page_size int
  1254. Pages []lib.Page_T
  1255. }
  1256. var r_jsons R_JSONS
  1257. page, _ := c.GetInt("page")
  1258. println(page)
  1259. if page < 1 {
  1260. page = 1
  1261. }
  1262. T_sn := c.GetString("T_sn")
  1263. //T_sn := c.GetString("Sn")
  1264. //Class_1, _ := c.GetInt("Class_1")
  1265. T_Name := c.GetString("T_Name")
  1266. Time_start := c.GetString("Time_start")
  1267. Time_end := c.GetString("Time_end")
  1268. //r_jsons.DeviceWarningclass = Device.Read_DeviceWarningList_All_1()
  1269. //T_Title := ""
  1270. //if Class_1 > 0 {
  1271. // T_Title = Device.Read_DeviceWarningList_ById(Class_1).T_name
  1272. //}
  1273. var cnt int64
  1274. r_jsons.DeviceWarning, cnt = Device.Read_DeviceWarning_1(admin_r, page, T_sn, T_Name, Time_start, Time_end)
  1275. page_size := math.Ceil(float64(cnt) / float64(conf.Page_size))
  1276. r_jsons.Page = int(page)
  1277. r_jsons.Page_size = int(page_size)
  1278. r_jsons.Pages = lib.Func_page(int64(page), int64(page_size))
  1279. r_jsons.Num = int(cnt)
  1280. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
  1281. c.ServeJSON()
  1282. return
  1283. }
  1284. // 列表 -
  1285. func (c *DeviceController) V2_DeviceWarning_List() {
  1286. // 验证登录
  1287. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  1288. if !b_ {
  1289. c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  1290. c.ServeJSON()
  1291. return
  1292. }
  1293. type R_JSONS struct {
  1294. //必须的大写开头
  1295. Data []Device.DeviceWarning
  1296. Num int64
  1297. Page int
  1298. Page_size int
  1299. }
  1300. var r_jsons R_JSONS
  1301. page, _ := c.GetInt("page")
  1302. println(page)
  1303. if page < 1 {
  1304. page = 1
  1305. }
  1306. page_z, _ := c.GetInt("page_z")
  1307. if page_z < 1 {
  1308. page_z = conf.Page_size
  1309. }
  1310. T_sn := c.GetString("T_sn")
  1311. T_id := c.GetString("T_id")
  1312. T_title := c.GetString("T_title")
  1313. Time_start := c.GetString("Time_start")
  1314. Time_end := c.GetString("Time_end")
  1315. T_handle, _ := c.GetInt("T_handle")
  1316. //r_jsons.DeviceWarningclass = Device.Read_DeviceWarningList_All_1()
  1317. //T_Title := ""
  1318. //if Class_1 > 0 {
  1319. // T_Title = Device.Read_DeviceWarningList_ById(Class_1).T_name
  1320. //}
  1321. r_jsons.Data, r_jsons.Num = Device.Read_DeviceWarning(admin_r, T_sn, T_id, T_title, T_handle, Time_start, Time_end, page, page_z)
  1322. r_jsons.Page = page
  1323. r_jsons.Page_size = int(math.Ceil(float64(r_jsons.Num) / float64(page_z)))
  1324. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
  1325. c.ServeJSON()
  1326. return
  1327. }
  1328. // 列表 -
  1329. func (c *DeviceController) DeviceWarning_Data_Excel() {
  1330. // 验证登录
  1331. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  1332. if !b_ {
  1333. c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  1334. c.ServeJSON()
  1335. return
  1336. }
  1337. //T_sn := c.GetString("T_sn")
  1338. Class_1, _ := c.GetInt("Class_1")
  1339. T_Name := c.GetString("T_Name")
  1340. Time_start := c.GetString("Time_start")
  1341. Time_end := c.GetString("Time_end")
  1342. c.Data["Class_1"] = Class_1
  1343. if len(Time_start) == 0 && len(Time_end) == 0 {
  1344. Time_start = time.Now().Format("2006-01-02") + " 00:00:00"
  1345. Time_end = time.Now().Format("2006-01-02") + " 23:59:59"
  1346. }
  1347. //
  1348. //T_Title := ""
  1349. //if Class_1 > 0 {
  1350. // T_Title = Device.Read_DeviceWarningList_ById(Class_1).T_name
  1351. //}
  1352. Device_data, _ := Device.Read_DeviceWarning_1(admin_r, 9999, "", T_Name, Time_start, Time_end)
  1353. f := excelize.NewFile() // 设置单元格的值
  1354. // 这里设置表头
  1355. f.SetCellValue("Sheet1", "A1", "报警类型")
  1356. f.SetCellValue("Sheet1", "B1", "Sn")
  1357. f.SetCellValue("Sheet1", "C1", "设备名称")
  1358. f.SetCellValue("Sheet1", "D1", "传感器")
  1359. f.SetCellValue("Sheet1", "E1", "温度℃")
  1360. f.SetCellValue("Sheet1", "F1", "湿度%")
  1361. f.SetCellValue("Sheet1", "G1", "报警内容")
  1362. f.SetCellValue("Sheet1", "H1", "记录时间")
  1363. f.SetCellValue("Sheet1", "I1", "处理")
  1364. f.SetCellValue("Sheet1", "J1", "处理时间")
  1365. // 设置列宽
  1366. f.SetColWidth("Sheet1", "A", "A", 20)
  1367. f.SetColWidth("Sheet1", "B", "B", 25)
  1368. f.SetColWidth("Sheet1", "C", "C", 30)
  1369. f.SetColWidth("Sheet1", "D", "D", 30)
  1370. f.SetColWidth("Sheet1", "E", "E", 10)
  1371. f.SetColWidth("Sheet1", "F", "F", 10)
  1372. f.SetColWidth("Sheet1", "G", "G", 30)
  1373. f.SetColWidth("Sheet1", "H", "H", 15)
  1374. f.SetColWidth("Sheet1", "I", "I", 30)
  1375. f.SetColWidth("Sheet1", "J", "J", 15)
  1376. line := 1
  1377. // 循环写入数据
  1378. for _, v := range Device_data {
  1379. line++
  1380. f.SetCellValue("Sheet1", fmt.Sprintf("A%d", line), v.T_Title)
  1381. f.SetCellValue("Sheet1", fmt.Sprintf("B%d", line), v.T_sn+"["+strconv.Itoa(v.T_Id)+"]")
  1382. f.SetCellValue("Sheet1", fmt.Sprintf("C%d", line), v.T_Addr)
  1383. f.SetCellValue("Sheet1", fmt.Sprintf("D%d", line), v.T_Name)
  1384. f.SetCellValue("Sheet1", fmt.Sprintf("E%d", line), v.T_T)
  1385. f.SetCellValue("Sheet1", fmt.Sprintf("F%d", line), v.T_RH)
  1386. f.SetCellValue("Sheet1", fmt.Sprintf("G%d", line), v.T_Remark)
  1387. f.SetCellValue("Sheet1", fmt.Sprintf("H%d", line), v.T_Ut)
  1388. f.SetCellValue("Sheet1", fmt.Sprintf("I%d", line), v.T_Text)
  1389. f.SetCellValue("Sheet1", fmt.Sprintf("J%d", line), v.UpdateTime)
  1390. }
  1391. timeStr := time.Now().Format("20060102150405")
  1392. // 保存文件
  1393. if err := f.SaveAs("ofile/" + timeStr + ".xlsx"); err != nil {
  1394. fmt.Println(err)
  1395. }
  1396. url, is := NatsServer.Qiniu_UploadFile(lib.GetCurrentDirectory()+"/ofile/"+timeStr+".xlsx", "ofile/"+timeStr+".xlsx")
  1397. if !is {
  1398. c.Data["json"] = lib.JSONS{Code: 203, Msg: "oss!"}
  1399. c.ServeJSON()
  1400. return
  1401. }
  1402. //删除文件
  1403. //err := os.Remove("ofile/" + timeStr + ".xlsx")
  1404. //if err != nil {
  1405. // fmt.Println(err)
  1406. //}
  1407. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: url}
  1408. c.ServeJSON()
  1409. return
  1410. }
  1411. // 列表 -
  1412. func (c *DeviceController) V2_DeviceWarning_Data_Excel() {
  1413. // 验证登录
  1414. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  1415. if !b_ {
  1416. c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  1417. c.ServeJSON()
  1418. return
  1419. }
  1420. //T_sn := c.GetString("T_sn")
  1421. T_sn := c.GetString("T_sn")
  1422. T_id := c.GetString("T_id")
  1423. T_title := c.GetString("T_title")
  1424. Time_start := c.GetString("Time_start")
  1425. Time_end := c.GetString("Time_end")
  1426. T_handle, _ := c.GetInt("T_handle")
  1427. Device_data, _ := Device.Read_DeviceWarning(admin_r, T_sn, T_id, T_title, T_handle, Time_start, Time_end, 0, 9999)
  1428. f := excelize.NewFile() // 设置单元格的值
  1429. // 这里设置表头
  1430. f.SetCellValue("Sheet1", "A1", "报警类型")
  1431. f.SetCellValue("Sheet1", "B1", "Sn")
  1432. f.SetCellValue("Sheet1", "C1", "设备名称")
  1433. f.SetCellValue("Sheet1", "D1", "传感器")
  1434. f.SetCellValue("Sheet1", "E1", "温度℃")
  1435. f.SetCellValue("Sheet1", "F1", "湿度%")
  1436. f.SetCellValue("Sheet1", "G1", "报警内容")
  1437. f.SetCellValue("Sheet1", "H1", "记录时间")
  1438. f.SetCellValue("Sheet1", "I1", "处理")
  1439. f.SetCellValue("Sheet1", "J1", "处理时间")
  1440. // 设置列宽
  1441. f.SetColWidth("Sheet1", "A", "A", 20)
  1442. f.SetColWidth("Sheet1", "B", "B", 25)
  1443. f.SetColWidth("Sheet1", "C", "C", 30)
  1444. f.SetColWidth("Sheet1", "D", "D", 30)
  1445. f.SetColWidth("Sheet1", "E", "E", 10)
  1446. f.SetColWidth("Sheet1", "F", "F", 10)
  1447. f.SetColWidth("Sheet1", "G", "G", 30)
  1448. f.SetColWidth("Sheet1", "H", "H", 15)
  1449. f.SetColWidth("Sheet1", "I", "I", 30)
  1450. f.SetColWidth("Sheet1", "J", "J", 15)
  1451. line := 1
  1452. // 循环写入数据
  1453. for _, v := range Device_data {
  1454. line++
  1455. f.SetCellValue("Sheet1", fmt.Sprintf("A%d", line), v.T_Title)
  1456. f.SetCellValue("Sheet1", fmt.Sprintf("B%d", line), v.T_sn+"["+strconv.Itoa(v.T_Id)+"]")
  1457. f.SetCellValue("Sheet1", fmt.Sprintf("C%d", line), v.T_Addr)
  1458. f.SetCellValue("Sheet1", fmt.Sprintf("D%d", line), v.T_Name)
  1459. f.SetCellValue("Sheet1", fmt.Sprintf("E%d", line), v.T_T)
  1460. f.SetCellValue("Sheet1", fmt.Sprintf("F%d", line), v.T_RH)
  1461. f.SetCellValue("Sheet1", fmt.Sprintf("G%d", line), v.T_Remark)
  1462. f.SetCellValue("Sheet1", fmt.Sprintf("H%d", line), v.T_Ut)
  1463. f.SetCellValue("Sheet1", fmt.Sprintf("I%d", line), v.T_Text)
  1464. f.SetCellValue("Sheet1", fmt.Sprintf("J%d", line), v.UpdateTime)
  1465. }
  1466. timeStr := time.Now().Format("20060102150405")
  1467. // 保存文件
  1468. if err := f.SaveAs("ofile/" + timeStr + ".xlsx"); err != nil {
  1469. fmt.Println(err)
  1470. }
  1471. url, is := NatsServer.Qiniu_UploadFile(lib.GetCurrentDirectory()+"/ofile/"+timeStr+".xlsx", "ofile/"+timeStr+".xlsx")
  1472. if !is {
  1473. c.Data["json"] = lib.JSONS{Code: 203, Msg: "oss!"}
  1474. c.ServeJSON()
  1475. return
  1476. }
  1477. //删除文件
  1478. //err := os.Remove("ofile/" + timeStr + ".xlsx")
  1479. //if err != nil {
  1480. // fmt.Println(err)
  1481. //}
  1482. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: url}
  1483. c.ServeJSON()
  1484. return
  1485. }
  1486. func (c *DeviceController) DeviceWarning_() {
  1487. id, _ := c.GetInt("id")
  1488. c.Data["T"] = Device.Read_DeviceWarning_ById(id)
  1489. c.Data["id"] = id
  1490. c.TplName = "Device/DeviceWarning-.html"
  1491. }
  1492. func (c *DeviceController) DeviceWarning_log() {
  1493. id, _ := c.GetInt("id")
  1494. T_Log := Device.Read_DeviceWarning_ById(id).T_Log
  1495. T_Log = strings.Replace(T_Log, "\n", "<hr>", -1)
  1496. c.Data["T_Log"] = T_Log
  1497. c.TplName = "Device/DeviceWarning-log.html"
  1498. }
  1499. func (c *DeviceController) V2_DeviceWarning_Get() {
  1500. // 验证登录
  1501. b_, _ := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  1502. if !b_ {
  1503. c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  1504. c.ServeJSON()
  1505. return
  1506. }
  1507. id, _ := c.GetInt("T_id")
  1508. T := Device.Read_DeviceWarning_ById(id)
  1509. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: Device.DeviceWarningToDeviceWarning_R(T)}
  1510. c.ServeJSON()
  1511. return
  1512. }
  1513. func (c *DeviceController) DeviceWarning_M() {
  1514. id := c.GetString("id")
  1515. c.Data["id"] = id
  1516. c.TplName = "Device/DeviceWarning-M.html"
  1517. }
  1518. func (c *DeviceController) DeviceWarning_Post() {
  1519. // 验证登录
  1520. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  1521. if !b_ {
  1522. c.Ctx.Redirect(302, "Login")
  1523. return
  1524. }
  1525. Id, _ := c.GetInt("Id")
  1526. T_Text := c.GetString("T_Text")
  1527. t_c := Device.DeviceWarning{
  1528. Id: Id,
  1529. T_Text: T_Text,
  1530. }
  1531. Device.Update_DeviceWarning_ById(t_c)
  1532. System.Add_UserLogs(admin_r.Admin_uuid, "设备管理", "报警处理操作", strconv.Itoa(Id)+"->"+T_Text)
  1533. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  1534. c.ServeJSON()
  1535. return
  1536. }
  1537. func (c *DeviceController) V2_DeviceWarning_Post() {
  1538. // 验证登录
  1539. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  1540. if !b_ {
  1541. c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  1542. c.ServeJSON()
  1543. return
  1544. }
  1545. Id, _ := c.GetInt("T_id")
  1546. T_Text := c.GetString("T_Text")
  1547. T := Device.Read_DeviceWarning_ById(Id)
  1548. if T.Id == 0 {
  1549. c.Data["json"] = lib.JSONS{Code: 206, Msg: "T_id Err!"}
  1550. c.ServeJSON()
  1551. return
  1552. }
  1553. T.T_Text = T_Text
  1554. T.T_State = 2
  1555. Device.Update_DeviceWarning(T, "T_Text", "T_State")
  1556. System.Add_UserLogs(admin_r.Admin_uuid, "设备管理", "报警处理操作", strconv.Itoa(Id)+"->"+T_Text)
  1557. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  1558. c.ServeJSON()
  1559. return
  1560. }
  1561. func (c *DeviceController) DeviceWarning_Del() {
  1562. // 验证登录
  1563. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  1564. if !b_ {
  1565. c.Ctx.Redirect(302, "Login")
  1566. return
  1567. }
  1568. Id, _ := c.GetInt("Id")
  1569. t_c := Device.DeviceWarning{
  1570. Id: Id,
  1571. }
  1572. Device.Update_DeviceWarning_Delete(t_c)
  1573. System.Add_UserLogs(admin_r.Admin_uuid, "设备管理", "报警删除操作", strconv.Itoa(Id))
  1574. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  1575. c.ServeJSON()
  1576. return
  1577. }
  1578. func (c *DeviceController) V2_DeviceWarning_Del() {
  1579. // 验证登录
  1580. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  1581. if !b_ {
  1582. c.Ctx.Redirect(302, "Login")
  1583. return
  1584. }
  1585. Id, _ := c.GetInt("T_id")
  1586. T := Device.Read_DeviceWarning_ById(Id)
  1587. if T.Id == 0 {
  1588. c.Data["json"] = lib.JSONS{Code: 206, Msg: "T_id Err!"}
  1589. c.ServeJSON()
  1590. return
  1591. }
  1592. T.T_State = 0
  1593. Device.Update_DeviceWarning(T, "T_State")
  1594. System.Add_UserLogs(admin_r.Admin_uuid, "设备管理", "报警删除操作", strconv.Itoa(Id))
  1595. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  1596. c.ServeJSON()
  1597. return
  1598. }
  1599. // 用户管理
  1600. func (c *DeviceController) DeviceBind_html() {
  1601. // 验证登录
  1602. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  1603. if !b_ {
  1604. c.Ctx.Redirect(302, "Login")
  1605. return
  1606. }
  1607. c.Data["Admin_Power"], _ = Admin.Read_AdminPower_ById(admin_r.Admin_power)
  1608. page, _ := c.GetInt("page")
  1609. println(page)
  1610. if page < 1 {
  1611. page = 1
  1612. }
  1613. Name := c.GetString("Name")
  1614. c.Data["Name"] = Name
  1615. c.Data["Power_List"] = Admin.Read_Power_List_ALL_Power_Administration(0)
  1616. Adminpower, _ := Admin.Read_AdminPower_ById(admin_r.Admin_power)
  1617. var cnt int64
  1618. if Adminpower.Power_User_r != 1 {
  1619. c.Ctx.Redirect(302, "Login")
  1620. return
  1621. }
  1622. c.Data["List"], cnt = Admin.Read_Admin_List_ALL_User(page, Name, admin_r.Id)
  1623. fmt.Println("cnt:", cnt)
  1624. page_size := math.Ceil(float64(cnt) / float64(conf.Page_size))
  1625. c.Data["Page"] = page
  1626. c.Data["Page_size"] = page_size
  1627. c.Data["Pages"] = lib.Func_page(int64(page), int64(page_size))
  1628. c.Data["cnt"] = cnt
  1629. c.TplName = "Device/DeviceBind.html"
  1630. }
  1631. func (c *DeviceController) DeviceBind_List() {
  1632. // 验证登录
  1633. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  1634. if !b_ {
  1635. c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  1636. c.ServeJSON()
  1637. return
  1638. }
  1639. if len(c.GetString("Admin_uuid")) > 1 {
  1640. s_, user_r := Admin.Read_Admin_ByAdmin_uuid(c.GetString("Admin_uuid"))
  1641. if s_ != nil {
  1642. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Admin_uuid Err!"}
  1643. c.ServeJSON()
  1644. return
  1645. }
  1646. admin_r = user_r
  1647. }
  1648. type R_JSONS struct {
  1649. //必须的大写开头
  1650. Device_lite []Device.Device
  1651. Num int
  1652. Page int
  1653. Page_size int
  1654. Pages []lib.Page_T
  1655. }
  1656. var r_jsons R_JSONS
  1657. page, _ := c.GetInt("page")
  1658. println(page)
  1659. if page < 1 {
  1660. page = 1
  1661. }
  1662. page_z, _ := c.GetInt("page_z")
  1663. println(page_z)
  1664. if page_z == 0 {
  1665. page_z = conf.Page_size
  1666. }
  1667. Class_1 := c.GetString("Class_1")
  1668. Name := c.GetString("Name")
  1669. T_sn := c.GetString("T_sn")
  1670. T_monitor := c.GetString("T_monitor")
  1671. T_online := c.GetString("T_online")
  1672. //Class_1, _ := c.GetInt("Class_1")
  1673. //Name := c.GetString("Name")
  1674. //T_sn := c.GetString("T_sn")
  1675. //c.Data["Class_1"] = Class_1
  1676. ////c.Data["Name"] = Name
  1677. //c.Data["T_sn"] = T_sn
  1678. var cnt int64
  1679. Device_lite, cnt := Device.Read_Device_ALL_bind_1(admin_r, page, page_z, T_sn, Name, Class_1, T_monitor, T_online)
  1680. r_jsons.Device_lite = Device_lite
  1681. page_size := math.Ceil(float64(cnt) / float64(page_z))
  1682. r_jsons.Page = page
  1683. r_jsons.Page_size = int(page_size)
  1684. r_jsons.Pages = lib.Func_page(int64(page), int64(page_size))
  1685. r_jsons.Num = int(cnt)
  1686. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
  1687. c.ServeJSON()
  1688. return
  1689. }
  1690. func (c *DeviceController) DeviceBind_Sensor_List() {
  1691. // 验证登录
  1692. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  1693. if !b_ {
  1694. c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  1695. c.ServeJSON()
  1696. return
  1697. }
  1698. if len(c.GetString("Admin_uuid")) > 1 {
  1699. s_, user_r := Admin.Read_Admin_ByAdmin_uuid(c.GetString("Admin_uuid"))
  1700. if s_ != nil {
  1701. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Admin_uuid Err!"}
  1702. c.ServeJSON()
  1703. return
  1704. }
  1705. admin_r = user_r
  1706. }
  1707. type R_JSONS struct {
  1708. //必须的大写开头
  1709. Device_lite []Device.R_Device
  1710. Num int
  1711. Page int
  1712. Page_size int
  1713. Pages []lib.Page_T
  1714. }
  1715. var r_jsons R_JSONS
  1716. page, _ := c.GetInt("page")
  1717. println(page)
  1718. if page < 1 {
  1719. page = 1
  1720. }
  1721. page_z, _ := c.GetInt("page_z")
  1722. println(page_z)
  1723. if page_z == 0 {
  1724. page_z = conf.Page_size
  1725. }
  1726. Class_1 := c.GetString("Class_1")
  1727. Name := c.GetString("Name")
  1728. T_sn := c.GetString("T_sn")
  1729. T_monitor := c.GetString("T_monitor")
  1730. T_online := c.GetString("T_online")
  1731. //Class_1, _ := c.GetInt("Class_1")
  1732. //Name := c.GetString("Name")
  1733. //T_sn := c.GetString("T_sn")
  1734. //c.Data["Class_1"] = Class_1
  1735. ////c.Data["Name"] = Name
  1736. //c.Data["T_sn"] = T_sn
  1737. var cnt int64
  1738. Device_lite, cnt := Device.Read_Device_ALL_bind_1(admin_r, page, page_z, T_sn, Name, Class_1, T_monitor, T_online)
  1739. for _, v := range Device_lite {
  1740. r_Device := Device.R_Device{}
  1741. r_Device.T_sn = v.T_sn
  1742. r_Device.T_MSISDN = v.T_MSISDN
  1743. r_Device.T_devName = v.T_devName
  1744. r_Device.T_give = v.T_give
  1745. r_Device.T_online = v.T_online
  1746. r_Device.T_monitor = v.T_monitor
  1747. r_Device.T_Dattery = v.T_Dattery
  1748. r_Device.T_protocol = v.T_protocol
  1749. r_Device.T_sensor_list, r_Device.T_sensor = Device.Read_DeviceSensor_ByTsn(v.T_sn)
  1750. r_jsons.Device_lite = append(r_jsons.Device_lite, r_Device)
  1751. }
  1752. page_size := math.Ceil(float64(cnt) / float64(page_z))
  1753. r_jsons.Page = page
  1754. r_jsons.Page_size = int(page_size)
  1755. r_jsons.Pages = lib.Func_page(int64(page), int64(page_size))
  1756. r_jsons.Num = int(cnt)
  1757. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
  1758. c.ServeJSON()
  1759. return
  1760. }
  1761. func (c *DeviceController) DeviceBind_html_() {
  1762. // 验证登录
  1763. b_, _ := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  1764. if !b_ {
  1765. c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  1766. c.ServeJSON()
  1767. return
  1768. }
  1769. c.TplName = "Device/DeviceBind-.html"
  1770. }
  1771. func (c *DeviceController) DeviceBind_Add_All() {
  1772. // 验证登录
  1773. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  1774. if !b_ {
  1775. c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  1776. c.ServeJSON()
  1777. return
  1778. }
  1779. s_, user_r := Admin.Read_Admin_ByAdmin_uuid(c.GetString("Admin_uuid"))
  1780. if s_ != nil {
  1781. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Admin_uuid Err!"}
  1782. c.ServeJSON()
  1783. return
  1784. }
  1785. Name := c.GetString("Name")
  1786. T_sn := c.GetString("T_sn")
  1787. num_x := 0
  1788. Device_l := Device.Read_Device_ALL_T_sn_T_devName_bind_1(T_sn, Name, admin_r)
  1789. fmt.Println("len(Device_l):", len(Device_l))
  1790. for _, v := range Device_l {
  1791. Device_bind_list := Device.Read_Device_ALL_T_sn_bind_1(v.T_sn, user_r)
  1792. if len(Device_bind_list) > 0 {
  1793. continue
  1794. }
  1795. T_Bind := Device.Device_Bind_Add(v.T_sn, user_r)
  1796. Device.DeviceSensor_T_Bind_ALL(v.T_sn, T_Bind)
  1797. System.Add_UserLogs(admin_r.Admin_uuid, "设备管理", "设备绑定", v.T_sn+"+>"+c.GetString("Admin_uuid"))
  1798. num_x = num_x + 1
  1799. }
  1800. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: num_x}
  1801. c.ServeJSON()
  1802. return
  1803. }
  1804. func (c *DeviceController) DeviceBind_Add() {
  1805. // 验证登录
  1806. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  1807. if !b_ {
  1808. c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  1809. c.ServeJSON()
  1810. return
  1811. }
  1812. s_, user_r := Admin.Read_Admin_ByAdmin_uuid(c.GetString("Admin_uuid"))
  1813. if s_ != nil {
  1814. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Admin_uuid Err!"}
  1815. c.ServeJSON()
  1816. return
  1817. }
  1818. T_sn := c.GetString("T_sn")
  1819. if len(T_sn) < 5 {
  1820. c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_sn Err!"}
  1821. c.ServeJSON()
  1822. return
  1823. }
  1824. _, err := Device.Read_Device_ByT_sn(T_sn)
  1825. if err != nil {
  1826. c.Data["json"] = lib.JSONS{Code: 206, Msg: "T_sn Err!"}
  1827. c.ServeJSON()
  1828. return
  1829. }
  1830. Device_bind_list := Device.Read_Device_ALL_T_sn_bind_1(T_sn, user_r)
  1831. if len(Device_bind_list) > 0 {
  1832. c.Data["json"] = lib.JSONS{Code: 203, Msg: "ok!"}
  1833. c.ServeJSON()
  1834. return
  1835. }
  1836. // 同步权限
  1837. T_Bind := Device.Device_Bind_Add(T_sn, user_r)
  1838. Device.DeviceSensor_T_Bind_ALL(T_sn, T_Bind)
  1839. System.Add_UserLogs(admin_r.Admin_uuid, "设备管理", "设备绑定", T_sn+"+>"+c.GetString("Admin_uuid"))
  1840. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  1841. c.ServeJSON()
  1842. return
  1843. }
  1844. func (c *DeviceController) V2_DeviceBind_Add() {
  1845. // 验证登录
  1846. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  1847. if !b_ {
  1848. c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  1849. c.ServeJSON()
  1850. return
  1851. }
  1852. s_, user_r := Admin.Read_Admin_ByAdmin_uuid(c.GetString("T_uuid"))
  1853. if s_ != nil {
  1854. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Admin_uuid Err!"}
  1855. c.ServeJSON()
  1856. return
  1857. }
  1858. T_sn := c.GetString("T_sn")
  1859. if len(T_sn) < 5 {
  1860. c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_sn Err!"}
  1861. c.ServeJSON()
  1862. return
  1863. }
  1864. _, err := Device.Read_Device_ByT_sn(T_sn)
  1865. if err != nil {
  1866. c.Data["json"] = lib.JSONS{Code: 206, Msg: "T_sn Err!"}
  1867. c.ServeJSON()
  1868. return
  1869. }
  1870. Device_bind_list := Device.Read_Device_ALL_T_sn_bind_1(T_sn, user_r)
  1871. if len(Device_bind_list) > 0 {
  1872. c.Data["json"] = lib.JSONS{Code: 203, Msg: "ok!"}
  1873. c.ServeJSON()
  1874. return
  1875. }
  1876. // 同步权限
  1877. T_Bind := Device.Device_Bind_Add(T_sn, user_r)
  1878. Device.DeviceSensor_T_Bind_ALL(T_sn, T_Bind)
  1879. System.Add_UserLogs(admin_r.Admin_uuid, "设备管理", "设备绑定", T_sn+"+>"+c.GetString("Admin_uuid"))
  1880. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  1881. c.ServeJSON()
  1882. return
  1883. }
  1884. func (c *DeviceController) DeviceBind_Del() {
  1885. // 验证登录
  1886. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  1887. if !b_ {
  1888. c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  1889. c.ServeJSON()
  1890. return
  1891. }
  1892. s_, user_r := Admin.Read_Admin_ByAdmin_uuid(c.GetString("Admin_uuid"))
  1893. if s_ != nil {
  1894. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Admin_uuid Err!"}
  1895. c.ServeJSON()
  1896. return
  1897. }
  1898. T_sn := c.GetString("T_sn")
  1899. if len(T_sn) < 5 {
  1900. c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_sn Err!"}
  1901. c.ServeJSON()
  1902. return
  1903. }
  1904. _, err := Device.Read_Device_ByT_sn(T_sn)
  1905. if err != nil {
  1906. c.Data["json"] = lib.JSONS{Code: 206, Msg: "T_sn Err!"}
  1907. c.ServeJSON()
  1908. return
  1909. }
  1910. Device_bind_list := Device.Read_Device_ALL_T_sn_bind_1(T_sn, user_r)
  1911. if len(Device_bind_list) == 0 {
  1912. c.Data["json"] = lib.JSONS{Code: 204, Msg: "ok!"}
  1913. c.ServeJSON()
  1914. return
  1915. }
  1916. // 同步权限
  1917. T_Bind := Device.Device_Bind_Del(T_sn, user_r)
  1918. Device.DeviceSensor_T_Bind_ALL(T_sn, T_Bind)
  1919. System.Add_UserLogs(admin_r.Admin_uuid, "设备管理", "设备解除绑定", T_sn+"->"+c.GetString("Admin_uuid"))
  1920. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  1921. c.ServeJSON()
  1922. return
  1923. }
  1924. func (c *DeviceController) V2_DeviceBind_Del() {
  1925. // 验证登录
  1926. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  1927. if !b_ {
  1928. c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  1929. c.ServeJSON()
  1930. return
  1931. }
  1932. s_, user_r := Admin.Read_Admin_ByAdmin_uuid(c.GetString("T_uuid"))
  1933. if s_ != nil {
  1934. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Admin_uuid Err!"}
  1935. c.ServeJSON()
  1936. return
  1937. }
  1938. T_sn := c.GetString("T_sn")
  1939. if len(T_sn) < 5 {
  1940. c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_sn Err!"}
  1941. c.ServeJSON()
  1942. return
  1943. }
  1944. _, err := Device.Read_Device_ByT_sn(T_sn)
  1945. if err != nil {
  1946. c.Data["json"] = lib.JSONS{Code: 206, Msg: "T_sn Err!"}
  1947. c.ServeJSON()
  1948. return
  1949. }
  1950. Device_bind_list := Device.Read_Device_ALL_T_sn_bind_1(T_sn, user_r)
  1951. if len(Device_bind_list) == 0 {
  1952. c.Data["json"] = lib.JSONS{Code: 204, Msg: "ok!"}
  1953. c.ServeJSON()
  1954. return
  1955. }
  1956. // 同步权限
  1957. T_Bind := Device.Device_Bind_Del(T_sn, user_r)
  1958. Device.DeviceSensor_T_Bind_ALL(T_sn, T_Bind)
  1959. System.Add_UserLogs(admin_r.Admin_uuid, "设备管理", "设备解除绑定", T_sn+"->"+c.GetString("Admin_uuid"))
  1960. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  1961. c.ServeJSON()
  1962. return
  1963. }
  1964. // 设备分类
  1965. func (c *DeviceController) DeviceClass_html() {
  1966. // 验证登录
  1967. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  1968. if !b_ {
  1969. c.Ctx.Redirect(302, "Login")
  1970. return
  1971. }
  1972. page, _ := c.GetInt("page")
  1973. println(page)
  1974. if page < 1 {
  1975. page = 1
  1976. }
  1977. Name := c.GetString("Name")
  1978. c.Data["Name"] = Name
  1979. var cnt int64
  1980. c.Data["List"], cnt = Device.Read_DeviceClass_ALL_1(admin_r.Admin_uuid, page, Name)
  1981. fmt.Println("cnt:", cnt)
  1982. page_size := math.Ceil(float64(cnt) / float64(conf.Page_size))
  1983. c.Data["Page"] = page
  1984. c.Data["Page_size"] = page_size
  1985. c.Data["Pages"] = lib.Func_page(int64(page), int64(page_size))
  1986. c.Data["cnt"] = cnt
  1987. c.TplName = "Device/DeviceClass.html"
  1988. }
  1989. // 分类
  1990. func (c *DeviceController) V2_Class_List() {
  1991. // 验证登录
  1992. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  1993. if !b_ {
  1994. c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  1995. c.ServeJSON()
  1996. return
  1997. }
  1998. type R_JSONS struct {
  1999. //必须的大写开头
  2000. Data []Device.DeviceClass
  2001. Num int64
  2002. Page int
  2003. Page_size int
  2004. }
  2005. var r_jsons R_JSONS
  2006. page, _ := c.GetInt("page")
  2007. println(page)
  2008. if page < 1 {
  2009. page = 1
  2010. }
  2011. page_z, _ := c.GetInt("page_z")
  2012. if page_z < 1 {
  2013. page_z = conf.Page_size
  2014. }
  2015. Name := c.GetString("T_name")
  2016. r_jsons.Data, r_jsons.Num = Device.Read_DeviceClass_ALL_1(admin_r.Admin_uuid, page, Name)
  2017. r_jsons.Page = page
  2018. r_jsons.Page_size = int(math.Ceil(float64(r_jsons.Num) / float64(page_z)))
  2019. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
  2020. c.ServeJSON()
  2021. return
  2022. }
  2023. func (c *DeviceController) DeviceClass_() {
  2024. // 验证登录
  2025. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  2026. if !b_ {
  2027. c.Ctx.Redirect(302, "Login")
  2028. return
  2029. }
  2030. id, _ := c.GetInt("id")
  2031. c.Data["T"], _ = Device.Read_Class_ById(id)
  2032. c.Data["id"] = id
  2033. c.Data["Admin_r"] = admin_r
  2034. c.TplName = "Device/DeviceClass-.html"
  2035. }
  2036. func (c *DeviceController) V2_Class_Get() {
  2037. // 验证登录
  2038. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  2039. if !b_ {
  2040. c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  2041. c.ServeJSON()
  2042. return
  2043. }
  2044. id, _ := c.GetInt("T_id")
  2045. T, err := Device.Read_Class_ById(id)
  2046. if err != nil {
  2047. c.Data["json"] = lib.JSONS{Code: 203, Msg: "T_id Err!"}
  2048. c.ServeJSON()
  2049. return
  2050. }
  2051. if admin_r.Admin_uuid != T.T_uuid {
  2052. c.Data["json"] = lib.JSONS{Code: 204, Msg: "没有权限!"}
  2053. c.ServeJSON()
  2054. return
  2055. }
  2056. type DeviceClass_R struct {
  2057. T_name string // 分类
  2058. T_Notice_wx string //w微信公众号 appid/名字|
  2059. T_Notice_wx2 string //w微信公众号 appid/名字|
  2060. T_Notice_phone string //p手机 1111111|
  2061. T_Notice_message string //m短信 1111111|
  2062. T_Notice_mailbox string //e邮箱 1111111|
  2063. T_Notice_mechanism string // 报警机制
  2064. // 湿度超下限预警,处理,w启用,数量,上限,~|
  2065. // 湿度超下限预警,0,0,0,0,0,0,0,0,0,0,0,0|
  2066. T_QRCode string // 微信二维码
  2067. T_QRCode2 string // 微信二维码(冷链)
  2068. }
  2069. var r_jsons DeviceClass_R
  2070. r_jsons.T_name = T.T_name
  2071. r_jsons.T_Notice_wx = T.T_Notice_wx
  2072. r_jsons.T_Notice_wx2 = T.T_Notice_wx2
  2073. r_jsons.T_Notice_phone = T.T_Notice_phone
  2074. r_jsons.T_Notice_message = T.T_Notice_message
  2075. r_jsons.T_Notice_mailbox = T.T_Notice_mailbox
  2076. r_jsons.T_Notice_mechanism = T.T_Notice_mechanism
  2077. // 测试环境!!!!!!!!!!!!!!!!!!!
  2078. //T_calss_id_str, _ := NatsServer.Wx_GenerateQRCode("-|" + lib.AesEncryptCBC(strconv.Itoa(T.Id), "0123456789012345") + "|- @宝智达 微信公众号通知")
  2079. //if len(T_calss_id_str) > 0 {
  2080. // r_jsons.T_QRCode = "https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=" + T_calss_id_str
  2081. //}
  2082. //
  2083. //T_calss_id_str, _ = NatsServer.Wx_GenerateQRCode2("-|" + lib.AesEncryptCBC(strconv.Itoa(T.Id), "0123456789012345") + "|- @宝智达 微信公众号通知")
  2084. //if len(T_calss_id_str) > 0 {
  2085. // r_jsons.T_QRCode2 = "https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=" + T_calss_id_str
  2086. //}
  2087. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
  2088. c.ServeJSON()
  2089. return
  2090. }
  2091. func (c *DeviceController) DeviceClass_Post() {
  2092. // 验证登录
  2093. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  2094. if !b_ {
  2095. c.Ctx.Redirect(302, "Login")
  2096. return
  2097. }
  2098. Id, _ := c.GetInt("Id")
  2099. T_name := c.GetString("T_name")
  2100. T_Notice_wx := c.GetString("T_Notice_wx")
  2101. T_Notice_wx2 := c.GetString("T_Notice_wx2")
  2102. T_Notice_phone := c.GetString("T_Notice_phone")
  2103. T_Notice_message := c.GetString("T_Notice_message")
  2104. T_Notice_mailbox := c.GetString("T_Notice_mailbox")
  2105. T_Notice_mechanism := c.GetString("T_Notice_mechanism")
  2106. t_c := Device.DeviceClass{
  2107. Id: Id,
  2108. T_name: T_name,
  2109. T_Notice_wx: T_Notice_wx,
  2110. T_Notice_wx2: T_Notice_wx2,
  2111. T_Notice_phone: T_Notice_phone,
  2112. T_Notice_message: T_Notice_message,
  2113. T_Notice_mailbox: T_Notice_mailbox,
  2114. T_Notice_mechanism: T_Notice_mechanism,
  2115. }
  2116. if Id == 0 {
  2117. t_c.T_State = 1
  2118. t_c.T_uuid = admin_r.Admin_uuid
  2119. t_c.T_Notice_wx = ""
  2120. t_c.T_Notice_wx2 = ""
  2121. t_c.T_Notice_phone = ""
  2122. t_c.T_Notice_message = ""
  2123. t_c.T_Notice_mailbox = ""
  2124. t_c.T_Notice_mechanism = Device.Read_DeviceWarningList_All_T_Notice_mechanism()
  2125. Device.Add_Class(t_c)
  2126. } else {
  2127. t_c.T_uuid = admin_r.Admin_uuid
  2128. Device.Update_Class_ById(t_c)
  2129. }
  2130. System.Add_UserLogs_T(admin_r.Admin_uuid, "设备管理", "分类操作", t_c)
  2131. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  2132. c.ServeJSON()
  2133. return
  2134. }
  2135. func (c *DeviceController) V2_Class_Add() {
  2136. // 验证登录
  2137. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  2138. if !b_ {
  2139. c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  2140. c.ServeJSON()
  2141. return
  2142. }
  2143. T_name := c.GetString("T_name")
  2144. t_c := Device.DeviceClass{
  2145. T_uuid: admin_r.Admin_uuid,
  2146. T_name: T_name,
  2147. T_Notice_mechanism: Device.Read_DeviceWarningList_All_T_Notice_mechanism(),
  2148. T_State: 1,
  2149. }
  2150. Device.Add_Class(t_c)
  2151. System.Add_UserLogs_T(admin_r.Admin_uuid, "分类管理", "分类添加", t_c)
  2152. // 同步分类
  2153. go func() {
  2154. DataList, _ := Admin.Read_v2_Admin_List(admin_r.Id, "", 0, 9999)
  2155. for _, v := range DataList {
  2156. if v.Admin_power > 6 {
  2157. V2_Class_Syn(admin_r, v)
  2158. }
  2159. }
  2160. }()
  2161. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  2162. c.ServeJSON()
  2163. return
  2164. }
  2165. func (c *DeviceController) V2_Class_Edit() {
  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("T_id")
  2174. T_name := c.GetString("T_name")
  2175. T_Notice_wx := c.GetString("T_Notice_wx")
  2176. T_Notice_wx2 := c.GetString("T_Notice_wx2")
  2177. T_Notice_phone := c.GetString("T_Notice_phone")
  2178. T_Notice_message := c.GetString("T_Notice_message")
  2179. T_Notice_mailbox := c.GetString("T_Notice_mailbox")
  2180. T_Notice_mechanism := c.GetString("T_Notice_mechanism")
  2181. R_DeviceClass, err := Device.Read_Class_ById(Id)
  2182. if err != nil {
  2183. c.Data["json"] = lib.JSONS{Code: 203, Msg: "T_id Err!"}
  2184. c.ServeJSON()
  2185. return
  2186. }
  2187. if R_DeviceClass.T_uuid != admin_r.Admin_uuid {
  2188. c.Data["json"] = lib.JSONS{Code: 203, Msg: "T_id Err!"}
  2189. c.ServeJSON()
  2190. return
  2191. }
  2192. R_DeviceClass.Id = Id
  2193. if len(T_name) > 0 {
  2194. R_DeviceClass.T_name = T_name
  2195. }
  2196. if len(T_Notice_wx) > 0 {
  2197. R_DeviceClass.T_Notice_wx = T_Notice_wx
  2198. }
  2199. if len(T_Notice_wx2) > 0 {
  2200. R_DeviceClass.T_Notice_wx2 = T_Notice_wx2
  2201. }
  2202. if len(T_Notice_phone) > 0 {
  2203. R_DeviceClass.T_Notice_phone = T_Notice_phone
  2204. }
  2205. if len(T_Notice_message) > 0 {
  2206. R_DeviceClass.T_Notice_message = T_Notice_message
  2207. }
  2208. if len(T_Notice_mailbox) > 0 {
  2209. R_DeviceClass.T_Notice_mailbox = T_Notice_mailbox
  2210. }
  2211. if len(T_Notice_mechanism) > 0 {
  2212. R_DeviceClass.T_Notice_mechanism = T_Notice_mechanism
  2213. }
  2214. 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")
  2215. System.Add_UserLogs_T(admin_r.Admin_uuid, "设备管理", "分类操作", R_DeviceClass)
  2216. // 同步分类
  2217. go func() {
  2218. DataList, _ := Admin.Read_v2_Admin_List(admin_r.Id, "", 0, 9999)
  2219. for _, v := range DataList {
  2220. if v.Admin_power > 6 {
  2221. V2_Class_Syn(admin_r, v)
  2222. }
  2223. }
  2224. }()
  2225. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  2226. c.ServeJSON()
  2227. return
  2228. }
  2229. func (c *DeviceController) DeviceWarningList_T_Tips() {
  2230. // 验证登录
  2231. b_, _ := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  2232. if !b_ {
  2233. c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  2234. c.ServeJSON()
  2235. return
  2236. }
  2237. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: Device.Read_DeviceWarningList_All_T_Notice_mechanism()}
  2238. c.ServeJSON()
  2239. return
  2240. }
  2241. func (c *DeviceController) DeviceClass_Del() {
  2242. // 验证登录
  2243. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  2244. if !b_ {
  2245. c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  2246. c.ServeJSON()
  2247. return
  2248. }
  2249. id, _ := c.GetInt("Id")
  2250. class_r, err := Device.Read_Class_ById(id)
  2251. if err != nil {
  2252. c.Data["json"] = lib.JSONS{Code: 202, Msg: "id Err!"}
  2253. c.ServeJSON()
  2254. return
  2255. }
  2256. if class_r.T_uuid != admin_r.Admin_uuid {
  2257. c.Data["json"] = lib.JSONS{Code: 203, Msg: "T_uuid Err!"}
  2258. c.ServeJSON()
  2259. return
  2260. }
  2261. Device.Delete_Class_ById(id)
  2262. DeviceSensor_class_list := Device.Read_DeviceSensor_ALL_class_1(id)
  2263. for _, v := range DeviceSensor_class_list {
  2264. Device.DeviceSensor_Bind_Del(v.T_sn, v.T_id, id)
  2265. }
  2266. System.Add_UserLogs(admin_r.Admin_uuid, "设备管理", "删除分类操作", strconv.Itoa(id))
  2267. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  2268. c.ServeJSON()
  2269. return
  2270. }
  2271. func (c *DeviceController) V2_Class_Del() {
  2272. // 验证登录
  2273. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  2274. if !b_ {
  2275. c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  2276. c.ServeJSON()
  2277. return
  2278. }
  2279. id, _ := c.GetInt("T_id")
  2280. class_r, err := Device.Read_Class_ById(id)
  2281. if err != nil {
  2282. c.Data["json"] = lib.JSONS{Code: 202, Msg: "id Err!"}
  2283. c.ServeJSON()
  2284. return
  2285. }
  2286. if class_r.T_uuid != admin_r.Admin_uuid {
  2287. c.Data["json"] = lib.JSONS{Code: 203, Msg: "T_uuid Err!"}
  2288. c.ServeJSON()
  2289. return
  2290. }
  2291. Device.Delete_Class_ById(id)
  2292. DeviceSensor_class_list := Device.Read_DeviceSensor_ALL_class_1(id)
  2293. for _, v := range DeviceSensor_class_list {
  2294. Device.DeviceSensor_Bind_Del(v.T_sn, v.T_id, id)
  2295. }
  2296. System.Add_UserLogs(admin_r.Admin_uuid, "设备管理", "删除分类操作", strconv.Itoa(id))
  2297. // 同步分类
  2298. go func() {
  2299. DataList, _ := Admin.Read_v2_Admin_List(admin_r.Id, "", 0, 9999)
  2300. for _, v := range DataList {
  2301. if v.Admin_power > 6 {
  2302. V2_Class_Syn(admin_r, v)
  2303. }
  2304. }
  2305. }()
  2306. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  2307. c.ServeJSON()
  2308. return
  2309. }
  2310. func (c *DeviceController) DeviceClass_Syn() {
  2311. // 验证登录
  2312. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  2313. if !b_ {
  2314. c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  2315. c.ServeJSON()
  2316. return
  2317. }
  2318. s_, user_r := Admin.Read_Admin_ByAdmin_uuid(c.GetString("Admin_uuid"))
  2319. if s_ != nil {
  2320. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Admin_uuid Err!"}
  2321. c.ServeJSON()
  2322. return
  2323. }
  2324. // 先全部 清掉
  2325. Device.Device_Bind_ALL_Del(user_r)
  2326. class_r := Device.Read_DeviceClass_ALL_T_uuid_1(user_r.Admin_uuid)
  2327. for _, v := range class_r {
  2328. fmt.Println("清掉:", v.Id)
  2329. // 删除分类
  2330. Device.Delete_Class_ById(v.Id)
  2331. // 删除 传感器分类
  2332. Device.DeviceSensor_T_Calss_ALL_Del(v.Id)
  2333. //Device.DeviceSensor_T_Bind_ALL_Del(user_r)
  2334. }
  2335. // 重新插入 分类
  2336. num_x := 0
  2337. class_r = Device.Read_DeviceClass_ALL_T_uuid_1(admin_r.Admin_uuid)
  2338. for _, v := range class_r {
  2339. fmt.Println("插入:", v.Id)
  2340. t_c := Device.DeviceClass{
  2341. T_uuid: user_r.Admin_uuid,
  2342. T_name: v.T_name,
  2343. T_Notice_wx: "",
  2344. T_Notice_phone: "",
  2345. T_Notice_message: "",
  2346. T_Notice_mailbox: "",
  2347. T_State: 1,
  2348. }
  2349. num_x = num_x + 1
  2350. // 添加分类
  2351. cid, err := Device.Add_Class(t_c)
  2352. if err != nil {
  2353. c.Data["json"] = lib.JSONS{Code: 200, Msg: "Add_Class E!"}
  2354. c.ServeJSON()
  2355. return
  2356. }
  2357. fmt.Println("cid:", cid)
  2358. // 添加 传感器分类
  2359. DeviceSensor_class_list := Device.Read_DeviceSensor_ALL_class_1(int(v.Id))
  2360. for _, v_c := range DeviceSensor_class_list {
  2361. // 绑定所有分类
  2362. Device.DeviceSensor_T_Calss_Add(v_c.T_sn, v_c.T_id, int(cid))
  2363. // 绑定所有权限
  2364. //Device_r, _ := Device.Read_Device_ByT_sn(v_c.T_sn)
  2365. //Device.DeviceSensor_T_Bind_Add(v_c.T_sn, v_c.T_id, user_r)
  2366. T_Bind := Device.Device_Bind_Add(v_c.T_sn, user_r)
  2367. Device.DeviceSensor_T_Bind_ALL(v_c.T_sn, T_Bind)
  2368. }
  2369. //
  2370. }
  2371. System.Add_UserLogs(admin_r.Admin_uuid, "设备管理", "同步分类操作", "->"+user_r.Admin_uuid)
  2372. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: num_x}
  2373. c.ServeJSON()
  2374. return
  2375. }
  2376. func V2_Class_Syn(admin_r Admin.Admin, user_r Admin.Admin) {
  2377. // 先全部 清掉
  2378. Device.Device_Bind_ALL_Del(user_r)
  2379. class_r := Device.Read_DeviceClass_ALL_T_uuid_1(user_r.Admin_uuid)
  2380. for _, v := range class_r {
  2381. fmt.Println("清掉:", v.Id)
  2382. // 删除分类
  2383. Device.Delete_Class_ById(v.Id)
  2384. // 删除 传感器分类
  2385. Device.DeviceSensor_T_Calss_ALL_Del(v.Id)
  2386. //Device.DeviceSensor_T_Bind_ALL_Del(user_r)
  2387. }
  2388. // 重新插入 分类
  2389. num_x := 0
  2390. class_r = Device.Read_DeviceClass_ALL_T_uuid_1(admin_r.Admin_uuid)
  2391. for _, v := range class_r {
  2392. fmt.Println("插入:", v.Id)
  2393. t_c := Device.DeviceClass{
  2394. T_uuid: user_r.Admin_uuid,
  2395. T_name: v.T_name,
  2396. T_Notice_wx: "",
  2397. T_Notice_phone: "",
  2398. T_Notice_message: "",
  2399. T_Notice_mailbox: "",
  2400. T_State: 1,
  2401. }
  2402. num_x = num_x + 1
  2403. // 添加分类
  2404. cid, err := Device.Add_Class(t_c)
  2405. if err != nil {
  2406. return
  2407. }
  2408. fmt.Println("cid:", cid)
  2409. // 添加 传感器分类
  2410. DeviceSensor_class_list := Device.Read_DeviceSensor_ALL_class_1(int(v.Id))
  2411. for _, v_c := range DeviceSensor_class_list {
  2412. // 绑定所有分类
  2413. Device.DeviceSensor_T_Calss_Add(v_c.T_sn, v_c.T_id, int(cid))
  2414. // 绑定所有权限
  2415. //Device_r, _ := Device.Read_Device_ByT_sn(v_c.T_sn)
  2416. //Device.DeviceSensor_T_Bind_Add(v_c.T_sn, v_c.T_id, user_r)
  2417. T_Bind := Device.Device_Bind_Add(v_c.T_sn, user_r)
  2418. Device.DeviceSensor_T_Bind_ALL(v_c.T_sn, T_Bind)
  2419. }
  2420. }
  2421. System.Add_UserLogs(admin_r.Admin_uuid, "设备管理", "同步分类操作", "->"+user_r.Admin_uuid)
  2422. return
  2423. }
  2424. func (c *DeviceController) DeviceClassBind_html_() {
  2425. // 验证登录
  2426. b_, _ := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  2427. if !b_ {
  2428. c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  2429. c.ServeJSON()
  2430. return
  2431. }
  2432. c.TplName = "Device/DeviceClassBind-.html"
  2433. }
  2434. func (c *DeviceController) DeviceClassBind_List() {
  2435. // 验证登录
  2436. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  2437. if !b_ {
  2438. c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  2439. c.ServeJSON()
  2440. return
  2441. }
  2442. type R_JSONS struct {
  2443. //必须的大写开头
  2444. DeviceSensor_lite []Device.DeviceSensor_R
  2445. Num int
  2446. Page int
  2447. Page_size int
  2448. Pages []lib.Page_T
  2449. }
  2450. var r_jsons R_JSONS
  2451. page, _ := c.GetInt("page")
  2452. println(page)
  2453. if page < 1 {
  2454. page = 1
  2455. }
  2456. Name := c.GetString("Name")
  2457. T_sn := c.GetString("T_sn")
  2458. T_calss_id, _ := c.GetInt("T_calss_id")
  2459. page_z, _ := c.GetInt("page_z")
  2460. if page_z == 0 {
  2461. page_z = conf.Page_size
  2462. }
  2463. //Name := c.GetString("Name")
  2464. //T_sn := c.GetString("T_sn")
  2465. //c.Data["Class_1"] = Class_1
  2466. ////c.Data["Name"] = Name
  2467. //c.Data["T_sn"] = T_sn
  2468. R_DeviceClass, err := Device.Read_Class_ById(T_calss_id)
  2469. if err != nil {
  2470. c.Data["json"] = lib.JSONS{Code: 205, Msg: "T_class_id Err!"}
  2471. c.ServeJSON()
  2472. return
  2473. }
  2474. if R_DeviceClass.T_uuid != admin_r.Admin_uuid {
  2475. c.Data["json"] = lib.JSONS{Code: 205, Msg: "T_class_id != Admin_uuid Err!"}
  2476. c.ServeJSON()
  2477. return
  2478. }
  2479. var cnt int64
  2480. Device_lite, cnt := Device.Read_DeviceSensor_class_ALL_1(admin_r, T_calss_id, page, page_z, T_sn, Name, "")
  2481. r_jsons.DeviceSensor_lite = Device_lite
  2482. page_size := math.Ceil(float64(cnt) / float64(page_z))
  2483. r_jsons.Page = page
  2484. r_jsons.Page_size = int(page_size)
  2485. r_jsons.Pages = lib.Func_page(int64(page), int64(page_size))
  2486. r_jsons.Num = int(cnt)
  2487. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
  2488. c.ServeJSON()
  2489. return
  2490. }
  2491. func (c *DeviceController) DeviceSensor_v2_List() {
  2492. // 验证登录
  2493. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  2494. if !b_ {
  2495. c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  2496. c.ServeJSON()
  2497. return
  2498. }
  2499. type R_JSONS struct {
  2500. //必须的大写开头
  2501. Data []Device.DeviceSensor_R
  2502. Num int64
  2503. Page int
  2504. Page_size int
  2505. }
  2506. var r_jsons R_JSONS
  2507. page, _ := c.GetInt("page")
  2508. println(page)
  2509. if page < 1 {
  2510. page = 1
  2511. }
  2512. page_z, _ := c.GetInt("page_z")
  2513. if page_z < 1 {
  2514. page_z = conf.Page_size
  2515. }
  2516. T_sn := c.GetString("T_sn")
  2517. Name := c.GetString("T_name") // 包含 T_name、T_sn
  2518. T_calss_id, _ := c.GetInt("T_calssid")
  2519. T_give, T_give_err := c.GetInt("T_give") //0 :丢弃 1:正常 空:所有
  2520. if T_give_err != nil {
  2521. T_give = -1
  2522. }
  2523. T_datashow, T_datashow_err := c.GetInt("T_datashow") //空:正常显示 1:强制显示 屏蔽数据展示
  2524. if T_datashow_err != nil {
  2525. T_datashow = -1
  2526. }
  2527. if len(c.GetString("User_uuid")) > 1 {
  2528. s_, user_r := Admin.Read_Admin_ByAdmin_uuid(c.GetString("User_uuid"))
  2529. if s_ != nil {
  2530. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Admin_uuid Err!"}
  2531. c.ServeJSON()
  2532. return
  2533. }
  2534. admin_r = user_r
  2535. }
  2536. if T_calss_id > 0 {
  2537. R_DeviceClass, err := Device.Read_Class_ById(T_calss_id)
  2538. if err != nil {
  2539. c.Data["json"] = lib.JSONS{Code: 205, Msg: "T_class_id Err!"}
  2540. c.ServeJSON()
  2541. return
  2542. }
  2543. if R_DeviceClass.T_uuid != admin_r.Admin_uuid {
  2544. c.Data["json"] = lib.JSONS{Code: 205, Msg: "T_class_id != Admin_uuid Err!"}
  2545. c.ServeJSON()
  2546. return
  2547. }
  2548. }
  2549. r_jsons.Data, r_jsons.Num = Device.Read_DeviceSensor_v2_List(admin_r, T_sn, Name, T_calss_id, T_give, T_datashow, page, page_z)
  2550. r_jsons.Page = page
  2551. r_jsons.Page_size = int(math.Ceil(float64(r_jsons.Num) / float64(page_z)))
  2552. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
  2553. c.ServeJSON()
  2554. return
  2555. }
  2556. func (c *DeviceController) DeviceClassBind_Add() {
  2557. // 验证登录
  2558. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  2559. if !b_ {
  2560. c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  2561. c.ServeJSON()
  2562. return
  2563. }
  2564. T_class_id, _ := c.GetInt("T_class_id")
  2565. T_sn := c.GetString("T_sn")
  2566. T_id, _ := c.GetInt("T_id")
  2567. if T_class_id == 0 || T_id == 0 || len(T_sn) == 0 {
  2568. c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_sn T_id T_class_id Err!"}
  2569. c.ServeJSON()
  2570. return
  2571. }
  2572. if _, err := Device.Read_Device_ByT_sn(T_sn); err != nil {
  2573. c.Data["json"] = lib.JSONS{Code: 204, Msg: "T_id Err!"}
  2574. c.ServeJSON()
  2575. return
  2576. }
  2577. R_DeviceClass, err := Device.Read_Class_ById(T_class_id)
  2578. if err != nil {
  2579. c.Data["json"] = lib.JSONS{Code: 205, Msg: "T_class_id Err!"}
  2580. c.ServeJSON()
  2581. return
  2582. }
  2583. if R_DeviceClass.T_uuid != admin_r.Admin_uuid {
  2584. c.Data["json"] = lib.JSONS{Code: 205, Msg: "T_class_id != Admin_uuid Err!"}
  2585. c.ServeJSON()
  2586. return
  2587. }
  2588. DeviceSensor_class_list := Device.Read_DeviceSensor_ALL_T_sn_T_id_class_1(T_sn, T_id, T_class_id)
  2589. if len(DeviceSensor_class_list) > 0 {
  2590. c.Data["json"] = lib.JSONS{Code: 203, Msg: "ok!"}
  2591. c.ServeJSON()
  2592. return
  2593. }
  2594. Device.DeviceSensor_T_Calss_Add(T_sn, T_id, T_class_id)
  2595. System.Add_UserLogs(admin_r.Admin_uuid, "设备管理", "分类绑定操作", strconv.Itoa(T_class_id)+"+>"+T_sn+"-"+strconv.Itoa(T_id))
  2596. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  2597. c.ServeJSON()
  2598. return
  2599. }
  2600. func (c *DeviceController) V2_ClassBind_Add() {
  2601. // 验证登录
  2602. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  2603. if !b_ {
  2604. c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  2605. c.ServeJSON()
  2606. return
  2607. }
  2608. T_class_id, _ := c.GetInt("T_class_id")
  2609. T_sn := c.GetString("T_sn")
  2610. T_id, _ := c.GetInt("T_id")
  2611. if T_class_id == 0 || T_id == 0 || len(T_sn) == 0 {
  2612. c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_sn T_id T_class_id Err!"}
  2613. c.ServeJSON()
  2614. return
  2615. }
  2616. if _, err := Device.Read_Device_ByT_sn(T_sn); err != nil {
  2617. c.Data["json"] = lib.JSONS{Code: 204, Msg: "T_id Err!"}
  2618. c.ServeJSON()
  2619. return
  2620. }
  2621. R_DeviceClass, err := Device.Read_Class_ById(T_class_id)
  2622. if err != nil {
  2623. c.Data["json"] = lib.JSONS{Code: 205, Msg: "T_class_id Err!"}
  2624. c.ServeJSON()
  2625. return
  2626. }
  2627. if R_DeviceClass.T_uuid != admin_r.Admin_uuid {
  2628. c.Data["json"] = lib.JSONS{Code: 205, Msg: "T_class_id != Admin_uuid Err!"}
  2629. c.ServeJSON()
  2630. return
  2631. }
  2632. DeviceSensor_class_list := Device.Read_DeviceSensor_ALL_T_sn_T_id_class_1(T_sn, T_id, T_class_id)
  2633. if len(DeviceSensor_class_list) > 0 {
  2634. c.Data["json"] = lib.JSONS{Code: 203, Msg: "ok!"}
  2635. c.ServeJSON()
  2636. return
  2637. }
  2638. // 同步分类
  2639. go func() {
  2640. DataList, _ := Admin.Read_v2_Admin_List(admin_r.Id, "", 0, 9999)
  2641. for _, v := range DataList {
  2642. if v.Admin_power > 6 {
  2643. V2_Class_Syn(admin_r, v)
  2644. }
  2645. }
  2646. }()
  2647. Device.DeviceSensor_T_Calss_Add(T_sn, T_id, T_class_id)
  2648. System.Add_UserLogs(admin_r.Admin_uuid, "设备管理", "分类绑定操作", strconv.Itoa(T_class_id)+"+>"+T_sn+"-"+strconv.Itoa(T_id))
  2649. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  2650. c.ServeJSON()
  2651. return
  2652. }
  2653. func (c *DeviceController) DeviceClassBind_Del() {
  2654. // 验证登录
  2655. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  2656. if !b_ {
  2657. c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  2658. c.ServeJSON()
  2659. return
  2660. }
  2661. T_class_id, _ := c.GetInt("T_class_id")
  2662. T_sn := c.GetString("T_sn")
  2663. T_id, _ := c.GetInt("T_id")
  2664. if T_class_id == 0 || T_id == 0 || len(T_sn) == 0 {
  2665. c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_sn T_id T_class_id Err!"}
  2666. c.ServeJSON()
  2667. return
  2668. }
  2669. if _, err := Device.Read_Device_ByT_sn(T_sn); err != nil {
  2670. c.Data["json"] = lib.JSONS{Code: 204, Msg: "T_id Err!"}
  2671. c.ServeJSON()
  2672. return
  2673. }
  2674. R_DeviceClass, err := Device.Read_Class_ById(T_class_id)
  2675. if err != nil {
  2676. c.Data["json"] = lib.JSONS{Code: 205, Msg: "T_class_id Err!"}
  2677. c.ServeJSON()
  2678. return
  2679. }
  2680. if R_DeviceClass.T_uuid != admin_r.Admin_uuid {
  2681. c.Data["json"] = lib.JSONS{Code: 205, Msg: "T_class_id != Admin_uuid Err!"}
  2682. c.ServeJSON()
  2683. return
  2684. }
  2685. DeviceSensor_class_list := Device.Read_DeviceSensor_ALL_T_sn_T_id_class_1(T_sn, T_id, T_class_id)
  2686. if len(DeviceSensor_class_list) == 0 {
  2687. c.Data["json"] = lib.JSONS{Code: 203, Msg: "ok!"}
  2688. c.ServeJSON()
  2689. return
  2690. }
  2691. Device.DeviceSensor_Bind_Del(T_sn, T_id, T_class_id)
  2692. System.Add_UserLogs(admin_r.Admin_uuid, "设备管理", "分类删除绑定操作", strconv.Itoa(T_class_id)+"->"+T_sn+"-"+strconv.Itoa(T_id))
  2693. // 同步分类
  2694. DataList, _ := Admin.Read_v2_Admin_List(admin_r.Id, "", 0, 9999)
  2695. for _, v := range DataList {
  2696. V2_Class_Syn(admin_r, v)
  2697. }
  2698. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  2699. c.ServeJSON()
  2700. return
  2701. }
  2702. func (c *DeviceController) V2_ClassBind_Del() {
  2703. // 验证登录
  2704. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  2705. if !b_ {
  2706. c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  2707. c.ServeJSON()
  2708. return
  2709. }
  2710. T_class_id, _ := c.GetInt("T_class_id")
  2711. T_sn := c.GetString("T_sn")
  2712. T_id, _ := c.GetInt("T_id")
  2713. if T_class_id == 0 || T_id == 0 || len(T_sn) == 0 {
  2714. c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_sn T_id T_class_id Err!"}
  2715. c.ServeJSON()
  2716. return
  2717. }
  2718. if _, err := Device.Read_Device_ByT_sn(T_sn); err != nil {
  2719. c.Data["json"] = lib.JSONS{Code: 204, Msg: "T_id Err!"}
  2720. c.ServeJSON()
  2721. return
  2722. }
  2723. R_DeviceClass, err := Device.Read_Class_ById(T_class_id)
  2724. if err != nil {
  2725. c.Data["json"] = lib.JSONS{Code: 205, Msg: "T_class_id Err!"}
  2726. c.ServeJSON()
  2727. return
  2728. }
  2729. if R_DeviceClass.T_uuid != admin_r.Admin_uuid {
  2730. c.Data["json"] = lib.JSONS{Code: 205, Msg: "T_class_id != Admin_uuid Err!"}
  2731. c.ServeJSON()
  2732. return
  2733. }
  2734. DeviceSensor_class_list := Device.Read_DeviceSensor_ALL_T_sn_T_id_class_1(T_sn, T_id, T_class_id)
  2735. if len(DeviceSensor_class_list) == 0 {
  2736. c.Data["json"] = lib.JSONS{Code: 203, Msg: "ok!"}
  2737. c.ServeJSON()
  2738. return
  2739. }
  2740. Device.DeviceSensor_Bind_Del(T_sn, T_id, T_class_id)
  2741. System.Add_UserLogs(admin_r.Admin_uuid, "设备管理", "分类删除绑定操作", strconv.Itoa(T_class_id)+"->"+T_sn+"-"+strconv.Itoa(T_id))
  2742. // 同步分类
  2743. go func() {
  2744. DataList, _ := Admin.Read_v2_Admin_List(admin_r.Id, "", 0, 9999)
  2745. for _, v := range DataList {
  2746. if v.Admin_power > 6 {
  2747. V2_Class_Syn(admin_r, v)
  2748. }
  2749. }
  2750. }()
  2751. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  2752. c.ServeJSON()
  2753. return
  2754. }
  2755. func (c *DeviceController) Get_DeviceClassId() {
  2756. // 验证登录
  2757. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  2758. if !b_ {
  2759. c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  2760. c.ServeJSON()
  2761. return
  2762. }
  2763. T_class_id, _ := c.GetInt("T_class_id")
  2764. R_DeviceClass, err := Device.Read_Class_ById(T_class_id)
  2765. if err != nil {
  2766. c.Data["json"] = lib.JSONS{Code: 201, Msg: "T_class_id Err!"}
  2767. c.ServeJSON()
  2768. return
  2769. }
  2770. if R_DeviceClass.T_uuid != admin_r.Admin_uuid {
  2771. c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_class_id != T_uuid Err!"}
  2772. c.ServeJSON()
  2773. return
  2774. }
  2775. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: R_DeviceClass}
  2776. c.ServeJSON()
  2777. return
  2778. }
  2779. // 任务列表
  2780. func (c *DeviceController) DeviceTask_List() {
  2781. // 验证登录
  2782. b_, _ := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  2783. if !b_ {
  2784. c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  2785. c.ServeJSON()
  2786. return
  2787. }
  2788. T_sn := c.GetString("T_sn")
  2789. Time_end := c.GetString("Time_end")
  2790. Time_start := c.GetString("Time_start")
  2791. DeviceTask_lite, _ := Device.Read_DeviceTask_All_50(T_sn, Time_end, Time_start)
  2792. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: DeviceTask_lite}
  2793. c.ServeJSON()
  2794. return
  2795. }
  2796. // 任务列表
  2797. func (c *DeviceController) DeviceTask_Post() {
  2798. // 验证登录
  2799. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  2800. if !b_ {
  2801. c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  2802. c.ServeJSON()
  2803. return
  2804. }
  2805. T_sn := c.GetString("T_sn")
  2806. T_task := c.GetString("T_task")
  2807. NatsServer.Set_DeviceTask(Device.Device_task{
  2808. T_sn: T_sn,
  2809. T_task: T_task,
  2810. })
  2811. System.Add_UserLogs(admin_r.Admin_uuid, "设备管理", "远程启停", T_sn+"-"+T_task)
  2812. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  2813. c.ServeJSON()
  2814. return
  2815. }
  2816. func (c *DeviceController) Get_DeviceClassId_QRCode() {
  2817. // 验证登录
  2818. b_, _ := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  2819. if !b_ {
  2820. c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  2821. c.ServeJSON()
  2822. return
  2823. }
  2824. T_calss_id := c.GetString("T_class_id")
  2825. if len(T_calss_id) == 0 {
  2826. c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_calss_id Err!"}
  2827. c.ServeJSON()
  2828. return
  2829. }
  2830. T_calss_id_str, _ := NatsServer.Wx_GenerateQRCode("-|" + lib.AesEncryptCBC(T_calss_id, "0123456789012345") + "|- @宝智达 微信公众号通知")
  2831. if len(T_calss_id_str) == 0 {
  2832. c.Data["json"] = lib.JSONS{Code: 201, Msg: "Err!"}
  2833. c.ServeJSON()
  2834. return
  2835. }
  2836. type Text struct {
  2837. QR string
  2838. Code string
  2839. }
  2840. T_calss_id_str = "https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=" + T_calss_id_str
  2841. Text_r := Text{
  2842. QR: T_calss_id_str,
  2843. Code: "请将本内容发送到 深圳市宝智达科技有限公司 微信公众号-|" + lib.AesEncryptCBC(T_calss_id, "0123456789012345") + "|- @宝智达 微信公众号通知 ",
  2844. }
  2845. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: Text_r}
  2846. c.ServeJSON()
  2847. return
  2848. }
  2849. func (c *DeviceController) Get_DeviceClassId_QRCode2() {
  2850. // 验证登录
  2851. b_, _ := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  2852. if !b_ {
  2853. c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  2854. c.ServeJSON()
  2855. return
  2856. }
  2857. T_calss_id := c.GetString("T_class_id")
  2858. if len(T_calss_id) == 0 {
  2859. c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_calss_id Err!"}
  2860. c.ServeJSON()
  2861. return
  2862. }
  2863. T_calss_id_str, _ := NatsServer.Wx_GenerateQRCode2("-|" + lib.AesEncryptCBC(T_calss_id, "0123456789012345") + "|- @宝智达 微信公众号通知")
  2864. if len(T_calss_id_str) == 0 {
  2865. c.Data["json"] = lib.JSONS{Code: 201, Msg: "Err!"}
  2866. c.ServeJSON()
  2867. return
  2868. }
  2869. type Text struct {
  2870. QR string
  2871. Code string
  2872. }
  2873. T_calss_id_str = "https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=" + T_calss_id_str
  2874. Text_r := Text{
  2875. QR: T_calss_id_str,
  2876. Code: "请将本内容发送到 宝智达冷链科技有限公司 微信公众号-|" + lib.AesEncryptCBC(T_calss_id, "0123456789012345") + "|- @宝智达 微信公众号通知 ",
  2877. }
  2878. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: Text_r}
  2879. c.ServeJSON()
  2880. return
  2881. }
  2882. func (c *DeviceController) DeviceData_Add() {
  2883. // 验证登录
  2884. if c.GetString("Tokey") != "1f9db553" {
  2885. c.Data["json"] = lib.JSONS{Code: 201, Msg: "Tokey Err!"}
  2886. c.ServeJSON()
  2887. return
  2888. }
  2889. T_sn := c.GetString("T_sn")
  2890. T_name := c.GetString("T_name")
  2891. T_id, _ := c.GetInt("T_id")
  2892. T_t, _ := c.GetFloat("T_t")
  2893. T_rh, _ := c.GetFloat("T_rh")
  2894. T_Tlower, _ := c.GetFloat("T_Tlower")
  2895. T_Tupper, _ := c.GetFloat("T_Tupper")
  2896. T_RHlower, _ := c.GetFloat("T_RHlower")
  2897. T_RHupper, _ := c.GetFloat("T_RHupper")
  2898. T_Site := c.GetString("T_Site")
  2899. T_Dattery, _ := c.GetInt("T_Dattery")
  2900. T_time, err := time.Parse("2006-01-02 15:04:05", c.GetString("T_time"))
  2901. if err != nil {
  2902. c.Data["json"] = lib.JSONS{Code: 201, Msg: "T_time Err!"}
  2903. c.ServeJSON()
  2904. return
  2905. }
  2906. //// 更新记录 - 缓存
  2907. DeviceData_t := Device.DeviceData_T{
  2908. T_name: T_name,
  2909. T_id: T_id,
  2910. T_t: float32(T_t),
  2911. T_rh: float32(T_rh),
  2912. T_Tlower: float32(T_Tlower),
  2913. T_Tupper: float32(T_Tupper),
  2914. T_RHlower: float32(T_RHlower),
  2915. T_RHupper: float32(T_RHupper),
  2916. T_Site: T_Site,
  2917. T_Dattery: T_Dattery,
  2918. T_time: T_time,
  2919. }
  2920. if !Device.Add_DeviceData(T_sn, DeviceData_t) {
  2921. c.Data["json"] = lib.JSONS{Code: 201, Msg: "Err!"}
  2922. c.ServeJSON()
  2923. return
  2924. }
  2925. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  2926. c.ServeJSON()
  2927. return
  2928. }
  2929. // 列表 - 设备日志
  2930. func (c *DeviceController) DeviceLogs() {
  2931. page, _ := c.GetInt("page")
  2932. println(page)
  2933. if page < 1 {
  2934. page = 1
  2935. }
  2936. T_sn := c.GetString("T_sn")
  2937. c.Data["T_sn"] = T_sn
  2938. var cnt int64
  2939. c.Data["List"], cnt = System.Read_DeviceLogs_ALL(page, T_sn)
  2940. page_size := math.Ceil(float64(cnt) / float64(conf.Page_size))
  2941. c.Data["Page"] = page
  2942. c.Data["Page_size"] = page_size
  2943. c.Data["Pages"] = lib.Func_page(int64(page), int64(page_size))
  2944. c.Data["cnt"] = cnt
  2945. c.TplName = "Device/DeviceLogs.html"
  2946. }