use of com.publiccms.entities.sys.SysExtendField 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;
}
use of com.publiccms.entities.sys.SysExtendField 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;
}
use of com.publiccms.entities.sys.SysExtendField in project PublicCMS-preview by sanluan.
the class ContentController method save.
/**
* 保存内容
*
* @param entity
* @param attribute
* @param contentParamters
* @param returnUrl
* @param request
* @param session
* @param response
* @param model
* @return view name
*/
@RequestMapping(value = "save", method = RequestMethod.POST)
public String save(CmsContent entity, CmsContentAttribute attribute, @ModelAttribute CmsContentParamters contentParamters, String returnUrl, HttpServletRequest request, HttpSession session, HttpServletResponse response, ModelMap model) {
SysSite site = getSite(request);
if (CommonUtils.empty(returnUrl)) {
returnUrl = site.getDynamicPath();
}
SysUser user = getUserFromSession(session);
CmsCategoryModel categoryModel = categoryModelService.getEntity(new CmsCategoryModelId(entity.getCategoryId(), entity.getModelId()));
if (ControllerUtils.verifyNotEmpty("categoryModel", categoryModel, model) || ControllerUtils.verifyCustom("contribute", null == user, model)) {
return REDIRECT + returnUrl;
}
CmsCategory category = categoryService.getEntity(entity.getCategoryId());
if (null != category && (site.getId() != category.getSiteId() || !category.isAllowContribute())) {
category = null;
}
CmsModel cmsModel = modelComponent.getMap(site).get(entity.getModelId());
if (ControllerUtils.verifyNotEmpty("category", category, model) || ControllerUtils.verifyNotEmpty("model", cmsModel, model)) {
return REDIRECT + returnUrl;
}
entity.setHasFiles(cmsModel.isHasFiles());
entity.setHasImages(cmsModel.isHasImages());
entity.setOnlyUrl(cmsModel.isOnlyUrl());
entity.setStatus(CmsContentService.STATUS_PEND);
if (null != entity.getId()) {
CmsContent oldEntity = service.getEntity(entity.getId());
if (null == oldEntity || ControllerUtils.verifyNotEquals("siteId", site.getId(), oldEntity.getSiteId(), model)) {
return REDIRECT + returnUrl;
}
entity = service.update(entity.getId(), entity, entity.isOnlyUrl() ? ignoreProperties : ignorePropertiesWithUrl);
if (null != entity.getId()) {
logOperateService.save(new LogOperate(site.getId(), user.getId(), LogLoginService.CHANNEL_WEB, "update.content", RequestUtils.getIpAddress(request), CommonUtils.getDate(), 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, "save.content", RequestUtils.getIpAddress(request), CommonUtils.getDate(), JsonUtils.getString(entity)));
}
if (entity.isHasImages() || entity.isHasFiles()) {
contentFileService.update(entity.getId(), user.getId(), entity.isHasFiles() ? contentParamters.getFiles() : null, // 更新保存图集,附件
entity.isHasImages() ? contentParamters.getImages() : null);
}
if (null != attribute.getText()) {
attribute.setWordCount(HtmlUtils.removeHtmlTag(attribute.getText()).length());
}
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);
return REDIRECT + returnUrl;
}
use of com.publiccms.entities.sys.SysExtendField in project PublicCMS-preview by sanluan.
the class SysExtendFieldService method update.
/**
* @param extendId
* @param entitys
*/
public void update(Integer extendId, List<SysExtendField> entitys) {
if (CommonUtils.notEmpty(extendId)) {
Set<String> codeList = new HashSet<>();
if (CommonUtils.notEmpty(entitys)) {
for (SysExtendField entity : entitys) {
if (CommonUtils.notEmpty(entity.getId().getExtendId())) {
if (null == getEntity(entity.getId())) {
save(entity);
} else {
update(entity.getId(), entity, ignoreProperties);
}
} else {
entity.getId().setExtendId(extendId);
save(entity);
}
codeList.add(entity.getId().getCode());
}
}
for (SysExtendField extend : getList(extendId)) {
if (!codeList.contains(extend.getId().getCode())) {
delete(extend.getId());
}
}
}
}
Aggregations