Authored by 张帅

后台发布相关

@@ -102,4 +102,15 @@ public class GrassArticleController { @@ -102,4 +102,15 @@ public class GrassArticleController {
102 } 102 }
103 return new ApiResponse.ApiResponseBuilder().build(); 103 return new ApiResponse.ApiResponseBuilder().build();
104 } 104 }
  105 +
  106 + @RequestMapping("/timerPublish")
  107 + public ApiResponse timerPublish( GrassArticleReq req){
  108 + logger.info("timerPublish begin, req is {}",req);
  109 + try {
  110 + grassArticleService.timerPublish(req);
  111 + } catch (PlatformException e) {
  112 + return new ApiResponse.ApiResponseBuilder().code(e.getCode()).message(e.getMessage()).build();
  113 + }
  114 + return new ApiResponse.ApiResponseBuilder().build();
  115 + }
105 } 116 }
@@ -28,4 +28,6 @@ public interface IGrassArticleService { @@ -28,4 +28,6 @@ public interface IGrassArticleService {
28 28
29 void deleteArticle(GrassArticleReq req) throws PlatformException; 29 void deleteArticle(GrassArticleReq req) throws PlatformException;
30 30
  31 + void timerPublish(GrassArticleReq req) throws PlatformException;
  32 +
31 } 33 }
@@ -346,7 +346,7 @@ public class GrassArticleServiceImpl implements IGrassArticleService{ @@ -346,7 +346,7 @@ public class GrassArticleServiceImpl implements IGrassArticleService{
346 } 346 }
347 grassArticleDao.updateByPrimaryKeySelective(grassArticle); 347 grassArticleDao.updateByPrimaryKeySelective(grassArticle);
348 //推荐和置顶操作,清前台缓存 348 //推荐和置顶操作,清前台缓存
349 - clearArticleListCache(); 349 + clearArticleListCache(req.getArticleId());
350 } 350 }
351 //编辑文章 没地方用到 351 //编辑文章 没地方用到
352 if(type == 1){ 352 if(type == 1){
@@ -451,6 +451,8 @@ public class GrassArticleServiceImpl implements IGrassArticleService{ @@ -451,6 +451,8 @@ public class GrassArticleServiceImpl implements IGrassArticleService{
451 grassArticle.setAuthorizeAccount(req.getAuthorizeAccount()); 451 grassArticle.setAuthorizeAccount(req.getAuthorizeAccount());
452 grassArticle.setAuthTime(time); 452 grassArticle.setAuthTime(time);
453 grassArticle.setCreateTime(time); 453 grassArticle.setCreateTime(time);
  454 + grassArticle.setIsRecommend(1);
  455 + grassArticle.setRecommendTime(time);
454 grassArticleDao.updateByPrimaryKeySelective(grassArticle); 456 grassArticleDao.updateByPrimaryKeySelective(grassArticle);
455 GrassArticleLabel grassArticleLabel = new GrassArticleLabel(); 457 GrassArticleLabel grassArticleLabel = new GrassArticleLabel();
456 grassArticleLabel.setArticleId(articleId); 458 grassArticleLabel.setArticleId(articleId);
@@ -469,6 +471,8 @@ public class GrassArticleServiceImpl implements IGrassArticleService{ @@ -469,6 +471,8 @@ public class GrassArticleServiceImpl implements IGrassArticleService{
469 grassArticle.setAuthorizeAccount(""); 471 grassArticle.setAuthorizeAccount("");
470 grassArticle.setAuthTime(0L); 472 grassArticle.setAuthTime(0L);
471 grassArticle.setCreateTime(0L); 473 grassArticle.setCreateTime(0L);
  474 + grassArticle.setIsRecommend(0);
  475 + grassArticle.setRecommendTime(0L);
472 grassArticleDao.updateByPrimaryKeySelective(grassArticle); 476 grassArticleDao.updateByPrimaryKeySelective(grassArticle);
473 GrassArticleLabel grassArticleLabel = new GrassArticleLabel(); 477 GrassArticleLabel grassArticleLabel = new GrassArticleLabel();
474 grassArticleLabel.setArticleId(articleId); 478 grassArticleLabel.setArticleId(articleId);
@@ -684,6 +688,140 @@ public class GrassArticleServiceImpl implements IGrassArticleService{ @@ -684,6 +688,140 @@ public class GrassArticleServiceImpl implements IGrassArticleService{
684 grassRefreshCacheService.refreshGrassCache(cacheReq); 688 grassRefreshCacheService.refreshGrassCache(cacheReq);
685 } 689 }
686 690
  691 + @Override
  692 + public void timerPublish(GrassArticleReq req) throws PlatformException {
  693 + logger.info("enter timerPublish, req is {}", req);
  694 + publishCheck(req);
  695 +
  696 + String publishTime = req.getPublishTime();
  697 + if(StringUtils.isEmpty(publishTime)){
  698 + throw new PlatformException("publishTime is null", 402);
  699 + }
  700 + long time = Long.valueOf(publishTime)+ new Random().nextInt(999);
  701 +
  702 + List<Integer> labels = Lists.newArrayList();
  703 + String[] urls = req.getArticleImages().split(",");
  704 + String[] skns = null;
  705 + if(StringUtils.isNotEmpty(req.getArticleSkns())){
  706 + skns = req.getArticleSkns().split(",");
  707 + if(skns.length > 5){
  708 + logger.info("timerPublish , article products more than most publish number");
  709 + throw new PlatformException("publish products most number is 5 ", 405);
  710 + }
  711 + }
  712 + if(urls.length > 9){
  713 + logger.info("timerPublish , article images more than most publish number");
  714 + throw new PlatformException("publish images most number is 9 ", 405);
  715 + }
  716 + if(StringUtils.isNotEmpty(req.getLabelIds())){
  717 + labels = Arrays.stream(req.getLabelIds().split(",")).map(Integer::valueOf).collect(Collectors.toList());
  718 + if(labels.size() > 5){
  719 + logger.info("timerPublish , article labels more than most publish number");
  720 + throw new PlatformException("publish labels most number is 5 ", 405);
  721 + }
  722 + }
  723 +
  724 + GrassArticle article = new GrassArticle();
  725 + article.setAuthorUid(req.getAuthorUid());
  726 + article.setCreateTime(time);
  727 + article.setAuthStatus(1);
  728 + article.setAuthTime(time);
  729 + try{
  730 + grassArticleDao.insertArticleSeletive(article);
  731 + logger.info("insert grass article success, uid is {}, ariticle id is {}", article.getAuthorUid(), article.getId());
  732 + }catch (Exception e){
  733 + logger.warn("insert grass article fail, uid is {}, e is {}",req.getAuthorUid(), e );
  734 + throw new PlatformException("timerPublish article failed", 402);
  735 + }
  736 +
  737 + try{
  738 + List<GrassArticleBlock> contentList = Lists.newArrayList();
  739 + int contentOrder =0;
  740 + for (String url : urls) {
  741 + GrassArticleBlock content = new GrassArticleBlock();
  742 + content.setArticleId(article.getId());
  743 + content.setContentData(getBlock(BLOCK_IMAGE,url));
  744 + content.setCreateTime(time);
  745 + content.setTemplateKey("image");
  746 + content.setOrderBy(contentOrder);
  747 + contentOrder++;
  748 + contentList.add(content);
  749 + }
  750 + if(StringUtils.isNotEmpty(req.getContent())){
  751 + GrassArticleBlock content = new GrassArticleBlock();
  752 + content.setArticleId(article.getId());
  753 + content.setContentData(getBlock(BLOCK_TEXT, req.getContent()));
  754 + content.setCreateTime(time);
  755 + content.setTemplateKey("text");
  756 + content.setOrderBy(contentOrder);
  757 + contentList.add(content);
  758 + }
  759 + grassArticleBlockDao.insertArticleContents(contentList);
  760 + logger.info("timerPublish insert grass article content success, ariticle id is {}, contentList size is {}", article.getId(), contentList.size());
  761 + }catch (Exception e){
  762 + logger.warn("timerPublish insert article images fail,ariticle id is {}, e is {}",article.getId(), e );
  763 + }
  764 +
  765 + try{
  766 + if(StringUtils.isNotEmpty( req.getArticleSkns())){
  767 + int orderby = 0;
  768 + List<GrassArticleProduct> sknList = Lists.newArrayList();
  769 + if(skns != null){
  770 + Integer sknType = Optional.ofNullable(req.getSknType()).orElse(1);
  771 + for (String skn: skns) {
  772 + GrassArticleProduct grassArticleSkn = new GrassArticleProduct();
  773 + grassArticleSkn.setArticleId(article.getId());
  774 + grassArticleSkn.setProductSkn(Integer.valueOf(skn));
  775 + grassArticleSkn.setCreateTime(time);
  776 + grassArticleSkn.setOrderBy(orderby);
  777 + grassArticleSkn.setProductSource(sknType);
  778 + orderby++;
  779 + sknList.add(grassArticleSkn);
  780 + }
  781 + }
  782 +
  783 + if(CollectionUtils.isNotEmpty(sknList)){
  784 + grassArticleProductDao.insertArticleSkns(sknList);
  785 + }
  786 + logger.info("timerPublish insert grass article skns success, ariticle id is {}, sknList size is {}", article.getId(), sknList.size());
  787 + }
  788 + }catch (Exception e){
  789 + logger.warn("timerPublish insert article skns fail,ariticle id is {}, e is {}",article.getId(), e );
  790 + }
  791 +
  792 + //构建lables 数据
  793 + List<GrassArticleLabel> grassArticleLabels = buildArticleLabels(article.getId(), labels,1);
  794 + try{
  795 + if(CollectionUtils.isNotEmpty(grassArticleLabels)){
  796 + for (GrassArticleLabel label : grassArticleLabels) {
  797 + label.setCreateTime(time);
  798 + }
  799 + grassArticleLabelDao.insertArticleLabels(grassArticleLabels);
  800 + }
  801 + }catch (Exception e){
  802 + logger.warn("timerPublish ,grassArticleLableDao insertArticleLables error, uid is {}, e is {}", req.getAuthorUid(), e);
  803 + }
  804 +
  805 + //定时发布的内容 免审 免推荐 直接进入推荐列表
  806 + Integer articleId = article.getId();
  807 + GrassArticle grassArticle = new GrassArticle();
  808 + grassArticle.setId(articleId);
  809 + grassArticle.setAuthStatus(1);
  810 + grassArticle.setAuthorizeAccount(req.getAuthorizeAccount());
  811 + grassArticle.setAuthTime(time);
  812 + grassArticle.setCreateTime(time);
  813 + grassArticle.setIsRecommend(1);
  814 + grassArticle.setRecommendTime(time);
  815 + grassArticleDao.updateByPrimaryKeySelective(grassArticle);
  816 + GrassArticleLabel grassArticleLabel = new GrassArticleLabel();
  817 + grassArticleLabel.setArticleId(articleId);
  818 + grassArticleLabel.setAuthStatus(1);//审核状态
  819 + grassArticleLabel.setCreateTime(time);
  820 + grassArticleLabelDao.updateByPrimaryKeySelective(grassArticleLabel);
  821 + logger.info("timerPublish updateByPrimaryKeySelective success! id={}",articleId);
  822 +
  823 + }
  824 +
687 private List<ArticleDetailRspBo> buildArticleDetail( List<GrassArticle> articleList){ 825 private List<ArticleDetailRspBo> buildArticleDetail( List<GrassArticle> articleList){
688 if(CollectionUtils.isEmpty(articleList)){ 826 if(CollectionUtils.isEmpty(articleList)){
689 return new ArrayList<>(); 827 return new ArrayList<>();
@@ -849,10 +987,11 @@ public class GrassArticleServiceImpl implements IGrassArticleService{ @@ -849,10 +987,11 @@ public class GrassArticleServiceImpl implements IGrassArticleService{
849 } 987 }
850 988
851 989
852 - private void clearArticleListCache(){ 990 + private void clearArticleListCache(Integer articleId){
853 logger.info("clearArticleListCache, type=1001"); 991 logger.info("clearArticleListCache, type=1001");
854 GrassCacheReq cacheReq = new GrassCacheReq(); 992 GrassCacheReq cacheReq = new GrassCacheReq();
855 cacheReq.setClearCode(1001); 993 cacheReq.setClearCode(1001);
  994 + cacheReq.setElementId(String.valueOf(articleId));
856 grassRefreshCacheService.refreshGrassCache(cacheReq); 995 grassRefreshCacheService.refreshGrassCache(cacheReq);
857 } 996 }
858 } 997 }
@@ -123,6 +123,7 @@ @@ -123,6 +123,7 @@
123 <tr> 123 <tr>
124 <td valign="bottom"> 124 <td valign="bottom">
125 <input id="draftBotton" class="btn btn-primary" style="font-size: 18px;" value="保存到草稿箱"/> 125 <input id="draftBotton" class="btn btn-primary" style="font-size: 18px;" value="保存到草稿箱"/>
  126 + <input id="timerBotton" class="btn btn-primary" style="font-size: 18px;" value="定时发布"/>
126 <input id="subBotton" class="btn btn-primary" style="font-size: 18px; margin-left: 30px;" value="立即发布"/> 127 <input id="subBotton" class="btn btn-primary" style="font-size: 18px; margin-left: 30px;" value="立即发布"/>
127 <span style="color:red">*运营平台发布的内容,均免审核,直接发布。</span><label></label><br> 128 <span style="color:red">*运营平台发布的内容,均免审核,直接发布。</span><label></label><br>
128 </td> 129 </td>
@@ -159,6 +160,13 @@ @@ -159,6 +160,13 @@
159 } 160 }
160 }); 161 });
161 162
  163 + $("#timerBotton").linkbutton({
  164 + iconCls : "icon-search",
  165 + onClick : function() {
  166 + getTimeDialog();
  167 + }
  168 + });
  169 +
162 // $("#articleUid").combobox({ 170 // $("#articleUid").combobox({
163 // required: true, 171 // required: true,
164 // editable:true, 172 // editable:true,
@@ -263,20 +271,6 @@ @@ -263,20 +271,6 @@
263 labelList+='<span class="tag"><span>'+text+'</span><a href="#" class="labelTag" data-index="'+i+'">x</a></span>&nbsp&nbsp&nbsp' 271 labelList+='<span class="tag"><span>'+text+'</span><a href="#" class="labelTag" data-index="'+i+'">x</a></span>&nbsp&nbsp&nbsp'
264 } 272 }
265 $("#labelList").html(labelList); 273 $("#labelList").html(labelList);
266 - },  
267 - onSelect:function (data) {  
268 - // debugger  
269 - // var arr = $(this).combobox("getValues");  
270 - // var textarr = $(this).combobox("getData");  
271 - // var checked = [];  
272 - // for (var i=0; i<arr.length;i++){  
273 - // for (var j=0; j< textarr.length;j++){  
274 - // if(arr[i] == textarr[j].id){  
275 - // checked.push(arr[i]);  
276 - // }  
277 - // }  
278 - // }  
279 - // $(this).combobox("setValues",checked);  
280 } 274 }
281 }); 275 });
282 276
@@ -507,6 +501,104 @@ @@ -507,6 +501,104 @@
507 501
508 502
509 503
  504 + // 定时 选择时间
  505 + function getTimeDialog(data,id, status){
  506 + var timeChoose = $("<div id='timeChoose'>").appendTo($(document.body));
  507 + var title = "选择时间";
  508 + var textVar = "确认";
  509 +
  510 + window.self.paramObject.mkData = data;
  511 + $(timeChoose).myDialog({
  512 + title: title,
  513 + width: "20%",
  514 + height: "20%",
  515 + resizable:false,
  516 + buttons:[{
  517 + id : "saveBtn",
  518 + text:textVar,
  519 + iconCls : "icon-save",
  520 + handler:function(){
  521 + debugger;
  522 + var time=''
  523 + if($("#publishTimeStr").datetimebox('getValue') !=null && $("#publishTimeStr").datetimebox('getValue') !=''){
  524 + time = parseInt(new Date($("#publishTimeStr").datetimebox('getValue')).getTime() );
  525 + }else {
  526 + $.messager.alert("发布失败", "请选择时间", "error");
  527 + return;
  528 + }
  529 + $("#publishArticleForm").form("submit",{
  530 + url : contextPath+"/grassArticle/timerPublish",
  531 + onSubmit : function(param) {
  532 + debugger;
  533 + if (!$("#publishArticleForm").form("validate")) {
  534 + return false;
  535 + }
  536 + param.publishTime =time;
  537 + var imgs = '';
  538 + var imageCount = 0;
  539 + $("input[name='url']").each(function(j,item){
  540 + debugger
  541 + var url = item.value;
  542 + if(imgs == ''){
  543 + imgs = url;
  544 + }else{
  545 + imgs = imgs + ","+url;
  546 + }
  547 + imageCount++;
  548 + });
  549 + $("#imgs").val(imgs);
  550 + if(imageCount > 9){
  551 + $.messager.alert("发布失败", "最多只能选择9张图片", "error");
  552 + return false;
  553 + }
  554 + if(imageCount < 1){
  555 + $.messager.alert("发布失败", "请选择至少一张图片", "error");
  556 + return false;
  557 + }
  558 + var labels = '';
  559 + $("input[name='labelId']").each(function(j,item){
  560 + debugger
  561 + var id = item.value;
  562 + if(labels == ''){
  563 + labels = id;
  564 + }else{
  565 + labels = labels + ","+id;
  566 + }
  567 + });
  568 + $("#labelIds").val(labels);
  569 + return true;
  570 + },
  571 + success : function(data) {
  572 + if (data) {
  573 + data = $.parseJSON(data);
  574 + if (data.code == 200) {
  575 + $.messager.alert("提示","发布成功", "info", function(){window.location.reload()});
  576 + // alert("保存成功");
  577 + } else {
  578 + $.messager.alert("保存失败", data.message, "error");
  579 + }
  580 + } else {
  581 + $.messager.alert("保存失败", data.message, "error");
  582 + }
  583 + }
  584 + });
  585 + $(timeChoose).dialog("close");
  586 + }
  587 + }, {
  588 + text: "关闭",
  589 + iconCls: "icon-cancel",
  590 + handler: function () {
  591 + $.messager.confirm("确认", "确认关闭吗?", function (flag) {
  592 + if(flag){
  593 + $(timeChoose).dialog("close");
  594 + }
  595 + });
  596 + }
  597 + }],
  598 + modal: true,
  599 + href: contextPath + "/html/grass/article/chooseTime.html"
  600 + });
  601 + }
510 602
511 // 编辑分组 603 // 编辑分组
512 function getEditDialog(data){ 604 function getEditDialog(data){