Sfoglia il codice sorgente

--update Article.class and Article config.

zzy.zhiyuan.foxmail 8 anni fa
parent
commit
c13e373418

+ 7 - 1
src/main/java/com/ekexiu/portal/dao/ArticleDao.java

@ -4,12 +4,14 @@ import java.sql.Connection;
4 4
import java.sql.SQLException;
5 5
import java.util.List;
6 6

7
import org.jfw.apt.annotation.Nullable;
7 8
import org.jfw.apt.orm.annotation.dao.DAO;
8 9
import org.jfw.apt.orm.annotation.dao.method.From;
9 10
import org.jfw.apt.orm.annotation.dao.method.OrderBy;
10 11
import org.jfw.apt.orm.annotation.dao.method.operator.DeleteWith;
11 12
import org.jfw.apt.orm.annotation.dao.method.operator.Insert;
12 13
import org.jfw.apt.orm.annotation.dao.method.operator.SelectList;
14
import org.jfw.apt.orm.annotation.dao.method.operator.SelectOne;
13 15
import org.jfw.apt.orm.annotation.dao.method.operator.Update;
14 16
import org.jfw.apt.orm.annotation.dao.method.operator.UpdateWith;
15 17
import org.jfw.apt.orm.annotation.dao.param.Set;
@ -41,7 +43,11 @@ public abstract class ArticleDao {
41 43
	public abstract int deletePro(Connection con, String professorId) throws SQLException;
42 44
	
43 45
	@SelectList
44
	@OrderBy(" ORDER BY CREATE_TIME DESC ")
46
	@OrderBy(" ORDER BY MODIFY_TIME DESC ")
45 47
	public abstract List<Article> queryPro(Connection con, String professorId) throws SQLException;
48
	
49
	@SelectOne
50
	@Nullable
51
	public abstract Article queryOne(Connection con, String articleId) throws SQLException;
46 52

47 53
}

+ 8 - 0
src/main/java/com/ekexiu/portal/po/Article.java

@ -7,6 +7,7 @@ import org.jfw.apt.orm.core.enums.DE;
7 7

8 8
import com.ekexiu.portal.basepo.CreateTimeSupported;
9 9
import com.ekexiu.portal.basepo.ModifyTimeSupported;
10
import com.ekexiu.portal.pojo.EditProfessor;
10 11

11 12
@Table
12 13
@PrimaryKey("articleId")
@ -20,6 +21,7 @@ public class Article implements CreateTimeSupported, ModifyTimeSupported {
20 21
	private String createTime;
21 22
	private String modifyTime;
22 23
	private String articleImg;
24
	private EditProfessor professor;
23 25
	
24 26
	@Column(DE.id_32)
25 27
	public String getArticleId() {
@ -82,5 +84,11 @@ public class Article implements CreateTimeSupported, ModifyTimeSupported {
82 84
	public void setArticleImg(String articleImg) {
83 85
		this.articleImg = articleImg;
84 86
	}
87
	public EditProfessor getProfessor() {
88
		return professor;
89
	}
90
	public void setProfessor(EditProfessor professor) {
91
		this.professor = professor;
92
	}
85 93

86 94
}

+ 61 - 31
src/main/java/com/ekexiu/portal/service/ArticleService.java

@ -14,29 +14,42 @@ import java.util.Date;
14 14
import java.util.List;
15 15

16 16
import org.jfw.apt.annotation.Autowrie;
17
import org.jfw.apt.annotation.Nullable;
18 17
import org.jfw.apt.web.annotation.Path;
19
import org.jfw.apt.web.annotation.operate.Delete;
20 18
import org.jfw.apt.web.annotation.operate.Get;
21 19
import org.jfw.apt.web.annotation.operate.Post;
22 20
import org.jfw.apt.web.annotation.param.JdbcConn;
23
import org.jfw.apt.web.annotation.param.PathVar;
24 21
import org.jfw.util.JpgUtil;
25 22
import org.jfw.util.StringUtil;
26 23
import org.jfw.util.exception.JfwBaseException;
27 24
import org.jfw.util.io.IoUtil;
28 25

29 26
import com.ekexiu.portal.dao.ArticleDao;
27
import com.ekexiu.portal.dao.ProfessorDao;
28
import com.ekexiu.portal.dao.ResourceDao;
30 29
import com.ekexiu.portal.po.Article;
30
import com.ekexiu.portal.pojo.EditProfessor;
31 31

32 32
@Path("/article")
33 33
public class ArticleService {
34 34
	private File tmpPath;
35 35
	private File articlePath;
36
	private String dateFormat = "yyyyMMdd";
36 37
	private int artMaxLen=640;
37 38
	private static final String JPG = "jpg";
38 39
	@Autowrie
39 40
	private ArticleDao articleDao;
41
	@Autowrie
42
	private ProfessorDao professorDao;
43
	@Autowrie
44
	private ResourceDao resourceDao;
45

46
	public String getDateFormat() {
47
		return dateFormat;
48
	}
49

50
	public void setDateFormat(String dateFormat) {
51
		this.dateFormat = dateFormat;
52
	}
40 53

41 54
	public File getTmpPath() {
42 55
		return tmpPath;
@ -70,6 +83,22 @@ public class ArticleService {
70 83
		this.articleDao = articleDao;
71 84
	}
72 85
	
86
	public ProfessorDao getProfessorDao() {
87
		return professorDao;
88
	}
89

90
	public void setProfessorDao(ProfessorDao professorDao) {
91
		this.professorDao = professorDao;
92
	}
93

94
	public ResourceDao getResourceDao() {
95
		return resourceDao;
96
	}
97

98
	public void setResourceDao(ResourceDao resourceDao) {
99
		this.resourceDao = resourceDao;
100
	}
101

73 102
	private byte[] resImage(byte[] src, int maxLen) throws IOException {
74 103
		ByteArrayInputStream in = new ByteArrayInputStream(src);
75 104
		ByteArrayOutputStream out = new ByteArrayOutputStream();
@ -96,21 +125,20 @@ public class ArticleService {
96 125
		byte[] src = this.readTmpFile(fn);
97 126
		src = JpgUtil.read(src);
98 127
		byte[] shareResImage = this.resImage(src, this.artMaxLen);
99
		File savePath = this.createDate(this.articlePath);
100
		IoUtil.saveStream(new FileOutputStream(new File(savePath, id + "." + JPG)), src, true);
101
		IoUtil.saveStream(new FileOutputStream(new File(savePath, id + "_s." + JPG)), shareResImage, true);
102
	}
103
	
104
	private File createDate(File path){
105
		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-DD");
106
		String date = df.format(new Date());
107
		String datePath = path + "/" +  date;
108
		File dateFile = new File(datePath);
128
		String savePath = this.articlePath + "/" + this.createDate();
129
		File dateFile = new File(savePath);
109 130
		if (!dateFile.exists()) {
110 131
			// 创建日期目录
111 132
			dateFile.mkdir();
112 133
		}
113
		return dateFile;
134
		IoUtil.saveStream(new FileOutputStream(new File(dateFile, id + "." + JPG)), src, true);
135
		IoUtil.saveStream(new FileOutputStream(new File(dateFile, id + "_s." + JPG)), shareResImage, true);
136
	}
137
	
138
	private String createDate(){
139
		SimpleDateFormat df = new SimpleDateFormat(this.dateFormat);
140
		String date = df.format(new Date());
141
		return date;
114 142
	}
115 143
	
116 144
	@Post
@ -120,7 +148,7 @@ public class ArticleService {
120 148
		String articleId = StringUtil.buildUUID();
121 149
		if(article.getArticleImg() != null){
122 150
			this.saveArtImg(article.getArticleImg(), articleId);
123
			article.setArticleImg(this.createDate(this.articlePath)+"/"+articleId+"."+JPG);
151
			article.setArticleImg(this.createDate()+"/"+articleId+"."+JPG);
124 152
		}
125 153
		article.setArticleId(articleId);
126 154
		this.articleDao.insert(con, article);
@ -133,32 +161,34 @@ public class ArticleService {
133 161
			throws SQLException, JfwBaseException, IOException{
134 162
		if(article.getArticleImg() != null){
135 163
			this.saveArtImg(article.getArticleImg(), article.getArticleId());
136
			article.setArticleImg(this.createDate(this.articlePath)+"/"+article.getArticleId()+"."+JPG);
164
			article.setArticleImg(this.createDate()+"/"+article.getArticleId()+"."+JPG);
137 165
		}
138 166
		this.articleDao.update(con, article);
139 167
	}
140 168
	
141
	@Post
142
	@Path("/subject")
143
	public void updateSubject(@JdbcConn(true) Connection con, @Nullable String subject, String articleId) throws SQLException{
144
		this.articleDao.updateSubject(con, subject, articleId);
145
	}
146
	
147
	@Post
148
	@Path("/industry")
149
	public void updateIndustry(@JdbcConn(true) Connection con, @Nullable String industry, String articleId) throws SQLException{
150
		this.articleDao.updateIndustry(con, industry, articleId);
151
	}
152
	
153 169
	@Get
154 170
	@Path("/qaPro")
155 171
	public List<Article> queryPro(@JdbcConn Connection con, String professorId) throws SQLException{
156 172
		return this.articleDao.queryPro(con, professorId);
157 173
	}
158 174
	
159
	@Delete
160
	@Path("/{articleId}")
161
	public void delete(@JdbcConn(true) Connection con, @PathVar String articleId) throws SQLException{
175
	@Get
176
	@Path("/query")
177
	public Article queryOne(@JdbcConn Connection con, String articleId) throws SQLException{
178
		Article article = this.articleDao.queryOne(con, articleId);
179
		if(article != null){
180
			EditProfessor professor = this.professorDao.queryBaseInfo(con, article.getProfessorId());
181
			if(professor != null){
182
				professor.setResources(this.resourceDao.queryPro(con, professor.getId()));
183
			}
184
			article.setProfessor(professor);
185
		}
186
		return article;
187
	}
188
	
189
	@Post
190
	@Path("/delete")
191
	public void delete(@JdbcConn(true) Connection con, String articleId) throws SQLException{
162 192
		this.articleDao.delete(con, articleId);
163 193
	}
164 194


+ 2 - 1
src/main/resources/project-test.properties

@ -117,7 +117,8 @@ com_ekexiu_portal_service_ImagesService.resourcePath::java.io.File=/kexiu/www/ht
117 117
#科研文章图片上传临时目录
118 118
com_ekexiu_portal_service_ArticleService.tmpPath::java.io.File=/kexiu/www/html/images/tmp
119 119
#科研文章图片保存目录
120
com_ekexiu_portal_service_ArticleService.articlePath::java.io.File=/kexiu/www/html/images/article
120
com_ekexiu_portal_service_ArticleService.articlePath::java.io.File=/kexiu/webdata/data/article
121
com_ekexiu_portal_service_ArticleService.dateFormat::java.lang.String=yyyyMMdd
121 122
#科研文章图片尺寸
122 123
com_ekexiu_portal_service_ArticleService.artMaxLen::int=640
123 124
#资源分享图片尺寸

+ 2 - 1
src/main/resources/project.properties

@ -117,7 +117,8 @@ com_ekexiu_portal_service_ImagesService.resourcePath::java.io.File=/kexiu/www/ht
117 117
#科研文章图片上传临时目录
118 118
com_ekexiu_portal_service_ArticleService.tmpPath::java.io.File=/kexiu/www/html/images/tmp
119 119
#科研文章图片保存目录
120
com_ekexiu_portal_service_ArticleService.articlePath::java.io.File=/kexiu/www/html/images/article
120
com_ekexiu_portal_service_ArticleService.articlePath::java.io.File=/kexiu/webdata/data/article
121
com_ekexiu_portal_service_ArticleService.dateFormat::java.lang.String=yyyyMMdd
121 122
#科研文章图片尺寸
122 123
com_ekexiu_portal_service_ArticleService.artMaxLen::int=640
123 124
#资源分享图片尺寸