VerifyTemplate.go 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448
  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. beego "github.com/beego/beego/v2/server/web"
  11. "math"
  12. )
  13. type VerifyTemplateController struct {
  14. beego.Controller
  15. }
  16. // 列表 -
  17. func (c *VerifyTemplateController) 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_name := c.GetString("T_name")
  35. var cnt int64
  36. List, cnt := VerifyTemplate.Read_VerifyTemplate_List(T_name, page, page_z)
  37. page_size := math.Ceil(float64(cnt) / float64(page_z))
  38. r_jsons.List = List
  39. r_jsons.Page = page
  40. r_jsons.Page_size = int(page_size)
  41. r_jsons.Pages = lib.Func_page(int64(page), int64(page_size))
  42. r_jsons.Num = int(cnt)
  43. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
  44. c.ServeJSON()
  45. return
  46. }
  47. // 添加-
  48. func (c *VerifyTemplateController) Add() {
  49. // 验证登录 User_is, User_r
  50. User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  51. if !User_is {
  52. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  53. c.ServeJSON()
  54. return
  55. }
  56. T_name := c.GetString("T_name")
  57. T_sort, _ := c.GetInt("T_sort")
  58. var_ := VerifyTemplate.VerifyTemplate{
  59. T_name: T_name,
  60. T_sort: T_sort,
  61. }
  62. Id, is := VerifyTemplate.Add_VerifyTemplate(var_)
  63. if !is {
  64. c.Data["json"] = lib.JSONS{Code: 202, Msg: "添加失败!"}
  65. c.ServeJSON()
  66. return
  67. }
  68. System.Add_UserLogs_T(User_r.T_uuid, "验证模板", "添加", var_)
  69. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: Id}
  70. c.ServeJSON()
  71. return
  72. }
  73. // 修改-
  74. func (c *VerifyTemplateController) Up() {
  75. // 验证登录 User_is, User_r
  76. User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  77. if !User_is {
  78. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  79. c.ServeJSON()
  80. return
  81. }
  82. T_name := c.GetString("T_name")
  83. T_sort, T_sort_err := c.GetInt("T_sort")
  84. T_VerifyTemplate_id := c.GetString("T_VerifyTemplate_id")
  85. r, is := VerifyTemplate.Read_VerifyTemplate(T_VerifyTemplate_id)
  86. if !is {
  87. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  88. c.ServeJSON()
  89. return
  90. }
  91. // .......
  92. if len(T_name) > 0 {
  93. r.T_name = T_name
  94. }
  95. if T_sort_err == nil {
  96. r.T_sort = T_sort
  97. }
  98. // .......
  99. if !VerifyTemplate.Update_VerifyTemplate(r, "T_name", "T_sort") {
  100. c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改失败!"}
  101. c.ServeJSON()
  102. return
  103. }
  104. System.Add_UserLogs_T(User_r.T_uuid, "验证模板", "修改", r)
  105. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  106. c.ServeJSON()
  107. return
  108. }
  109. // 删除-
  110. func (c *VerifyTemplateController) Del() {
  111. // 验证登录 User_is, User_r
  112. User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  113. if !User_is {
  114. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  115. c.ServeJSON()
  116. return
  117. }
  118. T_VerifyTemplate_id := c.GetString("T_VerifyTemplate_id")
  119. if r, is := VerifyTemplate.Read_VerifyTemplate(T_VerifyTemplate_id); is {
  120. if !VerifyTemplate.Delete_VerifyTemplate(r) {
  121. c.Data["json"] = lib.JSONS{Code: 202, Msg: "删除失败!"}
  122. c.ServeJSON()
  123. return
  124. }
  125. System.Add_UserLogs_T(User_r.T_uuid, "验证模板", "删除", r)
  126. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  127. c.ServeJSON()
  128. return
  129. }
  130. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  131. c.ServeJSON()
  132. return
  133. }
  134. /// -----------------------------------------------------------------------------
  135. // 标签列表 -
  136. func (c *VerifyTemplateController) Map_List() {
  137. // 验证登录 User_is, User_r
  138. _, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  139. if !User_is {
  140. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  141. c.ServeJSON()
  142. return
  143. }
  144. var r_jsons lib.R_JSONS
  145. page, _ := c.GetInt("page")
  146. if page < 1 {
  147. page = 1
  148. }
  149. page_z, _ := c.GetInt("page_z")
  150. if page_z < 1 {
  151. page_z = conf.Page_size
  152. }
  153. T_sort, _ := c.GetInt("T_sort") // 排序
  154. T_flow_sort, _ := c.GetInt("T_flow_sort") // 验证流程排序
  155. T_VerifyTemplate_id := c.GetString("T_VerifyTemplate_id")
  156. var cnt int64
  157. List, cnt := VerifyTemplate.Read_VerifyTemplateMap_List(T_VerifyTemplate_id, T_sort, T_flow_sort, page, page_z)
  158. page_size := math.Ceil(float64(cnt) / float64(page_z))
  159. r_jsons.List = List
  160. r_jsons.Page = page
  161. r_jsons.Page_size = int(page_size)
  162. r_jsons.Pages = lib.Func_page(int64(page), int64(page_size))
  163. r_jsons.Num = int(cnt)
  164. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
  165. c.ServeJSON()
  166. return
  167. }
  168. // 标签添加-
  169. func (c *VerifyTemplateController) Map_Add() {
  170. // 验证登录 User_is, User_r
  171. User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  172. if !User_is {
  173. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  174. c.ServeJSON()
  175. return
  176. }
  177. T_VerifyTemplate_id := c.GetString("T_VerifyTemplate_id")
  178. T_name := c.GetString("T_name")
  179. T_field := c.GetString("T_field")
  180. T_text := c.GetString("T_text")
  181. T_label, _ := c.GetInt("T_label")
  182. T_source, _ := c.GetInt("T_source")
  183. T_sort, _ := c.GetInt("T_sort")
  184. T_flow_sort, _ := c.GetInt("T_flow_sort")
  185. T_max_time, _ := c.GetInt("T_max_time")
  186. T_min_time, _ := c.GetInt("T_min_time")
  187. var_ := VerifyTemplate.VerifyTemplateMap{
  188. T_VerifyTemplate_id: T_VerifyTemplate_id,
  189. T_name: T_name,
  190. T_field: T_field,
  191. T_text: T_text,
  192. T_label: T_label,
  193. T_source: T_source,
  194. T_sort: T_sort,
  195. T_flow_sort: T_flow_sort,
  196. T_max_time: T_max_time,
  197. T_min_time: T_min_time,
  198. }
  199. Id, is := VerifyTemplate.Add_VerifyTemplateMap(var_)
  200. if !is {
  201. c.Data["json"] = lib.JSONS{Code: 202, Msg: "添加失败!"}
  202. c.ServeJSON()
  203. return
  204. }
  205. System.Add_UserLogs_T(User_r.T_uuid, "验证模板标签", "添加", var_)
  206. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: Id}
  207. c.ServeJSON()
  208. return
  209. }
  210. // 标签修改-
  211. func (c *VerifyTemplateController) Map_Up() {
  212. // 验证登录 User_is, User_r
  213. User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  214. if !User_is {
  215. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  216. c.ServeJSON()
  217. return
  218. }
  219. T_name := c.GetString("T_name")
  220. T_field := c.GetString("T_field")
  221. T_text := c.GetString("T_text")
  222. T_label, T_label_err := c.GetInt("T_label")
  223. T_sort, T_sort_err := c.GetInt("T_sort")
  224. T_source, T_source_err := c.GetInt("T_source")
  225. T_min_time, T_min_time_err := c.GetInt("T_min_time")
  226. T_max_time, T_max_time_err := c.GetInt("T_max_time")
  227. T_flow_sort, T_flow_sort_err := c.GetInt("T_flow_sort")
  228. T_id := c.GetString("T_id")
  229. r, is := VerifyTemplate.Read_VerifyTemplateMap(T_id)
  230. if !is {
  231. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  232. c.ServeJSON()
  233. return
  234. }
  235. // .......
  236. if len(T_name) > 0 {
  237. r.T_name = T_name
  238. }
  239. if len(T_field) > 0 {
  240. r.T_field = T_field
  241. }
  242. if len(T_text) > 0 {
  243. r.T_text = T_text
  244. }
  245. if T_label_err == nil {
  246. r.T_label = T_label
  247. }
  248. if T_sort_err == nil {
  249. r.T_sort = T_sort
  250. }
  251. if T_source_err == nil {
  252. r.T_source = T_source
  253. }
  254. if T_min_time_err == nil {
  255. r.T_min_time = T_min_time
  256. }
  257. if T_max_time_err == nil {
  258. r.T_max_time = T_max_time
  259. }
  260. if T_flow_sort_err == nil {
  261. r.T_flow_sort = T_flow_sort
  262. }
  263. if !VerifyTemplate.Update_VerifyTemplateMap(r, "T_name", "T_label", "T_text", "T_field", "T_sort", "T_source", "T_min_time", "T_max_time", "T_flow_sort") {
  264. c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改失败!"}
  265. c.ServeJSON()
  266. return
  267. }
  268. System.Add_UserLogs_T(User_r.T_uuid, "验证模板标签", "修改", r)
  269. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  270. c.ServeJSON()
  271. return
  272. }
  273. // 标签删除-
  274. func (c *VerifyTemplateController) Map_Del() {
  275. // 验证登录 User_is, User_r
  276. User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  277. if !User_is {
  278. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  279. c.ServeJSON()
  280. return
  281. }
  282. T_id := c.GetString("T_id")
  283. if r, is := VerifyTemplate.Read_VerifyTemplateMap(T_id); is {
  284. if !VerifyTemplate.Delete_VerifyTemplateMap(r) {
  285. c.Data["json"] = lib.JSONS{Code: 202, Msg: "删除失败!"}
  286. c.ServeJSON()
  287. return
  288. }
  289. System.Add_UserLogs_T(User_r.T_uuid, "验证模板标签", "删除", r)
  290. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  291. c.ServeJSON()
  292. return
  293. }
  294. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  295. c.ServeJSON()
  296. return
  297. }
  298. /// -----------------------------------------------------------------------------
  299. // 标签数据列表 -
  300. func (c *VerifyTemplateController) Map_Data_List() {
  301. //验证登录 User_is, User_r
  302. _, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  303. if !User_is {
  304. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  305. c.ServeJSON()
  306. return
  307. }
  308. T_VerifyTemplate_id := c.GetString("T_VerifyTemplate_id")
  309. T_source, T_source_err := c.GetInt("T_source")
  310. if T_source_err != nil || T_source == 0 {
  311. c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_source 错误!"}
  312. c.ServeJSON()
  313. return
  314. }
  315. T_task_id := c.GetString("T_task_id")
  316. _, is := Task.Read_Task(T_task_id)
  317. if !is {
  318. c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_task_id 错误!"}
  319. c.ServeJSON()
  320. return
  321. }
  322. Map_List := VerifyTemplate.Read_VerifyTemplateMap_List_For_Data(T_VerifyTemplate_id, T_source)
  323. Data := VerifyTemplate.Read_VerifyTemplateMapData_List(T_source, T_task_id, T_VerifyTemplate_id, Map_List)
  324. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: Data}
  325. c.ServeJSON()
  326. return
  327. }
  328. // 添加标签数据
  329. func (c *VerifyTemplateController) Map_Data_Pu() {
  330. //验证登录 User_is, User_r
  331. //token := c.Ctx.Request.Header.Get("user_tokey")
  332. //User_r, User_is := Account.Verification_Admin(token, "")
  333. //if !User_is {
  334. // c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  335. // c.ServeJSON()
  336. // return
  337. //}
  338. type RequestBody struct {
  339. User_tokey string
  340. T_source int
  341. T_task_id string
  342. T_VerifyTemplate_id string
  343. VerifyTemplateMapData []VerifyTemplate.VerifyTemplateMapData_R
  344. }
  345. var body RequestBody
  346. data := c.Ctx.Input.RequestBody
  347. err := json.Unmarshal(data, &body)
  348. if err != nil {
  349. c.Data["json"] = lib.JSONS{Code: 202, Msg: "json.Unmarshal is err:" + err.Error()}
  350. c.ServeJSON()
  351. }
  352. User_r, User_is := Account.Verification_Admin(body.User_tokey, "")
  353. if !User_is {
  354. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  355. c.ServeJSON()
  356. return
  357. }
  358. _, is := Task.Read_Task(body.T_task_id)
  359. if !is {
  360. c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_task_id 错误!"}
  361. c.ServeJSON()
  362. return
  363. }
  364. MapDataList := make([]VerifyTemplate.VerifyTemplateMapData, 0)
  365. for _, v := range body.VerifyTemplateMapData {
  366. if len(v.T_value) == 0 {
  367. continue
  368. }
  369. val := VerifyTemplate.VerifyTemplateMapData{
  370. T_source: body.T_source,
  371. T_task_id: body.T_task_id,
  372. T_VerifyTemplate_id: body.T_VerifyTemplate_id,
  373. T_VerifyTemplateMap_id: v.T_VerifyTemplateMap_id,
  374. T_value: v.T_value,
  375. }
  376. MapDataList = append(MapDataList, val)
  377. }
  378. ids, is := VerifyTemplate.AddOrUpdate_VerifyTemplateMapData(MapDataList)
  379. if !is {
  380. c.Data["json"] = lib.JSONS{Code: 202, Msg: "保存失败"}
  381. c.ServeJSON()
  382. return
  383. }
  384. System.Add_UserLogs_T(User_r.T_uuid, "验证模版标签数据", "保存", body)
  385. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: ids}
  386. c.ServeJSON()
  387. return
  388. }