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
package tkio.task;
import common.context.AppUtils;
import common.model.AppCategory;
import common.model.AppInfo;
import common.repository.AppCategoryRepository;
import common.repository.AppInfoRepository;
import common.repository.CityRepository;
import common.repository.UserRepository;
import dmp.model.TagCrawlerAppsWandoujia;
import dmp.repository.TagCrawlerAppsWandoujiaRepository;
import org.springframework.beans.factory.annotation.Autowired;
import security.annotation.Authorization;
import tkio.model.App;
import tkio.repository.AccountRepository;
import util.DateUtil;
import util.StringUtil;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
/**
* Created by zxy on 2017/12/26.
*/
public class SyncAppDataTask
{
@Autowired TagCrawlerAppsWandoujiaRepository tagRepository;
@Autowired AppInfoRepository appInfoRepository;
@Autowired AppCategoryRepository appCategoryRepository;
@Autowired CityRepository cityRepository;
public void syncAppData()
{
System.out.println(DateUtil.getBeforeDays(1));
List<TagCrawlerAppsWandoujia> list = tagRepository.findAllByDs("2017-12-15");
List<String> citys = cityRepository.findCitys();
List<AppInfo> appInfos = new ArrayList<>();
List<AppCategory> appCategories = appCategoryRepository.findAll();
Map<String, List<String>> map = new HashMap<>();
for (AppCategory appCategory : appCategories) {
List<String> innerList = map.get(appCategory.getLevel());
if (innerList == null) {
innerList = new ArrayList<>();
}
innerList.add(appCategory.getName());
map.put(appCategory.getLevel(), innerList);
}
List<AppCategory> newCategorys = new ArrayList<>();
List<AppInfo> newInfos = new ArrayList<>();
for (TagCrawlerAppsWandoujia tag : list) {
AppInfo appInfo = new AppInfo();
appInfo.setName(tag.getName());
appInfo.setCompany(tag.getMaker());
appInfo.setOs("Android");
appInfo.setPkgName(tag.getPkgname());
appInfo.setLogoUrl(tag.getApplogo_link());
String types = tag.getMix_types();
if (!StringUtil.isEmpty(types)) {
String[] typeArray = types.split("_");
String otherCase = "";
for (int i=0; i<typeArray.length; i++) {
if (map.containsKey(String.valueOf(i+1)) && !map.get(String.valueOf(i+1)).contains(typeArray[i])) {
List<String> mapValue = map.get(String.valueOf(i+1));
AppCategory newCate = new AppCategory();
newCate.setName(typeArray[i]);
newCate.setLevel(String.valueOf(i+1));
newCategorys.add(newCate);
mapValue.add(typeArray[i]);
map.put(String.valueOf(i+1), mapValue);
} else if (!map.containsKey(String.valueOf(i+1))) {
AppCategory newCate = new AppCategory();
newCate.setName(typeArray[i]);
newCate.setLevel(String.valueOf(i+1));
newCategorys.add(newCate);
List<String> mapValue = new ArrayList<>();
mapValue.add(typeArray[i]);
map.put(String.valueOf(i+1), mapValue);
}
if (i == 0) {
appInfo.setFirstCate(typeArray[i]);
}
if (i == 1) {
appInfo.setSecondCate(typeArray[i]);
}
if (i == 2) {
appInfo.setThirdCate(typeArray[i]);
}
if (i > 2) {
otherCase += "_" + typeArray[i];
}
}
if (otherCase.length() > 0) {
appInfo.setOtherCate(otherCase.substring(1));
}
}
for (String city : citys) {
if (tag.getMaker().indexOf(city) > -1) {
appInfo.setLocation(city);
break;
}
}
newInfos.add(appInfo);
System.out.println(appInfo);
}
appInfoRepository.save(newInfos);
appCategoryRepository.save(newCategorys);
}
public static void main(String[] args)
{
SyncAppDataTask task = new SyncAppDataTask();
task.syncAppData();
}
}