From c6f7d5dd4858a8f5ee76f7625e813432cd46bcfb Mon Sep 17 00:00:00 2001 From: zhouc Date: Sat, 26 Oct 2024 19:40:58 +0800 Subject: [PATCH] =?UTF-8?q?1.=E5=86=85=E5=AE=A1=E9=A2=84=E7=AE=97=E5=8D=95?= =?UTF-8?q?=E9=99=84=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../intauditbusa/op/InAuditWithdrawalOp.java | 8 +- .../intauditbusa/op/IntAuditBuSaAuditOp.java | 604 +++++------------- 2 files changed, 150 insertions(+), 462 deletions(-) diff --git a/src/main/java/com/yem/wm/im/intauditbusa/op/InAuditWithdrawalOp.java b/src/main/java/com/yem/wm/im/intauditbusa/op/InAuditWithdrawalOp.java index 2a2fe050..bb06f50d 100644 --- a/src/main/java/com/yem/wm/im/intauditbusa/op/InAuditWithdrawalOp.java +++ b/src/main/java/com/yem/wm/im/intauditbusa/op/InAuditWithdrawalOp.java @@ -1,5 +1,6 @@ package com.yem.wm.im.intauditbusa.op; +import com.yem.wm.utils.DynamicObjectUtil; import kd.bos.dataentity.entity.DynamicObject; import kd.bos.entity.plugin.AbstractOperationServicePlugIn; import kd.bos.entity.plugin.args.EndOperationTransactionArgs; @@ -41,12 +42,7 @@ public class InAuditWithdrawalOp extends AbstractOperationServicePlugIn { } } if (bool) { - String object = (String) map.get("uid"); - String yemSourcebillid = dataEntitie.getString("yem_sourcebillid"); - AttachmentServiceHelper.remove("yem_es_salesorder", dataEntitie.getLong("yem_sourcebillid"), map.get("uid")); - DeleteServiceHelper.delete("bos_attachment", new QFilter[]{new QFilter("fnumber", QCP.equals, object) - , new QFilter("finterid", QCP.equals, yemSourcebillid) - , new QFilter("fentrykey", QCP.equals, "yem_es_salesorder")}); + DeleteServiceHelper.delete("bos_attachment", new QFilter[]{new QFilter("id", QCP.equals, map.get("attPkId"))}); } } } diff --git a/src/main/java/com/yem/wm/im/intauditbusa/op/IntAuditBuSaAuditOp.java b/src/main/java/com/yem/wm/im/intauditbusa/op/IntAuditBuSaAuditOp.java index 79d06db2..3a906fde 100644 --- a/src/main/java/com/yem/wm/im/intauditbusa/op/IntAuditBuSaAuditOp.java +++ b/src/main/java/com/yem/wm/im/intauditbusa/op/IntAuditBuSaAuditOp.java @@ -3,16 +3,20 @@ package com.yem.wm.im.intauditbusa.op; import com.yem.wm.utils.DynamicObjectUtil; import com.yem.wm.utils.FunctionalCommon; import com.yem.wm.utils.YEM; +import kd.bos.cache.CacheFactory; +import kd.bos.cache.TempFileCache; import kd.bos.context.RequestContext; import kd.bos.dataentity.entity.DynamicObject; import kd.bos.dataentity.entity.DynamicObjectCollection; import kd.bos.entity.plugin.AbstractOperationServicePlugIn; import kd.bos.entity.plugin.PreparePropertysEventArgs; import kd.bos.entity.plugin.args.EndOperationTransactionArgs; +import kd.bos.exception.KDBizException; import kd.bos.exception.KDException; import kd.bos.fileservice.FileItem; import kd.bos.fileservice.FileService; import kd.bos.fileservice.FileServiceFactory; +import kd.bos.orm.ORM; import kd.bos.orm.query.QCP; import kd.bos.orm.query.QFilter; import kd.bos.print.api.PrintTask; @@ -23,7 +27,13 @@ import kd.bos.servicehelper.AttDto; import kd.bos.servicehelper.AttachmentServiceHelper; import kd.bos.servicehelper.BusinessDataServiceHelper; import kd.bos.servicehelper.operation.SaveServiceHelper; +import kd.bos.servicehelper.user.UserConfigServiceHelper; +import kd.bos.url.UrlService; +import kd.bos.util.FileNameUtils; import kd.sdk.plugin.Plugin; +import com.alibaba.fastjson.JSONObject; +import kd.bos.dataentity.serialization.SerializationUtils; + import java.io.ByteArrayOutputStream; import java.io.IOException; @@ -42,8 +52,7 @@ public class IntAuditBuSaAuditOp extends AbstractOperationServicePlugIn implemen DynamicObject[] dataEntities = e.getDataEntities(); for (DynamicObject dataEntitie : dataEntities) { dataEntitie = BusinessDataServiceHelper.loadSingle(dataEntitie.getPkValue(), dataEntitie.getDynamicObjectType().getName()); -// writeBackSumCost(dataEntitie); - createPdf(dataEntitie); + printdata(dataEntitie,"attachmentpanel"); } } @@ -53,474 +62,157 @@ public class IntAuditBuSaAuditOp extends AbstractOperationServicePlugIn implemen } /** - * @description 反写金额系列字段 - * @author xwudd - * @param[1] dataEntitie - * return - * @time 2023/10/30 9:18 + * 生成附件 + * @param dataEntity + * @param attachmentKey */ - public void writeBackSumCost(DynamicObject dataEntitie) { - DynamicObject billType = dataEntitie.getDynamicObject("yem_billtype"); - if (YEM.isNotEmpty(billType)) { - String number = billType.getString("number"); - if ("yem_im_intauditbusa_ZJWX".equals(number)) { - String sourceBillType = dataEntitie.getString("yem_sourcebilltype"); - Long sourceBillId = dataEntitie.getLong("yem_sourcebillid"); - Long sourceEntryId = dataEntitie.getLong("yem_sourceentryid"); - DynamicObject entity = BusinessDataServiceHelper.loadSingle(sourceBillId, sourceBillType); - if (YEM.isNotEmpty(entity)) { - String name = entity.getDynamicObjectType().getName(); - DynamicObjectCollection entrys = null; - if ("yem_es_salesorder".equals(name)) { - entrys = entity.getDynamicObjectCollection("yem_es_materialinfo"); - } - if ("yem_im_clientdemand".equals(name)) { - entrys = entity.getDynamicObjectCollection("yem_im_detailedinfor"); - } - BigDecimal commissionAmtTotal = BigDecimal.ZERO; - BigDecimal commissionAmtBaTotal = BigDecimal.ZERO; - BigDecimal commissionAmt = (BigDecimal) dataEntitie.get("yem_commissionamt"); - BigDecimal commissionAmtBa = (BigDecimal) dataEntitie.get("yem_commissionamtba"); - commissionAmtTotal = commissionAmtTotal.add(commissionAmt); - commissionAmtBaTotal = commissionAmtBaTotal.add(commissionAmtBa); - if (YEM.isNotEmpty(entrys)) { - BigDecimal amtPriceClause = BigDecimal.ZERO; - BigDecimal amtPriceClauseBase = BigDecimal.ZERO; - for (DynamicObject entry : entrys) { - long entryId = entry.getLong("id"); - if (sourceEntryId == entryId) { - BigDecimal disAmt = entry.getBigDecimal("yem_disamt"); - BigDecimal saFobPrice = entry.getBigDecimal("yem_safobprice");//销售fob单价 - BigDecimal exrate = entity.getBigDecimal("yem_exrate");//汇率 - BigDecimal qty = entry.getBigDecimal("yem_qty");//数量 - BigDecimal priceFieldAccBa = entry.getBigDecimal("yem_pricefieldaccba");//资源配置单价 - BigDecimal sumCost = (BigDecimal) dataEntitie.get("yem_sumcost"); - BigDecimal sumCostBase = (BigDecimal) dataEntitie.get("yem_sumcostbase"); - BigDecimal saPricePriceClause = BigDecimal.ZERO; - if(disAmt.compareTo(BigDecimal.ZERO) > 0){ - BigDecimal afterFrontDisPrice = entity.getBigDecimal("yem_afterfrontdisprice"); - saPricePriceClause = afterFrontDisPrice.add(priceFieldAccBa).add(sumCost); - }else{ - saPricePriceClause = saFobPrice.add(priceFieldAccBa).add(sumCost); - } - BigDecimal frontDisPrice = sumCost.add(saFobPrice); - BigDecimal frontDisAmt = frontDisPrice.multiply(qty); - BigDecimal saaAmtPriceClause = saPricePriceClause.multiply(qty); - BigDecimal saaAmtPriceClauseBase = saaAmtPriceClause.multiply(exrate); - amtPriceClause = amtPriceClause.add(saaAmtPriceClause); - amtPriceClauseBase = amtPriceClauseBase.add(saaAmtPriceClauseBase); + public static void printdata(DynamicObject dataEntity, String attachmentKey) { + Object pkId = dataEntity.getPkValue(); + if (YEM.isEmpty(pkId)) { + throw new KDBizException("请先保存单据。"); + } + String entityId = dataEntity.getDataEntityType().getName(); + String formId = dataEntity.getDataEntityType().getName(); + String yem_billtype = dataEntity.getString("yem_billtype.number"); - entry.set("yem_onecarsum", sumCost);//单车总费用 - entry.set("yem_onecarsumbase", sumCostBase);//单车总费用(人民币) - entry.set("yem_sapricepriceclause", saPricePriceClause);//销售单价(价格条款) - entry.set("yem_sapriceclausebase", saPricePriceClause.multiply(exrate));//销售单价(价格条款人民币) - entry.set("yem_saamtpriceclause", saaAmtPriceClause);//销售金额(价格条款) - entry.set("yem_samtpriceclauseba", saaAmtPriceClauseBase);//销售金额(价格条款人民币) - entry.set("yem_truecarprice", saFobPrice.add(sumCost));//实际整车单价 - entry.set("yem_truecaramt", (saFobPrice.add(sumCost)).multiply(qty));//实际整车金额 - entry.set("yem_truecarpriceba", (saFobPrice.add(sumCost)).multiply(exrate));//实际整车单价人民币 - entry.set("yem_truecaramtba", (saFobPrice.add(sumCost)).multiply(qty).multiply(exrate));//实际整车金额人民币 -// entry.set("yem_commissionamten",commissionAmt);// -// entry.set("yem_commissionamtbaen",commissionAmtBa);// - entry.set("yem_frontdisprice", frontDisPrice);//折扣前销售单价 - entry.set("yem_frontdisamt", frontDisAmt);//折扣前销售金额 - entry.set("yem_totalamount", sumCost.multiply(entry.getBigDecimal("yem_qty")));//总费用 - entry.set("yem_totalamountrmb", sumCostBase.multiply(entry.getBigDecimal("yem_qty")));//总费用(人民币) - } else { - amtPriceClause = amtPriceClause.add(entry.getBigDecimal("yem_saamtpriceclause")); - amtPriceClauseBase = amtPriceClauseBase.add(entry.getBigDecimal("yem_samtpriceclauseba")); - BigDecimal commissionAmtEn = entry.getBigDecimal("yem_commissionamten"); - BigDecimal commissionAmtBaEn = entry.getBigDecimal("yem_commissionamtbaen"); - commissionAmtTotal = commissionAmtTotal.add(commissionAmtEn); - commissionAmtBaTotal = commissionAmtBaTotal.add(commissionAmtBaEn); - } - } - BigDecimal oneCarSum = BigDecimal.ZERO; - BigDecimal oneCarBaseSum = BigDecimal.ZERO; - for (DynamicObject entry : entrys) { - BigDecimal qty = entry.getBigDecimal("yem_qty"); - BigDecimal oneCar = entry.getBigDecimal("yem_onecarsum"); - BigDecimal oneCarBase = entry.getBigDecimal("yem_onecarsumbase"); - oneCarSum = oneCarSum.add(qty.multiply(oneCar)); - oneCarBaseSum = oneCarBaseSum.add(qty.multiply(oneCarBase)); - } - entity.set("yem_sumcost", oneCarSum); - entity.set("yem_sumcostbase", oneCarBaseSum); - entity.set("yem_offeramount", amtPriceClause); - entity.set("yem_offerstandardcoin", amtPriceClauseBase); - DynamicObject recCondition = entity.getDynamicObject("yem_reccondition"); - if(YEM.isNotEmpty(recCondition)){ - String basis = recCondition.getString("basis"); - if("A".equals(basis)){ - DynamicObjectCollection salesContraC_ss = null; - if(sourceBillType.equals("yem_im_clientdemand")){ - salesContraC_ss = entity.getDynamicObjectCollection("yem_salescontrac_s"); - }else{ - salesContraC_ss = entity.getDynamicObjectCollection("yem_es_salescontrac_s"); - } - for(DynamicObject salesContraC_s : salesContraC_ss){ - BigDecimal rapRate = salesContraC_s.getBigDecimal("yem_raprate"); - salesContraC_s.set("yem_rapamt",rapRate.divide(new BigDecimal(100)).multiply(amtPriceClause)); - } - } - } - } - SaveServiceHelper.save(new DynamicObject[]{entity}); - } + if (yem_billtype.equals("yem_im_intauditbusa_PJWX")) { + formId = "yem_im_intauditbu_layout1"; + } else if (yem_billtype.equals("yem_im_intauditbusa_ZJWX")) { + formId = "yem_im_intauditbus_layout"; + } + String tplId = ""; + String printLang = ""; + String setting = UserConfigServiceHelper.getSetting(YEM.getCurrentUserId(), formId + "_printsetting"); + if (setting != null) { + JSONObject fromJsonString = SerializationUtils.fromJsonString(setting, JSONObject.class); + if (fromJsonString != null) { + tplId = fromJsonString.getString("templateid"); + printLang = fromJsonString.getString("printlang"); } - if ("yem_im_intauditbusa_PJWX".equals(number)) { - String sourceBillType = dataEntitie.getString("yem_sourcebilltype"); - Long sourceBillId = dataEntitie.getLong("yem_sourcebillid"); - Long sourceEntryId = dataEntitie.getLong("yem_sourceentryid"); - DynamicObject entity = BusinessDataServiceHelper.loadSingle(sourceBillId, sourceBillType); - if (YEM.isNotEmpty(entity)) { -// entity.set("yem_commissionamt",dataEntitie.getBigDecimal("yem_commissionamt")); -// entity.set("yem_commissionamtba",dataEntitie.getBigDecimal("yem_commissionamtba")); - BigDecimal exrate = entity.getBigDecimal("yem_exrate"); - BigDecimal carLoadFobPrice = dataEntitie.getBigDecimal("yem_carloadfobprice"); - BigDecimal carLoadFobPriceBa = dataEntitie.getBigDecimal("yem_carloadfobpriceba"); - BigDecimal contractPriceSum = dataEntitie.getBigDecimal("yem_contractpricesum"); - BigDecimal contractPriceSumBa = dataEntitie.getBigDecimal("yem_contractpricesumba"); - BigDecimal sumCost = dataEntitie.getBigDecimal("yem_sumcost"); - BigDecimal sumCostBase = dataEntitie.getBigDecimal("yem_sumcostbase"); - BigDecimal currTotalAmount = BigDecimal.ZERO; - BigDecimal currOneCarSum = BigDecimal.ZERO; - entity.set("yem_offeramount", contractPriceSum);// - entity.set("yem_offerstandardcoin", contractPriceSumBa);// - String name = entity.getDynamicObjectType().getName(); - DynamicObjectCollection entrys = null; - if ("yem_es_salesorder".equals(name)) { - entrys = entity.getDynamicObjectCollection("yem_es_materialinfo"); + } + if (YEM.isEmpty(tplId)) { + throw new KDBizException("没有设置打印模板,请在“打印”->“设置”中进行设置。"); + } else { + ArrayList pkIds = new ArrayList<>(); + pkIds.add(pkId); + // 打印任务 + ArrayList taskList = new ArrayList<>(); + PrintTask printTask = new PrintTask(); + printTask.setTplId(tplId);// 打印模板的id + printTask.setPkIds(pkIds); + printTask.setPrintType("billForm");// 打印对象的类型,是单据(billForm),报表(report),还是动态表单(dynamic) + printTask.setFormId(entityId); + taskList.add(printTask); + // 打印作业 + PrintWork printWork = new PrintWork(); + printWork.setPrintLang(YEM.isEmpty(printLang) ? "zh_CN" : printLang); + printWork.setExpType("pdf"); + printWork.setTaskList(taskList); + // 生成打印模板生成的pdf文件 + PrtAttach doPrint = BosPrintServiceHelper.doPrint(printWork); +// PrtAttach doPrint = BosPrintServiceHelper.execPrint(printWork); + //调用打印服务接口 + List attachDetails = doPrint.getAttachDetail(); + for (PrtAttach.AttachDetail attachDetail : attachDetails) { + String filePath = attachDetail.getFilePath(); + String fileName = attachDetail.getFileName(); +// String attachmentKey = "yem_approval"; + Boolean isattachmentpanel = isattachmentpanel(dataEntity, fileName, attachmentKey); + if (isattachmentpanel) { + String url = ""; + if (filePath.contains("configKey=redis.serversForCache&id=tempfile")) { + //持久化附件到服务器 + String attachmentFullUrl = UrlService.getAttachmentFullUrl(filePath); + url = uploadTempfile(attachmentFullUrl, fileName); + } else { + url = filePath; } - if ("yem_im_clientdemand".equals(name)) { - entrys = entity.getDynamicObjectCollection("yem_im_detailedinfor"); - } - - int lastIdx = 0; - - for (DynamicObject entry : entrys) { - int index = entrys.indexOf(entry); - boolean ifGift = entry.getBoolean("yem_ifgift"); - if (!ifGift) { - lastIdx = index; - } - } - - for (DynamicObject entry : entrys) { - int index = entrys.indexOf(entry); - boolean ifGift = entry.getBoolean("yem_ifgift"); - if (!ifGift) { - BigDecimal disAmt = entry.getBigDecimal("yem_disamt"); - BigDecimal qty = entry.getBigDecimal("yem_qty"); - BigDecimal saFobAmount = entry.getBigDecimal("yem_safobamount"); - BigDecimal saFobPrice = entry.getBigDecimal("yem_safobprice");//销售fob单价 - BigDecimal oneCarSum = saFobAmount.divide(carLoadFobPrice, RoundingMode.HALF_UP).multiply(sumCost).divide(qty, RoundingMode.HALF_UP); - BigDecimal oneCarSumBase = oneCarSum.multiply(exrate); - BigDecimal frontDisPrice = oneCarSum.add(saFobPrice); - BigDecimal frontDisAmt = frontDisPrice.multiply(qty); - BigDecimal saPricePriceClause = BigDecimal.ZERO; - if(disAmt.compareTo(BigDecimal.ZERO) > 0){ - BigDecimal afterFrontDisPrice = entry.getBigDecimal("yem_afterfrontdisprice"); - saPricePriceClause = afterFrontDisPrice.add(oneCarSum); - }else{ - saPricePriceClause = saFobPrice.add(oneCarSum); - } - BigDecimal saPriceAmtClause = saPricePriceClause.multiply(qty); - - entry.set("yem_saamtpriceclause", saPriceAmtClause);//销售金额(价格条款) - entry.set("yem_sapricepriceclause", saPricePriceClause);//销售单价(价格条款) - entry.set("yem_samtpriceclauseba", saPriceAmtClause.multiply(exrate));//销售金额(价格条款)(人民币) - entry.set("yem_sapriceclausebase", saPricePriceClause.multiply(exrate));//销售单价(价格条款)(人民币) - entry.set("yem_frontdisprice", frontDisPrice);//折扣前销售单价 - entry.set("yem_frontdisamt", frontDisAmt);//折扣前销售金额 - - BigDecimal calcTotalAmount = saFobAmount.divide(carLoadFobPrice, RoundingMode.HALF_UP).multiply(sumCost); - // 尾差处理 - BigDecimal scale = sumCost.subtract(currTotalAmount.setScale(2, RoundingMode.HALF_UP)); - if (index == lastIdx) { - entry.set("yem_totalamount", scale.setScale(2, RoundingMode.HALF_UP));//总费用 - entry.set("yem_totalamountrmb", scale.multiply(exrate));//总费用(人民币) - entry.set("yem_onecarsum", scale.divide(qty, RoundingMode.HALF_UP));//总费用 - entry.set("yem_onecarsumbase", scale.divide(qty, RoundingMode.HALF_UP).multiply(exrate));//总费用(人民币) - } else { - entry.set("yem_totalamount", calcTotalAmount.setScale(2, RoundingMode.HALF_UP));//总费用 - entry.set("yem_totalamountrmb", calcTotalAmount.multiply(exrate));//总费用(人民币) - entry.set("yem_onecarsum", calcTotalAmount.divide(qty, RoundingMode.HALF_UP));//总费用 - entry.set("yem_onecarsumbase", calcTotalAmount.divide(qty, RoundingMode.HALF_UP).multiply(exrate));//总费用(人民币) - currTotalAmount = currTotalAmount.add(calcTotalAmount.setScale(2, RoundingMode.HALF_UP)); - } - - } else { - entry.set("yem_onecarsum", null);//总费用 - entry.set("yem_onecarsumbase", null);//总费用(人民币) - entry.set("yem_saamtpriceclause", null);//销售金额(价格条款) - entry.set("yem_sapricepriceclause", null);//销售单价(价格条款) - entry.set("yem_samtpriceclauseba", null);//销售金额(价格条款)(人民币) - entry.set("yem_sapriceclausebase", null);//销售单价(价格条款)(人民币) - entry.set("yem_frontdisprice", null);//折扣前销售单价 - entry.set("yem_frontdisamt", null);//折扣前销售金额 - } - } - entity.set("yem_sumcost", sumCost);// - entity.set("yem_sumcostbase", sumCostBase);// - - DynamicObject recCondition = entity.getDynamicObject("yem_reccondition"); - if(YEM.isNotEmpty(recCondition)){ - String basis = recCondition.getString("basis"); - if("A".equals(basis)){ - DynamicObjectCollection salesContraC_ss = null; - if(sourceBillType.equals("yem_im_clientdemand")){ - salesContraC_ss = entity.getDynamicObjectCollection("yem_salescontrac_s"); - }else{ - salesContraC_ss = entity.getDynamicObjectCollection("yem_es_salescontrac_s"); - } - for(DynamicObject salesContraC_s : salesContraC_ss){ - BigDecimal rapRate = salesContraC_s.getBigDecimal("yem_raprate"); - salesContraC_s.set("yem_rapamt",rapRate.divide(new BigDecimal(100)).multiply(contractPriceSum)); - } - } - } - - SaveServiceHelper.save(new DynamicObject[]{entity}); + uploadAttachmentPanel(entityId, pkId, attachmentKey, fileName, url); + } else { + throw new KDBizException("当前单据已上传PDF套打,禁止再次生成!\n如需再次上传请删除原附件后重试!"); } + break; } } } - - -// public void createPdf(DynamicObject dataEntitie) { -// String billKey = dataEntitie.getDataEntityType().getName(); -// DynamicObject billType = dataEntitie.getDynamicObject("yem_billtype"); -// String billTypeNumber = YEM.isNotEmpty(billType) ? billType.getString("number") : ""; -// String selectFields = DynamicObjectUtil.getSelectfields("bos_manageprinttpl", false); -// List managePrintTpls = new ArrayList(); -// if ("yem_im_intauditbusa_PJWX".equals(billTypeNumber)) { -// DynamicObject[] managePrintTpl = BusinessDataServiceHelper.load("bos_manageprinttpl", selectFields, new QFilter[]{new QFilter("billformid.number", QCP.equals, billKey), new QFilter("printtplid.number", QCP.like, "%PJ%"), new QFilter("enable", QCP.equals, "1")}); -// if (managePrintTpl.length > 0) { -// managePrintTpls.add(managePrintTpl[0]); -// } -// } -// if ("yem_im_intauditbusa_ZJWX".equals(billTypeNumber)) { -// DynamicObject[] managePrintTpl = BusinessDataServiceHelper.load("bos_manageprinttpl", selectFields, new QFilter[]{new QFilter("billformid.number", QCP.equals, billKey), new QFilter("printtplid.number", QCP.like, "%HSZJ%"), new QFilter("enable", QCP.equals, "1")}); -// if (managePrintTpl.length > 0) { -// managePrintTpls.add(managePrintTpl[0]); -// } -// managePrintTpl = BusinessDataServiceHelper.load("bos_manageprinttpl", selectFields, new QFilter[]{new QFilter("billformid.number", QCP.equals, billKey), new QFilter("printtplid.number", QCP.like, "%NSZJ%"), new QFilter("enable", QCP.equals, "1")}); -// if (managePrintTpl.length > 0) { -// managePrintTpls.add(managePrintTpl[0]); -// } -// } -// long id = dataEntitie.getLong("id"); -// //租户ID -// String tenantId = RequestContext.get().getTenantId(); -// //账套ID -// String accountId = RequestContext.get().getAccountId(); -// for (DynamicObject managePrintTpl : managePrintTpls) { -// if (YEM.isNotEmpty(managePrintTpl)) { -// String tplIdByNum = managePrintTpl.getDynamicObject("printtplid").getString("number"); -// String tplId = BosPrintServiceHelper.getTplIdByNum(tplIdByNum); -// String attName = FunctionalCommon.setAttName(tplIdByNum, dataEntitie); -// PrintWork work = new PrintWork(); -// //设置打印语言 -// work.setPrintLang("zh_CN"); -// //设置类型:1代表pdf -// work.setExpType("1"); -// List printTasks = new ArrayList<>(); -// PrintTask printTask = new PrintTask(); -// //设置模板ID -// printTask.setTplId(tplId); -// //设置当前单据id -// printTask.setPkIds(new ArrayList(Arrays.asList(id))); -// printTasks.add(printTask); -// work.setTaskList(printTasks); -// //调用打印服务接口 -// PrtAttach prtAttach = BosPrintServiceHelper.doPrint(work); -// //获取生成的pdf在文件服务器中的路径 -// String path = prtAttach.getAttachDetail().get(0).getFilePath(); -// //因为打印生成的临时文件,后续会自动清理,故而需要业务上传的文件服务器转存。 -// FileService fileService = FileServiceFactory.getAttachmentFileService(); -// InputStream inputStream = FileServiceFactory.getAttachmentFileService().getInputStream(path); -// try { -// ByteArrayOutputStream dest = new ByteArrayOutputStream(); -// IOUtils.copy(inputStream, dest); -// InputStream stream1 = new ByteArrayInputStream(dest.toByteArray()); -// InputStream stream2 = new ByteArrayInputStream(dest.toByteArray()); -// long fileSize = getFileSize(stream1); -// SimpleDateFormat yyyyMMdd = new SimpleDateFormat("yyyyMMdd"); -// String date = yyyyMMdd.format(new Date()); -// String biilNo = dataEntitie.getString("billno"); -// path = fileService.upload(new FileItem(attName + ".pdf", "/" + tenantId + "/" + accountId + "/" + date + "/yem_im_intauditbus_prtpl/" + attName + ".pdf", stream2)); -//// path = fileService.upload(new FileItem(attName + ".pdf", "/yxzg-topview-dev/1797950314112879616/" + date + "/yem_im_intauditbus_prtpl/" + attName + ".pdf", inputStream)); -// -// List> attachments = new ArrayList<>(); -// Map attaMap = new HashMap<>(16); -// attaMap.put("size", fileSize); -// attaMap.put("url", path); -// attaMap.put("name", attName + ".pdf"); -// attaMap.put("type", ".pdf"); -// attaMap.put("uid", "rc-upload-" + System.nanoTime() + "-" + (int) (Math.random() * 100)); -// attaMap.put("status", "success"); -// attaMap.put("entityNum", dataEntitie.getString("yem_sourcebilltype")); -// attaMap.put("client", "web"); -// // 当前时间戳 -// long time = System.currentTimeMillis(); -// attaMap.put("createdate", time); -// attaMap.put("lastModified", time); -// attachments.add(attaMap); -// AttachmentServiceHelper.upload(dataEntitie.getString("yem_sourcebilltype"), String.valueOf(dataEntitie.getLong("yem_sourcebillid")), "attachmentpanel", attachments); -//// List attDtoList = new ArrayList<>(); -//// AttDto attDto = new AttDto(); -//// //绑定文件服务器中的路径 -//// attDto.setPath(path); -//// //单据附件标识 -//// attDto.setAttKey("attachmentpanel"); -//// //文件大小(字节数) -//// attDto.setSize(Long.valueOf(AttachmentServiceHelper.getFileSizeByPath(path))); -//// attDtoList.add(attDto); -//// //第一个参数为目标单据标识;第二个参数为目标单据pkId,第三个参数为附件列表 -//// Map bindingParam = AttachmentServiceHelper.genBindingParam(dataEntitie.getString("yem_sourcebilltype"), String.valueOf(dataEntitie.getLong("yem_sourcebillid")), attDtoList); -//// //绑定接口返回结果 -//// Map resultMap = AttachmentServiceHelper.bindingAttachment(bindingParam); -// } catch (Exception e) { -// String message = e.getMessage(); -// e.printStackTrace(); -// } -// -// } -// } -// } - - public void createPdf(DynamicObject dataEntitie) { - String billKey = dataEntitie.getDataEntityType().getName(); - DynamicObject billType = dataEntitie.getDynamicObject("yem_billtype"); - String billTypeNumber = YEM.isNotEmpty(billType) ? billType.getString("number") : ""; - String selectFields = DynamicObjectUtil.getSelectfields("bos_manageprinttpl", false); - List managePrintTpls = new ArrayList(); - if ("yem_im_intauditbusa_PJWX".equals(billTypeNumber)) { - DynamicObject[] managePrintTpl = BusinessDataServiceHelper.load("bos_manageprinttpl", selectFields, - new QFilter[]{new QFilter("billformid.number", QCP.equals, billKey), - new QFilter("printtplid.number", QCP.like, "%PJ%"), - new QFilter("enable", QCP.equals, "1")}); - if (managePrintTpl.length > 0) { - managePrintTpls.add(managePrintTpl[0]); - } - } - if ("yem_im_intauditbusa_ZJWX".equals(billTypeNumber)) { - DynamicObject[] managePrintTpl = BusinessDataServiceHelper.load("bos_manageprinttpl", selectFields, - new QFilter[]{new QFilter("billformid.number", QCP.equals, billKey), - new QFilter("printtplid.number", QCP.like, "%HSZJ%"), - new QFilter("enable", QCP.equals, "1")}); - if (managePrintTpl.length > 0) { - managePrintTpls.add(managePrintTpl[0]); - } - managePrintTpl = BusinessDataServiceHelper.load("bos_manageprinttpl", selectFields, - new QFilter[]{new QFilter("billformid.number", QCP.equals, billKey), - new QFilter("printtplid.number", QCP.like, "%NSZJ%"), - new QFilter("enable", QCP.equals, "1")}); - if (managePrintTpl.length > 0) { - managePrintTpls.add(managePrintTpl[0]); - } - } - long id = dataEntitie.getLong("id"); - //租户ID - String tenantId = RequestContext.get().getTenantId(); - //账套ID - String accountId = RequestContext.get().getAccountId(); - for (DynamicObject managePrintTpl : managePrintTpls) { - if (YEM.isNotEmpty(managePrintTpl)) { - String tplIdByNum = managePrintTpl.getDynamicObject("printtplid").getString("number"); - String tplId = BosPrintServiceHelper.getTplIdByNum(tplIdByNum); - String attName = FunctionalCommon.setAttName(tplIdByNum, dataEntitie); - PrintWork work = new PrintWork(); - //设置打印语言 - work.setPrintLang("zh_CN"); - //设置类型:1代表pdf - work.setExpType("1"); - List printTasks = new ArrayList<>(); - PrintTask printTask = new PrintTask(); - //设置模板ID - printTask.setTplId(tplId); - //设置当前单据id - printTask.setPkIds(new ArrayList(Arrays.asList(id))); - printTasks.add(printTask); - work.setTaskList(printTasks); - //调用打印服务接口 - PrtAttach prtAttach = BosPrintServiceHelper.doPrint(work); - //获取生成的pdf在文件服务器中的路径 - String path = prtAttach.getAttachDetail().get(0).getFilePath(); - //因为打印生成的临时文件,后续会自动清理,故而需要业务上传的文件服务器转存。 - FileService fileService = FileServiceFactory.getAttachmentFileService(); - InputStream inputStream = FileServiceFactory.getAttachmentFileService().getInputStream(path); - SimpleDateFormat yyyyMMdd = new SimpleDateFormat("yyyyMMdd"); - String date = yyyyMMdd.format(new Date()); - String biilNo = dataEntitie.getString("billno"); - path = fileService.upload(new FileItem(attName + ".pdf", "/" + tenantId + "/" + accountId + "/" + date + "/yem_im_intauditbus_prtpl/" + attName + ".pdf", inputStream)); - path = "/" + tenantId + "/" + accountId + "/" + date + "/yem_im_intauditbus_prtpl/" + attName + ".pdf"; - try { - List attDtoList = new ArrayList<>(); - AttDto attDto = new AttDto(); - //绑定文件服务器中的路径 - attDto.setPath(path); - //单据附件标识 - attDto.setAttKey("attachmentpanel"); - //文件大小(字节数) - attDto.setSize(Long.valueOf(AttachmentServiceHelper.getFileSizeByPath(attDto.getPath()))); - attDtoList.add(attDto); - //第一个参数为目标单据标识;第二个参数为目标单据pkId,第三个参数为附件列表 - Map bindingParam = AttachmentServiceHelper.genBindingParam(dataEntitie.getString("yem_sourcebilltype"), - String.valueOf(dataEntitie.getLong("yem_sourcebillid")), attDtoList); - //绑定接口返回结果 - Map resultMap = AttachmentServiceHelper.bindingAttachment(bindingParam); - } catch (Exception e) { - String message = e.getMessage(); - e.printStackTrace(); - throw new KDException(e.getMessage()); - } - - } - } - } - - public static long getFileSize(InputStream instream) throws IOException { - long fileSize = 0; - byte[] buffer = new byte[1024]; - int len; - while ((len = instream.read(buffer)) != -1) { - fileSize += len; - } - instream.close(); - return fileSize; - } - - private static ByteArrayOutputStream cloneInputStream(InputStream input) { - + public static DynamicObject uploadAttachmentPanel(String formId, Object pkId, String attachmentKey, String fileName, String url) { + int size = 10; try { - - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - - byte[] buffer = new byte[1024]; - - int len; - - while ((len = input.read(buffer)) > -1) { - - baos.write(buffer, 0, len); - - } - - baos.flush(); - - return baos; - + size = FileServiceFactory.getAttachmentFileService().getInputStream(url).available(); } catch (IOException e) { - e.printStackTrace(); - - return null; - } + if (YEM.isNotEmpty(url)) { + if (YEM.isEmpty(fileName)) { + fileName = url.substring(url.lastIndexOf("/") + 1); + } + Date today = new Date(); + DynamicObject newAtt = BusinessDataServiceHelper.newDynamicObject("bos_attachment"); + Long id = ORM.create().genLongId("bos_attachment"); + newAtt.set("id", id); + newAtt.set("fnumber", "upload_" + id); + newAtt.set("FBillType", formId); + newAtt.set("FInterID", pkId); + newAtt.set("FModifyTime", today); + newAtt.set("fcreatetime", today); + newAtt.set("FaliasFileName", fileName); + newAtt.set("FAttachmentName", fileName); + newAtt.set("FFileId", url); + newAtt.set("FExtName", fileName.substring(fileName.lastIndexOf(46) + 1)); + newAtt.set("FATTACHMENTSIZE", 100); + newAtt.set("FCREATEMEN", RequestContext.get().getCurrUserId()); + newAtt.set("fattachmentpanel", attachmentKey); + newAtt.set("fdescription", ""); + SaveServiceHelper.save(new DynamicObject[]{newAtt}); + return newAtt; + } + return null; + } + /** + * 上传临时文件到服务器中 + * + * @param url + * @param name + * @return + */ + private static String uploadTempfile(String url, String name) { + TempFileCache cache = CacheFactory.getCommonCacheFactory().getTempFileCache(); + InputStream in = cache.getInputStream(url); + FileService service = FileServiceFactory.getAttachmentFileService(); + FileService fs = FileServiceFactory.getAttachmentFileService(); + RequestContext requestContext = RequestContext.get(); + String uuid = UUID.randomUUID().toString().replace("-", ""); + // 生成文件路径-上传附件时远程服务器需要存储文件的位置 + String pathParam = FileNameUtils.getAttachmentFileName(requestContext.getTenantId(), + requestContext.getAccountId(), uuid, name); + FileItem fileItem = new FileItem(name, pathParam, in); + // cache.remove(url); + // 上传附件到文件服务器 + String downUrl = service.upload(fileItem); + return downUrl; + } + public static Boolean isattachmentpanel(DynamicObject dataEntity, String fileName, String attachmentKey) { + List> attachmentpanel = + AttachmentServiceHelper.getAttachments(dataEntity.getDynamicObjectType().getName(), dataEntity.getPkValue(), attachmentKey); + if ("attachmentpanel".equals(attachmentKey)) { + + if (attachmentpanel.size() > 0) { + for (int i = 0; i < attachmentpanel.size(); i++) { + Map stringObjectMap = attachmentpanel.get(i); + String name = (String) stringObjectMap.get("name"); + if (name.equals(fileName)) { + return false; + } + } + } else { + return true; + } + return true; + } else { + return attachmentpanel.size() <= 0; + } } }