Device.go 58 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124
  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_sensor_list, r_Device.T_sensor = Device.Read_DeviceSensor_ByTsn(v.T_sn)
  58. Device_lite_r = append(Device_lite_r, r_Device)
  59. }
  60. c.Data["Device_lite"] = Device_lite_r
  61. page_size := math.Ceil(float64(cnt) / float64(page_z))
  62. c.Data["Page"] = page
  63. c.Data["Page_size"] = page_size
  64. c.Data["Pages"] = lib.Func_page(int64(page), int64(page_size))
  65. c.Data["cnt"] = cnt
  66. c.TplName = "Device/Device.html"
  67. }
  68. func (c *DeviceController) Device_() {
  69. id, _ := c.GetInt("id")
  70. c.Data["id"] = id
  71. if id > 0 {
  72. c.Data["Date"] = Device.Read_Device_ById(id)
  73. //c.Data["FormulaList"] = Formula.ReadFormulaListByid_List(id)
  74. }
  75. c.Data["DeviceSnOld_List"] = Device.Read_DeviceSnOld_1()
  76. c.TplName = "Device/Device-.html"
  77. }
  78. func (c *DeviceController) Device_Parameter_html() {
  79. // 验证登录
  80. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  81. if !b_ {
  82. c.Ctx.Redirect(302, "Login")
  83. return
  84. }
  85. c.Data["Admin_Power"], _ = Admin.Read_AdminPower_ById(admin_r.Admin_power)
  86. c.Data["Admin"] = admin_r
  87. Sn := c.GetString("Sn")
  88. DeviceParameter_lite := Device.Read_DeviceParameter_SN(Sn)
  89. if len(DeviceParameter_lite) > 0 {
  90. c.Data["DeviceParameter"] = DeviceParameter_lite[0]
  91. } else {
  92. NatsServer.Read_DeviceParameter(Sn)
  93. }
  94. c.Data["DeviceParameter_lite_z"] = len(DeviceParameter_lite)
  95. c.Data["DeviceParameter_lite_SendState_z"] = len(Device.Read_DeviceParameter_SN_T_SendState_0(Sn))
  96. DeviceParameter_lite_s_1 := Device.Read_DeviceParameter_SN_T_State_1(Sn)
  97. c.Data["DeviceParameter_lite"] = DeviceParameter_lite_s_1
  98. c.Data["Device"], _ = Device.Read_Device_ByT_sn(Sn)
  99. c.TplName = "Device/Device_Parameter-.html"
  100. }
  101. func (c *DeviceController) DeviceSensor_List_html() {
  102. // 验证登录
  103. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  104. if !b_ {
  105. c.Ctx.Redirect(302, "Login")
  106. return
  107. }
  108. c.Data["Admin_Power"], _ = Admin.Read_AdminPower_ById(admin_r.Admin_power)
  109. Sn := c.GetString("Sn")
  110. Id, _ := c.GetInt("Id")
  111. //
  112. //c.Data["Device_lite"] = Device.Read_DeviceParameter_SN(Sn)
  113. c.Data["DeviceSensor"], _ = Device.Read_DeviceSensor_ByTsn_Tid(Sn, Id)
  114. DeviceSensorParameter_list := Device.Read_DeviceSensorParameter_SN_T_id(Sn, Id)
  115. c.Data["DeviceSensorParameter_lite"] = DeviceSensorParameter_list
  116. c.Data["DeviceSensorParameter_T_SendState_0"] = 0
  117. if len(DeviceSensorParameter_list) > 0 {
  118. if DeviceSensorParameter_list[0].T_SendState == 0 {
  119. c.Data["DeviceSensorParameter_T_SendState_0"] = 1
  120. }
  121. }
  122. c.Data["Device"], _ = Device.Read_Device_ByT_sn(Sn)
  123. c.TplName = "Device/Device_Sensor-.html"
  124. }
  125. func (c *DeviceController) Device_Parameter_Del_Device() {
  126. // 验证登录
  127. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  128. if !b_ {
  129. c.Ctx.Redirect(302, "Login")
  130. return
  131. }
  132. Sn := c.GetString("Sn")
  133. Id, _ := c.GetInt("Id")
  134. System.Add_UserLogs_T(admin_r.Admin_uuid, "设备管理", "传感器 删除操作", "SN:"+Sn+" ["+strconv.Itoa(Id)+"]")
  135. //c.Data["Device_lite"] = Device.Read_DeviceParameter_SN(Sn)
  136. Device.Delete_DeviceSensor_ById(Sn, Id)
  137. NatsServer.Del_DeviceSensor(Device.DeviceSensor_Del{
  138. T_sn: Sn, T_id: Id,
  139. })
  140. c.Data["json"] = lib.JSONS{Code: 200, Msg: "OK"}
  141. c.ServeJSON()
  142. return
  143. }
  144. func (c *DeviceController) Device_Parameter_Del() {
  145. // 验证登录
  146. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  147. if !b_ {
  148. c.Ctx.Redirect(302, "Login")
  149. return
  150. }
  151. Sn := c.GetString("Sn")
  152. Id, _ := c.GetInt("Id")
  153. System.Add_UserLogs_T(admin_r.Admin_uuid, "设备管理", "传感器 删除操作", "SN:"+Sn+" ["+strconv.Itoa(Id)+"]")
  154. //c.Data["Device_lite"] = Device.Read_DeviceParameter_SN(Sn)
  155. Device.Delete_DeviceSensor_ById(Sn, Id)
  156. c.Data["json"] = lib.JSONS{Code: 200, Msg: "OK"}
  157. c.ServeJSON()
  158. return
  159. }
  160. func (c *DeviceController) UpDeviceSensor_Tsort() {
  161. // 验证登录
  162. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  163. if !b_ {
  164. c.Ctx.Redirect(302, "Login")
  165. return
  166. }
  167. Sn := c.GetString("Sn")
  168. Id, _ := c.GetInt("Id")
  169. T_sort, _ := c.GetInt("T_sort")
  170. DeviceSensor, is := Device.Read_DeviceSensor_ByT_sn(Sn, Id)
  171. if !is {
  172. c.Data["json"] = lib.JSONS{Code: 201, Msg: "信息错误!"}
  173. c.ServeJSON()
  174. return
  175. }
  176. DeviceSensor.T_sort = T_sort
  177. //c.Data["Device_lite"] = Device.Read_DeviceParameter_SN(Sn)
  178. Device.Update_DeviceSensor(DeviceSensor, "T_sort")
  179. System.Add_UserLogs_T(admin_r.Admin_uuid, "设备管理", "传感器 排序操作", "SN:"+Sn+" ["+strconv.Itoa(Id)+"]"+strconv.Itoa(T_sort))
  180. c.Data["json"] = lib.JSONS{Code: 200, Msg: "OK"}
  181. c.ServeJSON()
  182. return
  183. }
  184. func (c *DeviceController) UpDeviceSensor_T_datashow() {
  185. // 验证登录
  186. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  187. if !b_ {
  188. c.Ctx.Redirect(302, "Login")
  189. return
  190. }
  191. Sn := c.GetString("Sn")
  192. Id, _ := c.GetInt("Id")
  193. T_datashow, _ := c.GetInt("T_datashow")
  194. DeviceSensor, is := Device.Read_DeviceSensor_ByT_sn(Sn, Id)
  195. if !is {
  196. c.Data["json"] = lib.JSONS{Code: 201, Msg: "信息错误!"}
  197. c.ServeJSON()
  198. return
  199. }
  200. DeviceSensor.T_datashow = T_datashow
  201. Device.Update_DeviceSensor(DeviceSensor, "T_datashow")
  202. System.Add_UserLogs_T(admin_r.Admin_uuid, "设备管理", "传感器 数据展示(0 屏蔽数据展示 1 正常数据展示)", "SN:"+Sn+" ["+strconv.Itoa(Id)+"]"+strconv.Itoa(T_datashow))
  203. c.Data["json"] = lib.JSONS{Code: 200, Msg: "OK"}
  204. c.ServeJSON()
  205. return
  206. }
  207. func (c *DeviceController) Device_Post() {
  208. /// 验证登录
  209. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  210. if !b_ {
  211. c.Ctx.Redirect(302, "Login")
  212. return
  213. }
  214. var err error
  215. T_sn := c.GetString("T_sn")
  216. T_MSISDN := c.GetString("T_MSISDN")
  217. var_ := Device.Device{
  218. T_sn: T_sn,
  219. T_MSISDN: T_MSISDN,
  220. T_Bind: "U" + strconv.Itoa(admin_r.Id) + "|",
  221. T_l_p: 0,
  222. T_give: 1,
  223. T_monitor: 1,
  224. T_State: 1,
  225. }
  226. if len(T_sn) < 8 {
  227. c.Data["json"] = lib.JSONS{Code: 303, Msg: "SN 太短 必须8个字符以上"}
  228. c.ServeJSON()
  229. return
  230. }
  231. if !(strings.Contains(T_sn, "KF") || strings.Contains(T_sn, "YD")) {
  232. c.Data["json"] = lib.JSONS{Code: 303, Msg: "必须包含 KF或YD!"}
  233. c.ServeJSON()
  234. return
  235. }
  236. _, err = Device.Read_Device_ByT_sn(T_sn)
  237. if err == nil {
  238. c.Data["json"] = lib.JSONS{Code: 303, Msg: "重复SN!"}
  239. c.ServeJSON()
  240. return
  241. }
  242. var_.T_devName = "等待设备上线.."
  243. // 创建数据库
  244. if !Device.CREATE_DeviceData(T_sn) {
  245. c.Data["json"] = lib.JSONS{Code: 302, Msg: "添加失败!"}
  246. c.ServeJSON()
  247. return
  248. }
  249. _, err = Device.Add_Device(var_)
  250. if err != nil {
  251. c.Data["json"] = lib.JSONS{Code: 301, Msg: "添加失败!"}
  252. c.ServeJSON()
  253. return
  254. }
  255. System.Add_UserLogs_T(admin_r.Admin_uuid, "设备管理", "设备添加", var_)
  256. //MqttServer.Get_Device_Realtime(T_sn) // 更新传感器 !!!
  257. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  258. c.ServeJSON()
  259. return
  260. }
  261. func (c *DeviceController) Device_Del() {
  262. // 验证登录
  263. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  264. if !b_ {
  265. c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  266. c.ServeJSON()
  267. return
  268. }
  269. if admin_r.Id != 1 {
  270. c.Data["json"] = lib.JSONS{Code: 201, Msg: "没有权限!"}
  271. c.ServeJSON()
  272. return
  273. }
  274. T_sn := c.GetString("T_sn")
  275. Device_r, err := Device.Read_Device_ByT_sn(T_sn)
  276. if err != nil {
  277. c.Data["json"] = lib.JSONS{Code: 201, Msg: "T_sn Err!"}
  278. c.ServeJSON()
  279. return
  280. }
  281. Device.Delete_Device(Device_r)
  282. DeviceSensor_list, _ := Device.Read_DeviceSensor_ByTsn(Device_r.T_sn)
  283. for _, v := range DeviceSensor_list {
  284. Device.Delete_DeviceSensor_ById(Device_r.T_sn, v.T_id)
  285. }
  286. Device.DELETE_DeviceSensor(Device_r.T_sn)
  287. Device.DELETE_DeviceDatar(Device_r.T_sn)
  288. Device.DELETE_DeviceParameter(Device_r.T_sn)
  289. Device.DELETE_DeviceSensorParameter(Device_r.T_sn)
  290. System.Add_UserLogs(admin_r.Admin_uuid, "设备管理", "设备删除", T_sn)
  291. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  292. c.ServeJSON()
  293. return
  294. }
  295. // 设备弃用
  296. func (c *DeviceController) Device_Give() {
  297. // 验证登录
  298. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  299. if !b_ {
  300. c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  301. c.ServeJSON()
  302. return
  303. }
  304. if admin_r.Admin_master != 1 {
  305. c.Data["json"] = lib.JSONS{Code: 201, Msg: "没有权限!"}
  306. c.ServeJSON()
  307. return
  308. }
  309. T_sn := c.GetString("T_sn")
  310. Device_r, err := Device.Read_Device_ByT_sn(T_sn)
  311. if err != nil {
  312. c.Data["json"] = lib.JSONS{Code: 201, Msg: "T_sn Err!"}
  313. c.ServeJSON()
  314. return
  315. }
  316. if Device_r.T_give == 0 {
  317. Device_r.T_give = 1
  318. System.Add_UserLogs(admin_r.Admin_uuid, "设备管理", "设备开启", T_sn)
  319. } else {
  320. Device_r.T_give = 0
  321. System.Add_UserLogs(admin_r.Admin_uuid, "设备管理", "设备弃用", T_sn)
  322. }
  323. Device.Update_Device(Device_r, "T_give")
  324. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  325. c.ServeJSON()
  326. return
  327. }
  328. //-------------------------------
  329. func (c *DeviceController) Device_List() {
  330. // 验证登录
  331. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  332. if !b_ {
  333. c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  334. c.ServeJSON()
  335. return
  336. }
  337. type R_JSONS struct {
  338. //必须的大写开头
  339. Device_lite []Device.R_Device
  340. Num int
  341. Page int
  342. Page_size int
  343. Pages []lib.Page_T
  344. }
  345. var r_jsons R_JSONS
  346. page, _ := c.GetInt("page")
  347. println(page)
  348. if page < 1 {
  349. page = 1
  350. }
  351. Class_1 := c.GetString("Class_1")
  352. Name := c.GetString("Name")
  353. T_sn := c.GetString("T_sn")
  354. T_online := c.GetString("T_online")
  355. //
  356. //c.Data["Class_1"] = Class_1
  357. //c.Data["T_sn"] = T_sn
  358. //c.Data["Class_List"] = Device.Read_Class_All_1()
  359. Device_r, err := Device.Read_Device_ByT_sn(T_sn)
  360. if err != nil {
  361. c.Data["json"] = lib.JSONS{Code: 206, Msg: "T_sn Err!"}
  362. c.ServeJSON()
  363. return
  364. }
  365. if !strings.Contains(Device_r.T_Bind, "U"+strconv.Itoa(admin_r.Id)+"|") && admin_r.Admin_master != 0 {
  366. c.Data["json"] = lib.JSONS{Code: 202, Msg: "! U" + strconv.Itoa(admin_r.Id)}
  367. c.ServeJSON()
  368. return
  369. }
  370. var cnt int64
  371. Device_lite, cnt := Device.Read_Device_ALL_bind_1(admin_r, page, 0, T_sn, Name, Class_1, "", T_online)
  372. for _, v := range Device_lite {
  373. r_Device := Device.R_Device{}
  374. r_Device.T_sn = v.T_sn
  375. r_Device.T_MSISDN = v.T_MSISDN
  376. r_Device.T_devName = v.T_devName
  377. r_Device.T_give = v.T_give
  378. r_Device.T_online = v.T_online
  379. r_Device.T_monitor = v.T_monitor
  380. r_Device.T_Dattery = v.T_Dattery
  381. r_Device.T_sensor_list, r_Device.T_sensor = Device.Read_DeviceSensor_ByTsn(v.T_sn)
  382. r_jsons.Device_lite = append(r_jsons.Device_lite, r_Device)
  383. }
  384. page_size := math.Ceil(float64(cnt) / float64(conf.Page_size))
  385. r_jsons.Page = int(page)
  386. r_jsons.Page_size = int(page_size)
  387. r_jsons.Pages = lib.Func_page(int64(page), int64(page_size))
  388. r_jsons.Num = int(cnt)
  389. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
  390. c.ServeJSON()
  391. return
  392. }
  393. func (c *DeviceController) DeviceSensor_List() {
  394. // 验证登录
  395. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  396. if !b_ {
  397. c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  398. c.ServeJSON()
  399. return
  400. }
  401. type R_JSONS struct {
  402. //必须的大写开头
  403. DeviceSensor_lite []Device.DeviceSensor_R
  404. Num int
  405. Page int
  406. Page_size int
  407. Pages []lib.Page_T
  408. }
  409. var r_jsons R_JSONS
  410. page, _ := c.GetInt("page")
  411. println(page)
  412. if page < 1 {
  413. page = 1
  414. }
  415. page_z, _ := c.GetInt("page_z")
  416. if page_z == 0 {
  417. page_z = conf.Page_size
  418. }
  419. T_sn := c.GetString("Sn")
  420. Device_r, err := Device.Read_Device_ByT_sn(T_sn)
  421. if err != nil {
  422. c.Data["json"] = lib.JSONS{Code: 206, Msg: "T_sn Err!"}
  423. c.ServeJSON()
  424. return
  425. }
  426. if admin_r.Admin_master > 1 {
  427. if !strings.Contains(Device_r.T_Bind, "U"+strconv.Itoa(admin_r.Id)+"|") && admin_r.Admin_master != 0 {
  428. c.Data["json"] = lib.JSONS{Code: 202, Msg: "! U" + strconv.Itoa(admin_r.Id)}
  429. c.ServeJSON()
  430. return
  431. }
  432. }
  433. //c.Data["Class_List"] = Device.Read_Class_All_1()
  434. var cnt int64
  435. r_jsons.DeviceSensor_lite, cnt = Device.Read_DeviceSensor_ALL_T_sn(T_sn, page, page_z)
  436. page_size := math.Ceil(float64(cnt) / float64(page_z))
  437. r_jsons.Page = int(page)
  438. r_jsons.Page_size = int(page_size)
  439. r_jsons.Pages = lib.Func_page(int64(page), int64(page_size))
  440. r_jsons.Num = int(cnt)
  441. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
  442. c.ServeJSON()
  443. return
  444. }
  445. // ------------------------------------------
  446. func (c *DeviceController) Read_DeviceParameter() {
  447. // 验证登录
  448. b_, _ := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  449. if !b_ {
  450. c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  451. c.ServeJSON()
  452. return
  453. }
  454. T_SN := c.GetString("SN")
  455. //Device_r, err := Device.Read_Device_ByT_sn(T_SN)
  456. //if err != nil {
  457. // c.Data["json"] = lib.JSONS{Code: 206, Msg: "T_sn Err!"}
  458. // c.ServeJSON()
  459. // return
  460. //}
  461. ////if !strings.Contains(Device_r.T_Bind, "U"+strconv.Itoa(r_admin.Id)) {
  462. //// c.Data["json"] = lib.JSONS{Code: 202, Msg: "! U" + strconv.Itoa(r_admin.Id)}
  463. //// c.ServeJSON()
  464. //// return
  465. ////}
  466. NatsServer.Read_DeviceParameter(T_SN)
  467. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  468. c.ServeJSON()
  469. return
  470. }
  471. func (c *DeviceController) Read_DeviceSensorParameter() {
  472. // 验证登录
  473. b_, _ := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  474. if !b_ {
  475. c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  476. c.ServeJSON()
  477. return
  478. }
  479. T_SN := c.GetString("SN")
  480. //Device_r, err := Device.Read_Device_ByT_sn(T_SN)
  481. //if err != nil {
  482. // c.Data["json"] = lib.JSONS{Code: 206, Msg: "T_sn Err!"}
  483. // c.ServeJSON()
  484. // return
  485. //}
  486. ////if !strings.Contains(Device_r.T_Bind, "U"+strconv.Itoa(r_admin.Id)) {
  487. //// c.Data["json"] = lib.JSONS{Code: 202, Msg: "! U" + strconv.Itoa(r_admin.Id)}
  488. //// c.ServeJSON()
  489. //// return
  490. ////}
  491. NatsServer.Read_DeviceSensorParameter(T_SN)
  492. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  493. c.ServeJSON()
  494. return
  495. }
  496. //
  497. func (c *DeviceController) Pu_DeviceParameter() {
  498. // 验证登录
  499. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  500. if !b_ {
  501. c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  502. c.ServeJSON()
  503. return
  504. }
  505. T_SN := c.GetString("SN")
  506. T_devName := c.GetString("T_devName")
  507. T_saveTime, _ := c.GetInt("T_saveTime")
  508. T_overrunSave, _ := c.GetInt("T_overrunSave")
  509. T_overrunAlarm, _ := c.GetInt("T_overrunAlarm")
  510. T_outageAlarm, _ := c.GetInt("T_outageAlarm")
  511. T_warningDelay, _ := c.GetInt("T_warningDelay")
  512. T_lostAlarm, _ := c.GetInt("T_lostAlarm")
  513. T_batteryLimit, _ := c.GetInt("T_batteryLimit")
  514. T_warningTime, _ := c.GetInt("T_warningTime")
  515. T_tempPre, _ := c.GetFloat("T_tempPre")
  516. T_humPre, _ := c.GetFloat("T_humPre")
  517. T_enwarning, _ := c.GetInt("T_enwarning")
  518. T_decTotal, _ := c.GetInt("T_decTotal")
  519. T_chDecTotal := c.GetString("T_chDecTotal")
  520. T_company := c.GetString("T_company")
  521. T_btname := c.GetString("T_btname")
  522. T_btserverID, _ := c.GetInt("T_btserverID")
  523. T_btchar, _ := c.GetInt("T_btchar")
  524. Device_r, err := Device.Read_Device_ByT_sn(T_SN)
  525. if err != nil {
  526. c.Data["json"] = lib.JSONS{Code: 206, Msg: "T_sn Err!"}
  527. c.ServeJSON()
  528. return
  529. }
  530. Admin_Power_, _ := Admin.Read_AdminPower_ById(admin_r.Admin_power)
  531. if Admin_Power_.Power_DeviceSensor_Compensate_e == 0 {
  532. c.Data["json"] = lib.JSONS{Code: 202, Msg: "! U" + strconv.Itoa(admin_r.Id)}
  533. c.ServeJSON()
  534. return
  535. }
  536. Deviceparameter := Device.DeviceParameter{
  537. T_uuid: admin_r.Admin_uuid,
  538. T_SendState: 0,
  539. T_State: 2,
  540. T_sn: T_SN,
  541. T_devName: T_devName,
  542. T_saveTime: T_saveTime,
  543. T_overrunSave: T_overrunSave,
  544. T_overrunAlarm: T_overrunAlarm,
  545. T_outageAlarm: T_outageAlarm,
  546. T_lostAlarm: T_lostAlarm,
  547. T_warningTime: T_warningTime,
  548. T_warningDelay: T_warningDelay,
  549. T_batteryLimit: T_batteryLimit,
  550. T_tempPre: float32(T_tempPre),
  551. T_humPre: float32(T_humPre),
  552. T_chDecTotal: T_chDecTotal,
  553. T_decTotal: strconv.Itoa(T_decTotal),
  554. T_enwarning: T_enwarning,
  555. T_company: T_company,
  556. T_btname: T_btname,
  557. T_btserverID: strconv.Itoa(T_btserverID),
  558. T_btchar: strconv.Itoa(T_btchar),
  559. }
  560. Deviceparameter, is := Device.Add_DeviceParameter(Deviceparameter)
  561. if !is {
  562. c.Data["json"] = lib.JSONS{Code: 203, Msg: "Add_DeviceParameter ERR"}
  563. c.ServeJSON()
  564. return
  565. }
  566. System.Add_UserLogs_T(admin_r.Admin_uuid, "设备管理", "设备参数操作", Deviceparameter)
  567. NatsServer.Pu_DeviceParameter(Deviceparameter)
  568. Device_r.T_devName = Deviceparameter.T_devName
  569. Device.Update_Device(Device_r, "T_devName")
  570. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  571. c.ServeJSON()
  572. return
  573. }
  574. //
  575. func (c *DeviceController) Pu_DeviceParameter_T_l_p() {
  576. // 验证登录
  577. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  578. if !b_ {
  579. c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  580. c.ServeJSON()
  581. return
  582. }
  583. T_SN := c.GetString("SN")
  584. T_l_p, _ := c.GetInt("T_l_p")
  585. Device_r, err := Device.Read_Device_ByT_sn(T_SN)
  586. if err != nil {
  587. c.Data["json"] = lib.JSONS{Code: 206, Msg: "T_sn Err!"}
  588. c.ServeJSON()
  589. return
  590. }
  591. // // 1物流端 2药店端
  592. Device_r.T_l_p = T_l_p
  593. Device.Update_Device(Device_r, "T_l_p")
  594. Device.DeviceSensor_T_l_p_ALL(T_SN, T_l_p)
  595. System.Add_UserLogs(admin_r.Admin_uuid, "设备管理", "设备参数操作", "类型选择(1物流端 2药店端):"+string(T_l_p))
  596. c.Data["json"] = lib.JSONS{Code: 222, Msg: "ok!"}
  597. c.ServeJSON()
  598. return
  599. }
  600. //
  601. func (c *DeviceController) Pu_DeviceParameter_T_give() {
  602. // 验证登录
  603. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  604. if !b_ {
  605. c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  606. c.ServeJSON()
  607. return
  608. }
  609. T_SN := c.GetString("SN")
  610. T_give, _ := c.GetInt("T_give")
  611. Device_r, err := Device.Read_Device_ByT_sn(T_SN)
  612. if err != nil {
  613. c.Data["json"] = lib.JSONS{Code: 206, Msg: "T_sn Err!"}
  614. c.ServeJSON()
  615. return
  616. }
  617. // // 1物流端 2药店端
  618. Device_r.T_give = T_give
  619. Device.Update_Device(Device_r, "T_give")
  620. Device.DeviceSensor_t_give_ALL(T_SN, T_give)
  621. System.Add_UserLogs(admin_r.Admin_uuid, "设备管理", "设备丢弃参数操作", "设备丢弃( 0 丢弃 1 正常):"+string(T_give))
  622. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  623. c.ServeJSON()
  624. return
  625. }
  626. //
  627. //func (c *DeviceController) Pu_DeviceParameter_Sensor_() {
  628. // // 验证登录
  629. // b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  630. // if !b_ {
  631. // c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  632. // c.ServeJSON()
  633. // return
  634. // }
  635. //
  636. // T_SN := c.GetString("SN")
  637. // _, err := Device.Read_Device_ByT_sn(T_SN)
  638. // if err != nil {
  639. // c.Data["json"] = lib.JSONS{Code: 206, Msg: "T_sn Err!"}
  640. // c.ServeJSON()
  641. // return
  642. // }
  643. // Admin_Power_, _ := Admin.Read_AdminPower_ById(admin_r.Admin_power)
  644. // if Admin_Power_.Power_DeviceSensor_Compensate_e == 0 {
  645. // c.Data["json"] = lib.JSONS{Code: 202, Msg: "! U" + strconv.Itoa(admin_r.Id)}
  646. // c.ServeJSON()
  647. // return
  648. // }
  649. //
  650. // T_sensor_list := c.GetString("T_sensor_list")
  651. // jsonStu_map_ := strings.Replace(string(T_sensor_list), "\"{", "{", -1)
  652. // jsonStu_map_ = strings.Replace(jsonStu_map_, "}\"", "}", -1)
  653. // jsonStu_map_ = strings.Replace(jsonStu_map_, "\\\"", "\"", -1)
  654. // println("jsonStu_map_:", jsonStu_map_)
  655. // var Rt_parameter_sensor_ []MqttServer.Rt_Parameter_Sensor_
  656. // err = json.Unmarshal([]byte(jsonStu_map_), &Rt_parameter_sensor_)
  657. // if err != nil {
  658. // c.Data["json"] = lib.JSONS{Code: 204, Msg: "T_sensor_list Err!"}
  659. // c.ServeJSON()
  660. // return
  661. // }
  662. //
  663. // Handle.Pu_DeviceParameter_Sensor(admin_r.Admin_uuid, T_SN, Rt_parameter_sensor_)
  664. // System.Add_UserLogs(admin_r.Admin_uuid,"设备管理", "传感器参数操作", jsonStu_map_)
  665. //
  666. // DeviceSensor,is := Device.Read_DeviceSensor_ByT_sn(T_SN, Rt_parameter_sensor_[0].T_id)
  667. // if is {
  668. // DeviceSensor.T_name = Rt_parameter_sensor_[0].T_name
  669. // Device.Update_TDeviceSensor(DeviceSensor,"T_name")
  670. // }
  671. //
  672. //
  673. // c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  674. // c.ServeJSON()
  675. // return
  676. //
  677. //}
  678. //
  679. func (c *DeviceController) Pu_DeviceParameter_Sensor() {
  680. // 验证登录
  681. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  682. if !b_ {
  683. c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  684. c.ServeJSON()
  685. return
  686. }
  687. T_SN := c.GetString("T_SN")
  688. T_name := c.GetString("T_name")
  689. T_id, _ := c.GetInt("T_id")
  690. T_Tlower, _ := c.GetFloat("T_Tlower")
  691. T_Tupper, _ := c.GetFloat("T_Tupper")
  692. T_RHlower, _ := c.GetFloat("T_RHlower")
  693. T_RHupper, _ := c.GetFloat("T_RHupper")
  694. T_en, _ := c.GetInt("T_en")
  695. T_free, _ := c.GetInt("T_free")
  696. // 权限 过滤
  697. Admin_Power_, _ := Admin.Read_AdminPower_ById(admin_r.Admin_power)
  698. if Admin_Power_.Power_DeviceSensor_Compensate_e == 0 {
  699. c.Data["json"] = lib.JSONS{Code: 202, Msg: "! U" + strconv.Itoa(admin_r.Id)}
  700. c.ServeJSON()
  701. return
  702. }
  703. _, err := Device.Read_Device_ByT_sn(T_SN)
  704. if err != nil {
  705. c.Data["json"] = lib.JSONS{Code: 206, Msg: "T_sn Err!"}
  706. c.ServeJSON()
  707. return
  708. }
  709. DeviceSensor, is := Device.Read_DeviceSensor_ByT_sn(T_SN, T_id)
  710. if !is {
  711. c.Data["json"] = lib.JSONS{Code: 208, Msg: "T_sn T_id Err!"}
  712. c.ServeJSON()
  713. return
  714. }
  715. Devicesensorparameter := Device.DeviceSensorParameter{
  716. T_sn: T_SN,
  717. T_id: T_id,
  718. T_name: T_name,
  719. T_Tlower: float32(T_Tlower),
  720. T_Tupper: float32(T_Tupper),
  721. T_RHlower: float32(T_RHlower),
  722. T_RHupper: float32(T_RHupper),
  723. T_en: T_en,
  724. T_free: T_free,
  725. T_uuid: admin_r.Admin_uuid,
  726. T_SendState: 0,
  727. T_State: 2,
  728. }
  729. dsp_id, is := Device.Add_DeviceSensorParameter(Devicesensorparameter)
  730. if !is {
  731. c.Data["json"] = lib.JSONS{Code: 209, Msg: "添加失败!"}
  732. c.ServeJSON()
  733. return
  734. }
  735. Devicesensorparameter.Id = int(dsp_id)
  736. // 更新名称
  737. DeviceSensor.T_name = T_name
  738. Device.Update_DeviceSensor(DeviceSensor, "T_name")
  739. System.Add_UserLogs_T(admin_r.Admin_uuid, "设备管理", "传感器参数操作", Devicesensorparameter)
  740. NatsServer.Pu_DeviceParameter_Sensor(Devicesensorparameter)
  741. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  742. c.ServeJSON()
  743. return
  744. }
  745. ////
  746. //func (c *DeviceController) Pu_DeviceParameter_Sensor_Cache() {
  747. // // 验证登录
  748. // b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  749. // if !b_ {
  750. // c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  751. // c.ServeJSON()
  752. // return
  753. // }
  754. //
  755. // T_SN := c.GetString("SN")
  756. // T_id := c.GetString("T_id")
  757. // _, err := Device.Read_Device_ByT_sn(T_SN)
  758. // if err != nil {
  759. // c.Data["json"] = lib.JSONS{Code: 206, Msg: "T_sn Err!"}
  760. // c.ServeJSON()
  761. // return
  762. // }
  763. // Admin_Power_, _ := Admin.Read_AdminPower_ById(admin_r.Admin_power)
  764. // if Admin_Power_.Power_DeviceSensor_Compensate_e == 0 {
  765. // c.Data["json"] = lib.JSONS{Code: 202, Msg: "! U" + strconv.Itoa(admin_r.Id)}
  766. // c.ServeJSON()
  767. // return
  768. // }
  769. //
  770. // T_sensor_list := c.GetString("T_sensor_list")
  771. // jsonStu_map_ := strings.Replace(string(T_sensor_list), "\"{", "{", -1)
  772. // jsonStu_map_ = strings.Replace(jsonStu_map_, "}\"", "}", -1)
  773. // jsonStu_map_ = strings.Replace(jsonStu_map_, "\\\"", "\"", -1)
  774. // println("jsonStu_map_:", jsonStu_map_)
  775. // var Rt_parameter_sensor_ []MqttServer.Rt_Parameter_Sensor_
  776. // err = json.Unmarshal([]byte(jsonStu_map_), &Rt_parameter_sensor_)
  777. // if err != nil {
  778. // c.Data["json"] = lib.JSONS{Code: 204, Msg: "T_sensor_list Err!"}
  779. // c.ServeJSON()
  780. // return
  781. // }
  782. // DeviceSensor,is := Device.Read_DeviceSensor_ByT_sn(T_SN, Rt_parameter_sensor_[0].T_id)
  783. // if is {
  784. // DeviceSensor.T_name = Rt_parameter_sensor_[0].T_name
  785. // Device.Update_TDeviceSensor(DeviceSensor,"T_name")
  786. // }
  787. //
  788. // Device.Redis_DeviceSensorParameterCache_Set(T_SN+"_"+T_id,jsonStu_map_)
  789. // //Handle.Pu_DeviceParameter_Sensor(admin_r.Admin_uuid, T_SN, Rt_parameter_sensor_)
  790. // System.Add_UserLogs(admin_r.Admin_uuid,"设备管理", "传感器参数操作-离线操作", jsonStu_map_)
  791. // c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  792. // c.ServeJSON()
  793. // return
  794. //
  795. //}
  796. // 列表 -
  797. func (c *DeviceController) DeviceWarning_List_html() {
  798. // 验证登录
  799. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  800. if !b_ {
  801. c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  802. c.ServeJSON()
  803. return
  804. }
  805. c.Data["Admin_r"] = admin_r
  806. page, _ := c.GetInt("page")
  807. println(page)
  808. if page < 1 {
  809. page = 1
  810. }
  811. c.Data["Admin_r"] = admin_r
  812. T_Name := c.GetString("T_Name")
  813. //T_sn := c.GetString("T_sn")
  814. Time_start := c.GetString("Time_start")
  815. Time_end := c.GetString("Time_end")
  816. if len(Time_start) == 0 && len(Time_end) == 0 {
  817. Time_start = time.Now().Format("2006-01-02") + " 00:00:00"
  818. Time_end = time.Now().Format("2006-01-02") + " 23:59:59"
  819. }
  820. c.Data["Time_start"] = Time_start
  821. c.Data["Time_end"] = Time_end
  822. c.Data["T_Name"] = T_Name
  823. //c.Data["Class_List"] = Device.Read_DeviceWarningList_All_1()
  824. //T_Title := ""
  825. //if Class_1 > 0 {
  826. // T_Title = Device.Read_DeviceWarningList_ById(Class_1).T_name
  827. //}
  828. var cnt int64
  829. DeviceWarning_List, cnt := Device.Read_DeviceWarning_1(admin_r, page, "", T_Name, Time_start, Time_end)
  830. //for i, v := range DeviceWarning_List {
  831. // DeviceWarning_List[i].T_State = 0
  832. // if strings.Contains(v.T_sn, "YD") {
  833. // DeviceWarning_List[i].T_State = 1
  834. // }
  835. //}
  836. c.Data["List"] = DeviceWarning_List
  837. page_size := math.Ceil(float64(cnt) / float64(conf.Page_size))
  838. c.Data["Page"] = page
  839. c.Data["Page_size"] = page_size
  840. c.Data["Pages"] = lib.Func_page(int64(page), int64(page_size))
  841. c.Data["cnt"] = cnt
  842. c.TplName = "Device/DeviceWarning.html"
  843. }
  844. // 列表 -
  845. func (c *DeviceController) DeviceWarning_List() {
  846. // 验证登录
  847. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  848. if !b_ {
  849. c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  850. c.ServeJSON()
  851. return
  852. }
  853. type R_JSONS struct {
  854. //必须的大写开头
  855. DeviceWarning []Device.DeviceWarning
  856. //DeviceWarningclass []Device.DeviceWarningList
  857. Num int
  858. Page int
  859. Page_size int
  860. Pages []lib.Page_T
  861. }
  862. var r_jsons R_JSONS
  863. page, _ := c.GetInt("page")
  864. println(page)
  865. if page < 1 {
  866. page = 1
  867. }
  868. T_sn := c.GetString("T_sn")
  869. //T_sn := c.GetString("Sn")
  870. //Class_1, _ := c.GetInt("Class_1")
  871. T_Name := c.GetString("T_Name")
  872. Time_start := c.GetString("Time_start")
  873. Time_end := c.GetString("Time_end")
  874. //r_jsons.DeviceWarningclass = Device.Read_DeviceWarningList_All_1()
  875. //T_Title := ""
  876. //if Class_1 > 0 {
  877. // T_Title = Device.Read_DeviceWarningList_ById(Class_1).T_name
  878. //}
  879. var cnt int64
  880. r_jsons.DeviceWarning, cnt = Device.Read_DeviceWarning_1(admin_r, page, T_sn, T_Name, Time_start, Time_end)
  881. page_size := math.Ceil(float64(cnt) / float64(conf.Page_size))
  882. r_jsons.Page = int(page)
  883. r_jsons.Page_size = int(page_size)
  884. r_jsons.Pages = lib.Func_page(int64(page), int64(page_size))
  885. r_jsons.Num = int(cnt)
  886. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
  887. c.ServeJSON()
  888. return
  889. }
  890. // 列表 -
  891. func (c *DeviceController) DeviceWarning_Data_Excel() {
  892. // 验证登录
  893. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  894. if !b_ {
  895. c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  896. c.ServeJSON()
  897. return
  898. }
  899. //T_sn := c.GetString("T_sn")
  900. Class_1, _ := c.GetInt("Class_1")
  901. T_Name := c.GetString("T_Name")
  902. Time_start := c.GetString("Time_start")
  903. Time_end := c.GetString("Time_end")
  904. c.Data["Class_1"] = Class_1
  905. if len(Time_start) == 0 && len(Time_end) == 0 {
  906. Time_start = time.Now().Format("2006-01-02") + " 00:00:00"
  907. Time_end = time.Now().Format("2006-01-02") + " 23:59:59"
  908. }
  909. //
  910. //T_Title := ""
  911. //if Class_1 > 0 {
  912. // T_Title = Device.Read_DeviceWarningList_ById(Class_1).T_name
  913. //}
  914. Device_data, _ := Device.Read_DeviceWarning_1(admin_r, 9999, "", T_Name, Time_start, Time_end)
  915. f := excelize.NewFile() // 设置单元格的值
  916. // 这里设置表头
  917. f.SetCellValue("Sheet1", "A1", "报警类型")
  918. f.SetCellValue("Sheet1", "B1", "Sn")
  919. f.SetCellValue("Sheet1", "C1", "设备名称")
  920. f.SetCellValue("Sheet1", "D1", "传感器")
  921. f.SetCellValue("Sheet1", "E1", "温度℃")
  922. f.SetCellValue("Sheet1", "F1", "湿度%")
  923. f.SetCellValue("Sheet1", "G1", "报警内容")
  924. f.SetCellValue("Sheet1", "H1", "记录时间")
  925. f.SetCellValue("Sheet1", "I1", "处理")
  926. f.SetCellValue("Sheet1", "J1", "处理时间")
  927. // 设置列宽
  928. f.SetColWidth("Sheet1", "A", "A", 20)
  929. f.SetColWidth("Sheet1", "B", "B", 25)
  930. f.SetColWidth("Sheet1", "C", "C", 30)
  931. f.SetColWidth("Sheet1", "D", "D", 30)
  932. f.SetColWidth("Sheet1", "E", "E", 10)
  933. f.SetColWidth("Sheet1", "F", "F", 10)
  934. f.SetColWidth("Sheet1", "G", "G", 30)
  935. f.SetColWidth("Sheet1", "H", "H", 15)
  936. f.SetColWidth("Sheet1", "I", "I", 30)
  937. f.SetColWidth("Sheet1", "J", "J", 15)
  938. line := 1
  939. // 循环写入数据
  940. for _, v := range Device_data {
  941. line++
  942. f.SetCellValue("Sheet1", fmt.Sprintf("A%d", line), v.T_Title)
  943. f.SetCellValue("Sheet1", fmt.Sprintf("B%d", line), v.T_sn+"["+strconv.Itoa(v.T_Id)+"]")
  944. f.SetCellValue("Sheet1", fmt.Sprintf("C%d", line), v.T_Addr)
  945. f.SetCellValue("Sheet1", fmt.Sprintf("D%d", line), v.T_Name)
  946. f.SetCellValue("Sheet1", fmt.Sprintf("E%d", line), v.T_T)
  947. f.SetCellValue("Sheet1", fmt.Sprintf("F%d", line), v.T_RH)
  948. f.SetCellValue("Sheet1", fmt.Sprintf("G%d", line), v.T_Remark)
  949. f.SetCellValue("Sheet1", fmt.Sprintf("H%d", line), v.T_Ut)
  950. f.SetCellValue("Sheet1", fmt.Sprintf("I%d", line), v.T_Text)
  951. f.SetCellValue("Sheet1", fmt.Sprintf("J%d", line), v.UpdateTime)
  952. }
  953. timeStr := time.Now().Format("20060102150405")
  954. // 保存文件
  955. if err := f.SaveAs("ofile/" + timeStr + ".xlsx"); err != nil {
  956. fmt.Println(err)
  957. }
  958. url, is := NatsServer.Qiniu_UploadFile(lib.GetCurrentDirectory()+"ofile/"+timeStr+".xlsx", "ofile/"+timeStr+".xlsx")
  959. if !is {
  960. c.Data["json"] = lib.JSONS{Code: 203, Msg: "oss!"}
  961. c.ServeJSON()
  962. return
  963. }
  964. //删除目录
  965. //err := os.Remove("ofile/" + timeStr + ".xlsx")
  966. //if err != nil {
  967. // fmt.Println(err)
  968. //}
  969. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: url}
  970. c.ServeJSON()
  971. return
  972. }
  973. func (c *DeviceController) DeviceWarning_() {
  974. id, _ := c.GetInt("id")
  975. c.Data["T"] = Device.Read_DeviceWarning_ById(id)
  976. c.Data["id"] = id
  977. c.TplName = "Device/DeviceWarning-.html"
  978. }
  979. func (c *DeviceController) DeviceWarning_log() {
  980. id, _ := c.GetInt("id")
  981. T_Log := Device.Read_DeviceWarning_ById(id).T_Log
  982. T_Log = strings.Replace(T_Log, "\n", "<hr>", -1)
  983. c.Data["T_Log"] = T_Log
  984. c.TplName = "Device/DeviceWarning-log.html"
  985. }
  986. func (c *DeviceController) DeviceWarning_M() {
  987. id := c.GetString("id")
  988. c.Data["id"] = id
  989. c.TplName = "Device/DeviceWarning-M.html"
  990. }
  991. func (c *DeviceController) DeviceWarning_Post() {
  992. // 验证登录
  993. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  994. if !b_ {
  995. c.Ctx.Redirect(302, "Login")
  996. return
  997. }
  998. Id, _ := c.GetInt("Id")
  999. T_Text := c.GetString("T_Text")
  1000. t_c := Device.DeviceWarning{
  1001. Id: Id,
  1002. T_Text: T_Text,
  1003. }
  1004. Device.Update_DeviceWarning_ById(t_c)
  1005. System.Add_UserLogs(admin_r.Admin_uuid, "设备管理", "报警处理操作", strconv.Itoa(Id)+"->"+T_Text)
  1006. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  1007. c.ServeJSON()
  1008. return
  1009. }
  1010. func (c *DeviceController) DeviceWarning_Del() {
  1011. // 验证登录
  1012. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  1013. if !b_ {
  1014. c.Ctx.Redirect(302, "Login")
  1015. return
  1016. }
  1017. Id, _ := c.GetInt("Id")
  1018. t_c := Device.DeviceWarning{
  1019. Id: Id,
  1020. }
  1021. Device.Update_DeviceWarning_Delete(t_c)
  1022. System.Add_UserLogs(admin_r.Admin_uuid, "设备管理", "报警删除操作", strconv.Itoa(Id))
  1023. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  1024. c.ServeJSON()
  1025. return
  1026. }
  1027. // 用户管理
  1028. func (c *DeviceController) DeviceBind_html() {
  1029. // 验证登录
  1030. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  1031. if !b_ {
  1032. c.Ctx.Redirect(302, "Login")
  1033. return
  1034. }
  1035. c.Data["Admin_Power"], _ = Admin.Read_AdminPower_ById(admin_r.Admin_power)
  1036. page, _ := c.GetInt("page")
  1037. println(page)
  1038. if page < 1 {
  1039. page = 1
  1040. }
  1041. Name := c.GetString("Name")
  1042. c.Data["Name"] = Name
  1043. c.Data["Power_List"] = Admin.Read_Power_List_ALL_Power_Administration(0)
  1044. Adminpower, _ := Admin.Read_AdminPower_ById(admin_r.Admin_power)
  1045. var cnt int64
  1046. if Adminpower.Power_User_r != 1 {
  1047. c.Ctx.Redirect(302, "Login")
  1048. return
  1049. }
  1050. c.Data["List"], cnt = Admin.Read_Admin_List_ALL_User(page, Name, admin_r.Id)
  1051. fmt.Println("cnt:", cnt)
  1052. page_size := math.Ceil(float64(cnt) / float64(conf.Page_size))
  1053. c.Data["Page"] = page
  1054. c.Data["Page_size"] = page_size
  1055. c.Data["Pages"] = lib.Func_page(int64(page), int64(page_size))
  1056. c.Data["cnt"] = cnt
  1057. c.TplName = "Device/DeviceBind.html"
  1058. }
  1059. func (c *DeviceController) DeviceBind_List() {
  1060. // 验证登录
  1061. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  1062. if !b_ {
  1063. c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  1064. c.ServeJSON()
  1065. return
  1066. }
  1067. if len(c.GetString("Admin_uuid")) > 1 {
  1068. s_, user_r := Admin.Read_Admin_ByAdmin_uuid(c.GetString("Admin_uuid"))
  1069. if s_ != nil {
  1070. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Admin_uuid Err!"}
  1071. c.ServeJSON()
  1072. return
  1073. }
  1074. admin_r = user_r
  1075. }
  1076. type R_JSONS struct {
  1077. //必须的大写开头
  1078. Device_lite []Device.Device
  1079. Num int
  1080. Page int
  1081. Page_size int
  1082. Pages []lib.Page_T
  1083. }
  1084. var r_jsons R_JSONS
  1085. page, _ := c.GetInt("page")
  1086. println(page)
  1087. if page < 1 {
  1088. page = 1
  1089. }
  1090. page_z, _ := c.GetInt("page_z")
  1091. println(page_z)
  1092. if page_z == 0 {
  1093. page_z = conf.Page_size
  1094. }
  1095. Class_1 := c.GetString("Class_1")
  1096. Name := c.GetString("Name")
  1097. T_sn := c.GetString("T_sn")
  1098. T_monitor := c.GetString("T_monitor")
  1099. T_online := c.GetString("T_online")
  1100. //Class_1, _ := c.GetInt("Class_1")
  1101. //Name := c.GetString("Name")
  1102. //T_sn := c.GetString("T_sn")
  1103. //c.Data["Class_1"] = Class_1
  1104. ////c.Data["Name"] = Name
  1105. //c.Data["T_sn"] = T_sn
  1106. var cnt int64
  1107. Device_lite, cnt := Device.Read_Device_ALL_bind_1(admin_r, page, page_z, T_sn, Name, Class_1, T_monitor, T_online)
  1108. r_jsons.Device_lite = Device_lite
  1109. page_size := math.Ceil(float64(cnt) / float64(page_z))
  1110. r_jsons.Page = page
  1111. r_jsons.Page_size = int(page_size)
  1112. r_jsons.Pages = lib.Func_page(int64(page), int64(page_size))
  1113. r_jsons.Num = int(cnt)
  1114. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
  1115. c.ServeJSON()
  1116. return
  1117. }
  1118. func (c *DeviceController) DeviceBind_Sensor_List() {
  1119. // 验证登录
  1120. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  1121. if !b_ {
  1122. c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  1123. c.ServeJSON()
  1124. return
  1125. }
  1126. if len(c.GetString("Admin_uuid")) > 1 {
  1127. s_, user_r := Admin.Read_Admin_ByAdmin_uuid(c.GetString("Admin_uuid"))
  1128. if s_ != nil {
  1129. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Admin_uuid Err!"}
  1130. c.ServeJSON()
  1131. return
  1132. }
  1133. admin_r = user_r
  1134. }
  1135. type R_JSONS struct {
  1136. //必须的大写开头
  1137. Device_lite []Device.R_Device
  1138. Num int
  1139. Page int
  1140. Page_size int
  1141. Pages []lib.Page_T
  1142. }
  1143. var r_jsons R_JSONS
  1144. page, _ := c.GetInt("page")
  1145. println(page)
  1146. if page < 1 {
  1147. page = 1
  1148. }
  1149. page_z, _ := c.GetInt("page_z")
  1150. println(page_z)
  1151. if page_z == 0 {
  1152. page_z = conf.Page_size
  1153. }
  1154. Class_1 := c.GetString("Class_1")
  1155. Name := c.GetString("Name")
  1156. T_sn := c.GetString("T_sn")
  1157. T_monitor := c.GetString("T_monitor")
  1158. T_online := c.GetString("T_online")
  1159. //Class_1, _ := c.GetInt("Class_1")
  1160. //Name := c.GetString("Name")
  1161. //T_sn := c.GetString("T_sn")
  1162. //c.Data["Class_1"] = Class_1
  1163. ////c.Data["Name"] = Name
  1164. //c.Data["T_sn"] = T_sn
  1165. var cnt int64
  1166. Device_lite, cnt := Device.Read_Device_ALL_bind_1(admin_r, page, page_z, T_sn, Name, Class_1, T_monitor, T_online)
  1167. for _, v := range Device_lite {
  1168. r_Device := Device.R_Device{}
  1169. r_Device.T_sn = v.T_sn
  1170. r_Device.T_MSISDN = v.T_MSISDN
  1171. r_Device.T_devName = v.T_devName
  1172. r_Device.T_give = v.T_give
  1173. r_Device.T_online = v.T_online
  1174. r_Device.T_monitor = v.T_monitor
  1175. r_Device.T_Dattery = v.T_Dattery
  1176. r_Device.T_sensor_list, r_Device.T_sensor = Device.Read_DeviceSensor_ByTsn(v.T_sn)
  1177. r_jsons.Device_lite = append(r_jsons.Device_lite, r_Device)
  1178. }
  1179. page_size := math.Ceil(float64(cnt) / float64(page_z))
  1180. r_jsons.Page = page
  1181. r_jsons.Page_size = int(page_size)
  1182. r_jsons.Pages = lib.Func_page(int64(page), int64(page_size))
  1183. r_jsons.Num = int(cnt)
  1184. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
  1185. c.ServeJSON()
  1186. return
  1187. }
  1188. func (c *DeviceController) DeviceBind_html_() {
  1189. // 验证登录
  1190. b_, _ := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  1191. if !b_ {
  1192. c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  1193. c.ServeJSON()
  1194. return
  1195. }
  1196. c.TplName = "Device/DeviceBind-.html"
  1197. }
  1198. func (c *DeviceController) DeviceBind_Add_All() {
  1199. // 验证登录
  1200. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  1201. if !b_ {
  1202. c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  1203. c.ServeJSON()
  1204. return
  1205. }
  1206. s_, user_r := Admin.Read_Admin_ByAdmin_uuid(c.GetString("Admin_uuid"))
  1207. if s_ != nil {
  1208. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Admin_uuid Err!"}
  1209. c.ServeJSON()
  1210. return
  1211. }
  1212. Name := c.GetString("Name")
  1213. T_sn := c.GetString("T_sn")
  1214. num_x := 0
  1215. Device_l := Device.Read_Device_ALL_T_sn_T_devName_bind_1(T_sn, Name, admin_r)
  1216. fmt.Println("len(Device_l):", len(Device_l))
  1217. for _, v := range Device_l {
  1218. Device_bind_list := Device.Read_Device_ALL_T_sn_bind_1(v.T_sn, user_r)
  1219. if len(Device_bind_list) > 0 {
  1220. continue
  1221. }
  1222. T_Bind := Device.Device_Bind_Add(v.T_sn, user_r)
  1223. Device.DeviceSensor_T_Bind_ALL(v.T_sn, T_Bind)
  1224. System.Add_UserLogs(admin_r.Admin_uuid, "设备管理", "设备绑定", v.T_sn+"+>"+c.GetString("Admin_uuid"))
  1225. num_x = num_x + 1
  1226. }
  1227. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: num_x}
  1228. c.ServeJSON()
  1229. return
  1230. }
  1231. func (c *DeviceController) DeviceBind_Add() {
  1232. // 验证登录
  1233. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  1234. if !b_ {
  1235. c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  1236. c.ServeJSON()
  1237. return
  1238. }
  1239. s_, user_r := Admin.Read_Admin_ByAdmin_uuid(c.GetString("Admin_uuid"))
  1240. if s_ != nil {
  1241. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Admin_uuid Err!"}
  1242. c.ServeJSON()
  1243. return
  1244. }
  1245. T_sn := c.GetString("T_sn")
  1246. if len(T_sn) < 5 {
  1247. c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_sn Err!"}
  1248. c.ServeJSON()
  1249. return
  1250. }
  1251. _, err := Device.Read_Device_ByT_sn(T_sn)
  1252. if err != nil {
  1253. c.Data["json"] = lib.JSONS{Code: 206, Msg: "T_sn Err!"}
  1254. c.ServeJSON()
  1255. return
  1256. }
  1257. Device_bind_list := Device.Read_Device_ALL_T_sn_bind_1(T_sn, user_r)
  1258. if len(Device_bind_list) > 0 {
  1259. c.Data["json"] = lib.JSONS{Code: 203, Msg: "ok!"}
  1260. c.ServeJSON()
  1261. return
  1262. }
  1263. // 同步权限
  1264. T_Bind := Device.Device_Bind_Add(T_sn, user_r)
  1265. Device.DeviceSensor_T_Bind_ALL(T_sn, T_Bind)
  1266. System.Add_UserLogs(admin_r.Admin_uuid, "设备管理", "设备绑定", T_sn+"+>"+c.GetString("Admin_uuid"))
  1267. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  1268. c.ServeJSON()
  1269. return
  1270. }
  1271. func (c *DeviceController) DeviceBind_Del() {
  1272. // 验证登录
  1273. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  1274. if !b_ {
  1275. c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  1276. c.ServeJSON()
  1277. return
  1278. }
  1279. s_, user_r := Admin.Read_Admin_ByAdmin_uuid(c.GetString("Admin_uuid"))
  1280. if s_ != nil {
  1281. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Admin_uuid Err!"}
  1282. c.ServeJSON()
  1283. return
  1284. }
  1285. T_sn := c.GetString("T_sn")
  1286. if len(T_sn) < 5 {
  1287. c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_sn Err!"}
  1288. c.ServeJSON()
  1289. return
  1290. }
  1291. _, err := Device.Read_Device_ByT_sn(T_sn)
  1292. if err != nil {
  1293. c.Data["json"] = lib.JSONS{Code: 206, Msg: "T_sn Err!"}
  1294. c.ServeJSON()
  1295. return
  1296. }
  1297. Device_bind_list := Device.Read_Device_ALL_T_sn_bind_1(T_sn, user_r)
  1298. if len(Device_bind_list) == 0 {
  1299. c.Data["json"] = lib.JSONS{Code: 204, Msg: "ok!"}
  1300. c.ServeJSON()
  1301. return
  1302. }
  1303. // 同步权限
  1304. T_Bind := Device.Device_Bind_Del(T_sn, user_r)
  1305. Device.DeviceSensor_T_Bind_ALL(T_sn, T_Bind)
  1306. System.Add_UserLogs(admin_r.Admin_uuid, "设备管理", "设备解除绑定", T_sn+"->"+c.GetString("Admin_uuid"))
  1307. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  1308. c.ServeJSON()
  1309. return
  1310. }
  1311. // 设备分类
  1312. func (c *DeviceController) DeviceClass_html() {
  1313. // 验证登录
  1314. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  1315. if !b_ {
  1316. c.Ctx.Redirect(302, "Login")
  1317. return
  1318. }
  1319. page, _ := c.GetInt("page")
  1320. println(page)
  1321. if page < 1 {
  1322. page = 1
  1323. }
  1324. Name := c.GetString("Name")
  1325. c.Data["Name"] = Name
  1326. var cnt int64
  1327. c.Data["List"], cnt = Device.Read_DeviceClass_ALL_1(admin_r.Admin_uuid, page, Name)
  1328. fmt.Println("cnt:", cnt)
  1329. page_size := math.Ceil(float64(cnt) / float64(conf.Page_size))
  1330. c.Data["Page"] = page
  1331. c.Data["Page_size"] = page_size
  1332. c.Data["Pages"] = lib.Func_page(int64(page), int64(page_size))
  1333. c.Data["cnt"] = cnt
  1334. c.TplName = "Device/DeviceClass.html"
  1335. }
  1336. func (c *DeviceController) DeviceClass_() {
  1337. // 验证登录
  1338. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  1339. if !b_ {
  1340. c.Ctx.Redirect(302, "Login")
  1341. return
  1342. }
  1343. id, _ := c.GetInt("id")
  1344. c.Data["T"], _ = Device.Read_Class_ById(id)
  1345. c.Data["id"] = id
  1346. c.Data["Admin_r"] = admin_r
  1347. c.TplName = "Device/DeviceClass-.html"
  1348. }
  1349. func (c *DeviceController) DeviceClass_Post() {
  1350. // 验证登录
  1351. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  1352. if !b_ {
  1353. c.Ctx.Redirect(302, "Login")
  1354. return
  1355. }
  1356. Id, _ := c.GetInt("Id")
  1357. T_name := c.GetString("T_name")
  1358. T_Notice_wx := c.GetString("T_Notice_wx")
  1359. T_Notice_wx2 := c.GetString("T_Notice_wx2")
  1360. T_Notice_phone := c.GetString("T_Notice_phone")
  1361. T_Notice_message := c.GetString("T_Notice_message")
  1362. T_Notice_mailbox := c.GetString("T_Notice_mailbox")
  1363. T_Notice_mechanism := c.GetString("T_Notice_mechanism")
  1364. t_c := Device.DeviceClass{
  1365. Id: Id,
  1366. T_name: T_name,
  1367. T_Notice_wx: T_Notice_wx,
  1368. T_Notice_wx2: T_Notice_wx2,
  1369. T_Notice_phone: T_Notice_phone,
  1370. T_Notice_message: T_Notice_message,
  1371. T_Notice_mailbox: T_Notice_mailbox,
  1372. T_Notice_mechanism: T_Notice_mechanism,
  1373. }
  1374. if Id == 0 {
  1375. t_c.T_State = 1
  1376. t_c.T_uuid = admin_r.Admin_uuid
  1377. t_c.T_Notice_wx = ""
  1378. t_c.T_Notice_wx2 = ""
  1379. t_c.T_Notice_phone = ""
  1380. t_c.T_Notice_message = ""
  1381. t_c.T_Notice_mailbox = ""
  1382. t_c.T_Notice_mechanism = Device.Read_DeviceWarningList_All_T_Notice_mechanism()
  1383. Device.Add_Class(t_c)
  1384. } else {
  1385. t_c.T_uuid = admin_r.Admin_uuid
  1386. Device.Update_Class_ById(t_c)
  1387. }
  1388. System.Add_UserLogs_T(admin_r.Admin_uuid, "设备管理", "分类操作", t_c)
  1389. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  1390. c.ServeJSON()
  1391. return
  1392. }
  1393. func (c *DeviceController) DeviceWarningList_T_Tips() {
  1394. // 验证登录
  1395. b_, _ := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  1396. if !b_ {
  1397. c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  1398. c.ServeJSON()
  1399. return
  1400. }
  1401. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: Device.Read_DeviceWarningList_All_T_Notice_mechanism()}
  1402. c.ServeJSON()
  1403. return
  1404. }
  1405. func (c *DeviceController) DeviceClass_Del() {
  1406. // 验证登录
  1407. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  1408. if !b_ {
  1409. c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  1410. c.ServeJSON()
  1411. return
  1412. }
  1413. id, _ := c.GetInt("Id")
  1414. class_r, err := Device.Read_Class_ById(id)
  1415. if err != nil {
  1416. c.Data["json"] = lib.JSONS{Code: 202, Msg: "id Err!"}
  1417. c.ServeJSON()
  1418. return
  1419. }
  1420. if class_r.T_uuid != admin_r.Admin_uuid {
  1421. c.Data["json"] = lib.JSONS{Code: 203, Msg: "T_uuid Err!"}
  1422. c.ServeJSON()
  1423. return
  1424. }
  1425. Device.Delete_Class_ById(id)
  1426. DeviceSensor_class_list := Device.Read_DeviceSensor_ALL_class_1(id)
  1427. for _, v := range DeviceSensor_class_list {
  1428. Device.DeviceSensor_Bind_Del(v.T_sn, v.T_id, id)
  1429. }
  1430. System.Add_UserLogs(admin_r.Admin_uuid, "设备管理", "删除分类操作", strconv.Itoa(id))
  1431. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  1432. c.ServeJSON()
  1433. return
  1434. }
  1435. func (c *DeviceController) DeviceClass_Syn() {
  1436. // 验证登录
  1437. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  1438. if !b_ {
  1439. c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  1440. c.ServeJSON()
  1441. return
  1442. }
  1443. s_, user_r := Admin.Read_Admin_ByAdmin_uuid(c.GetString("Admin_uuid"))
  1444. if s_ != nil {
  1445. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Admin_uuid Err!"}
  1446. c.ServeJSON()
  1447. return
  1448. }
  1449. // 先全部 清掉
  1450. Device.Device_Bind_ALL_Del(user_r)
  1451. class_r := Device.Read_DeviceClass_ALL_T_uuid_1(user_r.Admin_uuid)
  1452. for _, v := range class_r {
  1453. fmt.Println("清掉:", v.Id)
  1454. // 删除分类
  1455. Device.Delete_Class_ById(v.Id)
  1456. // 删除 传感器分类
  1457. Device.DeviceSensor_T_Calss_ALL_Del(v.Id)
  1458. //Device.DeviceSensor_T_Bind_ALL_Del(user_r)
  1459. }
  1460. // 重新插入 分类
  1461. num_x := 0
  1462. class_r = Device.Read_DeviceClass_ALL_T_uuid_1(admin_r.Admin_uuid)
  1463. for _, v := range class_r {
  1464. fmt.Println("插入:", v.Id)
  1465. t_c := Device.DeviceClass{
  1466. T_uuid: user_r.Admin_uuid,
  1467. T_name: v.T_name,
  1468. T_Notice_wx: "",
  1469. T_Notice_phone: "",
  1470. T_Notice_message: "",
  1471. T_Notice_mailbox: "",
  1472. T_State: 1,
  1473. }
  1474. num_x = num_x + 1
  1475. // 添加分类
  1476. cid, err := Device.Add_Class(t_c)
  1477. if err != nil {
  1478. c.Data["json"] = lib.JSONS{Code: 200, Msg: "Add_Class E!"}
  1479. c.ServeJSON()
  1480. return
  1481. }
  1482. fmt.Println("cid:", cid)
  1483. // 添加 传感器分类
  1484. DeviceSensor_class_list := Device.Read_DeviceSensor_ALL_class_1(int(v.Id))
  1485. for _, v_c := range DeviceSensor_class_list {
  1486. // 绑定所有分类
  1487. Device.DeviceSensor_T_Calss_Add(v_c.T_sn, v_c.T_id, int(cid))
  1488. // 绑定所有权限
  1489. //Device_r, _ := Device.Read_Device_ByT_sn(v_c.T_sn)
  1490. //Device.DeviceSensor_T_Bind_Add(v_c.T_sn, v_c.T_id, user_r)
  1491. T_Bind := Device.Device_Bind_Add(v_c.T_sn, user_r)
  1492. Device.DeviceSensor_T_Bind_ALL(v_c.T_sn, T_Bind)
  1493. }
  1494. //
  1495. }
  1496. System.Add_UserLogs(admin_r.Admin_uuid, "设备管理", "同步分类操作", "->"+user_r.Admin_uuid)
  1497. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: num_x}
  1498. c.ServeJSON()
  1499. return
  1500. }
  1501. func (c *DeviceController) DeviceClassBind_html_() {
  1502. // 验证登录
  1503. b_, _ := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  1504. if !b_ {
  1505. c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  1506. c.ServeJSON()
  1507. return
  1508. }
  1509. c.TplName = "Device/DeviceClassBind-.html"
  1510. }
  1511. func (c *DeviceController) DeviceClassBind_List() {
  1512. // 验证登录
  1513. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  1514. if !b_ {
  1515. c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  1516. c.ServeJSON()
  1517. return
  1518. }
  1519. type R_JSONS struct {
  1520. //必须的大写开头
  1521. DeviceSensor_lite []Device.DeviceSensor_R
  1522. Num int
  1523. Page int
  1524. Page_size int
  1525. Pages []lib.Page_T
  1526. }
  1527. var r_jsons R_JSONS
  1528. page, _ := c.GetInt("page")
  1529. println(page)
  1530. if page < 1 {
  1531. page = 1
  1532. }
  1533. Name := c.GetString("Name")
  1534. T_sn := c.GetString("T_sn")
  1535. T_calss_id, _ := c.GetInt("T_calss_id")
  1536. page_z, _ := c.GetInt("page_z")
  1537. if page_z == 0 {
  1538. page_z = conf.Page_size
  1539. }
  1540. //Name := c.GetString("Name")
  1541. //T_sn := c.GetString("T_sn")
  1542. //c.Data["Class_1"] = Class_1
  1543. ////c.Data["Name"] = Name
  1544. //c.Data["T_sn"] = T_sn
  1545. R_DeviceClass, err := Device.Read_Class_ById(T_calss_id)
  1546. if err != nil {
  1547. c.Data["json"] = lib.JSONS{Code: 205, Msg: "T_class_id Err!"}
  1548. c.ServeJSON()
  1549. return
  1550. }
  1551. if R_DeviceClass.T_uuid != admin_r.Admin_uuid {
  1552. c.Data["json"] = lib.JSONS{Code: 205, Msg: "T_class_id != Admin_uuid Err!"}
  1553. c.ServeJSON()
  1554. return
  1555. }
  1556. var cnt int64
  1557. Device_lite, cnt := Device.Read_DeviceSensor_class_ALL_1(admin_r, T_calss_id, page, page_z, T_sn, Name, "")
  1558. r_jsons.DeviceSensor_lite = Device_lite
  1559. page_size := math.Ceil(float64(cnt) / float64(page_z))
  1560. r_jsons.Page = page
  1561. r_jsons.Page_size = int(page_size)
  1562. r_jsons.Pages = lib.Func_page(int64(page), int64(page_size))
  1563. r_jsons.Num = int(cnt)
  1564. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
  1565. c.ServeJSON()
  1566. return
  1567. }
  1568. func (c *DeviceController) DeviceClassBind_Add() {
  1569. // 验证登录
  1570. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  1571. if !b_ {
  1572. c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  1573. c.ServeJSON()
  1574. return
  1575. }
  1576. T_class_id, _ := c.GetInt("T_class_id")
  1577. T_sn := c.GetString("T_sn")
  1578. T_id, _ := c.GetInt("T_id")
  1579. if T_class_id == 0 || T_id == 0 || len(T_sn) == 0 {
  1580. c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_sn T_id T_class_id Err!"}
  1581. c.ServeJSON()
  1582. return
  1583. }
  1584. if _, err := Device.Read_Device_ByT_sn(T_sn); err != nil {
  1585. c.Data["json"] = lib.JSONS{Code: 204, Msg: "T_id Err!"}
  1586. c.ServeJSON()
  1587. return
  1588. }
  1589. R_DeviceClass, err := Device.Read_Class_ById(T_class_id)
  1590. if err != nil {
  1591. c.Data["json"] = lib.JSONS{Code: 205, Msg: "T_class_id Err!"}
  1592. c.ServeJSON()
  1593. return
  1594. }
  1595. if R_DeviceClass.T_uuid != admin_r.Admin_uuid {
  1596. c.Data["json"] = lib.JSONS{Code: 205, Msg: "T_class_id != Admin_uuid Err!"}
  1597. c.ServeJSON()
  1598. return
  1599. }
  1600. DeviceSensor_class_list := Device.Read_DeviceSensor_ALL_T_sn_T_id_class_1(T_sn, T_id, T_class_id)
  1601. if len(DeviceSensor_class_list) > 0 {
  1602. c.Data["json"] = lib.JSONS{Code: 203, Msg: "ok!"}
  1603. c.ServeJSON()
  1604. return
  1605. }
  1606. Device.DeviceSensor_T_Calss_Add(T_sn, T_id, T_class_id)
  1607. System.Add_UserLogs(admin_r.Admin_uuid, "设备管理", "分类绑定操作", strconv.Itoa(T_class_id)+"+>"+T_sn+"-"+strconv.Itoa(T_id))
  1608. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  1609. c.ServeJSON()
  1610. return
  1611. }
  1612. func (c *DeviceController) DeviceClassBind_Del() {
  1613. // 验证登录
  1614. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  1615. if !b_ {
  1616. c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  1617. c.ServeJSON()
  1618. return
  1619. }
  1620. T_class_id, _ := c.GetInt("T_class_id")
  1621. T_sn := c.GetString("T_sn")
  1622. T_id, _ := c.GetInt("T_id")
  1623. if T_class_id == 0 || T_id == 0 || len(T_sn) == 0 {
  1624. c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_sn T_id T_class_id Err!"}
  1625. c.ServeJSON()
  1626. return
  1627. }
  1628. if _, err := Device.Read_Device_ByT_sn(T_sn); err != nil {
  1629. c.Data["json"] = lib.JSONS{Code: 204, Msg: "T_id Err!"}
  1630. c.ServeJSON()
  1631. return
  1632. }
  1633. R_DeviceClass, err := Device.Read_Class_ById(T_class_id)
  1634. if err != nil {
  1635. c.Data["json"] = lib.JSONS{Code: 205, Msg: "T_class_id Err!"}
  1636. c.ServeJSON()
  1637. return
  1638. }
  1639. if R_DeviceClass.T_uuid != admin_r.Admin_uuid {
  1640. c.Data["json"] = lib.JSONS{Code: 205, Msg: "T_class_id != Admin_uuid Err!"}
  1641. c.ServeJSON()
  1642. return
  1643. }
  1644. DeviceSensor_class_list := Device.Read_DeviceSensor_ALL_T_sn_T_id_class_1(T_sn, T_id, T_class_id)
  1645. if len(DeviceSensor_class_list) == 0 {
  1646. c.Data["json"] = lib.JSONS{Code: 203, Msg: "ok!"}
  1647. c.ServeJSON()
  1648. return
  1649. }
  1650. Device.DeviceSensor_Bind_Del(T_sn, T_id, T_class_id)
  1651. System.Add_UserLogs(admin_r.Admin_uuid, "设备管理", "分类删除绑定操作", strconv.Itoa(T_class_id)+"->"+T_sn+"-"+strconv.Itoa(T_id))
  1652. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  1653. c.ServeJSON()
  1654. return
  1655. }
  1656. func (c *DeviceController) Get_DeviceClassId() {
  1657. // 验证登录
  1658. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  1659. if !b_ {
  1660. c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  1661. c.ServeJSON()
  1662. return
  1663. }
  1664. T_class_id, _ := c.GetInt("T_class_id")
  1665. R_DeviceClass, err := Device.Read_Class_ById(T_class_id)
  1666. if err != nil {
  1667. c.Data["json"] = lib.JSONS{Code: 201, Msg: "T_class_id Err!"}
  1668. c.ServeJSON()
  1669. return
  1670. }
  1671. if R_DeviceClass.T_uuid != admin_r.Admin_uuid {
  1672. c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_class_id != T_uuid Err!"}
  1673. c.ServeJSON()
  1674. return
  1675. }
  1676. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: R_DeviceClass}
  1677. c.ServeJSON()
  1678. return
  1679. }
  1680. // 任务列表
  1681. func (c *DeviceController) DeviceTask_List() {
  1682. // 验证登录
  1683. b_, _ := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  1684. if !b_ {
  1685. c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  1686. c.ServeJSON()
  1687. return
  1688. }
  1689. T_sn := c.GetString("T_sn")
  1690. Time_end := c.GetString("Time_end")
  1691. Time_start := c.GetString("Time_start")
  1692. DeviceTask_lite, _ := Device.Read_DeviceTask_All_50(T_sn, Time_end, Time_start)
  1693. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: DeviceTask_lite}
  1694. c.ServeJSON()
  1695. return
  1696. }
  1697. // 任务列表
  1698. func (c *DeviceController) DeviceTask_Post() {
  1699. // 验证登录
  1700. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  1701. if !b_ {
  1702. c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  1703. c.ServeJSON()
  1704. return
  1705. }
  1706. T_sn := c.GetString("T_sn")
  1707. T_task := c.GetString("T_task")
  1708. NatsServer.Set_DeviceTask(Device.Device_task{
  1709. T_sn: T_sn,
  1710. T_task: T_task,
  1711. })
  1712. System.Add_UserLogs(admin_r.Admin_uuid, "设备管理", "远程启停", T_sn+"-"+T_task)
  1713. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  1714. c.ServeJSON()
  1715. return
  1716. }
  1717. func (c *DeviceController) Get_DeviceClassId_QRCode() {
  1718. // 验证登录
  1719. b_, _ := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  1720. if !b_ {
  1721. c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  1722. c.ServeJSON()
  1723. return
  1724. }
  1725. T_calss_id := c.GetString("T_class_id")
  1726. if len(T_calss_id) == 0 {
  1727. c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_calss_id Err!"}
  1728. c.ServeJSON()
  1729. return
  1730. }
  1731. T_calss_id_str, _ := NatsServer.Wx_GenerateQRCode("-|" + lib.AesEncryptCBC(T_calss_id, "0123456789012345") + "|- @宝智达 微信公众号通知")
  1732. if len(T_calss_id_str) == 0 {
  1733. c.Data["json"] = lib.JSONS{Code: 201, Msg: "Err!"}
  1734. c.ServeJSON()
  1735. return
  1736. }
  1737. type Text struct {
  1738. QR string
  1739. Code string
  1740. }
  1741. T_calss_id_str = "https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=" + T_calss_id_str
  1742. Text_r := Text{
  1743. QR: T_calss_id_str,
  1744. Code: "请将本内容发送到 深圳市宝智达科技有限公司 微信公众号-|" + lib.AesEncryptCBC(T_calss_id, "0123456789012345") + "|- @宝智达 微信公众号通知 ",
  1745. }
  1746. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: Text_r}
  1747. c.ServeJSON()
  1748. return
  1749. }
  1750. func (c *DeviceController) Get_DeviceClassId_QRCode2() {
  1751. // 验证登录
  1752. b_, _ := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  1753. if !b_ {
  1754. c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  1755. c.ServeJSON()
  1756. return
  1757. }
  1758. T_calss_id := c.GetString("T_class_id")
  1759. if len(T_calss_id) == 0 {
  1760. c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_calss_id Err!"}
  1761. c.ServeJSON()
  1762. return
  1763. }
  1764. T_calss_id_str, _ := NatsServer.Wx_GenerateQRCode2("-|" + lib.AesEncryptCBC(T_calss_id, "0123456789012345") + "|- @宝智达 微信公众号通知")
  1765. if len(T_calss_id_str) == 0 {
  1766. c.Data["json"] = lib.JSONS{Code: 201, Msg: "Err!"}
  1767. c.ServeJSON()
  1768. return
  1769. }
  1770. type Text struct {
  1771. QR string
  1772. Code string
  1773. }
  1774. T_calss_id_str = "https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=" + T_calss_id_str
  1775. Text_r := Text{
  1776. QR: T_calss_id_str,
  1777. Code: "请将本内容发送到 宝智达冷链科技有限公司 微信公众号-|" + lib.AesEncryptCBC(T_calss_id, "0123456789012345") + "|- @宝智达 微信公众号通知 ",
  1778. }
  1779. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: Text_r}
  1780. c.ServeJSON()
  1781. return
  1782. }
  1783. func (c *DeviceController) DeviceData_Add() {
  1784. // 验证登录
  1785. if c.GetString("Tokey") != "1f9db553" {
  1786. c.Data["json"] = lib.JSONS{Code: 201, Msg: "Tokey Err!"}
  1787. c.ServeJSON()
  1788. return
  1789. }
  1790. T_sn := c.GetString("T_sn")
  1791. T_name := c.GetString("T_name")
  1792. T_id, _ := c.GetInt("T_id")
  1793. T_t, _ := c.GetFloat("T_t")
  1794. T_rh, _ := c.GetFloat("T_rh")
  1795. T_Tlower, _ := c.GetFloat("T_Tlower")
  1796. T_Tupper, _ := c.GetFloat("T_Tupper")
  1797. T_RHlower, _ := c.GetFloat("T_RHlower")
  1798. T_RHupper, _ := c.GetFloat("T_RHupper")
  1799. T_Site := c.GetString("T_Site")
  1800. T_Dattery, _ := c.GetInt("T_Dattery")
  1801. T_time, err := time.Parse("2006-01-02 15:04:05", c.GetString("T_time"))
  1802. if err != nil {
  1803. c.Data["json"] = lib.JSONS{Code: 201, Msg: "T_time Err!"}
  1804. c.ServeJSON()
  1805. return
  1806. }
  1807. //// 更新记录 - 缓存
  1808. DeviceData_t := Device.DeviceData_T{
  1809. T_name: T_name,
  1810. T_id: T_id,
  1811. T_t: float32(T_t),
  1812. T_rh: float32(T_rh),
  1813. T_Tlower: float32(T_Tlower),
  1814. T_Tupper: float32(T_Tupper),
  1815. T_RHlower: float32(T_RHlower),
  1816. T_RHupper: float32(T_RHupper),
  1817. T_Site: T_Site,
  1818. T_Dattery: T_Dattery,
  1819. T_time: T_time,
  1820. }
  1821. if !Device.Add_DeviceData(T_sn, DeviceData_t) {
  1822. c.Data["json"] = lib.JSONS{Code: 201, Msg: "Err!"}
  1823. c.ServeJSON()
  1824. return
  1825. }
  1826. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  1827. c.ServeJSON()
  1828. return
  1829. }
  1830. // 列表 - 设备日志
  1831. func (c *DeviceController) DeviceLogs() {
  1832. page, _ := c.GetInt("page")
  1833. println(page)
  1834. if page < 1 {
  1835. page = 1
  1836. }
  1837. T_sn := c.GetString("T_sn")
  1838. c.Data["T_sn"] = T_sn
  1839. var cnt int64
  1840. c.Data["List"], cnt = System.Read_DeviceLogs_ALL(page, T_sn)
  1841. page_size := math.Ceil(float64(cnt) / float64(conf.Page_size))
  1842. c.Data["Page"] = page
  1843. c.Data["Page_size"] = page_size
  1844. c.Data["Pages"] = lib.Func_page(int64(page), int64(page_size))
  1845. c.Data["cnt"] = cnt
  1846. c.TplName = "Device/DeviceLogs.html"
  1847. }