From cd1ab2636bcee06337706f2f9ee53fff681f8fea Mon Sep 17 00:00:00 2001 From: houyi Date: Wed, 15 Oct 2014 18:34:08 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=88=9D=E5=A7=8B=E5=8C=96?= =?UTF-8?q?=E6=8C=89=E9=92=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 5 +++ resources/applicationContext.xml | 2 +- resources/log4j.properties | 9 ++++ resources/lottery.properties | 3 +- src/com/lottery/Launcher.java | 1 + src/com/lottery/action/ImportBtnAction.java | 9 ++-- src/com/lottery/action/InitDataAction.java | 20 +++++++++ .../lottery/service/LotteryAllService.java | 42 +++++++++++++++++++ .../lottery/service/LotteryAnyService.java | 1 + src/com/lottery/ui/MainUI.java | 23 ++++++---- 10 files changed, 101 insertions(+), 14 deletions(-) create mode 100644 resources/log4j.properties create mode 100644 src/com/lottery/action/InitDataAction.java diff --git a/pom.xml b/pom.xml index cfca4ff..b73f68c 100644 --- a/pom.xml +++ b/pom.xml @@ -31,6 +31,11 @@ aopalliance 1.0 + + org.javassist + javassist + 3.18.2-GA + c3p0 c3p0 diff --git a/resources/applicationContext.xml b/resources/applicationContext.xml index db3b8b6..891270b 100644 --- a/resources/applicationContext.xml +++ b/resources/applicationContext.xml @@ -12,7 +12,7 @@ - + diff --git a/resources/log4j.properties b/resources/log4j.properties new file mode 100644 index 0000000..9edb018 --- /dev/null +++ b/resources/log4j.properties @@ -0,0 +1,9 @@ +### set log levels ### +log4j.rootLogger = INFO,console +log4j.logger.org.hibernate.type=TRACE +log4j.logger.com.itec.bdp=DEBUG +#console +log4j.appender.console = org.apache.log4j.ConsoleAppender +log4j.appender.console.Target = System.out +log4j.appender.console.layout = org.apache.log4j.PatternLayout +log4j.appender.console.layout.ConversionPattern = %-d{HH:mm:ss} [%t:%r] - [%p] %m%n diff --git a/resources/lottery.properties b/resources/lottery.properties index 514c88b..8e7adee 100644 --- a/resources/lottery.properties +++ b/resources/lottery.properties @@ -19,7 +19,8 @@ javax.persistence.validation.mode=none #------------ H2 ------------ h2.jdbc.driver=org.h2.Driver -h2.jdbc.url=jdbc:h2:tcp://127.0.0.1/~/lottery +#h2.jdbc.url=jdbc:h2:tcp://127.0.0.1/~/lottery +h2.jdbc.url=jdbc:h2:~/lottery h2.hibernate.dialect=org.hibernate.dialect.H2Dialect h2.jdbc.username=lottery h2.jdbc.password=lottery diff --git a/src/com/lottery/Launcher.java b/src/com/lottery/Launcher.java index e4cd277..f37909a 100644 --- a/src/com/lottery/Launcher.java +++ b/src/com/lottery/Launcher.java @@ -1,5 +1,6 @@ package com.lottery; +import org.springframework.context.annotation.ComponentScan; import org.springframework.context.support.ClassPathXmlApplicationContext; /** diff --git a/src/com/lottery/action/ImportBtnAction.java b/src/com/lottery/action/ImportBtnAction.java index a3ee30c..fe9548d 100644 --- a/src/com/lottery/action/ImportBtnAction.java +++ b/src/com/lottery/action/ImportBtnAction.java @@ -1,6 +1,7 @@ package com.lottery.action; import com.lottery.model.LotteryAll; +import com.lottery.model.LotteryAny; import org.apache.commons.io.FileUtils; import org.apache.commons.lang.StringUtils; @@ -63,14 +64,14 @@ private void processImport(File file) { try { List lines = FileUtils.readLines(file); - List lotteryAlls = new ArrayList(); + List lotteryAnys = new ArrayList(); for (String line : lines) { - LotteryAll lotteryAll = new LotteryAll(); + LotteryAny lotteryAny = new LotteryAny(); - lotteryAlls.add(lotteryAll); + lotteryAnys.add(lotteryAny); } - //TODO 保存 lotteryAlls + //TODO 保存 lotteryAnys } catch (IOException e) { diff --git a/src/com/lottery/action/InitDataAction.java b/src/com/lottery/action/InitDataAction.java new file mode 100644 index 0000000..dada290 --- /dev/null +++ b/src/com/lottery/action/InitDataAction.java @@ -0,0 +1,20 @@ +package com.lottery.action; + +import com.lottery.service.LotteryAllService; +import org.springframework.beans.factory.annotation.Autowired; + +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +/** + * Created by houyi on 2014/10/15. + */ +public class InitDataAction implements ActionListener { + @Autowired + private LotteryAllService lotteryAllService; + + @Override + public void actionPerformed(ActionEvent e) { + lotteryAllService.initLotteryData(); + } +} diff --git a/src/com/lottery/service/LotteryAllService.java b/src/com/lottery/service/LotteryAllService.java index af17d5e..31a63a4 100644 --- a/src/com/lottery/service/LotteryAllService.java +++ b/src/com/lottery/service/LotteryAllService.java @@ -1,9 +1,11 @@ package com.lottery.service; +import com.lottery.model.LotteryAll; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.lottery.dao.LotteryAllDao; +import org.springframework.transaction.annotation.Transactional; /** * @author houyi @@ -13,4 +15,44 @@ public class LotteryAllService { @Autowired private LotteryAllDao lotteryAllDao; + + @Transactional + public void initLotteryData(){ + for (int i = 0 ; i <= 99999 ; i ++){ + LotteryAll lotteryAll = new LotteryAll(); + if(i >= 0 && i < 10){ + lotteryAll.setFront_one(0); + lotteryAll.setFront_two(0); + lotteryAll.setFront_three(0); + lotteryAll.setFront_four(0); + lotteryAll.setFront_five(i); + }else if(i >= 10 && i < 100){ + lotteryAll.setFront_one(0); + lotteryAll.setFront_two(0); + lotteryAll.setFront_three(0); + lotteryAll.setFront_four(Integer.parseInt(String.valueOf(i).substring(0, 1))); + lotteryAll.setFront_five(Integer.parseInt(String.valueOf(i).substring(1))); + }else if(i >= 100 && i < 1000){ + lotteryAll.setFront_one(0); + lotteryAll.setFront_two(0); + lotteryAll.setFront_three(Integer.parseInt(String.valueOf(i).substring(0, 1))); + lotteryAll.setFront_four(Integer.parseInt(String.valueOf(i).substring(1, 2))); + lotteryAll.setFront_five(Integer.parseInt(String.valueOf(i).substring(2))); + }else if(i >= 1000 && i < 10000){ + lotteryAll.setFront_one(0); + lotteryAll.setFront_two(Integer.parseInt(String.valueOf(i).substring(0, 1))); + lotteryAll.setFront_three(Integer.parseInt(String.valueOf(i).substring(1, 2))); + lotteryAll.setFront_four(Integer.parseInt(String.valueOf(i).substring(2, 3))); + lotteryAll.setFront_five(Integer.parseInt(String.valueOf(i).substring(3))); + }else if(i >= 10000 && i <= 99999){ + lotteryAll.setFront_one(Integer.parseInt(String.valueOf(i).substring(0, 1))); + lotteryAll.setFront_two(Integer.parseInt(String.valueOf(i).substring(1, 2))); + lotteryAll.setFront_three(Integer.parseInt(String.valueOf(i).substring(2, 3))); + lotteryAll.setFront_four(Integer.parseInt(String.valueOf(i).substring(3, 4))); + lotteryAll.setFront_five(Integer.parseInt(String.valueOf(i).substring(4))); + } + lotteryAll.setStatus("N"); + lotteryAllDao.save(lotteryAll); + } + } } diff --git a/src/com/lottery/service/LotteryAnyService.java b/src/com/lottery/service/LotteryAnyService.java index 534d80d..4ca27fc 100644 --- a/src/com/lottery/service/LotteryAnyService.java +++ b/src/com/lottery/service/LotteryAnyService.java @@ -13,4 +13,5 @@ public class LotteryAnyService { @Autowired private LotteryAnyDao lotteryAnyDao; + } diff --git a/src/com/lottery/ui/MainUI.java b/src/com/lottery/ui/MainUI.java index 8ae72c8..bcde675 100644 --- a/src/com/lottery/ui/MainUI.java +++ b/src/com/lottery/ui/MainUI.java @@ -1,6 +1,7 @@ package com.lottery.ui; import com.lottery.action.ImportBtnAction; +import com.lottery.action.InitDataAction; import javax.swing.*; import javax.swing.border.EmptyBorder; @@ -34,21 +35,22 @@ public void run() { * Create the frame. */ public MainUI() { - setTitle("\u5927\u4E50\u900F\u5206\u6790\u7CFB\u7EDF"); + setTitle("͸ϵͳ"); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setBounds(100, 100, 450, 300); JMenuBar menuBar = new JMenuBar(); setJMenuBar(menuBar); - JMenu mnNewMenu = new JMenu("\u6587\u4EF6"); + JMenu mnNewMenu = new JMenu(" "); menuBar.add(mnNewMenu); - JMenuItem menuItem = new JMenuItem("\u5BFC\u5165\u6570\u636E"); + JMenuItem menuItem = new JMenuItem(""); mnNewMenu.add(menuItem); - JMenuItem menuItem_1 = new JMenuItem("\u9000\u51FA"); + JMenuItem menuItem_1 = new JMenuItem(" "); mnNewMenu.add(menuItem_1); + contentPane = new JPanel(); contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); contentPane.setLayout(new BorderLayout(0, 0)); @@ -58,17 +60,22 @@ public MainUI() { toolBar.setEnabled(false); contentPane.add(toolBar, BorderLayout.NORTH); - JButton importBtn = new JButton("\u5BFC\u5165\u6570\u636E"); + JButton initBtn = new JButton("ʼ"); + initBtn.addActionListener(new InitDataAction()); + initBtn.setPreferredSize(new Dimension(100, 30)); + toolBar.add(initBtn); + + JButton importBtn = new JButton(""); importBtn.addActionListener(new ImportBtnAction()); - importBtn.setPreferredSize(new Dimension(60, 30)); + importBtn.setPreferredSize(new Dimension(80, 30)); toolBar.add(importBtn); JComboBox comboBox_1 = new JComboBox(); - comboBox_1.setPreferredSize(new Dimension(400, 30)); + comboBox_1.setPreferredSize(new Dimension(350, 30)); toolBar.add(comboBox_1); JComboBox comboBox = new JComboBox(); - comboBox.setPreferredSize(new Dimension(400, 30)); + comboBox.setPreferredSize(new Dimension(350, 30)); toolBar.add(comboBox); }