package com.pqs9300.controller.uploadFiles;

import com.pqs9300.service.uploadFiles.UploadFilesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.Map;

/**
 * @Author: xuyang
 * @Description:
 */
@Controller
@RequestMapping("uploadFile")
public class UploadFilesController extends HttpServlet {

    @Autowired
    private UploadFilesService uploadFilesService;

    @RequestMapping(value = "upload")
    public String vdWaveform(HttpServletRequest request, HttpSession session) {
        return "business/transaction/indexNextStep";
    }

    /**
     * @Author: xuyang
     * @Date: 2020/7/6 9:58
     * @Description: 首页上传按钮发送的请求
     */
    @RequestMapping(value = "oneFileUpload")
    @ResponseBody
    public Map<String,Object> oneFileUpload(@RequestParam(required = false) MultipartFile file, HttpServletRequest request, HttpServletResponse response, String supIndex, String lineIndex, Integer stepCount, String updateTime){
        return uploadFilesService.fileInformation(file, request, response, supIndex, lineIndex, stepCount,updateTime);
    }

    /**
     * 单文件上传文件名确认修改
     * @param file
     * @param request
     * @param response
     * @param supIndex
     * @param lineIndex
     * @param stepCount
     * @param updateTime
     * @return
     */
    @RequestMapping(value = "fileUploadCommit")
    @ResponseBody
    public Map<String,Object> FileUploadCommit(@RequestParam(required = false) MultipartFile file, HttpServletRequest request, HttpServletResponse response, String supIndex, String lineIndex, Integer stepCount, String updateTime){
        return uploadFilesService.fileCommit(file, request, response, supIndex, lineIndex, stepCount,updateTime);
    }

    /**
     * 跳转多文件上传界面
     * @param supIndex
     * @param stepCount
     * @return
     */
    @RequestMapping(value = "uploadMoreFiles")
    public ModelAndView uploadMoreFiles(String supIndex, Integer stepCount) {
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("supIndex", supIndex);
        modelAndView.addObject("stepCount", stepCount);
        modelAndView.setViewName("business/upload/uploadMoreFiles");
        return modelAndView;
    }

    /**
     * 多文件上传
     * @param file
     * @param request
     * @param response
     * @param supIndex
     * @param stepCount
     * @return
     */
    @RequestMapping(value = "uploadMoreFile")
    @ResponseBody
    public Map<String,Object> uploadMoreFile(@RequestParam("file") MultipartFile file, HttpServletRequest request, HttpServletResponse response, String supIndex, Integer stepCount) {
        return uploadFilesService.uploadFiles(file, request, response, supIndex, stepCount);
    }


}
