科目导入和生成逻辑优化
This commit is contained in:
parent
cfb8409f70
commit
0811ca98c2
|
|
@ -33,7 +33,7 @@ public class InitAccountFormPlugin extends AbstractFormPlugin {
|
|||
private final static Log log = LogFactory.getLog(InitAccountFormPlugin.class);
|
||||
private static final String OK_BUTTON_KEY = "btnok";//确认按钮
|
||||
private static final String entityName = "bd_accountview";//会计科目实体 财务库 表名 T_BD_Account
|
||||
private static final String acctTypeName = "bd_accounttype";//科目类型
|
||||
private static final String acctTypeName = "bd_accounttype";//科目类型 T_bd_accounttype
|
||||
private static final String hswdName = "bd_asstacttype";//系统库 核算维度 表名t_bas_flex_property
|
||||
private static final String orgName = "bos_org";//业务单元
|
||||
private static final String bbName = "bd_currency";//币别
|
||||
|
|
@ -42,7 +42,65 @@ public class InitAccountFormPlugin extends AbstractFormPlugin {
|
|||
private static final String insertSql = "insert into T_BD_Account_U (fdataid,fuseorgid) values (?,?);";
|
||||
//处理科目在每个公司生成
|
||||
Map<String, DynamicObject> companyAcctMaps = null;
|
||||
Map<String, Long> acctids = new HashMap<>();//科目编号和ID对应关系
|
||||
Map<String, DynamicObject> accountMaps = new HashMap<>();//将科目编号与对象关联
|
||||
Map<String, DynamicObject> parentMaps = new HashMap<>();//将父级科目编号与对象关联
|
||||
|
||||
private DynamicObject handleParentAcct(String number,String name,String acctType,DynamicObject acctTypeInfo){
|
||||
String parentnumber = number.substring(0, 4);
|
||||
if(parentMaps.get(parentnumber) == null){
|
||||
//处理父级科目名称
|
||||
String parentname = name;
|
||||
if(name.contains("-")){
|
||||
parentname = name.substring(0, name.indexOf("-"));
|
||||
}
|
||||
DynamicObject acctInfo = BusinessDataServiceHelper.newDynamicObject(entityName);
|
||||
acctInfo.set("accounttable", EsbUtils.ACCTABLE);//科目表fid,上正式时,注意此ID
|
||||
acctInfo.set("number", parentnumber);
|
||||
acctInfo.set("name", parentname);
|
||||
acctInfo.set("longnumber", parentnumber);
|
||||
acctInfo.set("fullname", parentname);
|
||||
//创建组织
|
||||
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", false);//明细科目 默认为否
|
||||
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", true);//手工录入 由接口同步
|
||||
acctInfo.set("iscash", false);//现金科目 默认false sap不区分
|
||||
acctInfo.set("isbank", false);//银行科目 默认false sap不区分
|
||||
acctInfo.set("iscashequivalent", false);//现金等价物 默认false sap不区分
|
||||
acctInfo.set("isjournal", false);//登日记账 现金等价物时需要勾选
|
||||
//处理现金 银行科目 登日记账
|
||||
handleAcctProperty(parentnumber,acctInfo);
|
||||
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});
|
||||
parentMaps.put(parentnumber,acctInfo);
|
||||
}
|
||||
return parentMaps.get(parentnumber);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beforeImportEntry(BeforeImportEntryEventArgs e) {
|
||||
|
|
@ -53,10 +111,9 @@ public class InitAccountFormPlugin extends AbstractFormPlugin {
|
|||
Iterator iterator;//遍历页签
|
||||
ImportEntryData importData;
|
||||
JSONObject rowdata;
|
||||
Map<String, Long> acctids = new HashMap<>();//科目编号和ID对应关系
|
||||
Map<String, DynamicObject> accountMaps = new HashMap<>();//将科目编号与对象关联
|
||||
StringBuilder resultstr = new StringBuilder();
|
||||
DynamicObject acctInfo;//科目对象
|
||||
DynamicObject parentAcctInfo;//科目对象
|
||||
String number;//科目编号
|
||||
if(list != null){
|
||||
log.info("科目导入shjh_details"+list.size());
|
||||
|
|
@ -85,16 +142,19 @@ public class InitAccountFormPlugin extends AbstractFormPlugin {
|
|||
resultstr.append("科目类型在金蝶中找不到");
|
||||
continue;
|
||||
}
|
||||
//根据当前编号和名称处理父级科目
|
||||
parentAcctInfo = handleParentAcct(number,name,acctType,acctTypeInfo);
|
||||
// if(name.contains("-")){
|
||||
// name = name.substring(name.indexOf("-")+1);
|
||||
// }
|
||||
//不存在,做新增 根据实体名称创建动态对象
|
||||
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("parent", parentAcctInfo.getLong("id"));
|
||||
acctInfo.set("parent", parentAcctInfo);
|
||||
//创建组织
|
||||
acctInfo.set("createorg", JhzjUtils.GROUPID);//创建组织
|
||||
acctInfo.set("org", JhzjUtils.GROUPID);//管理组织
|
||||
|
|
@ -107,18 +167,20 @@ public class InitAccountFormPlugin extends AbstractFormPlugin {
|
|||
//损益类型
|
||||
acctInfo.set("pltype", getSY(acctType));
|
||||
acctInfo.set("dc", 1);//余额方向 默认为借
|
||||
acctInfo.set("level", 1);//级次 默认为1
|
||||
acctInfo.set("level", 2);//级次 默认为2
|
||||
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("ismanual", true);//手工录入 由接口同步
|
||||
acctInfo.set("iscash", false);//现金科目 默认false sap不区分
|
||||
acctInfo.set("isbank", false);//银行科目 默认false sap不区分
|
||||
acctInfo.set("iscashequivalent", false);//现金等价物 默认false sap不区分
|
||||
acctInfo.set("isjournal", false);//登日记账 现金等价物时需要勾选
|
||||
//处理现金 银行科目 登日记账
|
||||
handleAcctProperty(number,acctInfo);
|
||||
acctInfo.set("enable", 1);//是否启用
|
||||
acctInfo.set("status", "C");//单据状态 A保存 B已提交 C已审核
|
||||
acctInfo.set("creator", RequestContext.get().getCurrUserId());//创建人
|
||||
|
|
@ -130,6 +192,7 @@ public class InitAccountFormPlugin extends AbstractFormPlugin {
|
|||
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);
|
||||
}
|
||||
|
|
@ -137,6 +200,17 @@ public class InitAccountFormPlugin extends AbstractFormPlugin {
|
|||
|
||||
list = (ArrayList) itemEntry.get("shjh_companys");//excel表格的某个页签-科目公司信息
|
||||
if(list != null){
|
||||
if(acctids.isEmpty()){
|
||||
DynamicObject[] accts = BusinessDataServiceHelper.load(entityName,"id",new QFilter[]{new QFilter("accounttable.id","=",EsbUtils.ACCTABLE),
|
||||
new QFilter("createorg.id","=", JhzjUtils.GROUPID),
|
||||
new QFilter("level","=", 2)});
|
||||
for (DynamicObject acct : accts){
|
||||
acct = BusinessDataServiceHelper.loadSingle(acct.getPkValue(),entityName);
|
||||
acctids.put(acct.getString("number"),acct.getLong("id"));
|
||||
accountMaps.put(acct.getString("number"),acct);
|
||||
}
|
||||
}
|
||||
|
||||
log.info("科目导入shjh_companys"+list.size());
|
||||
iterator = list.iterator();//遍历页签
|
||||
JSONArray companysJson = new JSONArray();
|
||||
|
|
@ -150,87 +224,90 @@ public class InitAccountFormPlugin extends AbstractFormPlugin {
|
|||
//处理科目分配
|
||||
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()) {
|
||||
importData = (ImportEntryData) iterator.next();
|
||||
rowdata = importData.getData();//具体的某行数据,key值为列名
|
||||
asstacttypesJson.add(rowdata);
|
||||
}
|
||||
if(!asstacttypesJson.isEmpty()){
|
||||
String hsxm;//核算维度名称 基础资料
|
||||
DynamicObject hsxmInfo;//核算维度对象
|
||||
DynamicObjectCollection dochswd;
|
||||
String companynum;
|
||||
DynamicObject checkitementryInfo = null;
|
||||
JSONObject json_body;
|
||||
for (int i = 0; i < asstacttypesJson.size(); i++) {
|
||||
json_body = asstacttypesJson.getJSONObject(i);
|
||||
hsxm = json_body.getString("shjh_asstactname");
|
||||
number = json_body.getString("shjh_hcode");
|
||||
if(EsbUtils.isEmpty(hsxm)){
|
||||
log.error(String.format("科目导入核算维度为空:%s", number));
|
||||
continue;
|
||||
if(list != null){
|
||||
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),
|
||||
new QFilter("level","=", 2)});
|
||||
for (DynamicObject acct : accts){
|
||||
acct = BusinessDataServiceHelper.loadSingle(acct.getPkValue(),entityName);
|
||||
companyAcctMaps.put(acct.getString("number")+acct.getDynamicObject("createorg").getString("number"),
|
||||
acct);
|
||||
}
|
||||
companynum = json_body.getString("shjh_companynums");
|
||||
//根据科目核算维度中的科目编号和公司编号获取对应科目对象,不存在的不处理
|
||||
acctInfo = companyAcctMaps.get(number+companynum);
|
||||
if(acctInfo == null){
|
||||
continue;
|
||||
}
|
||||
hsxmInfo = getHsxmInfo(hsxm);
|
||||
if(hsxmInfo == null){
|
||||
log.error(String.format("科目导入核算维度在金蝶中找不到:%s", hsxm));
|
||||
resultstr.append(number);
|
||||
resultstr.append("核算维度在金蝶中找不到");
|
||||
continue;
|
||||
}
|
||||
//判断当前科目是否存在此核算维度,不存在则新增,存在则判断是否必录
|
||||
dochswd = acctInfo.getDynamicObjectCollection("checkitementry");
|
||||
for (int j = 0; j < dochswd.size(); j++) {
|
||||
checkitementryInfo = dochswd.get(j);
|
||||
if(hsxmInfo.getLong("id") == checkitementryInfo.getDynamicObject("asstactitem").getLong("id")){
|
||||
break;
|
||||
}
|
||||
log.info("科目导入shjh_hswds"+list.size());
|
||||
iterator = list.iterator();//遍历页签
|
||||
JSONArray asstacttypesJson = new JSONArray();
|
||||
while (iterator.hasNext()) {
|
||||
importData = (ImportEntryData) iterator.next();
|
||||
rowdata = importData.getData();//具体的某行数据,key值为列名
|
||||
asstacttypesJson.add(rowdata);
|
||||
}
|
||||
if(!asstacttypesJson.isEmpty()){
|
||||
String hsxm;//核算维度名称 基础资料
|
||||
DynamicObject hsxmInfo;//核算维度对象
|
||||
DynamicObjectCollection dochswd;
|
||||
String companynum;
|
||||
DynamicObject checkitementryInfo = null;
|
||||
JSONObject json_body;
|
||||
for (int i = 0; i < asstacttypesJson.size(); i++) {
|
||||
json_body = asstacttypesJson.getJSONObject(i);
|
||||
hsxm = json_body.getString("shjh_asstactname");
|
||||
number = json_body.getString("shjh_hcode");
|
||||
if(EsbUtils.isEmpty(hsxm)){
|
||||
log.error(String.format("科目导入核算维度为空:%s", number));
|
||||
continue;
|
||||
}
|
||||
checkitementryInfo = null;
|
||||
companynum = json_body.getString("shjh_companynums");
|
||||
//根据科目核算维度中的科目编号和公司编号获取对应科目对象,不存在的不处理
|
||||
acctInfo = companyAcctMaps.get(number+companynum);
|
||||
if(acctInfo == null){
|
||||
continue;
|
||||
}
|
||||
hsxmInfo = getHsxmInfo(hsxm);
|
||||
if(hsxmInfo == null){
|
||||
log.error(String.format("科目导入核算维度在金蝶中找不到:%s", hsxm));
|
||||
resultstr.append(number);
|
||||
resultstr.append("核算维度在金蝶中找不到");
|
||||
continue;
|
||||
}
|
||||
//判断当前科目是否存在此核算维度,不存在则新增,存在则判断是否必录
|
||||
dochswd = acctInfo.getDynamicObjectCollection("checkitementry");
|
||||
for (int j = 0; j < dochswd.size(); j++) {
|
||||
checkitementryInfo = dochswd.get(j);
|
||||
if(hsxmInfo.getLong("id") == checkitementryInfo.getDynamicObject("asstactitem").getLong("id")){
|
||||
break;
|
||||
}
|
||||
checkitementryInfo = null;
|
||||
}
|
||||
if(checkitementryInfo == null || dochswd.isEmpty()){
|
||||
checkitementryInfo = dochswd.addNew();
|
||||
checkitementryInfo.set("asstactitem",hsxmInfo);
|
||||
checkitementryInfo.set("isdetail", true);//明细
|
||||
}
|
||||
if("1".equals(json_body.getString("shjh_isneed"))){
|
||||
checkitementryInfo.set("isrequire", true);//必录
|
||||
}else{
|
||||
checkitementryInfo.set("isrequire", false);//必录
|
||||
}
|
||||
acctInfo.set("isassist", true);//主表的isassist是否包含核算项目为是
|
||||
SaveServiceHelper.save(new DynamicObject[]{acctInfo});
|
||||
companyAcctMaps.put(number+companynum,acctInfo);
|
||||
}
|
||||
if(checkitementryInfo == null || dochswd.isEmpty()){
|
||||
checkitementryInfo = dochswd.addNew();
|
||||
checkitementryInfo.set("asstactitem",hsxmInfo);
|
||||
checkitementryInfo.set("isdetail", true);//明细
|
||||
}
|
||||
if("1".equals(json_body.getString("shjh_isneed"))){
|
||||
checkitementryInfo.set("isrequire", true);//必录
|
||||
}else{
|
||||
checkitementryInfo.set("isrequire", false);//必录
|
||||
}
|
||||
acctInfo.set("isassist", true);//主表的isassist是否包含核算项目为是
|
||||
SaveServiceHelper.save(new DynamicObject[]{acctInfo});
|
||||
companyAcctMaps.put(number+companynum,acctInfo);
|
||||
}
|
||||
}
|
||||
|
||||
if(resultstr.length() > 0){
|
||||
this.getView().showMessage("科目导入数据处理异常"+resultstr);
|
||||
// this.getView().showMessage("科目导入数据处理异常"+resultstr);
|
||||
log.info("科目导入数据处理异常"+resultstr);
|
||||
return;
|
||||
}
|
||||
log.info("科目导入处理成功");
|
||||
this.getView().showMessage("处理成功");
|
||||
// this.getView().showMessage("处理成功");
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -244,6 +321,22 @@ public class InitAccountFormPlugin extends AbstractFormPlugin {
|
|||
// selectedButton.addClickListener(this);
|
||||
}
|
||||
|
||||
private void handleAcctProperty(String number,DynamicObject acctInfo){
|
||||
// 1001开头 勾选现金科目
|
||||
// 1002开头 勾选银行科目
|
||||
// 1012开头 勾选现金等价物
|
||||
// 1001 或 1002开头 勾选登日记账
|
||||
if(number.startsWith("1001")){
|
||||
acctInfo.set("iscash", true);//现金科目 默认false sap不区分
|
||||
acctInfo.set("isjournal", true);//登日记账 现金等价物时需要勾选
|
||||
}else if(number.startsWith("1002")){
|
||||
acctInfo.set("isbank", true);//银行科目 默认false sap不区分
|
||||
acctInfo.set("isjournal", true);//登日记账 现金等价物时需要勾选
|
||||
}else if(number.startsWith("1012")){
|
||||
acctInfo.set("iscashequivalent", true);//现金等价物 默认false sap不区分
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 按钮点击实现方法
|
||||
*/
|
||||
|
|
@ -308,7 +401,8 @@ public class InitAccountFormPlugin extends AbstractFormPlugin {
|
|||
continue;
|
||||
}
|
||||
newAcctInfo = BusinessDataServiceHelper.loadSingle(entityName,new QFilter[]{new QFilter("number","=",acctnum),
|
||||
new QFilter("createorg.number","=", compnum)});
|
||||
new QFilter("createorg.number","=", compnum),
|
||||
new QFilter("accounttable.id","=",EsbUtils.ACCTABLE)});
|
||||
if(newAcctInfo == null){
|
||||
hsorgInfo = getOrgInfo(compnum);
|
||||
if(hsorgInfo == null){
|
||||
|
|
@ -370,7 +464,7 @@ public class InitAccountFormPlugin extends AbstractFormPlugin {
|
|||
}
|
||||
//损益类型
|
||||
newAcctInfo.set("pltype", olddo.getString("pltype"));
|
||||
|
||||
newAcctInfo.set("parent", olddo.getDynamicObject("parent"));
|
||||
newAcctInfo.set("ctrlstrategy", "1");//控制策略 5全局共享 7私有 1逐级分配
|
||||
newAcctInfo.set("control", "nocontrol");//受控系统 nocontrol 无 应付 应收 资产
|
||||
newAcctInfo.set("dc", 1);//余额方向 默认为借
|
||||
|
|
@ -381,11 +475,11 @@ public class InitAccountFormPlugin extends AbstractFormPlugin {
|
|||
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("ismanual", true);//手工录入 由接口同步
|
||||
newAcctInfo.set("iscash", olddo.getBoolean("iscash"));//现金科目 默认false sap不区分
|
||||
newAcctInfo.set("isbank", olddo.getBoolean("isbank"));//银行科目 默认false sap不区分
|
||||
newAcctInfo.set("iscashequivalent", olddo.getBoolean("iscashequivalent"));//现金等价物 默认false sap不区分
|
||||
newAcctInfo.set("isjournal", olddo.getBoolean("isjournal"));//登日记账 现金等价物时需要勾选
|
||||
newAcctInfo.set("enable", 1);//是否启用
|
||||
newAcctInfo.set("status", "C");//单据状态 A保存 B已提交 C已审核
|
||||
newAcctInfo.set("creator", RequestContext.get().getCurrUserId());//创建人
|
||||
|
|
@ -420,7 +514,7 @@ public class InitAccountFormPlugin extends AbstractFormPlugin {
|
|||
|
||||
private String getSY(String acctType){
|
||||
//根据科目类型返回对应损益类型
|
||||
if("001".equals(acctType)){
|
||||
if("01".equals(acctType) || "001".equals(acctType)){
|
||||
//资产负债类返回非损益类科目
|
||||
return "0";
|
||||
}else{
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ import java.util.Map;
|
|||
public class AspAccountControler {
|
||||
private static final String entityName = "bd_accountview";//会计科目实体 财务库 表名 T_BD_Account
|
||||
// private static final String acctTableName = "bd_accounttable";//科目表
|
||||
private static final String acctTypeName = "bd_accounttype";//科目类型
|
||||
private static final String acctTypeName = "bd_accounttype";//科目类型 T_bd_accounttype
|
||||
private static final String hswdName = "bd_asstacttype";//系统库 核算维度 表名t_bas_flex_property
|
||||
private static final String orgName = "bos_org";//业务单元
|
||||
private static final String bbName = "bd_currency";//币别
|
||||
|
|
@ -85,6 +85,7 @@ public class AspAccountControler {
|
|||
String acctType;//科目类型 资产负债类 损益类
|
||||
DynamicObject acctInfo;
|
||||
DynamicObject acctTypeInfo;
|
||||
DynamicObject parentAcctInfo;
|
||||
JSONObject json_body;
|
||||
|
||||
Map<String, Long> acctids = new HashMap<>();//科目编号和ID对应关系
|
||||
|
|
@ -117,7 +118,8 @@ public class AspAccountControler {
|
|||
// }
|
||||
//根据科目编号和集团ID查找对应科目是否已存在
|
||||
acctInfo = BusinessDataServiceHelper.loadSingle(entityName,new QFilter[]{new QFilter("number","=",number),
|
||||
new QFilter("createorg.id","=", JhzjUtils.GROUPID)});
|
||||
new QFilter("createorg.id","=", JhzjUtils.GROUPID),
|
||||
new QFilter("accounttable.id","=",EsbUtils.ACCTABLE)});
|
||||
if(acctInfo != null){
|
||||
//处理科目更新逻辑,此时能修改哪些字段?名称 是否可用
|
||||
if("0".equals(json_body.getString("status")) || !name.equals(acctInfo.getString("name"))){
|
||||
|
|
@ -142,15 +144,13 @@ public class AspAccountControler {
|
|||
acctInfo.set("number", number);
|
||||
acctInfo.set("name", name);
|
||||
//处理父级科目
|
||||
// parentAcctInfo = getParentAcct(number);
|
||||
parentAcctInfo = getParentAcct(number,name,acctType,acctTypeInfo);
|
||||
acctInfo.set("longnumber", number);
|
||||
acctInfo.set("fullname", name);
|
||||
// acctInfo.set("parent", parentAcctInfo.getLong("id"));
|
||||
acctInfo.set("parent", parentAcctInfo);
|
||||
//创建组织
|
||||
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);
|
||||
//币别核算--外币核算类型--集团科目新增时默认为allcurrency
|
||||
|
|
@ -160,18 +160,20 @@ public class AspAccountControler {
|
|||
//损益类型
|
||||
acctInfo.set("pltype", getSY(acctType));
|
||||
acctInfo.set("dc", 1);//余额方向 默认为借
|
||||
acctInfo.set("level", 1);//级次 默认为1
|
||||
acctInfo.set("level", 2);//级次 默认为2
|
||||
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("ismanual", true);//手工录入 由接口同步
|
||||
acctInfo.set("iscash", false);//现金科目 默认false sap不区分
|
||||
acctInfo.set("isbank", false);//银行科目 默认false sap不区分
|
||||
acctInfo.set("iscashequivalent", false);//现金等价物 默认false sap不区分
|
||||
acctInfo.set("isjournal", false);//登日记账 现金等价物时需要勾选
|
||||
//处理现金 银行科目 登日记账
|
||||
handleAcctProperty(number,acctInfo);
|
||||
acctInfo.set("enable", 1);//是否启用
|
||||
acctInfo.set("status", "C");//单据状态 A保存 B已提交 C已审核
|
||||
acctInfo.set("creator", RequestContext.get().getCurrUserId());//创建人
|
||||
|
|
@ -263,6 +265,22 @@ public class AspAccountControler {
|
|||
}
|
||||
}
|
||||
|
||||
private void handleAcctProperty(String number,DynamicObject acctInfo){
|
||||
// 1001开头 勾选现金科目
|
||||
// 1002开头 勾选银行科目
|
||||
// 1012开头 勾选现金等价物
|
||||
// 1001 或 1002开头 勾选登日记账
|
||||
if(number.startsWith("1001")){
|
||||
acctInfo.set("iscash", true);//现金科目 默认false sap不区分
|
||||
acctInfo.set("isjournal", true);//登日记账 现金等价物时需要勾选
|
||||
}else if(number.startsWith("1002")){
|
||||
acctInfo.set("isbank", true);//银行科目 默认false sap不区分
|
||||
acctInfo.set("isjournal", true);//登日记账 现金等价物时需要勾选
|
||||
}else if(number.startsWith("1012")){
|
||||
acctInfo.set("iscashequivalent", true);//现金等价物 默认false sap不区分
|
||||
}
|
||||
}
|
||||
|
||||
private Map<String, DynamicObject> handleAccountCompany(Map<String, DynamicObject> accountMaps,JSONArray companysJson){
|
||||
Map<String, DynamicObject> baseMaps = new HashMap<>();
|
||||
if(companysJson == null){
|
||||
|
|
@ -286,7 +304,8 @@ public class AspAccountControler {
|
|||
continue;
|
||||
}
|
||||
newAcctInfo = BusinessDataServiceHelper.loadSingle(entityName,new QFilter[]{new QFilter("number","=",acctnum),
|
||||
new QFilter("createorg.number","=", compnum)});
|
||||
new QFilter("createorg.number","=", compnum),
|
||||
new QFilter("accounttable.id","=",EsbUtils.ACCTABLE)});
|
||||
if(newAcctInfo == null){
|
||||
hsorgInfo = getOrgInfo(compnum);
|
||||
if(hsorgInfo == null){
|
||||
|
|
@ -347,7 +366,7 @@ public class AspAccountControler {
|
|||
}
|
||||
//损益类型
|
||||
newAcctInfo.set("pltype", olddo.getString("pltype"));
|
||||
|
||||
newAcctInfo.set("parent", olddo.getDynamicObject("parent"));
|
||||
newAcctInfo.set("ctrlstrategy", "1");//控制策略 5全局共享 7私有 1逐级分配
|
||||
newAcctInfo.set("control", "nocontrol");//受控系统 nocontrol 无 应付 应收 资产
|
||||
newAcctInfo.set("dc", 1);//余额方向 默认为借
|
||||
|
|
@ -358,11 +377,11 @@ public class AspAccountControler {
|
|||
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("ismanual", true);//手工录入 由接口同步
|
||||
newAcctInfo.set("iscash", olddo.getBoolean("iscash"));//现金科目 默认false sap不区分
|
||||
newAcctInfo.set("isbank", olddo.getBoolean("isbank"));//银行科目 默认false sap不区分
|
||||
newAcctInfo.set("iscashequivalent", olddo.getBoolean("iscashequivalent"));//现金等价物 默认false sap不区分
|
||||
newAcctInfo.set("isjournal", olddo.getBoolean("isjournal"));//登日记账 现金等价物时需要勾选
|
||||
newAcctInfo.set("enable", 1);//是否启用
|
||||
newAcctInfo.set("status", "C");//单据状态 A保存 B已提交 C已审核
|
||||
newAcctInfo.set("creator", RequestContext.get().getCurrUserId());//创建人
|
||||
|
|
@ -405,27 +424,73 @@ public class AspAccountControler {
|
|||
return baseMaps;
|
||||
}
|
||||
|
||||
private DynamicObject getParentAcct(String number){
|
||||
private DynamicObject getParentAcct(String number,String name,String acctType,DynamicObject acctTypeInfo){
|
||||
//sap科目编号为10位,且没有层级关系,金蝶按照4-6分两级自行处理
|
||||
String parentNumber = number.substring(0,4);
|
||||
DynamicObject parentAcctInfo = BusinessDataServiceHelper.loadSingleFromCache(entityName,
|
||||
new QFilter[]{new QFilter("number","=",parentNumber)});
|
||||
if(parentAcctInfo == null){
|
||||
//根据科目编号的前四位未找到对应科目,则新增
|
||||
parentAcctInfo = BusinessDataServiceHelper.newDynamicObject(entityName);
|
||||
parentAcctInfo.set("longnumber", number);
|
||||
// parentAcctInfo.set("fullname", name);
|
||||
String parentnumber = number.substring(0,4);
|
||||
DynamicObject acctInfo = BusinessDataServiceHelper.loadSingleFromCache(entityName,
|
||||
new QFilter[]{new QFilter("number","=", parentnumber),
|
||||
new QFilter("accounttable.id","=", EsbUtils.ACCTABLE),
|
||||
new QFilter("createorg.id","=", JhzjUtils.GROUPID)});
|
||||
if(acctInfo == null){
|
||||
//处理父级科目名称
|
||||
String parentname = name;
|
||||
if(name.contains("-")){
|
||||
parentname = name.substring(0, name.indexOf("-"));
|
||||
}
|
||||
acctInfo = BusinessDataServiceHelper.newDynamicObject(entityName);
|
||||
acctInfo.set("accounttable", EsbUtils.ACCTABLE);//科目表fid,上正式时,注意此ID
|
||||
acctInfo.set("number", parentnumber);
|
||||
acctInfo.set("name", parentname);
|
||||
acctInfo.set("longnumber", parentnumber);
|
||||
acctInfo.set("fullname", parentname);
|
||||
//创建组织
|
||||
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", false);//明细科目 默认为否
|
||||
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", true);//手工录入 由接口同步
|
||||
acctInfo.set("iscash", false);//现金科目 默认false sap不区分
|
||||
acctInfo.set("isbank", false);//银行科目 默认false sap不区分
|
||||
acctInfo.set("iscashequivalent", false);//现金等价物 默认false sap不区分
|
||||
acctInfo.set("isjournal", false);//登日记账 现金等价物时需要勾选
|
||||
//处理现金 银行科目 登日记账
|
||||
handleAcctProperty(parentnumber,acctInfo);
|
||||
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});
|
||||
}
|
||||
return parentAcctInfo;
|
||||
return acctInfo;
|
||||
}
|
||||
|
||||
private String getSY(String acctType){
|
||||
//根据科目类型返回对应损益类型
|
||||
if("001".equals(acctType)){
|
||||
if("01".equals(acctType) || "001".equals(acctType)){
|
||||
//资产负债类返回非损益类科目
|
||||
return "0";
|
||||
}else{
|
||||
//损益类返回其它损益类型
|
||||
//损益类返回其它损益类型s
|
||||
return "6";
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue