VerifyTemplate.go 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371
  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. func (c *VerifyTemplateController) Map_Data_List() {
  240. //验证登录 User_is, User_r
  241. _, User_is := lib.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  242. if !User_is {
  243. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  244. c.ServeJSON()
  245. return
  246. }
  247. T_VerifyTemplate_id := c.GetString("T_VerifyTemplate_id")
  248. T_source, T_source_err := c.GetInt("T_source")
  249. if T_source_err != nil {
  250. c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_source 错误!"}
  251. c.ServeJSON()
  252. return
  253. }
  254. T_task_id := c.GetString("T_task_id")
  255. _, is := Task.Read_Task(T_task_id)
  256. if !is {
  257. c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_task_id 错误!"}
  258. c.ServeJSON()
  259. return
  260. }
  261. Map_List := VerifyTemplate.Read_VerifyTemplateMap_List_For_Data(T_VerifyTemplate_id, T_source)
  262. Data := VerifyTemplate.Read_VerifyTemplateMapData_List(T_source, T_task_id, T_VerifyTemplate_id, Map_List)
  263. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: Data}
  264. c.ServeJSON()
  265. return
  266. }
  267. // 添加标签数据
  268. func (c *VerifyTemplateController) Map_Data_Pu() {
  269. //验证登录 User_is, User_r
  270. User_r, User_is := lib.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  271. if !User_is {
  272. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  273. c.ServeJSON()
  274. return
  275. }
  276. type RequestBody struct {
  277. T_source int
  278. T_task_id string
  279. T_VerifyTemplate_id string
  280. VerifyTemplateMapData []VerifyTemplate.VerifyTemplateMapData_R
  281. }
  282. var body RequestBody
  283. data := c.Ctx.Input.RequestBody
  284. err := json.Unmarshal(data, &body)
  285. if err != nil {
  286. c.Data["json"] = lib.JSONS{Code: 202, Msg: "json.Unmarshal is err:" + err.Error()}
  287. c.ServeJSON()
  288. }
  289. _, is := Task.Read_Task(body.T_task_id)
  290. if !is {
  291. c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_task_id 错误!"}
  292. c.ServeJSON()
  293. return
  294. }
  295. MapDataList := make([]VerifyTemplate.VerifyTemplateMapData, 0)
  296. for _, v := range body.VerifyTemplateMapData {
  297. if len(v.T_value) == 0 {
  298. continue
  299. }
  300. val := VerifyTemplate.VerifyTemplateMapData{
  301. T_source: body.T_source,
  302. T_task_id: body.T_task_id,
  303. T_VerifyTemplate_id: body.T_VerifyTemplate_id,
  304. T_VerifyTemplateMap_id: v.T_VerifyTemplateMap_id,
  305. T_value: v.T_value,
  306. }
  307. MapDataList = append(MapDataList, val)
  308. }
  309. ids, is := VerifyTemplate.AddOrUpdate_VerifyTemplateMapData(MapDataList)
  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, "验证模版标签数据", "保存", body)
  316. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: ids}
  317. c.ServeJSON()
  318. return
  319. }