From 27920d99bc5925de113aa4f0c22dbba3dcea672f Mon Sep 17 00:00:00 2001 From: admin <weikou2014> Date: 星期一, 19 八月 2019 17:46:58 +0800 Subject: [PATCH] 增加通用模板免单内容 --- fanli/src/main/java/com/yeshi/fanli/controller/client/v2/IntegralControllerV2.java | 361 ++++++++++++++++++++++++++++++++++++++++++++++++-- 1 files changed, 341 insertions(+), 20 deletions(-) diff --git a/fanli/src/main/java/com/yeshi/fanli/controller/client/v2/IntegralControllerV2.java b/fanli/src/main/java/com/yeshi/fanli/controller/client/v2/IntegralControllerV2.java index b197c46..516d376 100644 --- a/fanli/src/main/java/com/yeshi/fanli/controller/client/v2/IntegralControllerV2.java +++ b/fanli/src/main/java/com/yeshi/fanli/controller/client/v2/IntegralControllerV2.java @@ -1,7 +1,10 @@ package com.yeshi.fanli.controller.client.v2; import java.io.PrintWriter; +import java.lang.reflect.Type; import java.util.ArrayList; +import java.util.Calendar; +import java.util.Date; import java.util.HashSet; import java.util.List; import java.util.Set; @@ -15,21 +18,34 @@ import com.google.gson.Gson; import com.google.gson.GsonBuilder; +import com.google.gson.JsonElement; +import com.google.gson.JsonPrimitive; +import com.google.gson.JsonSerializationContext; +import com.google.gson.JsonSerializer; import com.google.gson.reflect.TypeToken; import com.yeshi.fanli.entity.accept.AcceptData; import com.yeshi.fanli.entity.bus.user.UserInfo; import com.yeshi.fanli.entity.bus.user.UserRank; +import com.yeshi.fanli.entity.integral.CodePublishRecord; +import com.yeshi.fanli.entity.integral.IntegralExchange; import com.yeshi.fanli.entity.integral.IntegralTaskClass; -import com.yeshi.fanli.entity.integral.IntegralTaskRecord; import com.yeshi.fanli.entity.integral.IntegralTaskClass.UniqueKeyEnum; +import com.yeshi.fanli.entity.integral.IntegralTaskRecord; +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.config.ConfigService; +import com.yeshi.fanli.service.inter.integral.CodePublishRecordService; +import com.yeshi.fanli.service.inter.integral.IntegralExchangeRecordService; +import com.yeshi.fanli.service.inter.integral.IntegralExchangeService; import com.yeshi.fanli.service.inter.integral.IntegralTaskClassService; import com.yeshi.fanli.service.inter.integral.IntegralTaskRecordService; import com.yeshi.fanli.service.inter.user.UserInfoExtraService; import com.yeshi.fanli.service.inter.user.UserInfoService; import com.yeshi.fanli.util.Constant; +import com.yeshi.fanli.util.StringUtil; import com.yeshi.fanli.vo.integral.DailySignVO; +import com.yeshi.fanli.vo.integral.ExchangeTipVO; import com.yeshi.fanli.vo.integral.IntegralTaskClassVO; import com.yeshi.fanli.vo.user.UserInfoExtraVO; @@ -40,20 +56,32 @@ public class IntegralControllerV2 { @Resource + private ConfigService configService; + + @Resource private UserInfoService userInfoService; @Resource private UserInfoExtraService userInfoExtraService; - + @Resource private IntegralTaskClassService integralTaskClassService; @Resource private IntegralTaskRecordService integralTaskRecordService; - + + @Resource + private IntegralExchangeService integralExchangeService; + + @Resource + private IntegralExchangeRecordService integralExchangeRecordService; + + @Resource + private CodePublishRecordService codePublishRecordService; /** * 鑾峰彇浠诲姟鍒楄〃 + * * @param acceptData * @param uid * @param page @@ -70,17 +98,18 @@ out.print(JsonUtil.loadFalseResult(1, "椤电爜涓嶆纭�")); return; } - + GsonBuilder gsonBuilder = new GsonBuilder().excludeFieldsWithoutExposeAnnotation(); Gson gson = gsonBuilder.create(); try { JSONObject data = new JSONObject(); - List<IntegralTaskClassVO> list = integralTaskClassService.getIntegralTaskClassVO(uid, (page - 1) * Constant.PAGE_SIZE, Constant.PAGE_SIZE); + List<IntegralTaskClassVO> list = integralTaskClassService.getIntegralTaskClassVO(uid, + (page - 1) * Constant.PAGE_SIZE, Constant.PAGE_SIZE); if (list == null) { list = new ArrayList<IntegralTaskClassVO>(); } long count = integralTaskClassService.countTaskClass(); - + if (page == 1) { UserInfoExtraVO extraVO = userInfoExtraService.getInfoExtraVOByUid(uid); if (extraVO == null) { @@ -93,18 +122,18 @@ out.print(JsonUtil.loadFalseResult(1, "鏌ヨ鐢ㄦ埛淇℃伅涓嶅叏")); return; } - + UserRank userRank = extraVO.getUserRank(); if (userRank == null) { out.print(JsonUtil.loadFalseResult(1, "鐢ㄦ埛绛夌骇涓嶅瓨鍦�")); return; } - + boolean signState = false; IntegralTaskClass taskClass = integralTaskClassService.getByUniqueKey(UniqueKeyEnum.dailySign.name()); if (taskClass != null) signState = integralTaskRecordService.isToDaySign(uid, taskClass.getId()); - + // 绛惧埌鏃ユ湡 DailySignVO dailySignVO = integralTaskClassService.getDailySignList(uid, userRank.getId()); data.put("signState", signState); @@ -113,7 +142,7 @@ data.put("userRank", gson.toJson(userRank)); data.put("dailySign", dailySignVO); } - + data.put("count", count); data.put("list", gson.toJson(list)); out.print(JsonUtil.loadTrueResult(data)); @@ -121,10 +150,10 @@ LogHelper.errorDetailInfo(e); } } - - + /** * 鑾峰彇宸插畬鎴愪换鍔� 鏈鍙栭噾甯� + * * @param acceptData * @param uid * @param out @@ -140,45 +169,337 @@ if (list == null) { list = new ArrayList<IntegralTaskRecord>(); } - + GsonBuilder gsonBuilder = new GsonBuilder().excludeFieldsWithoutExposeAnnotation(); Gson gson = gsonBuilder.create(); - + JSONObject data = new JSONObject(); data.put("list", gson.toJson(list)); out.print(JsonUtil.loadTrueResult(data)); } - /** * 棰嗗彇閲戝竵 + * * @param acceptData * @param uid - * @param ids + * @param ids // 棰嗗彇id + * @param gids // 鏈鍙杋d * @param out */ @RequestMapping(value = "receiveGoldCoin", method = RequestMethod.POST) - public void receiveGoldCoin(AcceptData acceptData, Long uid, String ids, PrintWriter out) { + public void receiveGoldCoin(AcceptData acceptData, Long uid, String ids, String gids, PrintWriter out) { if (uid == null || uid <= 0) { out.print(JsonUtil.loadFalseResult(1, "鐢ㄦ埛鏈櫥褰�")); return; } - + Gson gson = new Gson(); - Set<Long> idList = gson.fromJson(ids, new TypeToken<HashSet<Long>>() {}.getType()); + Set<Long> idList = gson.fromJson(ids, new TypeToken<HashSet<Long>>() { + }.getType()); if (idList == null || idList.size() == 0) { out.print(JsonUtil.loadFalseResult("棰嗗彇id涓嶈兘涓虹┖")); return; } + + Set<Long> gidList = gson.fromJson(gids, new TypeToken<HashSet<Long>>() {}.getType()); try { Integer goldCoin = integralTaskRecordService.receiveGoldCoin(uid, idList); + + List<IntegralTaskRecord> list = null; + if (gidList != null && gidList.size() > 0) { + list = integralTaskRecordService.listNotReceived(5 - gidList.size(), uid); + } else { + list = integralTaskRecordService.listNotReceived(5, uid); + } + + 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())); } } - + + /** + * 閲戝竵鍏戞崲鍒楄〃 + * + * @param acceptData + * @param uid + * @param ids + * @param out + */ + @RequestMapping(value = "getExchangeList", method = RequestMethod.POST) + public void getExchangeList(AcceptData acceptData, Long uid, Integer page, PrintWriter out) { + if (uid == null || uid <= 0) { + out.print(JsonUtil.loadFalseResult(1, "鐢ㄦ埛鏈櫥褰�")); + return; + } + + if (page == null || page < 1) { + out.print(JsonUtil.loadFalseResult(1, "椤电爜涓嶆纭�")); + return; + } + + UserInfoExtraVO extraVO = userInfoExtraService.getInfoExtraVOByUid(uid); + if (extraVO == null) { + out.print(JsonUtil.loadFalseResult(1, "鐢ㄦ埛鐩稿叧淇℃伅涓嶅瓨鍦�")); + return; + } + + List<IntegralExchange> list = integralExchangeRecordService.listExchange((page - 1) * Constant.PAGE_SIZE, + Constant.PAGE_SIZE, uid); + if (list == null) + list = new ArrayList<IntegralExchange>(); + + Long count = integralExchangeService.countValid(); + + GsonBuilder gsonBuilder = new GsonBuilder().excludeFieldsWithoutExposeAnnotation(); + Gson gson = gsonBuilder.create(); + + JSONObject data = new JSONObject(); + data.put("goldCoin", extraVO.getGoldCoin() + "鏋�"); + data.put("count", count); + data.put("list", gson.toJson(list)); + out.print(JsonUtil.loadTrueResult(data)); + } + + /** + * 鍏戞崲閲戝竵妫�楠� + * + * @param acceptData + * @param uid + * @param id + * @param out + */ + @RequestMapping(value = "verifyExchange", method = RequestMethod.POST) + public void verifyExchange(AcceptData acceptData, Long uid, Long id, PrintWriter out) { + try { + ExchangeTipVO exchange = integralExchangeService.verifyExchange(uid, id); + + GsonBuilder gsonBuilder = new GsonBuilder().excludeFieldsWithoutExposeAnnotation(); + Gson gson = gsonBuilder.create(); + + JSONObject data = new JSONObject(); + data.put("result", gson.toJson(exchange)); + out.print(JsonUtil.loadTrueResult(data)); + } catch (IntegralExchangeException e) { + out.print(JsonUtil.loadFalseResult(1, e.getMsg())); + } + } + + /** + * 鍏戞崲閲戝竵 + * + * @param acceptData + * @param uid + * @param id + * @param out + */ + @RequestMapping(value = "exchange", method = RequestMethod.POST) + public void exchange(AcceptData acceptData, Long uid, Long id, PrintWriter out) { + try { + IntegralExchange exchange = integralExchangeService.exchange(uid, id); + + GsonBuilder gsonBuilder = new GsonBuilder().excludeFieldsWithoutExposeAnnotation(); + Gson gson = gsonBuilder.create(); + + JSONObject data = new JSONObject(); + data.put("result", gson.toJson(exchange)); + out.print(JsonUtil.loadTrueResult(data)); + } catch (IntegralExchangeException e) { + out.print(JsonUtil.loadFalseResult(1, e.getMsg())); + } + } + + /** + * 鍏戞崲閲戝竵妫�楠�-閭�璇风爜 + * + * @param acceptData + * @param uid + * @param id + * @param out + */ + @RequestMapping(value = "verifyInviteCode", method = RequestMethod.POST) + public void verifyInviteCode(AcceptData acceptData, Long uid, Long id, PrintWriter out) { + try { + ExchangeTipVO exchange = integralExchangeService.verifyInviteCode(uid, id); + + GsonBuilder gsonBuilder = new GsonBuilder().excludeFieldsWithoutExposeAnnotation(); + Gson gson = gsonBuilder.create(); + + JSONObject data = new JSONObject(); + data.put("result", gson.toJson(exchange)); + out.print(JsonUtil.loadTrueResult(data)); + } catch (IntegralExchangeException e) { + out.print(JsonUtil.loadFalseResult(1, e.getMsg())); + } + } + + /** + * 鍏戞崲閲戝竵-閭�璇风爜 + * + * @param acceptData + * @param uid + * @param id + * @param out + */ + @RequestMapping(value = "exchangeInviteCode", method = RequestMethod.POST) + public void exchangeInviteCode(AcceptData acceptData, Long uid, Long id, PrintWriter out) { + try { + integralExchangeService.exchangeInviteCode(uid, id); + out.print(JsonUtil.loadTrueResult("閭�璇风爜婵�娲绘垚鍔�")); + } catch (IntegralExchangeException e) { + out.print(JsonUtil.loadFalseResult(1, e.getMsg())); + } + } + + /** + * 閭�璇风爜鍙戝竷鍒楄〃 + * + * @param acceptData + * @param page + * @param out + */ + @RequestMapping(value = "getPublishList", method = RequestMethod.POST) + public void getPublishList(AcceptData acceptData, Integer page, PrintWriter out) { + if (page == null || page < 1) { + out.print(JsonUtil.loadFalseResult(1, "椤电爜涓嶆纭�")); + return; + } + + List<CodePublishRecord> list = codePublishRecordService.listValid((page - 1) * Constant.PAGE_SIZE, + Constant.PAGE_SIZE); + if (list == null) { + list = new ArrayList<CodePublishRecord>(); + } + + long count = codePublishRecordService.countValid(); + + JSONObject data = new JSONObject(); + data.put("count", count); + data.put("list", getGson().toJson(list)); + data.put("helpLink", configService.get("publish_list_help_link")); + out.print(JsonUtil.loadTrueResult(data)); + } + + /** + * 浜嬩欢鎺ㄩ�� + * + * @param acceptData + * @param event + * @param uid + * @param out + */ + @RequestMapping(value = "pushEvent", method = RequestMethod.POST) + public void pushEvent(AcceptData acceptData, String event, Long uid, PrintWriter out) { + if (uid == null || uid == 0) { + out.print(JsonUtil.loadFalseResult("鐢ㄦ埛灏氭湭鐧诲綍")); + return; + } + + if (StringUtil.isNullOrEmpty(event)) { + out.print(JsonUtil.loadFalseResult("浜嬩欢涓虹┖")); + return; + } + + JSONObject data = new JSONObject(); + if ("recommendSearch".equalsIgnoreCase(event) || "scanGoods".equalsIgnoreCase(event) + || "scanTBCart".equalsIgnoreCase(event)) { + JSONObject notify = new JSONObject(); + switch (event) { + + case "recommendSearch": + notify.put("name", "瀹屾垚涓�娆℃櫤鑳芥悳绱�"); + notify.put("score", "+20閲戝竵"); + break; + case "scanGoods": + notify.put("name", "瀹屾垚涓�娆″晢鍝佹祻瑙�"); + notify.put("score", "+100閲戝竵"); + break; + case "scanTBCart": + notify.put("name", "瀹屾垚涓�娆¤喘鐗╄溅娴忚"); + notify.put("score", "+300閲戝竵"); + break; + } + + data.put("notify", notify); + } + out.print(JsonUtil.loadTrueResult(data)); + } + + /** + * 鏃堕棿澶勭悊 + * + * @return + */ + private Gson getGson() { + GsonBuilder gb = JsonUtil.getConvertBigDecimalToStringSubZeroBuilder(new GsonBuilder()); + gb.excludeFieldsWithoutExposeAnnotation(); + gb.registerTypeAdapter(Date.class, new JsonSerializer<Date>() { + @Override + public JsonElement serialize(Date value, Type theType, JsonSerializationContext context) { + String desc = ""; + if (value != null) { + // 鍒ゆ柇鏄惁鏄悓涓�澶� + + Calendar calendar = Calendar.getInstance(); + calendar.setTime(value); + int y1 = calendar.get(Calendar.YEAR);// 鑾峰彇骞翠唤 + int d1 = calendar.get(Calendar.DAY_OF_YEAR);// 鑾峰彇骞翠腑绗嚑澶� + + Date nowDate = new Date(); + Calendar calendar2 = Calendar.getInstance(); + calendar2.setTime(nowDate); + int y2 = calendar2.get(Calendar.YEAR);// 鑾峰彇骞翠唤 + int d2 = calendar2.get(Calendar.DAY_OF_YEAR);// 鑾峰彇骞翠腑绗嚑澶� + + long old = value.getTime(); + long now = nowDate.getTime(); + if (y1 == y2) { + if (d1 == d2) { + long cha = now - old; + if (cha < 1000 * 60 * 2L) { + desc = "鍒氬垰"; + } else if (cha < 1000 * 60 * 60L) { + desc = (cha / (1000 * 60)) + "鍒嗛挓鍓�"; + } else { + desc = (cha / (1000 * 60 * 60)) + "灏忔椂鍓�"; + } + } else if (d2 - d1 == 1) { + desc = "鏄ㄥぉ"; + } else { + desc = (d2 - d1) + "澶╁墠"; + } + } else { + int timeDistance = 0; + for (int i = y1; i < y2; i++) { + if (i % 4 == 0 && i % 100 != 0 || i % 400 == 0) { + timeDistance += 366; // 闂板勾 + } else { + timeDistance += 365; // 涓嶆槸闂板勾 + } + } + desc = timeDistance + (d2 - d1) + "澶╁墠"; + } + + return new JsonPrimitive(desc); + } + + return new JsonPrimitive(""); + } + }); + + Gson gson = gb.create(); + return gson; + } + } -- Gitblit v1.8.0