package controllers import ( "ColdVerify_server/conf" "ColdVerify_server/lib" "ColdVerify_server/models/Account" FileManagementModel "ColdVerify_server/models/FileManagement" "ColdVerify_server/models/System" "math" "strings" beego "github.com/beego/beego/v2/server/web" ) type FileManagementController struct { beego.Controller } func (c *FileManagementController) List() { User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey")) if !User_is { c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"} c.ServeJSON() return } page, _ := c.GetInt("page") if page < 1 { page = 1 } pageSize, _ := c.GetInt("page_z") if pageSize < 1 { pageSize = conf.Page_size } fileName := strings.TrimSpace(c.GetString("file_name")) list, cnt := FileManagementModel.ReadFileManagementList(fileName, page, pageSize) pageCount := math.Ceil(float64(cnt) / float64(pageSize)) var response lib.R_JSONS response.List = list response.Page = page response.Page_size = int(pageCount) response.Pages = lib.Func_page(int64(page), int64(pageCount)) response.Num = int(cnt) System.Add_UserLogs_T(User_r.T_uuid, "文件管理", "查询", map[string]interface{}{ "file_name": fileName, "page": page, "page_z": pageSize, }) c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: response} c.ServeJSON() } func (c *FileManagementController) Get() { User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey")) if !User_is { c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"} c.ServeJSON() return } id, err := c.GetInt("Id") if err != nil || id <= 0 { c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"} c.ServeJSON() return } file, ok := FileManagementModel.ReadFileManagementById(id) if !ok { c.Data["json"] = lib.JSONS{Code: 202, Msg: "未找到文件信息!"} c.ServeJSON() return } System.Add_UserLogs_T(User_r.T_uuid, "文件管理", "详情", map[string]interface{}{ "id": id, }) c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: FileManagementModel.ToFileManagementR(file)} c.ServeJSON() } func (c *FileManagementController) Add() { User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey")) if !User_is { c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"} c.ServeJSON() return } fileName := strings.TrimSpace(c.GetString("file_name")) filePath := strings.TrimSpace(c.GetString("file_path")) if len(fileName) == 0 || len(filePath) == 0 { c.Data["json"] = lib.JSONS{Code: 202, Msg: "文件名称和文件路径不能为空!"} c.ServeJSON() return } file := FileManagementModel.FileManagement{ FileName: fileName, FilePath: filePath, } id, ok := FileManagementModel.AddFileManagement(file) if !ok { c.Data["json"] = lib.JSONS{Code: 202, Msg: "添加失败!"} c.ServeJSON() return } System.Add_UserLogs_T(User_r.T_uuid, "文件管理", "添加", file) c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: id} c.ServeJSON() } func (c *FileManagementController) Up() { User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey")) if !User_is { c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"} c.ServeJSON() return } id, err := c.GetInt("Id") if err != nil || id <= 0 { c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"} c.ServeJSON() return } file, ok := FileManagementModel.ReadFileManagementById(id) if !ok { c.Data["json"] = lib.JSONS{Code: 202, Msg: "未找到文件信息!"} c.ServeJSON() return } fileName := strings.TrimSpace(c.GetString("file_name")) filePath := strings.TrimSpace(c.GetString("file_path")) updateCols := make([]string, 0, 2) if len(fileName) > 0 { file.FileName = fileName updateCols = append(updateCols, "FileName") } if len(filePath) > 0 { file.FilePath = filePath updateCols = append(updateCols, "FilePath") } if len(updateCols) == 0 { c.Data["json"] = lib.JSONS{Code: 202, Msg: "没有可更新的内容!"} c.ServeJSON() return } if !FileManagementModel.UpdateFileManagement(file, updateCols...) { c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改失败!"} c.ServeJSON() return } System.Add_UserLogs_T(User_r.T_uuid, "文件管理", "修改", file) c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"} c.ServeJSON() } func (c *FileManagementController) Del() { User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey")) if !User_is { c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"} c.ServeJSON() return } id, err := c.GetInt("Id") if err != nil || id <= 0 { c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"} c.ServeJSON() return } file, ok := FileManagementModel.ReadFileManagementById(id) if !ok { c.Data["json"] = lib.JSONS{Code: 202, Msg: "未找到文件信息!"} c.ServeJSON() return } if !FileManagementModel.DeleteFileManagement(file) { c.Data["json"] = lib.JSONS{Code: 202, Msg: "删除失败!"} c.ServeJSON() return } System.Add_UserLogs_T(User_r.T_uuid, "文件管理", "删除", file) c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"} c.ServeJSON() }