|
@@ -3,7 +3,9 @@ package cn.efunbox.audio.controller;
|
|
|
import cn.efunbox.audio.consts.Consts;
|
|
|
import cn.efunbox.audio.consts.Status;
|
|
|
import cn.efunbox.audio.entity.Admin;
|
|
|
+import cn.efunbox.audio.entity.Trail;
|
|
|
import cn.efunbox.audio.service.AdminService;
|
|
|
+import cn.efunbox.audio.service.TrailService;
|
|
|
import cn.efunbox.audio.utils.ApiCode;
|
|
|
import cn.efunbox.audio.utils.Common;
|
|
|
import cn.efunbox.audio.utils.HttpUtil;
|
|
@@ -36,6 +38,9 @@ public class AdminController {
|
|
|
AdminService adminService;
|
|
|
@Autowired
|
|
|
StringRedisTemplate stringRedisTemplate;
|
|
|
+ @Autowired
|
|
|
+ TrailService trailService;
|
|
|
+
|
|
|
@Value("${admin.token.expire}")
|
|
|
int tokenExpire = 24*30;
|
|
|
|
|
@@ -141,11 +146,24 @@ public class AdminController {
|
|
|
|
|
|
@RequestMapping(value = "/register", method = RequestMethod.POST)
|
|
|
public void Register(HttpServletRequest request, HttpServletResponse response, @RequestBody Admin admin){
|
|
|
+
|
|
|
+ String id = request.getHeader("id");
|
|
|
+ Admin superAdmin = adminService.GetOne(Long.valueOf(id));
|
|
|
+ if(superAdmin==null || false==superAdmin.getName().equalsIgnoreCase("superadmin")){
|
|
|
+ HttpUtil.responseApiCode(request, response, ApiCode.ACCESS_DENIED);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ TrailController.Insert(adminService, trailService, request, "admin", admin.getId(), " 创建管理员:" + admin.getName());
|
|
|
InsertUpdate(request, response, admin);
|
|
|
}
|
|
|
|
|
|
@RequestMapping(value = "/update", method = RequestMethod.POST)
|
|
|
public void Update(HttpServletRequest request, HttpServletResponse response, @RequestBody Admin admin){
|
|
|
+ if(admin.getName().equalsIgnoreCase("superadmin")){
|
|
|
+ HttpUtil.responseApiCode(request, response, ApiCode.PARAMETER_ERROR);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ TrailController.Insert(adminService, trailService, request, "admin", admin.getId(), " 修改管理员:" + admin.getName());
|
|
|
InsertUpdate(request, response, admin);
|
|
|
}
|
|
|
|
|
@@ -154,22 +172,23 @@ public class AdminController {
|
|
|
String idAdmin = request.getParameter("idAdmin");
|
|
|
adminService.Delete(Long.valueOf(idAdmin));
|
|
|
HttpUtil.responseOk(request, response);
|
|
|
+ TrailController.Insert(adminService, trailService, request, "admin", Long.valueOf(idAdmin), " 删除管理员:" + idAdmin);
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- public void InsertUpdate(HttpServletRequest request, HttpServletResponse response, Admin admin){
|
|
|
+ public Admin InsertUpdate(HttpServletRequest request, HttpServletResponse response, Admin admin){
|
|
|
String name = admin.getName();
|
|
|
String pwd = admin.getPwd();
|
|
|
if(admin.getId()==null){
|
|
|
|
|
|
if(name==null || name.length()<4 || pwd==null || pwd.length()<4){
|
|
|
HttpUtil.responseApiCode(request, response, ApiCode.PARAMETER_ERROR);
|
|
|
- return;
|
|
|
+ return admin;
|
|
|
}
|
|
|
List<Admin> list = adminService.SearchByName(name);
|
|
|
if(list!=null && list.size()>0){
|
|
|
HttpUtil.responseApiCode(request, response, ApiCode.RECORD_EXIST);
|
|
|
- return;
|
|
|
+ return admin;
|
|
|
}
|
|
|
admin.setStatus(Status.ONLINE.getCode());
|
|
|
admin.setCreated(new Timestamp(new Date().getTime()));
|
|
@@ -177,7 +196,7 @@ public class AdminController {
|
|
|
Admin adminOld = adminService.GetOne(admin.getId());
|
|
|
if(adminOld==null){
|
|
|
HttpUtil.responseApiCode(request, response, ApiCode.PARAMETER_ERROR);
|
|
|
- return;
|
|
|
+ return admin;
|
|
|
}
|
|
|
admin = (Admin)Common.CopyValue(admin, adminOld);
|
|
|
}
|
|
@@ -194,7 +213,7 @@ public class AdminController {
|
|
|
SaveRedis(admin);
|
|
|
|
|
|
HttpUtil.responseOkData(request, response, admin);
|
|
|
- return;
|
|
|
+ return admin;
|
|
|
}
|
|
|
|
|
|
/**
|