提交 | 用户 | 时间
|
e7c126
|
1 |
package com.xxl.job.admin.controller; |
H |
2 |
|
|
3 |
import com.xxl.job.admin.controller.annotation.PermissionLimit; |
|
4 |
import com.xxl.job.admin.service.LoginService; |
|
5 |
import com.xxl.job.admin.service.XxlJobService; |
|
6 |
import com.xxl.job.core.biz.model.ReturnT; |
|
7 |
import org.springframework.beans.propertyeditors.CustomDateEditor; |
|
8 |
import org.springframework.stereotype.Controller; |
|
9 |
import org.springframework.ui.Model; |
|
10 |
import org.springframework.web.bind.WebDataBinder; |
|
11 |
import org.springframework.web.bind.annotation.InitBinder; |
|
12 |
import org.springframework.web.bind.annotation.RequestMapping; |
|
13 |
import org.springframework.web.bind.annotation.RequestMethod; |
|
14 |
import org.springframework.web.bind.annotation.ResponseBody; |
|
15 |
import org.springframework.web.servlet.ModelAndView; |
|
16 |
import org.springframework.web.servlet.view.RedirectView; |
|
17 |
|
|
18 |
import javax.annotation.Resource; |
|
19 |
import javax.servlet.http.HttpServletRequest; |
|
20 |
import javax.servlet.http.HttpServletResponse; |
|
21 |
import java.text.SimpleDateFormat; |
|
22 |
import java.util.Date; |
|
23 |
import java.util.Map; |
|
24 |
|
|
25 |
/** |
|
26 |
* index controller |
|
27 |
* @author xuxueli 2015-12-19 16:13:16 |
|
28 |
*/ |
|
29 |
@Controller |
|
30 |
public class IndexController { |
|
31 |
|
|
32 |
@Resource |
|
33 |
private XxlJobService xxlJobService; |
|
34 |
@Resource |
|
35 |
private LoginService loginService; |
|
36 |
|
|
37 |
|
|
38 |
@RequestMapping("/") |
|
39 |
public String index(Model model) { |
|
40 |
|
|
41 |
Map<String, Object> dashboardMap = xxlJobService.dashboardInfo(); |
|
42 |
model.addAllAttributes(dashboardMap); |
|
43 |
|
|
44 |
return "index"; |
|
45 |
} |
|
46 |
|
|
47 |
@RequestMapping("/chartInfo") |
|
48 |
@ResponseBody |
|
49 |
public ReturnT<Map<String, Object>> chartInfo(Date startDate, Date endDate) { |
|
50 |
ReturnT<Map<String, Object>> chartInfo = xxlJobService.chartInfo(startDate, endDate); |
|
51 |
return chartInfo; |
|
52 |
} |
|
53 |
|
|
54 |
@RequestMapping("/toLogin") |
|
55 |
@PermissionLimit(limit=false) |
|
56 |
public ModelAndView toLogin(HttpServletRequest request, HttpServletResponse response,ModelAndView modelAndView) { |
|
57 |
if (loginService.ifLogin(request, response) != null) { |
|
58 |
modelAndView.setView(new RedirectView("/",true,false)); |
|
59 |
return modelAndView; |
|
60 |
} |
|
61 |
return new ModelAndView("login"); |
|
62 |
} |
|
63 |
|
|
64 |
@RequestMapping(value="login", method=RequestMethod.POST) |
|
65 |
@ResponseBody |
|
66 |
@PermissionLimit(limit=false) |
|
67 |
public ReturnT<String> loginDo(HttpServletRequest request, HttpServletResponse response, String userName, String password, String ifRemember){ |
|
68 |
boolean ifRem = (ifRemember!=null && ifRemember.trim().length()>0 && "on".equals(ifRemember))?true:false; |
|
69 |
return loginService.login(request, response, userName, password, ifRem); |
|
70 |
} |
|
71 |
|
|
72 |
@RequestMapping(value="logout", method=RequestMethod.POST) |
|
73 |
@ResponseBody |
|
74 |
@PermissionLimit(limit=false) |
|
75 |
public ReturnT<String> logout(HttpServletRequest request, HttpServletResponse response){ |
|
76 |
return loginService.logout(request, response); |
|
77 |
} |
|
78 |
|
|
79 |
@RequestMapping("/help") |
|
80 |
public String help() { |
|
81 |
|
|
82 |
/*if (!PermissionInterceptor.ifLogin(request)) { |
|
83 |
return "redirect:/toLogin"; |
|
84 |
}*/ |
|
85 |
|
|
86 |
return "help"; |
|
87 |
} |
|
88 |
|
|
89 |
@InitBinder |
|
90 |
public void initBinder(WebDataBinder binder) { |
|
91 |
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
|
92 |
dateFormat.setLenient(false); |
|
93 |
binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true)); |
|
94 |
} |
|
95 |
|
|
96 |
} |