需求分析:
与PublicCMS作者写的对接
前端暴露接口
如:
POJO
package com.publiccms.entities.message;
import com.publiccms.common.database.CmsUpgrader;
import com.publiccms.common.generator.annotation.GeneratorColumn;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.exception.DataException;
import org.springframework.format.annotation.DateTimeFormat;
import javax.persistence.*;
import java.util.Date;
/**
* @author qyq
* @date 2021-04-19 18:53
*/
@Entity
@Table(name = "volunteersMessage")
@DynamicUpdate
public class VolunteersMessage implements java.io.Serializable{
private static final long serialVersionUID = 1L;
@GeneratorColumn(title = "ID")
private Integer id;
@GeneratorColumn(title = "姓名", condition = true, like = true)
private String name;
@GeneratorColumn(title = "证件号码", condition = true, like = true)
private String uuid;
@GeneratorColumn(title = "学历", condition = true, like = true)
private String education;
@GeneratorColumn(title = "邮件", condition = true, like = true)
private String email;
/**(状态)*/
@GeneratorColumn(title = "状态", condition = true, like = true)
private Integer status = 0;
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@GeneratorColumn(title = "提交时间", condition = true)
private Date submitTime;
@Id
@GeneratedValue(generator = "cmsGenerator")
@GenericGenerator(name = "cmsGenerator", strategy = CmsUpgrader.IDENTIFIER_GENERATOR)
@Column(name = "id", unique = true, nullable = false)
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
@Column(name = "name", length = 50)
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Column(name = "uuid", length = 50)
public String getUuid() {
return uuid;
}
public void setUuid(String uuid) {
this.uuid = uuid;
}
@Column(name = "education", length = 50)
public String getEducation() {
return education;
}
public void setEducation(String education) {
this.education = education;
}
@Column(name = "email", length = 50)
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public Integer getStatus() {
return status;
}
public void setStatus(Integer status) {
this.status = status;
}
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "submit_time", length = 19)
public Date getSubmitTime() {
return submitTime;
}
public void setSubmitTime(Date submitTime) {
this.submitTime = submitTime;
}
public VolunteersMessage() {
}
public VolunteersMessage( String name, String uuid, String education, String email, Integer status, Date submitTime) {
this.name = name;
this.uuid = uuid;
this.education = education;
this.email = email;
this.status = status;
this.submitTime = submitTime;
}
}
controller层
package com.publiccms.controller.web.message;
import com.publiccms.common.constants.CommonConstants;
import com.publiccms.common.tools.CommonUtils;
import com.publiccms.common.tools.ControllerUtils;
import com.publiccms.common.tools.JsonUtils;
import com.publiccms.common.tools.RequestUtils;
import com.publiccms.entities.cms.*;
import com.publiccms.entities.log.LogOperate;
import com.publiccms.entities.message.VolunteersMessage;
import com.publiccms.entities.sys.SysDept;
import com.publiccms.entities.sys.SysDeptCategoryId;
import com.publiccms.entities.sys.SysSite;
import com.publiccms.entities.sys.SysUser;
import com.publiccms.logic.component.template.ModelComponent;
import com.publiccms.logic.component.template.TemplateComponent;
import com.publiccms.logic.service.cms.CmsCategoryModelService;
import com.publiccms.logic.service.cms.CmsCategoryService;
import com.publiccms.logic.service.cms.CmsContentAttributeService;
import com.publiccms.logic.service.cms.CmsContentService;
import com.publiccms.logic.service.log.LogLoginService;
import com.publiccms.logic.service.log.LogOperateService;
import com.publiccms.logic.service.message.VolunteersMessageService;
import com.publiccms.logic.service.sys.SysDeptCategoryService;
import com.publiccms.logic.service.sys.SysDeptService;
import com.publiccms.views.pojo.entities.CmsModel;
import com.publiccms.views.pojo.entities.ExtendData;
import com.publiccms.views.pojo.model.CmsContentParameters;
import org.apache.commons.lang3.ArrayUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractController;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import static com.publiccms.common.constants.CommonConstants.ERROR;
import static com.publiccms.common.constants.CommonConstants.SUCCESS;
import static com.publiccms.common.tools.CommonUtils.notEmpty;
import static com.publiccms.controller.admin.cms.CmsContentAdminController.initContent;
/**
* @Description:(志愿者信息)
* @author qyq
* @date 2021-04-19 20:17
*/
@Component
@Controller
@RequestMapping("volunteersMessage")
public class VolunteersMessageController extends AbstractController {
@Autowired
private VolunteersMessageService volunteersMessageService;
@Autowired
protected LogOperateService logOperateService;
@Autowired
private CmsContentService service;
@Autowired
private CmsContentAttributeService cmsContentAttributeService;
@Autowired
private ModelComponent modelComponent;
@Autowired
private SysDeptService sysDeptService;
@Autowired
private CmsCategoryModelService categoryModelService;
@Autowired
private TemplateComponent templateComponent;
@Autowired
private CmsCategoryService categoryService;
@Autowired
private SysDeptCategoryService sysDeptCategoryService;
private String[] ignoreProperties = new String[]{"id"};
public static final String[] ignoreProperties2 = new String[] { "siteId", "userId", "categoryId", "tagIds", "sort",
"createDate", "updateDate", "clicks", "comments", "scores", "childs", "checkUserId", "disabled" };
public static final String[] ignorePropertiesWithUrl = ArrayUtils.addAll(ignoreProperties2, new String[] { "url" });
@RequestMapping(value = "save", method = RequestMethod.POST)
@ResponseBody
public String save(@RequestAttribute SysSite site, VolunteersMessage entity, HttpServletRequest request,
HttpSession session, ModelMap model) {
try {
if (notEmpty(entity.getId())) {
entity = volunteersMessageService.update(entity.getId(), entity, ignoreProperties);
} else {
CmsContentAttribute cmsContentAttribute = new CmsContentAttribute();
Date date1 = new Date();
entity.setSubmitTime(date1);
// volunteersMessageService.save(entity);
String data = JsonUtils.getString(entity);
cmsContentAttribute.setData(data);
// cmsContentAttributeService.save(cmsContentAttribute);
CmsContent cmsContent = new CmsContent();
short siteID = 1;
cmsContent.setSiteId(siteID);
cmsContent.setTitle(entity.getName());
cmsContent.setUserId(1);
cmsContent.setCategoryId(3);
cmsContent.setModelId("zyz");
cmsContent.setCopied(false);
cmsContent.setContribute(false);
cmsContent.setOnlyUrl(false);
cmsContent.setHasFiles(false);
cmsContent.setHasImages(false);
cmsContent.setHasStatic(false);
cmsContent.setUrl("/volunteers.html");
cmsContent.setChilds(0);
cmsContent.setScores(0);
cmsContent.setComments(0);
cmsContent.setClicks(0);
Date date = new Date();
cmsContent.setPublishDate(date);
cmsContent.setCreateDate(date1);
cmsContent.setSort(0);
cmsContent.setStatus(2);
cmsContent.setDisabled(false);
// service.save(cmsContent);
CmsContentParameters contentParameters = new CmsContentParameters();
List<ExtendData> listData = new ArrayList<>();
listData.add(new ExtendData("name", entity.getName()));
listData.add(new ExtendData("uuid", entity.getUuid()));
listData.add(new ExtendData("education", entity.getEducation()));
listData.add(new ExtendData("email", entity.getEmail()));
contentParameters.setModelExtendDataList(listData);
CmsModel cmsModel = modelComponent.getMap(site).get(cmsContent.getModelId());
CmsCategory category = categoryService.getEntity(cmsContent.getCategoryId());
service.updateQuote(cmsContent.getSiteId(), cmsContent.getId(), contentParameters, cmsModel, category, cmsContentAttribute);
SysUser admin = new SysUser();
admin.setId(1L);
admin.setSiteId(siteID);
admin.setDeptId(1);
insert(site,admin,cmsContent,cmsContentAttribute,contentParameters,null,
null,request, model);
}
} catch (Exception e) {
e.printStackTrace();
return ERROR;
}
return SUCCESS;
}
public String insert(@RequestAttribute SysSite site, @SessionAttribute SysUser admin, CmsContent entity,
CmsContentAttribute attribute, @ModelAttribute CmsContentParameters contentParameters, Boolean draft, Boolean checked,
HttpServletRequest request, ModelMap model) {
SysDept dept = sysDeptService.getEntity(admin.getDeptId());
if (ControllerUtils.verifyNotEmpty("deptId", admin.getDeptId(), model)
|| ControllerUtils.verifyNotEmpty("deptId", dept, model)
|| ControllerUtils.verifyCustom("noright", !(dept.isOwnsAllCategory() || null != sysDeptCategoryService
.getEntity(new SysDeptCategoryId(admin.getDeptId(), entity.getCategoryId()))), model)) {
return CommonConstants.TEMPLATE_ERROR;
}
CmsCategoryModel categoryModel = categoryModelService
.getEntity(new CmsCategoryModelId(entity.getCategoryId(), entity.getModelId()));
if (ControllerUtils.verifyNotEmpty("categoryModel", categoryModel, model)) {
return CommonConstants.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 CommonConstants.TEMPLATE_ERROR;
}
Date now = CommonUtils.getDate();
initContent(entity, cmsModel, draft, checked, attribute, true, now);
if (null != entity.getId()) {
CmsContent oldEntity = service.getEntity(entity.getId());
if (null == oldEntity || ControllerUtils.verifyNotEquals("siteId", site.getId(), oldEntity.getSiteId(), model)
|| ControllerUtils.verifyCustom("noright",
!(admin.isOwnsAllContent() || oldEntity.getUserId() == admin.getId()), model)) {
return CommonConstants.TEMPLATE_ERROR;
}
entity.setUpdateDate(now);
entity = service.update(entity.getId(), entity, entity.isOnlyUrl() ? ignoreProperties : ignorePropertiesWithUrl);
if (null != entity) {
logOperateService.save(new LogOperate(site.getId(), admin.getId(), LogLoginService.CHANNEL_WEB_MANAGER,
"update.content", RequestUtils.getIpAddress(request), now, JsonUtils.getString(entity)));
}
} else {
entity.setSiteId(site.getId());
entity.setUserId(admin.getId());
service.save(entity);
if (CommonUtils.notEmpty(entity.getParentId())) {
service.updateChilds(entity.getParentId(), 1);
}
logOperateService.save(new LogOperate(site.getId(), admin.getId(), LogLoginService.CHANNEL_WEB_MANAGER,
"save.content", RequestUtils.getIpAddress(request), now, JsonUtils.getString(entity)));
}
entity = service.saveTagAndAttribute(site.getId(), admin.getId(), entity.getId(), contentParameters, cmsModel,
category.getExtendId(), attribute);
if (null != checked && checked) {
service.check(site.getId(), admin, new Long[] { entity.getId() });
}
templateComponent.createContentFile(site, entity, category, categoryModel);// 静态化
if (null == entity.getParentId() && !entity.isOnlyUrl()) {
service.updateQuote(site.getId(), entity.getId(), contentParameters, cmsModel, category, attribute);
if (CommonUtils.notEmpty(contentParameters.getCategoryIds())) {
List<CmsCategory> categoryList = categoryService.getEntitys(
contentParameters.getCategoryIds().toArray(new Integer[contentParameters.getCategoryIds().size()]));
service.saveQuote(site.getId(), entity.getId(), contentParameters, categoryList, cmsModel, category, attribute);
if (null != checked && checked) {
for (CmsCategory c : categoryList) {
templateComponent.createCategoryFile(site, c, null, null);
}
}
}
}
if (null != checked && checked) {
templateComponent.createCategoryFile(site, category, null, null);
CmsContent parent = service.getEntity(entity.getParentId());
}
return CommonConstants.TEMPLATE_DONE;
}
@Override
protected ModelAndView handleRequestInternal(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws Exception {
return null;
}
service层
package com.publiccms.logic.service.message;
import com.publiccms.common.base.BaseService;
import com.publiccms.common.handler.PageHandler;
import com.publiccms.entities.message.VolunteersMessage;
import com.publiccms.logic.dao.message.VolunteersMessageDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
/**
* @Description:(志愿者信息)
* @author qyq
* @date 2021-04-19 20:27
*/
@Repository
public class VolunteersMessageService extends BaseService<VolunteersMessage> {
@Autowired
private VolunteersMessageDao volunteersMessageDao;
@Transactional(readOnly = true)
public PageHandler getPage(String name, Integer status, Integer pageIndex, Integer pageSize) {
return volunteersMessageDao.getPage(name,status,pageIndex,pageSize);
}
}
dao层
package com.publiccms.logic.dao.message;
import com.publiccms.common.base.BaseDao;
import com.publiccms.common.handler.PageHandler;
import com.publiccms.common.handler.QueryHandler;
import com.publiccms.common.tools.CommonUtils;
import com.publiccms.entities.message.VolunteersMessage;
import org.springframework.stereotype.Repository;
import java.text.SimpleDateFormat;
import static com.publiccms.common.tools.CommonUtils.getDate;
import static com.publiccms.common.tools.CommonUtils.notEmpty;
/**
* @Description:(志愿者信息)
* @author qyq
* @date 2021-04-19 19:59
*/
@Repository
public class VolunteersMessageDao extends BaseDao<VolunteersMessage> {
@Override
protected VolunteersMessage init(VolunteersMessage entity) {
// SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
if (CommonUtils.empty(String.valueOf(entity.getSubmitTime()))) {
entity.setSubmitTime(getDate());
}
return entity;
}
public PageHandler getPage(String name, Integer status, Integer pageIndex, Integer pageSize) {
QueryHandler queryHandler = getQueryHandler("from VolunteersMessage bean");
if (notEmpty(name)) {
queryHandler.condition("(bean.name like :name)").setParameter("name", like(name));
}
if (notEmpty(status)) {
queryHandler.condition("(bean.status = :status)").setParameter("status", status);
}
queryHandler.order("bean.id desc");
return getPage(queryHandler, pageIndex, pageSize);
}
}
view层
package com.publiccms.views.directive.message;
import com.publiccms.common.base.AbstractTemplateDirective;
import com.publiccms.common.handler.PageHandler;
import com.publiccms.common.handler.RenderHandler;
import com.publiccms.logic.service.message.VolunteersMessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.io.IOException;
/**
* @author qyq
* @date 2021-04-20 11:06
*/
@Component
public class VolunteersMessageListDirective extends AbstractTemplateDirective {
@Autowired
private VolunteersMessageService volunteersMessageService;
@Override
public void execute(RenderHandler handler) throws IOException, Exception {
PageHandler page = volunteersMessageService.getPage(handler.getString("name"), handler.getInteger("status"),
handler.getInteger("pageIndex", 1), handler.getInteger("count", 30));
handler.put("page", page).render();
}
@Override
public boolean needAppToken() {
return true;
}
}
内容管理呈现
好了,不出意外是都可以用滴!
如果出意外可以看看比较详细的这篇 链接: https://blog.csdn.net/One_Piece111/article/details/116061425?spm=1001.2014.3001.5501.