HFM深入技术学习系列之四--调用API生成日记账

概述

本文描述使用HFM提供的SDK自动生成日记账

介绍

分为三个步骤
1 获得进入HFM的session
2 获得JournalOM
3 使用JournalOM保存日记账

用到的包

fmcommon.jar
fm-web-objectmodel.jar
hssutil.jar

代码示例

获取JournalOM

ISecurityManager tpMNG  = HSSUtilManager.getSecurityManager();
String ssoToken = tpMNG.authenticateUser(USERNAME, PASSWORD);
SessionOM adminSessionOM = new SessionOM();
adminSessionInfo1 = adminSessionOM.createSession(ssoToken, Locale.ENGLISH, HFM_DEV, FINCAPP);
JournalOM adminJournalOM = new JournalOM(adminSessionInfo1);

生成日记账

JSONObject json = (JSONObject) jsonObj;
labels.add((String) json.get("label")) ;
try {
    journal = journalOM.getJournalByName((String) json.get("label"), (String) json.get("scenario"), (String) json.get("year"), (String) json.get("period"));
    journalOM.performJournalAction(labels, (String) json.get("scenario"), (String) json.get("year"), (String) json.get("period"), JOURNAL_ACTION.JBA_DELETE);
}
catch (Exception e){
    System.out.println(e.getMessage());
}
journal.setLabel((String) json.get("label"));
journal.setBalancedType(JOURNAL_BALANCE_TYPE.JBTF_UNBALANCED);
journal.setSecurity((String) json.get("security"));
journal.setType(JOURNAL_TYPE.JTF_REGULAR);
journal.setSingleEntity((String) json.get("singleEntity"));
journal.setSingleParent((String) json.get("singleParent"));
journal.setStatus(JOURNAL_STATUS.JSF_WORKING);
year = new JournalDimension();
period = new JournalDimension();
value = new JournalDimension();
scenario = new JournalDimension();
scenario.setName("Scenario");
scenario.setMember((String) json.get("scenario"));
year.setName("Year");
year.setMember((String) json.get("year"));
period.setName("Period");
period.setMember((String) json.get("period"));
value.setName("Value");
value.setMember((String) json.get("value"));
povs.add(scenario);
povs.add(year);
povs.add(period);
povs.add(value);
JSONArray journalLines = (JSONArray) json.get("lines");
List<JournalLineItem> journalLineItems = new ArrayList<JournalLineItem>();
i=0;
for (Object jsonLineObj : journalLines) {
    JSONObject jsonLine = (JSONObject) jsonLineObj;
    entity = new JournalDimension();
    account = new JournalDimension();
    icp = new JournalDimension();
    custom1 = new JournalDimension();
    custom2 = new JournalDimension();
    custom3 = new JournalDimension();
    custom4 = new JournalDimension();
    journalDimensions = new ArrayList<JournalDimension>();
    lineItem = new JournalLineItem();
    entity.setName("Entity");
    entity.setMember((String) jsonLine.get("entity"));
    account.setName("Account");
    account.setMember((String) jsonLine.get("account"));
    icp.setName("ICP");
    icp.setMember((String) jsonLine.get("icp"));
    custom1.setName("Custom1");
    custom1.setMember((String) jsonLine.get("custom1"));
    custom2.setName("Custom2");
    custom2.setMember((String) jsonLine.get("custom2"));
    custom3.setName("Custom3");
    custom3.setMember((String) jsonLine.get("custom3"));
    custom4.setName("Custom4");
    custom4.setMember((String) jsonLine.get("custom4"));
    journalDimensions.add(entity);
    journalDimensions.add(account);
    journalDimensions.add(icp);
    journalDimensions.add(custom1);
    journalDimensions.add(custom2);
    journalDimensions.add(custom3);
    journalDimensions.add(custom4);
    lineItem.setLineItemDimensions(journalDimensions);
    lineItem.setAmount((String) jsonLine.get("amount"));
    lineType = (String) jsonLine.get("linetype");
    if (lineType.equals("dr")) {
        lineItem.setDebitUnit(DEBIT_CREDIT_UNIT.JE_TYPE_DEBIT);
    } else {
        lineItem.setDebitUnit(DEBIT_CREDIT_UNIT.JE_TYPE_CREDIT);
    }
    journalLineItems.add(i, lineItem);
    i++;
}
journal.setPov(povs);
journal.setLineItems(journalLineItems);
journalOM.saveJournal(journal);

你可能感兴趣的:(HFM,HFM,java,API,SDK)