| | |
| | | |
| | | package org.springblade.mdm.program.controller; |
| | | |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import io.swagger.v3.oas.annotations.Operation; |
| | | import io.swagger.v3.oas.annotations.Parameter; |
| | | import io.swagger.v3.oas.annotations.tags.Tag; |
| | | import jakarta.servlet.http.HttpServletResponse; |
| | | 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.Func; |
| | | import org.springblade.core.tool.utils.UrlUtil; |
| | | import org.springblade.mdm.commons.service.ParamService; |
| | | 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.springframework.web.bind.annotation.PostMapping; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | import org.springblade.mdm.program.vo.NcProgramExportDncPageVO; |
| | | import org.springblade.mdm.program.vo.NcProgramExportDncQueryVO; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import java.io.ByteArrayOutputStream; |
| | | import java.io.IOException; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * 程序涉密网-工控网交换接口 |
| | |
| | | @RestController |
| | | @RequestMapping("/program/exchange") |
| | | @AllArgsConstructor |
| | | @Tag(name = "导出DNC", description = "涉密网沉痼导出DNC") |
| | | @Tag(name = "导出工控网", description = "涉密网程序导出给工控网") |
| | | @Slf4j |
| | | public class NcProgramExportDNCController { |
| | | |
| | | private final NcProgramService ncProgramService; |
| | | private final ParamService paramService; |
| | | private final NcProgramApprovedService ncProgramApprovedService; |
| | | private final NcProgramExportDNCService ncProgramExportDNCService; |
| | | @Operation(summary = "程序导出DNC分页查询", description = "分页查询,供用户选择数据") |
| | | @GetMapping("/export-dnc-page") |
| | | public R<IPage<NcProgramExportDncPageVO>> page(NcProgramExportDncQueryVO query) { |
| | | String userRole = AuthUtil.getUserRole();//角色别名,多个角色逗号分隔 |
| | | List<String> userRoleAliasList = Func.toStrList(",", userRole); |
| | | |
| | | String managerRole = paramService.getProgramManagerRoleAlias(); |
| | | if(!userRoleAliasList.contains(managerRole) && !AuthUtil.isAdministrator() && !AuthUtil.isAdmin()){ |
| | | //非数控管理员角色、管理员,限制未只能导出自己的程序 |
| | | query.setUserId(AuthUtil.getUserId()); |
| | | } |
| | | |
| | | return R.data(ncProgramApprovedService.exportDncPageQuery(query)); |
| | | } |
| | | |
| | | @PostMapping("/export-dnc") |
| | | @Operation(summary = "数控程序导出dnc", description = "数控程序导出到工控网") |
| | | public void exportDnc(Long nodeId, 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 { |
| | | //导出文件名称要求导出人名字+时间戳 |
| | | |
| | | //return R.<Boolean>status(true); |
| | | 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("无效参数格式") |
| | | );*/ |
| | | //} |
| | | |
| | | } |
| | | |
| | | |
| | | |
| | | } |