From c389b1ca090df256bad7fd0d183914146c1f93b8 Mon Sep 17 00:00:00 2001
From: admin <weikou2014>
Date: 星期五, 12 四月 2019 12:15:06 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master'

---
 fanli/src/main/java/com/yeshi/fanli/service/impl/homemodule/SpecialServiceImpl.java |  362 ++++++++++++++++++++++++++++++++++++++++++---------
 1 files changed, 295 insertions(+), 67 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 b52ee45..c4401cb 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,6 +1,7 @@
 package com.yeshi.fanli.service.impl.homemodule;
 
 import java.io.InputStream;
+import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
 import java.util.UUID;
@@ -11,12 +12,20 @@
 import org.springframework.cache.annotation.Cacheable;
 import org.springframework.stereotype.Service;
 import org.springframework.web.multipart.MultipartFile;
+import org.yeshi.utils.JsonUtil;
 import org.yeshi.utils.tencentcloud.COSManager;
 
 import com.yeshi.fanli.dao.mybatis.homemodule.SpecialMapper;
 import com.yeshi.fanli.entity.bus.homemodule.Special;
+import com.yeshi.fanli.entity.common.JumpDetailV2;
+import com.yeshi.fanli.exception.homemodule.SpecialException;
+import com.yeshi.fanli.service.inter.common.JumpDetailV2Service;
+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.StringUtil;
+
+import net.sf.json.JSONObject;
 
 
 @Service
@@ -24,50 +33,211 @@
 	
 	@Resource
 	private SpecialMapper specialMapper;
+	
+	@Resource
+	private SpecialPlaceService specialPlaceService;
+	
+	@Resource
+	private SpecialCardService specialCardService;
+	
+	@Resource
+	private JumpDetailV2Service jumpDetailV2Service;
 
 	
-	@Override
-	public int deleteByPrimaryKey(Long id) {
-		return specialMapper.deleteByPrimaryKey(id);
-	}
-
-	@Override
-	public int insert(Special record) {
-		return specialMapper.insert(record);
-	}
-
-	@Override
-	public int insertSelective(Special record) {
-		return specialMapper.insertSelective(record);
-	}
-
 	@Override
 	public Special selectByPrimaryKey(Long id) {
 		return specialMapper.selectByPrimaryKey(id);
 	}
 
+	
 	@Override
-	public int updateByPrimaryKeySelective(Special record) {
-		return specialMapper.updateByPrimaryKeySelective(record);
+	public void saveObject(MultipartFile file, MultipartFile file2, MultipartFile file3, Special record, String jumpType) 
+			throws SpecialException, Exception{
+		
+		Long cardId = record.getCardId();
+		if (cardId == null) {
+			throw new SpecialException(1, "绠$悊ID涓嶈兘涓虹┖");
+		}
+		
+		String name = record.getName();
+		if (name == null || name.trim().length() == 0) {
+			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鏍煎紡");
+		}
+		
+		if (!StringUtil.isNullOrEmpty(jumpType)) {
+			List<JumpDetailV2> listByType = jumpDetailV2Service.listByType(jumpType);
+			if (listByType !=null && listByType.size() > 0) {
+				record.setJumpDetail(listByType.get(0));
+			} 
+		}
+		
+		Long state = record.getState();
+		if (state == null) {
+			record.setState(0L);
+		}
+		
+		// 鍥剧墖涓婁紶
+		String picture = null;
+		if (file != null) {
+			picture = uploadPicture(file);
+		}
+		
+		// 鍥剧墖涓婁紶
+		String subPicture = null;
+		if (file2 != null) {
+			subPicture = uploadPicture(file2);
+		}
+		
+		// 鍥剧墖涓婁紶
+		String icon = null;
+		if (file3 != null) {
+			icon = uploadPicture(file3);
+		}
+		
+		Long id = record.getId();
+		if (id == null) {
+			record.setIcon(icon);
+			record.setPicture(picture);
+			record.setSubPicture(subPicture);
+			
+			int maxOrder = specialMapper.getMaxOrderByCard(cardId);
+			record.setOrderby(maxOrder + 1);
+			
+			record.setCreatetime(new Date());
+			record.setUpdatetime(new Date());
+			specialMapper.insert(record);
+		} else {
+			// 淇敼
+			Special resultObj = specialMapper.selectByPrimaryKey(id);
+			if (resultObj == null) {
+				throw new SpecialException(1, "淇敼鍐呭宸蹭笉瀛樺湪");
+			}
+			
+			if (picture != null && picture.trim().length() > 0) {
+				// 鍒犻櫎鑰佸浘
+				removePicture(resultObj.getPicture());
+				// 瀛樺偍鏂板浘
+				record.setPicture(picture);
+			} else {
+				record.setPicture(resultObj.getPicture());
+			}
+			
+			if (subPicture != null && subPicture.trim().length() > 0) {
+				// 鍒犻櫎鑰佸浘
+				removePicture(resultObj.getSubPicture());
+				// 瀛樺偍鏂板浘
+				record.setSubPicture(subPicture);
+			} else {
+				record.setSubPicture(resultObj.getSubPicture());
+			}
+			
+			
+			if (icon != null && icon.trim().length() > 0) {
+				// 鍒犻櫎鑰佸浘
+				removePicture(resultObj.getIcon());
+				// 瀛樺偍鏂板浘
+				record.setIcon(icon);
+			} else {
+				record.setIcon(resultObj.getIcon());
+			}
+			
+			record.setOrderby(resultObj.getOrderby());
+			record.setCreatetime(resultObj.getCreatetime());
+			record.setUpdatetime(new Date());
+			specialMapper.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/special/"+UUID.randomUUID().toString().replace("-", "") + "." + type;
+		// 鎵ц涓婁紶
+		String fileLink= COSManager.getInstance().uploadFile(inputStream, filePath).getUrl();
+		
+		return fileLink;
 	}
 
-	@Override
-	public int updateByPrimaryKey(Special record) {
-		return specialMapper.updateByPrimaryKey(record);
+	/**
+	 * 鍒犻櫎鍥剧墖-涓嶆洿鏂版暟鎹簱
+	 * @param record
+	 * @throws Exception
+	 */
+	public void removePicture(String picture) throws Exception {
+		if (picture != null && picture.trim().length() > 0) {
+			COSManager.getInstance().deleteFile(picture);
+		}
 	}
+	
+	
+	@Override
+	@Transactional
+	public void updateOrder(Long id, Integer moveType) throws SpecialException {
+		
+		if (id == null || moveType == null || (!moveType.equals(1) && !moveType.equals(-1))) {
+			throw new SpecialException(1, "璇蜂紶閫掓纭弬鏁�");
+		}
+		
+		Special resultObj = specialMapper.selectByPrimaryKey(id);
+		if (resultObj == null) {
+			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, "鍦ㄧ浉鍚屼娇鐢ㄥ湴鏂逛腑浼樺厛绾у凡缁忔渶楂樹簡");
+			}
+		}
+		
+		resultObj.setOrderby(exchangeObject.getOrderby());
+		exchangeObject.setOrderby(order);
+		
+		specialMapper.updateByPrimaryKey(resultObj);
+		specialMapper.updateByPrimaryKey(exchangeObject);
+	}
+	
 	
 	@Override
 	@Transactional
 	public int deleteBatchByPrimaryKey(List<Long> list) throws Exception{
-		
 		List<Special> listSpecial = specialMapper.queryByListPrimaryKey(list);
 		for (Special special: listSpecial) {
 			String src = special.getPicture();
 			if (!StringUtil.isNullOrEmpty(src)) {
 				COSManager.getInstance().deleteFile(src);
 			}
+			
+			String subPicture = special.getSubPicture();
+			if (!StringUtil.isNullOrEmpty(subPicture)) {
+				COSManager.getInstance().deleteFile(subPicture);
+			}
 		}
-		
 		return specialMapper.deleteBatchByPrimaryKey(list);
 	}
 	
@@ -79,6 +249,11 @@
 			if (!StringUtil.isNullOrEmpty(src)) {
 				COSManager.getInstance().deleteFile(src);
 			}
+			
+			String subPicture = special.getSubPicture();
+			if (!StringUtil.isNullOrEmpty(subPicture)) {
+				COSManager.getInstance().deleteFile(subPicture);
+			}
 		}
 		
 		return specialMapper.deleteBatchByCardID(list);
@@ -87,24 +262,43 @@
 	
 	@Override
 	public List<Special> listQueryByCard(long start, int count, Long card, String key){
-		return specialMapper.listQueryByCard(start, count, card, key);
+		
+		List<Special> list = specialMapper.listQueryByCard(start, count, card, key);
+		if (list == null || list.size() == 0) {
+			return list;
+		}
+		
+		// 璺宠浆閾炬帴
+		for (Special special: list) {
+			String params = special.getParams();
+			if (StringUtil.isNullOrEmpty(params)) {
+				special.setParams("");
+			}
+			
+			String remark = special.getRemark();
+			if (StringUtil.isNullOrEmpty(remark)) {
+				special.setRemark("");
+			}
+			
+			JumpDetailV2 jumpDetail = special.getJumpDetail();
+			if (jumpDetail == null) {
+				// 榛樿鏈�夋嫨
+				JumpDetailV2 jumpDetailV2 = new JumpDetailV2();
+				jumpDetailV2.setName("-鏈�夋嫨-");
+				jumpDetailV2.setType("default");
+				special.setJumpDetail(jumpDetailV2);
+			}
+		}
+		return list;
 	}
+	
 	
 	@Override
 	public long countlistQueryByCard(Long card, String key) {
 		return specialMapper.countlistQueryByCard(card, key);
 	}
 	
-	@Override
-	public List<Special> getOrderByCardID(Long cardId, Integer type, Integer order) {
-		return specialMapper.getOrderByCardID(cardId, type, order);
-	}
 	
-	@Override
-	public int getMaxOrderByCard(Long card) {
-		return specialMapper.getMaxOrderByCard(card);
-	}
-
 	@Override
 	@Cacheable(value = "configCache", key = "'listBySystemAndCard-'+#card+'-'+#systemId")
 	public List<Special> listBySystemAndCard(String card, Long systemId) {
@@ -120,47 +314,81 @@
 
 	
 	@Override
-	public void uploadPicture(MultipartFile file, Special record, Long cardId) throws Exception {
+	@Cacheable(value = "configCache", key = "'listCacheSpecialToIndex'")
+	public JSONObject listCacheSpecialToIndex() throws Exception{
 		
-		InputStream inputStream = file.getInputStream();
-		String contentType = file.getContentType();
-		String type = contentType.substring(contentType.indexOf("/") + 1);
-		// 涓婁紶鏂囦欢鐩稿浣嶇疆
-		String fileUrl="SpecialPic/"+UUID.randomUUID().toString().replace("-", "") + "." + type;
-		
-		/*  淇敼鍥剧墖鏃讹紝鍏堝垹闄ゅ凡瀛樺湪鍥剧墖  */
-		if (record != null) { 
-			String src = record.getPicture();
-			if (!StringUtil.isNullOrEmpty(src)) {
-				COSManager.getInstance().deleteFile(src);
+		// 棣栭〉-5鍦嗗舰2鎺掑尯鍩�
+		JSONObject arcMap = new JSONObject();
+		List<Special> listArc = specialMapper.listByPlaceKey("index_arc");
+		if (listArc == null) {
+			listArc = new ArrayList<Special>();
+		} else if(listArc.size() > 0){
+			Special special = listArc.get(0);
+			if (special != null) {
+				// 鑳屾櫙鍥剧墖
+				arcMap.put("bottomPicture", special.getBottomPicture());
 			}
 		}
+		// 鏁版嵁澶勭悊
+		handlelist(listArc);
+		arcMap.put("list", JsonUtil.getApiCommonGson().toJson(listArc));
 		
-		String uploadFilePath = COSManager.getInstance().uploadFile(inputStream, fileUrl).getUrl();
 		
-		/*  鏇存柊鏁版嵁搴撲俊鎭�  */
-		if (!StringUtil.isNullOrEmpty(uploadFilePath)) {
-			
-			if (record != null) {
-				record.setUpdatetime(new Date());
-				record.setPicture(uploadFilePath);
-				updateByPrimaryKeySelective(record);
-			} else {
-				record = new Special();
-				record.setPicture(uploadFilePath);
-				record.setCreatetime(new Date());
-				record.setUpdatetime(new Date());
-				record.setCardId(cardId);
-				record.setState(0L);
-				
-				int maxOrder = getMaxOrderByCard(cardId);
-				record.setOrderby(maxOrder + 1);
-				record.setShowType("default");
-				insertSelective(record);
+		// 棣栭〉-娲诲姩鍖哄煙锛堝コ鐜嬭妭锛�
+		JSONObject activityMap = new JSONObject();
+		List<Special> listActivity = specialMapper.listByPlaceKey("index_activity");
+		if (listActivity == null) {
+			listActivity = new ArrayList<Special>();
+		} else if(listActivity.size() > 0){
+			Special special = listActivity.get(0);
+			if (special != null) {
+				// 鑳屾櫙鍥剧墖
+				activityMap.put("bottomPicture", special.getBottomPicture());
 			}
-			
+		}
+		// 鏁版嵁澶勭悊
+		handlelist(listActivity);
+		activityMap.put("list", JsonUtil.getApiCommonGson().toJson(listActivity));
+		
+		
+		// 棣栭〉-鏂瑰舰涓撻锛堝搧鐗屽埜銆佹瘝濠�...锛�
+		JSONObject blockJsonMap = new JSONObject();
+		List<Special> listBlock = specialMapper.listByPlaceKey("index_block");
+		if (listBlock == null) {
+			listBlock = new ArrayList<Special>();
+		} else if(listBlock.size() > 0){
+			Special special = listBlock.get(0);
+			if (special != null) {
+				// 鑳屾櫙鍥剧墖
+				blockJsonMap.put("bottomPicture", special.getBottomPicture());
+			}
+		}
+		// 鏁版嵁澶勭悊
+		handlelist(listBlock);
+		blockJsonMap.put("list", JsonUtil.getApiCommonGson().toJson(listBlock));
+	
+		JSONObject root = new JSONObject();
+		root.put("arcArea", arcMap);
+		root.put("activityArea", activityMap);
+		root.put("blockArea", blockJsonMap);
+		return root;
+	}
+	
+	
+	/**
+	 * 澶勭悊 鏁版嵁
+	 * @param list
+	 */
+	public void handlelist(List<Special> list) {
+		if (list != null && list.size() > 0) {
+			for (Special special: list) {
+				boolean needLogin = special.isJumpLogin();
+				JumpDetailV2 jumpDetail = special.getJumpDetail();
+				if (jumpDetail != null) {
+					jumpDetail.setNeedLogin(needLogin);
+					special.setJumpDetail(jumpDetail);
+				}
+			}
 		}
 	}
-
-	
 }

--
Gitblit v1.8.0