Skip to content

Commit e1bf3be

Browse files
committed
2018年6月15日小测验前更新数据,补充数据库
1 parent 292d219 commit e1bf3be

12 files changed

Lines changed: 499 additions & 11 deletions

File tree

src/main/java/cn/lynu/lyq/java_exam/test/PDFGenerateTest1.java

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
import com.itextpdf.text.BaseColor;
66
import com.itextpdf.text.Chunk;
77
import com.itextpdf.text.Document;
8+
import com.itextpdf.text.DocumentException;
89
import com.itextpdf.text.Font;
9-
import com.itextpdf.text.Image;
1010
import com.itextpdf.text.PageSize;
1111
import com.itextpdf.text.Paragraph;
1212
import com.itextpdf.text.Phrase;
@@ -38,8 +38,8 @@ public static void main(String[] args) throws Exception{
3838
doc.add(new Paragraph("Hello World!你好,世界",fontChinese));
3939
doc.add(new Paragraph("You are Welcome!"));
4040

41-
Image img = Image.getInstance("C:\\Users\\mikemelon\\Pictures\\1.png");
42-
doc.add(img);
41+
// Image img = Image.getInstance("C:\\Users\\mikemelon\\Pictures\\1.png");
42+
// doc.add(img);
4343

4444
doc.newPage();
4545
doc.add(new Phrase("Phrase page"));
@@ -78,19 +78,38 @@ public static void addChoiceQuestionAndAnswer(Document doc) throws Exception{
7878
doc.add(new Chunk("D. Java BE",fontEn));
7979
doc.add(Chunk.NEWLINE);
8080
doc.add(new Chunk("答案:B",fontCn));
81+
doc.add(Chunk.NEWLINE);
82+
addChunkForChineseAndEnglish("这是一个Java语言的关键字main、abstract,false的测试!数组int[] k={1,2,3,4}",doc,fontCn,fontEn);
8183

8284
}
8385

84-
public static void addChunkForChineseAndEnglish(String str, Document doc, Font fontCn, Font fontEn){
86+
public static void addChunkForChineseAndEnglish(String str, Document doc, Font fontCn, Font fontEn) throws DocumentException{
8587
StringBuilder sb = new StringBuilder();
8688
char[] chars = str.toCharArray();
8789
for(int i=0; i<chars.length; i++){
88-
if(i==0)
90+
if(i==0){
8991
sb.append(chars[i]);
90-
else{
91-
// if(isChinese(chars[i]))
92+
}else{
93+
if(isChinese(chars[i]) && !isChinese(chars[i-1])){
94+
doc.add(new Chunk(sb.toString(),fontEn));
95+
sb = new StringBuilder();
96+
sb.append(chars[i]);
97+
}else if(!isChinese(chars[i]) && isChinese(chars[i-1])){
98+
doc.add(new Chunk(sb.toString(),fontCn));
99+
sb = new StringBuilder();
100+
sb.append(chars[i]);
101+
}else{
102+
sb.append(chars[i]);
103+
}
92104
}
93105

106+
if(i==chars.length-1){
107+
if(isChinese(chars[i])){
108+
doc.add(new Chunk(sb.toString(),fontCn));
109+
}else{
110+
doc.add(new Chunk(sb.toString(),fontEn));
111+
}
112+
}
94113
}
95114

96115
}
Lines changed: 194 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,194 @@
1+
package cn.lynu.lyq.java_exam.test;
2+
3+
import java.io.FileOutputStream;
4+
5+
import org.springframework.context.support.ClassPathXmlApplicationContext;
6+
7+
import com.itextpdf.text.BaseColor;
8+
import com.itextpdf.text.Chunk;
9+
import com.itextpdf.text.Document;
10+
import com.itextpdf.text.DocumentException;
11+
import com.itextpdf.text.Font;
12+
import com.itextpdf.text.PageSize;
13+
import com.itextpdf.text.Paragraph;
14+
import com.itextpdf.text.pdf.BaseFont;
15+
import com.itextpdf.text.pdf.PdfWriter;
16+
17+
import cn.lynu.lyq.java_exam.dao.BankQuestionDao;
18+
import cn.lynu.lyq.java_exam.entity.BankBlankFillingQuestion;
19+
import cn.lynu.lyq.java_exam.entity.BankChoiceQuestion;
20+
import cn.lynu.lyq.java_exam.entity.BankJudgeQuestion;
21+
22+
public class PDFGenerateTest2 {
23+
24+
public static void main(String[] args) throws Exception{
25+
System.out.println("\u2713");
26+
System.out.println("\u2717");
27+
Document doc = new Document(PageSize.A4);
28+
PdfWriter pdfWriter = PdfWriter.getInstance(doc, new FileOutputStream("c:\\Problems.pdf"));
29+
doc.open();
30+
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
31+
BankQuestionDao bankQuestionDao = (BankQuestionDao) context.getBean("bankQuestionDao");
32+
for(int i=1; i<=5; i++){
33+
BankChoiceQuestion bq = bankQuestionDao.findChoiceById(i);
34+
addChoiceQuestionAndAnswer(doc,bq);
35+
}
36+
37+
for(int i=1; i<=5; i++){
38+
BankJudgeQuestion bq = bankQuestionDao.findJudgeById(i);
39+
addJudgeQuestionAndAnswer(doc,bq);
40+
}
41+
42+
for(int i=1; i<=5; i++){
43+
BankBlankFillingQuestion bq = bankQuestionDao.findBlankFillingById(i);
44+
addBlankFillingQuestionAndAnswer(doc,bq);
45+
}
46+
doc.close();
47+
context.close();
48+
}
49+
50+
public static void addChoiceQuestionAndAnswer(Document doc, BankChoiceQuestion bq) throws Exception{
51+
52+
BaseFont bfChinese = BaseFont.createFont("C:/WINDOWS/Fonts/SIMKAI.TTF", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
53+
Font fontCn = new Font(bfChinese, 20, Font.NORMAL);
54+
Font fontCn2 = new Font(bfChinese, 12, Font.NORMAL);
55+
Font fontEn = new Font(Font.FontFamily.TIMES_ROMAN,19,Font.NORMAL);
56+
57+
addParagraphForChineseAndEnglish(bq.getId()+"."+bq.getContent(),doc,fontCn,fontEn);
58+
addChunkForChineseAndEnglish(bq.getChoiceA(),doc,fontCn,fontEn);
59+
doc.add(Chunk.NEWLINE);
60+
addChunkForChineseAndEnglish(bq.getChoiceB(),doc,fontCn,fontEn);
61+
doc.add(Chunk.NEWLINE);
62+
addChunkForChineseAndEnglish(bq.getChoiceC(),doc,fontCn,fontEn);
63+
doc.add(Chunk.NEWLINE);
64+
addChunkForChineseAndEnglish(bq.getChoiceD(),doc,fontCn,fontEn);
65+
doc.add(Chunk.NEWLINE);
66+
addChunkForChineseAndEnglish("答案是:"+bq.getAnswer(),doc,fontCn,fontEn);
67+
68+
Chunk ck=new Chunk(bq.getKnowledgePoint().substring(0, bq.getKnowledgePoint().indexOf('*')),fontCn2);
69+
ck.setBackground(BaseColor.ORANGE, 1f,2f,2f,1f);
70+
ck.setTextRise(12.5f);
71+
doc.add(ck);
72+
73+
doc.add(Chunk.NEWLINE);
74+
doc.add(Chunk.NEWLINE);
75+
76+
}
77+
78+
79+
public static void addJudgeQuestionAndAnswer(Document doc, BankJudgeQuestion bq) throws Exception{
80+
81+
BaseFont bfChinese = BaseFont.createFont("C:/WINDOWS/Fonts/SIMKAI.TTF", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
82+
Font fontCn = new Font(bfChinese, 20, Font.NORMAL);
83+
Font fontCn2 = new Font(bfChinese, 12, Font.NORMAL);
84+
Font fontEn = new Font(Font.FontFamily.TIMES_ROMAN,19,Font.NORMAL);
85+
86+
addParagraphForChineseAndEnglish(bq.getId()+"."+bq.getContent(),doc,fontCn,fontEn);
87+
doc.add(new Chunk("答案是:"+(bq.getAnswer().equals("T")?"正确":"错误"),fontCn));
88+
89+
Chunk ck=new Chunk(bq.getKnowledgePoint().substring(0, bq.getKnowledgePoint().indexOf('*')),fontCn2);
90+
ck.setBackground(BaseColor.ORANGE, 1f,2f,2f,1f);
91+
ck.setTextRise(12.5f);
92+
doc.add(ck);
93+
94+
doc.add(Chunk.NEWLINE);
95+
doc.add(Chunk.NEWLINE);
96+
}
97+
98+
public static void addBlankFillingQuestionAndAnswer(Document doc, BankBlankFillingQuestion bq) throws Exception{
99+
100+
BaseFont bfChinese = BaseFont.createFont("C:/WINDOWS/Fonts/SIMKAI.TTF", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
101+
Font fontCn = new Font(bfChinese, 20, Font.NORMAL);
102+
Font fontCn2 = new Font(bfChinese, 12, Font.NORMAL);
103+
Font fontEn = new Font(Font.FontFamily.TIMES_ROMAN,19,Font.NORMAL);
104+
105+
addParagraphForChineseAndEnglish(bq.getId()+"."+bq.getContent(),doc,fontCn,fontEn);
106+
addChunkForChineseAndEnglish("答案是:"+bq.getAnswer(),doc,fontCn,fontEn);
107+
108+
Chunk ck=new Chunk(bq.getKnowledgePoint().substring(0, bq.getKnowledgePoint().indexOf('*')),fontCn2);
109+
ck.setBackground(BaseColor.ORANGE, 1f,2f,2f,1f);
110+
ck.setTextRise(12.5f);
111+
doc.add(ck);
112+
113+
doc.add(Chunk.NEWLINE);
114+
doc.add(Chunk.NEWLINE);
115+
}
116+
117+
public static void addChunkForChineseAndEnglish(String str, Document doc, Font fontCn, Font fontEn) throws DocumentException{
118+
StringBuilder sb = new StringBuilder();
119+
char[] chars = str.toCharArray();
120+
for(int i=0; i<chars.length; i++){
121+
if(i==0){
122+
sb.append(chars[i]);
123+
}else{
124+
if(isChinese(chars[i]) && !isChinese(chars[i-1])){
125+
doc.add(new Chunk(sb.toString(),fontEn));
126+
sb = new StringBuilder();
127+
sb.append(chars[i]);
128+
}else if(!isChinese(chars[i]) && isChinese(chars[i-1])){
129+
doc.add(new Chunk(sb.toString(),fontCn));
130+
sb = new StringBuilder();
131+
sb.append(chars[i]);
132+
}else{
133+
sb.append(chars[i]);
134+
}
135+
}
136+
137+
if(i==chars.length-1){
138+
if(isChinese(chars[i])){
139+
doc.add(new Chunk(sb.toString(),fontCn));
140+
}else{
141+
doc.add(new Chunk(sb.toString(),fontEn));
142+
}
143+
}
144+
}
145+
146+
}
147+
148+
public static void addParagraphForChineseAndEnglish(String str, Document doc, Font fontCn, Font fontEn) throws DocumentException{
149+
StringBuilder sb = new StringBuilder();
150+
Paragraph para = new Paragraph();
151+
char[] chars = str.toCharArray();
152+
for(int i=0; i<chars.length; i++){
153+
if(i==0){
154+
sb.append(chars[i]);
155+
}else{
156+
if(isChinese(chars[i]) && !isChinese(chars[i-1])){
157+
para.add(new Chunk(sb.toString(),fontEn));
158+
sb = new StringBuilder();
159+
sb.append(chars[i]);
160+
}else if(!isChinese(chars[i]) && isChinese(chars[i-1])){
161+
para.add(new Chunk(sb.toString(),fontCn));
162+
sb = new StringBuilder();
163+
sb.append(chars[i]);
164+
}else{
165+
sb.append(chars[i]);
166+
}
167+
}
168+
169+
if(i==chars.length-1){
170+
if(isChinese(chars[i])){
171+
para.add(new Chunk(sb.toString(),fontCn));
172+
}else{
173+
para.add(new Chunk(sb.toString(),fontEn));
174+
}
175+
}
176+
}
177+
para.setLeading(25f);
178+
doc.add(para);
179+
}
180+
181+
private static final boolean isChinese(char c) {
182+
Character.UnicodeBlock ub = Character.UnicodeBlock.of(c);
183+
if (ub == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS
184+
|| ub == Character.UnicodeBlock.CJK_COMPATIBILITY_IDEOGRAPHS
185+
|| ub == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS_EXTENSION_A
186+
|| ub == Character.UnicodeBlock.GENERAL_PUNCTUATION
187+
|| ub == Character.UnicodeBlock.CJK_SYMBOLS_AND_PUNCTUATION
188+
|| ub == Character.UnicodeBlock.HALFWIDTH_AND_FULLWIDTH_FORMS) {
189+
return true;
190+
}
191+
return false;
192+
}
193+
194+
}

src/main/java/cn/lynu/lyq/java_exam/utils/PropertyUtils.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import java.util.Date;
1313
import java.util.Properties;
1414

15-
import org.jfree.util.Log;
1615
import org.slf4j.Logger;
1716
import org.slf4j.LoggerFactory;
1817

@@ -43,7 +42,7 @@ public static void setProperty(String key, String value){
4342
is = new FileInputStream(propFile);
4443
prop.load(is);
4544

46-
Log.debug(prop.keySet());
45+
logger.debug(prop.keySet().toString());
4746
prop.setProperty(key, value);
4847
os = new FileOutputStream(propFile);
4948
prop.store(os, "modified at "+ new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
@@ -64,7 +63,7 @@ public static void main(String[] args) throws IOException, URISyntaxException {
6463
// prop.list(System.out);
6564

6665
String test1 = getProperty("lyqtest1");
67-
System.out.println(test1);
66+
logger.debug(test1);
6867
setProperty("lyqtest1","bbbbb");
6968

7069
}

src/main/resources/import/examdb20180615.sql

Lines changed: 276 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
exam.scheduledTime.default=6000
2-
exam.detail.allowed=true
2+
exam.detail.allowed=false
33
exam.timeout.autosubmit=true
6.8 KB
Loading
6.83 KB
Loading
9.56 KB
Loading
10.2 KB
Loading
12.8 KB
Loading

0 commit comments

Comments
 (0)