package com.xkrs.controller; import com.xkrs.dao.FileDao; import com.xkrs.encapsulation.PromptMessageEnum; import com.xkrs.model.qo.FileQo; 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(FileQo fileQo, @RequestParam("fileExcel") MultipartFile fileExcel) throws IOException { return fileService.insertFileExcel(fileQo, fileExcel); } /** * 修改上传的模板信息 * * @param fileQo * @param fileExcel * @return * @throws IOException */ @PostMapping("/updateFileUploadPath") @Transactional(rollbackOn = Exception.class) public String updateFileUploadPath(FileQo fileQo, @RequestParam("fileExcel") MultipartFile fileExcel) throws IOException { String lotNo = fileQo.getLotNo(); String machineNo = fileQo.getMachineNo(); String materialNo = fileQo.getMaterialNo(); String modelNo = fileQo.getModelNo(); String machineTypeNo = fileQo.getMachineTypeNo(); String craftItemName = fileQo.getCraftItemName(); Locale locale = LocaleContextHolder.getLocale(); String file = ExcelUploadUtil.memoryFile(fileExcel, 1); fileDao.updateFileUploadPath(lotNo, machineNo, materialNo, modelNo, machineTypeNo, craftItemName, 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); } }