DeviceClass.go 18 KB

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