| | |
| | |
|
| | | 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;
|
| | |
| | | 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 AppVersionService appVersionService;
|
| | | |
| | | @Resource
|
| | | private CommonShareInfoService commonShareInfoService;
|
| | | |
| | | @Resource
|
| | | private ConfigService configService;
|
| | | |
| | |
|
| | | @Override
|
| | | public int insertSelective(SwiperPicture record) {
|
| | |
| | | }
|
| | |
|
| | | @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
|
| | |
| | | }
|
| | |
|
| | | @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, "参数不能为空");
|
| | | }
|
| | |
| | | if (id == null) {
|
| | | int maxOrder = swiperPictureMapper.getMaxOrderByBannerID(bannerId);
|
| | | record.setOrder(maxOrder + 1);
|
| | |
|
| | | Integer state = record.getState();
|
| | | // 默认停用
|
| | | if (state == null) {
|
| | |
| | | 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 (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);
|
| | | }
|
| | |
|
| | | /**
|
| | |
| | | if (!StringUtil.isNullOrEmpty(src)) {
|
| | | COSManager.getInstance().deleteFile(src);
|
| | | }
|
| | | |
| | | commonShareInfoService.deleteByPidAndType(swiperPicture.getId(), CommonShareInfoEnum.banner.name());
|
| | | }
|
| | |
|
| | | if (listSwiper != null)
|
| | |
| | |
|
| | | @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
|
| | | @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) {
|
| | |
| | | }
|
| | | }
|
| | | }
|
| | | return list;
|
| | | return transformVO(list);
|
| | | }
|
| | |
|
| | | /**
|
| | |
| | |
|
| | | @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) {
|
| | |
| | | }
|
| | | }
|
| | |
|
| | | 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)
|
| | |
| | | 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;
|
| | | }
|
| | |
|
| | | }
|