From d9c533b6145a82e71ecfd2df6cc57d62de430e17 Mon Sep 17 00:00:00 2001 From: mzr <1562242162@qq.com> Date: Wed, 26 Mar 2025 19:00:58 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=9A=E6=97=B6=E4=BB=BB=E5=8A=A1-=E9=94=80?= =?UTF-8?q?=E5=94=AE=E5=8F=91=E7=A5=A8=E5=90=8C=E6=AD=A5=E5=85=B3=E8=81=94?= =?UTF-8?q?=E5=8D=95=E6=8D=AE=E5=8F=91=E7=A5=A8=E5=8F=B7=E5=8F=8A=E7=9B=B8?= =?UTF-8?q?=E5=85=B3=E5=AD=97=E6=AE=B5-2005=E9=80=82=E9=85=8D2312-liujie?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../nc/bs/uapbd/task/InvoiceTaskPlugin.java | 122 ++++++++++++++++++ 1 file changed, 122 insertions(+) create mode 100644 uapbd/src/private/nc/bs/uapbd/task/InvoiceTaskPlugin.java diff --git a/uapbd/src/private/nc/bs/uapbd/task/InvoiceTaskPlugin.java b/uapbd/src/private/nc/bs/uapbd/task/InvoiceTaskPlugin.java new file mode 100644 index 0000000..96e1c5b --- /dev/null +++ b/uapbd/src/private/nc/bs/uapbd/task/InvoiceTaskPlugin.java @@ -0,0 +1,122 @@ +package nc.bs.uapbd.task; + +import nc.bs.dao.BaseDAO; +import nc.bs.logging.Logger; +import nc.bs.pub.pa.PreAlertObject; +import nc.bs.pub.taskcenter.BgWorkingContext; +import nc.bs.pub.taskcenter.IBackgroundWorkPlugin; +import nc.bs.trade.business.HYSuperDMO; +import nc.jdbc.framework.processor.MapListProcessor; +import nc.vo.pub.BusinessException; +import nc.vo.sscivm.ivsale.IVApplicationHeadVO; +import nc.vo.sscivm.ivsale.IVApplogVO; +import uap.mw.trans.TransactionFactory; + +import java.util.ArrayList; +import java.util.HashMap; + +public class InvoiceTaskPlugin implements IBackgroundWorkPlugin{ + + @Override + public PreAlertObject executeTask(BgWorkingContext arg0) throws BusinessException { + // TODO Auto-generated method stub + Logger.error("---start----任务开始运行--"); + try { + BaseDAO dao = new BaseDAO(); + String sql = " SELECT sscivm_invoice.pk_invoice,so_saleinvoice.csaleinvoiceid,so_saleinvoice.vbillcode billcode, sscivm_invoice.fphm, " + + "sscivm_invoice.Gmfmc, sscivm_invoice.Jshj, sscivm_invoice.viewurl, sscivm_invoice.billno " + + " FROM sscivm_invoice " + + " left join sscivm_invoice_relation on sscivm_invoice_relation.PK_INVOICE = sscivm_invoice.pk_invoice " + + " left join so_saleinvoice on so_saleinvoice.csaleinvoiceid = sscivm_invoice_relation.billid " + + " left join sscivm_ivapplog on sscivm_ivapplog.fphm = sscivm_invoice.fphm " + + " where " + + " sscivm_invoice_relation.billtype = '32' " + + " and so_saleinvoice.vdef20 <> 'Y' " + + " and sscivm_invoice.dr = 0 " + + " and sscivm_ivapplog.kpzt = 2 "; +// + " so_saleinvoice.vbillcode = 'SI2024070400000738' "; + ArrayList> al = (ArrayList>)dao.executeQuery(sql, new MapListProcessor()); + Logger.error("---alData------"+al); + if(al.size() > 0) { + for(HashMap sscivm_invoice : al) { + Object pk_invoice = sscivm_invoice.get("pk_invoice"); //bip发票主键 + Object csaleinvoiceid = sscivm_invoice.get("csaleinvoiceid"); //销售发票id + Object billcode = sscivm_invoice.get("billcode"); //销售发票编码 + Object billno = sscivm_invoice.get("billno"); //bip单据编码编码 + Object fphm = sscivm_invoice.get("fphm"); + Object Gmfmc = sscivm_invoice.get("Gmfmc"); + Object Jshj = sscivm_invoice.get("Jshj"); + Object viewurl = sscivm_invoice.get("viewurl"); + String ctcode=""; + HYSuperDMO dmo = new HYSuperDMO(); + IVApplogVO[] ivApplogVO=(IVApplogVO[]) dmo.queryByWhereClause(IVApplogVO.class, "fphm='"+fphm+"' and dr=0 "); + Logger.error("---ivApplogVO------"+ivApplogVO); + if(ivApplogVO!=null&&ivApplogVO.length>0) { + ivApplogVO[0].getLyid();//开票申请单主键 + IVApplicationHeadVO ivApplicationHeadVO =(IVApplicationHeadVO) dmo.queryByPrimaryKey(IVApplicationHeadVO.class, ivApplogVO[0].getLyid()); + ctcode=ivApplicationHeadVO.getDef2();//合同号 + } + Object url = ctcode+"_"+Gmfmc+"_"+fphm+"_"+Jshj + ".pdf"; + /** + * 回写逻辑: + * 1.修改发票关联关系单据编码 + * 2.ERP销售发票回传,根据销售发票id,回写发票号和单据编号 + * 3.根据销售发票id 回写下游应收单表头表体发票号 + * 4.查询销售发票下游单据,如果有将下游单据表体字段【来源单据号】更新成新的发票号 + */ + //手动开启事务 + TransactionFactory.getTMProxy().begin(3,0); + //修改发票信息单据号 + String sscivmSql = "UPDATE sscivm_invoice set billno = '" + fphm +"' where pk_invoice = '"+ pk_invoice +"'"; + dao.executeUpdate(sscivmSql); + Logger.error("---sscivmSqlExecute------"+sscivmSql); + //修改发票关联关系单据编码 + String sirSql = "UPDATE sscivm_invoice_relation set billno = '" + fphm +"' where pk_invoice = '"+ pk_invoice +"' and billid = '"+ csaleinvoiceid +"'"; + dao.executeUpdate(sirSql); + Logger.error("---sirSqlExecute------"+sirSql); + //ERP销售发票回传,根据销售发票id,回写发票号和单据编号 + String sSaleSql = "UPDATE so_saleinvoice set vdef20 = 'Y' , vdef13 = '" + fphm + "', vbillcode = '" + fphm +"' where csaleinvoiceid = '" + csaleinvoiceid + "'"; + dao.executeUpdate(sSaleSql); + Logger.error("---sSaleSqlExecute------"+sSaleSql); + //根据销售发票id 回写下游应收单表头发票号 + String recBillSql = "MERGE INTO ar_recbill a USING (select DISTINCT pk_recbill,top_billid,top_billtype from ar_recitem) b ON ( a.pk_recbill = b.pk_recbill AND b.top_billid = '" + csaleinvoiceid + "' AND b.top_billtype = '32' ) \n" + + "WHEN MATCHED THEN\n" + + "UPDATE \n" + + "SET a.invoiceno = '" + fphm + "'"; + dao.executeUpdate(recBillSql); + Logger.error("---recBillSqlExecute------"+recBillSql); + //根据销售发票id 回写下游应收单表体发票号 + String recItemSql = "UPDATE ar_recitem \n" + + "SET invoiceno = '" + fphm + "' \n" + + "WHERE\n" + + "top_billid = '" + csaleinvoiceid + "' \n" + + "AND top_billtype = '32'"; + dao.executeUpdate(recItemSql); + Logger.error("---recItemSqlExecute------"+recItemSql); + //查询销售发票下游单据,如果有将下游单据表体字段【来源单据号】更新成新的发票号 + String saleOutSql = "UPDATE ic_saleout_b \n" + + "SET vsourcebillcode = '"+ fphm +"' \n" + + "WHERE\n" + + "csourcetype = '32' \n" + + "AND csourcebillhid = '" + csaleinvoiceid +"'"; + dao.executeUpdate(saleOutSql); + Logger.error("---saleOutSqlExecute------"+saleOutSql); + //正常结束 + TransactionFactory.getTMProxy().end(null); + } + + + } + } catch(Exception e) { + e.printStackTrace(); + //异常回滚 + TransactionFactory.getTMProxy().end(e); + Logger.error("writeBack Error: ",e); + } + return null; + } + + + + +}