Java项目:设备台账管理系统(java+SSM+HTML+JSP+JS+mysql)
管理员角色包含以下功能:管理员登录,物理设备管理,IP地址资源管理,虚拟机管理,通知公告管理,学历管理,部门管理,员工管理等功能。员工角色包含以下功能:员工角色登录,查看物理设备,查看IP地址,查看虚拟机,通知公告查看等功能。1.运行环境:最好是java jdk 1.8,我们在这个平台上运行的。其他版本理论上也可以。2.IDE环境:IDEA,Eclipse,Myeclipse都可以。推荐IDEA;
源码获取:俺的博客首页 "资源" 里下载!
项目介绍
管理员角色包含以下功能:
管理员登录,物理设备管理,IP地址资源管理,虚拟机管理,通知公告管理,学历管理,部门管理,员工管理等功能。
员工角色包含以下功能:
员工角色登录,查看物理设备,查看IP地址,查看虚拟机,通知公告查看等功能。
环境需要
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版本;
技术栈
1. 后端:Spring+SpringMVC+Mybatis
2. 前端:HTML+CSS+JavaScript+jsp
使用说明
1. 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件;
2. 使用IDEA/Eclipse/MyEclipse导入项目,Eclipse/MyEclipse导入时,若为maven项目请选择maven;
若为maven项目,导入成功后请执行maven clean;maven install命令,然后运行;
3. 将项目中application.yml配置文件中的数据库配置改为自己的配置;
4. 运行项目,输入localhost:8080/ 登录
系统用户管理控制层:
@Controller
public class SysuserController {
@Resource
private SysuserServier userService;
@RequestMapping("flogin.do")
public String login() {
return "login";
}
@RequestMapping("admin/showUserInfo.do")
public String showUserInfo(ModelMap map,HttpSession session){
if(session.getAttribute("auser")==null){
return "login";
}
Sysuser u=(Sysuser)session.getAttribute("auser");
map.put("user",userService.getById(u.getUid()));
return "admin/update_user_persion";
}
@RequestMapping("admin/updatePersionUser.do")
public String updateUserInfo(ModelMap map,HttpSession session,Sysuser user){
userService.update(user);
map.put("user", userService.getById(user.getUid()));
session.setAttribute("suc", "cc");
return "redirect:showUserInfo.do";
}
@RequestMapping("admin/login.do")
public String aLogin() {
return "admin/login";
}
// 处理修改个人信息
@RequestMapping("showInfo.do")
public String showInfo(HttpSession session,ModelMap map) {
Sysuser u=(Sysuser)session.getAttribute("user");
if(u==null){
return "fore_login";
}else{
map.put("user", userService.getById(u.getUid()));
return "showUserinfo";
}
}
// 处理修改个人信息
@RequestMapping("addShowInfo.do")
public String addShowInfo(HttpSession session,ModelMap map,Sysuser user) {
userService.update(user);
return "success";
}
// 文件上传
public String fileUpload(@RequestParam(value="file",required=false)MultipartFile file,
HttpServletRequest request,String img){
String path=request.getSession().getServletContext().getRealPath("upload");
System.out.println("path==="+path);
System.out.println("file==="+file);
String fileName=file.getOriginalFilename();
System.out.println("fileName==="+fileName);
File targetFile=new File(path,fileName);
if(!targetFile.exists()){
targetFile.mkdirs();
}
try {
file.transferTo(targetFile);
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
String pa=request.getContextPath()+"/upload/"+fileName;
System.out.println("path==="+pa);
if(fileName!=null&&!fileName.equals("")){
img=fileName;
}else{
img=null;
}
return img;
}
// 后台登录
@RequestMapping("admin/alogin.do")
public String checkLogin(ModelMap map,Sysuser user, HttpSession session) {
Map<String,Object> u=new HashMap<String,Object>();
System.out.println("name===" + user.getUname());
System.out.println("pwd===" + user.getPwd());
u.put("uname",user.getUname());
u.put("utype", user.getUtype());
u.put("pwd",user.getPwd());
user = userService.adminLogin(u);
if (user != null) {
session.setAttribute("auser", user);
System.out.println("auser=" + user);
return "admin/index";
} else {
map.put("errorInfo", "用户名或者密码错误!");
return "admin/login";
}
}
// 后台注销登录
@RequestMapping("admin/loginout.do")
public String adminLoginOut(HttpSession session) {
session.removeAttribute("auser");
return "redirect:login.do";
}
// 前台注销登录
@RequestMapping("loginout.do")
public String loginOut(HttpSession session) {
session.removeAttribute("user");
session.removeAttribute("p");
return "fore_login";
}
// 验证用户名是否存在
@RequestMapping("admin/checkUname.do")
public void checkUname(Sysuser user,HttpServletResponse response){
Map<String,Object> map=new HashMap<String,Object>();
map.put("uname", user.getUname());
System.out.println("uname==="+user.getUname());
System.out.println("uname222==="+userService.checkUname(map));
JSONObject obj=new JSONObject();
if(userService.checkUname(map)!=null){
obj.put("info", "ok");
}else{
obj.put("info", "用户名可以用!");
}
response.setContentType("text/html;charset=utf-8");
PrintWriter out=null;
try {
out=response.getWriter();
out.print(obj);
out.flush();
} catch (IOException e) {
e.printStackTrace();
}finally{
out.close();
}
}
@RequestMapping("checkmibao.do")
public void checkMB(Sysuser user,HttpServletResponse response,HttpSession session){
JSONObject obj=new JSONObject();
Sysuser u=userService.getById(user.getUid());
String q=u.getQuestion();
if(u==null||u.equals("")){
obj.put("info", "ng");
}else{
if(q.equals(user.getQuestion())){
obj.put("info", u.getPwd());
}else{
obj.put("info", "ng");
}
}
response.setContentType("text/html;charset=utf-8");
PrintWriter out=null;
try {
out=response.getWriter();
out.print(obj);
out.flush();
} catch (IOException e) {
e.printStackTrace();
}finally{
out.close();
}
}
// 验证用户名是否存在
@RequestMapping("checkUname.do")
public void checkReg(Sysuser user,HttpServletResponse response){
Map map=new HashMap();
map.put("uname", user.getUname());
System.out.println("uname==="+user.getUname());
System.out.println("uname222==="+userService.checkUname(map));
JSONObject obj=new JSONObject();
if(userService.checkUname(map)!=null){
System.out.println("uname233333333333===");
obj.put("info", "ng");
}else{
System.out.println("uname255555555555555===");
obj.put("info", "用户名可以用!");
}
response.setContentType("text/html;charset=utf-8");
PrintWriter out=null;
try {
out=response.getWriter();
out.print(obj);
out.flush();
} catch (IOException e) {
e.printStackTrace();
}finally{
out.close();
}
}
@RequestMapping("checkPass.do")
public void checkPass(Sysuser user,HttpServletResponse response){
Map map=new HashMap();
map.put("uname", user.getUname());
System.out.println("uname==="+user.getUname());
System.out.println("uname222==="+userService.checkUname(map));
JSONObject obj=new JSONObject();
if(userService.checkUname(map)!=null){
obj.put("info", userService.checkUname(map).getPwd());
}else{
obj.put("info", "ng");
}
response.setContentType("text/html;charset=utf-8");
PrintWriter out=null;
try {
out=response.getWriter();
out.print(obj);
out.flush();
} catch (IOException e) {
e.printStackTrace();
}finally{
out.close();
}
}
@RequestMapping("reg.do")
public String addReg(Sysuser user, HttpSession session) {
user.setIsdel("1");
user.setUtype("会员");
Timestamp time=new Timestamp(System.currentTimeMillis());
user.setPubtime(time.toString());
userService.add(user);
return "fore_login";
}
// 添加用户
@RequestMapping("admin/addUser.do")
public String addUser(Sysuser user, HttpSession session) {
user.setIsdel("1");
Timestamp time=new Timestamp(System.currentTimeMillis());
user.setPubtime(time.toString());
userService.add(user);
return "redirect:userList.do";
}
// 管理员注册
@RequestMapping("admin/addUser2.do")
public String addUser2(Sysuser user, HttpSession session) {
user.setIsdel("1");
Timestamp time=new Timestamp(System.currentTimeMillis());
user.setPubtime(time.toString());
userService.add(user);
return "admin/login";
}
// 处理更新用户的信息
@RequestMapping("admin/doUpdateUser.do")
public String doUpdateUser(ModelMap map, int id) {
System.out.println("id=="+id);
map.put("user",userService.getById(id));
return "admin/update_user";
}
// 更新用户的信息
@RequestMapping("admin/updateUser.do")
public String updateUser(Sysuser user) {
userService.update(user);
return "redirect:userList.do";
}
// 查询所有用户的信息
@RequestMapping("admin/userList.do")
public String userList(@RequestParam(value = "page", required = false) String page, HttpSession session,
ModelMap map) {
if (page == null || page.equals("")) {
page = "1";
}
PageBean pageBean = new PageBean(Integer.parseInt(page), PageBean.PAGESIZE);
Map<String, Object> pmap = new HashMap<String, Object>();
pmap.put("pageno", pageBean.getStart());
pmap.put("pageSize", pageBean.getPageSize());
Map cmap=new HashMap();
/*pmap.put("utype", "会员");
cmap.put("utype", "会员");*/
int total = userService.getCount(cmap);
pageBean.setTotal(total);
List<Sysuser> list = userService.getByPage(pmap);
map.put("page", pageBean);
map.put("list", list);
session.setAttribute("p", 1);
return "admin/user_list";
}
// 模糊查询并分页
@RequestMapping("admin/userListQuery.do")
public String useListQuery(@RequestParam(value = "page", required = false) String page, HttpSession session,
ModelMap map,Sysuser user) {
if (page == null || page.equals("")) {
page = "1";
}
PageBean pageBean = new PageBean(Integer.parseInt(page), PageBean.PAGESIZE);
Map<String, Object> pmap = new HashMap<String, Object>();
pmap.put("pageno", pageBean.getStart());
pmap.put("pageSize", pageBean.getPageSize());
pmap.put("uname", user.getUname());
Map cmap=new HashMap();
/* pmap.put("utype", "会员");
cmap.put("utype", "会员");*/
int total = userService.getCount(pmap);
pageBean.setTotal(total);
List<Sysuser> list = userService.getByPage(pmap);
map.put("page", pageBean);
map.put("list", list);
session.setAttribute("p", 2);
return "admin/user_list";
}
@RequestMapping("admin/deleteUser.do")
public String deleteUser(int id){
userService.delete(id);
return "redirect:userList.do";
}
}
设备信息控制层:
@Controller
@RequestMapping("/baseInfos")
public class BaseInfoController {
@Autowired
private BaseInfoService baseInfoService;
@Autowired
private LogService logService;
/**
* 获取所有设备类型信息
* @param map
* @return
*/
@RequestMapping("/type/list")
public String listDeviceType(ModelMap map){
List<DeviceType> typeList = baseInfoService.listDeviceType();
map.put("typeList",typeList);
return "deviceTypes::table-refresh";
}
/**
* 添加设备类型
* @param deviceType
* @return
*/
@PostMapping("/type")
@ResponseBody
public int addtDeviceType(DeviceType deviceType){
return baseInfoService.addtDeviceType(deviceType);
}
/**
* 删除设备类型
* @param typeId
* @return
*/
@DeleteMapping("/type/{typeId}")
@ResponseBody
public int delteDeviceTypByid(@PathVariable("typeId") String typeId){
return baseInfoService.deleteDeviceTypeById(typeId);
}
/**
* 修改设备类型
* @param deviceType
* @return
*/
@PutMapping("/type")
@ResponseBody
public int updateDeviceType(DeviceType deviceType){
return baseInfoService.updateDeviceType(deviceType);
}
/**
* 获取所有设备品牌信息
* @param map
* @return
*/
@RequestMapping("/brand/list")
public String listDeviceBrand(ModelMap map){
List<DeviceBrand> brandList = baseInfoService.listDeviceBrand();
map.put("brandList",brandList);
return "deviceBrands::table-refresh";
}
/**
* 添加设备品牌
* @param deviceBrand
* @return
*/
@PostMapping("/brand")
@ResponseBody
public int addtDeviceBrand(DeviceBrand deviceBrand){
return baseInfoService.addtDeviceBrand(deviceBrand);
}
/**
* 删除设备品牌
* @param brandId
* @return
*/
@DeleteMapping("/brand/{brandId}")
@ResponseBody
public int delteDeviceBrandByid(@PathVariable("brandId") String brandId){
return baseInfoService.deleteDeviceBrandById(brandId);
}
/**
* 修改品牌
* @param deviceBrand
* @return
*/
@PutMapping("/brand")
@ResponseBody
public int updateDeviceBrand(DeviceBrand deviceBrand){
return baseInfoService.updateDeviceBrand(deviceBrand);
}
/**
* 获取系统日志
* @param map
* @return
*/
@RequestMapping("/log")
public String listLog(ModelMap map, HttpServletRequest request){
String startTime = request.getParameter("startTime");
String endTime = request.getParameter("endTime");
List<SystemLog> logs = logService.listLogsByDate(startTime,endTime);
map.put("logList",logs);
return "system::logList-refresh";
}
}
设备管理控制层:
@Controller
@RequestMapping("/device")
public class DeviceController {
@Autowired
private DeviceService deviceService;
/**
* 获取所有设备信息
* @param map
* @return
*/
@GetMapping("/list/{pageName}")
public String listDevices(ModelMap map,@PathVariable("pageName") String pageName){
List<DeviceDTO> deviceDTOList = deviceService.listDeviceDto();
map.put("dtoList", deviceDTOList);
return pageName+"::table-refresh";
}
/**
* 按条件查询设备
* @param map
* @param pageName
* @return
*/
@PostMapping("/list")
public String listDeviceDTOByExample(ModelMap map,DeviceDTO example,String pageName,String userName){
List<DeviceDTO> deviceDTOList = deviceService.listDeviceDTOByexample(example);
if(!StringUtils.isEmpty(userName)){
deviceDTOList = deviceService.selectDeviceDTObyUserName(deviceDTOList,userName);
}
map.put("dtoList", deviceDTOList);
return pageName+"::table-refresh";
};
/**
* 根据id获取设备信息
* @param map
* @return
*/
@GetMapping("/{devId}")
public String getDeviceById(ModelMap map,@PathVariable("devId") String devId){
DeviceDTO dto = deviceService.getDeviceDtoById(devId);
map.put("detailDTO", dto);
return "deviceList::modal-refresh";
}
/**
* 新增设备
* @param request
* @return
* @throws ParseException
*/
@PostMapping
public String addDevice(HttpServletRequest request) throws ParseException {
Device device = new Device();
device.setDevId(request.getParameter("devId"));
device.setTypeId(request.getParameter("typeId"));
device.setBrandId(request.getParameter("brandId"));
device.setDevModel(request.getParameter("devModel"));
device.setErpCode(request.getParameter("erpCode"));
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
device.setPurchaseTime(sdf.parse(request.getParameter("purchaseTime")));
device.setLastUpate(new Date());
//新增设备基本信息时,触发器会自动新增设备使用信息和运行信息
deviceService.addDevice(device);
return "deviceManage";
}
/**
* 检查设备id是否重复
* @param devId
* @return
*/
@GetMapping("/checkDevId")
@ResponseBody
public int checkDevId(String devId){
DeviceDTO deviceDTO = deviceService.getDeviceDtoById(devId);
if (deviceDTO != null )
return 0;
else
return 1;
}
/**
* 修改设备基础信息
* @param request
* @return
* @throws ParseException
*/
@PutMapping("/baseInfo")
public String updateDevicveBaseInfo(HttpServletRequest request) throws ParseException {
Device device = new Device();
device.setDevId(request.getParameter("devId"));
device.setTypeId(request.getParameter("typeId"));
device.setBrandId(request.getParameter("brandId"));
device.setDevModel(request.getParameter("devModel"));
device.setErpCode(request.getParameter("erpCode"));
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
device.setPurchaseTime(sdf.parse(request.getParameter("purchaseTime")));
device.setLastUpate(new Date());
deviceService.updateDevice(device);
return "deviceManage";
}
/**
* 根据id删除设备
* @param devId
* @return
*/
@DeleteMapping
@ResponseBody
public int deleteDeviceById(@RequestBody String devId){
return deviceService.deleteDeviceById(devId);
}
/**
* 修改设备状态
* @param devId
* @param status
* @return
*/
@PutMapping("/status")
@ResponseBody
public int updateStatus(String devId,int status){
return deviceService.updateStatusByid(devId,status);
}
/**
* 分配设备持有者
* @return
*/
@PutMapping("/owner")
@ResponseBody
public int updateDevOwner(HttpServletRequest request){
String devId = request.getParameter("devId");
String[] groups = request.getParameter("groups").split(",");
return deviceService.updateDevOwnersByDevId(devId,groups);
};
/**
* 分配设备使用部门
* @param request
* @return
*/
@PutMapping("/org")
@ResponseBody
public int updateDevOrg(HttpServletRequest request){
String devId = request.getParameter("devId");
String fri_org = request.getParameter("fri_org");
String sec_org = request.getParameter("sec_org");
String orgid_addr = request.getParameter("orgid_addr");
return deviceService.updateDevOrgsByDevId(devId,fri_org,sec_org,orgid_addr);
};
/**
* 刷新使用信息模块
* @param map
* @param devId
* @return
*/
@GetMapping("/useage_info")
public String allotDevice(ModelMap map,String devId){
DeviceDTO deviceDTO = deviceService.getDeviceDtoById(devId);
map.put("deviceDTO",deviceDTO);
return "allotDevice::useage_info";
}
/**
* 导出报表
* @param response
* @param request
*/
@GetMapping("/exportExcel")
public void exportExcel(HttpServletRequest request,HttpServletResponse response){
String pageName = request.getParameter("pageName");
String[] headers = request.getParameter("headers").split(",");
deviceService.exportExcel(response,pageName,headers);
}
/**
* 下载模板
* @param request
* @param response
* @throws ServletException
* @throws IOException
*/
@GetMapping("/template")
public void downloadServlet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setCharacterEncoding("UTF-8");
//设置ContentType字段值
response.setContentType("text/html;charset=utf-8");
//获取所要下载的文件名称
String filename = request.getParameter("filename");
//下载文件所在目录
String folder = request.getServletContext().getRealPath("/WEB-INF/statics/file/");
//通知浏览器以下载的方式打开
response.addHeader("Content-type", "appllication/octet-stream");
response.addHeader("Content-Disposition", "attachment;filename="+filename);
//通知文件流读取文件
// InputStream in = request.getServletContext().getResourceAsStream(folder+filename);
InputStream in = new FileInputStream(folder+filename);
//获取response对象的输出流
OutputStream out = response.getOutputStream();
byte[] buffer = new byte[1024];
int len;
//循环取出流中的数据
while((len = in.read(buffer)) != -1){
out.write(buffer,0,len);
}
}
/**
* 获取图表统计数据
* @param request
* @return
* @throws ParseException
*/
@GetMapping("/statistics")
@ResponseBody
public Map<String, Object> reloadChart(HttpServletRequest request) throws ParseException {
String monthStr = request.getParameter("monthStr");
monthStr = subMonth(monthStr);
Map resultMap = new HashMap();
//设备类型统计
Map typeMap = deviceService.staDeviceByType(monthStr);
resultMap.put("typeMap",typeMap);
//设备品牌统计
Map brandMap = deviceService.staDeviceByBrand(monthStr);
resultMap.put("brandMap",brandMap);
//设备部门统计
Map orgMap = deviceService.staDeviceByOrg(monthStr);
resultMap.put("orgMap",orgMap);
//设备状态统计
Map statusMap = deviceService.staDeviceByStatus(monthStr);
resultMap.put("statusMap",statusMap);
return resultMap;
}
/**
* 传入具体日期 ,返回具体日期增加一个月。
* @param date 日期
* @return 2017-05-13
* @throws ParseException
*/
private String subMonth(String date) throws ParseException {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
Date dt = sdf.parse(date);
Calendar rightNow = Calendar.getInstance();
rightNow.setTime(dt);
rightNow.add(Calendar.MONTH, 1);
Date dt1 = rightNow.getTime();
String reStr = sdf.format(dt1);
return reStr;
}
@PostMapping("/file")
@ResponseBody
public Map uploadFile(HttpServletRequest request) throws Exception {
System.out.println("文件上传");
//文件上传的位置
String path = request.getSession().getServletContext().getRealPath("/upload");
File file = new File(path);
if(!file.exists()){
file.mkdirs();
}
//解析request对象,获取文件上传项
DiskFileItemFactory factory = new DiskFileItemFactory();
ServletFileUpload fileUpload = new ServletFileUpload(factory);
//解析
List<FileItem> list = fileUpload.parseRequest(request);
//遍历
for (FileItem item:list
) {
if(item.isFormField()){//普通表单项
} else{
String fileName = item.getName()+UUID.randomUUID();
//完成文件上传
item.write(new File(path,fileName));
//删除临时文件
item.delete();
return deviceService.fileRead(path+"/"+fileName);
}
}
return null;
}
}
源码获取:俺的博客首页 "资源" 里下载!
更多推荐
所有评论(0)