电子回单、电子对账单获取下载地址

This commit is contained in:
李贵强 2025-10-16 12:40:16 +08:00
parent 147f84bffd
commit 7366547b0b
2 changed files with 163 additions and 0 deletions

View File

@ -0,0 +1,68 @@
package shjh.jhzj7.fi.fi.plugin.task;
import kd.bos.context.RequestContext;
import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.dataentity.entity.DynamicObjectCollection;
import kd.bos.dataentity.utils.StringUtils;
import kd.bos.exception.KDException;
import kd.bos.ext.fi.bei.util.EmptyUtil;
import kd.bos.form.plugin.AbstractFormPlugin;
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.schedule.executor.AbstractTask;
import kd.bos.servicehelper.AttachmentServiceHelper;
import kd.bos.servicehelper.BusinessDataServiceHelper;
import kd.bos.servicehelper.QueryServiceHelper;
import kd.bos.servicehelper.operation.SaveServiceHelper;
import kd.bos.url.UrlService;
import kd.sdk.plugin.Plugin;
import kd.tmc.bei.common.helper.ReceiptPrintHelper;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* 动态表单插件
* 单子回单查询-定时获取回单url保存
*/
public class ElecReceiptUrlSaveTask extends AbstractTask implements Plugin {
private final static Log logger = LogFactory.getLog(ElecReceiptUrlSaveTask.class);
@Override
public void execute(RequestContext requestContext, Map<String, Object> map) throws KDException {
QFilter qFilter = new QFilter("ismatch", QCP.equals, true);
qFilter.and(new QFilter("shjh_url", QCP.equals, ""));
//qFilter.and(new QFilter("billno", QCP.equals, "EBB-250428-000571"));
DynamicObject[] load = BusinessDataServiceHelper.load("bei_elecreceipt", "id,billno,billstatus,ismatch,receiptno,shjh_url", qFilter.toArray());
if (load.length != 0) {
for (DynamicObject dynamicObject : load) {
Object pkValue = dynamicObject.getPkValue();
DynamicObjectCollection fileReceiptColl = QueryServiceHelper.query("bei_elecreceipt", "id,billno,fileflag,uploadfilename,username", new QFilter[]{new QFilter("id", "in", pkValue)});
List<String> FileBillList = (List) fileReceiptColl.stream().filter((e) -> {
return e.getBoolean("fileflag") && StringUtils.isNotBlank("uploadfilename");
}).map((e) -> {
return e.getString("uploadfilename");
}).collect(Collectors.toList());
if (!EmptyUtil.isEmpty(FileBillList)) {
Iterator var2 = FileBillList.iterator();
while (var2.hasNext()) {
String fileUrl = (String) var2.next();
//String realPath = ReceiptPrintHelper.getRealUploadUrl(fileUrl);
String downloadUrl = UrlService.getAttachmentDownloadUrl(fileUrl);
logger.info("电子回单下载URL:"+downloadUrl);
DynamicObject beiElecreceipt = BusinessDataServiceHelper.loadSingle(pkValue, "bei_elecreceipt");
beiElecreceipt.set("shjh_url", downloadUrl);
beiElecreceipt.set("shjh_url_tag", downloadUrl);
SaveServiceHelper.update(beiElecreceipt);
}
}
}
}
}
}

View File

@ -0,0 +1,95 @@
package shjh.jhzj7.fi.fi.plugin.task;
import kd.bos.context.RequestContext;
import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.dataentity.entity.DynamicObjectCollection;
import kd.bos.dataentity.entity.LocaleString;
import kd.bos.dataentity.utils.StringUtils;
import kd.bos.exception.KDException;
import kd.bos.ext.fi.bei.util.EmptyUtil;
import kd.bos.fileservice.FileService;
import kd.bos.fileservice.FileServiceFactory;
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.schedule.executor.AbstractTask;
import kd.bos.servicehelper.BusinessDataServiceHelper;
import kd.bos.servicehelper.PrintServiceHelper;
import kd.bos.servicehelper.operation.SaveServiceHelper;
import kd.bos.servicehelper.print.NotePrintService;
import kd.bos.url.UrlService;
import kd.bos.util.ExceptionUtils;
import kd.sdk.plugin.Plugin;
import kd.tmc.bei.common.helper.BeiHelper;
import kd.tmc.bei.common.helper.ReceiptPrintHelper;
import kd.tmc.fbp.common.ofd.OfdConvertUtil;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
/**
* 后台任务插件
* 电子对账单查询-获取回单地址保存在单据
*/
public class ElecStatementUrlSaveTask extends AbstractTask implements Plugin {
private final static Log logger = LogFactory.getLog(ElecStatementUrlSaveTask.class);
@Override
public void execute(RequestContext requestContext, Map<String, Object> map) throws KDException {
DynamicObject[] load = BusinessDataServiceHelper.load("bei_elecstatement", "id,billno,billstatus,isfile,shjh_url", new QFilter[]{new QFilter("billstatus", QCP.equals, "C")});
if (load.length != 0) {
ArrayList<Long> idList = new ArrayList<>();
for (DynamicObject bill : load) {
if (bill.getBoolean("isfile") && EmptyUtil.isEmpty(bill.getString("shjh_url"))) {
idList.add((Long) bill.getPkValue());
}
}
if (idList.size() != 0) {
Map<Object, DynamicObject> beiElecstatement = BusinessDataServiceHelper.loadFromCache(idList.toArray(), "bei_elecstatement");
// 处理每个单据
for (DynamicObject bill : beiElecstatement.values()) {
getPdfUrlFromFileBill(bill);
}
}
}
}
/**
* 从文件类型单据获取PDF URL
*/
private void getPdfUrlFromFileBill(DynamicObject bill) {
try {
DynamicObjectCollection urlEntry = bill.getDynamicObjectCollection("urlEntry");
if (!EmptyUtil.isEmpty(urlEntry)) {
for (DynamicObject urlInfo : urlEntry) {
String downloadUrl = getRealUploadUrl(urlInfo); // 需要实现这个方法
bill.set("shjh_url", downloadUrl);
bill.set("shjh_url_tag", downloadUrl);
SaveServiceHelper.update(bill);
}
}
} catch (Exception e) {
logger.error("处理文件类型PDF失败", e);
}
}
private String getRealUploadUrl(DynamicObject statement) {
String uploadFilName = statement.getString("e_fileservicepath");
String downloadUrl = UrlService.getAttachmentDownloadUrl(uploadFilName);
logger.info("获取文件下载路径:" +downloadUrl);
return downloadUrl;
}
}