package com.test.controller;

import com.alibaba.fastjson.JSONObject;
import com.test.service.FileService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Controller
@RequestMapping(path = {"/server/file/"})
public class FileController {

    @Resource
    FileService fileService;

    /**
     * 把附件上传到 FTP
     * @param request
     * @param response
     * @param file_id_
     * @param file_path_
     */
    @RequestMapping(path = {"uploadFileToFTP"})
    public void uploadFileToFTP (HttpServletRequest request,
         HttpServletResponse response,
         String file_id_, String file_path_) {
        try {
            request.setCharacterEncoding("utf-8");
            response.setCharacterEncoding("utf-8");
            JSONObject paramsJO = new JSONObject();
            if (StringUtils.isNotBlank(file_id_)) {
                paramsJO.put("file_id_", file_id_);
                paramsJO.put("file_path_", file_path_);
            }
            JSONObject jo = fileService.uploadFileToFTP(request,
                    response, paramsJO);
            System.out.println(jo.toJSONString());
            response.getWriter().write(jo.toJSONString());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * 从 FTP 上下载文件
     * @param request
     * @param response
     * @param file_id_
     * @param file_path_
     */
    @RequestMapping(path = {"downloadFileToFTP"})
    public void downloadFileToFTP (HttpServletRequest request,
         HttpServletResponse response, @RequestBody String jsonStr) {
        try {
            request.setCharacterEncoding("utf-8");
            response.setCharacterEncoding("utf-8");
            JSONObject paramsJO = new JSONObject();
            if (StringUtils.isNotBlank(jsonStr)) {
                paramsJO = JSONObject.parseObject(jsonStr);
            }
            JSONObject jo = fileService.downloadFileToFTP(request,
                    response, paramsJO);
            System.out.println(jo.toJSONString());
            response.getWriter().write(jo.toJSONString());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
最近下载更多
lcqlcl  LV11 2023年8月29日
lironggang  LV38 2023年3月31日
annazhang  LV29 2022年12月1日
zw050256  LV7 2022年9月30日
wuyu8995861  LV7 2022年7月26日
zxysss  LV3 2022年1月6日
cwx1234  LV11 2021年10月8日
123456nty  LV36 2021年9月18日
newhaijun  LV15 2021年8月23日
zy_286315  LV7 2021年8月4日
最近浏览更多
WBelong  LV7 2023年12月19日
lichengai  LV7 2023年11月27日
漫步的海星  LV4 2023年9月21日
lcqlcl  LV11 2023年8月29日
cwb6357123  LV6 2023年6月30日
CL200228  LV4 2023年4月29日
mzj695 2023年4月6日
暂无贡献等级
lironggang  LV38 2023年3月31日
清横白川玉  LV4 2023年1月3日
annazhang  LV29 2022年12月1日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友