From 30d8e227e8d823b6c38c3b9c90ac2df03b63befe Mon Sep 17 00:00:00 2001
From: admin <weikou2014>
Date: 星期二, 25 二月 2025 16:41:22 +0800
Subject: [PATCH] 淘宝转链接口更新

---
 fanli/src/main/java/com/yeshi/fanli/service/impl/homemodule/FloatADServiceImpl.java |  899 +++++++++++++++++++++++++++++------------------------------
 1 files changed, 449 insertions(+), 450 deletions(-)

diff --git a/fanli/src/main/java/com/yeshi/fanli/service/impl/homemodule/FloatADServiceImpl.java b/fanli/src/main/java/com/yeshi/fanli/service/impl/homemodule/FloatADServiceImpl.java
index 7788f95..8f5fff9 100644
--- a/fanli/src/main/java/com/yeshi/fanli/service/impl/homemodule/FloatADServiceImpl.java
+++ b/fanli/src/main/java/com/yeshi/fanli/service/impl/homemodule/FloatADServiceImpl.java
@@ -1,450 +1,449 @@
-package com.yeshi.fanli.service.impl.homemodule;
-
-import java.io.InputStream;
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-import java.util.UUID;
-
-import javax.annotation.Resource;
-
-import org.springframework.cache.annotation.Cacheable;
-import org.springframework.stereotype.Service;
-import org.springframework.transaction.annotation.Transactional;
-import org.springframework.web.multipart.MultipartFile;
-import org.yeshi.utils.tencentcloud.COSManager;
-
-import com.yeshi.fanli.dao.mybatis.homemodule.FloatADMapper;
-import com.yeshi.fanli.entity.AppVersionInfo;
-import com.yeshi.fanli.entity.bus.homemodule.AdActivityVersionControl;
-import com.yeshi.fanli.entity.bus.homemodule.AdActivityVersionControl.AdActivityType;
-import com.yeshi.fanli.entity.bus.homemodule.FloatAD;
-import com.yeshi.fanli.entity.bus.homemodule.FloatAD.FloatADTypeEnum;
-import com.yeshi.fanli.entity.common.JumpDetailV2;
-import com.yeshi.fanli.exception.banner.SwiperPictureException;
-import com.yeshi.fanli.exception.homemodule.FloatADException;
-import com.yeshi.fanli.service.inter.common.JumpDetailV2Service;
-import com.yeshi.fanli.service.inter.config.AppVersionService;
-import com.yeshi.fanli.service.inter.homemodule.AdActivityVersionControlService;
-import com.yeshi.fanli.service.inter.homemodule.FloatADService;
-import com.yeshi.fanli.util.FilePathEnum;
-import com.yeshi.fanli.util.StringUtil;
-
-@Service
-public class FloatADServiceImpl implements FloatADService {
-
-	@Resource
-	private FloatADMapper floatADMapper;
-	
-	@Resource
-	private JumpDetailV2Service jumpDetailV2Service;
-	
-	@Resource
-	private AppVersionService appVersionService;
-	
-	@Resource
-	private AdActivityVersionControlService adActivityVersionControlService;
-	
-	
-	@Override
-	public void saveObject(MultipartFile file, FloatAD record, String jumpType) throws FloatADException, Exception{
-		
-		String position = record.getPosition();
-		if (position == null || position.trim().length() == 0) {
-			throw new FloatADException(1, "浣跨敤浣嶇疆涓嶈兘涓虹┖");
-		}
-		
-		String showMode = record.getShowMode();
-		if (showMode == null || showMode.trim().length() == 0) {
-			throw new FloatADException(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 FloatADException(1, "璺宠浆鍙傛暟闈濲SON鏍煎紡");
-		} else {
-			record.setParams(params.trim());
-		}
-		
-		FloatADTypeEnum typeEnum = record.getTypeEnum();
-		if (typeEnum == null)
-			throw new FloatADException(1, "绫诲瀷涓嶈兘涓虹┖");
-			
-		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);
-		}
-		
-		// 閫傜敤绫诲瀷 锛� 0閫氱敤  1鏂颁汉
-		Integer type = record.getType();
-		if (type == null) {
-			record.setType(0);
-		}
-		
-		Long id = record.getId();
-		if (id == null) {
-			int maxOrder = floatADMapper.getMaxOrderByPosition(position);
-			record.setPicture(picture);
-			Integer state = record.getState();
-			if (state == null) {
-				record.setState(0);
-			}
-			
-			record.setOrder(maxOrder + 1);
-			record.setCreateTime(new Date());
-			record.setUpdateTime(new Date());
-			floatADMapper.insert(record);
-		} else {
-			// 淇敼
-			FloatAD resultObj = floatADMapper.selectByPrimaryKey(id);
-			if (resultObj == null) {
-				throw new FloatADException(1, "淇敼鍐呭宸蹭笉瀛樺湪");
-			}
-			
-			if (picture != null && picture.trim().length() > 0) {
-				// 鍒犻櫎鑰佸浘
-				removePicture(resultObj.getPicture());
-				// 瀛樺偍鏂板浘
-				record.setPicture(picture);
-			} else {
-				record.setPicture(resultObj.getPicture());
-			}
-			
-			record.setOrder(resultObj.getOrder());
-			record.setCreateTime(resultObj.getCreateTime());
-			record.setUpdateTime(new Date());
-			floatADMapper.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= FilePathEnum.floatAD.getPath() +UUID.randomUUID().toString().replace("-", "") + "." + type;
-		// 鎵ц涓婁紶
-		String fileLink= COSManager.getInstance().uploadFile(inputStream, filePath).getUrl();
-		
-		return fileLink;
-	}
-
-	/**
-	 * 鍒犻櫎鍥剧墖-涓嶆洿鏂版暟鎹簱
-	 * @param record
-	 * @throws Exception
-	 */
-	public void removePicture(String picture) throws Exception {
-		if (picture != null && picture.trim().length() > 0) {
-			COSManager.getInstance().deleteFile(picture);
-		}
-	}
-	
-	@Override
-	@Transactional(rollbackFor=Exception.class)
-	public void updateOrder(Long id, Integer moveType) throws FloatADException {
-		
-		if (id == null || moveType == null || (!moveType.equals(1) && !moveType.equals(-1))) {
-			throw new FloatADException(1, "璇蜂紶閫掓纭弬鏁�");
-		}
-		
-		FloatAD resultObj = floatADMapper.selectByPrimaryKey(id);
-		if (resultObj == null) {
-			throw new FloatADException(1, "姝ゅ唴瀹瑰凡涓嶅瓨鍦�");
-		}
-		
-		Integer order = resultObj.getOrder();
-		String position = resultObj.getPosition();
-		
-		// 鑾峰彇浜ゆ崲瀵硅薄
-		FloatAD exchangeObject = floatADMapper.getByAdjoinOrder(position, order, moveType);
-		if (exchangeObject == null) {
-			if (moveType == 1) {
-				throw new FloatADException(1, "鍦ㄧ浉鍚屼娇鐢ㄥ湴鏂逛腑浼樺厛绾у凡缁忔渶浣庝簡");
-			} else {
-				throw new FloatADException(1, "鍦ㄧ浉鍚屼娇鐢ㄥ湴鏂逛腑浼樺厛绾у凡缁忔渶楂樹簡");
-			}
-		}
-		
-		resultObj.setOrder(exchangeObject.getOrder());
-		exchangeObject.setOrder(order);
-		
-		floatADMapper.updateByPrimaryKey(resultObj);
-		floatADMapper.updateByPrimaryKey(exchangeObject);
-	}
-	
-	
-	@Override
-	public void switchState(Long id) throws FloatADException {
-		if (id == null) {
-			throw new FloatADException(1, "璇蜂紶閫掓纭弬鏁�");
-		}
-		FloatAD resultObj = floatADMapper.selectByPrimaryKey(id);
-		if (resultObj == null) {
-			throw new FloatADException(1, "姝ゅ唴瀹瑰凡涓嶅瓨鍦�");
-		}
-		
-		Integer state = resultObj.getState();
-		if (state == null || state == 0) {
-			state = 1;
-		} else {
-			state = 0;
-		}
-		
-		FloatAD updateObj = new FloatAD();
-		updateObj.setId(id);
-		updateObj.setState(state);
-		floatADMapper.updateByPrimaryKeySelective(updateObj);
-	}
-	
-	
-	@Override
-	@Transactional(rollbackFor=Exception.class)
-	public int deleteByPrimaryKeyList(List<Long> list) throws Exception{
-		
-		List<FloatAD> listSwiper = floatADMapper.ListByPrimaryKey(list);
-		if (listSwiper == null || listSwiper.size() == 0) {
-			return 0;
-		}
-		
-		// 鍒犻櫎宸插瓨鍦ㄥ浘鐗�
-		for (FloatAD floatAD: listSwiper) {
-			removePicture(floatAD.getPicture());
-			
-			List<AdActivityVersionControl> versionList = adActivityVersionControlService
-					.listByTypeAndSourceId(AdActivityType.floatAD, floatAD.getId());
-			if (versionList != null)
-				for (AdActivityVersionControl control : versionList)
-					adActivityVersionControlService.deleteByPrimaryKey(control.getId());
-		}
-		
-		return floatADMapper.deleteByPrimaryKeyList(list);
-	}
-
-	
-
-	@Override
-	public List<FloatAD> listQuery(long start, int count, String key, Integer state) throws FloatADException {
-		
-		List<FloatAD> listQuery = floatADMapper.listQuery(start, count, key, state);
-		if (listQuery == null || listQuery.size() == 0) {
-			return listQuery;
-		}
-		
-		for (FloatAD floatAD : listQuery) {
-			
-			FloatADTypeEnum typeEnum = floatAD.getTypeEnum();
-			if (typeEnum != null) {
-				floatAD.setTypeName(typeEnum.getDesc());
-			}
-			
-			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm");
-			Date startTime = floatAD.getStartTime();
-			if (startTime == null) {
-				floatAD.setStartTime_str("");
-			} else {
-				floatAD.setStartTime_str(sdf.format(startTime));
-			}
-			
-			Date endTime = floatAD.getEndTime();
-			if (endTime == null) {
-				floatAD.setEndTime_str("");
-			} else {
-				floatAD.setEndTime_str(sdf.format(endTime));
-			}
-			
-			String params = floatAD.getParams();
-			if (params == null) {
-				floatAD.setParams("");
-			}
-			
-			JumpDetailV2 jumpDetail = floatAD.getJumpDetail();
-			if (jumpDetail == null) {
-				// 榛樿鏈�夋嫨
-				jumpDetail = new JumpDetailV2();
-				jumpDetail.setName("-鏈�夋嫨-");
-				jumpDetail.setType("default");
-			} else {
-				jumpDetail = jumpDetailV2Service.selectByPrimaryKey(jumpDetail.getId());
-			} 
-			
-			floatAD.setJumpDetail(jumpDetail);
-		}
-		
-		return listQuery;
-	}
-
-
-	@Override
-	public long countQuery(String key, Integer state) {
-		return floatADMapper.countQuery(key, state);
-	}
-
-	@Cacheable(value = "configCache", key = "'getEffectiveFloatAD-'+#position+'-'+#type")
-	@Override
-	public FloatAD getEffectiveFloatAD(String position, Integer type) {
-		FloatAD floatAD = floatADMapper.getEffectiveFloatAD(position, type);
-		if (floatAD != null) {
-			JumpDetailV2 jumpDetail = floatAD.getJumpDetail();
-			
-			// 鏌ヨJumpDetailV2
-			if (jumpDetail != null) {
-				jumpDetail = jumpDetailV2Service.selectByPrimaryKey(jumpDetail.getId());
-				if (jumpDetail != null) {
-					// 璺宠浆鐣岄潰鏄惁闇�瑕佺櫥褰�
-					jumpDetail.setNeedLogin(floatAD.isJumpNeedLogin());
-				}
-			} 
-			
-			floatAD.setJumpDetail(jumpDetail);
-		}
-		return floatAD;
-	}
-	
-	
-	@Transactional(rollbackFor = Exception.class)
-	@Override
-	public void setVersions(Long id, List<Long> versions) throws Exception {
-		FloatAD record = floatADMapper.selectByPrimaryKey(id);
-		if (record == null) {
-			throw new Exception("涓撻涓嶅瓨鍦�");
-		}
-
-		Set<Long> oldSet = new HashSet<>();
-
-		List<AdActivityVersionControl> versionList = adActivityVersionControlService
-				.listByTypeAndSourceId(AdActivityType.floatAD, id);
-		if (versionList != null) {
-			for (AdActivityVersionControl control : versionList)
-				oldSet.add(control.getVersion().getId());
-		}
-
-		Set<Long> newSet = new HashSet<>();
-		for (Long version : versions) {
-			newSet.add(version);
-		}
-
-		Set<Long> delSet = new HashSet<>();
-		delSet.addAll(oldSet);
-		delSet.removeAll(newSet);
-		for (Long versionId : delSet) {
-			adActivityVersionControlService.deleteBySourceAndVersion(id, AdActivityType.floatAD, versionId);
-		}
-
-		Set<Long> addSet = new HashSet<>();
-		addSet.addAll(newSet);
-		addSet.removeAll(oldSet);
-		// 娣诲姞鏄犲皠
-		for (Long versionId : addSet) {
-			AdActivityVersionControl control = new AdActivityVersionControl();
-			control.setCreateTime(new Date());
-			control.setSourceId(id);
-			control.setType(AdActivityType.floatAD);
-			control.setVersion(new AppVersionInfo(versionId));
-			try {
-				adActivityVersionControlService.addVersionControl(control);
-			} catch (Exception e) {
-				throw new SwiperPictureException(2, e.getMessage());
-			}
-		}
-	}
-	
-	@Cacheable(value = "configCache", key = "'getValidFloatADCache-'+#position+'-'+#type+'-'+#platform+'-'+#versionCode")
-	@Override
-	public List<FloatAD> getValidFloatADCache(String position, Integer type, String platform, Integer versionCode) {
-		List<FloatAD> list = floatADMapper.getValidFloatAD(position, type);
-		// 杩囨护
-		filterFloatAD(list, platform, versionCode);
-		
-		return list;
-	}
-	
-	/**
-	 * 杩囨护
-	 * 
-	 * @param list
-	 * @param platform
-	 * @param versionCode
-	 */
-	private void filterFloatAD(List<FloatAD> list, String platform, int versionCode) {
-		if (list == null || list.size() == 0)
-			return;
-		AppVersionInfo app = appVersionService.getClientVersion(platform, versionCode);
-		if (app == null) {
-			list.clear();
-			return;
-		}
-		List<Long> versionIdList = new ArrayList<>();
-		versionIdList.add(app.getId());
-		List<Long> sourceIdList = new ArrayList<>();
-		for (FloatAD record : list) {
-			sourceIdList.add(record.getId());
-		}
-
-		Set<Long> sourceIds = adActivityVersionControlService.filterSourceIdByVersion(sourceIdList,
-				AdActivityType.floatAD, versionIdList);
-		
-		for (int i = 0; i < list.size(); i++) {
-			// 杩囨护鐗堟湰
-			if (!sourceIds.contains(list.get(i).getId())) {
-				list.remove(i--);
-				continue;
-			}
-			
-			// 璺宠浆鏄惁鐧诲綍
-			FloatAD floatAD = list.get(i);
-			JumpDetailV2 jumpDetail = floatAD.getJumpDetail();
-			if (jumpDetail != null) {
-				jumpDetail = jumpDetailV2Service.selectByPrimaryKey(jumpDetail.getId());
-				if (jumpDetail != null) {
-					jumpDetail.setNeedLogin(floatAD.isJumpNeedLogin());
-				}
-			}
-		}
-	}
-
-}
-
+package com.yeshi.fanli.service.impl.homemodule;
+
+import java.io.InputStream;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+import java.util.UUID;
+
+import javax.annotation.Resource;
+
+import com.yeshi.fanli.entity.SystemEnum;
+import org.springframework.cache.annotation.Cacheable;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+import org.springframework.web.multipart.MultipartFile;
+import org.yeshi.utils.tencentcloud.COSManager;
+
+import com.yeshi.fanli.dao.mybatis.homemodule.FloatADMapper;
+import com.yeshi.fanli.entity.AppVersionInfo;
+import com.yeshi.fanli.entity.bus.homemodule.AdActivityVersionControl;
+import com.yeshi.fanli.entity.bus.homemodule.AdActivityVersionControl.AdActivityType;
+import com.yeshi.fanli.entity.bus.homemodule.FloatAD;
+import com.yeshi.fanli.entity.bus.homemodule.FloatAD.FloatADTypeEnum;
+import com.yeshi.fanli.entity.common.JumpDetailV2;
+import com.yeshi.fanli.exception.banner.SwiperPictureException;
+import com.yeshi.fanli.exception.homemodule.FloatADException;
+import com.yeshi.fanli.service.inter.common.JumpDetailV2Service;
+import com.yeshi.fanli.service.inter.config.AppVersionService;
+import com.yeshi.fanli.service.inter.homemodule.AdActivityVersionControlService;
+import com.yeshi.fanli.service.inter.homemodule.FloatADService;
+import com.yeshi.fanli.util.FilePathEnum;
+import com.yeshi.fanli.util.StringUtil;
+
+@Service
+public class FloatADServiceImpl implements FloatADService {
+
+	@Resource
+	private FloatADMapper floatADMapper;
+	
+	@Resource
+	private JumpDetailV2Service jumpDetailV2Service;
+	
+	@Resource
+	private AppVersionService appVersionService;
+	
+	@Resource
+	private AdActivityVersionControlService adActivityVersionControlService;
+	
+	
+	@Override
+	public void saveObject(MultipartFile file, FloatAD record, String jumpType) throws FloatADException, Exception{
+		
+		String position = record.getPosition();
+		if (position == null || position.trim().length() == 0) {
+			throw new FloatADException(1, "浣跨敤浣嶇疆涓嶈兘涓虹┖");
+		}
+		
+		String showMode = record.getShowMode();
+		if (showMode == null || showMode.trim().length() == 0) {
+			throw new FloatADException(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 FloatADException(1, "璺宠浆鍙傛暟闈濲SON鏍煎紡");
+		} else {
+			record.setParams(params.trim());
+		}
+		
+		FloatADTypeEnum typeEnum = record.getTypeEnum();
+		if (typeEnum == null)
+			throw new FloatADException(1, "绫诲瀷涓嶈兘涓虹┖");
+			
+		if (!StringUtil.isNullOrEmpty(jumpType)) {
+			List<JumpDetailV2> listByType = jumpDetailV2Service.listByType(jumpType,record.getSystem());
+			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);
+		}
+		
+		// 閫傜敤绫诲瀷 锛� 0閫氱敤  1鏂颁汉
+		Integer type = record.getType();
+		if (type == null) {
+			record.setType(0);
+		}
+		
+		Long id = record.getId();
+		if (id == null) {
+			int maxOrder = floatADMapper.getMaxOrderByPosition(position,record.getSystem());
+			record.setPicture(picture);
+			Integer state = record.getState();
+			if (state == null) {
+				record.setState(0);
+			}
+			
+			record.setOrder(maxOrder + 1);
+			record.setCreateTime(new Date());
+			record.setUpdateTime(new Date());
+			floatADMapper.insert(record);
+		} else {
+			// 淇敼
+			FloatAD resultObj = floatADMapper.selectByPrimaryKey(id);
+			if (resultObj == null) {
+				throw new FloatADException(1, "淇敼鍐呭宸蹭笉瀛樺湪");
+			}
+			
+			if (picture != null && picture.trim().length() > 0) {
+				// 鍒犻櫎鑰佸浘
+				removePicture(resultObj.getPicture());
+				// 瀛樺偍鏂板浘
+				record.setPicture(picture);
+			} else {
+				record.setPicture(resultObj.getPicture());
+			}
+			
+			record.setOrder(resultObj.getOrder());
+			record.setCreateTime(resultObj.getCreateTime());
+			record.setUpdateTime(new Date());
+			floatADMapper.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= FilePathEnum.floatAD.getPath() +UUID.randomUUID().toString().replace("-", "") + "." + type;
+		// 鎵ц涓婁紶
+		String fileLink= COSManager.getInstance().uploadFile(inputStream, filePath).getUrl();
+		
+		return fileLink;
+	}
+
+	/**
+	 * 鍒犻櫎鍥剧墖-涓嶆洿鏂版暟鎹簱
+	 * @throws Exception
+	 */
+	public void removePicture(String picture) throws Exception {
+		if (picture != null && picture.trim().length() > 0) {
+			COSManager.getInstance().deleteFile(picture);
+		}
+	}
+	
+	@Override
+	@Transactional(rollbackFor=Exception.class)
+	public void updateOrder(Long id, Integer moveType) throws FloatADException {
+		
+		if (id == null || moveType == null || (!moveType.equals(1) && !moveType.equals(-1))) {
+			throw new FloatADException(1, "璇蜂紶閫掓纭弬鏁�");
+		}
+		
+		FloatAD resultObj = floatADMapper.selectByPrimaryKey(id);
+		if (resultObj == null) {
+			throw new FloatADException(1, "姝ゅ唴瀹瑰凡涓嶅瓨鍦�");
+		}
+		
+		Integer order = resultObj.getOrder();
+		String position = resultObj.getPosition();
+		
+		// 鑾峰彇浜ゆ崲瀵硅薄
+		FloatAD exchangeObject = floatADMapper.getByAdjoinOrder(position, order, moveType,resultObj.getSystem());
+		if (exchangeObject == null) {
+			if (moveType == 1) {
+				throw new FloatADException(1, "鍦ㄧ浉鍚屼娇鐢ㄥ湴鏂逛腑浼樺厛绾у凡缁忔渶浣庝簡");
+			} else {
+				throw new FloatADException(1, "鍦ㄧ浉鍚屼娇鐢ㄥ湴鏂逛腑浼樺厛绾у凡缁忔渶楂樹簡");
+			}
+		}
+		
+		resultObj.setOrder(exchangeObject.getOrder());
+		exchangeObject.setOrder(order);
+		
+		floatADMapper.updateByPrimaryKey(resultObj);
+		floatADMapper.updateByPrimaryKey(exchangeObject);
+	}
+	
+	
+	@Override
+	public void switchState(Long id) throws FloatADException {
+		if (id == null) {
+			throw new FloatADException(1, "璇蜂紶閫掓纭弬鏁�");
+		}
+		FloatAD resultObj = floatADMapper.selectByPrimaryKey(id);
+		if (resultObj == null) {
+			throw new FloatADException(1, "姝ゅ唴瀹瑰凡涓嶅瓨鍦�");
+		}
+		
+		Integer state = resultObj.getState();
+		if (state == null || state == 0) {
+			state = 1;
+		} else {
+			state = 0;
+		}
+		
+		FloatAD updateObj = new FloatAD();
+		updateObj.setId(id);
+		updateObj.setState(state);
+		floatADMapper.updateByPrimaryKeySelective(updateObj);
+	}
+	
+	
+	@Override
+	@Transactional(rollbackFor=Exception.class)
+	public int deleteByPrimaryKeyList(List<Long> list) throws Exception{
+		
+		List<FloatAD> listSwiper = floatADMapper.ListByPrimaryKey(list);
+		if (listSwiper == null || listSwiper.size() == 0) {
+			return 0;
+		}
+		
+		// 鍒犻櫎宸插瓨鍦ㄥ浘鐗�
+		for (FloatAD floatAD: listSwiper) {
+			removePicture(floatAD.getPicture());
+			
+			List<AdActivityVersionControl> versionList = adActivityVersionControlService
+					.listByTypeAndSourceId(AdActivityType.floatAD, floatAD.getId());
+			if (versionList != null)
+				for (AdActivityVersionControl control : versionList)
+					adActivityVersionControlService.deleteByPrimaryKey(control.getId());
+		}
+		
+		return floatADMapper.deleteByPrimaryKeyList(list);
+	}
+
+	
+
+	@Override
+	public List<FloatAD> listQuery(long start, int count, String key, Integer state,SystemEnum system) throws FloatADException {
+		
+		List<FloatAD> listQuery = floatADMapper.listQuery(start, count, key, state,system);
+		if (listQuery == null || listQuery.size() == 0) {
+			return listQuery;
+		}
+		
+		for (FloatAD floatAD : listQuery) {
+			
+			FloatADTypeEnum typeEnum = floatAD.getTypeEnum();
+			if (typeEnum != null) {
+				floatAD.setTypeName(typeEnum.getDesc());
+			}
+			
+			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm");
+			Date startTime = floatAD.getStartTime();
+			if (startTime == null) {
+				floatAD.setStartTime_str("");
+			} else {
+				floatAD.setStartTime_str(sdf.format(startTime));
+			}
+			
+			Date endTime = floatAD.getEndTime();
+			if (endTime == null) {
+				floatAD.setEndTime_str("");
+			} else {
+				floatAD.setEndTime_str(sdf.format(endTime));
+			}
+			
+			String params = floatAD.getParams();
+			if (params == null) {
+				floatAD.setParams("");
+			}
+			
+			JumpDetailV2 jumpDetail = floatAD.getJumpDetail();
+			if (jumpDetail == null) {
+				// 榛樿鏈�夋嫨
+				jumpDetail = new JumpDetailV2();
+				jumpDetail.setName("-鏈�夋嫨-");
+				jumpDetail.setType("default");
+			} else {
+				jumpDetail = jumpDetailV2Service.selectByPrimaryKey(jumpDetail.getId());
+			} 
+			
+			floatAD.setJumpDetail(jumpDetail);
+		}
+		
+		return listQuery;
+	}
+
+
+	@Override
+	public long countQuery(String key, Integer state,SystemEnum system) {
+		return floatADMapper.countQuery(key, state,system);
+	}
+
+	@Cacheable(value = "configCache", key = "'getEffectiveFloatAD-'+#position+'-'+#type")
+	@Override
+	public FloatAD getEffectiveFloatAD(String position, Integer type,SystemEnum system) {
+		FloatAD floatAD = floatADMapper.getEffectiveFloatAD(position, type,system);
+		if (floatAD != null) {
+			JumpDetailV2 jumpDetail = floatAD.getJumpDetail();
+			
+			// 鏌ヨJumpDetailV2
+			if (jumpDetail != null) {
+				jumpDetail = jumpDetailV2Service.selectByPrimaryKey(jumpDetail.getId());
+				if (jumpDetail != null) {
+					// 璺宠浆鐣岄潰鏄惁闇�瑕佺櫥褰�
+					jumpDetail.setNeedLogin(floatAD.isJumpNeedLogin());
+				}
+			} 
+			
+			floatAD.setJumpDetail(jumpDetail);
+		}
+		return floatAD;
+	}
+	
+	
+	@Transactional(rollbackFor = Exception.class)
+	@Override
+	public void setVersions(Long id, List<Long> versions) throws Exception {
+		FloatAD record = floatADMapper.selectByPrimaryKey(id);
+		if (record == null) {
+			throw new Exception("涓撻涓嶅瓨鍦�");
+		}
+
+		Set<Long> oldSet = new HashSet<>();
+
+		List<AdActivityVersionControl> versionList = adActivityVersionControlService
+				.listByTypeAndSourceId(AdActivityType.floatAD, id);
+		if (versionList != null) {
+			for (AdActivityVersionControl control : versionList)
+				oldSet.add(control.getVersion().getId());
+		}
+
+		Set<Long> newSet = new HashSet<>();
+		for (Long version : versions) {
+			newSet.add(version);
+		}
+
+		Set<Long> delSet = new HashSet<>();
+		delSet.addAll(oldSet);
+		delSet.removeAll(newSet);
+		for (Long versionId : delSet) {
+			adActivityVersionControlService.deleteBySourceAndVersion(id, AdActivityType.floatAD, versionId);
+		}
+
+		Set<Long> addSet = new HashSet<>();
+		addSet.addAll(newSet);
+		addSet.removeAll(oldSet);
+		// 娣诲姞鏄犲皠
+		for (Long versionId : addSet) {
+			AdActivityVersionControl control = new AdActivityVersionControl();
+			control.setCreateTime(new Date());
+			control.setSourceId(id);
+			control.setType(AdActivityType.floatAD);
+			control.setVersion(new AppVersionInfo(versionId));
+			try {
+				adActivityVersionControlService.addVersionControl(control);
+			} catch (Exception e) {
+				throw new SwiperPictureException(2, e.getMessage());
+			}
+		}
+	}
+	
+	@Cacheable(value = "configCache", key = "'getValidFloatADCache-'+#position+'-'+#type+'-'+#platform+'-'+#versionCode+'-'+#system")
+	@Override
+	public List<FloatAD> getValidFloatADCache(String position, Integer type, String platform, Integer versionCode, SystemEnum system) {
+		List<FloatAD> list = floatADMapper.getValidFloatAD(position, type,system);
+		// 杩囨护
+		filterFloatAD(list, platform, versionCode,system);
+		return list;
+	}
+	
+	/**
+	 * 杩囨护
+	 * 
+	 * @param list
+	 * @param platform
+	 * @param versionCode
+	 */
+	private void filterFloatAD(List<FloatAD> list, String platform, int versionCode, SystemEnum system) {
+		if (list == null || list.size() == 0)
+			return;
+		AppVersionInfo app = appVersionService.getClientVersion(platform, versionCode,system);
+		if (app == null) {
+			list.clear();
+			return;
+		}
+		List<Long> versionIdList = new ArrayList<>();
+		versionIdList.add(app.getId());
+		List<Long> sourceIdList = new ArrayList<>();
+		for (FloatAD record : list) {
+			sourceIdList.add(record.getId());
+		}
+
+		Set<Long> sourceIds = adActivityVersionControlService.filterSourceIdByVersion(sourceIdList,
+				AdActivityType.floatAD, versionIdList);
+		
+		for (int i = 0; i < list.size(); i++) {
+			// 杩囨护鐗堟湰
+			if (!sourceIds.contains(list.get(i).getId())) {
+				list.remove(i--);
+				continue;
+			}
+			
+			// 璺宠浆鏄惁鐧诲綍
+			FloatAD floatAD = list.get(i);
+			JumpDetailV2 jumpDetail = floatAD.getJumpDetail();
+			if (jumpDetail != null) {
+				jumpDetail = jumpDetailV2Service.selectByPrimaryKey(jumpDetail.getId());
+				if (jumpDetail != null) {
+					jumpDetail.setNeedLogin(floatAD.isJumpNeedLogin());
+				}
+			}
+		}
+	}
+
+}
+

--
Gitblit v1.8.0