资金计划定时任务调用sap接口
This commit is contained in:
parent
d9fe22b56e
commit
f8f2438c71
|
|
@ -434,13 +434,13 @@ public class ClearAccountBillOperation extends AbstractOperationServicePlugIn im
|
|||
DynamicObject userinfo = BusinessDataServiceHelper.loadSingleFromCache(RequestContext.get().getCurrUserId(), userName);
|
||||
String oauser = userinfo.getString("shjh_oauser");
|
||||
IS_HEADER.put("USNAM",oauser);//用户名
|
||||
//----------------处理详细入参----------------------
|
||||
//----------------处理详细入参(清账不需要items参数)----------------------
|
||||
String customerCode = customerinfo.getString("number");
|
||||
JSONObject item = new JSONObject();
|
||||
item.put("KUNNR",customerCode);//客户编号
|
||||
item.put("HKONT","");//TODO 总账科目
|
||||
item.put("DMBTR",prinfo.getString("shjh_receamount"));//金额-传清账单收款金额
|
||||
IT_ITEM.add(item);
|
||||
// JSONObject item = new JSONObject();
|
||||
// item.put("KUNNR",customerCode);//客户编号
|
||||
// item.put("HKONT","");//总账科目
|
||||
// item.put("DMBTR",prinfo.getString("shjh_receamount"));//金额-传清账单收款金额
|
||||
// IT_ITEM.add(item);
|
||||
//----------------处理清账数据入参----------------------
|
||||
DynamicObjectCollection docolls = prinfo.getDynamicObjectCollection("shjh_details");
|
||||
DynamicObject entryinfo;
|
||||
|
|
@ -466,7 +466,7 @@ public class ClearAccountBillOperation extends AbstractOperationServicePlugIn im
|
|||
}
|
||||
return entryidList;
|
||||
});
|
||||
//遍历map
|
||||
//遍历map,还原收款单对象
|
||||
DynamicObject recebill;//收款单
|
||||
for (Map.Entry<Long,Long> entry : entrybillids.entrySet()) {
|
||||
//收款单分录ID entry.getKey();
|
||||
|
|
|
|||
|
|
@ -16,8 +16,16 @@ import kd.bos.schedule.executor.AbstractTask;
|
|||
import kd.bos.servicehelper.BusinessDataServiceHelper;
|
||||
import kd.sdk.plugin.Plugin;
|
||||
import kd.tmc.fpm.business.dataproc.save.ReportDataSDKService;
|
||||
import kd.tmc.fpm.business.dataproc.save.domain.FpmResponse;
|
||||
import kd.tmc.fpm.business.dataproc.save.domain.ReportDataBatchSaveParam;
|
||||
import shjh.jhzj7.fi.fi.utils.JhzjUtils;
|
||||
import shjh.jhzj7.fi.fi.utils.SapUtils;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
|
|
@ -40,15 +48,30 @@ public class FundPlanCollectionTask extends AbstractTask implements Plugin {
|
|||
DynamicObject[] collection = BusinessDataServiceHelper.load(entityName, "id", qFilter.toArray());
|
||||
if(collection.length > 0){
|
||||
//调用SAP应收已清接口,按照公司、月份、计划科目汇总金额
|
||||
Map<String, BigDecimal> acctamountMap = getSapARClearedData();
|
||||
if(acctamountMap == null){
|
||||
return;
|
||||
}
|
||||
ReportDataSDKService reportService = new ReportDataSDKService();//报表服务,用于写入或者查询报表数据
|
||||
ReportDataBatchSaveParam pdsp;//报表批量保存的参数
|
||||
JSONObject json_obj;//入参主对象
|
||||
JSONArray items;//计划科目明细
|
||||
String reportPeriodCode;//编报期间的编号
|
||||
DynamicObject reportOrg;//编报主体对象
|
||||
DynamicObject accountInfo;//资金计划科目
|
||||
DynamicObjectCollection maindimentrys;
|
||||
String billno;//资金计划编制单号
|
||||
String result;//反写结果
|
||||
FpmResponse<Void> frv;//反写结果
|
||||
for(DynamicObject doinfo : collection){
|
||||
doinfo = BusinessDataServiceHelper.loadSingle(doinfo.getPkValue(),entityName);
|
||||
billno = doinfo.getString("billno");
|
||||
logger.info("资金计划编制单号"+billno);
|
||||
maindimentrys = doinfo.getDynamicObjectCollection("maindimentry");//主维度分录
|
||||
if(maindimentrys.isEmpty()){
|
||||
logger.info("资金计划编制单主维度分录为空,不继续反写"+billno);
|
||||
continue;
|
||||
}
|
||||
json_obj = new JSONObject();
|
||||
//体系编号 非必填时,系统通过【编报主体 code】确定,需保证一个编报主体只关联一个体系
|
||||
json_obj.put("systemCode",doinfo.getDynamicObject("bodysys").getString("number"));
|
||||
|
|
@ -57,13 +80,16 @@ public class FundPlanCollectionTask extends AbstractTask implements Plugin {
|
|||
reportOrg = doinfo.getDynamicObject("reportorg");
|
||||
json_obj.put("reportOrgCode",reportOrg.getString("number"));//编报主体 code
|
||||
//组装计划科目
|
||||
maindimentrys = doinfo.getDynamicObjectCollection("maindimentry");//主维度分录
|
||||
items = new JSONArray(maindimentrys.size());
|
||||
int i = 1;
|
||||
for(DynamicObject entryinfo : maindimentrys){
|
||||
accountInfo = entryinfo.getDynamicObject("subjectmem");
|
||||
if(!accountInfo.getBoolean("isleaf")){
|
||||
continue;
|
||||
}
|
||||
JSONObject itemInfo = new JSONObject();
|
||||
itemInfo.put("currencyCode",entryinfo.getDynamicObject("currencymem").getString("number"));//币别 code
|
||||
itemInfo.put("subjectCode",entryinfo.getDynamicObject("subjectmem").getString("number"));//计划科目 code
|
||||
itemInfo.put("subjectCode",accountInfo.getString("number"));//计划科目 code
|
||||
itemInfo.put("entryPeriodCode",entryinfo.getDynamicObject("periodmem").getString("number"));//主维度数据分录期间 code
|
||||
//组装度量值
|
||||
JSONArray mms = new JSONArray(1);//科目的度量值明细,目前只写入计划参考数
|
||||
|
|
@ -78,10 +104,66 @@ public class FundPlanCollectionTask extends AbstractTask implements Plugin {
|
|||
}
|
||||
|
||||
json_obj.put("batchSaveData",items);//报表批量写入数据
|
||||
logger.info("收款计划实际数入参"+json_obj.toJSONString());
|
||||
logger.info(billno+"收款计划实际数入参"+json_obj.toJSONString());
|
||||
pdsp = gson.fromJson(json_obj.toJSONString(), ReportDataBatchSaveParam.class);
|
||||
reportService.batchSaveReportData(SerializationUtils.serializeToBase64(pdsp));
|
||||
result = reportService.batchSaveReportData(SerializationUtils.serializeToBase64(pdsp));
|
||||
frv = SerializationUtils.deSerializeFromBase64(result);
|
||||
logger.info(billno+"收款计划实际数反写结果"+frv.getCode()+frv.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Map<String, BigDecimal> getSapARClearedData(){
|
||||
//获取当前日期
|
||||
Calendar cal = Calendar.getInstance();
|
||||
//设置日期为本月1号
|
||||
cal.set(Calendar.DAY_OF_MONTH, 1);
|
||||
//将日期减去一月份得到上月1号
|
||||
cal.add(Calendar.MONTH, -1);
|
||||
//获取上月1号的日期
|
||||
Date lastMonthFirstDay = cal.getTime();
|
||||
//日期格式
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
||||
JSONArray IT_LIST = new JSONArray();
|
||||
String duedate_starts = sdf.format(lastMonthFirstDay);//上月1号
|
||||
String duedate_ends = sdf.format(new Date());//当前月
|
||||
addFilterCondition(IT_LIST, "BUDAT", duedate_starts, duedate_ends);//过账日期-上月和当前月
|
||||
JSONObject sapresult = SapUtils.sapARClearedDataAPI(IT_LIST, "FundPlanCollectionTask");
|
||||
if(sapresult != null){
|
||||
JSONObject data = sapresult.getJSONObject("data");
|
||||
if(data != null){
|
||||
JSONArray items = data.getJSONArray("IT_ITEM");
|
||||
Map<String, BigDecimal> acctamountMap = new HashMap<>();
|
||||
BigDecimal amount;
|
||||
String productnum;
|
||||
for (int i = 0; i < items.size(); i++) {
|
||||
sapresult = items.getJSONObject(i);
|
||||
amount = sapresult.getBigDecimal("DMBTR");//已清金额
|
||||
productnum = sapresult.getString("SPART");//产品组
|
||||
if(acctamountMap.containsKey(productnum)){
|
||||
acctamountMap.put(productnum, JhzjUtils.addTwoAmount(amount,acctamountMap.get(productnum)));
|
||||
}else{
|
||||
acctamountMap.put(productnum,amount);
|
||||
}
|
||||
// sapresult.getString("BUKRS");//公司编号
|
||||
// sapresult.getString("BUDAT");//过账日期
|
||||
// sapresult.getString("WAERS");//币别编号
|
||||
// sapresult.getString("HKONT");//科目编号
|
||||
// sapresult.getString("RSTGR");//付款原因代码
|
||||
}
|
||||
return acctamountMap;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public 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:排除
|
||||
jsonObject.put("LOW", low); // LOW,枚举字段所代表值的区间开始值
|
||||
jsonObject.put("HIGH", high); // HIGH,枚举字段所代表值的区间结束值
|
||||
jsonObject.put("OPTION", "BT"); //默认BT
|
||||
IT_LIST.add(jsonObject);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,8 +16,11 @@ import kd.bos.schedule.executor.AbstractTask;
|
|||
import kd.bos.servicehelper.BusinessDataServiceHelper;
|
||||
import kd.sdk.plugin.Plugin;
|
||||
import kd.tmc.fpm.business.dataproc.save.ReportDataSDKService;
|
||||
import kd.tmc.fpm.business.dataproc.save.domain.FpmResponse;
|
||||
import kd.tmc.fpm.business.dataproc.save.domain.ReportDataBatchSaveParam;
|
||||
import shjh.jhzj7.fi.fi.utils.SapUtils;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
|
|
@ -49,9 +52,20 @@ public class FundPlanPaymentTask extends AbstractTask implements Plugin {
|
|||
JSONArray items;//计划科目明细
|
||||
String reportPeriodCode;//编报期间的编号
|
||||
DynamicObject reportOrg;//编报主体对象
|
||||
DynamicObject accountInfo;//资金计划科目
|
||||
DynamicObjectCollection maindimentrys;
|
||||
String billno;//资金计划编制单号
|
||||
String result;//反写结果
|
||||
FpmResponse<Void> frv;//反写结果
|
||||
for(DynamicObject doinfo : collection){
|
||||
doinfo = BusinessDataServiceHelper.loadSingle(doinfo.getPkValue(),entityName);
|
||||
billno = doinfo.getString("billno");
|
||||
logger.info("资金计划编制单号"+billno);
|
||||
maindimentrys = doinfo.getDynamicObjectCollection("maindimentry");//主维度分录
|
||||
if(maindimentrys.isEmpty()){
|
||||
logger.info("资金计划编制单主维度分录为空,不继续反写"+billno);
|
||||
continue;
|
||||
}
|
||||
json_obj = new JSONObject();
|
||||
//体系编号 非必填时,系统通过【编报主体 code】确定,需保证一个编报主体只关联一个体系
|
||||
json_obj.put("systemCode",doinfo.getDynamicObject("bodysys").getString("number"));
|
||||
|
|
@ -60,13 +74,16 @@ public class FundPlanPaymentTask extends AbstractTask implements Plugin {
|
|||
reportOrg = doinfo.getDynamicObject("reportorg");
|
||||
json_obj.put("reportOrgCode",reportOrg.getString("number"));//编报主体 code
|
||||
//组装计划科目
|
||||
maindimentrys = doinfo.getDynamicObjectCollection("maindimentry");//主维度分录
|
||||
items = new JSONArray(maindimentrys.size());
|
||||
int i = 1;
|
||||
for(DynamicObject entryinfo : maindimentrys){
|
||||
accountInfo = entryinfo.getDynamicObject("subjectmem");
|
||||
if(!accountInfo.getBoolean("isleaf")){
|
||||
continue;
|
||||
}
|
||||
JSONObject itemInfo = new JSONObject();
|
||||
itemInfo.put("currencyCode",entryinfo.getDynamicObject("currencymem").getString("number"));//币别 code
|
||||
itemInfo.put("subjectCode",entryinfo.getDynamicObject("subjectmem").getString("number"));//计划科目 code
|
||||
itemInfo.put("subjectCode",accountInfo.getString("number"));//计划科目 code
|
||||
itemInfo.put("entryPeriodCode",entryinfo.getDynamicObject("periodmem").getString("number"));//主维度数据分录期间 code
|
||||
//组装度量值
|
||||
JSONArray mms = new JSONArray(1);//科目的度量值明细,目前只写入计划参考数
|
||||
|
|
@ -81,11 +98,46 @@ public class FundPlanPaymentTask extends AbstractTask implements Plugin {
|
|||
}
|
||||
|
||||
json_obj.put("batchSaveData",items);//报表批量写入数据
|
||||
logger.info("付款计划参考数入参"+json_obj.toJSONString());
|
||||
logger.info(billno+"付款计划参考数入参"+json_obj.toJSONString());
|
||||
pdsp = gson.fromJson(json_obj.toJSONString(), ReportDataBatchSaveParam.class);
|
||||
reportService.batchSaveReportData(SerializationUtils.serializeToBase64(pdsp));
|
||||
result = reportService.batchSaveReportData(SerializationUtils.serializeToBase64(pdsp));
|
||||
frv = SerializationUtils.deSerializeFromBase64(result);
|
||||
logger.info(billno+"付款计划参考数反写结果"+frv.getCode()+frv.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private JSONObject getSapAR(){
|
||||
//日期格式
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
||||
JSONArray IT_LIST = new JSONArray();
|
||||
String duedate_starts = sdf.format(null);
|
||||
String duedate_ends = sdf.format(null);
|
||||
addFilterCondition(IT_LIST, "FAEDT", duedate_starts, duedate_ends);//到期日
|
||||
JSONObject sapresult = SapUtils.vouchers_payable(IT_LIST, "FundPlanPaymentTask");
|
||||
if(sapresult != null){
|
||||
JSONObject data = sapresult.getJSONObject("data");
|
||||
if(data != null){
|
||||
JSONArray items = data.getJSONArray("IT_ITEM");
|
||||
for (int i = 0; i < items.size(); i++) {
|
||||
sapresult = items.getJSONObject(i);
|
||||
sapresult.getString("BUKRS");//公司编号
|
||||
sapresult.getString("FAEDT");//到期日
|
||||
sapresult.getString("WRBTR");//未清金额
|
||||
sapresult.getString("ZREQ_DEPT");//二级部门,需求部门
|
||||
}
|
||||
}
|
||||
}
|
||||
return sapresult;
|
||||
}
|
||||
|
||||
public 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:排除
|
||||
jsonObject.put("LOW", low); // LOW,枚举字段所代表值的区间开始值
|
||||
jsonObject.put("HIGH", high); // HIGH,枚举字段所代表值的区间结束值
|
||||
jsonObject.put("OPTION", "BT"); //默认BT
|
||||
IT_LIST.add(jsonObject);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -48,6 +48,9 @@ public class SapUtils {
|
|||
private static final String interfaceID5 = "AccountsReceivableVoucherList";//SAP应收凭证清单 识别被调接口并进行路由
|
||||
private static final String Apimenthod5 = "SAP应收凭证清单";
|
||||
|
||||
private static final String interfaceID8 = "ARClearedDataQuery";//SAP应收已清收款(拆分品牌)数据 识别被调接口并进行路由
|
||||
private static final String Apimenthod8 = "SAP应收已清收款";
|
||||
|
||||
private static final String interfaceID6 = "ReversalVoucher";//SAP反清账 识别被调接口并进行路由
|
||||
private static final String Apimenthod6 = "SAP反清账";
|
||||
private static final String interfaceID7 = "FinancialTransactionVoucher";//SAP清账 识别被调接口并进行路由
|
||||
|
|
@ -127,6 +130,24 @@ public class SapUtils {
|
|||
return processRequest(arBody, thirdPartyMap, Apimenthod5);
|
||||
}
|
||||
|
||||
/**
|
||||
* SAP应收已清收款(拆分品牌)数据接口
|
||||
* @param IT_LIST 过滤条件入参
|
||||
* @param billno 单据编号
|
||||
* @author yuxueliang
|
||||
*/
|
||||
public static JSONObject sapARClearedDataAPI(JSONArray IT_LIST,String billno){
|
||||
Map<String, Object> thirdPartyMap = new HashMap<>();
|
||||
thirdPartyMap.put("interfaceID",interfaceID8);
|
||||
thirdPartyMap.put("receiverID",receiverID1);
|
||||
thirdPartyMap.put("URL",sapArUrl);
|
||||
thirdPartyMap.put("billno",billno);
|
||||
// 组装请求体
|
||||
JSONObject arBody = sapArBody("ZAP_INPUT",IT_LIST);
|
||||
// 发送请求并处理响应
|
||||
return processRequest(arBody, thirdPartyMap, Apimenthod8);
|
||||
}
|
||||
|
||||
/**
|
||||
* SAP反清账接口
|
||||
* @param IT_LIST 过滤条件入参
|
||||
|
|
|
|||
Loading…
Reference in New Issue