部门和科目接口优化
This commit is contained in:
parent
12bacadca2
commit
84380ba10a
|
|
@ -58,6 +58,9 @@ public class AdminOrgControler {
|
|||
JSONArray itemsJson = new JSONArray();//返回值明细集合
|
||||
JSONObject itemInfo;//返回值明细对象
|
||||
JSONArray detailsJson = json_obj.getJSONArray("items");
|
||||
if(detailsJson == null){
|
||||
return CustomApiResult.fail("400","未识别到items参数");
|
||||
}
|
||||
// //处理入参的排序,按照deptLevel正序
|
||||
// detailsJson.sort(Comparator.comparing(json -> ((JSONObject) json).getString("deptLevel")));
|
||||
String orgNumber;
|
||||
|
|
@ -100,7 +103,7 @@ public class AdminOrgControler {
|
|||
continue;
|
||||
}
|
||||
param = new OrgParam();
|
||||
param.setName(orgName);
|
||||
param.setName(orgName.replace("_","-"));
|
||||
param.setNumber(orgNumber);
|
||||
param.setOrgPatternId(4);//组织形态ID,默认ID为4L(部门)1为公司;当前组织是公司还是部门需要有字段可以体现
|
||||
param.setDuty(OrgViewType.Admin);//组织属性-行政组织
|
||||
|
|
|
|||
|
|
@ -47,6 +47,8 @@ public class AspAccountControler {
|
|||
private static final Map<String, DynamicObject> mapObject = new HashMap<>();//公司对象集合
|
||||
private static final Map<String, DynamicObject> hsxmMaps = new HashMap<>();//核算维度对象集合
|
||||
|
||||
private String insertSql = "insert into T_BD_Account_U (fdataid,fuseorgid) values (?,?);";
|
||||
|
||||
/**
|
||||
* @param bizParam 入参json格式数据
|
||||
* @return 自定义返回值
|
||||
|
|
@ -67,8 +69,9 @@ public class AspAccountControler {
|
|||
JSONArray itemsJson = new JSONArray();//返回值明细集合
|
||||
JSONObject itemInfo;//返回值明细对象
|
||||
//根据科目基本信息得到科目编号和JSONObject
|
||||
Map<String, JSONObject> baseMaps = getBaseMap(json_obj.getJSONArray("items"));
|
||||
// Map<String, JSONObject> baseMaps = getBaseMap(json_obj.getJSONArray("items"));
|
||||
JSONArray companysJson = json_obj.getJSONArray("companys");
|
||||
JSONArray detailsJson = json_obj.getJSONArray("items");
|
||||
String number;//科目编号
|
||||
String name;//科目名称
|
||||
// String isleaf;//是否叶子节点
|
||||
|
|
@ -78,35 +81,30 @@ public class AspAccountControler {
|
|||
String bbhs;//币别核算 不核算外币 核算所有外币 指定核算币别(需要指定币别ISO)
|
||||
String acctType;//科目类型 资产负债类 损益类
|
||||
String descurrencynum;//指定币别编号
|
||||
DynamicObject hsorgInfo;
|
||||
// DynamicObject hsorgInfo;
|
||||
DynamicObject acctInfo;
|
||||
DynamicObject acctTypeInfo;
|
||||
DynamicObject parentAcctInfo;
|
||||
JSONObject company_body;
|
||||
// DynamicObject parentAcctInfo;
|
||||
JSONObject json_body;
|
||||
String companynum;
|
||||
DynamicObjectCollection docbb;
|
||||
DynamicObject bbInfo;
|
||||
String bbiso;
|
||||
String insertSql = "insert into T_BD_Account_U(fdataid,fuseorgid) values (?,?);";
|
||||
|
||||
Map<String, Long> acctids = new HashMap<>();//科目编号和ID对应关系
|
||||
Map<String, DynamicObject> accountMaps = new HashMap<>();//将科目编号与对象关联
|
||||
//先根据基础信息在集团层面生成科目,不考虑核算维度,使用逐级分配
|
||||
//再根据公司信息进行科目分配
|
||||
//最后处理每个公司下科目的核算维度和禁用状态
|
||||
for (int i = 0; i < companysJson.size(); i++) {
|
||||
company_body = companysJson.getJSONObject(i);
|
||||
number = company_body.getString("code");
|
||||
json_body = baseMaps.get(number);
|
||||
if(json_body == null){
|
||||
continue;
|
||||
}
|
||||
companynum = company_body.getString("companynum");//公司编号
|
||||
for (int i = 0; i < detailsJson.size(); i++) {
|
||||
json_body = companysJson.getJSONObject(i);
|
||||
number = json_body.getString("code");
|
||||
// json_body = baseMaps.get(number);
|
||||
// companynum = company_body.getString("companynum");//公司编号
|
||||
name = json_body.getString("name");
|
||||
acctType = json_body.getString("type");
|
||||
bbhs = json_body.getString("acctcurrency");
|
||||
descurrencynum = json_body.getString("descurrencynum");
|
||||
if(EsbUtils.isEmpty(number) || EsbUtils.isEmpty(name) || EsbUtils.isEmpty(acctType) || EsbUtils.isEmpty(bbhs) || EsbUtils.isEmpty(companynum)){
|
||||
if(EsbUtils.isEmpty(number) || EsbUtils.isEmpty(name) || EsbUtils.isEmpty(acctType) || EsbUtils.isEmpty(bbhs)){
|
||||
log.error(String.format("会计科目接口入参为空异常:%s", json_body.toJSONString()));
|
||||
itemInfo = new JSONObject();
|
||||
itemInfo.put("code",number);
|
||||
|
|
@ -122,13 +120,13 @@ public class AspAccountControler {
|
|||
itemsJson.add(itemInfo);
|
||||
continue;
|
||||
}
|
||||
//根据科目编号和公司编号查找对应科目是否已存在
|
||||
//根据科目编号和集团ID查找对应科目是否已存在
|
||||
acctInfo = BusinessDataServiceHelper.loadSingle(entityName,new QFilter[]{new QFilter("number","=",number),
|
||||
new QFilter("createorg.number","=", companynum)});
|
||||
new QFilter("createorg.id","=", JhzjUtils.GROUPID)});
|
||||
// acctInfo = BusinessDataServiceHelper.loadSingle(entityName,new QFilter[]{new QFilter("number","=",number)});
|
||||
if(acctInfo != null){
|
||||
//处理科目更新逻辑,此时能修改哪些字段?名称 币别核算 核算维度 是否可用
|
||||
if("0".equals(company_body.getString("companystatus")) || "0".equals(json_body.getString("status"))){
|
||||
if("0".equals(json_body.getString("status"))){
|
||||
acctInfo.set("enable", 0);//科目禁用处理
|
||||
}
|
||||
acctInfo.set("name", name);
|
||||
|
|
@ -160,15 +158,15 @@ public class AspAccountControler {
|
|||
itemsJson.add(itemInfo);
|
||||
continue;
|
||||
}
|
||||
hsorgInfo = getOrgInfo(companynum);
|
||||
if(hsorgInfo == null){
|
||||
log.error(String.format("公司编号在金蝶中未找到对应组织:%s", companynum));
|
||||
itemInfo = new JSONObject();
|
||||
itemInfo.put("code",number);
|
||||
itemInfo.put("error","公司编号在金蝶中未找到对应组织:"+companynum);
|
||||
itemsJson.add(itemInfo);
|
||||
continue;
|
||||
}
|
||||
// hsorgInfo = getOrgInfo(companynum);
|
||||
// if(hsorgInfo == null){
|
||||
// log.error(String.format("公司编号在金蝶中未找到对应组织:%s", companynum));
|
||||
// itemInfo = new JSONObject();
|
||||
// itemInfo.put("code",number);
|
||||
// itemInfo.put("error","公司编号在金蝶中未找到对应组织:"+companynum);
|
||||
// itemsJson.add(itemInfo);
|
||||
// continue;
|
||||
// }
|
||||
//不存在,做新增 根据实体名称创建动态对象
|
||||
acctInfo = BusinessDataServiceHelper.newDynamicObject(entityName);
|
||||
acctInfo.set("accounttable", EsbUtils.ACCTABLE);//科目表fid,上正式时,注意此ID
|
||||
|
|
@ -180,10 +178,10 @@ public class AspAccountControler {
|
|||
acctInfo.set("fullname", name);
|
||||
// acctInfo.set("parent", parentAcctInfo.getLong("id"));
|
||||
//创建组织
|
||||
// acctInfo.set("createorg", JhzjUtils.GROUPID);//创建组织
|
||||
// acctInfo.set("org", JhzjUtils.GROUPID);//管理组织
|
||||
acctInfo.set("createorg", hsorgInfo.getLong("id"));//创建组织
|
||||
acctInfo.set("org", hsorgInfo.getLong("id"));//管理组织
|
||||
acctInfo.set("createorg", JhzjUtils.GROUPID);//创建组织
|
||||
acctInfo.set("org", JhzjUtils.GROUPID);//管理组织
|
||||
// acctInfo.set("createorg", hsorgInfo.getLong("id"));//创建组织
|
||||
// acctInfo.set("org", hsorgInfo.getLong("id"));//管理组织
|
||||
//科目类型
|
||||
acctInfo.set("accounttype", acctTypeInfo.getLong("id"));
|
||||
//币别核算--外币核算类型
|
||||
|
|
@ -230,25 +228,32 @@ public class AspAccountControler {
|
|||
//处理科目使用范围
|
||||
DB.update(DBRoute.of("sys"), insertSql, new Object[]{kmId,JhzjUtils.GROUPID});
|
||||
}
|
||||
accountMaps.put(number+companynum,acctInfo);
|
||||
acctids.put(number,acctInfo.getLong("id"));
|
||||
accountMaps.put(number,acctInfo);
|
||||
}
|
||||
|
||||
//处理科目分配
|
||||
EsbUtils.handleAssign(companysJson, acctids, entityName);
|
||||
|
||||
//处理核算维度
|
||||
//处理科目在每个公司生成
|
||||
handleAccountCompany(accountMaps,companysJson);
|
||||
//处理每个公司下科目的核算维度和禁用状态
|
||||
JSONArray asstacttypesJson = json_obj.getJSONArray("asstacttypes");
|
||||
String hsxm;//核算维度名称 基础资料
|
||||
DynamicObject hsxmInfo;//核算维度对象
|
||||
DynamicObjectCollection dochswd;
|
||||
String companynum;
|
||||
DynamicObject checkitementryInfo = null;
|
||||
for (int i = 0; i < asstacttypesJson.size(); i++) {
|
||||
json_body = asstacttypesJson.getJSONObject(i);
|
||||
hsxm = json_body.getString("asstactname");
|
||||
number = json_body.getString("code");
|
||||
if(EsbUtils.isEmpty(hsxm)){
|
||||
log.error(String.format("核算维度为空:%s", number));
|
||||
itemInfo = new JSONObject();
|
||||
itemInfo.put("code",number);
|
||||
itemInfo.put("error","核算维度为空"+number);
|
||||
itemsJson.add(itemInfo);
|
||||
continue;
|
||||
}
|
||||
number = json_body.getString("code");
|
||||
companynum = json_body.getString("companynum");
|
||||
//根据科目核算维度中的科目编号和公司编号获取对应科目对象,不存在的不处理
|
||||
acctInfo = accountMaps.get(number+companynum);
|
||||
|
|
@ -297,6 +302,93 @@ public class AspAccountControler {
|
|||
}
|
||||
}
|
||||
|
||||
private void handleAccountCompany(Map<String, DynamicObject> accountMaps,JSONArray companysJson){
|
||||
Map<String, DynamicObject> baseMaps = new HashMap<>();
|
||||
JSONObject json_body;
|
||||
DynamicObject oldAcctInfo;
|
||||
DynamicObject newAcctInfo;
|
||||
DynamicObject hsorgInfo;
|
||||
String compnum;
|
||||
String acctnum;
|
||||
for (int i = 0; i < companysJson.size(); i++) {
|
||||
json_body = companysJson.getJSONObject(i);
|
||||
acctnum = json_body.getString("code");//科目编号
|
||||
compnum = json_body.getString("companynum");//公司编号
|
||||
if(EsbUtils.isEmpty(acctnum) || EsbUtils.isEmpty(compnum)){
|
||||
continue;
|
||||
}
|
||||
oldAcctInfo = accountMaps.get(acctnum);
|
||||
if(oldAcctInfo == null){
|
||||
continue;
|
||||
}
|
||||
newAcctInfo = BusinessDataServiceHelper.loadSingle(entityName,new QFilter[]{new QFilter("number","=",acctnum),
|
||||
new QFilter("createorg.number","=", compnum)});
|
||||
if(newAcctInfo == null){
|
||||
hsorgInfo = getOrgInfo(compnum);
|
||||
if(hsorgInfo == null){
|
||||
continue;
|
||||
}
|
||||
//复制对象,修改其中的某些属性,比如id和组织id
|
||||
newAcctInfo = copydo(oldAcctInfo,hsorgInfo);
|
||||
}
|
||||
baseMaps.put(acctnum+compnum, newAcctInfo);
|
||||
}
|
||||
}
|
||||
|
||||
private DynamicObject copydo(DynamicObject olddo, DynamicObject hsorgInfo){
|
||||
DynamicObject newAcctInfo = BusinessDataServiceHelper.newDynamicObject(entityName);
|
||||
newAcctInfo.set("accounttable", EsbUtils.ACCTABLE);//科目表fid,上正式时,注意此ID
|
||||
newAcctInfo.set("number", olddo.getString("number"));
|
||||
newAcctInfo.set("name", olddo.getString("name"));
|
||||
newAcctInfo.set("longnumber", olddo.getString("longnumber"));
|
||||
newAcctInfo.set("fullname", olddo.getString("fullname"));
|
||||
newAcctInfo.set("createorg", hsorgInfo.getLong("id"));//创建组织
|
||||
newAcctInfo.set("org", hsorgInfo.getLong("id"));//管理组织
|
||||
//科目类型
|
||||
newAcctInfo.set("accounttype", olddo.getDynamicObject("accounttype").getLong("id"));
|
||||
//币别核算--外币核算类型
|
||||
newAcctInfo.set("acctcurrency", olddo.getString("acctcurrency"));//不核算外币nocurrency 指定核算币别descurrency 核算所有币别allcurrency
|
||||
//如果是指定核算币别
|
||||
if("descurrency".equals(olddo.getString("acctcurrency"))){
|
||||
//处理具体币别分录数据,根据逗号进行分割
|
||||
DynamicObjectCollection olddocbb = olddo.getDynamicObjectCollection("currencyentry");
|
||||
DynamicObjectCollection newdocbb = newAcctInfo.getDynamicObjectCollection("currencyentry");
|
||||
DynamicObject oldentryinfo;
|
||||
for (int j = 0; j < olddocbb.size(); j++) {
|
||||
oldentryinfo = olddocbb.get(j);
|
||||
newdocbb.addNew().set("currency",oldentryinfo.getDynamicObject("currency").getLong("id"));
|
||||
}
|
||||
}
|
||||
//损益类型
|
||||
newAcctInfo.set("pltype", olddo.getString("pltype"));
|
||||
|
||||
newAcctInfo.set("ctrlstrategy", "1");//控制策略 5全局共享 7私有 1逐级分配
|
||||
newAcctInfo.set("control", "nocontrol");//受控系统 nocontrol 无 应付 应收 资产
|
||||
newAcctInfo.set("dc", 1);//余额方向 默认为借
|
||||
newAcctInfo.set("level", 1);//级次 默认为1
|
||||
newAcctInfo.set("isleaf", true);//明细科目 默认为是
|
||||
newAcctInfo.set("startdate", new Date());//版本化日期
|
||||
newAcctInfo.set("enddate", TypeUtils.castToDate("2999-12-31"));//失效日期
|
||||
newAcctInfo.set("accrualdirection", "nocontrol");//科目录入方向控制 不控制nocontrol 借方debit 贷方credit
|
||||
newAcctInfo.set("orgcontrollevel", 1);//控制级次 默认为1
|
||||
newAcctInfo.set("isallowca", false);//允许公司增加下级科目 由接口同步 为false时控制级次可以不设置
|
||||
newAcctInfo.set("ismanual", false);//手工录入 由接口同步
|
||||
newAcctInfo.set("iscash", false);//现金科目 默认false sap不区分
|
||||
newAcctInfo.set("isbank", false);//银行科目 默认false sap不区分
|
||||
newAcctInfo.set("iscashequivalent", false);//现金等价物 默认false sap不区分
|
||||
newAcctInfo.set("isjournal", false);//登日记账 现金等价物时需要勾选
|
||||
newAcctInfo.set("enable", 1);//是否启用
|
||||
newAcctInfo.set("status", "C");//单据状态 A保存 B已提交 C已审核
|
||||
newAcctInfo.set("creator", RequestContext.get().getCurrUserId());//创建人
|
||||
//手动指定科目的金蝶id
|
||||
newAcctInfo.set("id", ID.genLongId());
|
||||
newAcctInfo.set("masterid", olddo.getLong("id"));//主数据内码,系统不会根据id自动生成,需要手动设置
|
||||
SaveServiceHelper.save(new DynamicObject[]{newAcctInfo});
|
||||
//处理科目使用范围
|
||||
DB.update(DBRoute.of("sys"), insertSql, new Object[]{newAcctInfo.getLong("id"),JhzjUtils.GROUPID});
|
||||
return newAcctInfo;
|
||||
}
|
||||
|
||||
private DynamicObject getHsxmInfo(String hsxmname){
|
||||
//核算维度对象集合
|
||||
DynamicObject orginfo = hsxmMaps.get(hsxmname);
|
||||
|
|
|
|||
Loading…
Reference in New Issue