From 60a099a7edfd81a3b10c766e113c019cdef6cd3d Mon Sep 17 00:00:00 2001
From: admin <weikou2014>
Date: 星期三, 13 五月 2020 16:08:59 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/div' into div

---
 fanli/src/main/java/com/yeshi/fanli/service/impl/homemodule/SpecialServiceImpl.java |  188 +++++++++++++++++++++++++++++++---------------
 1 files changed, 125 insertions(+), 63 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 f2f8c16..8a1cc30 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;
@@ -26,20 +27,24 @@
 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.bus.homemodule.SpecialExtra;
 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.SpecialExtraService;
 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 com.yeshi.fanli.vo.homemodule.SpecialVO;
 
 import net.sf.json.JSONObject;
 
@@ -55,6 +60,9 @@
 	@Resource
 	private SpecialCardService specialCardService;
 
+	@Resource
+	private SpecialExtraService specialExtraService;
+	
 	@Resource
 	private JumpDetailV2Service jumpDetailV2Service;
 
@@ -74,7 +82,7 @@
 
 	@Override
 	public void saveObject(MultipartFile file, MultipartFile file2, MultipartFile file3, Special record,
-			String jumpType) throws SpecialException, Exception {
+			String jumpType, SpecialExtra extra) throws SpecialException, Exception {
 
 		Long cardId = record.getCardId();
 		if (cardId == null) {
@@ -96,11 +104,8 @@
 			record.setParams(null);
 		} else if (!StringUtil.isJson(params)) {
 			throw new SpecialException(1, "璺宠浆鍙傛暟闈濲SON鏍煎紡");
-		}
-
-		String startTime_str = record.getStartTime_str();
-		if (record.isTimeTask() && (startTime_str == null || startTime_str.length() == 0)) {
-			throw new SpecialException(1, "鎺у埗鏃堕棿涓嶈兘涓虹┖");
+		} else {
+			record.setParams(params.trim());
 		}
 
 		if (!StringUtil.isNullOrEmpty(jumpType)) {
@@ -111,7 +116,7 @@
 		}
 
 		// 鏃堕棿杞崲
-		conversionTime(record);
+		handleTime(record);
 
 		Long state = record.getState();
 		if (state == null) {
@@ -151,6 +156,8 @@
 			record.setUpdatetime(new Date());
 			specialMapper.insert(record);
 
+			extra.setId(record.getId());
+			
 			Special s = new Special();
 			s.setId(record.getId());
 			s.setOrderby(Integer.parseInt(s.getId() + ""));
@@ -215,7 +222,12 @@
 
 			record.setUpdatetime(new Date());
 			specialMapper.updateByPrimaryKey(record);
+			
+			extra.setId(record.getId());
 		}
+		
+		// 娣诲姞琛ュ厖淇℃伅
+		specialExtraService.saveExtraInfo(extra);
 	}
 
 	/**
@@ -223,30 +235,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, "璧峰鏃堕棿涓嶈兘灏忎簬缁撴潫鏃堕棿");
 		}
 	}
 
@@ -265,7 +271,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();
 
@@ -285,7 +291,7 @@
 	}
 
 	@Override
-	@Transactional(rollbackFor=Exception.class)
+	@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)) || sex == null) {
@@ -351,7 +357,7 @@
 				COSManager.getInstance().deleteFile(subPicture);
 			}
 		}
-		
+
 		if (listSpecial != null)
 			for (Special special : listSpecial) {
 				List<AdActivityVersionControl> versionList = adActivityVersionControlService
@@ -382,60 +388,84 @@
 	}
 
 	@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);
 			}
+			
+			// 琛ュ厖淇℃伅
+			SpecialExtra extra = specialExtraService.selectByPrimaryKey(specialVO.getId());
+			if (extra == null) {
+				specialVO.setNeedSpin(false);
+				specialVO.setComment("");
+			} else {
+				specialVO.setNeedSpin(extra.getNeedSpin());
+				if (StringUtil.isNullOrEmpty(extra.getComment())) {
+					specialVO.setComment("");
+				} else {
+					specialVO.setComment(extra.getComment());
+				}
+			}
+			
+			listvo.add(specialVO);
 		}
-		return list;
+		return listvo;
 	}
 
 	@Override
@@ -542,7 +572,7 @@
 					if (hour < 6) {// 0-6鐐逛箣闂翠笉杩涘叆鑷喘绔嬪噺鐨勯〉闈�
 						s.setJumpDetail(jumpDetailV2Service.getByTypeCache("web"));
 						JSONObject params = new JSONObject();
-						params.put("url", configService.get("tlj_own_buy_nogoods"));
+						params.put("url", configService.get(ConfigKeyEnum.tljOwnBuyNogoods.getKey()));
 						s.setParams(params.toString());
 					} else {
 						// 鏌ヨ涓撻璇︽儏
@@ -551,10 +581,16 @@
 						s.setParams(special.getParams());
 					}
 				}
+
+				if (s.getJumpDetail() != null) {
+					s.getJumpDetail().setNeedLogin(s.isJumpLogin()
+							| (s.getJumpDetail().getNeedLogin() != null && s.getJumpDetail().getNeedLogin()));
+				}
+
 			}
 
 		// 鏁版嵁澶勭悊
-		handlelist(listArc);
+//		handlelist(listArc);
 		arcMap.put("list", JsonUtil.getApiCommonGson().toJson(listArc));
 
 		// 棣栭〉-娲诲姩鍖哄煙锛堝コ鐜嬭妭锛�
@@ -712,4 +748,30 @@
 			}
 		}
 	}
+	
+	@Override
+	public void switchState(Long id) throws SpecialException {
+		if (id == null) {
+			throw new SpecialException(1, "璇蜂紶閫掓纭弬鏁�");
+		}
+		
+		Special resultObj = specialMapper.selectByPrimaryKey(id);
+		if (resultObj == null) {
+			throw new SpecialException(1, "姝ゅ唴瀹瑰凡涓嶅瓨鍦�");
+		}
+		
+		Long state = resultObj.getState();
+		if (state == null || state == 0) {
+			state = 1L;
+		} else {
+			state = 0L;
+		}
+		
+		Special updateObj = new Special();
+		updateObj.setId(id);
+		updateObj.setState(state);
+		updateObj.setJumpLogin(resultObj.isJumpLogin());
+		specialMapper.updateByPrimaryKeySelective(updateObj);
+	}
+	
 }

--
Gitblit v1.8.0