Controller
/**
* <p>* 删除某个公司
* </p>
*
* @author chenmin
* @create 2014-6-10下午1:32:29
* @desc delCorporation
* @param resourceNo
* @param request
* @return
* @throws SystemException
*/
@RequestMapping("/delCorporation.do")
public @ResponseBody
String delCorporation(@RequestParam("resourceNo") String resourceNo,
HttpServletRequest request) throws SystemException {
try {
//判断待删除的公司下是否有角色、用户、部门
List<Department> depts = departmentService.queryDepartmentByResourceNo(resourceNo);
List<Role> roles = roleService.queryRoleByResourceNo(resourceNo);
List<User> users = userService.queryUserByResourceNo(resourceNo);
if(!depts.isEmpty()){//如果公司下有部门,就提示先删除该公司下的部门
return "hasDept";
}
if(!roles.isEmpty()){
return "hasRole";
}
if(!users.isEmpty()){
return "hasUser";
}
corporationService.removeCorporationByResourceNo(resourceNo,request);
LOGGER.debug(" deleting Corporation is successful !");
return "success";
} catch (Exception e) {
LOGGER.error(" deleting Corporation is error !" + e);
throw new SystemException(ErrorCode.ERROR_9003,"删除公司出现异常!", e);
}
}
js:
//提交删除请求
function delCorp(){
var resourceNo = fnGetSelectedRowData(oTable).resourceNo;
jConfirm("你确定要删除公司吗?","系统提示",function(ok){
if(ok){
$.post(Root+"/model/corp/delCorporation.do",{"resourceNo":resourceNo},function(result){
if(result=='success'){
oTable.fnDraw();
}else if(result=='hasUser'){
jAlert("请先删除该公司下的用户!","系统提示");
}else if(result=='hasRole'){
jAlert("请先删除该公司下的角色!","系统提示");
}else if(result=='hasDept'){
jAlert("请先删除该公司下的部门!","系统提示");
}else{
jAlert(result);
}
});
}
});
}