From d844a30a240603daab46e8b2b32b01cd90f1272e Mon Sep 17 00:00:00 2001
From: yujian <yujian@163.com>
Date: 星期四, 23 四月 2020 09:59:31 +0800
Subject: [PATCH] 会员升级调整

---
 fanli/src/main/java/com/yeshi/fanli/service/impl/homemodule/HomeNavbarServiceImpl.java |  109 +++++++++++++++++++++++++++++-------------------------
 1 files changed, 58 insertions(+), 51 deletions(-)

diff --git a/fanli/src/main/java/com/yeshi/fanli/service/impl/homemodule/HomeNavbarServiceImpl.java b/fanli/src/main/java/com/yeshi/fanli/service/impl/homemodule/HomeNavbarServiceImpl.java
index 820aeb2..a47bb46 100644
--- a/fanli/src/main/java/com/yeshi/fanli/service/impl/homemodule/HomeNavbarServiceImpl.java
+++ b/fanli/src/main/java/com/yeshi/fanli/service/impl/homemodule/HomeNavbarServiceImpl.java
@@ -20,6 +20,7 @@
 import com.yeshi.fanli.entity.bus.homemodule.HomeNavbar.NavbarTypeEnum;
 import com.yeshi.fanli.entity.bus.homemodule.SwiperBanner;
 import com.yeshi.fanli.exception.homemodule.HomeNavbarException;
+import com.yeshi.fanli.exception.homemodule.SpecialException;
 import com.yeshi.fanli.service.inter.goods.GoodsClassService;
 import com.yeshi.fanli.service.inter.homemodule.HomeNavbarService;
 import com.yeshi.fanli.service.inter.homemodule.SwiperBannerService;
@@ -69,12 +70,6 @@
 			throw new HomeNavbarException(1, "瀵艰埅鍚嶇О涓嶈兘涓虹┖");
 		}
 		
-		String startTime_str = record.getStartTime_str();
-		if (record.isTimeTask() && (startTime_str == null || startTime_str.length() == 0)) {
-			throw new HomeNavbarException(1, "鎺у埗鏃堕棿涓嶈兘涓虹┖");
-		}
-		
-		
 		Integer sex = null;
 		NavbarTypeEnum type = record.getType();
 		if (NavbarTypeEnum.category.equals(type)) {
@@ -108,7 +103,7 @@
 		}
 		
 		// 鏃堕棿杞崲
-		conversionTime(record);
+		handleTime(record);
 		
 		// 鍥剧墖涓婁紶
 		String picture = null;
@@ -201,37 +196,33 @@
 		}
 	}
 	
-
+	
 	/**
 	 * web娈垫椂闂磋浆鎹�
+	 * 
 	 * @param record
 	 */
-	public void conversionTime(HomeNavbar record) throws HomeNavbarException, 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(HomeNavbar 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, "璧峰鏃堕棿涓嶈兘灏忎簬缁撴潫鏃堕棿");
 		}
 	}
+	
 	
 	@Override
 	public void updateOrder(Long id, Integer moveType, Integer sex) throws HomeNavbarException, Exception{
@@ -299,30 +290,21 @@
 			return null;
 		}
 		
+		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm");
+		
 		for (HomeNavbar homeNavbar: listObj) {
-				
 			Date startTime = homeNavbar.getStartTime();
-			Date endTime = homeNavbar.getEndTime();
-			
-			if (startTime == null && endTime == null) {
-				homeNavbar.setTimeTask(false);
+			if (startTime == null) {
 				homeNavbar.setStartTime_str("");
+			} else {
+				homeNavbar.setStartTime_str(sdf.format(startTime));
+			}
+			
+			Date endTime = homeNavbar.getEndTime();
+			if (endTime == null) {
 				homeNavbar.setEndTime_str("");
 			} else {
-				homeNavbar.setTimeTask(true);
-				
-				SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm");
-				if (startTime == null) {
-					homeNavbar.setStartTime_str("");
-				} else {
-					homeNavbar.setStartTime_str(sdf.format(startTime));
-				}
-				
-				if (endTime == null) {
-					homeNavbar.setEndTime_str("");
-				} else {
-					homeNavbar.setEndTime_str(sdf.format(endTime));
-				}
+				homeNavbar.setEndTime_str(sdf.format(endTime));
 			}
 			
 			Long classId = homeNavbar.getClassId();
@@ -377,4 +359,29 @@
 		return homeNavbarMapper.getEffectiveByClassId(classId);
 	}
 
+	
+	@Override
+	public void switchState(Long id) throws HomeNavbarException {
+		if (id == null) {
+			throw new HomeNavbarException(1, "璇蜂紶閫掓纭弬鏁�");
+		}
+		
+		HomeNavbar resultObj = homeNavbarMapper.selectByPrimaryKey(id);
+		if (resultObj == null) {
+			throw new HomeNavbarException(1, "姝ゅ唴瀹瑰凡涓嶅瓨鍦�");
+		}
+		
+		Integer state = resultObj.getState();
+		if (state == null || state == 0) {
+			state = 1;
+		} else {
+			state = 0;
+		}
+		
+		HomeNavbar updateObj = new HomeNavbar();
+		updateObj.setId(id);
+		updateObj.setState(state);
+		homeNavbarMapper.updateByPrimaryKeySelective(updateObj);
+	}
+	
 }

--
Gitblit v1.8.0