From 947eb7af029cc0e062cd860a4dae0f6118868c66 Mon Sep 17 00:00:00 2001 From: KADGang <54164637+KADGang@users.noreply.github.com> Date: Tue, 7 Jun 2022 13:01:21 +0800 Subject: [PATCH] Add some administrator functions These features are not perfect. --- .../qiusheng/config/AdminSecurityConfig.java | 5 +++-- .../org/pockettech/qiusheng/dao/ChartDao.java | 1 + .../org/pockettech/qiusheng/dao/EventDao.java | 1 + .../org/pockettech/qiusheng/dao/SongDao.java | 1 + .../qiusheng/impl/StoreChartsServiceImpl.java | 15 +++++++++++++++ .../qiusheng/impl/StoreEventsServiceImpl.java | 11 +++++++++++ .../qiusheng/impl/StoreListServiceImpl.java | 17 +++++++++++++++++ .../qiusheng/impl/admin/AdminDetailService.java | 1 - .../src/main/resources/mapping/ChartMapper.xml | 4 ++++ .../src/main/resources/mapping/EventMapper.xml | 4 ++++ .../src/main/resources/mapping/SongMapper.xml | 4 ++++ 11 files changed, 61 insertions(+), 3 deletions(-) diff --git a/qiusheng-core/src/main/java/org/pockettech/qiusheng/config/AdminSecurityConfig.java b/qiusheng-core/src/main/java/org/pockettech/qiusheng/config/AdminSecurityConfig.java index 84009e6..5331f9d 100644 --- a/qiusheng-core/src/main/java/org/pockettech/qiusheng/config/AdminSecurityConfig.java +++ b/qiusheng-core/src/main/java/org/pockettech/qiusheng/config/AdminSecurityConfig.java @@ -30,7 +30,8 @@ protected void configure(HttpSecurity http) throws Exception { .and() .formLogin() .loginProcessingUrl("/admin/login") -// .loginPage("/login") //TODO:实现自定义登录 - .permitAll(); + .permitAll() + .and() + .csrf().disable();//TODO:尝试在qiusheng-terminal中加入csrf防护 } } diff --git a/qiusheng-core/src/main/java/org/pockettech/qiusheng/dao/ChartDao.java b/qiusheng-core/src/main/java/org/pockettech/qiusheng/dao/ChartDao.java index 8671b7c..144cbf3 100644 --- a/qiusheng-core/src/main/java/org/pockettech/qiusheng/dao/ChartDao.java +++ b/qiusheng-core/src/main/java/org/pockettech/qiusheng/dao/ChartDao.java @@ -13,4 +13,5 @@ public interface ChartDao { Integer findSidByCid(@Param("cid") int cid); void uploadChartMsg(Chart chart); void updateChart(Chart chart); + int deleteChart(@Param("cid") int cid); } diff --git a/qiusheng-core/src/main/java/org/pockettech/qiusheng/dao/EventDao.java b/qiusheng-core/src/main/java/org/pockettech/qiusheng/dao/EventDao.java index 6867558..f549f83 100644 --- a/qiusheng-core/src/main/java/org/pockettech/qiusheng/dao/EventDao.java +++ b/qiusheng-core/src/main/java/org/pockettech/qiusheng/dao/EventDao.java @@ -11,4 +11,5 @@ public interface EventDao { String findCidListByEid(@Param("eid") int eid); void addEvent(Event event); void updateEvent(Event event); + int deleteEvent(@Param("eid") int eid); } diff --git a/qiusheng-core/src/main/java/org/pockettech/qiusheng/dao/SongDao.java b/qiusheng-core/src/main/java/org/pockettech/qiusheng/dao/SongDao.java index 7d14d19..2a511b8 100644 --- a/qiusheng-core/src/main/java/org/pockettech/qiusheng/dao/SongDao.java +++ b/qiusheng-core/src/main/java/org/pockettech/qiusheng/dao/SongDao.java @@ -16,4 +16,5 @@ public interface SongDao { void updateSong(Song song); void updateLengthBySid(@Param("sid") int sid, @Param("length") int length); void updateSongMD5PathBySid(Song song); + int deleteSong(@Param("sid") int sid); } diff --git a/qiusheng-core/src/main/java/org/pockettech/qiusheng/impl/StoreChartsServiceImpl.java b/qiusheng-core/src/main/java/org/pockettech/qiusheng/impl/StoreChartsServiceImpl.java index bf7bc90..faf36f1 100644 --- a/qiusheng-core/src/main/java/org/pockettech/qiusheng/impl/StoreChartsServiceImpl.java +++ b/qiusheng-core/src/main/java/org/pockettech/qiusheng/impl/StoreChartsServiceImpl.java @@ -335,6 +335,21 @@ public DownloadResult chartDownload(@RequestParam(required = false) int cid) { return new DownloadResult(0, items, chart.getSid(), chart.getCid()); } + @PostMapping("/admin/store/deleteChart") + @ResponseBody + public int deleteChart(@RequestParam int cid) { + int deleteCode = chartDao.deleteChart(cid); + //TODO:添加删除铺面文件的选项与逻辑 + + if (deleteCode == 0) { + log.info("删除谱面(cid: " + cid + ")时出错,可能原因为数据库中并未存在该谱面"); + return 1; + } else + log.info("成功删除谱面(cid: " + cid + ")"); + + return 0; + } + //返回代码类 @Data @AllArgsConstructor diff --git a/qiusheng-core/src/main/java/org/pockettech/qiusheng/impl/StoreEventsServiceImpl.java b/qiusheng-core/src/main/java/org/pockettech/qiusheng/impl/StoreEventsServiceImpl.java index c9784dc..93bc0b9 100644 --- a/qiusheng-core/src/main/java/org/pockettech/qiusheng/impl/StoreEventsServiceImpl.java +++ b/qiusheng-core/src/main/java/org/pockettech/qiusheng/impl/StoreEventsServiceImpl.java @@ -95,4 +95,15 @@ public void addEvent(@RequestBody(required = false) Event event) { public void updateEvent(@RequestBody(required = false) Event event) { eventDao.updateEvent(event); } + + @PostMapping("/admin/event/delete") + @ResponseBody + public void deleteEvent(@RequestParam(required = false) int eid) { + int deleteCode = eventDao.deleteEvent(eid); + + if (deleteCode == 0) + log.info("删除活动(eid: " + eid + ")时出错,可能原因为数据库中并未存在该事件"); + else + log.info("成功删除活动(eid: " + eid + ")"); + } } diff --git a/qiusheng-core/src/main/java/org/pockettech/qiusheng/impl/StoreListServiceImpl.java b/qiusheng-core/src/main/java/org/pockettech/qiusheng/impl/StoreListServiceImpl.java index b49544a..6fb0bc0 100644 --- a/qiusheng-core/src/main/java/org/pockettech/qiusheng/impl/StoreListServiceImpl.java +++ b/qiusheng-core/src/main/java/org/pockettech/qiusheng/impl/StoreListServiceImpl.java @@ -86,4 +86,21 @@ public ListResult storePromote(@RequestParam(required = false) Integ return new ListResult<>(1,false,0, result); } + + @PostMapping("/admin/store/deleteSong") + @ResponseBody + public int deleteSong(@RequestParam int sid) { + //TODO:添加删除歌曲以下所有铺面文件的选项与逻辑 + + + int deleteCode = songDao.deleteSong(sid); + + if (deleteCode == 0) { + log.info("删除谱面(cid: " + sid + ")时出错,可能原因为数据库中并未存在该谱面"); + return 1; + } else + log.info("成功删除谱面(cid: " + sid + ")"); + + return 0; + } } diff --git a/qiusheng-core/src/main/java/org/pockettech/qiusheng/impl/admin/AdminDetailService.java b/qiusheng-core/src/main/java/org/pockettech/qiusheng/impl/admin/AdminDetailService.java index 799dcae..7a852da 100644 --- a/qiusheng-core/src/main/java/org/pockettech/qiusheng/impl/admin/AdminDetailService.java +++ b/qiusheng-core/src/main/java/org/pockettech/qiusheng/impl/admin/AdminDetailService.java @@ -3,7 +3,6 @@ import lombok.extern.slf4j.Slf4j; import org.pockettech.qiusheng.dao.AdminDao; import org.pockettech.qiusheng.entity.userrole.Admin; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.core.userdetails.UserDetails; import org.springframework.security.core.userdetails.UserDetailsService; import org.springframework.security.core.userdetails.UsernameNotFoundException; diff --git a/qiusheng-core/src/main/resources/mapping/ChartMapper.xml b/qiusheng-core/src/main/resources/mapping/ChartMapper.xml index 2773ed2..b2c7060 100644 --- a/qiusheng-core/src/main/resources/mapping/ChartMapper.xml +++ b/qiusheng-core/src/main/resources/mapping/ChartMapper.xml @@ -61,5 +61,9 @@ type = #{type},size = #{size},c_mode = #{c_mode},c_md5 = ifnull(#{c_md5},c_md5),c_file_path = #{c_file_path} where cid = #{cid} + + + delete from chart where cid = #{cid} + diff --git a/qiusheng-core/src/main/resources/mapping/EventMapper.xml b/qiusheng-core/src/main/resources/mapping/EventMapper.xml index de0a774..85afb5b 100644 --- a/qiusheng-core/src/main/resources/mapping/EventMapper.xml +++ b/qiusheng-core/src/main/resources/mapping/EventMapper.xml @@ -28,5 +28,9 @@ start = #{start}, end = #{end}, cover = #{cover}, active = #{active}, cid_list = #{cid_list} where eid = #{eid} + + + delete from events where eid = #{eid} + diff --git a/qiusheng-core/src/main/resources/mapping/SongMapper.xml b/qiusheng-core/src/main/resources/mapping/SongMapper.xml index 3c57fc9..6722af5 100644 --- a/qiusheng-core/src/main/resources/mapping/SongMapper.xml +++ b/qiusheng-core/src/main/resources/mapping/SongMapper.xml @@ -58,5 +58,9 @@ update song set img_md5 = #{img_md5}, img_file_path = #{img_file_path} where sid = #{sid} + + + delete from song where sid = #{sid} +