| | |
| | | import lombok.AllArgsConstructor; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springblade.core.log.exception.ServiceException; |
| | | import org.springblade.core.secure.utils.AuthUtil; |
| | | import org.springblade.core.tenant.annotation.NonDS; |
| | | import org.springblade.core.tool.api.R; |
| | | import org.springblade.core.tool.utils.DateUtil; |
| | | import org.springblade.core.tool.utils.UrlUtil; |
| | | import org.springblade.mdm.commons.vo.IdsVO; |
| | | import org.springblade.mdm.program.service.NcProgramApprovedService; |
| | | import org.springblade.mdm.program.service.NcProgramExportDNCService; |
| | | import org.springblade.mdm.program.service.NcProgramService; |
| | | import org.springblade.mdm.program.vo.NcNodeProgramQueryVO; |
| | | import org.springblade.mdm.program.vo.NcProgramExportDncPageVO; |
| | | import org.springblade.mdm.program.vo.NcProgramExportDncQueryVO; |
| | | import org.springblade.mdm.program.vo.NcProgramVO; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import java.io.ByteArrayOutputStream; |
| | | import java.io.IOException; |
| | | |
| | | /** |
| | |
| | | |
| | | @PostMapping("/export-dnc") |
| | | @Operation(summary = "数控程序导出dnc", description = "数控程序导出到工控网") |
| | | public void exportDnc(@RequestBody @Parameter(description = "审批表id数组") IdsVO vo, HttpServletResponse response) { |
| | | public void exportDnc(@RequestBody @Parameter(description = "审批表id数组") IdsVO vo, HttpServletResponse response) throws IOException { |
| | | if(vo.getIds() == null || vo.getIds().length == 0) { |
| | | throw new ServiceException("未选择文件导出"); |
| | | } |
| | | try { |
| | | String filename = "programexp-"+ DateUtil.format(DateUtil.now(), "yyyyMMddHHmm")+".zip"; |
| | | response.setHeader("Content-Disposition", "attachment; filename="+filename); |
| | | response.setContentType("application/octet-stream"); |
| | | ncProgramExportDNCService.exportDnc(vo.getIds(),response.getOutputStream()); |
| | | } catch (IOException e) { |
| | | log.error("导出DNC异常", e); |
| | | throw new RuntimeException(e); |
| | | } |
| | | //try { |
| | | //导出文件名称要求导出人名字+时间戳 |
| | | |
| | | String uname = UrlUtil.encode(AuthUtil.getNickName()); |
| | | //String filename =AuthUtil.getNickName()+"-"+ DateUtil.format(DateUtil.now(), "yyyyMMddHHmm")+".zip"; |
| | | String filename = uname+"-"+ DateUtil.format(DateUtil.now(), "yyyyMMddHHmm")+".zip"; |
| | | response.setHeader("Content-Disposition", "attachment; filename="+filename); |
| | | response.setContentType("application/octet-stream;charset=utf-8"); |
| | | |
| | | ByteArrayOutputStream bos = new ByteArrayOutputStream(); |
| | | ncProgramExportDNCService.exportDnc(vo.getIds(),bos); |
| | | response.getOutputStream().write(bos.toByteArray()); |
| | | |
| | | |
| | | //} catch (Exception e) { |
| | | //log.error("导出DNC异常", e); |
| | | /* |
| | | |
| | | throw new ResponseStatusException( |
| | | HttpStatus.NO_CONTENT, |
| | | "参数只能包含字母", |
| | | new IllegalArgumentException("无效参数格式") |
| | | );*/ |
| | | //} |
| | | |
| | | } |
| | | |