2 Angajamente 445a627db8 ... 771863c66d

Autor SHA1 Permisiunea de a trimite mesaje. Dacă este dezactivată, utilizatorul nu va putea trimite nici un fel de mesaj Data
  lisheng 771863c66d 报销工作台: 1 săptămână în urmă
  lisheng 1a664aa9b4 报销工作台: 1 săptămână în urmă

+ 47 - 14
code/jyyy/nckd-jimin-jyyy-fi/src/main/java/nckd/jimin/jyyy/fi/common/util/ReceiveTicketUtils.java

@@ -21,7 +21,9 @@ import kd.bos.servicehelper.PrintServiceHelper;
 import kd.bos.servicehelper.QueryServiceHelper;
 import kd.bos.svc.util.print.PrintFileUtil;
 import kd.bos.util.CollectionUtils;
+import kd.bos.util.ExceptionUtils;
 import kd.bos.web.actions.utils.FilePathUtil;
+import kd.tmc.bei.common.helper.ReceiptPrintHelper;
 import nckd.jimin.jyyy.fi.common.constant.BillTypeConstants;
 import nckd.jimin.jyyy.fi.common.constant.ErPrintSetConstant;
 import nckd.jimin.jyyy.fi.common.entity.MergePrintEntity;
@@ -36,8 +38,6 @@ import java.util.Map;
 import java.util.Set;
 import java.util.stream.Collectors;
 
-import static java.util.Comparator.comparing;
-
 public class ReceiveTicketUtils {
     private static Log logger = LogFactory.getLog(ReceiveTicketUtils.class);
 
@@ -223,22 +223,55 @@ public class ReceiveTicketUtils {
      */
     public static byte[] getElecReceiptPrintUrl(Object receiptId){
         List<Map<String, Object>> attachments = AttachmentServiceHelper.getAttachments(BillTypeConstants.BEI_ELECRECEIPT, receiptId, "attachmentpanel");
-        if(attachments.size() > 1){
-            throw new KDBizException("电子回单文件存在多个,请修复数据后再打印。");
-        }
-        Object relativeUrl = attachments.get(0).get("relativeUrl");
-        if (StringUtils.isNotBlank(relativeUrl)) {
-            try{
+        List<byte[]> resList = new ArrayList<>(10);
+        for (Map<String, Object> attachmentMap: attachments) {
+            if(attachmentMap.get("type") != null
+                    && ("pdf".equals(attachmentMap.get("type").toString()) || "jpg".equals(attachmentMap.get("type").toString()))) {
+
+                if(attachmentMap == null) {
+                    continue;
+                }
+
+                Object relativeUrl = attachmentMap.get("relativeUrl");
+                if (relativeUrl == null) {
+                    continue;
+                }
+
+                ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
                 String path = FilePathUtil.dealPath(relativeUrl.toString(), "attach");
                 InputStream inputStream = FileServiceFactory.getAttachmentFileService().getInputStream(path);
-                ByteArrayOutputStream  outputStream = new ByteArrayOutputStream();
-                return getBytes(inputStream,outputStream);
-            }catch (Exception e){
-                logger.error("getElecReceiptPrintUrl_getBytes_error",e);
-                throw new KDBizException("获取电子回单文件异常:" + e.getMessage());
+
+                if("jpg".equals(attachmentMap.get("type").toString())){
+                    ReceiptPrintHelper.imageConvertPdf(path, resList, inputStream);
+                    continue;
+                }
+
+                byte[] bytesAtt = null;
+                try {
+                    bytesAtt = getBytes(inputStream,outputStream);
+                } catch (IOException e) {
+                    throw new RuntimeException(e);
+                }
+                if(bytesAtt != null){
+                    resList.add(bytesAtt);
+                }
+            }
+        }
+        byte[] mergeMultiPdf = null;
+        if (!resList.isEmpty()) {
+            if (resList.size() > 1) {
+                try {
+                    mergeMultiPdf = ReceiptPrintHelper.mergeMultiPdf(resList);
+                } catch (Exception var5) {
+                    throw new KDBizException(ExceptionUtils.getExceptionStackTraceMessage(var5));
+                }
+            } else {
+                mergeMultiPdf = (byte[])resList.get(0);
             }
+        } else {
+            return null;
         }
-        return null;
+        return mergeMultiPdf;
     }
 
     public static byte[] getBytes(InputStream inputStream, ByteArrayOutputStream outputStream) throws IOException {

+ 10 - 41
code/jyyy/nckd-jimin-jyyy-fi/src/main/java/nckd/jimin/jyyy/fi/plugin/form/HandInReceiveTicketPlugin.java

@@ -59,6 +59,7 @@ import nckd.jimin.jyyy.fi.common.entity.MergePrintEntity;
 import nckd.jimin.jyyy.fi.common.util.ErFindRelationBillUtils;
 import nckd.jimin.jyyy.fi.common.util.ReceiveTicketUtils;
 
+import java.io.IOException;
 import java.util.*;
 import java.util.stream.Collectors;
 
@@ -403,51 +404,19 @@ public class HandInReceiveTicketPlugin extends AbstractFormPlugin implements Row
 
     protected void doViewElecReceipt(){
         DynamicObject selectRow = getSelectRows().get(0);
-
-        Map<String, Set<Object>> relationBelowBillMap = ErFindRelationBillUtils.getRelationBelowBillMap(selectRow.getString(HandInReceiveTicketConstant.SCANBILLENTRY.KEY_NCKD_BILLID),
-                selectRow.getString(HandInReceiveTicketConstant.SCANBILLENTRY.KEY_NCKD_FORMID));
-
-        if (!relationBelowBillMap.containsKey(BillTypeConstants.CAS_PAYBILL)
-                || CollectionUtils.isEmpty(relationBelowBillMap.get(BillTypeConstants.CAS_PAYBILL))) {
-            getView().showTipNotification("没有相应的电子回单!");
-            return;
-        }
-        Set<Object> casPayBillIdSet = relationBelowBillMap.get(BillTypeConstants.CAS_PAYBILL);
-        boolean isHasReceipt = false;
-        for (Object casPayBillId : casPayBillIdSet) {
-            Map<String, Object> fileMap = getElecreceiptByFile(casPayBillId.toString());
-            if (fileMap != null) {
-                isHasReceipt = true;
-                this.getView().previewAttachment(fileMap);
-            }
+        String pdfUrl = null;
+        try {
+            pdfUrl = FeiBillFileViewMultHelper.getElecreceiptByFile(selectRow.getString(HandInReceiveTicketConstant.SCANBILLENTRY.KEY_NCKD_BILLID));
+        } catch (IOException ex) {
+            throw new RuntimeException(ex);
         }
 
-        if(!isHasReceipt){
-            getView().showTipNotification("没有相应的电子回单!");
-            return;
+        if (kd.bos.util.StringUtils.isNotEmpty(pdfUrl)) {
+            FeiBillFileViewMultHelper.openForm(this.getView(), pdfUrl);
+        } else {
+            this.getView().showSuccessNotification("没有相应的电子回单!");
         }
 
-//        List<byte[]> mergeArray = new ArrayList<>();
-//        Set<Object> elecReceiptIdSet = relationBelowBillMap.get(BillTypeConstants.BEI_ELECRECEIPT);
-//        for(Object elecReceiptId : elecReceiptIdSet){
-//            byte[] bytes = ReceiveTicketUtils.getElecReceiptPrintUrl(elecReceiptId);
-//            mergeArray.add(bytes);
-//        }
-//
-//        byte[] bytes = PrintServiceHelper.mergeMultiPdf(mergeArray);//拼接文件流
-//
-//        String fileName = String.format("单据%s电子回单文件文件预览",selectRow.getString(HandInReceiveTicketConstant.SCANBILLENTRY.KEY_NCKD_NUMBER));
-//        TempFileCache tfc = CacheFactory.getCommonCacheFactory().getTempFileCache();
-//        // 设置临时文件有效时间
-//        String tempUrl = tfc.saveAsFullUrl(fileName + ".pdf", bytes, 60 * 60 * 2);//文件流生成临时文件
-//        String url = null;
-//        try {
-//            url = URLEncoder.encode(tempUrl, "UTF-8");
-//        } catch (UnsupportedEncodingException e) {
-//            e.printStackTrace();
-//        }
-//        String previewurl = UrlService.getAttachmentPreviewUrl(url);
-//        getView().openUrl(previewurl);
     }