2022-03-01 14:39:41 +08:00

78 lines
2.5 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.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
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(@RequestBody 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(@RequestBody FileUpdateQo fileUpdateQo, @RequestParam("fileExcel") MultipartFile fileExcel) throws IOException {
Locale locale = LocaleContextHolder.getLocale();
String file = ExcelUploadUtil.memoryFile(fileExcel,1);
fileDao.updateFileUploadPath(fileUpdateQo.getLotNo(), fileUpdateQo.getMachineNo(), fileUpdateQo.getMaterialNo(), fileUpdateQo.getModelNo(), fileUpdateQo.getPartNo(), 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);
}
}