From 23c2ce5f8ab136577c27be4a70819abc5d5f8c39 Mon Sep 17 00:00:00 2001
From: yujian <yujian>
Date: 星期五, 22 三月 2019 11:24:59 +0800
Subject: [PATCH] 轮播图加入时间限制

---
 fanli/src/main/java/com/yeshi/fanli/service/impl/homemodule/SwiperPictureServiceImpl.java |  148 +++++++++++++++++++++++++++++++------------------
 1 files changed, 94 insertions(+), 54 deletions(-)

diff --git a/fanli/src/main/java/com/yeshi/fanli/service/impl/homemodule/SwiperPictureServiceImpl.java b/fanli/src/main/java/com/yeshi/fanli/service/impl/homemodule/SwiperPictureServiceImpl.java
index 2032cb9..53ba772 100644
--- a/fanli/src/main/java/com/yeshi/fanli/service/impl/homemodule/SwiperPictureServiceImpl.java
+++ b/fanli/src/main/java/com/yeshi/fanli/service/impl/homemodule/SwiperPictureServiceImpl.java
@@ -1,6 +1,8 @@
 package com.yeshi.fanli.service.impl.homemodule;
 
 import java.io.InputStream;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
 import java.util.Date;
 import java.util.List;
 import java.util.UUID;
@@ -15,9 +17,9 @@
 
 import com.yeshi.fanli.dao.mybatis.homemodule.SwiperPictureMapper;
 import com.yeshi.fanli.entity.bus.homemodule.SwiperPicture;
-import com.yeshi.fanli.exception.NotExistObjectException;
+import com.yeshi.fanli.entity.common.JumpDetailV2;
 import com.yeshi.fanli.exception.banner.SwiperPictureException;
-import com.yeshi.fanli.service.inter.config.SystemConfigService;
+import com.yeshi.fanli.service.inter.common.JumpDetailV2Service;
 import com.yeshi.fanli.service.inter.homemodule.SwiperPictureService;
 import com.yeshi.fanli.util.StringUtil;
 
@@ -28,17 +30,9 @@
 	private SwiperPictureMapper swiperPictureMapper;
 	
 	@Resource
-	private SystemConfigService systemConfigService;
+	private JumpDetailV2Service jumpDetailV2Service;
 	
-	@Override
-	public int deleteByPrimaryKey(Long id) throws SwiperPictureException{
-		return swiperPictureMapper.deleteByPrimaryKey(id);
-	}
 
-	@Override
-	public int insert(SwiperPicture record) throws SwiperPictureException{
-		return swiperPictureMapper.insert(record);
-	}
 
 	@Override
 	public int insertSelective(SwiperPicture record) throws SwiperPictureException{
@@ -71,9 +65,8 @@
 	}
 
 	
-	
 	@Override
-	public void save(SwiperPicture record) throws SwiperPictureException{
+	public void saveObject(MultipartFile file, SwiperPicture record, String jumpType) throws SwiperPictureException, Exception{
 		
 		if (record == null) {
 			throw new SwiperPictureException(1, "鍙傛暟涓嶈兘涓虹┖");
@@ -85,34 +78,61 @@
 		}
 		
 		String params = record.getParams();
-		if (!StringUtil.isNullOrEmpty(params)) {
-			try {
-				String jumpValue = systemConfigService.get("jump");
-				if (StringUtil.isNullOrEmpty(jumpValue)) {
-					jumpValue = "{\"url\":\"#\"}";
-				}
-				params = jumpValue.replace("#", params);
-				
-			} catch (NotExistObjectException e) {
-				e.printStackTrace();
+		if ((params != null && params.trim().length() == 0) || "null".equalsIgnoreCase(params) ) {
+			record.setParams(null);
+		}
+		
+		if (!StringUtil.isNullOrEmpty(jumpType)) {
+			List<JumpDetailV2> listByType = jumpDetailV2Service.listByType(jumpType);
+			if (listByType !=null && listByType.size() > 0) {
+				record.setJumpDetail(listByType.get(0));
+			} 
+		}
+		
+		try {
+			SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm");
+			String startTime_str = record.getStartTime_str();
+			if (startTime_str != null && startTime_str.trim().length() > 0) {
+				startTime_str = startTime_str.replaceAll("T", " ");
+				record.setStartTime(format.parse(startTime_str));
 			}
+			
+			String endTime_str = record.getEndTime_str();
+			if (endTime_str != null && endTime_str.trim().length() > 0) {
+				endTime_str = endTime_str.replaceAll("T", " ");
+				record.setEndTime(format.parse(endTime_str));
+			}
+			
+		} catch (ParseException e) {
+			e.printStackTrace();
+		}
+		
+		
+		String picture = null;
+		if (file != null) {
+			picture = uploadPicture(file);
 		}
 		
 		Long id = record.getId();
 		
 		if (id == null) {
-			// 鏂板
-			
 			int maxOrder = swiperPictureMapper.getMaxOrderByBannerID(bannerId);
 			record.setOrder(maxOrder + 1);
+			
+			Integer state = record.getState();
 			// 榛樿鍋滅敤
-			record.setState(1);
-			// 榛樿闈炵郴缁熸帶鍒�
-			record.setAutoControl(1);
-			// 榛樿闈炵櫥闄�
-			record.setJumpNeedLogin(false);
+			if (state == null) {
+				record.setState(1);
+			}
+			
+			Integer autoControl = record.getAutoControl();
+			if (autoControl == null) {
+				// 榛樿闈炵郴缁熸帶鍒�
+				record.setAutoControl(1);
+			}
 			record.setCreatetime(new Date());
 			record.setUpdatetime(new Date());
+			record.setSrc(picture);
 			
 			swiperPictureMapper.insert(record);
 		} else {
@@ -122,13 +142,57 @@
 				throw new SwiperPictureException(1, "鍙傛暟涓嶈兘涓虹┖");
 			}
 			
+			if (picture != null && picture.trim().length() > 0) {
+				// 鍒犻櫎宸插瓨鍦ㄥ浘鐗�
+				removePicture(resultObj);
+				
+				record.setSrc(picture);
+			} else {
+				record.setSrc(resultObj.getSrc());
+			}
+			
 			record.setOrder(resultObj.getOrder());
 			record.setCreatetime(resultObj.getCreatetime());
 			record.setUpdatetime(new Date());
+			
 			swiperPictureMapper.updateByPrimaryKey(record);
 		}
 	}
 	
+
+	/**
+	 * 涓婁紶鍥剧墖
+	 * @param file
+	 * @return
+	 * @throws Exception
+	 */
+	public String uploadPicture(MultipartFile file) throws Exception {
+		
+		// 鏂囦欢瑙f瀽 
+		InputStream inputStream = file.getInputStream();
+		String contentType = file.getContentType();
+		String type = contentType.substring(contentType.indexOf("/") + 1);
+	
+		// 鏂囦欢璺緞
+		String filePath="/img/swiperPic/"+UUID.randomUUID().toString().replace("-", "") + "." + type;
+		// 鎵ц涓婁紶
+		String fileLink= COSManager.getInstance().uploadFile(inputStream, filePath).getUrl();
+		
+		return fileLink;
+	}
+	
+	
+	/**
+	 * 鍒犻櫎鍥剧墖-涓嶆洿鏂版暟鎹簱
+	 * @param record
+	 * @throws Exception
+	 */
+	public void removePicture(SwiperPicture record) throws Exception {
+		String picture = record.getSrc();
+		if (picture != null && picture.trim().length() > 0) {
+			COSManager.getInstance().deleteFile(picture);
+		}
+	}
 	
 	@Override
 	@Transactional
@@ -155,30 +219,6 @@
 		return swiperPictureMapper.queryByListBannerID(list);
 	}
 
-	@Override
-	public void uploadPicture(MultipartFile file, SwiperPicture record) throws Exception {
-		
-		InputStream inputStream = file.getInputStream();
-		String contentType = file.getContentType();
-		String type = contentType.substring(contentType.indexOf("/") + 1);
-		// 涓婁紶鏂囦欢鐩稿浣嶇疆
-		String fileUrl="swiperPic/"+UUID.randomUUID().toString().replace("-", "") + "." + type;
-		
-		/*  淇敼鍥剧墖鏃讹紝鍏堝垹闄ゅ凡瀛樺湪鍥剧墖  */
-		String src = record.getSrc();
-		if (!StringUtil.isNullOrEmpty(src)) {
-			COSManager.getInstance().deleteFile(src);
-		}
-		
-		String uploadFilePath = COSManager.getInstance().uploadFile(inputStream, fileUrl).getUrl();
-		
-		/*  鏇存柊鏁版嵁搴撲俊鎭�  */
-		if (!StringUtil.isNullOrEmpty(uploadFilePath)) {
-			record.setSrc(uploadFilePath);
-			record.setUpdatetime(new Date());
-			updateByPrimaryKeySelective(record);
-		}
-	}
 
 	@Override
 	public List<SwiperPicture> getOrderByBannerID(Long bannerId, Integer type, Integer order) throws SwiperPictureException {

--
Gitblit v1.8.0