认领处理单-ESB接口开发-父子页面传参
This commit is contained in:
		
							parent
							
								
									38448475e7
								
							
						
					
					
						commit
						c96f8ebe30
					
				|  | @ -0,0 +1,137 @@ | ||||||
|  | package shjh.jhzj7.fi.fi.plugin.form; | ||||||
|  | 
 | ||||||
|  | import kd.bos.dataentity.entity.DynamicObjectCollection; | ||||||
|  | import kd.bos.entity.datamodel.IDataModel; | ||||||
|  | import kd.bos.form.CloseCallBack; | ||||||
|  | import kd.bos.form.FormShowParameter; | ||||||
|  | import kd.bos.form.ShowType; | ||||||
|  | import kd.bos.form.control.Toolbar; | ||||||
|  | import kd.bos.form.control.events.ItemClickEvent; | ||||||
|  | import kd.bos.form.events.ClosedCallBackEvent; | ||||||
|  | import kd.bos.form.plugin.AbstractFormPlugin; | ||||||
|  | import kd.bos.logging.Log; | ||||||
|  | import kd.bos.logging.LogFactory; | ||||||
|  | import kd.sdk.plugin.Plugin; | ||||||
|  | import shjh.jhzj7.fi.fi.plugin.form.info.ClaimFieldsInfo; | ||||||
|  | 
 | ||||||
|  | import java.util.EventObject; | ||||||
|  | import java.util.HashMap; | ||||||
|  | 
 | ||||||
|  | /** | ||||||
|  |  * 动态表单插件-【认领处理单】 | ||||||
|  |  * | ||||||
|  |  * @author LiGuiQiang | ||||||
|  |  */ | ||||||
|  | public class ClaimBillButtonAssPlugin extends AbstractFormPlugin implements Plugin { | ||||||
|  | 
 | ||||||
|  |     private final static Log logger = LogFactory.getLog(ClaimBillButtonAssPlugin.class); | ||||||
|  |     private static final String FEE_CONTROL = "shjh_fkbill"; | ||||||
|  |     private static final String KEY_PAYMENT = "assPayment"; | ||||||
|  |     private static final String KEY_LOAN = "assLoan"; | ||||||
|  | 
 | ||||||
|  |     @Override | ||||||
|  |     public void registerListener(EventObject e) { | ||||||
|  |         super.registerListener(e); | ||||||
|  |         Toolbar toolbar = getControl("tbmain"); | ||||||
|  |         toolbar.addItemClickListener(this); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     @Override | ||||||
|  |     public void itemClick(ItemClickEvent evt) { | ||||||
|  |         try { | ||||||
|  |             if (evt.getItemKey().equals(ClaimFieldsInfo.ASS_PAYMENT)) { | ||||||
|  |                 FormShowParameter showParameter = createFormParameter("paymentApi"); | ||||||
|  |                 this.getView().showForm(showParameter); | ||||||
|  |             } else if (evt.getItemKey().equals(ClaimFieldsInfo.ASS_LOAN)) { | ||||||
|  |                 FormShowParameter showParameter = createFormParameter("loanApi"); | ||||||
|  |                 this.getView().showForm(showParameter); | ||||||
|  |             } | ||||||
|  |         } catch (Exception e) { | ||||||
|  |             logger.error("认领处理单异常:"+e.getMessage(),e); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     private FormShowParameter createFormParameter(String apiKey) { | ||||||
|  |         HashMap<String, Object> map = new HashMap<>(2); | ||||||
|  |         map.put("Apikey",apiKey); | ||||||
|  |         map.put("billNumber",this.getModel().getValue("claimno")); | ||||||
|  |         FormShowParameter showParameter = new FormShowParameter(); | ||||||
|  |         showParameter.setFormId(FEE_CONTROL); | ||||||
|  |         showParameter.getOpenStyle().setShowType(ShowType.Modal); | ||||||
|  |         showParameter.setCustomParams(map); | ||||||
|  |         showParameter.setCloseCallBack(new CloseCallBack(this, "paymentApi".equals(apiKey) ? KEY_PAYMENT : KEY_LOAN)); | ||||||
|  |         return showParameter; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     @Override | ||||||
|  |     public void closedCallBack(ClosedCallBackEvent e) { | ||||||
|  |         super.closedCallBack(e); | ||||||
|  |         try { | ||||||
|  |             String callBackId = e.getActionId(); | ||||||
|  |             if (KEY_PAYMENT.equals(callBackId)) { | ||||||
|  |                 handleReturnData(e, ClaimFieldsInfo.PREPAYMENT_NUMBER, "paymentApi"); | ||||||
|  |             } else if (KEY_LOAN.equals(callBackId)) { | ||||||
|  |                 handleReturnData(e, ClaimFieldsInfo.LOAN_NUMBER, "loanApi"); | ||||||
|  |             } | ||||||
|  |         } catch (Exception ex) { | ||||||
|  |             logger.error("认领处理单回调子页面参数异常:"+ex.getMessage(),ex); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     private void handleReturnData(ClosedCallBackEvent e, String uniqueField, String apiKey) { | ||||||
|  |         DynamicObjectCollection returnData = (DynamicObjectCollection) e.getReturnData(); | ||||||
|  |         if (null != returnData && returnData.size() > 0) { | ||||||
|  |             DynamicObjectCollection entry = this.getModel().getEntryEntity(ClaimFieldsInfo.ENTRY); | ||||||
|  |             if (null != entry) { | ||||||
|  |                 for (int i = 0; i < returnData.size(); i++) { | ||||||
|  |                     String uniqueValue = returnData.get(i).getString(uniqueField); | ||||||
|  |                     boolean exists = false; | ||||||
|  |                     for (int j = 0; j < entry.size(); j++) { | ||||||
|  |                         String entryUniqueValue = entry.get(j).getString(uniqueField); | ||||||
|  |                         if (uniqueValue.equals(entryUniqueValue)) { | ||||||
|  |                             exists = true; | ||||||
|  |                             break; | ||||||
|  |                         } | ||||||
|  |                     } | ||||||
|  | 
 | ||||||
|  |                     // 如果已存在,则跳过该条数据 | ||||||
|  |                     if (exists) { | ||||||
|  |                         continue; | ||||||
|  |                     } | ||||||
|  | 
 | ||||||
|  |                     int rows = returnData.size() - entry.size(); | ||||||
|  |                     if (rows > 0) { | ||||||
|  |                         IDataModel model = this.getModel(); | ||||||
|  |                         model.batchCreateNewEntryRow(ClaimFieldsInfo.ENTRY, rows); | ||||||
|  |                     } | ||||||
|  | 
 | ||||||
|  |                     // 根据apiKey判断需要填充的字段 | ||||||
|  |                     if ("paymentApi".equals(apiKey)) { | ||||||
|  |                         setPaymentValues(returnData, i); | ||||||
|  |                     } else if ("loanApi".equals(apiKey)) { | ||||||
|  |                         setLoanValues(returnData, i); | ||||||
|  |                     } | ||||||
|  | 
 | ||||||
|  |                     this.getView().updateView(ClaimFieldsInfo.ENTRY); | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     private void setPaymentValues(DynamicObjectCollection returnData, int i) { | ||||||
|  |         this.getModel().setValue(ClaimFieldsInfo.PREPAYMENT_NUMBER, returnData.get(i).getString(ClaimFieldsInfo.PREPAYMENT_NUMBER), i); | ||||||
|  |         this.getModel().setValue(ClaimFieldsInfo.BILL_SUBJECT, returnData.get(i).getString(ClaimFieldsInfo.BILL_SUBJECT), i); | ||||||
|  |         this.getModel().setValue(ClaimFieldsInfo.PREPAYMENT_DATE, returnData.get(i).getDate(ClaimFieldsInfo.PREPAYMENT_DATE), i); | ||||||
|  |         this.getModel().setValue(ClaimFieldsInfo.PAYMENT_AMOUNT, returnData.get(i).getBigDecimal(ClaimFieldsInfo.PAYMENT_AMOUNT), i); | ||||||
|  |         this.getModel().setValue(ClaimFieldsInfo.DOCUMENT_AMOUNT, returnData.get(i).getBigDecimal(ClaimFieldsInfo.DOCUMENT_AMOUNT), i); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     private void setLoanValues(DynamicObjectCollection returnData, int i) { | ||||||
|  |         this.getModel().setValue(ClaimFieldsInfo.LOAN_NUMBER, returnData.get(i).getString(ClaimFieldsInfo.LOAN_NUMBER), i); | ||||||
|  |         this.getModel().setValue(ClaimFieldsInfo.LOAN_AMOUNT, returnData.get(i).getBigDecimal(ClaimFieldsInfo.LOAN_AMOUNT), i); | ||||||
|  |         this.getModel().setValue(ClaimFieldsInfo.LOAN_BALANCE, returnData.get(i).getBigDecimal(ClaimFieldsInfo.LOAN_BALANCE), i); | ||||||
|  |         this.getModel().setValue(ClaimFieldsInfo.VERIFICATION_NUMBER, returnData.get(i).getString(ClaimFieldsInfo.VERIFICATION_NUMBER), i); | ||||||
|  |         this.getModel().setValue(ClaimFieldsInfo.FISCAL_YEAR, returnData.get(i).getString(ClaimFieldsInfo.FISCAL_YEAR), i); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  | } | ||||||
|  | @ -1,11 +1,14 @@ | ||||||
| package shjh.jhzj7.fi.fi.plugin.form; | package shjh.jhzj7.fi.fi.plugin.form; | ||||||
| 
 | 
 | ||||||
|  | import kd.bos.context.RequestContext; | ||||||
| import kd.bos.dataentity.entity.DynamicObject; | import kd.bos.dataentity.entity.DynamicObject; | ||||||
| import kd.bos.dataentity.entity.DynamicObjectCollection; | import kd.bos.dataentity.entity.DynamicObjectCollection; | ||||||
| import kd.bos.dataentity.utils.StringUtils; | import kd.bos.dataentity.utils.StringUtils; | ||||||
| import kd.bos.entity.datamodel.events.PropertyChangedArgs; | import kd.bos.entity.datamodel.events.PropertyChangedArgs; | ||||||
| import kd.bos.form.field.ComboEdit; | import kd.bos.form.field.ComboEdit; | ||||||
| import kd.bos.form.plugin.AbstractFormPlugin; | import kd.bos.form.plugin.AbstractFormPlugin; | ||||||
|  | import kd.bos.servicehelper.BusinessDataServiceHelper; | ||||||
|  | import kd.bos.servicehelper.user.UserServiceHelper; | ||||||
| import kd.sdk.plugin.Plugin; | import kd.sdk.plugin.Plugin; | ||||||
| import shjh.jhzj7.fi.fi.plugin.form.info.ClaimFieldsInfo; | import shjh.jhzj7.fi.fi.plugin.form.info.ClaimFieldsInfo; | ||||||
| 
 | 
 | ||||||
|  | @ -27,7 +30,10 @@ public class ClaimBillFormPlugin extends AbstractFormPlugin implements Plugin { | ||||||
|         this.getView().setVisible(false,ClaimFieldsInfo.REPAYMENT_METHOD); |         this.getView().setVisible(false,ClaimFieldsInfo.REPAYMENT_METHOD); | ||||||
|         this.getView().setVisible(false,ClaimFieldsInfo.CUSTOMER_SPLIT); |         this.getView().setVisible(false,ClaimFieldsInfo.CUSTOMER_SPLIT); | ||||||
|         this.getView().setVisible(false,ClaimFieldsInfo.ENTRY_CUSTOMER); |         this.getView().setVisible(false,ClaimFieldsInfo.ENTRY_CUSTOMER); | ||||||
|  |         this.getView().setVisible(false,ClaimFieldsInfo.ASS_PAYMENT); | ||||||
|  |         this.getView().setVisible(false,ClaimFieldsInfo.ASS_LOAN); | ||||||
|         hideEntryFields(); |         hideEntryFields(); | ||||||
|  |         initShowFields(); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     @Override |     @Override | ||||||
|  | @ -43,32 +49,47 @@ public class ClaimBillFormPlugin extends AbstractFormPlugin implements Plugin { | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     private void initShowFields(){ | ||||||
|  |         DynamicObject receivingType = (DynamicObject) this.getModel().getValue(ClaimFieldsInfo.RECEIVING_TYPE); | ||||||
|  |         if (null!=receivingType){ | ||||||
|  |             String number = receivingType.getString("number"); | ||||||
|  |             if (null!=number){ | ||||||
|  |                 showFieldsByType(number); | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|     private void handleReceivingTypeChange() { |     private void handleReceivingTypeChange() { | ||||||
|         DynamicObject receivingType = (DynamicObject) this.getModel().getValue(ClaimFieldsInfo.RECEIVING_TYPE); |         DynamicObject receivingType = (DynamicObject) this.getModel().getValue(ClaimFieldsInfo.RECEIVING_TYPE); | ||||||
|         if (null!=receivingType){ |         if (null!=receivingType){ | ||||||
|             String number = receivingType.getString("number"); |             String number = receivingType.getString("number"); | ||||||
|             if (null!=number){ |             if (null!=number){ | ||||||
|                 clearFields(); |                 clearFields(); | ||||||
|                 switch (number) { |                 showFieldsByType(number); | ||||||
|                     case "100": |  | ||||||
|                         showTopFieldsBySale(); |  | ||||||
|                         break; |  | ||||||
|                     case "103": |  | ||||||
|                         showCostCenter(); |  | ||||||
|                         showRefundMethods(); |  | ||||||
|                         showEntryFieldsByRefund(); |  | ||||||
|                         break; |  | ||||||
|                     case "109": |  | ||||||
|                         showCostCenter(); |  | ||||||
|                         showRepaymentMethod(); |  | ||||||
|                         showEntryFieldsByEmployee(); |  | ||||||
|                         break; |  | ||||||
|                     default: |  | ||||||
|                         break; |  | ||||||
|                 } |  | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|  |     } | ||||||
| 
 | 
 | ||||||
|  |     private void showFieldsByType(String number){ | ||||||
|  |         switch (number) { | ||||||
|  |             case "100": | ||||||
|  |                 showTopFieldsBySale(); | ||||||
|  |                 break; | ||||||
|  |             case "103": | ||||||
|  |                 showPaymentButton(); | ||||||
|  |                 showCostCenter(); | ||||||
|  |                 showRefundMethods(); | ||||||
|  |                 showEntryFieldsByRefund(); | ||||||
|  |                 break; | ||||||
|  |             case "109": | ||||||
|  |                 showLoanButton(); | ||||||
|  |                 showCostCenter(); | ||||||
|  |                 showRepaymentMethod(); | ||||||
|  |                 showEntryFieldsByEmployee(); | ||||||
|  |                 break; | ||||||
|  |             default: | ||||||
|  |                 break; | ||||||
|  |         } | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     private void handleRefundMethodsChange() { |     private void handleRefundMethodsChange() { | ||||||
|  | @ -98,9 +119,20 @@ public class ClaimBillFormPlugin extends AbstractFormPlugin implements Plugin { | ||||||
|         this.getView().setVisible(true, ClaimFieldsInfo.CUSTOMER_SPLIT); |         this.getView().setVisible(true, ClaimFieldsInfo.CUSTOMER_SPLIT); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     private void showPaymentButton(){ this.getView().setVisible(true,ClaimFieldsInfo.ASS_PAYMENT);} | ||||||
|  | 
 | ||||||
|  |     private void showLoanButton(){ this.getView().setVisible(true,ClaimFieldsInfo.ASS_LOAN);} | ||||||
| 
 | 
 | ||||||
|     private void showCostCenter() { |     private void showCostCenter() { | ||||||
|         this.getView().setVisible(true, ClaimFieldsInfo.COST_CENTER); |         this.getView().setVisible(true, ClaimFieldsInfo.COST_CENTER); | ||||||
|  |         long currentUserId = UserServiceHelper.getCurrentUserId(); | ||||||
|  |         DynamicObject user = BusinessDataServiceHelper.loadSingle(currentUserId, "bos_user"); | ||||||
|  |         if (null!=user){ | ||||||
|  |             DynamicObject userCostCenter = user.getDynamicObject(ClaimFieldsInfo.USER_COST_CENTER); | ||||||
|  |             if (null!=userCostCenter){ | ||||||
|  |                 this.getModel().setValue(ClaimFieldsInfo.COST_CENTER,userCostCenter); | ||||||
|  |             } | ||||||
|  |         } | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     private void showRefundMethods() { |     private void showRefundMethods() { | ||||||
|  | @ -147,6 +179,8 @@ public class ClaimBillFormPlugin extends AbstractFormPlugin implements Plugin { | ||||||
|         this.getView().setVisible(false, ClaimFieldsInfo.REPAYMENT_METHOD); |         this.getView().setVisible(false, ClaimFieldsInfo.REPAYMENT_METHOD); | ||||||
|         this.getModel().setValue(ClaimFieldsInfo.CUSTOMER_SPLIT, null); |         this.getModel().setValue(ClaimFieldsInfo.CUSTOMER_SPLIT, null); | ||||||
|         this.getView().setVisible(false, ClaimFieldsInfo.CUSTOMER_SPLIT); |         this.getView().setVisible(false, ClaimFieldsInfo.CUSTOMER_SPLIT); | ||||||
|  |         this.getView().setVisible(false,ClaimFieldsInfo.ASS_PAYMENT); | ||||||
|  |         this.getView().setVisible(false,ClaimFieldsInfo.ASS_LOAN); | ||||||
|         DynamicObjectCollection entry = this.getModel().getEntryEntity(ClaimFieldsInfo.ENTRY); |         DynamicObjectCollection entry = this.getModel().getEntryEntity(ClaimFieldsInfo.ENTRY); | ||||||
|         if (null!=entry){ |         if (null!=entry){ | ||||||
|             hideEntryFields(); |             hideEntryFields(); | ||||||
|  |  | ||||||
|  | @ -0,0 +1,413 @@ | ||||||
|  | package shjh.jhzj7.fi.fi.plugin.form; | ||||||
|  | 
 | ||||||
|  | import com.alibaba.fastjson.JSONArray; | ||||||
|  | import com.alibaba.fastjson.JSONObject; | ||||||
|  | import kd.bos.dataentity.entity.DynamicObject; | ||||||
|  | import kd.bos.dataentity.entity.DynamicObjectCollection; | ||||||
|  | import kd.bos.dataentity.utils.StringUtils; | ||||||
|  | import kd.bos.form.FormShowParameter; | ||||||
|  | import kd.bos.form.ShowType; | ||||||
|  | import kd.bos.form.control.Button; | ||||||
|  | import kd.bos.form.control.Control; | ||||||
|  | import kd.bos.form.control.EntryGrid; | ||||||
|  | import kd.bos.form.control.Toolbar; | ||||||
|  | import kd.bos.form.control.events.ItemClickEvent; | ||||||
|  | import kd.bos.form.events.AfterDoOperationEventArgs; | ||||||
|  | import kd.bos.form.events.BeforeClosedEvent; | ||||||
|  | import kd.bos.form.operate.FormOperate; | ||||||
|  | import kd.bos.form.plugin.AbstractFormPlugin; | ||||||
|  | import kd.bos.logging.Log; | ||||||
|  | import kd.bos.logging.LogFactory; | ||||||
|  | import kd.bos.servicehelper.user.UserServiceHelper; | ||||||
|  | import kd.sdk.plugin.Plugin; | ||||||
|  | import shjh.jhzj7.fi.fi.plugin.form.info.ClaimFieldsInfo; | ||||||
|  | import shjh.jhzj7.fi.fi.utils.ApiUtils; | ||||||
|  | import shjh.jhzj7.fi.fi.utils.EsbUtils; | ||||||
|  | 
 | ||||||
|  | import java.util.*; | ||||||
|  | 
 | ||||||
|  | /** | ||||||
|  |  * 动态表单插件-【收款处理单关联表单】 | ||||||
|  |  * | ||||||
|  |  * @author LiGuiQiang | ||||||
|  |  */ | ||||||
|  | public class FeeControlApiPlugin extends AbstractFormPlugin implements Plugin { | ||||||
|  |     private final static Log logger = LogFactory.getLog(FeeControlApiPlugin.class); | ||||||
|  |     private static final DynamicObjectCollection PARAM_LIST = new DynamicObjectCollection(); | ||||||
|  |     private static final String QUERY_BUTTON_KEY="shjh_btnquery"; | ||||||
|  |     private static final String SELECTED_BUTTON_KEY="shjh_btnok"; | ||||||
|  |     private static final String ENTRY_KEY = "shjh_entryentity"; | ||||||
|  |     private static final String PAYMENT_API="paymentApi"; | ||||||
|  |     private static final String LOAN_API="loanApi"; | ||||||
|  | 
 | ||||||
|  |     @Override | ||||||
|  |     public void registerListener(EventObject e) { | ||||||
|  |         super.registerListener(e); | ||||||
|  |         Button queryButton = this.getView().getControl(QUERY_BUTTON_KEY); | ||||||
|  |         Button selectedButton = this.getView().getControl(SELECTED_BUTTON_KEY); | ||||||
|  |         queryButton.addClickListener(this); | ||||||
|  |         selectedButton.addClickListener(this); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     @Override | ||||||
|  |     public void afterBindData(EventObject e) { | ||||||
|  |         super.afterBindData(e); | ||||||
|  |         FormShowParameter showParameter = this.getView().getFormShowParameter(); | ||||||
|  |         String apiKey = showParameter.getCustomParam("Apikey"); | ||||||
|  |         if (LOAN_API.equals(apiKey)){ | ||||||
|  |             this.getView().setVisible(false,"shjh_supplier"); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     @Override | ||||||
|  |     public void click(EventObject evt) { | ||||||
|  |         try { | ||||||
|  |             // 校验和获取过滤条件 | ||||||
|  |             DynamicObject org = (DynamicObject) this.getModel().getValue("shjh_orgfield"); | ||||||
|  |             if (org == null) { | ||||||
|  |                 this.getView().showMessage("请选择公司!"); | ||||||
|  |                 return; | ||||||
|  |             } | ||||||
|  | 
 | ||||||
|  |             Date startDate = (Date) this.getModel().getValue("shjh_startdate"); | ||||||
|  |             if (startDate == null) { | ||||||
|  |                 this.getView().showMessage("请选择开始日期!"); | ||||||
|  |                 return; | ||||||
|  |             } | ||||||
|  | 
 | ||||||
|  |             Date endDate = (Date) this.getModel().getValue("shjh_enddate"); | ||||||
|  |             if (endDate == null) { | ||||||
|  |                 this.getView().showMessage("请选择结束日期!"); | ||||||
|  |                 return; | ||||||
|  |             } | ||||||
|  | 
 | ||||||
|  |             String companyCode = org.getString("number"); | ||||||
|  | 
 | ||||||
|  |             Control source = (Control) evt.getSource(); | ||||||
|  |             String key = source.getKey(); | ||||||
|  | 
 | ||||||
|  |             // 点击查询按钮 | ||||||
|  |             if (StringUtils.equals(QUERY_BUTTON_KEY, key)) { | ||||||
|  |                 handleQueryButtonClick(companyCode, startDate, endDate); | ||||||
|  |             } | ||||||
|  |             // 点击选择按钮 | ||||||
|  |             else if (StringUtils.equals(SELECTED_BUTTON_KEY, key)) { | ||||||
|  |                 handleSelectedButton(); | ||||||
|  |             } | ||||||
|  |         } catch (Exception e) { | ||||||
|  |             logger.error("Error in click method: " + e.getMessage(), e); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     private void handleQueryButtonClick(String companyCode, Date startDate, Date endDate) { | ||||||
|  |         try { | ||||||
|  |             FormShowParameter showParameter = this.getView().getFormShowParameter(); | ||||||
|  |             String apiKey = showParameter.getCustomParam("Apikey"); | ||||||
|  |             String billNumber = showParameter.getCustomParam("billNumber"); | ||||||
|  | 
 | ||||||
|  |             if (StringUtils.equals(PAYMENT_API, apiKey)) { | ||||||
|  |                 handlePaymentApi(companyCode, startDate, endDate, billNumber); | ||||||
|  |             } else if (StringUtils.equals(LOAN_API, apiKey)) { | ||||||
|  |                 handleLoanApi(companyCode, startDate, endDate, billNumber); | ||||||
|  |             } | ||||||
|  | 
 | ||||||
|  |             this.getView().updateView(ENTRY_KEY); | ||||||
|  | 
 | ||||||
|  |         } catch (Exception e) { | ||||||
|  |             logger.error("Error in handleQueryButtonClick: " + e.getMessage(), e); | ||||||
|  |             this.getView().showMessage("查询操作失败,请稍后再试!"); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     private void handlePaymentApi(String companyCode, Date startDate, Date endDate, String billNumber) { | ||||||
|  |         try { | ||||||
|  |             DynamicObject supplier = (DynamicObject) this.getModel().getValue("shjh_supplier"); | ||||||
|  |             if (supplier == null) { | ||||||
|  |                 this.getView().showMessage("请选择供应商!"); | ||||||
|  |                 return; | ||||||
|  |             } | ||||||
|  |             String supplierCode = supplier.getString("number"); | ||||||
|  | 
 | ||||||
|  |             HashMap<String, String> head = ApiUtils.buildHead(); | ||||||
|  |             HashMap<String, Object> body = ApiUtils.buildBody(companyCode, this.getUserCode(), startDate.toString(), endDate.toString()); | ||||||
|  |             HashMap<String, Object> data = (HashMap<String, Object>) body.get("data"); | ||||||
|  | 
 | ||||||
|  |             // 添加额外的参数 | ||||||
|  |             data.put("SupplierCode", supplierCode); | ||||||
|  |             data.put("IsWriteOffDetail", true); | ||||||
|  | 
 | ||||||
|  |             //String response = ApiUtils.sendPost(head, body, "预付款清单接口地址", billNumber, "预付款清单接口", "Query"); | ||||||
|  |             //handlePaymentApiResponse(response); | ||||||
|  |             handlePaymentApiResponse(); | ||||||
|  |         } catch (Exception e) { | ||||||
|  |             logger.error("Error in handlePaymentApi: " + e.getMessage(), e); | ||||||
|  |             this.getView().showMessage("处理预付款清单接口时发生错误!"); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     private void handleLoanApi(String companyCode, Date startDate, Date endDate, String billNumber) { | ||||||
|  |         try { | ||||||
|  |             HashMap<String, String> head = ApiUtils.buildHead(); | ||||||
|  |             HashMap<String, Object> body = ApiUtils.buildBody(companyCode, this.getUserCode(), startDate.toString(), endDate.toString()); | ||||||
|  |             //String response = ApiUtils.sendPost(head, body, "借款单清单接口地址", billNumber, "借款单清单接口", "Query"); | ||||||
|  |             //handleLoanApiResponse(response); | ||||||
|  |             handleLoanApiResponse(); | ||||||
|  |         } catch (Exception e) { | ||||||
|  |             logger.error("Error in handleLoanApi: " + e.getMessage(), e); | ||||||
|  |             this.getView().showMessage("处理借款单清单接口时发生错误!"); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     private void handlePaymentApiResponse() { | ||||||
|  |         try { | ||||||
|  |             hideLoanFields(); | ||||||
|  |             //获取测试数据 | ||||||
|  |             String response = getPaymentApiResponse(); | ||||||
|  |             JSONObject root = JSONObject.parseObject(response); | ||||||
|  |             JSONObject data = root.getJSONObject("data"); | ||||||
|  |             JSONArray rows = data.getJSONArray("rows"); | ||||||
|  |             DynamicObjectCollection entry = this.getModel().getEntryEntity(ENTRY_KEY); | ||||||
|  |             entry.clear(); | ||||||
|  |             for (int i = 0; i < rows.size(); i++) { | ||||||
|  |                 JSONObject top = (JSONObject) rows.get(i); | ||||||
|  |                 JSONArray loanDetailInfo = top.getJSONArray("LoanDetailInfo"); | ||||||
|  |                 JSONObject detail = (JSONObject) loanDetailInfo.get(0); | ||||||
|  |                 entry.addNew(); | ||||||
|  |                 setPaymentApiValues(top, detail, i); | ||||||
|  |             } | ||||||
|  |         } catch (Exception e) { | ||||||
|  |             logger.error("预付单数据解析异常: " + e.getMessage(), e); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     private String getPaymentApiResponse() { | ||||||
|  |         return "{\n" + | ||||||
|  |                 "  \"rootContextID\": \"8as6dfasd6f98as7d6f9a98sd76f\",\n" + | ||||||
|  |                 "  \"code\": \"0\",\n" + | ||||||
|  |                 "  \"msg\": \"成功\",\n" + | ||||||
|  |                 "  \"data\": {\n" + | ||||||
|  |                 "    \"total\": 2,\n" + | ||||||
|  |                 "    \"rows\": [\n" + | ||||||
|  |                 "      {\n" + | ||||||
|  |                 "        \"ID\": \"fc7443ac-9f85-4d17-a7ee-5620330f28a6\",\n" + | ||||||
|  |                 "        \"RequestCode\": \"YFK2025010900001\",\n" + | ||||||
|  |                 "        \"RequestAmt\": 111,\n" + | ||||||
|  |                 "        \"RequestDate\": \"2025-01-09 11:29:22\",\n" + | ||||||
|  |                 "        \"GLDate\": \"2025-01-14 00:00:00\",\n" + | ||||||
|  |                 "        \"RequestUserName\": \"余超\",\n" + | ||||||
|  |                 "        \"AvailableAmt\": 111,\n" + | ||||||
|  |                 "        \"SupplierId\": 89948,\n" + | ||||||
|  |                 "        \"SupplierId_Name\": \"品销宝\",\n" + | ||||||
|  |                 "        \"CompanyCode\": \"C021\",\n" + | ||||||
|  |                 "        \"CompanyName\": \"上海家化电子商务有限公司\",\n" + | ||||||
|  |                 "        \"RequestRemark\": \"测试\",\n" + | ||||||
|  |                 "        \"LoanDetailInfo\": [\n" + | ||||||
|  |                 "          {\n" + | ||||||
|  |                 "            \"BillHeaderID\": \"fc7443ac-9f85-4d17-a7ee-5620330f28a6\",\n" + | ||||||
|  |                 "            \"PoOrderNo\": null,\n" + | ||||||
|  |                 "            \"PoOrderColNo\": null,\n" + | ||||||
|  |                 "            \"DetailID\": \"d7bc66bf-11e7-4ef5-9d98-80881c1caff7\",\n" + | ||||||
|  |                 "            \"ApplyAmt\": 111,\n" + | ||||||
|  |                 "            \"ThisAmt\": null,\n" + | ||||||
|  |                 "            \"AvailableAmt\": 111,\n" + | ||||||
|  |                 "            \"RequestCode\": \"YFK2025010900001\",\n" + | ||||||
|  |                 "            \"RequestName\": \"2025-01-09对公预付款单\",\n" + | ||||||
|  |                 "            \"RequestAmt\": 111,\n" + | ||||||
|  |                 "            \"InitialAmount\": 111,\n" + | ||||||
|  |                 "            \"Remark\": \"测试\",\n" + | ||||||
|  |                 "            \"CreatedDate\": \"2025-01-09 11:29:11\",\n" + | ||||||
|  |                 "            \"ExpenseItemName\": \"会务费\",\n" + | ||||||
|  |                 "            \"CurrencyId\": 10510,\n" + | ||||||
|  |                 "            \"BillAvailableAmt\": 111\n" + | ||||||
|  |                 "          }\n" + | ||||||
|  |                 "        ]\n" + | ||||||
|  |                 "      },\n" + | ||||||
|  |                 "      {\n" + | ||||||
|  |                 "        \"ID\": \"fc7443ac-9f65-4d17-a7ee-5620330f28a6\",\n" + | ||||||
|  |                 "        \"RequestCode\": \"YFK2025010900002\",\n" + | ||||||
|  |                 "        \"RequestAmt\": 100,\n" + | ||||||
|  |                 "        \"RequestDate\": \"2025-02-18 11:29:22\",\n" + | ||||||
|  |                 "        \"GLDate\": \"2025-01-14 00:00:00\",\n" + | ||||||
|  |                 "        \"RequestUserName\": \"余超\",\n" + | ||||||
|  |                 "        \"AvailableAmt\": 100,\n" + | ||||||
|  |                 "        \"SupplierId\": 89949,\n" + | ||||||
|  |                 "        \"SupplierId_Name\": \"雀氏\",\n" + | ||||||
|  |                 "        \"CompanyCode\": \"C021\",\n" + | ||||||
|  |                 "        \"CompanyName\": \"上海家化电子商务有限公司\",\n" + | ||||||
|  |                 "        \"RequestRemark\": \"测试\",\n" + | ||||||
|  |                 "        \"LoanDetailInfo\": [\n" + | ||||||
|  |                 "          {\n" + | ||||||
|  |                 "            \"BillHeaderID\": \"fc7443ac-9f65-4d17-a7ee-5620330f28a6\",\n" + | ||||||
|  |                 "            \"PoOrderNo\": null,\n" + | ||||||
|  |                 "            \"PoOrderColNo\": null,\n" + | ||||||
|  |                 "            \"DetailID\": \"d7bc66bf-11e7-4ef5-9d98-80881c1caff3\",\n" + | ||||||
|  |                 "            \"ApplyAmt\": 100,\n" + | ||||||
|  |                 "            \"ThisAmt\": null,\n" + | ||||||
|  |                 "            \"AvailableAmt\": 100,\n" + | ||||||
|  |                 "            \"RequestCode\": \"YFK2025010900002\",\n" + | ||||||
|  |                 "            \"RequestName\": \"2025-02-18对公预付款单\",\n" + | ||||||
|  |                 "            \"RequestAmt\": 100,\n" + | ||||||
|  |                 "            \"InitialAmount\": 100,\n" + | ||||||
|  |                 "            \"Remark\": \"测试\",\n" + | ||||||
|  |                 "            \"CreatedDate\": \"2025-02-18 11:29:11\",\n" + | ||||||
|  |                 "            \"ExpenseItemName\": \"会务费\",\n" + | ||||||
|  |                 "            \"CurrencyId\": 10511,\n" + | ||||||
|  |                 "            \"BillAvailableAmt\": 100\n" + | ||||||
|  |                 "          }\n" + | ||||||
|  |                 "        ]\n" + | ||||||
|  |                 "      }\n" + | ||||||
|  |                 "    ]\n" + | ||||||
|  |                 "  }\n" + | ||||||
|  |                 "}\n"; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     private void setPaymentApiValues(JSONObject top, JSONObject detail, int i) { | ||||||
|  |         try { | ||||||
|  |             this.getModel().setValue("shjh_billno", top.getString("CompanyCode"), i); | ||||||
|  |             this.getModel().setValue("shjh_prepaymentnum", top.getString("RequestCode"), i); | ||||||
|  |             this.getModel().setValue("shjh_billsubject", detail.getString("RequestName"), i); | ||||||
|  |             this.getModel().setValue("shjh_prepaymentdate", detail.getDate("CreatedDate"), i); | ||||||
|  |             this.getModel().setValue("shjh_paymentamount", top.getBigDecimal("RequestAmt"), i); | ||||||
|  |             this.getModel().setValue("shjh_documentamount", top.getBigDecimal("AvailableAmt"), i); | ||||||
|  |             this.getModel().setValue("shjh_fiscalyear", top.getString("GLDate").substring(0, 4), i); | ||||||
|  |         } catch (Exception e) { | ||||||
|  |             logger.error("预付单赋值异常: " + e.getMessage(), e); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     private void handleLoanApiResponse() { | ||||||
|  |         try { | ||||||
|  |             hidePaymentFields(); | ||||||
|  |             String response = getLoanApiResponse(); | ||||||
|  |             JSONObject root = JSONObject.parseObject(response); | ||||||
|  |             JSONObject data = root.getJSONObject("data"); | ||||||
|  |             JSONArray rows = data.getJSONArray("rows"); | ||||||
|  |             DynamicObjectCollection entry = this.getModel().getEntryEntity(ENTRY_KEY); | ||||||
|  |             entry.clear(); | ||||||
|  |             for (int i = 0; i < rows.size(); i++) { | ||||||
|  |                 JSONObject top = (JSONObject) rows.get(i); | ||||||
|  |                 entry.addNew(); | ||||||
|  |                 setLoanApiValues(top, i); | ||||||
|  |             } | ||||||
|  |         } catch (Exception e) { | ||||||
|  |             logger.error("借款单数据解析异常: " + e.getMessage(), e); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     private String getLoanApiResponse() { | ||||||
|  | 
 | ||||||
|  |         return "{\n" + | ||||||
|  |                 "  \"rootContextID\": \"8as6dfasd6f98as7d6f9a98sd76f\",\n" + | ||||||
|  |                 "  \"code\": \"0\",\n" + | ||||||
|  |                 "  \"msg\": \"成功\",\n" + | ||||||
|  |                 "  \"data\": {\n" + | ||||||
|  |                 "    \"total\": 1,\n" + | ||||||
|  |                 "    \"rows\": [\n" + | ||||||
|  |                 "      {\n" + | ||||||
|  |                 "        \"ID\": \"a50547a4-d661-486b-a5c0-adecdbe958b9\",\n" + | ||||||
|  |                 "        \"RequestCode\": \"JKY2025011400001\",\n" + | ||||||
|  |                 "        \"RequestName\": \"财务及分销系统余超2025-01-14员工借款单员工借款员工借款\",\n" + | ||||||
|  |                 "        \"RequestAmt\": 111,\n" + | ||||||
|  |                 "        \"RequestDate\": \"2025-01-14 14:57:13\",\n" + | ||||||
|  |                 "        \"GLDate\": \"2025-01-14 00:00:00\",\n" + | ||||||
|  |                 "        \"RequestUserName\": \"余超\",\n" + | ||||||
|  |                 "        \"AvailableAmt\": 111,\n" + | ||||||
|  |                 "        \"CurrencyName\": \"人民币\",\n" + | ||||||
|  |                 "        \"StrColumn6\": \"6217001180014130648\",\n" + | ||||||
|  |                 "        \"StrColumn7\": \"建设银行\",\n" + | ||||||
|  |                 "        \"CompanyCode\": \"C001\",\n" + | ||||||
|  |                 "        \"CompanyName\": \"上海家化联合股份有限公司\",\n" + | ||||||
|  |                 "        \"RequestRemark\": \"上传\",\n" + | ||||||
|  |                 "        \"StrColumn20\": \"1600000001\",\n" + | ||||||
|  |                 "        \"LoanDetailInfo\": null\n" + | ||||||
|  |                 "      }\n" + | ||||||
|  |                 "    ]\n" + | ||||||
|  |                 "  }\n" + | ||||||
|  |                 "}\n"; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     private void setLoanApiValues(JSONObject top, int i) { | ||||||
|  |         try { | ||||||
|  |             this.getModel().setValue("shjh_billno", top.getString("CompanyCode"), i); | ||||||
|  |             this.getModel().setValue("shjh_loannum", top.getString("RequestCode"), i); | ||||||
|  |             this.getModel().setValue("shjh_loanamount", top.getBigDecimal("RequestAmt"), i); | ||||||
|  |             this.getModel().setValue("shjh_loanbalance", top.getBigDecimal("AvailableAmt"), i); | ||||||
|  |             this.getModel().setValue("shjh_verificationnum", top.getString("StrColumn20"), i); | ||||||
|  |             this.getModel().setValue("shjh_fiscalyear", top.getString("GLDate").substring(0, 4), i); | ||||||
|  |         } catch (Exception e) { | ||||||
|  |             logger.error("借款单赋值异常: " + e.getMessage(), e); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     private void hidePaymentFields(){ | ||||||
|  |         this.getView().setVisible(false,"shjh_prepaymentnum"); | ||||||
|  |         this.getView().setVisible(false,"shjh_purchasenum"); | ||||||
|  |         this.getView().setVisible(false,"shjh_purchaselinenum"); | ||||||
|  |         this.getView().setVisible(false,"shjh_billsubject"); | ||||||
|  |         this.getView().setVisible(false,"shjh_prepaymentdate"); | ||||||
|  |         this.getView().setVisible(false,"shjh_paymentamount"); | ||||||
|  |         this.getView().setVisible(false,"shjh_documentamount"); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     private void hideLoanFields(){ | ||||||
|  |         this.getView().setVisible(false,"shjh_billno"); | ||||||
|  |         this.getView().setVisible(false,"shjh_loannum"); | ||||||
|  |         this.getView().setVisible(false,"shjh_loanamount"); | ||||||
|  |         this.getView().setVisible(false,"shjh_loanbalance"); | ||||||
|  |     } | ||||||
|  |     private void handleSelectedButton() { | ||||||
|  |         try { | ||||||
|  |             PARAM_LIST.clear(); | ||||||
|  |             EntryGrid entryGrid = this.getControl(ENTRY_KEY); | ||||||
|  |             int[] selectRows = entryGrid.getSelectRows(); | ||||||
|  |             DynamicObjectCollection entity = this.getModel().getEntryEntity(ENTRY_KEY); | ||||||
|  |             if (selectRows != null && selectRows.length > 0) { | ||||||
|  |                 for (int selectRow : selectRows) { | ||||||
|  |                     DynamicObject dynamicObject = entity.get(selectRow); | ||||||
|  |                     PARAM_LIST.add(dynamicObject); | ||||||
|  |                 } | ||||||
|  |                 this.getView().close(); | ||||||
|  |             } else { | ||||||
|  |                 this.getView().showMessage("请选中一条数据!"); | ||||||
|  |             } | ||||||
|  |         } catch (Exception e) { | ||||||
|  |             logger.error("传递参数异常: " + e.getMessage(), e); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |         @Override | ||||||
|  |         public void beforeClosed (BeforeClosedEvent e){ | ||||||
|  |             super.beforeClosed(e); | ||||||
|  |             this.getView().returnDataToParent(PARAM_LIST); | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |     public String getUserCode() { | ||||||
|  |         String number = null; | ||||||
|  |         try { | ||||||
|  |             Long userId = UserServiceHelper.getCurrentUserId(); | ||||||
|  |             ArrayList<Long> list = new ArrayList<>(); | ||||||
|  |             list.add(userId); | ||||||
|  | 
 | ||||||
|  |             // 获取用户信息 | ||||||
|  |             List<Map<String, Object>> userMaps = UserServiceHelper.get(list); | ||||||
|  |             if (userMaps != null && !userMaps.isEmpty()) { | ||||||
|  |                 // 取第一个用户的number,假设每个用户只有一个number | ||||||
|  |                 Map<String, Object> userMap = userMaps.get(0); | ||||||
|  |                 number = (String) userMap.get("number"); | ||||||
|  |             } | ||||||
|  | 
 | ||||||
|  |             // 如果number为空,则抛出异常 | ||||||
|  |             if (number == null || number.isEmpty()) { | ||||||
|  |                 throw new IllegalArgumentException("User number is null or empty"); | ||||||
|  |             } | ||||||
|  | 
 | ||||||
|  |         } catch (Exception e) { | ||||||
|  |             // 捕获异常并记录日志 | ||||||
|  |             logger.error("Error occurred while getting user code: ", e); | ||||||
|  |             // 根据需求,可以选择重新抛出异常或者返回默认值 | ||||||
|  |             throw new RuntimeException("Failed to get user code", e); | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         return number; | ||||||
|  |     } | ||||||
|  |     } | ||||||
|  | @ -65,4 +65,10 @@ public class ClaimFieldsInfo { | ||||||
|      * Entry:应收金额 |      * Entry:应收金额 | ||||||
|      */ |      */ | ||||||
|     public static final String RECEIVABLE_AMOUNT = "e_receivableamt"; |     public static final String RECEIVABLE_AMOUNT = "e_receivableamt"; | ||||||
|  | 
 | ||||||
|  |     public static final String ASS_PAYMENT = "shjh_asspayment"; | ||||||
|  | 
 | ||||||
|  |     public static final String ASS_LOAN= "shjh_assloan"; | ||||||
|  | 
 | ||||||
|  |     public static final String USER_COST_CENTER= "shjh_fycc"; | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -0,0 +1,92 @@ | ||||||
|  | package shjh.jhzj7.fi.fi.utils; | ||||||
|  | 
 | ||||||
|  | import com.alibaba.fastjson.JSON; | ||||||
|  | import kd.bos.logging.Log; | ||||||
|  | import kd.bos.logging.LogFactory; | ||||||
|  | import org.apache.http.HttpResponse; | ||||||
|  | import org.apache.http.client.methods.HttpPost; | ||||||
|  | import org.apache.http.entity.StringEntity; | ||||||
|  | import org.apache.http.impl.client.CloseableHttpClient; | ||||||
|  | import org.apache.http.impl.client.HttpClients; | ||||||
|  | import org.apache.http.util.EntityUtils; | ||||||
|  | 
 | ||||||
|  | import java.io.IOException; | ||||||
|  | import java.text.SimpleDateFormat; | ||||||
|  | import java.util.Date; | ||||||
|  | import java.util.HashMap; | ||||||
|  | import java.util.UUID; | ||||||
|  | 
 | ||||||
|  | /** | ||||||
|  |  * @author LiGuiQiang | ||||||
|  |  */ | ||||||
|  | public class ApiUtils { | ||||||
|  | 
 | ||||||
|  |     static Log log = LogFactory.getLog(ApiUtils.class); | ||||||
|  | 
 | ||||||
|  |     public static HashMap<String,String> buildHead(){ | ||||||
|  |         HashMap<String,String> header = new HashMap<>(5); | ||||||
|  |         header.put("Content-Type","application/json;charset=UTF-8"); | ||||||
|  |         header.put("x-Gateway-APIKey","207b5296-9866-4b4b-8146-1fea58b3c8c9"); | ||||||
|  |         header.put("interfaceID","FMGetJahYFKList"); | ||||||
|  |         header.put("receiverID","FeiKong"); | ||||||
|  |         return header; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     public static HashMap<String,Object> buildBody(String companyCode,String userCode,String queryBeginDate,String queryEndDate){ | ||||||
|  |         // 生成唯一事务ID | ||||||
|  |         String rootContextId = UUID.randomUUID().toString(); | ||||||
|  |         // 获取当前请求时间,格式为 yyyy-MM-dd HH:mm:ss.SSS | ||||||
|  |         SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS"); | ||||||
|  |         String requestTime = sdf.format(new Date()); | ||||||
|  |         HashMap<String,Object> body = new HashMap<>(5); | ||||||
|  |         body.put("rootContextID",rootContextId); | ||||||
|  |         body.put("requestTime",requestTime); | ||||||
|  |         HashMap<String,Object> data = new HashMap<>(10); | ||||||
|  |         data.put("UserCode",userCode); | ||||||
|  |         data.put("QueryBeginDate",queryBeginDate); | ||||||
|  |         data.put("QueryEndDate",queryEndDate); | ||||||
|  |         data.put("page","1"); | ||||||
|  |         data.put("rows","10"); | ||||||
|  |         data.put("CompanyCode",companyCode); | ||||||
|  |         body.put("data",data); | ||||||
|  |         return body; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * 调接口 | ||||||
|  |      * @param header | ||||||
|  |      * @param body | ||||||
|  |      * @param url | ||||||
|  |      * @return | ||||||
|  |      * @throws IOException | ||||||
|  |      */ | ||||||
|  |     public static String sendPost(HashMap header, HashMap body, String url ,String billNumber,String api,String processName) throws IOException { | ||||||
|  |         String responseData = ""; | ||||||
|  |         // 准备要发送的 JSON 数据 | ||||||
|  |         // 使用 FastJSON 将 Map 转换为 JSON 字符串 | ||||||
|  |         String jsonString = JSON.toJSONString(body); | ||||||
|  |         CloseableHttpClient httpClient = HttpClients.createDefault(); | ||||||
|  |         // 创建 HttpPost 请求 | ||||||
|  |         HttpPost httpPost = new HttpPost(url); | ||||||
|  |         // 设置请求头 | ||||||
|  |         for (Object o : header.keySet()) { | ||||||
|  |             httpPost.setHeader((String) o, (String) header.get(o)); | ||||||
|  |         } | ||||||
|  |         // 设置请求体 | ||||||
|  |         StringEntity jsonEntity = new StringEntity(jsonString,"UTF-8"); | ||||||
|  |         httpPost.setEntity(jsonEntity); | ||||||
|  |         // 发送请求并获取响应 | ||||||
|  |         HttpResponse response = httpClient.execute(httpPost); | ||||||
|  |         // 检查响应状态 | ||||||
|  |         if (response.getStatusLine().getStatusCode() == 200) { | ||||||
|  |             // 获取响应数据 | ||||||
|  |             responseData = EntityUtils.toString(response.getEntity()); | ||||||
|  |             log.info("SendPost,Response: " + responseData); | ||||||
|  |             EsbUtils.saveLog(billNumber,api,httpPost.toString(),response.toString(),true,processName); | ||||||
|  |         } else { | ||||||
|  |             log.info("SendPost,Error: " + response.getStatusLine().getStatusCode()); | ||||||
|  |             EsbUtils.saveLog(billNumber,api,httpPost.toString(),response.toString(),false,processName); | ||||||
|  |         } | ||||||
|  |         return responseData; | ||||||
|  |     } | ||||||
|  | } | ||||||
		Loading…
	
		Reference in New Issue