|
@@ -0,0 +1,307 @@
|
|
|
|
+package nckd.jimin.jyyy.fi.webapi;
|
|
|
|
+
|
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
|
+import kd.bos.dataentity.OperateOption;
|
|
|
|
+import kd.bos.dataentity.entity.DynamicObject;
|
|
|
|
+import kd.bos.dataentity.entity.DynamicObjectCollection;
|
|
|
|
+import kd.bos.dataentity.metadata.dynamicobject.DynamicObjectType;
|
|
|
|
+import kd.bos.entity.operate.result.OperationResult;
|
|
|
|
+import kd.bos.logging.Log;
|
|
|
|
+import kd.bos.logging.LogFactory;
|
|
|
|
+import kd.bos.openapi.common.custom.annotation.ApiController;
|
|
|
|
+import kd.bos.openapi.common.custom.annotation.ApiParam;
|
|
|
|
+import kd.bos.openapi.common.custom.annotation.ApiPostMapping;
|
|
|
|
+import kd.bos.openapi.common.result.CustomApiResult;
|
|
|
|
+import kd.bos.openapi.common.result.OpenApiResult;
|
|
|
|
+import kd.bos.openapi.common.util.OpenApiSdkUtil;
|
|
|
|
+import kd.bos.orm.query.QCP;
|
|
|
|
+import kd.bos.orm.query.QFilter;
|
|
|
|
+import kd.bos.servicehelper.BusinessDataServiceHelper;
|
|
|
|
+import kd.bos.servicehelper.operation.OperationServiceHelper;
|
|
|
|
+import kd.bos.servicehelper.operation.SaveServiceHelper;
|
|
|
|
+
|
|
|
|
+import javax.validation.Valid;
|
|
|
|
+import java.io.Serializable;
|
|
|
|
+import java.util.Date;
|
|
|
|
+import java.util.HashMap;
|
|
|
|
+import java.util.Map;
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+@ApiController(
|
|
|
|
+ desc = "对接SRM预付款、付款",
|
|
|
|
+ value = "SRM"
|
|
|
|
+)
|
|
|
|
+public class SRMSynPayApiPlugin implements Serializable {
|
|
|
|
+ private static final long serialVersionUID = 3112572075286232761L;
|
|
|
|
+ private static final Log logger = LogFactory.getLog(SRMSynPayApiPlugin.class);
|
|
|
|
+ //对公报销单
|
|
|
|
+ private static final String ENTITY_PUBLICPAY = "er_publicreimbursebill";
|
|
|
|
+ //预付单
|
|
|
|
+ private static final String ENTITY_PREPAY = "er_prepaybill";
|
|
|
|
+
|
|
|
|
+ @ApiPostMapping("synPayForSRM")
|
|
|
|
+ public CustomApiResult<JSONObject> synPayForSRM(
|
|
|
|
+ @Valid @ApiParam(value = "付款申请") JSONArray bizAccountOutBills,
|
|
|
|
+ @Valid @ApiParam(value = "预付款") JSONArray dailyLoanBills) {
|
|
|
|
+ if(bizAccountOutBills == null && dailyLoanBills == null){
|
|
|
|
+ return returnResult("E", "失败,bizAccountOutBills、dailyLoanBills参数不能同时为空", null);
|
|
|
|
+ }
|
|
|
|
+ int bizAcctOutBillSize = 0;
|
|
|
|
+ int dailyLoanBillSize = 0;
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ if(bizAccountOutBills != null && bizAccountOutBills.size() > 0){
|
|
|
|
+ bizAcctOutBillSize = bizAccountOutBills.size();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if(dailyLoanBills != null && dailyLoanBills.size() > 0){
|
|
|
|
+ dailyLoanBillSize = dailyLoanBills.size();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if(bizAcctOutBillSize > 0 && dailyLoanBillSize > 0){
|
|
|
|
+ return returnResult("100", "失败,bizAccountOutBills、dailyLoanBills参数不能同时存在", null);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ JSONArray responseData = new JSONArray();
|
|
|
|
+ if(bizAcctOutBillSize > 0){
|
|
|
|
+ responseData = synBizAcctOutBill(bizAccountOutBills);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return returnResult("0", "成功", responseData);
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 同步付款
|
|
|
|
+ * @param bizAccountOutBills
|
|
|
|
+ */
|
|
|
|
+ private JSONArray synBizAcctOutBill(JSONArray bizAccountOutBills){
|
|
|
|
+ JSONArray responseData = new JSONArray();
|
|
|
|
+
|
|
|
|
+ for(int i = 0; i < bizAccountOutBills.size(); i++){
|
|
|
|
+ JSONObject inputData = bizAccountOutBills.getJSONObject(i);
|
|
|
|
+
|
|
|
|
+ JSONObject saveReturn = saveBizAcctOutBillInfo(inputData);
|
|
|
|
+
|
|
|
|
+ responseData.add(saveReturn);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return responseData;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 构造对公报销单对象
|
|
|
|
+ * @param inputData
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ private JSONObject saveBizAcctOutBillInfo (JSONObject inputData){
|
|
|
|
+ JSONObject returnMap = new JSONObject();
|
|
|
|
+
|
|
|
|
+ DynamicObject bizAcctOutBill = BusinessDataServiceHelper.newDynamicObject(ENTITY_PUBLICPAY);
|
|
|
|
+
|
|
|
|
+ String billType = inputData.getString("billType");//单据类型
|
|
|
|
+ String srmBillNo = inputData.getString("SRMBillNo");//srm单据号
|
|
|
|
+ String srmUrl = inputData.getString("srmUrl");//
|
|
|
|
+ String project = inputData.getString("project");//项目编号
|
|
|
|
+ String u8Org = inputData.getString("u8Org");//发票抬头
|
|
|
|
+ String invoicedAmount = inputData.getString("invoicedAmount");//本次开票金额
|
|
|
|
+ String contract = inputData.getString("contractNumber");//合同编号
|
|
|
|
+ String cause = inputData.getString("cause");//事由
|
|
|
|
+ String orgUnit = inputData.getString("orgUnit");//申请部门
|
|
|
|
+ String position = inputData.getString("position");//职位
|
|
|
|
+ String biller = inputData.getString("biller");//制单人工号
|
|
|
|
+ String applier = inputData.getString("applier");//经办人工号
|
|
|
|
+
|
|
|
|
+ applier = "ID-000014";
|
|
|
|
+
|
|
|
|
+ bizAcctOutBill.set("bizdate", new Date());//申请日期
|
|
|
|
+ bizAcctOutBill.set("description", cause);//事由
|
|
|
|
+ bizAcctOutBill.set("applier", getF7FieldValue("bos_user", "number", applier));//申请人
|
|
|
|
+ bizAcctOutBill.set("org", getF7FieldValue("bos_org", "number", "20240612-0009"));//部门
|
|
|
|
+ bizAcctOutBill.set("company", getF7FieldValue("bos_org", "number", "20240612-0009"));//公司行政组织
|
|
|
|
+ bizAcctOutBill.set("costdept", getF7FieldValue("bos_org", "number", "20240612-0009"));//费用承担部门
|
|
|
|
+ bizAcctOutBill.set("costcompany", getF7FieldValue("bos_org", "number", "3140"));//费用承担公司
|
|
|
|
+
|
|
|
|
+ //费用明细
|
|
|
|
+ DynamicObjectCollection expenseEntry = bizAcctOutBill.getDynamicObjectCollection("expenseentryentity");
|
|
|
|
+ DynamicObjectType type = expenseEntry.getDynamicObjectType();
|
|
|
|
+ JSONArray bizAccountOutBillEntry = inputData.getJSONArray("bizAccountOutBillEntry");
|
|
|
|
+
|
|
|
|
+ for(int i = 0; i < bizAccountOutBillEntry.size(); i++){
|
|
|
|
+ JSONObject jsonData = bizAccountOutBillEntry.getJSONObject(i);
|
|
|
|
+
|
|
|
|
+ String xsproject = "FYXM01.26";//jsonData.getString("xsproject");//核算项目,项目编号
|
|
|
|
+ String tax = jsonData.getString("tax");//税额
|
|
|
|
+ String amountOriWithoutTax = jsonData.getString("amountOriWithoutTax");//原币不含税金额
|
|
|
|
+ String taxRate = jsonData.getString("taxRate");//税率
|
|
|
|
+ String currencyType = jsonData.getString("currencyType");//币别
|
|
|
|
+ String amountOri = jsonData.getString("amountOri");//原币金额
|
|
|
|
+
|
|
|
|
+ DynamicObject entry = new DynamicObject(type);
|
|
|
|
+
|
|
|
|
+ entry.set("expenseitem", getF7FieldValue("er_expenseitemedit", "number", "FYXM01.26"));
|
|
|
|
+ entry.set("entrycurrency", getF7FieldValue("bd_currency", "number", "CNY"));
|
|
|
|
+ entry.set("expenseamount", "100");
|
|
|
|
+
|
|
|
|
+ expenseEntry.add(entry);
|
|
|
|
+ }
|
|
|
|
+ bizAcctOutBill.set("expenseentryentity", expenseEntry);
|
|
|
|
+
|
|
|
|
+// //收款明细
|
|
|
|
+// DynamicObjectCollection accountEntry = bizAcctOutBill.getDynamicObjectCollection("accountentry");
|
|
|
|
+// type = accountEntry.getDynamicObjectType();
|
|
|
|
+// JSONArray bizAccountOutBillAccountEntry = inputData.getJSONArray("bizAccountOutBillAccountEntry");
|
|
|
|
+//
|
|
|
|
+// for(int i = 0; i < bizAccountOutBillAccountEntry.size(); i++){
|
|
|
|
+// JSONObject jsonData = bizAccountOutBillAccountEntry.getJSONObject(i);
|
|
|
|
+//
|
|
|
|
+// String payerType = jsonData.getString("payerType");//收款人类型
|
|
|
|
+// String payerName = jsonData.getString("payerName");//原币社会信用码
|
|
|
|
+// String amountOri = jsonData.getString("amountOri");//原币金额
|
|
|
|
+// String currencyType = jsonData.getString("currencyType");//币别
|
|
|
|
+//
|
|
|
|
+// DynamicObject entry = new DynamicObject(type);
|
|
|
|
+//
|
|
|
|
+// accountEntry.add(entry);
|
|
|
|
+// }
|
|
|
|
+// bizAcctOutBill.set("accountentry", accountEntry);
|
|
|
|
+//
|
|
|
|
+// //冲预付/借款
|
|
|
|
+// DynamicObjectCollection writeoffmoney = bizAcctOutBill.getDynamicObjectCollection("writeoffmoney");
|
|
|
|
+// type = writeoffmoney.getDynamicObjectType();
|
|
|
|
+// JSONArray bizAccountOutBillLoanCheckEntry = inputData.getJSONArray("bizAccountOutBillLoanCheckEntry");
|
|
|
|
+//
|
|
|
|
+// for(int i = 0; i < bizAccountOutBillLoanCheckEntry.size(); i++){
|
|
|
|
+// JSONObject jsonData = bizAccountOutBillLoanCheckEntry.getJSONObject(i);
|
|
|
|
+//
|
|
|
|
+// String sourceBillNumber = jsonData.getString("sourceBillNumber");//源单编号(借款单)
|
|
|
|
+// String checkAmountOri = jsonData.getString("checkAmountOri");//冲账金额
|
|
|
|
+// String currencyType = jsonData.getString("currencyType");//币别
|
|
|
|
+// String srmseq = jsonData.getString("srmseq");//预付单行号
|
|
|
|
+//
|
|
|
|
+// DynamicObject entry = new DynamicObject(type);
|
|
|
|
+//
|
|
|
|
+// writeoffmoney.add(entry);
|
|
|
|
+// }
|
|
|
|
+// bizAcctOutBill.set("writeoffmoney", writeoffmoney);
|
|
|
|
+//
|
|
|
|
+// //发票信息
|
|
|
|
+// DynamicObjectCollection invoiceEntry = bizAcctOutBill.getDynamicObjectCollection("invoiceentry");
|
|
|
|
+// type = invoiceEntry.getDynamicObjectType();
|
|
|
|
+// JSONArray fpentry = inputData.getJSONArray("fpentry");
|
|
|
|
+//
|
|
|
|
+// for(int i = 0; i < fpentry.size(); i++){
|
|
|
|
+// JSONObject jsonData = fpentry.getJSONObject(i);
|
|
|
|
+//
|
|
|
|
+// String fpNumber = jsonData.getString("fpNumber");//发票号
|
|
|
|
+// String fpCode = jsonData.getString("fpCode");//发票代码
|
|
|
|
+// String taxAmount = jsonData.getString("taxAmount");//税额
|
|
|
|
+//
|
|
|
|
+// DynamicObject entry = new DynamicObject(type);
|
|
|
|
+//
|
|
|
|
+// invoiceEntry.add(entry);
|
|
|
|
+// }
|
|
|
|
+// bizAcctOutBill.set("invoiceentry", invoiceEntry);
|
|
|
|
+
|
|
|
|
+// try {
|
|
|
|
+ JSONArray test = new JSONArray();
|
|
|
|
+
|
|
|
|
+ JSONObject testobj = new JSONObject();
|
|
|
|
+// testobj.put("billno", "testsdk");
|
|
|
|
+ testobj.put("bizdate", "2022-08-29");
|
|
|
|
+ testobj.put("description", "test");
|
|
|
|
+ testobj.put("applier_number", "ID-000014");
|
|
|
|
+ testobj.put("org_number", "20240612-0009");
|
|
|
|
+ testobj.put("company_number", "20240612-0009");
|
|
|
|
+ testobj.put("costdept_number", "20240612-0009");
|
|
|
|
+ testobj.put("costcompany_number", "3140");
|
|
|
|
+
|
|
|
|
+ JSONArray entryArray = new JSONArray();
|
|
|
|
+
|
|
|
|
+ JSONObject entryObj = new JSONObject();
|
|
|
|
+ entryObj.put("entrycurrency_number", "CNY");
|
|
|
|
+ entryObj.put("expenseitem_number", "FYXM01.26");
|
|
|
|
+ entryObj.put("expenseamount", "989.92");
|
|
|
|
+
|
|
|
|
+ entryArray.add(entryObj);
|
|
|
|
+
|
|
|
|
+ testobj.put("expenseentryentity", entryArray);
|
|
|
|
+
|
|
|
|
+ test.add(testobj);
|
|
|
|
+
|
|
|
|
+ JSONObject requestDataJson = new JSONObject();
|
|
|
|
+ requestDataJson.put("data", test);
|
|
|
|
+
|
|
|
|
+// OpenApiResult result = OpenApiSdkUtil.invoke("/v2/em/er_publicreimbursebill/er_publicreimbursebill_save", requestDataJson, new HashMap<>());
|
|
|
|
+
|
|
|
|
+// String message = result.getMessage();
|
|
|
|
+
|
|
|
|
+ //新增保存供应商对象
|
|
|
|
+ OperationResult resultSave = SaveServiceHelper.saveOperate(ENTITY_PUBLICPAY, new DynamicObject[]{bizAcctOutBill}, OperateOption.create());
|
|
|
|
+
|
|
|
|
+ StringBuilder err = new StringBuilder();
|
|
|
|
+ if (resultSave.getSuccessPkIds().size() <= 0) {
|
|
|
|
+ for (int i = 0; i < resultSave.getAllErrorOrValidateInfo().size(); i++) {
|
|
|
|
+ String message = resultSave.getAllErrorOrValidateInfo().get(i).getMessage();
|
|
|
|
+ err.append("/").append(message);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ returnMap.put("code", "500");
|
|
|
|
+ returnMap.put("msg", err.toString());
|
|
|
|
+
|
|
|
|
+ return returnMap;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+// } catch(Exception e){
|
|
|
|
+// String msg = e.getMessage();
|
|
|
|
+//
|
|
|
|
+// }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+// DynamicObject customerObj = BusinessDataServiceHelper.loadSingle(supplierId, "bd_supplier");
|
|
|
|
+//
|
|
|
|
+// OperationServiceHelper.executeOperate("submit", ENTITY_SUPPLIER, new DynamicObject[]{customerObj}, OperateOption.create());
|
|
|
|
+// OperationServiceHelper.executeOperate("audit", ENTITY_SUPPLIER, new DynamicObject[]{customerObj}, OperateOption.create());
|
|
|
|
+
|
|
|
|
+ return returnMap;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private DynamicObject getF7FieldValue(String entityName, String type, String value){
|
|
|
|
+ QFilter qFilter = new QFilter("status", QCP.equals, "C");
|
|
|
|
+ qFilter.and(new QFilter("number", QCP.equals, value));
|
|
|
|
+
|
|
|
|
+ DynamicObject objectInfo = BusinessDataServiceHelper.loadSingle(entityName, qFilter.toArray());
|
|
|
|
+
|
|
|
|
+ return objectInfo;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 同步付款
|
|
|
|
+ * @param dailyLoanBills
|
|
|
|
+ */
|
|
|
|
+ private JSONArray synDailyLoanBill(JSONArray dailyLoanBills){
|
|
|
|
+ JSONArray responseData = new JSONArray();
|
|
|
|
+
|
|
|
|
+ return responseData;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 自定义返回data对象
|
|
|
|
+ * @param code 编码
|
|
|
|
+ * @param message 错误信息
|
|
|
|
+ * @return CustomApiResult 返回
|
|
|
|
+ */
|
|
|
|
+ public CustomApiResult<JSONObject> returnResult(String code, String message, JSONArray responseData){
|
|
|
|
+ JSONObject reslutData = new JSONObject();
|
|
|
|
+
|
|
|
|
+ reslutData.put("message", message);
|
|
|
|
+ reslutData.put("code", code);
|
|
|
|
+
|
|
|
|
+ reslutData.put("data", responseData);
|
|
|
|
+
|
|
|
|
+ return CustomApiResult.success(reslutData);
|
|
|
|
+ }
|
|
|
|
+}
|