| | |
| | | package com.hxh.spring.test.ad; |
| | | |
| | | |
| | | import com.google.gson.*; |
| | | import com.yeshi.buwan.dao.jump.JumpDetailDao; |
| | | import com.yeshi.buwan.dao.recommend.FloatADDao; |
| | | import com.yeshi.buwan.domain.ad.AdAreaConfig; |
| | | import com.yeshi.buwan.domain.ad.ThirdAdType; |
| | | import com.yeshi.buwan.domain.jump.JumpDetail; |
| | | import com.yeshi.buwan.domain.jump.JumpTypeEnum; |
| | | import com.yeshi.buwan.domain.recommend.FloatAD; |
| | | import com.yeshi.buwan.domain.system.DetailSystem; |
| | | import com.yeshi.buwan.dto.ad.AdAreaConfigDto; |
| | | import com.yeshi.buwan.service.imp.SystemService; |
| | | import com.yeshi.buwan.service.inter.ad.AdAreaConfigService; |
| | | import com.yeshi.buwan.util.ad.AdAreaUtil; |
| | | import com.yeshi.buwan.util.factory.ad.AdAreaConfigFactory; |
| | | import com.yeshi.buwan.vo.ad.AdConfigTypeVO; |
| | | import org.json.JSONObject; |
| | | import org.junit.Test; |
| | | import org.junit.runner.RunWith; |
| | |
| | | import org.yeshi.utils.TimeUtil; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.Date; |
| | | import java.lang.reflect.Type; |
| | | import java.util.*; |
| | | |
| | | @RunWith(SpringJUnit4ClassRunner.class) |
| | | @ContextConfiguration(locations = {"classpath:spring.xml"}) |
| | |
| | | |
| | | @Resource |
| | | private FloatADDao floatADDao; |
| | | |
| | | @Resource |
| | | private AdAreaConfigService adAreaConfigService; |
| | | |
| | | @Test |
| | | public void addJumpDetail() { |
| | |
| | | ad.setParams(params.toString()); |
| | | ad.setPicture("https://ec-1255749512.cos.ap-guangzhou.myqcloud.com/resource/s11/float.png"); |
| | | ad.setShow(true); |
| | | ad.setShowStartTime(new Date(TimeUtil.convertToTimeTemp("2020-10-21","yyyy-MM-dd"))); |
| | | ad.setShowEndTime(new Date(TimeUtil.convertToTimeTemp("2020-11-12","yyyy-MM-dd"))); |
| | | ad.setShowStartTime(new Date(TimeUtil.convertToTimeTemp("2020-10-21", "yyyy-MM-dd"))); |
| | | ad.setShowEndTime(new Date(TimeUtil.convertToTimeTemp("2020-11-12", "yyyy-MM-dd"))); |
| | | ad.setWeight(1); |
| | | floatADDao.save(ad); |
| | | } |
| | |
| | | public void getFloatAd() { |
| | | floatADDao.list(true, new Date(), 1, 1); |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | @Test |
| | | public void addAdAreaConfig() { |
| | | AdAreaConfigDto config = new AdAreaConfigDto(); |
| | | config.setChannel("vivo"); |
| | | config.setDetailSystem(new DetailSystem(44L+"")); |
| | | config.setAdType(ThirdAdType.vivo); |
| | | config.setProvinces(Arrays.asList(new String[]{"广东", "浙江"})); |
| | | config.setPositions(Arrays.asList(new AdConfigTypeVO[]{AdConfigTypeVO.homeInterstitial, AdConfigTypeVO.videoDetailFullVideo})); |
| | | config.setStartTime("00:00:00"); |
| | | config.setEndTime("23:59:59"); |
| | | adAreaConfigService.addConfig(AdAreaConfigFactory.createBean(config)); |
| | | } |
| | | |
| | | @Test |
| | | public void updateAdAreaConfig() { |
| | | AdAreaConfigDto config = new AdAreaConfigDto(); |
| | | config.setStartTime("00:00:01"); |
| | | config.setEndTime("23:59:59"); |
| | | AdAreaConfig bean = AdAreaConfigFactory.createBean(config); |
| | | bean.setId(2L); |
| | | adAreaConfigService.updateConfig(bean); |
| | | } |
| | | |
| | | @Test |
| | | public void listAdAreaConfig() { |
| | | List<AdAreaConfig> mList = adAreaConfigService.listCache("huawei", 44L); |
| | | ThirdAdType adType = AdAreaUtil.getAdType("重庆", "深圳", AdConfigTypeVO.homeInterstitial, mList); |
| | | System.out.println(mList); |
| | | for (AdAreaConfig bean : mList) { |
| | | AdAreaConfigDto dto = AdAreaConfigFactory.createDTO(bean); |
| | | System.out.println(dto); |
| | | } |
| | | } |
| | | |
| | | private final Gson gson = new GsonBuilder() |
| | | .registerTypeAdapter(Date.class, new JsonSerializer<Date>() { |
| | | |
| | | @Override |
| | | public JsonElement serialize(Date src, Type typeOfSrc, JsonSerializationContext context) { |
| | | return src == null ? new JsonPrimitive("") : new JsonPrimitive(com.yeshi.buwan.util.TimeUtil.getGernalTime(src.getTime(), "yyyy.MM.dd HH:mm:ss")); |
| | | } |
| | | }).registerTypeAdapter(ThirdAdType.class, new JsonSerializer<ThirdAdType>() { |
| | | |
| | | @Override |
| | | public JsonElement serialize(ThirdAdType src, Type typeOfSrc, JsonSerializationContext context) { |
| | | return src == null ? new JsonPrimitive("") : new JsonPrimitive(src.name()); |
| | | } |
| | | }).registerTypeAdapter(AdConfigTypeVO.class, new JsonSerializer<AdConfigTypeVO>() { |
| | | |
| | | @Override |
| | | public JsonElement serialize(AdConfigTypeVO src, Type typeOfSrc, JsonSerializationContext context) { |
| | | return src == null ? new JsonPrimitive("") : new JsonPrimitive(src.getName()); |
| | | } |
| | | }) |
| | | .create(); |
| | | |
| | | @Resource |
| | | private SystemService systemService; |
| | | |
| | | @Test |
| | | public void testList(){ |
| | | |
| | | List<AdAreaConfig> list = adAreaConfigService.list(null, 1, 20); |
| | | Set<Long> detailSystemIds = new HashSet<>(); |
| | | for (AdAreaConfig ad : list) { |
| | | detailSystemIds.add(ad.getDetailSystemId()); |
| | | } |
| | | Map<Long, DetailSystem> detailSystemMap = new HashMap<>(); |
| | | for (Long sid : detailSystemIds) { |
| | | detailSystemMap.put(sid, systemService.getDetailSystemById(sid + "")); |
| | | } |
| | | |
| | | List<AdAreaConfigDto> flist = new ArrayList<>(); |
| | | for (AdAreaConfig ad : list) { |
| | | AdAreaConfigDto dto = AdAreaConfigFactory.createDTO(ad); |
| | | // dto.setDetailSystem(detailSystemMap.get(ad.getDetailSystemId())); |
| | | flist.add(dto); |
| | | } |
| | | System.out.println( gson.toJson(flist)); |
| | | |
| | | |
| | | } |
| | | |
| | | } |