parent
							
								
									15c4317e7c
								
							
						
					
					
						commit
						1d6f17330b
					
				|  | @ -5,13 +5,32 @@ import com.alibaba.fastjson.JSONException; | ||||||
| import com.alibaba.fastjson.JSONObject; | import com.alibaba.fastjson.JSONObject; | ||||||
| import com.drew.lang.annotations.NotNull; | import com.drew.lang.annotations.NotNull; | ||||||
| import kd.bos.api.client.ApiResult; | import kd.bos.api.client.ApiResult; | ||||||
|  | import kd.bos.dataentity.OperateOption; | ||||||
|  | import kd.bos.dataentity.entity.DynamicObject; | ||||||
|  | import kd.bos.dataentity.entity.DynamicObjectCollection; | ||||||
|  | import kd.bos.entity.operate.OperateOptionConst; | ||||||
|  | import kd.bos.entity.operate.result.OperateErrorInfo; | ||||||
|  | import kd.bos.entity.operate.result.OperationResult; | ||||||
|  | import kd.bos.entity.validate.ValidateResult; | ||||||
|  | import kd.bos.entity.validate.ValidateResultCollection; | ||||||
| import kd.bos.logging.Log; | import kd.bos.logging.Log; | ||||||
| import kd.bos.logging.LogFactory; | import kd.bos.logging.LogFactory; | ||||||
| import kd.bos.openapi.common.custom.annotation.ApiController; | import kd.bos.openapi.common.custom.annotation.ApiController; | ||||||
| import kd.bos.openapi.common.custom.annotation.ApiParam; | import kd.bos.openapi.common.custom.annotation.ApiParam; | ||||||
| import kd.bos.openapi.common.custom.annotation.ApiPostMapping; | import kd.bos.openapi.common.custom.annotation.ApiPostMapping; | ||||||
|  | import kd.bos.openapi.common.custom.annotation.ApiRequestBody; | ||||||
| import kd.bos.openapi.common.result.CustomApiResult; | import kd.bos.openapi.common.result.CustomApiResult; | ||||||
|  | import kd.bos.orm.query.QCP; | ||||||
|  | import kd.bos.orm.query.QFilter; | ||||||
|  | import kd.bos.servicehelper.BusinessDataServiceHelper; | ||||||
|  | import kd.bos.servicehelper.operation.OperationServiceHelper; | ||||||
| import shjh.jhzj7.fi.fi.utils.JhzjUtils; | import shjh.jhzj7.fi.fi.utils.JhzjUtils; | ||||||
|  | import shjh.jhzj7.fi.fi.webapi.model.ApplyBillModel; | ||||||
|  | 
 | ||||||
|  | import javax.validation.Valid; | ||||||
|  | import java.math.BigDecimal; | ||||||
|  | import java.math.RoundingMode; | ||||||
|  | import java.util.*; | ||||||
| 
 | 
 | ||||||
| /** | /** | ||||||
|  * "应付付款申请单接口 |  * "应付付款申请单接口 | ||||||
|  | @ -21,31 +40,360 @@ import shjh.jhzj7.fi.fi.utils.JhzjUtils; | ||||||
| public class ApplyBillControler { | public class ApplyBillControler { | ||||||
|     private static final String entityName = "bos_costcenter";//系统库 表名 t_bas_costcenter |     private static final String entityName = "bos_costcenter";//系统库 表名 t_bas_costcenter | ||||||
|     private static final String orgEntName = "bos_org";//系统库 表名 t_org_org |     private static final String orgEntName = "bos_org";//系统库 表名 t_org_org | ||||||
|  |     private static final String BD_CURRENCY = "bd_currency";//币种 表名 t_bd_currency | ||||||
|  |     private static final String BD_SUPPLIER = "bd_supplier";//供应商 表名 t_bd_supplier | ||||||
|  |     private static final String BD_CUSTOMER = "bd_customer";//客户 表名 t_bd_customer | ||||||
|  |     private static final String BD_BEBANK = "bd_bebank";//行名行号 表名 t_bd_bebank | ||||||
|  |     private static final String BD_SETTLEMENTTYPE = "bd_settlementtype";//结算方式 表名 t_bd_settlementtype | ||||||
|  |     private static final String GL_CASHFLOWITEM = "gl_cashflowitem";//现金流量项目 表名 t_gl_cashflowitem | ||||||
|  |     private static final String BOS_BILLTYPE = "bos_billtype";//单据类型 表名 t_bas_billtype | ||||||
|  |     private static final String CAS_PAYMENTBILLTYPE = "cas_paymentbilltype";//付款类型 表名 t_cas_paymentbilltype | ||||||
|  |     private static final String BD_EXRATETABLE = "bd_exratetable";//汇率表 表名 t_bd_exratetable | ||||||
|  |     private static final String AP_PAYAPPLY = "ap_payapply";//应付付款申请单 表名 t_ap_applypaybill | ||||||
|     private static final String apimenthod = "/applybill_sync"; |     private static final String apimenthod = "/applybill_sync"; | ||||||
|     private static final Log log = LogFactory.getLog(ApplyBillControler.class); |     private static final Log log = LogFactory.getLog(ApplyBillControler.class); | ||||||
|  | 
 | ||||||
|     @ApiPostMapping(value = apimenthod, desc = "应付付款申请单接口") |     @ApiPostMapping(value = apimenthod, desc = "应付付款申请单接口") | ||||||
|     public CustomApiResult<ApiResult> applybill_sync (@NotNull @ApiParam(value="入参json格式数据",example="") String applybill) { |     public CustomApiResult<ApiResult> applybill_sync (@NotNull @Valid @ApiRequestBody(value="入参json格式数据") ApplyBillModel applybill) { | ||||||
|         JSONObject json_body; |         JSONObject json_body; | ||||||
|         try{ |         String jsonBodyString = null; | ||||||
|             //解析入参,如果格式不正确,日志记录,并反馈esb |         try { | ||||||
|             json_body = JSON.parseObject(applybill); |             // 解析入参,如果格式不正确,日志记录,并反馈esb | ||||||
|         }catch (JSONException e) { |             json_body = (JSONObject) JSON.toJSON(applybill); | ||||||
|             String jsonResult = String.format("应付付款申请单接口入参异常:%s", e.getMessage()); |             jsonBodyString = JSON.toJSONString(json_body); | ||||||
|             log.error(jsonResult); |         } catch (JSONException e) { | ||||||
|             JhzjUtils.saveLog(apimenthod,"费控",applybill,jsonResult,false,"API"); |             handleError("应付付款申请单接口入参异常:" + e.getMessage(), apimenthod, "费控",jsonBodyString); | ||||||
|             return CustomApiResult.fail("400","接口入参异常"); |             return CustomApiResult.fail("400", "接口入参异常"); | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         // 校验入参是否为空或是否合法(日期和金额字段格式),如果不合法反馈费控 | ||||||
|  |         //--------------------------------------------------表头字段--------------------------------------------------------------- | ||||||
|  |         String fkBillID = applybill.getFkBillID(); // 费控表头ID | ||||||
|  |         String fkEntryID = applybill.getFkEntryID(); // 费控分录ID | ||||||
|  |         QFilter Q1 = new QFilter("shjh_fkbillid", QCP.equals, fkBillID); | ||||||
|  |         QFilter Q2 = new QFilter("shjh_fkentryid", QCP.equals, fkEntryID); | ||||||
|  |         DynamicObject ap_payapply = BusinessDataServiceHelper.loadSingle(AP_PAYAPPLY, new QFilter[]{Q1, Q2}); | ||||||
|  |         if (null != ap_payapply) { | ||||||
|  |             String errorMessage = "同步失败,fkBillID:" + fkBillID + ",fkEntryID:" + fkEntryID + "的费控单据已存在"; | ||||||
|  |             handleError(errorMessage, apimenthod, "费控",jsonBodyString); | ||||||
|  |             return CustomApiResult.fail("400", errorMessage); | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         // 未查到,新增应付付款申请单 | ||||||
|  |         ap_payapply = BusinessDataServiceHelper.newDynamicObject(AP_PAYAPPLY); | ||||||
|  | 
 | ||||||
|  |         ap_payapply.set("shjh_fkbillid", fkBillID); | ||||||
|  |         ap_payapply.set("shjh_fkentryid", fkEntryID); | ||||||
|  | 
 | ||||||
|  |         // 费控单据编号 | ||||||
|  |         String fkBillNum = applybill.getFkBillNum(); | ||||||
|  |         if (null == fkBillNum || fkBillNum.isEmpty()) { | ||||||
|  |             handleError("同步失败,费控单据编号为空", apimenthod, "费控",jsonBodyString); | ||||||
|  |             return CustomApiResult.fail("400", "费控单据编号为空"); | ||||||
|  |         } | ||||||
|  |         ap_payapply.set("shjh_fkdjbh", fkBillNum); | ||||||
|  | 
 | ||||||
|  |         // 公司编号 | ||||||
|  |         String companyNum = applybill.getCompanyNum(); | ||||||
|  |         QFilter Q3 = new QFilter("number", QCP.equals, companyNum); | ||||||
|  |         DynamicObject org = BusinessDataServiceHelper.loadSingle(orgEntName, new QFilter[]{Q3}); | ||||||
|  |         if (null == org) { | ||||||
|  |             handleError("同步失败,费控单据编号:" + fkBillNum + "的组织编码不存在", apimenthod, "费控",jsonBodyString); | ||||||
|  |             return CustomApiResult.fail("400", "组织编码不存在"); | ||||||
|  |         } | ||||||
|  |         ap_payapply.set("settleorg", org); // 结算组织 | ||||||
|  |         ap_payapply.set("applyorg" , org); // 申请组织 | ||||||
|  |         ap_payapply.set("payorg"   , org); // 付款组织 | ||||||
|  |         ap_payapply.set("purorg"   , org); // 采购组织 | ||||||
|  |         // 申请日期 | ||||||
|  |         Date bizDate = applybill.getBizDate(); | ||||||
|  |         if (null == bizDate) { | ||||||
|  |             handleError("同步失败,费控单据编号:" + fkBillNum + "的申请日期为空", apimenthod, "费控",jsonBodyString); | ||||||
|  |             return CustomApiResult.fail("400", "申请日期为空"); | ||||||
|  |         } | ||||||
|  |         ap_payapply.set("applydate", bizDate); | ||||||
|  |         //请款事由 | ||||||
|  |         String applycause = applybill.getApplycause(); | ||||||
|  |         ap_payapply.set("applycause", applycause); | ||||||
|  | 
 | ||||||
|  |         String[][] currencyInfo = { | ||||||
|  |                 {"paycurrency", "付款币别"}, | ||||||
|  |                 {"settlecurrency", "结算币别"} | ||||||
|  |         }; | ||||||
|  |         for (String[] info : currencyInfo) { | ||||||
|  |             String currencyType = info[0]; | ||||||
|  |             String currencyTypeName = info[1]; | ||||||
|  |             // 根据币别类型从 applybill 获取对应的币别编号 | ||||||
|  |             String currencyNumber = "paycurrency".equals(currencyType) ? applybill.getPaycurrency() : applybill.getSettlecurrency(); | ||||||
|  |             // 检查币别编号是否为空 | ||||||
|  |             if (currencyNumber == null || currencyNumber.trim().isEmpty()) { | ||||||
|  |                 handleError("同步失败,费控单据编号:" + fkBillNum + "的" + currencyTypeName + "为空", apimenthod, "费控", jsonBodyString); | ||||||
|  |                 return CustomApiResult.fail("400", currencyTypeName + "为空"); | ||||||
|  |             } | ||||||
|  |             QFilter filter = new QFilter("number", QCP.equals, currencyNumber); | ||||||
|  |             DynamicObject currency = BusinessDataServiceHelper.loadSingle(BD_CURRENCY, new QFilter[]{filter}); | ||||||
|  |             // 检查 currency 是否为空 | ||||||
|  |             if (currency == null) { | ||||||
|  |                 handleError("同步失败,费控单据编号:" + fkBillNum + "的" + currencyTypeName + "不存在", apimenthod, "费控", jsonBodyString); | ||||||
|  |                 return CustomApiResult.fail("400", currencyTypeName + "不存在"); | ||||||
|  |             } | ||||||
|  |             ap_payapply.set(currencyType, currency); | ||||||
|  |         } | ||||||
|  |         // 申请金额 , 汇率 , 申请金额折结算币别 | ||||||
|  |         BigDecimal amount =BigDecimal.ZERO; | ||||||
|  |         String[][] fieldInfo = { | ||||||
|  |                 {"applyamount", "getApplyamount", "申请金额"}, | ||||||
|  |                 {"exchangerate", "getExchangerate", "汇率"}, | ||||||
|  |                 {"appseleamount", "getAppseleamount", "申请金额折结算币别"} | ||||||
|  |         }; | ||||||
|  |         for (String[] info : fieldInfo) { | ||||||
|  |             String fieldName = info[0]; | ||||||
|  |             String getterMethod = info[1]; | ||||||
|  |             String fieldDesc = info[2]; | ||||||
|  |             try { | ||||||
|  |                 // 通过反射调用对应的 getter 方法获取值 | ||||||
|  |                 java.lang.reflect.Method method = applybill.getClass().getMethod(getterMethod); | ||||||
|  |                 String valueStr = (String) method.invoke(applybill); | ||||||
|  |                 BigDecimal value = new BigDecimal(valueStr); | ||||||
|  |                 value = value.setScale(2, RoundingMode.HALF_UP); | ||||||
|  |                 // 将处理后的值设置到 ap_payapply 中 | ||||||
|  |                 ap_payapply.set(fieldName, value); | ||||||
|  |                 if ("applyamount".equals(fieldName)) { | ||||||
|  |                     amount = value; | ||||||
|  |                 } | ||||||
|  |             } catch (NumberFormatException e) { | ||||||
|  |                 // 处理数字格式异常 | ||||||
|  |                 handleError("同步失败,费控单据编号:" + fkBillNum + "的" + fieldDesc + "格式不正确", apimenthod, "费控",jsonBodyString); | ||||||
|  |                 return CustomApiResult.fail("400", fieldDesc + "格式不正确"); | ||||||
|  |             } catch (Exception e) { | ||||||
|  |                 // 处理反射调用方法时可能出现的其他异常 | ||||||
|  |                 handleError("同步失败,获取费控单据编号:" + fkBillNum + "的" + fieldDesc + "时出现异常", apimenthod, "费控",jsonBodyString); | ||||||
|  |                 return CustomApiResult.fail("400", fieldDesc + "格式不正确"); | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |         //汇率日期 | ||||||
|  |         Date exchangerateDate = applybill.getExchangerateDate(); | ||||||
|  |         ap_payapply.set("exratedate", exchangerateDate); | ||||||
|  |         //原因码 | ||||||
|  |         String causeNum = applybill.getCauseNum(); | ||||||
|  |         if (causeNum == null || causeNum.isEmpty()) { | ||||||
|  |             handleError("同步失败,费控单据编号:" + fkBillNum + "的原因码为空", apimenthod, "费控",jsonBodyString); | ||||||
|  |             return CustomApiResult.fail("400", "原因码为空"); | ||||||
|  |         } | ||||||
|  |         QFilter Q7 = new QFilter("number", QCP.equals, causeNum); | ||||||
|  |         DynamicObject cause = BusinessDataServiceHelper.loadSingle(GL_CASHFLOWITEM, new QFilter[]{Q7}); | ||||||
|  |         if (null == cause) { | ||||||
|  |             handleError("同步失败,费控单据编号:" + fkBillNum + "的原因码不存在", apimenthod, "费控",jsonBodyString); | ||||||
|  |             return CustomApiResult.fail("400", "原因码不存在"); | ||||||
|  |         } | ||||||
|  |         ap_payapply.set("shjh_yym", cause); | ||||||
|  | 
 | ||||||
|  |         //--------------------------------------------------分录字段--------------------------------------------------------------- | ||||||
|  | 
 | ||||||
|  |         DynamicObjectCollection entry = ap_payapply.getDynamicObjectCollection("entry");//明细 | ||||||
|  |         DynamicObject ap_payapply_entry = entry.addNew(); | ||||||
|  |         // 定义往来类型和对应值的映射 | ||||||
|  |         Map<String, String> asstactTypeMap = new HashMap<>(); | ||||||
|  |         asstactTypeMap.put("供应商", "bd_supplier"); | ||||||
|  |         asstactTypeMap.put("客户", "bd_customer"); | ||||||
|  |         // 往来类型 | ||||||
|  |         String asstacttype = applybill.getAsstacttype(); | ||||||
|  |         // 检查往来类型是否为空或无效 | ||||||
|  |         if (asstacttype == null || asstacttype.isEmpty() ||!asstactTypeMap.containsKey(asstacttype)) { | ||||||
|  |             String errorMessage = asstacttype == null || asstacttype.isEmpty() ? "往来类型为空" : "往来类型不存在"; | ||||||
|  |             handleError("同步失败,费控单据编号:" + fkBillNum + "的" + errorMessage, apimenthod, "费控",jsonBodyString); | ||||||
|  |             return CustomApiResult.fail("400", errorMessage); | ||||||
|  |         } | ||||||
|  |         // 根据往来类型设置值 | ||||||
|  |         ap_payapply_entry.set("e_asstacttype", asstactTypeMap.get(asstacttype)); | ||||||
|  |         // 往来户 | ||||||
|  |         String asstact = applybill.getAsstact(); | ||||||
|  |         if (asstact == null || asstact.isEmpty()) { | ||||||
|  |             handleError("同步失败,费控单据编号:" + fkBillNum + "的往来户为空", apimenthod, "费控",jsonBodyString); | ||||||
|  |             return CustomApiResult.fail("400", "往来户为空"); | ||||||
|  |         } | ||||||
|  |         QFilter Q4 = new QFilter("number", QCP.equals, asstact); | ||||||
|  |         DynamicObject party = "供应商".equals(asstacttype) | ||||||
|  |                 ? BusinessDataServiceHelper.loadSingle(BD_SUPPLIER, new QFilter[]{Q4}) | ||||||
|  |                 : BusinessDataServiceHelper.loadSingle(BD_CUSTOMER, new QFilter[]{Q4}); | ||||||
|  |         if (party == null) { | ||||||
|  |             String errorMessage = "同步失败,费控单据编号:" + fkBillNum + "的" + ("供应商".equals(asstacttype) ? "供应商" : "客户") + "不存在"; | ||||||
|  |             handleError(errorMessage, apimenthod, "费控",jsonBodyString); | ||||||
|  |             return CustomApiResult.fail("400", errorMessage); | ||||||
|  |         } | ||||||
|  |         ap_payapply_entry.set("e_asstact", party); | ||||||
|  |         //往来账户 | ||||||
|  |         String assacct = applybill.getAssacct(); | ||||||
|  |         if(assacct == null || assacct.isEmpty()){ | ||||||
|  |             handleError("同步失败,费控单据编号:" + fkBillNum + "的往来账户为空", apimenthod, "费控",jsonBodyString); | ||||||
|  |             return CustomApiResult.fail("400", "往来账户为空"); | ||||||
|  |         } | ||||||
|  |         ap_payapply_entry.set("e_assacct", assacct); | ||||||
|  |         //往来银行 | ||||||
|  |         String bebank = applybill.getBebank(); | ||||||
|  |         if(bebank == null || bebank.isEmpty()){ | ||||||
|  |             handleError("同步失败,费控单据编号:" + fkBillNum + "的往来银行为空", apimenthod, "费控",jsonBodyString); | ||||||
|  |             return CustomApiResult.fail("400", "往来银行为空"); | ||||||
|  |         } | ||||||
|  |         QFilter Q5 = new QFilter("name", QCP.equals, bebank); | ||||||
|  |         DynamicObject bank = BusinessDataServiceHelper.loadSingle(BD_BEBANK, new QFilter[]{Q5}); | ||||||
|  |         if (null == bank) { | ||||||
|  |             handleError("同步失败,费控单据编号:" + fkBillNum + "的往来银行不存在", apimenthod, "费控",jsonBodyString); | ||||||
|  |             return CustomApiResult.fail("400", "往来银行不存在"); | ||||||
|  |         } | ||||||
|  |         ap_payapply_entry.set("e_bebank", bank); | ||||||
|  |         //往来账户名称 | ||||||
|  |         String asstactRealName = applybill.getAsstactRealName(); | ||||||
|  |         if (asstactRealName == null || asstactRealName.isEmpty()) { | ||||||
|  |             handleError("同步失败,费控单据编号:" + fkBillNum + "的往来账户名称为空", apimenthod, "费控",jsonBodyString); | ||||||
|  |             return CustomApiResult.fail("400", "往来账户名称为空"); | ||||||
|  |         } | ||||||
|  |         ap_payapply_entry.set("shjh_asstactrealname", asstactRealName); | ||||||
|  |         //到期日 | ||||||
|  |         Date duedate = applybill.getDuedate(); | ||||||
|  |         if (null == duedate) { | ||||||
|  |             handleError("同步失败,费控单据编号:" + fkBillNum + "的到期日为空", apimenthod, "费控",jsonBodyString); | ||||||
|  |             return CustomApiResult.fail("400", "到期日为空"); | ||||||
|  |         } | ||||||
|  |         ap_payapply_entry.set("e_duedate", duedate); | ||||||
|  | 
 | ||||||
|  |         //分录申请金额 | ||||||
|  |         ap_payapply_entry.set("e_applyamount", amount); | ||||||
|  | 
 | ||||||
|  |         //结算方式 | ||||||
|  |         String settlementtype = applybill.getSettlementtype(); | ||||||
|  |         if (settlementtype == null || settlementtype.isEmpty()) { | ||||||
|  |             handleError("同步失败,费控单据编号:" + fkBillNum + "的结算方式为空", apimenthod, "费控",jsonBodyString); | ||||||
|  |             return CustomApiResult.fail("400", "结算方式为空"); | ||||||
|  |         } | ||||||
|  |         QFilter Q6 = new QFilter("name", QCP.equals, settlementtype); | ||||||
|  |         DynamicObject settlement = BusinessDataServiceHelper.loadSingle(BD_SETTLEMENTTYPE, new QFilter[]{Q6}); | ||||||
|  |         if (null == settlement) { | ||||||
|  |             handleError("同步失败,费控单据编号:" + fkBillNum + "的结算方式不存在", apimenthod, "费控",jsonBodyString); | ||||||
|  |             return CustomApiResult.fail("400", "结算方式不存在"); | ||||||
|  |         } | ||||||
|  |         ap_payapply_entry.set("e_settlementtype", settlement); | ||||||
|  |         String remark = applybill.getRemark();//备注 | ||||||
|  |         ap_payapply_entry.set("e_remark", remark); | ||||||
|  | 
 | ||||||
|  |         //付款类型 | ||||||
|  |         String paymenttype = applybill.getPaymenttype(); | ||||||
|  |         if (paymenttype == null || paymenttype.isEmpty()) { | ||||||
|  |             handleError("同步失败,费控单据编号:" + fkBillNum + "的付款类型为空", apimenthod, "费控",jsonBodyString); | ||||||
|  |             return CustomApiResult.fail("400", "付款类型为空"); | ||||||
|  |         } | ||||||
|  |         QFilter Q9 = new QFilter("number", QCP.equals, paymenttype); | ||||||
|  |         DynamicObject paytype = BusinessDataServiceHelper.loadSingle(CAS_PAYMENTBILLTYPE, new QFilter[]{Q9}); | ||||||
|  |         if (null == paytype) { | ||||||
|  |             handleError("同步失败,费控单据编号:" + fkBillNum + "的付款类型不存在", apimenthod, "费控",jsonBodyString); | ||||||
|  |             return CustomApiResult.fail("400", "付款类型不存在"); | ||||||
|  |         } | ||||||
|  |         ap_payapply_entry.set("e_paymenttype", paytype); | ||||||
|  | 
 | ||||||
|  |         //单据类型 | ||||||
|  |         QFilter Q8 = new QFilter("name", QCP.equals, "其他付款申请"); | ||||||
|  |         DynamicObject billtype = BusinessDataServiceHelper.loadSingle(BOS_BILLTYPE, new QFilter[]{Q8}); | ||||||
|  |         if (null != billtype) { | ||||||
|  |             ap_payapply.set("billtype", billtype); | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         //汇率表 | ||||||
|  |         QFilter Q10 = new QFilter("number", QCP.equals, "ERT-01"); | ||||||
|  |         DynamicObject exrate = BusinessDataServiceHelper.loadSingle(BD_EXRATETABLE, new QFilter[]{Q10}); | ||||||
|  |         if (null != exrate) { | ||||||
|  |             ap_payapply.set("exratetable", exrate); | ||||||
|  |         } | ||||||
|  |         ap_payapply.set("billstatus", "A");//状态:暂存 | ||||||
|  | 
 | ||||||
|  |         //select * from t_ap_applypaybill where fid = 2148014743875508224 or fid = 2148018902158815232 | ||||||
|  |         //todo:单头:申请人,核准金额,核准金额折结算币,付款状态,冻结状态,换算方式,单据来源类型 | ||||||
|  |         //     明细:seq,e_approvedamt(核准金额),e_approvedseleamt(核准金额折结算币),e_corebilltype(核心单据类型),e_freezestate(冻结状态),e_creator(创建人),e_closestatus(行关闭状态) | ||||||
|  | 
 | ||||||
|  |         OperateOption option= OperateOption.create(); | ||||||
|  |         option.setVariableValue(OperateOptionConst.IGNOREWARN, String.valueOf(true)); // 不执行警告级别校验器 | ||||||
|  |         // 新增数据 | ||||||
|  |         OperationResult saveResult = OperationServiceHelper.executeOperate("save", AP_PAYAPPLY, new DynamicObject[]{ap_payapply}, option); | ||||||
|  |         if(saveResult.isSuccess()){ | ||||||
|  |             OperationResult submitResult = OperationServiceHelper.executeOperate("submit", AP_PAYAPPLY, new DynamicObject[]{ap_payapply}, option); | ||||||
|  |             if(submitResult.isSuccess()) { | ||||||
|  |                 OperationServiceHelper.executeOperate("audit", AP_PAYAPPLY, new DynamicObject[]{ap_payapply}, option); | ||||||
|  | 
 | ||||||
|  |             }else{ | ||||||
|  |                 List<String> errors = new ArrayList<>(); | ||||||
|  |                 ValidateResultCollection validateResult = submitResult.getValidateResult(); | ||||||
|  |                 for (int h = 0; h < validateResult.errorSize(); h++) { | ||||||
|  |                     List<ValidateResult> validateErrors = validateResult.getValidateErrors(); | ||||||
|  |                     for (int k = 0; k < validateErrors.size(); k++) { | ||||||
|  |                         ValidateResult errinfo = validateErrors.get(k); | ||||||
|  |                         List<OperateErrorInfo> allErrorInfo = errinfo.getAllErrorInfo(); | ||||||
|  |                         for (int l = 0; l < allErrorInfo.size(); l++) { | ||||||
|  |                             errors.add(allErrorInfo.get(l).getMessage()); | ||||||
|  |                         } | ||||||
|  |                     } | ||||||
|  |                 } | ||||||
|  |                 //todo:提交失败,将保存的数据删除,记录日志 | ||||||
|  | //                OperationServiceHelper.executeOperate("delete", AP_PAYAPPLY, new DynamicObject[]{ap_payapply}, option); | ||||||
|  |             } | ||||||
|  |         }else { | ||||||
|  |             //todo:保存失败,记录日志 | ||||||
|  |             List<String> errors = new ArrayList<>(); | ||||||
|  |             ValidateResultCollection validateResult = saveResult.getValidateResult(); | ||||||
|  |             for (int h = 0; h < validateResult.errorSize(); h++) { | ||||||
|  |                 List<ValidateResult> validateErrors = validateResult.getValidateErrors(); | ||||||
|  |                 for (int k = 0; k < validateErrors.size(); k++) { | ||||||
|  |                     ValidateResult errinfo = validateErrors.get(k); | ||||||
|  |                     List<OperateErrorInfo> allErrorInfo = errinfo.getAllErrorInfo(); | ||||||
|  |                     for (int l = 0; l < allErrorInfo.size(); l++) { | ||||||
|  |                         errors.add(allErrorInfo.get(l).getMessage()); | ||||||
|  |                     } | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|         } |         } | ||||||
|         //校验入参是否为空或是否合法(日期和金额字段格式),如果不合法反馈费控 |  | ||||||
|         String paramResult = paramIslegal(json_body); |  | ||||||
|         //还原入参中的内容为金蝶对象,如果不合法反馈费控 |  | ||||||
|         //根据费控主表和分表id查找金蝶中是否已存在相同付款申请单 |  | ||||||
|         JSONObject json_result = new JSONObject();//返回值主对象 |         JSONObject json_result = new JSONObject();//返回值主对象 | ||||||
|         JhzjUtils.saveLog(apimenthod,"ESB",applybill,json_result.toJSONString(),true,"API"); |         JhzjUtils.saveLog(apimenthod,"ESB",null,json_result.toJSONString(),true,"API"); | ||||||
|         return CustomApiResult.success(null); |         return CustomApiResult.success(null); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     private void handleError(String errorMessage, String apimenthod, String moduleName,String inputParam) { | ||||||
|  |         log.error(errorMessage); | ||||||
|  |         JhzjUtils.saveLog(apimenthod, moduleName, inputParam, errorMessage, false, "API"); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|     private String paramIslegal(JSONObject json_body){ |     private String paramIslegal(JSONObject json_body){ | ||||||
| 
 | 
 | ||||||
|         return null; |         return null; | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | //    String applyamount = applybill.getApplyamount();//申请金额 | ||||||
|  | //        try { | ||||||
|  | //                BigDecimal applyAmountBigDecimal = new BigDecimal(applyamount); | ||||||
|  | //                applyAmountBigDecimal = applyAmountBigDecimal.setScale(2, RoundingMode.HALF_UP); // 保留两位小数并四舍五入 | ||||||
|  | //                ap_payapply.set("applyamount", applyAmountBigDecimal); | ||||||
|  | //                } catch (NumberFormatException e) { | ||||||
|  | //                handleError("同步失败,费控单据编号:" + fkBillNum + "的申请金额格式不正确", apimenthod, "费控"); | ||||||
|  | //                throw new IllegalArgumentException("申请金额格式不正确", e); | ||||||
|  | //                } | ||||||
|  | //                String exchangerate = applybill.getExchangerate();//汇率 | ||||||
|  | //                try { | ||||||
|  | //                BigDecimal applyAmountBigDecimal = new BigDecimal(exchangerate); | ||||||
|  | //                applyAmountBigDecimal = applyAmountBigDecimal.setScale(2, RoundingMode.HALF_UP); // 保留两位小数并四舍五入 | ||||||
|  | //                ap_payapply.set("exchangerate", applyAmountBigDecimal); | ||||||
|  | //                } catch (NumberFormatException e) { | ||||||
|  | //                handleError("同步失败,费控单据编号:" + fkBillNum + "的汇率格式不正确", apimenthod, "费控"); | ||||||
|  | //                throw new IllegalArgumentException("汇率格式不正确", e); | ||||||
|  | //                } | ||||||
|  | //                String appseleamount = applybill.getAppseleamount();//申请金额折结算币别 | ||||||
|  | //                try { | ||||||
|  | //                BigDecimal applyAmountBigDecimal = new BigDecimal(appseleamount); | ||||||
|  | //                applyAmountBigDecimal = applyAmountBigDecimal.setScale(2, RoundingMode.HALF_UP); // 保留两位小数并四舍五入 | ||||||
|  | //                ap_payapply.set("appseleamount", applyAmountBigDecimal); | ||||||
|  | //                } catch (NumberFormatException e) { | ||||||
|  | //                handleError("同步失败,费控单据编号:" + fkBillNum + "的申请金额折结算币别格式不正确", apimenthod, "费控"); | ||||||
|  | //                throw new IllegalArgumentException("申请金额折结算币别格式不正确", e); | ||||||
|  | //                } | ||||||
|  | @ -0,0 +1,208 @@ | ||||||
|  | package shjh.jhzj7.fi.fi.webapi.model; | ||||||
|  | import kd.bos.openapi.common.custom.annotation.ApiModel; | ||||||
|  | import kd.bos.openapi.common.custom.annotation.ApiParam; | ||||||
|  | 
 | ||||||
|  | import java.util.Date; | ||||||
|  | @ApiModel | ||||||
|  | public class ApplyBillModel { | ||||||
|  | 
 | ||||||
|  |     @ApiParam(value="公司编号",required=true,position=1) | ||||||
|  |     private String companyNum; | ||||||
|  |     @ApiParam(value="费控单据编号",required=true,position=2) | ||||||
|  |     private String fkBillNum; | ||||||
|  |     @ApiParam(value="申请日期",required=true,position=3) | ||||||
|  |     private Date bizDate; | ||||||
|  |     @ApiParam(value="请款事由",required=false,position=4) | ||||||
|  |     private String applycause; | ||||||
|  |     @ApiParam(value="付款币别",required=true,position=5) | ||||||
|  |     private String paycurrency; | ||||||
|  |     @ApiParam(value="结算币别",required=true,position=6) | ||||||
|  |     private String settlecurrency; | ||||||
|  |     @ApiParam(value="申请金额",required=true,position=7) | ||||||
|  |     private String applyamount; | ||||||
|  |     @ApiParam(value="汇率",required=true,position=8) | ||||||
|  |     private String exchangerate; | ||||||
|  |     @ApiParam(value="汇率日期",required=false,position=9) | ||||||
|  |     private Date exchangerateDate; | ||||||
|  |     @ApiParam(value="申请金额折结算币别",required=true,position=10) | ||||||
|  |     private String appseleamount; | ||||||
|  |     @ApiParam(value="往来类型",required=true,position=11) | ||||||
|  |     private String asstacttype; | ||||||
|  |     @ApiParam(value="往来户",required=true,position=12) | ||||||
|  |     private String asstact; | ||||||
|  |     @ApiParam(value="往来账户",required=true,position=13) | ||||||
|  |     private String assacct; | ||||||
|  |     @ApiParam(value="往来银行",required=true,position=14) | ||||||
|  |     private String bebank; | ||||||
|  |     @ApiParam(value="往来账户名称",required=true,position=15) | ||||||
|  |     private String asstactRealName; | ||||||
|  |     @ApiParam(value="到期日",required=true,position=16) | ||||||
|  |     private Date duedate; | ||||||
|  |     @ApiParam(value="结算方式",required=true,position=17) | ||||||
|  |     private String settlementtype; | ||||||
|  |     @ApiParam(value="原因码",required=true,position=18) | ||||||
|  |     private String causeNum; | ||||||
|  |     @ApiParam(value="备注",required=false,position=19) | ||||||
|  |     private String remark; | ||||||
|  |     @ApiParam(value="费控表头ID",required=true,position=20) | ||||||
|  |     private String fkBillID; | ||||||
|  |     @ApiParam(value="费控分录ID",required=true,position=21) | ||||||
|  |     private String fkEntryID; | ||||||
|  |     @ApiParam(value="付款类型",required=true,position=22) | ||||||
|  |     private String paymenttype; | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  |     public void setPaymenttype(String paymenttype) { | ||||||
|  |         this.paymenttype = paymenttype; | ||||||
|  |     } | ||||||
|  |     public String getPaymenttype() { | ||||||
|  |         return paymenttype; | ||||||
|  |     } | ||||||
|  |     public void setCompanyNum(String companyNum) { | ||||||
|  |         this.companyNum = companyNum; | ||||||
|  |     } | ||||||
|  |     public String getCompanyNum() { | ||||||
|  |         return companyNum; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     public void setFkBillNum(String fkBillNum) { | ||||||
|  |         this.fkBillNum = fkBillNum; | ||||||
|  |     } | ||||||
|  |     public String getFkBillNum() { | ||||||
|  |         return fkBillNum; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     public void setFkBillID(String fkBillID) { | ||||||
|  |         this.fkBillID = fkBillID; | ||||||
|  |     } | ||||||
|  |     public String getFkBillID() { | ||||||
|  |         return fkBillID; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     public void setFkEntryID(String fkEntryID) { | ||||||
|  |         this.fkEntryID = fkEntryID; | ||||||
|  |     } | ||||||
|  |     public String getFkEntryID() { | ||||||
|  |         return fkEntryID; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     public void setApplycause(String applycause) { | ||||||
|  |         this.applycause = applycause; | ||||||
|  |     } | ||||||
|  |     public String getApplycause() { | ||||||
|  |         return applycause; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     public void setPaycurrency(String paycurrency) { | ||||||
|  |         this.paycurrency = paycurrency; | ||||||
|  |     } | ||||||
|  |     public String getPaycurrency() { | ||||||
|  |         return paycurrency; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     public void setSettlecurrency(String settlecurrency) { | ||||||
|  |         this.settlecurrency = settlecurrency; | ||||||
|  |     } | ||||||
|  |     public String getSettlecurrency() { | ||||||
|  |         return settlecurrency; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     public void setApplyamount(String applyamount) { | ||||||
|  |         this.applyamount = applyamount; | ||||||
|  |     } | ||||||
|  |     public String getApplyamount() { | ||||||
|  |         return applyamount; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     public void setExchangerate(String exchangerate) { | ||||||
|  |         this.exchangerate = exchangerate; | ||||||
|  |     } | ||||||
|  |     public String getExchangerate() { | ||||||
|  |         return exchangerate; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     public void setBizDate(Date bizDate) { | ||||||
|  |         this.bizDate = bizDate; | ||||||
|  |     } | ||||||
|  |     public Date getBizDate() { | ||||||
|  |         return bizDate; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     public void setExchangerateDate(Date exchangerateDate) { | ||||||
|  |         this.exchangerateDate = exchangerateDate; | ||||||
|  |     } | ||||||
|  |     public Date getExchangerateDate() { | ||||||
|  |         return exchangerateDate; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     public void setAppseleamount(String appseleamount) { | ||||||
|  |         this.appseleamount = appseleamount; | ||||||
|  |     } | ||||||
|  |     public String getAppseleamount() { | ||||||
|  |         return appseleamount; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     public void setAsstacttype(String asstacttype) { | ||||||
|  |         this.asstacttype = asstacttype; | ||||||
|  |     } | ||||||
|  |     public String getAsstacttype() { | ||||||
|  |         return asstacttype; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     public void setAsstact(String asstact) { | ||||||
|  |         this.asstact = asstact; | ||||||
|  |     } | ||||||
|  |     public String getAsstact() { | ||||||
|  |         return asstact; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     public void setAssacct(String assacct) { | ||||||
|  |         this.assacct = assacct; | ||||||
|  |     } | ||||||
|  |     public String getAssacct() { | ||||||
|  |         return assacct; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     public void setBebank(String bebank) { | ||||||
|  |         this.bebank = bebank; | ||||||
|  |     } | ||||||
|  |     public String getBebank() { | ||||||
|  |         return bebank; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     public void setAsstactRealName(String asstactRealName) { | ||||||
|  |         this.asstactRealName = asstactRealName; | ||||||
|  |     } | ||||||
|  |     public String getAsstactRealName() { | ||||||
|  |         return asstactRealName; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     public void setDuedate(Date duedate) { | ||||||
|  |         this.duedate = duedate; | ||||||
|  |     } | ||||||
|  |     public Date getDuedate() { | ||||||
|  |         return duedate; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     public void setSettlementtype(String settlementtype) { | ||||||
|  |         this.settlementtype = settlementtype; | ||||||
|  |     } | ||||||
|  |     public String getSettlementtype() { | ||||||
|  |         return settlementtype; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     public void setCauseNum(String causeNum) { | ||||||
|  |         this.causeNum = causeNum; | ||||||
|  |     } | ||||||
|  |     public String getCauseNum() { | ||||||
|  |         return causeNum; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     public void setRemark(String remark) { | ||||||
|  |         this.remark = remark; | ||||||
|  |     } | ||||||
|  |     public String getRemark() { | ||||||
|  |         return remark; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  | } | ||||||
		Loading…
	
		Reference in New Issue