99import org .springframework .stereotype .Controller ;
1010import org .springframework .web .bind .annotation .*;
1111
12+ import javax .servlet .http .HttpServletRequest ;
1213import javax .servlet .http .HttpSession ;
1314import java .sql .Timestamp ;
1415import java .util .HashMap ;
@@ -25,6 +26,25 @@ public AdminController(AdminService adminService){
2526 this .adminService = adminService ;
2627 }
2728
29+ //重定向后的请求处理
30+ @ RequestMapping (value = "/page/login" , method = RequestMethod .GET )
31+ public String getIndex (HttpServletRequest request ){
32+ request .getSession ().setAttribute ("isRedirect" , true ); //添加session信息,避免拦截器重复拦截
33+ return "/page/index.html" ;
34+ }
35+
36+ //处理管理端的所有静态请求
37+ @ RequestMapping (value = "/page/activity/*" , method = RequestMethod .GET )
38+ public String checkIndex (HttpSession session ){
39+ //如果登录,则跳回主页面
40+ if (checkUser (session )){
41+ return "/page/index.html" ;
42+ }
43+ //如果访问静态请求时没有登录,则重定向
44+ return "redirect:/page/login" ;
45+ }
46+
47+ //管理端登录
2848 @ ResponseBody
2949 @ RequestMapping (value = "/login" , method = RequestMethod .POST ,
3050 produces = "application/json;charset=UTF-8" )
@@ -42,12 +62,14 @@ public ResponseEntity adminLogin(@RequestBody String jsonString, HttpSession ses
4262 }
4363 }
4464
65+ //管理端登出
4566 @ ResponseBody
4667 @ RequestMapping (value = "/logout" , method = RequestMethod .GET ,
4768 produces = "application/json;charset=UTF-8" )
4869 public ResponseEntity adminLogout (HttpSession session ){
4970 if (session .getAttribute ("username" ) != null ){
5071 sessionList .remove (session .getAttribute ("username" ).toString ());
72+ session .removeAttribute ("username" );
5173 }
5274 return new ResponseEntity (HttpStatus .OK );
5375 }
@@ -90,32 +112,32 @@ public ResponseEntity<String> postActivity(@RequestBody String jsonString, HttpS
90112 }
91113 }
92114
115+ //获取用户列表,用于登录
93116 @ ResponseBody
94- @ RequestMapping (value = "/user" , method = RequestMethod .POST ,
117+ @ RequestMapping (value = "/user" , method = RequestMethod .GET ,
95118 produces = "application/json;charset=UTF-8" )
96- public ResponseEntity <String > getUsers (HttpSession session ){
97- if (checkUser (session )){
98- return new ResponseEntity <>(adminService .getUser (), HttpStatus .OK );
99- }
100- else return new ResponseEntity <>("" , HttpStatus .UNAUTHORIZED );
119+ public ResponseEntity <String > getUsers (){
120+ return new ResponseEntity <>(adminService .getUser (), HttpStatus .OK );
101121 }
102122
123+ //获取所有活动
103124 @ ResponseBody
104125 @ RequestMapping (value = "/admin/activity" , method = RequestMethod .GET ,
105126 produces = "application/json;charset=UTF-8" )
106127 public ResponseEntity <String > adminGetActivity (HttpSession session ){
107128 if (checkUser (session )){
108- return new ResponseEntity <>(adminService .getActivity (), HttpStatus .OK );
129+ return new ResponseEntity <>(adminService .getActivities (), HttpStatus .OK );
109130 }
110131 else return new ResponseEntity <>("" , HttpStatus .UNAUTHORIZED );
111132 }
112133
134+ //设置活动状态
113135 @ ResponseBody
114136 @ RequestMapping (value = "/admin/activity/{id}/status" , method = RequestMethod .PUT ,
115137 produces = "application/json;charset=UTF-8" )
116138 public ResponseEntity setActivityStatus (@ PathVariable long id , @ RequestBody String jsonString , HttpSession session ){
117139 if (checkUser (session )){
118- byte status = (byte )Integer . parseInt ( new JSONObject (jsonString ).getString ("status" ) );
140+ byte status = (byte )new JSONObject (jsonString ).getInt ("status" );
119141 if (adminService .setActivityStatus (id , status )){
120142 return new ResponseEntity (HttpStatus .ACCEPTED );
121143 }
@@ -124,10 +146,71 @@ public ResponseEntity setActivityStatus(@PathVariable long id, @RequestBody Stri
124146 else return new ResponseEntity (HttpStatus .UNAUTHORIZED );
125147 }
126148
149+ //作为管理员获取一个活动的结构
150+ @ ResponseBody
151+ @ RequestMapping (value = "/admin/activity/{id}" , method = RequestMethod .GET ,
152+ produces = "application/json;charset=UTF-8" )
153+ public ResponseEntity <String > getActivityStructure (@ PathVariable long id , HttpSession session ){
154+ if (checkUser (session )){
155+ return new ResponseEntity <>(adminService .getActivityStructure (id ), HttpStatus .OK );
156+ }
157+ else return new ResponseEntity <>("" , HttpStatus .UNAUTHORIZED );
158+ }
159+
160+ //删除一个报名
161+ @ ResponseBody
162+ @ RequestMapping (value = "/admin/activity/{id}" , method = RequestMethod .DELETE ,
163+ produces = "application/json;charset=UTF-8" )
164+ public ResponseEntity <String > deleteActivity (@ PathVariable long id , HttpSession session ){
165+ if (checkUser (session )){
166+ return new ResponseEntity <>(adminService .deleteActivity (id ), HttpStatus .OK );
167+ }
168+ else return new ResponseEntity <>("" , HttpStatus .UNAUTHORIZED );
169+ }
170+
171+ //获取一个报名内的报名信息
172+ @ ResponseBody
173+ @ RequestMapping (value = "/admin/activity/{id}/applicant" , method = RequestMethod .GET ,
174+ produces = "application/json;charset=UTF-8" )
175+ public ResponseEntity <String > getActivityApplicants (@ PathVariable long id , HttpSession session ){
176+ if (checkUser (session )){
177+ return new ResponseEntity <>(adminService .getActivityApplicants (id ), HttpStatus .OK );
178+ }
179+ else return new ResponseEntity <>("" , HttpStatus .UNAUTHORIZED );
180+ }
181+
182+ //删除指定的报名信息
183+ @ ResponseBody
184+ @ RequestMapping (value = "/admin/activity/{aid}/applicant/{iid}" , method = RequestMethod .DELETE ,
185+ produces = "application/json;charset=UTF-8" )
186+ public ResponseEntity <String > deleteApplicantInfo (@ PathVariable long aid , @ PathVariable int iid , HttpSession session ){
187+ if (checkUser (session )){
188+ return new ResponseEntity <>(adminService .deleteApplicantInfo (aid , iid ), HttpStatus .OK );
189+ }
190+ else return new ResponseEntity <>("" , HttpStatus .UNAUTHORIZED );
191+ }
192+
193+ //更新报名信息
194+ @ ResponseBody
195+ @ RequestMapping (value = "/admin/activity/{id}" , method = RequestMethod .PUT ,
196+ produces = "application/json;charset=UTF-8" )
197+ public ResponseEntity <String > alterActivityStructure (@ PathVariable long id , HttpSession session ,
198+ @ RequestBody String jsonString ){
199+ if (checkUser (session ) ){
200+ if (adminService .alterActivityStructure (id , new JSONObject (jsonString )))
201+ return new ResponseEntity <>("" , HttpStatus .OK );
202+ else
203+ return new ResponseEntity <>("" , HttpStatus .NOT_ACCEPTABLE );
204+ }
205+ else return new ResponseEntity <>("" , HttpStatus .UNAUTHORIZED );
206+ }
207+
127208 // 检查当前用户连接是否已经登陆
128209 private boolean checkUser (HttpSession session ){
210+ if (session == null ) return false ;
129211 String userName = session .getAttribute ("username" ) == null ?
130212 null : session .getAttribute ("username" ).toString ();
131213 return userName != null && sessionList .get (userName ).equals (session .getId ());
132214 }
215+
133216}
0 commit comments