소스 검색

新闻门户端列表及详情

Antiloveg 8 년 전
부모
커밋
b6840d6f82

+ 2 - 0
src/main/java/com/goafanti/common/dao/NewsMapper.java

@@ -25,4 +25,6 @@ public interface NewsMapper {
 
 	int batchDeleteByPrimaryKey(List<String> id);
 
+	List<NewsSummary> findPortalList(Map<String, Object> params);
+
 }

+ 18 - 0
src/main/java/com/goafanti/common/mapper/NewsMapper.xml

@@ -272,4 +272,22 @@
 			#{item}
 	</foreach>
   </delete>
+  
+  <select id="findPortalList" resultType="com.goafanti.news.bo.NewsSummary">
+		select
+			id, 
+			create_time as createTime, 
+			title , 
+			title_img as titleImg, 
+			type, 
+			hot, 
+			summary
+		from news
+		where 1 =1
+		<if test=" type != null">
+			and type = #{type,jdbcType=INTEGER}
+		</if>
+		order by create_time desc
+		limit #{pageNo,jdbcType=INTEGER}, #{pageSize,jdbcType=INTEGER}
+	</select>
 </mapper>

+ 16 - 0
src/main/java/com/goafanti/news/bo/NewsSummary.java

@@ -2,6 +2,10 @@ package com.goafanti.news.bo;
 
 import java.util.Date;
 
+import org.apache.commons.lang3.time.DateFormatUtils;
+
+import com.goafanti.common.constant.AFTConstants;
+
 public class NewsSummary {
 	/**
 	 * 主键
@@ -93,5 +97,17 @@ public class NewsSummary {
 	public void setSummary(String summary) {
 		this.summary = summary;
 	}
+	
+	public String getCreateTimeFormattedDate() {
+		if (this.createTime == null) {
+			return null;
+		} else {
+			return DateFormatUtils.format(this.createTime, AFTConstants.YYYYMMDD);
+		}
+	}
+
+	public void setCreateTimeFormattedDate(String createTimeFormattedDate) {
+
+	}
 
 }

+ 32 - 0
src/main/java/com/goafanti/news/controller/NewsController.java

@@ -6,9 +6,12 @@ import javax.servlet.http.HttpServletRequest;
 import org.springframework.stereotype.Controller;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.ResponseBody;
 import org.springframework.web.servlet.ModelAndView;
 
 import com.alibaba.druid.util.StringUtils;
+import com.goafanti.common.bo.Result;
+import com.goafanti.common.constant.ErrorConstants;
 import com.goafanti.common.controller.BaseController;
 import com.goafanti.news.enums.NewsType;
 import com.goafanti.news.service.NewsService;
@@ -48,4 +51,33 @@ public class NewsController extends BaseController {
 		//modelview.addObject(attributeValue)
 		return modelview;
 	}
+	
+	/**
+	 * 新闻列表
+	 */
+	@RequestMapping(value = "/portal/news/list", method = RequestMethod.GET)
+	@ResponseBody
+	public Result portalNewsList(Integer type, String pageSize, String pageNo, String noCache){
+		Result res  = new Result();
+		if (StringUtils.equals(noCache, "clear")) {
+			newsService.cleanList();
+		}
+		res.setData(newsService.findPortalList(pageSize, pageNo, type));
+		return res;
+	}
+	
+	/**
+	 * 新闻详情
+	 */
+	@RequestMapping(value = "/portal/news/detail", method = RequestMethod.GET)
+	@ResponseBody
+	public Result portalNewsDetail(Long id){
+		Result res = new Result();
+		if (null == id) {
+			res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "", "新闻ID"));
+			return res;
+		}
+		res.setData(newsService.findNewsDetail(id));
+		return res;
+	}
 }

+ 23 - 0
src/main/java/com/goafanti/news/service/NewsService.java

@@ -125,6 +125,29 @@ public class NewsService extends BaseMybatisDao<NewsMapper> {
 		return newsMapper.batchDeleteByPrimaryKey(id);
 	}
 
+	public List<NewsSummary> findPortalList(String pageSize, String pageNo, Integer type) {
+		Map<String, Object> params = new HashMap<String, Object>();
+		params.put("type", type);
+		Integer pSize = null;
+		Integer pNo = null;
+		if (StringUtils.isNumeric(pageSize)) {
+			pSize = Integer.parseInt(pageSize);
+		}
+		if (StringUtils.isNumeric(pageNo)) {
+			pNo = Integer.parseInt(pageNo);
+		}
+		if (pNo == null || pNo < 0) {
+			pNo = 0;
+		}
+
+		if (pSize == null || pSize < 0 || pSize > 5) {
+			pSize = 5;
+		}
+		params.put("pageSize", pSize);
+		params.put("pageNo", pNo);
+		return newsMapper.findPortalList(params);
+	}
+
 	
 
 }