admin
2020-05-19 744594ef1a2f530fc3e86ea9dc48b62247f79420
fanli/src/main/java/com/yeshi/fanli/controller/client/v2/IntegralControllerV2.java
@@ -35,29 +35,33 @@
import com.yeshi.fanli.entity.common.JumpDetailV2;
import com.yeshi.fanli.entity.integral.CodePublishRecord;
import com.yeshi.fanli.entity.integral.IntegralExchange;
import com.yeshi.fanli.entity.integral.IntegralExchange.ExchangeTypeEnum;
import com.yeshi.fanli.entity.integral.IntegralTask;
import com.yeshi.fanli.entity.integral.IntegralTask.TaskUniqueKeyEnum;
import com.yeshi.fanli.entity.integral.IntegralTaskClass.UniqueKeyEnum;
import com.yeshi.fanli.entity.integral.IntegralTaskRecord;
import com.yeshi.fanli.entity.system.ConfigKeyEnum;
import com.yeshi.fanli.exception.integral.IntegralExchangeException;
import com.yeshi.fanli.exception.integral.IntegralTaskRecordException;
import com.yeshi.fanli.log.LogHelper;
import com.yeshi.fanli.service.inter.common.JumpDetailV2Service;
import com.yeshi.fanli.service.inter.config.ConfigService;
import com.yeshi.fanli.service.inter.integral.CodePublishRecordService;
import com.yeshi.fanli.service.inter.integral.IntegralDetailService;
import com.yeshi.fanli.service.inter.integral.IntegralExchangeRecordService;
import com.yeshi.fanli.service.inter.integral.IntegralExchangeService;
import com.yeshi.fanli.service.inter.integral.IntegralGetService;
import com.yeshi.fanli.service.inter.integral.IntegralTaskClassService;
import com.yeshi.fanli.service.inter.integral.IntegralTaskRankService;
import com.yeshi.fanli.service.inter.integral.IntegralTaskRecordService;
import com.yeshi.fanli.service.inter.integral.IntegralTaskService;
import com.yeshi.fanli.service.inter.user.UserInfoExtraService;
import com.yeshi.fanli.service.inter.user.UserInfoService;
import com.yeshi.fanli.service.inter.user.integral.CodePublishRecordService;
import com.yeshi.fanli.service.inter.user.integral.IntegralDetailService;
import com.yeshi.fanli.service.inter.user.integral.IntegralExchangeRecordService;
import com.yeshi.fanli.service.inter.user.integral.IntegralExchangeService;
import com.yeshi.fanli.service.inter.user.integral.IntegralGetService;
import com.yeshi.fanli.service.inter.user.integral.IntegralTaskClassService;
import com.yeshi.fanli.service.inter.user.integral.IntegralTaskRankService;
import com.yeshi.fanli.service.inter.user.integral.IntegralTaskRecordService;
import com.yeshi.fanli.service.inter.user.integral.IntegralTaskService;
import com.yeshi.fanli.util.Constant;
import com.yeshi.fanli.util.StringUtil;
import com.yeshi.fanli.util.TimeUtil;
import com.yeshi.fanli.util.VersionUtil;
import com.yeshi.fanli.util.annotation.RequestSerializableByKey;
import com.yeshi.fanli.vo.integral.DailySignVO;
import com.yeshi.fanli.vo.integral.ExchangeTipVO;
import com.yeshi.fanli.vo.integral.IntegralDetailVO;
@@ -183,10 +187,11 @@
            data.put("userRank", gson.toJson(userRank));
            data.put("dailySign", dailySignVO);
         }
         for (int i = 0; i < list.size(); i++) {
            IntegralTaskClassVO taskClassVO = list.get(i);
         for (IntegralTaskClassVO taskClassVO : list) {
            UniqueKeyEnum uniqueKey = taskClassVO.getUniqueKey();
            // 邀请好友:是否激活邀请码
            if (uniqueKey == UniqueKeyEnum.inviteTeam) {
               UserInfoExtraVO extraVO = userInfoExtraService.getInfoExtraVOByUid(uid);
@@ -233,19 +238,27 @@
               taskClassVO.setLightUp(true);
            }
            // 查询当日
            Integer dateType = 1;
            if (uniqueKey == UniqueKeyEnum.orderReward || uniqueKey == UniqueKeyEnum.accountMaintain)
               dateType = null; // 查询历史
            Long id = taskClassVO.getId();
            int countFinished = 0;
            Integer totalGoldCoin = integralTaskRecordService.getTotalGoldCoin(uid, id, dateType);
            Long id = taskClassVO.getId();
            // 查询当日
            Integer totalGoldCoin = integralTaskRecordService.getTotalGoldCoin(uid, id, 1);
            if (totalGoldCoin != null && totalGoldCoin > 0) {
               taskClassVO.setFinishedCoin("+" + totalGoldCoin);
               if (uniqueKey != UniqueKeyEnum.dailySign)
                  countFinished = integralTaskRecordService.countFinished(uid, id, dateType);
               if (uniqueKey != UniqueKeyEnum.dailySign && uniqueKey != UniqueKeyEnum.accountMaintain) {
                  countFinished = integralTaskRecordService.countFinished(uid, id, 1);
               }
            }
            if (uniqueKey == UniqueKeyEnum.accountMaintain) {
               countFinished = integralTaskRecordService.countFinished(uid, id, null); // 查询历史
            }
            /*
             * // 完善信息完成后,列表中消失 if (uniqueKey ==
             * UniqueKeyEnum.accountMaintain && taskNum == countFinished) {
             * list.remove(i); i --; continue; }
             */
            progress = progress.replace("{已完成}", countFinished + "").replace("{总任务}", taskNum + "");
            if (signState == 0 && uniqueKey == UniqueKeyEnum.dailySign) {
@@ -277,10 +290,7 @@
         return;
      }
      int count = 5;
      if ("android".equalsIgnoreCase(acceptData.getPlatform())) {
         count = Integer.MAX_VALUE;
      }
      int count = Integer.MAX_VALUE;
      List<IntegralTaskRecord> list = integralTaskRecordService.listNotReceived(count, uid);
      if (list == null) {
@@ -306,6 +316,7 @@
    *            // 未领取id
    * @param out
    */
   @RequestSerializableByKey(key = "'receiveGoldCoin-'+#uid")
   @RequestMapping(value = "receiveGoldCoin", method = RequestMethod.POST)
   public void receiveGoldCoin(AcceptData acceptData, Long uid, Integer type, String ids, String gids,
         PrintWriter out) {
@@ -333,24 +344,8 @@
            return;
         }
         Integer goldCoin = integralTaskRecordService.receiveGoldCoin(uid, idList);
         Set<Long> gidList = gson.fromJson(gids, new TypeToken<HashSet<Long>>() {
         }.getType());
         List<IntegralTaskRecord> list = null;
         if (gidList != null && gidList.size() > 0) {
            list = integralTaskRecordService.listNotReceivedExcludeId(5 - gidList.size(), uid, gidList);
         } else {
            list = integralTaskRecordService.listNotReceivedExcludeId(5, uid, null);
         }
         if (list == null) {
            list = new ArrayList<IntegralTaskRecord>();
         }
         GsonBuilder gsonBuilder = new GsonBuilder().excludeFieldsWithoutExposeAnnotation();
         Gson gson2 = gsonBuilder.create();
         JSONObject data = new JSONObject();
         data.put("goldCoin", goldCoin);
         data.put("list", gson2.toJson(list));
         out.print(JsonUtil.loadTrueResult(data));
      } catch (IntegralTaskRecordException e) {
         out.print(JsonUtil.loadFalseResult(e.getMsg()));
@@ -385,8 +380,22 @@
      List<IntegralExchange> list = integralExchangeRecordService.listExchange((page - 1) * Constant.PAGE_SIZE,
            Constant.PAGE_SIZE, uid);
      if (list == null)
         list = new ArrayList<IntegralExchange>();
      List<IntegralExchange> listNew = new ArrayList<>();
      if (list != null)
         listNew.addAll(list);
      if (VersionUtil.greaterThan_2_0_7(acceptData.getPlatform(), acceptData.getVersion())) {
         for (int i=0; i < listNew.size(); i ++) {
            IntegralExchange integralExchange = listNew.get(i);
            ExchangeTypeEnum type = integralExchange.getType();
            if (type != null &&
                  (type == ExchangeTypeEnum.inviteCodeActivate || type == ExchangeTypeEnum.inviteCodePublish)) {
               listNew.remove(i);
               i--;
            }
         }
      }
      // Long count = integralExchangeService.countValid();
@@ -395,9 +404,31 @@
      JSONObject data = new JSONObject();
      data.put("goldCoin", extraVO.getGoldCoin() + "枚");
      data.put("count", list.size());
      data.put("list", gson.toJson(list));
      data.put("count", listNew.size());
      data.put("list", gson.toJson(listNew));
      out.print(JsonUtil.loadTrueResult(data));
   }
   @RequestMapping(value = "getExchangeDetail")
   public void getExchangeDetail(AcceptData acceptData, Long id, String callback, PrintWriter out) {
      if (id == null || id <= 0) {
         out.print(JsonUtil.loadFalseResult(1, "兑换ID有误"));
         return;
      }
      IntegralExchange exchange = integralExchangeService.selectByPrimaryKey(id);
      if (exchange != null) {
         GsonBuilder gsonBuilder = new GsonBuilder().excludeFieldsWithoutExposeAnnotation();
         Gson gson = gsonBuilder.create();
         if (StringUtil.isNullOrEmpty(callback))
            out.print(JsonUtil.loadTrueResult(gson.toJson(exchange)));
         else
            out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadTrueResult(gson.toJson(exchange))));
      } else {
         if (StringUtil.isNullOrEmpty(callback))
            out.print(JsonUtil.loadFalseResult("未找到"));
         else
            out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult("未找到")));
      }
   }
   /**
@@ -408,8 +439,8 @@
    * @param id
    * @param out
    */
   @RequestMapping(value = "verifyExchange", method = RequestMethod.POST)
   public void verifyExchange(AcceptData acceptData, Long uid, Long id, PrintWriter out) {
   @RequestMapping(value = "verifyExchange")
   public void verifyExchange(AcceptData acceptData, Long uid, Long id, String callback, PrintWriter out) {
      try {
         ExchangeTipVO exchange = integralExchangeService.verifyExchange(uid, id);
@@ -417,9 +448,17 @@
         Gson gson = gsonBuilder.create();
         JSONObject data = new JSONObject();
         data.put("result", gson.toJson(exchange));
         out.print(JsonUtil.loadTrueResult(data));
         if (StringUtil.isNullOrEmpty(callback)) {
            out.print(JsonUtil.loadTrueResult(data));
         } else {
            out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadTrueResult(data)));
         }
      } catch (IntegralExchangeException e) {
         out.print(JsonUtil.loadFalseResult(1, e.getMsg()));
         if (StringUtil.isNullOrEmpty(callback)) {
            out.print(JsonUtil.loadFalseResult(1, e.getMsg()));
         } else {
            out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult(1, e.getMsg())));
         }
      }
   }
@@ -431,8 +470,9 @@
    * @param id
    * @param out
    */
   @RequestMapping(value = "exchange", method = RequestMethod.POST)
   public void exchange(AcceptData acceptData, Long uid, Long id, PrintWriter out) {
   @RequestSerializableByKey(key = "'integralexchange-'+#uid")
   @RequestMapping(value = "exchange")
   public void exchange(AcceptData acceptData, Long uid, Long id, String callback, PrintWriter out) {
      try {
         IntegralExchange exchange = integralExchangeService.exchange(uid, id);
@@ -444,9 +484,15 @@
         JSONObject data = new JSONObject();
         data.put("result", gson.toJson(exchange));
         data.put("goldCoin", extraVO.getGoldCoin() + "枚");
         out.print(JsonUtil.loadTrueResult(data));
         if (StringUtil.isNullOrEmpty(callback))
            out.print(JsonUtil.loadTrueResult(data));
         else
            out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadTrueResult(data)));
      } catch (IntegralExchangeException e) {
         out.print(JsonUtil.loadFalseResult(1, e.getMsg()));
         if (StringUtil.isNullOrEmpty(callback))
            out.print(JsonUtil.loadFalseResult(1, e.getMsg()));
         else
            out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult(1, e.getMsg())));
      }
   }
@@ -482,6 +528,7 @@
    * @param id
    * @param out
    */
   @RequestSerializableByKey(key = "'exchangeInviteCode-'+#uid")
   @RequestMapping(value = "exchangeInviteCode", method = RequestMethod.POST)
   public void exchangeInviteCode(AcceptData acceptData, Long uid, Long id, PrintWriter out) {
      try {
@@ -510,7 +557,7 @@
      }
      try {
         List<CodePublishRecord> list = codePublishRecordService.listValid((page - 1) * Constant.PAGE_SIZE,
         List<CodePublishRecord> list = codePublishRecordService.listValid(null, (page - 1) * Constant.PAGE_SIZE,
               Constant.PAGE_SIZE);
         if (list == null) {
            list = new ArrayList<CodePublishRecord>();
@@ -521,7 +568,7 @@
         JSONObject data = new JSONObject();
         data.put("count", count);
         data.put("list", getGson().toJson(list));
         data.put("helpLink", configService.get("publish_list_help_link"));
         data.put("helpLink", configService.get(ConfigKeyEnum.publishListHelpLink.getKey()));
         out.print(JsonUtil.loadTrueResult(data));
      } catch (Exception e) {
         out.print(JsonUtil.loadFalseResult(1, "获取失败"));
@@ -550,46 +597,50 @@
      }
      IntegralTaskRecord record = null;
      if (TaskUniqueKeyEnum.recommendSearch.name().equalsIgnoreCase(event)) {
         record = integralGetService.addRecommendSearch(uid);
      } else if (TaskUniqueKeyEnum.shareInvite.name().equalsIgnoreCase(event)) {
         record = integralGetService.addShareInvite(uid);
      } else if (TaskUniqueKeyEnum.inShop.name().equalsIgnoreCase(event)) {
         JSONObject json = JSONObject.fromObject(data);
         record = integralGetService.addIntoShop(uid, StringUtil.Md5(json.optString("url")));
      } else if (TaskUniqueKeyEnum.scanPush.name().equalsIgnoreCase(event)) {
         record = integralGetService.addScanPushHistory(uid);
      } else if (TaskUniqueKeyEnum.scanGoods.name().equalsIgnoreCase(event)) {
         JSONObject json = JSONObject.fromObject(data);
         record = integralGetService.addScanGoodsDetail(uid, json.optInt("goodsType"), json.optLong("goodsId"));
      } else if (TaskUniqueKeyEnum.scanHomeBanner.name().equalsIgnoreCase(event)) {
         JSONObject json = JSONObject.fromObject(data);
         record = integralGetService.addScanRecommendBanner(uid, json.optString("id"));
      } else if (TaskUniqueKeyEnum.scanSpecial.name().equalsIgnoreCase(event)) {
         JSONObject json = JSONObject.fromObject(data);
         record = integralGetService.addScanRecommendSpecial(uid, json.optString("id"));
      } else if (TaskUniqueKeyEnum.scanTBCart.name().equalsIgnoreCase(event)) {
         record = integralGetService.addScanTaoBaoCart(uid);
      }
      if (record != null) {
         JSONObject notifyData = new JSONObject();
         if (TaskUniqueKeyEnum.recommendSearch.name().equalsIgnoreCase(event)
               || TaskUniqueKeyEnum.scanGoods.name().equalsIgnoreCase(event)
               || TaskUniqueKeyEnum.scanTBCart.name().equalsIgnoreCase(event)) {
            JSONObject notify = new JSONObject();
            if (TaskUniqueKeyEnum.recommendSearch.name().equalsIgnoreCase(event))
               notify.put("name", "完成一次智能搜索");
            else if (TaskUniqueKeyEnum.scanGoods.name().equalsIgnoreCase(event))
               notify.put("name", "完成一次商品浏览");
            else if (TaskUniqueKeyEnum.scanTBCart.name().equalsIgnoreCase(event))
               notify.put("name", "完成一次购物车浏览");
            notify.put("score", String.format("+%s金币", record.getGoldCoin()));
            notifyData.put("notify", notify);
      try {
         if (TaskUniqueKeyEnum.recommendSearch.name().equalsIgnoreCase(event)) {
            record = integralGetService.addRecommendSearch(uid);
         } else if (TaskUniqueKeyEnum.shareInvite.name().equalsIgnoreCase(event)) {
            record = integralGetService.addShareInvite(uid);
         } else if (TaskUniqueKeyEnum.inShop.name().equalsIgnoreCase(event)) {
            JSONObject json = JSONObject.fromObject(data);
            record = integralGetService.addIntoShop(uid, StringUtil.Md5(json.optString("url")));
         } else if (TaskUniqueKeyEnum.scanPush.name().equalsIgnoreCase(event)) {
            record = integralGetService.addScanPushHistory(uid);
         } else if (TaskUniqueKeyEnum.scanGoods.name().equalsIgnoreCase(event)) {
            JSONObject json = JSONObject.fromObject(data);
            record = integralGetService.addScanGoodsDetail(uid, json.optInt("goodsType"), json.optLong("goodsId"));
         } else if (TaskUniqueKeyEnum.scanHomeBanner.name().equalsIgnoreCase(event)) {
            JSONObject json = JSONObject.fromObject(data);
            record = integralGetService.addScanRecommendBanner(uid, json.optString("id"));
         } else if (TaskUniqueKeyEnum.scanSpecial.name().equalsIgnoreCase(event)) {
            JSONObject json = JSONObject.fromObject(data);
            record = integralGetService.addScanRecommendSpecial(uid, json.optString("id"));
         } else if (TaskUniqueKeyEnum.scanTBCart.name().equalsIgnoreCase(event)) {
            record = integralGetService.addScanTaoBaoCart(uid);
         }
         out.print(JsonUtil.loadTrueResult(notifyData));
      } else {
         if (record != null) {
            JSONObject notifyData = new JSONObject();
            if (TaskUniqueKeyEnum.recommendSearch.name().equalsIgnoreCase(event)
                  || TaskUniqueKeyEnum.scanGoods.name().equalsIgnoreCase(event)
                  || TaskUniqueKeyEnum.scanTBCart.name().equalsIgnoreCase(event)) {
               JSONObject notify = new JSONObject();
               if (TaskUniqueKeyEnum.recommendSearch.name().equalsIgnoreCase(event))
                  notify.put("name", "完成一次智能搜索");
               else if (TaskUniqueKeyEnum.scanGoods.name().equalsIgnoreCase(event))
                  notify.put("name", "完成一次商品浏览");
               else if (TaskUniqueKeyEnum.scanTBCart.name().equalsIgnoreCase(event))
                  notify.put("name", "完成一次购物车浏览");
               notify.put("score", String.format("+%s金币", record.getGoldCoin()));
               notifyData.put("notify", notify);
            }
            out.print(JsonUtil.loadTrueResult(notifyData));
         } else {
            out.print(JsonUtil.loadFalseResult(""));
         }
      } catch (Exception e) {
         out.print(JsonUtil.loadFalseResult(""));
      }
   }