Search in sources :

Example 1 with CmsCategoryType

use of com.publiccms.entities.cms.CmsCategoryType in project PublicCMS-preview by sanluan.

the class CmsCategoryAdminController method save.

/**
 * @param entity
 * @param attribute
 * @param categoryParamters
 * @param request
 * @param session
 * @param model
 * @return view name
 */
@RequestMapping("save")
public String save(CmsCategory entity, CmsCategoryAttribute attribute, @ModelAttribute CmsCategoryParamters categoryParamters, HttpServletRequest request, HttpSession session, ModelMap model) {
    SysSite site = getSite(request);
    if (null != entity.getId()) {
        CmsCategory oldEntity = service.getEntity(entity.getId());
        if (null == oldEntity || ControllerUtils.verifyNotEquals("siteId", site.getId(), oldEntity.getSiteId(), model)) {
            return TEMPLATE_ERROR;
        }
        entity = service.update(entity.getId(), entity, ignoreProperties);
        if (null != entity) {
            if (null != oldEntity.getParentId() && oldEntity.getParentId() != entity.getParentId()) {
                service.generateChildIds(site.getId(), oldEntity.getParentId());
                service.generateChildIds(site.getId(), entity.getParentId());
            } else if (null != entity.getParentId() && null == oldEntity.getParentId()) {
                service.generateChildIds(site.getId(), entity.getParentId());
            }
            logOperateService.save(new LogOperate(site.getId(), getAdminFromSession(session).getId(), LogLoginService.CHANNEL_WEB_MANAGER, "update.category", RequestUtils.getIpAddress(request), CommonUtils.getDate(), JsonUtils.getString(entity)));
        }
    } else {
        if (entity.isOnlyUrl()) {
            entity.setUrl(entity.getPath());
        }
        entity.setSiteId(site.getId());
        service.save(entity);
        service.addChildIds(entity.getParentId(), entity.getId());
        logOperateService.save(new LogOperate(site.getId(), getAdminFromSession(session).getId(), LogLoginService.CHANNEL_WEB_MANAGER, "save.category", RequestUtils.getIpAddress(request), CommonUtils.getDate(), JsonUtils.getString(entity)));
    }
    if (null == extendService.getEntity(entity.getExtendId())) {
        entity = service.updateExtendId(entity.getId(), (Integer) extendService.save(new SysExtend("category", entity.getId())));
    }
    Integer[] tagTypeIds = tagTypeService.update(site.getId(), categoryParamters.getTagTypes());
    // 更新保存标签分类
    service.updateTagTypeIds(entity.getId(), arrayToCommaDelimitedString(tagTypeIds));
    List<CmsCategoryModelParamters> categoryModelList = categoryParamters.getCategoryModelList();
    if (CommonUtils.notEmpty(categoryModelList)) {
        for (CmsCategoryModelParamters cmsCategoryModelParamters : categoryModelList) {
            if (null != cmsCategoryModelParamters.getCategoryModel()) {
                cmsCategoryModelParamters.getCategoryModel().getId().setCategoryId(entity.getId());
                if (cmsCategoryModelParamters.isUse()) {
                    categoryModelService.updateCategoryModel(cmsCategoryModelParamters.getCategoryModel());
                } else {
                    categoryModelService.delete(cmsCategoryModelParamters.getCategoryModel().getId());
                }
            }
        }
    }
    // 修改或增加内容扩展字段
    extendFieldService.update(entity.getExtendId(), categoryParamters.getContentExtends());
    CmsCategoryType categoryType = categoryTypeService.getEntity(entity.getTypeId());
    if (null != categoryType && CommonUtils.notEmpty(categoryType.getExtendId())) {
        List<SysExtendField> categoryTypeExtendList = extendFieldService.getList(categoryType.getExtendId());
        Map<String, String> map = ExtendUtils.getSysExtentDataMap(categoryParamters.getExtendDataList(), categoryTypeExtendList);
        attribute.setData(ExtendUtils.getExtendString(map));
    } else {
        attribute.setData(null);
    }
    attributeService.updateAttribute(entity.getId(), attribute);
    try {
        publish(site, entity.getId(), null);
    } catch (IOException | TemplateException e) {
        ControllerUtils.verifyCustom("static", true, model);
        log.error(e.getMessage(), e);
    }
    return TEMPLATE_DONE;
}
Also used : LogOperate(com.publiccms.entities.log.LogOperate) TemplateException(freemarker.template.TemplateException) CmsCategoryType(com.publiccms.entities.cms.CmsCategoryType) StringUtils.arrayToCommaDelimitedString(org.springframework.util.StringUtils.arrayToCommaDelimitedString) IOException(java.io.IOException) CmsCategoryModelParamters(com.publiccms.views.pojo.model.CmsCategoryModelParamters) SysSite(com.publiccms.entities.sys.SysSite) SysExtendField(com.publiccms.entities.sys.SysExtendField) CmsCategory(com.publiccms.entities.cms.CmsCategory) SysExtend(com.publiccms.entities.sys.SysExtend) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with CmsCategoryType

use of com.publiccms.entities.cms.CmsCategoryType in project PublicCMS-preview by sanluan.

the class CmsCategoryTypeDirective method execute.

@Override
public void execute(RenderHandler handler) throws IOException, Exception {
    Integer id = handler.getInteger("id");
    SysSite site = getSite(handler);
    if (CommonUtils.notEmpty(id)) {
        CmsCategoryType entity = service.getEntity(id);
        if (null != entity && site.getId() == entity.getSiteId()) {
            handler.put("object", entity).render();
        }
    } else {
        Integer[] ids = handler.getIntegerArray("ids");
        if (CommonUtils.notEmpty(ids)) {
            List<CmsCategoryType> entityList = service.getEntitys(ids);
            Map<String, CmsCategoryType> map = new LinkedHashMap<>();
            for (CmsCategoryType entity : entityList) {
                if (site.getId() == entity.getSiteId()) {
                    map.put(String.valueOf(entity.getId()), entity);
                }
            }
            handler.put("map", map).render();
        }
    }
}
Also used : CmsCategoryType(com.publiccms.entities.cms.CmsCategoryType) SysSite(com.publiccms.entities.sys.SysSite) LinkedHashMap(java.util.LinkedHashMap)

Example 3 with CmsCategoryType

use of com.publiccms.entities.cms.CmsCategoryType in project PublicCMS-preview by sanluan.

the class CmsCategoryTypeAdminController method delete.

/**
 * @param id
 * @param request
 * @param session
 * @param model
 * @return view name
 */
@RequestMapping("delete")
public String delete(Integer id, HttpServletRequest request, HttpSession session, ModelMap model) {
    SysSite site = getSite(request);
    CmsCategoryType entity = service.getEntity(id);
    if (null != entity) {
        if (ControllerUtils.verifyNotEquals("siteId", site.getId(), entity.getSiteId(), model) || ControllerUtils.verifyNotGreaterThen("category", categoryService.getPage(new CmsCategoryQuery(site.getId(), null, true, id, null, null, false), null, null).getTotalCount(), 1, model)) {
            return TEMPLATE_ERROR;
        }
        service.delete(id);
        extendService.delete(entity.getExtendId());
        logOperateService.save(new LogOperate(site.getId(), getAdminFromSession(session).getId(), LogLoginService.CHANNEL_WEB_MANAGER, "delete.categoryType", RequestUtils.getIpAddress(request), CommonUtils.getDate(), id.toString()));
    }
    return TEMPLATE_DONE;
}
Also used : LogOperate(com.publiccms.entities.log.LogOperate) CmsCategoryQuery(com.publiccms.views.pojo.query.CmsCategoryQuery) CmsCategoryType(com.publiccms.entities.cms.CmsCategoryType) SysSite(com.publiccms.entities.sys.SysSite) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 4 with CmsCategoryType

use of com.publiccms.entities.cms.CmsCategoryType in project PublicCMS-preview by sanluan.

the class CmsCategoryTypeAdminController method save.

/**
 * @param entity
 * @param categoryTypeParamters
 * @param request
 * @param session
 * @param model
 * @return view name
 */
@RequestMapping("save")
public String save(CmsCategoryType entity, @ModelAttribute CmsCategoryTypeParamters categoryTypeParamters, HttpServletRequest request, HttpSession session, ModelMap model) {
    SysSite site = getSite(request);
    if (null != entity.getId()) {
        CmsCategoryType oldEntity = service.getEntity(entity.getId());
        if (null == oldEntity || ControllerUtils.verifyNotEquals("siteId", site.getId(), oldEntity.getSiteId(), model)) {
            return TEMPLATE_ERROR;
        }
        entity = service.update(entity.getId(), entity, ignoreProperties);
        if (null != entity) {
            logOperateService.save(new LogOperate(site.getId(), getAdminFromSession(session).getId(), LogLoginService.CHANNEL_WEB_MANAGER, "update.categoryType", RequestUtils.getIpAddress(request), CommonUtils.getDate(), JsonUtils.getString(entity)));
        }
    } else {
        entity.setSiteId(site.getId());
        service.save(entity);
        logOperateService.save(new LogOperate(site.getId(), getAdminFromSession(session).getId(), LogLoginService.CHANNEL_WEB_MANAGER, "save.categoryType", RequestUtils.getIpAddress(request), CommonUtils.getDate(), JsonUtils.getString(entity)));
    }
    if (null == extendService.getEntity(entity.getExtendId())) {
        entity = service.updateExtendId(entity.getId(), (Integer) extendService.save(new SysExtend("categoryType", entity.getId())));
    }
    // 修改或增加分类类型扩展字段
    extendFieldService.update(entity.getExtendId(), categoryTypeParamters.getCategoryExtends());
    return TEMPLATE_DONE;
}
Also used : LogOperate(com.publiccms.entities.log.LogOperate) CmsCategoryType(com.publiccms.entities.cms.CmsCategoryType) SysExtend(com.publiccms.entities.sys.SysExtend) SysSite(com.publiccms.entities.sys.SysSite) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

CmsCategoryType (com.publiccms.entities.cms.CmsCategoryType)4 SysSite (com.publiccms.entities.sys.SysSite)4 LogOperate (com.publiccms.entities.log.LogOperate)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 SysExtend (com.publiccms.entities.sys.SysExtend)2 CmsCategory (com.publiccms.entities.cms.CmsCategory)1 SysExtendField (com.publiccms.entities.sys.SysExtendField)1 CmsCategoryModelParamters (com.publiccms.views.pojo.model.CmsCategoryModelParamters)1 CmsCategoryQuery (com.publiccms.views.pojo.query.CmsCategoryQuery)1 TemplateException (freemarker.template.TemplateException)1 IOException (java.io.IOException)1 LinkedHashMap (java.util.LinkedHashMap)1 StringUtils.arrayToCommaDelimitedString (org.springframework.util.StringUtils.arrayToCommaDelimitedString)1