文章详情

短信预约-IT技能 免费直播动态提醒

请输入下面的图形验证码

提交验证

短信预约提醒成功

Java实战之实现OA办公管理系统

2024-04-02 19:55

关注

介绍

环境配置:

Jdk1.8 + Tomcat8.5 + mysql + Eclispe(IntelliJ IDEA,Eclispe,MyEclispe,Sts都支持)

项目技术:

JSP +Spring + SpringMVC + MyBatis + html+ css + JavaScript + JQuery + Ajax + layui+ maven等等

效果图

核心代码

用户管理控制层


 
@Controller
@RequestMapping("/user")
public class UserController extends BaseController{
 
    private String prefix = "system/user/";
 
    @Autowired
    IUserService iUserService;
    @Autowired
    IRoleService iRoleService;
    @Autowired
    IDeptService iDeptService;
    @Autowired
    IPositionService iPositionService;
 
    @Autowired
    private SysPasswordService passwordService;
 
 
 
    
    @RequestMapping("/tolist")
    @RequiresPermissions("user:list")
    public String toUserList()
    {
        return prefix + "user";
    }
 
 
    
    @RequestMapping("/tableList")
    @ResponseBody
    public TableDataInfo list(User user)
    {
        startPage();
        List<User> users = iUserService.selectByUser(user);
 
        return getDataTable(users);
    }
 
 
    
    @RequiresPermissions("user:update")
    @RequestMapping("/edit/{userId}")
    public String edit(@PathVariable("userId") String userId, Model model)
    {
        // 个人信息
        User user = iUserService.selectByPrimaryKey(userId);
        Map<String, Object> role_post_dept = getRole_Post_Dept();
        model.addAttribute("depts", role_post_dept.get("dept"));
        model.addAttribute("roles", role_post_dept.get("role"));
        model.addAttribute("positions", role_post_dept.get("position"));
        model.addAttribute("user", user);
        return prefix + "edit";
    }
 
    
    @PostMapping("/editSave")
    @RequiresPermissions("user:update")
    @Operlog(modal = "用户管理", descr = "修改用户信息")
    @ResponseBody
    public AjaxResult save(User user)
    {
        if (StringUtils.isNotNull(user.getUid()) && User.isBoss(user.getUid()))
        {
            return error("不允许修改管理员用户");
        }
        if(user.getPwd()!=null){
            user.setSalt(ShiroUtils.randomSalt());
            SimpleHash md5 = new SimpleHash("MD5", user.getPwd(), user.getSalt(), 1024);
            user.setPwd(md5.toHex());
        }
        return result(iUserService.updateByPrimaryKeySelective(user));
    }
 
 
    
    @RequestMapping("/toAdd")
    @RequiresPermissions("user:add")
    public String toaddUser(Model model)
    {
        Map<String, Object> role_post_dept = getRole_Post_Dept();
        model.addAttribute("depts", role_post_dept.get("dept"));
        model.addAttribute("roles", role_post_dept.get("role"));
        model.addAttribute("positions", role_post_dept.get("position"));
        return prefix + "add";
    }
 
    
 
    @RequestMapping("/addSave")
    @RequiresPermissions("user:add")
    @Operlog(modal = "用户管理", descr = "添加用户")
    @ResponseBody
    public AjaxResult addUser(User user)
    {
        user.setSalt(ShiroUtils.randomSalt());
        SimpleHash md5 = new SimpleHash("MD5", user.getPwd(), user.getSalt(), 1024);
        user.setPwd(md5.toHex());
        user.setAvatar(CsEnum.avatar.USER_AVATAR.getValue());
        user.setCreateTime(new Date());
        return result(iUserService.insertSelective(user));
    }
 
    
    @RequestMapping("/del")
    @RequiresPermissions("user:del")
    @Operlog(modal = "用户模块", descr = "删除用户")
    @ResponseBody
    public AjaxResult delByUserIds(String[] ids)
    {
        try
        {
            int i = iUserService.deleteByPrimaryKeys(ids);
        }
        catch (Exception e)
        {
            return error(e.getMessage());
        }
        return success();
    }
 
    
    @RequestMapping("/resetPwd/{userId}")
    @RequiresPermissions("user:update")
    public String editPwd(@PathVariable("userId") String id, Model model)
    {
        model.addAttribute("uid", id);
        return prefix + "resetPwd";
    }
 
 
    
 
    @RequestMapping("/resetPwd")
    @RequiresPermissions("user:update")
    @Operlog(modal = "用户模块", descr = "修改密码")
    @ResponseBody
    public AjaxResult resetPwd(User user)
    {
        return result(iUserService.resrtPwd(user));
    }
 
    
    @PostMapping("/checkPhoneUnique")
    @ResponseBody
    public String checkPhoneUnique(User user)
    {
        String uniqueFlag = "0";
        if (user != null)
        {
            uniqueFlag = iUserService.checkPhoneUnique(user);
        }
        return uniqueFlag;
    }
 
    
    @PostMapping("/checkEmailUnique")
    @ResponseBody
    public String checkEmailUnique(User user)
    {
        String uniqueFlag = "0";
        if (user != null)
        {
            uniqueFlag = iUserService.checkEmailUnique(user);
        }
        return uniqueFlag;
    }
 
 
    
    @PostMapping("/checkLoginNameUnique")
    @ResponseBody
    public String checkLoginNameUnique(User user)
    {
        String uniqueFlag = "0";
        if (user != null)
        {
            uniqueFlag = iUserService.checkLoginNameUnique(user);
        }
        return uniqueFlag;
    }
 
 
    public Map<String, Object> getRole_Post_Dept()
    {
        Map<String, Object> map = new HashMap<>();
//        角色
        List<Role> roles = iRoleService.selectRoleList(new Role());
//        部门信息
        List<Dept> depts = iDeptService.selectDeptList(new Dept());
//        岗位
        List<Position> positions = iPositionService.selectPositionList(new Position());
        map.put("role", roles);
        map.put("dept", depts);
        map.put("position", positions);
 
        return map;
    }
 
 
    
    @RequestMapping("/myMsg")
    public String ToMyMsg(Model model, HttpServletRequest request)
    {
        User user = iUserService.selectByPrimaryKey(getUserId());
        model.addAttribute("user", user);
        model.addAttribute("loginIp", HttpHeaderUtil.getIpAddr(request));
        return prefix + "profile/msg";
    }
 
 
    
    @RequestMapping("/resetMyPwd")
    public String toResetPwd(Model model)
    {
        User user = iUserService.selectByPrimaryKey(getUserId());
        model.addAttribute("user", user);
        return prefix + "profile/resetPwd";
    }
 
    
    @RequestMapping("/updateMyPwdSave")
    @ResponseBody
    @RequiresPermissions("user:update")
    @Operlog(modal = "个人信息", descr = "修改密码")
    public AjaxResult updateMyPwdSave(String password)
    {
        User user = new User();
        user.setSalt(ShiroUtils.randomSalt());
        SimpleHash md5 = new SimpleHash("MD5", password, user.getSalt(), 1024);
        user.setPwd(md5.toHex());
        user.setUid(getUserId());
        int i = iUserService.updateByPrimaryKeySelective(user);
        if (i > 0)
        {
            //更新shiro中的信息
            ShiroUtils.reloadUser(iUserService.selectByPrimaryKey(getUserId()));
            return success();
        }
        return error();
    }
 
    
    @RequestMapping("/updateAvatar")
    public String toupdateAvatar(Model model)
    {
        model.addAttribute("user", getUser());
        return prefix + "profile/avatar";
    }
 
    
    @RequestMapping("/updateAvatarSave")
    @RequiresPermissions("user:update")
    @Operlog(modal = "个人信息", descr = "修改头像")
    @ResponseBody
    public AjaxResult toupdateAvatar(MultipartFile file)
    {
        try
        {
            String imgPath = UploadFile.uploadUserImg(file);
            if (StringUtils.isEmpty(imgPath))
            {
                return error("图片上传失败,稍后再试!");
            }
 
            User user = new User();
            user.setUid(getUserId());
            user.setAvatar(imgPath);
            int i = iUserService.updateByPrimaryKeySelective(user);
            if (i > 0)
            {
                ShiroUtils.reloadUser(iUserService.selectByPrimaryKey(getUserId()));
            }
            return result(i);
        }
        catch (IOException e)
        {
            return error();
        }
        catch (FileSizeException e)
        {
            //文件过大
            return error(e.getMsg());
        }
        catch (FileNameLengthException e)
        {
            //文件名字超长
            return error(e.getMsg());
        }
    }
 
 
    
    @RequestMapping("/checkPassword")
    @ResponseBody
    public boolean checkPassword(String password)
    {
        //加密后与数据库密码比较
        User user = getUser();
        SimpleHash md5 = new SimpleHash("MD5", password, user.getSalt(), 1024);
        String oldPassword = md5.toHex();
        String pwd = getPwd();
        if (pwd.equals(oldPassword))
        {
            return true;
        }
        return false;
    }
 
 
}

部门管理控制层


@Controller
@RequestMapping("/dept")
public class DeptController extends BaseController{
 
    private String prefix = "system/dept/";
 
    @Autowired
    IDeptService iDeptService;
 
    @Autowired
    IUserService iUserService;
 
 
    
 
    @RequestMapping("/tolist")
    @RequiresPermissions("dept:list")
    public String tolist()
    {
        return prefix + "dept";
    }
 
 
    
    @RequestMapping("/ajaxlist")
    @ResponseBody
    public List<Dept> list(Dept dept)
    {
        List<Dept> depts = iDeptService.selectDeptList(dept);
        return depts;
    }
 
    
    @RequestMapping("/tableList")
    @ResponseBody
    public TableDataInfo listPag(Dept dept)
    {
        //开启分页
        startPage();
        List<Dept> depts = iDeptService.selectDeptList(dept);
        return getDataTable(depts);
    }
 
 
    
    @RequiresPermissions("dept:add")
    @RequestMapping("/toAdd")
    public String toAdd(Model model)
    {
        List<User> users = iUserService.selectByUser(new User());
        model.addAttribute("users", users);
        return prefix + "add";
    }
 
 
    
    @RequestMapping("/getDeptAndUserTreeData")
    @ResponseBody
    public List<Object> DeptAndUserTreeData()
    {
        List<Dept> depts = iDeptService.selectDeptAndUser();
 
        List<User> users=new ArrayList<>();
        LinkedList<Object> deptList = new LinkedList<>();
        for (Dept dept : depts)
        {
            Map<String, Object> deptMap = new HashMap();
            deptMap.put("name", dept.getDeptName());
            deptMap.put("id", null);
            users = dept.getUsers();
            LinkedList<Object> userlist = new LinkedList<>();
            for (User user : users)
            {
                Map<String, Object> userMap = new HashMap();
                userMap.put("name",user.getName());
                userMap.put("id",user.getUid());
                userMap.put("icon","/img/timg.jpg");
                userlist.add(userMap);
            }
            deptMap.put("children",userlist);
            deptList.add(deptMap);
        }
 
        return deptList;
    }
 
 
    
    @RequestMapping("/del")
    @RequiresPermissions("dept:del")
    @ResponseBody
    @Operlog(modal = "部门管理",descr = "删除部门")
    public AjaxResult del(String[] ids)
    {
        try
        {
            iDeptService.deleteByPrimaryKeys(ids);
        }
        catch (Exception e)
        {
            return error(e.getMessage());
        }
        return success();
    }
 
 
    
 
    @RequestMapping("/addSave")
    @Operlog(modal = "部门管理",descr = "添加部门")
    @RequiresPermissions("dept:add")
    @ResponseBody
    public AjaxResult addDept(Dept dept)
    {
        dept.setCreateTime(new Date());
        return  result(iDeptService.insertSelective(dept));
    }
 
 
    
    @RequestMapping("/edit/{id}")
    @RequiresPermissions("dept:update")
    public String edit(@PathVariable("id") String id, Model model)
    {
        Dept dept = iDeptService.selectByPrimaryKey(id);
        List<User> users = iUserService.selectByUser(new User());
        model.addAttribute("users", users);
 
        model.addAttribute("Dept", dept);
        return prefix + "edit";
 
    }
 
    
    @RequestMapping("/editSave")
    @RequiresPermissions("dept:update")
    @Operlog(modal = "部门管理",descr = "修改信息")
    @ResponseBody
    public AjaxResult save(Dept dept)
    {
        int i = 0;
        try
        {
            i = iDeptService.updateByPrimaryKeySelective(dept);
        }
        catch (Exception e)
        {
            return error(e.getMessage());
        }
        return result(i);
    }
 
 
    
    @PostMapping("/checkDeptNameUnique")
    @ResponseBody
    public String checkDeptNameUnique(Dept dept)
    {
        String uniqueFlag = "0";
        if (dept != null)
        {
            uniqueFlag = iDeptService.checkDeptNameUnique(dept);
        }
        return uniqueFlag;
    }
}

角色管理控制层


@Controller
@RequestMapping("/role")
public class RoleController extends BaseController{
    private String prefix = "system/role/";
 
 
    @Autowired
    IUserService iUserService;
 
    @Autowired
    IRoleService iRoleService;
 
    @Autowired
    IPermissionService iPermissionService;
 
    
    @RequestMapping("/tolist")
    @RequiresPermissions("role:list")
    public String tolist()
    {
        return prefix + "role";
    }
 
 
    
    @RequestMapping("/ajaxlist")
    @ResponseBody
    public List<Role> list(Role role)
    {
        List<Role> roles = iRoleService.selectRoleList(role);
        return roles;
    }
 
    
    @RequestMapping("/tableList")
    @ResponseBody
    public TableDataInfo listPag(Role role)
    {
        //开启分页
        startPage();
        List<Role> roles = iRoleService.selectRoleList(role);
        return getDataTable(roles);
    }
 
 
    
    @RequestMapping("/toAdd")
    @RequiresPermissions("role:add")
    public String toAdd(Model model)
    {
        return prefix + "add";
    }
 
 
    
    @RequestMapping("/del")
    @RequiresPermissions("role:del")
    @Operlog(modal = "角色管理",descr = "删除角色")
    @ResponseBody
    public AjaxResult del(Integer[] ids)
    {
        try
        {
            iRoleService.deleteByPrimaryKeys(ids);
        }
        catch (Exception e)
        {
            return error(e.getMessage());
        }
        return success();
    }
 
 
    
 
    @RequestMapping("/addSave")
    @RequiresPermissions("role:update")
    @Operlog(modal = "角色管理",descr = "添加角色")
    @ResponseBody
    public AjaxResult addRole(Role role, Integer[] ids)
    {
        role.setCreateTime(new Date());
        int insert = 0;
        try
        {
            if (StringUtils.isEmpty(ids))
            {
                ids = new Integer[0];
            }
            insert = iRoleService.insert(role, ids);
        }
        catch (Exception e)
        {
            return error(e.getMessage());
        }
        //清空缓存
        ShiroUtils.clearCachedAuthorizationInfo();
        return  result(insert);
    }
 
 
    
    @RequestMapping("/selectById/{roleId}")
    @ResponseBody
    public Role selectById(@PathVariable("roleId") Integer roleId)
    {
        Role role = iRoleService.selectByPrimaryKey(roleId);
        return role;
    }
 
 
    
    @RequestMapping("/edit/{id}")
    @RequiresPermissions("role:update")
    public String edit(@PathVariable("id") Integer id, Model model)
    {
        Role role = iRoleService.selectByPrimaryKey(id);
        model.addAttribute("Role", role);
        return prefix + "edit";
    }
 
    
    @RequestMapping("/editPower/{id}")
    @RequiresPermissions("role:update")
    public String editPower(@PathVariable("id") Integer id, Model model)
    {
        Role role = iRoleService.selectByPrimaryKey(id);
        model.addAttribute("Role", role);
        return prefix + "editPower";
    }
 
 
    
    @RequestMapping("/editSave")
    @RequiresPermissions("role:update")
    @Operlog(modal = "角色管理",descr = "修改角色信息")
    @ResponseBody
    public AjaxResult save(Role role)
    {
        int i = 0;
        try
        {
            i = iRoleService.updateByPrimaryKeySelective(role);
        }
        catch (Exception e)
        {
            return error(e.getMessage());
        }
        return result(i);
    }
 
 
    
    @RequestMapping("/editPowerSave")
    @RequiresPermissions("role:update")
    @Operlog(modal = "角色管理",descr = "修改角色权限")
    @ResponseBody
    public AjaxResult editPowerSave(Role role, Integer[] ids)
    {
        int i = 0;
        try
        {
            if (StringUtils.isEmpty(ids))
            {
                ids = new Integer[0];
            }
            i = iRoleService.updateByPrimaryKeyPowerSelective(role, ids);
        }
        catch (Exception e)
        {
            return error(e.getMessage());
        }
        //清空缓存
        ShiroUtils.clearCachedAuthorizationInfo();
        //如果用户正在修改的角色id 是当前用户的角色id 则刷新 subject的User信息
        if (role.getRoleId().equals(getRoleId()))
        {
            ShiroUtils.reloadUser(iUserService.selectByPrimaryKey(getUserId()));
        }
        return result(i);
    }
 
 
    
    @PostMapping("/checkRoleNameUnique")
    @ResponseBody
    public String checkDeptNameUnique(Role role)
    {
        String uniqueFlag = "0";
        if (role != null)
        {
            uniqueFlag = iRoleService.checkRoleNameUnique(role);
        }
        return uniqueFlag;
    }
}

会议室管理控制层


@Controller
@RequestMapping("/room")
public class MeetRoomController extends BaseController{
    private Logger log = LoggerFactory.getLogger(this.getClass());
    private String prefix = "system/room/";
 
 
    @Autowired
    private IMeetingRoomService iMeetingRoomService;
 
    
    @RequestMapping("/tolist")
    public String tolist()
    {
        return prefix + "room";
    }
 
 
    
    @RequestMapping("/ajaxlist")
    @ResponseBody
    public List<MeetingRoom> list(MeetingRoom meetingRoom)
    {
        List<MeetingRoom> meetingRooms = iMeetingRoomService.selectMeetRoomList(meetingRoom);
        return meetingRooms;
    }
 
    
    @RequestMapping("/tableList")
    @ResponseBody
    public TableDataInfo listPag(MeetingRoom meetingRoom)
    {
        //开启分页
        startPage();
        List<MeetingRoom> meetingRooms = iMeetingRoomService.selectMeetRoomList(meetingRoom);
        return getDataTable(meetingRooms);
    }
 
 
    
    @RequestMapping("/toAdd")
    @RequiresPermissions("meetRoom:list")
    public String toAdd()
    {
        return prefix + "add";
    }
 
 
    
    @RequestMapping("/del")
    @RequiresPermissions("meetRoom:del")
    @Operlog(modal = "会议室管理",descr = "删除会议室")
    @ResponseBody
    public AjaxResult del(Integer[] ids)
    {
        try
        {
            iMeetingRoomService.deleteByPrimaryKeys(ids);
        }
        catch (Exception e)
        {
            return error(e.getMessage());
        }
        return success();
    }
 
 
    
 
    @RequestMapping("/addSave")
    @RequiresPermissions("meetRoom:add")
    @Operlog(modal = "会议室管理",descr = "添加会议室")
    @ResponseBody
    public AjaxResult addMeetingRoom(MeetingRoom meetingRoom)
    {
        meetingRoom.setCreateTime(new Date());
        return result(iMeetingRoomService.insertSelective(meetingRoom));
    }
 
 
    
    @RequestMapping("/edit/{id}")
    @RequiresPermissions("meetRoom:update")
    public String edit(@PathVariable("id") Integer id, Model model)
    {
        MeetingRoom meetingRoom = iMeetingRoomService.selectByPrimaryKey(id);
        model.addAttribute("room", meetingRoom);
        return prefix + "edit";
 
    }
 
    
    @RequestMapping("/editSave")
    @RequiresPermissions("meetRoom:update")
    @Operlog(modal = "会议室管理",descr = "修改会议室")
    @ResponseBody
    public AjaxResult save(MeetingRoom meetingRoom)
    {
        return result(iMeetingRoomService.updateByPrimaryKeySelective(meetingRoom));
    }
 
 
    
    @PostMapping("/checkRoomNameUnique")
    @ResponseBody
    public String checkMeetingRoomNameUnique(MeetingRoom meetingRoom)
    {
        String uniqueFlag = "0";
        if (meetingRoom != null)
        {
            uniqueFlag = iMeetingRoomService.checkRoomNameUnique(meetingRoom);
        }
        return uniqueFlag;
    }
}

以上就是Java实战之实现OA办公管理系统的详细内容,更多关于Java办公管理系统的资料请关注编程网其它相关文章!

阅读原文内容投诉

免责声明:

① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。

② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341

软考中级精品资料免费领

  • 历年真题答案解析
  • 备考技巧名师总结
  • 高频考点精准押题
  • 2024年上半年信息系统项目管理师第二批次真题及答案解析(完整版)

    难度     813人已做
    查看
  • 【考后总结】2024年5月26日信息系统项目管理师第2批次考情分析

    难度     354人已做
    查看
  • 【考后总结】2024年5月25日信息系统项目管理师第1批次考情分析

    难度     318人已做
    查看
  • 2024年上半年软考高项第一、二批次真题考点汇总(完整版)

    难度     435人已做
    查看
  • 2024年上半年系统架构设计师考试综合知识真题

    难度     224人已做
    查看

相关文章

发现更多好内容

猜你喜欢

AI推送时光机
位置:首页-资讯-后端开发
咦!没有更多了?去看看其它编程学习网 内容吧
首页课程
资料下载
问答资讯