资金计划优化

This commit is contained in:
yuxueliang0813 2025-04-01 17:54:21 +08:00
parent 3e84d58207
commit 04963a8444
4 changed files with 154 additions and 32 deletions

View File

@ -65,6 +65,11 @@ public class InitAccountFormPlugin extends AbstractFormPlugin {
if (StringUtils.equals(OK_BUTTON_KEY, key)) { if (StringUtils.equals(OK_BUTTON_KEY, key)) {
// 点击确认按钮 // 点击确认按钮
String params = (String) this.getModel().getValue("shjh_largetextfield"); String params = (String) this.getModel().getValue("shjh_largetextfield");
if(EsbUtils.isEmpty(params)){
this.getView().showMessage("请输入科目JSON格式参数");
return ;
}
params = params.replace("\n","").replace("\t","");
JSONObject json_obj = JSONObject.parseObject(params); JSONObject json_obj = JSONObject.parseObject(params);
JSONArray detailsJson = json_obj.getJSONArray("items"); JSONArray detailsJson = json_obj.getJSONArray("items");
if(detailsJson == null){ if(detailsJson == null){

View File

@ -34,6 +34,8 @@ import java.util.Map;
*/ */
public class FundPlanCollectionTask extends AbstractTask implements Plugin { public class FundPlanCollectionTask extends AbstractTask implements Plugin {
private static final String entityName = "fpm_report";//资金计划编制 t_fpm_report private static final String entityName = "fpm_report";//资金计划编制 t_fpm_report
private static final String payReceName = "shjh_pay_account";//收付款资金计划科目配置表
private static final String ppsybName = "shjh_pp_syb";//品牌和事业部对应关系 tk_shjh_pp_syb
private static final Log logger = LogFactory.getLog(FundPlanCollectionTask.class); private static final Log logger = LogFactory.getLog(FundPlanCollectionTask.class);
private Gson gson = new Gson();//用于将json格式化为对象 private Gson gson = new Gson();//用于将json格式化为对象
@ -59,7 +61,10 @@ public class FundPlanCollectionTask extends AbstractTask implements Plugin {
String reportPeriodCode;//编报期间的编号 String reportPeriodCode;//编报期间的编号
DynamicObject reportOrg;//编报主体对象 DynamicObject reportOrg;//编报主体对象
DynamicObject accountInfo;//资金计划科目 DynamicObject accountInfo;//资金计划科目
DynamicObjectCollection maindimentrys; String sybnum;//事业部编号-编报主体的编号
String months;//月份-科目编制分录中的期间编号
String accountnum;//资金计划科目编号
DynamicObjectCollection maindimentrys;//主维度分录-包含了父级和子级所有科目
String billno;//资金计划编制单号 String billno;//资金计划编制单号
String result;//反写结果 String result;//反写结果
FpmResponse<Void> frv;//反写结果 FpmResponse<Void> frv;//反写结果
@ -78,25 +83,27 @@ public class FundPlanCollectionTask extends AbstractTask implements Plugin {
reportPeriodCode = doinfo.getDynamicObject("reportperiod").getString("number"); reportPeriodCode = doinfo.getDynamicObject("reportperiod").getString("number");
json_obj.put("reportPeriodCode",reportPeriodCode);//编报期间 code json_obj.put("reportPeriodCode",reportPeriodCode);//编报期间 code
reportOrg = doinfo.getDynamicObject("reportorg"); reportOrg = doinfo.getDynamicObject("reportorg");
json_obj.put("reportOrgCode",reportOrg.getString("number"));//编报主体 code sybnum = reportOrg.getString("number");
json_obj.put("reportOrgCode",sybnum);//编报主体 code
//组装计划科目 //组装计划科目
items = new JSONArray(maindimentrys.size()); items = new JSONArray(maindimentrys.size());
int i = 1;
for(DynamicObject entryinfo : maindimentrys){ for(DynamicObject entryinfo : maindimentrys){
accountInfo = entryinfo.getDynamicObject("subjectmem"); accountInfo = entryinfo.getDynamicObject("subjectmem");
if(!accountInfo.getBoolean("isleaf")){ if(!accountInfo.getBoolean("isleaf")){
continue; continue;
} }
accountnum = accountInfo.getString("number");
JSONObject itemInfo = new JSONObject(); JSONObject itemInfo = new JSONObject();
itemInfo.put("currencyCode",entryinfo.getDynamicObject("currencymem").getString("number"));//币别 code itemInfo.put("currencyCode",entryinfo.getDynamicObject("currencymem").getString("number"));//币别 code
itemInfo.put("subjectCode",accountInfo.getString("number"));//计划科目 code itemInfo.put("subjectCode",accountnum);//计划科目 code
itemInfo.put("entryPeriodCode",entryinfo.getDynamicObject("periodmem").getString("number"));//主维度数据分录期间 code months = entryinfo.getDynamicObject("periodmem").getString("number");
itemInfo.put("entryPeriodCode",months);//主维度数据分录期间 code
//组装度量值 //组装度量值
JSONArray mms = new JSONArray(1);//科目的度量值明细目前只写入计划参考数 JSONArray mms = new JSONArray(1);//科目的度量值明细目前只写入计划参考数
JSONObject mmInfo = new JSONObject(); JSONObject mmInfo = new JSONObject();
//PLANREFERENCEAMT 计划参考值 ACTMAT 已执行额度 //PLANREFERENCEAMT 计划参考值 ACTMAT 已执行额度
mmInfo.put("templateMetricType","ACTMAT");//度量值预置类型 mmInfo.put("templateMetricType","ACTMAT");//度量值预置类型
mmInfo.put("amount",i++);//TODO 写入金额-从SAP接口中获取 mmInfo.put("amount",acctamountMap.get(sybnum+months+accountnum));//写入金额-从SAP接口中汇总
mmInfo.put("amountUnit","one");//金额单位 one元 thousand千元 ten_thousand 万元 mmInfo.put("amountUnit","one");//金额单位 one元 thousand千元 ten_thousand 万元
mms.add(mmInfo); mms.add(mmInfo);
itemInfo.put("metricMembers",mms);//度量值列表 itemInfo.put("metricMembers",mms);//度量值列表
@ -135,18 +142,35 @@ public class FundPlanCollectionTask extends AbstractTask implements Plugin {
JSONArray items = data.getJSONArray("IT_ITEM"); JSONArray items = data.getJSONArray("IT_ITEM");
Map<String, BigDecimal> acctamountMap = new HashMap<>(); Map<String, BigDecimal> acctamountMap = new HashMap<>();
BigDecimal amount; BigDecimal amount;
String productnum; String productnum;//品牌
String sybnum;//事业部编号
String months;//月份
String accountnum;//资金计划科目编号
String mapkey;//事业部编号+月份+资金计划科目编号
DynamicObject ppsybinfo;
for (int i = 0; i < items.size(); i++) { for (int i = 0; i < items.size(); i++) {
sapresult = items.getJSONObject(i); sapresult = items.getJSONObject(i);
amount = sapresult.getBigDecimal("DMBTR");//已清金额 amount = sapresult.getBigDecimal("DMBTR");//已清金额
productnum = sapresult.getString("SPART");//产品组 productnum = sapresult.getString("SPART");//产品组
if(acctamountMap.containsKey(productnum)){ months = sapresult.getString("BUDAT");//过账日期
acctamountMap.put(productnum, JhzjUtils.addTwoAmount(amount,acctamountMap.get(productnum))); if(JhzjUtils.isEmpty(months)){
continue;
}
months = JhzjUtils.getFundPeriodBySAPDate(months);
//根据品牌和事业部关系将该笔金额归属到事业部上
ppsybinfo = BusinessDataServiceHelper.loadSingleFromCache(ppsybName,new QFilter[]{new QFilter("shjh_pp", QCP.equals, productnum)});
if(ppsybinfo != null){
sybnum = ppsybinfo.getDynamicObject("shjh_division").getString("number");
mapkey = sybnum+months;
if(acctamountMap.containsKey(mapkey)){
acctamountMap.put(mapkey, JhzjUtils.addTwoAmount(amount,acctamountMap.get(mapkey)));
}else{
acctamountMap.put(mapkey,amount);
}
}else{ }else{
acctamountMap.put(productnum,amount); //TODO 如果品牌没有对应的事业部时数据放哪里
} }
// sapresult.getString("BUKRS");//公司编号 // sapresult.getString("BUKRS");//公司编号
// sapresult.getString("BUDAT");//过账日期
// sapresult.getString("WAERS");//币别编号 // sapresult.getString("WAERS");//币别编号
// sapresult.getString("HKONT");//科目编号 // sapresult.getString("HKONT");//科目编号
// sapresult.getString("RSTGR");//付款原因代码 // sapresult.getString("RSTGR");//付款原因代码
@ -157,6 +181,78 @@ public class FundPlanCollectionTask extends AbstractTask implements Plugin {
return null; return null;
} }
//根据sap的应收已清数据获取对应的资金计划科目编号
private String xdMembersubjectNumber(DynamicObject bill){
//收款单系统自动根据配置表(shjh_pay_account)带出资金计划科目
QFilter qFilter = new QFilter("shjh_biztype", QCP.equals,"B");//业务类型:收款
//公司范围_多选基础资料
DynamicObject openorg = bill.getDynamicObject("openorg");
if (null != openorg) {
Long orgid = openorg.getLong("id");
QFilter q1 = new QFilter("shjh_companys.fbasedataid", QCP.equals, orgid);
qFilter = qFilter.and(q1);
}
//业务大类
DynamicObject shjhBizbig = bill.getDynamicObject("shjh_bizebig");
if (null != shjhBizbig) {
Long shjhBizbigid = shjhBizbig.getLong("id");
QFilter q2 = new QFilter("shjh_bizbig.fbasedataid", QCP.equals, shjhBizbigid);
qFilter = qFilter.and(q2);
}
//业务小类
DynamicObject shjhbizsmall = bill.getDynamicObject("shjh_bizsmall");
if (null != shjhbizsmall) {
Long shjhbizsmallid = shjhbizsmall.getLong("id");
QFilter q3 = new QFilter("shjh_bizsmall.fbasedataid", QCP.equals, shjhbizsmallid);
qFilter = qFilter.and(q3);
}
//成本中心 shjh_costcenter
DynamicObject shjhCostcenter = bill.getDynamicObject("shjh_costcenter");
if (null != shjhCostcenter) {
Long costcenterid = shjhCostcenter.getLong("id");
QFilter q4 = new QFilter("shjh_cc.fbasedataid", QCP.equals, costcenterid);
qFilter = qFilter.and(q4);
}
DynamicObjectCollection entrys = bill.getDynamicObjectCollection("entry");//付款明细
if (!entrys.isEmpty()) {
DynamicObject entry = entrys.get(0);
//原因码 shjh_reasoncode
DynamicObject shjhYym = entry.getDynamicObject("shjh_yym");
if (null != shjhYym) {
Long yymid = shjhYym.getLong("id");
QFilter q5 = new QFilter("shjh_yym.fbasedataid", QCP.equals, yymid);
qFilter = qFilter.and(q5);
}
//会计科目 shjh_coaitemcode
DynamicObject shjhSapkjkm = entry.getDynamicObject("shjh_accountsap");
if (null != shjhSapkjkm) {
Long kjkmid = shjhSapkjkm.getLong("id");
QFilter q6 = new QFilter("shjh_kjkm.fbasedataid", QCP.equals, kjkmid);
qFilter = qFilter.and(q6);
}
}
DynamicObject[] accounts = BusinessDataServiceHelper.load(payReceName, "id", qFilter.toArray());
if (accounts.length > 1) {
//上述查询条件返回结果大于1时再根据生效日期,失效日期区间,判断当前时间满足的数据
Date currentDate = new Date();
QFilter startDateFilter = new QFilter("shjh_begindate", QCP.less_equals, currentDate);
QFilter endDateFilter = new QFilter("shjh_enddate", QCP.large_equals, currentDate);
QFilter newFilter = qFilter.and(startDateFilter).and(endDateFilter);
accounts = BusinessDataServiceHelper.load(payReceName, "id", newFilter.toArray());
}
if (accounts.length > 0) {
// 处理找到符合条件的账户
DynamicObject account = accounts[0];
account = BusinessDataServiceHelper.loadSingle(account.getPkValue(), payReceName);
return account.getDynamicObject("shjh_membersubject").getString("number");
} else {
logger.info("没有找到符合条件的资金计划科目");
}
return null;
}
public void addFilterCondition(JSONArray IT_LIST, String field, String low, String high) { public void addFilterCondition(JSONArray IT_LIST, String field, String low, String high) {
JSONObject jsonObject = new JSONObject(); JSONObject jsonObject = new JSONObject();
jsonObject.put("FIELD", field); //字段名称 jsonObject.put("FIELD", field); //字段名称

View File

@ -4,7 +4,6 @@ import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import kd.bos.context.RequestContext; import kd.bos.context.RequestContext;
import kd.bos.dataentity.entity.DynamicObject; import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.isc.util.script.encoding.Hash;
import kd.bos.orm.query.QFilter; import kd.bos.orm.query.QFilter;
import kd.bos.servicehelper.BusinessDataServiceHelper; import kd.bos.servicehelper.BusinessDataServiceHelper;
import kd.bos.servicehelper.basedata.BaseDataServiceHelper; import kd.bos.servicehelper.basedata.BaseDataServiceHelper;
@ -19,11 +18,11 @@ public class EsbUtils {
private static final String jklogEntityName = "shjh_jklog"; private static final String jklogEntityName = "shjh_jklog";
public static final Long CCROOTID = 100000l;//成本中心根节点ID public static final Long CCROOTID = 100000L;//成本中心根节点ID
public static final Long SUPPLIERSTATUS = 880835462149703680l;//供应商状态 默认合格 public static final Long SUPPLIERSTATUS = 880835462149703680L;//供应商状态 默认合格
public static final Long SUPPLIERSTAND = 716529547008326656l;//供应商分类标准 public static final Long SUPPLIERSTAND = 716529547008326656L;//供应商分类标准
public static final Long CUSTOMERSTAND = 712984405228187648l;//客户分类标准 public static final Long CUSTOMERSTAND = 712984405228187648L;//客户分类标准
public static final Long CUSTOMERSTATUS = 1122390034075371520l;//客户状态 默认合格 public static final Long CUSTOMERSTATUS = 1122390034075371520L;//客户状态 默认合格
public static final Long ACCTABLE = 2125524820924832768L;//科目表 public static final Long ACCTABLE = 2125524820924832768L;//科目表
private static final String orgName = "bos_org";//系统库 表名 t_org_org private static final String orgName = "bos_org";//系统库 表名 t_org_org

View File

@ -1,24 +1,11 @@
package shjh.jhzj7.fi.fi.utils; package shjh.jhzj7.fi.fi.utils;
import kd.bos.context.RequestContext; import kd.bos.context.RequestContext;
import kd.bos.data.BusinessDataReader;
import kd.bos.dataentity.OperateOption;
import kd.bos.dataentity.entity.DynamicObject; import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.dataentity.entity.ILocaleString; import kd.bos.dataentity.entity.ILocaleString;
import kd.bos.dataentity.entity.LocaleString; import kd.bos.dataentity.entity.LocaleString;
import kd.bos.logging.Log;
import kd.bos.logging.LogFactory;
import kd.bos.message.api.EmailInfo;
import kd.bos.message.api.MessageChannels;
import kd.bos.message.service.handler.EmailHandler;
import kd.bos.mutex.DataMutex;
import kd.bos.servicehelper.BusinessDataServiceHelper;
import kd.bos.servicehelper.operation.SaveServiceHelper;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.*;
import kd.bos.data.BusinessDataReader;
import kd.bos.dataentity.OperateOption;
import kd.bos.entity.EntityMetadataCache; import kd.bos.entity.EntityMetadataCache;
import kd.bos.entity.MainEntityType; import kd.bos.entity.MainEntityType;
import kd.bos.entity.botp.runtime.ConvertOperationResult; import kd.bos.entity.botp.runtime.ConvertOperationResult;
@ -29,10 +16,22 @@ import kd.bos.entity.operate.OperateOptionConst;
import kd.bos.entity.operate.result.IOperateInfo; import kd.bos.entity.operate.result.IOperateInfo;
import kd.bos.entity.operate.result.OperationResult; import kd.bos.entity.operate.result.OperationResult;
import kd.bos.exception.KDBizException; import kd.bos.exception.KDBizException;
import kd.bos.logging.Log;
import kd.bos.logging.LogFactory;
import kd.bos.message.api.EmailInfo;
import kd.bos.message.api.MessageChannels;
import kd.bos.message.service.handler.EmailHandler;
import kd.bos.mutex.DataMutex;
import kd.bos.servicehelper.BusinessDataServiceHelper;
import kd.bos.servicehelper.botp.ConvertServiceHelper; import kd.bos.servicehelper.botp.ConvertServiceHelper;
import kd.bos.servicehelper.operation.SaveServiceHelper;
import kd.bos.servicehelper.workflow.MessageCenterServiceHelper; import kd.bos.servicehelper.workflow.MessageCenterServiceHelper;
import kd.bos.workflow.engine.msg.info.MessageInfo; import kd.bos.workflow.engine.msg.info.MessageInfo;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.*;
public class JhzjUtils { public class JhzjUtils {
private static final String jklogEntityName = "shjh_jklog"; private static final String jklogEntityName = "shjh_jklog";
@ -49,6 +48,29 @@ public class JhzjUtils {
return value == null || value.trim().length() <= 0; return value == null || value.trim().length() <= 0;
} }
/**
* 根据sap日期获取到资金计划中需要用到的期间 M_FY2025.Q01.M01
* @param sapdate sap日期
*/
public static String getFundPeriodBySAPDate(String sapdate){
String year = sapdate.substring(0,4);//截取年份
String monthstr = sapdate.substring(5,7);//截取月份
int month = Integer.parseInt(monthstr);
if(month <= 3){
//第一季度
return "M_FY"+year+".Q01.M"+monthstr;
}else if(4 <= month && month <= 6){
//第二季度
return "M_FY"+year+".Q02.M"+monthstr;
}else if(7 <= month && month <= 9){
//第三季度
return "M_FY"+year+".Q03.M"+monthstr;
}else{
//第四季度
return "M_FY"+year+".Q04.M"+monthstr;
}
}
/** /**
* 保存接口调用过程中的日志 * 保存接口调用过程中的日志
* @param billno 单据编号 * @param billno 单据编号