package controllers import ( "Cold_WorkOrder/Nats" "Cold_WorkOrder/conf" "Cold_WorkOrder/lib" "Cold_WorkOrder/models/Account" "Cold_WorkOrder/models/WorkOrder" beego "github.com/beego/beego/v2/server/web" "math" ) type WorkOrderController struct { beego.Controller User_r Account.User // 登陆的用户 T_pid int // 公司id } func (c *WorkOrderController) Prepare() { c.User_r = *Account.User_r c.T_pid = *Account.T_pid } // 列表 - func (c *WorkOrderController) List() { if c.User_r.T_pid > 0 { c.Data["json"] = lib.JSONS{Code: 202, Msg: "无权查看!"} c.ServeJSON() return } var r_jsons lib.R_JSONS page, _ := c.GetInt("page") if page < 1 { page = 1 } page_z, _ := c.GetInt("page_z") if page_z < 1 { page_z = conf.Page_size } Company_name := c.GetString("T_name") T_handle, _ := c.GetInt("T_handle") var CompanyIds []int var Company_list []Account.Company Company_list = Nats.CompanyListAllByT_name(Company_name) if len(Company_name) > 0 { for _, v := range Company_list { CompanyIds = append(CompanyIds, v.Id) } } Account.Read_Admin_All_Map(Nats.UserListAll()) Account.Read_Company_All_Map(Company_list) var cnt int64 List, cnt := WorkOrder.Read_WorkOrder_List(T_handle, page, page_z, CompanyIds) page_size := math.Ceil(float64(cnt) / float64(page_z)) r_jsons.List = List r_jsons.Page = page r_jsons.Page_size = int(page_size) r_jsons.Pages = lib.Func_page(int64(page), int64(page_size)) r_jsons.Num = int(cnt) c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons} c.ServeJSON() return } // 列表 - func (c *WorkOrderController) User_List() { var r_jsons lib.R_JSONS page, _ := c.GetInt("page") if page < 1 { page = 1 } page_z, _ := c.GetInt("page_z") if page_z < 1 { page_z = conf.Page_size } var cnt int64 var Company_list []Account.Company Company_list = Nats.CompanyListAllByT_name("") Account.Read_Admin_All_Map(Nats.UserListAll()) Account.Read_Company_All_Map(Company_list) List, cnt := WorkOrder.Read_UserWorkOrder_List(c.User_r, c.T_pid, page, page_z) page_size := math.Ceil(float64(cnt) / float64(page_z)) r_jsons.List = List r_jsons.Page = page r_jsons.Page_size = int(page_size) r_jsons.Pages = lib.Func_page(int64(page), int64(page_size)) r_jsons.Num = int(cnt) c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons} c.ServeJSON() return } // 标签查询- func (c *WorkOrderController) Get() { Id, err := c.GetInt("Id") if err != nil || Id == 0 { c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"} c.ServeJSON() return } r, err := WorkOrder.Read_WorkOrder_ById(Id) if err != nil { c.Data["json"] = lib.JSONS{Code: 202, Msg: "查询失败!"} c.ServeJSON() return } c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: WorkOrder.WorkOrderToWorkOrder_(r)} c.ServeJSON() return } // 添加- func (c *WorkOrderController) Add() { T_title := c.GetString("T_title") T_text := c.GetString("T_text") if c.User_r.T_pid == 0 { c.Data["json"] = lib.JSONS{Code: 202, Msg: "仅限用户提交!"} c.ServeJSON() return } var_ := WorkOrder.WorkOrder{ T_uuid: c.User_r.T_uuid, T_pid: c.User_r.T_pid, T_title: T_title, T_text: T_text, T_State: 2, // 1 已处理 2 待处理 } Id, err := WorkOrder.Add_WorkOrder(var_) if err != nil { c.Data["json"] = lib.JSONS{Code: 202, Msg: "添加失败!"} c.ServeJSON() return } Nats.AddUserLogs(c.User_r.T_uuid, "工单系统", "添加", var_) c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: Id} c.ServeJSON() return } // 标签修改- func (c *WorkOrderController) Up() { Id, err := c.GetInt("Id") if err != nil || Id == 0 { c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"} c.ServeJSON() return } T_title := c.GetString("T_title") // 工单标题 T_text := c.GetString("T_text") // 工单详情 T_handle, T_handle_err := c.GetInt("T_handle") // 处理状态 1-已处理 3-已回访 T_info := c.GetString("T_info") r, err := WorkOrder.Read_WorkOrder_ById(Id) if err != nil { c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改失败!"} c.ServeJSON() return } // ....... cols := []string{} if len(T_title) > 0 { r.T_title = T_title cols = append(cols, "T_title") } if len(T_text) > 0 { r.T_text = T_text cols = append(cols, "T_text") } if T_handle_err == nil { r.T_State = T_handle cols = append(cols, "T_State") if r.T_State == 1 { r.T_deal_with = WorkOrder.UpdateWorkOrderInfoToString(r.T_deal_with, T_info, c.User_r.T_uuid) cols = append(cols, "T_deal_with") } if r.T_State == 3 { r.T_callback = WorkOrder.UpdateWorkOrderInfoToString(r.T_callback, T_info, c.User_r.T_uuid) cols = append(cols, "T_callback") } } // ....... if !WorkOrder.Update_WorkOrder(r, cols...) { c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改失败!"} c.ServeJSON() return } Nats.AddUserLogs(c.User_r.T_uuid, "工单系统", "修改", r) c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"} c.ServeJSON() return } // 标签删除- func (c *WorkOrderController) Del() { Id, err := c.GetInt("Id") if err != nil || Id == 0 { c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"} c.ServeJSON() return } r, err := WorkOrder.Read_WorkOrder_ById(Id) if err != nil { c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"} c.ServeJSON() return } if err = WorkOrder.Delete_WorkOrder_ById(r); err != nil { c.Data["json"] = lib.JSONS{Code: 202, Msg: "删除失败!"} c.ServeJSON() return } Nats.AddUserLogs(c.User_r.T_uuid, "工单系统", "删除", r) c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"} c.ServeJSON() return }