源码获取:俺的博客首页 "资源" 里下载!
项目介绍
本项目分为管理员与用户两种角色;
管理员角色包含以下功能:
管理员登录,菜单管理,角色管理,修改密码,用户管理,学院班级管理,日志列表管理,
实验室管理,设备管理,设备申请管理,查看我的设备申请,实验室申请管理,查看我的实验室申请等功能。
用户角色包含以下功能:
用户登录,修改密码,查看用户列表,实验室管理,设备管理等功能。
环境需要
1.运行环境:最好是java jdk 1.8,我们在这个平台上运行的。其他版本理论上也可以。
2.IDE环境:IDEA,Eclipse,Myeclipse都可以。推荐IDEA;
3.tomcat环境:Tomcat 7.x,8.x,9.x版本均可
4.硬件环境:windows 7/8/10 1G内存以上;或者 Mac OS;
5.数据库:MySql 5.7版本;
6.是否Maven项目:是;
技术栈
1. 后端:Spring+SpringMVC+Mbytes
2. 前端:JSP+css+javascript+jQuery+easyUI+h-ui
使用说明
1. 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件;
2. 使用IDEA/Eclipse/MyEclipse导入项目,Eclipse/MyEclipse导入时,若为maven项目请选择maven;
若为maven项目,导入成功后请执行maven clean;maven install命令,然后运行;
3. 将项目中db.properties配置文件中的数据库配置改为自己的配置;
4. 运行项目,在浏览器中输入localhost:8080/ssm_ziyuan_yuyue
用户管理控制器:
/**
* 用户管理控制器
*
*/
@RequestMapping("/admin/user")
@Controller
public class UserController {
@Autowired
private UserService userService;
@Autowired
private RoleService roleService;
@Autowired
PartService partService;
/**
* 用户列表页面
* @param model
* @return
*/
@RequestMapping(value="/list",method=RequestMethod.GET)
public ModelAndView list(ModelAndView model){
Map<String, Object> queryMap = new HashMap<String, Object>();
model.addObject("roleList", roleService.findList(queryMap));
model.addObject("partList", partService.list());
model.setViewName("user/list");
return model;
}
/**
* 获取用户列表
* @param page
* @param username
* @param roleId
* @param sex
* @return
*/
@RequestMapping(value="/list",method=RequestMethod.POST)
@ResponseBody
public Map<String, Object> getList(Page page,
@RequestParam(name="username",required=false,defaultValue="") String username,
@RequestParam(name="roleId",required=false) Long roleId,
@RequestParam(name="pid",required=false) Long pid,
@RequestParam(name="sex",required=false) Integer sex
){
Map<String, Object> ret = new HashMap<String, Object>();
Map<String, Object> queryMap = new HashMap<String, Object>();
queryMap.put("username", username);
queryMap.put("roleId", roleId);
queryMap.put("pid", pid);
queryMap.put("sex", sex);
queryMap.put("offset", page.getOffset());
queryMap.put("pageSize", page.getRows());
ret.put("rows", userService.findList(queryMap));
ret.put("total", userService.getTotal(queryMap));
return ret;
}
/**
* 添加用户
* @param user
* @return
*/
@RequestMapping(value="/add",method=RequestMethod.POST)
@ResponseBody
public Map<String, String> add(User user){
Map<String, String> ret = new HashMap<String, String>();
if(user == null){
ret.put("type", "error");
ret.put("msg", "请填写正确的用户信息!");
return ret;
}
if(StringUtils.isEmpty(user.getUsername())){
ret.put("type", "error");
ret.put("msg", "请填写用户名!");
return ret;
}
if(StringUtils.isEmpty(user.getPassword())){
ret.put("type", "error");
ret.put("msg", "请填写密码!");
return ret;
}
if(user.getRoleId() == null){
ret.put("type", "error");
ret.put("msg", "请选择所属角色!");
return ret;
}
if(isExist(user.getUsername(), 0l)){
ret.put("type", "error");
ret.put("msg", "该用户名已经存在,请重新输入!");
return ret;
}
if(userService.add(user) <= 0){
ret.put("type", "error");
ret.put("msg", "用户添加失败,请联系管理员!");
return ret;
}
ret.put("type", "success");
ret.put("msg", "角色添加成功!");
return ret;
}
/**
* 编辑用户
* @param user
* @return
*/
@RequestMapping(value="/edit",method=RequestMethod.POST)
@ResponseBody
public Map<String, String> edit(User user){
Map<String, String> ret = new HashMap<String, String>();
if(user == null){
ret.put("type", "error");
ret.put("msg", "请填写正确的用户信息!");
return ret;
}
if(StringUtils.isEmpty(user.getUsername())){
ret.put("type", "error");
ret.put("msg", "请填写用户名!");
return ret;
}
// if(StringUtils.isEmpty(user.getPassword())){
// ret.put("type", "error");
// ret.put("msg", "请填写密码!");
// return ret;
// }
if(user.getRoleId() == null){
ret.put("type", "error");
ret.put("msg", "请选择所属角色!");
return ret;
}
if(isExist(user.getUsername(), user.getId())){
ret.put("type", "error");
ret.put("msg", "该用户名已经存在,请重新输入!");
return ret;
}
if(userService.edit(user) <= 0){
ret.put("type", "error");
ret.put("msg", "用户添加失败,请联系管理员!");
return ret;
}
ret.put("type", "success");
ret.put("msg", "角色添加成功!");
return ret;
}
/**
* 批量删除用户
* @param ids
* @return
*/
@RequestMapping(value="/delete",method=RequestMethod.POST)
@ResponseBody
public Map<String, String> delete(String ids){
Map<String, String> ret = new HashMap<String, String>();
if(StringUtils.isEmpty(ids)){
ret.put("type", "error");
ret.put("msg", "选择要删除的数据!");
return ret;
}
if(ids.contains(",")){
ids = ids.substring(0,ids.length()-1);
}
if(userService.delete(ids) <= 0){
ret.put("type", "error");
ret.put("msg", "用户删除失败,请联系管理员!");
return ret;
}
ret.put("type", "success");
ret.put("msg", "用户删除成功!");
return ret;
}
/**
* 上传图片
* @param photo
* @param request
* @return
*/
@RequestMapping(value="/upload_photo",method=RequestMethod.POST)
@ResponseBody
public Map<String, String> uploadPhoto(MultipartFile photo,HttpServletRequest request){
Map<String, String> ret = new HashMap<String, String>();
if(photo == null){
ret.put("type", "error");
ret.put("msg", "选择要上传的文件!");
return ret;
}
if(photo.getSize() > 1024*1024*1024){
ret.put("type", "error");
ret.put("msg", "文件大小不能超过10M!");
return ret;
}
//获取文件后缀
String suffix = photo.getOriginalFilename().substring(photo.getOriginalFilename().lastIndexOf(".")+1,photo.getOriginalFilename().length());
if(!"jpg,jpeg,gif,png".toUpperCase().contains(suffix.toUpperCase())){
ret.put("type", "error");
ret.put("msg", "请选择jpg,jpeg,gif,png格式的图片!");
return ret;
}
String savePath = request.getSession().getServletContext().getRealPath("/") + "/resources/upload/";
File savePathFile = new File(savePath);
if(!savePathFile.exists()){
//若不存在改目录,则创建目录
savePathFile.mkdir();
}
String filename = new Date().getTime()+"."+suffix;
try {
//将文件保存至指定目录
photo.transferTo(new File(savePath+filename));
}catch (Exception e) {
// TODO Auto-generated catch block
ret.put("type", "error");
ret.put("msg", "保存文件异常!");
e.printStackTrace();
return ret;
}
ret.put("type", "success");
ret.put("msg", "上传成功!");
ret.put("filepath",request.getSession().getServletContext().getContextPath() + "/resources/upload/" + filename );
return ret;
}
/**
* 判断该用户名是否存在
* @param username
* @param id
* @return
*/
private boolean isExist(String username,Long id){
User user = userService.findByUsername(username);
if(user == null)return false;
if(user.getId().longValue() == id.longValue())return false;
return true;
}
}
角色role控制器:
/**
* 角色role控制器
*
*/
@RequestMapping("/admin/role")
@Controller
public class RoleController {
@Autowired
private RoleService roleService;
@Autowired
private AuthorityService authorityService;
@Autowired
private MenuService menuService;
/**
* 角色列表页面
* @param model
* @return
*/
@RequestMapping(value="/list",method=RequestMethod.GET)
public ModelAndView list(ModelAndView model){
model.setViewName("/role/list");
return model;
}
/**
* 获取角色列表
* @param page
* @param name
* @return
*/
@RequestMapping(value="/list",method=RequestMethod.POST)
@ResponseBody
public Map<String, Object> getList(Page page,
@RequestParam(name="name",required=false,defaultValue="") String name
){
Map<String, Object> ret = new HashMap<String, Object>();
Map<String, Object> queryMap = new HashMap<String, Object>();
queryMap.put("name", name);
queryMap.put("offset", page.getOffset());
queryMap.put("pageSize", page.getRows());
ret.put("rows", roleService.findList(queryMap));
ret.put("total", roleService.getTotal(queryMap));
return ret;
}
/**
* 角色添加
* @param role
* @return
*/
@RequestMapping(value="/add",method=RequestMethod.POST)
@ResponseBody
public Map<String, String> add(Role role){
Map<String, String> ret = new HashMap<String, String>();
if(role == null){
ret.put("type", "error");
ret.put("msg", "请填写正确的角色信息!");
return ret;
}
if(StringUtils.isEmpty(role.getName())){
ret.put("type", "error");
ret.put("msg", "请填写角色名称!");
return ret;
}
if(roleService.add(role) <= 0){
ret.put("type", "error");
ret.put("msg", "角色添加失败,请联系管理员!");
return ret;
}
ret.put("type", "success");
ret.put("msg", "角色添加成功!");
return ret;
}
/**
* 角色修改
* @param role
* @return
*/
@RequestMapping(value="/edit",method=RequestMethod.POST)
@ResponseBody
public Map<String, String> edit(Role role){
Map<String, String> ret = new HashMap<String, String>();
if(role == null){
ret.put("type", "error");
ret.put("msg", "请填写正确的角色信息!");
return ret;
}
if(StringUtils.isEmpty(role.getName())){
ret.put("type", "error");
ret.put("msg", "请填写角色名称!");
return ret;
}
if(roleService.edit(role) <= 0){
ret.put("type", "error");
ret.put("msg", "角色修改失败,请联系管理员!");
return ret;
}
ret.put("type", "success");
ret.put("msg", "角色修改成功!");
return ret;
}
/**
* 删除角色信息
* @param id
* @return
*/
@RequestMapping(value="/delete",method=RequestMethod.POST)
@ResponseBody
public Map<String, String> delete(Long id){
Map<String, String> ret = new HashMap<String, String>();
if(id == null){
ret.put("type", "error");
ret.put("msg", "请选择要删除的角色!");
return ret;
}
try {
if(roleService.delete(id) <= 0){
ret.put("type", "error");
ret.put("msg", "删除失败,请联系管理员!");
return ret;
}
} catch (Exception e) {
// TODO: handle exception
ret.put("type", "error");
ret.put("msg", "该角色下存在权限或者用户信息,不能删除!");
return ret;
}
ret.put("type", "success");
ret.put("msg", "角色删除成功!");
return ret;
}
/**
* 获取所有的菜单信息
* @return
*/
@RequestMapping(value="/get_all_menu",method=RequestMethod.POST)
@ResponseBody
public List<Menu> getAllMenu(){
return menuService.list();
}
/**
* 添加权限
* @param ids
* @return
*/
@RequestMapping(value="/add_authority",method=RequestMethod.POST)
@ResponseBody
public Map<String, String> addAuthority(
@RequestParam(name="ids",required=true) String ids,
@RequestParam(name="roleId",required=true) Long roleId
){
Map<String,String> ret = new HashMap<String, String>();
if(StringUtils.isEmpty(ids)){
ret.put("type", "error");
ret.put("msg", "请选择相应的权限!");
return ret;
}
if(roleId == null){
ret.put("type", "error");
ret.put("msg", "请选择相应的角色!");
return ret;
}
if(ids.contains(",")){
ids = ids.substring(0,ids.length()-1);
}
String[] idArr = ids.split(",");
if(idArr.length > 0){
authorityService.deleteByRoleId(roleId);
}
for(String id:idArr){
Authority authority = new Authority();
authority.setMenuId(Long.valueOf(id));
authority.setRoleId(roleId);
authorityService.add(authority);
}
ret.put("type", "success");
ret.put("msg", "权限编辑成功!");
return ret;
}
/**
* 获取某个角色的所有权限
* @param roleId
* @return
*/
@RequestMapping(value="/get_role_authority",method=RequestMethod.POST)
@ResponseBody
public List<Authority> getRoleAuthority(
@RequestParam(name="roleId",required=true) Long roleId
){
return authorityService.findListByRoleId(roleId);
}
}
设备管理控制层:
@Controller
@RequestMapping("/admin/devOrder")
public class DevOrderController {
@Autowired
DevOrderService devOrderService;
@Autowired
DeviceService deviceService;
@Autowired
UserService userService;
//设备借用列表页面
@RequestMapping(value="/list",method=RequestMethod.GET)
public String list(){
return "order/devOrder";
}
//我的设备申请页面
@RequestMapping(value="/mylist",method=RequestMethod.GET)
public String mylist(){
return "order/myDevOrder";
}
//获取用户个人设备列表
@RequestMapping(value="/mylist",method=RequestMethod.POST)
@ResponseBody
public EasyUIDataGridResult mylist(Integer page, Integer rows,
@RequestParam(name="uid",required=false,defaultValue="") Integer uid,
@RequestParam(name="name",required=false,defaultValue="") String name,
@RequestParam(name="astatus",required=false,defaultValue="") Integer astatus,
@RequestParam(name="rstatus",required=false,defaultValue="") Integer rstatus,
@RequestParam(name="btime",required=false,defaultValue="") String btime,
@RequestParam(name="rtime",required=false,defaultValue="") String rtime){
Map<String, Object> query = new HashMap<String, Object>();
query.put("page",page);
query.put("rows",rows);
query.put("uid", uid);
query.put("name", name);
query.put("astatus",astatus);
query.put("rstatus",rstatus);
query.put("btime",btime);
query.put("rtime",rtime);
EasyUIDataGridResult result = devOrderService.myList(query);
return result;
}
//获取设备列表
@RequestMapping(value="/list",method=RequestMethod.POST)
@ResponseBody
public EasyUIDataGridResult getlist(Integer page, Integer rows,
@RequestParam(name="name",required=false,defaultValue="") String name,
@RequestParam(name="username",required=false,defaultValue="") String username,
@RequestParam(name="astatus",required=false,defaultValue="") Integer astatus,
@RequestParam(name="rstatus",required=false,defaultValue="") Integer rstatus,
@RequestParam(name="btime",required=false,defaultValue="") String btime,
@RequestParam(name="rtime",required=false,defaultValue="") String rtime){
Map<String, Object> query = new HashMap<String, Object>();
User user = userService.findByUsername(username);
if (user != null) {
query.put("uid", user.getId());
}
else {
query.put("uid", null);
}
query.put("page",page);
query.put("rows",rows);
query.put("name", name);
query.put("astatus",astatus);
query.put("rstatus",rstatus);
query.put("btime",btime);
query.put("rtime",rtime);
EasyUIDataGridResult result = devOrderService.getList(query);
return result;
}
//新增设备借用
@RequestMapping(value="/add", method=RequestMethod.POST)
@ResponseBody
public E3Result add(DevOrder deviceBorrow){
Device device = deviceService.findByname(deviceBorrow.getName());
if (device.getQuantity() < (device.getUsable()+deviceBorrow.getNumber())) {
return E3Result.build(400, "库存不足");
}
Long id = IDUtils.genId();
deviceBorrow.setId(id);
deviceBorrow.setAstatus(1);
deviceBorrow.setRstatus(0);
E3Result e3Result = devOrderService.add(deviceBorrow);
return e3Result;
}
//审核更新借用
@RequestMapping(value="/edit", method=RequestMethod.POST)
@ResponseBody
public E3Result edit(String ids){
Long id;
String[] idss = ids.split(",");
if (idss.length > 1){
for (int i = 0; i < idss.length; i++){
id = Long.parseLong(idss[i]);
DevOrder order = devOrderService.findById(id);
Device device = deviceService.findByname(order.getName());
if (device.getUsable() < order.getNumber()) {
return E3Result.build(400, "库存不足");
}
device.setUsable(device.getUsable() - order.getNumber());
Integer integer = devOrderService.edit(id);
try {
MailUtils.sendMail(order.getEmail(), userService.findById(order.getUid()).getUsername()+",您好",
order.getName()+"申请成功,请尽快到实验室领取");
} catch (AddressException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (MessagingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if (integer < 1){
return E3Result.build(400, "审核失败!");
}
}
return E3Result.build(200, "审核成功");
}
else {
id = Long.parseLong(ids);
DevOrder order = devOrderService.findById(id);
Device device = deviceService.findByname(order.getName());
if (device.getUsable() < order.getNumber()) {
return E3Result.build(400, "库存不足");
}
device.setUsable(device.getUsable() - order.getNumber());
deviceService.edit(device);
Integer integer = devOrderService.edit(id);
try {
MailUtils.sendMail(order.getEmail(), userService.findById(order.getUid()).getUsername()+",您好",
order.getName()+"申请成功,请尽快到实验室领取");
} catch (AddressException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (MessagingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return E3Result.build(200, "审核成功");
}
}
//删除\拒绝
@RequestMapping("/delete")
@ResponseBody
public E3Result delete(String ids){
Long id;
String[] idss = ids.split(",");
if (idss.length > 1){
for (int i = 0; i < idss.length; i++){
id = Long.parseLong(idss[i]);
DevOrder order = devOrderService.findById(id);
if (order.getAstatus() == 1) {
try {
MailUtils.sendMail(order.getEmail(), userService.findById(order.getUid()).getUsername()+",您好",
order.getName()+"申请失败");
} catch (AddressException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (MessagingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
Integer integer = devOrderService.delete(id);
if (integer < 1){
return E3Result.build(400, "失败!");
}
}
return E3Result.build(200, "成功");
}
else {
id = Long.parseLong(ids);
DevOrder order = devOrderService.findById(id);
if (order.getAstatus() == 1) {
try {
MailUtils.sendMail(order.getEmail(), userService.findById(order.getUid()).getUsername()+",您好",
order.getName()+"申请失败");
} catch (AddressException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (MessagingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
Integer integer = devOrderService.delete(id);
return E3Result.build(200, "成功");
}
}
//归还
@RequestMapping("/retEdit")
@ResponseBody
public E3Result retEdit(String ids){
Long id;
String[] idss = ids.split(",");
if (idss.length > 1){
for (int i = 0; i < idss.length; i++){
id = Long.parseLong(idss[i]);
DevOrder order = devOrderService.findById(id);
if (order.getAstatus() == 1) {
return E3Result.build(400, "该项尚未审核");
}
Integer integer = devOrderService.retEdit(id);
if (integer < 1){
return E3Result.build(400, "失败!");
}
}
return E3Result.build(200, "成功");
}
else {
id = Long.parseLong(ids);
DevOrder order = devOrderService.findById(id);
if (order.getAstatus() == 1) {
return E3Result.build(400, "该项尚未审核");
}
Integer integer = devOrderService.retEdit(id);
Device device = deviceService.findByname(order.getName());
device.setUsable(device.getUsable() + order.getNumber());
deviceService.edit(device);
return E3Result.build(200, "成功");
}
}
}
源码获取:俺的博客首页 "资源" 里下载!