User user = getUserFromSession(session);
if (user == null) {
return getErrorUrl(UNLOGIN_ERROR_MESSAGE);
}
String url = JCMSConstant.createModelUrl(modelName, suffix);
Model model = new Model();
model.setModelName(modelName);
model.setTitle(title);
model.setExtname(suffix);
model.setKeyword(keyword);
model.setContent(content);
model.setStatus(status);
model.setTopicid(topicid);
model.setRate(refresh);
model.setType(modelType);
Date now = new Date();
Date timeoutDate = DateUtils.addDays(now, timeout);
model.setTimeout(DateFormatUtils.ISO_DATETIME_FORMAT.format(timeoutDate));
model.setAddTime(JCMSConstant.getDateString(now));
model.setLastModify(JCMSConstant.getDateString(now));
model.setModifyUser(user.getUserName());
model.setUrl(url);
int insertModel =modelService.addModel(model);
int insertPushRecord =pushRecordService.addBlankDoc(title, null, url, topicid, 60, user.getUserName(), null);
if(insertModel<=0){
logger.error("插入模板失败:" + ToStringBuilder.reflectionToString(model));
return getErrorUrl("插入模板失败");
}
if(insertPushRecord<=0){
logger.error("插入空文章失败");
return getErrorUrl("插入空文章失败");
}
if (status == Model.modelStatus.publish.ordinal()) {//发布模板
try {
modelService.publishModelContent(model);
} catch (IOException e) {
logger.error("输出模板页面出错,modelName=" + model.getModelName(), e);
return getErrorUrl("插入空文章失败");
}
return redirect("/admin/topic/topicPage.do?topicid=" + topicid + "&pageNum=" + pageNum
+ "&type=" + type);