From eec7e789a87863c25d92c10ad5dfc22ad80c448d Mon Sep 17 00:00:00 2001 From: admin <weikou2014> Date: 星期二, 14 七月 2020 12:36:48 +0800 Subject: [PATCH] 系统区分BUG修复 --- fanli/src/main/java/com/yeshi/fanli/service/impl/homemodule/SwiperPictureServiceImpl.java | 154 ++++++++++++++++++++++++++++++++++++++++++-------- 1 files changed, 128 insertions(+), 26 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..895fd7c 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,8 @@ 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; @@ -22,15 +24,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 +56,13 @@ @Resource private AppVersionService appVersionService; + + @Resource + private CommonShareInfoService commonShareInfoService; + + @Resource + private ConfigService configService; + @Override public int insertSelective(SwiperPicture record) { @@ -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, "鍙傛暟涓嶈兘涓虹┖"); } @@ -91,7 +107,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 +115,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 +166,6 @@ if (id == null) { int maxOrder = swiperPictureMapper.getMaxOrderByBannerID(bannerId); record.setOrder(maxOrder + 1); - Integer state = record.getState(); // 榛樿鍋滅敤 if (state == null) { @@ -154,8 +180,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 +193,6 @@ if (picture != null && picture.trim().length() > 0) { // 鍒犻櫎宸插瓨鍦ㄥ浘鐗� removePicture(resultObj); - record.setSrc(picture); } else { record.setSrc(resultObj.getSrc()); @@ -175,9 +201,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 +245,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 +298,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); } @@ -259,9 +322,9 @@ } @Override - @Cacheable(value = "bannerCache", key = "'getByBannerCard-'+#card") - public List<SwiperPicture> getByBannerCard(String card) { - List<SwiperPicture> list = swiperPictureMapper.getByBannerCard(card); + @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(); @@ -272,7 +335,7 @@ } } } - return list; + return transformVO(list,system); } /** @@ -282,10 +345,10 @@ * @param platform * @param versionCode */ - private void filterSwipePicture(List<SwiperPicture> list, String platform, int 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); + AppVersionInfo app = appVersionService.getClientVersion(platform, versionCode,system); if (app == null) { list.clear(); return; @@ -306,33 +369,34 @@ } } - @Cacheable(value = "bannerCache", key = "'getByBannerCardAndVersion-'+#card+'-'+#platform+'-'+#version") + @Cacheable(value = "bannerCache", key = "'getByBannerCardAndVersion-'+#card+'-'+#platform+'-'+#version+'-'+#system") @Override - public List<SwiperPicture> getByBannerCardAndVersion(String card, String platform, int version) { - List<SwiperPicture> list = swiperPictureMapper.getByBannerCard(card); - filterSwipePicture(list, platform, version); + 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 list; + return transformVO(list,system); } @Override @Cacheable(value = "bannerCache", key = "'getByBannerId-'+#bannerId") - public List<SwiperPicture> getByBannerId(Long bannerId) { - return swiperPictureMapper.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") + @Cacheable(value = "bannerCache", key = "'getByBannerId-'+#bannerId+'-'+#platform+'-'+#version+'-'+#system") @Override - public List<SwiperPicture> getByBannerId(Long bannerId, String platform, int version) + public List<BannerVO> getByBannerId(Long bannerId, String platform, int version,SystemEnum system) throws SwiperPictureException { List<SwiperPicture> pictureList = swiperPictureMapper.getByBannerId(bannerId); - filterSwipePicture(pictureList, platform, version); - return pictureList; + filterSwipePicture(pictureList, platform, version,system); + return transformVO(pictureList,system); } @Transactional(rollbackFor = Exception.class) @@ -383,7 +447,45 @@ 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")); + } + listVo.add(bannerVO); + } + } + return listVo; } } -- Gitblit v1.8.0