use of com.publiccms.entities.sys.SysDeptCategory in project PublicCMS-preview by sanluan.
the class SysDeptCategoryDirective method execute.
@Override
public void execute(RenderHandler handler) throws IOException, Exception {
Integer deptId = handler.getInteger("deptId");
Integer categoryId = handler.getInteger("categoryId");
if (CommonUtils.notEmpty(deptId)) {
if (CommonUtils.notEmpty(categoryId)) {
SysDept entity = sysDeptService.getEntity(deptId);
if (null != entity) {
if (entity.isOwnsAllCategory()) {
handler.put("object", true).render();
} else {
handler.put("object", null != service.getEntity(new SysDeptCategoryId(deptId, categoryId))).render();
}
}
} else {
Integer[] categoryIds = handler.getIntegerArray("categoryIds");
if (CommonUtils.notEmpty(categoryIds)) {
Map<String, Boolean> map = new LinkedHashMap<>();
SysDept entity = sysDeptService.getEntity(deptId);
if (null != entity) {
if (entity.isOwnsAllCategory()) {
for (Integer id : categoryIds) {
map.put(String.valueOf(id), true);
}
} else {
SysDeptCategoryId[] ids = new SysDeptCategoryId[categoryIds.length];
for (int i = 0; i < categoryIds.length; i++) {
map.put(String.valueOf(categoryIds[i]), false);
ids[i] = new SysDeptCategoryId(deptId, categoryIds[i]);
}
for (SysDeptCategory e : service.getEntitys(ids)) {
map.put(String.valueOf(e.getId().getCategoryId()), true);
}
}
}
handler.put("map", map).render();
}
}
}
}
use of com.publiccms.entities.sys.SysDeptCategory 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;
}
Aggregations