From 28cf328a098334b51a3e9d2d56f983fb8c862211 Mon Sep 17 00:00:00 2001
From: yujian <yujian@163.com>
Date: 星期六, 23 五月 2020 09:54:38 +0800
Subject: [PATCH] 足迹、收藏订单兼容新需求

---
 fanli/src/main/java/com/yeshi/fanli/service/impl/homemodule/SpecialServiceImpl.java |  216 ++++++++++++++++++++++++++++++++++++-----------------
 1 files changed, 147 insertions(+), 69 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 700b80d..e7624a3 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
@@ -12,6 +12,7 @@
 
 import javax.annotation.Resource;
 
+import org.apache.commons.beanutils.PropertyUtils;
 import org.springframework.cache.annotation.Cacheable;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
@@ -25,16 +26,18 @@
 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.CommonShareInfo;
+import com.yeshi.fanli.entity.bus.homemodule.CommonShareInfo.CommonShareInfoEnum;
 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.CommonShareInfoService;
 import com.yeshi.fanli.service.inter.homemodule.SpecialCardService;
 import com.yeshi.fanli.service.inter.homemodule.SpecialPlaceService;
 import com.yeshi.fanli.service.inter.homemodule.SpecialService;
@@ -42,6 +45,7 @@
 import com.yeshi.fanli.util.FilePathEnum;
 import com.yeshi.fanli.util.StringUtil;
 import com.yeshi.fanli.util.VersionUtil;
+import com.yeshi.fanli.vo.homemodule.SpecialVO;
 
 import net.sf.json.JSONObject;
 
@@ -57,6 +61,9 @@
 	@Resource
 	private SpecialCardService specialCardService;
 
+	@Resource
+	private CommonShareInfoService commonShareInfoService;
+	
 	@Resource
 	private JumpDetailV2Service jumpDetailV2Service;
 
@@ -76,7 +83,7 @@
 
 	@Override
 	public void saveObject(MultipartFile file, MultipartFile file2, MultipartFile file3, Special record,
-			String jumpType) throws SpecialException, Exception {
+			String jumpType, CommonShareInfo shareInfo) throws SpecialException, Exception {
 
 		Long cardId = record.getCardId();
 		if (cardId == null) {
@@ -102,11 +109,6 @@
 			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)) {
 			List<JumpDetailV2> listByType = jumpDetailV2Service.listByType(jumpType);
 			if (listByType != null && listByType.size() > 0) {
@@ -115,7 +117,7 @@
 		}
 
 		// 鏃堕棿杞崲
-		conversionTime(record);
+		handleTime(record);
 
 		Long state = record.getState();
 		if (state == null) {
@@ -155,6 +157,8 @@
 			record.setUpdatetime(new Date());
 			specialMapper.insert(record);
 
+			shareInfo.setPid(record.getId());
+			
 			Special s = new Special();
 			s.setId(record.getId());
 			s.setOrderby(Integer.parseInt(s.getId() + ""));
@@ -219,7 +223,13 @@
 
 			record.setUpdatetime(new Date());
 			specialMapper.updateByPrimaryKey(record);
+			
+			shareInfo.setPid(record.getId());
 		}
+		
+		// 娣诲姞琛ュ厖淇℃伅
+		shareInfo.setType(CommonShareInfoEnum.special);
+		commonShareInfoService.save(shareInfo);
 	}
 
 	/**
@@ -227,30 +237,24 @@
 	 * 
 	 * @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));
-				}
-			}
+	private void handleTime(Special record) throws SpecialException, Exception {
+		SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm");
+		
+		String startTime_str = record.getStartTime_str();
+		if (!StringUtil.isNullOrEmpty(startTime_str)) {
+			startTime_str = startTime_str.replaceAll("T", " ");
+			record.setStartTime(format.parse(startTime_str));
+		}
+		
+		String endTime_str = record.getEndTime_str();
+		if (!StringUtil.isNullOrEmpty(endTime_str)) {
+			endTime_str = endTime_str.replaceAll("T", " ");
+			record.setEndTime(format.parse(endTime_str));
+		}
+		
+		if (record.getEndTime() != null && record.getStartTime() != null
+				&& record.getStartTime().getTime() > record.getEndTime().getTime()) {
+			throw new SpecialException(1, "璧峰鏃堕棿涓嶈兘灏忎簬缁撴潫鏃堕棿");
 		}
 	}
 
@@ -354,6 +358,8 @@
 			if (!StringUtil.isNullOrEmpty(subPicture)) {
 				COSManager.getInstance().deleteFile(subPicture);
 			}
+			
+			commonShareInfoService.deleteByPidAndType(special.getId(), CommonShareInfoEnum.special.name());
 		}
 
 		if (listSpecial != null)
@@ -380,66 +386,92 @@
 			if (!StringUtil.isNullOrEmpty(subPicture)) {
 				COSManager.getInstance().deleteFile(subPicture);
 			}
+			
+			commonShareInfoService.deleteByPidAndType(special.getId(), CommonShareInfoEnum.special.name());
 		}
 
 		return specialMapper.deleteBatchByCardID(list);
 	}
 
 	@Override
-	public List<Special> listQueryByCard(long start, int count, Long card, String key, Integer sex) {
-
+	public List<SpecialVO> listQueryByCard(long start, int count, Long card, String key, Integer sex) {
 		List<Special> list = specialMapper.listQueryByCard(start, count, card, key, sex);
-		if (list == null || list.size() == 0) {
-			return list;
+		if (list == null) {
+			return null;
 		}
 
-		// 璺宠浆閾炬帴
+	    List<SpecialVO> listvo = new ArrayList<SpecialVO>();
 		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("");
+			SpecialVO specialVO = new SpecialVO();
+			try {
+				PropertyUtils.copyProperties(specialVO, special);
+			} catch (Exception e) {
+				e.printStackTrace();
+				continue;
+			}
+			
+			if (specialVO.getState() != null && specialVO.getState().longValue() == 0) {
+				specialVO.setState(1L);
 			} else {
-				special.setTimeTask(true);
-
+				specialVO.setState(0L);
+			}
+			
+			Date startTime = specialVO.getStartTime();
+			Date endTime = specialVO.getEndTime();
+			if (startTime == null && endTime == null) {
+				specialVO.setStartTime_str("");
+				specialVO.setEndTime_str("");
+			} else {
 				SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm");
 				if (startTime == null) {
-					special.setStartTime_str("");
+					specialVO.setStartTime_str("");
 				} else {
-					special.setStartTime_str(sdf.format(startTime));
+					specialVO.setStartTime_str(sdf.format(startTime));
 				}
 
 				if (endTime == null) {
-					special.setEndTime_str("");
+					specialVO.setEndTime_str("");
 				} else {
-					special.setEndTime_str(sdf.format(endTime));
+					specialVO.setEndTime_str(sdf.format(endTime));
 				}
 			}
 
-			String params = special.getParams();
+			String params = specialVO.getParams();
 			if (StringUtil.isNullOrEmpty(params)) {
-				special.setParams("");
+				specialVO.setParams("");
 			}
 
-			String remark = special.getRemark();
+			String remark = specialVO.getRemark();
 			if (StringUtil.isNullOrEmpty(remark)) {
-				special.setRemark("");
+				specialVO.setRemark("");
 			}
 
-			JumpDetailV2 jumpDetail = special.getJumpDetail();
+			JumpDetailV2 jumpDetail = specialVO.getJumpDetail();
 			if (jumpDetail == null) {
 				// 榛樿鏈�夋嫨
 				JumpDetailV2 jumpDetailV2 = new JumpDetailV2();
 				jumpDetailV2.setName("-鏈�夋嫨-");
 				jumpDetailV2.setType("default");
-				special.setJumpDetail(jumpDetailV2);
+				specialVO.setJumpDetail(jumpDetailV2);
 			}
+			
+			// 鍒嗕韩琛ュ厖淇℃伅
+			CommonShareInfo info = commonShareInfoService.getByPidAndType(specialVO.getId(),
+					CommonShareInfoEnum.special.name());
+			if (info == null) {
+				specialVO.setNeedSpin(false);
+				specialVO.setComment("");
+			} else {
+				specialVO.setNeedSpin(info.getNeedSpin());
+				if (StringUtil.isNullOrEmpty(info.getComment())) {
+					specialVO.setComment("");
+				} else {
+					specialVO.setComment(info.getComment());
+				}
+			}
+			listvo.add(specialVO);
 		}
-		return list;
+		return listvo;
 	}
 
 	@Override
@@ -449,22 +481,24 @@
 
 	@Override
 	@Cacheable(value = "specialCache", key = "'listBySystemAndCard-'+#card+'-'+#systemId")
-	public List<Special> listBySystemAndCard(String card, Long systemId) {
-		return specialMapper.listBySystemAndCard(card, systemId);
+	public List<SpecialVO> listBySystemAndCard(String card, Long systemId) {
+		List<Special> specialList = specialMapper.listBySystemAndCard(card, systemId);
+		return transformVO(specialList);
 	}
 
 	@Override
 	@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);
+	public List<SpecialVO> listPageBySystemAndCard(long start, int count, String card, Long systemId) {
+		List<Special> specialList = specialMapper.listPageBySystemAndCard(start, count, card, systemId);
+		return transformVO(specialList);
 	}
 
 	@Override
 	@Cacheable(value = "specialCache", key = "'listByVersion-'+#start+'-'+#count+'-'+#card+'-'+#platform+'-'+#versionCode")
-	public List<Special> listByVersion(long start, int count, String card, String platform, Integer versionCode) {
+	public List<SpecialVO> 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;
+		return transformVO(specialList);
 	}
 
 	/**
@@ -565,7 +599,7 @@
 
 		// 鏁版嵁澶勭悊
 //		handlelist(listArc);
-		arcMap.put("list", JsonUtil.getApiCommonGson().toJson(listArc));
+		arcMap.put("list", JsonUtil.getApiCommonGson().toJson(transformVO(listArc)));
 
 		// 棣栭〉-娲诲姩鍖哄煙锛堝コ鐜嬭妭锛�
 		JSONObject activityMap = new JSONObject();
@@ -591,7 +625,7 @@
 
 		handlelist(listActivity);
 
-		activityMap.put("list", JsonUtil.getApiCommonGson().toJson(listActivity));
+		activityMap.put("list", JsonUtil.getApiCommonGson().toJson(transformVO(listActivity)));
 
 		// 棣栭〉-鏂瑰舰涓撻锛堝搧鐗屽埜銆佹瘝濠�...锛�
 		String indexBlock = "index_block";
@@ -624,7 +658,7 @@
 
 		// 鏁版嵁澶勭悊
 		handlelist(listBlock);
-		blockJsonMap.put("list", JsonUtil.getApiCommonGson().toJson(listBlock));
+		blockJsonMap.put("list", JsonUtil.getApiCommonGson().toJson(transformVO(listBlock)));
 
 		JSONObject root = new JSONObject();
 		root.put("arcArea", arcMap);
@@ -651,10 +685,53 @@
 
 	@Override
 	@Cacheable(value = "specialCache", key = "'listByPlaceKeyHasLabel'+#start+'-'+#platform+'-'+#versionCode+'-'+#list")
-	public List<Special> listByPlaceKeyHasLabel(long start, int count, List<String> list, Integer platform,
+	public List<SpecialVO> listByPlaceKeyHasLabel(long start, int count, List<String> list, Integer platform,
 			Integer versionCode) {
-		return specialMapper.listByPlaceKeyHasLabel(start, count, list, null, platform, versionCode);
+		List<Special> listSpecial =  specialMapper.listByPlaceKeyHasLabel(start, count, list, null,
+				platform, versionCode);
+		return 	transformVO(listSpecial);
 	}
+	
+	
+	/**
+	 * 杞崲VO
+	 * @param list
+	 * @return
+	 */
+	private List<SpecialVO> transformVO(List<Special> list) {
+		List<SpecialVO> listVo = new ArrayList<SpecialVO>();
+		if (list != null && list.size() > 0) {
+			for (Special special: list) {
+				SpecialVO specialVO = new SpecialVO();
+				try {
+					PropertyUtils.copyProperties(specialVO, special);
+				} catch (Exception e) {
+					e.printStackTrace();
+					continue;
+				}
+			
+				// 璺宠浆娲诲姩杩囨浮椤�
+				CommonShareInfo info = commonShareInfoService.getByPidAndType(specialVO.getId(), 
+						CommonShareInfoEnum.special.name());
+				if (info != null && !StringUtil.isNullOrEmpty(info.getComment())) {
+					String link = configService.get(ConfigKeyEnum.activityDetailLink.getKey()) + "?type=%s&id=%s";
+					link = String.format(link, CommonShareInfoEnum.special.name(),specialVO.getId());
+					
+					JSONObject params = new JSONObject();
+					params.put("url", link);
+					
+					specialVO.setComment(info.getComment());
+					specialVO.setParams(params.toString());
+					specialVO.setJumpDetail(jumpDetailV2Service.getByTypeCache("web"));
+				}
+				listVo.add(specialVO);
+			}
+		}
+		return listVo;
+	}
+	
+	
+	
 
 	/**
 	 * 澶勭悊 鏁版嵁
@@ -744,6 +821,7 @@
 		Special updateObj = new Special();
 		updateObj.setId(id);
 		updateObj.setState(state);
+		updateObj.setJumpLogin(resultObj.isJumpLogin());
 		specialMapper.updateByPrimaryKeySelective(updateObj);
 	}
 	

--
Gitblit v1.8.0