admin
2025-02-20 f537abe9f3646c739beaf15076246a2f71a347e9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
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.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration;
import org.yeshi.utils.StringUtil;
import org.yeshi.utils.TimeUtil;
 
import javax.annotation.Resource;
import java.lang.reflect.Type;
import java.util.*;
 
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath:spring.xml"})
@WebAppConfiguration
public class AdTest {
 
    @Resource
    private JumpDetailDao jumpDetailDao;
 
    @Resource
    private FloatADDao floatADDao;
 
    @Resource
    private AdAreaConfigService adAreaConfigService;
 
    @Test
    public void addJumpDetail() {
        JumpDetail detail = new JumpDetail();
        detail.setActivity("com.weikou.beibeivideo.ui.mine.BrowserActivity");
        detail.setController("");
        detail.setType(JumpTypeEnum.web);
        jumpDetailDao.save(detail);
    }
 
    @Test
    public void getJumpDetail() {
        JumpDetail detail = jumpDetailDao.selectByType(JumpTypeEnum.baichuan);
        System.out.println(detail);
    }
 
    @Test
    public void addFloatAd() {
        JumpDetail detail = jumpDetailDao.selectByType(JumpTypeEnum.baichuan);
        JSONObject params = new JSONObject();
        params.put("url", "https://s.click.taobao.com/kYgxJvu");
        FloatAD ad = new FloatAD();
        ad.setId(StringUtil.Md5(System.currentTimeMillis() + ""));
        ad.setJumpDetail(detail);
        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.setWeight(1);
        floatADDao.save(ad);
    }
 
 
    @Test
    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));
 
 
    }
 
}