Browse Source

--资源导入功能;

zzy.zhiyuan.foxmail 7 years ago
parent
commit
051bc483a1

+ 22 - 0
src/main/java/com/ekexiu/portal/dao/ResourceTmpLogDao.java

@ -0,0 +1,22 @@
1
package com.ekexiu.portal.dao;
2

3
import java.sql.Connection;
4
import java.sql.SQLException;
5
import java.util.List;
6

7
import org.jfw.apt.orm.annotation.dao.DAO;
8
import org.jfw.apt.orm.annotation.dao.method.OrderBy;
9
import org.jfw.apt.orm.annotation.dao.method.operator.Insert;
10
import org.jfw.apt.orm.annotation.dao.method.operator.LimitSelect;
11

12
import com.ekexiu.portal.po.ResourceTmpLog;
13

14
@DAO
15
public abstract class ResourceTmpLogDao {
16
	@Insert
17
	public abstract int insert(Connection con,ResourceTmpLog log)throws SQLException;
18
	
19
	@LimitSelect
20
	@OrderBy("ORDER BY CREATE_TIME")
21
	public abstract List<ResourceTmpLog> query(Connection con,String ownerId,String resourceTmpId,int rows)throws SQLException;
22
}

+ 54 - 0
src/main/java/com/ekexiu/portal/po/ResourceTmpLog.java

@ -0,0 +1,54 @@
1
package com.ekexiu.portal.po;
2

3
import org.jfw.apt.orm.annotation.entry.Column;
4
import org.jfw.apt.orm.annotation.entry.Table;
5
import org.jfw.apt.orm.annotation.entry.Unique;
6
import org.jfw.apt.orm.annotation.entry.Uniques;
7
import org.jfw.apt.orm.core.enums.DE;
8

9
import com.ekexiu.portal.basepo.CreateTimeSupported;
10

11
@Table
12
@Uniques(@Unique(clolumns = { "resourceId", "resourceTmpId" }, name = "RESOURCE_TMP_LOG_UQ"))
13
public class ResourceTmpLog implements CreateTimeSupported {
14
	private String ownerId;
15
	private String resourceId;
16
	private String resourceTmpId;
17
	private String createTime;
18

19
	@Column(DE.id_32)
20
	public String getOwnerId() {
21
		return ownerId;
22
	}
23

24
	public void setOwnerId(String ownerId) {
25
		this.ownerId = ownerId;
26
	}
27

28
	@Column(DE.id_32)
29
	public String getResourceId() {
30
		return resourceId;
31
	}
32

33
	public void setResourceId(String resourceId) {
34
		this.resourceId = resourceId;
35
	}
36

37
	@Column(DE.id_32)
38
	public String getResourceTmpId() {
39
		return resourceTmpId;
40
	}
41

42
	public void setResourceTmpId(String resourceTmpId) {
43
		this.resourceTmpId = resourceTmpId;
44
	}
45

46
	public String getCreateTime() {
47
		return createTime;
48
	}
49

50
	public void setCreateTime(String createTime) {
51
		this.createTime = createTime;
52
	}
53

54
}

+ 32 - 1
src/main/java/com/ekexiu/portal/service/ResourceService.java

@ -29,12 +29,14 @@ import com.ekexiu.portal.dao.OrgDao;
29 29
import com.ekexiu.portal.dao.OrgResStaffDao;
30 30
import com.ekexiu.portal.dao.ProfessorDao;
31 31
import com.ekexiu.portal.dao.ResourceDao;
32
import com.ekexiu.portal.dao.ResourceTmpLogDao;
32 33
import com.ekexiu.portal.dao.WatchDao;
33 34
import com.ekexiu.portal.po.ArticleRes;
34 35
import com.ekexiu.portal.po.Image;
35 36
import com.ekexiu.portal.po.Operation;
36 37
import com.ekexiu.portal.po.OrgResStaff;
37 38
import com.ekexiu.portal.po.Resource;
39
import com.ekexiu.portal.po.ResourceTmpLog;
38 40
import com.ekexiu.portal.pojo.EditOrganization;
39 41
import com.ekexiu.portal.pojo.EditProfessor;
40 42

@ -65,6 +67,8 @@ public class ResourceService {
65 67
	private OrgResStaffDao orgResStaffDao;
66 68
	@Autowrie
67 69
	private OrgDao orgDao;
70
	@Autowrie
71
	private ResourceTmpLogDao resourceTmpLogDao;
68 72

69 73
	public String getTimeFormat() {
70 74
		return timeFormat;
@ -170,6 +174,14 @@ public class ResourceService {
170 174
		this.orgDao = orgDao;
171 175
	}
172 176

177
	public ResourceTmpLogDao getResourceTmpLogDao() {
178
		return resourceTmpLogDao;
179
	}
180

181
	public void setResourceTmpLogDao(ResourceTmpLogDao resourceTmpLogDao) {
182
		this.resourceTmpLogDao = resourceTmpLogDao;
183
	}
184

173 185
	private String publishTime(){
174 186
		SimpleDateFormat df = new SimpleDateFormat(this.timeFormat);
175 187
		String publishTime = df.format(new Date());
@ -192,17 +204,26 @@ public class ResourceService {
192 204
	
193 205
	@Post
194 206
	@Path("/importRes")
195
	public String importRes(@JdbcConn Connection con,Resource resource,@Nullable String imgSrc)throws SQLException{
207
	public String importRes(@JdbcConn(true) Connection con,Resource resource,String resourceTmpId,@Nullable String imgSrc)throws SQLException, JfwBaseException{
196 208
		String resourceId = StringUtil.buildUUID();
197 209
		resource.setResourceId(resourceId);
198 210
		resource.setStatus("1");
211
		resource.setPublishTime(this.publishTime());
199 212
		resource.setPageViews(0);
213
		ResourceTmpLog log = new ResourceTmpLog();
214
		log.setResourceId(resourceId);
215
		log.setResourceTmpId(resourceTmpId);
200 216
		if(resource.getProfessorId() != null){
201 217
			resource.setResourceType("1");
218
			log.setOwnerId(resource.getProfessorId());
202 219
		}else if(resource.getOrgId() != null){
203 220
			resource.setResourceType("2");
221
			log.setOwnerId(resource.getOrgId());
222
		}else{
223
			throw new JfwBaseException(-1, "bad parameter:ownerId");
204 224
		}
205 225
		this.resourceDao.insert(con, resource);
226
		this.resourceTmpLogDao.insert(con, log);
206 227
		if(imgSrc != null){
207 228
			Image image = new Image();
208 229
			image.setImageId(StringUtil.buildUUID());
@ -214,6 +235,16 @@ public class ResourceService {
214 235
		return resourceId;
215 236
	}
216 237
	
238
	@Get
239
	@Path("/isImportRes")
240
	public boolean isImportRes(@JdbcConn Connection con,String id,String resourceTmpId,@DefaultValue("1") int rows)throws SQLException{
241
		List<ResourceTmpLog> logs = this.resourceTmpLogDao.query(con, id, resourceTmpId, rows);
242
		if(logs.isEmpty()){
243
			return false;
244
		}
245
		return true;
246
	}
247
	
217 248
	@Post
218 249
	@Path("/save")
219 250
	public String save(@JdbcConn(true) Connection con, Resource resource, @Nullable String[] fns, @Nullable String[] imageIds)