| | |
| | | import java.io.InputStream;
|
| | | import java.text.ParseException;
|
| | | import java.text.SimpleDateFormat;
|
| | | import java.util.ArrayList;
|
| | | import java.util.Date;
|
| | | import java.util.HashSet;
|
| | | import java.util.List;
|
| | | import java.util.Set;
|
| | | import java.util.UUID;
|
| | |
|
| | | import javax.annotation.Resource;
|
| | |
|
| | | import org.springframework.cache.annotation.Cacheable;
|
| | | import org.springframework.stereotype.Service;
|
| | | import org.springframework.transaction.annotation.Transactional;
|
| | | import org.springframework.web.multipart.MultipartFile;
|
| | | import org.yeshi.utils.tencentcloud.COSManager;
|
| | |
|
| | | import com.yeshi.fanli.dao.mybatis.homemodule.FloatADMapper;
|
| | | 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.FloatAD;
|
| | | import com.yeshi.fanli.entity.bus.homemodule.FloatAD.FloatADTypeEnum;
|
| | | import com.yeshi.fanli.entity.common.JumpDetailV2;
|
| | | import com.yeshi.fanli.exception.banner.SwiperPictureException;
|
| | | import com.yeshi.fanli.exception.homemodule.FloatADException;
|
| | | import com.yeshi.fanli.service.inter.common.JumpDetailV2Service;
|
| | | import com.yeshi.fanli.service.inter.config.AppVersionService;
|
| | | import com.yeshi.fanli.service.inter.homemodule.AdActivityVersionControlService;
|
| | | import com.yeshi.fanli.service.inter.homemodule.FloatADService;
|
| | | import com.yeshi.fanli.util.FilePathEnum;
|
| | | import com.yeshi.fanli.util.StringUtil;
|
| | |
| | |
|
| | | @Resource
|
| | | private JumpDetailV2Service jumpDetailV2Service;
|
| | | |
| | | @Resource
|
| | | private AppVersionService appVersionService;
|
| | | |
| | | @Resource
|
| | | private AdActivityVersionControlService adActivityVersionControlService;
|
| | |
|
| | |
|
| | | @Override
|
| | |
| | | record.setParams(null);
|
| | | } else if (!StringUtil.isJson(params)) {
|
| | | throw new FloatADException(1, "跳转参数非JSON格式");
|
| | | } else {
|
| | | record.setParams(params.trim());
|
| | | }
|
| | |
|
| | | FloatADTypeEnum typeEnum = record.getTypeEnum();
|
| | |
| | | // 删除已存在图片
|
| | | for (FloatAD floatAD: listSwiper) {
|
| | | removePicture(floatAD.getPicture());
|
| | | |
| | | List<AdActivityVersionControl> versionList = adActivityVersionControlService
|
| | | .listByTypeAndSourceId(AdActivityType.floatAD, floatAD.getId());
|
| | | if (versionList != null)
|
| | | for (AdActivityVersionControl control : versionList)
|
| | | adActivityVersionControlService.deleteByPrimaryKey(control.getId());
|
| | | }
|
| | |
|
| | | return floatADMapper.deleteByPrimaryKeyList(list);
|
| | |
| | | return floatADMapper.countQuery(key, state);
|
| | | }
|
| | |
|
| | | @Cacheable(value = "configCache", key = "'getEffectiveFloatAD-'+#position+'-'+#type")
|
| | | @Override
|
| | | public FloatAD getEffectiveFloatAD(String position, Integer type) {
|
| | | FloatAD floatAD = floatADMapper.getEffectiveFloatAD(position, type);
|
| | |
| | | }
|
| | |
|
| | |
|
| | | @Transactional(rollbackFor = Exception.class)
|
| | | @Override
|
| | | public List<FloatAD> getValidCommonByPosition(String position) {
|
| | | return floatADMapper.getValidFloatAD(position, 1);
|
| | | public void setVersions(Long id, List<Long> versions) throws Exception {
|
| | | FloatAD record = floatADMapper.selectByPrimaryKey(id);
|
| | | if (record == null) {
|
| | | throw new Exception("专题不存在");
|
| | | }
|
| | |
|
| | | Set<Long> oldSet = new HashSet<>();
|
| | |
|
| | | List<AdActivityVersionControl> versionList = adActivityVersionControlService
|
| | | .listByTypeAndSourceId(AdActivityType.floatAD, 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.floatAD, 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.floatAD);
|
| | | control.setVersion(new AppVersionInfo(versionId));
|
| | | try {
|
| | | adActivityVersionControlService.addVersionControl(control);
|
| | | } catch (Exception e) {
|
| | | throw new SwiperPictureException(2, e.getMessage());
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | @Cacheable(value = "configCache", key = "'getValidFloatADCache-'+#position+'-'+#type+'-'+#platform+'-'+#versionCode")
|
| | | @Override
|
| | | public List<FloatAD> getValidByPosition(String position) {
|
| | | return floatADMapper.getValidFloatAD(position, null);
|
| | | public List<FloatAD> getValidFloatADCache(String position, Integer type, String platform, Integer versionCode) {
|
| | | List<FloatAD> list = floatADMapper.getValidFloatAD(position, type);
|
| | | // 过滤
|
| | | filterFloatAD(list, platform, versionCode);
|
| | | |
| | | return list;
|
| | | }
|
| | | |
| | | /**
|
| | | * 过滤
|
| | | * |
| | | * @param list
|
| | | * @param platform
|
| | | * @param versionCode
|
| | | */
|
| | | private void filterFloatAD(List<FloatAD> list, String platform, int versionCode) {
|
| | | if (list == null || list.size() == 0)
|
| | | return;
|
| | | AppVersionInfo app = appVersionService.getClientVersion(platform, versionCode);
|
| | | if (app == null) {
|
| | | list.clear();
|
| | | return;
|
| | | }
|
| | | List<Long> versionIdList = new ArrayList<>();
|
| | | versionIdList.add(app.getId());
|
| | | List<Long> sourceIdList = new ArrayList<>();
|
| | | for (FloatAD record : list) {
|
| | | sourceIdList.add(record.getId());
|
| | | }
|
| | |
|
| | | Set<Long> sourceIds = adActivityVersionControlService.filterSourceIdByVersion(sourceIdList,
|
| | | AdActivityType.floatAD, versionIdList);
|
| | | |
| | | for (int i = 0; i < list.size(); i++) {
|
| | | // 过滤版本
|
| | | if (!sourceIds.contains(list.get(i).getId())) {
|
| | | list.remove(i--);
|
| | | continue;
|
| | | }
|
| | | |
| | | // 跳转是否登录
|
| | | FloatAD floatAD = list.get(i);
|
| | | JumpDetailV2 jumpDetail = floatAD.getJumpDetail();
|
| | | if (jumpDetail != null) {
|
| | | jumpDetail = jumpDetailV2Service.selectByPrimaryKey(jumpDetail.getId());
|
| | | if (jumpDetail != null) {
|
| | | jumpDetail.setNeedLogin(floatAD.isJumpNeedLogin());
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | }
|
| | |
|