ScheduledTask.java
5.61 KB
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
package com.xkl.config;
import com.xkl.domain.*;
import com.xkl.model.CityModel;
import com.xkl.repository.*;
import lombok.extern.apachecommons.CommonsLog;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.util.*;
/**
* Created by win7 on 2016/11/21.
* 定时任务读取打分标准
*/
@Component
@CommonsLog
public class ScheduledTask implements Constants{
@Autowired
private XklAmpReportMetaScoreStandardRespository scoreStandardRespository;
@Autowired
private XklAmpReportMetaItemsRespository metaItemsRespository;
@Autowired
private XklAmpReportCategoryRespository reportCategoryRespository;
@Autowired
private XklAmpReportAveScoreRespository reportAveScoreRespository;
@Autowired
private XklCityRespository xklCityRespository;
@Scheduled(initialDelay = 0,fixedRate = 24*60*60*1000)
public void getTableMap(){
log.info("Load ScoreStandard and reportCategory Table");
Iterator<XklAmpReportMetaScoreStandardEntity> it=scoreStandardRespository.findAll().iterator();
while(it.hasNext()){
XklAmpReportMetaScoreStandardEntity scoreStandard=it.next();
scoreMap.put(scoreStandard.getItemId(),scoreStandard);
}
}
@Scheduled(initialDelay = 0,fixedRate = 24*60*60*1000)
public void getWeightedScoreMap(){
log.info("Load WeightedScore Table");
Iterator<XklAmpReportCategoryEntity> iterator = reportCategoryRespository.findAll().iterator();
while (iterator.hasNext()){
XklAmpReportCategoryEntity reportCategory = iterator.next();
weightedScoreMap.put(reportCategory.getId(),reportCategory);
}
}
@Scheduled(initialDelay = 0,fixedRate = 24*60*60*1000)
public void getItemMetaMap(){
log.info("Load ItemMeta Table");
Iterator<XklAmpReportMetaItemsEntity> it = metaItemsRespository.findAll().iterator();
while(it.hasNext()){
XklAmpReportMetaItemsEntity reportMetaItems = it.next();
if(reportMetaItems.getType()!=1) {//测试项目除外
itemMetaMap.put(reportMetaItems.getItemId(), reportMetaItems);
}else{
testItemSet.add(reportMetaItems.getItemId());
}
}
}
@Scheduled(initialDelay = 0,fixedRate = 24*60*60*1000)
public void getAveScoreMap(){
log.info("Load AveScore Table");
Iterator<XklAmpReportAverageScoreEntity> iterator = reportAveScoreRespository.findAll().iterator();
while (iterator.hasNext()){
XklAmpReportAverageScoreEntity reportCategory = iterator.next();
String ageAndType = reportCategory.getAgeId()+"-"+reportCategory.getScoreType();
aveScoreMap.put(ageAndType,reportCategory.getAverageScore());
}
}
@Scheduled(initialDelay = 0,fixedRate = 24*60*60*1000)
public void getCityMap(){
log.info("Load City Table");
Map<Long,XklCityEntity> idCityMap = new HashMap<>();
Iterator<XklCityEntity> iterator = xklCityRespository.findAll().iterator();
while(iterator.hasNext()){
XklCityEntity city = iterator.next();
idCityMap.put(city.getId(),city);
}
for (Map.Entry<Long, XklCityEntity> entry : idCityMap.entrySet()) {
long id = entry.getKey();
XklCityEntity xklCity = entry.getValue();
long parentId = xklCity.getParentId();
List<Long> idList = new ArrayList<>();
idList.add(id);
idList.add(parentId);
getIdList(parentId,idCityMap,idList);
CityModel cityModel = new CityModel();
if(idList.size()== Constants.ID_TYPE_COUNTRY){//国家级:中国000000
cityModel.setType(Constants.ID_TYPE_COUNTRY);
cityModel.setCountry(idList.get(0));
}else if(idList.size() == Constants.ID_TYPE_PROVINCE){//省级:北京110000,河北130000
cityModel.setType(Constants.ID_TYPE_PROVINCE);
cityModel.setCountry(idList.get(1));
cityModel.setProvince(idList.get(0));
}else if(idList.size() == Constants.ID_TYPE_CITY){//市级:东城区110101,石家庄市130100
cityModel.setType(Constants.ID_TYPE_CITY);
cityModel.setCountry(idList.get(2));
cityModel.setProvince(idList.get(1));
cityModel.setCity(idList.get(0));
}else if(idList.size() == Constants.ID_TYPE_COUNTY){//区级:石家庄市长安区130102
cityModel.setType(Constants.ID_TYPE_COUNTY);
cityModel.setCountry(idList.get(3));
cityModel.setProvince(idList.get(2));
cityModel.setCity(idList.get(1));
cityModel.setCounty(idList.get(0));
}else{
cityModel.setType(Constants.ID_TYPE_COUNTRY);
cityModel.setCountry(idList.get(0));
}
cityMap.put(xklCity.getIdCardCode(),cityModel);
}
log.info("load city table success");
}
/**
* 递归找parent,直到中国
* @param parentId
* @param idCityMap
* @param idList
*/
public void getIdList(long parentId,Map<Long,XklCityEntity> idCityMap,List<Long> idList){
if(parentId == 0) return;
XklCityEntity city = idCityMap.get(parentId);
if(city!=null){
long grandParentId = city.getParentId();
idList.add(grandParentId);
getIdList(grandParentId,idCityMap,idList);
}else{
return;
}
}
}