标签:
描述:
1.上级机构可以为空。
2.机构添加时,选择了上级机构,在未提交前,另一用户将该机构删除,然后前一用户再提交表单,提示会保存成功,本操作应该保存失败。
思路:在上级机构不为空时,保存前进行查询判断,如果保存前一刻查询该机构存在则可以保存成功,否则保存提示“保存失败,请检查机构是否存在,再重试!”;
@RequiresPermissions("sys:office:edit") @RequestMapping(value = "save") public String save(Office office, Model model, RedirectAttributes redirectAttributes) { if(Global.isDemoMode()){ addMessage(redirectAttributes, "演示模式,不允许操作!"); return "redirect:" + adminPath + "/sys/office/";} if (!beanValidator(model, office)){ return form(office, model); } if("".equals(office.getParent().getName())){ officeService.save(office); if(office.getChildDeptList()!=null){ Office childOffice = null; for(String id : office.getChildDeptList()){ childOffice = new Office(); childOffice.setName(DictUtils.getDictLabel(id, "sys_office_common", "未知")); childOffice.setParent(office); childOffice.setArea(office.getArea()); childOffice.setType("2"); childOffice.setGrade(String.valueOf(Integer.valueOf(office.getGrade())+1)); childOffice.setUseable(Global.YES); officeService.save(childOffice); } } addMessage(redirectAttributes, "保存机构‘" + office.getName() + "‘成功"); }else{ // if(!("".equals(office.getParent().getName()))){//添加下级机构 int m = officeService.findByParentId(office.getParent().getName()); if(m==0){ addMessage(redirectAttributes, "保存失败,请检查机构是否存在,再重试!" ); }else{ officeService.save(office); if(office.getChildDeptList()!=null){ Office childOffice = null; for(String id : office.getChildDeptList()){ childOffice = new Office(); childOffice.setName(DictUtils.getDictLabel(id, "sys_office_common", "未知")); childOffice.setParent(office); childOffice.setArea(office.getArea()); childOffice.setType("2");
childOffice.setGrade(String.valueOf(Integer.valueOf(office.getGrade())+1)); childOffice.setUseable(Global.YES); officeService.save(childOffice); } } addMessage(redirectAttributes, "保存机构‘" + office.getName() + "‘成功"); } } String id = "0".equals(office.getParentId()) ? "" : office.getParentId(); return "redirect:" + adminPath + "/sys/office/forlist?id="+id+"&parentIds="+office.getParentIds(); }
标签:
原文地址:http://www.cnblogs.com/banxian-yi/p/5357365.html