作者主页:舒克日记
简介:Java领域优质创作者、Java项目、学习资料、技术互助
文中获取源码
系统描述: OA办公管理系统,这是一款由jsp+ssm(spring+s pringmvc+mybatis)+mysql实现的简单的OA办公管理系统。
主要实现的功能:有员工注册登录,自动计算当前月迟到、早退、加班、缺勤天数并根据图表展示,任务管理 (任务发布、更新、删除、进度条展示完成度),通知管理(通知发布、更新、删除),站内信发布、回复、删除等,发布公告和任务及站内信时可上传图片等。
运行环境:jdk1.8 eclipse tomcat7 mysql5.7
运用技术:jsp+ssm(spring+s pringmvc+mybatis)+mysql
1.运行环境:最好是java jdk1.8,我们在这个平台上运行的。其他版本理论上也可以。
2.IDE环境:IDEA,Eclipse,Myeclipse都可以。推荐IDEA;
3.tomcat环境:Tomcat7.x,8.X,9.x版本均可
4.硬件环境:windows7/8/10 4G内存以上;或者Mac OS;
5.是否Maven项目:是;查看源码目录中是否包含pom.xml;若包含,则为maven项目,否则为非maven.项目
6.数据库:MySql5.7/8.0等版本均可;
后台框架:ssm、MyBatis
数据库:MySQL
环境:JDK8、TOMCAT、IDEA
1.使用Navicati或者其它工具,在mysql中创建对应sq文件名称的数据库,并导入项目的sql文件;
2.使用IDEA/Eclipse/MyEclipse导入项目,修改配置,运行项目;
3.将项目中config-propertiesi配置文件中的数据库配置改为自己的配置,然后运行;
idea导入源码空间站顶目教程说明(Vindows版)-ssm篇:
http://mtw.so/5MHvZq
源码地址:http://codegym.top。
HomeController
package com.noa.controller;
import java.util.List;
import javax.servlet.http.HttpSession;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import com.noa.po.Announcement;
import com.noa.po.AnnouncementCustom;
import com.noa.po.EmployeeCustom;
import com.noa.service.AnnouncementService;
import com.noa.service.AttendanceService;
import com.noa.service.EmployeeService;
import com.noa.service.SysService;
@Controller
public class HomeController {
@Autowired
EmployeeService employeeService;
@Autowired
AttendanceService attendanceService;
@Autowired
AnnouncementService announcementService;
@Autowired
SysService sysService;
EmployeeCustom activeEmp;
@RequestMapping("/home")
public String showHome(Model model,HttpSession session) throws Exception{
activeEmp = (EmployeeCustom) SecurityUtils.getSubject().getPrincipal();
session.setAttribute("activeEmp", activeEmp);
//展示出勤率,[0]正常 [1]加班 [2]迟到早退 [3]缺席[4]剩余天数
int[] attendance = attendanceService.countMonthState(activeEmp);
model.addAttribute("attendance",attendance);
//公告一览
List<AnnouncementCustom> announceList = announcementService.showAllAnnouncement(activeEmp);
model.addAttribute("announceList", announceList);
//可发布公告的对象
model.addAttribute("departmentList", sysService.getAbleToAnnounceDeps());
return "/home/home";
}
@RequestMapping("/announce.action")
@RequiresPermissions(value={"announce:create:all","announce:create:main","announce:create:sub"},logical=Logical.OR)
public String annouce(HttpSession session,String target,Announcement announcement) throws Exception{
activeEmp = (EmployeeCustom)session.getAttribute("activeEmp");
announcement.setText(announcement.getText().replaceAll("\r\n", "
"));
announcementService.announce(announcement, activeEmp);
return "redirect:/home";
}
@RequestMapping("/delete_announce.action")
public String deleteAnnouce(HttpSession session,Integer delete_id) throws Exception{
announcementService.deleteAnnouncement(delete_id);
return "redirect:/home";
}
}
CustomRealm
package com.noa.shiro;
import java.util.List;
import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authc.AuthenticationInfo;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authc.SimpleAuthenticationInfo;
import org.apache.shiro.authz.AuthorizationInfo;
import org.apache.shiro.authz.SimpleAuthorizationInfo;
import org.apache.shiro.realm.AuthorizingRealm;
import org.apache.shiro.subject.PrincipalCollection;
import org.apache.shiro.util.ByteSource;
import org.springframework.beans.factory.annotation.Autowired;
import com.noa.po.Employee;
import com.noa.po.EmployeeCustom;
import com.noa.service.EmployeeService;
import com.noa.service.SysService;
public class CustomRealm extends AuthorizingRealm {
@Autowired
EmployeeService employeeService;
@Autowired
SysService sysService;
@Override
public void setName(String name) {
super.setName("customRealm");
}
@Override // 认证, 认证失败返回null,
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
// 取出身份信息
String username = (String) token.getPrincipal();
Employee authenticateInfo = null;
try {
authenticateInfo = employeeService.findAccountByUsername(username);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// 不存在该username的account时,返回null
if (authenticateInfo == null) {
return null;
}
EmployeeCustom activeEmp = null;
try {
activeEmp = employeeService.findEmployeeById(authenticateInfo.getId());
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// 存在用户时返回SimpleAuthenticationInfo
SimpleAuthenticationInfo simpleAuthenticationInfo = new SimpleAuthenticationInfo(activeEmp,
authenticateInfo.getPassword(), ByteSource.Util.bytes(authenticateInfo.getSalt()), this.getName());
// 接下来由authenticator通过 散列算法(xml中设置) 和盐(第三个参数)和输入的password(token中)
// 与正确的密码匹配(第二个参数)
return simpleAuthenticationInfo;
}
@Override // 授权
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
EmployeeCustom activeEmp = (EmployeeCustom) principals.getPrimaryPrincipal();
List<String> permissionList = null;
try {
permissionList = sysService.getPermissionByEmpId(activeEmp.getId());
} catch (Exception e) {
e.printStackTrace();
}
SimpleAuthorizationInfo simpleAuthorizationInfo = new SimpleAuthorizationInfo();
simpleAuthorizationInfo.addStringPermissions(permissionList);
//计算出勤
if(simpleAuthorizationInfo != null){
try {
employeeService.login(employeeService.findEmployeeById(activeEmp.getId()));
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return simpleAuthorizationInfo;
}
}