package com.whyc.controller;
|
|
import com.whyc.dto.Response;
|
import com.whyc.service.SOPService;
|
import io.swagger.annotations.Api;
|
import io.swagger.annotations.ApiOperation;
|
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestParam;
|
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.multipart.MultipartFile;
|
|
import java.io.IOException;
|
import java.text.ParseException;
|
|
@RequestMapping("sop")
|
@RestController
|
@Api(tags = "SOP")
|
public class SOPController {
|
|
@Autowired
|
private SOPService service;
|
|
@ApiOperation("excel解析")
|
@PostMapping("excelParse")
|
public Response excelParse(@RequestParam MultipartFile multipartFile) throws IOException, InvalidFormatException, ParseException {
|
Response<Object> response = new Response<>();
|
String name=multipartFile.getOriginalFilename();
|
assert name != null;
|
if(!name.substring(name.length()-4).equals(".xls") && !name.substring(name.length()-5).equals(".xlsx")){
|
response.set(1,false,"文件解析错误:上传格式非excel格式");
|
}else{
|
response = service.excelParse(multipartFile.getInputStream());
|
}
|
return response;
|
}
|
}
|