From df300df7832cc3d24f1b09297998e8bee8cfd126 Mon Sep 17 00:00:00 2001
From: yujian <yujian@123.com>
Date: 星期二, 20 八月 2019 18:06:43 +0800
Subject: [PATCH] 签到弹框bug

---
 fanli/src/main/java/com/yeshi/fanli/controller/client/v2/IntegralControllerV2.java |  212 +++++++++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 181 insertions(+), 31 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 b24f155..0a16be2 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,5 +1,6 @@
 package com.yeshi.fanli.controller.client.v2;
 
+import java.io.IOException;
 import java.io.PrintWriter;
 import java.lang.reflect.Type;
 import java.util.ArrayList;
@@ -22,13 +23,16 @@
 import com.google.gson.JsonPrimitive;
 import com.google.gson.JsonSerializationContext;
 import com.google.gson.JsonSerializer;
+import com.google.gson.TypeAdapter;
 import com.google.gson.reflect.TypeToken;
+import com.google.gson.stream.JsonReader;
+import com.google.gson.stream.JsonWriter;
 import com.yeshi.fanli.entity.accept.AcceptData;
+import com.yeshi.fanli.entity.bus.tlj.UserTaoLiJinDetail.TaoLiJinDetailTypeEnum;
 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;
 import com.yeshi.fanli.entity.integral.IntegralTaskRecord;
 import com.yeshi.fanli.exception.integral.IntegralExchangeException;
@@ -36,6 +40,7 @@
 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.IntegralDetailService;
 import com.yeshi.fanli.service.inter.integral.IntegralExchangeRecordService;
 import com.yeshi.fanli.service.inter.integral.IntegralExchangeService;
 import com.yeshi.fanli.service.inter.integral.IntegralTaskClassService;
@@ -44,8 +49,10 @@
 import com.yeshi.fanli.service.inter.user.UserInfoService;
 import com.yeshi.fanli.util.Constant;
 import com.yeshi.fanli.util.StringUtil;
+import com.yeshi.fanli.util.TimeUtil;
 import com.yeshi.fanli.vo.integral.DailySignVO;
 import com.yeshi.fanli.vo.integral.ExchangeTipVO;
+import com.yeshi.fanli.vo.integral.IntegralDetailVO;
 import com.yeshi.fanli.vo.integral.IntegralTaskClassVO;
 import com.yeshi.fanli.vo.user.UserInfoExtraVO;
 
@@ -75,6 +82,9 @@
 
 	@Resource
 	private IntegralExchangeRecordService integralExchangeRecordService;
+	
+	@Resource
+	private IntegralDetailService integralDetailService;
 
 	@Resource
 	private CodePublishRecordService codePublishRecordService;
@@ -109,8 +119,18 @@
 				list = new ArrayList<IntegralTaskClassVO>();
 			}
 			long count = integralTaskClassService.countTaskClass();
-
+			
+			// 鐢ㄦ埛绛惧埌
+			Integer signState = 0;
 			if (page == 1) {
+				
+				// 绛惧埌
+				try { 
+					signState = integralTaskClassService.finishedDailySign(uid);
+				} catch (Exception e) {
+					e.printStackTrace();
+				}
+				
 				UserInfoExtraVO extraVO = userInfoExtraService.getInfoExtraVOByUid(uid);
 				if (extraVO == null) {
 					out.print(JsonUtil.loadFalseResult(1, "鐢ㄦ埛鐩稿叧淇℃伅涓嶅瓨鍦�"));
@@ -128,21 +148,65 @@
 					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);
+
+				boolean ejectSign = false;
+				if (signState == 1) 
+					ejectSign = true;
+
+				data.put("signState", ejectSign);
 				data.put("goldCoin", extraVO.getGoldCoin());
 				data.put("portrait", userInfo.getPortrait());
 				data.put("userRank", gson.toJson(userRank));
 				data.put("dailySign", dailySignVO);
 			}
 
+			
+			for (IntegralTaskClassVO taskClassVO : list) {
+				String progress = taskClassVO.getProgress();
+				if (StringUtil.isNullOrEmpty(progress))
+					continue;
+				
+				Integer taskNum = taskClassVO.getTaskNum();
+				if (taskNum == null)
+					continue;
+
+				UniqueKeyEnum uniqueKey = taskClassVO.getUniqueKey();
+				if (uniqueKey == UniqueKeyEnum.dailySign) {
+					if (signState == 0) {
+						taskClassVO.setLightUp(true); // 绛惧埌澶辫触
+					} else if (signState == 1) {
+						taskClassVO.setLightUp(false);
+					} else if (signState == 2) {
+						taskClassVO.setLightUp(false);
+					}
+				} else {
+					taskClassVO.setLightUp(true);
+				}
+				
+				Integer dateType = 1; // 鏌ヨ褰撴棩
+				if (uniqueKey == UniqueKeyEnum.orderReward)
+					dateType = null; // 鏌ヨ鍘嗗彶
+
+				Long id = taskClassVO.getId();
+				int countFinished = 0;
+				Integer totalGoldCoin = integralTaskRecordService.getTotalGoldCoin(uid, id, dateType);
+				if (totalGoldCoin != null && totalGoldCoin > 0) {
+					taskClassVO.setFinishedCoin("+" + totalGoldCoin);
+					if (uniqueKey != UniqueKeyEnum.dailySign)
+						countFinished = integralTaskRecordService.countFinished(uid, id, dateType);
+				}
+				progress = progress.replace("{宸插畬鎴恾", countFinished + "").replace("{鎬讳换鍔", taskNum + "");
+				
+				if (signState == 0 && uniqueKey == UniqueKeyEnum.dailySign) {
+					progress = "鏈鍒�";
+					taskClassVO.setBtnName("绛惧埌");
+				} 
+				taskClassVO.setProgress(progress);
+			}
+			
 			data.put("count", count);
 			data.put("list", gson.toJson(list));
 			out.print(JsonUtil.loadTrueResult(data));
@@ -165,7 +229,12 @@
 			return;
 		}
 
-		List<IntegralTaskRecord> list = integralTaskRecordService.listNotReceived(5, uid);
+		int count = 5;
+		if ("android".equalsIgnoreCase(acceptData.getPlatform())) {
+			count = Integer.MAX_VALUE;
+		}
+		
+		List<IntegralTaskRecord> list = integralTaskRecordService.listNotReceived(count, uid);
 		if (list == null) {
 			list = new ArrayList<IntegralTaskRecord>();
 		}
@@ -188,30 +257,37 @@
 	 * @param out
 	 */
 	@RequestMapping(value = "receiveGoldCoin", method = RequestMethod.POST)
-	public void receiveGoldCoin(AcceptData acceptData, Long uid, String ids, String gids, PrintWriter out) {
+	public void receiveGoldCoin(AcceptData acceptData, Long uid, Integer type, 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());
-		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);
+			// 鍏ㄩ儴棰嗗彇
+			if (type != null && type == 1) {
+				Integer goldCoin = integralTaskRecordService.receiveGoldCoinALL(uid);
+				JSONObject data = new JSONObject();
+				data.put("goldCoin", goldCoin);
+				out.print(JsonUtil.loadTrueResult(data));
+				return;
+			} 
 			
+			// 閮ㄥ垎棰嗗彇
+			Gson gson = new Gson();
+			Set<Long> idList = gson.fromJson(ids, new TypeToken<HashSet<Long>>() {
+			}.getType());
+			if (idList == null || idList.size() == 0) {
+				out.print(JsonUtil.loadFalseResult("棰嗗彇id涓嶈兘涓虹┖"));
+				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.listNotReceived(5 - gidList.size(), uid);
+				list = integralTaskRecordService.listNotReceivedExcludeId(5 - gidList.size(), uid, gidList);
 			} else {
-				list = integralTaskRecordService.listNotReceived(5, uid);
+				list = integralTaskRecordService.listNotReceivedExcludeId(5, uid, null);
 			}
 			
 			if (list == null) {
@@ -219,7 +295,7 @@
 			}
 			GsonBuilder gsonBuilder = new GsonBuilder().excludeFieldsWithoutExposeAnnotation();
 			Gson gson2 = gsonBuilder.create();
-
+	
 			JSONObject data = new JSONObject();
 			data.put("goldCoin", goldCoin);
 			data.put("list", gson2.toJson(list));
@@ -260,14 +336,14 @@
 		if (list == null)
 			list = new ArrayList<IntegralExchange>();
 
-		Long count = integralExchangeService.countValid();
+		//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("count", list.size());
 		data.put("list", gson.toJson(list));
 		out.print(JsonUtil.loadTrueResult(data));
 	}
@@ -419,15 +495,15 @@
 			
 			case "recommendSearch":
 				notify.put("name", "瀹屾垚涓�娆℃櫤鑳芥悳绱�");
-				notify.put("score", "+20");
+				notify.put("score", "+20閲戝竵");
 				break;
 			case "scanGoods":
 				notify.put("name", "瀹屾垚涓�娆″晢鍝佹祻瑙�");
-				notify.put("score", "+10");
+				notify.put("score", "+100閲戝竵");
 				break;
 			case "scanTBCart":
 				notify.put("name", "瀹屾垚涓�娆¤喘鐗╄溅娴忚");
-				notify.put("score", "+30");
+				notify.put("score", "+300閲戝竵");
 				break;
 			}
 
@@ -502,4 +578,78 @@
 		return gson;
 	}
 
+	
+	/**
+	 * 鏄庣粏璇︽儏
+	 * 
+	 * @param acceptData
+	 * @param uid
+	 * @param index
+	 *            List鏈�鏈殑涓婚敭ID
+	 * @param year
+	 *            骞翠唤
+	 * @param month
+	 *            鏈堜唤
+	 *  @param type  缁熻绫诲瀷  0鍏ㄩ儴  1
+	 * @param out
+	 */
+	@RequestMapping(value = "getDetails")
+	public void getDetails(AcceptData acceptData, Long uid, Long index, Integer year, Integer month, Integer type,
+			PrintWriter out) {
+		if (uid == null || uid == 0) {
+			out.print(JsonUtil.loadFalseResult(1, "鐢ㄦ埛鏈櫥褰�"));
+			return;
+		}
+
+		if ((year == null && month != null) || (year != null && month == null)) {
+			out.print(JsonUtil.loadFalseResult(1, "鏃ユ湡涓嶅畬鏁�"));
+			return;
+		}
+		
+		Date date = null;
+
+		if (year != null && month != null) {
+			date = new Date(TimeUtil.convertToTimeTemp(year + "-" + month, "yyyy-M"));
+			Calendar ca = Calendar.getInstance();
+			ca.setTime(date);
+			ca.add(Calendar.MONTH, 1);
+			date = new Date(ca.getTimeInMillis() - 1);
+		}
+
+		// 鏌ヨ鍒楄〃
+		List<IntegralDetailVO> list = integralDetailService.listDetailForClient(uid, index, date);
+		// 缁熻鎬绘潯鏁�
+		long count = integralDetailService.countDetailForClient(uid, index, date);
+
+		GsonBuilder gsonBuilder = new GsonBuilder().excludeFieldsWithoutExposeAnnotation();
+		gsonBuilder.registerTypeAdapter(TaoLiJinDetailTypeEnum.class, new TypeAdapter<TaoLiJinDetailTypeEnum>() {
+			@Override
+			public TaoLiJinDetailTypeEnum read(JsonReader arg0) throws IOException {
+				return null;
+			}
+
+			@Override
+			public void write(JsonWriter out, TaoLiJinDetailTypeEnum arg1) throws IOException {
+				out.beginObject();
+				out.name("portrait").value(arg1.getPicture());
+				out.endObject();
+			}
+		}).registerTypeAdapter(Date.class, new JsonSerializer<Date>() {
+			@Override
+			public JsonElement serialize(Date value, Type theType, JsonSerializationContext context) {
+				if (value == null) {
+					return new JsonPrimitive("");
+				} else {
+					return new JsonPrimitive(TimeUtil.getGernalTime(value.getTime(), "yyyy.MM.dd HH:mm"));
+				}
+			}
+		});
+
+		Gson gson = gsonBuilder.create();
+
+		JSONObject data = new JSONObject();
+		data.put("count", count);
+		data.put("data", gson.toJson(list));
+		out.print(JsonUtil.loadTrueResult(data));
+	}
 }

--
Gitblit v1.8.0