Device.go 58 KB

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