|
@ -1,36 +1,46 @@
|
1
|
1
|
package com.ekexiu.portal.question;
|
2
|
2
|
|
3
|
|
import com.ekexiu.portal.notify.NotifyService;
|
4
|
|
import com.ekexiu.portal.notify.NotifyType;
|
5
|
|
import com.ekexiu.portal.util.SqlUtil;
|
|
3
|
import java.io.ByteArrayInputStream;
|
|
4
|
import java.io.File;
|
|
5
|
import java.io.FileInputStream;
|
|
6
|
import java.io.FileOutputStream;
|
|
7
|
import java.io.IOException;
|
|
8
|
import java.io.InputStream;
|
|
9
|
import java.io.OutputStream;
|
|
10
|
import java.sql.Connection;
|
|
11
|
import java.sql.PreparedStatement;
|
|
12
|
import java.sql.SQLException;
|
|
13
|
import java.util.ArrayList;
|
|
14
|
import java.util.LinkedList;
|
|
15
|
import java.util.List;
|
|
16
|
import java.util.Map;
|
|
17
|
import java.util.concurrent.atomic.AtomicInteger;
|
|
18
|
|
6
|
19
|
import org.jfw.apt.annotation.Autowrie;
|
7
|
20
|
import org.jfw.apt.annotation.DefaultValue;
|
8
|
21
|
import org.jfw.apt.annotation.Nullable;
|
9
|
22
|
import org.jfw.apt.web.annotation.Path;
|
10
|
23
|
import org.jfw.apt.web.annotation.operate.Get;
|
11
|
24
|
import org.jfw.apt.web.annotation.operate.Post;
|
12
|
|
import org.jfw.apt.web.annotation.param.*;
|
|
25
|
import org.jfw.apt.web.annotation.param.AfterCommit;
|
|
26
|
import org.jfw.apt.web.annotation.param.FieldParam;
|
|
27
|
import org.jfw.apt.web.annotation.param.JdbcConn;
|
|
28
|
import org.jfw.apt.web.annotation.param.RequestParam;
|
|
29
|
import org.jfw.apt.web.annotation.param.Upload;
|
13
|
30
|
import org.jfw.util.DateUtil;
|
|
31
|
import org.jfw.util.JpgUtil;
|
14
|
32
|
import org.jfw.util.ListUtil;
|
15
|
33
|
import org.jfw.util.StringUtil;
|
16
|
34
|
import org.jfw.util.exception.JfwBaseException;
|
|
35
|
import org.jfw.util.io.IoUtil;
|
17
|
36
|
import org.jfw.util.jdbc.JdbcUtil;
|
18
|
37
|
import org.jfw.util.jdbc.PreparedStatementConfig;
|
19
|
38
|
import org.jfw.util.web.fileupload.Item;
|
20
|
39
|
import org.jfw.util.web.fileupload.UploadItemIterator;
|
21
|
40
|
|
22
|
|
import java.io.File;
|
23
|
|
import java.io.FileOutputStream;
|
24
|
|
import java.io.InputStream;
|
25
|
|
import java.io.OutputStream;
|
26
|
|
import java.sql.Connection;
|
27
|
|
import java.sql.PreparedStatement;
|
28
|
|
import java.sql.SQLException;
|
29
|
|
import java.util.ArrayList;
|
30
|
|
import java.util.LinkedList;
|
31
|
|
import java.util.List;
|
32
|
|
import java.util.Map;
|
33
|
|
import java.util.concurrent.atomic.AtomicInteger;
|
|
41
|
import com.ekexiu.portal.notify.NotifyService;
|
|
42
|
import com.ekexiu.portal.notify.NotifyType;
|
|
43
|
import com.ekexiu.portal.util.SqlUtil;
|
34
|
44
|
|
35
|
45
|
@Path("/question")
|
36
|
46
|
public class Service {
|
|
@ -45,6 +55,16 @@ public class Service {
|
45
|
55
|
|
46
|
56
|
private File imgPath;
|
47
|
57
|
|
|
58
|
private int imgMaxWidth = 70;
|
|
59
|
|
|
60
|
public int getImgMaxWidth() {
|
|
61
|
return imgMaxWidth;
|
|
62
|
}
|
|
63
|
|
|
64
|
public void setImgMaxWidth(int imgMaxWidth) {
|
|
65
|
this.imgMaxWidth = imgMaxWidth;
|
|
66
|
}
|
|
67
|
|
48
|
68
|
public NotifyService getNotifyService() {
|
49
|
69
|
return notifyService;
|
50
|
70
|
}
|
|
@ -124,6 +144,39 @@ public class Service {
|
124
|
144
|
}
|
125
|
145
|
}
|
126
|
146
|
|
|
147
|
private void saveSmallImg(String imgs) throws IOException {
|
|
148
|
if (imgs != null) {
|
|
149
|
List<String> list = ListUtil.splitTrimExcludeEmpty(imgs, ',');
|
|
150
|
if (list.size() > 0) {
|
|
151
|
String oname = list.get(0);
|
|
152
|
if (oname != null) {
|
|
153
|
if (oname.startsWith("/")) {
|
|
154
|
oname = oname.substring(1);
|
|
155
|
int idx = oname.indexOf('.');
|
|
156
|
if (idx > 0) {
|
|
157
|
String dname = oname.substring(0, idx) + "_s.jpg";
|
|
158
|
File dest = new File(this.imgPath, dname);
|
|
159
|
if (dest.exists())
|
|
160
|
return;
|
|
161
|
File src = new File(this.imgPath, oname);
|
|
162
|
if (src.exists()) {
|
|
163
|
byte[] obs = IoUtil.readStream(new FileInputStream(src), true);
|
|
164
|
obs = JpgUtil.read(obs);
|
|
165
|
FileOutputStream out = new FileOutputStream(dest);
|
|
166
|
try {
|
|
167
|
JpgUtil.scalingZoom(new ByteArrayInputStream(obs), out, this.imgMaxWidth);
|
|
168
|
out.flush();
|
|
169
|
} finally {
|
|
170
|
IoUtil.close(out);
|
|
171
|
}
|
|
172
|
}
|
|
173
|
}
|
|
174
|
}
|
|
175
|
}
|
|
176
|
}
|
|
177
|
}
|
|
178
|
}
|
|
179
|
|
127
|
180
|
/**
|
128
|
181
|
* 新增一提问
|
129
|
182
|
*
|
|
@ -132,6 +185,7 @@ public class Service {
|
132
|
185
|
* title 标题 ,cnt 描述 img 图片 以英文逗号分隔, keys 关键字 以英文逗号分隔 ,uid 用户ID
|
133
|
186
|
* @return
|
134
|
187
|
* @throws SQLException
|
|
188
|
* @throws IOException
|
135
|
189
|
*/
|
136
|
190
|
@Path()
|
137
|
191
|
@Post
|
|
@ -140,7 +194,7 @@ public class Service {
|
140
|
194
|
@FieldParam(value = "cnt", valueClass = String.class, required = false),
|
141
|
195
|
@FieldParam(value = "img", valueClass = String.class, required = false), @FieldParam(value = "keys", valueClass = String.class),
|
142
|
196
|
@FieldParam(value = "uid", valueClass = String.class) }) Question q)
|
143
|
|
throws SQLException {
|
|
197
|
throws SQLException, IOException {
|
144
|
198
|
String id = StringUtil.buildUUID();
|
145
|
199
|
q.setId(id);
|
146
|
200
|
q.setReplyCount(0);
|
|
@ -152,6 +206,7 @@ public class Service {
|
152
|
206
|
List<String> kws = ListUtil.splitTrimExcludeEmpty(q.getKeys(), ',');
|
153
|
207
|
if (kws.isEmpty())
|
154
|
208
|
throw new IllegalArgumentException("param keys invalid");
|
|
209
|
this.saveSmallImg(q.getImg());
|
155
|
210
|
questionDao.insert(con, q);
|
156
|
211
|
questionDao.insert(con, build(id, kws));
|
157
|
212
|
return id;
|
|
@ -297,10 +352,10 @@ public class Service {
|
297
|
352
|
|
298
|
353
|
@Get
|
299
|
354
|
@Path("/answer")
|
300
|
|
public Answer answer(@JdbcConn Connection con,@Nullable String id,@Nullable String uid, @Nullable String qid) throws SQLException {
|
301
|
|
if(id!=null){
|
|
355
|
public Answer answer(@JdbcConn Connection con, @Nullable String id, @Nullable String uid, @Nullable String qid) throws SQLException {
|
|
356
|
if (id != null) {
|
302
|
357
|
return questionDao.queryAnswer(con, id);
|
303
|
|
}else if(qid!=null && uid !=null){
|
|
358
|
} else if (qid != null && uid != null) {
|
304
|
359
|
return questionDao.answer(con, uid, qid);
|
305
|
360
|
}
|
306
|
361
|
return null;
|
|
@ -584,8 +639,8 @@ public class Service {
|
584
|
639
|
|
585
|
640
|
@Get
|
586
|
641
|
@Path("/answer/delete")
|
587
|
|
public int logicDelete(@JdbcConn(true) Connection con, String id,String qid) throws SQLException {
|
588
|
|
if (questionDao.logicDeleteAnswer(con, id,qid) > 0) {
|
|
642
|
public int logicDelete(@JdbcConn(true) Connection con, String id, String qid) throws SQLException {
|
|
643
|
if (questionDao.logicDeleteAnswer(con, id, qid) > 0) {
|
589
|
644
|
questionDao.decQuestionReply(con, qid);
|
590
|
645
|
return 1;
|
591
|
646
|
}
|