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
import java.sql.SQLException;
4
import java.sql.SQLException;
5
import java.util.List;
5
import java.util.List;
6

6

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

7

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

11

11
@Table
12
@Table
12
@PrimaryKey("articleId")
13
@PrimaryKey("articleId")
20
	private String createTime;
21
	private String createTime;
21
	private String modifyTime;
22
	private String modifyTime;
22
	private String articleImg;
23
	private String articleImg;
24
	private EditProfessor professor;
23
	
25
	
24
	@Column(DE.id_32)
26
	@Column(DE.id_32)
25
	public String getArticleId() {
27
	public String getArticleId() {
82
	public void setArticleImg(String articleImg) {
84
	public void setArticleImg(String articleImg) {
83
		this.articleImg = articleImg;
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
import java.util.List;
14
import java.util.List;
15

15

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

25

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

31

32
@Path("/article")
32
@Path("/article")
33
public class ArticleService {
33
public class ArticleService {
34
	private File tmpPath;
34
	private File tmpPath;
35
	private File articlePath;
35
	private File articlePath;
36
	private String dateFormat = "yyyyMMdd";
36
	private int artMaxLen=640;
37
	private int artMaxLen=640;
37
	private static final String JPG = "jpg";
38
	private static final String JPG = "jpg";
38
	@Autowrie
39
	@Autowrie
39
	private ArticleDao articleDao;
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
	public File getTmpPath() {
54
	public File getTmpPath() {
42
		return tmpPath;
55
		return tmpPath;
70
		this.articleDao = articleDao;
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
	private byte[] resImage(byte[] src, int maxLen) throws IOException {
102
	private byte[] resImage(byte[] src, int maxLen) throws IOException {
74
		ByteArrayInputStream in = new ByteArrayInputStream(src);
103
		ByteArrayInputStream in = new ByteArrayInputStream(src);
75
		ByteArrayOutputStream out = new ByteArrayOutputStream();
104
		ByteArrayOutputStream out = new ByteArrayOutputStream();
96
		byte[] src = this.readTmpFile(fn);
125
		byte[] src = this.readTmpFile(fn);
97
		src = JpgUtil.read(src);
126
		src = JpgUtil.read(src);
98
		byte[] shareResImage = this.resImage(src, this.artMaxLen);
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
		if (!dateFile.exists()) {
130
		if (!dateFile.exists()) {
110
			// 创建日期目录
131
			// 创建日期目录
111
			dateFile.mkdir();
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
	@Post
144
	@Post
120
		String articleId = StringUtil.buildUUID();
148
		String articleId = StringUtil.buildUUID();
121
		if(article.getArticleImg() != null){
149
		if(article.getArticleImg() != null){
122
			this.saveArtImg(article.getArticleImg(), articleId);
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
		article.setArticleId(articleId);
153
		article.setArticleId(articleId);
126
		this.articleDao.insert(con, article);
154
		this.articleDao.insert(con, article);
133
			throws SQLException, JfwBaseException, IOException{
161
			throws SQLException, JfwBaseException, IOException{
134
		if(article.getArticleImg() != null){
162
		if(article.getArticleImg() != null){
135
			this.saveArtImg(article.getArticleImg(), article.getArticleId());
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
		this.articleDao.update(con, article);
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
	@Get
169
	@Get
154
	@Path("/qaPro")
170
	@Path("/qaPro")
155
	public List<Article> queryPro(@JdbcConn Connection con, String professorId) throws SQLException{
171
	public List<Article> queryPro(@JdbcConn Connection con, String professorId) throws SQLException{
156
		return this.articleDao.queryPro(con, professorId);
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
		this.articleDao.delete(con, articleId);
192
		this.articleDao.delete(con, articleId);
163
	}
193
	}
164

194


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

117
#科研文章图片上传临时目录
117
#科研文章图片上传临时目录
118
com_ekexiu_portal_service_ArticleService.tmpPath::java.io.File=/kexiu/www/html/images/tmp
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
com_ekexiu_portal_service_ArticleService.artMaxLen::int=640
123
com_ekexiu_portal_service_ArticleService.artMaxLen::int=640
123
#资源分享图片尺寸
124
#资源分享图片尺寸

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

117
#科研文章图片上传临时目录
117
#科研文章图片上传临时目录
118
com_ekexiu_portal_service_ArticleService.tmpPath::java.io.File=/kexiu/www/html/images/tmp
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
com_ekexiu_portal_service_ArticleService.artMaxLen::int=640
123
com_ekexiu_portal_service_ArticleService.artMaxLen::int=640
123
#资源分享图片尺寸
124
#资源分享图片尺寸