Explorar el Código

社区功能开发

夏文涛 hace 2 años
padre
commit
157f309146

+ 5 - 0
mhotel/src/com/happy/Model/ArticleTweet.java

@@ -75,6 +75,11 @@ public class ArticleTweet {
     private String userName;
 
     /**
+     * 用户头像
+     */
+    private String userPhoto;
+
+    /**
      * 文章收藏数
      */
     private Integer collectNum;

+ 15 - 1
mhotel/src/com/happy/action/articleTweetAction.java

@@ -91,6 +91,16 @@ public class articleTweetAction extends BaseController implements ModelDriven<Ar
             return null;
         }
 
+        //查询当前用户
+        Users user = userService.queryByUserId(String.valueOf(articleTweetDto.getCreateId()));
+        if (user == null) {
+            jsonObject.put("code", 500);
+            jsonObject.put("message", "用户信息已失效,查看详情失败");
+            jsonObject.put("data", null);
+            ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
+            return null;
+        }
+
         Date now = DateUtil.formateDate(DateUtil.getCurrentDate(), DateUtil.Time_Formatter_Second);
         try {
             //添加推文
@@ -104,6 +114,8 @@ public class articleTweetAction extends BaseController implements ModelDriven<Ar
             data.setCreateDate(now);
             data.setApprove(1);//正在审批
             data.setStatus(1);
+            data.setUserName(user.getUser_name());
+            data.setUserPhoto(user.getHeadPhoto());
             int aId = articleTweetService.insert(data);
             if (aId <= 0) {
                 ResUtil.writeJson(ServletActionContext.getResponse(), new JSONObject() {{
@@ -148,6 +160,8 @@ public class articleTweetAction extends BaseController implements ModelDriven<Ar
             String id = String.valueOf(UUID.randomUUID());
             workflow.setLinkId(String.valueOf(aId));//存推文的ID
             workflow.setCreateId(String.valueOf(articleTweetDto.getCreateId()));
+            workflow.setTitle(articleTweetDto.getTitle());
+            workflow.setRemark(articleTweetDto.getContent());
             workflow.setId(id);
             workflow.setStatus(1);//1是正在审批
             workflow.setType(3);//3是推文
@@ -623,7 +637,7 @@ public class articleTweetAction extends BaseController implements ModelDriven<Ar
             return null;
         }
 
-        IPage<ArticleListVo> result = articleTweetService.queryArticlesPage(articleTweetDto.getTownId().equals("") ? null : articleTweetDto.getTownId(), articleTweetDto.getUserId(), articleTweetDto.getType(), page, rows);
+        IPage<ArticleListVo> result = articleTweetService.queryArticlesPage(articleTweetDto.getKeyWord(), articleTweetDto.getTownId().equals("") ? null : articleTweetDto.getTownId(), articleTweetDto.getUserId(), articleTweetDto.getType(), page, rows);
         if (result.getPageList().size() > 0) {
             String articleIds = StringUtils.join(result.getPageList().stream().map(ArticleListVo::getId).collect(Collectors.toList()), ",");
             List<FileInfo> fileInfos = articleTweetService.queryList("and link_id in (" + articleIds + ")");

+ 2 - 2
mhotel/src/com/happy/dao/ArticleTweetDao.java

@@ -167,7 +167,7 @@ public interface ArticleTweetDao {
      * @param rows
      * @return
      */
-    List<ArticleListVo> queryArticlesPage(String townId, Integer userId, Integer type, int page, int rows);
+    List<ArticleListVo> queryArticlesPage(String keyWord, String townId, Integer userId, Integer type, int page, int rows);
 
     /**
      * 社区首页推文列表总数据条数
@@ -176,7 +176,7 @@ public interface ArticleTweetDao {
      * @param type
      * @return
      */
-    int queryArticlesTotal(String townId, Integer userId, Integer type);
+    int queryArticlesTotal(String keyWord, String townId, Integer userId, Integer type);
 
     /**
      * 相关推文列表分页数据

+ 14 - 12
mhotel/src/com/happy/dao/impl/ArticleTweetImplDao.java

@@ -61,10 +61,12 @@ public class ArticleTweetImplDao implements ArticleTweetDao {
     @Override
     public int insert(ArticleTweet articleTweet) {
         KeyHolder key = new GeneratedKeyHolder();
-        String sql = "insert into `article_tweet` (user_id,title,content,location_id,hotel_id,create_id,create_date,status,approve) " +
-                "values(:userId,:title,:content,:locationId,:hotelId,:createId,:createDate,:status,:approve) ";
+        String sql = "insert into `article_tweet` (user_id,user_name,user_photo,title,content,location_id,hotel_id,create_id,create_date,status,approve) " +
+                "values(:userId,:userName,:userPhoto,:title,:content,:locationId,:hotelId,:createId,:createDate,:status,:approve) ";
         MapSqlParameterSource sps = new MapSqlParameterSource();
         sps.addValue("userId", articleTweet.getUserId());
+        sps.addValue("userName", articleTweet.getApprove());
+        sps.addValue("userPhoto", articleTweet.getApprove());
         sps.addValue("title", articleTweet.getTitle());
         sps.addValue("content", articleTweet.getContent());
         sps.addValue("locationId", articleTweet.getLocationId());
@@ -74,6 +76,7 @@ public class ArticleTweetImplDao implements ArticleTweetDao {
         sps.addValue("status", articleTweet.getStatus());
         sps.addValue("approve", articleTweet.getApprove());
 
+
         int num = 0;
         try {
             num = namedParameterJdbcTemplate.update(sql, sps, key);
@@ -89,6 +92,7 @@ public class ArticleTweetImplDao implements ArticleTweetDao {
     public int updateArticleApprove(ArticleTweet articleTweet) {
         String sql = "update article_tweet set approve = :approve where id = :id";
         MapSqlParameterSource sps = new MapSqlParameterSource();
+        sps.addValue("approve", articleTweet.getApprove());
         sps.addValue("id", articleTweet.getId());
         int num = 0;
         try {
@@ -376,7 +380,7 @@ public class ArticleTweetImplDao implements ArticleTweetDao {
     }
 
     @Override
-    public List<ArticleListVo> queryArticlesPage(String townId, Integer userId, Integer type, int page, int rows) {
+    public List<ArticleListVo> queryArticlesPage(String keyWord, String townId, Integer userId, Integer type, int page, int rows) {
         int start = (page - 1) * rows;// 每页的起始下标
 
         String innSql = "";
@@ -394,13 +398,12 @@ public class ArticleTweetImplDao implements ArticleTweetDao {
             innSql = "inner join article_collect acc on acc.is_lose = 0 and acc.article_id = at.id and acc.user_id = :userId\n";//收藏
         }
 
-        String sqlWhere = townId == null ? "" : "and at.location_id = '" + townId + "'";
-
-        String sql = "select at.id,at.location_id as town_id,hd.name as town_name,at.title,at.user_id,u.user_name,\n" + caseSql +
+        String sqlWhere = townId == null ? "" : "and at.location_id = '" + townId + "' ";
+        sqlWhere = sqlWhere + (keyWord == null ? "" : "and (at.user_name like '%"+ keyWord +"%' or at.title like '%"+ keyWord +"%' or at.content like '%"+ keyWord +"%') ");
+        String sql = "select at.id,at.location_id as town_id,hd.name as town_name,at.title,at.user_id,at.user_name,at.user_photo,\n" + caseSql +
                 "(select count(*) from article_collect where is_lose = 0 and article_id = at.id) as collect_num\n" +
                 "from article_tweet at\n" +
                 "left join hotel_dict hd on hd.id = at.location_id\n" +
-                "left join users u on u.id = at.user_id\n" +
                 leftSql +
                 innSql +
                 "where at.approve = 2 " + sqlWhere +
@@ -419,7 +422,7 @@ public class ArticleTweetImplDao implements ArticleTweetDao {
     }
 
     @Override
-    public int queryArticlesTotal(String townId, Integer userId, Integer type) {
+    public int queryArticlesTotal(String keyWord, String townId, Integer userId, Integer type) {
 
         String innSql = "";
         if (type.intValue() == 1) {//关注
@@ -428,8 +431,8 @@ public class ArticleTweetImplDao implements ArticleTweetDao {
             innSql = "inner join article_collect acc on acc.is_lose = 0 and acc.article_id = at.id and acc.user_id = :userId\n";//收藏
         }
 
-        String sqlWhere = townId == null ? "" : "and at.location_id = '" + townId + "'";
-
+        String sqlWhere = townId == null ? "" : "and at.location_id = '" + townId + "' ";
+        sqlWhere = sqlWhere + (keyWord == null ? "" : "and (at.user_name like '%"+ keyWord +"%' or at.title like '%"+ keyWord +"%' or at.content like '%"+ keyWord +"%') ");
         String sql = "select count(*) from article_tweet at\n" +
                 innSql +
                 "where at.approve = 2 " + sqlWhere;
@@ -445,11 +448,10 @@ public class ArticleTweetImplDao implements ArticleTweetDao {
     public List<ArticleListVo> relatedTweetPage(Integer userId, String townId, Integer articleId, int page, int rows) {
         int start = (page - 1) * rows;// 每页的起始下标
 
-        String sql = "select at.id,at.location_id as town_id,hd.name as town_name,at.title,at.user_id,u.user_name,case ac.id when null then 0 else 1 end is_collect,\n" +
+        String sql = "select at.id,at.location_id as town_id,hd.name as town_name,at.title,at.user_id,at.user_name,at.user_photo,case ac.id when null then 0 else 1 end is_collect,\n" +
                 "(select count(*) from article_collect where is_lose = 0 and article_id = at.id) as collect_num\n" +
                 "from article_tweet at\n" +
                 "left join hotel_dict hd on hd.id = at.location_id\n" +
-                "left join users u on u.id = at.user_id\n" +
                 "left join article_collect ac on ac.is_lose = 0 and ac.article_id = at.id and ac.user_id = :userId\n" +
                 "where at.approve = 2 and at.location_id = :townId and at.id != :articleId\n" +
                 "order by at.create_date desc ";

+ 8 - 0
mhotel/src/com/happy/dto/ArticleTweetDto.java

@@ -44,6 +44,14 @@ public class ArticleTweetDto extends ArticleTweet {
     public Integer type;
 
     /**
+     * 关键字搜索
+     * 内容
+     * 标题
+     * 作者名称
+     */
+    public String keyWord;
+
+    /**
      * 作者ID
      */
     public Integer authorId;

+ 1 - 1
mhotel/src/com/happy/service/ArticleTweetService.java

@@ -152,7 +152,7 @@ public interface ArticleTweetService {
      * @param rows
      * @return
      */
-    IPage<ArticleListVo> queryArticlesPage(String townId, Integer userId, Integer type, int page, int rows);
+    IPage<ArticleListVo> queryArticlesPage(String keyWord, String townId, Integer userId, Integer type, int page, int rows);
 
     /**
      * 相关推文分页数据

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

@@ -142,10 +142,10 @@ public class ArticleTweetImplService implements ArticleTweetService {
     }
 
     @Override
-    public IPage<ArticleListVo> queryArticlesPage(String townId, Integer userId, Integer type, int page, int rows) {
+    public IPage<ArticleListVo> queryArticlesPage(String keyWord, String townId, Integer userId, Integer type, int page, int rows) {
         IPage<ArticleListVo> iPage = new IPage();
-        List<ArticleListVo> commentList = articleTweetDao.queryArticlesPage(townId, userId, type, page, rows);
-        int total = articleTweetDao.queryArticlesTotal(townId, userId, type);
+        List<ArticleListVo> commentList = articleTweetDao.queryArticlesPage(keyWord, townId, userId, type, page, rows);
+        int total = articleTweetDao.queryArticlesTotal(keyWord, townId, userId, type);
         iPage.setPageList(commentList == null ? new ArrayList<>() : commentList);
         iPage.setPage(page);
         iPage.setTotalPage((int) Math.ceil((double) total / rows));

+ 5 - 0
mhotel/src/com/happy/vo/ArticleListVo.java

@@ -51,6 +51,11 @@ public class ArticleListVo {
     private String userName;
 
     /**
+     * 用户头像
+     */
+    private String userPhoto;
+
+    /**
      * 是否收藏
      * 未收藏:0
      * 已收藏:1