| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207 |
- 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()
- }
|