科目余额工序取数

This commit is contained in:
zhangzhiguo 2025-09-29 13:46:04 +08:00
parent a4dc2091a3
commit 5cb700ebfa
3 changed files with 69 additions and 43 deletions

View File

@ -10,6 +10,7 @@ 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.DeleteServiceHelper;
import kd.bos.servicehelper.operation.SaveServiceHelper;
import zcgj.zcdev.zcdev.fs.utils.AccountRecord;
import zcgj.zcdev.zcdev.fs.utils.BalanceQueryParamApi;
@ -171,6 +172,14 @@ public class AssistbalanceAutoData {
if (!addEntities.isEmpty()) {
try {
// 删除旧数据保证每个组织每个期间只保留一份最新的
Long orgId = orgObj.getLong("id");
Long periodId = curperiod.getLong("id");
QFilter orgFilter = new QFilter("zcgj_org", QCP.equals, orgId);
QFilter periodFilter = new QFilter("zcgj_period", QCP.equals, periodId);
DeleteServiceHelper.delete("zcgj_rpt_assistbalance", new QFilter[]{orgFilter.and(periodFilter)});
SaveServiceHelper.save(addEntities.toArray(new DynamicObject[0]));
} catch (Exception ex) {
throw new RuntimeException(ex);

View File

@ -11,6 +11,7 @@ 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.DeleteServiceHelper;
import kd.bos.servicehelper.operation.SaveServiceHelper;
import kd.bos.util.StringUtils;
import zcgj.zcdev.zcdev.fs.utils.AccountRecord;
@ -36,8 +37,7 @@ public class SubjectbalanceAutoData {
DynamicObject[] load = BusinessDataServiceHelper.load("bos_org", "id,structure.longnumber,structure.view", new QFilter[]{number, structure, isleaf});
List<Long> orgIds = new ArrayList<>();
Map<String, DynamicObject> orgNumberMap = new HashMap<>();
for (int i = 0; i < load.length; i++) {
DynamicObject dynamicObject = load[i];
for (DynamicObject dynamicObject : load) {
orgNumberMap.put(dynamicObject.getString("number"), dynamicObject);
orgIds.add(dynamicObject.getLong("id"));
}
@ -57,6 +57,7 @@ public class SubjectbalanceAutoData {
orgIds.add(dynamicObject.getLong("id"));
}
}
// 查询组织下对应的当前期间数据
DynamicObject[] orgByCurperiod = BusinessDataServiceHelper.load("gl_accountbook",
"org,curperiod",
@ -67,8 +68,7 @@ public class SubjectbalanceAutoData {
orgByCurperiodMap.put(dynamicObject.getLong("org.id"), dynamicObject);
}
//清除数据
//DeleteServiceHelper.delete("zcgj_rpt_assistbalance",new QFilter[]{});
// 标记旧数据为非最新
List<Object[]> sqlparams = new ArrayList<>();
Object[] sqlparam = new Object[]{false};
sqlparams.add(sqlparam);
@ -92,7 +92,6 @@ public class SubjectbalanceAutoData {
for (String orgNumber : orgNumberMap.keySet()) {
BalanceQueryParamApi balanceQueryParamApi = new BalanceQueryParamApi();
balanceQueryParamApi.setSelectors(Arrays.asList(selectorsArray));
// balanceQueryParamApi.setOrgNumber("cw000102");
balanceQueryParamApi.setOrgNumber(orgNumber);
balanceQueryParamApi.setBookTypeNumber("100002"); //账簿类型
balanceQueryParamApi.setAccountTableNumber("0003");//科目表
@ -111,7 +110,6 @@ public class SubjectbalanceAutoData {
continue;
}
List<String> groupBy = new ArrayList<>();
if (!StringUtils.isEmpty(asseestype)) {
Map<String, List<Map<String, String>>> accountAssgrp = new HashMap<>();
@ -123,7 +121,6 @@ public class SubjectbalanceAutoData {
accountAssgrp.put(accNum, li);
}
balanceQueryParamApi.setAccountAssgrp(accountAssgrp);
groupBy.add(asseestype);
}
groupBy.add("account");
@ -131,19 +128,19 @@ public class SubjectbalanceAutoData {
Gson gson = new Gson();
String json = gson.toJson(balanceQueryParamApi);
Map<String, Object> params = gson.fromJson(json,
new TypeToken<Map<String, Object>>(){}.getType());
new TypeToken<Map<String, Object>>() {
}.getType());
OpenApiResult balanceData = OpenApiSdkUtil.invoke("/v2/gl/getBalanceApi", params);
List<DynamicObject> addEntities = new ArrayList<>();
if (balanceData.isStatus()) {
String data = (String) balanceData.getData();
Type listType = new TypeToken<List<AccountRecord>>() {}.getType();
Type listType = new TypeToken<List<AccountRecord>>() {
}.getType();
List<AccountRecord> records = gson.fromJson(data, listType);
// 示例输出
for (AccountRecord record : records) {
DynamicObject assistbalance
=BusinessDataServiceHelper.newDynamicObject("zcgj_rpt_assistbalancegx");
DynamicObject assistbalance = BusinessDataServiceHelper.newDynamicObject("zcgj_rpt_assistbalancegx");
assistbalance.set("zcgj_debitlocal", record.getDebitlocal());
assistbalance.set("zcgj_beginlocal", record.getBeginlocal());
assistbalance.set("zcgj_creditlocal", record.getCreditlocal());
@ -155,7 +152,7 @@ public class SubjectbalanceAutoData {
assistbalance.set("zcgj_account", record.getAccount());
assistbalance.set("zcgj_period", curperiod);
assistbalance.set("zcgj_isnew", true);
//assistbalance.set("zcgj_pm",projectMap.get(orgNumber));
Map<String, AccountRecord.AssGrpItem> assgrp = record.getAssgrp();
if (assgrp.containsKey("0032")) {
if (assgrp.get("0032") != null) {
@ -170,11 +167,17 @@ public class SubjectbalanceAutoData {
}
addEntities.add(assistbalance);
}
}
if (!addEntities.isEmpty()) {
try {
// 删除旧数据保证每个组织每个期间只保留一份最新的
Long orgId = orgObj.getLong("id");
Long periodId = curperiod.getLong("id");
QFilter orgFilter = new QFilter("zcgj_org", QCP.equals, orgId);
QFilter periodFilter = new QFilter("zcgj_period", QCP.equals, periodId);
DeleteServiceHelper.delete("zcgj_rpt_assistbalancegx", new QFilter[]{orgFilter.and(periodFilter)});
// 保存新数据
SaveServiceHelper.save(addEntities.toArray(new DynamicObject[0]));
} catch (Exception ex) {
throw new RuntimeException(ex);
@ -183,4 +186,5 @@ public class SubjectbalanceAutoData {
}
}
}
}

View File

@ -11,6 +11,7 @@ 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.DeleteServiceHelper;
import kd.bos.servicehelper.operation.SaveServiceHelper;
import zcgj.zcdev.zcdev.fs.utils.AccountRecord;
import zcgj.zcdev.zcdev.fs.utils.BalanceQueryParamApi;
@ -189,6 +190,18 @@ public class SuppliertbalanceAutoData {
if (!addEntities.isEmpty()) {
try {
// 删除旧数据保证每个组织每个期间只保留一份最新的
Long orgId = orgObj.getLong("id");
Long periodId = curperiod.getLong("id");
QFilter orgFilter = new QFilter("zcgj_org", QCP.equals, orgId);
QFilter periodFilter = new QFilter("zcgj_period", QCP.equals, periodId);
if("YUFZK".equals(type)){//预付账款
DeleteServiceHelper.delete("zcgj_rpt_assibalancegysyu", new QFilter[]{orgFilter.and(periodFilter)});
}else if("YIFZK".equals(type)){//应付账款
DeleteServiceHelper.delete("zcgj_rpt_assibalancegysyi", new QFilter[]{orgFilter.and(periodFilter)});
}
SaveServiceHelper.save(addEntities.toArray(new DynamicObject[0]));
} catch (Exception ex) {
throw new RuntimeException(ex);