package com.liang.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.liang.common.base.BaseResult;
import com.liang.common.utils.FileUtil;
import com.liang.dao.FileListMapper;
import com.liang.entity.FileName;
import com.liang.entity.PrjAnnualbudget;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static com.liang.common.base.BaseController.RESULT_ROWS;
import static com.liang.common.base.BaseController.RESULT_TOTAL;

/**
 * @Author ly
 * @Date 2025/2/13 10:45
 * @Version 1.0
 */
@Slf4j
@Controller
@RequestMapping("files")
public class FileutilController {

    @Resource
    private FileListMapper fileListMapper;


    @ApiOperation(value = "文件系统首页",notes = "初始页面")
    @RequestMapping(value = "/fileUtils",method = RequestMethod.GET)
    public String getFile(){
        // 获取 xml 文件中 记录的地址
        // 文件绑定地址设置在前端url 中 创建一个新建按钮
        // 新建按钮绑定为 绑定相关数据类型

        String path = "D:\\视频\\素材\\";
        FileUtil fileUtil = new FileUtil();
        List<String> FileNamelist= fileUtil.getFileName(path);
        for (String fileName : FileNamelist){
            System.out.println(fileName);
        }
        return "file/fileUtil";
    }

    @ApiOperation(value = "页面初始化",notes = "页面初始化")
    @RequestMapping(value = "/list",method = RequestMethod.POST)
    @ResponseBody
    public BaseResult getList(@RequestParam("page") Integer pageNum,
                              @RequestParam("limit") Integer pageSize ){
        // 分页
        PageHelper.startPage(pageNum,pageSize);
        Map<String,String> map = new HashMap<>();

        List<FileName> list = fileListMapper.getFileName(map);

        // 拼接
        PageInfo<FileName> pageinfo = new PageInfo<>(list);
        //取出查询结果
        List<FileName> rows = pageinfo.getList();
        int total = (int) pageinfo.getTotal();
        Map<String, Object> result = new HashMap<>();
        result.put(RESULT_ROWS, rows);
        result.put(RESULT_TOTAL, total);


        return BaseResult.success(result);
    }



}
