package com.tenwa.lease.app.invoicemanager; import java.io.File; import java.math.BigDecimal; import java.text.DecimalFormat; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; import java.util.List; import java.util.UUID; import jbo.app.tenwa.calc.LC_CALC_CONDITION; import jbo.app.tenwa.calc.LC_FUND_INCOME; import jbo.app.tenwa.calc.LC_FUND_PLAN; import jbo.app.tenwa.calc.LC_RENT_INCOME; import jbo.app.tenwa.calc.LC_RENT_PLAN; import jbo.app.tenwa.calc.LI_INVOICE_CONFIRM; import jbo.app.tenwa.calc.LI_INVOICE_CONFIRM_DETAIL; import jbo.app.tenwa.calc.LI_INVOICE_RESULT; import jbo.app.tenwa.calc.VI_LI_INVOICE; import jbo.app.tenwa.customer.CUSTOMER_COMPANY; import jbo.app.tenwa.customer.CUSTOMER_PERSON; import jbo.awe.USER_INFO; import jbo.com.tenwa.entity.comm.invoice.LI_FUND_INVOICE_DOWNLOAD_INFO; import jbo.com.tenwa.entity.comm.invoice.LI_FUND_INVOICE_INFO; import jbo.com.tenwa.entity.comm.invoice.LI_RENT_INVOICE_DOWNLOAD_INFO; import jbo.com.tenwa.entity.comm.invoice.LI_RENT_INVOICE_INFO; import jbo.com.tenwa.entity.comm.invoice.LI_TAX_FUND_UPLOAD_INFO; import jbo.com.tenwa.entity.comm.invoice.LI_TAX_RENT_UPLOAD_INFO; import jbo.com.tenwa.entity.comm.own.OWN_ACCOUNT; import jbo.com.tenwa.entity.comm.own.OWN_INFO; import jbo.com.tenwa.lease.comm.LB_CONTRACT_INFO; import jbo.com.tenwa.lease.comm.LB_CONTRACT_INVOICE_TYPE; import org.apache.commons.lang.StringUtils; import org.bouncycastle.util.encoders.Base64Encoder; import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; import org.springframework.web.client.RestTemplate; import com.alibaba.fastjson.util.Base64; import com.amarsoft.app.lc.util.DateAssistant; import com.amarsoft.are.jbo.BizObject; import com.amarsoft.are.jbo.BizObjectKey; import com.amarsoft.are.jbo.BizObjectManager; import com.amarsoft.are.jbo.JBOException; import com.amarsoft.are.jbo.JBOFactory; import com.amarsoft.are.jbo.JBOTransaction; import com.amarsoft.awe.Configure; import com.tenwa.app.invoice.action.InvoiceRequest; import com.tenwa.app.invoice.data.ResponseEnum; import com.tenwa.app.invoice.pojo.ResultPojo; import com.tenwa.app.invoice.request.InvoiceRequestBase; import com.tenwa.app.invoice.request.InvoiceRequestHead; import com.tenwa.app.invoice.utils.DownloadPdfUtil; import com.tenwa.app.invoice.utils.JaxbUtil; import com.tenwa.app.invoice.utils.MathUtil; import com.tenwa.app.invoice.utils.Num2ChineseUtil; import com.tenwa.app.invoice.utils.PasswordGenerateUtil; import com.tenwa.app.invoice.utils.ResultUtil; import com.tenwa.flow.action.comm.BaseTable; import com.tenwa.util.SecurityUtil; import com.tenwa.util.SerialNumberUtil; /** * @author admin * */ public class InvoiceManagerController extends BaseTable{ private String InvoiceStatus; private String PlanList; private String IncomeList; private String PaymentList; private String PlanIncomeList; private String IncomeId; private String PlanId; private String UploadId; private String RebackStatus; private String ContractId; private String ContractInvoiceStatus; private String ReceiptList; private String sid; private String url = "http://fpfw2.aiee.fun:8899/fpfw2/api/kpbusiness"; private String appId = "77c61651-f40e-4536-9991-bba64bd3521e"; public String getUrl() { return url; } public void setUrl(String url) { this.url = url; } public String getAppId() { return appId; } public void setAppId(String appId) { this.appId = appId; } public String getSid() { return sid; } public void setSid(String sid) { this.sid = sid; } public String getInvoiceStatus() { return InvoiceStatus; } public void setInvoiceStatus(String invoiceStatus) { InvoiceStatus = invoiceStatus; } public String getPlanList() { return PlanList; } public void setPlanList(String planList) { PlanList = planList; } public String getIncomeList() { return IncomeList; } public void setIncomeList(String incomeList) { IncomeList = incomeList; } public String getPaymentList() { return PaymentList; } public void setPaymentList(String paymentList) { PaymentList = paymentList; } public String getPlanIncomeList() { return PlanIncomeList; } public void setPlanIncomeList(String planIncomeList) { PlanIncomeList = planIncomeList; } public String getIncomeId() { return IncomeId; } public void setIncomeId(String incomeId) { IncomeId = incomeId; } public String getPlanId() { return PlanId; } public void setPlanId(String planId) { PlanId = planId; } public String getUploadId() { return UploadId; } public void setUploadId(String uploadId) { UploadId = uploadId; } public String getRebackStatus() { return RebackStatus; } public void setRebackStatus(String rebackStatus) { RebackStatus = rebackStatus; } public String getContractId() { return ContractId; } public void setContractId(String contractId) { ContractId = contractId; } public String getContractInvoiceStatus() { return ContractInvoiceStatus; } public void setContractInvoiceStatus(String contractInvoiceStatus) { ContractInvoiceStatus = contractInvoiceStatus; } public String getReceiptList() { return ReceiptList; } public void setReceiptList(String receiptList) { ReceiptList = receiptList; } /** * 资金计划开票/暂不开票申请 * @param tx * @return * @throws Exception */ public String submitOrNoInvoiceFundPlanInvoice(JBOTransaction tx) throws Exception{ BizObjectManager lfiiManager = JBOFactory.getBizObjectManager(LI_FUND_INVOICE_INFO.CLASS_NAME); BizObjectManager lfpManager= JBOFactory.getBizObjectManager(LC_FUND_PLAN.CLASS_NAME); BizObjectManager lcitManager= JBOFactory.getBizObjectManager(LB_CONTRACT_INVOICE_TYPE.CLASS_NAME); tx.join(lfiiManager); tx.join(lfpManager); tx.join(lcitManager); String[] fundPlanIds = PlanList.split("@"); for(int i=0;i planIncomeIdList = new ArrayList(); for(int i=0;i checkInvoiceList= (List)invoiceManager.createQuery("SELECT DISTINCT O.customername,O.customer_id FROM O WHERE O.id IN ("+planIncomeIdStr+")").getResultList(false); if(checkInvoiceList!=null &&checkInvoiceList.size()>1){ return "选择的不是同一个客户!"; }else if(checkInvoiceList!=null &&checkInvoiceList.size()==1){ customerid = checkInvoiceList.get(0).getAttribute("customer_id").toString(); customerName = checkInvoiceList.get(0).getAttribute("customername").toString(); }else{ return "ERROR[02]"; } String confirmId=UUID.randomUUID().toString().replaceAll("-", ""); Double hjje =0.00; Double hjse = 0.00; Double jshj = 0.00; List confirmDetailList = new ArrayList(); DecimalFormat df2 = new DecimalFormat(".00"); DecimalFormat df6 = new DecimalFormat(".000000"); BizObjectManager invoiceFundManager = JBOFactory.getBizObjectManager(LI_FUND_INVOICE_INFO.CLASS_NAME); BizObjectManager invoiceRentManager = JBOFactory.getBizObjectManager(LI_RENT_INVOICE_INFO.CLASS_NAME); Double sl = 0.06; for(int i=0;i0){ BizObjectManager confirmManager = JBOFactory.getBizObjectManager(LI_INVOICE_CONFIRM.CLASS_NAME); tx.join(confirmManager); BizObject confirmBizObject = confirmManager.newObject(); String ownId = ownAccount.getAttribute("own_id").toString(); BizObjectManager ownInfoManager = JBOFactory.getBizObjectManager(OWN_INFO.CLASS_NAME); BizObject ownInfo = ownInfoManager.createQuery("OWN_NUMBER=:OWN_NUMBER").setParameter("OWN_NUMBER", ownId).getSingleResult(false); String xhdwdzdh = ownInfo.getAttribute("LEASE_TEL").toString(); BizObjectManager customerPersonManager = JBOFactory.getBizObjectManager(CUSTOMER_PERSON.CLASS_NAME); BizObjectManager customerCompanyManager = JBOFactory.getBizObjectManager(CUSTOMER_COMPANY.CLASS_NAME); BizObject customerPerson = customerPersonManager.createQuery("SELECT o.certid,caa.fulladdress,o.mobile,ca.acc_number,ca.bank_name from o JOIN jbo.app.tenwa.customer.CUSTOMER_ACCOUNT ca ON ca.customerid=o.customerid JOIN jbo.app.tenwa.customer.CUSTOMER_ADDRESS caa ON caa.customerid=ca.customerid where o.customerid=:customerid") .setParameter("customerid", customerid).getSingleResult(false); BizObject customerCompany = customerCompanyManager.createQuery("customerid=:customerid").setParameter("customerid", customerid).getSingleResult(false); String companyTel=""; if(customerCompany!=null){ companyTel = customerCompany.getAttribute("company_tel").toString(); } String certid=""; String fulladdress=""; String mobile=""; String acc_number=""; String bank_name=""; String acc_bank=""; String address_tel=""; if(customerPerson!=null){ certid=customerPerson.getAttribute("certid").toString(); fulladdress=customerPerson.getAttribute("fulladdress").toString(); mobile=customerPerson.getAttribute("mobile").toString(); acc_number=customerPerson.getAttribute("acc_number").toString(); bank_name=customerPerson.getAttribute("bank_name").toString(); acc_bank = "["+bank_name+"]["+acc_number+"]"; address_tel = "["+mobile+"]["+fulladdress+"]"; } BizObjectManager contractInfoManager = JBOFactory.getBizObjectManager(LB_CONTRACT_INFO.CLASS_NAME); BizObject contractInfo = contractInfoManager.createQuery("SELECT o.leas_form,lul.customer_id,ci.customertype FROM o JOIN jbo.com.tenwa.lease.comm.LB_UNION_LESSEE lul ON o.id=lul.contract_id JOIN jbo.app.tenwa.customer.CUSTOMER_INFO ci ON ci.customerid=lul.customer_id WHERE O.businesstype='1' AND lul.customer_id=:customerid").setParameter("customerid",customerid).getSingleResult(false); String customertype = contractInfo.getAttribute("customertype").toString(); BizObjectManager userInfoManager = JBOFactory.getBizObjectManager(USER_INFO.CLASS_NAME); BizObject userInfo = userInfoManager.createQuery("userid=:userid").setParameter("userid", CurUserID).getSingleResult(false); String username=userInfo.getAttribute("username").toString(); confirmBizObject.setAttributeValue("id", confirmId); confirmBizObject.setAttributeValue("sid", PasswordGenerateUtil.getRandom(64, PasswordGenerateUtil.TYPE.LETTER_CAPITAL)); confirmBizObject.setAttributeValue("yylxdm", "1"); confirmBizObject.setAttributeValue("fplxdm", "026"); confirmBizObject.setAttributeValue("kplx", "0"); confirmBizObject.setAttributeValue("tspz", "00"); confirmBizObject.setAttributeValue("xhdwdzdh", xhdwdzdh); confirmBizObject.setAttributeValue("xhdwyhzh", ownAccount.getAttribute("acc_number").toString()); confirmBizObject.setAttributeValue("ghdwsbh", certid); confirmBizObject.setAttributeValue("ghdwmc", customerName); confirmBizObject.setAttributeValue("ghdwdzdh", address_tel); confirmBizObject.setAttributeValue("ghdwyhzh", acc_bank); confirmBizObject.setAttributeValue("hsslbs", "0"); confirmBizObject.setAttributeValue("zhsl", ""); confirmBizObject.setAttributeValue("hjje", hjje); confirmBizObject.setAttributeValue("hjse", hjse); confirmBizObject.setAttributeValue("jshj", MathUtil.add( hjje,hjse )); confirmBizObject.setAttributeValue("fhr", ""); confirmBizObject.setAttributeValue("kpr", username); confirmBizObject.setAttributeValue("zyspmc", ""); confirmBizObject.setAttributeValue("spsm", ""); confirmBizObject.setAttributeValue("ssyf", ""); confirmBizObject.setAttributeValue("tzdbh", ""); confirmBizObject.setAttributeValue("yfpdm", ""); confirmBizObject.setAttributeValue("yfphm", ""); confirmBizObject.setAttributeValue("GMF_DZYX", ""); if(customertype=="01"){ confirmBizObject.setAttributeValue("GMF_SJHM", companyTel); }else{ confirmBizObject.setAttributeValue("GMF_SJHM", mobile); } confirmBizObject.setAttributeValue("GMF_OPENID", ""); confirmBizObject = this.initTabeUserInfo(confirmBizObject); confirmManager.saveObject(confirmBizObject); InvoiceRequest invoiceRequest = new InvoiceRequest(); ResultPojo result = invoiceRequest.send(confirmBizObject,confirmDetailList); if(result.getCode()==0){ InvoiceRequestBase responseBase = (InvoiceRequestBase) result.getData(); String returncode = responseBase.getBody().getReturncode(); String returnmsg = responseBase.getBody().getReturnmsg(); System.out.println("[OK][returncode]=>>>"+returncode); System.out.println("[OK][returnmsg]=>>>"+returnmsg); if("0".equals(returncode)){ System.out.println("[OK][SUCCESS]"); /*for(BizObject confirmDetailBizObject : confirmDetailList){ String invoiceId = confirmDetailBizObject.getAttribute("invoice_id").toString(); String invoice_type = confirmDetailBizObject.getAttribute("invoice_type").toString(); if("fund".equals(invoice_type)){ //invoiceFundManager.createQuery("update o set INVOICE_STATUS=:invoicestatus where ID=:id ").setParameter("id",invoiceId).setParameter("invoicestatus","3").executeUpdate(); }else{ //invoiceRentManager.createQuery("update o set INVOICE_STATUS=:invoicestatus where ID=:id ").setParameter("id",invoiceId).setParameter("invoicestatus","3").executeUpdate(); } }*/ return "开票申请成功"; }else{ return returnmsg; } }else{ System.out.println("[FAIL]=>>>"+result.getMsg()); return result.getMsg(); } }else{ return "操作失败!"; } } public String selectConfirm(JBOTransaction tx) throws JBOException{ Configure config = Configure.getInstance(); String INVOICE_LOCAL_PATH=""; try { INVOICE_LOCAL_PATH = config.getConfigure("INVOICE_LOCAL_PATH"); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); return "a3web->[INVOICE_LOCAL_PATH]不存在"; } String sid = this.getSid(); InvoiceRequestBase invoiceRequestBase = new InvoiceRequestBase(); InvoiceRequestHead invoiceRequestHead = new InvoiceRequestHead(); invoiceRequestHead.setAppid(this.appId); invoiceRequestHead.setSid(sid); invoiceRequestBase.setHead(invoiceRequestHead); invoiceRequestBase.setComment("查询开票结果"); invoiceRequestBase.setId("CXKPJG"); invoiceRequestBase.setVersion("1.0"); String xml = JaxbUtil.convertToXml(invoiceRequestBase); ResultPojo result = doPost(xml); BizObjectManager confirmManager = JBOFactory.getBizObjectManager(LI_INVOICE_CONFIRM.CLASS_NAME); BizObject confirm = confirmManager.createQuery("sid=:sid").setParameter("sid", sid).getSingleResult(false); String invoice_confirm_id = confirm.getAttribute("id").toString(); String id=UUID.randomUUID().toString().replaceAll("-", ""); if(result.getCode()==0){ InvoiceRequestBase responseBase = (InvoiceRequestBase) result.getData(); String returncode = responseBase.getBody().getReturncode(); String returnmsg = responseBase.getBody().getReturnmsg(); String fplxdm = responseBase.getBody().getFplxdm(); String fpdm = responseBase.getBody().getFpdm(); String fphm = responseBase.getBody().getFphm(); String kprq = responseBase.getBody().getKprq(); String hjje = responseBase.getBody().getHjje(); String skm = responseBase.getBody().getSkm(); String jym = responseBase.getBody().getJym(); String pdfurl = ""; String localFile = ""; String path=""; if("0".equals(returncode)){ pdfurl = responseBase.getBody().getPdfurl(); SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd"); String ydm = dateFormat.format(new Date()); path = File.separator + ydm.substring(0, 4)+File.separator + ydm.substring(4, 6)+File.separator + ydm.substring(6, 8); path = path+File.separator+PasswordGenerateUtil.getRandom(50, PasswordGenerateUtil.TYPE.LETTER_CAPITAL)+".pdf"; localFile = INVOICE_LOCAL_PATH+path; try { DownloadPdfUtil.go(pdfurl,localFile); } catch (Exception e) { e.printStackTrace(); return "下载PDF失败"; } } try { path = SecurityUtil.encrypt(path, "invoice"); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } BizObjectManager confirmResultManager = JBOFactory.getBizObjectManager(LI_INVOICE_RESULT.CLASS_NAME); BizObject confirmResult = confirmResultManager.createQuery("sid=:sid").setParameter("sid", sid).getSingleResult(false); if(confirmResult==null){ BizObject confirmResultNew = confirmResultManager.newObject(); confirmResultNew.setAttributeValue("ID",id); confirmResultNew.setAttributeValue("sid",sid); confirmResultNew.setAttributeValue("fplxdm",fplxdm); confirmResultNew.setAttributeValue("fpdm",fpdm ); confirmResultNew.setAttributeValue("fphm",fphm); confirmResultNew.setAttributeValue("kprq",kprq); confirmResultNew.setAttributeValue("hjje",hjje); confirmResultNew.setAttributeValue("skm",skm); confirmResultNew.setAttributeValue("jym",jym); confirmResultNew.setAttributeValue("pdfurl",pdfurl); confirmResultNew.setAttributeValue("localFile",path ); confirmResultNew.setAttributeValue("returncode",returncode); confirmResultNew.setAttributeValue("returnmsg",returnmsg); confirmResultManager.saveObject(confirmResultNew); }else{ confirmResultManager.createQuery("update o set fplxdm=:fplxdm,fpdm=:fpdm,fphm=:fphm,kprq=:kprq,hjje=:hjje,skm=:skm,jym=:jym,pdfurl=:pdfurl,localFile=:localFile,returncode=:returncode,returnmsg=:returnmsg where sid=:sid ") .setParameter("sid",sid).setParameter("fplxdm","fplxdm") .setParameter("fpdm",fpdm).setParameter("fphm","fphm") .setParameter("kprq",kprq).setParameter("hjje","hjje") .setParameter("skm",skm).setParameter("jym","jym") .setParameter("pdfurl",pdfurl).setParameter("localFile","localFile") .setParameter("returncode",returncode).setParameter("returnmsg","returnmsg") .executeUpdate(); } System.out.println("[OK][returncode]=>>>"+returncode); System.out.println("[OK][returnmsg]=>>>"+returnmsg); if("0".equals(returncode)){ //System.out.println("[OK][SUCCESS]"); // BizObjectManager confirmDetailManager = JBOFactory.getBizObjectManager(LI_INVOICE_CONFIRM_DETAIL.CLASS_NAME); //BizObject confirmDetail = confirmDetailManager.createQuery("invoice_confirm_id=:invoice_confirm_id").setParameter("invoice_confirm_id", invoice_confirm_id).getSingleResult(false); //String invoiceId = confirmDetail.getAttribute("invoice_id").toString(); // String invoice_type = confirmDetail.getAttribute("invoice_type").toString(); //if("fund".equals(invoice_type)){ //invoiceFundManager.createQuery("update o set INVOICE_STATUS=:invoicestatus where ID=:id ").setParameter("id",invoiceId).setParameter("invoicestatus","5").executeUpdate(); //}else{ //invoiceRentManager.createQuery("update o set INVOICE_STATUS=:invoicestatus where ID=:id ").setParameter("id",invoiceId).setParameter("invoicestatus","5").executeUpdate(); //} return "开票申请成功"; }else{ return returnmsg; } }else{ System.out.println("[FAIL]=>>>"+result.getMsg()); return result.getMsg(); } /* if(result.getCode().toString()!="0"){ return "查询失败"; } System.out.println("result=>>>"+JSONObject.toJSONString(result)); showResult(result); return "查询成功";*/ } public ResultPojo doPost(String xml){ HttpHeaders httpHeaders = new HttpHeaders(); MultiValueMap param = new LinkedMultiValueMap<>(); httpHeaders.setContentType(MediaType.APPLICATION_FORM_URLENCODED); param.add("bw",xml) ; RestTemplate restTemplate = new RestTemplate(); HttpEntity> entity = new HttpEntity<>(param, httpHeaders); ResponseEntity response = null ; try { response = restTemplate.exchange(this.url, HttpMethod.POST, entity, String.class); }catch (Exception e){ return ResultUtil.error(ResponseEnum.NETWORK.getMsg()); } System.out.println(response.getBody()); InvoiceRequestBase r = JaxbUtil.converyToJavaBean(response.getBody(), InvoiceRequestBase.class); return ResultUtil.success(r); } private void showResult(ResultPojo result) { if(result.getCode()==0){ InvoiceRequestBase responseBase = (InvoiceRequestBase) result.getData(); String returncode = responseBase.getBody().getReturncode(); String returnmsg = responseBase.getBody().getReturnmsg(); System.out.println("[OK][returncode]=>>>"+returncode); System.out.println("[OK][returnmsg]=>>>"+returnmsg); if("0".equals(returncode)){ System.out.println("[OK][SUCCESS]"); } }else{ System.out.println("[FAIL]=>>>"+result.getMsg()); } } /** * 退回开票申请 * @param tx * @return * @throws Exception */ public String backInvoice(JBOTransaction tx) throws Exception{ BizObjectManager lriiManager = JBOFactory.getBizObjectManager(LI_RENT_INVOICE_INFO.CLASS_NAME); BizObjectManager lfiiManager = JBOFactory.getBizObjectManager(LI_FUND_INVOICE_INFO.CLASS_NAME); tx.join(lriiManager); tx.join(lfiiManager); String[] planIncomeIds = PlanIncomeList.split("@"); for(int i=0;i