| | |
| | | package com.yeshi.fanli.service.impl.help;
|
| | |
|
| | | import java.util.ArrayList;
|
| | | import java.util.Date;
|
| | | import java.util.HashSet;
|
| | | import java.util.List;
|
| | | import java.util.Set;
|
| | |
|
| | | import javax.annotation.Resource;
|
| | |
|
| | | import org.springframework.cache.annotation.Cacheable;
|
| | | import org.springframework.stereotype.Service;
|
| | | import org.springframework.transaction.annotation.Transactional;
|
| | |
|
| | | import com.yeshi.fanli.dao.mybatis.help.AppPageNotificationMapper;
|
| | | import com.yeshi.fanli.entity.AppVersionInfo;
|
| | | import com.yeshi.fanli.entity.bus.help.AppPageNotification;
|
| | | import com.yeshi.fanli.entity.bus.homemodule.AdActivityVersionControl;
|
| | | import com.yeshi.fanli.entity.bus.homemodule.FloatAD;
|
| | | import com.yeshi.fanli.entity.bus.homemodule.AdActivityVersionControl.AdActivityType;
|
| | | import com.yeshi.fanli.entity.common.JumpDetailV2;
|
| | | import com.yeshi.fanli.exception.banner.SwiperPictureException;
|
| | | import com.yeshi.fanli.service.inter.config.AppVersionService;
|
| | | import com.yeshi.fanli.service.inter.help.AppPageNotificationService;
|
| | | import com.yeshi.fanli.service.inter.homemodule.AdActivityVersionControlService;
|
| | | import com.yeshi.fanli.util.StringUtil;
|
| | |
|
| | | @Service
|
| | |
| | | @Resource
|
| | | private AppPageNotificationMapper appPageNotificationMapper;
|
| | |
|
| | | @Resource
|
| | | private AppVersionService appVersionService;
|
| | | |
| | | @Resource
|
| | | private AdActivityVersionControlService adActivityVersionControlService;
|
| | | |
| | | |
| | | @Override
|
| | | public AppPageNotification getAppPageNotificationByType(String type) {
|
| | |
|
| | | return appPageNotificationMapper.selectByType(type);
|
| | | }
|
| | |
|
| | | @Cacheable(value = "configCache", key = "'getValidNotificationByTypeCache-'+#type")
|
| | | @Cacheable(value = "configCache", key = "'getValidNotificationByTypeCache-'+#type+'-'+ #platform+'-'+#versionCode")
|
| | | @Override
|
| | | public AppPageNotification getValidNotificationByTypeCache(String type) {
|
| | | return appPageNotificationMapper.selectValidByType(type);
|
| | | public AppPageNotification getValidNotificationByTypeCache(String type, String platform, Integer versionCode) {
|
| | | AppPageNotification record = appPageNotificationMapper.selectValidByType(type);
|
| | | if (record == null)
|
| | | return null;
|
| | | |
| | | // 过滤版本
|
| | | AppVersionInfo app = appVersionService.getClientVersion(platform, versionCode);
|
| | | if (app == null) {
|
| | | return null;
|
| | | }
|
| | | List<Long> versionIdList = new ArrayList<>();
|
| | | versionIdList.add(app.getId());
|
| | | |
| | | List<Long> sourceIdList = new ArrayList<>();
|
| | | sourceIdList.add(record.getId());
|
| | | Set<Long> sourceIds = adActivityVersionControlService.filterSourceIdByVersion(sourceIdList,
|
| | | AdActivityType.notification, versionIdList);
|
| | | |
| | | if (!sourceIds.contains(record.getId())) {
|
| | | return null;
|
| | | }
|
| | | |
| | | return record;
|
| | | }
|
| | | |
| | |
|
| | | @Override
|
| | | public void addAppPageNotification(AppPageNotification apn) throws Exception {
|
| | |
| | | }
|
| | |
|
| | |
|
| | | @Transactional(rollbackFor = Exception.class)
|
| | | @Override
|
| | | public void setVersions(Long id, List<Long> versions) throws Exception {
|
| | | AppPageNotification record = appPageNotificationMapper.selectByPrimaryKey(id);
|
| | | if (record == null) {
|
| | | throw new Exception("专题不存在");
|
| | | }
|
| | |
|
| | | Set<Long> oldSet = new HashSet<>();
|
| | |
|
| | | List<AdActivityVersionControl> versionList = adActivityVersionControlService
|
| | | .listByTypeAndSourceId(AdActivityType.notification, id);
|
| | | 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.notification, 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(id);
|
| | | control.setType(AdActivityType.notification);
|
| | | control.setVersion(new AppVersionInfo(versionId));
|
| | | try {
|
| | | adActivityVersionControlService.addVersionControl(control);
|
| | | } catch (Exception e) {
|
| | | throw new SwiperPictureException(2, e.getMessage());
|
| | | }
|
| | | }
|
| | | }
|
| | | |
| | | }
|