InfoTemplate.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678
  1. package controllers
  2. import (
  3. "ColdVerify_server/conf"
  4. "ColdVerify_server/lib"
  5. "ColdVerify_server/models/Account"
  6. "ColdVerify_server/models/InfoCollection"
  7. "ColdVerify_server/models/System"
  8. "encoding/json"
  9. beego "github.com/beego/beego/v2/server/web"
  10. "math"
  11. "strconv"
  12. "time"
  13. )
  14. type InfoTemplateController struct {
  15. beego.Controller
  16. }
  17. // 列表 -
  18. func (c *InfoTemplateController) List() {
  19. // 验证登录 User_is, User_r
  20. _, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  21. if !User_is {
  22. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  23. c.ServeJSON()
  24. return
  25. }
  26. var r_jsons lib.R_JSONS
  27. page, _ := c.GetInt("page")
  28. if page < 1 {
  29. page = 1
  30. }
  31. page_z, _ := c.GetInt("page_z")
  32. if page_z < 1 {
  33. page_z = conf.Page_size
  34. }
  35. T_class, _ := c.GetInt("T_class")
  36. if T_class <= 0 {
  37. c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_class Err!"}
  38. c.ServeJSON()
  39. return
  40. }
  41. T_name := c.GetString("T_name")
  42. var cnt int64
  43. List, cnt := InfoCollection.Read_InfoTemplate_List(T_class, T_name, page, page_z)
  44. page_size := math.Ceil(float64(cnt) / float64(page_z))
  45. r_jsons.List = List
  46. r_jsons.Page = page
  47. r_jsons.Page_size = int(page_size)
  48. r_jsons.Pages = lib.Func_page(int64(page), int64(page_size))
  49. r_jsons.Num = int(cnt)
  50. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
  51. c.ServeJSON()
  52. return
  53. }
  54. // 添加-
  55. func (c *InfoTemplateController) Add() {
  56. // 验证登录 User_is, User_r
  57. User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  58. if !User_is {
  59. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  60. c.ServeJSON()
  61. return
  62. }
  63. T_name := c.GetString("T_name")
  64. T_sort, _ := c.GetInt("T_sort")
  65. T_class, _ := c.GetInt("T_class")
  66. var_ := InfoCollection.InfoTemplate{
  67. T_class: T_class,
  68. T_name: T_name,
  69. T_sort: T_sort,
  70. }
  71. Id, is := InfoCollection.Add_InfoTemplate(var_)
  72. if !is {
  73. c.Data["json"] = lib.JSONS{Code: 202, Msg: "添加失败!"}
  74. c.ServeJSON()
  75. return
  76. }
  77. System.Add_UserLogs_T(User_r.T_uuid, "信息采集模板", "添加", var_)
  78. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: Id}
  79. c.ServeJSON()
  80. return
  81. }
  82. // 修改-
  83. func (c *InfoTemplateController) Up() {
  84. // 验证登录 User_is, User_r
  85. User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  86. if !User_is {
  87. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  88. c.ServeJSON()
  89. return
  90. }
  91. T_name := c.GetString("T_name")
  92. T_sort, T_sort_err := c.GetInt("T_sort")
  93. T_InfoTemplate_id := c.GetString("T_InfoTemplate_id")
  94. r, is := InfoCollection.Read_InfoTemplate(T_InfoTemplate_id)
  95. if !is {
  96. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  97. c.ServeJSON()
  98. return
  99. }
  100. // .......
  101. if len(T_name) > 0 {
  102. r.T_name = T_name
  103. }
  104. if T_sort_err == nil {
  105. r.T_sort = T_sort
  106. }
  107. // .......
  108. if !InfoCollection.Update_InfoTemplate(r, "T_name", "T_sort") {
  109. c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改失败!"}
  110. c.ServeJSON()
  111. return
  112. }
  113. System.Add_UserLogs_T(User_r.T_uuid, "信息采集模板", "修改", r)
  114. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  115. c.ServeJSON()
  116. return
  117. }
  118. // 删除-
  119. func (c *InfoTemplateController) Del() {
  120. // 验证登录 User_is, User_r
  121. User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  122. if !User_is {
  123. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  124. c.ServeJSON()
  125. return
  126. }
  127. T_InfoTemplate_id := c.GetString("T_InfoTemplate_id")
  128. r, is := InfoCollection.Read_InfoTemplate(T_InfoTemplate_id)
  129. if !is {
  130. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  131. c.ServeJSON()
  132. return
  133. }
  134. if !InfoCollection.Delete_InfoTemplate(r) {
  135. c.Data["json"] = lib.JSONS{Code: 202, Msg: "删除失败!"}
  136. c.ServeJSON()
  137. return
  138. }
  139. mapList, _ := InfoCollection.Read_InfoTemplateMap_List(T_InfoTemplate_id, 0, 0)
  140. for _, v := range mapList {
  141. if vtm, is := InfoCollection.Read_InfoTemplateMap(v.T_id); is {
  142. InfoCollection.Delete_InfoTemplateMap(vtm)
  143. }
  144. }
  145. System.Add_UserLogs_T(User_r.T_uuid, "信息采集模板", "删除", r)
  146. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  147. c.ServeJSON()
  148. return
  149. }
  150. // 复制-
  151. func (c *InfoTemplateController) Copy() {
  152. // 验证登录 User_is, User_r
  153. User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  154. if !User_is {
  155. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  156. c.ServeJSON()
  157. return
  158. }
  159. T_InfoTemplate_id := c.GetString("T_InfoTemplate_id")
  160. T_name := c.GetString("T_name")
  161. r, is := InfoCollection.Read_InfoTemplate(T_InfoTemplate_id)
  162. if !is {
  163. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  164. c.ServeJSON()
  165. return
  166. }
  167. var_ := InfoCollection.InfoTemplate{
  168. T_class: r.T_class,
  169. T_name: T_name,
  170. T_sort: r.T_sort,
  171. }
  172. new_id, is := InfoCollection.Add_InfoTemplate(var_)
  173. if !is {
  174. c.Data["json"] = lib.JSONS{Code: 202, Msg: "复制失败!"}
  175. c.ServeJSON()
  176. return
  177. }
  178. mapList, _ := InfoCollection.Read_InfoTemplateMap_List(T_InfoTemplate_id, 0, 0)
  179. tempMap := make(map[string]struct{})
  180. idList := make([]string, len(mapList))
  181. // 生成mapList长度的T_id
  182. for i := 0; i < len(mapList); i++ {
  183. // 生成编号
  184. rand_x := 0
  185. T_id := ""
  186. for true {
  187. T_id = lib.GetRandstring(4, "", int64(rand_x))
  188. _, is = InfoCollection.Read_InfoTemplateMap(T_id)
  189. if !is {
  190. if _, ok := tempMap[T_id]; !ok {
  191. break
  192. }
  193. }
  194. rand_x += 1
  195. }
  196. tempMap[T_id] = struct{}{}
  197. idList[i] = T_id
  198. }
  199. mapInsertList := make([]InfoCollection.InfoTemplateMap, 0)
  200. for i, v := range mapList {
  201. vtm := InfoCollection.InfoTemplateMap{
  202. T_id: idList[i],
  203. T_InfoTemplate_id: new_id,
  204. T_name: v.T_name,
  205. T_text: v.T_text,
  206. T_label: v.T_label,
  207. T_sort: v.T_sort,
  208. }
  209. mapInsertList = append(mapInsertList, vtm)
  210. }
  211. _, is = InfoCollection.Add_InfoTemplateMapMulti(mapInsertList)
  212. if !is {
  213. c.Data["json"] = lib.JSONS{Code: 202, Msg: "复制失败!"}
  214. c.ServeJSON()
  215. return
  216. }
  217. System.Add_UserLogs_T(User_r.T_uuid, "信息采集模板", "复制", var_)
  218. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: new_id}
  219. c.ServeJSON()
  220. return
  221. }
  222. /// -----------------------------------------------------------------------------
  223. // 标签列表 -
  224. func (c *InfoTemplateController) Map_List() {
  225. // 验证登录 User_is, User_r
  226. _, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  227. if !User_is {
  228. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  229. c.ServeJSON()
  230. return
  231. }
  232. var r_jsons lib.R_JSONS
  233. T_sort, _ := c.GetInt("T_sort") // 排序
  234. T_flow_sort, _ := c.GetInt("T_flow_sort") // 验证流程排序
  235. T_InfoTemplate_id := c.GetString("T_InfoTemplate_id")
  236. var cnt int64
  237. List, cnt := InfoCollection.Read_InfoTemplateMap_List(T_InfoTemplate_id, T_sort, T_flow_sort)
  238. r_jsons.List = List
  239. r_jsons.Num = int(cnt)
  240. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
  241. c.ServeJSON()
  242. return
  243. }
  244. // 标签添加-
  245. func (c *InfoTemplateController) Map_Add() {
  246. // 验证登录 User_is, User_r
  247. User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  248. if !User_is {
  249. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  250. c.ServeJSON()
  251. return
  252. }
  253. T_InfoTemplate_id := c.GetString("T_InfoTemplate_id")
  254. T_name := c.GetString("T_name")
  255. T_text := c.GetString("T_text")
  256. T_label, _ := c.GetInt("T_label")
  257. T_sort, _ := c.GetInt("T_sort")
  258. var_ := InfoCollection.InfoTemplateMap{
  259. T_InfoTemplate_id: T_InfoTemplate_id,
  260. T_name: T_name,
  261. T_text: T_text,
  262. T_label: T_label,
  263. T_sort: T_sort,
  264. }
  265. Id, is := InfoCollection.Add_InfoTemplateMap(var_)
  266. if !is {
  267. c.Data["json"] = lib.JSONS{Code: 202, Msg: "添加失败!"}
  268. c.ServeJSON()
  269. return
  270. }
  271. System.Add_UserLogs_T(User_r.T_uuid, "信息采集模板标签", "添加", var_)
  272. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: Id}
  273. c.ServeJSON()
  274. return
  275. }
  276. // 标签修改-
  277. func (c *InfoTemplateController) Map_Up() {
  278. // 验证登录 User_is, User_r
  279. User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  280. if !User_is {
  281. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  282. c.ServeJSON()
  283. return
  284. }
  285. T_name := c.GetString("T_name")
  286. T_text := c.GetString("T_text")
  287. T_label, T_label_err := c.GetInt("T_label")
  288. T_sort, T_sort_err := c.GetInt("T_sort")
  289. T_id := c.GetString("T_id")
  290. r, is := InfoCollection.Read_InfoTemplateMap(T_id)
  291. if !is {
  292. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  293. c.ServeJSON()
  294. return
  295. }
  296. // .......
  297. if len(T_name) > 0 {
  298. r.T_name = T_name
  299. }
  300. if len(T_text) > 0 {
  301. r.T_text = T_text
  302. }
  303. if T_label_err == nil {
  304. r.T_label = T_label
  305. }
  306. if T_sort_err == nil {
  307. r.T_sort = T_sort
  308. }
  309. if !InfoCollection.Update_InfoTemplateMap(r, "T_name", "T_label", "T_text", "T_sort") {
  310. c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改失败!"}
  311. c.ServeJSON()
  312. return
  313. }
  314. System.Add_UserLogs_T(User_r.T_uuid, "信息采集模板标签", "修改", r)
  315. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  316. c.ServeJSON()
  317. return
  318. }
  319. // 标签删除-
  320. func (c *InfoTemplateController) Map_Del() {
  321. // 验证登录 User_is, User_r
  322. User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  323. if !User_is {
  324. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  325. c.ServeJSON()
  326. return
  327. }
  328. T_id := c.GetString("T_id")
  329. if r, is := InfoCollection.Read_InfoTemplateMap(T_id); is {
  330. if !InfoCollection.Delete_InfoTemplateMap(r) {
  331. c.Data["json"] = lib.JSONS{Code: 202, Msg: "删除失败!"}
  332. c.ServeJSON()
  333. return
  334. }
  335. System.Add_UserLogs_T(User_r.T_uuid, "信息采集模板标签", "删除", r)
  336. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  337. c.ServeJSON()
  338. return
  339. }
  340. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  341. c.ServeJSON()
  342. return
  343. }
  344. /// -----------------------------------------------------------------------------
  345. // 标签数据列表 -
  346. func (c *InfoTemplateController) Map_Data_List() {
  347. // 验证登录 User_is, User_r
  348. _, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  349. if !User_is {
  350. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  351. c.ServeJSON()
  352. return
  353. }
  354. T_InfoTemplate_id := c.GetString("T_InfoTemplate_id")
  355. T_InfoCollection_id := c.GetString("T_InfoCollection_id")
  356. _, is := InfoCollection.Read_InfoCollection(T_InfoCollection_id)
  357. if !is {
  358. c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_InfoCollection_id 错误!"}
  359. c.ServeJSON()
  360. return
  361. }
  362. Map_List := InfoCollection.Read_InfoTemplateMap_List_For_Data(T_InfoTemplate_id)
  363. Data := InfoCollection.Read_InfoTemplateMapData_List(T_InfoCollection_id, T_InfoTemplate_id, Map_List)
  364. type JSONS struct {
  365. //必须的大写开头
  366. Code int16
  367. Msg string
  368. Data interface{} // 泛型
  369. }
  370. c.Data["json"] = JSONS{Code: 200, Msg: "ok!", Data: Data}
  371. c.ServeJSON()
  372. return
  373. }
  374. // 添加标签数据
  375. func (c *InfoTemplateController) Map_Data_Pu() {
  376. //验证登录 User_is, User_r
  377. //token := c.Ctx.Request.Header.Get("user_tokey")
  378. //User_r, User_is := Account.Verification_Admin(token, "")
  379. //if !User_is {
  380. // c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  381. // c.ServeJSON()
  382. // return
  383. //}
  384. type RequestBody struct {
  385. User_tokey string
  386. T_InfoCollection_id string
  387. T_InfoTemplate_id string
  388. InfoTemplateMapData []InfoCollection.InfoTemplateMapData_R
  389. }
  390. var body RequestBody
  391. data := c.Ctx.Input.RequestBody
  392. err := json.Unmarshal(data, &body)
  393. if err != nil {
  394. c.Data["json"] = lib.JSONS{Code: 202, Msg: "json返序列化失败:" + err.Error()}
  395. c.ServeJSON()
  396. }
  397. User_r, User_is := Account.Verification_Admin(body.User_tokey, "")
  398. if !User_is {
  399. System.Add_UserLogs_T(User_r.T_uuid, "信息采集模版标签数据", "未登录-保存", body)
  400. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  401. c.ServeJSON()
  402. return
  403. }
  404. infoCollection, is := InfoCollection.Read_InfoCollection(body.T_InfoCollection_id)
  405. if !is {
  406. c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_InfoCollection_id 错误!"}
  407. c.ServeJSON()
  408. return
  409. }
  410. // 如果信息采集开始时间为空,则设置为当前时间
  411. if len(infoCollection.T_start_time) == 0 {
  412. infoCollection.T_start_time = time.Now().Format("2006-01-02 15:04:05")
  413. if !InfoCollection.Update_InfoCollection(infoCollection, "T_start_time") {
  414. c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改信息采集开始时间失败!"}
  415. c.ServeJSON()
  416. return
  417. }
  418. }
  419. MapDataList := make([]InfoCollection.InfoTemplateMapData, 0)
  420. for _, v := range body.InfoTemplateMapData {
  421. val := InfoCollection.InfoTemplateMapData{
  422. T_InfoCollection_id: body.T_InfoCollection_id,
  423. T_InfoTemplate_id: body.T_InfoTemplate_id,
  424. T_InfoTemplateMap_id: v.T_InfoTemplateMap_id,
  425. T_value: v.T_value,
  426. }
  427. MapDataList = append(MapDataList, val)
  428. }
  429. ids, is := InfoCollection.AddOrUpdate_InfoTemplateMapData(MapDataList)
  430. if !is {
  431. c.Data["json"] = lib.JSONS{Code: 202, Msg: "保存失败"}
  432. c.ServeJSON()
  433. return
  434. }
  435. System.Add_UserLogs_T(User_r.T_uuid, "信息采集模版标签数据", "保存", body)
  436. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: ids}
  437. c.ServeJSON()
  438. return
  439. }
  440. func (c *InfoTemplateController) Map_Data_Copy() {
  441. // 验证登录 User_is, User_r
  442. User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  443. if !User_is {
  444. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  445. c.ServeJSON()
  446. return
  447. }
  448. T_copy_InfoCollection_id := c.GetString("T_copy_InfoCollection_id")
  449. copy_InfoCollection, is := InfoCollection.Read_InfoCollection(T_copy_InfoCollection_id)
  450. if !is {
  451. c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_copy_InfoCollection_id 错误!"}
  452. c.ServeJSON()
  453. return
  454. }
  455. T_paste_InfoCollection_id := c.GetString("T_paste_InfoCollection_id")
  456. paste_InfoCollection, is := InfoCollection.Read_InfoCollection(T_paste_InfoCollection_id)
  457. if !is {
  458. c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_paste_InfoCollection_id 错误!"}
  459. c.ServeJSON()
  460. return
  461. }
  462. if copy_InfoCollection.T_InfoTemplate_id != paste_InfoCollection.T_InfoTemplate_id {
  463. c.Data["json"] = lib.JSONS{Code: 202, Msg: "仅支持相同模板间复制!"}
  464. c.ServeJSON()
  465. return
  466. }
  467. list := InfoCollection.Read_MapData_List(T_copy_InfoCollection_id, copy_InfoCollection.T_InfoTemplate_id)
  468. MapDataList := make([]InfoCollection.InfoTemplateMapData, 0)
  469. for _, v := range list {
  470. val := InfoCollection.InfoTemplateMapData{
  471. T_InfoCollection_id: paste_InfoCollection.T_InfoCollection_id,
  472. T_InfoTemplate_id: paste_InfoCollection.T_InfoTemplate_id,
  473. T_InfoTemplateMap_id: v.T_InfoTemplateMap_id,
  474. T_value: v.T_value,
  475. }
  476. MapDataList = append(MapDataList, val)
  477. }
  478. var ids []int64
  479. ids, is = InfoCollection.AddOrUpdate_InfoTemplateMapData(MapDataList)
  480. if !is {
  481. c.Data["json"] = lib.JSONS{Code: 202, Msg: "保存失败"}
  482. c.ServeJSON()
  483. return
  484. }
  485. System.Add_UserLogs_T(User_r.T_uuid, "信息采集模版标签数据", "复制", MapDataList)
  486. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: ids}
  487. c.ServeJSON()
  488. return
  489. }
  490. func (c *InfoTemplateController) Class_List() {
  491. // 验证登录 User_is, User_r
  492. _, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  493. if !User_is {
  494. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  495. c.ServeJSON()
  496. return
  497. }
  498. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: InfoCollection.Read_InfoTemplateClass_List()}
  499. c.ServeJSON()
  500. return
  501. }
  502. func (c *InfoTemplateController) Class_Add() {
  503. // 验证登录 User_is, User_r
  504. User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  505. if !User_is {
  506. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  507. c.ServeJSON()
  508. return
  509. }
  510. T_name := c.GetString("T_name")
  511. T_fid, _ := c.GetInt("T_fid")
  512. var_ := InfoCollection.InfoTemplateClass{
  513. T_name: T_name,
  514. T_fid: T_fid,
  515. T_State: 1,
  516. }
  517. Id, err := InfoCollection.Add_InfoTemplateClass(var_)
  518. if err != nil {
  519. c.Data["json"] = lib.JSONS{Code: 203, Msg: "添加失败"}
  520. c.ServeJSON()
  521. return
  522. }
  523. System.Add_UserLogs_T(User_r.T_uuid, "模板分类", "添加", var_)
  524. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: Id}
  525. c.ServeJSON()
  526. return
  527. }
  528. func (c *InfoTemplateController) Class_Up() {
  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.GetInt("T_id")
  536. T_name := c.GetString("T_name")
  537. R_InfoTemplateToolClass, err := InfoCollection.Read_InfoTemplateClass_ById(T_id)
  538. if err != nil {
  539. c.Data["json"] = lib.JSONS{Code: 203, Msg: "T_id Err!"}
  540. c.ServeJSON()
  541. return
  542. }
  543. if len(T_name) > 0 {
  544. R_InfoTemplateToolClass.T_name = T_name
  545. }
  546. if is := InfoCollection.Update_InfoTemplateClass(R_InfoTemplateToolClass, "T_name"); !is {
  547. c.Data["json"] = lib.JSONS{Code: 203, Msg: "修改失败"}
  548. c.ServeJSON()
  549. return
  550. }
  551. System.Add_UserLogs_T(User_r.T_uuid, "模板分类", "修改", R_InfoTemplateToolClass)
  552. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  553. c.ServeJSON()
  554. return
  555. }
  556. func (c *InfoTemplateController) Class_Del() {
  557. User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  558. if !User_is {
  559. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  560. c.ServeJSON()
  561. return
  562. }
  563. T_id, _ := c.GetInt("T_id")
  564. R_InfoTemplateToolClass, err := InfoCollection.Read_InfoTemplateClass_ById(T_id)
  565. if err != nil {
  566. c.Data["json"] = lib.JSONS{Code: 203, Msg: "T_id Err!"}
  567. c.ServeJSON()
  568. return
  569. }
  570. ids := InfoCollection.ReadInfoTemplateClassIds_T_path(R_InfoTemplateToolClass.T_path)
  571. if is := InfoCollection.Delete_InfoTemplateClass_ByIds(ids); !is {
  572. c.Data["json"] = lib.JSONS{Code: 202, Msg: "删除失败!"}
  573. c.ServeJSON()
  574. return
  575. }
  576. System.Add_UserLogs(User_r.T_uuid, "模板分类", "删除", strconv.Itoa(T_id))
  577. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  578. c.ServeJSON()
  579. return
  580. }