| | |
| | | package org.dromara.eims.controller; |
| | | |
| | | import java.io.IOException; |
| | | import java.io.InputStream; |
| | | import java.io.UnsupportedEncodingException; |
| | | import java.net.URLEncoder; |
| | | import java.util.List; |
| | | |
| | | import jakarta.servlet.ServletOutputStream; |
| | | import lombok.RequiredArgsConstructor; |
| | | import jakarta.servlet.http.HttpServletResponse; |
| | | import jakarta.validation.constraints.*; |
| | | import cn.dev33.satoken.annotation.SaCheckPermission; |
| | | import org.springframework.core.io.ClassPathResource; |
| | | import org.springframework.http.MediaType; |
| | | import org.springframework.web.bind.annotation.*; |
| | | import org.springframework.validation.annotation.Validated; |
| | | import org.dromara.common.idempotent.annotation.RepeatSubmit; |
| | |
| | | import org.dromara.eims.domain.bo.EimsInspectPlanBo; |
| | | import org.dromara.eims.service.IEimsInspectPlanService; |
| | | import org.dromara.common.mybatis.core.page.TableDataInfo; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | /** |
| | | * 点检计划 |
| | |
| | | @PathVariable Long[] ids) { |
| | | return toAjax(eimsInspectPlanService.deleteWithValidByIds(List.of(ids), true)); |
| | | } |
| | | |
| | | /** |
| | | * 导入数据 |
| | | * |
| | | * @param file 导入文件 |
| | | * @param updateSupport 是否更新已存在数据 |
| | | */ |
| | | @Log(title = "点检计划", businessType = BusinessType.IMPORT) |
| | | @SaCheckPermission("eims:inspectPlan:import") |
| | | @PostMapping(value = "/importData", consumes = MediaType.MULTIPART_FORM_DATA_VALUE) |
| | | public R<Void> importData(@RequestPart("file") MultipartFile file, boolean updateSupport) throws Exception { |
| | | // ExcelResult<InspectCheckItemVo> result = ExcelUtil.importExcel(file.getInputStream(), InspectCheckItemVo.class, new InspectCheckItemImportListener(updateSupport)); |
| | | String res = eimsInspectPlanService.importData(file, updateSupport); |
| | | return R.ok(res); |
| | | } |
| | | |
| | | /** |
| | | * 获取导入模板 |
| | | */ |
| | | @PostMapping("/importTemplate") |
| | | public void importTemplate(HttpServletResponse response) throws UnsupportedEncodingException { |
| | | // 设置响应类型 |
| | | response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); |
| | | response.setCharacterEncoding("utf-8"); |
| | | |
| | | // 设置文件名 |
| | | String fileName = URLEncoder.encode("点检计划导入模板", "UTF-8"); |
| | | response.setHeader("Content-Disposition", |
| | | "attachment;filename=" + fileName + ".xlsx"); |
| | | |
| | | // 读取模板文件 |
| | | ClassPathResource templateResource = new ClassPathResource("template/dj.xlsx"); |
| | | try (InputStream inputStream = templateResource.getInputStream(); |
| | | ServletOutputStream outputStream = response.getOutputStream()) { |
| | | |
| | | // 流拷贝 |
| | | byte[] buffer = new byte[1024]; |
| | | int bytesRead; |
| | | while ((bytesRead = inputStream.read(buffer)) != -1) { |
| | | outputStream.write(buffer, 0, bytesRead); |
| | | } |
| | | } catch (IOException e) { |
| | | throw new RuntimeException("模板文件读取失败", e); |
| | | } |
| | | } |
| | | } |