Search in sources :

Example 1 with SysDept

use of com.publiccms.entities.sys.SysDept in project PublicCMS-preview by sanluan.

the class CmsContentAdminController method save.

/**
 * 保存内容
 *
 * @param entity
 * @param attribute
 * @param contentParamters
 * @param draft
 * @param checked
 * @param request
 * @param session
 * @param model
 * @return view name
 */
@RequestMapping("save")
public String save(CmsContent entity, CmsContentAttribute attribute, @ModelAttribute CmsContentParamters contentParamters, Boolean draft, Boolean checked, HttpServletRequest request, HttpSession session, ModelMap model) {
    SysSite site = getSite(request);
    SysUser user = getAdminFromSession(session);
    SysDept dept = sysDeptService.getEntity(user.getDeptId());
    if (ControllerUtils.verifyNotEmpty("deptId", user.getDeptId(), model) && ControllerUtils.verifyNotEmpty("deptId", dept, model) && ControllerUtils.verifyCustom("noright", !(dept.isOwnsAllCategory() || null != sysDeptCategoryService.getEntity(new SysDeptCategoryId(user.getDeptId(), entity.getCategoryId()))), model)) {
        return TEMPLATE_ERROR;
    }
    CmsCategoryModel categoryModel = categoryModelService.getEntity(new CmsCategoryModelId(entity.getCategoryId(), entity.getModelId()));
    if (ControllerUtils.verifyNotEmpty("categoryModel", categoryModel, model)) {
        return TEMPLATE_ERROR;
    }
    CmsCategory category = categoryService.getEntity(entity.getCategoryId());
    if (null != category && site.getId() != category.getSiteId()) {
        category = null;
    }
    CmsModel cmsModel = modelComponent.getMap(site).get(entity.getModelId());
    if (ControllerUtils.verifyNotEmpty("category", category, model) || ControllerUtils.verifyNotEmpty("model", cmsModel, model)) {
        return TEMPLATE_ERROR;
    }
    entity.setHasFiles(cmsModel.isHasFiles());
    entity.setHasImages(cmsModel.isHasImages());
    entity.setOnlyUrl(cmsModel.isOnlyUrl());
    if ((null == checked || !checked) && null != draft && draft) {
        entity.setStatus(CmsContentService.STATUS_DRAFT);
    } else {
        entity.setStatus(CmsContentService.STATUS_PEND);
    }
    Date now = CommonUtils.getDate();
    if (null == entity.getPublishDate()) {
        entity.setPublishDate(now);
    }
    if (null != attribute.getText()) {
        String text = HtmlUtils.removeHtmlTag(attribute.getText());
        attribute.setWordCount(text.length());
        if (CommonUtils.empty(entity.getDescription())) {
            entity.setDescription(StringUtils.substring(text, 0, 300));
        }
    }
    if (null != entity.getId()) {
        CmsContent oldEntity = service.getEntity(entity.getId());
        if (null == oldEntity || ControllerUtils.verifyNotEquals("siteId", site.getId(), oldEntity.getSiteId(), model)) {
            return TEMPLATE_ERROR;
        }
        entity.setUpdateDate(now);
        entity = service.update(entity.getId(), entity, entity.isOnlyUrl() ? ignoreProperties : ignorePropertiesWithUrl);
        if (null != entity) {
            logOperateService.save(new LogOperate(site.getId(), user.getId(), LogLoginService.CHANNEL_WEB_MANAGER, "update.content", RequestUtils.getIpAddress(request), now, JsonUtils.getString(entity)));
        }
    } else {
        entity.setSiteId(site.getId());
        entity.setUserId(user.getId());
        service.save(entity);
        if (CommonUtils.notEmpty(entity.getParentId())) {
            service.updateChilds(entity.getParentId(), 1);
        }
        logOperateService.save(new LogOperate(site.getId(), user.getId(), LogLoginService.CHANNEL_WEB_MANAGER, "save.content", RequestUtils.getIpAddress(request), now, JsonUtils.getString(entity)));
    }
    Long[] tagIds = tagService.update(site.getId(), contentParamters.getTags());
    // 更新保存标签
    service.updateTagIds(entity.getId(), arrayToDelimitedString(tagIds, BLANK_SPACE));
    if (entity.isHasImages() || entity.isHasFiles()) {
        contentFileService.update(entity.getId(), user.getId(), entity.isHasFiles() ? contentParamters.getFiles() : null, // 更新保存图集,附件
        entity.isHasImages() ? contentParamters.getImages() : null);
    }
    List<ExtendField> modelExtendList = cmsModel.getExtendList();
    Map<String, String> map = ExtendUtils.getExtentDataMap(contentParamters.getModelExtendDataList(), modelExtendList);
    if (null != category && null != extendService.getEntity(category.getExtendId())) {
        List<SysExtendField> categoryExtendList = extendFieldService.getList(category.getExtendId());
        Map<String, String> categoryMap = ExtendUtils.getSysExtentDataMap(contentParamters.getCategoryExtendDataList(), categoryExtendList);
        if (CommonUtils.notEmpty(map)) {
            map.putAll(categoryMap);
        } else {
            map = categoryMap;
        }
    }
    if (CommonUtils.notEmpty(map)) {
        attribute.setData(ExtendUtils.getExtendString(map));
    } else {
        attribute.setData(null);
    }
    // 更新保存扩展字段,文本字段
    attributeService.updateAttribute(entity.getId(), attribute);
    // 更新保存推荐内容
    cmsContentRelatedService.update(entity.getId(), user.getId(), contentParamters.getContentRelateds());
    // 静态化
    templateComponent.createContentFile(site, entity, category, categoryModel);
    if (null != checked && checked) {
        service.check(site.getId(), user.getId(), new Long[] { entity.getId() }, false);
        if (CommonUtils.notEmpty(entity.getParentId())) {
            publish(new Long[] { entity.getParentId() }, request, session, model);
        }
        templateComponent.createCategoryFile(site, category, null, null);
    }
    return TEMPLATE_DONE;
}
Also used : CmsContent(com.publiccms.entities.cms.CmsContent) LogOperate(com.publiccms.entities.log.LogOperate) SysUser(com.publiccms.entities.sys.SysUser) CmsModel(com.publiccms.views.pojo.entities.CmsModel) SysDept(com.publiccms.entities.sys.SysDept) SysExtendField(com.publiccms.entities.sys.SysExtendField) ExtendField(com.publiccms.views.pojo.entities.ExtendField) SysDeptCategoryId(com.publiccms.entities.sys.SysDeptCategoryId) StringUtils.arrayToDelimitedString(org.springframework.util.StringUtils.arrayToDelimitedString) CmsCategoryModelId(com.publiccms.entities.cms.CmsCategoryModelId) CmsCategoryModel(com.publiccms.entities.cms.CmsCategoryModel) Date(java.util.Date) SysSite(com.publiccms.entities.sys.SysSite) SysExtendField(com.publiccms.entities.sys.SysExtendField) CmsCategory(com.publiccms.entities.cms.CmsCategory) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with SysDept

use of com.publiccms.entities.sys.SysDept in project PublicCMS-preview by sanluan.

the class SysDeptService method delete.

/**
 * @param siteId
 * @param id
 * @return
 */
public List<Integer> delete(short siteId, Integer id) {
    SysDept entity = getEntity(id);
    List<Integer> idList = new ArrayList<>();
    if (null != entity && siteId == entity.getSiteId()) {
        @SuppressWarnings("unchecked") List<SysDept> list = (List<SysDept>) getPage(entity.getSiteId(), entity.getId(), null, null, null).getList();
        for (SysDept child : list) {
            delete(child.getId());
            idList.add(child.getId());
        }
        dao.delete(id);
        idList.add(id);
    }
    return idList;
}
Also used : SysDept(com.publiccms.entities.sys.SysDept) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList)

Example 3 with SysDept

use of com.publiccms.entities.sys.SysDept in project PublicCMS-preview by sanluan.

the class SysDeptDirective method execute.

@Override
public void execute(RenderHandler handler) throws IOException, Exception {
    Integer id = handler.getInteger("id");
    SysSite site = getSite(handler);
    if (CommonUtils.notEmpty(id)) {
        SysDept 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<SysDept> entityList = service.getEntitys(ids);
            Map<String, SysDept> map = new LinkedHashMap<>();
            for (SysDept entity : entityList) {
                if (site.getId() == entity.getSiteId()) {
                    map.put(String.valueOf(entity.getId()), entity);
                }
            }
            handler.put("map", map).render();
        }
    }
}
Also used : SysDept(com.publiccms.entities.sys.SysDept) SysSite(com.publiccms.entities.sys.SysSite) LinkedHashMap(java.util.LinkedHashMap)

Example 4 with SysDept

use of com.publiccms.entities.sys.SysDept in project PublicCMS-preview by sanluan.

the class SysDeptPageDirective method execute.

@Override
public void execute(RenderHandler handler) throws IOException, Exception {
    Integer deptId = handler.getInteger("deptId");
    String page = handler.getString("page");
    if (CommonUtils.notEmpty(deptId)) {
        if (CommonUtils.notEmpty(page)) {
            SysDeptPage entity = service.getEntity(deptId, page);
            if (null != entity) {
                handler.put("object", entity).render();
            }
        } else {
            String[] pages = handler.getStringArray("pages");
            if (CommonUtils.notEmpty(pages)) {
                Map<String, Boolean> map = new LinkedHashMap<>();
                SysDept entity = sysDeptService.getEntity(deptId);
                if (null != entity && entity.isOwnsAllCategory()) {
                    for (String p : pages) {
                        map.put(p, true);
                    }
                } else {
                    SysDeptPageId[] ids = new SysDeptPageId[pages.length];
                    for (int i = 0; i < pages.length; i++) {
                        map.put(pages[i], false);
                        ids[i] = new SysDeptPageId(deptId, pages[i]);
                    }
                    for (SysDeptPage e : service.getEntitys(ids)) {
                        map.put(e.getId().getPage(), true);
                    }
                }
                handler.put("map", map).render();
            }
        }
    }
}
Also used : SysDept(com.publiccms.entities.sys.SysDept) SysDeptPage(com.publiccms.entities.sys.SysDeptPage) SysDeptPageId(com.publiccms.entities.sys.SysDeptPageId) LinkedHashMap(java.util.LinkedHashMap)

Example 5 with SysDept

use of com.publiccms.entities.sys.SysDept in project PublicCMS-preview by sanluan.

the class SysDeptAdminController method disable.

/**
 * @param id
 * @param request
 * @param session
 * @param model
 * @return view name
 */
@RequestMapping(value = "disableUser", method = RequestMethod.POST)
public String disable(Long id, HttpServletRequest request, HttpSession session, ModelMap model) {
    if (ControllerUtils.verifyEquals("admin.operate", getAdminFromSession(session).getId(), id, model)) {
        return TEMPLATE_ERROR;
    }
    SysUser entity = userService.getEntity(id);
    if (null != entity) {
        SysSite site = getSite(request);
        SysDept dept = service.getEntity(entity.getDeptId());
        SysUser admin = getAdminFromSession(session);
        if (ControllerUtils.verifyNotEquals("siteId", site.getId(), entity.getSiteId(), model) || ControllerUtils.verifyNotEmpty("deptId", dept, model) || ControllerUtils.verifyNotEquals("userId", dept.getUserId(), admin.getId(), model)) {
            return TEMPLATE_ERROR;
        }
        userService.updateStatus(id, true);
        logOperateService.save(new LogOperate(site.getId(), admin.getId(), LogLoginService.CHANNEL_WEB_MANAGER, "disable.user", RequestUtils.getIpAddress(request), CommonUtils.getDate(), JsonUtils.getString(entity)));
    }
    return TEMPLATE_DONE;
}
Also used : LogOperate(com.publiccms.entities.log.LogOperate) SysUser(com.publiccms.entities.sys.SysUser) SysDept(com.publiccms.entities.sys.SysDept) SysSite(com.publiccms.entities.sys.SysSite) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

SysDept (com.publiccms.entities.sys.SysDept)10 SysSite (com.publiccms.entities.sys.SysSite)7 LogOperate (com.publiccms.entities.log.LogOperate)6 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)6 SysUser (com.publiccms.entities.sys.SysUser)5 SysDeptCategoryId (com.publiccms.entities.sys.SysDeptCategoryId)3 LinkedHashMap (java.util.LinkedHashMap)3 SysDeptCategory (com.publiccms.entities.sys.SysDeptCategory)2 SysDeptPage (com.publiccms.entities.sys.SysDeptPage)2 SysDeptPageId (com.publiccms.entities.sys.SysDeptPageId)2 SysRoleUser (com.publiccms.entities.sys.SysRoleUser)2 SysRoleUserId (com.publiccms.entities.sys.SysRoleUserId)2 ArrayList (java.util.ArrayList)2 CmsCategory (com.publiccms.entities.cms.CmsCategory)1 CmsCategoryModel (com.publiccms.entities.cms.CmsCategoryModel)1 CmsCategoryModelId (com.publiccms.entities.cms.CmsCategoryModelId)1 CmsContent (com.publiccms.entities.cms.CmsContent)1 SysDomain (com.publiccms.entities.sys.SysDomain)1 SysExtendField (com.publiccms.entities.sys.SysExtendField)1 SysRole (com.publiccms.entities.sys.SysRole)1