| | |
| | | package com.example.erp.controller.pp; |
| | | |
| | | import org.springframework.core.io.InputStreamResource; |
| | | import com.example.erp.common.Constants; |
| | | import com.example.erp.common.Result; |
| | | import com.example.erp.entity.pp.LayoutsData; |
| | | import com.example.erp.entity.pp.OptimizeProjectMange; |
| | | import com.example.erp.exception.ServiceException; |
| | | import com.example.erp.service.pp.GlassOptimizeService; |
| | | import com.example.erp.service.pp.JsonToOptConverter; |
| | | import com.example.erp.service.userInfo.UserService; |
| | | import com.fasterxml.jackson.core.JsonProcessingException; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.http.HttpHeaders; |
| | | import org.springframework.http.HttpStatus; |
| | | import org.springframework.http.ResponseEntity; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import java.io.File; |
| | | import java.io.FileInputStream; |
| | | import java.io.IOException; |
| | | import java.nio.file.Path; |
| | | import java.nio.file.Paths; |
| | | import java.sql.Date; |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | | |
| | | @RestController |
| | | @Api(value="优化管理controller",tags={"优化管理操作接口"}) |
| | |
| | | public class GlassOptimizeController { |
| | | @Autowired |
| | | GlassOptimizeService glassOptimizeService; |
| | | @Autowired |
| | | private UserService userService; |
| | | //工程信息 |
| | | @ApiOperation("工程信息接口") |
| | | @PostMapping ("/projectInfo/{projectNo}/{username}") |
| | | public Result projectInfo( |
| | | @PathVariable String projectNo,@PathVariable String username){ |
| | | return Result.success(glassOptimizeService.projectInfoSv(projectNo,username)); |
| | | } |
| | | |
| | | |
| | | // 优化信息传入 |
| | | @ApiOperation("优化传入信息接口") |
| | | @PostMapping ("/optimizeInfo/{projectNo}/{username}") |
| | | public Result optimizeInfo(@PathVariable String projectNo,@PathVariable String username){ |
| | | return Result.success(glassOptimizeService.optimizeInfoSv(projectNo,username)); |
| | | } |
| | | |
| | | //工程信息流程卡 |
| | | @ApiOperation("工程信息流程卡接口") |
| | | @PostMapping ("/getProcessCard/{projectNo}") |
| | | public Result getProcessCard( |
| | | @PathVariable String projectNo){ |
| | | return Result.success(glassOptimizeService.getProcessCardSv(projectNo)); |
| | | } |
| | | |
| | | @ApiOperation("工程信息查询接口") |
| | | @PostMapping ("/getProjectState/{projectNo}") |
| | | public Result getProjectState( |
| | | @PathVariable String projectNo){ |
| | | return Result.success(glassOptimizeService.getProjectState(projectNo)); |
| | | } |
| | | |
| | | //库存信息 |
| | | @ApiOperation("库存信息接口") |
| | | @GetMapping ("/materialStore/{thickness}/{model}/{projectNumber}") |
| | | public Result materialStore( |
| | | @PathVariable String thickness, |
| | | @PathVariable String model,@PathVariable String projectNumber, |
| | | @RequestParam(name = "type", required = false) Integer type,@RequestParam(name = "username", required = false) String username ){ |
| | | return Result.success(glassOptimizeService.materialStoreSv(thickness,model,projectNumber,type,username)); |
| | | } |
| | | |
| | | |
| | | //工程查询流程卡 |
| | | @ApiOperation("创建工程查询流程卡接口") |
| | |
| | | public Result getFlowCardList( |
| | | @PathVariable String optionVal, |
| | | @PathVariable Integer radio){ |
| | | return Result.seccess(glassOptimizeService.getFlowCardList(optionVal,radio)); |
| | | return Result.success(glassOptimizeService.getFlowCardList(optionVal,radio)); |
| | | } |
| | | |
| | | //工程查询流程卡 |
| | | @ApiOperation("修改工程查询流程卡接口") |
| | | @PostMapping ("/getUpdateFlowCardList/{type}/{thickness}/{radio}/{projectNo}") |
| | | public Result getUpdateFlowCardList( |
| | | @PathVariable String type,@PathVariable String thickness, |
| | | @PathVariable Integer radio,@PathVariable String projectNo){ |
| | | return Result.success(glassOptimizeService.getUpdateFlowCardList(type,thickness,radio,projectNo)); |
| | | } |
| | | |
| | | //工程查询流程卡 |
| | | @ApiOperation("工程查询流程卡") |
| | | @PostMapping ("/getProjectList") |
| | | public Result getProjectList(){ |
| | | return Result.seccess(glassOptimizeService.getProjectListSv()); |
| | | return Result.success(glassOptimizeService.getProjectListSv()); |
| | | } |
| | | |
| | | @ApiOperation("根据工程卡号工程查询流程卡") |
| | | @PostMapping ("/getProjectByProjectNo/{projectNo}") |
| | | public Result getProjectByProjectNo( |
| | | @PathVariable String projectNo |
| | | ){ |
| | | return Result.success(glassOptimizeService.getProjectByProjectNoSv(projectNo)); |
| | | } |
| | | |
| | | |
| | | |
| | | //工程管理查询 |
| | | @ApiOperation("工程管理查询接口") |
| | |
| | | @PathVariable Date startSelectTime, |
| | | @PathVariable Date endSelectTime, |
| | | @RequestBody OptimizeProjectMange optimizeProjectMange) { |
| | | return Result.seccess(glassOptimizeService.OptimizeProjectMange(startSelectTime,endSelectTime,optimizeProjectMange)); |
| | | return Result.success(glassOptimizeService.OptimizeProjectMange(startSelectTime,endSelectTime,optimizeProjectMange)); |
| | | } |
| | | |
| | | //修改工程状态 |
| | | @ApiOperation("修改工程状态接口") |
| | | @PostMapping("/updateProjectState/{projectNumber}/{state}") |
| | | @PostMapping("/updateProjectState/{projectNumber}/{state}/{states}/{code}") |
| | | public Result updateProjectState( |
| | | @PathVariable String projectNumber, |
| | | @PathVariable Integer state |
| | | ) { |
| | | if (glassOptimizeService.updateProjectState(projectNumber, state)) { |
| | | return Result.seccess(); |
| | | } else { |
| | | throw new ServiceException(Constants.Code_500, "修改失败"); |
| | | |
| | | @PathVariable Integer state, |
| | | @PathVariable Integer states, |
| | | @PathVariable Integer code |
| | | ) throws JsonProcessingException { |
| | | try { |
| | | if (glassOptimizeService.updateProjectState(projectNumber, state, states, code)) { |
| | | return Result.success(); |
| | | } else { |
| | | throw new ServiceException(Constants.Code_500, "修改失败"); |
| | | } |
| | | } catch (Exception e) { |
| | | return Result.error("201", e.getMessage()); |
| | | } |
| | | } |
| | | |
| | |
| | | @PostMapping("/deleteProject/{projectNumber}") |
| | | public Result deleteProject( |
| | | @PathVariable String projectNumber){ |
| | | return Result.seccess(glassOptimizeService.deleteProject(projectNumber)); |
| | | return Result.success(glassOptimizeService.deleteProject(projectNumber,1)); |
| | | } |
| | | |
| | | //模拟计算工程号查询 |
| | | @ApiOperation("模拟计算工程号查询") |
| | | @PostMapping ("/selectProjectCompute/{projectNumber}") |
| | | public Result selectProjectCompute( |
| | | @PathVariable String projectNumber){ |
| | | return Result.success(glassOptimizeService.selectProjectComputeSv(projectNumber)); |
| | | } |
| | | |
| | | //模拟计算工程号查询 |
| | | @ApiOperation("模拟计算工程数据查询") |
| | | @PostMapping ("/selectProjectComputeAll/{projectNumber}") |
| | | public Result selectProjectComputeAll( |
| | | @PathVariable String projectNumber){ |
| | | return Result.success(glassOptimizeService.selectProjectComputeAll(projectNumber)); |
| | | } |
| | | |
| | | //模拟计算流程卡详情 |
| | | @ApiOperation("模拟计算流程卡详情") |
| | | @PostMapping ("/selectComputeDetail/{processId}/{technologyNumber}/{patchState}") |
| | | public Result selectComputeDetail( |
| | | @PathVariable String processId, @PathVariable Integer technologyNumber,@PathVariable String patchState){ |
| | | return Result.success(glassOptimizeService.selectComputeDetailSv(processId,technologyNumber,patchState)); |
| | | } |
| | | |
| | | @ApiOperation("模拟计算") |
| | | @PostMapping("/simulationCalculate") |
| | | public Result simulationCalculate(@RequestBody Map<String, Object> object) { |
| | | try { |
| | | return Result.success(glassOptimizeService.SimulationCalculation(object)); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | return Result.error(); |
| | | } |
| | | } |
| | | |
| | | @ApiOperation("模拟计算保存") |
| | | @PostMapping("/simulationSave") |
| | | public Result simulationSave(@RequestBody Map<String, Object> object) { |
| | | System.out.println("接收到的模拟计算保存数据: " + object); |
| | | try { |
| | | return Result.success(glassOptimizeService.addSimulation(object)); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | return Result.error(); |
| | | } |
| | | } |
| | | |
| | | @ApiOperation("优化设置保存") |
| | | @PostMapping("/optimizeParms/{username}") |
| | | public Result optimizeParmsSave(@RequestBody Map<String, Object> object,@PathVariable String username) { |
| | | try { |
| | | return Result.success(glassOptimizeService.optimizeParmsSave(object,username)); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | return Result.error(); |
| | | } |
| | | } |
| | | |
| | | |
| | | @PostMapping("/selectOptimizeParms/{username}") |
| | | public Result getOptimizeParms(@PathVariable String username) { |
| | | return Result.success(userService.getOptimizeParms(username)); |
| | | } |
| | | |
| | | |
| | | |
| | | @ApiOperation("模拟计算多流程卡") |
| | | @PostMapping("/selectComputeDetailmore") |
| | | public Result selectComputeDetailmore(@RequestBody Map<String, Object> object) { |
| | | try { |
| | | return Result.success(glassOptimizeService.SimulationCalculation(object)); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | return Result.error(); |
| | | } |
| | | } |
| | | |
| | | |
| | | @PostMapping("/calculate") |
| | | public ResponseEntity<Map<String, Object>> receiveOptimizeRequest( |
| | | @RequestBody Map<String, Object> requestData) { |
| | | |
| | | Map<String, Object> response = new HashMap<>(); |
| | | |
| | | try { |
| | | // 立即返回接收成功的响应 |
| | | response.put("code", "200"); |
| | | response.put("msg", "success"); |
| | | response.put("data", ""); |
| | | |
| | | // 异步处理计算任务 |
| | | // glassOptimizeService.processExternalOptimizeRequest(requestData); |
| | | System.out.println(requestData); |
| | | |
| | | return ResponseEntity.ok(response); |
| | | } catch (Exception e) { |
| | | response.put("code", 201); |
| | | response.put("msg", "false: " + e.getMessage()); |
| | | response.put("data", ""); |
| | | return ResponseEntity.status(500).body(response); |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | //创建工程查询流程卡明细 |
| | | @ApiOperation("创建工程查询流程卡明细") |
| | | @PostMapping ("/getProcessCardDetail/{processId}/{technologyNumber}") |
| | | public Result getProcessCardDetail( |
| | | @PathVariable String processId, |
| | | @PathVariable Integer technologyNumber){ |
| | | return Result.success(glassOptimizeService.getProcessCardDetailSv(processId,technologyNumber)); |
| | | } |
| | | |
| | | @ApiOperation("膜系查询") |
| | | @PostMapping ("/selectGlassType") |
| | | public Result selectGlassType(){ |
| | | return Result.success(glassOptimizeService.selectGlassTypeSv()); |
| | | } |
| | | |
| | | @ApiOperation("最新工程号查询") |
| | | @PostMapping ("/getProjectId") |
| | | public Result getProjectId(){ |
| | | return Result.success(glassOptimizeService.getProjectIdSv()); |
| | | } |
| | | @ApiOperation("创建工程接口") |
| | | @PostMapping("/addProject/{optionVal}/{projectId}/{projectNmae}") |
| | | public Result addProject( |
| | | @PathVariable String optionVal, |
| | | @PathVariable String projectId, |
| | | @PathVariable String projectNmae, |
| | | @RequestBody Map<String,Object> object){ |
| | | return Result.success(glassOptimizeService.addProjectSv(optionVal,projectId,projectNmae,object)); |
| | | } |
| | | |
| | | |
| | | @ApiOperation("保存优化结果接口") |
| | | @PostMapping("/saveOptimizeData/{projectId}") |
| | | public Result saveOptimizeResult( @PathVariable String projectId, |
| | | @RequestBody Map<String,Object> object){ |
| | | return Result.success(glassOptimizeService.saveOptimizeResult(object,projectId)); |
| | | } |
| | | |
| | | @ApiOperation("查询报告数据接口") |
| | | @PostMapping("/getReportData/{processId}") |
| | | public Result getReportData(@PathVariable String processId){ |
| | | return Result.success(glassOptimizeService.getReportDataSv(processId)); |
| | | } |
| | | |
| | | @ApiOperation("查询物料信息接口") |
| | | @PostMapping("/materialInfo/{processId}") |
| | | public Result materialInfo( |
| | | @PathVariable String processId){ |
| | | return Result.success(glassOptimizeService.getMaterialInfoSv(processId)); |
| | | } |
| | | |
| | | |
| | | @ApiOperation("查询产品列表接口") |
| | | @PostMapping("/getProductList/{processId}") |
| | | public Result getProductList( |
| | | @PathVariable String processId){ |
| | | return Result.success(glassOptimizeService.getProductListSv(processId)); |
| | | } |
| | | |
| | | @ApiOperation("查询优化结果接口") |
| | | @PostMapping("/selectOptimizeResult/{processId}") |
| | | public Result selectOptimizeResult( |
| | | @PathVariable String processId){ |
| | | return Result.success(glassOptimizeService.selectOptimizeResult(processId)); |
| | | } |
| | | |
| | | @ApiOperation("查询优化结果信息接口") |
| | | @PostMapping("/getOptimizeInfo/{processId}") |
| | | public Result getOptimizeInfo( |
| | | @PathVariable String processId){ |
| | | return Result.success(glassOptimizeService.getOptimizeInfoSv(processId)); |
| | | } |
| | | |
| | | @ApiOperation("更新优化结果接口") |
| | | @PostMapping("/updateOptimizeResult/{processId}") |
| | | public Result updateOptimizeResult( |
| | | @PathVariable String processId,@RequestBody Map<String,Object> object){ |
| | | |
| | | return Result.success(glassOptimizeService.updateOptimizeResult(object,processId)); |
| | | } |
| | | @ApiOperation("OPT文件下载接口") |
| | | @PostMapping("/generateOpt") |
| | | public ResponseEntity<byte[]> generateOptFile(@RequestBody LayoutsData layoutsData) throws IOException { |
| | | // 确保 layoutsData 包含 Layouts 数组 |
| | | if (layoutsData == null || layoutsData.getLayouts() == null) { |
| | | throw new IllegalArgumentException("Layouts 数据不能为空"); |
| | | } |
| | | |
| | | // 生成 OPT 文件内容 |
| | | String optContent = JsonToOptConverter.generateOptContent(layoutsData); |
| | | |
| | | // 创建响应头 |
| | | HttpHeaders headers = new HttpHeaders(); |
| | | headers.setContentType(org.springframework.http.MediaType.TEXT_PLAIN); |
| | | headers.setContentDispositionFormData("attachment", "output.opt"); |
| | | |
| | | // 返回文件内容 |
| | | return new ResponseEntity<>(optContent.getBytes(), headers, HttpStatus.OK); |
| | | } |
| | | |
| | | @PostMapping("/getConfiguration/{type}/{username}") |
| | | public Result getConfiguration(@PathVariable String type,@PathVariable String username) { |
| | | return Result.success(glassOptimizeService.getConfiguration(type,username)); |
| | | } |
| | | |
| | | @ApiOperation("修片磨量修改") |
| | | @PostMapping("/saveConfiguration/{type}/{username}") |
| | | public Result saveConfiguration(@PathVariable String type,@PathVariable String username, @RequestBody Map<String,Object> object){ |
| | | return Result.success(glassOptimizeService.saveConfiguration(object,type,username)); |
| | | } |
| | | |
| | | @ApiOperation("模拟排版") |
| | | @PostMapping("/simulatedTypesetting") |
| | | public Result simulatedTypesetting(@RequestBody Map<String, Object> object) { |
| | | return Result.success(glassOptimizeService.simulatedTypesetting1(object)); |
| | | } |
| | | |
| | | |
| | | @CrossOrigin(origins = "*") |
| | | @ApiOperation("PDF文件下载接口") |
| | | @GetMapping("/reports/pdf") |
| | | public ResponseEntity<InputStreamResource> downloadPdf(@RequestParam String filePath) { |
| | | try { |
| | | String decodedPath = java.net.URLDecoder.decode(filePath, "UTF-8"); |
| | | System.out.println("接收到的文件路径: " + decodedPath); |
| | | |
| | | // 放宽验证条件,仅检查必要条件 |
| | | if (decodedPath == null || decodedPath.trim().isEmpty()) { |
| | | System.out.println("文件路径为空"); |
| | | return ResponseEntity.badRequest().build(); |
| | | } |
| | | |
| | | // 检查是否为PDF文件(不严格检查开头) |
| | | if (!decodedPath.trim().toLowerCase().endsWith(".pdf")) { |
| | | System.out.println("文件不是PDF格式: " + decodedPath); |
| | | return ResponseEntity.badRequest().build(); |
| | | } |
| | | |
| | | // 处理路径,正确处理Windows网络路径 |
| | | String processedPath = decodedPath.trim(); |
| | | // 确保网络路径格式正确 |
| | | if (processedPath.startsWith("\\\\")) { |
| | | // 已经是正确的网络路径格式 |
| | | System.out.println("检测到Windows网络路径: " + processedPath); |
| | | } else if (processedPath.startsWith("\\")) { |
| | | // 补全网络路径 |
| | | processedPath = "\\" + processedPath; |
| | | System.out.println("补全网络路径为: " + processedPath); |
| | | } |
| | | |
| | | System.out.println("处理后的文件路径: " + processedPath); |
| | | |
| | | // 构造文件路径 |
| | | File file = new File(processedPath); |
| | | System.out.println("构造的文件绝对路径: " + file.getAbsolutePath()); |
| | | System.out.println("文件规范路径: " + file.getCanonicalPath()); |
| | | |
| | | // 检查文件是否存在 |
| | | if (!file.exists()) { |
| | | System.out.println("文件不存在: " + file.getAbsolutePath()); |
| | | return ResponseEntity.notFound().build(); |
| | | } |
| | | |
| | | // 检查是否为文件(而非目录) |
| | | if (!file.isFile()) { |
| | | System.out.println("路径不是文件: " + file.getAbsolutePath()); |
| | | return ResponseEntity.badRequest().build(); |
| | | } |
| | | |
| | | // 创建Resource |
| | | InputStreamResource resource = new InputStreamResource(new FileInputStream(file)); |
| | | |
| | | // 设置响应头 |
| | | HttpHeaders headers = new HttpHeaders(); |
| | | headers.add(HttpHeaders.CONTENT_DISPOSITION, "inline; filename=\"" + file.getName() + "\""); |
| | | headers.add(HttpHeaders.CONTENT_TYPE, "application/pdf"); |
| | | headers.add(HttpHeaders.CONTENT_LENGTH, String.valueOf(file.length())); |
| | | headers.add(HttpHeaders.ACCESS_CONTROL_EXPOSE_HEADERS, HttpHeaders.CONTENT_DISPOSITION); |
| | | |
| | | return ResponseEntity.ok() |
| | | .headers(headers) |
| | | .contentType(org.springframework.http.MediaType.APPLICATION_PDF) |
| | | .body(resource); |
| | | |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build(); |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | //模拟计算工程号查询第三方 |
| | | @ApiOperation("模拟计算工程号查询") |
| | | @PostMapping ("/selectProjectComputeMpThirdParty/{projectNumber}") |
| | | public Result selectProjectComputeMpThirdParty( @PathVariable String projectNumber){ |
| | | return Result.success(glassOptimizeService.selectProjectComputeMpThirdParty(projectNumber)); |
| | | } |
| | | |
| | | //模拟计算流程卡详情第三方 |
| | | @ApiOperation("模拟计算流程卡详情") |
| | | @PostMapping ("/selectComputeDetailThirdParty/{processId}/{technologyNumber}") |
| | | public Result selectComputeDetailThirdParty( |
| | | @PathVariable String processId, @PathVariable Integer technologyNumber){ |
| | | return Result.success(glassOptimizeService.selectComputeDetailThirdParty(processId,technologyNumber)); |
| | | } |
| | | |
| | | @ApiOperation("模拟计算保存") |
| | | @PostMapping("/simulationSaveThirdParty") |
| | | public Result simulationSaveThirdParty(@RequestBody Map<String, Object> object) { |
| | | try { |
| | | return Result.success(glassOptimizeService.simulationSaveThirdParty(object)); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | return Result.error(); |
| | | } |
| | | } |
| | | |
| | | //删除工程 |
| | | @ApiOperation("工程管理删除接口") |
| | | @PostMapping("/deleteProjectThirdParty/{projectNumber}") |
| | | public Result deleteProjectThirdParty( |
| | | @PathVariable String projectNumber){ |
| | | return Result.success(glassOptimizeService.deleteProjectThirdParty(projectNumber)); |
| | | } |
| | | |
| | | @ApiOperation("工程信息接口") |
| | | @PostMapping ("/projectInfoThirdParty/{projectNo}") |
| | | public Result projectInfoThirdParty( |
| | | @PathVariable String projectNo){ |
| | | return Result.success(glassOptimizeService.projectInfoThirdParty(projectNo)); |
| | | } |
| | | |
| | | //库存信息 |
| | | @ApiOperation("库存信息接口") |
| | | @GetMapping ("/materialStoreSvThirdParty/{projectNumber}") |
| | | public Result materialStoreSvThirdParty(@PathVariable String projectNumber ){ |
| | | return Result.success(glassOptimizeService.materialStoreSvThirdParty(projectNumber)); |
| | | } |
| | | |
| | | //工程信息流程卡 |
| | | @ApiOperation("工程信息流程卡接口") |
| | | @PostMapping ("/getProcessCardMpThirdParty/{projectNo}") |
| | | public Result getProcessCardMpThirdParty( |
| | | @PathVariable String projectNo){ |
| | | return Result.success(glassOptimizeService.getProcessCardMpThirdParty(projectNo)); |
| | | } |
| | | |
| | | @ApiOperation("mes工程任务下发接口") |
| | | @PostMapping("/getIssuingProjects") |
| | | public Result issuingProjects(@RequestBody String projectNo) throws JsonProcessingException { |
| | | return Result.success(glassOptimizeService.issuingProjects(projectNo)); |
| | | } |
| | | |
| | | |
| | | @ApiOperation("mes工程生产不可见接口") |
| | | @PostMapping("/issuingCancelProject") |
| | | public Result issuingCancelProject(@RequestBody String projectNo){ |
| | | return Result.success(glassOptimizeService.issuingCancelProject(projectNo)); |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | } |