From 2e5c6b46697f7b96460ad0c356740df52bf056d2 Mon Sep 17 00:00:00 2001 From: yujian <yujian@123.com> Date: 星期三, 14 八月 2019 09:51:07 +0800 Subject: [PATCH] 金币兑换 --- fanli/src/main/java/com/yeshi/fanli/controller/client/v2/IntegralControllerV2.java | 161 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 157 insertions(+), 4 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 6af5f5c..56dc804 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,10 +18,15 @@ 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.IntegralTaskClass.UniqueKeyEnum; @@ -26,6 +34,7 @@ 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.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; @@ -61,6 +70,9 @@ @Resource private IntegralExchangeRecordService integralExchangeRecordService; + + @Resource + private CodePublishRecordService codePublishRecordService; /** * 鑾峰彇浠诲姟鍒楄〃 @@ -228,7 +240,7 @@ Gson gson = gsonBuilder.create(); JSONObject data = new JSONObject(); - data.put("goldCoin", extraVO.getGoldCoin()); + data.put("goldCoin", extraVO.getGoldCoin() + "鏋�"); data.put("count", count); data.put("list", gson.toJson(list)); out.print(JsonUtil.loadTrueResult(data)); @@ -253,7 +265,7 @@ data.put("result", gson.toJson(exchange)); out.print(JsonUtil.loadTrueResult(data)); } catch (IntegralExchangeException e) { - e.printStackTrace(); + out.print(JsonUtil.loadFalseResult(1, e.getMsg())); } } @@ -267,7 +279,7 @@ @RequestMapping(value = "exchange", method = RequestMethod.POST) public void exchange(AcceptData acceptData, Long uid, Long id, PrintWriter out) { try { - ExchangeTipVO exchange = integralExchangeService.verifyExchange(uid, id); + IntegralExchange exchange = integralExchangeService.exchange(uid, id); GsonBuilder gsonBuilder = new GsonBuilder().excludeFieldsWithoutExposeAnnotation(); Gson gson = gsonBuilder.create(); @@ -276,7 +288,148 @@ data.put("result", gson.toJson(exchange)); out.print(JsonUtil.loadTrueResult(data)); } catch (IntegralExchangeException e) { - e.printStackTrace(); + 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)); + 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