From 49a88b2e87dc2c961b77068d440df65bd30e6874 Mon Sep 17 00:00:00 2001 From: liuzhaotian Date: Wed, 3 Jul 2024 11:44:58 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E7=94=9F=E4=BA=A7=E6=9D=83?= =?UTF-8?q?=E9=99=90=E4=BF=AE=E6=94=B9=EF=BC=8C=E6=96=B0=E5=A2=9E=E7=A9=BA?= =?UTF-8?q?=E5=B0=8F=E6=9D=BFBug=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/plan/OptimizePlanController.java | 19 ++--- .../admin/plan/vo/OrderGoodsResp.java | 2 +- .../executor/dal/mysql/plate/PlateMapper.java | 2 +- .../service/plan/PlanServiceImpl.java | 9 ++- .../service/plate/PlateServiceImpl.java | 4 +- .../resources/mapper/plate/PlateMapper.xml | 4 + .../admin/voice/VoiceController.java | 26 +++++-- .../manage/service/voice/VoiceService.java | 14 +++- .../service/voice/VoiceServiceImpl.java | 73 ++++++++++++++++++- 9 files changed, 129 insertions(+), 24 deletions(-) diff --git a/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/controller/admin/plan/OptimizePlanController.java b/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/controller/admin/plan/OptimizePlanController.java index a81799d41..75ae2aa88 100644 --- a/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/controller/admin/plan/OptimizePlanController.java +++ b/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/controller/admin/plan/OptimizePlanController.java @@ -36,7 +36,8 @@ public class OptimizePlanController { @GetMapping("/getPlateListByPlanId") @Operation(summary = "根据排单id获取板材列表") - @PreAuthorize("@ss.hasPermission('executor:optimize-plate:create')") +// @PreAuthorize("@ss.hasPermission('executor:optimize-plate:create')") + @PreAuthorize("@ss.hasPermission('placeorder:optimize')") public CommonResult> getPlateListByPlanId(@Schema(description = "排单id") @RequestParam("planId") Long planId) { return CommonResult.success(optimizePlanService.getPlateListByPlanId(planId)); } @@ -44,7 +45,7 @@ public class OptimizePlanController { @PostMapping("/addRemain") @Operation(summary = "添加余料板") - @PreAuthorize("@ss.hasPermission('executor:optimize-plate:create')") + @PreAuthorize("@ss.hasPermission('placeorder:optimize')") public CommonResult addRemain(@RequestBody @Valid AddRemainReqVO vo){ return CommonResult.success(optimizePlanService.addRemain(vo)); } @@ -52,35 +53,35 @@ public class OptimizePlanController { @PostMapping("savePlanPlateResult") @Operation(summary = "提交保存优化结果文件") @OperateLog(logArgs = false) - @PreAuthorize("@ss.hasPermission('executor:optimize-plate:create')") + @PreAuthorize("@ss.hasPermission('placeorder:optimize')") public CommonResult savePlanPlateResult(SavePlanPlateResult result) { return CommonResult.success(optimizePlanService.savePlanPlateResult(result)); } @GetMapping("commit") @Operation(summary = "开始开料") - @PreAuthorize("@ss.hasPermission('executor:optimize-plate:create')") + @PreAuthorize("@ss.hasPermission('placeorder:optimize')") public CommonResult commit(@RequestParam @Valid @NotNull(message = "排单id不能空") Long planId) { return CommonResult.success(optimizePlanService.commit(planId)); } @GetMapping("/endCutting") @Operation(summary = "结束开料") - @PreAuthorize("@ss.hasPermission('executor:optimize-plate:create')") + @PreAuthorize("@ss.hasPermission('placeorder:optimize')") public CommonResult endCutting(@RequestParam @Valid @NotNull(message = "排单id不能空") Long planId) { return success(optimizePlanService.endCutting(planId)); } @GetMapping("/getOptimizeParam") @Operation(summary = "获取优化算法参数") - @PreAuthorize("@ss.hasPermission('executor:optimize-plate:create')") + @PreAuthorize("@ss.hasPermission('placeorder:optimize')") public CommonResult getOptimizeParam(@RequestParam @Valid @NotNull(message = "排单id不能空") Long planId) { return CommonResult.success(optimizePlanService.getOptimizeParam(planId)); } @GetMapping("/getCfData") @Operation(summary = "获取cfData") - @PreAuthorize("@ss.hasPermission('executor:optimize-plate:create')") + @PreAuthorize("@ss.hasPermission('placeorder:optimize')") public CommonResult getCfData(@RequestParam @Valid @NotNull(message = "排单id不能空") Long planId) { //todo return CommonResult.success(null); @@ -100,7 +101,7 @@ public class OptimizePlanController { @GetMapping("/getOrderSource") @Operation(summary = "获取生产单源数据") - @PreAuthorize("@ss.hasPermission('production:manager-list:calculate')") + @PreAuthorize("@ss.hasPermission('placeorder:optimize')") public CommonResult getOrderSource(@Schema(description = "生产单id") @RequestParam(required = false) Long orderId, @Schema(description = "排单id") @RequestParam(required = false) Long planId, @Schema(description = "机台Id") @RequestParam("machineId") Long machineId @@ -112,7 +113,7 @@ public class OptimizePlanController { @GetMapping("/getLabelDataSourceValue") @Operation(summary = "获取标签数据源value") - @PreAuthorize("@ss.hasPermission('executor:optimize-plate:create')") + @PreAuthorize("@ss.hasPermission('placeorder:optimize')") public CommonResult> getLabelDataSourceValue(@Valid GetSourceDataReq req ) { return CommonResult.success( optimizePlanService.getLabelDataSourceValue(req)); diff --git a/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/controller/admin/plan/vo/OrderGoodsResp.java b/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/controller/admin/plan/vo/OrderGoodsResp.java index 64e4c1809..f7fbea228 100644 --- a/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/controller/admin/plan/vo/OrderGoodsResp.java +++ b/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/controller/admin/plan/vo/OrderGoodsResp.java @@ -36,7 +36,7 @@ public class OrderGoodsResp { private BigDecimal area; @Schema(description = "板件数量") - private Long num; + private int num; @Schema(description = "生产单信息") diff --git a/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/dal/mysql/plate/PlateMapper.java b/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/dal/mysql/plate/PlateMapper.java index 06dbd7ee0..0756362e1 100644 --- a/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/dal/mysql/plate/PlateMapper.java +++ b/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/dal/mysql/plate/PlateMapper.java @@ -127,7 +127,7 @@ public interface PlateMapper extends BaseMapperX { List selectGoodsPage( @Param("orderIds") List orderIds, @Param("organId") Long organId); - IPage selectGoodsList(@Param("page") IPage page,@Param("pageReqVO") OrderPageReqVOCopy pageReqVO,@Param("organId") Long organId); + IPage selectGoodsList(@Param("page") IPage page,@Param("goodsIds") List goodsIds,@Param("organId") Long organId); List selectOrderIds(@Param("orderIds") List orderIds,@Param("organId") Long organId); diff --git a/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/service/plan/PlanServiceImpl.java b/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/service/plan/PlanServiceImpl.java index 7ed3a28b2..9489b0064 100644 --- a/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/service/plan/PlanServiceImpl.java +++ b/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/service/plan/PlanServiceImpl.java @@ -391,7 +391,7 @@ public class PlanServiceImpl implements PlanService { public PageResult getOrderGoodsPage(OrderPageReqVOCopy pageReqVO) { - PageDTO page = new PageDTO<>(pageReqVO.getPageNo(), pageReqVO.getPageSize()); + PageDTO page = new PageDTO<>(pageReqVO.getPageNo(), pageReqVO.getPageSize()); QueryWrapperX queryWrapperX = new QueryWrapperX<>(); queryWrapperX @@ -440,6 +440,13 @@ public class PlanServiceImpl implements PlanService { for (OrderGoodsResp record : orderGoodsResps.getRecords()) { + record.setNum(orderRespVOCopies.stream().filter(e-> Objects.equals(e.getGoodsId(), record.getGoodsId())). + mapToInt(OrderRespVOCopy::getNum).sum()); + + record.setArea(orderRespVOCopies.stream().filter(e-> Objects.equals(e.getGoodsId(), record.getGoodsId())) + .map(OrderRespVOCopy::getArea) + .reduce(BigDecimal.ZERO,BigDecimal::add)); + record.setOrderIds(orderIdsList.stream().filter(e -> Objects.equals(e.getGoodsId(), record.getGoodsId())).collect(Collectors.toList())); record.setOrderList(orderRespVOCopies.stream().filter(e -> Objects.equals(e.getGoodsId(), record.getGoodsId())).collect(Collectors.toList())); } diff --git a/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/service/plate/PlateServiceImpl.java b/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/service/plate/PlateServiceImpl.java index 925c1c793..48b76a547 100644 --- a/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/service/plate/PlateServiceImpl.java +++ b/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/service/plate/PlateServiceImpl.java @@ -266,9 +266,7 @@ public class PlateServiceImpl implements PlateService { plateDO.setRemark(reqVO.getRemake1() +","+ reqVO.getRemake2()); - Long goodsId = goodsMapper.selectId(reqVO.getOrderId(), reqVO.getGoodsId(), getUserOrganId()).getId(); - - plateDO.setGoodsId(goodsId); + plateDO.setGoodsId(reqVO.getGoodsId()); plateDO.setPlateNo((obtainingTime) + Long.toString(plateNo).substring(2)); diff --git a/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/resources/mapper/plate/PlateMapper.xml b/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/resources/mapper/plate/PlateMapper.xml index 92dd8b47e..6b04f5845 100644 --- a/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/resources/mapper/plate/PlateMapper.xml +++ b/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/resources/mapper/plate/PlateMapper.xml @@ -408,6 +408,10 @@ and b.status = 2 and a.deleted = false and opi.item_id is null + and c.goods_id in + + #{goodsIds} + group by c.goods_id,c.id,b.id ,c.goods_name,c.width,c.height,c.thickness, c.material, c.color; diff --git a/cf-module-prod-manage/cf-module-prod-manage-biz/src/main/java/com/cf/imes/module/manage/controller/admin/voice/VoiceController.java b/cf-module-prod-manage/cf-module-prod-manage-biz/src/main/java/com/cf/imes/module/manage/controller/admin/voice/VoiceController.java index 826be6071..af78ae521 100644 --- a/cf-module-prod-manage/cf-module-prod-manage-biz/src/main/java/com/cf/imes/module/manage/controller/admin/voice/VoiceController.java +++ b/cf-module-prod-manage/cf-module-prod-manage-biz/src/main/java/com/cf/imes/module/manage/controller/admin/voice/VoiceController.java @@ -4,8 +4,12 @@ package com.cf.imes.module.manage.controller.admin.voice; import com.cf.imes.framework.common.pojo.CommonResult; import com.cf.imes.module.manage.controller.admin.voice.vo.VoiceReqVO; import com.cf.imes.module.manage.service.voice.VoiceService; +import com.jacob.com.Dispatch; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; +import org.springframework.core.io.ByteArrayResource; +import org.springframework.core.io.InputStreamResource; +import org.springframework.http.ResponseEntity; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; @@ -15,6 +19,8 @@ import javax.validation.Valid; import org.springframework.web.bind.annotation.RestController; +import java.io.ByteArrayInputStream; +import java.sql.Blob; @Tag(name = "管理后台 - 语音播报") @@ -31,19 +37,29 @@ public class VoiceController { @PostMapping() @Operation(summary = "语音播报") @PreAuthorize("@ss.hasPermission('manage:voice:insert')") - public CommonResult voiceAnnouncements(@Valid @RequestBody VoiceReqVO reqVO ) throws Exception { + public CommonResult> voiceAnnouncements(@Valid @RequestBody VoiceReqVO reqVO ) throws Exception { + String sourceFile = voiceService.voiceAnnouncements(reqVO.getData()); - String gzipFile = sourceFile+".zip"; - // 压缩语音文件 - voiceService.zipFiles(sourceFile, gzipFile); + ResponseEntity voice = voiceService.getVoice(sourceFile); + // 删除生成的 mp3 文件 voiceService.deleteFiles(sourceFile); - return CommonResult.success(gzipFile); + + return CommonResult.success(voice); + +// String gzipFile = sourceFile+".zip"; +// +// // 压缩语音文件 +// voiceService.zipFiles(sourceFile, gzipFile); +// + + + } diff --git a/cf-module-prod-manage/cf-module-prod-manage-biz/src/main/java/com/cf/imes/module/manage/service/voice/VoiceService.java b/cf-module-prod-manage/cf-module-prod-manage-biz/src/main/java/com/cf/imes/module/manage/service/voice/VoiceService.java index a5b73ebc8..d8e0c777f 100644 --- a/cf-module-prod-manage/cf-module-prod-manage-biz/src/main/java/com/cf/imes/module/manage/service/voice/VoiceService.java +++ b/cf-module-prod-manage/cf-module-prod-manage-biz/src/main/java/com/cf/imes/module/manage/service/voice/VoiceService.java @@ -1,17 +1,29 @@ package com.cf.imes.module.manage.service.voice; +import com.jacob.com.Dispatch; +import org.springframework.core.io.ByteArrayResource; +import org.springframework.core.io.InputStreamResource; +import org.springframework.http.ResponseEntity; + +import java.io.ByteArrayInputStream; import java.io.IOException; +import java.sql.Blob; +import java.sql.SQLException; public interface VoiceService { // 生成音频文件 - String voiceAnnouncements(String data); + + String voiceAnnouncements(String data) throws IOException, SQLException; // 把生成的音频文件进行压缩 void zipFiles(String sourceFile, String gzipFile) throws IOException; void deleteFiles(String sourceFile); + + ResponseEntity getVoice(String sourceFile); + } diff --git a/cf-module-prod-manage/cf-module-prod-manage-biz/src/main/java/com/cf/imes/module/manage/service/voice/VoiceServiceImpl.java b/cf-module-prod-manage/cf-module-prod-manage-biz/src/main/java/com/cf/imes/module/manage/service/voice/VoiceServiceImpl.java index f413d260a..6c109959e 100644 --- a/cf-module-prod-manage/cf-module-prod-manage-biz/src/main/java/com/cf/imes/module/manage/service/voice/VoiceServiceImpl.java +++ b/cf-module-prod-manage/cf-module-prod-manage-biz/src/main/java/com/cf/imes/module/manage/service/voice/VoiceServiceImpl.java @@ -3,16 +3,36 @@ package com.cf.imes.module.manage.service.voice; import com.cf.imes.module.manage.config.VocieParameters; import com.jacob.activeX.ActiveXComponent; -import com.jacob.com.ComThread; import com.jacob.com.Dispatch; import com.jacob.com.Variant; import lombok.extern.slf4j.Slf4j; +import org.springframework.core.io.ByteArrayResource; +import org.springframework.core.io.InputStreamResource; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Service; import javax.annotation.Resource; -import javax.servlet.http.HttpServletResponse; import java.io.*; +import org.springframework.http.HttpHeaders; +import org.springframework.http.MediaType; +import com.jacob.activeX.ActiveXComponent; +import com.jacob.com.Dispatch; +import com.jacob.com.Variant; +import javax.sql.rowset.serial.SerialBlob; +import java.io.BufferedReader; +import java.io.FileReader; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.sql.Blob; +import java.sql.SQLException; +import java.util.Objects; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; import java.net.http.WebSocket; import java.nio.ByteBuffer; import java.nio.channels.Channels; @@ -23,6 +43,8 @@ import java.util.Random; import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; +import static org.aspectj.weaver.tools.cache.SimpleCacheFactory.path; + @Service @Slf4j public class VoiceServiceImpl implements VoiceService{ @@ -31,11 +53,13 @@ public class VoiceServiceImpl implements VoiceService{ private VocieParameters vocieParameters; + + // static { // System.loadLibrary("jacob-1.18-x64"); // } - // 生成音频文件 + //生成音频文件 @Override public String voiceAnnouncements(String data) { @@ -106,6 +130,48 @@ public class VoiceServiceImpl implements VoiceService{ + + + @Override + public ResponseEntity getVoice( String fileName) { + try { + File audioFile = new File(fileName); + if (!audioFile.exists()) { + return ResponseEntity.status(HttpStatus.NOT_FOUND).body(null); + } + + // 读取文件到字节数组 + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + try (FileInputStream fileInputStream = new FileInputStream(audioFile)) { + byte[] buffer = new byte[1024]; + int bytesRead; + while ((bytesRead = fileInputStream.read(buffer)) != -1) { + byteArrayOutputStream.write(buffer, 0, bytesRead); + } + } + + byte[] audioBytes = byteArrayOutputStream.toByteArray(); + ByteArrayResource byteArrayResource = new ByteArrayResource(audioBytes); + + HttpHeaders headers = new HttpHeaders(); + headers.setContentType(MediaType.parseMediaType("audio/mpeg")); + headers.setContentLength(audioBytes.length); + headers.setCacheControl("must-revalidate, post-check=0, pre-check=0"); + + return new ResponseEntity<>(audioBytes, headers, HttpStatus.OK); + + } catch (IOException e) { + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null); + } + } + + + + + + + + /** * 把生成的音频文件进行压缩 * @param fileNames 需要压缩的文件名称列表(包含相对路径) @@ -175,4 +241,5 @@ public class VoiceServiceImpl implements VoiceService{ } + }