Browse Source

Merge branch 'master' of https://git.coding.net/aft/AFT

wubb 8 years ago
parent
commit
3046113ce7

+ 2 - 1
src/main/java/com/goafanti/admin/controller/AdminLectureApiController.java

@@ -20,6 +20,7 @@ import com.goafanti.common.constant.ErrorConstants;
 import com.goafanti.common.controller.BaseApiController;
 import com.goafanti.common.enums.AttachmentType;
 import com.goafanti.common.enums.LectureDynamicType;
+import com.goafanti.common.enums.LectureFields;
 import com.goafanti.common.enums.LectureHotType;
 import com.goafanti.common.enums.PatentInfoFields;
 import com.goafanti.common.model.Lecture;
@@ -92,7 +93,7 @@ public class AdminLectureApiController extends BaseApiController {
 		Result res = new Result();
 		if (bindingResult.hasErrors()) {
 			res.getError().add(buildErrorByMsg(bindingResult.getFieldError().getDefaultMessage(),
-					PatentInfoFields.getFieldDesc(bindingResult.getFieldError().getField())));
+					LectureFields.getFieldDesc(bindingResult.getFieldError().getField())));
 			return res;
 		}
 

+ 166 - 2
src/main/java/com/goafanti/admin/controller/AdminNewsApiController.java

@@ -1,18 +1,182 @@
 package com.goafanti.admin.controller;
 
+import java.text.ParseException;
+import java.util.Arrays;
+
 import javax.annotation.Resource;
+import javax.servlet.http.HttpServletRequest;
+import javax.validation.Valid;
 
+import org.springframework.beans.BeanUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.validation.BindingResult;
 import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RestController;
 
+import com.goafanti.common.bo.Result;
+import com.goafanti.common.constant.AFTConstants;
+import com.goafanti.common.constant.ErrorConstants;
 import com.goafanti.common.controller.BaseApiController;
+import com.goafanti.common.enums.AttachmentType;
+import com.goafanti.common.model.News;
+import com.goafanti.common.utils.DateUtils;
+import com.goafanti.common.utils.StringUtils;
+import com.goafanti.core.mybatis.JDBCIdGenerator;
+import com.goafanti.core.shiro.token.TokenManager;
+import com.goafanti.news.bo.InputNews;
+import com.goafanti.news.enums.NewsFields;
 import com.goafanti.news.service.NewsService;
+
 /**
  * 新闻
  */
 @RestController
 @RequestMapping(value = "/api/admin/news")
-public class AdminNewsApiController extends BaseApiController{
+public class AdminNewsApiController extends BaseApiController {
 	@Resource
-	private NewsService newsService;
+	private NewsService		newsService;
+	@Autowired
+	private JDBCIdGenerator	idGenerator;
+
+	/**
+	 * 新闻列表
+	 */
+	@RequestMapping(value = "/list", method = RequestMethod.GET)
+	public Result list(Integer type, String title, String author, String startCreateTime, String endCreateTime,
+			String source, Integer hot, String pageSize, String pageNo) {
+		Result res = new Result();
+		if (null == type) {
+			res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "", "新闻类型"));
+			return res;
+		}
+		Integer pNo = 1;
+		Integer pSize = 10;
+		if (StringUtils.isNumeric(pageSize)) {
+			pSize = Integer.parseInt(pageSize);
+		}
+		if (StringUtils.isNumeric(pageNo)) {
+			pNo = Integer.parseInt(pageNo);
+		}
+		res.setData(newsService.listNews(type, title, author, startCreateTime, endCreateTime, source, hot, pNo, pSize));
+		return res;
+	}
+
+	/**
+	 * 新增
+	 */
+	@RequestMapping(value = "/add", method = RequestMethod.POST)
+	public Result add(@Valid InputNews news, BindingResult bindingResult, String createTimeFormattedDate) {
+		Result res = new Result();
+		if (bindingResult.hasErrors()) {
+			res.getError().add(buildErrorByMsg(bindingResult.getFieldError().getDefaultMessage(),
+					NewsFields.getFieldDesc(bindingResult.getFieldError().getField())));
+			return res;
+		}
+		res = disposeInputNews(res, news, createTimeFormattedDate);
+		if (!res.getError().isEmpty()) {
+			return res;
+		}
+		newsService.save(idGenerator.generateId(), (News) res.getData());
+		return res;
+	}
+
+	/**
+	 * 修改
+	 */
+	@RequestMapping(value = "/update", method = RequestMethod.POST)
+	public Result update(InputNews news, BindingResult bindingResult, String createTimeFormattedDate) {
+		Result res = new Result();
+		if (bindingResult.hasErrors()) {
+			res.getError().add(buildErrorByMsg(bindingResult.getFieldError().getDefaultMessage(),
+					NewsFields.getFieldDesc(bindingResult.getFieldError().getField())));
+			return res;
+		}
+
+		if (null == news.getId()) {
+			res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "", "新闻Id"));
+			return res;
+		}
+
+		res = disposeInputNews(res, news, createTimeFormattedDate);
+		if (!res.getError().isEmpty()) {
+			return res;
+		}
+		newsService.update(news.getId(), (News) res.getData());
+		return res;
+	}
+
+	/**
+	 * 详情
+	 */
+	@RequestMapping(value = "/detail", method = RequestMethod.GET)
+	public Result detail(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;
+	}
+
+	/**
+	 * 删除
+	 */
+	@RequestMapping(value = "/delete", method = RequestMethod.POST)
+	public Result delete(@RequestParam(name = "ids[]", required = false) String[] ids) {
+		Result res = new Result();
+		if (ids == null || ids.length < 1) {
+			res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", ""));
+		} else {
+			res.setData(newsService.batchDeleteByPrimaryKey(Arrays.asList(ids)));
+		}
+		return res;
+	}
+	
+	/**
+	 * 新闻题图图片上传
+	 */
+	@RequestMapping(value = "/upload", method = RequestMethod.POST)
+	public Result upload(HttpServletRequest req, String sign) {
+		Result res = new Result();
+		AttachmentType attachmentType = AttachmentType.getField(sign);
+		if (attachmentType == AttachmentType.NEWS_TITLE_PICTURE ||
+				attachmentType == AttachmentType.NEWS_CONTENT_PICTURE) {
+			res.setData(handleFiles(res, "/news/", false, req, sign, TokenManager.getAdminId()));
+		} else {
+			res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "附件标示"));
+		}
+		return res;
+	}
+	
+	
+
+	private Result disposeInputNews(Result res, InputNews news, String createTimeFormattedDate) {
+		if (StringUtils.isBlank(news.getTitle())) {
+			res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "", "新闻标题"));
+			return res;
+		}
+
+		if (StringUtils.isBlank(createTimeFormattedDate)) {
+			res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "", "新闻时间"));
+			return res;
+		}
+
+		if (null == news.getType()) {
+			res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "", "新闻类型"));
+			return res;
+		}
+
+		News n = new News();
+		BeanUtils.copyProperties(news, n);
+		try {
+			n.setCreateTime(DateUtils.parseDate(createTimeFormattedDate, AFTConstants.YYYYMMDD));
+		} catch (ParseException e) {
+		}
+		res.setData(n);
+		return res;
+	}
+
 }

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

@@ -22,4 +22,9 @@ public interface NewsMapper {
 	int updateByPrimaryKey(News record);
 
 	List<NewsSummary> findList(Map<String, Object> params);
+
+	int batchDeleteByPrimaryKey(List<String> id);
+
+	List<NewsSummary> findPortalList(Map<String, Object> params);
+
 }

+ 3 - 1
src/main/java/com/goafanti/common/enums/AttachmentType.java

@@ -41,8 +41,10 @@ public enum AttachmentType {
 	ACHIEVEMENT_TEMPLATE("achievement_template", "科技成果批量导入模板"),
 	DEMAND_ORDER_FILE("demand_order_file", "科技需求意向单/交易单附件"),
 	BANNERS_PIC("banners", "广告图片"),
-	NEWS_PIC("news", "新闻图片"),
+	NEWS_TITLE_PICTURE("news_title_picture", "新闻题图图片"),
+	NEWS_CONTENT_PICTURE("news_content_picture", "新闻内容图片"),
 	LECTURE_PICTURE("lecture_picture", "科技讲堂展示图片");
+	
 
 	private AttachmentType(String code, String desc) {
 		this.code = code;

+ 57 - 0
src/main/java/com/goafanti/common/enums/LectureFields.java

@@ -0,0 +1,57 @@
+package com.goafanti.common.enums;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public enum LectureFields {
+	ID("id", "科技讲堂ID"),
+	UID("uid", "用户ID"),
+	NAME("name", "讲堂名称"),
+	SUMMARY("summary", "简介"),
+	
+	LECTUREURL("lectureUrl", "讲堂URL"),
+	HOT("hot", "大咖说页面展示标记"),
+	DYNAMIC("dynamic", "科技明星页面展示标记"),
+	
+	OTHER("", "未知参数");
+	
+	private String	code;
+	private String	desc;
+	
+	private static Map<String, LectureFields> status = new HashMap<String, LectureFields>();
+	
+	private LectureFields(String code, String desc) {
+		this.code = code;
+		this.desc = desc;
+	}
+	
+	static {
+		for (LectureFields value : LectureFields.values()) {
+			status.put(value.getCode(), value);
+		}
+	}
+	
+	public static LectureFields getField(String code) {
+		if (containsType(code)) {
+			return status.get(code);
+		}
+		return OTHER;
+	}
+	
+	public static String getFieldDesc(String code) {
+		return getField(code).getDesc();
+	}
+
+	public static boolean containsType(String code) {
+		return status.containsKey(code);
+	}
+	
+	public String getCode() {
+		return code;
+	}
+
+	public String getDesc() {
+		return desc;
+	}
+
+}

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

@@ -195,4 +195,99 @@
       summary = #{summary,jdbcType=VARCHAR}
     where id = #{id,jdbcType=BIGINT}
   </update>
+  
+  <select id="findNewsListByPage" parameterType="String" resultMap="BaseResultMap">
+  	select
+  		id,
+  		create_time,
+  		title,
+  		author,
+  		type,
+  		hot,
+  		source,
+  		summary
+  	from news
+  	where 1 =1
+  	<if test="type != null">
+  		and type = #{type,jdbcType=INTEGER}
+  	</if>
+  	<if test="title != null">
+  		and title like CONCAT('%',#{title,jdbcType=VARCHAR},'%')
+  	</if>
+  	<if test="author != null">
+  		and author like CONCAT('%',#{author,jdbcType=VARCHAR},'%')
+  	</if>
+  	<if test="sDate != null">
+  	    and create_time <![CDATA[ >= ]]>  #{sDate,jdbcType=TIMESTAMP}
+  	</if>
+  	<if test="eDate != null">
+  		and create_time <![CDATA[ < ]]>  #{eDate,jdbcType=TIMESTAMP}
+  	</if>
+  	<if test="source != null">
+  		and source like CONCAT('%',#{source,jdbcType=VARCHAR},'%')
+  	</if>
+  	<if test="hot != null">
+  		and hot = #{hot,jdbcType=INTEGER}
+  	</if>
+  	order by create_time desc
+  	<if test="page_sql!=null">
+			${page_sql}
+	</if>
+  </select>
+  
+   <select id="findNewsCount" parameterType="String" resultType="java.lang.Integer">
+  	select
+  		count(1)
+  	from news
+  	where 1 =1
+  	<if test="type != null">
+  		and type = #{type,jdbcType=INTEGER}
+  	</if>
+  	<if test="title != null">
+  		and title like CONCAT('%',#{title,jdbcType=VARCHAR},'%')
+  	</if>
+  	<if test="author != null">
+  		and author like CONCAT('%',#{author,jdbcType=VARCHAR},'%')
+  	</if>
+  	<if test="sDate != null">
+  	    and create_time <![CDATA[ >= ]]>  #{sDate,jdbcType=TIMESTAMP}
+  	</if>
+  	<if test="eDate != null">
+  		and create_time <![CDATA[ < ]]>  #{eDate,jdbcType=TIMESTAMP}
+  	</if>
+  	<if test="source != null">
+  		and source like CONCAT('%',#{source,jdbcType=VARCHAR},'%')
+  	</if>
+  	<if test="hot != null">
+  		and hot = #{hot,jdbcType=INTEGER}
+  	</if>
+  </select>
+  
+  <delete id="batchDeleteByPrimaryKey" parameterType="java.util.List">
+  	delete
+  		from news
+  	where id in
+  	<foreach item="item" index="index" collection="list" open="("
+			separator="," close=")">
+			#{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 != 0" >
+			and type = #{type,jdbcType=INTEGER}
+		</if>
+		order by create_time desc
+		limit #{pageNo,jdbcType=INTEGER}, #{pageSize,jdbcType=INTEGER}
+	</select>
 </mapper>

+ 1 - 1
src/main/java/com/goafanti/common/mapper/NewsMapperExt.xml

@@ -17,7 +17,7 @@
 		select
 		<include refid="Summary_Column_List" />
 		from news
-		where 1=1 
+		where hot = 1 
 		<if test=" type != null">
 			and type = #{type,jdbcType=INTEGER}
 		</if>

+ 171 - 155
src/main/java/com/goafanti/common/model/News.java

@@ -2,160 +2,176 @@ package com.goafanti.common.model;
 
 import java.util.Date;
 
+import org.apache.commons.lang3.time.DateFormatUtils;
+
+import com.goafanti.common.constant.AFTConstants;
+
 public class News {
-    /**
-    * 主键
-    */
-    private Long id;
-
-    /**
-    * 创建时间
-    */
-    private Date createTime;
-
-    /**
-    * 修改时间
-    */
-    private Date editTime;
-
-    /**
-    * 标题
-    */
-    private String title;
-
-    /**
-    * 题图url
-    */
-    private String titleImg;
-
-    /**
-    * 作者
-    */
-    private String author;
-
-    /**
-    * 类型
-    */
-    private Integer type;
-
-    /**
-    * 是否放在首页
-    */
-    private Integer hot;
-
-    /**
-    * 来源
-    */
-    private String source;
-
-    /**
-    * 来源url
-    */
-    private String sourceUrl;
-
-    /**
-    * 简介
-    */
-    private String summary;
-
-    /**
-    * 内容
-    */
-    private String content;
-
-    public Long getId() {
-        return id;
-    }
-
-    public void setId(Long id) {
-        this.id = id;
-    }
-
-    public Date getCreateTime() {
-        return createTime;
-    }
-
-    public void setCreateTime(Date createTime) {
-        this.createTime = createTime;
-    }
-
-    public Date getEditTime() {
-        return editTime;
-    }
-
-    public void setEditTime(Date editTime) {
-        this.editTime = editTime;
-    }
-
-    public String getTitle() {
-        return title;
-    }
-
-    public void setTitle(String title) {
-        this.title = title;
-    }
-
-    public String getTitleImg() {
-        return titleImg;
-    }
-
-    public void setTitleImg(String titleImg) {
-        this.titleImg = titleImg;
-    }
-
-    public String getAuthor() {
-        return author;
-    }
-
-    public void setAuthor(String author) {
-        this.author = author;
-    }
-
-    public Integer getType() {
-        return type;
-    }
-
-    public void setType(Integer type) {
-        this.type = type;
-    }
-
-    public Integer getHot() {
-        return hot;
-    }
-
-    public void setHot(Integer hot) {
-        this.hot = hot;
-    }
-
-    public String getSource() {
-        return source;
-    }
-
-    public void setSource(String source) {
-        this.source = source;
-    }
-
-    public String getSourceUrl() {
-        return sourceUrl;
-    }
-
-    public void setSourceUrl(String sourceUrl) {
-        this.sourceUrl = sourceUrl;
-    }
-
-    public String getSummary() {
-        return summary;
-    }
-
-    public void setSummary(String summary) {
-        this.summary = summary;
-    }
-
-    public String getContent() {
-        return content;
-    }
-
-    public void setContent(String content) {
-        this.content = content;
-    }
+	/**
+	 * 主键
+	 */
+	private Long	id;
+
+	/**
+	 * 创建时间
+	 */
+	private Date	createTime;
+
+	/**
+	 * 修改时间
+	 */
+	private Date	editTime;
+
+	/**
+	 * 标题
+	 */
+	private String	title;
+
+	/**
+	 * 题图url
+	 */
+	private String	titleImg;
+
+	/**
+	 * 作者
+	 */
+	private String	author;
+
+	/**
+	 * 类型
+	 */
+	private Integer	type;
+
+	/**
+	 * 是否放在首页
+	 */
+	private Integer	hot;
+
+	/**
+	 * 来源
+	 */
+	private String	source;
+
+	/**
+	 * 来源url
+	 */
+	private String	sourceUrl;
+
+	/**
+	 * 简介
+	 */
+	private String	summary;
+
+	/**
+	 * 内容
+	 */
+	private String	content;
+
+	public Long getId() {
+		return id;
+	}
+
+	public void setId(Long id) {
+		this.id = id;
+	}
+
+	public Date getCreateTime() {
+		return createTime;
+	}
+
+	public void setCreateTime(Date createTime) {
+		this.createTime = createTime;
+	}
+
+	public Date getEditTime() {
+		return editTime;
+	}
+
+	public void setEditTime(Date editTime) {
+		this.editTime = editTime;
+	}
+
+	public String getTitle() {
+		return title;
+	}
+
+	public void setTitle(String title) {
+		this.title = title;
+	}
+
+	public String getTitleImg() {
+		return titleImg;
+	}
+
+	public void setTitleImg(String titleImg) {
+		this.titleImg = titleImg;
+	}
+
+	public String getAuthor() {
+		return author;
+	}
+
+	public void setAuthor(String author) {
+		this.author = author;
+	}
+
+	public Integer getType() {
+		return type;
+	}
+
+	public void setType(Integer type) {
+		this.type = type;
+	}
+
+	public Integer getHot() {
+		return hot;
+	}
+
+	public void setHot(Integer hot) {
+		this.hot = hot;
+	}
+
+	public String getSource() {
+		return source;
+	}
+
+	public void setSource(String source) {
+		this.source = source;
+	}
+
+	public String getSourceUrl() {
+		return sourceUrl;
+	}
+
+	public void setSourceUrl(String sourceUrl) {
+		this.sourceUrl = sourceUrl;
+	}
+
+	public String getSummary() {
+		return summary;
+	}
+
+	public void setSummary(String summary) {
+		this.summary = summary;
+	}
+
+	public String getContent() {
+		return content;
+	}
+
+	public void setContent(String content) {
+		this.content = content;
+	}
+
+	public String getCreateTimeFormattedDate() {
+		if (this.createTime == null) {
+			return null;
+		} else {
+			return DateFormatUtils.format(this.createTime, AFTConstants.YYYYMMDD);
+		}
+	}
+
+	public void setCreateTimeFormattedDate(String createTimeFormattedDate) {
+
+	}
 }

+ 2 - 1
src/main/java/com/goafanti/common/utils/FileUtils.java

@@ -105,7 +105,8 @@ public class FileUtils {
 				|| sign.indexOf("demand_picture") != -1 || sign.indexOf("demand_text_file") != -1
 				|| sign.indexOf("achievement_technical_picture") != -1
 				|| sign.indexOf("achievement_maturity_picture") != -1 || sign.indexOf("demand_order_file") != -1
-				|| sign.indexOf("lecture_picture") != -1) {
+				|| sign.indexOf("lecture_picture") != -1
+				|| sign.indexOf("news") != -1) {
 			uniq = true;
 		}
 		String fileName = "";

+ 121 - 0
src/main/java/com/goafanti/news/bo/InputNews.java

@@ -0,0 +1,121 @@
+package com.goafanti.news.bo;
+
+import javax.validation.constraints.Max;
+import javax.validation.constraints.Min;
+import javax.validation.constraints.Size;
+
+import com.goafanti.common.constant.ErrorConstants;
+
+public class InputNews {
+	
+	private Long	id;
+	
+	@Size(min = 0, max = 45, message = "{" + ErrorConstants.PARAM_SIZE_ERROR + "}")
+	private String	title;
+	
+	@Size(min = 0, max = 128, message = "{" + ErrorConstants.PARAM_SIZE_ERROR + "}")
+	private String	titleImg;
+	
+	@Size(min = 0, max = 45, message = "{" + ErrorConstants.PARAM_SIZE_ERROR + "}")
+	private String	author;
+	
+	@Max(value = 99, message = "{" + ErrorConstants.PARAM_ERROR + "}")
+	@Min(value = 0, message = "{" + ErrorConstants.PARAM_ERROR + "}")
+	private Integer	type;
+	
+	@Max(value = 1, message = "{" + ErrorConstants.PARAM_ERROR + "}")
+	@Min(value = 0, message = "{" + ErrorConstants.PARAM_ERROR + "}")
+	private Integer	hot;
+	
+	@Size(min = 0, max = 45, message = "{" + ErrorConstants.PARAM_SIZE_ERROR + "}")
+	private String	source;
+	
+	@Size(min = 0, max = 255, message = "{" + ErrorConstants.PARAM_SIZE_ERROR + "}")
+	private String	sourceUrl;
+	
+	@Size(min = 0, max = 144, message = "{" + ErrorConstants.PARAM_SIZE_ERROR + "}")
+	private String	summary;
+	
+	private String	content;
+
+	public Long getId() {
+		return id;
+	}
+
+	public void setId(Long id) {
+		this.id = id;
+	}
+
+	public String getTitle() {
+		return title;
+	}
+
+	public void setTitle(String title) {
+		this.title = title;
+	}
+
+	public String getTitleImg() {
+		return titleImg;
+	}
+
+	public void setTitleImg(String titleImg) {
+		this.titleImg = titleImg;
+	}
+
+	public String getAuthor() {
+		return author;
+	}
+
+	public void setAuthor(String author) {
+		this.author = author;
+	}
+
+	public Integer getType() {
+		return type;
+	}
+
+	public void setType(Integer type) {
+		this.type = type;
+	}
+
+	public Integer getHot() {
+		return hot;
+	}
+
+	public void setHot(Integer hot) {
+		this.hot = hot;
+	}
+
+	public String getSource() {
+		return source;
+	}
+
+	public void setSource(String source) {
+		this.source = source;
+	}
+
+	public String getSourceUrl() {
+		return sourceUrl;
+	}
+
+	public void setSourceUrl(String sourceUrl) {
+		this.sourceUrl = sourceUrl;
+	}
+
+	public String getSummary() {
+		return summary;
+	}
+
+	public void setSummary(String summary) {
+		this.summary = summary;
+	}
+
+	public String getContent() {
+		return content;
+	}
+
+	public void setContent(String content) {
+		this.content = content;
+	}
+
+}

+ 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) {
+
+	}
 
 }

+ 49 - 1
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.utils.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;
@@ -45,6 +48,51 @@ public class NewsController extends BaseController {
 	@RequestMapping(value = "/portal/news/newsDetails", method = RequestMethod.GET)
 	public ModelAndView portalNewsNewsDetails(HttpServletRequest request, ModelAndView modelview) {
 		modelview.setViewName("/portal/news/newsDetails");
+		//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.cleanPortalList();
+		}
+		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;
+		}
+		res.setData(newsService.findPortalList(pSize, pNo, 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;
+	}
 }

+ 60 - 0
src/main/java/com/goafanti/news/enums/NewsFields.java

@@ -0,0 +1,60 @@
+package com.goafanti.news.enums;
+
+import java.util.HashMap;
+import java.util.Map;
+
+
+public enum NewsFields {
+	
+	ID("id", "科技讲堂ID"),
+	TITLE("title", "标题"),
+	TITLEIMG("titleImg", "题图url"),
+	AUTHOR("author", "作者"),
+	TYPE("type", "类型"),
+	HOT("hot", "大咖说页面展示标记"),
+	SOURCE("source", "来源"),
+	SOURCEURL("sourceUrl", "来源url"),
+	SUMMARY("summary", "简介"),
+	CONTENT("content", "内容"),
+	OTHER("", "未知参数");
+	
+	private String	code;
+	private String	desc;
+	
+	private static Map<String, NewsFields> status = new HashMap<String, NewsFields>();
+	
+	private NewsFields(String code, String desc) {
+		this.code = code;
+		this.desc = desc;
+	}
+	
+	static {
+		for (NewsFields value : NewsFields.values()) {
+			status.put(value.getCode(), value);
+		}
+	}
+	
+	public static NewsFields getField(String code) {
+		if (containsType(code)) {
+			return status.get(code);
+		}
+		return OTHER;
+	}
+	
+	public static String getFieldDesc(String code) {
+		return getField(code).getDesc();
+	}
+
+	public static boolean containsType(String code) {
+		return status.containsKey(code);
+	}
+	
+	public String getCode() {
+		return code;
+	}
+
+	public String getDesc() {
+		return desc;
+	}
+
+}

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

@@ -1,5 +1,6 @@
 package com.goafanti.news.service;
 
+import java.text.ParseException;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -13,10 +14,14 @@ import org.springframework.cache.annotation.Cacheable;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
+import com.goafanti.common.constant.AFTConstants;
 import com.goafanti.common.dao.NewsMapper;
 import com.goafanti.common.model.News;
+import com.goafanti.common.utils.DateUtils;
 import com.goafanti.common.utils.LoggerUtils;
+import com.goafanti.common.utils.StringUtils;
 import com.goafanti.core.mybatis.BaseMybatisDao;
+import com.goafanti.core.mybatis.page.Pagination;
 import com.goafanti.news.bo.NewsSummary;
 
 @Service
@@ -57,5 +62,85 @@ public class NewsService extends BaseMybatisDao<NewsMapper> {
 		newsMapper.insert(news);
 		return news;
 	}
+	
+	@CachePut(value = "NewsCache", key = "'News:'+#id")
+	public News update(long id, News news) {
+		newsMapper.updateByPrimaryKeyWithBLOBs(news);
+		return news;
+	}
+
+	@SuppressWarnings("unchecked")
+	public Pagination<News> listNews(Integer type, String title, String author, String startCreateTime,
+			String endCreateTime, String source, Integer hot, Integer pNo, Integer pSize) {
+		Map<String, Object> params = new HashMap<>();
+		if (null != type) {
+			params.put("type", type);
+		}
+
+		if (StringUtils.isNotBlank(title)) {
+			params.put("title", title);
+		}
+
+		if (StringUtils.isNotBlank(author)) {
+			params.put("author", author);
+		}
+
+		if (StringUtils.isNotBlank(startCreateTime)) {
+			try {
+				params.put("sDate", DateUtils.parseDate(startCreateTime, AFTConstants.YYYYMMDD));
+			} catch (ParseException e) {
+			}
+		}
+
+		if (StringUtils.isNotBlank(endCreateTime)) {
+			try {
+				params.put("eDate", DateUtils.addDays(DateUtils.parseDate(endCreateTime, AFTConstants.YYYYMMDD), 1));
+			} catch (ParseException e) {
+			}
+		}
+
+		if (StringUtils.isNotBlank(source)) {
+			params.put("source", source);
+		}
+		
+		if (null != hot){
+			params.put("hot", hot);
+		}
+
+		if (pNo == null || pNo < 0) {
+			pNo = 1;
+		}
+
+		if (pSize == null || pSize < 0 || pSize > 10) {
+			pSize = 10;
+		}
+		return (Pagination<News>) findPage("findNewsListByPage", "findNewsCount", params, pNo, pSize);
+	}
+
+	public News findNewsDetail(Long id) {
+		return newsMapper.selectByPrimaryKey(id);
+	}
+
+	public int batchDeleteByPrimaryKey(List<String> id) {
+		return newsMapper.batchDeleteByPrimaryKey(id);
+	}
+	
+	@Cacheable(value = "NewsPortalListCache", key = "'NewsPortalList:Page:'+#pageNo+'Type:'+#type+'Size:'+#pageSize")
+	public List<NewsSummary> findPortalList(Integer pSize, Integer pNo, Integer type) {
+		Map<String, Object> params = new HashMap<String, Object>();
+		params.put("type", type);
+		
+		params.put("pageSize", pSize);
+		params.put("pageNo", pNo);
+		return newsMapper.findPortalList(params);
+	}
+	
+	@CacheEvict(value = "NewsPortalListCache", allEntries = true)
+	public void cleanPortalList() {
+		LoggerUtils.debug(logger, "清除门户端新闻列表缓存:[%s]");
+		
+	}
+
+	
 
 }