package com.liang.WT.controller;

import com.liang.common.base.BaseResult;
import com.liang.common.utils.FileUtil;
import com.liang.service.SysDictInfoService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.io.IOException;
import java.util.*;

/**
 * @Author ly
 * @Date 2025/4/13 23:00
 * @Version 1.0
 */
@Controller
@RequestMapping("/bugFile")
public class BugFileController {

    @Resource
    private SysDictInfoService sysDictInfoService;


    @RequestMapping(value = "/init",method = RequestMethod.GET)
    public String edit(Model model){
        return "bugfile/list";

    }

    @RequestMapping(value = "/add",method = RequestMethod.GET)
    public String add(Model model){
        return "bugfile/add";
    }

    // 文件上传
    @RequestMapping(value = "/uploadfile",method = RequestMethod.POST)
    public BaseResult uploadFile(@RequestParam("file") MultipartFile file) {

        FileUtil fileUtil = new FileUtil();
        // 获取文件上传路径
        Map<String,String> map = sysDictInfoService.getDictMap("ftpID");
        // 判别请求的url 是否正常
        if (file.isEmpty()) {
            return BaseResult.failure(1,"文件不能为空");
        }
            boolean mun = fileUtil.uploadToFtp(
                    file,map.get("ip"),
                    Integer.parseInt(map.get("port")),
                    map.get("user"),
                    map.get("password"),
                    map.get("remoteDirpath")
            );
        System.out.println(mun);
            return BaseResult.success(mun);
        }






}
