实现的功能有:
管理员:系统管理、请假管理、公告管理、档案资料管理、通讯录管理、日常办公管理、邮箱管理消息管理等。
员工:登录、修改个人信息、请假(申请请假)、日常办公(工作日志、任务管理、日常管理)、通讯录查阅、档案资料管理(个人档案、公共档案、下载、上传)、查阅消息、邮件管理(收件箱、发邮件、已发邮件列表)、打卡考勤等。
部门经理:部门经理主要是对员工请假等一些列流程的审核。
运行环境:windows/Linux均可、jdk1.8、mysql5.7、redis3.0、idea/eclipse均可。
系统类型控制器:
@Controller
@RequestMapping("/")
public class TypeSysController {
Logger log = LoggerFactory.getLogger(getClass());
@Autowired
private TypeDao typeDao;
@Autowired
private TypeService typeService;
/**
* 进入类型管理表格界面
*
* @param req
* @return
*/
@RequestMapping("testsystype")
public String testsystype(HttpServletRequest req) {
Iterable typeList = typeDao.findAll();
req.setAttribute("typeList", typeList);
return "systemcontrol/typemanage";
}
/**
* 查找类型表格
*
* @param req
* @return
*/
@RequestMapping("typetable")
public String typeTable(HttpServletRequest req) {
if(!StringUtils.isEmpty(req.getParameter("name"))){
String name="%"+req.getParameter("name")+"%";
req.setAttribute("typeList",typeDao.findByTypeNameLikeOrTypeModelLike(name, name));
}
else{
Iterable typeList = typeDao.findAll();
req.setAttribute("typeList", typeList);
}
return "systemcontrol/typetable";
}
/**
* 类型编辑界面;
*
* @param req
* @return
*/
@RequestMapping("typeedit")
public String typeEdit(HttpServletRequest req) {
if (!StringUtils.isEmpty(req.getParameter("typeid"))) {
Long typeid = Long.parseLong(req.getParameter("typeid"));
SystemTypeList typeObj = typeDao.findOne(typeid);
req.setAttribute("typeObj", typeObj);
HttpSession session = req.getSession();
session.setAttribute("typeid", typeid);
}
return "systemcontrol/typeedit";
}
/**
* 系统管理表单验证
*
* @param req
* @param menu
* @param br
* 后台校验表单数据,不通过则回填数据,显示错误信息;通过则直接执行业务,例如新增、编辑等;
* @return
*/
@RequestMapping("typecheck")
public String testMess(HttpServletRequest req, @Valid SystemTypeList menu, BindingResult br) {
HttpSession session = req.getSession();
Long menuId = null;
req.setAttribute("menuObj", menu);
// 这里返回ResultVO对象,如果校验通过,ResultEnum.SUCCESS.getCode()返回的值为200;否则就是没有通过;
ResultVO res = BindingResultVOUtil.hasErrors(br);
// 校验失败
if (!ResultEnum.SUCCESS.getCode().equals(res.getCode())) {
List list = new MapToList<>().mapToList(res.getData());
req.setAttribute("errormess", list.get(0).toString());
// 代码调试阶段,下面是错误的相关信息;
System.out.println("list错误的实体类信息:" + menu);
System.out.println("list错误详情:" + list);
System.out.println("list错误第一条:" + list.get(0));
System.out.println("啊啊啊错误的信息——:" + list.get(0).toString());
// 下面的info信息是打印出详细的信息
log.info("getData:{}", res.getData());
log.info("getCode:{}", res.getCode());
log.info("getMsg:{}", res.getMsg());
}
// 校验通过,下面写自己的逻辑业务
else {
// 判断是否从编辑界面进来的,前面有"session.setAttribute("getId",getId);",在这里获取,并remove掉;
if (!StringUtils.isEmpty(session.getAttribute("typeid"))) {
System.out.println(session.getAttribute("typeid"));
menuId = (Long) session.getAttribute("typeid"); // 获取进入编辑界面的menuID值
menu.setTypeId(menuId);
log.info("getId:{}", session.getAttribute("typeid"));
session.removeAttribute("typeid");
}
// 执行业务代码
typeService.save(menu);
System.out.println("此操作是正确的");
req.setAttribute("success", "后台验证成功");
}
System.out.println("是否进入最后的实体类信息:" + menu);
return "systemcontrol/typeedit";
}
/**
* 执行删除方法
*/
@RequestMapping("deletetype")
public String deleteThis(HttpServletRequest req){
Long typeId=Long.parseLong(req.getParameter("id"));
typeService.deleteType(typeId);
return "forward:/testsystype";
}
}
系统状态控制器:
@Controller
@RequestMapping("/")
public class StatusSysController {
Logger log=LoggerFactory.getLogger(getClass());
@Autowired
private StatusDao statusDao;
@Autowired
private StatusService statusService;
/**
* 状态表格界面
* @param req
* @return
*/
@RequestMapping("testsysstatus")
public String testsysstatus(HttpServletRequest req){
Iterable statusList=statusDao.findAll();
req.setAttribute("statusList", statusList);
return "systemcontrol/statusmanage";
}
/**
* 查找状态表格
* @param req
* @return
*/
@RequestMapping("statustable")
public String statusTable(HttpServletRequest req){
if(!StringUtils.isEmpty(req.getParameter("name"))){
String name="%"+req.getParameter("name")+"%";
req.setAttribute("statusList",statusDao.findByStatusNameLikeOrStatusModelLike(name, name));
}
else{
Iterable statusList=statusDao.findAll();
req.setAttribute("statusList", statusList);
}
return "systemcontrol/statustable";
}
/**
* 状态编辑界面
* @param req
* @return
*/
@RequestMapping("statusedit")
public String typeEdit(HttpServletRequest req){
if(!StringUtils.isEmpty(req.getParameter("statusid"))){
Long statusid=Long.parseLong(req.getParameter("statusid"));
SystemStatusList statusList=statusDao.findOne(statusid);
req.setAttribute("status", statusList);
HttpSession session=req.getSession();
session.setAttribute("statusid", statusid);
}
return "systemcontrol/statusedit";
}
/**
* 系统管理表单验证
*
* @param req
* @param menu
* @param br
* 后台校验表单数据,不通过则回填数据,显示错误信息;通过则直接执行业务,例如新增、编辑等;
* @return
*/
@RequestMapping("statuscheck")
public String testMess(HttpServletRequest req, @Valid SystemStatusList menu, BindingResult br) {
req.setAttribute("menuObj", menu);
System.out.println(menu);
// 这里返回ResultVO对象,如果校验通过,ResultEnum.SUCCESS.getCode()返回的值为200;否则就是没有通过;
ResultVO res = BindingResultVOUtil.hasErrors(br);
// 校验失败
if (!ResultEnum.SUCCESS.getCode().equals(res.getCode())) {
List list = new MapToList<>().mapToList(res.getData());
req.setAttribute("errormess", list.get(0).toString());
// 代码调试阶段,下面是错误的相关信息;
System.out.println("list错误的实体类信息:" + menu);
System.out.println("list错误详情:" + list);
System.out.println("list错误第一条:" + list.get(0));
System.out.println("啊啊啊错误的信息——:" + list.get(0).toString());
// 下面的info信息是打印出详细的信息
log.info("getData:{}", res.getData());
log.info("getCode:{}", res.getCode());
log.info("getMsg:{}", res.getMsg());
}
// 校验通过,下面写自己的逻辑业务
else {
HttpSession session = req.getSession();
// 判断是否从编辑界面进来的,前面有"session.setAttribute("getId",getId);",在这里获取,并remove掉;
if (!StringUtils.isEmpty(session.getAttribute("statusid"))) {
Long menuId = (Long) session.getAttribute("statusid"); // 获取进入编辑界面的menuID值
menu.setStatusId(menuId);
session.removeAttribute("statusid");
}
// 执行业务代码
statusService.save(menu);
System.out.println("此操作是正确的");
req.setAttribute("success", "后台验证成功");
}
System.out.println("是否进入最后的实体类信息:" + menu);
return "systemcontrol/statusedit";
}
/**
* 删除方法
*/
@RequestMapping("deletestatus")
public String deleteStatus(HttpServletRequest req){
Long statusId=Long.parseLong(req.getParameter("id"));
statusService.deleteStatus(statusId);
return "forward:/testsysstatus";
}
}
用户的控制面板:
@Controller
@RequestMapping("/")
public class UserpanelController {
@Autowired
private UserDao udao;
@Autowired
private DeptDao ddao;
@Autowired
private PositionDao pdao;
@Autowired
private InformRelationDao irdao;
@Autowired
private MailreciverDao mdao;
@Autowired
private NotepaperDao ndao;
@Autowired
private NotepaperService nservice;
// @Value("${img.rootpath}")
private String rootpath;
@PostConstruct
public void UserpanelController(){
try {
rootpath= ResourceUtils.getURL("classpath:").getPath().replace("/target/classes/","/static/image");
System.out.println(rootpath);
}catch (IOException e){
System.out.println("获取项目路径异常");
}
}
@RequestMapping("userpanel")
public String index(@SessionAttribute("userId") Long userId,Model model,HttpServletRequest req,
@RequestParam(value = "page", defaultValue = "0") int page,
@RequestParam(value = "size", defaultValue = "10") int size){
Pageable pa=new PageRequest(page, size);
User user=null;
if(!StringUtil.isEmpty((String) req.getAttribute("errormess"))){
user=(User) req.getAttribute("users");
req.setAttribute("errormess",req.getAttribute("errormess"));
}
else if(!StringUtil.isEmpty((String) req.getAttribute("success"))){
user=(User) req.getAttribute("users");
req.setAttribute("success","fds");
}
else{
//找到这个用户
user=udao.findOne(userId);
}
//找到部门名称
String deptname=ddao.findname(user.getDept().getDeptId());
//找到职位名称
String positionname=pdao.findById(user.getPosition().getId());
//找未读通知消息
List noticelist=irdao.findByReadAndUserId(false, user);
//找未读邮件
List maillist=mdao.findByReadAndDelAndReciverId(false,false, user);
//找便签
Page list=ndao.findByUserIdOrderByCreateTimeDesc(user,pa);
List notepaperlist=list.getContent();
model.addAttribute("user", user);
model.addAttribute("deptname", deptname);
model.addAttribute("positionname", positionname);
model.addAttribute("noticelist", noticelist.size());
model.addAttribute("maillist", maillist.size());
model.addAttribute("notepaperlist", notepaperlist);
model.addAttribute("page", list);
model.addAttribute("url", "panel");
return "user/userpanel";
}
/**
* 上下页
*/
@RequestMapping("panel")
public String index(@SessionAttribute("userId") Long userId,Model model,
@RequestParam(value = "page", defaultValue = "0") int page,
@RequestParam(value = "size", defaultValue = "10") int size){
Pageable pa=new PageRequest(page, size);
User user=udao.findOne(userId);
//找便签
Page list=ndao.findByUserIdOrderByCreateTimeDesc(user,pa);
List notepaperlist=list.getContent();
model.addAttribute("notepaperlist", notepaperlist);
model.addAttribute("page", list);
model.addAttribute("url", "panel");
return "user/panel";
}
/**
* 存便签
*/
@RequestMapping("writep")
public String savepaper(Notepaper npaper,@SessionAttribute("userId") Long userId,@RequestParam(value="concent",required=false)String concent){
User user=udao.findOne(userId);
npaper.setCreateTime(new Date());
npaper.setUserId(user);
System.out.println("内容"+npaper.getConcent());
if(npaper.getTitle()==null|| npaper.getTitle().equals(""))
npaper.setTitle("无标题");
if(npaper.getConcent()==null|| npaper.getConcent().equals(""))
npaper.setConcent(concent);
ndao.save(npaper);
return "redirect:/userpanel";
}
/**
* 删除便签
*/
@RequestMapping("notepaper")
public String deletepaper(HttpServletRequest request,@SessionAttribute("userId") Long userId){
User user=udao.findOne(userId);
String paperid=request.getParameter("id");
Long lpid = Long.parseLong(paperid);
Notepaper note=ndao.findOne(lpid);
if(user.getUserId().equals(note.getUserId().getUserId())){
nservice.delete(lpid);
}else{
System.out.println("权限不匹配,不能删除");
return "redirect:/notlimit";
}
return "redirect:/userpanel";
}
/**
* 修改用户
* @throws IOException
* @throws IllegalStateException
*/
@RequestMapping("saveuser")
public String saveemp(@RequestParam("filePath")MultipartFile filePath,HttpServletRequest request,@Valid User user,
BindingResult br,@SessionAttribute("userId") Long userId) throws IllegalStateException, IOException{
String imgpath=nservice.upload(filePath);
User users=udao.findOne(userId);
//重新set用户
users.setRealName(user.getRealName());
users.setUserTel(user.getUserTel());
users.setEamil(user.getEamil());
users.setAddress(user.getAddress());
users.setUserEdu(user.getUserEdu());
users.setSchool(user.getSchool());
users.setIdCard(user.getIdCard());
users.setBank(user.getBank());
users.setSex(user.getSex());
users.setThemeSkin(user.getThemeSkin());
users.setBirth(user.getBirth());
if(!StringUtil.isEmpty(user.getUserSign())){
users.setUserSign(user.getUserSign());
}
if(!StringUtil.isEmpty(user.getPassword())){
users.setPassword(user.getPassword());
}
if(!StringUtil.isEmpty(imgpath)){
users.setImgPath(imgpath);
}
request.setAttribute("users", users);
ResultVO res = BindingResultVOUtil.hasErrors(br);
if (!ResultEnum.SUCCESS.getCode().equals(res.getCode())) {
List list = new MapToList<>().mapToList(res.getData());
request.setAttribute("errormess", list.get(0).toString());
System.out.println("list错误的实体类信息:" + user);
System.out.println("list错误详情:" + list);
System.out.println("list错误第一条:" + list.get(0));
System.out.println("啊啊啊错误的信息——:" + list.get(0).toString());
}else{
udao.save(users);
request.setAttribute("success", "执行成功!");
}
return "forward:/userpanel";
}
@RequestMapping("image/**")
public void image(Model model, HttpServletResponse response, @SessionAttribute("userId") Long userId, HttpServletRequest request)
throws Exception {
String projectPath = ClassUtils.getDefaultClassLoader().getResource("").getPath();
System.out.println(projectPath);
String startpath = new String(URLDecoder.decode(request.getRequestURI(), "utf-8"));
String path = startpath.replace("/image", "");
File f = new File(rootpath, path);
ServletOutputStream sos = response.getOutputStream();
FileInputStream input = new FileInputStream(f.getPath());
byte[] data = new byte[(int) f.length()];
IOUtils.readFully(input, data);
// 将文件流输出到浏览器
IOUtils.write(data, sos);
input.close();
sos.close();
}
}