Bladeren bron

后台特色以及其标题的增删改查

Reiskuchen 5 jaren geleden
bovenliggende
commit
27323db3ed

+ 25 - 2
official_backend/src/main/java/com/hssx/ysofficial/controller/FeedbackController.java

@@ -8,6 +8,7 @@ import org.springframework.beans.factory.annotation.Autowired;
 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>
@@ -23,26 +24,48 @@ public class FeedbackController {
     @Autowired
     private FeedbackService feedbackService;
 
+    /**
+     * 获取用户说模块的标题
+     */
     @RequestMapping("/getFeedbackTitle")
     public HttpRespMsg getFeedbackTitle() {
         return feedbackService.getFeedbackTitle();
     }
 
+    /**
+     * 更新用户说模块的标题
+     * content 标题内容
+     */
     @RequestMapping("/updateFeedbackTitle")
     public HttpRespMsg updateFeedbackTitle(@RequestParam String content) {
         return feedbackService.updateFeedbackTitle(content);
     }
 
+    /**
+     * 获取用户说模块具体的信息列表
+     */
     @RequestMapping("/listFeedback")
     public HttpRespMsg listFeedback() {
         return feedbackService.listFeedback();
     }
 
+    /**
+     * 新增或修改某个用户说模块具体的信息
+     * id 修改时需要的id
+     * companyName 公司名称
+     * clientName 客户名称和职称
+     * description 具体描述
+     * file 可上传的图片
+     */
     @RequestMapping("/insertOrUpdateFeedback")
-    public HttpRespMsg insertOrUpdateFeedback(Feedback feedback) {
-        return feedbackService.insertOrUpdateFeedback(feedback);
+    public HttpRespMsg insertOrUpdateFeedback(Feedback feedback, MultipartFile file) {
+        return feedbackService.insertOrUpdateFeedback(feedback, file);
     }
 
+    /**
+     * 删除某个用户说模块具体的信息
+     * id 要删除的id
+     */
     @RequestMapping("/deleteFeedback")
     public HttpRespMsg deleteFeedback(@RequestParam Integer id) {
         return feedbackService.deleteFeedback(id);

+ 6 - 0
official_backend/src/main/java/com/hssx/ysofficial/entity/Feedback.java

@@ -50,6 +50,12 @@ public class Feedback extends Model<Feedback> {
     @TableField("description")
     private String description;
 
+    /**
+     * 图片
+     */
+    @TableField("pic_url")
+    private String picUrl;
+
 
     @Override
     protected Serializable pkVal() {

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

@@ -3,6 +3,7 @@ package com.hssx.ysofficial.service;
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.hssx.ysofficial.entity.Feedback;
 import com.hssx.ysofficial.utility.HttpRespMsg;
+import org.springframework.web.multipart.MultipartFile;
 
 /**
  * <p>
@@ -19,7 +20,7 @@ public interface FeedbackService extends IService<Feedback> {
 
     HttpRespMsg listFeedback();
 
-    HttpRespMsg insertOrUpdateFeedback(Feedback feedback);
+    HttpRespMsg insertOrUpdateFeedback(Feedback feedback, MultipartFile multipartFile);
 
     HttpRespMsg deleteFeedback(Integer id);
 }

+ 82 - 1
official_backend/src/main/java/com/hssx/ysofficial/service/impl/FeedbackServiceImpl.java

@@ -1,10 +1,20 @@
 package com.hssx.ysofficial.service.impl;
 
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.hssx.ysofficial.entity.Feedback;
+import com.hssx.ysofficial.entity.Parameter;
 import com.hssx.ysofficial.mapper.FeedbackMapper;
+import com.hssx.ysofficial.mapper.ParameterMapper;
 import com.hssx.ysofficial.service.FeedbackService;
-import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.hssx.ysofficial.utility.HttpRespMsg;
+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.util.UUID;
 
 /**
  * <p>
@@ -17,4 +27,75 @@ import org.springframework.stereotype.Service;
 @Service
 public class FeedbackServiceImpl extends ServiceImpl<FeedbackMapper, Feedback> implements FeedbackService {
 
+    @Value("${upload.path}")
+    private String uploadPath;
+
+    @Resource
+    private ParameterMapper parameterMapper;
+
+    @Resource
+    private FeedbackMapper feedbackMapper;
+
+    @Override
+    public HttpRespMsg getFeedbackTitle() {
+        HttpRespMsg httpRespMsg = new HttpRespMsg();
+        httpRespMsg.data = parameterMapper.selectById(1); //id是1的即为标题
+        return httpRespMsg;
+    }
+
+    @Override
+    public HttpRespMsg updateFeedbackTitle(String content) {
+        HttpRespMsg httpRespMsg = new HttpRespMsg();
+        Parameter parameter = parameterMapper.selectById(1).setParameterValue(content);
+        if (parameterMapper.updateById(parameter) == 0) {
+            httpRespMsg.setError("新增失败");
+        }
+        return httpRespMsg;
+    }
+
+    @Override
+    public HttpRespMsg listFeedback() {
+        HttpRespMsg httpRespMsg = new HttpRespMsg();
+        httpRespMsg.data = feedbackMapper.selectList(new QueryWrapper<Feedback>().orderByAsc("id"));
+        return httpRespMsg;
+    }
+
+    @Override
+    public HttpRespMsg insertOrUpdateFeedback(Feedback feedback, MultipartFile multipartFile) {
+        HttpRespMsg httpRespMsg = new HttpRespMsg();
+        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();
+            }
+            feedback.setPicUrl("/upload/" + storedFileName);
+        }
+        if (feedback.getId() == null) {
+            if (feedbackMapper.insert(feedback) == 0) {
+                httpRespMsg.setError("新增失败");
+            }
+        } else {
+            if (feedbackMapper.updateById(feedback) == 0) {
+                httpRespMsg.setError("修改失败");
+            }
+        }
+        return httpRespMsg;
+    }
+
+    @Override
+    public HttpRespMsg deleteFeedback(Integer id) {
+        HttpRespMsg httpRespMsg = new HttpRespMsg();
+        if (feedbackMapper.deleteById(id) == 0) {
+            httpRespMsg.setError("删除失败");
+        }
+        return httpRespMsg;
+    }
 }

+ 1 - 1
official_backend/src/main/java/com/hssx/ysofficial/utility/CodeGenerator.java

@@ -188,7 +188,7 @@ public class CodeGenerator {
         //若想要生成的实体类继承某个Controller,则可打开下面注释。写上需要继承的Controller的位置即可
 //        strategy.setSuperControllerClass("com.baomidou.ant.common.BaseController");
         //单独生成逗号隔开
-        strategy.setInclude("characteristic");
+        strategy.setInclude("feedback");
         //全生成
 //        strategy.setInclude();//表名,多个英文逗号分割
         //多个英文逗号隔开

+ 2 - 1
official_backend/src/main/resources/mapper/FeedbackMapper.xml

@@ -8,11 +8,12 @@
         <result column="company_name" property="companyName" />
         <result column="client_name" property="clientName" />
         <result column="description" property="description" />
+        <result column="pic_url" property="picUrl" />
     </resultMap>
 
     <!-- 通用查询结果列 -->
     <sql id="Base_Column_List">
-        id, company_name, client_name, description
+        id, company_name, client_name, description, pic_url
     </sql>
 
 </mapper>