科目初始化-科目维度

This commit is contained in:
yuxueliang0813 2025-04-03 16:47:34 +08:00
parent afd416e4b5
commit 984942b5ae
1 changed files with 109 additions and 85 deletions

View File

@ -48,100 +48,122 @@ public class InitAccountFormPlugin extends AbstractFormPlugin {
//处理导入的excel数据 注意 excel中的列名必须与分录的列标识一致否则无法识别到excel中的数据
HashMap itemEntry = (HashMap) e.getSource();//excel表格全量数据
ArrayList list = (ArrayList) itemEntry.get("shjh_details");//excel表格的某个页签-科目基本信息
Iterator iterator = list.iterator();//遍历页签
Iterator iterator;//遍历页签
ImportEntryData importData;
JSONObject rowdata;
String number;//科目编号
String name;//科目名称
String acctType;//科目类型 资产负债类 损益类
DynamicObject acctInfo;
DynamicObject acctTypeInfo;
Map<String, Long> acctids = new HashMap<>();//科目编号和ID对应关系
Map<String, DynamicObject> accountMaps = new HashMap<>();//将科目编号与对象关联
//先根据基础信息在集团层面生成科目不考虑核算维度使用逐级分配
//再根据公司信息进行科目分配
//最后处理每个公司下科目的核算维度和禁用状态
StringBuilder resultstr = new StringBuilder();
while (iterator.hasNext()) {
importData = (ImportEntryData) iterator.next();
rowdata = importData.getData();//具体的某行数据key值为列名
if("0".equals(rowdata.getString("shjh_status"))){
//科目状态为0不导入
continue;
}
number = rowdata.getString("shjh_code");//科目编号
name = rowdata.getString("shjh_name");//科目名称
acctType = rowdata.getString("shjh_type");//科目类型
acctTypeInfo = BusinessDataServiceHelper.loadSingleFromCache(acctTypeName,new QFilter[]{
new QFilter("number","=",acctType)});
if(acctTypeInfo == null){
log.error(String.format("科目类型在金蝶中找不到:%s", acctType));
resultstr.append(number);
resultstr.append("科目类型在金蝶中找不到");
continue;
}
//不存在做新增 根据实体名称创建动态对象
acctInfo = BusinessDataServiceHelper.newDynamicObject(entityName);
acctInfo.set("accounttable", EsbUtils.ACCTABLE);//科目表fid上正式时注意此ID
acctInfo.set("number", number);
acctInfo.set("name", name);
//处理父级科目
DynamicObject acctInfo;//科目对象
String number;//科目编号
if(list != null){
log.info("科目导入shjh_details"+list.size());
iterator = list.iterator();//遍历页签
String name;//科目名称
String acctType;//科目类型 资产负债类 损益类
DynamicObject acctTypeInfo;
//先根据基础信息在集团层面生成科目不考虑核算维度使用逐级分配
//再根据公司信息进行科目分配
//最后处理每个公司下科目的核算维度和禁用状态
while (iterator.hasNext()) {
importData = (ImportEntryData) iterator.next();
rowdata = importData.getData();//具体的某行数据key值为列名
if("0".equals(rowdata.getString("shjh_status"))){
//科目状态为0不导入
continue;
}
number = rowdata.getString("shjh_code");//科目编号
name = rowdata.getString("shjh_name");//科目名称
acctType = rowdata.getString("shjh_type");//科目类型
acctTypeInfo = BusinessDataServiceHelper.loadSingleFromCache(acctTypeName,new QFilter[]{
new QFilter("number","=",acctType)});
if(acctTypeInfo == null){
log.error(String.format("科目导入科目类型在金蝶中找不到:%s", acctType));
resultstr.append(number);
resultstr.append("科目类型在金蝶中找不到");
continue;
}
//不存在做新增 根据实体名称创建动态对象
acctInfo = BusinessDataServiceHelper.newDynamicObject(entityName);
acctInfo.set("accounttable", EsbUtils.ACCTABLE);//科目表fid上正式时注意此ID
acctInfo.set("number", number);
acctInfo.set("name", name);
//处理父级科目
// parentAcctInfo = getParentAcct(number);
acctInfo.set("longnumber", number);
acctInfo.set("fullname", name);
acctInfo.set("longnumber", number);
acctInfo.set("fullname", name);
// acctInfo.set("parent", parentAcctInfo.getLong("id"));
//创建组织
acctInfo.set("createorg", JhzjUtils.GROUPID);//创建组织
acctInfo.set("org", JhzjUtils.GROUPID);//管理组织
//科目类型
acctInfo.set("accounttype", acctTypeInfo);
//币别核算--外币核算类型--集团科目新增时默认为allcurrency
acctInfo.set("acctcurrency", "allcurrency");//不核算外币nocurrency 指定核算币别descurrency 核算所有币别allcurrency
acctInfo.set("ctrlstrategy", "1");//控制策略 5全局共享 7私有 1逐级分配
acctInfo.set("control", "nocontrol");//受控系统 nocontrol 应付 应收 资产
//损益类型
acctInfo.set("pltype", getSY(acctType));
acctInfo.set("dc", 1);//余额方向 默认为借
acctInfo.set("level", 1);//级次 默认为1
acctInfo.set("isleaf", true);//明细科目 默认为是
acctInfo.set("startdate", new Date());//版本化日期
acctInfo.set("enddate", TypeUtils.castToDate("2999-12-31"));//失效日期
acctInfo.set("accrualdirection", "nocontrol");//科目录入方向控制 不控制nocontrol 借方debit 贷方credit
acctInfo.set("orgcontrollevel", 1);//控制级次 默认为1
acctInfo.set("isallowca", false);//允许公司增加下级科目 由接口同步 为false时控制级次可以不设置
acctInfo.set("ismanual", false);//手工录入 由接口同步
acctInfo.set("iscash", false);//现金科目 默认false sap不区分
acctInfo.set("isbank", false);//银行科目 默认false sap不区分
acctInfo.set("iscashequivalent", false);//现金等价物 默认false sap不区分
acctInfo.set("isjournal", false);//登日记账 现金等价物时需要勾选
acctInfo.set("enable", 1);//是否启用
acctInfo.set("status", "C");//单据状态 A保存 B已提交 C已审核
acctInfo.set("creator", RequestContext.get().getCurrUserId());//创建人
//手动指定科目的金蝶id
long kmId = ID.genLongId();
acctInfo.set("id", kmId);
acctInfo.set("masterid", kmId);//主数据内码系统不会根据id自动生成需要手动设置
//保存数据直接保存入库不走操作校验
SaveServiceHelper.save(new DynamicObject[]{acctInfo});
//处理科目使用范围
DB.update(DBRoute.of("fi"), insertSql, new Object[]{kmId,JhzjUtils.GROUPID});
acctids.put(number,acctInfo.getLong("id"));
accountMaps.put(number,acctInfo);
//创建组织
acctInfo.set("createorg", JhzjUtils.GROUPID);//创建组织
acctInfo.set("org", JhzjUtils.GROUPID);//管理组织
//科目类型
acctInfo.set("accounttype", acctTypeInfo);
//币别核算--外币核算类型--集团科目新增时默认为allcurrency
acctInfo.set("acctcurrency", "allcurrency");//不核算外币nocurrency 指定核算币别descurrency 核算所有币别allcurrency
acctInfo.set("ctrlstrategy", "1");//控制策略 5全局共享 7私有 1逐级分配
acctInfo.set("control", "nocontrol");//受控系统 nocontrol 应付 应收 资产
//损益类型
acctInfo.set("pltype", getSY(acctType));
acctInfo.set("dc", 1);//余额方向 默认为借
acctInfo.set("level", 1);//级次 默认为1
acctInfo.set("isleaf", true);//明细科目 默认为是
acctInfo.set("startdate", new Date());//版本化日期
acctInfo.set("enddate", TypeUtils.castToDate("2999-12-31"));//失效日期
acctInfo.set("accrualdirection", "nocontrol");//科目录入方向控制 不控制nocontrol 借方debit 贷方credit
acctInfo.set("orgcontrollevel", 1);//控制级次 默认为1
acctInfo.set("isallowca", false);//允许公司增加下级科目 由接口同步 为false时控制级次可以不设置
acctInfo.set("ismanual", false);//手工录入 由接口同步
acctInfo.set("iscash", false);//现金科目 默认false sap不区分
acctInfo.set("isbank", false);//银行科目 默认false sap不区分
acctInfo.set("iscashequivalent", false);//现金等价物 默认false sap不区分
acctInfo.set("isjournal", false);//登日记账 现金等价物时需要勾选
acctInfo.set("enable", 1);//是否启用
acctInfo.set("status", "C");//单据状态 A保存 B已提交 C已审核
acctInfo.set("creator", RequestContext.get().getCurrUserId());//创建人
//手动指定科目的金蝶id
long kmId = ID.genLongId();
acctInfo.set("id", kmId);
acctInfo.set("masterid", kmId);//主数据内码系统不会根据id自动生成需要手动设置
//保存数据直接保存入库不走操作校验
SaveServiceHelper.save(new DynamicObject[]{acctInfo});
//处理科目使用范围
DB.update(DBRoute.of("fi"), insertSql, new Object[]{kmId,JhzjUtils.GROUPID});
acctids.put(number,acctInfo.getLong("id"));
accountMaps.put(number,acctInfo);
}
}
list = (ArrayList) itemEntry.get("shjh_companys");//excel表格的某个页签-科目公司信息
iterator = list.iterator();//遍历页签
JSONArray companysJson = new JSONArray();
while (iterator.hasNext()) {
importData = (ImportEntryData) iterator.next();
rowdata = importData.getData();//具体的某行数据key值为列名
companysJson.add(rowdata);
}
//处理科目在每个公司生成
Map<String, DynamicObject> companyAcctMaps = handleAccountCompany(accountMaps,companysJson);
//处理科目分配
EsbUtils.handleAssignInit(companysJson, acctids, entityName);
Map<String, DynamicObject> companyAcctMaps = null;
if(list != null){
log.info("科目导入shjh_companys"+list.size());
iterator = list.iterator();//遍历页签
JSONArray companysJson = new JSONArray();
while (iterator.hasNext()) {
importData = (ImportEntryData) iterator.next();
rowdata = importData.getData();//具体的某行数据key值为列名
companysJson.add(rowdata);
}
//处理科目在每个公司生成
companyAcctMaps = handleAccountCompany(accountMaps,companysJson);
//处理科目分配
EsbUtils.handleAssignInit(companysJson, acctids, entityName);
}
if(companyAcctMaps == null){
companyAcctMaps = new HashMap<>();
//本次只导入核算维度数据 companyAcctMaps 手动获取一次各个分公司的科目数据
DynamicObject[] accts = BusinessDataServiceHelper.load(entityName,"id",new QFilter[]{new QFilter("accounttable.id","=",EsbUtils.ACCTABLE),
new QFilter("createorg.id","<>", JhzjUtils.GROUPID)});
for (DynamicObject acct : accts){
acct = BusinessDataServiceHelper.loadSingle(acct.getPkValue(),entityName);
companyAcctMaps.put(acct.getString("number")+acct.getDynamicObject("createorg").getString("number"),
acct);
}
}
//处理每个公司下科目的核算维度和禁用状态
list = (ArrayList) itemEntry.get("shjh_hswds");//excel表格的某个页签-科目核算维度信息
log.info("科目导入shjh_hswds"+list.size());
iterator = list.iterator();//遍历页签
JSONArray asstacttypesJson = new JSONArray();
while (iterator.hasNext()) {
@ -161,7 +183,7 @@ public class InitAccountFormPlugin extends AbstractFormPlugin {
hsxm = json_body.getString("shjh_asstactname");
number = json_body.getString("shjh_hcode");
if(EsbUtils.isEmpty(hsxm)){
log.error(String.format("核算维度为空:%s", number));
log.error(String.format("科目导入核算维度为空:%s", number));
continue;
}
companynum = json_body.getString("shjh_companynums");
@ -172,7 +194,7 @@ public class InitAccountFormPlugin extends AbstractFormPlugin {
}
hsxmInfo = getHsxmInfo(hsxm);
if(hsxmInfo == null){
log.error(String.format("核算维度在金蝶中找不到:%s", hsxm));
log.error(String.format("科目导入核算维度在金蝶中找不到:%s", hsxm));
resultstr.append(number);
resultstr.append("核算维度在金蝶中找不到");
continue;
@ -203,9 +225,11 @@ public class InitAccountFormPlugin extends AbstractFormPlugin {
}
if(resultstr.length() > 0){
this.getView().showMessage("科目数据处理异常"+resultstr);;
this.getView().showMessage("科目导入数据处理异常"+resultstr);
log.info("科目导入数据处理异常"+resultstr);
return;
}
log.info("科目导入处理成功");
this.getView().showMessage("处理成功");
}