DeviceClass.go 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699
  1. package controllers
  2. import (
  3. "ColdVerify_server/conf"
  4. "ColdVerify_server/lib"
  5. "ColdVerify_server/models/Account"
  6. "ColdVerify_server/models/Certificate"
  7. "ColdVerify_server/models/Device"
  8. "ColdVerify_server/models/System"
  9. "ColdVerify_server/models/Task"
  10. "fmt"
  11. beego "github.com/beego/beego/v2/server/web"
  12. "math"
  13. "strings"
  14. )
  15. type DeviceClassController struct {
  16. beego.Controller
  17. }
  18. // 列表 -
  19. func (c *DeviceClassController) List() {
  20. // 验证登录 User_is, User_r
  21. User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  22. if !User_is {
  23. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  24. c.ServeJSON()
  25. return
  26. }
  27. var r_jsons lib.R_JSONS
  28. page, _ := c.GetInt("page")
  29. if page < 1 {
  30. page = 1
  31. }
  32. page_z, _ := c.GetInt("page_z")
  33. if page_z < 1 {
  34. page_z = conf.Page_size
  35. }
  36. T_name := c.GetString("T_name")
  37. var cnt int64
  38. List, cnt := Device.Read_DeviceClass_List(User_r.T_uuid, T_name, page, page_z)
  39. page_size := math.Ceil(float64(cnt) / float64(page_z))
  40. r_jsons.List = List
  41. r_jsons.Page = page
  42. r_jsons.Page_size = int(page_size)
  43. r_jsons.Pages = lib.Func_page(int64(page), int64(page_size))
  44. r_jsons.Num = int(cnt)
  45. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
  46. c.ServeJSON()
  47. return
  48. }
  49. // 获取-
  50. func (c *DeviceClassController) Get() {
  51. // 验证登录 User_is, User_r
  52. _, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  53. if !User_is {
  54. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  55. c.ServeJSON()
  56. return
  57. }
  58. Id, err := c.GetInt("Id")
  59. if err != nil {
  60. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  61. c.ServeJSON()
  62. return
  63. }
  64. r, is := Device.Read_DeviceClass_ById(Id)
  65. if !is {
  66. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  67. c.ServeJSON()
  68. return
  69. }
  70. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r}
  71. c.ServeJSON()
  72. return
  73. }
  74. // 添加-
  75. func (c *DeviceClassController) Add() {
  76. // 验证登录 User_is, User_r
  77. User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  78. if !User_is {
  79. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  80. c.ServeJSON()
  81. return
  82. }
  83. T_name := c.GetString("T_name")
  84. var_ := Device.DeviceClass{
  85. T_uuid: User_r.T_uuid,
  86. T_name: T_name,
  87. T_State: 1,
  88. }
  89. Id, is := Device.Add_DeviceClass(var_)
  90. if !is {
  91. c.Data["json"] = lib.JSONS{Code: 202, Msg: "添加失败!"}
  92. c.ServeJSON()
  93. return
  94. }
  95. System.Add_UserLogs_T(User_r.T_uuid, "分类管理", "添加", var_)
  96. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: Id}
  97. c.ServeJSON()
  98. return
  99. }
  100. // 修改-
  101. func (c *DeviceClassController) Up() {
  102. // 验证登录 User_is, User_r
  103. User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  104. if !User_is {
  105. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  106. c.ServeJSON()
  107. return
  108. }
  109. T_name := c.GetString("T_name")
  110. Id, err := c.GetInt("Id")
  111. if err != nil {
  112. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  113. c.ServeJSON()
  114. return
  115. }
  116. r, is := Device.Read_DeviceClass_ById(Id)
  117. if !is {
  118. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  119. c.ServeJSON()
  120. return
  121. }
  122. // .......
  123. if len(T_name) > 0 {
  124. r.T_name = T_name
  125. }
  126. // .......
  127. if !Device.Update_DeviceClass(r, "T_name") {
  128. c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改失败!"}
  129. c.ServeJSON()
  130. return
  131. }
  132. System.Add_UserLogs_T(User_r.T_uuid, "分类管理", "修改", r)
  133. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  134. c.ServeJSON()
  135. return
  136. }
  137. // 删除-
  138. func (c *DeviceClassController) Del() {
  139. // 验证登录 User_is, User_r
  140. User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  141. if !User_is {
  142. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  143. c.ServeJSON()
  144. return
  145. }
  146. Id, err := c.GetInt("Id")
  147. if err != nil {
  148. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  149. c.ServeJSON()
  150. return
  151. }
  152. if r, is := Device.Read_DeviceClass_ById(Id); is {
  153. if !Device.Delete_DeviceClass_(r) {
  154. c.Data["json"] = lib.JSONS{Code: 202, Msg: "删除失败!"}
  155. c.ServeJSON()
  156. return
  157. }
  158. System.Add_UserLogs_T(User_r.T_uuid, "分类管理", "删除", r)
  159. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  160. c.ServeJSON()
  161. return
  162. }
  163. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  164. c.ServeJSON()
  165. return
  166. }
  167. //--------------------------
  168. // 列表 -
  169. func (c *DeviceClassController) List_List() {
  170. // 验证登录 User_is, User_r
  171. //_, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  172. //if !User_is {
  173. // c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  174. // c.ServeJSON()
  175. // return
  176. //}
  177. var r_jsons lib.R_JSONS
  178. page, _ := c.GetInt("page")
  179. if page < 1 {
  180. page = 1
  181. }
  182. page_z, _ := c.GetInt("page_z")
  183. if page_z < 1 {
  184. page_z = conf.Page_size
  185. }
  186. T_class, _ := c.GetInt("T_class")
  187. T_sn := c.GetString("T_sn")
  188. T_remark := c.GetString("T_remark")
  189. _, is := Device.Read_DeviceClass_ById(T_class)
  190. if !is {
  191. c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_class 错误!"}
  192. c.ServeJSON()
  193. return
  194. }
  195. var cnt int64
  196. //List, cnt := Device.Read_DeviceClassList_List(T_class, T_sn, page, 9999)
  197. List, cnt := Device.Read_DeviceClassList_OrderList(T_class, T_sn, T_remark, page, 9999)
  198. page_size := math.Ceil(float64(cnt) / float64(page_z))
  199. r_jsons.List = List
  200. r_jsons.Page = page
  201. r_jsons.Page_size = int(page_size)
  202. r_jsons.Pages = lib.Func_page(int64(page), int64(page_size))
  203. r_jsons.Num = int(cnt)
  204. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
  205. c.ServeJSON()
  206. return
  207. }
  208. // 添加- 旧功能
  209. func (c *DeviceClassController) List_Add1() {
  210. // 验证登录 User_is, User_r
  211. User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  212. if !User_is {
  213. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  214. c.ServeJSON()
  215. return
  216. }
  217. T_class, _ := c.GetInt("T_class")
  218. //方式1:001,002,003,004,005,008
  219. //方式2:001~005,008
  220. T_layout_no_list := c.GetString("T_layout_no_list")
  221. //T_sn := c.GetString("T_sn")
  222. T_remark := c.GetString("T_remark")
  223. _, is := Device.Read_DeviceClass_ById(T_class)
  224. if !is {
  225. c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_class 错误"}
  226. c.ServeJSON()
  227. return
  228. }
  229. list := strings.Split(strings.TrimRight(T_layout_no_list, ","), ",")
  230. snMap := make(map[string]string)
  231. excludeId := make(map[string]struct{})
  232. errList := []string{}
  233. var successNum int // 成功数量
  234. for _, v := range list {
  235. if strings.Contains(v, "!") {
  236. excludeId[fmt.Sprintf("%03d", lib.To_int(strings.TrimLeft(strings.Trim(v, "!"), "0")))] = struct{}{}
  237. continue
  238. }
  239. // 001~005
  240. if strings.Contains(v, "~") {
  241. vlist := strings.Split(v, "~")
  242. if len(vlist) != 2 {
  243. c.Data["json"] = lib.JSONS{Code: 202, Msg: "布局编号格式错误!"}
  244. c.ServeJSON()
  245. return
  246. }
  247. vstart, vend := lib.To_int(strings.TrimLeft(vlist[0], "0")), lib.To_int(strings.TrimLeft(vlist[1], "0"))
  248. for i := vstart; i < vend+1; i++ {
  249. T_id := fmt.Sprintf("%03d", i)
  250. cert, is := Certificate.Read_Certificate_ByT_layout_no(T_id)
  251. if !is {
  252. //c.Data["json"] = lib.JSONS{Code: 202, Msg: fmt.Sprintf("%s布局编号不存在!", T_id)}
  253. //c.ServeJSON()
  254. //return
  255. errList = append(errList, fmt.Sprintf("%s布局编号不存在!", T_id))
  256. continue
  257. }
  258. snMap[T_id] = cert.T_sn
  259. }
  260. } else {
  261. // 001,002
  262. cert, is := Certificate.Read_Certificate_ByT_layout_no(v)
  263. if !is {
  264. //c.Data["json"] = lib.JSONS{Code: 202, Msg: fmt.Sprintf("%s布局编号不存在!", v)}
  265. //c.ServeJSON()
  266. //return
  267. errList = append(errList, v)
  268. continue
  269. }
  270. snMap[v] = cert.T_sn
  271. }
  272. }
  273. errList2 := []string{}
  274. succesId := []string{}
  275. for T_id, T_sn := range snMap {
  276. if _, ok := excludeId[T_id]; ok {
  277. continue
  278. }
  279. //if _, is = Device.Read_Device(T_sn); !is {
  280. // c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_sn 不存在!"}
  281. // c.ServeJSON()
  282. // return
  283. //}
  284. if dc, is := Device.Read_DeviceClassList_T_class_T_sn(T_class, T_sn); is && dc.Id > 0 {
  285. successNum += 1
  286. continue
  287. }
  288. var pdf Certificate.CertificatePdf
  289. pdfList, _ := Certificate.Read_CertificatePdf_Newest(T_id)
  290. if len(pdfList) > 0 {
  291. pdf = pdfList[0]
  292. }
  293. var_ := Device.DeviceClassList{
  294. T_class: T_class,
  295. T_id: T_id,
  296. T_sn: T_sn,
  297. T_failure_time: pdf.T_failure_time,
  298. T_pdf: pdf.T_pdf,
  299. T_remark: T_remark,
  300. T_State: 1,
  301. }
  302. _, is = Device.Add_DeviceClassList(var_)
  303. if !is {
  304. //c.Data["json"] = lib.JSONS{Code: 202, Msg: "添加失败!"}
  305. //c.ServeJSON()
  306. //return
  307. errList2 = append(errList2, T_id)
  308. continue
  309. }
  310. successNum += 1
  311. succesId = append(succesId, T_id)
  312. System.Add_UserLogs_T(User_r.T_uuid, "分类设备管理", "添加", var_)
  313. }
  314. if len(errList) == 0 && len(errList2) == 0 {
  315. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: successNum}
  316. c.ServeJSON()
  317. return
  318. }
  319. var errStr string
  320. if len(errList) > 0 {
  321. errStr += strings.Join(errList, ",") + "编号不存在"
  322. }
  323. if len(errList2) > 0 {
  324. if len(errStr) > 0 {
  325. errStr += ","
  326. }
  327. errStr += strings.Join(errList2, ",") + "添加失败"
  328. }
  329. //if len(succesId) > 0 {
  330. // if len(errStr) > 0 {
  331. // errStr += ","
  332. // }
  333. // errStr += strings.Join(succesId, ",") + "添加成功"
  334. //}
  335. c.Data["json"] = lib.JSONS{Code: 210, Msg: errStr, Data: successNum}
  336. c.ServeJSON()
  337. return
  338. }
  339. func (c *DeviceClassController) List_Add() {
  340. // 验证登录 User_is, User_r
  341. User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  342. if !User_is {
  343. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  344. c.ServeJSON()
  345. return
  346. }
  347. T_class, _ := c.GetInt("T_class")
  348. T_sn_id_list := c.GetString("T_sn_id_list")
  349. list := strings.Split(strings.TrimRight(T_sn_id_list, "|"), "|")
  350. T_remark := c.GetString("T_remark")
  351. _, is := Device.Read_DeviceClass_ById(T_class)
  352. if !is {
  353. c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_class 错误"}
  354. c.ServeJSON()
  355. return
  356. }
  357. var successNum int // 成功数量
  358. errList := []string{}
  359. errList2 := []string{}
  360. succesId := []string{}
  361. for _, sn_id := range list {
  362. T_sn := strings.Split(sn_id, ",")[0]
  363. T_id := strings.Split(sn_id, ",")[1]
  364. // 判断是否已存在sn
  365. dc, is := Device.Read_DeviceClassList_T_class_T_sn(T_class, T_sn)
  366. // 添加的id和数据库已存在id相同
  367. if is && dc.T_id == T_id {
  368. successNum += 1
  369. continue
  370. }
  371. // 添加的id和数据库已存在id不同
  372. if is && dc.T_id != T_id {
  373. _, is = Device.Read_DeviceClassList_T_class_T_id(T_class, T_id)
  374. if is {
  375. errList2 = append(errList2, sn_id)
  376. continue
  377. }
  378. dc.T_id = T_id
  379. dc.T_remark = T_remark
  380. if !Device.Update_DeviceClassList(dc, "T_id", "T_remark") {
  381. errList = append(errList, sn_id)
  382. } else {
  383. successNum += 1
  384. }
  385. continue
  386. }
  387. var pdf Certificate.CertificatePdf
  388. //pdfList, _ := Certificate.Read_CertificatePdf_Newest(T_sn)
  389. pdfList, _ := Certificate.Read_CertificatePdf_T_layout_no(T_id, "")
  390. if len(pdfList) > 0 {
  391. pdf = pdfList[0]
  392. }
  393. var_ := Device.DeviceClassList{
  394. T_class: T_class,
  395. T_id: T_id,
  396. T_sn: T_sn,
  397. T_failure_time: pdf.T_failure_time,
  398. T_pdf: pdf.T_pdf,
  399. T_Certificate_sn: pdf.T_Certificate_sn,
  400. T_remark: T_remark,
  401. T_State: 1,
  402. }
  403. _, is = Device.Add_DeviceClassList(var_)
  404. if !is {
  405. errList = append(errList, sn_id)
  406. continue
  407. }
  408. successNum += 1
  409. succesId = append(succesId, sn_id)
  410. System.Add_UserLogs_T(User_r.T_uuid, "分类设备管理", "添加", var_)
  411. }
  412. if len(errList) == 0 && len(errList2) == 0 {
  413. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: successNum}
  414. c.ServeJSON()
  415. return
  416. }
  417. var errStr string
  418. if len(errList2) > 0 {
  419. errStr += strings.Join(errList2, ",") + "编号已存在"
  420. }
  421. if len(errList) > 0 {
  422. if len(errStr) > 0 {
  423. errStr += ","
  424. }
  425. errStr += strings.Join(errList, ",") + "添加失败"
  426. }
  427. c.Data["json"] = lib.JSONS{Code: 210, Msg: errStr, Data: successNum}
  428. c.ServeJSON()
  429. return
  430. }
  431. func (c *DeviceClassController) List_Copy() {
  432. // 验证登录 User_is, User_r
  433. _, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  434. if !User_is {
  435. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  436. c.ServeJSON()
  437. return
  438. }
  439. T_copy_task_id := c.GetString("T_copy_task_id")
  440. copy_task, is := Task.Read_Task(T_copy_task_id)
  441. if !is {
  442. c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_copy_task_id 错误!"}
  443. c.ServeJSON()
  444. return
  445. }
  446. T_paste_task_id := c.GetString("T_paste_task_id")
  447. paste_task, is := Task.Read_Task(T_paste_task_id)
  448. if !is {
  449. c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_paste_task_id 错误!"}
  450. c.ServeJSON()
  451. return
  452. }
  453. copyList, cnt := Device.Read_DeviceClassList_OrderList(copy_task.T_class, "", "", 0, 9999)
  454. var successNum int // 成功数量
  455. errList := []string{}
  456. for _, v := range copyList {
  457. ds, is2 := Device.Read_DeviceClassList_T_class_T_id(paste_task.T_class, v.T_id)
  458. // id存在 更新
  459. if is2 {
  460. ds.T_sn = v.T_sn
  461. ds.T_remark = v.T_remark
  462. if !Device.Update_DeviceClassList(ds, "T_sn", "T_remark") {
  463. errList = append(errList, v.T_id)
  464. continue
  465. }
  466. } else {
  467. // 判断是否已存在sn
  468. _, is3 := Device.Read_DeviceClassList_T_class_T_sn(paste_task.T_class, v.T_sn)
  469. // 删除要粘贴的任务里重复的sn
  470. if is3 {
  471. if !Device.Delete_DeviceClassList_(ds) {
  472. errList = append(errList, v.T_id)
  473. continue
  474. }
  475. }
  476. // 不存在则添加
  477. var pdf Certificate.CertificatePdf
  478. pdfList, _ := Certificate.Read_CertificatePdf_T_layout_no(v.T_id, "")
  479. if len(pdfList) > 0 {
  480. pdf = pdfList[0]
  481. }
  482. var_ := Device.DeviceClassList{
  483. T_class: paste_task.T_class,
  484. T_id: v.T_id,
  485. T_sn: v.T_sn,
  486. T_failure_time: pdf.T_failure_time,
  487. T_pdf: pdf.T_pdf,
  488. T_Certificate_sn: pdf.T_Certificate_sn,
  489. T_remark: v.T_remark,
  490. T_State: 1,
  491. }
  492. _, is = Device.Add_DeviceClassList(var_)
  493. if !is {
  494. errList = append(errList, v.T_id)
  495. continue
  496. }
  497. }
  498. }
  499. if len(errList) == 0 {
  500. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: cnt}
  501. c.ServeJSON()
  502. return
  503. }
  504. var errStr string
  505. if len(errList) > 0 {
  506. if len(errStr) > 0 {
  507. errStr += ","
  508. }
  509. errStr += strings.Join(errList, ",") + "粘贴失败"
  510. }
  511. c.Data["json"] = lib.JSONS{Code: 210, Msg: errStr, Data: successNum}
  512. c.ServeJSON()
  513. return
  514. }
  515. // 修改-
  516. func (c *DeviceClassController) List_Up() {
  517. // 验证登录 User_is, User_r
  518. User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  519. if !User_is {
  520. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  521. c.ServeJSON()
  522. return
  523. }
  524. T_id := c.GetString("T_id")
  525. T_remark := c.GetString("T_remark")
  526. Id, err := c.GetInt("Id")
  527. if err != nil {
  528. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  529. c.ServeJSON()
  530. return
  531. }
  532. r, is := Device.Read_DeviceClassList_ById(Id)
  533. if !is {
  534. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  535. c.ServeJSON()
  536. return
  537. }
  538. _, is = Device.Read_DeviceClass_ById(r.T_class)
  539. if !is {
  540. c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_class 错误!"}
  541. c.ServeJSON()
  542. return
  543. }
  544. _, is = Device.Read_DeviceClassList_T_class_T_id(r.T_class, T_id)
  545. if is && T_id != r.T_id {
  546. c.Data["json"] = lib.JSONS{Code: 202, Msg: T_id + "编号已存在!"}
  547. c.ServeJSON()
  548. return
  549. }
  550. if len(T_id) > 0 {
  551. r.T_id = T_id
  552. // 修改布局编号对应的证书
  553. var pdf Certificate.CertificatePdf
  554. pdfList, _ := Certificate.Read_CertificatePdf_T_layout_no(T_id, r.CreateTime.Format("2006-01-02"))
  555. if len(pdfList) > 0 {
  556. pdf = pdfList[0]
  557. }
  558. r.T_failure_time = pdf.T_failure_time
  559. r.T_pdf = pdf.T_pdf
  560. r.T_Certificate_sn = pdf.T_Certificate_sn
  561. }
  562. if len(T_remark) > 0 {
  563. r.T_remark = T_remark
  564. }
  565. if !Device.Update_DeviceClassList(r, "T_id", "T_remark") {
  566. c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改失败!"}
  567. c.ServeJSON()
  568. return
  569. }
  570. System.Add_UserLogs_T(User_r.T_uuid, "分类设备管理", "修改", r)
  571. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  572. c.ServeJSON()
  573. return
  574. }
  575. // 删除-
  576. func (c *DeviceClassController) List_Del() {
  577. // 验证登录 User_is, User_r
  578. User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  579. if !User_is {
  580. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  581. c.ServeJSON()
  582. return
  583. }
  584. Id, err := c.GetInt("Id")
  585. if err != nil {
  586. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  587. c.ServeJSON()
  588. return
  589. }
  590. if r, is := Device.Read_DeviceClassList_ById(Id); is {
  591. _, is = Device.Read_DeviceClass_ById(r.T_class)
  592. if !is {
  593. c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_class 错误!"}
  594. c.ServeJSON()
  595. return
  596. }
  597. if !Device.Delete_DeviceClassList_(r) {
  598. c.Data["json"] = lib.JSONS{Code: 202, Msg: "删除失败!"}
  599. c.ServeJSON()
  600. return
  601. }
  602. System.Add_UserLogs_T(User_r.T_uuid, "分类设备管理", "删除", r)
  603. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  604. c.ServeJSON()
  605. return
  606. }
  607. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  608. c.ServeJSON()
  609. return
  610. }
  611. // 添加设备列表。模板下载
  612. func (c *DeviceClassController) List_Template_Download() {
  613. // 返回生成的 Excel 文件
  614. c.Ctx.Output.Download("ofile/添加设备列表模板.xlsx")
  615. }