From b3da9f82b7740d39742fef1a81a56c22fe1c8b9c Mon Sep 17 00:00:00 2001 From: yujian <yujian@163.com> Date: 星期一, 08 六月 2020 17:27:02 +0800 Subject: [PATCH] 券后价调整 --- fanli/src/main/java/com/yeshi/fanli/service/impl/homemodule/SwiperPictureServiceImpl.java | 135 +++++++++++++++++++++++++++++++++++++++----- 1 files changed, 118 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 dd15da1..7f4e743 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) { @@ -78,9 +94,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, "鍙傛暟涓嶈兘涓虹┖"); } @@ -91,7 +106,7 @@ } String params = record.getParams(); - if (params == null || params.trim().length() == 0 || "null".equalsIgnoreCase(params)) { + 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鏍煎紡"); @@ -99,6 +114,17 @@ 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); if (listByType != null && listByType.size() > 0) { @@ -139,7 +165,6 @@ if (id == null) { int maxOrder = swiperPictureMapper.getMaxOrderByBannerID(bannerId); record.setOrder(maxOrder + 1); - Integer state = record.getState(); // 榛樿鍋滅敤 if (state == null) { @@ -154,8 +179,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 +192,6 @@ if (picture != null && picture.trim().length() > 0) { // 鍒犻櫎宸插瓨鍦ㄥ浘鐗� removePicture(resultObj); - record.setSrc(picture); } else { record.setSrc(resultObj.getSrc()); @@ -175,9 +200,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); } /** @@ -214,17 +244,44 @@ 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) @@ -240,6 +297,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); } @@ -260,7 +322,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) { @@ -272,7 +334,7 @@ } } } - return list; + return transformVO(list); } /** @@ -308,7 +370,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) { @@ -317,22 +379,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) @@ -383,7 +446,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