admin
2020-05-19 744594ef1a2f530fc3e86ea9dc48b62247f79420
fanli/src/main/java/com/yeshi/fanli/controller/admin/GoodsEvaluateAdminController.java
@@ -19,6 +19,7 @@
import com.google.gson.reflect.TypeToken;
import com.yeshi.fanli.dto.ConfigParamsDTO;
import com.yeshi.fanli.dto.pdd.PDDGoodsDetail;
import com.yeshi.fanli.entity.bus.user.vip.UserLevelEnum;
import com.yeshi.fanli.entity.dynamic.CommentInfo;
import com.yeshi.fanli.entity.dynamic.CommentInfo.CommentInfoEnum;
import com.yeshi.fanli.entity.dynamic.GoodsEvaluate;
@@ -34,6 +35,7 @@
import com.yeshi.fanli.service.inter.dynamic.GoodsEvaluateService;
import com.yeshi.fanli.service.inter.order.config.HongBaoManageService;
import com.yeshi.fanli.service.manger.ClipboardAnalysisManager;
import com.yeshi.fanli.service.manger.IClipboardAnalysisResult;
import com.yeshi.fanli.tag.PageEntity;
import com.yeshi.fanli.util.Constant;
import com.yeshi.fanli.util.RedisManager;
@@ -43,6 +45,8 @@
import com.yeshi.fanli.util.cache.PinDuoDuoCacheUtil;
import com.yeshi.fanli.util.factory.goods.GoodsDetailVOFactory;
import com.yeshi.fanli.vo.goods.GoodsDetailVO;
import com.yeshi.fanli.vo.msg.TokenVO;
import com.yeshi.fanli.vo.search.GoodsDocParseResultVO;
import net.sf.json.JSONObject;
@@ -74,6 +78,28 @@
   @Resource
   private HongBaoManageService hongBaoManageService;
   private CommonGoods commonGoods;
   /**
    * 修改状态
    * @param callback
    * @param id
    * @param out
    */
   @RequestMapping(value = "switchState")
   public void switchState(String callback, String id, PrintWriter out) {
      try {
         goodsEvaluateService.switchState(id);
         JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult("操作成功"));
      } catch (GoodsEvaluateException e) {
         JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult(e.getMsg()));
      } catch (Exception e) {
         JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("操作失败"));
         e.printStackTrace();
      }
   }
   /**
    * 保存信息
    * 
@@ -104,8 +130,7 @@
    * 保存信息
    * 
    * @param callback
    * @param special
    *            0a39676f138c4dcba722e321d43c4284
    * @param special  0a39676f138c4dcba722e321d43c4284
    * @param out
    */
   @RequestMapping(value = "saveSingleGoods")
@@ -116,7 +141,8 @@
         if (request instanceof MultipartHttpServletRequest) {
            fileRequest = (MultipartHttpServletRequest) request;
         }
         String commentText = goodsEvaluateService.saveSingleGoods(pid, goodsId, goodsType, videoUrl, picNum, picUrls, fileRequest);
         String commentText = goodsEvaluateService.saveSingleGoods(pid, goodsId, goodsType, videoUrl, picNum,
               picUrls, fileRequest);
         JSONObject object = new JSONObject();
         object.put("comment", commentText);
         JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult(object));
@@ -128,54 +154,12 @@
      }
   }
   /**
    * 保存信息
    *
    * @param callback
    * @param special
    *            0a39676f138c4dcba722e321d43c4284
    * @param out
    */
   @RequestMapping(value = "saveGoodsCoupon")
   public void saveGoodsCoupon(String callback, String pid, String content, PrintWriter out) {
      try {
         goodsEvaluateService.saveGoodsCoupon(pid, content);
         JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult("保存成功"));
      } catch (GoodsEvaluateException e) {
         JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult(e.getMsg()));
      } catch (Exception e) {
         JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("保存失败"));
         e.printStackTrace();
      }
   }
   /**
    * 保存信息
    *
    * @param callback
    * @param pid
    * @param kind : 1单品  2多品 3活动
    * @param out
    */
   @RequestMapping(value = "saveCurrencyCoupon")
   public void saveCurrencyCoupon(String callback, String pid, int kind, CommentInfo commentInfo, PrintWriter out) {
      try {
         goodsEvaluateService.saveCurrencyCoupon(pid, kind,commentInfo);
         JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult("保存成功"));
      } catch (GoodsEvaluateException e) {
         JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult(e.getMsg()));
      } catch (Exception e) {
         JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("保存失败"));
         e.printStackTrace();
      }
   }
   /**
    * 获取信息
    * 
    * @param callback
    * @param special
    *            0a39676f138c4dcba722e321d43c4284
    * @param special  0a39676f138c4dcba722e321d43c4284
    * @param out
    */
   @RequestMapping(value = "getSingleGoodsinfo")
@@ -222,95 +206,8 @@
         e.printStackTrace();
      }
   }
   /**
    * 获取信息
    *
    * @param callback
    * @param special
    *            0a39676f138c4dcba722e321d43c4284
    * @param out
    */
   @RequestMapping(value = "getCurrencyCoupon")
   public void getCurrencyCoupon(String callback, String pid, PrintWriter out) {
      try {
         CommentInfo commentInfo = new CommentInfo();
         if (!StringUtil.isNullOrEmpty(pid)) {
            GoodsEvaluate goodsEvaluate = goodsEvaluateService.getById(pid);
            if (goodsEvaluate != null && goodsEvaluate.getComments() != null
                  && goodsEvaluate.getComments().size() > 0) {
               for (CommentInfo info : goodsEvaluate.getComments()) {
                  if (info != null)
                     if (CommentInfoEnum.currencyCoupon == info.getTypeEnum()) {
                        commentInfo = info;
                     }
               }
            }
         }
         JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult(commentInfo));
      } catch (Exception e) {
         JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("查询失败"));
         e.printStackTrace();
      }
   }
   /**
    * 获取信息
    *
    * @param callback
    * @param special
    *            0a39676f138c4dcba722e321d43c4284
    * @param out
    */
   @RequestMapping(value = "getSingleGoodsCoupon")
   public void getSingleGoodsCoupon(String callback, String pid, PrintWriter out) {
      try {
         CommentInfo commentInfo = new CommentInfo();
         if (!StringUtil.isNullOrEmpty(pid)) {
            GoodsEvaluate goodsEvaluate = goodsEvaluateService.getById(pid);
            if (goodsEvaluate != null && goodsEvaluate.getComments() != null
                  && goodsEvaluate.getComments().size() > 0) {
               for (CommentInfo info : goodsEvaluate.getComments()) {
                  if (info != null)
                     if (CommentInfoEnum.goodsCoupon == info.getTypeEnum()) {
                        commentInfo = info;
                     }
               }
            }
         }
         JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult(commentInfo));
      } catch (Exception e) {
         JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("查询失败"));
         e.printStackTrace();
      }
   }
   /**
    * 保存多个商品
    *
    * @param out
    */
   @RequestMapping(value = "saveMultipleGoods")
   public void saveMultipleGoods(String callback, String pid, String videoUrl, String goodsList,
         HttpServletRequest request, PrintWriter out) {
      try {
         MultipartHttpServletRequest fileRequest = null;
         if (request instanceof MultipartHttpServletRequest) {
            fileRequest = (MultipartHttpServletRequest) request;
         }
         goodsEvaluateService.saveMultipleGoods(pid, videoUrl, goodsList, fileRequest);
         JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult("保存成功"));
      } catch (GoodsEvaluateException e) {
         JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult(e.getMsg()));
      } catch (Exception e) {
         JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("保存失败"));
         e.printStackTrace();
         LogHelper.errorDetailInfo(e);
         LogHelper.test(e);
      }
   }
   
   /**
    * 
    * @param callback
@@ -337,7 +234,7 @@
         e.printStackTrace();
      }
   }
   /**
    * 
    * @param callback
@@ -351,13 +248,13 @@
            JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("请先保存推荐语信息"));
            return;
         }
         List<CommentInfo> newList = new ArrayList<>();
         GoodsEvaluate goodsEvaluate = goodsEvaluateService.getById(id);
         if (goodsEvaluate != null) {
            List<CommentInfo> comments = goodsEvaluate.getComments();
            if (comments != null && comments.size() > 0) {
               for (CommentInfo commentInfo: comments) {
               for (CommentInfo commentInfo : comments) {
                  CommentInfoEnum typeEnum = commentInfo.getTypeEnum();
                  if (typeEnum == CommentInfoEnum.goodsCoupon) {
                     newList.add(commentInfo);
@@ -373,6 +270,90 @@
         e.printStackTrace();
      }
   }
   /**
    * 保存信息
    *
    * @param callback
    * @param pid
    * @param kind     : 1单品 2多品 3活动
    * @param out
    */
   @RequestMapping(value = "saveCurrencyCoupon")
   public void saveCurrencyCoupon(String callback, String pid, int kind, CommentInfo commentInfo, PrintWriter out) {
      try {
         goodsEvaluateService.saveCurrencyCoupon(pid, kind, commentInfo);
         JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult("保存成功"));
      } catch (GoodsEvaluateException e) {
         JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult(e.getMsg()));
      } catch (Exception e) {
         JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("保存失败"));
         e.printStackTrace();
      }
   }
   /**
    * 获取信息
    *
    * @param callback
    * @param special  0a39676f138c4dcba722e321d43c4284
    * @param out
    */
   @RequestMapping(value = "getCurrencyCoupon")
   public void getCurrencyCoupon(String callback, String pid, PrintWriter out) {
      try {
         CommentInfo commentInfo = new CommentInfo();
         if (!StringUtil.isNullOrEmpty(pid)) {
            GoodsEvaluate goodsEvaluate = goodsEvaluateService.getById(pid);
            if (goodsEvaluate != null && goodsEvaluate.getComments() != null
                  && goodsEvaluate.getComments().size() > 0) {
               for (CommentInfo info : goodsEvaluate.getComments()) {
                  if (info != null)
                     if (CommentInfoEnum.currencyCoupon == info.getTypeEnum()) {
                        commentInfo = info;
                     }
               }
            }
         }
         JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult(commentInfo));
      } catch (Exception e) {
         JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("查询失败"));
         e.printStackTrace();
      }
   }
   /**
    * 保存多个商品
    *
    * @param out
    */
   @RequestMapping(value = "saveMultipleGoods")
   public void saveMultipleGoods(String callback, String pid, String videoUrl, String goodsList,
         HttpServletRequest request, PrintWriter out) {
      try {
         MultipartHttpServletRequest fileRequest = null;
         if (request instanceof MultipartHttpServletRequest) {
            fileRequest = (MultipartHttpServletRequest) request;
         }
         goodsEvaluateService.saveMultipleGoods(pid, videoUrl, goodsList, fileRequest);
         JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult("保存成功"));
      } catch (GoodsEvaluateException e) {
         JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult(e.getMsg()));
      } catch (Exception e) {
         JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("保存失败"));
         e.printStackTrace();
         LogHelper.errorDetailInfo(e);
         LogHelper.test(e);
      }
   }
   
   /**
@@ -422,19 +403,18 @@
    * 保存信息
    * 
    * @param callback
    * @param special
    *            0a39676f138c4dcba722e321d43c4284
    * @param special  0a39676f138c4dcba722e321d43c4284
    * @param out
    */
   @RequestMapping(value = "saveActivityPic")
   public void saveActivityPic(String callback, String pid, ImgInfo imgInfo, HttpServletRequest request,
   public void saveActivityPic(String callback, String pid, ImgInfo imgInfo, String picUrls, HttpServletRequest request,
         PrintWriter out) {
      try {
         MultipartHttpServletRequest fileRequest = null;
         if (request instanceof MultipartHttpServletRequest) {
            fileRequest = (MultipartHttpServletRequest) request;
         }
         goodsEvaluateService.saveActivityPic(pid, imgInfo, fileRequest);
         goodsEvaluateService.saveActivityPic(pid, imgInfo,picUrls, fileRequest);
         JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult("保存成功"));
      } catch (GoodsEvaluateException e) {
         JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult(e.getMsg()));
@@ -448,8 +428,7 @@
    * 获取信息
    * 
    * @param callback
    * @param special
    *            0a39676f138c4dcba722e321d43c4284
    * @param special  0a39676f138c4dcba722e321d43c4284
    * @param out
    */
   @RequestMapping(value = "getActivityPic")
@@ -457,19 +436,23 @@
      try {
         String videoPic = "";
         String videoUrl = "";
         String activityPic = "";
         String activityUrl = "";
         List<String> list = new ArrayList<String>();
         GoodsEvaluate goodsEvaluate = goodsEvaluateService.getById(pid);
         if (goodsEvaluate != null && goodsEvaluate.getImgList() != null && goodsEvaluate.getImgList().size() > 0) {
            activityUrl = goodsEvaluate.getJumpLink();
            List<ImgInfo> imgList = goodsEvaluate.getImgList();
            for (ImgInfo imgInfo : imgList) {
               ImgEnum type = imgInfo.getType();
               if (type == ImgEnum.video) {
                  videoPic = imgInfo.getUrl();
                  videoUrl = imgInfo.getVideoUrl();
               } else if (type == ImgEnum.activity) {
                  activityPic = imgInfo.getUrl();
                  activityUrl = imgInfo.getActivityUrl();
               } else {
                  list.add(imgInfo.getUrl());
                  if (StringUtil.isNullOrEmpty(activityUrl) && !StringUtil.isNullOrEmpty(imgInfo.getActivityUrl())) {
                     activityUrl  = imgInfo.getActivityUrl();
                  }
               }
            }
         }
@@ -477,7 +460,7 @@
         JSONObject data = new JSONObject();
         data.put("videoUrl", videoUrl);
         data.put("videoPic", videoPic);
         data.put("activityPic", activityPic);
         data.put("listPic", list);
         data.put("activityUrl", activityUrl);
         JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult(data));
      } catch (Exception e) {
@@ -490,8 +473,7 @@
    * 保存信息
    * 
    * @param callback
    * @param special
    *            0a39676f138c4dcba722e321d43c4284
    * @param special  0a39676f138c4dcba722e321d43c4284
    * @param out
    */
   @RequestMapping(value = "saveSuCai")
@@ -518,8 +500,7 @@
    * 获取信息
    * 
    * @param callback
    * @param special
    *            0a39676f138c4dcba722e321d43c4284
    * @param special  0a39676f138c4dcba722e321d43c4284
    * @param out
    */
   @RequestMapping(value = "getSuCaiPic")
@@ -560,7 +541,6 @@
      }
   }
   /**
    * 保存信息
    * 
@@ -632,8 +612,7 @@
    * @param out
    */
   @RequestMapping(value = "query")
   public void query(String callback, Integer pageIndex, Integer pageSize, String key, Integer state,
         PrintWriter out) {
   public void query(String callback, Integer pageIndex, Integer pageSize, String key, Integer state, String typeEnum, PrintWriter out) {
      if (pageIndex == null || pageIndex < 1) {
         pageIndex = 1;
      }
@@ -642,7 +621,7 @@
      }
      try {
         List<GoodsEvaluate> list = goodsEvaluateService.query((pageIndex - 1) * pageSize, pageSize, key, state, 1);
         List<GoodsEvaluate> list = goodsEvaluateService.query((pageIndex - 1) * pageSize, pageSize, key, state, 1, typeEnum);
         if (list == null || list.size() == 0) {
            JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("暂无数据"));
            return;
@@ -664,7 +643,7 @@
            }
         }
         long count = goodsEvaluateService.count(key, state, 1);
         long count = goodsEvaluateService.count(key, state, 1, typeEnum);
         int totalPage = (int) (count % pageSize == 0 ? count / pageSize : count / pageSize + 1);
         PageEntity pe = new PageEntity(pageIndex, pageSize, count, totalPage);
@@ -699,7 +678,7 @@
      }
      try {
         List<GoodsEvaluate> list = goodsEvaluateService.query((pageIndex - 1) * pageSize, pageSize, key, state, 2);
         List<GoodsEvaluate> list = goodsEvaluateService.query((pageIndex - 1) * pageSize, pageSize, key, state, 2, null);
         if (list == null || list.size() == 0) {
            JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("暂无数据"));
            return;
@@ -721,7 +700,7 @@
            }
         }
         long count = goodsEvaluateService.count(key, state, 2);
         long count = goodsEvaluateService.count(key, state, 2, null);
         int totalPage = (int) (count % pageSize == 0 ? count / pageSize : count / pageSize + 1);
         PageEntity pe = new PageEntity(pageIndex, pageSize, count, totalPage);
@@ -746,7 +725,11 @@
   @RequestMapping(value = "getGoodsByUrl")
   public void getGoodsByUrl(String callback, String link, PrintWriter out) {
      try {
         CommonGoods commonGoods = clipboardAnalysisManager.parseLink(link);
         //CommonGoods commonGoods = clipboardAnalysisManager.parseLink(link);
         // 根据口令链接获取商品
          getGoods(link);
          CommonGoods commonGoods = getCommonGoods();
         if (commonGoods == null) {
            JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("未找到该商品"));
            return;
@@ -754,7 +737,7 @@
         GoodsDetailVO goodsDetail = null;
         BigDecimal fanLiRate = hongBaoManageService.getFanLiRate();
         BigDecimal shareRate = hongBaoManageService.getShareRate();
         BigDecimal vipFanLiRate = hongBaoManageService.getVIPFanLiRate();
         BigDecimal vipFanLiRate = hongBaoManageService.getFanLiRate(UserLevelEnum.superVIP);
         ConfigParamsDTO params = new ConfigParamsDTO(fanLiRate, shareRate, Constant.MAX_REWARD_RATE, vipFanLiRate);
         if (commonGoods.getGoodsType() == Constant.SOURCE_TYPE_TAOBAO) {
@@ -763,17 +746,17 @@
               String pictUrlWhite = goodsBrief.getPictUrlWhite();
               if (!StringUtil.isNullOrEmpty(pictUrlWhite)) {
                  goodsBrief.setPictUrl(pictUrlWhite);
                  List<String> picList = new ArrayList<>();
                  picList.add(pictUrlWhite);
                  List<String> imgList = goodsBrief.getImgList();
                  if (imgList != null) {
                     picList.addAll(imgList);
                  }
                  goodsBrief.setImgList(picList);
               }
               goodsDetail = GoodsDetailVOFactory.convertTaoBao(goodsBrief, params);
            } catch (TaobaoGoodsDownException e) {
               JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("该商品已下架"));
@@ -801,7 +784,37 @@
      } catch (Exception e) {
         JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("获取失败"));
         e.printStackTrace();
      } finally {
         setCommonGoods(null);
      }
   }
   private void getGoods(String text) {
      Long uid = Constant.LINK_TOKEN_VERIFY_UID;
      clipboardAnalysisManager.parse("android", "55", text, uid, new IClipboardAnalysisResult() {
         @Override
         public void onResult(GoodsDocParseResultVO result) {}
         @Override
         public void onResult(String result) {}
         @Override
         public void onResult(CommonGoods goods) {
            setCommonGoods(goods);
         }
         @Override
         public void onResult(TokenVO tokenVO) {
         }
         @Override
         public void none() {
         }
         @Override
         public void needLogin(String msg) {
         }
      });
   }
   /**
@@ -920,4 +933,14 @@
      }
   }
   public CommonGoods getCommonGoods() {
      return commonGoods;
   }
   public void setCommonGoods(CommonGoods commonGoods) {
      this.commonGoods = commonGoods;
   }
}