|
|
@@ -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 ";
|