科目余额取数表 - 资产负债,客户0001、供应商0005、银行账户0003
This commit is contained in:
parent
8b911d3a83
commit
5bd8683140
|
|
@ -0,0 +1,218 @@
|
||||||
|
package zcgj.zcdev.zcdev.fs.plugin.common;
|
||||||
|
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
import com.google.gson.reflect.TypeToken;
|
||||||
|
import kd.bos.dataentity.entity.DynamicObject;
|
||||||
|
import kd.bos.dataentity.entity.DynamicObjectCollection;
|
||||||
|
import kd.bos.db.DB;
|
||||||
|
import kd.bos.db.DBRoute;
|
||||||
|
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.DeleteServiceHelper;
|
||||||
|
import kd.bos.servicehelper.operation.SaveServiceHelper;
|
||||||
|
import kd.bos.util.StringUtils;
|
||||||
|
import zcgj.zcdev.zcdev.fs.utils.AccountRecord;
|
||||||
|
import zcgj.zcdev.zcdev.fs.utils.BalanceQueryParamApi;
|
||||||
|
|
||||||
|
import java.lang.reflect.Type;
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 科目余额取数表 - 资产负债,客户0001、供应商0005、银行账户0003
|
||||||
|
*/
|
||||||
|
public class AssetsLiabilitiesbalanceAutoData {
|
||||||
|
|
||||||
|
private static final String[] asseestypeArrays = new String[]{"0001","0005","0003"};
|
||||||
|
|
||||||
|
public static void getData(Long periodId) {
|
||||||
|
String[] selectorsArray = new String[]{"beginlocal", "endlocal", "yeardebitfor", "yearcreditfor", "debitlocal", "creditlocal"};
|
||||||
|
|
||||||
|
QFilter filteraccountTable = new QFilter("number", QCP.equals, "0003");
|
||||||
|
DynamicObject accountTableLoad = BusinessDataServiceHelper.loadSingle("bd_accounttable", "id", new QFilter[]{filteraccountTable});
|
||||||
|
|
||||||
|
// 查询核算组织
|
||||||
|
QFilter number = new QFilter("fisaccounting", "=", "1");
|
||||||
|
QFilter structure = new QFilter("structure.longnumber", QCP.like, "10000000!10006431%");
|
||||||
|
QFilter isleaf = new QFilter("structure.isleaf", QCP.equals, true);
|
||||||
|
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 (DynamicObject dynamicObject : load) {
|
||||||
|
orgNumberMap.put(dynamicObject.getString("number"), dynamicObject);
|
||||||
|
orgIds.add(dynamicObject.getLong("id"));
|
||||||
|
}
|
||||||
|
|
||||||
|
DynamicObject[] costcompany = BusinessDataServiceHelper.load("zcgj_minecompany", "zcgj_costcompany", new QFilter[]{});
|
||||||
|
if (costcompany != null) {
|
||||||
|
List<Long> ids = new ArrayList<>();
|
||||||
|
for (DynamicObject dynamicObject : costcompany) {
|
||||||
|
DynamicObject minecompany = dynamicObject.getDynamicObject("zcgj_costcompany");
|
||||||
|
long id = minecompany.getLong("id");
|
||||||
|
ids.add(id);
|
||||||
|
}
|
||||||
|
QFilter idFilter = new QFilter("id", QCP.in, ids);
|
||||||
|
DynamicObject[] org = BusinessDataServiceHelper.load("bos_org", "id,structure.longnumber,structure.view", new QFilter[]{idFilter});
|
||||||
|
for (DynamicObject dynamicObject : org) {
|
||||||
|
orgNumberMap.put(dynamicObject.getString("number"), dynamicObject);
|
||||||
|
orgIds.add(dynamicObject.getLong("id"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 查询组织下对应的当前期间数据
|
||||||
|
DynamicObject[] orgByCurperiod = BusinessDataServiceHelper.load("gl_accountbook",
|
||||||
|
"org,curperiod",
|
||||||
|
new QFilter[]{new QFilter("enable", QCP.equals, Boolean.TRUE).
|
||||||
|
and("status", QCP.equals, "C").and("org.id", QCP.in, orgIds)});
|
||||||
|
Map<Long, DynamicObject> orgByCurperiodMap = new HashMap<>();
|
||||||
|
for (DynamicObject dynamicObject : orgByCurperiod) {
|
||||||
|
orgByCurperiodMap.put(dynamicObject.getLong("org.id"), dynamicObject);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 标记旧数据为非最新
|
||||||
|
List<Object[]> sqlparams = new ArrayList<>();
|
||||||
|
Object[] sqlparam = new Object[]{false};
|
||||||
|
sqlparams.add(sqlparam);
|
||||||
|
DB.executeBatch(DBRoute.of("fi"),
|
||||||
|
"update tk_zcgj_rpt_assistbalangx set fk_zcgj_isnew = ? ", sqlparams);
|
||||||
|
|
||||||
|
for (String asseestype : asseestypeArrays) {
|
||||||
|
// 查询科目余额配置表
|
||||||
|
DynamicObject[] accountConf = BusinessDataServiceHelper.load("zcgj_conf_balanceacczcfz", "zcgj_entryentity.zcgj_account,zcgj_entryentity.zcgj_asseestype", new QFilter[]{});
|
||||||
|
Set<String> accountNumber = new HashSet<>();
|
||||||
|
for (DynamicObject dynamicObject : accountConf) {
|
||||||
|
DynamicObjectCollection zcgjEntryentity = dynamicObject.getDynamicObjectCollection("zcgj_entryentity");
|
||||||
|
for (DynamicObject object : zcgjEntryentity) {
|
||||||
|
String zcgjAsseestype = object.getString("zcgj_asseestype");
|
||||||
|
if (asseestype.equals(zcgjAsseestype)) {
|
||||||
|
accountNumber.add(object.getDynamicObject("zcgj_account").getString("number"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (String orgNumber : orgNumberMap.keySet()) {
|
||||||
|
BalanceQueryParamApi balanceQueryParamApi = new BalanceQueryParamApi();
|
||||||
|
balanceQueryParamApi.setSelectors(Arrays.asList(selectorsArray));
|
||||||
|
balanceQueryParamApi.setOrgNumber(orgNumber);
|
||||||
|
balanceQueryParamApi.setBookTypeNumber("100002"); //账簿类型
|
||||||
|
balanceQueryParamApi.setAccountTableNumber("0003");//科目表
|
||||||
|
|
||||||
|
DynamicObject orgObj = orgNumberMap.get(orgNumber);
|
||||||
|
DynamicObject periodObj = orgByCurperiodMap.get(orgObj.getLong("id"));
|
||||||
|
DynamicObject curperiod = null;
|
||||||
|
if(periodId==null){
|
||||||
|
if (periodObj != null) {
|
||||||
|
curperiod = periodObj.getDynamicObject("curperiod");
|
||||||
|
if (curperiod != null) {
|
||||||
|
balanceQueryParamApi.setPeriodNumber(curperiod.getString("number")); //
|
||||||
|
} else {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
QFilter idFilter = new QFilter("id", QCP.equals, periodId);
|
||||||
|
curperiod = BusinessDataServiceHelper.loadSingle("bd_period", "id,number", new QFilter[]{idFilter});
|
||||||
|
String periodNumber = curperiod.getString("number");
|
||||||
|
balanceQueryParamApi.setPeriodNumber(periodNumber); //
|
||||||
|
}
|
||||||
|
|
||||||
|
List<String> groupBy = new ArrayList<>();
|
||||||
|
if (!StringUtils.isEmpty(asseestype)) {
|
||||||
|
Map<String, List<Map<String, String>>> accountAssgrp = new HashMap<>();
|
||||||
|
List<Map<String, String>> li = new ArrayList<>();
|
||||||
|
Map<String, String> map1 = new HashMap<>();
|
||||||
|
map1.put(asseestype, "");
|
||||||
|
li.add(map1);
|
||||||
|
for (String accNum : accountNumber) {
|
||||||
|
accountAssgrp.put(accNum, li);
|
||||||
|
}
|
||||||
|
balanceQueryParamApi.setAccountAssgrp(accountAssgrp);
|
||||||
|
groupBy.add(asseestype);
|
||||||
|
}else{
|
||||||
|
Map<String, List<Map<String, String>>> accountAssgrp = new HashMap<>();
|
||||||
|
List<Map<String, String>> li = new ArrayList<>();
|
||||||
|
for (String accNum : accountNumber) {
|
||||||
|
accountAssgrp.put(accNum, li);
|
||||||
|
}
|
||||||
|
balanceQueryParamApi.setAccountAssgrp(accountAssgrp);
|
||||||
|
}
|
||||||
|
groupBy.add("account");
|
||||||
|
balanceQueryParamApi.setGroupBys(groupBy);
|
||||||
|
Gson gson = new Gson();
|
||||||
|
String json = gson.toJson(balanceQueryParamApi);
|
||||||
|
Map<String, Object> params = gson.fromJson(json,
|
||||||
|
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();
|
||||||
|
List<AccountRecord> records = gson.fromJson(data, listType);
|
||||||
|
for (AccountRecord record : records) {
|
||||||
|
DynamicObject assistbalance = BusinessDataServiceHelper.newDynamicObject("zcgj_rpt_assistbalan_zcfz");
|
||||||
|
assistbalance.set("zcgj_debitlocal", record.getDebitlocal());
|
||||||
|
assistbalance.set("zcgj_beginlocal", record.getBeginlocal());
|
||||||
|
assistbalance.set("zcgj_creditlocal", record.getCreditlocal());
|
||||||
|
assistbalance.set("zcgj_yeardebitfor", record.getYeardebitfor());
|
||||||
|
assistbalance.set("zcgj_yearcreditfor", record.getYearcreditfor());
|
||||||
|
assistbalance.set("zcgj_endlocal", record.getEndlocal());
|
||||||
|
assistbalance.set("zcgj_org", orgNumberMap.get(orgNumber));
|
||||||
|
assistbalance.set("zcgj_accounttable", accountTableLoad);
|
||||||
|
assistbalance.set("zcgj_account", record.getAccount());
|
||||||
|
assistbalance.set("zcgj_period", curperiod);
|
||||||
|
assistbalance.set("zcgj_isnew", true);
|
||||||
|
assistbalance.set("zcgj_sourcetype", asseestype);
|
||||||
|
|
||||||
|
Map<String, AccountRecord.AssGrpItem> assgrp = record.getAssgrp();
|
||||||
|
if(assgrp!=null){//客户0001、供应商0005、银行账户0003
|
||||||
|
if (assgrp.containsKey("0001")) {
|
||||||
|
if (assgrp.get("0001") != null) {
|
||||||
|
assistbalance.set("zcgj_customernumber",assgrp.get("0001").getNumber());
|
||||||
|
assistbalance.set("zcgj_customername",assgrp.get("0001").getName());
|
||||||
|
}
|
||||||
|
} else if (assgrp.containsKey("0005")) {
|
||||||
|
if (assgrp.get("0005") != null) {
|
||||||
|
assistbalance.set("zcgj_suppliernumber",assgrp.get("0005").getNumber());
|
||||||
|
assistbalance.set("zcgj_suppliername",assgrp.get("0005").getName());
|
||||||
|
}
|
||||||
|
}else if (assgrp.containsKey("0003")) {
|
||||||
|
if (assgrp.get("0003") != null) {
|
||||||
|
assistbalance.set("zcgj_bankaccountnumber", assgrp.get("0003").getNumber());
|
||||||
|
assistbalance.set("zcgj_bankaccountname", assgrp.get("0003").getName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
addEntities.add(assistbalance);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!addEntities.isEmpty()) {
|
||||||
|
try {
|
||||||
|
// ✅ 删除旧数据(保证每个组织、每个期间只保留一份最新的)
|
||||||
|
Long orgId = orgObj.getLong("id");
|
||||||
|
Long periodIddelete = curperiod.getLong("id");
|
||||||
|
QFilter orgFilter = new QFilter("zcgj_org", QCP.equals, orgId);
|
||||||
|
QFilter periodFilter = new QFilter("zcgj_period", QCP.equals, periodIddelete);
|
||||||
|
QFilter sourcetypeFilter = new QFilter("zcgj_sourcetype", QCP.equals, asseestype);
|
||||||
|
QFilter isnewFilter = new QFilter("zcgj_isnew", QCP.equals, false);
|
||||||
|
DeleteServiceHelper.delete("zcgj_rpt_assistbalan_zcfz", new QFilter[]{orgFilter.and(periodFilter).and(sourcetypeFilter).and(isnewFilter)});
|
||||||
|
// 保存新数据
|
||||||
|
SaveServiceHelper.save(addEntities.toArray(new DynamicObject[0]));
|
||||||
|
} catch (Exception ex) {
|
||||||
|
throw new RuntimeException(ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,48 @@
|
||||||
|
package zcgj.zcdev.zcdev.fs.plugin.form;
|
||||||
|
|
||||||
|
import kd.bos.entity.filter.ControlFilters;
|
||||||
|
import kd.bos.form.control.events.ItemClickEvent;
|
||||||
|
import kd.bos.list.IListView;
|
||||||
|
import kd.bos.list.ListShowParameter;
|
||||||
|
import kd.bos.list.plugin.AbstractListPlugin;
|
||||||
|
import kd.bos.logging.Log;
|
||||||
|
import kd.bos.logging.LogFactory;
|
||||||
|
import kd.sdk.plugin.Plugin;
|
||||||
|
import zcgj.zcdev.zcdev.fs.plugin.common.AssetsLiabilitiesbalanceAutoData;
|
||||||
|
import zcgj.zcdev.zcdev.fs.plugin.common.SubjectbalanceAutoData;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 核算维度余额取数表(矿山二开)
|
||||||
|
*/
|
||||||
|
public class AssetsLiabilitiesbalancePlugin extends AbstractListPlugin implements Plugin {
|
||||||
|
private static final Log log = LogFactory.getLog(AssetsLiabilitiesbalancePlugin.class);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void itemClick(ItemClickEvent evt) {
|
||||||
|
super.itemClick(evt);
|
||||||
|
String itemKey = evt.getItemKey();
|
||||||
|
if("zcgj_gatdata".equals(itemKey)) {
|
||||||
|
//科目余额表自动取数
|
||||||
|
AssetsLiabilitiesbalanceAutoData.getData(null);//其他
|
||||||
|
}else if("zcgj_gatdataperiod".equals(itemKey)) {
|
||||||
|
//获取列表查询参数
|
||||||
|
ControlFilters filters = ((IListView)this.getView()).getControlFilters();
|
||||||
|
List<Object> filter = filters.getFilter("zcgj_period.id");
|
||||||
|
if(filter.isEmpty()) {
|
||||||
|
this.getView().showMessage("请选择期间!");
|
||||||
|
}else{
|
||||||
|
for (Object periodId : filter) {
|
||||||
|
if(periodId instanceof String) {
|
||||||
|
AssetsLiabilitiesbalanceAutoData.getData(Long.valueOf((String)periodId));//其他
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//重新执行一下拉取最新的数据,解决历史数据最新勾选问题
|
||||||
|
AssetsLiabilitiesbalanceAutoData.getData(null);//其他
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue