| | |
| | | import com.aps.common.log.annotation.Log; |
| | | import com.aps.common.log.enums.BusinessType; |
| | | import com.aps.common.security.annotation.RequiresPermissions; |
| | | import com.aps.common.security.utils.DictUtils; |
| | | import com.aps.core.domain.ApsGasPipelineMo; |
| | | import com.aps.core.service.IApsGasPipelineMoService; |
| | | import com.aps.system.api.domain.SysDictData; |
| | | import io.swagger.v3.oas.annotations.Operation; |
| | | import io.swagger.v3.oas.annotations.tags.Tag; |
| | | import jakarta.servlet.http.HttpServletResponse; |
| | | import lombok.SneakyThrows; |
| | | import org.apache.commons.io.IOUtils; |
| | | import org.apache.poi.ss.usermodel.Row; |
| | | import org.apache.poi.ss.usermodel.Sheet; |
| | | import org.apache.poi.ss.usermodel.Workbook; |
| | | import org.apache.poi.ss.usermodel.WorkbookFactory; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.core.io.ByteArrayResource; |
| | | import org.springframework.http.HttpHeaders; |
| | | import org.springframework.http.ResponseEntity; |
| | | import org.springframework.web.bind.annotation.*; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import java.io.ByteArrayInputStream; |
| | | import java.io.ByteArrayOutputStream; |
| | | import java.net.URLEncoder; |
| | | import java.nio.charset.StandardCharsets; |
| | | import java.util.List; |
| | | |
| | | /** |
| | |
| | | |
| | | @Operation(summary = "导入管路手工气体工单数据", description = "批量导入") |
| | | @Log(title = "导入管路手工气体工单数据", businessType = BusinessType.IMPORT) |
| | | @RequiresPermissions("gasPipeline:mo:import") |
| | | // @RequiresPermissions("gasPipeline:mo:import") |
| | | @PostMapping("/importData") |
| | | public AjaxResult importData(MultipartFile file) throws Exception { |
| | | |
| | | int i = apsGasPipelineMoService.batchInsertGasPipelineMo(file); |
| | | return toAjax(i); |
| | | apsGasPipelineMoService.batchInsertGasPipelineMo(file); |
| | | return toAjax(true); |
| | | } |
| | | |
| | | /** |
| | |
| | | { |
| | | return toAjax(apsGasPipelineMoService.deleteApsGasPipelineMoByIds(ids)); |
| | | } |
| | | |
| | | /** |
| | | * 下载气体预测数据导入模板 |
| | | */ |
| | | @SneakyThrows |
| | | @Operation(summary = "下载气体工单数据导入模板", description = "下载气体工单数据导入模板") |
| | | // @RequiresPermissions("gasPipeline:mo:template") |
| | | // @Log(title = "下载气体工单数据导入模板", businessType = BusinessType.EXPORT) |
| | | @GetMapping("/template") |
| | | public ResponseEntity<ByteArrayResource> exportTemplate() { |
| | | byte[] file = IOUtils.resourceToByteArray("/templates/气体工单数据模板v1.0.xlsx"); |
| | | Workbook workbook = WorkbookFactory.create(new ByteArrayInputStream(file)); |
| | | Sheet sheet = workbook.getSheet("字典-生产基地"); |
| | | List<SysDictData> sysDictDataList = DictUtils.getDictCache("aps_factory"); |
| | | if (sysDictDataList != null) { |
| | | for (int i = 0; i < sysDictDataList.size(); i++) { |
| | | Row row = sheet.createRow(i + 1); |
| | | row.createCell(0).setCellValue(sysDictDataList.get(i).getDictValue()); |
| | | row.createCell(1).setCellValue(sysDictDataList.get(i).getDictLabel()); |
| | | } |
| | | ByteArrayOutputStream baos = new ByteArrayOutputStream(); |
| | | workbook.write(baos); |
| | | file = baos.toByteArray(); |
| | | } |
| | | workbook.close(); |
| | | ByteArrayResource resource = new ByteArrayResource(file); |
| | | return ResponseEntity.ok() |
| | | .header("Access-Control-Expose-Headers", HttpHeaders.CONTENT_DISPOSITION) |
| | | .header(HttpHeaders.CONTENT_DISPOSITION, |
| | | String.format("attachment;filename=%s", URLEncoder.encode("气体工单数据模板.xlsx", StandardCharsets.UTF_8))) |
| | | .header(HttpHeaders.CONTENT_TYPE, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet") |
| | | .contentLength(file.length) |
| | | .body(resource); |
| | | } |
| | | } |