@Override public Catalog saveCatalog(Catalog catalog) { Catalog sameAliasCatalog = findByAlias(catalog.getModule(), catalog.getAlias()); if ((catalog.getId() == null && sameAliasCatalog != null) || (catalog.getId() != null && sameAliasCatalog != null && !sameAliasCatalog.getId().equals(catalog.getId()))) throw new AppException(ErrorCode.ENTITY_ALREADY_EXIST, "访问别名已被使用,请换一个!"); Date now = new Date(); Catalog entity = null; if (catalog.getId() == null) { entity = new Catalog(); entity.setUpdateAt(now); entity.setCreateAt(now); } else { entity = catalogDao.findOne(catalog.getId()); if (entity == null) throw new AppException(ErrorCode.ENTITY_NOT_FOUND, "要更新的栏目没有找到!"); entity.setUpdateAt(now); } entity.setAlias(catalog.getAlias()); entity.setClickDisplay(catalog.getClickDisplay()); entity.setLevel(getSetLevel(catalog)); entity.setModule(catalog.getModule()); entity.setNavDisplay(catalog.getNavDisplay()); entity.setNewWindowOpen( catalog.getNewWindowOpen() != null ? catalog.getNewWindowOpen() : false); entity.setPid( catalog.getPid() == null ? null : (catalog.getPid() == 0 ? null : catalog.getPid())); entity.setRank(catalog.getRank() != null ? catalog.getRank() : 0); entity.setSubTitle(catalog.getSubTitle()); entity.setTitle(catalog.getTitle()); if (entity.getModule().ordinal() == Module.outlink.ordinal()) { if (entity.getAttributes() == null) entity.setAttributes(new HashMap<String, String>()); entity.getAttributes().put(Catalog.ATTR_KEY_OUTLINK_URL, catalog.getOutlinkUrl()); } return catalogDao.save(entity); }