Device.go 58 KB

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