|
|
@@ -0,0 +1,91 @@
|
|
|
+package com.lc.ibps.components.verification.controller;
|
|
|
+
|
|
|
+import com.lc.ibps.api.base.constants.StateEnum;
|
|
|
+import com.lc.ibps.cloud.entity.APIResult;
|
|
|
+import com.lc.ibps.cloud.provider.GenericProvider;
|
|
|
+import com.lc.ibps.components.verification.model.InspectionItemVO;
|
|
|
+import com.lc.ibps.components.verification.service.PerformanceVerificationService;
|
|
|
+import io.swagger.annotations.Api;
|
|
|
+import io.swagger.annotations.ApiOperation;
|
|
|
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
|
|
+import org.apache.poi.ss.usermodel.Workbook;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.validation.annotation.Validated;
|
|
|
+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.ByteArrayOutputStream;
|
|
|
+import java.io.IOException;
|
|
|
+
|
|
|
+@Validated
|
|
|
+@Api(tags = "性能验证接口")
|
|
|
+@RequestMapping(value = "/pv")
|
|
|
+@RestController
|
|
|
+public class PerformanceVerificationController extends GenericProvider{
|
|
|
+
|
|
|
+ protected static final Logger logger = LoggerFactory.getLogger(PerformanceVerificationController.class);
|
|
|
+ @Autowired
|
|
|
+ private PerformanceVerificationService performanceVerificationService;
|
|
|
+
|
|
|
+
|
|
|
+ @PostMapping("/importExcelRecord")
|
|
|
+ @ApiOperation("导入检测数据")
|
|
|
+ public APIResult<Void> importExcelRecord(@RequestParam(value = "name") String name,
|
|
|
+ @RequestParam(value = "id") String id,
|
|
|
+ @RequestParam(value = "applyFiles") MultipartFile applyFiles
|
|
|
+ ) {
|
|
|
+ APIResult<Void> apiResult = new APIResult<>();
|
|
|
+ InspectionItemVO itemVO = null;
|
|
|
+ try {
|
|
|
+ itemVO = performanceVerificationService.importExcelRecord(name, id, applyFiles);
|
|
|
+ if (itemVO.isDataPass()) {
|
|
|
+ apiResult.setMessage("导入成功");
|
|
|
+ apiResult.setState(StateEnum.SUCCESS.getCode());
|
|
|
+ } else {
|
|
|
+ apiResult.setMessage("数据校验失败");
|
|
|
+ apiResult.setState(StateEnum.ERROR.getCode());
|
|
|
+// apiResult.setVariables(itemVO.getErrorMessage());
|
|
|
+ }
|
|
|
+ } catch (IOException e) {
|
|
|
+ apiResult.setMessage("导入失败");
|
|
|
+ apiResult.setState(StateEnum.ERROR.getCode());
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ return apiResult;
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("/exportExcelTemplate")
|
|
|
+ @ApiOperation(value = "导出数据模板", notes = "导出数据")
|
|
|
+ public void exportExcelTemplate(@RequestParam(value = "name") String name,
|
|
|
+ @RequestParam(value = "id") String id) {
|
|
|
+ ByteArrayOutputStream bos = null;
|
|
|
+ try {
|
|
|
+
|
|
|
+ Workbook workbook = performanceVerificationService.exportExcelTemplateExport(name, id);
|
|
|
+// String rootRealPath = AppFileUtil.getRealPath("/" + AppFileUtil.TEMP_PATH); // 操作的根目录
|
|
|
+ String fileName = "dataTemplate_" + name + (workbook instanceof HSSFWorkbook ? ".xls" : ".xlsx");
|
|
|
+// FileUtil.writeFile(rootRealPath + File.separator + fileName + (workbook instanceof HSSFWorkbook ? ".xls" : ".xlsx"), workbook);
|
|
|
+ bos = new ByteArrayOutputStream();
|
|
|
+ workbook.write(bos);
|
|
|
+ byte[] barray = bos.toByteArray();
|
|
|
+ com.lc.ibps.base.web.util.RequestUtil.downLoadFileByByte(this.getRequest(), this.getResponse(), barray, fileName);// 导出
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ logger.error("/pv/exportExcelTemplate", e);
|
|
|
+ } finally {
|
|
|
+ if (bos != null) {
|
|
|
+ try {
|
|
|
+ bos.close();
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|