From de4110d3d3944ffcd797fd8c43f0d455cc731f84 Mon Sep 17 00:00:00 2001
From: yujian <yujian@163.com>
Date: 星期日, 17 五月 2020 11:43:52 +0800
Subject: [PATCH] 活动详情

---
 fanli/src/main/java/com/yeshi/fanli/service/impl/homemodule/SwiperPictureServiceImpl.java |  100 +++++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 83 insertions(+), 17 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 b0da86f..213727c 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
@@ -12,6 +12,7 @@
 
 import javax.annotation.Resource;
 
+import org.apache.commons.beanutils.PropertyUtils;
 import org.springframework.cache.annotation.Cacheable;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
@@ -22,15 +23,23 @@
 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 {
@@ -46,6 +55,13 @@
 
 	@Resource
 	private AppVersionService appVersionService;
+	
+	@Resource
+	private CommonShareInfoService commonShareInfoService;
+	
+	@Resource
+	private ConfigService configService;
+	
 
 	@Override
 	public int insertSelective(SwiperPicture record) {
@@ -68,8 +84,9 @@
 	}
 
 	@Override
-	public List<SwiperPicture> queryByBannerID(long start, int count, Long bannerId) throws SwiperPictureException {
-		return swiperPictureMapper.queryByBannerID(start, count, bannerId);
+	public List<BannerVO> queryByBannerID(long start, int count, Long bannerId) throws SwiperPictureException {
+		List<SwiperPicture> list = swiperPictureMapper.queryByBannerID(start, count, bannerId);
+		return transformVO(list);
 	}
 
 	@Override
@@ -78,9 +95,8 @@
 	}
 
 	@Override
-	public void saveObject(MultipartFile file, SwiperPicture record, String jumpType)
+	public void saveObject(MultipartFile file, SwiperPicture record, String jumpType, CommonShareInfo shareInfo)
 			throws SwiperPictureException, Exception {
-
 		if (record == null) {
 			throw new SwiperPictureException(1, "鍙傛暟涓嶈兘涓虹┖");
 		}
@@ -139,7 +155,6 @@
 		if (id == null) {
 			int maxOrder = swiperPictureMapper.getMaxOrderByBannerID(bannerId);
 			record.setOrder(maxOrder + 1);
-
 			Integer state = record.getState();
 			// 榛樿鍋滅敤
 			if (state == null) {
@@ -154,8 +169,9 @@
 			record.setCreatetime(new Date());
 			record.setUpdatetime(new Date());
 			record.setSrc(picture);
-
 			swiperPictureMapper.insert(record);
+			
+			shareInfo.setPid(record.getId());
 		} else {
 			// 淇敼
 			SwiperPicture resultObj = swiperPictureMapper.selectByPrimaryKey(id);
@@ -166,7 +182,6 @@
 			if (picture != null && picture.trim().length() > 0) {
 				// 鍒犻櫎宸插瓨鍦ㄥ浘鐗�
 				removePicture(resultObj);
-
 				record.setSrc(picture);
 			} else {
 				record.setSrc(resultObj.getSrc());
@@ -175,9 +190,14 @@
 			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);
 	}
 
 	/**
@@ -250,6 +270,8 @@
 			if (!StringUtil.isNullOrEmpty(src)) {
 				COSManager.getInstance().deleteFile(src);
 			}
+			
+			commonShareInfoService.deleteByPidAndType(swiperPicture.getId(), CommonShareInfoEnum.banner.name());
 		}
 
 		if (listSwiper != null)
@@ -265,6 +287,11 @@
 
 	@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);
 	}
 
@@ -285,7 +312,7 @@
 
 	@Override
 	@Cacheable(value = "bannerCache", key = "'getByBannerCard-'+#card")
-	public List<SwiperPicture> getByBannerCard(String card) {
+	public List<BannerVO> getByBannerCard(String card) {
 		List<SwiperPicture> list = swiperPictureMapper.getByBannerCard(card);
 		if (list != null && list.size() > 0) {
 			for (SwiperPicture swiperPicture : list) {
@@ -297,7 +324,7 @@
 				}
 			}
 		}
-		return list;
+		return transformVO(list);
 	}
 
 	/**
@@ -333,7 +360,7 @@
 
 	@Cacheable(value = "bannerCache", key = "'getByBannerCardAndVersion-'+#card+'-'+#platform+'-'+#version")
 	@Override
-	public List<SwiperPicture> getByBannerCardAndVersion(String card, String platform, int version) {
+	public List<BannerVO> getByBannerCardAndVersion(String card, String platform, int version) {
 		List<SwiperPicture> list = swiperPictureMapper.getByBannerCard(card);
 		filterSwipePicture(list, platform, version);
 		for (SwiperPicture picture : list) {
@@ -342,22 +369,23 @@
 			}
 		}
 
-		return list;
+		return transformVO(list);
 	}
 
 	@Override
 	@Cacheable(value = "bannerCache", key = "'getByBannerId-'+#bannerId")
-	public List<SwiperPicture> getByBannerId(Long bannerId) {
-		return swiperPictureMapper.getByBannerId(bannerId);
+	public List<BannerVO> getByBannerId(Long bannerId) {
+		List<SwiperPicture>  pictureList = swiperPictureMapper.getByBannerId(bannerId);
+		return transformVO(pictureList);
 	}
 
 	@Cacheable(value = "bannerCache", key = "'getByBannerId-'+#bannerId+'-'+#platform+'-'+#version")
 	@Override
-	public List<SwiperPicture> getByBannerId(Long bannerId, String platform, int version)
+	public List<BannerVO> getByBannerId(Long bannerId, String platform, int version)
 			throws SwiperPictureException {
 		List<SwiperPicture> pictureList = swiperPictureMapper.getByBannerId(bannerId);
 		filterSwipePicture(pictureList, platform, version);
-		return pictureList;
+		return transformVO(pictureList);
 	}
 
 	@Transactional(rollbackFor = Exception.class)
@@ -408,7 +436,45 @@
 				throw new SwiperPictureException(2, e.getMessage());
 			}
 		}
-
+	}
+	
+	
+	
+	/**
+	 * 杞崲VO
+	 * @param list
+	 * @return
+	 */
+	private List<BannerVO> transformVO(List<SwiperPicture> list) {
+		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.get(ConfigKeyEnum.activityDetailLink.getKey()) + "?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"));
+				}
+				listVo.add(bannerVO);
+			}
+		}
+		return listVo;
 	}
 
 }

--
Gitblit v1.8.0