Explorar o código

更改新增新闻功能

xusonglin %!s(int64=5) %!d(string=hai) anos
pai
achega
a55dc1e997

+ 17 - 0
src/main/java/com/jkcredit/sysnews/enums/CommonEnumStatus.java

@@ -0,0 +1,17 @@
+package com.jkcredit.sysnews.enums;
+
+import com.jkcredit.sysnews.enums.base.EnumStatus;
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+
+@Getter
+@AllArgsConstructor
+public enum CommonEnumStatus implements EnumStatus {
+    /**
+     * 未知状态
+     */
+    UNKNOWN_STATUS(-1, "未知状态");
+
+    private Integer value;
+    private String desc;
+}

+ 34 - 0
src/main/java/com/jkcredit/sysnews/enums/PhotoTypeEnum.java

@@ -0,0 +1,34 @@
+package com.jkcredit.sysnews.enums;
+
+import com.jkcredit.sysnews.enums.base.EnumStatus;
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+
+@Getter
+@AllArgsConstructor
+public enum PhotoTypeEnum implements EnumStatus {
+    //图片类型;
+    //1.首页大图;2.首页腰封图;3.新闻图片;4.友情链接图片
+    /**
+     * 首页大图
+     */
+    HOME_PAGE_FIRST_PHOTO(1, "首页大图"),
+
+    /**
+     * 首页腰封图
+     */
+    HOME_PAGE_MIDDLE_PHOTO(2, "首页腰封图"),
+
+    /**
+     * 新闻图片
+     */
+    NEWS_PHOTO(3, "新闻图片"),
+
+    /**
+     * 友情链接图片
+     */
+    LINKS_PHOTO(4, "友情链接图片");
+
+    private Integer value;
+    private String desc;
+}

+ 23 - 0
src/main/java/com/jkcredit/sysnews/enums/base/EnumStatus.java

@@ -0,0 +1,23 @@
+//
+// Source code recreated from a .class file by IntelliJ IDEA
+// (powered by Fernflower decompiler)
+//
+
+package com.jkcredit.sysnews.enums.base;
+
+
+import com.jkcredit.sysnews.spi.lang.exception.ServiceException;
+import com.jkcredit.sysnews.util.EnumStatusUtils;
+
+public interface EnumStatus extends IEnumStatus<Integer> {
+
+    static EnumStatus getEnumStatus(Class<?> typeClass, int value) {
+        EnumStatus status = EnumStatusUtils.getStatusByValue(typeClass, value);
+        if (status == null) {
+            throw new ServiceException("枚举值未定义, typeClass = " + typeClass.getCanonicalName() + ", Value = " + value);
+        } else {
+            return status;
+        }
+    }
+
+}

+ 23 - 0
src/main/java/com/jkcredit/sysnews/enums/base/IEnumStatus.java

@@ -0,0 +1,23 @@
+package com.jkcredit.sysnews.enums.base;
+
+/**
+ * @description:
+ * @author: xusonglin
+ * @create: 2020/3/5 10:58
+ * @version: V1.0
+ **/
+public interface IEnumStatus<T> {
+    /**
+     * 获取枚举值
+     *
+     * @return 枚举值
+     */
+    T getValue();
+
+    /**
+     * 获取枚举描述
+     *
+     * @return 枚举描述
+     */
+    String getDesc();
+}

+ 3 - 0
src/main/java/com/jkcredit/sysnews/model/dto/newsArticle/NewsArticleDto.java

@@ -1,6 +1,7 @@
 package com.jkcredit.sysnews.model.dto.newsArticle;
 
 import lombok.Data;
+import org.springframework.web.multipart.MultipartFile;
 
 import java.io.Serializable;
 
@@ -24,4 +25,6 @@ public class NewsArticleDto implements Serializable {
     private Long photoId;
 
     private Long navigationBarId;
+
+    private MultipartFile photo;
 }

+ 16 - 0
src/main/java/com/jkcredit/sysnews/resource/web/navigationBar/NavigationBarResource.java

@@ -0,0 +1,16 @@
+package com.jkcredit.sysnews.resource.web.navigationBar;
+
+import com.jkcredit.sysnews.resource.base.WebResource;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.web.bind.annotation.RestController;
+
+/**
+ * @description:
+ * @author: xusonglin
+ * @create: 2020/3/2 22:25
+ * @version: V1.0
+ **/
+@Slf4j
+@RestController
+public class NavigationBarResource extends WebResource {
+}

+ 29 - 0
src/main/java/com/jkcredit/sysnews/resource/web/newsArticle/fb/NewsArticleAddFB.java

@@ -0,0 +1,29 @@
+package com.jkcredit.sysnews.resource.web.newsArticle.fb;
+
+import lombok.Data;
+import org.springframework.web.multipart.MultipartFile;
+
+import java.io.Serializable;
+
+/**
+ * @description:
+ * @author: xusonglin
+ * @create: 2020/3/5 10:26
+ * @version: V1.0
+ **/
+@Data
+public class NewsArticleAddFB implements Serializable {
+    private static final long serialVersionUID = 595360654408025003L;
+
+    private Long id;
+
+    private String title;
+
+    private String newsAbstract;
+
+    private String content;
+
+    private MultipartFile photo;
+
+    private Long navigationBarId;
+}

+ 3 - 0
src/main/java/com/jkcredit/sysnews/resource/web/newsArticle/fb/NewsArticleFB.java

@@ -1,6 +1,7 @@
 package com.jkcredit.sysnews.resource.web.newsArticle.fb;
 
 import lombok.Data;
+import org.springframework.web.multipart.MultipartFile;
 
 import java.io.Serializable;
 
@@ -25,4 +26,6 @@ public class NewsArticleFB implements Serializable {
     private Long photoId;
 
     private Long navigationBarId;
+
+    private MultipartFile photo;
 }

+ 19 - 1
src/main/java/com/jkcredit/sysnews/service/newsArticle/NewsArticleServiceImpl.java

@@ -2,10 +2,13 @@ package com.jkcredit.sysnews.service.newsArticle;
 
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.jkcredit.sysnews.enums.PhotoTypeEnum;
 import com.jkcredit.sysnews.mapper.NewsArticleMapper;
 import com.jkcredit.sysnews.model.dto.newsArticle.NewsArticleDto;
+import com.jkcredit.sysnews.model.dto.photo.PhotoDto;
 import com.jkcredit.sysnews.model.po.newsArticle.NewsArticlePo;
 import com.jkcredit.sysnews.model.vo.newsArticle.NewsArticleVo;
+import com.jkcredit.sysnews.model.vo.photo.PhotoVo;
 import com.jkcredit.sysnews.service.base.BaseService;
 import com.jkcredit.sysnews.service.photo.PhotoService;
 import com.jkcredit.sysnews.spi.lang.constant.CommonConstant;
@@ -14,6 +17,7 @@ import com.jkcredit.sysnews.util.AssertUtils;
 import com.jkcredit.sysnews.util.BeanUtil;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang.StringUtils;
+import org.apache.commons.lang.enums.EnumUtils;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
@@ -61,10 +65,24 @@ public class NewsArticleServiceImpl extends BaseService implements NewsArticleSe
     @Override
     public void saveNewsArticle(NewsArticleDto newsArticleDto) {
         validate(newsArticleDto);
+
+        PhotoDto photoDto = new PhotoDto();
+        photoDto.setName(newsArticleDto.getTitle());
+        photoDto.setType(PhotoTypeEnum.NEWS_PHOTO.getValue());
+        photoDto.setPhoto(newsArticleDto.getPhoto());
+
+        PhotoVo photoVo;
+        try {
+            photoVo = photoService.savePhoto(photoDto);
+        } catch (ServiceException e) {
+            log.error("新增图片失败,失败原因:{}", e.getMessage());
+            throw new ServiceException("新增图片失败");
+        }
+
         NewsArticlePo newsArticlePo = new NewsArticlePo();
         BeanUtil.copyProperties(newsArticlePo, newsArticleDto);
         newsArticlePo.setCreateTime(new Date());
-
+        newsArticlePo.setPhotoId(photoVo.getId());
         try {
             mapper.insert(newsArticlePo);
         } catch (Exception e) {

+ 41 - 0
src/main/java/com/jkcredit/sysnews/util/EnumStatusUtils.java

@@ -0,0 +1,41 @@
+package com.jkcredit.sysnews.util;
+
+import com.jkcredit.sysnews.enums.CommonEnumStatus;
+import com.jkcredit.sysnews.enums.base.EnumStatus;
+import lombok.NoArgsConstructor;
+
+
+@NoArgsConstructor
+public final class EnumStatusUtils {
+
+    public static EnumStatus getStatusByValue(Class<?> enums, Integer value) {
+        if (enums.isEnum()) {
+            Object[] statuses = enums.getEnumConstants();
+
+            for (Object o : statuses) {
+                EnumStatus status = (EnumStatus) o;
+                if (status.getValue().equals(value)) {
+                    return status;
+                }
+            }
+        }
+
+        return CommonEnumStatus.UNKNOWN_STATUS;
+    }
+
+    public static EnumStatus getStatusByDesc(Class<?> enums, String desc) {
+        if (enums.isEnum()) {
+            Object[] statuses = enums.getEnumConstants();
+
+            for (Object o : statuses) {
+                EnumStatus status = (EnumStatus) o;
+                if (status.getDesc().equals(desc)) {
+                    return status;
+                }
+            }
+        }
+
+        return CommonEnumStatus.UNKNOWN_STATUS;
+    }
+
+}