java springbootOA办公自动化系统:
主要功能模块:系统、用户、角色、考勤、流程、公告、邮件、任务、日程、计划、文件、笔记、通讯录、讨论区等多个模块管理
使用Maven进行项目管理,基于springboot框架开发的项目,mysql底层数据库,前端采用freemarker模板引擎,Bootstrap作为前端UI框架,集成了jpa、mybatis等框架。
![](https://img-blog.csdnimg.cn/20210627101340736.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3Bhc3RjbG91ZHM=,size_16,color_FFFFFF,t_70)
![](https://img-blog.csdnimg.cn/20210627101351451.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3Bhc3RjbG91ZHM=,size_16,color_FFFFFF,t_70)
![](https://img-blog.csdnimg.cn/20210627101356942.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3Bhc3RjbG91ZHM=,size_16,color_FFFFFF,t_70)
![](https://img-blog.csdnimg.cn/20210627101417513.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3Bhc3RjbG91ZHM=,size_16,color_FFFFFF,t_70)
![](https://img-blog.csdnimg.cn/20210627101424602.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3Bhc3RjbG91ZHM=,size_16,color_FFFFFF,t_70)
![](https://img-blog.csdnimg.cn/20210627101437603.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3Bhc3RjbG91ZHM=,size_16,color_FFFFFF,t_70)
![](https://img-blog.csdnimg.cn/20210627101446888.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3Bhc3RjbG91ZHM=,size_16,color_FFFFFF,t_70)
![](https://img-blog.csdnimg.cn/20210627101500733.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3Bhc3RjbG91ZHM=,size_16,color_FFFFFF,t_70)
![](https://img-blog.csdnimg.cn/20210627101511653.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3Bhc3RjbG91ZHM=,size_16,color_FFFFFF,t_70)
![](https://img-blog.csdnimg.cn/20210627101528760.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3Bhc3RjbG91ZHM=,size_16,color_FFFFFF,t_70)
![](https://img-blog.csdnimg.cn/20210627101541506.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3Bhc3RjbG91ZHM=,size_16,color_FFFFFF,t_70)
![](https://img-blog.csdnimg.cn/20210627101600264.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3Bhc3RjbG91ZHM=,size_16,color_FFFFFF,t_70)
![](https://img-blog.csdnimg.cn/20210627101613130.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3Bhc3RjbG91ZHM=,size_16,color_FFFFFF,t_70)
![](https://img-blog.csdnimg.cn/20210627101623670.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3Bhc3RjbG91ZHM=,size_16,color_FFFFFF,t_70)
![](https://img-blog.csdnimg.cn/2021062710163061.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3Bhc3RjbG91ZHM=,size_16,color_FFFFFF,t_70)
![](https://img-blog.csdnimg.cn/20210627101641138.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3Bhc3RjbG91ZHM=,size_16,color_FFFFFF,t_70)
![](https://img-blog.csdnimg.cn/20210627101646786.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3Bhc3RjbG91ZHM=,size_16,color_FFFFFF,t_70)
![](https://img-blog.csdnimg.cn/20210627101656797.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3Bhc3RjbG91ZHM=,size_16,color_FFFFFF,t_70)
![](https://img-blog.csdnimg.cn/20210627101703147.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3Bhc3RjbG91ZHM=,size_16,color_FFFFFF,t_70)
![](https://img-blog.csdnimg.cn/20210627101712750.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3Bhc3RjbG91ZHM=,size_16,color_FFFFFF,t_70)
![](https://img-blog.csdnimg.cn/20210627101721796.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3Bhc3RjbG91ZHM=,size_16,color_FFFFFF,t_70)
![](https://img-blog.csdnimg.cn/20210627101747343.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3Bhc3RjbG91ZHM=,size_16,color_FFFFFF,t_70)
![](https://img-blog.csdnimg.cn/20210627101755174.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3Bhc3RjbG91ZHM=,size_16,color_FFFFFF,t_70)
![](https://img-blog.csdnimg.cn/20210627101803563.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3Bhc3RjbG91ZHM=,size_16,color_FFFFFF,t_70)
显示菜单管理和操作界面代码:
@Controller
@RequestMapping("/")
public class MenuSysController {
Logger log = LoggerFactory.getLogger(getClass());
@Autowired
private IndexDao iDao;
@Autowired
private MenuSysService menuService;
@Autowired
private UserDao uDao;
@Autowired
private RoleDao rdao;
@Autowired
private RolepowerlistDao rldao;
@Autowired
private RoleService roleService;
/**
* 显示菜单管理界面
* @param req
* @return
*/
@RequestMapping("testsysmenu")
public String testsysmenu(HttpServletRequest req) {
menuService.findAllMenuSys(req);
return "systemcontrol/menumanage";
}
/**
* 查找菜单
*/
@RequestMapping("menutable")
public String menuTable(HttpServletRequest req){
if(!StringUtils.isEmpty(req.getParameter("name"))){
req.setAttribute("oneMenuAll", iDao.findByMenuNameLike("%"+req.getParameter("name")+"%"));
}
else{
menuService.findAllMenuSys(req);
}
return "systemcontrol/menutable";
}
/**
* 改变排序
* @param req
* @return
*/
@RequestMapping("changeSortId")
public String changeSortId(HttpServletRequest req,@SessionAttribute("userId")Long userId) {
User user=uDao.findOne(userId);
Long parentId = Long.parseLong(req.getParameter("parentid"));
Long menuId = Long.parseLong(req.getParameter("menuid"));
Integer sortId = Integer.parseInt(req.getParameter("sortid"));
Integer arithNum = Integer.parseInt(req.getParameter("num"));
log.info("parentId:{}", parentId);
log.info("menuId:{}", menuId);
log.info("sortId:{}", sortId);
log.info("arithNum:{}", arithNum);
if (arithNum == 1) {
int a1 = menuService.changeSortId(sortId, arithNum, parentId);
int a2 = menuService.changeSortId2(sortId, arithNum, menuId);
log.info("a1:{}", a1);
log.info("a2:{}", a2);
} else {
int a1 = menuService.changeSortId(sortId, arithNum, parentId);
int a2 = menuService.changeSortId2(sortId, arithNum, menuId);
log.info("a1:{}", a1);
log.info("a2:{}", a2);
}
menuService.findMenuSys(req,user);
return "redirect:/testsysmenu";
}
/**
* 菜单管理的编辑界面
* @param req
* @return
*/
@RequestMapping("menuedit")
public String newpage(HttpServletRequest req) {
if(!StringUtils.isEmpty(req.getAttribute("errormess"))){
req.setAttribute("errormess", req.getAttribute("errormess"));
}
if(!StringUtils.isEmpty(req.getAttribute("success"))){
req.setAttribute("success", req.getAttribute("success"));
}
List<SystemMenu> parentList=iDao.findByParentIdOrderBySortId(0L);
req.setAttribute("parentList", parentList);
HttpSession session = req.getSession();
session.removeAttribute("getId");
if (!StringUtils.isEmpty(req.getParameter("id"))) {
Long getId = Long.parseLong(req.getParameter("id"));
SystemMenu menuObj = iDao.findOne(getId);
if (!StringUtils.isEmpty(req.getParameter("add"))) {
Long getAdd = menuObj.getMenuId();
String getName=menuObj.getMenuName();
req.setAttribute("getAdd", getAdd);
req.setAttribute("getName", getName);
log.info("getAdd:{}", getAdd);
} else {
session.setAttribute("getId", getId);
log.info("getId:{}", getId);
req.setAttribute("menuObj", menuObj);
}
}
return "systemcontrol/menuedit";
}
/**
* 系统管理表单验证
* @param req
* @param menu
* @param br
* 后台校验表单数据,不通过则回填数据,显示错误信息;通过则直接执行业务,例如新增、编辑等;
* @return
*/
@RequestMapping("test111")
public String testMess(HttpServletRequest req, @Valid SystemMenu 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<Object> 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("getId"))) {
menuId = (Long)session.getAttribute("getId"); // 获取进入编辑界面的menuID值
menu.setMenuId(menuId);
log.info("getId:{}", session.getAttribute("getId"));
session.removeAttribute("getId");
menuService.save(menu);
}else{
//执行新增 的代码;
menuService.save(menu);
List<Role> roles=rdao.findAll();
for (Role role : roles) {
if(role.getRoleId()==1){
roleService.sava(new Rolepowerlist(role, menu, true));
}else{
roleService.sava(new Rolepowerlist(role, menu, false));
}
}
}
//执行业务代码
System.out.println("此操作是正确的");
req.setAttribute("success", "后台验证成功");
}
System.out.println("是否进入最后的实体类信息:" + menu);
return "forward:/menuedit";
}
/**
* 菜单管理的删除
* @return
*/
@RequestMapping("deletethis")
public String delete(HttpServletRequest req){
Long menuId=Long.parseLong(req.getParameter("id"));
int i=menuService.deleteThis(menuId);
log.info("{}:i=",i);
return "forward:/testsysmenu";
}
}
通讯录管理和操作代码:
@Controller
@RequestMapping("/")
public class AddrController {
@Autowired
AddressDao addressDao;
@Autowired
AddressService addressService;
@Autowired
UserDao uDao;
@Autowired
AddreddUserService addressUserService;
@Autowired
AddressMapper am;
@Autowired
AddressUserDao auDao;
@Autowired
ProcessService proservice;
@Autowired
FileServices fileServices;
@Autowired
AttachService attachService;
@Autowired
AttachmentDao atDao;
@Autowired
private MailServices mservice;
@Autowired
private AttachmentDao AttDao;
/**
* 通讯录管理
* @param userId
* @param model
* @param page
* @param size
* @return
*/
@RequestMapping("addrmanage")
public String addrmanage(@SessionAttribute("userId") Long userId,Model model,
@RequestParam(value="page",defaultValue="0") int page,
@RequestParam(value="size",defaultValue="10") int size
) {
User user=uDao.findOne(userId);
Set<String> catalogs=auDao.findByUser(user);
Pageable pa=new PageRequest(page, size,new Sort(Direction.ASC, "dept"));
Page<User> userspage=uDao.findAll(pa);
List<User> users=userspage.getContent();
List<DirectorUser> nothandles=auDao.findByUserAndShareuserNotNullAndHandle(user,false);
model.addAttribute("count", nothandles.size());
model.addAttribute("catalogs", catalogs);
model.addAttribute("users", users);
model.addAttribute("page", userspage);
model.addAttribute("url", "inaddresspaging");
return "address/addrmanage";
}
/**
* 将外部通讯录联系人改变分类;
*/
@RequestMapping("changethistype")
public @ResponseBody Boolean changeType(@RequestParam(value="did")Long did,@SessionAttribute("userId") Long userId,@RequestParam(value="catalog")String catalog){
System.out.println("did:"+did);
System.out.println("catalog:"+catalog);
User user=uDao.findOne(userId);
Director d=addressDao.findOne(did);
DirectorUser du=auDao.findByDirectorAndUser(d, user);
du.setCatalogName(catalog);
addressUserService.save(du);
System.out.println("执行成功!");
return true;
}
/**
* 修改用户下面的外部分类
* 根据老分类找到所有的中间表的集合
* 再循环修改新分类名字
* @param typename
* @param oldtypename
* @param userId
* @return
*/
@RequestMapping("changetypename")
public String changeTypeName(@RequestParam(value="typename")String typename,
@RequestParam(value="oldtypename")String oldtypename,
@SessionAttribute("userId") Long userId
){
User user=uDao.findOne(userId);
List<DirectorUser> dus=auDao.findByCatalogNameAndUser(oldtypename, user);
for (DirectorUser directorUser : dus) {
directorUser.setCatalogName(typename);
}
addressUserService.savaList(dus);
return "redirect:/outaddresspaging";
}
/**
* 查看内部联系人
*/
@RequestMapping("inmessshow")
public String inMessShow(Model model,@RequestParam(value="userId")Long userId){
User user=uDao.findOne(userId);
model.addAttribute("user", user);
return "address/inmessshow";
}
/**
* 查看外部联系人
*/
@RequestMapping("outmessshow")
public String outMessShow(Model model,@RequestParam("director") Long director,@SessionAttribute("userId") Long userId){
Director d=addressDao.findOne(director);
User user=uDao.findOne(userId);
DirectorUser du=auDao.findByDirectorAndUser(d, user);
if(Objects.isNull(d) || Objects.isNull(du)){
System.out.println("权限不匹配,不能操作");
return "redirect:/notlimit";
}
if(d.getAttachment()!=null){
model.addAttribute("imgpath", atDao.findOne(d.getAttachment()).getAttachmentPath());
}else{
model.addAttribute("imgpath", "/timg.jpg");
}
model.addAttribute("d", d);
return "address/outmessshow";
}
/**
* 编辑
* @return
*/
@RequestMapping("addaddress")
public String addAddress(HttpServletRequest req,@RequestParam(value="did",required=false) Long did,HttpSession session,
@SessionAttribute("userId") Long userId, Model model){
User user=uDao.findOne(userId);
Set<String> calogs=auDao.findByUser(user);
model.addAttribute("calogs", calogs);
if(!StringUtils.isEmpty(did)){
Director director=addressDao.findOne(did);
System.out.println();
if(Objects.isNull(director)|| !Objects.equals(director.getMyuser().getUserId(), userId)){
System.out.println("权限不匹配,不能操作");
return "redirect:/notlimit";
}
DirectorUser du=auDao.findByDirectorAndUser(director, user);
model.addAttribute("director", director);
model.addAttribute("du", du);
session.setAttribute("did", did);
}
return "address/addressedit";
}
/**
* 保存外部联系人
* @throws IOException
* @throws IllegalStateException
*/
@RequestMapping("savaaddress")
public String savaAddress(@Valid Director director,DirectorUser directorUser,BindingResult br,@RequestParam("file")MultipartFile file,HttpSession session,
Model model,@SessionAttribute("userId") Long userId,HttpServletRequest req) throws PinyinException, IllegalStateException, IOException{
User user=uDao.findOne(userId);
ResultVO res = BindingResultVOUtil.hasErrors(br);
if (!ResultEnum.SUCCESS.getCode().equals(res.getCode())) {
System.out.println("输入信息有误!");
}else{
String pinyin=PinyinHelper.convertToPinyinString(director.getUserName(), "", PinyinFormat.WITHOUT_TONE);
director.setPinyin(pinyin);
director.setMyuser(user);
if(!StringUtils.isEmpty(session.getAttribute("did"))){
/*修改*/
Long did=Long.parseLong(session.getAttribute("did")+"");
Director di=addressDao.findOne(did);
director.setDirectorId(di.getDirectorId());
director.setAttachment(di.getAttachment());
DirectorUser dc=auDao.findByDirectorAndUser(director, user);
directorUser.setDirectorUserId(dc.getDirectorUserId());
session.removeAttribute("did");
}
//试一下
if(file.getSize()>0){
Attachment attaid=mservice.upload(file, user);
attaid.setModel("aoa_bursement");
Attachment att=AttDao.save(attaid);
/*Attachment att= (Attachment) fileServices.savefile(file, user, null, false);*/
director.setAttachment(att.getAttachmentId());
}
directorUser.setHandle(true);
directorUser.setDirector(director);
directorUser.setUser(user);
addressService.sava(director);
addressUserService.save(directorUser);
}
return "redirect:/addrmanage";
}
/**
* 用户删除某个外部通讯录联系人
*/
@RequestMapping("deletedirector")
public String deleteDirector(@SessionAttribute("userId") Long userId,Model model,@RequestParam(value="did",required=false) Long did){
DirectorUser du=auDao.findOne(did);
Director director=du.getDirector();
List<DirectorUser> dires=auDao.findByDirector(director);
User user=uDao.findOne(userId);
if(!Objects.equals(du.getUser().getUserId(), userId)){
System.out.println("权限不匹配,不能删除");
return "redirect:/notlimit";
}
List<DirectorUser> dus=auDao.findByCatalogNameAndUser(du.getCatalogName(), user);
if(dus.size()>1){
addressUserService.deleteObj(du);
if(dires.size()==1){
addressService.deleteDirector(du.getDirector());
System.out.println("最后一个拥有的用户删掉了该联系人,即删掉该联系人的信息");
}
}else{
/*当size=1时,说明这是最后一位拥有*/
du.setDirector(null);
addressUserService.save(du);
if(dires.size()==1){
addressService.deleteDirector(director);
System.out.println("最后一个拥有的用户删掉了该联系人,即删掉该联系人的信息");
}
}
return "redirect:/outaddresspaging";
}
/**
* 删除分类名称
*/
@RequestMapping("deletetypename")
public String deletetypename(@RequestParam(value="typename") String typename,@SessionAttribute("userId") Long userId){
User user=uDao.findOne(userId);
List<DirectorUser> dus=auDao.findByCatalogNameAndUser(typename, user);
for (DirectorUser directorUser : dus) {
directorUser.setCatalogName(null);
}
addressUserService.savaList(dus);
return "redirect:/outaddresspaging";
}
/**addtypename
* 增加外部分类名称
* */
@RequestMapping("addtypename")
public String addTypename(@RequestParam(value="typename",required=false) String typename,
@RequestParam(value="oldtypename",required=false) String oldtypename,
@SessionAttribute("userId") Long userId,Model model){
System.out.println("进来这个了么?");
User user=uDao.findOne(userId);
if(oldtypename!=null){
List<DirectorUser> dus=auDao.findByCatalogNameAndUser(oldtypename, user);
for (DirectorUser directorUser : dus) {
directorUser.setCatalogName(typename);
}
addressUserService.savaList(dus);
}else{
DirectorUser dc=new DirectorUser(user, typename);
addressUserService.save(dc);
}
Set<String> catalogs=auDao.findByUser(user);
System.out.println(catalogs);
model.addAttribute("catalogs", catalogs);
return "address/addtypename";
}
/**
* 分享给我的消息的界面
*/
@RequestMapping("sharemess")
public String shareMess(@RequestParam(value="page",defaultValue="0")int page,
@RequestParam(value="size",defaultValue="5")int size,
@RequestParam(value="baseKey",required=false) String baseKey,
@RequestParam(value="catalog",required=false)String catalog,
@RequestParam(value="duid",required=false)Long duid,
Model model,@SessionAttribute("userId") Long userId){
User user=uDao.findOne(userId);
List<Order> orders=new ArrayList<>();
orders.add(new Order(Direction.ASC, "handle"));
orders.add(new Order(Direction.DESC, "sharetime"));
Sort sort=new Sort(orders);
Pageable pa=new PageRequest(page, size, sort);
Page<DirectorUser> duspage=auDao.findByShareuser(user, pa);
if(!StringUtils.isEmpty(duid)){
DirectorUser du=auDao.findOne(duid);
System.out.println();
du.setCatalogName(catalog);
du.setHandle(true);
addressUserService.save(du);
}
if(!StringUtils.isEmpty(baseKey)){
duspage=auDao.findBaseKey("%"+baseKey+"%",user,pa);
model.addAttribute("sort", "&baseKey="+baseKey);
}else{
duspage=auDao.findByUserAndShareuserNotNull(user, pa);
}
Set<String> catalogs=auDao.findByUser(user);
System.out.println(catalogs);
model.addAttribute("catalogs", catalogs);
List<DirectorUser> dus=duspage.getContent();
model.addAttribute("page", duspage);
model.addAttribute("dus", dus);
model.addAttribute("url", "sharemess");
return "address/sharemess";
}
/**
* 我分享的消息界面
*/
@RequestMapping("mesharemess")
public String meShareMess(@RequestParam(value="page",defaultValue="0")int page,
@RequestParam(value="size",defaultValue="5")int size,
@RequestParam(value="baseKey",required=false) String baseKey,
Model model,@SessionAttribute("userId") Long userId
){
User user=uDao.findOne(userId);
Pageable pa=new PageRequest(page, size, new Sort(Direction.DESC, "sharetime"));
Page<DirectorUser> duspage=auDao.findByShareuser(user, pa);
if(!StringUtils.isEmpty(baseKey)){
duspage=auDao.findBaseKey("%"+baseKey+"%",user,pa);
model.addAttribute("sort", "&baseKey="+baseKey);
}else{
duspage=auDao.findByShareuser(user, pa);
}
List<DirectorUser> dus=duspage.getContent();
model.addAttribute("page", duspage);
model.addAttribute("dus", dus);
model.addAttribute("url", "mesharemess");
return "address/mesharemess";
}
/**
* 分享消息的业务controller
*/
@RequestMapping("shareother")
public String shareOther(@SessionAttribute("userId")Long userId,@RequestParam(value="directors[]") Long[] directors,
Model model,
@RequestParam(value="sharedirector") Long sharedirector){
User user=uDao.findOne(userId);
Director director=addressDao.findOne(sharedirector);
List<User> users=new ArrayList<>();
List<DirectorUser> dus=new ArrayList<>();
for (int i = 0; i < directors.length; i++) {
User shareuser=uDao.findOne(directors[i]);
System.out.println("分享的用户:"+shareuser);
DirectorUser du=auDao.findByDirectorAndUser(director, shareuser);
if(Objects.isNull(du)){
System.out.println("没找到该对象、进行保存保存");
DirectorUser dir=new DirectorUser();
dir.setUser(shareuser);
dir.setShareuser(user);
dir.setDirector(director);
dus.add(dir);
}else{
System.out.println("该用户已存在该联系人,不用重复保存!");
users.add(shareuser);
}
}
for (DirectorUser directorUser : dus) {
System.out.println("中间表:"+directorUser);
}
for (User u : users) {
System.out.println("已存有该联系人的用户:"+u);
}
addressUserService.savaList(dus);
if(users.size()>0){
model.addAttribute("users", users);
return "address/userhas";
}
return "address/sharesuccess";
}
/**
* 进入分享联系人的模态框分页
*/
@RequestMapping("modalshare")
public String modalShare(@RequestParam(value="page",defaultValue="0") int page,Model model,
@RequestParam(value="size",defaultValue="10") int size){
Pageable pa=new PageRequest(0, 10);
Page<User> userspage=uDao.findAll(pa);
List<User> users=userspage.getContent();
model.addAttribute("modalurl", "modalpaging");
model.addAttribute("modalpage", userspage);
model.addAttribute("users", users);
return "address/modalshare";
}
/**
* 分享模态框的分页
*/
@RequestMapping("modalpaging")
public String modalPaging(@RequestParam(value="page",defaultValue="0") int page,Model model,
@RequestParam(value="size",defaultValue="10") int size,
@RequestParam(value="baseKey",required=false) String baseKey){
Pageable pa=new PageRequest(page, size);
Page<User> userspage=null;
List<User> users=null;
if(!StringUtils.isEmpty(baseKey)){
System.out.println(baseKey);
userspage=uDao.findUsers("%"+baseKey+"%", baseKey+"%", pa);
model.addAttribute("baseKey", baseKey);
model.addAttribute("sort", "&baseKey="+baseKey);
}else{
userspage=uDao.findAll(pa);
}
users=userspage.getContent();
model.addAttribute("modalurl", "modalpaging");
model.addAttribute("modalpage", userspage);
model.addAttribute("users", users);
return "address/shareuser";
}
/**
外部通讯录
* @return
*/
@RequestMapping("outaddresspaging")
public String outAddress(@RequestParam(value="pageNum",defaultValue="1") int page,Model model,
@RequestParam(value="baseKey",required=false) String baseKey,
@RequestParam(value="outtype",required=false) String outtype,
@RequestParam(value="alph",defaultValue="ALL") String alph,
@SessionAttribute("userId") Long userId
){
PageHelper.startPage(page, 10);
List<Map<String, Object>> directors=am.allDirector(userId, alph, outtype, baseKey);
List<Map<String, Object>> adds=addressService.fengzhaung(directors);
PageInfo<Map<String, Object>> pageinfo=new PageInfo<>(directors);
if(!StringUtils.isEmpty(outtype)){
model.addAttribute("outtype", outtype);
}
Pageable pa=new PageRequest(0, 10);
Page<User> userspage=uDao.findAll(pa);
List<User> users=userspage.getContent();
model.addAttribute("modalurl", "modalpaging");
model.addAttribute("modalpage", userspage);
model.addAttribute("users", users);
model.addAttribute("userId", userId);
model.addAttribute("baseKey", baseKey);
model.addAttribute("directors", adds);
model.addAttribute("page", pageinfo);
model.addAttribute("url", "outaddresspaging");
return "address/outaddrss";
}
/**
* 内部通讯录表格,并处理分页
* @return
*/
@RequestMapping("inaddresspaging")
public String inAddress(@RequestParam(value="page",defaultValue="0") int page,Model model,
@RequestParam(value="size",defaultValue="10") int size,
@RequestParam(value="baseKey",required=false) String baseKey,
@RequestParam(value="alph",defaultValue="ALL") String alph
){
Page<User> userspage=null;
Pageable pa=new PageRequest(page, size);
if(StringUtils.isEmpty(baseKey)){
if("ALL".equals(alph)){
userspage=uDao.findAll(pa);
}else{
userspage=uDao.findByPinyinLike(alph+"%",pa);
}
}else{
if("ALL".equals(alph)){
userspage=uDao.findUsers("%"+baseKey+"%",baseKey+"%", pa);
}else{
userspage=uDao.findSelectUsers("%"+baseKey+"%", alph+"%",pa);
}
}
if(!StringUtils.isEmpty(baseKey)){
model.addAttribute("baseKey", baseKey);
model.addAttribute("sort", "&alph="+alph+"&baseKey="+baseKey);
}else{
model.addAttribute("sort", "&alph="+alph);
}
List<User> users=userspage.getContent();
model.addAttribute("users", users);
model.addAttribute("page", userspage);
model.addAttribute("url", "inaddresspaging");
return "address/inaddrss";
}
}
通讯录管理控制器:
@Controller
@RequestMapping("/")
public class AddrController {
@Autowired
AddressDao addressDao;
@Autowired
AddressService addressService;
@Autowired
UserDao uDao;
@Autowired
AddreddUserService addressUserService;
@Autowired
AddressMapper am;
@Autowired
AddressUserDao auDao;
@Autowired
ProcessService proservice;
@Autowired
FileServices fileServices;
@Autowired
AttachService attachService;
@Autowired
AttachmentDao atDao;
@Autowired
private MailServices mservice;
@Autowired
private AttachmentDao AttDao;
/**
* 通讯录管理
* @param userId
* @param model
* @param page
* @param size
* @return
*/
@RequestMapping("addrmanage")
public String addrmanage(@SessionAttribute("userId") Long userId,Model model,
@RequestParam(value="page",defaultValue="0") int page,
@RequestParam(value="size",defaultValue="10") int size
) {
User user=uDao.findOne(userId);
Set<String> catalogs=auDao.findByUser(user);
Pageable pa=new PageRequest(page, size,new Sort(Direction.ASC, "dept"));
Page<User> userspage=uDao.findAll(pa);
List<User> users=userspage.getContent();
List<DirectorUser> nothandles=auDao.findByUserAndShareuserNotNullAndHandle(user,false);
model.addAttribute("count", nothandles.size());
model.addAttribute("catalogs", catalogs);
model.addAttribute("users", users);
model.addAttribute("page", userspage);
model.addAttribute("url", "inaddresspaging");
return "address/addrmanage";
}
/**
* 将外部通讯录联系人改变分类;
*/
@RequestMapping("changethistype")
public @ResponseBody Boolean changeType(@RequestParam(value="did")Long did,@SessionAttribute("userId") Long userId,@RequestParam(value="catalog")String catalog){
System.out.println("did:"+did);
System.out.println("catalog:"+catalog);
User user=uDao.findOne(userId);
Director d=addressDao.findOne(did);
DirectorUser du=auDao.findByDirectorAndUser(d, user);
du.setCatalogName(catalog);
addressUserService.save(du);
System.out.println("执行成功!");
return true;
}
/**
* 修改用户下面的外部分类
* 根据老分类找到所有的中间表的集合
* 再循环修改新分类名字
* @param typename
* @param oldtypename
* @param userId
* @return
*/
@RequestMapping("changetypename")
public String changeTypeName(@RequestParam(value="typename")String typename,
@RequestParam(value="oldtypename")String oldtypename,
@SessionAttribute("userId") Long userId
){
User user=uDao.findOne(userId);
List<DirectorUser> dus=auDao.findByCatalogNameAndUser(oldtypename, user);
for (DirectorUser directorUser : dus) {
directorUser.setCatalogName(typename);
}
addressUserService.savaList(dus);
return "redirect:/outaddresspaging";
}
/**
* 查看内部联系人
*/
@RequestMapping("inmessshow")
public String inMessShow(Model model,@RequestParam(value="userId")Long userId){
User user=uDao.findOne(userId);
model.addAttribute("user", user);
return "address/inmessshow";
}
/**
* 查看外部联系人
*/
@RequestMapping("outmessshow")
public String outMessShow(Model model,@RequestParam("director") Long director,@SessionAttribute("userId") Long userId){
Director d=addressDao.findOne(director);
User user=uDao.findOne(userId);
DirectorUser du=auDao.findByDirectorAndUser(d, user);
if(Objects.isNull(d) || Objects.isNull(du)){
System.out.println("权限不匹配,不能操作");
return "redirect:/notlimit";
}
if(d.getAttachment()!=null){
model.addAttribute("imgpath", atDao.findOne(d.getAttachment()).getAttachmentPath());
}else{
model.addAttribute("imgpath", "/timg.jpg");
}
model.addAttribute("d", d);
return "address/outmessshow";
}
/**
* 编辑
* @return
*/
@RequestMapping("addaddress")
public String addAddress(HttpServletRequest req,@RequestParam(value="did",required=false) Long did,HttpSession session,
@SessionAttribute("userId") Long userId, Model model){
User user=uDao.findOne(userId);
Set<String> calogs=auDao.findByUser(user);
model.addAttribute("calogs", calogs);
if(!StringUtils.isEmpty(did)){
Director director=addressDao.findOne(did);
System.out.println();
if(Objects.isNull(director)|| !Objects.equals(director.getMyuser().getUserId(), userId)){
System.out.println("权限不匹配,不能操作");
return "redirect:/notlimit";
}
DirectorUser du=auDao.findByDirectorAndUser(director, user);
model.addAttribute("director", director);
model.addAttribute("du", du);
session.setAttribute("did", did);
}
return "address/addressedit";
}
/**
* 保存外部联系人
* @throws IOException
* @throws IllegalStateException
*/
@RequestMapping("savaaddress")
public String savaAddress(@Valid Director director,DirectorUser directorUser,BindingResult br,@RequestParam("file")MultipartFile file,HttpSession session,
Model model,@SessionAttribute("userId") Long userId,HttpServletRequest req) throws PinyinException, IllegalStateException, IOException{
User user=uDao.findOne(userId);
ResultVO res = BindingResultVOUtil.hasErrors(br);
if (!ResultEnum.SUCCESS.getCode().equals(res.getCode())) {
System.out.println("输入信息有误!");
}else{
String pinyin=PinyinHelper.convertToPinyinString(director.getUserName(), "", PinyinFormat.WITHOUT_TONE);
director.setPinyin(pinyin);
director.setMyuser(user);
if(!StringUtils.isEmpty(session.getAttribute("did"))){
/*修改*/
Long did=Long.parseLong(session.getAttribute("did")+"");
Director di=addressDao.findOne(did);
director.setDirectorId(di.getDirectorId());
director.setAttachment(di.getAttachment());
DirectorUser dc=auDao.findByDirectorAndUser(director, user);
directorUser.setDirectorUserId(dc.getDirectorUserId());
session.removeAttribute("did");
}
//试一下
if(file.getSize()>0){
Attachment attaid=mservice.upload(file, user);
attaid.setModel("aoa_bursement");
Attachment att=AttDao.save(attaid);
/*Attachment att= (Attachment) fileServices.savefile(file, user, null, false);*/
director.setAttachment(att.getAttachmentId());
}
directorUser.setHandle(true);
directorUser.setDirector(director);
directorUser.setUser(user);
addressService.sava(director);
addressUserService.save(directorUser);
}
return "redirect:/addrmanage";
}
/**
* 用户删除某个外部通讯录联系人
*/
@RequestMapping("deletedirector")
public String deleteDirector(@SessionAttribute("userId") Long userId,Model model,@RequestParam(value="did",required=false) Long did){
DirectorUser du=auDao.findOne(did);
Director director=du.getDirector();
List<DirectorUser> dires=auDao.findByDirector(director);
User user=uDao.findOne(userId);
if(!Objects.equals(du.getUser().getUserId(), userId)){
System.out.println("权限不匹配,不能删除");
return "redirect:/notlimit";
}
List<DirectorUser> dus=auDao.findByCatalogNameAndUser(du.getCatalogName(), user);
if(dus.size()>1){
addressUserService.deleteObj(du);
if(dires.size()==1){
addressService.deleteDirector(du.getDirector());
System.out.println("最后一个拥有的用户删掉了该联系人,即删掉该联系人的信息");
}
}else{
/*当size=1时,说明这是最后一位拥有*/
du.setDirector(null);
addressUserService.save(du);
if(dires.size()==1){
addressService.deleteDirector(director);
System.out.println("最后一个拥有的用户删掉了该联系人,即删掉该联系人的信息");
}
}
return "redirect:/outaddresspaging";
}
/**
* 删除分类名称
*/
@RequestMapping("deletetypename")
public String deletetypename(@RequestParam(value="typename") String typename,@SessionAttribute("userId") Long userId){
User user=uDao.findOne(userId);
List<DirectorUser> dus=auDao.findByCatalogNameAndUser(typename, user);
for (DirectorUser directorUser : dus) {
directorUser.setCatalogName(null);
}
addressUserService.savaList(dus);
return "redirect:/outaddresspaging";
}
/**addtypename
* 增加外部分类名称
* */
@RequestMapping("addtypename")
public String addTypename(@RequestParam(value="typename",required=false) String typename,
@RequestParam(value="oldtypename",required=false) String oldtypename,
@SessionAttribute("userId") Long userId,Model model){
System.out.println("进来这个了么?");
User user=uDao.findOne(userId);
if(oldtypename!=null){
List<DirectorUser> dus=auDao.findByCatalogNameAndUser(oldtypename, user);
for (DirectorUser directorUser : dus) {
directorUser.setCatalogName(typename);
}
addressUserService.savaList(dus);
}else{
DirectorUser dc=new DirectorUser(user, typename);
addressUserService.save(dc);
}
Set<String> catalogs=auDao.findByUser(user);
System.out.println(catalogs);
model.addAttribute("catalogs", catalogs);
return "address/addtypename";
}
/**
* 分享给我的消息的界面
*/
@RequestMapping("sharemess")
public String shareMess(@RequestParam(value="page",defaultValue="0")int page,
@RequestParam(value="size",defaultValue="5")int size,
@RequestParam(value="baseKey",required=false) String baseKey,
@RequestParam(value="catalog",required=false)String catalog,
@RequestParam(value="duid",required=false)Long duid,
Model model,@SessionAttribute("userId") Long userId){
User user=uDao.findOne(userId);
List<Order> orders=new ArrayList<>();
orders.add(new Order(Direction.ASC, "handle"));
orders.add(new Order(Direction.DESC, "sharetime"));
Sort sort=new Sort(orders);
Pageable pa=new PageRequest(page, size, sort);
Page<DirectorUser> duspage=auDao.findByShareuser(user, pa);
if(!StringUtils.isEmpty(duid)){
DirectorUser du=auDao.findOne(duid);
System.out.println();
du.setCatalogName(catalog);
du.setHandle(true);
addressUserService.save(du);
}
if(!StringUtils.isEmpty(baseKey)){
duspage=auDao.findBaseKey("%"+baseKey+"%",user,pa);
model.addAttribute("sort", "&baseKey="+baseKey);
}else{
duspage=auDao.findByUserAndShareuserNotNull(user, pa);
}
Set<String> catalogs=auDao.findByUser(user);
System.out.println(catalogs);
model.addAttribute("catalogs", catalogs);
List<DirectorUser> dus=duspage.getContent();
model.addAttribute("page", duspage);
model.addAttribute("dus", dus);
model.addAttribute("url", "sharemess");
return "address/sharemess";
}
/**
* 我分享的消息界面
*/
@RequestMapping("mesharemess")
public String meShareMess(@RequestParam(value="page",defaultValue="0")int page,
@RequestParam(value="size",defaultValue="5")int size,
@RequestParam(value="baseKey",required=false) String baseKey,
Model model,@SessionAttribute("userId") Long userId
){
User user=uDao.findOne(userId);
Pageable pa=new PageRequest(page, size, new Sort(Direction.DESC, "sharetime"));
Page<DirectorUser> duspage=auDao.findByShareuser(user, pa);
if(!StringUtils.isEmpty(baseKey)){
duspage=auDao.findBaseKey("%"+baseKey+"%",user,pa);
model.addAttribute("sort", "&baseKey="+baseKey);
}else{
duspage=auDao.findByShareuser(user, pa);
}
List<DirectorUser> dus=duspage.getContent();
model.addAttribute("page", duspage);
model.addAttribute("dus", dus);
model.addAttribute("url", "mesharemess");
return "address/mesharemess";
}
/**
* 分享消息的业务controller
*/
@RequestMapping("shareother")
public String shareOther(@SessionAttribute("userId")Long userId,@RequestParam(value="directors[]") Long[] directors,
Model model,
@RequestParam(value="sharedirector") Long sharedirector){
User user=uDao.findOne(userId);
Director director=addressDao.findOne(sharedirector);
List<User> users=new ArrayList<>();
List<DirectorUser> dus=new ArrayList<>();
for (int i = 0; i < directors.length; i++) {
User shareuser=uDao.findOne(directors[i]);
System.out.println("分享的用户:"+shareuser);
DirectorUser du=auDao.findByDirectorAndUser(director, shareuser);
if(Objects.isNull(du)){
System.out.println("没找到该对象、进行保存保存");
DirectorUser dir=new DirectorUser();
dir.setUser(shareuser);
dir.setShareuser(user);
dir.setDirector(director);
dus.add(dir);
}else{
System.out.println("该用户已存在该联系人,不用重复保存!");
users.add(shareuser);
}
}
for (DirectorUser directorUser : dus) {
System.out.println("中间表:"+directorUser);
}
for (User u : users) {
System.out.println("已存有该联系人的用户:"+u);
}
addressUserService.savaList(dus);
if(users.size()>0){
model.addAttribute("users", users);
return "address/userhas";
}
return "address/sharesuccess";
}
/**
* 进入分享联系人的模态框分页
*/
@RequestMapping("modalshare")
public String modalShare(@RequestParam(value="page",defaultValue="0") int page,Model model,
@RequestParam(value="size",defaultValue="10") int size){
Pageable pa=new PageRequest(0, 10);
Page<User> userspage=uDao.findAll(pa);
List<User> users=userspage.getContent();
model.addAttribute("modalurl", "modalpaging");
model.addAttribute("modalpage", userspage);
model.addAttribute("users", users);
return "address/modalshare";
}
/**
* 分享模态框的分页
*/
@RequestMapping("modalpaging")
public String modalPaging(@RequestParam(value="page",defaultValue="0") int page,Model model,
@RequestParam(value="size",defaultValue="10") int size,
@RequestParam(value="baseKey",required=false) String baseKey){
Pageable pa=new PageRequest(page, size);
Page<User> userspage=null;
List<User> users=null;
if(!StringUtils.isEmpty(baseKey)){
System.out.println(baseKey);
userspage=uDao.findUsers("%"+baseKey+"%", baseKey+"%", pa);
model.addAttribute("baseKey", baseKey);
model.addAttribute("sort", "&baseKey="+baseKey);
}else{
userspage=uDao.findAll(pa);
}
users=userspage.getContent();
model.addAttribute("modalurl", "modalpaging");
model.addAttribute("modalpage", userspage);
model.addAttribute("users", users);
return "address/shareuser";
}
/**
外部通讯录
* @return
*/
@RequestMapping("outaddresspaging")
public String outAddress(@RequestParam(value="pageNum",defaultValue="1") int page,Model model,
@RequestParam(value="baseKey",required=false) String baseKey,
@RequestParam(value="outtype",required=false) String outtype,
@RequestParam(value="alph",defaultValue="ALL") String alph,
@SessionAttribute("userId") Long userId
){
PageHelper.startPage(page, 10);
List<Map<String, Object>> directors=am.allDirector(userId, alph, outtype, baseKey);
List<Map<String, Object>> adds=addressService.fengzhaung(directors);
PageInfo<Map<String, Object>> pageinfo=new PageInfo<>(directors);
if(!StringUtils.isEmpty(outtype)){
model.addAttribute("outtype", outtype);
}
Pageable pa=new PageRequest(0, 10);
Page<User> userspage=uDao.findAll(pa);
List<User> users=userspage.getContent();
model.addAttribute("modalurl", "modalpaging");
model.addAttribute("modalpage", userspage);
model.addAttribute("users", users);
model.addAttribute("userId", userId);
model.addAttribute("baseKey", baseKey);
model.addAttribute("directors", adds);
model.addAttribute("page", pageinfo);
model.addAttribute("url", "outaddresspaging");
return "address/outaddrss";
}
/**
* 内部通讯录表格,并处理分页
* @return
*/
@RequestMapping("inaddresspaging")
public String inAddress(@RequestParam(value="page",defaultValue="0") int page,Model model,
@RequestParam(value="size",defaultValue="10") int size,
@RequestParam(value="baseKey",required=false) String baseKey,
@RequestParam(value="alph",defaultValue="ALL") String alph
){
Page<User> userspage=null;
Pageable pa=new PageRequest(page, size);
if(StringUtils.isEmpty(baseKey)){
if("ALL".equals(alph)){
userspage=uDao.findAll(pa);
}else{
userspage=uDao.findByPinyinLike(alph+"%",pa);
}
}else{
if("ALL".equals(alph)){
userspage=uDao.findUsers("%"+baseKey+"%",baseKey+"%", pa);
}else{
userspage=uDao.findSelectUsers("%"+baseKey+"%", alph+"%",pa);
}
}
if(!StringUtils.isEmpty(baseKey)){
model.addAttribute("baseKey", baseKey);
model.addAttribute("sort", "&alph="+alph+"&baseKey="+baseKey);
}else{
model.addAttribute("sort", "&alph="+alph);
}
List<User> users=userspage.getContent();
model.addAttribute("users", users);
model.addAttribute("page", userspage);
model.addAttribute("url", "inaddresspaging");
return "address/inaddrss";
}
}