Authored by 张帅

后台发布相关

... ... @@ -102,4 +102,15 @@ public class GrassArticleController {
}
return new ApiResponse.ApiResponseBuilder().build();
}
@RequestMapping("/timerPublish")
public ApiResponse timerPublish( GrassArticleReq req){
logger.info("timerPublish begin, req is {}",req);
try {
grassArticleService.timerPublish(req);
} catch (PlatformException e) {
return new ApiResponse.ApiResponseBuilder().code(e.getCode()).message(e.getMessage()).build();
}
return new ApiResponse.ApiResponseBuilder().build();
}
}
... ...
... ... @@ -28,4 +28,6 @@ public interface IGrassArticleService {
void deleteArticle(GrassArticleReq req) throws PlatformException;
void timerPublish(GrassArticleReq req) throws PlatformException;
}
... ...
... ... @@ -346,7 +346,7 @@ public class GrassArticleServiceImpl implements IGrassArticleService{
}
grassArticleDao.updateByPrimaryKeySelective(grassArticle);
//推荐和置顶操作,清前台缓存
clearArticleListCache();
clearArticleListCache(req.getArticleId());
}
//编辑文章 没地方用到
if(type == 1){
... ... @@ -451,6 +451,8 @@ public class GrassArticleServiceImpl implements IGrassArticleService{
grassArticle.setAuthorizeAccount(req.getAuthorizeAccount());
grassArticle.setAuthTime(time);
grassArticle.setCreateTime(time);
grassArticle.setIsRecommend(1);
grassArticle.setRecommendTime(time);
grassArticleDao.updateByPrimaryKeySelective(grassArticle);
GrassArticleLabel grassArticleLabel = new GrassArticleLabel();
grassArticleLabel.setArticleId(articleId);
... ... @@ -469,6 +471,8 @@ public class GrassArticleServiceImpl implements IGrassArticleService{
grassArticle.setAuthorizeAccount("");
grassArticle.setAuthTime(0L);
grassArticle.setCreateTime(0L);
grassArticle.setIsRecommend(0);
grassArticle.setRecommendTime(0L);
grassArticleDao.updateByPrimaryKeySelective(grassArticle);
GrassArticleLabel grassArticleLabel = new GrassArticleLabel();
grassArticleLabel.setArticleId(articleId);
... ... @@ -684,6 +688,140 @@ public class GrassArticleServiceImpl implements IGrassArticleService{
grassRefreshCacheService.refreshGrassCache(cacheReq);
}
@Override
public void timerPublish(GrassArticleReq req) throws PlatformException {
logger.info("enter timerPublish, req is {}", req);
publishCheck(req);
String publishTime = req.getPublishTime();
if(StringUtils.isEmpty(publishTime)){
throw new PlatformException("publishTime is null", 402);
}
long time = Long.valueOf(publishTime)+ new Random().nextInt(999);
List<Integer> labels = Lists.newArrayList();
String[] urls = req.getArticleImages().split(",");
String[] skns = null;
if(StringUtils.isNotEmpty(req.getArticleSkns())){
skns = req.getArticleSkns().split(",");
if(skns.length > 5){
logger.info("timerPublish , article products more than most publish number");
throw new PlatformException("publish products most number is 5 ", 405);
}
}
if(urls.length > 9){
logger.info("timerPublish , article images more than most publish number");
throw new PlatformException("publish images most number is 9 ", 405);
}
if(StringUtils.isNotEmpty(req.getLabelIds())){
labels = Arrays.stream(req.getLabelIds().split(",")).map(Integer::valueOf).collect(Collectors.toList());
if(labels.size() > 5){
logger.info("timerPublish , article labels more than most publish number");
throw new PlatformException("publish labels most number is 5 ", 405);
}
}
GrassArticle article = new GrassArticle();
article.setAuthorUid(req.getAuthorUid());
article.setCreateTime(time);
article.setAuthStatus(1);
article.setAuthTime(time);
try{
grassArticleDao.insertArticleSeletive(article);
logger.info("insert grass article success, uid is {}, ariticle id is {}", article.getAuthorUid(), article.getId());
}catch (Exception e){
logger.warn("insert grass article fail, uid is {}, e is {}",req.getAuthorUid(), e );
throw new PlatformException("timerPublish article failed", 402);
}
try{
List<GrassArticleBlock> contentList = Lists.newArrayList();
int contentOrder =0;
for (String url : urls) {
GrassArticleBlock content = new GrassArticleBlock();
content.setArticleId(article.getId());
content.setContentData(getBlock(BLOCK_IMAGE,url));
content.setCreateTime(time);
content.setTemplateKey("image");
content.setOrderBy(contentOrder);
contentOrder++;
contentList.add(content);
}
if(StringUtils.isNotEmpty(req.getContent())){
GrassArticleBlock content = new GrassArticleBlock();
content.setArticleId(article.getId());
content.setContentData(getBlock(BLOCK_TEXT, req.getContent()));
content.setCreateTime(time);
content.setTemplateKey("text");
content.setOrderBy(contentOrder);
contentList.add(content);
}
grassArticleBlockDao.insertArticleContents(contentList);
logger.info("timerPublish insert grass article content success, ariticle id is {}, contentList size is {}", article.getId(), contentList.size());
}catch (Exception e){
logger.warn("timerPublish insert article images fail,ariticle id is {}, e is {}",article.getId(), e );
}
try{
if(StringUtils.isNotEmpty( req.getArticleSkns())){
int orderby = 0;
List<GrassArticleProduct> sknList = Lists.newArrayList();
if(skns != null){
Integer sknType = Optional.ofNullable(req.getSknType()).orElse(1);
for (String skn: skns) {
GrassArticleProduct grassArticleSkn = new GrassArticleProduct();
grassArticleSkn.setArticleId(article.getId());
grassArticleSkn.setProductSkn(Integer.valueOf(skn));
grassArticleSkn.setCreateTime(time);
grassArticleSkn.setOrderBy(orderby);
grassArticleSkn.setProductSource(sknType);
orderby++;
sknList.add(grassArticleSkn);
}
}
if(CollectionUtils.isNotEmpty(sknList)){
grassArticleProductDao.insertArticleSkns(sknList);
}
logger.info("timerPublish insert grass article skns success, ariticle id is {}, sknList size is {}", article.getId(), sknList.size());
}
}catch (Exception e){
logger.warn("timerPublish insert article skns fail,ariticle id is {}, e is {}",article.getId(), e );
}
//构建lables 数据
List<GrassArticleLabel> grassArticleLabels = buildArticleLabels(article.getId(), labels,1);
try{
if(CollectionUtils.isNotEmpty(grassArticleLabels)){
for (GrassArticleLabel label : grassArticleLabels) {
label.setCreateTime(time);
}
grassArticleLabelDao.insertArticleLabels(grassArticleLabels);
}
}catch (Exception e){
logger.warn("timerPublish ,grassArticleLableDao insertArticleLables error, uid is {}, e is {}", req.getAuthorUid(), e);
}
//定时发布的内容 免审 免推荐 直接进入推荐列表
Integer articleId = article.getId();
GrassArticle grassArticle = new GrassArticle();
grassArticle.setId(articleId);
grassArticle.setAuthStatus(1);
grassArticle.setAuthorizeAccount(req.getAuthorizeAccount());
grassArticle.setAuthTime(time);
grassArticle.setCreateTime(time);
grassArticle.setIsRecommend(1);
grassArticle.setRecommendTime(time);
grassArticleDao.updateByPrimaryKeySelective(grassArticle);
GrassArticleLabel grassArticleLabel = new GrassArticleLabel();
grassArticleLabel.setArticleId(articleId);
grassArticleLabel.setAuthStatus(1);//审核状态
grassArticleLabel.setCreateTime(time);
grassArticleLabelDao.updateByPrimaryKeySelective(grassArticleLabel);
logger.info("timerPublish updateByPrimaryKeySelective success! id={}",articleId);
}
private List<ArticleDetailRspBo> buildArticleDetail( List<GrassArticle> articleList){
if(CollectionUtils.isEmpty(articleList)){
return new ArrayList<>();
... ... @@ -849,10 +987,11 @@ public class GrassArticleServiceImpl implements IGrassArticleService{
}
private void clearArticleListCache(){
private void clearArticleListCache(Integer articleId){
logger.info("clearArticleListCache, type=1001");
GrassCacheReq cacheReq = new GrassCacheReq();
cacheReq.setClearCode(1001);
cacheReq.setElementId(String.valueOf(articleId));
grassRefreshCacheService.refreshGrassCache(cacheReq);
}
}
... ...
... ... @@ -123,6 +123,7 @@
<tr>
<td valign="bottom">
<input id="draftBotton" class="btn btn-primary" style="font-size: 18px;" value="保存到草稿箱"/>
<input id="timerBotton" class="btn btn-primary" style="font-size: 18px;" value="定时发布"/>
<input id="subBotton" class="btn btn-primary" style="font-size: 18px; margin-left: 30px;" value="立即发布"/>
<span style="color:red">*运营平台发布的内容,均免审核,直接发布。</span><label></label><br>
</td>
... ... @@ -159,6 +160,13 @@
}
});
$("#timerBotton").linkbutton({
iconCls : "icon-search",
onClick : function() {
getTimeDialog();
}
});
// $("#articleUid").combobox({
// required: true,
// editable:true,
... ... @@ -263,20 +271,6 @@
labelList+='<span class="tag"><span>'+text+'</span><a href="#" class="labelTag" data-index="'+i+'">x</a></span>&nbsp&nbsp&nbsp'
}
$("#labelList").html(labelList);
},
onSelect:function (data) {
// debugger
// var arr = $(this).combobox("getValues");
// var textarr = $(this).combobox("getData");
// var checked = [];
// for (var i=0; i<arr.length;i++){
// for (var j=0; j< textarr.length;j++){
// if(arr[i] == textarr[j].id){
// checked.push(arr[i]);
// }
// }
// }
// $(this).combobox("setValues",checked);
}
});
... ... @@ -507,6 +501,104 @@
// 定时 选择时间
function getTimeDialog(data,id, status){
var timeChoose = $("<div id='timeChoose'>").appendTo($(document.body));
var title = "选择时间";
var textVar = "确认";
window.self.paramObject.mkData = data;
$(timeChoose).myDialog({
title: title,
width: "20%",
height: "20%",
resizable:false,
buttons:[{
id : "saveBtn",
text:textVar,
iconCls : "icon-save",
handler:function(){
debugger;
var time=''
if($("#publishTimeStr").datetimebox('getValue') !=null && $("#publishTimeStr").datetimebox('getValue') !=''){
time = parseInt(new Date($("#publishTimeStr").datetimebox('getValue')).getTime() );
}else {
$.messager.alert("发布失败", "请选择时间", "error");
return;
}
$("#publishArticleForm").form("submit",{
url : contextPath+"/grassArticle/timerPublish",
onSubmit : function(param) {
debugger;
if (!$("#publishArticleForm").form("validate")) {
return false;
}
param.publishTime =time;
var imgs = '';
var imageCount = 0;
$("input[name='url']").each(function(j,item){
debugger
var url = item.value;
if(imgs == ''){
imgs = url;
}else{
imgs = imgs + ","+url;
}
imageCount++;
});
$("#imgs").val(imgs);
if(imageCount > 9){
$.messager.alert("发布失败", "最多只能选择9张图片", "error");
return false;
}
if(imageCount < 1){
$.messager.alert("发布失败", "请选择至少一张图片", "error");
return false;
}
var labels = '';
$("input[name='labelId']").each(function(j,item){
debugger
var id = item.value;
if(labels == ''){
labels = id;
}else{
labels = labels + ","+id;
}
});
$("#labelIds").val(labels);
return true;
},
success : function(data) {
if (data) {
data = $.parseJSON(data);
if (data.code == 200) {
$.messager.alert("提示","发布成功", "info", function(){window.location.reload()});
// alert("保存成功");
} else {
$.messager.alert("保存失败", data.message, "error");
}
} else {
$.messager.alert("保存失败", data.message, "error");
}
}
});
$(timeChoose).dialog("close");
}
}, {
text: "关闭",
iconCls: "icon-cancel",
handler: function () {
$.messager.confirm("确认", "确认关闭吗?", function (flag) {
if(flag){
$(timeChoose).dialog("close");
}
});
}
}],
modal: true,
href: contextPath + "/html/grass/article/chooseTime.html"
});
}
// 编辑分组
function getEditDialog(data){
... ...