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