VerifyTemplate.go 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523
  1. package controllers
  2. import (
  3. "bzd_server/lib"
  4. "bzd_server/models/System"
  5. "bzd_server/models/Task"
  6. "bzd_server/models/VerifyTemplate"
  7. "encoding/json"
  8. beego "github.com/beego/beego/v2/server/web"
  9. )
  10. type VerifyTemplateController struct {
  11. beego.Controller
  12. }
  13. // 列表 -
  14. func (c *VerifyTemplateController) List() {
  15. // 验证登录 User_is, User_r
  16. _, User_is := lib.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  17. if !User_is {
  18. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  19. c.ServeJSON()
  20. return
  21. }
  22. T_name := c.GetString("T_name")
  23. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: VerifyTemplate.Read_VerifyTemplate_List(T_name)}
  24. c.ServeJSON()
  25. return
  26. }
  27. // 添加-
  28. func (c *VerifyTemplateController) Add() {
  29. // 验证登录 User_is, User_r
  30. User_r, User_is := lib.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  31. if !User_is {
  32. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  33. c.ServeJSON()
  34. return
  35. }
  36. T_name := c.GetString("T_name")
  37. T_sort, _ := c.GetInt("T_sort")
  38. var_ := VerifyTemplate.VerifyTemplate{
  39. T_name: T_name,
  40. T_sort: T_sort,
  41. }
  42. Id, is := VerifyTemplate.Add_VerifyTemplate(var_)
  43. if !is {
  44. c.Data["json"] = lib.JSONS{Code: 202, Msg: "添加失败!"}
  45. c.ServeJSON()
  46. return
  47. }
  48. System.Add_UserLogs_T(User_r.T_uuid, "验证模板", "添加", var_)
  49. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: Id}
  50. c.ServeJSON()
  51. return
  52. }
  53. // 修改-
  54. func (c *VerifyTemplateController) Up() {
  55. // 验证登录 User_is, User_r
  56. User_r, User_is := lib.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, T_sort_err := c.GetInt("T_sort")
  64. T_VerifyTemplate_id := c.GetString("T_VerifyTemplate_id")
  65. r, is := VerifyTemplate.Read_VerifyTemplate(T_VerifyTemplate_id)
  66. if !is {
  67. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  68. c.ServeJSON()
  69. return
  70. }
  71. // .......
  72. if len(T_name) > 0 {
  73. r.T_name = T_name
  74. }
  75. if T_sort_err == nil {
  76. r.T_sort = T_sort
  77. }
  78. // .......
  79. if !VerifyTemplate.Update_VerifyTemplate(r, "T_name", "T_sort") {
  80. c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改失败!"}
  81. c.ServeJSON()
  82. return
  83. }
  84. System.Add_UserLogs_T(User_r.T_uuid, "验证模板", "修改", r)
  85. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  86. c.ServeJSON()
  87. return
  88. }
  89. // 删除-
  90. func (c *VerifyTemplateController) Del() {
  91. // 验证登录 User_is, User_r
  92. User_r, User_is := lib.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  93. if !User_is {
  94. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  95. c.ServeJSON()
  96. return
  97. }
  98. T_VerifyTemplate_id := c.GetString("T_VerifyTemplate_id")
  99. if r, is := VerifyTemplate.Read_VerifyTemplate(T_VerifyTemplate_id); is {
  100. if !VerifyTemplate.Delete_VerifyTemplate(r) {
  101. c.Data["json"] = lib.JSONS{Code: 202, Msg: "删除失败!"}
  102. c.ServeJSON()
  103. return
  104. }
  105. System.Add_UserLogs_T(User_r.T_uuid, "验证模板", "删除", r)
  106. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  107. c.ServeJSON()
  108. return
  109. }
  110. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  111. c.ServeJSON()
  112. return
  113. }
  114. /// -----------------------------------------------------------------------------
  115. // 标签列表 -
  116. func (c *VerifyTemplateController) Map_List() {
  117. // 验证登录 User_is, User_r
  118. _, User_is := lib.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  119. if !User_is {
  120. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  121. c.ServeJSON()
  122. return
  123. }
  124. T_VerifyTemplate_id := c.GetString("T_VerifyTemplate_id")
  125. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: VerifyTemplate.Read_VerifyTemplateMap_List(T_VerifyTemplate_id)}
  126. c.ServeJSON()
  127. return
  128. }
  129. // 标签添加-
  130. func (c *VerifyTemplateController) Map_Add() {
  131. // 验证登录 User_is, User_r
  132. User_r, User_is := lib.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  133. if !User_is {
  134. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  135. c.ServeJSON()
  136. return
  137. }
  138. T_VerifyTemplate_id := c.GetString("T_VerifyTemplate_id")
  139. T_name := c.GetString("T_name")
  140. T_field := c.GetString("T_field")
  141. T_text := c.GetString("T_text")
  142. T_label, _ := c.GetInt("T_label")
  143. T_source, _ := c.GetInt("T_source")
  144. T_sort, _ := c.GetInt("T_sort")
  145. var_ := VerifyTemplate.VerifyTemplateMap{
  146. T_VerifyTemplate_id: T_VerifyTemplate_id,
  147. T_name: T_name,
  148. T_field: T_field,
  149. T_text: T_text,
  150. T_label: T_label,
  151. T_source: T_source,
  152. T_sort: T_sort,
  153. }
  154. Id, is := VerifyTemplate.Add_VerifyTemplateMap(var_)
  155. if !is {
  156. c.Data["json"] = lib.JSONS{Code: 202, Msg: "添加失败!"}
  157. c.ServeJSON()
  158. return
  159. }
  160. System.Add_UserLogs_T(User_r.T_uuid, "验证模板标签", "添加", var_)
  161. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: Id}
  162. c.ServeJSON()
  163. return
  164. }
  165. // 标签修改-
  166. func (c *VerifyTemplateController) Map_Up() {
  167. // 验证登录 User_is, User_r
  168. User_r, User_is := lib.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  169. if !User_is {
  170. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  171. c.ServeJSON()
  172. return
  173. }
  174. T_name := c.GetString("T_name")
  175. T_field := c.GetString("T_field")
  176. T_text := c.GetString("T_text")
  177. T_label, T_label_err := c.GetInt("T_label")
  178. T_sort, T_sort_err := c.GetInt("T_sort")
  179. T_id := c.GetString("T_id")
  180. r, is := VerifyTemplate.Read_VerifyTemplateMap(T_id)
  181. if !is {
  182. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  183. c.ServeJSON()
  184. return
  185. }
  186. // .......
  187. if len(T_name) > 0 {
  188. r.T_name = T_name
  189. }
  190. if len(T_field) > 0 {
  191. r.T_field = T_field
  192. }
  193. if len(T_text) > 0 {
  194. r.T_text = T_text
  195. }
  196. if T_label_err == nil {
  197. r.T_label = T_label
  198. }
  199. if T_sort_err == nil {
  200. r.T_sort = T_sort
  201. }
  202. // .......
  203. if !VerifyTemplate.Update_VerifyTemplateMap(r, "T_name", "T_label", "T_text", "T_field", "T_sort") {
  204. c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改失败!"}
  205. c.ServeJSON()
  206. return
  207. }
  208. System.Add_UserLogs_T(User_r.T_uuid, "验证模板标签", "修改", r)
  209. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  210. c.ServeJSON()
  211. return
  212. }
  213. // 标签删除-
  214. func (c *VerifyTemplateController) Map_Del() {
  215. // 验证登录 User_is, User_r
  216. User_r, User_is := lib.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  217. if !User_is {
  218. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  219. c.ServeJSON()
  220. return
  221. }
  222. T_id := c.GetString("T_id")
  223. if r, is := VerifyTemplate.Read_VerifyTemplateMap(T_id); is {
  224. if !VerifyTemplate.Delete_VerifyTemplateMap(r) {
  225. c.Data["json"] = lib.JSONS{Code: 202, Msg: "删除失败!"}
  226. c.ServeJSON()
  227. return
  228. }
  229. System.Add_UserLogs_T(User_r.T_uuid, "验证模板标签", "删除", r)
  230. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  231. c.ServeJSON()
  232. return
  233. }
  234. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  235. c.ServeJSON()
  236. return
  237. }
  238. /// -----------------------------------------------------------------------------
  239. // 标签数据列表 -
  240. func (c *VerifyTemplateController) Map_Data_List() {
  241. //验证登录 User_is, User_r
  242. _, User_is := lib.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  243. if !User_is {
  244. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  245. c.ServeJSON()
  246. return
  247. }
  248. T_VerifyTemplate_id := c.GetString("T_VerifyTemplate_id")
  249. T_source, T_source_err := c.GetInt("T_source")
  250. if T_source_err != nil || T_source == 0 {
  251. c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_source 错误!"}
  252. c.ServeJSON()
  253. return
  254. }
  255. T_task_id := c.GetString("T_task_id")
  256. _, is := Task.Read_Task(T_task_id)
  257. if !is {
  258. c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_task_id 错误!"}
  259. c.ServeJSON()
  260. return
  261. }
  262. Map_List := VerifyTemplate.Read_VerifyTemplateMap_List_For_Data(T_VerifyTemplate_id, T_source)
  263. Data := VerifyTemplate.Read_VerifyTemplateMapData_List(T_source, T_task_id, T_VerifyTemplate_id, Map_List)
  264. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: Data}
  265. c.ServeJSON()
  266. return
  267. }
  268. // 添加标签数据
  269. func (c *VerifyTemplateController) Map_Data_Pu() {
  270. //验证登录 User_is, User_r
  271. User_r, User_is := lib.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  272. if !User_is {
  273. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  274. c.ServeJSON()
  275. return
  276. }
  277. type RequestBody struct {
  278. T_source int
  279. T_task_id string
  280. T_VerifyTemplate_id string
  281. VerifyTemplateMapData []VerifyTemplate.VerifyTemplateMapData_R
  282. }
  283. var body RequestBody
  284. data := c.Ctx.Input.RequestBody
  285. err := json.Unmarshal(data, &body)
  286. if err != nil {
  287. c.Data["json"] = lib.JSONS{Code: 202, Msg: "json.Unmarshal is err:" + err.Error()}
  288. c.ServeJSON()
  289. }
  290. _, is := Task.Read_Task(body.T_task_id)
  291. if !is {
  292. c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_task_id 错误!"}
  293. c.ServeJSON()
  294. return
  295. }
  296. MapDataList := make([]VerifyTemplate.VerifyTemplateMapData, 0)
  297. for _, v := range body.VerifyTemplateMapData {
  298. if len(v.T_value) == 0 {
  299. continue
  300. }
  301. val := VerifyTemplate.VerifyTemplateMapData{
  302. T_source: body.T_source,
  303. T_task_id: body.T_task_id,
  304. T_VerifyTemplate_id: body.T_VerifyTemplate_id,
  305. T_VerifyTemplateMap_id: v.T_VerifyTemplateMap_id,
  306. T_value: v.T_value,
  307. }
  308. MapDataList = append(MapDataList, val)
  309. }
  310. ids, is := VerifyTemplate.AddOrUpdate_VerifyTemplateMapData(MapDataList)
  311. if !is {
  312. c.Data["json"] = lib.JSONS{Code: 202, Msg: "保存失败"}
  313. c.ServeJSON()
  314. return
  315. }
  316. System.Add_UserLogs_T(User_r.T_uuid, "验证模版标签数据", "保存", body)
  317. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: ids}
  318. c.ServeJSON()
  319. return
  320. }
  321. /// -----------------------------------------------------------------------------
  322. // 标签列表 -
  323. func (c *VerifyTemplateController) Time_List() {
  324. // 验证登录 User_is, User_r
  325. _, User_is := lib.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  326. if !User_is {
  327. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  328. c.ServeJSON()
  329. return
  330. }
  331. T_VerifyTemplateMap_id := c.GetString("T_VerifyTemplateMap_id")
  332. r, is := VerifyTemplate.Read_VerifyTemplateMap(T_VerifyTemplateMap_id)
  333. if !is {
  334. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  335. c.ServeJSON()
  336. return
  337. }
  338. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: VerifyTemplate.Read_VerifyTemplateTime_List(T_VerifyTemplateMap_id, r)}
  339. c.ServeJSON()
  340. return
  341. }
  342. // 标签添加-
  343. func (c *VerifyTemplateController) Time_Add() {
  344. // 验证登录 User_is, User_r
  345. User_r, User_is := lib.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  346. if !User_is {
  347. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  348. c.ServeJSON()
  349. return
  350. }
  351. T_VerifyTemplateMap_id := c.GetString("T_VerifyTemplateMap_id")
  352. T_step_name := c.GetString("T_step_name")
  353. T_min_time, _ := c.GetInt("T_min_time")
  354. T_max_time, _ := c.GetInt("T_max_time")
  355. T_text := c.GetString("T_text")
  356. T_sort, _ := c.GetInt("T_sort")
  357. var_ := VerifyTemplate.VerifyTemplateTime{
  358. T_VerifyTemplateMap_id: T_VerifyTemplateMap_id,
  359. T_step_name: T_step_name,
  360. T_min_time: T_min_time,
  361. T_max_time: T_max_time,
  362. T_text: T_text,
  363. T_sort: T_sort,
  364. }
  365. Id, is := VerifyTemplate.Add_VerifyTemplateTime(var_)
  366. if !is {
  367. c.Data["json"] = lib.JSONS{Code: 202, Msg: "添加失败!"}
  368. c.ServeJSON()
  369. return
  370. }
  371. System.Add_UserLogs_T(User_r.T_uuid, "验证模板标签-时间流程", "添加", var_)
  372. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: Id}
  373. c.ServeJSON()
  374. return
  375. }
  376. // 标签修改-
  377. func (c *VerifyTemplateController) Time_Up() {
  378. // 验证登录 User_is, User_r
  379. User_r, User_is := lib.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  380. if !User_is {
  381. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  382. c.ServeJSON()
  383. return
  384. }
  385. //T_VerifyTemplateMap_id := c.GetString("T_VerifyTemplateMap_id")
  386. T_step_name := c.GetString("T_step_name")
  387. T_min_time, T_min_time_err := c.GetInt("T_min_time")
  388. T_max_time, T_max_time_err := c.GetInt("T_max_time")
  389. T_text := c.GetString("T_text")
  390. T_sort, T_sort_err := c.GetInt("T_sort")
  391. T_id := c.GetString("T_id")
  392. r, is := VerifyTemplate.Read_VerifyTemplateTime(T_id)
  393. if !is {
  394. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  395. c.ServeJSON()
  396. return
  397. }
  398. if len(T_step_name) > 0 {
  399. r.T_step_name = T_step_name
  400. }
  401. if len(T_text) > 0 {
  402. r.T_text = T_text
  403. }
  404. if T_min_time_err == nil {
  405. r.T_min_time = T_min_time
  406. }
  407. if T_max_time_err == nil {
  408. r.T_max_time = T_max_time
  409. }
  410. if len(T_text) > 0 {
  411. r.T_text = T_text
  412. }
  413. if T_sort_err == nil {
  414. r.T_sort = T_sort
  415. }
  416. if !VerifyTemplate.Update_VerifyTemplateTime(r, "T_step_name", "T_min_time", "T_max_time", "T_text", "T_sort") {
  417. c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改失败!"}
  418. c.ServeJSON()
  419. return
  420. }
  421. System.Add_UserLogs_T(User_r.T_uuid, "验证模板标签-时间流程", "修改", r)
  422. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  423. c.ServeJSON()
  424. return
  425. }
  426. // 标签删除-
  427. func (c *VerifyTemplateController) Time_Del() {
  428. // 验证登录 User_is, User_r
  429. User_r, User_is := lib.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  430. if !User_is {
  431. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  432. c.ServeJSON()
  433. return
  434. }
  435. T_id := c.GetString("T_id")
  436. if r, is := VerifyTemplate.Read_VerifyTemplateTime(T_id); is {
  437. if !VerifyTemplate.Delete_VerifyTemplateTime(r) {
  438. c.Data["json"] = lib.JSONS{Code: 202, Msg: "删除失败!"}
  439. c.ServeJSON()
  440. return
  441. }
  442. System.Add_UserLogs_T(User_r.T_uuid, "验证模板标签-时间流程", "删除", r)
  443. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  444. c.ServeJSON()
  445. return
  446. }
  447. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  448. c.ServeJSON()
  449. return
  450. }