Skip to content

Commit

Permalink
Improve the event's function
Browse files Browse the repository at this point in the history
  • Loading branch information
KADGang committed May 18, 2022
1 parent 267c41a commit 3ce5858
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package org.pockettech.qiusheng.dao;

import org.apache.ibatis.annotations.Param;
import org.pockettech.qiusheng.entity.data.Chart;
import org.pockettech.qiusheng.entity.data.Event;

import java.util.List;

public interface EventDao {
List<Event> findEventsByActive(@Param("active") int active);
String findCidListByEid(@Param("eid") int eid);
void addEvent(Event event);
void updateEvent(Event event);
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@
import org.pockettech.qiusheng.entity.data.User;
import org.pockettech.qiusheng.entity.result.ChartResult;
import org.pockettech.qiusheng.entity.result.ListResult;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
Expand Down Expand Up @@ -74,6 +71,7 @@ public ListResult<ChartResult> eventCharts(@RequestParam(required = false) Integ
String[] cid_list = cids.split(",");

for (String cid : cid_list){
//TODO:可以试着改改
Chart chart = chartDao.findChartByCid(Integer.parseInt(cid));
User user = userDao.findNameByUid(chart.getUid());
Song song = songDao.findSongById(chart.getSid());
Expand All @@ -85,4 +83,16 @@ public ListResult<ChartResult> eventCharts(@RequestParam(required = false) Integ

return new ListResult<>(0,true,2,result);
}

@PostMapping("/admin/event/add")
@ResponseBody
public void addEvent(@RequestBody(required = false) Event event) {
eventDao.addEvent(event);
}

@PostMapping("/admin/event/update")
@ResponseBody
public void updateEvent(@RequestBody(required = false) Event event) {
eventDao.updateEvent(event);
}
}
16 changes: 16 additions & 0 deletions qiusheng-core/src/main/resources/mapping/EventMapper.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,21 @@
select cid_list from events where eid = #{eid}
</select>

<insert id="addEvent" parameterType="org.pockettech.qiusheng.entity.data.Event">
<selectKey keyProperty="eid" order="AFTER" resultType="java.lang.Integer">
SELECT LAST_INSERT_ID()
</selectKey>
insert into events
(eid, name, sponsor, start, end, cover, active, cid_list)
values
(#{eid}, #{name}, #{sponsor}, #{start}, #{end}, #{cover}, #{active}, #{cid_list})
</insert>

<update id="updateEvent" parameterType="org.pockettech.qiusheng.entity.data.Event">
update events set
name = #{name}, sponsor = #{sponsor},
start = #{start}, end = #{end}, cover = #{cover}, active = #{active}, cid_list = #{cid_list}
where eid = #{eid}
</update>
</mapper>

16 changes: 10 additions & 6 deletions qiusheng-core/src/main/resources/sql/qiusheng_core.sql
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,16 @@ create table if not exists chart
);
create table if not exists events
(
eid int auto_increment,
sid int null,
constraint events_pk
primary key (eid),
constraint events_song_sid_fk
foreign key (sid) references song (sid)
eid int auto_increment,
name varchar(50) not null,
sponsor varchar(50) not null,
start date not null,
end date not null,
cover varchar(200) null,
active int not null,
cid_list varchar(400) not null,
constraint table_name_pk
primary key (eid)
);
create table if not exists admin
(
Expand Down

0 comments on commit 3ce5858

Please sign in to comment.