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/SwiperPictureServiceImpl.java |  751 +++++++++++++++++++++++++++++++++++++--------------------
 1 files changed, 491 insertions(+), 260 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 4864721..de18084 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,260 +1,491 @@
-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;
-
-import javax.annotation.Resource;
-import javax.transaction.Transactional;
-
-import org.springframework.cache.annotation.Cacheable;
-import org.springframework.stereotype.Service;
-import org.springframework.web.multipart.MultipartFile;
-import org.yeshi.utils.tencentcloud.COSManager;
-
-import com.yeshi.fanli.dao.mybatis.homemodule.SwiperPictureMapper;
-import com.yeshi.fanli.entity.bus.homemodule.SwiperPicture;
-import com.yeshi.fanli.entity.common.JumpDetailV2;
-import com.yeshi.fanli.exception.banner.SwiperPictureException;
-import com.yeshi.fanli.service.inter.common.JumpDetailV2Service;
-import com.yeshi.fanli.service.inter.homemodule.SwiperPictureService;
-import com.yeshi.fanli.util.StringUtil;
-
-@Service
-public class SwiperPictureServiceImpl implements SwiperPictureService {
-
-	@Resource
-	private SwiperPictureMapper swiperPictureMapper;
-	
-	@Resource
-	private JumpDetailV2Service jumpDetailV2Service;
-	
-
-
-	@Override
-	public int insertSelective(SwiperPicture record) throws SwiperPictureException{
-		return swiperPictureMapper.insertSelective(record);
-	}
-
-	@Override
-	public SwiperPicture selectByPrimaryKey(Long id) throws SwiperPictureException{
-		return swiperPictureMapper.selectByPrimaryKey(id);
-	}
-
-	@Override
-	public int updateByPrimaryKeySelective(SwiperPicture record) throws SwiperPictureException{
-		return swiperPictureMapper.updateByPrimaryKeySelective(record);
-	}
-
-	@Override
-	public int updateByPrimaryKey(SwiperPicture record) throws SwiperPictureException{
-		return swiperPictureMapper.updateByPrimaryKey(record);
-	}
-
-	@Override
-	public List<SwiperPicture> queryByBannerID(long start, int count, Long bannerId) throws SwiperPictureException{
-		return swiperPictureMapper.queryByBannerID(start, count, bannerId);
-	}
-
-	@Override
-	public long countQueryByBannerID(Long bannerId) throws SwiperPictureException{
-		return swiperPictureMapper.countQueryByBannerID(bannerId);
-	}
-
-	
-	@Override
-	public void saveObject(MultipartFile file, SwiperPicture record, String jumpType) throws SwiperPictureException, Exception{
-		
-		if (record == null) {
-			throw new SwiperPictureException(1, "鍙傛暟涓嶈兘涓虹┖");
-		}
-		
-		Long bannerId = record.getBannerId();
-		if (bannerId == null) {
-			throw new SwiperPictureException(1, "鏍囪瘑绠$悊ID涓嶈兘涓虹┖");
-		}
-		
-		String params = record.getParams();
-		if (params == null || params.trim().length() == 0 || "null".equalsIgnoreCase(params) ) {
-			record.setParams(null);
-		} else if (!StringUtil.isJson(params)) {
-			throw new SwiperPictureException(1, "璺宠浆鍙傛暟闈濲SON鏍煎紡");
-		}
-		
-		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();
-			// 榛樿鍋滅敤
-			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 {
-			// 淇敼
-			SwiperPicture resultObj = swiperPictureMapper.selectByPrimaryKey(id);
-			if (resultObj == null) {
-				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
-	public int deleteBatchByPrimaryKey(List<Long> list) throws SwiperPictureException{
-		
-		List<SwiperPicture> listSwiper = swiperPictureMapper.queryByListPrimaryKey(list);
-		for (SwiperPicture swiperPicture: listSwiper) {
-			String src = swiperPicture.getSrc();
-			if (!StringUtil.isNullOrEmpty(src)) {
-				COSManager.getInstance().deleteFile(src);
-			}
-		}
-		
-		return swiperPictureMapper.deleteBatchByPrimaryKey(list);
-	}
-
-	@Override
-	public int deleteBatchByBannerID(List<Long> list) throws SwiperPictureException{
-		return swiperPictureMapper.deleteBatchByBannerID(list);
-	}
-	
-	@Override
-	public List<SwiperPicture> queryByListBannerID(List<Long> list) throws Exception{
-		return swiperPictureMapper.queryByListBannerID(list);
-	}
-
-
-	@Override
-	public List<SwiperPicture> getOrderByBannerID(Long bannerId, Integer type, Integer order) throws SwiperPictureException {
-		return swiperPictureMapper.getOrderByBannerID(bannerId, type, order);
-	}
-
-	@Override
-	public int getMaxOrderByBannerID(Long bannerId) throws SwiperPictureException {
-		return swiperPictureMapper.getMaxOrderByBannerID(bannerId);
-	}
-	
-	@Override
-	@Cacheable(value = "bannerCache", key = "'getByBannerCard-'+#card")
-	public List<SwiperPicture> getByBannerCard(String card) throws SwiperPictureException {
-		List<SwiperPicture> list = swiperPictureMapper.getByBannerCard(card);
-		if (list != null && list.size() > 0) {
-			for (SwiperPicture swiperPicture: list) {
-				boolean needLogin = swiperPicture.isJumpNeedLogin();
-				JumpDetailV2 jumpDetail = swiperPicture.getJumpDetail();
-				if (jumpDetail != null) {
-					jumpDetail.setNeedLogin(needLogin);
-					swiperPicture.setJumpDetail(jumpDetail);
-				}
-			}
-		}
-		return list;
-	}
-	
-	
-	@Override
-	@Cacheable(value = "bannerCache", key = "'getByBannerId-'+#bannerId")
-	public List<SwiperPicture> getByBannerId(Long bannerId) throws SwiperPictureException {
-		return swiperPictureMapper.getByBannerId(bannerId);
-	}
-	
-}
-
+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.apache.commons.beanutils.PropertyUtils;
+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.SwiperPictureMapper;
+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.CommonShareInfo;
+import com.yeshi.fanli.entity.bus.homemodule.CommonShareInfo.CommonShareInfoEnum;
+import com.yeshi.fanli.entity.bus.homemodule.SwiperPicture;
+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.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.CommonShareInfoService;
+import com.yeshi.fanli.service.inter.homemodule.SwiperPictureService;
+import com.yeshi.fanli.util.FilePathEnum;
+import com.yeshi.fanli.util.StringUtil;
+import com.yeshi.fanli.vo.homemodule.BannerVO;
+
+import net.sf.json.JSONObject;
+
+@Service
+public class SwiperPictureServiceImpl implements SwiperPictureService {
+
+	@Resource
+	private SwiperPictureMapper swiperPictureMapper;
+
+	@Resource
+	private JumpDetailV2Service jumpDetailV2Service;
+
+	@Resource
+	private AdActivityVersionControlService adActivityVersionControlService;
+
+	@Resource
+	private AppVersionService appVersionService;
+	
+	@Resource
+	private CommonShareInfoService commonShareInfoService;
+	
+	@Resource
+	private ConfigService configService;
+	
+
+	@Override
+	public int insertSelective(SwiperPicture record) {
+		return swiperPictureMapper.insertSelective(record);
+	}
+
+	@Override
+	public SwiperPicture selectByPrimaryKey(Long id) {
+		return swiperPictureMapper.selectByPrimaryKey(id);
+	}
+
+	@Override
+	public int updateByPrimaryKeySelective(SwiperPicture record) {
+		return swiperPictureMapper.updateByPrimaryKeySelective(record);
+	}
+
+	@Override
+	public int updateByPrimaryKey(SwiperPicture record) {
+		return swiperPictureMapper.updateByPrimaryKey(record);
+	}
+
+	@Override
+	public List<SwiperPicture> queryByBannerID(long start, int count, Long bannerId) throws SwiperPictureException {
+		return swiperPictureMapper.queryByBannerID(start, count, bannerId);
+	}
+
+	@Override
+	public long countQueryByBannerID(Long bannerId) throws SwiperPictureException {
+		return swiperPictureMapper.countQueryByBannerID(bannerId);
+	}
+
+	@Override
+	public void saveObject(MultipartFile file, SwiperPicture record, String jumpType, CommonShareInfo shareInfo,SystemEnum system)
+			throws SwiperPictureException, Exception {
+		if (record == null) {
+			throw new SwiperPictureException(1, "鍙傛暟涓嶈兘涓虹┖");
+		}
+
+		Long bannerId = record.getBannerId();
+		if (bannerId == null) {
+			throw new SwiperPictureException(1, "鏍囪瘑绠$悊ID涓嶈兘涓虹┖");
+		}
+
+		String params = record.getParams();
+		if (params == null || params.trim().length() == 0 || "null".equalsIgnoreCase(params) || "\"null\"".equalsIgnoreCase(params)) {
+			record.setParams(null);
+		} else if (!StringUtil.isJson(params)) {
+			throw new SwiperPictureException(1, "璺宠浆鍙傛暟闈濲SON鏍煎紡");
+		} else {
+			record.setParams(params.trim());
+		}
+
+		String title = record.getTitle();
+		if (!StringUtil.isNullOrEmpty(title) && ("null".equalsIgnoreCase(title) || "\"null\"".equalsIgnoreCase(title))) { 
+			record.setTitle(null);
+		}
+		
+		String desc = record.getDesc();
+		if (!StringUtil.isNullOrEmpty(desc) && ("null".equalsIgnoreCase(desc) || "\"null\"".equalsIgnoreCase(desc))) { 
+			record.setDesc(null);
+		}
+		
+		
+		if (!StringUtil.isNullOrEmpty(jumpType)) {
+			List<JumpDetailV2> listByType = jumpDetailV2Service.listByType(jumpType,system);
+			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 remark = record.getRemark();
+		if (remark != null && (remark.trim().length() == 0 || remark.equalsIgnoreCase("null"))) {
+			record.setRemark(null);
+		}
+
+		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();
+			// 榛樿鍋滅敤
+			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);
+			
+			shareInfo.setPid(record.getId());
+		} else {
+			// 淇敼
+			SwiperPicture resultObj = swiperPictureMapper.selectByPrimaryKey(id);
+			if (resultObj == null) {
+				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);
+			
+			shareInfo.setPid(record.getId());
+		}
+		
+		// 娣诲姞琛ュ厖淇℃伅
+		shareInfo.setType(CommonShareInfoEnum.banner);
+		commonShareInfoService.save(shareInfo);
+	}
+
+	/**
+	 * 涓婁紶鍥剧墖
+	 * 
+	 * @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.swiper.getPath() + 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
+	public void switchState(Long id) throws SwiperPictureException {
+		if (id == null) {
+			throw new SwiperPictureException(1, "璇蜂紶閫掓纭弬鏁�");
+		}
+		
+		SwiperPicture resultObj = swiperPictureMapper.selectByPrimaryKey(id);
+		if (resultObj == null) {
+			throw new SwiperPictureException(1, "姝ゅ唴瀹瑰凡涓嶅瓨鍦�");
+		}
+		
+		Integer state = resultObj.getState();
+		if (state == null || state == 0) {
+			state = 1;
+		} else {
+			state = 0;
+		}
+		
+		SwiperPicture updateObj = new SwiperPicture();
+		updateObj.setId(id);
+		updateObj.setState(state);
+		updateObj.setJumpNeedLogin(resultObj.isJumpNeedLogin());
+		swiperPictureMapper.updateByPrimaryKeySelective(updateObj);
+	}
+
+	@Override
+	@Transactional(rollbackFor = Exception.class)
+	public int deleteBatchByPrimaryKey(List<Long> list) throws SwiperPictureException {
+		List<SwiperPicture> listSwiper = swiperPictureMapper.queryByListPrimaryKey(list);
+		for (SwiperPicture swiperPicture : listSwiper) {
+			String src = swiperPicture.getSrc();
+			if (!StringUtil.isNullOrEmpty(src)) {
+				COSManager.getInstance().deleteFile(src);
+			}
+			
+			commonShareInfoService.deleteByPidAndType(swiperPicture.getId(), CommonShareInfoEnum.banner.name());
+		}
+
+		if (listSwiper != null)
+			for (SwiperPicture picture : listSwiper) {
+				List<AdActivityVersionControl> versionList = adActivityVersionControlService
+						.listByTypeAndSourceId(AdActivityType.banner, picture.getId());
+				if (versionList != null)
+					for (AdActivityVersionControl control : versionList)
+						adActivityVersionControlService.deleteByPrimaryKey(control.getId());
+			}
+		return swiperPictureMapper.deleteBatchByPrimaryKey(list);
+	}
+
+	@Override
+	public int deleteBatchByBannerID(List<Long> list) throws SwiperPictureException {
+		if (list != null) {
+			for (Long id : list) {
+				commonShareInfoService.deleteByPidAndType(id, CommonShareInfoEnum.banner.name());
+			}
+		}
+		return swiperPictureMapper.deleteBatchByBannerID(list);
+	}
+
+	@Override
+	public List<SwiperPicture> queryByListBannerID(List<Long> list) throws Exception {
+		return swiperPictureMapper.queryByListBannerID(list);
+	}
+
+	@Override
+	public List<SwiperPicture> getOrderByBannerID(Long bannerId, Integer type, Integer order) {
+		return swiperPictureMapper.getOrderByBannerID(bannerId, type, order);
+	}
+
+	@Override
+	public int getMaxOrderByBannerID(Long bannerId) throws SwiperPictureException {
+		return swiperPictureMapper.getMaxOrderByBannerID(bannerId);
+	}
+
+	@Override
+	@Cacheable(value = "bannerCache", key = "'getByBannerCard-'+#card+'-'+#system")
+	public List<BannerVO> getByBannerCard(String card,SystemEnum system) {
+		List<SwiperPicture> list = swiperPictureMapper.getByBannerCard(card,system);
+		if (list != null && list.size() > 0) {
+			for (SwiperPicture swiperPicture : list) {
+				boolean needLogin = swiperPicture.isJumpNeedLogin();
+				JumpDetailV2 jumpDetail = swiperPicture.getJumpDetail();
+				if (jumpDetail != null) {
+					jumpDetail.setNeedLogin(needLogin);
+					swiperPicture.setJumpDetail(jumpDetail);
+				}
+			}
+		}
+		return transformVO(list,system);
+	}
+
+	/**
+	 * 涓撻鐗堟湰杩囨护
+	 * 
+	 * @param list
+	 * @param platform
+	 * @param versionCode
+	 */
+	private void filterSwipePicture(List<SwiperPicture> 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 (SwiperPicture picture : list) {
+			sourceIdList.add(picture.getId());
+		}
+
+		Set<Long> sourceIds = adActivityVersionControlService.filterSourceIdByVersion(sourceIdList,
+				AdActivityType.banner, versionIdList);
+		for (int i = 0; i < list.size(); i++) {
+			if (!sourceIds.contains(list.get(i).getId())) {
+				list.remove(i--);
+			}
+		}
+	}
+
+	@Cacheable(value = "bannerCache", key = "'getByBannerCardAndVersion-'+#card+'-'+#platform+'-'+#version+'-'+#system")
+	@Override
+	public List<BannerVO> getByBannerCardAndVersion(String card, String platform, int version,SystemEnum system) {
+		List<SwiperPicture> list = swiperPictureMapper.getByBannerCard(card,system);
+		filterSwipePicture(list, platform, version,system);
+		for (SwiperPicture picture : list) {
+			if (picture.isJumpNeedLogin() && picture.getJumpDetail() != null) {
+				picture.getJumpDetail().setNeedLogin(true);
+			}
+		}
+
+		return transformVO(list,system);
+	}
+
+	@Override
+	@Cacheable(value = "bannerCache", key = "'getByBannerId-'+#bannerId")
+	public List<BannerVO> getByBannerId(Long bannerId,SystemEnum system) {
+		List<SwiperPicture>  pictureList = swiperPictureMapper.getByBannerId(bannerId);
+		return transformVO(pictureList,system);
+	}
+
+	@Cacheable(value = "bannerCache", key = "'getByBannerId-'+#bannerId+'-'+#platform+'-'+#version+'-'+#system")
+	@Override
+	public List<BannerVO> getByBannerId(Long bannerId, String platform, int version,SystemEnum system)
+			throws SwiperPictureException {
+		List<SwiperPicture> pictureList = swiperPictureMapper.getByBannerId(bannerId);
+		filterSwipePicture(pictureList, platform, version,system);
+		return transformVO(pictureList,system);
+	}
+
+	@Transactional(rollbackFor = Exception.class)
+	@Override
+	public void setVersions(Long id, List<Long> versions) throws SwiperPictureException {
+		SwiperPicture swiperPicture = selectByPrimaryKey(id);
+		if (swiperPicture == null) {
+			throw new SwiperPictureException(1, "Banner涓嶅瓨鍦�");
+		}
+
+		Set<Long> oldSet = new HashSet<>();
+
+		List<AdActivityVersionControl> versionList = adActivityVersionControlService
+				.listByTypeAndSourceId(AdActivityType.banner, swiperPicture.getId());
+		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.banner, 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(swiperPicture.getId());
+			control.setType(AdActivityType.banner);
+			control.setVersion(new AppVersionInfo(versionId));
+			try {
+				adActivityVersionControlService.addVersionControl(control);
+			} catch (Exception e) {
+				throw new SwiperPictureException(2, e.getMessage());
+			}
+		}
+	}
+	
+	
+	
+	/**
+	 * 杞崲VO
+	 * @param list
+	 * @return
+	 */
+	private List<BannerVO> transformVO(List<SwiperPicture> list, SystemEnum system) {
+		List<BannerVO> listVo = new ArrayList<BannerVO>();
+		if (list != null && list.size() > 0) {
+			for (SwiperPicture swiperPicture: list) {
+				BannerVO bannerVO = new BannerVO();
+				try {
+					PropertyUtils.copyProperties(bannerVO, swiperPicture);
+				} catch (Exception e) {
+					e.printStackTrace();
+					continue;
+				}
+			
+				// 璺宠浆娲诲姩杩囨浮椤�
+				CommonShareInfo info = commonShareInfoService.getByPidAndType(bannerVO.getId(), 
+						CommonShareInfoEnum.banner.name());
+				if (info != null && !StringUtil.isNullOrEmpty(info.getComment())) {
+					String link = configService.getValue(ConfigKeyEnum.activityDetailLink.getKey(),system) + "?type=%s&id=%s";
+					link = String.format(link, CommonShareInfoEnum.banner.name(),bannerVO.getId());
+					
+					JSONObject params = new JSONObject();
+					params.put("url", link);
+					
+					bannerVO.setComment(info.getComment());
+					bannerVO.setParams(params.toString());
+					bannerVO.setJumpDetail(jumpDetailV2Service.getByTypeCache("web",system));
+				}
+				listVo.add(bannerVO);
+			}
+		}
+		return listVo;
+	}
+
+}

--
Gitblit v1.8.0