74 lines
2.3 KiB
Java
74 lines
2.3 KiB
Java
|
package com.xkrs.controller;
|
||
|
|
||
|
import com.xkrs.dao.FileDao;
|
||
|
import com.xkrs.encapsulation.PromptMessageEnum;
|
||
|
import com.xkrs.model.qo.FileQo;
|
||
|
import com.xkrs.model.qo.FileUpdateQo;
|
||
|
import com.xkrs.service.FileService;
|
||
|
import com.xkrs.util.ExcelUploadUtil;
|
||
|
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
|
||
|
import org.springframework.context.i18n.LocaleContextHolder;
|
||
|
import org.springframework.web.bind.annotation.*;
|
||
|
import org.springframework.web.multipart.MultipartFile;
|
||
|
|
||
|
import javax.annotation.Resource;
|
||
|
import javax.servlet.http.HttpServletResponse;
|
||
|
import javax.transaction.Transactional;
|
||
|
import java.io.IOException;
|
||
|
import java.util.Locale;
|
||
|
|
||
|
import static com.xkrs.encapsulation.OutputEncapsulation.outputEncapsulationObject;
|
||
|
|
||
|
/**
|
||
|
* @Author: XinYi Song
|
||
|
* @Date: 2022/1/20 16:01
|
||
|
*/
|
||
|
@RestController
|
||
|
public class FileController {
|
||
|
|
||
|
@Resource
|
||
|
private FileService fileService;
|
||
|
|
||
|
@Resource
|
||
|
private FileDao fileDao;
|
||
|
|
||
|
/**
|
||
|
* 上传模板信息
|
||
|
* @param fileQo
|
||
|
* @param fileExcel
|
||
|
* @return
|
||
|
* @throws IOException
|
||
|
*/
|
||
|
@PostMapping("/insertFileExcel")
|
||
|
public String insertFileExcel(FileQo fileQo, @RequestParam("fileExcel") MultipartFile fileExcel) throws IOException {
|
||
|
return fileService.insertFileExcel(fileQo,fileExcel);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 修改上传的模板信息
|
||
|
* @param fileUpdateQo
|
||
|
* @param fileExcel
|
||
|
* @return
|
||
|
* @throws IOException
|
||
|
*/
|
||
|
@PostMapping("/updateFileUploadPath")
|
||
|
@Transactional(rollbackOn = Exception.class)
|
||
|
public String updateFileUploadPath(FileUpdateQo fileUpdateQo,@RequestParam("fileExcel") MultipartFile fileExcel) throws IOException {
|
||
|
Locale locale = LocaleContextHolder.getLocale();
|
||
|
String file = ExcelUploadUtil.memoryFile(fileExcel);
|
||
|
fileDao.updateFileUploadPath(fileUpdateQo.getFileModelNumber(),fileUpdateQo.getFileBatchNumber(),fileUpdateQo.getFileMachineCode(),fileUpdateQo.getFileProductNumber(),file);
|
||
|
return outputEncapsulationObject(PromptMessageEnum.SUCCESS,"修改成功!",locale);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 导出excel
|
||
|
*
|
||
|
* @param fileQo
|
||
|
* @return
|
||
|
*/
|
||
|
@PostMapping("/exportExcel")
|
||
|
public String exportExcel(@RequestBody FileQo fileQo) throws IOException, InvalidFormatException {
|
||
|
return fileService.exportExcel(fileQo);
|
||
|
}
|
||
|
}
|