VerifyTemplate.go 25 KB

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