admin
2021-07-30 19533a17aa55fafc70d0a385928e785cb50e1ebc
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
package com.yeshi.buwan.acFun;
 
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
import javax.annotation.Resource;
 
import org.springframework.stereotype.Component;
 
import com.google.gson.JsonArray;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParseException;
import com.yeshi.buwan.service.imp.AcFunTypeService;
@Component
public class AcFunAdpater implements JsonDeserializer<List<AcFunVideo>>{
 
    @Resource
    private AcFunTypeService acFunTypeService;
    
    @Override
    public List<AcFunVideo> deserialize(JsonElement json, Type type,
            JsonDeserializationContext context) throws JsonParseException {
        List<AcFunVideo> acFunVideoList = new ArrayList<AcFunVideo>();
        if(json.isJsonArray()){
            JsonArray array = json.getAsJsonArray();
            AcFunVideo acFunVideo;
             Map<String,AcFunType> map = new HashMap<String,AcFunType>();
             List<AcFunType> list = acFunTypeService.getAcFunTypeList();
             for (AcFunType acFunType : list) {
                    map.put(acFunType.getCode(), acFunType);
                }
            for (int i = 0; i < array.size(); i++) {
                JsonElement acJson = array.get(i);
                if(acJson.isJsonObject()){
                    acFunVideo = new AcFunVideo();
                    JsonObject acObject = acJson.getAsJsonObject();
                    long id = acObject.get("id").getAsLong();
                    String url = acObject.get("playUrl").getAsString();
                    String img = acObject.get("videoThumbImg").getAsString();
                    String desc = acObject.get("videoDesc").getAsString();
                    JsonElement videoTag = acObject.get("videoTag");
                    String tag ="";
                    if(videoTag != null){
                        tag = acObject.get("videoTag").getAsString();
                    }
                    String title = acObject.get("videoTitle").getAsString();
                    long update = acObject.get("updatedAt").getAsLong();
                    int num = acObject.get("videoNum").getAsInt();
                    String vcode = acObject.get("videoType").getAsString();
                    AcFunType acType = map.get(vcode);
                    if(acType != null){
                        acFunVideo.setVideoType(acType);
                    }
                    acFunVideo.setId(id);
                    acFunVideo.setPlayUrl(url);
                    acFunVideo.setVideoDesc(desc);
                    acFunVideo.setVideoNum(num);
                    acFunVideo.setVideoTag(tag);
                    acFunVideo.setVideoThumbImg(img);
                    acFunVideo.setVideoTitle(title);
                    acFunVideo.setUpdateTime(update);
                    acFunVideoList.add(acFunVideo);
                }
            }
        }
        
        return acFunVideoList;
    }
 
}