VerifyTemplate.go 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  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_sort, _ := c.GetInt("T_sort")
  144. var_ := VerifyTemplate.VerifyTemplateMap{
  145. T_VerifyTemplate_id: T_VerifyTemplate_id,
  146. T_name: T_name,
  147. T_field: T_field,
  148. T_text: T_text,
  149. T_label: T_label,
  150. T_sort: T_sort,
  151. }
  152. Id, is := VerifyTemplate.Add_VerifyTemplateMap(var_)
  153. if !is {
  154. c.Data["json"] = lib.JSONS{Code: 202, Msg: "添加失败!"}
  155. c.ServeJSON()
  156. return
  157. }
  158. System.Add_UserLogs_T(User_r.T_uuid, "验证模板标签", "添加", var_)
  159. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: Id}
  160. c.ServeJSON()
  161. return
  162. }
  163. // 标签修改-
  164. func (c *VerifyTemplateController) Map_Up() {
  165. // 验证登录 User_is, User_r
  166. User_r, User_is := lib.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_name := c.GetString("T_name")
  173. T_field := c.GetString("T_field")
  174. T_text := c.GetString("T_text")
  175. T_label, T_label_err := c.GetInt("T_label")
  176. T_sort, T_sort_err := c.GetInt("T_sort")
  177. T_id := c.GetString("T_id")
  178. r, is := VerifyTemplate.Read_VerifyTemplateMap(T_id)
  179. if !is {
  180. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  181. c.ServeJSON()
  182. return
  183. }
  184. // .......
  185. if len(T_name) > 0 {
  186. r.T_name = T_name
  187. }
  188. if len(T_field) > 0 {
  189. r.T_field = T_field
  190. }
  191. if len(T_text) > 0 {
  192. r.T_text = T_text
  193. }
  194. if T_label_err == nil {
  195. r.T_label = T_label
  196. }
  197. if T_sort_err == nil {
  198. r.T_sort = T_sort
  199. }
  200. // .......
  201. if !VerifyTemplate.Update_VerifyTemplateMap(r, "T_name", "T_label", "T_text", "T_field", "T_sort") {
  202. c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改失败!"}
  203. c.ServeJSON()
  204. return
  205. }
  206. System.Add_UserLogs_T(User_r.T_uuid, "验证模板标签", "修改", r)
  207. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  208. c.ServeJSON()
  209. return
  210. }
  211. // 标签删除-
  212. func (c *VerifyTemplateController) Map_Del() {
  213. // 验证登录 User_is, User_r
  214. User_r, User_is := lib.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  215. if !User_is {
  216. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  217. c.ServeJSON()
  218. return
  219. }
  220. T_id := c.GetString("T_id")
  221. if r, is := VerifyTemplate.Read_VerifyTemplateMap(T_id); is {
  222. if !VerifyTemplate.Delete_VerifyTemplateMap(r) {
  223. c.Data["json"] = lib.JSONS{Code: 202, Msg: "删除失败!"}
  224. c.ServeJSON()
  225. return
  226. }
  227. System.Add_UserLogs_T(User_r.T_uuid, "验证模板标签", "删除", r)
  228. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  229. c.ServeJSON()
  230. return
  231. }
  232. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  233. c.ServeJSON()
  234. return
  235. }
  236. // 标签数据列表 -
  237. func (c *VerifyTemplateController) Map_Data_List() {
  238. //验证登录 User_is, User_r
  239. _, User_is := lib.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  240. if !User_is {
  241. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  242. c.ServeJSON()
  243. return
  244. }
  245. T_VerifyTemplate_id := c.GetString("T_VerifyTemplate_id")
  246. T_task_id := c.GetString("T_task_id")
  247. _, is := Task.Read_Task(T_task_id)
  248. if !is {
  249. c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_task_id 错误!"}
  250. c.ServeJSON()
  251. return
  252. }
  253. Map_List := VerifyTemplate.Read_VerifyTemplateMap_List_1(T_VerifyTemplate_id)
  254. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: VerifyTemplate.Read_VerifyTemplateMapData_List(T_task_id, T_VerifyTemplate_id, Map_List)}
  255. c.ServeJSON()
  256. return
  257. }
  258. // 添加标签数据
  259. func (c *VerifyTemplateController) Map_Data_Add() {
  260. //验证登录 User_is, User_r
  261. User_r, User_is := lib.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  262. if !User_is {
  263. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  264. c.ServeJSON()
  265. return
  266. }
  267. type RequestBody struct {
  268. T_task_id string
  269. T_VerifyTemplate_id string
  270. VerifyTemplateMapData []VerifyTemplate.VerifyTemplateMapData_R
  271. }
  272. var body RequestBody
  273. data := c.Ctx.Input.RequestBody
  274. err := json.Unmarshal(data, &body)
  275. if err != nil {
  276. c.Data["json"] = lib.JSONS{Code: 202, Msg: "json.Unmarshal is err:" + err.Error()}
  277. c.ServeJSON()
  278. }
  279. _, is := Task.Read_Task(body.T_task_id)
  280. if !is {
  281. c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_task_id 错误!"}
  282. c.ServeJSON()
  283. return
  284. }
  285. MapDataList := make([]VerifyTemplate.VerifyTemplateMapData, 0)
  286. for _, v := range body.VerifyTemplateMapData {
  287. if len(v.T_value) == 0 {
  288. continue
  289. }
  290. val := VerifyTemplate.VerifyTemplateMapData{
  291. T_task_id: body.T_task_id,
  292. T_VerifyTemplate_id: body.T_VerifyTemplate_id,
  293. T_VerifyTemplateMap_id: v.T_VerifyTemplateMap_id,
  294. T_value: v.T_value,
  295. }
  296. MapDataList = append(MapDataList, val)
  297. }
  298. ids, is := VerifyTemplate.AddOrUpdate_VerifyTemplateMapData(MapDataList)
  299. if !is {
  300. c.Data["json"] = lib.JSONS{Code: 202, Msg: "保存失败"}
  301. c.ServeJSON()
  302. return
  303. }
  304. System.Add_UserLogs_T(User_r.T_uuid, "验证模版标签数据", "保存", body)
  305. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: ids}
  306. c.ServeJSON()
  307. return
  308. }