|
@@ -0,0 +1,209 @@
|
|
|
+package nckd.jimin.jyyy.fi.plugin.form;
|
|
|
+
|
|
|
+import kd.bos.dataentity.entity.DynamicObject;
|
|
|
+import kd.bos.dataentity.entity.LocaleString;
|
|
|
+import kd.bos.dataentity.resource.ResManager;
|
|
|
+import kd.bos.entity.datamodel.ListSelectedRowCollection;
|
|
|
+import kd.bos.entity.operate.result.OperationResult;
|
|
|
+import kd.bos.exception.KDBizException;
|
|
|
+import kd.bos.fileservice.FileServiceFactory;
|
|
|
+import kd.bos.form.FormShowParameter;
|
|
|
+import kd.bos.form.IFormView;
|
|
|
+import kd.bos.form.ShowType;
|
|
|
+import kd.bos.form.events.AfterDoOperationEventArgs;
|
|
|
+import kd.bos.list.plugin.AbstractListPlugin;
|
|
|
+import kd.bos.logging.Log;
|
|
|
+import kd.bos.logging.LogFactory;
|
|
|
+import kd.bos.orm.query.QCP;
|
|
|
+import kd.bos.orm.query.QFilter;
|
|
|
+import kd.bos.servicehelper.AttachmentServiceHelper;
|
|
|
+import kd.bos.servicehelper.BusinessDataServiceHelper;
|
|
|
+import kd.bos.servicehelper.print.NotePrintService;
|
|
|
+import kd.bos.util.ExceptionUtils;
|
|
|
+import kd.bos.web.actions.utils.FilePathUtil;
|
|
|
+import kd.fi.cas.util.EmptyUtil;
|
|
|
+import kd.sdk.plugin.Plugin;
|
|
|
+import kd.tmc.bei.common.helper.ReceiptPrintHelper;
|
|
|
+import java.io.ByteArrayOutputStream;
|
|
|
+import java.io.IOException;
|
|
|
+import java.io.InputStream;
|
|
|
+import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 费用报销类单据联查电子回单批量
|
|
|
+ * @author wanghaiwu_kd
|
|
|
+ * @date 2025/08/27
|
|
|
+ */
|
|
|
+public class FeiBillFileViewMultListPlugin extends AbstractListPlugin implements Plugin {
|
|
|
+
|
|
|
+ private static final Log logger = LogFactory.getLog(FeiBillFileViewMultListPlugin.class);
|
|
|
+ @Override
|
|
|
+ public void afterDoOperation(AfterDoOperationEventArgs e) {
|
|
|
+ super.afterDoOperation(e);
|
|
|
+ String opKey = e.getOperateKey();
|
|
|
+
|
|
|
+ if ("nckd_multelecreceipt".equalsIgnoreCase(opKey)) {
|
|
|
+ ListSelectedRowCollection selectedRows = this.getSelectedRows();
|
|
|
+ Object selectId = selectedRows.get(0).getPrimaryKeyValue();
|
|
|
+
|
|
|
+ OperationResult operationResult = e.getOperationResult();
|
|
|
+ if (operationResult.isSuccess()) {
|
|
|
+ logger.info("-- 报销单联查电子回单附件开始 --");
|
|
|
+ if(EmptyUtil.isNoEmpty(selectId)){
|
|
|
+ String pdfUrl = null;
|
|
|
+ try {
|
|
|
+ pdfUrl = getElecreceiptByFile(selectId.toString());
|
|
|
+ } catch (IOException ex) {
|
|
|
+ throw new RuntimeException(ex);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (kd.bos.util.StringUtils.isNotEmpty(pdfUrl)) {
|
|
|
+ this.openForm(this.getView(), pdfUrl);
|
|
|
+ } else {
|
|
|
+ this.getView().showSuccessNotification("没有相应的电子回单!");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取电子回单ID
|
|
|
+ * 通过付款单ID获取交易明细ID,再通过交易明细ID获取电子回单ID
|
|
|
+ * @param payBillId
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public String getElecreceiptByFile(String payBillId) throws IOException {
|
|
|
+ Long billId = Long.parseLong(payBillId);
|
|
|
+ QFilter qFilter = new QFilter("sourcebillid", QCP.equals, billId);
|
|
|
+ qFilter.and(new QFilter("detailseqid", QCP.not_equals, " "));
|
|
|
+
|
|
|
+ //查询报销单的下游付款单
|
|
|
+ DynamicObject[] billDyns = BusinessDataServiceHelper.load("cas_paybill","id,detailseqid", qFilter.toArray());
|
|
|
+ if(EmptyUtil.isEmpty(billDyns)) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ List<String> transdetailIds = Arrays.stream(billDyns)
|
|
|
+ .map(dyn -> dyn.getString("detailseqid"))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ if(transdetailIds.size() == 0) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ qFilter = new QFilter("billno", QCP.in, transdetailIds);
|
|
|
+
|
|
|
+ //查询付款单的下游交易明细
|
|
|
+ DynamicObject[] transdetailDyns = BusinessDataServiceHelper.load("bei_transdetail","id,receiptno", qFilter.toArray());
|
|
|
+ if(EmptyUtil.isEmpty(transdetailDyns)) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ List<byte[]> resList = new ArrayList<>(10);
|
|
|
+
|
|
|
+ for(DynamicObject transdetail : transdetailDyns){
|
|
|
+ String elecreceiptNo = transdetail.getString("receiptno");
|
|
|
+ QFilter qf2 = new QFilter("receiptno", QCP.equals, elecreceiptNo);
|
|
|
+ DynamicObject elecreceiptDyn = BusinessDataServiceHelper.loadSingle("bei_elecreceipt", new QFilter[]{qf2});
|
|
|
+
|
|
|
+ if(EmptyUtil.isEmpty(elecreceiptDyn)) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ Map<String, Object> attachmentMap = getAttachmentFile(elecreceiptDyn.getLong("id"));
|
|
|
+
|
|
|
+ if(attachmentMap == null) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ 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);
|
|
|
+
|
|
|
+ byte[] bytesAtt = getBytes(inputStream,outputStream);
|
|
|
+ resList.add(bytesAtt);
|
|
|
+ }
|
|
|
+
|
|
|
+ if(resList.size() == 0){
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ String pdfUrl = null;
|
|
|
+
|
|
|
+ try {
|
|
|
+ pdfUrl = this.finlyOpenForm(resList);
|
|
|
+ } catch (Exception var27) {
|
|
|
+ logger.error("mergeMultiPdf Fail:", ExceptionUtils.getExceptionStackTraceMessage(var27));
|
|
|
+ }
|
|
|
+
|
|
|
+ return pdfUrl;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public static Map<String, Object> getAttachmentFile(Long billId) {
|
|
|
+
|
|
|
+ //创建一条基础资料数据-附件字段
|
|
|
+ //获取单据信息,并查询单据中的附件字段
|
|
|
+ QFilter qf = new QFilter("id", QCP.equals, billId);
|
|
|
+ DynamicObject file =BusinessDataServiceHelper.loadSingle("bei_elecreceipt", "attachmentpanel",new QFilter[]{qf});
|
|
|
+ //获取单据中附件面板信息
|
|
|
+ List<Map<String, Object>> atts = AttachmentServiceHelper.getAttachments("bei_elecreceipt", file.getPkValue().toString(), "attachmentpanel");
|
|
|
+ //遍历文件 电子回单只有一条
|
|
|
+ for (Map<String, Object> att: atts) {
|
|
|
+ return att;
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private byte[] getBytes(InputStream inputStream, ByteArrayOutputStream outputStream) throws IOException {
|
|
|
+ int b;
|
|
|
+ while ((b= inputStream.read())!=-1){
|
|
|
+ outputStream.write(b);
|
|
|
+ }
|
|
|
+ byte[] bytes1 = outputStream.toByteArray();
|
|
|
+ return bytes1;
|
|
|
+ }
|
|
|
+
|
|
|
+ private String finlyOpenForm(List<byte[]> resList) {
|
|
|
+ if (!resList.isEmpty()) {
|
|
|
+ byte[] mergeMultiPdf;
|
|
|
+ if (resList.size() > 1) {
|
|
|
+ try {
|
|
|
+ mergeMultiPdf = ReceiptPrintHelper.mergeMultiPdf(resList);
|
|
|
+ } catch (Exception var5) {
|
|
|
+ throw new KDBizException(ExceptionUtils.getExceptionStackTraceMessage(var5));
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ mergeMultiPdf = (byte[])resList.get(0);
|
|
|
+ }
|
|
|
+
|
|
|
+ NotePrintService notePrintService = new NotePrintService();
|
|
|
+ LocaleString localeString = new LocaleString("receipt");
|
|
|
+ return notePrintService.createPdfUrl(localeString, mergeMultiPdf);
|
|
|
+ } else {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void openForm(IFormView view, String pdfUrl) {
|
|
|
+ IFormView mainView = view.getMainView();
|
|
|
+ if (mainView == null) {
|
|
|
+ view.openUrl(pdfUrl);
|
|
|
+ } else {
|
|
|
+ FormShowParameter formShowParameter = new FormShowParameter();
|
|
|
+ formShowParameter.setFormId("bos_printpreview");
|
|
|
+ formShowParameter.getOpenStyle().setShowType(ShowType.MainNewTabPage);
|
|
|
+ formShowParameter.setCustomParam("src", pdfUrl);
|
|
|
+ formShowParameter.setCaption(ResManager.loadKDString("联查回单", "ElecReceiptQueryPlugin_1", "bos-ext-tmc", new Object[0]));
|
|
|
+ view.getParentView().showForm(formShowParameter);
|
|
|
+ view.sendFormAction(view.getParentView());
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+}
|