Search in sources :

Example 1 with ServiceDelException

use of com.itrus.portal.exception.ServiceDelException in project portal by ixinportal.

the class SysRegionController method deleteSysRegion.

/**
 * 删除行政区
 * @param id
 * @param sourceId 触发页面 0:列表页面;1:详情页面; 默认为列表页面
 * @param model
 * @return
 */
@RequestMapping(value = "/{pid}/{type}/{id}", method = RequestMethod.DELETE)
public String deleteSysRegion(@PathVariable("id") Long id, @PathVariable("pid") Long pid, @PathVariable("type") Integer type, @RequestParam(value = "fromId", required = false) Integer sourceId, RedirectAttributesModelMap model) {
    String retUrl = "redirect:/sysregion/list?parentId=" + pid + "&type=" + type;
    try {
        SysRegion sysRegion = sysRegionService.delRegion(id);
        // 删除成功标记,用于刷新树
        model.addFlashAttribute("reNode", 1);
        model.addFlashAttribute("errMsg", "成功删除行政区【" + sysRegion.getNameCn() + "】");
        retUrl = "redirect:/sysregion/list?parentId=" + sysRegion.getParentId() + "&type=" + sysRegion.getType();
        LogUtil.adminlog(sqlSession, "删除行政区", "删除行政区【" + sysRegion.getNameCn() + "】,代码为【" + sysRegion.getCode() + "】");
    } catch (ServiceDelException e) {
        model.addFlashAttribute("errMsg", e.getMessage());
    } catch (Exception e) {
        e.printStackTrace();
        model.addFlashAttribute("errMsg", e.getMessage());
    }
    if (!model.getFlashAttributes().containsKey("reNode") && sourceId != null && 1 == sourceId) {
        retUrl = "redirect:/sysregion/" + id;
    }
    return retUrl;
}
Also used : ServiceDelException(com.itrus.portal.exception.ServiceDelException) SysRegion(com.itrus.portal.db.SysRegion) ServiceNullException(com.itrus.portal.exception.ServiceNullException) ServiceDelException(com.itrus.portal.exception.ServiceDelException)

Example 2 with ServiceDelException

use of com.itrus.portal.exception.ServiceDelException in project portal by ixinportal.

the class SysRegionService method delRegion.

/**
 * 删除行政区
 * @return 删除成功返回删除对象,否则返回null
 */
public SysRegion delRegion(Long id) throws ServiceDelException {
    SysRegion sysRegion = sqlSession.selectOne("com.itrus.portal.db.SysRegionMapper.selectByPrimaryKey", id);
    if (sysRegion == null) {
        throw new ServiceDelException("不存在将要删除的行政区信息");
    }
    SysRegionExample sysRegionExample = new SysRegionExample();
    SysRegionExample.Criteria srCriteria = sysRegionExample.createCriteria();
    srCriteria.andParentIdEqualTo(id);
    Integer num = sqlSession.selectOne("com.itrus.portal.db.SysRegionMapper.countByExample", sysRegionExample);
    // 若包含子节点,不允许删除
    if (num != null && num > 0) {
        throw new ServiceDelException("无法删除存在下级的行政区");
    }
    sqlSession.delete("com.itrus.portal.db.SysRegionMapper.deleteByPrimaryKey", id);
    return sysRegion;
}
Also used : ServiceDelException(com.itrus.portal.exception.ServiceDelException) SysRegion(com.itrus.portal.db.SysRegion) SysRegionExample(com.itrus.portal.db.SysRegionExample)

Aggregations

SysRegion (com.itrus.portal.db.SysRegion)2 ServiceDelException (com.itrus.portal.exception.ServiceDelException)2 SysRegionExample (com.itrus.portal.db.SysRegionExample)1 ServiceNullException (com.itrus.portal.exception.ServiceNullException)1