Reiskuchen 5 лет назад
Родитель
Сommit
609291a5f2

+ 3 - 2
official_backend/src/main/java/com/hssx/ysofficial/controller/ArticleController.java

@@ -9,6 +9,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
 
 import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.multipart.MultipartFile;
 
 /**
  * <p>
@@ -40,8 +41,8 @@ public class ArticleController {
     }
 
     @RequestMapping("/editArticle")
-    public HttpRespMsg editArticle(Article article){
-        return articleService.editArticle(article);
+    public HttpRespMsg editArticle(Article article, MultipartFile multipartFile){
+        return articleService.editArticle(article, multipartFile);
     }
 
     @RequestMapping("/deleteArticleById")

+ 19 - 7
official_backend/src/main/java/com/hssx/ysofficial/entity/Article.java

@@ -12,11 +12,11 @@ import lombok.experimental.Accessors;
 
 /**
  * <p>
- * 
+ * 第一个数据是公司优势 其他是案例
  * </p>
  *
  * @author Reiskuchen
- * @since 2019-10-23
+ * @since 2019-10-24
  */
 @Data
 @EqualsAndHashCode(callSuper = false)
@@ -33,35 +33,47 @@ public class Article extends Model<Article> {
     private Integer id;
 
     /**
-     * the title of articles
+     * 案例的名字
      */
     @TableField("title")
     private String title;
 
     /**
-     * the content of article
+     * 案例内容
      */
     @TableField("content")
     private String content;
 
     /**
-     * the type of article
+     * 案例种类: 公司优势或案例
      */
     @TableField("type")
     private String type;
 
     /**
-     * whether the article is sticked or not
+     * 是否显示在首页 0不显示 1显示
      */
     @TableField("sticky")
     private Integer sticky;
 
     /**
-     * the position of article in the list
+     * 位置 应该按照位置排序
      */
     @TableField("position")
     private Integer position;
 
+    /**
+     * 图片地址
+     */
+    @TableField("image_url")
+    private String imageUrl;
+
+    /**
+     * 简介
+     */
+    @TableField("introduction")
+    private String introduction;
+
 
     @Override
     protected Serializable pkVal() {

+ 20 - 2
official_backend/src/main/java/com/hssx/ysofficial/entity/BannerPictures.java

@@ -13,11 +13,11 @@ import lombok.experimental.Accessors;
 
 /**
  * <p>
- * the pictures of banner
+ * 轮播图图片
  * </p>
  *
  * @author Reiskuchen
- * @since 2019-10-23
+ * @since 2019-10-24
  */
 @Data
 @EqualsAndHashCode(callSuper = false)
@@ -27,21 +27,39 @@ public class BannerPictures extends Model<BannerPictures> {
 
     private static final long serialVersionUID=1L;
 
+    /**
+     * id
+     */
     @TableId(value = "id", type = IdType.AUTO)
     private Integer id;
 
+    /**
+     * 轮播图url
+     */
     @TableField("url")
     private String url;
 
+    /**
+     * 轮播图文件名
+     */
     @TableField("file_name")
     private String fileName;
 
+    /**
+     * 轮播图大小
+     */
     @TableField("file_size")
     private String fileSize;
 
+    /**
+     * 轮播图文件类型
+     */
     @TableField("file_type")
     private String fileType;
 
+    /**
+     * 上传时间
+     */
     @TableField("upload_indate")
     private LocalDateTime uploadIndate;
 

+ 5 - 5
official_backend/src/main/java/com/hssx/ysofficial/entity/Comment.java

@@ -17,7 +17,7 @@ import lombok.experimental.Accessors;
  * </p>
  *
  * @author Reiskuchen
- * @since 2019-10-23
+ * @since 2019-10-24
  */
 @Data
 @EqualsAndHashCode(callSuper = false)
@@ -34,25 +34,25 @@ public class Comment extends Model<Comment> {
     private Integer id;
 
     /**
-     * the name of customer
+     * 留言者姓名
      */
     @TableField("name")
     private String name;
 
     /**
-     * the phone number of customer
+     * 留言者联系方式
      */
     @TableField("phone")
     private String phone;
 
     /**
-     * the main content left by customer
+     * 留言内容
      */
     @TableField("comment")
     private String comment;
 
     /**
-     * the timestamp when the customer left the message
+     * 留言时间
      */
     @TableField("indate")
     private LocalDateTime indate;

+ 17 - 2
official_backend/src/main/java/com/hssx/ysofficial/entity/Cooperations.java

@@ -12,11 +12,11 @@ import lombok.experimental.Accessors;
 
 /**
  * <p>
- * the cooperations of client company and high school
+ * 合作伙伴
  * </p>
  *
  * @author Reiskuchen
- * @since 2019-10-23
+ * @since 2019-10-24
  */
 @Data
 @EqualsAndHashCode(callSuper = false)
@@ -29,18 +29,33 @@ public class Cooperations extends Model<Cooperations> {
     @TableId(value = "id", type = IdType.AUTO)
     private Integer id;
 
+    /**
+     * 合作者名称
+     */
     @TableField("name")
     private String name;
 
+    /**
+     * 合作者的描述
+     */
     @TableField("description")
     private String description;
 
+    /**
+     * 一张描述用的图的url
+     */
     @TableField("image_url")
     private String imageUrl;
 
+    /**
+     * 合作者种类: 学校或公司
+     */
     @TableField("type")
     private Integer type;
 
+    /**
+     * 是否显示于首页 0为不显示 1为显示
+     */
     @TableField("sticky")
     private Integer sticky;
 

+ 11 - 2
official_backend/src/main/java/com/hssx/ysofficial/entity/User.java

@@ -12,11 +12,11 @@ import lombok.experimental.Accessors;
 
 /**
  * <p>
- * 
+ * 用户
  * </p>
  *
  * @author Reiskuchen
- * @since 2019-10-23
+ * @since 2019-10-24
  */
 @Data
 @EqualsAndHashCode(callSuper = false)
@@ -26,12 +26,21 @@ public class User extends Model<User> {
 
     private static final long serialVersionUID=1L;
 
+    /**
+     * id
+     */
     @TableId(value = "id", type = IdType.AUTO)
     private Integer id;
 
+    /**
+     * 用户名
+     */
     @TableField("username")
     private String username;
 
+    /**
+     * 密码
+     */
     @TableField("password")
     private String password;
 

+ 1 - 1
official_backend/src/main/java/com/hssx/ysofficial/mapper/ArticleMapper.java

@@ -14,5 +14,5 @@ import org.apache.ibatis.annotations.Select;
  */
 public interface ArticleMapper extends BaseMapper<Article> {
     @Select("SELECT MAX(position)+1 AS new_position FROM article;")
-    public Integer getNewPosition();
+    Integer getNewPosition();
 }

+ 2 - 1
official_backend/src/main/java/com/hssx/ysofficial/service/ArticleService.java

@@ -3,6 +3,7 @@ package com.hssx.ysofficial.service;
 import com.hssx.ysofficial.entity.Article;
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.hssx.ysofficial.utility.HttpRespMsg;
+import org.springframework.web.multipart.MultipartFile;
 
 /**
  * <p>
@@ -16,7 +17,7 @@ public interface ArticleService extends IService<Article> {
     HttpRespMsg getArticleAll();
     HttpRespMsg getArticleById(Integer id);
     HttpRespMsg getArticleByType(String Type);
-    HttpRespMsg editArticle(Article article);
+    HttpRespMsg editArticle(Article article, MultipartFile multipartFile);
     HttpRespMsg deleteArticleById(Integer id);
     HttpRespMsg switchSticky(Integer id);
     HttpRespMsg switchPosition(Integer id, Integer position);

+ 31 - 2
official_backend/src/main/java/com/hssx/ysofficial/service/impl/ArticleServiceImpl.java

@@ -7,12 +7,16 @@ import com.hssx.ysofficial.service.ArticleService;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.hssx.ysofficial.utility.HttpRespMsg;
 import org.hibernate.validator.constraints.EAN;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
+import org.springframework.web.multipart.MultipartFile;
 
 import javax.annotation.Resource;
+import java.io.File;
 import java.sql.SQLOutput;
 import java.util.HashMap;
 import java.util.Map;
+import java.util.UUID;
 
 /**
  * <p>
@@ -24,6 +28,13 @@ import java.util.Map;
  */
 @Service
 public class ArticleServiceImpl extends ServiceImpl<ArticleMapper, Article> implements ArticleService {
+
+    @Value("${upload.path}")
+    private String uploadPath;
+
+    @Value("${download.path}")
+    private String downloadPath;
+
     @Resource
     private ArticleMapper articleMapper;
 
@@ -56,11 +67,29 @@ public class ArticleServiceImpl extends ServiceImpl<ArticleMapper, Article> impl
     }
 
     @Override
-    public HttpRespMsg editArticle(Article article){
+    public HttpRespMsg editArticle(Article article, MultipartFile multipartFile){
         HttpRespMsg httpRespMsg = new HttpRespMsg();
         if(article != null){
             Integer id = article.getId();
-            if(id == null){
+
+            if(multipartFile != null){
+                String fileName = multipartFile.getOriginalFilename();
+                File direction = new File(uploadPath);
+                String rand = UUID.randomUUID().toString().replaceAll("-", "");
+                String suffix = fileName.substring(fileName.lastIndexOf("."));
+                String storedFileName = rand + suffix;
+                try {
+                    File savedFile = new File(direction, storedFileName);
+                    savedFile.createNewFile();
+                    multipartFile.transferTo(savedFile);
+                } catch (Exception e) {
+                    e.printStackTrace();
+                }
+                article.setImageUrl("/upload/" + storedFileName);
+            }
+
+            if(id == -1){
+                article.setId(null);
                 article.setPosition(articleMapper.getNewPosition());
                 articleMapper.insert(article);
             }else{

+ 6 - 0
official_backend/src/main/resources/application.properties

@@ -21,6 +21,12 @@ spring.datasource.hikari.ConnectionTimeout=60000
 spring.datasource.hikari.ValidationTimeout=3000
 spring.datasource.hikari.LoginTimeout=5
 
+spring.servlet.multipart.enabled=true
+spring.servlet.multipart.file-size-threshold=0
+spring.servlet.multipart.max-file-size=100MB
+spring.servlet.multipart.max-request-size=100MB
+spring.servlet.multipart.resolve-lazily=false
+
 #ÎļþÉÏ´«Â·¾¶
 upload.path=D:/ysofficial/upload/
 

+ 3 - 1
official_backend/src/main/resources/mapper/ArticleMapper.xml

@@ -10,11 +10,13 @@
         <result column="type" property="type" />
         <result column="sticky" property="sticky" />
         <result column="position" property="position" />
+        <result column="image_url" property="imageUrl" />
+        <result column="introduction" property="introduction" />
     </resultMap>
 
     <!-- 通用查询结果列 -->
     <sql id="Base_Column_List">
-        id, title, content, type, sticky, position
+        id, title, content, type, sticky, position, image_url, introduction
     </sql>
 
 </mapper>