Quellcode durchsuchen

--首页资源搜索和文章搜索;

zzy.zhiyuan.foxmail vor 8 Jahren
Ursprung
Commit
6ba67c95f8

+ 147 - 0
src/main/java/com/ekexiu/portal/dao/ArticleDao.java

@ -383,6 +383,153 @@ public abstract class ArticleDao {
383 383
	@Where("STATUS = '1'")
384 384
	public abstract PageQueryResult<Article> queryPageForPublish(Connection con,@Like@Nullable String articleTitle,int pageSize,int pageNo) throws SQLException;
385 385
	
386
	public PageQueryResult<Article> firstPageQuery(Connection con,String key,int pageSize,int pageNo) throws SQLException{
387
        int total = 0;
388
        PageQueryResult<Article> queryResult = new PageQueryResult<Article>();
389
        int index = 1;
390
        boolean hasKey = null != key;
391
        StringBuilder sql = new StringBuilder();
392
        sql.append(" WHERE STATUS = '1'");
393
        if(hasKey){
394
            sql.append(" AND (PROFESSOR_ID IN (SELECT ID FROM PROFESSOR WHERE NAME LIKE ?)");
395
            sql.append(" OR ORG_ID IN (SELECT ID FROM ORGANIZATION WHERE NAME LIKE ? OR FOR_SHORT LIKE ?)");
396
            sql.append(" OR ARTICLE_TITLE LIKE ? OR SUBJECT LIKE ?)");
397
        }
398
        StringBuilder whereSql = sql;
399
        sql = new StringBuilder();
400
        sql.append("SELECT COUNT(1) FROM ARTICLE");
401
        sql.append(whereSql);
402
        PreparedStatement ps = con.prepareStatement(sql.toString());
403
        try{
404
            if(hasKey){
405
                ps.setString(index++,key);
406
                ps.setString(index++,key);
407
                ps.setString(index++,key);
408
                ps.setString(index++,key);
409
                ps.setString(index++,key);
410
            }
411
            queryResult.setPageSize(pageSize);
412
            ResultSet rs = ps.executeQuery();
413
            try{
414
                rs.next();
415
                total = rs.getInt(1);
416
            }finally{
417
                try{rs.close();}catch(Exception e1){}
418
            }
419
        }finally{
420
            try{ps.close();}catch(Exception e2){}
421
        }
422
        queryResult.setTotal(total);
423
        if(0== total){
424
            queryResult.setPageNo(1);
425
            queryResult.setData(Collections.<Article>emptyList());
426
            return queryResult;
427
        }
428
        index = 1;
429
        boolean firstPage = (1 == pageNo);
430
        if(firstPage){
431
            queryResult.setPageNo(1);
432
            sql = new StringBuilder();
433
            sql.append("SELECT ARTICLE_ID,PROFESSOR_ID,ARTICLE_TITLE,ARTICLE_CONTENT,SUBJECT,INDUSTRY,PUBLISH_TIME,ARTICLE_IMG,ORG_ID,ARTICLE_TYPE,ARTICLE_AGREE,PAGE_VIEWS,STATUS,CREATE_TIME,MODIFY_TIME FROM ARTICLE");
434
            sql.append(whereSql);
435
            sql.append(" ORDER BY PUBLISH_TIME DESC");
436
            sql.append(" LIMIT ").append(pageSize);
437
        }else{
438
            int pageNum = total / pageSize;
439
            if(total % pageSize != 0){
440
                ++pageNum;
441
            }
442
            if(pageNo > pageNum){
443
                pageNo = pageNum;
444
            }
445
            queryResult.setPageNo(pageNo);
446
            --pageNo;
447
            int offset = (pageNo * pageSize);
448
            sql = new StringBuilder();
449
            sql.append("SELECT ARTICLE_ID,PROFESSOR_ID,ARTICLE_TITLE,ARTICLE_CONTENT,SUBJECT,INDUSTRY,PUBLISH_TIME,ARTICLE_IMG,ORG_ID,ARTICLE_TYPE,ARTICLE_AGREE,PAGE_VIEWS,STATUS,CREATE_TIME,MODIFY_TIME FROM ARTICLE");
450
            sql.append(whereSql);
451
            sql.append(" ORDER BY PUBLISH_TIME DESC");
452
            sql.append(" LIMIT ").append(pageSize).append(" OFFSET ").append(offset);
453
        }
454
        ps = con.prepareStatement(sql.toString());
455
        try{
456
            if(hasKey){
457
                ps.setString(index++,key);
458
                ps.setString(index++,key);
459
                ps.setString(index++,key);
460
                ps.setString(index++,key);
461
                ps.setString(index++,key);
462
            }
463
            ResultSet rs = ps.executeQuery();
464
            try{
465
                List<Article> articles = new ArrayList<Article>();
466
                queryResult.setData(articles);
467
                int size = 0;
468
                while((size<pageSize) && rs.next()){
469
                    ++size;
470
                    Article article =  new Article();
471
                    article.setArticleId(rs.getString(1));
472
                    String professorId = rs.getString(2);
473
                    if(rs.wasNull()){
474
                    	professorId = null;
475
                    }
476
                    article.setProfessorId(professorId);
477
                    article.setArticleTitle(rs.getString(3));
478
                    String articleContent = rs.getString(4);
479
                    if(rs.wasNull()){
480
                    	articleContent = null;
481
                    }
482
                    article.setArticleContent(articleContent);
483
                    String subject = rs.getString(5);
484
                    if(rs.wasNull()){
485
                    	subject = null;
486
                    }
487
                    article.setSubject(subject);
488
                    String industry = rs.getString(6);
489
                    if(rs.wasNull()){
490
                    	industry = null;
491
                    }
492
                    article.setIndustry(industry);
493
                    String publishTime = rs.getString(7);
494
                    if(rs.wasNull()){
495
                    	publishTime = null;
496
                    }
497
                    article.setPublishTime(publishTime);
498
                    String articleImg = rs.getString(8);
499
                    if(rs.wasNull()){
500
                    	articleImg = null;
501
                    }
502
                    article.setArticleImg(articleImg);
503
                    String orgId = rs.getString(9);
504
                    if(rs.wasNull()){
505
                    	orgId = null;
506
                    }
507
                    article.setOrgId(orgId);
508
                    String articleType = rs.getString(10);
509
                    if(rs.wasNull()){
510
                    	articleType = null;
511
                    }
512
                    article.setArticleType(articleType);
513
                    article.setArticleAgree(rs.getInt(11));
514
                    article.setPageViews(rs.getInt(12));
515
                    String status = rs.getString(13);
516
                    if(rs.wasNull()){
517
                    	status = null;
518
                    }
519
                    article.setStatus(status);
520
                    article.setCreateTime(rs.getString(14));
521
                    article.setModifyTime(rs.getString(15));
522
                    articles.add(article);
523
                }
524
                return queryResult;
525
            }finally{
526
                try{rs.close();}catch(Exception e3){}
527
            }
528
        }finally{
529
            try{ps.close();}catch(Exception e4){}
530
        }
531
    }
532
	
386 533
	public PageQueryResult<Article> queryPageForSelf(Connection con,@Nullable String professorId,@Nullable String orgId,
387 534
			@Nullable String articleTitle,int pageSize,int pageNo) throws SQLException{
388 535
        int total = 0;

+ 156 - 0
src/main/java/com/ekexiu/portal/dao/ResourceDao.java

@ -1156,6 +1156,162 @@ public abstract class ResourceDao {
1156 1156
        }
1157 1157
    }
1158 1158
	
1159
	public PageQueryResult<Resource> firstPageQuery(Connection con,String key,int pageSize,int pageNo) throws SQLException{
1160
        int total = 0;
1161
        PageQueryResult<Resource> queryResult = new PageQueryResult<Resource>();
1162
        int index = 1;
1163
        boolean hasKey = null != key;
1164
        StringBuilder sql = new StringBuilder();
1165
        sql.append(" WHERE STATUS = '1'");
1166
        if(hasKey){
1167
            sql.append(" AND (PROFESSOR_ID IN (SELECT ID FROM PROFESSOR WHERE NAME LIKE ?)");
1168
            sql.append(" OR ORG_ID IN (SELECT ID FROM ORGANIZATION WHERE NAME LIKE ? OR FOR_SHORT LIKE ?)");
1169
            sql.append(" OR RESOURCE_NAME LIKE ? OR SUBJECT LIKE ? OR SUPPORTED_SERVICES LIKE ? OR ORG_NAME LIKE ? OR SPEC LIKE ?)");
1170
        }
1171
        StringBuilder whereSql = sql;
1172
        sql = new StringBuilder();
1173
        sql.append("SELECT COUNT(1) FROM RESOURCE");
1174
        sql.append(whereSql);
1175
        PreparedStatement ps = con.prepareStatement(sql.toString());
1176
        try{
1177
            if(hasKey){
1178
                ps.setString(index++,key);
1179
                ps.setString(index++,key);
1180
                ps.setString(index++,key);
1181
                ps.setString(index++,key);
1182
                ps.setString(index++,key);
1183
                ps.setString(index++,key);
1184
                ps.setString(index++,key);
1185
                ps.setString(index++,key);
1186
            }
1187
            queryResult.setPageSize(pageSize);
1188
            ResultSet rs = ps.executeQuery();
1189
            try{
1190
                rs.next();
1191
                total = rs.getInt(1);
1192
            }finally{
1193
                try{rs.close();}catch(Exception e1){}
1194
            }
1195
        }finally{
1196
            try{ps.close();}catch(Exception e2){}
1197
        }
1198
        queryResult.setTotal(total);
1199
        if(0== total){
1200
            queryResult.setPageNo(1);
1201
            queryResult.setData(Collections.<Resource>emptyList());
1202
            return queryResult;
1203
        }
1204
        index = 1;
1205
        boolean firstPage = (1 == pageNo);
1206
        if(firstPage){
1207
            queryResult.setPageNo(1);
1208
            sql = new StringBuilder();
1209
            sql.append("SELECT RESOURCE_ID,RESOURCE_NAME,SUBJECT,SUPPORTED_SERVICES,ORG_NAME,SPEC,PARAMETER,STATUS,DESCP,PROFESSOR_ID,PUBLISH_TIME,PAGE_VIEWS,ORG_ID,RESOURCE_TYPE FROM RESOURCE");
1210
            sql.append(whereSql);
1211
            sql.append(" ORDER BY PUBLISH_TIME DESC");
1212
            sql.append(" LIMIT ").append(pageSize);
1213
        }else{
1214
            int pageNum = total / pageSize;
1215
            if(total % pageSize != 0){
1216
                ++pageNum;
1217
            }
1218
            if(pageNo > pageNum){
1219
                pageNo = pageNum;
1220
            }
1221
            queryResult.setPageNo(pageNo);
1222
            --pageNo;
1223
            int offset = (pageNo * pageSize);
1224
            sql = new StringBuilder();
1225
            sql.append("SELECT RESOURCE_ID,RESOURCE_NAME,SUBJECT,SUPPORTED_SERVICES,ORG_NAME,SPEC,PARAMETER,STATUS,DESCP,PROFESSOR_ID,PUBLISH_TIME,PAGE_VIEWS,ORG_ID,RESOURCE_TYPE FROM RESOURCE");
1226
            sql.append(whereSql);
1227
            sql.append(" ORDER BY PUBLISH_TIME DESC");
1228
            sql.append(" LIMIT ").append(pageSize).append(" OFFSET ").append(offset);
1229
        }
1230
        ps = con.prepareStatement(sql.toString());
1231
        try{
1232
            if(hasKey){
1233
                ps.setString(index++,key);
1234
                ps.setString(index++,key);
1235
                ps.setString(index++,key);
1236
                ps.setString(index++,key);
1237
                ps.setString(index++,key);
1238
                ps.setString(index++,key);
1239
                ps.setString(index++,key);
1240
                ps.setString(index++,key);
1241
            }
1242
            ResultSet rs = ps.executeQuery();
1243
            try{
1244
                List<Resource> resources = new ArrayList<Resource>();
1245
                queryResult.setData(resources);
1246
                int size = 0;
1247
                while((size<pageSize) && rs.next()){
1248
                    ++size;
1249
                    Resource resource =  new Resource();
1250
                    resource.setResourceId(rs.getString(1));
1251
                    resource.setResourceName(rs.getString(2));
1252
                    String subject = rs.getString(3);
1253
                    if(rs.wasNull()){
1254
                    	subject = null;
1255
                    }
1256
                    resource.setSubject(subject);
1257
                    resource.setSupportedServices(rs.getString(4));
1258
                    String orgName = rs.getString(5);
1259
                    if(rs.wasNull()){
1260
                    	orgName = null;
1261
                    }
1262
                    resource.setOrgName(orgName);
1263
                    String spec = rs.getString(6);
1264
                    if(rs.wasNull()){
1265
                    	spec = null;
1266
                    }
1267
                    resource.setSpec(spec);
1268
                    String parameter = rs.getString(7);
1269
                    if(rs.wasNull()){
1270
                    	parameter = null;
1271
                    }
1272
                    resource.setParameter(parameter);
1273
                    String status = rs.getString(8);
1274
                    if(rs.wasNull()){
1275
                    	status = null;
1276
                    }
1277
                    resource.setStatus(status);
1278
                    String descp = rs.getString(9);
1279
                    if(rs.wasNull()){
1280
                    	descp = null;
1281
                    }
1282
                    resource.setDescp(descp);
1283
                    String proId = rs.getString(10);
1284
                    if(rs.wasNull()){
1285
                    	proId = null;
1286
                    }
1287
                    resource.setProfessorId(proId);
1288
                    String publishTime = rs.getString(11);
1289
                    if(rs.wasNull()){
1290
                    	publishTime = null;
1291
                    }
1292
                    resource.setPublishTime(publishTime);
1293
                    int pageViews = rs.getInt(12);
1294
                    if(rs.wasNull()){
1295
                    	pageViews = 0;
1296
                    }
1297
                    resource.setPageViews(pageViews);
1298
                    String orgid = rs.getString(13);
1299
                    if(rs.wasNull()){
1300
                    	orgid = null;
1301
                    }
1302
                    resource.setOrgId(orgid);
1303
                    resource.setResourceType(rs.getString(14));
1304
                    resources.add(resource);
1305
                }
1306
                return queryResult;
1307
            }finally{
1308
                try{rs.close();}catch(Exception e3){}
1309
            }
1310
        }finally{
1311
            try{ps.close();}catch(Exception e4){}
1312
        }
1313
    }
1314
	
1159 1315
	/**
1160 1316
	 * 资源搜索页面接口,添加资源拥有者基本信息
1161 1317
	 * @param key 搜索条件

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

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

10 10
import com.ekexiu.portal.basepo.CreateTimeSupported;
11 11
import com.ekexiu.portal.basepo.ModifyTimeSupported;
12
import com.ekexiu.portal.pojo.EditOrganization;
12 13
import com.ekexiu.portal.pojo.EditProfessor;
13 14

14 15
@Table
@ -31,6 +32,7 @@ public class Article implements CreateTimeSupported, ModifyTimeSupported {
31 32
	private String status;
32 33
	private EditProfessor professor;
33 34
	private Organization organization;
35
	private EditOrganization editOrganization;
34 36
	
35 37
	public EditProfessor getProfessor() {
36 38
		return professor;
@ -44,6 +46,12 @@ public class Article implements CreateTimeSupported, ModifyTimeSupported {
44 46
	public void setOrganization(Organization organization) {
45 47
		this.organization = organization;
46 48
	}
49
	public EditOrganization getEditOrganization() {
50
		return editOrganization;
51
	}
52
	public void setEditOrganization(EditOrganization editOrganization) {
53
		this.editOrganization = editOrganization;
54
	}
47 55
	@Column(DE.id_32)
48 56
	public String getArticleId() {
49 57
		return articleId;

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

@ -42,6 +42,8 @@ import com.ekexiu.portal.po.ArticleAgree;
42 42
import com.ekexiu.portal.po.ArticlePro;
43 43
import com.ekexiu.portal.po.ArticleRes;
44 44
import com.ekexiu.portal.po.Image;
45
import com.ekexiu.portal.pojo.EditOrganization;
46
import com.ekexiu.portal.pojo.EditProfessor;
45 47
import com.ekexiu.portal.pojo.FindInfo;
46 48

47 49
@Path("/article")
@ -630,6 +632,35 @@ public class ArticleService {
630 632
		return this.articleDao.queryPageForPublish(con, articleTitle, pageSize, pageNo);
631 633
	}
632 634
	
635
	@Get
636
	@Path("/firstpq")
637
	public PageQueryResult<Article> firstPageQuery(@JdbcConn Connection con,@Nullable String key,
638
			@DefaultValue("20") int pageSize,@DefaultValue("1") int pageNo)throws SQLException{
639
		if(key != null){
640
			key = "%" + key + "%";
641
		}
642
		PageQueryResult<Article> queryResult = this.articleDao.firstPageQuery(con, key, pageSize, pageNo);
643
		List<Article> articles = queryResult.getData();
644
		if(!articles.isEmpty()){
645
			for (Article article : articles) {
646
				if("1".equals(article.getArticleTitle())){
647
					EditProfessor professor = this.professorDao.queryBaseInfo(con, article.getProfessorId());
648
					if(professor != null){
649
						professor.setHasHeadImage(this.imageService.hasProfessorImage(professor.getId()));
650
					}
651
					article.setProfessor(professor);
652
				}else if("2".equals(article.getArticleType())){
653
					EditOrganization organization = this.orgDao.queryEditOrg(con, article.getOrgId());
654
					if(organization != null){
655
						organization.setHasOrgLogo(this.imageService.hasOrgLogo(organization.getId()));
656
					}
657
					article.setEditOrganization(organization);
658
				}
659
			}
660
		}
661
		return queryResult;
662
	}
663
	
633 664
	@Get
634 665
	@Path("/pqself")
635 666
	public PageQueryResult<Article> queryPageSelf(@JdbcConn Connection con,@Nullable String professorId,@Nullable String orgId,

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

@ -190,6 +190,30 @@ public class ResourceService {
190 190
		return resourceId;
191 191
	}
192 192
	
193
	@Post
194
	@Path("/importRes")
195
	public String importRes(@JdbcConn Connection con,Resource resource,@Nullable String imgSrc)throws SQLException{
196
		String resourceId = StringUtil.buildUUID();
197
		resource.setResourceId(resourceId);
198
		resource.setStatus("1");
199
		resource.setPageViews(0);
200
		if(resource.getProfessorId() != null){
201
			resource.setResourceType("1");
202
		}else if(resource.getOrgId() != null){
203
			resource.setResourceType("2");
204
		}
205
		this.resourceDao.insert(con, resource);
206
		if(imgSrc != null){
207
			Image image = new Image();
208
			image.setImageId(StringUtil.buildUUID());
209
			image.setImageSrc(imgSrc);
210
			image.setSort(1);
211
			image.setResourceId(resourceId);
212
			this.imageDao.insert(con, image);
213
		}
214
		return resourceId;
215
	}
216
	
193 217
	@Post
194 218
	@Path("/save")
195 219
	public String save(@JdbcConn(true) Connection con, Resource resource, @Nullable String[] fns, @Nullable String[] imageIds) 
@ -688,7 +712,11 @@ public class ResourceService {
688 712
		if(!resources.isEmpty()){
689 713
			for (Resource resource : resources) {
690 714
				resource.setImages(this.imageDao.queryRes(con, resource.getResourceId()));
691
				resource.setProfessor(this.professorDao.queryOne(con, resource.getProfessorId()));
715
				if(resource.getProfessorId() != null){
716
					resource.setProfessor(this.professorDao.queryOne(con, resource.getProfessorId()));
717
				}else if(resource.getOrgId() != null){
718
					resource.setOrganization(this.orgDao.queryEditOrg(con, resource.getOrgId()));
719
				}
692 720
			}
693 721
		}
694 722
		return resources;
@ -795,6 +823,36 @@ public class ResourceService {
795 823
		}
796 824
	}
797 825
	
826
	@Get
827
	@Path("/firstpq")
828
	public PageQueryResult<Resource> firstPageQuery(@JdbcConn Connection con,@Nullable String key,
829
			@DefaultValue("20") int pageSize,@DefaultValue("1") int pageNo)throws SQLException{
830
		if(key != null){
831
			key = "%" + key + "%";
832
		}
833
		PageQueryResult<Resource> queryResult = this.resourceDao.firstPageQuery(con, key, pageSize, pageNo);
834
		List<Resource> resources = queryResult.getData();
835
		if(!resources.isEmpty()){
836
			for (Resource resource : resources) {
837
				resource.setImages(this.imagesService.queryRes(con, resource.getResourceId()));
838
				if(resource.getProfessorId() != null){
839
					EditProfessor professor = this.professorDao.queryBaseInfo(con, resource.getProfessorId());
840
					if(professor != null){
841
						professor.setHasHeadImage(this.imageService.hasProfessorImage(professor.getId()));
842
					}
843
					resource.setEditProfessor(professor);
844
				}else if(resource.getOrgId() != null){
845
					EditOrganization organization = this.orgDao.queryEditOrg(con, resource.getOrgId());
846
					if(organization != null){
847
						organization.setHasOrgLogo(this.imageService.hasOrgLogo(organization.getId()));
848
					}
849
					resource.setOrganization(organization);
850
				}
851
			}
852
		}
853
		return queryResult;
854
	}
855
	
798 856
	@Get
799 857
	@Path("/pqRes")
800 858
	public PageQueryResult<Resource> queryPageRes(@JdbcConn(false) Connection con, @Nullable String key,