DeviceClass.go 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702
  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. if len(T_sn) == 0 || len(T_id) == 0 {
  365. errList = append(errList, sn_id)
  366. continue
  367. }
  368. // 判断是否已存在sn
  369. dc, is := Device.Read_DeviceClassList_T_class_T_sn(T_class, T_sn)
  370. // 添加的id和数据库已存在id相同
  371. if is && dc.T_id == T_id {
  372. successNum += 1
  373. continue
  374. }
  375. // 添加的id和数据库已存在id不同
  376. if is && dc.T_id != T_id {
  377. _, is = Device.Read_DeviceClassList_T_class_T_id(T_class, T_id)
  378. if is {
  379. errList2 = append(errList2, sn_id)
  380. continue
  381. }
  382. dc.T_id = T_id
  383. dc.T_remark = T_remark
  384. if !Device.Update_DeviceClassList(dc, "T_id", "T_remark") {
  385. errList = append(errList, sn_id)
  386. } else {
  387. successNum += 1
  388. }
  389. continue
  390. }
  391. var pdf Certificate.CertificatePdf
  392. //pdfList, _ := Certificate.Read_CertificatePdf_Newest(T_sn)
  393. pdfList, _ := Certificate.Read_CertificatePdf_T_layout_no(T_id, "")
  394. if len(pdfList) > 0 {
  395. pdf = pdfList[0]
  396. }
  397. var_ := Device.DeviceClassList{
  398. T_class: T_class,
  399. T_id: T_id,
  400. T_sn: T_sn,
  401. T_failure_time: pdf.T_failure_time,
  402. T_pdf: pdf.T_pdf,
  403. T_Certificate_sn: pdf.T_Certificate_sn,
  404. T_remark: T_remark,
  405. T_State: 1,
  406. }
  407. _, is = Device.Add_DeviceClassList(var_)
  408. if !is {
  409. errList = append(errList, sn_id)
  410. continue
  411. }
  412. successNum += 1
  413. succesId = append(succesId, sn_id)
  414. System.Add_UserLogs_T(User_r.T_uuid, "分类设备管理", "添加", var_)
  415. }
  416. if len(errList) == 0 && len(errList2) == 0 {
  417. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: successNum}
  418. c.ServeJSON()
  419. return
  420. }
  421. var errStr string
  422. if len(errList2) > 0 {
  423. errStr += strings.Join(errList2, ",") + "编号已存在"
  424. }
  425. if len(errList) > 0 {
  426. if len(errStr) > 0 {
  427. errStr += ","
  428. }
  429. errStr += strings.Join(errList, ",") + "添加失败"
  430. }
  431. c.Data["json"] = lib.JSONS{Code: 210, Msg: errStr, Data: successNum}
  432. c.ServeJSON()
  433. return
  434. }
  435. func (c *DeviceClassController) List_Copy() {
  436. // 验证登录 User_is, User_r
  437. _, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  438. if !User_is {
  439. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  440. c.ServeJSON()
  441. return
  442. }
  443. T_copy_task_id := c.GetString("T_copy_task_id")
  444. copy_task, is := Task.Read_Task(T_copy_task_id)
  445. if !is {
  446. c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_copy_task_id 错误!"}
  447. c.ServeJSON()
  448. return
  449. }
  450. T_paste_task_id := c.GetString("T_paste_task_id")
  451. paste_task, is := Task.Read_Task(T_paste_task_id)
  452. if !is {
  453. c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_paste_task_id 错误!"}
  454. c.ServeJSON()
  455. return
  456. }
  457. copyList, cnt := Device.Read_DeviceClassList_OrderList(copy_task.T_class, "", "", "", 0, 9999)
  458. var successNum int // 成功数量
  459. errList := []string{}
  460. for _, v := range copyList {
  461. ds, is2 := Device.Read_DeviceClassList_T_class_T_id(paste_task.T_class, v.T_id)
  462. // id存在 更新
  463. if is2 {
  464. ds.T_sn = v.T_sn
  465. ds.T_remark = v.T_remark
  466. if !Device.Update_DeviceClassList(ds, "T_sn", "T_remark") {
  467. errList = append(errList, v.T_id)
  468. continue
  469. }
  470. } else {
  471. // 判断是否已存在sn
  472. _, is3 := Device.Read_DeviceClassList_T_class_T_sn(paste_task.T_class, v.T_sn)
  473. // 删除要粘贴的任务里重复的sn
  474. if is3 {
  475. if !Device.Delete_DeviceClassList_(ds) {
  476. errList = append(errList, v.T_id)
  477. continue
  478. }
  479. }
  480. // 不存在则添加
  481. var pdf Certificate.CertificatePdf
  482. pdfList, _ := Certificate.Read_CertificatePdf_T_layout_no(v.T_id, "")
  483. if len(pdfList) > 0 {
  484. pdf = pdfList[0]
  485. }
  486. var_ := Device.DeviceClassList{
  487. T_class: paste_task.T_class,
  488. T_id: v.T_id,
  489. T_sn: v.T_sn,
  490. T_failure_time: pdf.T_failure_time,
  491. T_pdf: pdf.T_pdf,
  492. T_Certificate_sn: pdf.T_Certificate_sn,
  493. T_remark: v.T_remark,
  494. T_State: 1,
  495. }
  496. _, is = Device.Add_DeviceClassList(var_)
  497. if !is {
  498. errList = append(errList, v.T_id)
  499. continue
  500. }
  501. }
  502. }
  503. if len(errList) == 0 {
  504. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: cnt}
  505. c.ServeJSON()
  506. return
  507. }
  508. var errStr string
  509. if len(errList) > 0 {
  510. if len(errStr) > 0 {
  511. errStr += ","
  512. }
  513. errStr += strings.Join(errList, ",") + "粘贴失败"
  514. }
  515. c.Data["json"] = lib.JSONS{Code: 210, Msg: errStr, Data: successNum}
  516. c.ServeJSON()
  517. return
  518. }
  519. // 修改-
  520. func (c *DeviceClassController) List_Up() {
  521. // 验证登录 User_is, User_r
  522. User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  523. if !User_is {
  524. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  525. c.ServeJSON()
  526. return
  527. }
  528. T_id := c.GetString("T_id")
  529. T_remark := c.GetString("T_remark")
  530. Id, err := c.GetInt("Id")
  531. if err != nil {
  532. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  533. c.ServeJSON()
  534. return
  535. }
  536. r, is := Device.Read_DeviceClassList_ById(Id)
  537. if !is {
  538. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  539. c.ServeJSON()
  540. return
  541. }
  542. _, is = Device.Read_DeviceClass_ById(r.T_class)
  543. if !is {
  544. c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_class 错误!"}
  545. c.ServeJSON()
  546. return
  547. }
  548. _, is = Device.Read_DeviceClassList_T_class_T_id(r.T_class, T_id)
  549. if is && T_id != r.T_id {
  550. c.Data["json"] = lib.JSONS{Code: 202, Msg: T_id + "编号已存在!"}
  551. c.ServeJSON()
  552. return
  553. }
  554. if len(T_id) > 0 {
  555. r.T_id = T_id
  556. // 修改布局编号对应的证书
  557. var pdf Certificate.CertificatePdf
  558. pdfList, _ := Certificate.Read_CertificatePdf_T_layout_no(T_id, r.CreateTime.Format("2006-01-02"))
  559. if len(pdfList) > 0 {
  560. pdf = pdfList[0]
  561. }
  562. r.T_failure_time = pdf.T_failure_time
  563. r.T_pdf = pdf.T_pdf
  564. r.T_Certificate_sn = pdf.T_Certificate_sn
  565. }
  566. if len(T_remark) > 0 {
  567. r.T_remark = T_remark
  568. }
  569. if !Device.Update_DeviceClassList(r, "T_id", "T_remark", "T_failure_time", "T_pdf", "T_Certificate_sn") {
  570. c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改失败!"}
  571. c.ServeJSON()
  572. return
  573. }
  574. System.Add_UserLogs_T(User_r.T_uuid, "分类设备管理", "修改", r)
  575. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  576. c.ServeJSON()
  577. return
  578. }
  579. // 删除-
  580. func (c *DeviceClassController) List_Del() {
  581. // 验证登录 User_is, User_r
  582. User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  583. if !User_is {
  584. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  585. c.ServeJSON()
  586. return
  587. }
  588. Id, err := c.GetInt("Id")
  589. if err != nil {
  590. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  591. c.ServeJSON()
  592. return
  593. }
  594. if r, is := Device.Read_DeviceClassList_ById(Id); is {
  595. _, is = Device.Read_DeviceClass_ById(r.T_class)
  596. if !is {
  597. c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_class 错误!"}
  598. c.ServeJSON()
  599. return
  600. }
  601. if !Device.Delete_DeviceClassList_(r) {
  602. c.Data["json"] = lib.JSONS{Code: 202, Msg: "删除失败!"}
  603. c.ServeJSON()
  604. return
  605. }
  606. System.Add_UserLogs_T(User_r.T_uuid, "分类设备管理", "删除", r)
  607. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  608. c.ServeJSON()
  609. return
  610. }
  611. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  612. c.ServeJSON()
  613. return
  614. }
  615. // 添加设备列表。模板下载
  616. func (c *DeviceClassController) List_Template_Download() {
  617. // 返回生成的 Excel 文件
  618. c.Ctx.Output.Download("ofile/添加设备列表模板.xlsx")
  619. }