From 972d3bc71115ec977dccf835fbcd148da3bcc86c Mon Sep 17 00:00:00 2001
From: yujian <yujian@123.com>
Date: 星期二, 03 九月 2019 16:41:49 +0800
Subject: [PATCH] 统计可用的免单券数量-countUsableFreeCouponForBuy

---
 fanli/src/main/java/com/yeshi/fanli/service/impl/homemodule/SpecialServiceImpl.java |  101 +++++++++++++++++++++++++++++++++++++++++---------
 1 files changed, 82 insertions(+), 19 deletions(-)

diff --git a/fanli/src/main/java/com/yeshi/fanli/service/impl/homemodule/SpecialServiceImpl.java b/fanli/src/main/java/com/yeshi/fanli/service/impl/homemodule/SpecialServiceImpl.java
index 90e1c1a..d3ec032 100644
--- a/fanli/src/main/java/com/yeshi/fanli/service/impl/homemodule/SpecialServiceImpl.java
+++ b/fanli/src/main/java/com/yeshi/fanli/service/impl/homemodule/SpecialServiceImpl.java
@@ -2,6 +2,7 @@
 
 import java.io.InputStream;
 import java.util.ArrayList;
+import java.util.Calendar;
 import java.util.Date;
 import java.util.List;
 import java.util.UUID;
@@ -17,11 +18,13 @@
 
 import com.yeshi.fanli.dao.mybatis.homemodule.SpecialMapper;
 import com.yeshi.fanli.dto.common.CommonContentTypeEnum;
+import com.yeshi.fanli.entity.AppVersionInfo;
 import com.yeshi.fanli.entity.accept.AcceptData;
 import com.yeshi.fanli.entity.bus.homemodule.Special;
 import com.yeshi.fanli.entity.common.JumpDetailV2;
 import com.yeshi.fanli.exception.homemodule.SpecialException;
 import com.yeshi.fanli.service.inter.common.JumpDetailV2Service;
+import com.yeshi.fanli.service.inter.config.AppVersionService;
 import com.yeshi.fanli.service.inter.config.ConfigService;
 import com.yeshi.fanli.service.inter.homemodule.SpecialCardService;
 import com.yeshi.fanli.service.inter.homemodule.SpecialPlaceService;
@@ -49,6 +52,10 @@
 
 	@Resource
 	private ConfigService configService;
+	
+	@Resource
+	private AppVersionService appVersionService;
+	
 
 	@Override
 	public Special selectByPrimaryKey(Long id) {
@@ -68,12 +75,32 @@
 		if (name == null || name.trim().length() == 0) {
 			throw new SpecialException(1, "涓撻鍚嶇О涓嶈兘涓虹┖");
 		}
-		
+
 		Integer sex = record.getSex();
 		if (sex == null) {
 			throw new SpecialException(1, "鎬у埆涓嶈兘涓虹┖");
 		}
-		
+
+		String version = record.getVersion();
+		Integer platformCode = record.getPlatform();
+		if (!StringUtil.isNullOrEmpty(version) && platformCode != null) {
+			String platform = "android";
+			if (platformCode == 2)
+				platform = "ios";
+			AppVersionInfo versionInfo = appVersionService.getByPlatformAndVersion(platform, version);
+			if (versionInfo == null)
+				throw new SpecialException(1, "鐗堟湰鍙蜂俊鎭己澶�");
+			
+			record.setVersionCode(versionInfo.getVersionCode());
+			record.setPlatform(platformCode);
+		} else {
+			if (!StringUtil.isNullOrEmpty(version))
+				throw new SpecialException(1, "骞冲彴绫诲瀷涓嶈兘涓虹┖");
+			
+			if (platformCode != null) 
+				throw new SpecialException(1, "鐗堟湰鍙蜂笉鑳戒负绌�");
+		}
+
 		String params = record.getParams();
 		if (params == null || params.trim().length() == 0 || "null".equalsIgnoreCase(params)) {
 			record.setParams(null);
@@ -81,8 +108,6 @@
 			throw new SpecialException(1, "璺宠浆鍙傛暟闈濲SON鏍煎紡");
 		}
 
-		
-		
 		if (!StringUtil.isNullOrEmpty(jumpType)) {
 			List<JumpDetailV2> listByType = jumpDetailV2Service.listByType(jumpType);
 			if (listByType != null && listByType.size() > 0) {
@@ -118,15 +143,22 @@
 			record.setIcon(icon);
 			record.setPicture(picture);
 			record.setSubPicture(subPicture);
-			
+
 			// 鎺掑簭
 			record.setOrderby(specialMapper.getDefaultMaxOrder(cardId) + 1);
 			record.setOrderMan(specialMapper.getManMaxOrder(cardId) + 1);
 			record.setOrderWoman(specialMapper.getWomanMaxOrder(cardId) + 1);
-			
+
 			record.setCreatetime(new Date());
 			record.setUpdatetime(new Date());
 			specialMapper.insert(record);
+
+			Special s = new Special();
+			s.setId(record.getId());
+			s.setOrderby(Integer.parseInt(s.getId() + ""));
+			s.setOrderMan(Integer.parseInt(s.getId() + ""));
+			s.setOrderWoman(Integer.parseInt(s.getId() + ""));
+			specialMapper.updateByPrimaryKeySelective(s);
 		} else {
 			// 淇敼
 			Special resultObj = specialMapper.selectByPrimaryKey(id);
@@ -177,12 +209,12 @@
 			} else {
 				record.setIcon(resultObj.getIcon());
 			}
-			
+
 			record.setOrderby(resultObj.getOrderby());
 			record.setOrderMan(resultObj.getOrderMan());
 			record.setOrderWoman(resultObj.getOrderWoman());
 			record.setCreatetime(resultObj.getCreatetime());
-			
+
 			record.setUpdatetime(new Date());
 			specialMapper.updateByPrimaryKey(record);
 		}
@@ -244,32 +276,32 @@
 			if (exchangeObject == null) {
 				throw new SpecialException(1, "娌℃湁鎵惧埌鍙氦鎹㈢殑浣嶇疆");
 			}
-			
+
 			resultObj.setOrderby(exchangeObject.getOrderby());
 			exchangeObject.setOrderby(orderby);
-		} else if (Special.SEX_MAN == sex ) {
+		} else if (Special.SEX_MAN == sex) {
 			Integer orderMan = resultObj.getOrderMan();
 			exchangeObject = specialMapper.getOrderByCardID(cardId, moveType, orderMan, sex);
 			if (exchangeObject == null) {
 				throw new SpecialException(1, "娌℃湁鎵惧埌鍙氦鎹㈢殑浣嶇疆");
 			}
-			
+
 			resultObj.setOrderMan(exchangeObject.getOrderMan());
 			exchangeObject.setOrderMan(orderMan);
-		} else if (Special.SEX_WOMAN == sex ) {
+		} else if (Special.SEX_WOMAN == sex) {
 			Integer orderWoman = resultObj.getOrderWoman();
 			exchangeObject = specialMapper.getOrderByCardID(cardId, moveType, orderWoman, sex);
-			
+
 			if (exchangeObject == null) {
 				throw new SpecialException(1, "娌℃湁鎵惧埌鍙氦鎹㈢殑浣嶇疆");
 			}
-			
+
 			resultObj.setOrderWoman(exchangeObject.getOrderWoman());
 			exchangeObject.setOrderWoman(orderWoman);
 		} else {
 			throw new SpecialException(1, "sex鍙傛暟涓嶆纭�");
 		}
-		
+
 		specialMapper.updateByPrimaryKey(resultObj);
 		specialMapper.updateByPrimaryKey(exchangeObject);
 	}
@@ -360,12 +392,28 @@
 	}
 
 	@Override
+	@Cacheable(value = "specialCache", key = "'listByVersion-'+#start+'-'+#count+'-'+#card+'-'+#platform+'-'+#versionCode")
+	public List<Special> listByVersion(long start, int count, String card, Integer platform, Integer versionCode) {
+		return specialMapper.listByVersion(start, count, card, platform, versionCode);
+	}
+	
+	
+	@Override
 	@Cacheable(value = "specialCache", key = "'listCacheSpecialToIndex'+#acceptData.platform+'-'+#acceptData.version+'-'+#sex")
 	public JSONObject listCacheSpecialToIndex(AcceptData acceptData, Integer sex) throws Exception {
 
 		// 棣栭〉-5鍦嗗舰2鎺掑尯鍩�
 		JSONObject arcMap = new JSONObject();
-		List<Special> listArc = specialMapper.listByPlaceKey("index_arc", sex);
+
+		String indexArc = "index_arc";
+		if (VersionUtil.greaterThan_1_6_0(acceptData.getPlatform(), acceptData.getVersion()))
+			indexArc = "index_arc_1.6.0";
+		else if (VersionUtil.greaterThan_1_5_70(acceptData.getPlatform(), acceptData.getVersion()))
+			indexArc = "index_arc_1.5.7";
+		else if (VersionUtil.greaterThan_1_5_60(acceptData.getPlatform(), acceptData.getVersion()))
+			indexArc = "index_arc_1.5.6";
+
+		List<Special> listArc = specialMapper.listByPlaceKey(indexArc, sex);
 		if (listArc == null) {
 			listArc = new ArrayList<Special>();
 		} else if (listArc.size() > 0) {
@@ -376,8 +424,10 @@
 			}
 		}
 
+		int hour = Calendar.getInstance().get(Calendar.HOUR_OF_DAY);
+
 		// 澶勭悊9.9鍖呴偖
-		if (listArc != null && VersionUtil.greaterThan_1_5_50(acceptData.getPlatform(), acceptData.getVersion())&&!Constant.IS_TEST)
+		if (listArc != null && VersionUtil.greaterThan_1_5_50(acceptData.getPlatform(), acceptData.getVersion()))
 			for (Special s : listArc) {
 				if (s.getName().contains("9.9")) {// 9鍧�9
 					s.setJumpDetail(jumpDetailV2Service.getByTypeCache("common_template"));
@@ -385,6 +435,16 @@
 					params.put("key", CommonContentTypeEnum._9k9.name());
 					params.put("title", CommonContentTypeEnum._9k9.getDesc());
 					s.setParams(params.toString());
+				} else if (s.getName().contains("鑷喘绔嬪噺")) {
+					if (hour < 6) {// 0-6鐐逛箣闂翠笉杩涘叆鑷喘绔嬪噺鐨勯〉闈�
+						s.setJumpDetail(jumpDetailV2Service.getByTypeCache("web"));
+						JSONObject params = new JSONObject();
+						params.put("url", configService.get("tlj_own_buy_nogoods"));
+						s.setParams(params.toString());
+					} else {
+						s.setJumpDetail(jumpDetailV2Service.getByTypeCache("tlj_own_buy"));
+						s.setParams(null);
+					}
 				}
 			}
 
@@ -417,8 +477,12 @@
 		activityMap.put("list", JsonUtil.getApiCommonGson().toJson(listActivity));
 
 		// 棣栭〉-鏂瑰舰涓撻锛堝搧鐗屽埜銆佹瘝濠�...锛�
+		String indexBlock = "index_block";
+		if (VersionUtil.greaterThan_1_5_60(acceptData.getPlatform(), acceptData.getVersion()))
+			indexBlock = "index_block_1.5.6";
+
 		JSONObject blockJsonMap = new JSONObject();
-		List<Special> listBlock = specialMapper.listByPlaceKey("index_block", sex);
+		List<Special> listBlock = specialMapper.listByPlaceKey(indexBlock, sex);
 		if (listBlock == null) {
 			listBlock = new ArrayList<Special>();
 		} else if (listBlock.size() > 0) {
@@ -429,7 +493,6 @@
 			}
 		}
 
-		
 		// 鍝佺墝鍒�
 		// >=1.5.40鍚庣殑鐗堟湰鍙互鐢�
 		if (("android".equalsIgnoreCase(acceptData.getPlatform()) && Integer.parseInt(acceptData.getVersion()) > 39)

--
Gitblit v1.8.0