Search in sources :

Example 1 with SysDeptPageId

use of com.publiccms.entities.sys.SysDeptPageId 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 2 with SysDeptPageId

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

the class SysDeptAdminController method save.

/**
 * @param entity
 * @param categoryIds
 * @param pages
 * @param request
 * @param session
 * @param model
 * @return view name
 */
@RequestMapping("save")
public String save(SysDept entity, Integer[] categoryIds, String[] pages, HttpServletRequest request, HttpSession session, ModelMap model) {
    SysSite site = getSite(request);
    if (null != entity.getId()) {
        SysDept 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.dept", RequestUtils.getIpAddress(request), CommonUtils.getDate(), JsonUtils.getString(entity)));
        }
        sysDeptCategoryService.updateDeptCategorys(entity.getId(), categoryIds);
        sysDeptPageService.updateDeptPages(entity.getId(), pages);
    } else {
        entity.setSiteId(site.getId());
        service.save(entity);
        logOperateService.save(new LogOperate(site.getId(), getAdminFromSession(session).getId(), LogLoginService.CHANNEL_WEB_MANAGER, "save.dept", RequestUtils.getIpAddress(request), CommonUtils.getDate(), JsonUtils.getString(entity)));
        if (CommonUtils.notEmpty(categoryIds)) {
            List<SysDeptCategory> list = new ArrayList<>();
            for (int categoryId : categoryIds) {
                list.add(new SysDeptCategory(new SysDeptCategoryId(entity.getId(), categoryId)));
            }
            sysDeptCategoryService.save(list);
        }
        if (CommonUtils.notEmpty(pages)) {
            List<SysDeptPage> list = new ArrayList<>();
            for (String page : pages) {
                list.add(new SysDeptPage(new SysDeptPageId(entity.getId(), page)));
            }
            sysDeptPageService.save(list);
        }
    }
    return TEMPLATE_DONE;
}
Also used : LogOperate(com.publiccms.entities.log.LogOperate) SysDept(com.publiccms.entities.sys.SysDept) SysDeptPage(com.publiccms.entities.sys.SysDeptPage) ArrayList(java.util.ArrayList) SysDeptCategoryId(com.publiccms.entities.sys.SysDeptCategoryId) StringUtils.arrayToCommaDelimitedString(org.springframework.util.StringUtils.arrayToCommaDelimitedString) SysDeptPageId(com.publiccms.entities.sys.SysDeptPageId) SysSite(com.publiccms.entities.sys.SysSite) SysDeptCategory(com.publiccms.entities.sys.SysDeptCategory) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

SysDept (com.publiccms.entities.sys.SysDept)2 SysDeptPage (com.publiccms.entities.sys.SysDeptPage)2 SysDeptPageId (com.publiccms.entities.sys.SysDeptPageId)2 LogOperate (com.publiccms.entities.log.LogOperate)1 SysDeptCategory (com.publiccms.entities.sys.SysDeptCategory)1 SysDeptCategoryId (com.publiccms.entities.sys.SysDeptCategoryId)1 SysSite (com.publiccms.entities.sys.SysSite)1 ArrayList (java.util.ArrayList)1 LinkedHashMap (java.util.LinkedHashMap)1 StringUtils.arrayToCommaDelimitedString (org.springframework.util.StringUtils.arrayToCommaDelimitedString)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1