|
@@ -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;
|
|
|
+ }
|
|
|
}
|