📄 initializedbdata.java
字号:
package org.operamasks.example.ejb.gl.service;import java.util.Date;import java.util.Random;import javax.naming.NamingException;import org.operamasks.example.ejb.gl.entity.AccountView;import org.operamasks.example.ejb.gl.entity.Currency;import org.operamasks.example.ejb.gl.entity.Period;import org.operamasks.example.ejb.gl.entity.Person;import org.operamasks.example.ejb.gl.entity.Voucher;import org.operamasks.example.ejb.gl.entity.VoucherEntry;import org.operamasks.example.ejb.gl.entity.VoucherType;/** * * @author xxj * initialize data */public class InitializeDBData { private static final int ENTRY_NUMBER = 100; private IAccountViewService accountViewService; private ICurrencyService currencyService; private IPeriodService periodService; private IVoucherService voucherService; private IVoucherTypeService voucherTypeService; private IPersonService personService; Random random = new Random(); public static void main(String[] args) throws NamingException { InitializeDBData initializer = new InitializeDBData(); initializer.initService(); initializer.initData(); } private void initData() { createCurrency(); createPerson(); createVoucherType(); createPeriod(); createAccountView(); createVoucher(); createVoucherEntry(); } private void createVoucherEntry() { for(int i =1; i< 101; i++){ Voucher voucher = voucherService.getVoucher("voucher_" + i); for (int j = 0; j < ENTRY_NUMBER; ++j) { voucher.getEntries().add( createVoucherEntry("entry_"+ i +"_" + j, "这是我的第" + (100 * i + j) + "条凭证分录", (100 * i + j), voucher)); } voucherService.modifyVoucher(voucher); } } private void createVoucher() { for (int i = 1; i < 101; i++) { Voucher voucher = new Voucher(); voucher.setId("voucher_" + i); voucher.setBookedDate(new Date()); voucher.setCashier(personService.getPerson("person_" + (random.nextInt(4) + 1))); voucher.setCurrency(currencyService.getCurrency("currency_1")); voucher.setHasCashAccount(random.nextBoolean()); voucher.setIsCheck(random.nextBoolean()); voucher.setLocalCreditAmount(random.nextDouble()); voucher.setLocalDebitAmout(random.nextDouble()); voucher.setName("voucher_" + i); voucher.setNumber("voucher_" + i); voucher.setPeriod(periodService.getPeriod("period_" + i)); voucher.setPoster(personService.getPerson("person_" + (random.nextInt(4) + 1))); voucher.setVoucherAbstract("这是我的第" + i + "张凭证"); voucher .setVoucherType(voucherTypeService .getVoucherType("voucherType_" + (random.nextInt(100) + 1))); // for (int j = 0; j < ENTRY_NUMBER; ++j) { // voucher.getEntries().add( // createVoucherEntry("entry_"+ i +"_" + j, "这是我的第" // + (100 * i + j) + "条凭证分录", (100 * i + j), // voucher)); // } voucherService.createVoucher(voucher); } } private VoucherEntry createVoucherEntry(String id, String desc, int seq, Voucher voucher) { VoucherEntry entry = new VoucherEntry(); entry.setId(id); entry.setAccountView(accountViewService.getAccountView("accountView_" + (random.nextInt(100) + 1))); entry.setCashier(personService.getPerson("person_" + (random.nextInt(4) + 1))); entry.setCurrency(currencyService.getCurrency("currency_1")); entry.setDescription(desc); entry.setIsCheck(random.nextBoolean()); entry.setLocalAmount(random.nextDouble()); entry.setPrice(random.nextDouble()); entry.setQuantity(random.nextInt()); entry.setSeq(seq); entry.setVoucher(voucher); // /** // * 给分录创建指定数目的辅助帐行记录 // */ // for (int i = 0; i < ASSIST_NUMBER; ++i) { // entry.getVoucherAssistRecords() // .add( // createVoucherAssistRecord(id + "-" + "assist" + i, // i, entry)); // } return entry; } // private VoucherAssistRecord createVoucherAssistRecord(String id, int seq, // VoucherEntry entry) { // VoucherAssistRecord assist = new VoucherAssistRecord(); // assist.setId(id); // assist.setInvoiceNumber(String.valueOf(random.nextDouble())); // assist.setLocalAmount(random.nextInt()); // assist.setOriginalAmount(random.nextInt()); // assist.setQuantity(random.nextInt()); // assist.setSettlementCode("Cashier" + random.nextInt()); // assist.setSeq(seq); // assist.setVoucherEntry(entry); // return assist; // } private void createAccountView() { for (int i = 1; i < 101; i++) { AccountView accountView = new AccountView(); accountView.setId("accountView_" + i); accountView.setIsBank(random.nextBoolean()); accountView.setIsLeaf(random.nextBoolean()); accountView.setLevel(i); accountView.setLongNumber("accountView_" + i); accountView.setName("accountView_" + i); accountView.setNumber("accountView_" + i); accountViewService.createAccountView(accountView); } } private void createPeriod() { for (int i = 1; i < 101; i++) { Period period = new Period(); period.setId("period_" + i); period.setBeginDate(new Date()); period.setNumber("period_" + i); period.setPeriodNumber(i); period.setPeriodQuarter(random.nextInt(4) + 1); period.setEndDate(new Date()); periodService.createPeriod(period); } } private void createVoucherType() { for (int i = 1; i < 101; i++) { VoucherType voucherType = new VoucherType(); voucherType.setId("voucherType_" + i); voucherType.setLevel(random.nextInt(10)); voucherType.setName("Post_" + i); voucherType.setNumber("voucherType_" + i); voucherType.setPretermit(i % 2 == 0); voucherTypeService.createVoucherType(voucherType); } } private void createPerson() { String[] personNames = new String[] { "wanx", "plutoluo", "lulc", "liqi" }; int i = 1; for (String personName : personNames) { Person person = new Person(); person.setId("person_" + i); person.setName(personName); person.setBirthday(new Date()); person.setEmail(personName + "@apusic.com"); person.setPosition("developer"); personService.createPerson(person); i++; } } private void createCurrency() { Currency currency = new Currency(); currency.setId("currency_1"); currency.setIsocode("ISO9001"); currency.setBaseUnit("元"); currency.setPrecision("0.00"); currency.setSign("人民币"); currencyService.createCurrency(currency); } private void initService() throws NamingException { java.util.Properties p = new java.util.Properties(); p.put(javax.naming.Context.PROVIDER_URL, "iiop://127.0.0.1:6888"); p.put(javax.naming.Context.INITIAL_CONTEXT_FACTORY, "com.apusic.naming.jndi.CNContextFactory"); javax.naming.InitialContext initCtx = new javax.naming.InitialContext(p); this.accountViewService = (IAccountViewService) initCtx .lookup("org.operamasks.example.ejb.gl.service.AccountViewService"); this.currencyService = (ICurrencyService) initCtx .lookup("org.operamasks.example.ejb.gl.service.CurrencyService"); this.periodService = (IPeriodService) initCtx .lookup("org.operamasks.example.ejb.gl.service.PeriodService"); this.voucherService = (IVoucherService) initCtx .lookup("org.operamasks.example.ejb.gl.service.VoucherService"); this.voucherTypeService = (IVoucherTypeService) initCtx .lookup("org.operamasks.example.ejb.gl.service.VoucherTypeService"); this.personService = (IPersonService) initCtx .lookup("org.operamasks.example.ejb.gl.service.PersonService"); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -