From 04963a84448d64232ea5e19d455418a52d48bfde Mon Sep 17 00:00:00 2001 From: yuxueliang0813 <407010292@qq.com> Date: Tue, 1 Apr 2025 17:54:21 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B5=84=E9=87=91=E8=AE=A1=E5=88=92=E4=BC=98?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fi/plugin/form/InitAccountFormPlugin.java | 5 + .../plugin/task/FundPlanCollectionTask.java | 118 ++++++++++++++++-- .../java/shjh/jhzj7/fi/fi/utils/EsbUtils.java | 11 +- .../shjh/jhzj7/fi/fi/utils/JhzjUtils.java | 52 +++++--- 4 files changed, 154 insertions(+), 32 deletions(-) diff --git a/main/java/shjh/jhzj7/fi/fi/plugin/form/InitAccountFormPlugin.java b/main/java/shjh/jhzj7/fi/fi/plugin/form/InitAccountFormPlugin.java index e4dcc83..7069284 100644 --- a/main/java/shjh/jhzj7/fi/fi/plugin/form/InitAccountFormPlugin.java +++ b/main/java/shjh/jhzj7/fi/fi/plugin/form/InitAccountFormPlugin.java @@ -65,6 +65,11 @@ public class InitAccountFormPlugin extends AbstractFormPlugin { if (StringUtils.equals(OK_BUTTON_KEY, key)) { // 点击确认按钮 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); JSONArray detailsJson = json_obj.getJSONArray("items"); if(detailsJson == null){ diff --git a/main/java/shjh/jhzj7/fi/fi/plugin/task/FundPlanCollectionTask.java b/main/java/shjh/jhzj7/fi/fi/plugin/task/FundPlanCollectionTask.java index 5da8069..7070115 100644 --- a/main/java/shjh/jhzj7/fi/fi/plugin/task/FundPlanCollectionTask.java +++ b/main/java/shjh/jhzj7/fi/fi/plugin/task/FundPlanCollectionTask.java @@ -34,6 +34,8 @@ import java.util.Map; */ public class FundPlanCollectionTask extends AbstractTask implements Plugin { 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 Gson gson = new Gson();//用于将json格式化为对象 @@ -59,7 +61,10 @@ public class FundPlanCollectionTask extends AbstractTask implements Plugin { String reportPeriodCode;//编报期间的编号 DynamicObject reportOrg;//编报主体对象 DynamicObject accountInfo;//资金计划科目 - DynamicObjectCollection maindimentrys; + String sybnum;//事业部编号-编报主体的编号 + String months;//月份-科目编制分录中的期间编号 + String accountnum;//资金计划科目编号 + DynamicObjectCollection maindimentrys;//主维度分录-包含了父级和子级所有科目 String billno;//资金计划编制单号 String result;//反写结果 FpmResponse frv;//反写结果 @@ -78,25 +83,27 @@ public class FundPlanCollectionTask extends AbstractTask implements Plugin { reportPeriodCode = doinfo.getDynamicObject("reportperiod").getString("number"); json_obj.put("reportPeriodCode",reportPeriodCode);//编报期间 code 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()); - int i = 1; for(DynamicObject entryinfo : maindimentrys){ accountInfo = entryinfo.getDynamicObject("subjectmem"); if(!accountInfo.getBoolean("isleaf")){ continue; } + accountnum = accountInfo.getString("number"); JSONObject itemInfo = new JSONObject(); itemInfo.put("currencyCode",entryinfo.getDynamicObject("currencymem").getString("number"));//币别 code - itemInfo.put("subjectCode",accountInfo.getString("number"));//计划科目 code - itemInfo.put("entryPeriodCode",entryinfo.getDynamicObject("periodmem").getString("number"));//主维度数据分录期间 code + itemInfo.put("subjectCode",accountnum);//计划科目 code + months = entryinfo.getDynamicObject("periodmem").getString("number"); + itemInfo.put("entryPeriodCode",months);//主维度数据分录期间 code //组装度量值 JSONArray mms = new JSONArray(1);//科目的度量值明细,目前只写入计划参考数 JSONObject mmInfo = new JSONObject(); //PLANREFERENCEAMT 计划参考值 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 万元 mms.add(mmInfo); itemInfo.put("metricMembers",mms);//度量值列表 @@ -135,18 +142,35 @@ public class FundPlanCollectionTask extends AbstractTask implements Plugin { JSONArray items = data.getJSONArray("IT_ITEM"); Map acctamountMap = new HashMap<>(); BigDecimal amount; - String productnum; + String productnum;//品牌 + String sybnum;//事业部编号 + String months;//月份 + String accountnum;//资金计划科目编号 + String mapkey;//事业部编号+月份+资金计划科目编号 + DynamicObject ppsybinfo; 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))); + months = sapresult.getString("BUDAT");//过账日期 + 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{ - acctamountMap.put(productnum,amount); + //TODO 如果品牌没有对应的事业部时,数据放哪里? } // sapresult.getString("BUKRS");//公司编号 -// sapresult.getString("BUDAT");//过账日期 // sapresult.getString("WAERS");//币别编号 // sapresult.getString("HKONT");//科目编号 // sapresult.getString("RSTGR");//付款原因代码 @@ -157,6 +181,78 @@ public class FundPlanCollectionTask extends AbstractTask implements Plugin { 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) { JSONObject jsonObject = new JSONObject(); jsonObject.put("FIELD", field); //字段名称 diff --git a/main/java/shjh/jhzj7/fi/fi/utils/EsbUtils.java b/main/java/shjh/jhzj7/fi/fi/utils/EsbUtils.java index 50dc3f6..14309a0 100644 --- a/main/java/shjh/jhzj7/fi/fi/utils/EsbUtils.java +++ b/main/java/shjh/jhzj7/fi/fi/utils/EsbUtils.java @@ -4,7 +4,6 @@ import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import kd.bos.context.RequestContext; import kd.bos.dataentity.entity.DynamicObject; -import kd.bos.isc.util.script.encoding.Hash; import kd.bos.orm.query.QFilter; import kd.bos.servicehelper.BusinessDataServiceHelper; import kd.bos.servicehelper.basedata.BaseDataServiceHelper; @@ -19,11 +18,11 @@ public class EsbUtils { private static final String jklogEntityName = "shjh_jklog"; - public static final Long CCROOTID = 100000l;//成本中心根节点ID - public static final Long SUPPLIERSTATUS = 880835462149703680l;//供应商状态 默认合格 - public static final Long SUPPLIERSTAND = 716529547008326656l;//供应商分类标准 - public static final Long CUSTOMERSTAND = 712984405228187648l;//客户分类标准 - public static final Long CUSTOMERSTATUS = 1122390034075371520l;//客户状态 默认合格 + public static final Long CCROOTID = 100000L;//成本中心根节点ID + public static final Long SUPPLIERSTATUS = 880835462149703680L;//供应商状态 默认合格 + public static final Long SUPPLIERSTAND = 716529547008326656L;//供应商分类标准 + public static final Long CUSTOMERSTAND = 712984405228187648L;//客户分类标准 + public static final Long CUSTOMERSTATUS = 1122390034075371520L;//客户状态 默认合格 public static final Long ACCTABLE = 2125524820924832768L;//科目表 private static final String orgName = "bos_org";//系统库 表名 t_org_org diff --git a/main/java/shjh/jhzj7/fi/fi/utils/JhzjUtils.java b/main/java/shjh/jhzj7/fi/fi/utils/JhzjUtils.java index 7fe2e09..3c74bbf 100644 --- a/main/java/shjh/jhzj7/fi/fi/utils/JhzjUtils.java +++ b/main/java/shjh/jhzj7/fi/fi/utils/JhzjUtils.java @@ -1,24 +1,11 @@ package shjh.jhzj7.fi.fi.utils; 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.ILocaleString; 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.MainEntityType; 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.OperationResult; 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.operation.SaveServiceHelper; import kd.bos.servicehelper.workflow.MessageCenterServiceHelper; import kd.bos.workflow.engine.msg.info.MessageInfo; +import java.math.BigDecimal; +import java.text.SimpleDateFormat; +import java.util.*; + public class JhzjUtils { private static final String jklogEntityName = "shjh_jklog"; @@ -49,6 +48,29 @@ public class JhzjUtils { 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 单据编号