소스 검색

news add&&update

Antiloveg 8 년 전
부모
커밋
fe6c1a071a

+ 0 - 1
schema/20170626-activities-news-billings.sql

@@ -11,7 +11,6 @@ CREATE TABLE `news` (
   `source` varchar(45) DEFAULT NULL COMMENT '来源',
   `source_url` varchar(255) DEFAULT NULL COMMENT '来源url',
   `summary` varchar(144) DEFAULT NULL COMMENT '简介',
-  `news_date` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '新闻时间',
   PRIMARY KEY (`id`)
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='新闻资讯';
 

+ 20 - 4
src/main/java/com/goafanti/admin/controller/AdminNewsApiController.java

@@ -1,12 +1,12 @@
 package com.goafanti.admin.controller;
 
 import java.text.ParseException;
-import java.util.UUID;
 
 import javax.annotation.Resource;
 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;
@@ -19,6 +19,7 @@ import com.goafanti.common.controller.BaseApiController;
 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.news.bo.InputNews;
 import com.goafanti.news.enums.NewsFields;
 import com.goafanti.news.service.NewsService;
@@ -31,6 +32,8 @@ import com.goafanti.news.service.NewsService;
 public class AdminNewsApiController extends BaseApiController {
 	@Resource
 	private NewsService newsService;
+	@Autowired
+	private JDBCIdGenerator	idGenerator;
 
 	/**
 	 * 新闻列表
@@ -70,8 +73,7 @@ public class AdminNewsApiController extends BaseApiController {
 		if (!res.getError().isEmpty()) {
 			return res;
 		}
-
-		newsService.save(UUID.randomUUID().timestamp(), (News) res.getData());
+		newsService.save(idGenerator.generateId(), (News) res.getData());
 		return res;
 	}
 
@@ -99,6 +101,20 @@ public class AdminNewsApiController extends BaseApiController {
 		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;
+	}
 
 	private Result disposeInputNews(Result res, InputNews news, String createTimeFormattedDate) {
 		if (StringUtils.isBlank(news.getTitle())) {
@@ -125,5 +141,5 @@ public class AdminNewsApiController extends BaseApiController {
 		res.setData(n);
 		return res;
 	}
-
+	
 }

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

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

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

@@ -13,14 +13,13 @@
     <result column="source" jdbcType="VARCHAR" property="source" />
     <result column="source_url" jdbcType="VARCHAR" property="sourceUrl" />
     <result column="summary" jdbcType="VARCHAR" property="summary" />
-    <result column="news_date" jdbcType="TIMESTAMP" property="newsDate" />
   </resultMap>
   <resultMap extends="BaseResultMap" id="ResultMapWithBLOBs" type="com.goafanti.common.model.News">
     <result column="content" jdbcType="LONGVARCHAR" property="content" />
   </resultMap>
   <sql id="Base_Column_List">
     id, create_time, edit_time, title, title_img, author, type, hot, source, source_url, 
-    summary, newsDate
+    summary
   </sql>
   <sql id="Blob_Column_List">
     content
@@ -41,13 +40,12 @@
     insert into news (id, create_time, edit_time, 
       title, title_img, author, 
       type, hot, source, 
-      source_url, summary, content, news_date
+      source_url, summary, content
       )
     values (#{id,jdbcType=BIGINT}, #{createTime,jdbcType=TIMESTAMP}, #{editTime,jdbcType=TIMESTAMP}, 
       #{title,jdbcType=VARCHAR}, #{titleImg,jdbcType=VARCHAR}, #{author,jdbcType=VARCHAR}, 
       #{type,jdbcType=INTEGER}, #{hot,jdbcType=INTEGER}, #{source,jdbcType=VARCHAR}, 
-      #{sourceUrl,jdbcType=VARCHAR}, #{summary,jdbcType=VARCHAR}, #{content,jdbcType=LONGVARCHAR},
-      #{newsDate,jdbcType=TIMESTAMP}
+      #{sourceUrl,jdbcType=VARCHAR}, #{summary,jdbcType=VARCHAR}, #{content,jdbcType=LONGVARCHAR}
       )
   </insert>
   <insert id="insertSelective" parameterType="com.goafanti.common.model.News">
@@ -89,9 +87,6 @@
       <if test="content != null">
         content,
       </if>
-      <if test="newsDate != null">
-        news_date,
-      </if>
     </trim>
     <trim prefix="values (" suffix=")" suffixOverrides=",">
       <if test="id != null">
@@ -130,9 +125,6 @@
       <if test="content != null">
         #{content,jdbcType=LONGVARCHAR},
       </if>
-      <if test="newsDate != null">
-        #{newsDate,jdbcType=TIMESTAMP},
-      </if>
     </trim>
   </insert>
   <update id="updateByPrimaryKeySelective" parameterType="com.goafanti.common.model.News">
@@ -171,9 +163,6 @@
       <if test="content != null">
         content = #{content,jdbcType=LONGVARCHAR},
       </if>
-      <if test="newsDate != null">
-        news_date  = #{newsDate ,jdbcType=TIMESTAMP},
-      </if>
     </set>
     where id = #{id,jdbcType=BIGINT}
   </update>
@@ -189,8 +178,7 @@
       source = #{source,jdbcType=VARCHAR},
       source_url = #{sourceUrl,jdbcType=VARCHAR},
       summary = #{summary,jdbcType=VARCHAR},
-      content = #{content,jdbcType=LONGVARCHAR},
-      news_date  = #{newsDate ,jdbcType=TIMESTAMP}
+      content = #{content,jdbcType=LONGVARCHAR}
     where id = #{id,jdbcType=BIGINT}
   </update>
   <update id="updateByPrimaryKey" parameterType="com.goafanti.common.model.News">
@@ -204,8 +192,7 @@
       hot = #{hot,jdbcType=INTEGER},
       source = #{source,jdbcType=VARCHAR},
       source_url = #{sourceUrl,jdbcType=VARCHAR},
-      summary = #{summary,jdbcType=VARCHAR},
-      news_date  = #{newsDate ,jdbcType=TIMESTAMP}
+      summary = #{summary,jdbcType=VARCHAR}
     where id = #{id,jdbcType=BIGINT}
   </update>
   

+ 0 - 15
src/main/java/com/goafanti/common/model/News.java

@@ -4,7 +4,6 @@ import java.util.Date;
 
 import org.apache.commons.lang3.time.DateFormatUtils;
 
-import com.fasterxml.jackson.annotation.JsonIgnore;
 import com.goafanti.common.constant.AFTConstants;
 
 public class News {
@@ -68,11 +67,6 @@ public class News {
 	 */
 	private String	content;
 
-	/**
-	 * 新闻日期
-	 */
-	private Date	newsDate;
-
 	public Long getId() {
 		return id;
 	}
@@ -168,15 +162,6 @@ public class News {
 	public void setContent(String content) {
 		this.content = content;
 	}
-	
-	@JsonIgnore
-	public Date getNewsDate() {
-		return newsDate;
-	}
-
-	public void setNewsDate(Date newsDate) {
-		this.newsDate = newsDate;
-	}
 
 	public String getCreateTimeFormattedDate() {
 		if (this.createTime == null) {

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

@@ -8,8 +8,6 @@ import com.goafanti.common.constant.ErrorConstants;
 
 public class InputNews {
 	
-	@Max(value = 999999999999999999L, message = "{" + ErrorConstants.PARAM_ERROR + "}")
-	@Min(value = 0, message = "{" + ErrorConstants.PARAM_ERROR + "}")
 	private Long	id;
 	
 	@Size(min = 0, max = 45, message = "{" + ErrorConstants.PARAM_SIZE_ERROR + "}")

+ 4 - 1
src/main/java/com/goafanti/news/service/NewsService.java

@@ -65,7 +65,6 @@ public class NewsService extends BaseMybatisDao<NewsMapper> {
 	
 	@CachePut(value = "NewsCache", key = "'News:'+#id")
 	public News update(long id, News news) {
-		news.setId(id);
 		newsMapper.updateByPrimaryKeyWithBLOBs(news);
 		return news;
 	}
@@ -118,6 +117,10 @@ public class NewsService extends BaseMybatisDao<NewsMapper> {
 		return (Pagination<News>) findPage("findNewsListByPage", "findNewsCount", params, pNo, pSize);
 	}
 
+	public News findNewsDetail(Long id) {
+		return newsMapper.selectByPrimaryKey(id);
+	}
+
 	
 
 }