Template.go 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. package controllers
  2. import (
  3. "bzd_server/conf"
  4. "bzd_server/lib"
  5. "bzd_server/models/Template"
  6. beego "github.com/beego/beego/v2/server/web"
  7. "math"
  8. )
  9. type TemplateController struct {
  10. beego.Controller
  11. }
  12. // 列表 -
  13. func (c *TemplateController) List_html() {
  14. // 验证登录 User_is, User_r
  15. //User_r,User_is := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  16. //if !User_is {
  17. // c.Data["json"] = lib.JSONS{Code: 302, Msg: "请重新登录!"}
  18. // c.ServeJSON()
  19. // return
  20. //}
  21. page, _ := c.GetInt("page")
  22. println(page)
  23. if page < 1 {
  24. page = 1
  25. }
  26. page_z, _ := c.GetInt("page_z")
  27. if page_z < 1 {
  28. page_z = conf.Page_size
  29. }
  30. T_name := c.GetString("T_name")
  31. T_class, _ := c.GetInt("T_class")
  32. c.Data["T_name"] = T_name
  33. c.Data["T_class"] = T_class
  34. var cnt int64
  35. c.Data["List"], cnt = Template.Read_Template_List(T_name, T_class, page, page_z)
  36. page_size := math.Ceil(float64(cnt) / float64(conf.Page_size))
  37. c.Data["Page"] = page
  38. c.Data["Page_size"] = page_size
  39. c.Data["Pages"] = lib.Func_page(int64(page), int64(page_size))
  40. c.Data["cnt"] = cnt
  41. c.TplName = "Template/Template.html"
  42. }
  43. // 二级页面
  44. func (c *TemplateController) List_() {
  45. // 验证登录 User_is, User_r
  46. //User_r,User_is := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  47. //if !User_is {
  48. // c.Data["json"] = lib.JSONS{Code: 302, Msg: "请重新登录!"}
  49. // c.ServeJSON()
  50. // return
  51. //}
  52. Id, _ := c.GetInt("Id")
  53. c.Data["Id"] = Id
  54. if Id > 0 {
  55. c.Data["Date"],_ = Template.Read_Template_ById(Id)
  56. //c.Data["FormulaList"] = Formula.ReadFormulaListByid_List(id)
  57. }
  58. c.TplName = "Template/Template-.html"
  59. }
  60. // 获取-
  61. func (c *TemplateController) Get() {
  62. // 验证登录 User_is, User_r
  63. //User_r,User_is := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  64. //if !User_is {
  65. // c.Data["json"] = lib.JSONS{Code: 302, Msg: "请重新登录!"}
  66. // c.ServeJSON()
  67. // return
  68. //}
  69. Id, err := c.GetInt("Id")
  70. if err != nil {
  71. c.Data["json"] = lib.JSONS{Code: 201, Msg: "Id 错误!"}
  72. c.ServeJSON()
  73. return
  74. }
  75. r, is := Template.Read_Template_ById(Id);
  76. if !is {
  77. c.Data["json"] = lib.JSONS{Code: 201, Msg: "Id 错误!"}
  78. c.ServeJSON()
  79. return
  80. }
  81. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!",Data: r}
  82. c.ServeJSON()
  83. return
  84. }
  85. // 列表 -
  86. func (c *TemplateController) List() {
  87. // 验证登录 User_is, User_r
  88. //User_r,User_is := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  89. //if !User_is {
  90. // c.Data["json"] = lib.JSONS{Code: 302, Msg: "请重新登录!"}
  91. // c.ServeJSON()
  92. // return
  93. //}
  94. var r_jsons lib.R_JSONS
  95. page, _ := c.GetInt("page")
  96. if page < 1 {
  97. page = 1
  98. }
  99. page_z, _ := c.GetInt("page_z")
  100. if page_z < 1 {
  101. page_z = conf.Page_size
  102. }
  103. T_name := c.GetString("T_name")
  104. T_class, _ := c.GetInt("T_class")
  105. var cnt int64
  106. List, cnt := Template.Read_Template_List(T_name, T_class, page, page_z)
  107. page_size := math.Ceil(float64(cnt) / float64(page_z))
  108. r_jsons.List = List
  109. r_jsons.Page = page
  110. r_jsons.Page_size = int(page_size)
  111. r_jsons.Pages = lib.Func_page(int64(page), int64(page_size))
  112. r_jsons.Num = int(cnt)
  113. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
  114. c.ServeJSON()
  115. return
  116. }
  117. // 添加-
  118. func (c *TemplateController) Add() {
  119. // 验证登录 User_is, User_r
  120. //User_r,User_is := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  121. //if !User_is {
  122. // c.Data["json"] = lib.JSONS{Code: 302, Msg: "请重新登录!"}
  123. // c.ServeJSON()
  124. // return
  125. //}
  126. T_name := c.GetString("T_name")
  127. T_class, _ := c.GetInt("T_class")
  128. //T_img := c.GetString("T_img")
  129. //T_int, _ := c.GetInt("T_int")
  130. //T_text := c.GetString("T_text")
  131. var_ := Template.Template{
  132. T_name: T_name,
  133. T_class: T_class,
  134. T_State: 1,
  135. }
  136. Id, is := Template.Add_Template(var_)
  137. if !is {
  138. c.Data["json"] = lib.JSONS{Code: 301, Msg: "添加失败!"}
  139. c.ServeJSON()
  140. return
  141. }
  142. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!",Data: Id}
  143. c.ServeJSON()
  144. return
  145. }
  146. // 修改-
  147. func (c *TemplateController) Up() {
  148. // 验证登录 User_is, User_r
  149. //User_r,User_is := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  150. //if !User_is {
  151. // c.Data["json"] = lib.JSONS{Code: 302, Msg: "请重新登录!"}
  152. // c.ServeJSON()
  153. // return
  154. //}
  155. T_name := c.GetString("T_name")
  156. T_class, T_class_err := c.GetInt("T_class")
  157. //T_img := c.GetString("T_img")
  158. //T_int, _ := c.GetInt("T_int")
  159. //T_text := c.GetString("T_text")
  160. Id, err := c.GetInt("Id")
  161. if err != nil {
  162. c.Data["json"] = lib.JSONS{Code: 201, Msg: "Id 错误!"}
  163. c.ServeJSON()
  164. return
  165. }
  166. r, is := Template.Read_Template_ById(Id);
  167. if !is {
  168. c.Data["json"] = lib.JSONS{Code: 201, Msg: "Id 错误!"}
  169. c.ServeJSON()
  170. return
  171. }
  172. // .......
  173. if len(T_name) > 0{
  174. r.T_name = T_name
  175. }
  176. if T_class_err == nil {
  177. r.T_class = T_class
  178. }
  179. // .......
  180. if !Template.Update_Template(r,"T_name","T_class") {
  181. c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改失败!"}
  182. c.ServeJSON()
  183. return
  184. }
  185. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  186. c.ServeJSON()
  187. return
  188. }
  189. // 删除-
  190. func (c *TemplateController) Del() {
  191. // 验证登录 User_is, User_r
  192. //User_r,User_is := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  193. //if !User_is {
  194. // c.Data["json"] = lib.JSONS{Code: 302, Msg: "请重新登录!"}
  195. // c.ServeJSON()
  196. // return
  197. //}
  198. Id, err := c.GetInt("Id")
  199. if err != nil {
  200. c.Data["json"] = lib.JSONS{Code: 201, Msg: "Id 错误!"}
  201. c.ServeJSON()
  202. return
  203. }
  204. if r, is := Template.Read_Template_ById(Id); is {
  205. if !Template.Delete_Template(r) {
  206. c.Data["json"] = lib.JSONS{Code: 202, Msg: "删除失败!"}
  207. c.ServeJSON()
  208. return
  209. }
  210. }
  211. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  212. c.ServeJSON()
  213. return
  214. }