package controllers import ( "bzd_server/conf" "bzd_server/lib" "bzd_server/models/System" "bzd_server/models/Task" beego "github.com/beego/beego/v2/server/web" "math" ) type TaskController struct { beego.Controller } // 列表 - func (c *TaskController) List() { // 验证登录 User_is, User_r _,User_is := lib.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey")) if !User_is { c.Data["json"] = lib.JSONS{Code: 302, 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 } T_name := c.GetString("T_name") T_uuid := c.GetString("T_uuid") var cnt int64 List, cnt := Task.Read_UserTask_List(T_uuid,T_name, 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 *TaskController) UserTaskList() { // 验证登录 User_is, User_r User_r,User_is := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey")) if !User_is { c.Data["json"] = lib.JSONS{Code: 302, 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 } T_name := c.GetString("T_name") var cnt int64 List, cnt := Task.Read_UserTask_List(User_r.T_uuid,T_name, 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 *TaskController) Get() { // 验证登录 User_is, User_r _,User_is := lib.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey")) if !User_is { c.Data["json"] = lib.JSONS{Code: 302, Msg: "请重新登录!"} c.ServeJSON() return } T_task_id := c.GetString("T_task_id") r, is := Task.Read_Task(T_task_id); if !is { c.Data["json"] = lib.JSONS{Code: 201, Msg: "Id 错误!"} c.ServeJSON() return } c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!",Data: Task.TaskToTask_R(r)} c.ServeJSON() return } // 添加- func (c *TaskController) Add() { // 验证登录 User_is, User_r User_r,User_is := lib.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey")) if !User_is { c.Data["json"] = lib.JSONS{Code: 302, Msg: "请重新登录!"} c.ServeJSON() return } T_name := c.GetString("T_name") T_uuid := c.GetString("T_uuid") var_ := Task.Task{ T_uuid: T_uuid, T_name: T_name, T_State: 1, } T_task_id, is := Task.Add_Task(var_) if !is { c.Data["json"] = lib.JSONS{Code: 301, Msg: "添加失败!"} c.ServeJSON() return } System.Add_UserLogs_T(User_r.T_uuid,"任务管理", "添加", var_) c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!",Data: T_task_id} c.ServeJSON() return } // 修改- func (c *TaskController) Up() { // 验证登录 User_is, User_r User_r,User_is := lib.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey")) if !User_is { c.Data["json"] = lib.JSONS{Code: 302, Msg: "请重新登录!"} c.ServeJSON() return } T_name := c.GetString("T_name") T_State,T_State_err := c.GetInt("T_State") T_doc1 := c.GetString("T_doc1") T_pdf1 := c.GetString("T_pdf1") T_doc2 := c.GetString("T_doc2") T_pdf2 := c.GetString("T_pdf2") T_doc3 := c.GetString("T_doc3") T_pdf3 := c.GetString("T_pdf3") T_task_id := c.GetString("T_task_id") r, is := Task.Read_Task(T_task_id); if !is { c.Data["json"] = lib.JSONS{Code: 201, Msg: "Id 错误!"} c.ServeJSON() return } // ....... if len(T_name) > 0{ r.T_name = T_name } if T_State_err == nil { r.T_State = T_State } if len(T_doc1) > 0{ r.T_doc1 = T_doc1 } if len(T_pdf1) > 0{ r.T_pdf1 = T_pdf1 } if len(T_doc2) > 0{ r.T_doc2 = T_doc2 } if len(T_pdf2) > 0{ r.T_pdf2 = T_pdf2 } if len(T_doc3) > 0{ r.T_doc3 = T_doc3 } if len(T_pdf3) > 0{ r.T_pdf3 = T_pdf3 } // ....... if !Task.Update_Task(r,"T_name","T_State","T_doc1","T_pdf1","T_doc2","T_pdf2","T_doc3","T_pdf3") { c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改失败!"} c.ServeJSON() return } System.Add_UserLogs_T(User_r.T_uuid,"任务管理", "修改", r) c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"} c.ServeJSON() return } // 删除- func (c *TaskController) Del() { // 验证登录 User_is, User_r User_r,User_is := lib.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey")) if !User_is { c.Data["json"] = lib.JSONS{Code: 302, Msg: "请重新登录!"} c.ServeJSON() return } T_task_id := c.GetString("T_task_id") if r, is := Task.Read_Task(T_task_id); is { if !Task.Delete_Task(r) { c.Data["json"] = lib.JSONS{Code: 202, Msg: "删除失败!"} c.ServeJSON() return } System.Add_UserLogs_T(User_r.T_uuid,"任务管理", "删除", r) } c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"} c.ServeJSON() return }