VerifyTemplate.go 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946
  1. package controllers
  2. import (
  3. "ColdVerify_server/conf"
  4. "ColdVerify_server/lib"
  5. "ColdVerify_server/models/Account"
  6. "ColdVerify_server/models/System"
  7. "ColdVerify_server/models/Task"
  8. "ColdVerify_server/models/VerifyTemplate"
  9. "encoding/json"
  10. "fmt"
  11. beego "github.com/beego/beego/v2/server/web"
  12. "math"
  13. "strconv"
  14. )
  15. type VerifyTemplateController struct {
  16. beego.Controller
  17. }
  18. // 列表 -
  19. func (c *VerifyTemplateController) List() {
  20. // 验证登录 User_is, User_r
  21. _, 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_class, _ := c.GetInt("T_class")
  37. if T_class <= 0 {
  38. c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_class Err!"}
  39. c.ServeJSON()
  40. return
  41. }
  42. T_name := c.GetString("T_name")
  43. var cnt int64
  44. List, cnt := VerifyTemplate.Read_VerifyTemplate_List(T_class, T_name, page, page_z)
  45. page_size := math.Ceil(float64(cnt) / float64(page_z))
  46. r_jsons.List = List
  47. r_jsons.Page = page
  48. r_jsons.Page_size = int(page_size)
  49. r_jsons.Pages = lib.Func_page(int64(page), int64(page_size))
  50. r_jsons.Num = int(cnt)
  51. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
  52. c.ServeJSON()
  53. return
  54. }
  55. // 添加-
  56. func (c *VerifyTemplateController) Add() {
  57. // 验证登录 User_is, User_r
  58. User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  59. if !User_is {
  60. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  61. c.ServeJSON()
  62. return
  63. }
  64. T_name := c.GetString("T_name")
  65. T_sort, _ := c.GetInt("T_sort")
  66. T_class, _ := c.GetInt("T_class")
  67. var_ := VerifyTemplate.VerifyTemplate{
  68. T_class: T_class,
  69. T_name: T_name,
  70. T_sort: T_sort,
  71. }
  72. Id, is := VerifyTemplate.Add_VerifyTemplate(var_)
  73. if !is {
  74. c.Data["json"] = lib.JSONS{Code: 202, Msg: "添加失败!"}
  75. c.ServeJSON()
  76. return
  77. }
  78. System.Add_UserLogs_T(User_r.T_uuid, "验证模板", "添加", var_)
  79. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: Id}
  80. c.ServeJSON()
  81. return
  82. }
  83. // 修改-
  84. func (c *VerifyTemplateController) Up() {
  85. // 验证登录 User_is, User_r
  86. User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  87. if !User_is {
  88. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  89. c.ServeJSON()
  90. return
  91. }
  92. T_name := c.GetString("T_name")
  93. T_sort, T_sort_err := c.GetInt("T_sort")
  94. T_VerifyTemplate_id := c.GetString("T_VerifyTemplate_id")
  95. T_scheme := c.GetString("T_scheme")
  96. T_reporting := c.GetString("T_reporting")
  97. T_inspect := c.GetString("T_inspect")
  98. r, is := VerifyTemplate.Read_VerifyTemplate(T_VerifyTemplate_id)
  99. if !is {
  100. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  101. c.ServeJSON()
  102. return
  103. }
  104. // .......
  105. if len(T_name) > 0 {
  106. r.T_name = T_name
  107. }
  108. if len(T_scheme) > 0 {
  109. r.T_scheme = T_scheme
  110. }
  111. if len(T_reporting) > 0 {
  112. r.T_reporting = T_reporting
  113. }
  114. if len(T_inspect) > 0 {
  115. r.T_inspect = T_inspect
  116. }
  117. if T_sort_err == nil {
  118. r.T_sort = T_sort
  119. }
  120. // .......
  121. if !VerifyTemplate.Update_VerifyTemplate(r, "T_name", "T_sort", "T_scheme", "T_reporting", "T_inspect") {
  122. c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改失败!"}
  123. c.ServeJSON()
  124. return
  125. }
  126. System.Add_UserLogs_T(User_r.T_uuid, "验证模板", "修改", r)
  127. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  128. c.ServeJSON()
  129. return
  130. }
  131. // 删除-
  132. func (c *VerifyTemplateController) Del() {
  133. // 验证登录 User_is, User_r
  134. User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  135. if !User_is {
  136. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  137. c.ServeJSON()
  138. return
  139. }
  140. T_VerifyTemplate_id := c.GetString("T_VerifyTemplate_id")
  141. r, is := VerifyTemplate.Read_VerifyTemplate(T_VerifyTemplate_id)
  142. if !is {
  143. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  144. c.ServeJSON()
  145. return
  146. }
  147. if !VerifyTemplate.Delete_VerifyTemplate(r) {
  148. c.Data["json"] = lib.JSONS{Code: 202, Msg: "删除失败!"}
  149. c.ServeJSON()
  150. return
  151. }
  152. mapList, _ := VerifyTemplate.Read_VerifyTemplateMap_List(T_VerifyTemplate_id, 0, 0)
  153. for _, v := range mapList {
  154. if vtm, is := VerifyTemplate.Read_VerifyTemplateMap(v.T_id); is {
  155. VerifyTemplate.Delete_VerifyTemplateMap(vtm)
  156. }
  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. // 复制-
  164. func (c *VerifyTemplateController) Copy() {
  165. // 验证登录 User_is, User_r
  166. User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  167. if !User_is {
  168. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  169. c.ServeJSON()
  170. return
  171. }
  172. T_VerifyTemplate_id := c.GetString("T_VerifyTemplate_id")
  173. T_name := c.GetString("T_name")
  174. r, is := VerifyTemplate.Read_VerifyTemplate(T_VerifyTemplate_id)
  175. if !is {
  176. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  177. c.ServeJSON()
  178. return
  179. }
  180. var_ := VerifyTemplate.VerifyTemplate{
  181. T_class: r.T_class,
  182. T_name: T_name,
  183. T_sort: r.T_sort,
  184. }
  185. new_id, is := VerifyTemplate.Add_VerifyTemplate(var_)
  186. if !is {
  187. c.Data["json"] = lib.JSONS{Code: 202, Msg: "复制失败!"}
  188. c.ServeJSON()
  189. return
  190. }
  191. mapList, _ := VerifyTemplate.Read_VerifyTemplateMap_List(T_VerifyTemplate_id, 0, 0)
  192. tempMap := make(map[string]struct{})
  193. idList := make([]string, len(mapList))
  194. // 生成mapList长度的T_id
  195. for i := 0; i < len(mapList); i++ {
  196. // 生成编号
  197. rand_x := 0
  198. T_id := ""
  199. for true {
  200. T_id = lib.GetRandstring(4, "", int64(rand_x))
  201. _, is = VerifyTemplate.Read_VerifyTemplateMap(T_id)
  202. if !is {
  203. if _, ok := tempMap[T_id]; !ok {
  204. break
  205. }
  206. }
  207. rand_x += 1
  208. }
  209. tempMap[T_id] = struct{}{}
  210. idList[i] = T_id
  211. }
  212. mapInsertList := make([]VerifyTemplate.VerifyTemplateMap, 0)
  213. for i, v := range mapList {
  214. vtm := VerifyTemplate.VerifyTemplateMap{
  215. T_id: idList[i],
  216. T_VerifyTemplate_id: new_id,
  217. T_name: v.T_name,
  218. T_text: v.T_text,
  219. T_label: v.T_label,
  220. T_source: v.T_source,
  221. T_sort: v.T_sort,
  222. T_flow_sort: v.T_flow_sort,
  223. T_max_time: v.T_max_time,
  224. T_min_time: v.T_min_time,
  225. }
  226. mapInsertList = append(mapInsertList, vtm)
  227. }
  228. _, is = VerifyTemplate.Add_VerifyTemplateMapMulti(mapInsertList)
  229. if !is {
  230. c.Data["json"] = lib.JSONS{Code: 202, Msg: "复制失败!"}
  231. c.ServeJSON()
  232. return
  233. }
  234. System.Add_UserLogs_T(User_r.T_uuid, "验证模板", "复制", var_)
  235. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: new_id}
  236. c.ServeJSON()
  237. return
  238. }
  239. /// -----------------------------------------------------------------------------
  240. // 标签列表 -
  241. func (c *VerifyTemplateController) Map_List() {
  242. // 验证登录 User_is, User_r
  243. _, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  244. if !User_is {
  245. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  246. c.ServeJSON()
  247. return
  248. }
  249. var r_jsons lib.R_JSONS
  250. // page, _ := c.GetInt("page")
  251. //
  252. // if page < 1 {
  253. // page = 1
  254. // }
  255. //
  256. // page_z, _ := c.GetInt("page_z")
  257. //
  258. // if page_z < 1 {
  259. // page_z = conf.Page_size
  260. // }
  261. T_sort, _ := c.GetInt("T_sort") // 排序
  262. T_flow_sort, _ := c.GetInt("T_flow_sort") // 验证流程排序
  263. T_VerifyTemplate_id := c.GetString("T_VerifyTemplate_id")
  264. var cnt int64
  265. List, cnt := VerifyTemplate.Read_VerifyTemplateMap_List(T_VerifyTemplate_id, T_sort, T_flow_sort)
  266. r_jsons.List = List
  267. r_jsons.Num = int(cnt)
  268. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
  269. c.ServeJSON()
  270. return
  271. }
  272. // 标签添加-
  273. func (c *VerifyTemplateController) Map_Add() {
  274. // 验证登录 User_is, User_r
  275. User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  276. if !User_is {
  277. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  278. c.ServeJSON()
  279. return
  280. }
  281. T_VerifyTemplate_id := c.GetString("T_VerifyTemplate_id")
  282. T_name := c.GetString("T_name")
  283. T_text := c.GetString("T_text")
  284. T_label, _ := c.GetInt("T_label")
  285. T_source, _ := c.GetInt("T_source")
  286. T_sort, _ := c.GetInt("T_sort")
  287. T_flow_sort, _ := c.GetInt("T_flow_sort")
  288. T_max_time, _ := c.GetInt("T_max_time")
  289. T_min_time, _ := c.GetInt("T_min_time")
  290. var_ := VerifyTemplate.VerifyTemplateMap{
  291. T_VerifyTemplate_id: T_VerifyTemplate_id,
  292. T_name: T_name,
  293. T_text: T_text,
  294. T_label: T_label,
  295. T_source: T_source,
  296. T_sort: T_sort,
  297. T_flow_sort: T_flow_sort,
  298. T_max_time: T_max_time,
  299. T_min_time: T_min_time,
  300. }
  301. Id, is := VerifyTemplate.Add_VerifyTemplateMap(var_)
  302. if !is {
  303. c.Data["json"] = lib.JSONS{Code: 202, Msg: "添加失败!"}
  304. c.ServeJSON()
  305. return
  306. }
  307. System.Add_UserLogs_T(User_r.T_uuid, "验证模板标签", "添加", var_)
  308. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: Id}
  309. c.ServeJSON()
  310. return
  311. }
  312. // 标签修改-
  313. func (c *VerifyTemplateController) Map_Up() {
  314. // 验证登录 User_is, User_r
  315. User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  316. if !User_is {
  317. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  318. c.ServeJSON()
  319. return
  320. }
  321. T_name := c.GetString("T_name")
  322. T_text := c.GetString("T_text")
  323. T_label, T_label_err := c.GetInt("T_label")
  324. T_sort, T_sort_err := c.GetInt("T_sort")
  325. T_source, T_source_err := c.GetInt("T_source")
  326. T_min_time, T_min_time_err := c.GetInt("T_min_time")
  327. T_max_time, T_max_time_err := c.GetInt("T_max_time")
  328. T_flow_sort, T_flow_sort_err := c.GetInt("T_flow_sort")
  329. T_id := c.GetString("T_id")
  330. r, is := VerifyTemplate.Read_VerifyTemplateMap(T_id)
  331. if !is {
  332. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  333. c.ServeJSON()
  334. return
  335. }
  336. // .......
  337. if len(T_name) > 0 {
  338. r.T_name = T_name
  339. }
  340. if len(T_text) > 0 {
  341. r.T_text = T_text
  342. }
  343. if T_label_err == nil {
  344. r.T_label = T_label
  345. }
  346. if T_sort_err == nil {
  347. r.T_sort = T_sort
  348. }
  349. if T_source_err == nil {
  350. r.T_source = T_source
  351. }
  352. if T_min_time_err == nil {
  353. r.T_min_time = T_min_time
  354. }
  355. if T_max_time_err == nil {
  356. r.T_max_time = T_max_time
  357. }
  358. if T_flow_sort_err == nil {
  359. r.T_flow_sort = T_flow_sort
  360. }
  361. if !VerifyTemplate.Update_VerifyTemplateMap(r, "T_name", "T_label", "T_text", "T_sort", "T_source", "T_min_time", "T_max_time", "T_flow_sort") {
  362. c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改失败!"}
  363. c.ServeJSON()
  364. return
  365. }
  366. System.Add_UserLogs_T(User_r.T_uuid, "验证模板标签", "修改", r)
  367. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  368. c.ServeJSON()
  369. return
  370. }
  371. // 标签删除-
  372. func (c *VerifyTemplateController) Map_Del() {
  373. // 验证登录 User_is, User_r
  374. User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  375. if !User_is {
  376. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  377. c.ServeJSON()
  378. return
  379. }
  380. T_id := c.GetString("T_id")
  381. if r, is := VerifyTemplate.Read_VerifyTemplateMap(T_id); is {
  382. if !VerifyTemplate.Delete_VerifyTemplateMap(r) {
  383. c.Data["json"] = lib.JSONS{Code: 202, Msg: "删除失败!"}
  384. c.ServeJSON()
  385. return
  386. }
  387. System.Add_UserLogs_T(User_r.T_uuid, "验证模板标签", "删除", r)
  388. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  389. c.ServeJSON()
  390. return
  391. }
  392. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  393. c.ServeJSON()
  394. return
  395. }
  396. /// -----------------------------------------------------------------------------
  397. // 标签数据列表 -
  398. func (c *VerifyTemplateController) Map_Data_List() {
  399. // 验证登录 User_is, User_r
  400. _, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  401. if !User_is {
  402. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  403. c.ServeJSON()
  404. return
  405. }
  406. T_VerifyTemplate_id := c.GetString("T_VerifyTemplate_id")
  407. T_source, _ := c.GetInt("T_source")
  408. T_flow, _ := c.GetInt("T_flow") // app 时间流程
  409. if T_flow == 0 && T_source == 0 {
  410. c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_source Err!"}
  411. c.ServeJSON()
  412. return
  413. }
  414. T_task_id := c.GetString("T_task_id")
  415. task, is := Task.Read_Task(T_task_id)
  416. if !is {
  417. c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_task_id 错误!"}
  418. c.ServeJSON()
  419. return
  420. }
  421. Map_List := VerifyTemplate.Read_VerifyTemplateMap_List_For_Data(T_VerifyTemplate_id, T_source, T_flow)
  422. Data := VerifyTemplate.Read_VerifyTemplateMapData_List(T_source, T_task_id, T_VerifyTemplate_id, Map_List)
  423. type JSONS struct {
  424. //必须的大写开头
  425. Code int16
  426. Msg string
  427. Data interface{} // 泛型
  428. T_step int
  429. }
  430. c.Data["json"] = JSONS{Code: 200, Msg: "ok!", Data: Data, T_step: task.T_step}
  431. c.ServeJSON()
  432. return
  433. }
  434. // 添加标签数据
  435. func (c *VerifyTemplateController) Map_Data_Pu() {
  436. //验证登录 User_is, User_r
  437. //token := c.Ctx.Request.Header.Get("user_tokey")
  438. //User_r, User_is := Account.Verification_Admin(token, "")
  439. //if !User_is {
  440. // c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  441. // c.ServeJSON()
  442. // return
  443. //}
  444. type RequestBody struct {
  445. User_tokey string
  446. T_source int
  447. T_task_id string
  448. T_VerifyTemplate_id string
  449. T_step int // 进行步骤下标
  450. VerifyTemplateMapData []VerifyTemplate.VerifyTemplateMapData_R
  451. }
  452. var body RequestBody
  453. data := c.Ctx.Input.RequestBody
  454. err := json.Unmarshal(data, &body)
  455. if err != nil {
  456. c.Data["json"] = lib.JSONS{Code: 202, Msg: "json返序列化失败:" + err.Error()}
  457. c.ServeJSON()
  458. }
  459. User_r, User_is := Account.Verification_Admin(body.User_tokey, "")
  460. if !User_is {
  461. System.Add_UserLogs_T(User_r.T_uuid, "验证模版标签数据", "未登录-保存", body)
  462. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  463. c.ServeJSON()
  464. return
  465. }
  466. task, is := Task.Read_Task(body.T_task_id)
  467. if !is {
  468. c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_task_id 错误!"}
  469. c.ServeJSON()
  470. return
  471. }
  472. task.T_step = body.T_step
  473. if !Task.Update_Task(task, "T_step") {
  474. c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改任务步骤失败!"}
  475. c.ServeJSON()
  476. return
  477. }
  478. MapDataList := make([]VerifyTemplate.VerifyTemplateMapData, 0)
  479. for _, v := range body.VerifyTemplateMapData {
  480. val := VerifyTemplate.VerifyTemplateMapData{
  481. T_source: v.T_source,
  482. T_task_id: body.T_task_id,
  483. T_VerifyTemplate_id: body.T_VerifyTemplate_id,
  484. T_VerifyTemplateMap_id: v.T_VerifyTemplateMap_id,
  485. T_flow_sort: v.T_flow_sort,
  486. T_max_time: v.T_max_time,
  487. T_min_time: v.T_min_time,
  488. T_value: v.T_value,
  489. T_start_time: v.T_start_time,
  490. }
  491. MapDataList = append(MapDataList, val)
  492. }
  493. ids, is := VerifyTemplate.AddOrUpdate_VerifyTemplateMapData_ADD_History(MapDataList, body.T_source, User_r.T_uuid)
  494. if !is {
  495. c.Data["json"] = lib.JSONS{Code: 202, Msg: "保存失败"}
  496. c.ServeJSON()
  497. return
  498. }
  499. System.Add_UserLogs_T(User_r.T_uuid, "验证模版标签数据", "保存", body)
  500. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: ids}
  501. c.ServeJSON()
  502. return
  503. }
  504. func (c *VerifyTemplateController) Map_Data_Copy() {
  505. // 验证登录 User_is, User_r
  506. User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  507. if !User_is {
  508. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  509. c.ServeJSON()
  510. return
  511. }
  512. T_source, _ := c.GetInt("T_source")
  513. T_flow, _ := c.GetInt("T_flow")
  514. if T_flow == 0 && T_source == 0 {
  515. c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_source Err!"}
  516. c.ServeJSON()
  517. return
  518. }
  519. T_copy_task_id := c.GetString("T_copy_task_id")
  520. copy_task, is := Task.Read_Task(T_copy_task_id)
  521. if !is {
  522. c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_copy_task_id 错误!"}
  523. c.ServeJSON()
  524. return
  525. }
  526. T_paste_task_id := c.GetString("T_paste_task_id")
  527. paste_task, is := Task.Read_Task(T_paste_task_id)
  528. if !is {
  529. c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_paste_task_id 错误!"}
  530. c.ServeJSON()
  531. return
  532. }
  533. if copy_task.T_VerifyTemplate_id != paste_task.T_VerifyTemplate_id {
  534. c.Data["json"] = lib.JSONS{Code: 202, Msg: "仅支持相同模板间复制!"}
  535. c.ServeJSON()
  536. return
  537. }
  538. list := VerifyTemplate.Read_MapData_List(T_source, T_copy_task_id, copy_task.T_VerifyTemplate_id)
  539. MapDataList := make([]VerifyTemplate.VerifyTemplateMapData, 0)
  540. for _, v := range list {
  541. val := VerifyTemplate.VerifyTemplateMapData{
  542. T_source: T_source,
  543. T_task_id: paste_task.T_task_id,
  544. T_VerifyTemplate_id: paste_task.T_VerifyTemplate_id,
  545. T_VerifyTemplateMap_id: v.T_VerifyTemplateMap_id,
  546. T_flow_sort: v.T_flow_sort,
  547. T_max_time: v.T_max_time,
  548. T_min_time: v.T_min_time,
  549. T_value: v.T_value,
  550. }
  551. MapDataList = append(MapDataList, val)
  552. }
  553. var ids []int64
  554. ids, is = VerifyTemplate.AddOrUpdate_VerifyTemplateMapData_ADD_History(MapDataList, T_source, User_r.T_uuid)
  555. if !is {
  556. c.Data["json"] = lib.JSONS{Code: 202, Msg: "保存失败"}
  557. c.ServeJSON()
  558. return
  559. }
  560. System.Add_UserLogs_T(User_r.T_uuid, "验证模版标签数据", "复制", MapDataList)
  561. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: ids}
  562. c.ServeJSON()
  563. return
  564. }
  565. // 添加标签数据
  566. func (c *VerifyTemplateController) Map_Data_History_List() {
  567. // 验证登录 User_is, User_r
  568. _, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  569. if !User_is {
  570. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  571. c.ServeJSON()
  572. return
  573. }
  574. T_task_id := c.GetString("T_task_id")
  575. T_source, _ := c.GetInt("T_source")
  576. _, is := Task.Read_Task(T_task_id)
  577. if !is {
  578. c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_task_id 错误!"}
  579. c.ServeJSON()
  580. return
  581. }
  582. AdminMap := Account.AdminListToMap(Account.Read_Admin_List_ALL_1())
  583. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: VerifyTemplate.Read_VerifyTemplateMapDataHistory_History_List(T_task_id, T_source, AdminMap)}
  584. c.ServeJSON()
  585. return
  586. }
  587. // 标签数据列表 -
  588. func (c *VerifyTemplateController) Map_Data_History_Data_List() {
  589. // 验证登录 User_is, User_r
  590. _, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  591. if !User_is {
  592. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  593. c.ServeJSON()
  594. return
  595. }
  596. T_time := c.GetString("T_time")
  597. if len(T_time) == 0 {
  598. c.Data["json"] = lib.JSONS{Code: 202, Msg: "请选择时间点!"}
  599. c.ServeJSON()
  600. return
  601. }
  602. T_source, _ := c.GetInt("T_source")
  603. if T_source == 0 {
  604. c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_source Err!"}
  605. c.ServeJSON()
  606. return
  607. }
  608. T_task_id := c.GetString("T_task_id")
  609. task, is := Task.Read_Task(T_task_id)
  610. if !is {
  611. c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_task_id 错误!"}
  612. c.ServeJSON()
  613. return
  614. }
  615. Map_List := VerifyTemplate.Read_VerifyTemplateMap_List_For_Data(task.T_VerifyTemplate_id, T_source, 0)
  616. Data := VerifyTemplate.Read_VerifyTemplateMapDataHistory_List(T_source, T_task_id, task.T_VerifyTemplate_id, T_time, Map_List)
  617. type JSONS struct {
  618. //必须的大写开头
  619. Code int16
  620. Msg string
  621. Data interface{} // 泛型
  622. T_step int
  623. }
  624. c.Data["json"] = JSONS{Code: 200, Msg: "ok!", Data: Data, T_step: task.T_step}
  625. c.ServeJSON()
  626. return
  627. }
  628. // 清除数据
  629. func (c *VerifyTemplateController) Map_Data_Clear_Value() {
  630. // 验证登录 User_is, User_r
  631. User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  632. if !User_is {
  633. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  634. c.ServeJSON()
  635. return
  636. }
  637. T_VerifyTemplate_id := c.GetString("T_VerifyTemplate_id")
  638. T_VerifyTemplateMap_id := c.GetString("T_VerifyTemplateMap_id")
  639. T_task_id := c.GetString("T_task_id")
  640. _, is := Task.Read_Task(T_task_id)
  641. if !is {
  642. c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_task_id 错误!"}
  643. c.ServeJSON()
  644. return
  645. }
  646. VerifyTemplate.Clear_VerifyTemplateMapData_T_value(T_task_id, T_VerifyTemplate_id, T_VerifyTemplateMap_id)
  647. System.Add_UserLogs_T(User_r.T_uuid, "验证模版标签数据", "清除数据", fmt.Sprintf("T_task_id:%s T_VerifyTemplate_id:%s T_VerifyTemplateMap_id:%s", T_task_id, T_VerifyTemplate_id, T_VerifyTemplateMap_id))
  648. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  649. c.ServeJSON()
  650. return
  651. }
  652. // 历史数据恢复
  653. func (c *VerifyTemplateController) Map_Data_History_Recover() {
  654. // 验证登录 User_is, User_r
  655. User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  656. if !User_is {
  657. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  658. c.ServeJSON()
  659. return
  660. }
  661. T_time := c.GetString("T_time")
  662. if len(T_time) == 0 {
  663. c.Data["json"] = lib.JSONS{Code: 202, Msg: "请选择时间点!"}
  664. c.ServeJSON()
  665. return
  666. }
  667. T_source, _ := c.GetInt("T_source")
  668. if T_source == 0 {
  669. c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_source Err!"}
  670. c.ServeJSON()
  671. return
  672. }
  673. T_task_id := c.GetString("T_task_id")
  674. task, is := Task.Read_Task(T_task_id)
  675. if !is {
  676. c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_task_id 错误!"}
  677. c.ServeJSON()
  678. return
  679. }
  680. HistoryList := VerifyTemplate.Read_MapDataHistory_List(T_source, T_task_id, task.T_VerifyTemplate_id, T_time)
  681. list := VerifyTemplate.Read_MapData_List(T_source, T_task_id, task.T_VerifyTemplate_id)
  682. HistoryListMap := make(map[string]VerifyTemplate.VerifyTemplateMapDataHistory)
  683. for _, data := range HistoryList {
  684. HistoryListMap[data.T_VerifyTemplateMap_id] = data
  685. }
  686. MapDataList := make([]VerifyTemplate.VerifyTemplateMapData, 0)
  687. for _, v := range list {
  688. if len(v.T_value) > 0 {
  689. continue
  690. }
  691. if HistoryListMap[v.T_VerifyTemplateMap_id].T_value == "" {
  692. continue
  693. }
  694. val := VerifyTemplate.VerifyTemplateMapData{
  695. T_source: T_source,
  696. T_task_id: task.T_task_id,
  697. T_VerifyTemplate_id: task.T_VerifyTemplate_id,
  698. T_VerifyTemplateMap_id: v.T_VerifyTemplateMap_id,
  699. T_flow_sort: v.T_flow_sort,
  700. T_max_time: v.T_max_time,
  701. T_min_time: v.T_min_time,
  702. T_value: HistoryListMap[v.T_VerifyTemplateMap_id].T_value,
  703. }
  704. MapDataList = append(MapDataList, val)
  705. }
  706. var ids []int64
  707. ids, is = VerifyTemplate.AddOrUpdate_VerifyTemplateMapData(MapDataList)
  708. if !is {
  709. c.Data["json"] = lib.JSONS{Code: 202, Msg: "保存失败"}
  710. c.ServeJSON()
  711. return
  712. }
  713. System.Add_UserLogs_T(User_r.T_uuid, "验证模版标签数据", "恢复", MapDataList)
  714. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: ids}
  715. c.ServeJSON()
  716. return
  717. }
  718. func (c *VerifyTemplateController) Class_List() {
  719. // 验证登录 User_is, User_r
  720. _, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  721. if !User_is {
  722. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  723. c.ServeJSON()
  724. return
  725. }
  726. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: VerifyTemplate.Read_VerifyTemplateClass_List()}
  727. c.ServeJSON()
  728. return
  729. }
  730. func (c *VerifyTemplateController) Class_Add() {
  731. // 验证登录 User_is, User_r
  732. User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  733. if !User_is {
  734. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  735. c.ServeJSON()
  736. return
  737. }
  738. T_name := c.GetString("T_name")
  739. T_fid, _ := c.GetInt("T_fid")
  740. var_ := VerifyTemplate.VerifyTemplateClass{
  741. T_name: T_name,
  742. T_fid: T_fid,
  743. T_State: 1,
  744. }
  745. Id, err := VerifyTemplate.Add_VerifyTemplateClass(var_)
  746. if err != nil {
  747. c.Data["json"] = lib.JSONS{Code: 203, Msg: "添加失败"}
  748. c.ServeJSON()
  749. return
  750. }
  751. System.Add_UserLogs_T(User_r.T_uuid, "模板分类", "添加", var_)
  752. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: Id}
  753. c.ServeJSON()
  754. return
  755. }
  756. func (c *VerifyTemplateController) Class_Up() {
  757. User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  758. if !User_is {
  759. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  760. c.ServeJSON()
  761. return
  762. }
  763. T_id, _ := c.GetInt("T_id")
  764. T_name := c.GetString("T_name")
  765. R_VerifyTemplateToolClass, err := VerifyTemplate.Read_VerifyTemplateClass_ById(T_id)
  766. if err != nil {
  767. c.Data["json"] = lib.JSONS{Code: 203, Msg: "T_id Err!"}
  768. c.ServeJSON()
  769. return
  770. }
  771. if len(T_name) > 0 {
  772. R_VerifyTemplateToolClass.T_name = T_name
  773. }
  774. if is := VerifyTemplate.Update_VerifyTemplateClass(R_VerifyTemplateToolClass, "T_name"); !is {
  775. c.Data["json"] = lib.JSONS{Code: 203, Msg: "修改失败"}
  776. c.ServeJSON()
  777. return
  778. }
  779. System.Add_UserLogs_T(User_r.T_uuid, "模板分类", "修改", R_VerifyTemplateToolClass)
  780. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  781. c.ServeJSON()
  782. return
  783. }
  784. func (c *VerifyTemplateController) Class_Del() {
  785. User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  786. if !User_is {
  787. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  788. c.ServeJSON()
  789. return
  790. }
  791. T_id, _ := c.GetInt("T_id")
  792. R_VerifyTemplateToolClass, err := VerifyTemplate.Read_VerifyTemplateClass_ById(T_id)
  793. if err != nil {
  794. c.Data["json"] = lib.JSONS{Code: 203, Msg: "T_id Err!"}
  795. c.ServeJSON()
  796. return
  797. }
  798. ids := VerifyTemplate.ReadVerifyTemplateClassIds_T_path(R_VerifyTemplateToolClass.T_path)
  799. if is := VerifyTemplate.Delete_VerifyTemplateClass_ByIds(ids); !is {
  800. c.Data["json"] = lib.JSONS{Code: 202, Msg: "删除失败!"}
  801. c.ServeJSON()
  802. return
  803. }
  804. System.Add_UserLogs(User_r.T_uuid, "模板分类", "删除", strconv.Itoa(T_id))
  805. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  806. c.ServeJSON()
  807. return
  808. }