From f4a0f2acc63d7785eab108419a4e16f5f688cb95 Mon Sep 17 00:00:00 2001
From: yujian <yujian@163.com>
Date: 星期六, 18 一月 2020 12:06:27 +0800
Subject: [PATCH] 用户注册信息

---
 fanli/src/main/java/com/yeshi/fanli/service/impl/homemodule/SpecialServiceImpl.java |  339 +++++++++++++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 306 insertions(+), 33 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 e348fd5..52819b9 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
@@ -1,9 +1,13 @@
 package com.yeshi.fanli.service.impl.homemodule;
 
 import java.io.InputStream;
+import java.text.SimpleDateFormat;
 import java.util.ArrayList;
+import java.util.Calendar;
 import java.util.Date;
+import java.util.HashSet;
 import java.util.List;
+import java.util.Set;
 import java.util.UUID;
 
 import javax.annotation.Resource;
@@ -17,21 +21,29 @@
 
 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.AdActivityVersionControl;
+import com.yeshi.fanli.entity.bus.homemodule.AdActivityVersionControl.AdActivityType;
 import com.yeshi.fanli.entity.bus.homemodule.Special;
 import com.yeshi.fanli.entity.common.JumpDetailV2;
+import com.yeshi.fanli.entity.system.ConfigKeyEnum;
+import com.yeshi.fanli.exception.banner.SwiperPictureException;
+import com.yeshi.fanli.exception.homemodule.HomeNavbarException;
 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.AdActivityVersionControlService;
 import com.yeshi.fanli.service.inter.homemodule.SpecialCardService;
 import com.yeshi.fanli.service.inter.homemodule.SpecialPlaceService;
 import com.yeshi.fanli.service.inter.homemodule.SpecialService;
 import com.yeshi.fanli.util.Constant;
+import com.yeshi.fanli.util.FilePathEnum;
 import com.yeshi.fanli.util.StringUtil;
 import com.yeshi.fanli.util.VersionUtil;
 
 import net.sf.json.JSONObject;
-import sun.security.krb5.internal.ccache.CCacheInputStream;
 
 @Service
 public class SpecialServiceImpl implements SpecialService {
@@ -50,6 +62,12 @@
 
 	@Resource
 	private ConfigService configService;
+
+	@Resource
+	private AppVersionService appVersionService;
+
+	@Resource
+	private AdActivityVersionControlService adActivityVersionControlService;
 
 	@Override
 	public Special selectByPrimaryKey(Long id) {
@@ -70,11 +88,23 @@
 			throw new SpecialException(1, "涓撻鍚嶇О涓嶈兘涓虹┖");
 		}
 
+		Integer sex = record.getSex();
+		if (sex == null) {
+			throw new SpecialException(1, "鎬у埆涓嶈兘涓虹┖");
+		}
+
 		String params = record.getParams();
 		if (params == null || params.trim().length() == 0 || "null".equalsIgnoreCase(params)) {
 			record.setParams(null);
 		} else if (!StringUtil.isJson(params)) {
 			throw new SpecialException(1, "璺宠浆鍙傛暟闈濲SON鏍煎紡");
+		} else {
+			record.setParams(params.trim());
+		}
+
+		String startTime_str = record.getStartTime_str();
+		if (record.isTimeTask() && (startTime_str == null || startTime_str.length() == 0)) {
+			throw new SpecialException(1, "鎺у埗鏃堕棿涓嶈兘涓虹┖");
 		}
 
 		if (!StringUtil.isNullOrEmpty(jumpType)) {
@@ -83,6 +113,9 @@
 				record.setJumpDetail(listByType.get(0));
 			}
 		}
+
+		// 鏃堕棿杞崲
+		conversionTime(record);
 
 		Long state = record.getState();
 		if (state == null) {
@@ -113,12 +146,21 @@
 			record.setPicture(picture);
 			record.setSubPicture(subPicture);
 
-			int maxOrder = specialMapper.getMaxOrderByCard(cardId);
-			record.setOrderby(maxOrder + 1);
+			// 鎺掑簭
+			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);
@@ -171,9 +213,44 @@
 			}
 
 			record.setOrderby(resultObj.getOrderby());
+			record.setOrderMan(resultObj.getOrderMan());
+			record.setOrderWoman(resultObj.getOrderWoman());
 			record.setCreatetime(resultObj.getCreatetime());
+
 			record.setUpdatetime(new Date());
 			specialMapper.updateByPrimaryKey(record);
+		}
+	}
+
+	/**
+	 * web娈垫椂闂磋浆鎹�
+	 * 
+	 * @param record
+	 */
+	public void conversionTime(Special record) throws SpecialException, Exception {
+		// 鏄惁鏃堕棿鎺у埗
+		if (!record.isTimeTask()) {
+			record.setStartTime(null);
+			record.setEndTime(null);
+		} else {
+			String startTime_str = record.getStartTime_str();
+			String endTime_str = record.getEndTime_str();
+
+			if ((startTime_str == null || startTime_str.trim().length() == 0)
+					&& (endTime_str == null || endTime_str.trim().length() == 0)) {
+				throw new HomeNavbarException(1, "璇疯緭鍏ユ帶鍒舵椂闂�");
+			} else {
+				SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm");
+				if (startTime_str != null && startTime_str.trim().length() > 0) {
+					startTime_str = startTime_str.replaceAll("T", " ");
+					record.setStartTime(format.parse(startTime_str));
+				}
+
+				if (endTime_str != null && endTime_str.trim().length() > 0) {
+					endTime_str = endTime_str.replaceAll("T", " ");
+					record.setEndTime(format.parse(endTime_str));
+				}
+			}
 		}
 	}
 
@@ -192,7 +269,7 @@
 		String type = contentType.substring(contentType.indexOf("/") + 1);
 
 		// 鏂囦欢璺緞
-		String filePath = "/img/special/" + UUID.randomUUID().toString().replace("-", "") + "." + type;
+		String filePath =FilePathEnum.special.getPath() + UUID.randomUUID().toString().replace("-", "") + "." + type;
 		// 鎵ц涓婁紶
 		String fileLink = COSManager.getInstance().uploadFile(inputStream, filePath).getUrl();
 
@@ -212,10 +289,10 @@
 	}
 
 	@Override
-	@Transactional
-	public void updateOrder(Long id, Integer moveType) throws SpecialException {
+	@Transactional(rollbackFor=Exception.class)
+	public void updateOrder(Long id, Integer moveType, Integer sex) throws SpecialException {
 
-		if (id == null || moveType == null || (!moveType.equals(1) && !moveType.equals(-1))) {
+		if (id == null || moveType == null || (!moveType.equals(1) && !moveType.equals(-1)) || sex == null) {
 			throw new SpecialException(1, "璇蜂紶閫掓纭弬鏁�");
 		}
 
@@ -224,28 +301,47 @@
 			throw new SpecialException(1, "姝ゅ唴瀹瑰凡涓嶅瓨鍦�");
 		}
 
-		Integer order = resultObj.getOrderby();
 		Long cardId = resultObj.getCardId();
-
 		// 鑾峰彇浜ゆ崲瀵硅薄
-		Special exchangeObject = specialMapper.getOrderByCardID(cardId, moveType, order);
-		if (exchangeObject == null) {
-			if (moveType == 1) {
-				throw new SpecialException(1, "鍦ㄧ浉鍚屼娇鐢ㄥ湴鏂逛腑浼樺厛绾у凡缁忔渶浣庝簡");
-			} else {
-				throw new SpecialException(1, "鍦ㄧ浉鍚屼娇鐢ㄥ湴鏂逛腑浼樺厛绾у凡缁忔渶楂樹簡");
+		Special exchangeObject = null;
+		if (Special.SEX_ALL == sex || Special.SEX_DEFAULT == sex) {
+			Integer orderby = resultObj.getOrderby();
+			exchangeObject = specialMapper.getOrderByCardID(cardId, moveType, orderby, sex);
+			if (exchangeObject == null) {
+				throw new SpecialException(1, "娌℃湁鎵惧埌鍙氦鎹㈢殑浣嶇疆");
 			}
-		}
 
-		resultObj.setOrderby(exchangeObject.getOrderby());
-		exchangeObject.setOrderby(order);
+			resultObj.setOrderby(exchangeObject.getOrderby());
+			exchangeObject.setOrderby(orderby);
+		} 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) {
+			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);
 	}
 
 	@Override
-	@Transactional
+	@Transactional(rollbackFor = Exception.class)
 	public int deleteBatchByPrimaryKey(List<Long> list) throws Exception {
 		List<Special> listSpecial = specialMapper.queryByListPrimaryKey(list);
 		for (Special special : listSpecial) {
@@ -259,6 +355,15 @@
 				COSManager.getInstance().deleteFile(subPicture);
 			}
 		}
+		
+		if (listSpecial != null)
+			for (Special special : listSpecial) {
+				List<AdActivityVersionControl> versionList = adActivityVersionControlService
+						.listByTypeAndSourceId(AdActivityType.special, special.getId());
+				if (versionList != null)
+					for (AdActivityVersionControl control : versionList)
+						adActivityVersionControlService.deleteByPrimaryKey(control.getId());
+			}
 		return specialMapper.deleteBatchByPrimaryKey(list);
 	}
 
@@ -281,15 +386,40 @@
 	}
 
 	@Override
-	public List<Special> listQueryByCard(long start, int count, Long card, String key) {
+	public List<Special> listQueryByCard(long start, int count, Long card, String key, Integer sex) {
 
-		List<Special> list = specialMapper.listQueryByCard(start, count, card, key);
+		List<Special> list = specialMapper.listQueryByCard(start, count, card, key, sex);
 		if (list == null || list.size() == 0) {
 			return list;
 		}
 
 		// 璺宠浆閾炬帴
 		for (Special special : list) {
+
+			Date startTime = special.getStartTime();
+			Date endTime = special.getEndTime();
+
+			if (startTime == null && endTime == null) {
+				special.setTimeTask(false);
+				special.setStartTime_str("");
+				special.setEndTime_str("");
+			} else {
+				special.setTimeTask(true);
+
+				SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm");
+				if (startTime == null) {
+					special.setStartTime_str("");
+				} else {
+					special.setStartTime_str(sdf.format(startTime));
+				}
+
+				if (endTime == null) {
+					special.setEndTime_str("");
+				} else {
+					special.setEndTime_str(sdf.format(endTime));
+				}
+			}
+
 			String params = special.getParams();
 			if (StringUtil.isNullOrEmpty(params)) {
 				special.setParams("");
@@ -313,29 +443,84 @@
 	}
 
 	@Override
-	public long countlistQueryByCard(Long card, String key) {
-		return specialMapper.countlistQueryByCard(card, key);
+	public long countlistQueryByCard(Long card, String key, Integer sex) {
+		return specialMapper.countlistQueryByCard(card, key, sex);
 	}
 
 	@Override
-	@Cacheable(value = "configCache", key = "'listBySystemAndCard-'+#card+'-'+#systemId")
+	@Cacheable(value = "specialCache", key = "'listBySystemAndCard-'+#card+'-'+#systemId")
 	public List<Special> listBySystemAndCard(String card, Long systemId) {
 		return specialMapper.listBySystemAndCard(card, systemId);
 	}
 
 	@Override
-	@Cacheable(value = "configCache", key = "'listPageBySystemAndCard-'+#start+'-'+#count+'-'+#card+'-'+#systemId")
+	@Cacheable(value = "specialCache", key = "'listPageBySystemAndCard-'+#start+'-'+#count+'-'+#card+'-'+#systemId")
 	public List<Special> listPageBySystemAndCard(long start, int count, String card, Long systemId) {
 		return specialMapper.listPageBySystemAndCard(start, count, card, systemId);
 	}
 
 	@Override
-	@Cacheable(value = "configCache", key = "'listCacheSpecialToIndex'+#acceptData.platform+'-'+#acceptData.version")
-	public JSONObject listCacheSpecialToIndex(AcceptData acceptData) throws Exception {
+	@Cacheable(value = "specialCache", key = "'listByVersion-'+#start+'-'+#count+'-'+#card+'-'+#platform+'-'+#versionCode")
+	public List<Special> listByVersion(long start, int count, String card, String platform, Integer versionCode) {
+		List<Special> specialList = specialMapper.listByPlaceKey(card, null, null, null);
+		filterSpecial(specialList, platform, versionCode);
+		return specialList;
+	}
+
+	/**
+	 * 涓撻鐗堟湰杩囨护
+	 * 
+	 * @param list
+	 * @param platform
+	 * @param versionCode
+	 */
+	private void filterSpecial(List<Special> list, String platform, int versionCode) {
+		if (list == null || list.size() == 0)
+			return;
+		AppVersionInfo app = appVersionService.getClientVersion(platform, versionCode);
+		if (app == null) {
+			list.clear();
+			return;
+		}
+		List<Long> versionIdList = new ArrayList<>();
+		versionIdList.add(app.getId());
+		List<Long> sourceIdList = new ArrayList<>();
+		for (Special special : list) {
+			sourceIdList.add(special.getId());
+		}
+
+		Set<Long> sourceIds = adActivityVersionControlService.filterSourceIdByVersion(sourceIdList,
+				AdActivityType.special, versionIdList);
+		for (int i = 0; i < list.size(); i++) {
+			if (!sourceIds.contains(list.get(i).getId())) {
+				list.remove(i--);
+			}
+		}
+	}
+
+	@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");
+
+		String indexArc = "index_arc";
+		if (VersionUtil.greaterThan_1_6_5(acceptData.getPlatform(), acceptData.getVersion()))
+			indexArc = "index_arc_1.6.5";
+		else 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";
+
+		String platform = acceptData.getPlatform();
+		int platformCode = Constant.getPlatformCode(platform);
+		int version = Integer.parseInt(acceptData.getVersion());
+
+		List<Special> listArc = specialMapper.listByPlaceKey(indexArc, sex, platformCode, version);
+		filterSpecial(listArc, platform, version);
 		if (listArc == null) {
 			listArc = new ArrayList<Special>();
 		} else if (listArc.size() > 0) {
@@ -346,8 +531,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"));
@@ -355,6 +542,18 @@
 					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(ConfigKeyEnum.tljOwnBuyNogoods.getKey()));
+						s.setParams(params.toString());
+					} else {
+						// 鏌ヨ涓撻璇︽儏
+						Special special = specialMapper.selectByPrimaryKey(s.getId());
+						s.setJumpDetail(special.getJumpDetail());
+						s.setParams(special.getParams());
+					}
 				}
 			}
 
@@ -369,8 +568,10 @@
 				&& configService.iosOnLining(Integer.parseInt(acceptData.getVersion()))) {
 			// 濡傛灉IOS褰撳墠鐗堟湰澶勪簬瀹℃牳鐘舵�佸氨涓嶈繑鍥�
 		} else {
-			listActivity = specialMapper.listByPlaceKey("index_activity");
+			listActivity = specialMapper.listByPlaceKey("index_activity", null, platformCode, version);
 		}
+
+		filterSpecial(listActivity, platform, version);
 
 		if (listActivity == null) {
 			listActivity = new ArrayList<Special>();
@@ -387,8 +588,13 @@
 		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");
+		List<Special> listBlock = specialMapper.listByPlaceKey(indexBlock, sex, platformCode, version);
+		filterSpecial(listBlock, platform, version);
 		if (listBlock == null) {
 			listBlock = new ArrayList<Special>();
 		} else if (listBlock.size() > 0) {
@@ -422,8 +628,26 @@
 	}
 
 	@Override
-	public List<Special> listByPlaceKey(String placeKey) {
-		return specialMapper.listByPlaceKey(placeKey);
+	public List<Special> listByPlaceKey(String placeKey, Integer platform, Integer versionCode) {
+		return specialMapper.listByPlaceKey(placeKey, null, platform, versionCode);
+	}
+
+	@Override
+	public List<Special> listByPlaceKeyList(long start, int count, List<String> list, Integer platform,
+			Integer versionCode) {
+		return specialMapper.listByPlaceKeyList(start, count, list, null, platform, versionCode);
+	}
+
+	@Override
+	public long countByPlaceKeyList(List<String> list, Integer platform, Integer versionCode) {
+		return specialMapper.countByPlaceKeyList(list, null, platform, versionCode);
+	}
+
+	@Override
+	@Cacheable(value = "specialCache", key = "'listByPlaceKeyHasLabel'+#start+'-'+#platform+'-'+#versionCode+'-'+#list")
+	public List<Special> listByPlaceKeyHasLabel(long start, int count, List<String> list, Integer platform,
+			Integer versionCode) {
+		return specialMapper.listByPlaceKeyHasLabel(start, count, list, null, platform, versionCode);
 	}
 
 	/**
@@ -443,4 +667,53 @@
 			}
 		}
 	}
+
+	@Transactional(rollbackFor = Exception.class)
+	@Override
+	public void setVersions(Long specialId, List<Long> versions) throws Exception {
+		Special special = selectByPrimaryKey(specialId);
+		if (special == null) {
+			throw new Exception("涓撻涓嶅瓨鍦�");
+		}
+
+		Set<Long> oldSet = new HashSet<>();
+
+		List<AdActivityVersionControl> versionList = adActivityVersionControlService
+				.listByTypeAndSourceId(AdActivityType.special, specialId);
+		if (versionList != null) {
+			for (AdActivityVersionControl control : versionList)
+				oldSet.add(control.getVersion().getId());
+		}
+
+		Set<Long> newSet = new HashSet<>();
+
+		for (Long version : versions) {
+			newSet.add(version);
+		}
+
+		Set<Long> delSet = new HashSet<>();
+		delSet.addAll(oldSet);
+		delSet.removeAll(newSet);
+		for (Long versionId : delSet) {
+			adActivityVersionControlService.deleteBySourceAndVersion(specialId, AdActivityType.special, versionId);
+		}
+
+		Set<Long> addSet = new HashSet<>();
+		addSet.addAll(newSet);
+		addSet.removeAll(oldSet);
+
+		// 娣诲姞鏄犲皠
+		for (Long versionId : addSet) {
+			AdActivityVersionControl control = new AdActivityVersionControl();
+			control.setCreateTime(new Date());
+			control.setSourceId(special.getId());
+			control.setType(AdActivityType.special);
+			control.setVersion(new AppVersionInfo(versionId));
+			try {
+				adActivityVersionControlService.addVersionControl(control);
+			} catch (Exception e) {
+				throw new SwiperPictureException(2, e.getMessage());
+			}
+		}
+	}
 }

--
Gitblit v1.8.0