1.ut优化
2.推送费控字段确认,以及成功返回方式 3.锁定解锁接口id有校验,字段确认, 4.凭证查询接口字段确认 5.源单是费控,不允许拆分和合并(依据) 6.接口返回值 7.排程校验 --s
This commit is contained in:
		
							parent
							
								
									f72ae66203
								
							
						
					
					
						commit
						690e630150
					
				|  | @ -110,20 +110,21 @@ public class SappzFormPlugin extends AbstractFormPlugin { | |||
| //                                size = 5000; | ||||
| //                            } | ||||
|                             for (int i = 0; i < IT_ITEMs.size(); i++) { | ||||
|                                 JSONObject it_list = (JSONObject)IT_ITEMs.get(i); | ||||
| //                            for (int i = 0; i < IT_ITEMs.size(); i++) { | ||||
|                                 JSONObject it_list = (JSONObject) IT_ITEMs.get(i); | ||||
|                                 DynamicObject add = shjhEntryentity.addNew(); | ||||
|                                 this.getModel().setValue("shjh_orgnumber", it_list.getString("BUKRS"), i);//公司编号,"公司代码 | ||||
|                                 this.getModel().setValue("shjh_vouchernumber", it_list.getString("BELNR"), i);//凭证号,会计凭证编号 | ||||
|                                 this.getModel().setValue("shjh_accountingyear", it_list.getString("GJAHR"), i);//会计年度,会计年度 | ||||
|                                 this.getModel().setValue("shjh_accountingsubject", it_list.getString("SAKNR"), i);//todo:会计科目:1001,总帐科目编号 | ||||
|                                 this.getModel().setValue("shjh_accountingsubject", it_list.getString("SAKNR"), i);//会计科目:1001,总帐科目编号 | ||||
|                                 this.getModel().setValue("shjh_accountingsubjecline", it_list.getString("EBELP"), i);//会计科目行项目号,采购凭证的项目编号 | ||||
|                                 this.getModel().setValue("shjh_outstandingamount",  new BigDecimal(it_list.getString("WRBTR")), i);//未清金额,凭证货币金额 | ||||
|                                 this.getModel().setValue("shjh_outstandingamount", new BigDecimal(it_list.getString("WRBTR")), i);//未清金额,凭证货币金额 | ||||
|                                 BigDecimal KURSF = new BigDecimal(it_list.getString("KURSF")); | ||||
|                                 if (KURSF.compareTo(BigDecimal.ZERO) == 0) { | ||||
|                                     KURSF = BigDecimal.ONE; | ||||
|                                 } | ||||
|                                 this.getModel().setValue("shjh_exchangerate",KURSF, i);//汇率 | ||||
|                                 this.getModel().setValue("shjh_applyforconversionof",new BigDecimal(it_list.getString("DMBTR")), i);//申请金额折结算币别,按本位币计的金额 | ||||
|                                 this.getModel().setValue("shjh_exchangerate", KURSF, i);//汇率 | ||||
|                                 this.getModel().setValue("shjh_applyforconversionof", new BigDecimal(it_list.getString("DMBTR")), i);//申请金额折结算币别,按本位币计的金额 | ||||
|                                 String FAEDT = it_list.getString("FAEDT"); | ||||
|                                 if (StringUtils.isNotEmpty(FAEDT)) { | ||||
|                                     Date date = StrToDate(FAEDT); | ||||
|  | @ -142,17 +143,17 @@ public class SappzFormPlugin extends AbstractFormPlugin { | |||
|                                 String ZFBDT = it_list.getString("ZFBDT"); | ||||
|                                 if (StringUtils.isNotEmpty(ZFBDT)) { | ||||
|                                     Date date = StrToDate(ZFBDT); | ||||
|                                      this.getModel().setValue("shjh_basedate", date, i);//基准日期,用于到期日计算的基准日期 | ||||
|                                     this.getModel().setValue("shjh_basedate", date, i);//基准日期,用于到期日计算的基准日期 | ||||
|                                 } | ||||
| //                                this.getModel().setValue("shjh_payee", "供应商", i);//todo:往来类型 | ||||
| //                                this.getModel().setValue("shjh_payeebanknum", it_list.getString("ZWLZH"), i);//todo:往来户名称 | ||||
|                                 this.getModel().setValue("shjh_payee", "供应商", i);//往来类型 | ||||
|                                 this.getModel().setValue("shjh_payeebanknum", "上海家化销售有限公司", i);//往来户名称 | ||||
|                                 this.getModel().setValue("shjh_description",it_list.getString("BVTYP") , i);//合作银行类型.合作银行类型 | ||||
|                                 this.getModel().setValue("shjh_description", it_list.getString("BVTYP"), i);//合作银行类型.合作银行类型 | ||||
|                                 this.getModel().setValue("shjh_reasoncode", "014", i);//todo:原因码 | ||||
|                                 this.getModel().setValue("shjh_classificationoffund", payablevouchernumber, i);//todo:资金计划分类 | ||||
|                                 this.getModel().setValue("shjh_secondarydept", it_list.getString("ZREQ_DEPT"), i);//二级部门,需求部门 | ||||
|                                 this.getModel().setValue("shjh_procurementeam",  it_list.getString("EKGRP"), i);//采购组 | ||||
|                                 this.getModel().setValue("shjh_procurementeam", it_list.getString("EKGRP"), i);//采购组 | ||||
|                                 this.getModel().setValue("shjh_isselfprocurment", it_list.getString("ZZXCG_FLAG"), i);//todo:是否自行采购 | ||||
|                                 this.getModel().setValue("shjh_paymentcurrency", it_list.getString("WAERS"), i);//付款币别编号CNY,货币码 | ||||
|                                 this.getModel().setValue("shjh_settlementcurrency", it_list.getString("WAERS"), i);//结算币别编号,货币码 | ||||
|  | @ -161,6 +162,8 @@ public class SappzFormPlugin extends AbstractFormPlugin { | |||
|                             this.getView().updateView("shjh_entryentity"); | ||||
|                         } | ||||
|                     } | ||||
|                 } else { | ||||
|                     this.getView().showMessage("查询失败:" + result.getString("msg")); | ||||
|                 } | ||||
|                 break; | ||||
|             case "confirm": | ||||
|  | @ -572,7 +575,7 @@ public class SappzFormPlugin extends AbstractFormPlugin { | |||
|     } | ||||
| 
 | ||||
| 
 | ||||
|     private Date StrToDate(String strDate){ | ||||
|     public static Date StrToDate(String strDate) { | ||||
|         SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); | ||||
|         try { | ||||
|             return sdf.parse(strDate); | ||||
|  | @ -621,7 +624,7 @@ public class SappzFormPlugin extends AbstractFormPlugin { | |||
|     } | ||||
| 
 | ||||
|     // 添加过滤条件到IT_LIST的方法 | ||||
|     private void addFilterCondition(JSONArray IT_LIST, String field, String low, String high) { | ||||
|     public static void addFilterCondition(JSONArray IT_LIST, String field, String low, String high) { | ||||
|         JSONObject jsonObject = new JSONObject(); | ||||
|         jsonObject.put("FIELD", field); // 字段 | ||||
|         jsonObject.put("SIGN", "I"); // I:包含 E:排除 | ||||
|  |  | |||
|  | @ -7,6 +7,7 @@ import kd.bos.dataentity.entity.DynamicObject; | |||
| import kd.bos.entity.operate.result.OperateErrorInfo; | ||||
| import kd.bos.entity.plugin.AbstractOperationServicePlugIn; | ||||
| import kd.bos.entity.plugin.args.BeforeOperationArgs; | ||||
| import kd.bos.servicehelper.BusinessDataServiceHelper; | ||||
| import kd.bos.servicehelper.operation.SaveServiceHelper; | ||||
| import kd.sdk.plugin.Plugin; | ||||
| 
 | ||||
|  | @ -23,20 +24,26 @@ public class PayApplyDeleteOperation extends AbstractOperationServicePlugIn impl | |||
|             //提交失败调取删除,删除判断单据状态暂存、来源系统sap、已锁定 才可以执行删除逻辑-->调解锁接口 | ||||
|             DynamicObject[] dataEntities = e.getDataEntities(); | ||||
|             for (DynamicObject bill : dataEntities) { | ||||
|                 bill = BusinessDataServiceHelper.loadSingle(bill.getPkValue(),"ap_payapply"); | ||||
|                 String billstatus = bill.getString("billstatus");//获取单据状态:暂存A | ||||
|                 String sourcesystem = bill.getString("shjh_sourcesystem");//来源系统:SAP_A | ||||
|                 boolean shjhSapwhetherlocking = bill.getBoolean("shjh_sapwhetherlocking");//SAP是否锁定:锁定 | ||||
|                 if ("A".equals(billstatus) && "A".equals(sourcesystem)) { | ||||
|                     if (!shjhSapwhetherlocking) { | ||||
|                         e.setCancel(true); | ||||
|                         return; | ||||
|                     } | ||||
| //                    if (!shjhSapwhetherlocking) { | ||||
| //                        OperateErrorInfo operateErrorInfo = new OperateErrorInfo(); | ||||
| //                        operateErrorInfo.setMessage("付款申请单:"+bill.getString("billno")+"状态解锁失败:SAP状态未锁定"); | ||||
| //                        operateErrorInfo.setErrorLevel(ErrorLevel.Error.name()); | ||||
| //                        operateErrorInfo.setPkValue(bill.getPkValue()); | ||||
| //                        this.operationResult.addErrorInfo(operateErrorInfo); | ||||
| //                        e.setCancel(true); | ||||
| //                        return; | ||||
| //                    } | ||||
|                     //调解锁接口 | ||||
|                     JSONArray IT_INPUT = new JSONArray(); | ||||
|                     JSONObject jsonObject = new JSONObject(); | ||||
|                     String FM_CompanyCode = ""; | ||||
|                     if (null!= bill.getDynamicObject("openorg")) { | ||||
|                         FM_CompanyCode = bill.getDynamicObject("openorg").getString("number");//公司编码_申请付款组织 | ||||
|                     if (null!= bill.getDynamicObject("applyorg")) { | ||||
|                         FM_CompanyCode = bill.getDynamicObject("applyorg").getString("number");//公司编码_申请付款组织 | ||||
|                     } | ||||
|                     jsonObject.put("bukrs",FM_CompanyCode);//公司代码_申请付款组织 | ||||
|                     jsonObject.put("belnr", bill.getString("shjh_vouchernum"));//会计凭证编号_SAP应付凭证号 | ||||
|  | @ -46,7 +53,8 @@ public class PayApplyDeleteOperation extends AbstractOperationServicePlugIn impl | |||
|                     if (null!= bill.getDynamicObject("creator")) { | ||||
|                         cname = bill.getDynamicObject("creator").getString("number");//创建人,工号_申请人 | ||||
|                     } | ||||
|                     jsonObject.put("cname", cname);//创建人,工号 | ||||
| //                    jsonObject.put("cname", cname);//创建人,工号 | ||||
|                     jsonObject.put("cname", "GH001657");//todo:创建人,工号 | ||||
|                     jsonObject.put("zjddjid", ""+bill.getPkValue());//金蝶单据ID | ||||
|                     jsonObject.put("zjddjbh", bill.getString("billno"));//金蝶单据编号 | ||||
|                     IT_INPUT.add(jsonObject); | ||||
|  |  | |||
|  | @ -7,6 +7,7 @@ import kd.bos.dataentity.entity.DynamicObject; | |||
| import kd.bos.entity.operate.result.OperateErrorInfo; | ||||
| import kd.bos.entity.plugin.AbstractOperationServicePlugIn; | ||||
| import kd.bos.entity.plugin.args.AfterOperationArgs; | ||||
| import kd.bos.servicehelper.BusinessDataServiceHelper; | ||||
| import kd.bos.servicehelper.operation.SaveServiceHelper; | ||||
| import kd.sdk.plugin.Plugin; | ||||
| 
 | ||||
|  | @ -24,26 +25,28 @@ public class PayApplySaveOperation extends AbstractOperationServicePlugIn implem | |||
|         //保存插件之后来源类型为sap且未锁定才去锁,并且更新状态 | ||||
|         DynamicObject[] dataEntities = e.getDataEntities(); | ||||
|         for (DynamicObject bill : dataEntities) { | ||||
|             bill = BusinessDataServiceHelper.loadSingle(bill.getPkValue(),"ap_payapply"); | ||||
|             String sourcesystem = bill.getString("shjh_sourcesystem");//来源系统:SAP | ||||
|             boolean shjhSapwhetherlocking = bill.getBoolean("shjh_sapwhetherlocking");//SAP是否锁定:未锁定 | ||||
|             if ("A".equals(sourcesystem) && !shjhSapwhetherlocking) { | ||||
|                 JSONArray IT_INPUT = new JSONArray(); | ||||
|                 JSONObject jsonObject = new JSONObject(); | ||||
|                 String FM_CompanyCode = ""; | ||||
|                 if (null!= bill.getDynamicObject("openorg")) { | ||||
|                     FM_CompanyCode = bill.getDynamicObject("openorg").getString("number");//公司编码_申请付款组织 | ||||
|                 if (null!= bill.getDynamicObject("applyorg")) { | ||||
|                     FM_CompanyCode = bill.getDynamicObject("applyorg").getString("number");//公司编码_申请付款组织 | ||||
|                 } | ||||
|                 jsonObject.put("bukrs",FM_CompanyCode);//公司代码_申请付款组织 | ||||
|                 jsonObject.put("belnr", bill.getString("shjh_vouchernum"));//会计凭证编号_SAP应付凭证号 | ||||
|                 jsonObject.put("gjahr", bill.getString("shjh_voucheryear"));//会计年度_SAP应付凭证会计年度 | ||||
|                 jsonObject.put("stasus", "01");//状态 01:锁定,02:解锁,03:关闭,04:退单:05:作废 | ||||
|                 jsonObject.put("BUKRS",FM_CompanyCode);//公司代码_申请付款组织 | ||||
|                 jsonObject.put("BELNR", bill.getString("shjh_vouchernum"));//会计凭证编号_SAP应付凭证号 | ||||
|                 jsonObject.put("GJAHR", bill.getString("shjh_voucheryear"));//会计年度_SAP应付凭证会计年度 | ||||
|                 jsonObject.put("STASUS", "01");//状态 01:锁定,02:解锁,03:关闭,04:退单:05:作废 | ||||
|                 String cname = ""; | ||||
|                 if (null!= bill.getDynamicObject("creator")) { | ||||
|                     cname = bill.getDynamicObject("creator").getString("number");//创建人,工号_申请人 | ||||
|                 } | ||||
|                 jsonObject.put("cname", cname);//创建人,工号 | ||||
|                 jsonObject.put("zjddjid", ""+bill.getPkValue());//金蝶单据ID | ||||
|                 jsonObject.put("zjddjbh", bill.getString("billno"));//金蝶单据编号 | ||||
| //                jsonObject.put("cname", cname);//todo:创建人,工号 | ||||
|                 jsonObject.put("CNAME", "GH001657");//todo:创建人,工号 | ||||
|                 jsonObject.put("ZJDDJID", ""+bill.getPkValue());//金蝶单据ID | ||||
|                 jsonObject.put("ZJDDJBH", bill.getString("billno"));//金蝶单据编号 | ||||
|                 IT_INPUT.add(jsonObject); | ||||
| 
 | ||||
|                 JSONObject jsonObjects = unlocked_status(IT_INPUT,bill.getString("billno")); | ||||
|  |  | |||
|  | @ -5,6 +5,7 @@ import kd.bos.entity.ExtendedDataEntity; | |||
| import kd.bos.entity.plugin.AbstractOperationServicePlugIn; | ||||
| import kd.bos.entity.plugin.AddValidatorsEventArgs; | ||||
| import kd.bos.entity.validate.AbstractValidator; | ||||
| import kd.bos.servicehelper.BusinessDataServiceHelper; | ||||
| import kd.sdk.plugin.Plugin; | ||||
| 
 | ||||
| public class PayApplySubmitOperation extends AbstractOperationServicePlugIn implements Plugin { | ||||
|  | @ -21,6 +22,7 @@ public class PayApplySubmitOperation extends AbstractOperationServicePlugIn impl | |||
|                     ExtendedDataEntity[] entities = this.getDataEntities(); | ||||
|                     for (ExtendedDataEntity entity : entities) { | ||||
|                         DynamicObject bill = entity.getDataEntity(); | ||||
|                         bill = BusinessDataServiceHelper.loadSingle(bill.getPkValue(),"ap_payapply"); | ||||
|                         String sourcesystem = bill.getString("shjh_sourcesystem");//来源系统:SAP_A | ||||
|                         boolean shjhSapwhetherlocking = bill.getBoolean("shjh_sapwhetherlocking");//SAP是否锁定:锁定 | ||||
|                         if ("A".equals(sourcesystem)) { | ||||
|  |  | |||
|  | @ -11,6 +11,7 @@ import kd.bos.entity.plugin.args.AfterOperationArgs; | |||
| import kd.bos.orm.query.QCP; | ||||
| import kd.bos.orm.query.QFilter; | ||||
| import kd.bos.servicehelper.BusinessDataServiceHelper; | ||||
| import kd.bos.servicehelper.operation.SaveServiceHelper; | ||||
| import kd.sdk.plugin.Plugin; | ||||
| 
 | ||||
| import java.time.LocalDate; | ||||
|  | @ -51,7 +52,8 @@ public class PaybillOperation extends AbstractOperationServicePlugIn implements | |||
|                     operateErrorInfo.setPkValue(bill.getPkValue()); | ||||
|                     this.operationResult.addErrorInfo(operateErrorInfo); | ||||
|                 }else { | ||||
|                     //todo:表头更新状态 | ||||
|                     bill.set("shjh_ispushfk",true); | ||||
|                     SaveServiceHelper.save(new DynamicObject[]{bill}); | ||||
|                     this.operationResult.addSuccessPkId(bill.getPkValue()); | ||||
|                 } | ||||
|             } | ||||
|  |  | |||
|  | @ -2,11 +2,14 @@ package shjh.jhzj7.fi.fi.plugin.task; | |||
| 
 | ||||
| import com.alibaba.fastjson.JSONArray; | ||||
| import com.alibaba.fastjson.JSONObject; | ||||
| import com.sap.db.jdbc.packet.ErrorLevel; | ||||
| import kd.bos.context.RequestContext; | ||||
| import kd.bos.dataentity.entity.DynamicObject; | ||||
| import kd.bos.entity.operate.result.OperateErrorInfo; | ||||
| import kd.bos.exception.KDException; | ||||
| import kd.bos.schedule.executor.AbstractTask; | ||||
| import kd.bos.servicehelper.BusinessDataServiceHelper; | ||||
| import kd.bos.servicehelper.operation.SaveServiceHelper; | ||||
| import kd.sdk.plugin.Plugin; | ||||
| 
 | ||||
| import java.util.Map; | ||||
|  | @ -28,8 +31,14 @@ public class PaybillPushFkTask extends AbstractTask implements Plugin { | |||
|             JSONArray body = buildBody(paybill); | ||||
|             data.put("header", header); | ||||
|             data.put("body", body); | ||||
|             withholding_billing(data, paybill.getString("billno")); | ||||
|             //todo:成功:表头更新状态 | ||||
|             JSONObject jsonObject = withholding_billing(data, paybill.getString("billno")); | ||||
|             String code = (String)jsonObject.get("code"); | ||||
|             if (!"0".equals(code)) { | ||||
|                 //todo:失败:记录错误信息 | ||||
|             }else { | ||||
|                 paybill.set("shjh_ispushfk",true); | ||||
|                 SaveServiceHelper.save(new DynamicObject[]{paybill}); | ||||
|             } | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  |  | |||
|  | @ -78,7 +78,7 @@ public class SapUtils { | |||
|         pendingsBody.put("requestTime", dates);//请求时间,格式为yyyy-MM-dd HH:mm:ss.SSS | ||||
| 
 | ||||
|         JSONObject data = new JSONObject(); | ||||
|         data.put("IT_INPUT",IT_INPUT); | ||||
|         data.put("IT_LIST",IT_INPUT); | ||||
|         pendingsBody.put("data", data); | ||||
|         return pendingsBody; | ||||
|     } | ||||
|  | @ -211,14 +211,14 @@ public class SapUtils { | |||
|                 String code = (String)jsonObject.get("code"); | ||||
|                 if (!"0".equals(code)) { | ||||
|                     logger.info(apiName +"失败!"); | ||||
|                     saveLog(apiName +(thirdPartyMap.get("billno").toString()), pendingsBody, jsonObject, false,apiName); | ||||
|                     saveLog( (thirdPartyMap.get("billno").toString()), pendingsBody, jsonObject, false,apiName); | ||||
|                     return jsonObject; | ||||
|                 } | ||||
|                 handleResponse(jsonObject, pendingsBody, thirdPartyMap,apiName); | ||||
|                 return com.alibaba.fastjson.JSONObject.parseObject(responseString); | ||||
|             }else { | ||||
|                 logger.info(apiName +"失败!"); | ||||
|                 saveLog(apiName +(thirdPartyMap.get("billno").toString()), pendingsBody, null, false,apiName); | ||||
|                 saveLog( (thirdPartyMap.get("billno").toString()), pendingsBody, null, false,apiName); | ||||
|             } | ||||
|         } catch (Exception e) { | ||||
|             handleException(e, pendingsBody, thirdPartyMap, jsonObject,apiName); | ||||
|  | @ -251,9 +251,9 @@ public class SapUtils { | |||
|     private static void handleResponse(JSONObject jsonObject, JSONObject pendingsBody, Map<String, Object> thirdPartyMap,String apiName) { | ||||
|         String operResult = jsonObject.getString("code"); | ||||
|         JSONObject jsonobject = jsonObject.getJSONObject("data"); | ||||
|         if (jsonobject == null || jsonobject.isEmpty()) { | ||||
|         if (jsonobject == null&&!"0".equals(operResult)) { | ||||
|             logger.info(apiName + "失败!"); | ||||
|             saveLog(apiName + (thirdPartyMap.get("billno").toString()), pendingsBody, jsonObject, false,apiName); | ||||
|             saveLog((thirdPartyMap.get("billno").toString()), pendingsBody, jsonObject, false,apiName); | ||||
|             return; | ||||
|         } | ||||
| 
 | ||||
|  | @ -261,7 +261,7 @@ public class SapUtils { | |||
| 
 | ||||
|         // 记录日志 | ||||
|         logger.info(logMessage); | ||||
|         saveLog(apiName + (thirdPartyMap.get("billno").toString()), pendingsBody, jsonObject, true,apiName); | ||||
|         saveLog((thirdPartyMap.get("billno").toString()), pendingsBody, jsonObject, true,apiName); | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|  | @ -276,7 +276,7 @@ public class SapUtils { | |||
|         // 记录异常信息 | ||||
|         String errorMessage = String.format(apiName +"状态回写接口异常:%s", e.getMessage()); | ||||
|         logger.error(errorMessage); | ||||
|         saveLog(apiName + thirdPartyMap.get("billno").toString(), pendingsBody, jsonObject, false,apiName); | ||||
|         saveLog(thirdPartyMap.get("billno").toString(), pendingsBody, jsonObject, false,apiName); | ||||
|         throw new RuntimeException(e); | ||||
|     } | ||||
| 
 | ||||
|  |  | |||
|  | @ -1,6 +1,7 @@ | |||
| package shjh.jhzj7.fi.fi.webapi; | ||||
| 
 | ||||
| import com.alibaba.fastjson.JSON; | ||||
| import com.alibaba.fastjson.JSONArray; | ||||
| import com.alibaba.fastjson.JSONException; | ||||
| import com.alibaba.fastjson.JSONObject; | ||||
| import com.drew.lang.annotations.NotNull; | ||||
|  | @ -9,6 +10,7 @@ import kd.bos.context.RequestContext; | |||
| import kd.bos.dataentity.OperateOption; | ||||
| import kd.bos.dataentity.entity.DynamicObject; | ||||
| import kd.bos.dataentity.entity.DynamicObjectCollection; | ||||
| import kd.bos.dataentity.utils.StringUtils; | ||||
| import kd.bos.entity.operate.OperateOptionConst; | ||||
| import kd.bos.entity.operate.result.OperateErrorInfo; | ||||
| import kd.bos.entity.operate.result.OperationResult; | ||||
|  | @ -31,11 +33,14 @@ import shjh.jhzj7.fi.fi.webapi.model.ApplyAdjustBillModel; | |||
| import javax.validation.Valid; | ||||
| import java.math.BigDecimal; | ||||
| import java.math.RoundingMode; | ||||
| import java.text.SimpleDateFormat; | ||||
| import java.util.Date; | ||||
| import java.util.HashMap; | ||||
| import java.util.Map; | ||||
| 
 | ||||
| import static shjh.jhzj7.fi.fi.plugin.form.SappzFormPlugin.BD_ACCOUNTVIEW; | ||||
| import static kd.bos.login.utils.DateUtils.formatDate; | ||||
| import static shjh.jhzj7.fi.fi.plugin.form.SappzFormPlugin.*; | ||||
| import static shjh.jhzj7.fi.fi.utils.SapUtils.vouchers_payable; | ||||
| import static shjh.jhzj7.fi.fi.webapi.ApplyBillControler.*; | ||||
| 
 | ||||
| /** | ||||
|  | @ -79,51 +84,59 @@ public class ApplyAdjustBillControler { | |||
| 
 | ||||
|         // 是否存在付款申请单? | ||||
|         if (ap_payapply == null) { | ||||
|             // todo:不存在,从SAP获取应付凭证,生成付款申请单 | ||||
|             ap_payapply = createOrUpdatePayApply(applyAdjustbill, companyNum, voucherNum, year, voucherLineNum, org, fkBillNum); | ||||
|             if (ap_payapply == null) { | ||||
|                 return CustomApiResult.fail("400", "创建或更新付款申请单失败,详情查看日志"); | ||||
|             } | ||||
|             log.info("不存在,从SAP获取应付凭证,生成付款申请单"); | ||||
|             JSONArray sappzs = querySapPz(applyAdjustbill); | ||||
|             if (null != sappzs) { | ||||
|                 log.info("SAP查询凭证接口存在凭证,准备生成付款申请单"); | ||||
|                 // 存在凭证,生成付款申请单 | ||||
|                 for (Object sappz : sappzs) { | ||||
|                     JSONObject it_list = (JSONObject) sappz; | ||||
|                     ap_payapply = createOrUpdatePayApply(it_list,fkBillNum); | ||||
|                     if (ap_payapply == null) { | ||||
|                         return CustomApiResult.fail("400", "创建或更新付款申请单失败,详情查看日志"); | ||||
|                     } | ||||
| 
 | ||||
|             // 将生成的付款申请单拆分明细 | ||||
|             BigDecimal amounts = applyAdjustbill.getAmount(); | ||||
|             if (amounts == null || amounts.toString().trim().isEmpty()) { | ||||
|                 return handleErrorAndReturn("同步失败, 调整单号:" + fkBillNum + "的调整金额为空", fkBillNum, null); | ||||
|             } | ||||
|             try { | ||||
|                 amounts = amounts.setScale(2, RoundingMode.HALF_UP); | ||||
|             } catch (NumberFormatException e) { | ||||
|                 return handleErrorAndReturn("同步失败, 调整单号:" + fkBillNum + "的金额格式不正确: " + amounts, fkBillNum, null); | ||||
|             } | ||||
|                     // 将生成的付款申请单拆分明细 | ||||
|                     BigDecimal amounts = applyAdjustbill.getAmount(); | ||||
|                     if (amounts == null || amounts.toString().trim().isEmpty()) { | ||||
|                         return handleErrorAndReturn("同步失败, 调整单号:" + fkBillNum + "的调整金额为空", fkBillNum, null); | ||||
|                     } | ||||
|                     try { | ||||
|                         amounts = amounts.setScale(2, RoundingMode.HALF_UP); | ||||
|                     } catch (NumberFormatException e) { | ||||
|                         return handleErrorAndReturn("同步失败, 调整单号:" + fkBillNum + "的金额格式不正确: " + amounts, fkBillNum, null); | ||||
|                     } | ||||
| 
 | ||||
|             DynamicObjectCollection collection = ap_payapply.getDynamicObjectCollection("entry"); | ||||
|             if (collection.isEmpty()) { | ||||
|                 return handleErrorAndReturn("同步失败, 调整单号:" + fkBillNum + "无明细信息", fkBillNum, null); | ||||
|             } | ||||
|                     DynamicObjectCollection collection = ap_payapply.getDynamicObjectCollection("entry"); | ||||
|                     if (collection.isEmpty()) { | ||||
|                         return handleErrorAndReturn("同步失败, 调整单号:" + fkBillNum + "无明细信息", fkBillNum, null); | ||||
|                     } | ||||
| 
 | ||||
|             DynamicObject add = collection.get(0); | ||||
|             BigDecimal amount = add.getBigDecimal("e_applyamount"); | ||||
|             int comparisonResult = amount.compareTo(amounts); | ||||
|                     DynamicObject add = collection.get(0); | ||||
|                     BigDecimal amount = add.getBigDecimal("e_applyamount"); | ||||
|                     int comparisonResult = amount.compareTo(amounts); | ||||
| 
 | ||||
|             if (comparisonResult > 0) { | ||||
|                 // 分录申请金额大于调整金额,可拆   由于新增,所以不需要考虑状态直接拆 difference(拆完剩余金额) | ||||
|                 BigDecimal difference = amount.subtract(amounts); | ||||
|                 add.set("e_applyamount", difference); // 拆完剩余金额 | ||||
|                 add.set("e_approvedamt", difference); // 同步核准金额 | ||||
|                     if (comparisonResult > 0) { | ||||
|                         // 分录申请金额大于调整金额,可拆   由于新增,所以不需要考虑状态直接拆 difference(拆完剩余金额) | ||||
|                         BigDecimal difference = amount.subtract(amounts); | ||||
|                         add.set("e_applyamount", difference); // 拆完剩余金额 | ||||
|                         add.set("e_approvedamt", difference); // 同步核准金额 | ||||
| 
 | ||||
|                 // 复制行 ,不考虑重复拆() | ||||
|                 cloneEntryRow(add, collection, amounts, applyAdjustbill.getFkBillNum()); | ||||
|                         // 复制行 ,不考虑重复拆() | ||||
|                         cloneEntryRow(add, collection, amounts, applyAdjustbill.getFkBillNum()); | ||||
| 
 | ||||
|                 // 标记付款申请___来源调整单 | ||||
| //                ap_payapply.set("shjh_sourceadjustment", true); | ||||
|                         // 标记付款申请___来源调整单 | ||||
|                         ap_payapply.set("shjh_sourceadjustment", true); | ||||
| 
 | ||||
|                 // 保存、提交和审核付款申请单 | ||||
|                 if (!processPayApply(ap_payapply, fkBillNum, jsonBodyString)) { | ||||
|                     return CustomApiResult.fail("400", "处理付款申请单失败,详情查看日志"); | ||||
|                         // 保存、提交和审核付款申请单 | ||||
|                         if (!processPayApply(ap_payapply, fkBillNum, jsonBodyString)) { | ||||
|                             return CustomApiResult.fail("400", "处理付款申请单失败,详情查看日志"); | ||||
|                         } | ||||
| 
 | ||||
|                         log.error("审核成功,费控调整单号:" + fkBillNum); | ||||
|                         JhzjUtils.saveLog(fkBillNum, Apimenthod, jsonBodyString, null, true, "API"); | ||||
|                     } | ||||
|                 } | ||||
| 
 | ||||
|                 log.error("审核成功,费控调整单号:" + fkBillNum); | ||||
|                 JhzjUtils.saveLog(fkBillNum, Apimenthod, jsonBodyString, null, true, "API"); | ||||
|             } | ||||
|         } | ||||
|         else { | ||||
|  | @ -238,6 +251,32 @@ public class ApplyAdjustBillControler { | |||
|         return CustomApiResult.success(null); | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      *  调取SAP凭证接口 | ||||
|      */ | ||||
|     private static JSONArray querySapPz(ApplyAdjustBillModel applyAdjustbill){ | ||||
|         JSONArray IT_LIST = new JSONArray(); | ||||
|         // 添加公司过滤条件 | ||||
|         addFilterCondition(IT_LIST, "BUKRS", applyAdjustbill.getCompanyNum(), applyAdjustbill.getCompanyNum()); | ||||
|         // 添加SAP应付凭证号过滤条件 | ||||
|         addFilterCondition(IT_LIST, "BELNR", applyAdjustbill.getVoucherNum(), applyAdjustbill.getVoucherNum()); | ||||
|         // 添加会计年度过滤条件 | ||||
|         addFilterCondition(IT_LIST, "GJAHR", applyAdjustbill.getVoucherYear(), applyAdjustbill.getVoucherYear()); | ||||
|         //todo:根据查询条件,调用SAP查询凭证接口,生成分录行 | ||||
|         JSONObject result = vouchers_payable(IT_LIST, applyAdjustbill.getFkBillNum()); | ||||
|         if (null != result && result.containsKey("data")) { | ||||
|             // 处理查询结果 | ||||
|             JSONObject data = (JSONObject) result.get("data"); | ||||
|             if (null != data && data.containsKey("IT_ITEM")) { | ||||
|                 JSONArray IT_ITEMs = (JSONArray) data.get("IT_ITEM"); | ||||
|                 if (!IT_ITEMs.isEmpty()) { | ||||
|                     return IT_ITEMs; | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
|         return null; | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * 处理付款申请单的保存、提交和审核操作 | ||||
|      * @param ap_payapply 付款申请单对象 | ||||
|  | @ -342,45 +381,65 @@ public class ApplyAdjustBillControler { | |||
|     /** | ||||
|      * 创建或更新付款申请单 | ||||
|      * | ||||
|      * @param applyAdjustbill 调整单模型 | ||||
|      * @param companyNum      公司编号 | ||||
|      * @param voucherNum      SAP凭证号 | ||||
|      * @param year            会计年度 | ||||
|      * @param voucherLineNum  凭证行号 | ||||
|      * @param org             组织信息 | ||||
|      * @param it_list SAP查到的凭证信息 | ||||
|      * @return 付款申请单的动态对象 | ||||
|      */ | ||||
|     private DynamicObject createOrUpdatePayApply(ApplyAdjustBillModel applyAdjustbill, String companyNum, String voucherNum, String year, String voucherLineNum, DynamicObject org, String fkBillNum) { | ||||
|         String vouchernum = voucherNum; | ||||
|         String voucheryear = year; | ||||
|         String voucherentrynum = voucherLineNum; | ||||
|         String accountingsubject = "1001";// 会计科目:1001 | ||||
|         BigDecimal outstandingamount = BigDecimal.valueOf(100);// 未清金额 | ||||
|         BigDecimal exchangerate = BigDecimal.ONE;// 汇率 | ||||
|         BigDecimal applyforconversionof = BigDecimal.ONE;// 申请金额折结算币别 | ||||
|         Date duedate = new Date();// 到期日 | ||||
|         Date bizDate = new Date();// 记账日期 | ||||
|         Date documentdate = new Date();// 凭证日期 | ||||
|         Date basedate = new Date();// 基准日期 | ||||
|         String asstacttype = "供应商";// 往来类型 | ||||
|         String asstact = "上海接口有限公司";// 往来户名称 | ||||
|         String assacct = "A";// 合作银行类型 | ||||
|         String reasoncode = "014";// 原因码 | ||||
|         String shjh_classificationoffund = "资金计划分类";// 资金计划分类 | ||||
|         String shjh_secondarydept = "二级部门";// 二级部门 | ||||
|         String procurementeam = "采购组";// 采购组 | ||||
|         Boolean isselfprocurment = Boolean.TRUE;// 是否自行采购 | ||||
|         String paymentcurrency = "CNY";// 付款币别编号 | ||||
|         String settlementcurrency = "CNY";// 结算币别编号 | ||||
|         String applycause = "摘要";// 摘要 | ||||
|         String sourcebillno = "外部系统编号001";// 外部系统编号 | ||||
|         String vouchertype = "0003";// 凭证类型 | ||||
|         String paymentterms = "付款条件";// 付款条件 | ||||
|         String refertoinvoicenumber = "发票号001";// 参照发票号 | ||||
|     private DynamicObject createOrUpdatePayApply(JSONObject it_list,String fkBillNum) { | ||||
|         String orgNum = it_list.getString("BUKRS");//公司编号,"公司代码 | ||||
|         String voucheryear = it_list.getString("GJAHR");//会计年度,会计年度 | ||||
|         String voucherentrynum = it_list.getString("BUZEI");//会计科目行项目号,行编号 | ||||
|         String accountingsubject = it_list.getString("SAKNR");//todo:会计科目:1001,总帐科目编号 | ||||
|         BigDecimal outstandingamount = new BigDecimal(it_list.getString("WRBTR"));//未清金额,凭证货币金额 | ||||
|         BigDecimal KURSF = new BigDecimal(it_list.getString("KURSF")); | ||||
|         if (KURSF.compareTo(BigDecimal.ZERO) == 0) { | ||||
|             KURSF = BigDecimal.ONE; | ||||
|         } | ||||
|         BigDecimal exchangerate = KURSF;//汇率 | ||||
|         BigDecimal applyforconversionof = new BigDecimal(it_list.getString("DMBTR"));//申请金额折结算币别,按本位币计的金额 | ||||
|         Date duedate = null;// 到期日 | ||||
|         String FAEDT = it_list.getString("FAEDT");//到期日,净价到期日 | ||||
|         if (StringUtils.isNotEmpty(FAEDT)) { | ||||
|             duedate = StrToDate(FAEDT); | ||||
|         } | ||||
|         Date bizDate = null;// 记账日期 | ||||
|         String BUDAT = it_list.getString("BUDAT"); | ||||
|         if (StringUtils.isNotEmpty(BUDAT)) { | ||||
|             bizDate = StrToDate(BUDAT);//记账日期,凭证中的过帐日期 | ||||
|         } | ||||
|         Date documentdate = null;// 凭证日期 | ||||
|         String BLDAT = it_list.getString("BLDAT"); | ||||
|         if (StringUtils.isNotEmpty(BLDAT)) { | ||||
|             documentdate = StrToDate(BLDAT);//凭证日期,凭证中的凭证日期 | ||||
|         } | ||||
|         Date basedate = null;// 基准日期 | ||||
|         String ZFBDT = it_list.getString("ZFBDT"); | ||||
|         if (StringUtils.isNotEmpty(ZFBDT)) { | ||||
|             basedate = StrToDate(ZFBDT);//基准日期,用于到期日计算的基准日期 | ||||
|         } | ||||
|         String asstacttype = "供应商";//todo:往来类型 | ||||
|         String asstact = "上海接口有限公司";//todo:往来户名称 | ||||
| //        String assacct = it_list.getString("BVTYP");//合作银行类型.合作银行类型 A | ||||
|         String assacct = "A";//合作银行类型.合作银行类型 A | ||||
|         String reasoncode = "014";//todo:原因码 014 | ||||
|         String shjh_classificationoffund = "资金计划分类";//todo:资金计划分类 | ||||
|         String shjh_secondarydept = it_list.getString("ZREQ_DEPT");//二级部门,需求部门 | ||||
|         String procurementeam = it_list.getString("EKGRP");//采购组 | ||||
|         Boolean isselfprocurment = Boolean.valueOf(it_list.getString("ZZXCG_FLAG"));//todo:是否自行采购 | ||||
|         String WAERS = it_list.getString("WAERS"); | ||||
|         if ("RMB".equals(WAERS)) { | ||||
|             WAERS = "CNY"; | ||||
|         } | ||||
|         String paymentcurrency = WAERS;//付款币别编号CNY,货币码 | ||||
|         String settlementcurrency = WAERS;//结算币别编号,货币码 | ||||
|         String applycause = it_list.getString("BKTXT");// TODO:摘要_凭证抬头文本 | ||||
|         String vouchernum = it_list.getString("BELNR");//外部系统编号_会计凭证编号 | ||||
|         String vouchertype = it_list.getString("BLART");// 凭证类型_凭证类型 | ||||
|         String paymentterms = it_list.getString("ZTERM");// 付款条件_付款条件代码 | ||||
|         String refertoinvoicenumber = "发票号001";// TODO:参照发票号 | ||||
| 
 | ||||
|         // 防重校验 | ||||
|         QFilter Q5 = new QFilter("shjh_vouchernum", QCP.equals, vouchernum); | ||||
|         QFilter Q6 = new QFilter("applyorg.number", QCP.equals, companyNum); | ||||
|         QFilter Q6 = new QFilter("applyorg.number", QCP.equals, orgNum); | ||||
|         QFilter Q7 = new QFilter("shjh_voucheryear", QCP.equals, voucheryear); | ||||
|         QFilter Q8 = new QFilter("shjh_voucherentrynum", QCP.equals, voucherentrynum); | ||||
|         DynamicObject ap_payapplys = BusinessDataServiceHelper.loadSingle(AP_PAYAPPLY, new QFilter[]{Q5, Q6, Q7, Q8}); | ||||
|  | @ -391,6 +450,7 @@ public class ApplyAdjustBillControler { | |||
| 
 | ||||
|             return null; | ||||
|         } | ||||
|         DynamicObject org = BusinessDataServiceHelper.loadSingle("bos_org", "id", new QFilter("number", "=", orgNum).toArray()); | ||||
| 
 | ||||
|         // 设置组织信息 | ||||
|         ap_payapply.set("settleorg", org); | ||||
|  | @ -450,7 +510,7 @@ public class ApplyAdjustBillControler { | |||
|         setPaymentType(ap_payapply, accountingsubject); | ||||
| 
 | ||||
|         // 设置默认字段 | ||||
|         if (!setDefaultFields(ap_payapply, vouchernum, voucherentrynum, voucheryear, procurementeam, isselfprocurment, sourcebillno, reasoncode, bizDate, documentdate, vouchertype, basedate, paymentterms, refertoinvoicenumber, companyNum, duedate, fkBillNum)) { | ||||
|         if (!setDefaultFields(ap_payapply, vouchernum, voucherentrynum, voucheryear, procurementeam, isselfprocurment, vouchernum, reasoncode, bizDate, documentdate, vouchertype, basedate, paymentterms, refertoinvoicenumber, orgNum, duedate, fkBillNum)) { | ||||
|             return null; | ||||
|         } | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue