erp同步销售发票定时任务

This commit is contained in:
lihao 2025-05-08 14:42:12 +08:00
parent a352b7f492
commit 63a4cdef68
1 changed files with 28 additions and 28 deletions

View File

@ -20,7 +20,7 @@ public class InvoiceTaskPlugin implements IBackgroundWorkPlugin{
@Override @Override
public PreAlertObject executeTask(BgWorkingContext arg0) throws BusinessException { public PreAlertObject executeTask(BgWorkingContext arg0) throws BusinessException {
// TODO Auto-generated method stub // TODO Auto-generated method stub
Logger.error("---start----任务开始运行--"); Logger.error("---start----任务开始运行--");
try { try {
BaseDAO dao = new BaseDAO(); BaseDAO dao = new BaseDAO();
String sql = " SELECT sscivm_invoice.pk_invoice,so_saleinvoice.csaleinvoiceid,so_saleinvoice.vbillcode billcode, sscivm_invoice.fphm, " + String sql = " SELECT sscivm_invoice.pk_invoice,so_saleinvoice.csaleinvoiceid,so_saleinvoice.vbillcode billcode, sscivm_invoice.fphm, " +
@ -39,53 +39,53 @@ public class InvoiceTaskPlugin implements IBackgroundWorkPlugin{
Logger.error("---alData------"+al); Logger.error("---alData------"+al);
if(al.size() > 0) { if(al.size() > 0) {
for(HashMap<String, Object> sscivm_invoice : al) { for(HashMap<String, Object> sscivm_invoice : al) {
Object pk_invoice = sscivm_invoice.get("pk_invoice"); //bip发票主键 Object pk_invoice = sscivm_invoice.get("pk_invoice"); //bip发票主键 0001A1100000004Y7DWZ
Object csaleinvoiceid = sscivm_invoice.get("csaleinvoiceid"); //销售发票id Object csaleinvoiceid = sscivm_invoice.get("csaleinvoiceid"); //销售发票id
Object billcode = sscivm_invoice.get("billcode"); //销售发票编码 Object billcode = sscivm_invoice.get("billcode"); //销售发票编码
Object billno = sscivm_invoice.get("billno"); //bip单据编码编码 Object billno = sscivm_invoice.get("billno"); //bip单据编码编码
Object fphm = sscivm_invoice.get("fphm"); Object fphm = sscivm_invoice.get("fphm");
Object Gmfmc = sscivm_invoice.get("Gmfmc"); Object Gmfmc = sscivm_invoice.get("Gmfmc");
Object Jshj = sscivm_invoice.get("Jshj"); Object Jshj = sscivm_invoice.get("Jshj");
Object viewurl = sscivm_invoice.get("viewurl"); Object viewurl = sscivm_invoice.get("viewurl");
String ctcode=""; String ctcode="";
HYSuperDMO dmo = new HYSuperDMO(); // HYSuperDMO dmo = new HYSuperDMO();
IVApplogVO[] ivApplogVO=(IVApplogVO[]) dmo.queryByWhereClause(IVApplogVO.class, "fphm='"+fphm+"' and dr=0 "); // IVApplogVO[] ivApplogVO=(IVApplogVO[]) dmo.queryByWhereClause(IVApplogVO.class, "fphm='"+fphm+"' and dr=0 ");
Logger.error("---ivApplogVO------"+ivApplogVO); // Logger.error("---ivApplogVO------"+ivApplogVO);
if(ivApplogVO!=null&&ivApplogVO.length>0) { // if(ivApplogVO!=null&&ivApplogVO.length>0) {
ivApplogVO[0].getLyid();//开票申请单主键 // ivApplogVO[0].getLyid();//开票申请单主键
IVApplicationHeadVO ivApplicationHeadVO =(IVApplicationHeadVO) dmo.queryByPrimaryKey(IVApplicationHeadVO.class, ivApplogVO[0].getLyid()); // IVApplicationHeadVO ivApplicationHeadVO =(IVApplicationHeadVO) dmo.queryByPrimaryKey(IVApplicationHeadVO.class, ivApplogVO[0].getLyid());
ctcode=ivApplicationHeadVO.getDef2();//合同号 // ctcode=ivApplicationHeadVO.getDef2();//合同号
} // }
Object url = ctcode+"_"+Gmfmc+"_"+fphm+"_"+Jshj + ".pdf"; // Object url = ctcode+"_"+Gmfmc+"_"+fphm+"_"+Jshj + ".pdf";
/** /**
* 回写逻辑 * 回写逻辑
* 1.修改发票关联关系单据编码 * 1.修改发票关联关系单据编码
* 2.ERP销售发票回传根据销售发票id回写发票号和单据编号 * 2.ERP销售发票回传根据销售发票id回写发票号和单据编号
* 3.根据销售发票id 回写下游应收单表头表体发票号 * 3.根据销售发票id 回写下游应收单表头表体发票号
* 4.查询销售发票下游单据如果有将下游单据表体字段来源单据号更新成新的发票号 * 4.查询销售发票下游单据如果有将下游单据表体字段来源单据号更新成新的发票号
*/ */
//手动开启事务 //手动开启事务
TransactionFactory.getTMProxy().begin(3,0); TransactionFactory.getTMProxy().begin(3,0);
//修改发票信息单据号 //修改发票信息单据号
String sscivmSql = "UPDATE sscivm_invoice set billno = '" + fphm +"' where pk_invoice = '"+ pk_invoice +"'"; String sscivmSql = "UPDATE sscivm_invoice set billno = '" + fphm +"' where pk_invoice = '"+ pk_invoice +"'";
dao.executeUpdate(sscivmSql); dao.executeUpdate(sscivmSql);
Logger.error("---sscivmSqlExecute------"+sscivmSql); Logger.error("---sscivmSqlExecute------"+sscivmSql);
//修改发票关联关系单据编码 //修改发票关联关系单据编码
String sirSql = "UPDATE sscivm_invoice_relation set billno = '" + fphm +"' where pk_invoice = '"+ pk_invoice +"' and billid = '"+ csaleinvoiceid +"'"; String sirSql = "UPDATE sscivm_invoice_relation set billno = '" + fphm +"' where pk_invoice = '"+ pk_invoice +"' and billid = '"+ csaleinvoiceid +"'";
dao.executeUpdate(sirSql); dao.executeUpdate(sirSql);
Logger.error("---sirSqlExecute------"+sirSql); Logger.error("---sirSqlExecute------"+sirSql);
//ERP销售发票回传根据销售发票id回写发票号和单据编号 //ERP销售发票回传根据销售发票id回写发票号和单据编号
String sSaleSql = "UPDATE so_saleinvoice set vdef20 = 'Y' , vdef13 = '" + fphm + "', vbillcode = '" + fphm +"' where csaleinvoiceid = '" + csaleinvoiceid + "'"; String sSaleSql = "UPDATE so_saleinvoice set vdef20 = 'Y' , vdef13 = '" + fphm + "', vbillcode = '" + fphm +"' where csaleinvoiceid = '" + csaleinvoiceid + "'";
dao.executeUpdate(sSaleSql); dao.executeUpdate(sSaleSql);
Logger.error("---sSaleSqlExecute------"+sSaleSql); Logger.error("---sSaleSqlExecute------"+sSaleSql);
//根据销售发票id 回写下游应收单表头发票号 //根据销售发票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" + 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" + "WHEN MATCHED THEN\n" +
"UPDATE \n" + "UPDATE \n" +
"SET a.invoiceno = '" + fphm + "'"; "SET a.invoiceno = '" + fphm + "'";
dao.executeUpdate(recBillSql); dao.executeUpdate(recBillSql);
Logger.error("---recBillSqlExecute------"+recBillSql); Logger.error("---recBillSqlExecute------"+recBillSql);
//根据销售发票id 回写下游应收单表体发票号 //根据销售发票id 回写下游应收单表体发票号
String recItemSql = "UPDATE ar_recitem \n" + String recItemSql = "UPDATE ar_recitem \n" +
"SET invoiceno = '" + fphm + "' \n" + "SET invoiceno = '" + fphm + "' \n" +
"WHERE\n" + "WHERE\n" +
@ -93,7 +93,7 @@ public class InvoiceTaskPlugin implements IBackgroundWorkPlugin{
"AND top_billtype = '32'"; "AND top_billtype = '32'";
dao.executeUpdate(recItemSql); dao.executeUpdate(recItemSql);
Logger.error("---recItemSqlExecute------"+recItemSql); Logger.error("---recItemSqlExecute------"+recItemSql);
//查询销售发票下游单据如果有将下游单据表体字段来源单据号更新成新的发票号 //查询销售发票下游单据如果有将下游单据表体字段来源单据号更新成新的发票号
String saleOutSql = "UPDATE ic_saleout_b \n" + String saleOutSql = "UPDATE ic_saleout_b \n" +
"SET vsourcebillcode = '"+ fphm +"' \n" + "SET vsourcebillcode = '"+ fphm +"' \n" +
"WHERE\n" + "WHERE\n" +
@ -101,7 +101,7 @@ public class InvoiceTaskPlugin implements IBackgroundWorkPlugin{
"AND csourcebillhid = '" + csaleinvoiceid +"'"; "AND csourcebillhid = '" + csaleinvoiceid +"'";
dao.executeUpdate(saleOutSql); dao.executeUpdate(saleOutSql);
Logger.error("---saleOutSqlExecute------"+saleOutSql); Logger.error("---saleOutSqlExecute------"+saleOutSql);
//正常结束 //正常结束
TransactionFactory.getTMProxy().end(null); TransactionFactory.getTMProxy().end(null);
} }
@ -109,7 +109,7 @@ public class InvoiceTaskPlugin implements IBackgroundWorkPlugin{
} }
} catch(Exception e) { } catch(Exception e) {
e.printStackTrace(); e.printStackTrace();
//异常回滚 //异常回滚
TransactionFactory.getTMProxy().end(e); TransactionFactory.getTMProxy().end(e);
Logger.error("writeBack Error: ",e); Logger.error("writeBack Error: ",e);
} }