whycxzp
2023-02-20 507330fdeef6c389efb265fe65b6590d26af7367
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package com.whyc.controller;
 
import com.whyc.dto.Response;
import com.whyc.service.ECRService;
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.*;
import org.springframework.web.multipart.MultipartFile;
 
import java.io.IOException;
import java.text.ParseException;
 
/**
 * 设 计 工  程  变  更  申  请  调  查  表(ECR)
 */
@RestController
@Api(tags = "ecr")
@RequestMapping("ecr")
public class ECRController {
 
    @Autowired
    private ECRService service;
 
    @ApiOperation("excel导入ECR")
    @PostMapping("ecrImportByExcel")
    public Response ecrImportByExcel(@RequestPart 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.ecrImportByExcel(multipartFile.getInputStream());
        }
        return response;
    }
}