Commit 17075bfc authored by Quxl's avatar Quxl

管理员

parent 02e4fc17
......@@ -13,11 +13,16 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.egolm.common.FileUtil;
import com.egolm.common.StringUtil;
import com.egolm.common.bean.Rjx;
import com.egolm.common.jdbc.Page;
import com.egolm.film.api.admin.service.AdminAuthService;
import com.egolm.film.api.admin.service.AdminTokenService;
import com.egolm.film.bean.Fc_admin;
import com.egolm.film.bean.Fc_admin_group;
import com.egolm.film.config.WebMvcConfig;
import com.egolm.film.config.XException;
import com.egolm.film.util.Common;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
......@@ -30,25 +35,70 @@ public class AdminAuthController {
@Autowired
AdminAuthService service;
@Autowired
AdminTokenService tokenService;
@ResponseBody
@RequestMapping("adminList")
@ApiOperation("管理员分页查询")
public Object adminList(String keyword, String group_id, Long index, Long limit) {
return Rjx.jsonOk();
public Object adminList(String keyword, Integer group_id, Long index, Long limit) {
index = index == null ? 1 : index;
limit = limit == null ? 20 : limit;
Page page = new Page(index, limit);
List<Map<String, Object>> list = service.queryAdminList(keyword, group_id, page);
return Rjx.jsonOk().setData(list);
}
@ResponseBody
@RequestMapping("adminSaveOrUpdate")
@RequestMapping("adminSave")
@ApiOperation("添加管理员")
public Object adminSaveOrUpdate(String realname, String username, String password, String group_id, Date expire_time, String email, String telphone) {
public Object adminSave(String realname, String username, String password, Integer group_id) {
String remoteIp = WebMvcConfig.getRemoteIp();
Fc_admin admin = new Fc_admin();
admin.setCreate_admin_id((Integer)tokenService.getToken().getId());
admin.setCreate_ip(remoteIp);
admin.setCreate_time(System.currentTimeMillis());
admin.setGroup_id(group_id);
admin.setRealname(realname);
admin.setUsername(username);
String salt = Common.getGenerateString(6);
String encodePassword = Common.encodePassword(password, salt);
admin.setPassword(encodePassword);
admin.setSalt(salt);
admin.setState(1);
service.saveAdmin(admin);
return Rjx.jsonOk();
}
@ResponseBody
@RequestMapping("adminUpdate")
@ApiOperation("修改管理员")
public Object adminUpdate(Integer adminid, String realname, String username, String password, Integer group_id) {
XException.assertNotBlank("管理员ID不能为空", adminid);
XException.assertNotBlank("姓名不能为空", realname);
XException.assertNotBlank("用户名不能为空", username);
XException.assertNotBlank("分组ID不能为空", group_id);
Fc_admin admin = new Fc_admin();
admin.setAdminid(adminid);
admin.setGroup_id(group_id);
admin.setRealname(realname);
admin.setUsername(username);
if(StringUtil.isNotBlank(password)) {
String salt = Common.getGenerateString(6);
String encodePassword = Common.encodePassword(password, salt);
admin.setPassword(encodePassword);
admin.setSalt(salt);
}
service.mergeAdmin(admin);
return Rjx.jsonOk();
}
@ResponseBody
@RequestMapping("adminDilabled")
@ApiOperation("禁用管理员")
public Object adminDilabled(String[] adminid) {
public Object adminDilabled(Integer[] adminid) {
XException.assertNotBlank("管理员ID不能为空", (Object[])adminid);
service.disableAdmin(adminid);
return Rjx.jsonOk();
}
......
......@@ -4,6 +4,7 @@ import java.util.List;
import java.util.Map;
import com.egolm.common.jdbc.Page;
import com.egolm.film.bean.Fc_admin;
import com.egolm.film.bean.Fc_admin_group;
public interface AdminAuthService {
......@@ -12,4 +13,12 @@ public interface AdminAuthService {
List<Map<String, Object>> queryGroupList(String keyword, Page page);
List<Map<String, Object>> queryAdminList(String keyword, Integer group_id, Page page);
void disableAdmin(Integer[] adminid);
void saveAdmin(Fc_admin admin);
void mergeAdmin(Fc_admin admin);
}
......@@ -10,6 +10,7 @@ import com.egolm.common.StringUtil;
import com.egolm.common.jdbc.JdbcTemplate;
import com.egolm.common.jdbc.Page;
import com.egolm.film.api.admin.service.AdminAuthService;
import com.egolm.film.bean.Fc_admin;
import com.egolm.film.bean.Fc_admin_group;
import com.egolm.film.util.SqlWhere;
......@@ -30,8 +31,31 @@ public class AdminAuthServiceImpl implements AdminAuthService {
@Override
public List<Map<String, Object>> queryGroupList(String keyword, Page page) {
SqlWhere argEdit = new SqlWhere().like("group_name", keyword);
String sql = "select * from" + StringUtil.join(" and ", " where ", "", "", argEdit.getArgs());
return jdbcTemplate.limitAll(sql, page, argEdit.getObjs());
String sql = "select * from fc_admin_group" + StringUtil.join(" and ", " where ", "", "", argEdit.getArgs());
return jdbcTemplate.limit(sql, page, argEdit.getObjs());
}
@Override
public List<Map<String, Object>> queryAdminList(String keyword, Integer group_id, Page page) {
SqlWhere argEdit = new SqlWhere().like("realname", keyword).like("username", keyword).eq("group_id", group_id);
String sql = "select * from fc_admin" + StringUtil.join(" and ", " where ", "", "", argEdit.getArgs());
return jdbcTemplate.limit(sql, page, argEdit.getObjs());
}
@Override
public void disableAdmin(Integer[] adminid) {
String sql = "update fc_admin set state = 2 where admin in (" + StringUtil.join("?", ", ", adminid.length) + ")";
jdbcTemplate.executeUpdate(sql, (Object[])adminid);
}
@Override
public void saveAdmin(Fc_admin admin) {
jdbcTemplate.save(admin);
}
@Override
public void mergeAdmin(Fc_admin admin) {
jdbcTemplate.merge(admin);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment