Kaynağa Gözat

更新文件 articleTweetAction.java

陈士柏 2 yıl önce
ebeveyn
işleme
268912d610
1 değiştirilmiş dosya ile 405 ekleme ve 15 silme
  1. 405 15
      mhotel/src/com/happy/action/articleTweetAction.java

+ 405 - 15
mhotel/src/com/happy/action/articleTweetAction.java

@@ -50,27 +50,23 @@ public class articleTweetAction extends BaseController implements ModelDriven<Ar
 
     @Resource
     public ArticleTweetService articleTweetService;
-
     @Resource
     public HousePriceService housePriceService;
-
     @Resource
     public HotelDictService hotelDictService;
-
     @Resource
     public WorkflowService workflowService;
-
     @Resource
     public HouseService houseService;
-
     @Resource
     public UserService userService;
+    @Resource
+    public AdminManagerService adminManagerService;
 
     public String key;
-
     public String startTime;
-
     public String endTime;
+    public String keyWord;
 
     public String getKey() {
         return key;
@@ -96,6 +92,14 @@ public class articleTweetAction extends BaseController implements ModelDriven<Ar
         this.endTime = endTime;
     }
 
+    public String getKeyWord() {
+        return keyWord;
+    }
+
+    public void setKeyWord(String keyWord) {
+        this.keyWord = keyWord;
+    }
+
     /**
      * 推文发布
      */
@@ -105,7 +109,6 @@ public class articleTweetAction extends BaseController implements ModelDriven<Ar
         com.alibaba.fastjson.JSONObject json = GetHttpParam.getHttpParam(request);
         ArticleTweetDto articleTweetDto = gson.fromJson(json.toString(), new TypeToken<ArticleTweetDto>() {
         }.getType());
-
         //图片和视频判断
         if (articleTweetDto.getImages() == null && articleTweetDto.getVideo() == null) {
             jsonObject.put("code", 500);
@@ -132,10 +135,8 @@ public class articleTweetAction extends BaseController implements ModelDriven<Ar
             ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
             return null;
         }
-
         //推文发布参数
         System.out.println("推文发布参数:" + JSON.toJSON(articleTweetDto));
-
         //查询当前用户
         Users user = userService.queryByUserId(String.valueOf(articleTweetDto.getCreateId()));
         if (user == null) {
@@ -145,7 +146,6 @@ public class articleTweetAction extends BaseController implements ModelDriven<Ar
             ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
             return null;
         }
-
         Date now = DateUtil.formateDate(DateUtil.getCurrentDate(), DateUtil.Time_Formatter_Second);
         try {
             //添加推文
@@ -159,6 +159,8 @@ public class articleTweetAction extends BaseController implements ModelDriven<Ar
             data.setCreateDate(now);
             data.setApprove(1);//正在审批
             data.setStatus(1);
+            data.setPublishWay("小程序");
+            data.setIsTop(0);
             data.setUserName(user.getUser_name());
             data.setUserPhoto(user.getHeadPhoto() == null ? ConstDefault.DefaultHeadPhoto : user.getHeadPhoto());
             int aId = articleTweetService.insert(data);
@@ -170,7 +172,6 @@ public class articleTweetAction extends BaseController implements ModelDriven<Ar
 
                 return null;
             }
-
             //添加附件
             List<String> fileStr = new ArrayList<>();
             if (articleTweetDto.getImages() != null && articleTweetDto.getImages().size() > 0) {
@@ -178,7 +179,6 @@ public class articleTweetAction extends BaseController implements ModelDriven<Ar
             } else {
                 fileStr.add(articleTweetDto.getVideo());
             }
-
             List<ArticleFileInfo> afis = new ArrayList<>();
             for (String f : fileStr) {
                 String[] split = f.split("/");
@@ -199,7 +199,6 @@ public class articleTweetAction extends BaseController implements ModelDriven<Ar
                 }}.toString());
                 return null;
             }
-
             //添加流程
             Workflow workflow = new Workflow();
             String id = String.valueOf(UUID.randomUUID());
@@ -227,8 +226,249 @@ public class articleTweetAction extends BaseController implements ModelDriven<Ar
             }}.toString());
             return null;
         }
+        ResUtil.writeJson(ServletActionContext.getResponse(), new JSONObject() {{
+            put("message", "推文发布成功");
+            put("code", 200);
+        }}.toString());
+        return null;
+    }
+
+    /**
+     * 管理端推文发布
+     */
+    public String insertArticleTweetMana() throws ParseException {
+        Gson gson = new Gson();
+        JSONObject jsonObject = new JSONObject();
+        com.alibaba.fastjson.JSONObject json = GetHttpParam.getHttpParam(request);
+        ArticleTweetDto articleTweetDto = gson.fromJson(json.toString(), new TypeToken<ArticleTweetDto>() {
+        }.getType());
+        //图片和视频判断
+        if (articleTweetDto.getImages() == null && articleTweetDto.getVideo() == null) {
+            jsonObject.put("code", 500);
+            jsonObject.put("message", "请上传图片或视频");
+            jsonObject.put("data", null);
+            ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
+            return null;
+        }
+        //图片最多上传九张
+        if (articleTweetDto.getImages() != null && articleTweetDto.getImages().size() > 9) {
+            jsonObject.put("code", 500);
+            jsonObject.put("message", "最多上传9张图片");
+            jsonObject.put("data", null);
+            ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
+            return null;
+        }
+        //标题、内容、地点、关联民宿不能为空
+        if (Func.checkNull(articleTweetDto.getTitle()) || Func.checkNull(articleTweetDto.getContent())
+                || Func.checkNull(articleTweetDto.getTownId()) || articleTweetDto.getHotelIds() == null
+                || articleTweetDto.getCreateId() == null) {
+            jsonObject.put("code", 500);
+            jsonObject.put("message", "参数不能为空");
+            jsonObject.put("data", null);
+            ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
+            return null;
+        }
+        //推文发布参数
+        System.out.println("推文发布参数:" + JSON.toJSON(articleTweetDto));
+
+        //查询当前用户
+        AdminManager adminManager = adminManagerService.getById(articleTweetDto.getCreateId());
+        if (adminManager == null) {
+            jsonObject.put("code", 500);
+            jsonObject.put("message", "用户信息已失效,查看详情失败");
+            jsonObject.put("data", null);
+            ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
+            return null;
+        }
+        List<ArticleTweet> articleTweets = articleTweetService.queryTops();
+        if (articleTweets!=null && articleTweets.size()>=3 && articleTweetDto.getIsTop()==1){
+            jsonObject.put("code", 500);
+            jsonObject.put("message", "置顶攻略不可超过3个");
+            jsonObject.put("data", null);
+            ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
+            return null;
+        }
+        Date now = DateUtil.formateDate(DateUtil.getCurrentDate(), DateUtil.Time_Formatter_Second);
+        try {
+            //添加推文
+            ArticleTweet data = new ArticleTweet();
+            data.setUserId(articleTweetDto.getCreateId());
+            data.setTitle(articleTweetDto.getTitle());
+            data.setContent(articleTweetDto.getContent());
+            data.setLocationId(articleTweetDto.getTownId());
+            data.setHotelId(StringUtils.join(articleTweetDto.getHotelIds(), ","));
+            data.setCreateId(articleTweetDto.getCreateId());
+            data.setCreateDate(now);
+            data.setApprove(2);//正在审批
+            data.setStatus(1);
+            data.setPublishWay("管理端");
+            data.setIsTop(articleTweetDto.getIsTop());
+            data.setUserName(adminManager.getAdminName());
+            data.setUserPhoto(ConstDefault.DefaultHeadPhoto);
+            int aId = articleTweetService.insert(data);
+            if (aId <= 0) {
+                ResUtil.writeJson(ServletActionContext.getResponse(), new JSONObject() {{
+                    put("message", "推文发布失败");
+                    put("code", 500);
+                }}.toString());
+
+                return null;
+            }
+            //添加附件
+            List<String> fileStr = new ArrayList<>();
+            if (articleTweetDto.getImages() != null && articleTweetDto.getImages().size() > 0) {
+                fileStr = articleTweetDto.getImages();
+            } else {
+                fileStr.add(articleTweetDto.getVideo());
+            }
+            List<ArticleFileInfo> afis = new ArrayList<>();
+            for (String f : fileStr) {
+                String[] split = f.split("/");
+                String fileName = split[split.length - 1];
+                ArticleFileInfo afi = new ArticleFileInfo();
+                afi.setLinkId(aId);
+                afi.setName(fileName);
+                afi.setType(1);
+                afi.setUrl(f);
+                afi.setCreateDate(now);
+                afis.add(afi);
+            }
+            int length = articleTweetService.insertArticleFileBatch(afis);
+            if (length <= 0) {
+                ResUtil.writeJson(ServletActionContext.getResponse(), new JSONObject() {{
+                    put("message", "推文附件新增失败");
+                    put("code", 500);
+                }}.toString());
+                return null;
+            }
+            //添加流程
+            Workflow workflow = new Workflow();
+            String id = String.valueOf(UUID.randomUUID());
+            workflow.setLinkId(String.valueOf(aId));//存推文的ID
+            workflow.setCreateId(String.valueOf(articleTweetDto.getCreateId()));
+            workflow.setTitle(articleTweetDto.getTitle());
+            workflow.setRemark(articleTweetDto.getContent());
+            workflow.setId(id);
+            workflow.setStatus(2);//1是正在审批
+            workflow.setType(3);//3是推文
+            workflow.setCoverImg(articleTweetDto.getImages() != null && articleTweetDto.getImages().size() > 0 ? articleTweetDto.getImages().get(0) : articleTweetDto.getVideo());
+            int i = workflowService.insert(workflow);
+            if (i <= 0) {
+                ResUtil.writeJson(ServletActionContext.getResponse(), new JSONObject() {{
+                    put("message", "推文流程发布失败");
+                    put("code", 500);
+                }}.toString());
+                return null;
+            }
+        } catch (Exception e) {
+            System.out.println("推文发布异常:" + e.getMessage());
+            ResUtil.writeJson(ServletActionContext.getResponse(), new JSONObject() {{
+                put("message", "推文发布异常");
+                put("code", 500);
+            }}.toString());
+            return null;
+        }
+        ResUtil.writeJson(ServletActionContext.getResponse(), new JSONObject() {{
+            put("message", "推文发布成功");
+            put("code", 200);
+        }}.toString());
+
+        return null;
+    }
+
+    /**
+     * 管理端修改推文
+     */
+    public String updateArticleTweetMana() throws ParseException {
+        Gson gson = new Gson();
+        JSONObject jsonObject = new JSONObject();
+        com.alibaba.fastjson.JSONObject json = GetHttpParam.getHttpParam(request);
+        ArticleTweetDto articleTweetDto = gson.fromJson(json.toString(), new TypeToken<ArticleTweetDto>() {
+        }.getType());
+        //图片和视频判断
+        if (articleTweetDto.getImages() == null && articleTweetDto.getVideo() == null) {
+            jsonObject.put("code", 500);
+            jsonObject.put("message", "请上传图片或视频");
+            jsonObject.put("data", null);
+            ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
+            return null;
+        }
+        //图片最多上传九张
+        if (articleTweetDto.getImages() != null && articleTweetDto.getImages().size() > 9) {
+            jsonObject.put("code", 500);
+            jsonObject.put("message", "最多上传9张图片");
+            jsonObject.put("data", null);
+            ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
+            return null;
+        }
+        //标题、内容、地点、关联民宿不能为空
+        if (Func.checkNull(articleTweetDto.getTitle()) || Func.checkNull(articleTweetDto.getContent())
+                || Func.checkNull(articleTweetDto.getTownId()) || articleTweetDto.getHotelIds() == null
+                || articleTweetDto.getCreateId() == null || articleTweetDto.getId()==null) {
+            jsonObject.put("code", 500);
+            jsonObject.put("message", "参数不能为空");
+            jsonObject.put("data", null);
+            ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
+            return null;
+        }
+        //推文发布参数
+        System.out.println("推文发布参数:" + JSON.toJSON(articleTweetDto));
 
+        //查询当前用户
+        AdminManager adminManager = adminManagerService.getById(articleTweetDto.getCreateId());
+        if (adminManager == null) {
+            jsonObject.put("code", 500);
+            jsonObject.put("message", "用户信息已失效,查看详情失败");
+            jsonObject.put("data", null);
+            ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
+            return null;
+        }
+        List<ArticleTweet> articleTweets = articleTweetService.queryTops();
+        if (articleTweets!=null && articleTweets.size()>=3 && articleTweetDto.getIsTop()==1){
+            List<Integer> ids = articleTweets.stream().map(ArticleTweet::getId).collect(Collectors.toList());
+            if (!ids.contains(articleTweetDto.getId())){
+                jsonObject.put("code", 500);
+                jsonObject.put("message", "置顶攻略不可超过3个");
+                jsonObject.put("data", null);
+                ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
+                return null;
+            }
+        }
+        Date now = DateUtil.formateDate(DateUtil.getCurrentDate(), DateUtil.Time_Formatter_Second);
+        try {
+            //添加推文
+            ArticleTweet data = new ArticleTweet();
+            data.setId(articleTweetDto.getId());
+            data.setUserId(articleTweetDto.getCreateId());
+            data.setTitle(articleTweetDto.getTitle());
+            data.setContent(articleTweetDto.getContent());
+            data.setLocationId(articleTweetDto.getTownId());
+            data.setHotelId(StringUtils.join(articleTweetDto.getHotelIds(), ","));
+            data.setCreateId(articleTweetDto.getCreateId());
+            data.setCreateDate(now);
+            data.setApprove(2);//1正在审批
+            data.setStatus(1);
+            data.setPublishWay("管理端");
+            data.setIsTop(articleTweetDto.getIsTop());
+            data.setUserName(adminManager.getAdminName());
+            data.setUserPhoto(ConstDefault.DefaultHeadPhoto);
+            int aId = articleTweetService.update(data);
+            if (aId <= 0) {
+                ResUtil.writeJson(ServletActionContext.getResponse(), new JSONObject() {{
+                    put("message", "推文发布失败");
+                    put("code", 500);
+                }}.toString());
 
+                return null;
+            }
+        } catch (Exception e) {
+            System.out.println("推文发布异常:" + e.getMessage());
+            ResUtil.writeJson(ServletActionContext.getResponse(), new JSONObject() {{
+                put("message", "推文发布异常");
+                put("code", 500);
+            }}.toString());
+            return null;
+        }
         ResUtil.writeJson(ServletActionContext.getResponse(), new JSONObject() {{
             put("message", "推文发布成功");
             put("code", 200);
@@ -237,6 +477,157 @@ public class articleTweetAction extends BaseController implements ModelDriven<Ar
         return null;
     }
 
+    // 操作推文-删除文件
+    public String delFile(){
+        JSONObject jsonObject = new JSONObject();
+        com.alibaba.fastjson.JSONObject json = GetHttpParam.getHttpParam(request);
+        Integer id = json.getInteger("id");
+        int m = articleTweetService.delArticleFileBatch(id);
+        if (m>0){
+            jsonObject.put("code", 200);
+            jsonObject.put("message", "删除成功");
+            ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
+            return null;
+        }
+        jsonObject.put("code", 500);
+        jsonObject.put("message", "删除失败");
+        ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
+        return null;
+    }
+
+    // 操作推文-增加文件
+    public String addFile() throws ParseException {
+        JSONObject jsonObject = new JSONObject();
+        com.alibaba.fastjson.JSONObject json = GetHttpParam.getHttpParam(request);
+        Integer id = json.getInteger("id");
+        String images = json.getString("images");
+        String video = json.getString("video");
+        //图片和视频判断
+        if (images.equals("") && video.equals("")) {
+            jsonObject.put("code", 500);
+            jsonObject.put("message", "请上传图片或视频");
+            jsonObject.put("data", null);
+            ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
+            return null;
+        }
+        String fileStr = "";
+        if (!images.equals("")) {
+            fileStr=images;
+        } else {
+            fileStr=video;
+        }
+
+        Date now = DateUtil.formateDate(DateUtil.getCurrentDate(), DateUtil.Time_Formatter_Second);
+        String[] split = fileStr.split("/");
+        String fileName = split[split.length - 1];
+        ArticleFileInfo afi = new ArticleFileInfo();
+        afi.setLinkId(id);
+        afi.setName(fileName);
+        afi.setType(1);
+        afi.setUrl(fileStr);
+        afi.setCreateDate(now);
+        int length = articleTweetService.insertArticleFile(afi);
+        if (length <= 0) {
+            ResUtil.writeJson(ServletActionContext.getResponse(), new JSONObject() {{
+                put("message", "新增失败");
+                put("code", 500);
+                put("data", null);
+            }}.toString());
+            return null;
+        }
+        ResUtil.writeJson(ServletActionContext.getResponse(), new JSONObject() {{
+            put("message", "新增成功");
+            put("code", 200);
+            put("data", length);
+        }}.toString());
+        return null;
+    }
+
+    // 删除推文
+    public String delArticle(){
+        JSONObject jsonObject = new JSONObject();
+        com.alibaba.fastjson.JSONObject json = GetHttpParam.getHttpParam(request);
+        Integer id = json.getInteger("id");
+        int m = articleTweetService.delArticle(id);
+        int n = articleTweetService.delArticleFile(id);
+        if (m>0 && n>0){
+            jsonObject.put("code", 200);
+            jsonObject.put("message", "删除成功");
+            ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
+            return null;
+        }
+        jsonObject.put("code", 500);
+        jsonObject.put("message", "删除失败");
+        ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
+        return null;
+    }
+
+    // 置顶推文
+    public String topArticle(){
+        Gson gson = new Gson();
+        JSONObject jsonObject = new JSONObject();
+        com.alibaba.fastjson.JSONObject json = GetHttpParam.getHttpParam(request);
+        ArticleTweetDto articleTweetDto = gson.fromJson(json.toString(), new TypeToken<ArticleTweetDto>() {}.getType());
+        List<ArticleTweet> articleTweets = articleTweetService.queryTops();
+        if (articleTweets!=null && articleTweets.size()>=3 && articleTweetDto.getIsTop()==1){
+            List<Integer> ids = articleTweets.stream().map(ArticleTweet::getId).collect(Collectors.toList());
+            if (!ids.contains(articleTweetDto.getId())){
+                jsonObject.put("code", 500);
+                jsonObject.put("message", "置顶攻略不可超过3个");
+                jsonObject.put("data", null);
+                ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
+                return null;
+            }
+        }
+        int m = articleTweetService.updateArticleTop(articleTweetDto);
+        if (m>0){
+            jsonObject.put("code", 200);
+            jsonObject.put("message", "修改成功");
+            jsonObject.put("data", null);
+            ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
+            return null;
+        }
+        jsonObject.put("code", 500);
+        jsonObject.put("message", "修改失败");
+        jsonObject.put("data", null);
+        ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
+        return null;
+    }
+
+    public String queryManageArticlePage() {
+        JSONObject jsonObject = new JSONObject();
+        IPage<ArticleListVo> result = articleTweetService.queryManageArticlesPage(keyWord, null, page, rows);
+        if (result.getPageList().size() > 0) {
+            String articleIds = StringUtils.join(result.getPageList().stream().map(ArticleListVo::getId).collect(Collectors.toList()), ",");
+            List<FileInfo> fileInfos = articleTweetService.queryList("and link_id in (" + articleIds + ")");
+
+            for (ArticleListVo data : result.getPageList()) {
+                if (fileInfos != null) {
+                    List<FileInfo> fileInfoList = fileInfos.stream().filter(e -> e.getLinkId().equals(data.getId().toString())).collect(Collectors.toList());
+                    if (fileInfoList != null) {
+                        if (fileInfoList.size() > 1) {
+                            data.setImage(fileInfoList.get(0).getUrl());
+                        } else if (fileInfoList.size() == 1) {
+                            String url = fileInfoList.get(0).getUrl();
+                            if (!url.endsWith("jpg") && !url.endsWith("png")) {
+                                data.setVideo(fileInfoList.get(0).getUrl());
+                            } else {
+                                data.setImage(url);
+                            }
+                        }
+                    }
+                }
+            }
+        }
+
+        jsonObject.put("code", ResultStatusCode.OK.getStatus());
+        jsonObject.put("message", "请求成功");
+        jsonObject.put("data", result);
+        ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
+
+        return null;
+    }
+
 
     /**
      * 根据推文数据ID查询推文详情数据
@@ -682,7 +1073,6 @@ public class articleTweetAction extends BaseController implements ModelDriven<Ar
         jsonObject.put("message", "请求成功");
         jsonObject.put("data", result);
         ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
-
         return null;
     }