WorkOrder.go 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. package controllers
  2. import (
  3. "Cold_WorkOrder/Nats"
  4. "Cold_WorkOrder/conf"
  5. "Cold_WorkOrder/lib"
  6. "Cold_WorkOrder/models/Account"
  7. "Cold_WorkOrder/models/WorkOrder"
  8. beego "github.com/beego/beego/v2/server/web"
  9. "math"
  10. )
  11. type WorkOrderController struct {
  12. beego.Controller
  13. User_r Account.User // 登陆的用户
  14. T_pid int // 公司id
  15. }
  16. func (c *WorkOrderController) Prepare() {
  17. c.User_r = *Account.User_r
  18. c.T_pid = *Account.T_pid
  19. }
  20. // 列表 -
  21. func (c *WorkOrderController) List() {
  22. if c.User_r.T_pid > 0 {
  23. c.Data["json"] = lib.JSONS{Code: 202, Msg: "无权查看!"}
  24. c.ServeJSON()
  25. return
  26. }
  27. var r_jsons lib.R_JSONS
  28. page, _ := c.GetInt("page")
  29. if page < 1 {
  30. page = 1
  31. }
  32. page_z, _ := c.GetInt("page_z")
  33. if page_z < 1 {
  34. page_z = conf.Page_size
  35. }
  36. Company_name := c.GetString("T_name")
  37. T_handle, _ := c.GetInt("T_handle")
  38. var CompanyIds []int
  39. var Company_list []Account.Company
  40. Company_list = Nats.CompanyListAllByT_name(Company_name)
  41. if len(Company_name) > 0 {
  42. for _, v := range Company_list {
  43. CompanyIds = append(CompanyIds, v.Id)
  44. }
  45. }
  46. Account.Read_Admin_All_Map(Nats.UserListAll())
  47. Account.Read_Company_All_Map(Company_list)
  48. var cnt int64
  49. List, cnt := WorkOrder.Read_WorkOrder_List(T_handle, page, page_z, CompanyIds)
  50. page_size := math.Ceil(float64(cnt) / float64(page_z))
  51. r_jsons.List = List
  52. r_jsons.Page = page
  53. r_jsons.Page_size = int(page_size)
  54. r_jsons.Pages = lib.Func_page(int64(page), int64(page_size))
  55. r_jsons.Num = int(cnt)
  56. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
  57. c.ServeJSON()
  58. return
  59. }
  60. // 列表 -
  61. func (c *WorkOrderController) User_List() {
  62. var r_jsons lib.R_JSONS
  63. page, _ := c.GetInt("page")
  64. if page < 1 {
  65. page = 1
  66. }
  67. page_z, _ := c.GetInt("page_z")
  68. if page_z < 1 {
  69. page_z = conf.Page_size
  70. }
  71. var cnt int64
  72. var Company_list []Account.Company
  73. Company_list = Nats.CompanyListAllByT_name("")
  74. Account.Read_Admin_All_Map(Nats.UserListAll())
  75. Account.Read_Company_All_Map(Company_list)
  76. List, cnt := WorkOrder.Read_UserWorkOrder_List(c.User_r, c.T_pid, page, page_z)
  77. page_size := math.Ceil(float64(cnt) / float64(page_z))
  78. r_jsons.List = List
  79. r_jsons.Page = page
  80. r_jsons.Page_size = int(page_size)
  81. r_jsons.Pages = lib.Func_page(int64(page), int64(page_size))
  82. r_jsons.Num = int(cnt)
  83. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
  84. c.ServeJSON()
  85. return
  86. }
  87. // 标签查询-
  88. func (c *WorkOrderController) Get() {
  89. Id, err := c.GetInt("Id")
  90. if err != nil || Id == 0 {
  91. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  92. c.ServeJSON()
  93. return
  94. }
  95. r, err := WorkOrder.Read_WorkOrder_ById(Id)
  96. if err != nil {
  97. c.Data["json"] = lib.JSONS{Code: 202, Msg: "查询失败!"}
  98. c.ServeJSON()
  99. return
  100. }
  101. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: WorkOrder.WorkOrderToWorkOrder_(r)}
  102. c.ServeJSON()
  103. return
  104. }
  105. // 添加-
  106. func (c *WorkOrderController) Add() {
  107. T_title := c.GetString("T_title")
  108. T_text := c.GetString("T_text")
  109. if c.User_r.T_pid == 0 {
  110. c.Data["json"] = lib.JSONS{Code: 202, Msg: "仅限用户提交!"}
  111. c.ServeJSON()
  112. return
  113. }
  114. var_ := WorkOrder.WorkOrder{
  115. T_uuid: c.User_r.T_uuid,
  116. T_pid: c.User_r.T_pid,
  117. T_title: T_title,
  118. T_text: T_text,
  119. T_State: 2, // 1 已处理 2 待处理
  120. }
  121. Id, err := WorkOrder.Add_WorkOrder(var_)
  122. if err != nil {
  123. c.Data["json"] = lib.JSONS{Code: 202, Msg: "添加失败!"}
  124. c.ServeJSON()
  125. return
  126. }
  127. Nats.AddUserLogs(c.User_r.T_uuid, "工单系统", "添加", var_)
  128. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: Id}
  129. c.ServeJSON()
  130. return
  131. }
  132. // 标签修改-
  133. func (c *WorkOrderController) Up() {
  134. Id, err := c.GetInt("Id")
  135. if err != nil || Id == 0 {
  136. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  137. c.ServeJSON()
  138. return
  139. }
  140. T_title := c.GetString("T_title") // 工单标题
  141. T_text := c.GetString("T_text") // 工单详情
  142. T_handle, T_handle_err := c.GetInt("T_handle") // 处理状态 1-已处理 3-已回访
  143. T_info := c.GetString("T_info")
  144. r, err := WorkOrder.Read_WorkOrder_ById(Id)
  145. if err != nil {
  146. c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改失败!"}
  147. c.ServeJSON()
  148. return
  149. }
  150. // .......
  151. cols := []string{}
  152. if len(T_title) > 0 {
  153. r.T_title = T_title
  154. cols = append(cols, "T_title")
  155. }
  156. if len(T_text) > 0 {
  157. r.T_text = T_text
  158. cols = append(cols, "T_text")
  159. }
  160. if T_handle_err == nil {
  161. r.T_State = T_handle
  162. cols = append(cols, "T_State")
  163. if r.T_State == 1 {
  164. r.T_deal_with = WorkOrder.UpdateWorkOrderInfoToString(r.T_deal_with, T_info, c.User_r.T_uuid)
  165. cols = append(cols, "T_deal_with")
  166. }
  167. if r.T_State == 3 {
  168. r.T_callback = WorkOrder.UpdateWorkOrderInfoToString(r.T_callback, T_info, c.User_r.T_uuid)
  169. cols = append(cols, "T_callback")
  170. }
  171. }
  172. // .......
  173. if !WorkOrder.Update_WorkOrder(r, cols...) {
  174. c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改失败!"}
  175. c.ServeJSON()
  176. return
  177. }
  178. Nats.AddUserLogs(c.User_r.T_uuid, "工单系统", "修改", r)
  179. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  180. c.ServeJSON()
  181. return
  182. }
  183. // 标签删除-
  184. func (c *WorkOrderController) Del() {
  185. Id, err := c.GetInt("Id")
  186. if err != nil || Id == 0 {
  187. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  188. c.ServeJSON()
  189. return
  190. }
  191. r, err := WorkOrder.Read_WorkOrder_ById(Id)
  192. if err != nil {
  193. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  194. c.ServeJSON()
  195. return
  196. }
  197. if err = WorkOrder.Delete_WorkOrder_ById(r); err != nil {
  198. c.Data["json"] = lib.JSONS{Code: 202, Msg: "删除失败!"}
  199. c.ServeJSON()
  200. return
  201. }
  202. Nats.AddUserLogs(c.User_r.T_uuid, "工单系统", "删除", r)
  203. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  204. c.ServeJSON()
  205. return
  206. }