Device.go 59 KB

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