From 27984081081a950c0edba9b140f45c61058da7b0 Mon Sep 17 00:00:00 2001 From: x ronger Date: Thu, 5 Dec 2019 20:01:39 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=BB=E9=A2=98=E7=AE=A1=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../rymcu/vertical/mapper/TopicMapper.java | 2 ++ .../rymcu/vertical/service/TopicService.java | 2 ++ .../service/impl/TopicServiceImpl.java | 23 +++++++++++++++++++ .../web/api/admin/AdminController.java | 18 +++++++++++++++ src/main/java/mapper/TopicMapper.xml | 5 ++++ 5 files changed, 50 insertions(+) diff --git a/src/main/java/com/rymcu/vertical/mapper/TopicMapper.java b/src/main/java/com/rymcu/vertical/mapper/TopicMapper.java index d36b1e7..f945a37 100644 --- a/src/main/java/com/rymcu/vertical/mapper/TopicMapper.java +++ b/src/main/java/com/rymcu/vertical/mapper/TopicMapper.java @@ -14,4 +14,6 @@ public interface TopicMapper extends Mapper { TopicDTO selectTopicByTopicUri(@Param("topicUri") String topicUri); List selectTopicTag(@Param("idTopic") Integer idTopic); + + Integer update(@Param("idTopic") Integer idTopic, @Param("topicTitle") String topicTitle, @Param("topicUri") String topicUri, @Param("topicIconPath") String topicIconPath, @Param("topicNva") String topicNva, @Param("topicStatus") String topicStatus, @Param("topicSort") Integer topicSort, @Param("topicDescription") String topicDescription); } diff --git a/src/main/java/com/rymcu/vertical/service/TopicService.java b/src/main/java/com/rymcu/vertical/service/TopicService.java index bfcf84b..5192e8f 100644 --- a/src/main/java/com/rymcu/vertical/service/TopicService.java +++ b/src/main/java/com/rymcu/vertical/service/TopicService.java @@ -25,4 +25,6 @@ public interface TopicService extends Service { * @return * */ Map findTopicByTopicUri(String topicUri, Integer page, Integer rows); + + Map saveTopic(Topic topic); } diff --git a/src/main/java/com/rymcu/vertical/service/impl/TopicServiceImpl.java b/src/main/java/com/rymcu/vertical/service/impl/TopicServiceImpl.java index 932c804..598fbde 100644 --- a/src/main/java/com/rymcu/vertical/service/impl/TopicServiceImpl.java +++ b/src/main/java/com/rymcu/vertical/service/impl/TopicServiceImpl.java @@ -11,6 +11,7 @@ import com.rymcu.vertical.service.TopicService; import org.springframework.stereotype.Service; import javax.annotation.Resource; +import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -49,4 +50,26 @@ public class TopicServiceImpl extends AbstractService implements TopicSer map.put("pagination", pagination); return map; } + + @Override + public Map saveTopic(Topic topic) { + Integer result = 0; + if (topic.getIdTopic() == null) { + topic.setCreatedTime(new Date()); + topic.setUpdatedTime(topic.getCreatedTime()); + result = topicMapper.insertSelective(topic); + } else { + topic.setCreatedTime(new Date()); + result = topicMapper.update(topic.getIdTopic(),topic.getTopicTitle(),topic.getTopicUri() + ,topic.getTopicIconPath(),topic.getTopicNva(),topic.getTopicStatus() + ,topic.getTopicSort(),topic.getTopicDescription()); + } + Map map = new HashMap(1); + if (result == 0) { + map.put("message","操作失败!"); + } else { + map.put("topic", topic); + } + return map; + } } diff --git a/src/main/java/com/rymcu/vertical/web/api/admin/AdminController.java b/src/main/java/com/rymcu/vertical/web/api/admin/AdminController.java index f26205a..e4a2c7a 100644 --- a/src/main/java/com/rymcu/vertical/web/api/admin/AdminController.java +++ b/src/main/java/com/rymcu/vertical/web/api/admin/AdminController.java @@ -123,4 +123,22 @@ public class AdminController { return GlobalResultGenerator.genSuccessResult(map); } + @GetMapping("/topic/detail/{idTopic}") + public GlobalResult topicDetail(@PathVariable Integer idTopic){ + Topic topic = topicService.findById(idTopic.toString()); + return GlobalResultGenerator.genSuccessResult(topic); + } + + @PostMapping("/topic/post") + public GlobalResult addTopic(@RequestBody Topic topic){ + Map map = topicService.saveTopic(topic); + return GlobalResultGenerator.genSuccessResult(map); + } + + @PutMapping("/topic/post") + public GlobalResult updateTopic(@RequestBody Topic topic){ + Map map = topicService.saveTopic(topic); + return GlobalResultGenerator.genSuccessResult(map); + } + } diff --git a/src/main/java/mapper/TopicMapper.xml b/src/main/java/mapper/TopicMapper.xml index 67b862e..bd7f2b4 100644 --- a/src/main/java/mapper/TopicMapper.xml +++ b/src/main/java/mapper/TopicMapper.xml @@ -34,6 +34,11 @@ + + update vertical_topic set topic_title = #{topicTitle},topic_uri = #{topicUri},topic_icon_path = #{topicIconPath} + ,topic_nva = #{topicNva},topic_status = #{topicStatus},topic_sort = #{topicSort},topic_description = #{topicDescription} + where id = #{idTopic} +