|
@ -19,6 +19,7 @@ import org.jfw.apt.orm.annotation.dao.method.Where;
|
19
|
19
|
import org.jfw.apt.orm.annotation.dao.method.operator.DeleteWith;
|
20
|
20
|
import org.jfw.apt.orm.annotation.dao.method.operator.Insert;
|
21
|
21
|
import org.jfw.apt.orm.annotation.dao.method.operator.LimitSelect;
|
|
22
|
import org.jfw.apt.orm.annotation.dao.method.operator.PageQuery;
|
22
|
23
|
import org.jfw.apt.orm.annotation.dao.method.operator.PageSelect;
|
23
|
24
|
import org.jfw.apt.orm.annotation.dao.method.operator.SelectList;
|
24
|
25
|
import org.jfw.apt.orm.annotation.dao.method.operator.SelectOne;
|
|
@ -33,6 +34,7 @@ import org.jfw.util.PageQueryResult;
|
33
|
34
|
|
34
|
35
|
import com.ekexiu.portal.po.Article;
|
35
|
36
|
import com.ekexiu.portal.pojo.FindInfo;
|
|
37
|
import com.ekexiu.portal.pojo.SelfArticle;
|
36
|
38
|
|
37
|
39
|
@DAO
|
38
|
40
|
public abstract class ArticleDao {
|
|
@ -593,207 +595,14 @@ public abstract class ArticleDao {
|
593
|
595
|
}
|
594
|
596
|
}
|
595
|
597
|
|
596
|
|
public PageQueryResult<Article> queryPageForSelf(Connection con,@Nullable String professorId,@Nullable String orgId,
|
597
|
|
@Nullable String articleTitle,int pageSize,int pageNo) throws SQLException{
|
598
|
|
int total = 0;
|
599
|
|
PageQueryResult<Article> queryResult = new PageQueryResult<Article>();
|
600
|
|
int index = 1;
|
601
|
|
boolean hasProfessorId = null != professorId;
|
602
|
|
boolean hasOrgId = null != orgId;
|
603
|
|
boolean hasArticleTitle = null != articleTitle;
|
604
|
|
StringBuilder sql = new StringBuilder();
|
605
|
|
sql.append("SELECT COUNT(1) FROM ARTICLE WHERE STATUS IN('0','1','2')");
|
606
|
|
if(hasProfessorId){
|
607
|
|
sql.append(" AND PROFESSOR_ID = ?");
|
608
|
|
}
|
609
|
|
if(hasOrgId){
|
610
|
|
sql.append(" AND ORG_ID = ?");
|
611
|
|
}
|
612
|
|
if(hasArticleTitle){
|
613
|
|
sql.append(" AND ARTICLE_TITLE LIKE ?");
|
614
|
|
}
|
615
|
|
PreparedStatement ps = con.prepareStatement(sql.toString());
|
616
|
|
try{
|
617
|
|
if(hasProfessorId){
|
618
|
|
ps.setString(index++, professorId);
|
619
|
|
}
|
620
|
|
if(hasOrgId){
|
621
|
|
ps.setString(index++, orgId);
|
622
|
|
}
|
623
|
|
if(hasArticleTitle){
|
624
|
|
ps.setString(index++, articleTitle);
|
625
|
|
}
|
626
|
|
queryResult.setPageSize(pageSize);
|
627
|
|
ResultSet rs = ps.executeQuery();
|
628
|
|
try{
|
629
|
|
rs.next();
|
630
|
|
total = rs.getInt(1);
|
631
|
|
}finally{
|
632
|
|
try{rs.close();}catch(Exception e1){}
|
633
|
|
}
|
634
|
|
}finally{
|
635
|
|
try{ps.close();}catch(Exception e2){}
|
636
|
|
}
|
637
|
|
queryResult.setTotal(total);
|
638
|
|
if(0== total){
|
639
|
|
queryResult.setPageNo(1);
|
640
|
|
queryResult.setData(Collections.<Article>emptyList());
|
641
|
|
return queryResult;
|
642
|
|
}
|
643
|
|
boolean firstPage = (1 == pageNo);
|
644
|
|
if(firstPage){
|
645
|
|
queryResult.setPageNo(1);
|
646
|
|
sql = new StringBuilder();
|
647
|
|
sql.append("(SELECT ARTICLE_ID,PROFESSOR_ID,ARTICLE_TITLE,'',SUBJECT,INDUSTRY,PUBLISH_TIME,ARTICLE_IMG,ORG_ID,ARTICLE_TYPE,ARTICLE_AGREE,PAGE_VIEWS,STATUS,CREATE_TIME,MODIFY_TIME,SHARE_ID,COL_NUM FROM ARTICLE WHERE STATUS IN('0','2')");
|
648
|
|
if(hasProfessorId){
|
649
|
|
sql.append(" AND PROFESSOR_ID = ?");
|
650
|
|
}
|
651
|
|
if(hasOrgId){
|
652
|
|
sql.append(" AND ORG_ID = ?");
|
653
|
|
}
|
654
|
|
if(hasArticleTitle){
|
655
|
|
sql.append(" AND ARTICLE_TITLE LIKE ?");
|
656
|
|
}
|
657
|
|
sql.append(" ORDER BY MODIFY_TIME DESC) UNION ALL (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,SHARE_ID FROM ARTICLE WHERE STATUS = '1'");
|
658
|
|
if(hasProfessorId){
|
659
|
|
sql.append(" AND PROFESSOR_ID = ?");
|
660
|
|
}
|
661
|
|
if(hasOrgId){
|
662
|
|
sql.append(" AND ORG_ID = ?");
|
663
|
|
}
|
664
|
|
if(hasArticleTitle){
|
665
|
|
sql.append(" AND ARTICLE_TITLE LIKE ?");
|
666
|
|
}
|
667
|
|
sql.append(" ORDER BY PUBLISH_TIME DESC)");
|
668
|
|
sql.append(" LIMIT ").append(pageSize);
|
669
|
|
}else{
|
670
|
|
int pageNum = total / pageSize;
|
671
|
|
if(total % pageSize != 0){
|
672
|
|
++pageNum;
|
673
|
|
}
|
674
|
|
if(pageNo > pageNum){
|
675
|
|
pageNo = pageNum;
|
676
|
|
}
|
677
|
|
queryResult.setPageNo(pageNo);
|
678
|
|
--pageNo;
|
679
|
|
int offset = (pageNo * pageSize);
|
680
|
|
sql = new StringBuilder();
|
681
|
|
sql.append("(SELECT ARTICLE_ID,PROFESSOR_ID,ARTICLE_TITLE,'',SUBJECT,INDUSTRY,PUBLISH_TIME,ARTICLE_IMG,ORG_ID,ARTICLE_TYPE,ARTICLE_AGREE,PAGE_VIEWS,STATUS,CREATE_TIME,MODIFY_TIME,SHARE_ID,COL_NUM FROM ARTICLE WHERE STATUS IN('0','2')");
|
682
|
|
if(hasProfessorId){
|
683
|
|
sql.append(" AND PROFESSOR_ID = ?");
|
684
|
|
}
|
685
|
|
if(hasOrgId){
|
686
|
|
sql.append(" AND ORG_ID = ?");
|
687
|
|
}
|
688
|
|
if(hasArticleTitle){
|
689
|
|
sql.append(" AND ARTICLE_TITLE LIKE ?");
|
690
|
|
}
|
691
|
|
sql.append(" ORDER BY MODIFY_TIME DESC) UNION ALL (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,SHARE_ID FROM ARTICLE WHERE STATUS = '1'");
|
692
|
|
if(hasProfessorId){
|
693
|
|
sql.append(" AND PROFESSOR_ID = ?");
|
694
|
|
}
|
695
|
|
if(hasOrgId){
|
696
|
|
sql.append(" AND ORG_ID = ?");
|
697
|
|
}
|
698
|
|
if(hasArticleTitle){
|
699
|
|
sql.append(" AND ARTICLE_TITLE LIKE ?");
|
700
|
|
}
|
701
|
|
sql.append(" ORDER BY PUBLISH_TIME DESC)");
|
702
|
|
sql.append(" LIMIT ").append(pageSize).append(" OFFSET ").append(offset);
|
703
|
|
}
|
704
|
|
ps = con.prepareStatement(sql.toString());
|
705
|
|
index = 1;
|
706
|
|
try{
|
707
|
|
if(hasProfessorId){
|
708
|
|
ps.setString(index++, professorId);
|
709
|
|
}
|
710
|
|
if(hasOrgId){
|
711
|
|
ps.setString(index++, orgId);
|
712
|
|
}
|
713
|
|
if(hasArticleTitle){
|
714
|
|
ps.setString(index++, articleTitle);
|
715
|
|
}
|
716
|
|
if(hasProfessorId){
|
717
|
|
ps.setString(index++, professorId);
|
718
|
|
}
|
719
|
|
if(hasOrgId){
|
720
|
|
ps.setString(index++, orgId);
|
721
|
|
}
|
722
|
|
if(hasArticleTitle){
|
723
|
|
ps.setString(index++, articleTitle);
|
724
|
|
}
|
725
|
|
ResultSet rs = ps.executeQuery();
|
726
|
|
try{
|
727
|
|
List<Article> articles = new ArrayList<Article>();
|
728
|
|
queryResult.setData(articles);
|
729
|
|
int size = 0;
|
730
|
|
while((size<pageSize) && rs.next()){
|
731
|
|
++size;
|
732
|
|
Article article = new Article();
|
733
|
|
article.setArticleId(rs.getString(1));
|
734
|
|
String proId = rs.getString(2);
|
735
|
|
if(rs.wasNull()){
|
736
|
|
proId = null;
|
737
|
|
}
|
738
|
|
article.setProfessorId(proId);
|
739
|
|
article.setArticleTitle(rs.getString(3));
|
740
|
|
String articleContent = rs.getString(4);
|
741
|
|
if(rs.wasNull()){
|
742
|
|
articleContent = null;
|
743
|
|
}
|
744
|
|
article.setArticleContent(articleContent);
|
745
|
|
String subject = rs.getString(5);
|
746
|
|
if(rs.wasNull()){
|
747
|
|
subject = null;
|
748
|
|
}
|
749
|
|
article.setSubject(subject);
|
750
|
|
String industry = rs.getString(6);
|
751
|
|
if(rs.wasNull()){
|
752
|
|
industry = null;
|
753
|
|
}
|
754
|
|
article.setIndustry(industry);
|
755
|
|
String publishTime = rs.getString(7);
|
756
|
|
if(rs.wasNull()){
|
757
|
|
publishTime = null;
|
758
|
|
}
|
759
|
|
article.setPublishTime(publishTime);
|
760
|
|
String articleImg = rs.getString(8);
|
761
|
|
if(rs.wasNull()){
|
762
|
|
articleImg = null;
|
763
|
|
}
|
764
|
|
article.setArticleImg(articleImg);
|
765
|
|
String org = rs.getString(9);
|
766
|
|
if(rs.wasNull()){
|
767
|
|
org = null;
|
768
|
|
}
|
769
|
|
article.setOrgId(org);
|
770
|
|
String articleType = rs.getString(10);
|
771
|
|
if(rs.wasNull()){
|
772
|
|
articleType = null;
|
773
|
|
}
|
774
|
|
article.setArticleType(articleType);
|
775
|
|
article.setArticleAgree(rs.getInt(11));
|
776
|
|
article.setPageViews(rs.getInt(12));
|
777
|
|
String status = rs.getString(13);
|
778
|
|
if(rs.wasNull()){
|
779
|
|
status = null;
|
780
|
|
}
|
781
|
|
article.setStatus(status);
|
782
|
|
article.setCreateTime(rs.getString(14));
|
783
|
|
article.setModifyTime(rs.getString(15));
|
784
|
|
article.setShareId(rs.getLong(16));
|
785
|
|
article.setColNum(rs.getInt(17));
|
786
|
|
articles.add(article);
|
787
|
|
}
|
788
|
|
return queryResult;
|
789
|
|
}finally{
|
790
|
|
try{rs.close();}catch(Exception e3){}
|
791
|
|
}
|
792
|
|
}finally{
|
793
|
|
try{ps.close();}catch(Exception e4){}
|
794
|
|
}
|
795
|
|
}
|
796
|
598
|
|
|
599
|
@PageQuery
|
|
600
|
@Exclude("articleContent")
|
|
601
|
@OrderBy(" ORDER BY selfOrderField DESC,SHARE_ID ASC ")
|
|
602
|
@Where("STATUS IN ('1','0','2')")
|
|
603
|
public abstract PageQueryResult<SelfArticle> queryPageForSelf(Connection con,@Nullable String professorId,@Nullable String orgId,
|
|
604
|
@Like @Nullable String articleTitle,int pageSize,int pageNo) throws SQLException;
|
|
605
|
|
797
|
606
|
public PageQueryResult<FindInfo> queryPage(Connection con,int pageSize,int pageNo) throws SQLException{
|
798
|
607
|
int total = 0;
|
799
|
608
|
PageQueryResult<FindInfo> queryResult = new PageQueryResult<FindInfo>();
|