Browse Source

添加推文攻略页面展示

liu 2 years ago
parent
commit
8dacef67cf

+ 53 - 0
mhotel/src/com/happy/action/articleTweetAction.java

@@ -55,6 +55,35 @@ public class articleTweetAction extends BaseController implements ModelDriven<Ar
     @Resource
     public UserService userService;
 
+    public String key;
+
+    public String startTime;
+
+    public String endTime;
+
+    public String getKey(){
+        return key;
+    }
+
+    public void setKey(String key){
+        this.key=key;
+    }
+
+    public String getStartTime() {
+        return startTime;
+    }
+
+    public void setStartTime(String startTime) {
+        this.startTime = startTime;
+    }
+
+    public String getEndTime() {
+        return endTime;
+    }
+
+    public void setEndTime(String endTime) {
+        this.endTime = endTime;
+    }
 
     /**
      * 推文发布
@@ -1145,5 +1174,29 @@ public class articleTweetAction extends BaseController implements ModelDriven<Ar
         return null;
     }
 
+    /**
+     * 攻略分页
+     * @return
+     */
+    public String walkthroughPage(){
+        JSONObject jsonObject = new JSONObject();
+
+        StringBuilder strSql = new StringBuilder(" and at.status=1 "); // 推文没删除才显示
+        if (!Func.checkNull(key)){
+            strSql.append(" and (at.user_name like '%").append(key).append("%' or at.title like '%").append(key).append("%') ");
+        }
+        if (!Func.checkNull(startTime) && !Func.checkNull(endTime)){
+            strSql.append(" and at.create_date >= '").append(startTime).append("' ");
+            strSql.append(" and at.create_date <= '").append(endTime).append("' ");
+        }
+
+        IPage<WalkthroughVo> walkthroughPage=articleTweetService.walkthroughPage(strSql.toString(),page, rows);
+
+        jsonObject.put("message", "查询分页成功");
+        jsonObject.put("code", 200);
+        jsonObject.put("data", walkthroughPage);
+        ResUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
+        return null;
+    }
 
 }

+ 4 - 0
mhotel/src/com/happy/dao/ArticleTweetDao.java

@@ -270,4 +270,8 @@ public interface ArticleTweetDao {
      * 获取点赞数最多的最新推文数据
      */
     ArticleLikeMaxVo queryMaxArticleLike();
+
+    List<WalkthroughVo> walkthroughPage(String strSql, Integer page, Integer rows);
+
+    int walkthroughTotal(String strSql);
 }

+ 41 - 0
mhotel/src/com/happy/dao/impl/ArticleTweetImplDao.java

@@ -5,6 +5,7 @@ import com.happy.Until.SqlUtil;
 import com.happy.Until.UUIDUtil;
 import com.happy.dao.ArticleTweetDao;
 import com.happy.vo.*;
+import org.apache.commons.lang.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.jdbc.core.BeanPropertyRowMapper;
 import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
@@ -739,5 +740,45 @@ public class ArticleTweetImplDao implements ArticleTweetDao {
 
     }
 
+    @Override
+    public List<WalkthroughVo> walkthroughPage(String strSql, Integer page, Integer rows) {
+        int start = (page - 1) * rows;// 每页的起始下标
+
+        String sql=" SELECT AT.id AS id, AT.location_id AS locationId, AT\n" +
+                "\t.user_name AS userName,\n" +
+                "\tAT.title AS title,\n" +
+                "\tAT.content AS content,\n" +
+                "\tAT.create_date AS createDate,\n" +
+                "\tafi2.urls AS urls \n" +
+                "FROM\n" +
+                "\t`article_tweet`\n" +
+                "\tAT LEFT JOIN ( SELECT afi.link_id, GROUP_CONCAT( afi.url ) AS urls FROM article_file_info afi GROUP BY afi.link_id ) afi2 ON afi2.link_id = AT.id \n" +
+                "WHERE\n" +
+                "\tAT.approve = 2 " +strSql+"ORDER BY AT.create_date limit :page,:rows ";
+
+        MapSqlParameterSource sps = new MapSqlParameterSource();
+        sps.addValue("page", start);
+        sps.addValue("rows", rows);
+        List<WalkthroughVo> list = namedParameterJdbcTemplate.query(sql, sps,
+                new BeanPropertyRowMapper<>(WalkthroughVo.class));
+        if (list != null && list.size() > 0) return list;
+        return null;
+    }
+
+    @Override
+    public int walkthroughTotal(String strSql) {
+        String sql="SELECT \n" +
+                "\tCOUNT(*)\n" +
+                "FROM\n" +
+                "\t`article_tweet`\n" +
+                "\tAT LEFT JOIN ( SELECT afi.link_id, GROUP_CONCAT( afi.url ) AS urls FROM article_file_info afi GROUP BY afi.link_id ) afi2 ON afi2.link_id = AT.id \n" +
+                "WHERE\n" +
+                "\tAT.approve = 2 " +strSql;
+
+        MapSqlParameterSource sps = new MapSqlParameterSource();
+
+        return namedParameterJdbcTemplate.queryForInt(sql, sps);
+    }
+
 
 }

+ 9 - 0
mhotel/src/com/happy/service/ArticleTweetService.java

@@ -241,4 +241,13 @@ public interface ArticleTweetService {
      * 获取点赞数最多的最新推文数据
      */
     ArticleLikeMaxVo queryMaxArticleLike();
+
+    /**
+     * 可以展示攻略的推文,(必须是审核成功的)
+     * @param strSql
+     * @param page
+     * @param rows
+     * @return
+     */
+    IPage<WalkthroughVo> walkthroughPage(String strSql,Integer page, Integer rows);
 }

+ 16 - 2
mhotel/src/com/happy/service/impl/ArticleTweetImplService.java

@@ -235,11 +235,12 @@ public class ArticleTweetImplService implements ArticleTweetService {
 
     /**
      * 更新用户简介
+     *
      * @param authorId
      * @param descript
      * @return
      */
-    public int updateDescript(Integer authorId, String descript){
+    public int updateDescript(Integer authorId, String descript) {
         int num = articleTweetDao.updateDescript(authorId, descript);
         return num;
     }
@@ -260,8 +261,21 @@ public class ArticleTweetImplService implements ArticleTweetService {
 
 
     @Override
-    public ArticleLikeMaxVo queryMaxArticleLike(){
+    public ArticleLikeMaxVo queryMaxArticleLike() {
         ArticleLikeMaxVo result = articleTweetDao.queryMaxArticleLike();
         return result;
     }
+
+    @Override
+    public IPage<WalkthroughVo> walkthroughPage(String strSql, Integer page, Integer rows) {
+        IPage<WalkthroughVo> iPage = new IPage();
+        List<WalkthroughVo> commentList = articleTweetDao.walkthroughPage(strSql, page, rows);
+        int total = articleTweetDao.walkthroughTotal(strSql);
+        iPage.setPageList(commentList == null ? new ArrayList<>() : commentList);
+        iPage.setPage(page);
+        iPage.setTotalPage((int) Math.ceil((double) total / rows));
+        iPage.setRows(rows);
+        iPage.setTotal(total);
+        return iPage;
+    }
 }