Ver Código Fonte

首页搜索标签排序在专家表中出现次数混乱问题。

zzy.zhiyuan.foxmail 8 anos atrás
pai
commit
9dc604befc

+ 170 - 0
src/main/java/com/ekexiu/portal/job/DictTaskJobEntry.java

@ -0,0 +1,170 @@
1
package com.ekexiu.portal.job;
2

3
import java.sql.Connection;
4
import java.sql.ResultSet;
5
import java.sql.SQLException;
6
import java.sql.Statement;
7
import java.util.ArrayList;
8
import java.util.Collections;
9
import java.util.List;
10

11
import javax.sql.DataSource;
12

13
import org.apache.log4j.Logger;
14
import org.jfw.apt.annotation.Autowrie;
15
import org.jfw.apt.annotation.Bean;
16
import org.jfw.util.ListUtil;
17

18
import com.ekexiu.portal.pojo.DataDictCode;
19
import com.ekexiu.portal.service.DataDictService;
20
@Bean
21
public class DictTaskJobEntry implements Runnable{
22
	private static Logger logger = Logger.getLogger(TaskJobEntry.class);
23
	private long delayTime = 1;
24
	private int maxCount = 20;
25
	@Autowrie("dataSource")
26
	private DataSource dataSource;
27
	@Autowrie
28
	private DataDictService dataDictService;
29
	
30
	public DataDictService getDataDictService() {
31
		return dataDictService;
32
	}
33
	public void setDataDictService(DataDictService dataDictService) {
34
		this.dataDictService = dataDictService;
35
	}
36
	public DataSource getDataSource() {
37
		return dataSource;
38
	}
39
	public void setDataSource(DataSource dataSource) {
40
		this.dataSource = dataSource;
41
	}
42
	public long getDelayTime() {
43
		return delayTime;
44
	}
45
	public void setDelayTime(long delayTime) {
46
		this.delayTime = delayTime;
47
	}
48
	public int getMaxCount() {
49
		return maxCount;
50
	}
51
	public void setMaxCount(int maxCount) {
52
		this.maxCount = maxCount;
53
	}
54
	@Override
55
	public void run() {
56
		try {
57
			Connection con =dataSource.getConnection();
58
			try{
59
				Items items = this.fillSetValue(con, "SELECT INDUSTRY FROM PROFESSOR");
60
				List<Item> list = items.getItemByDescSort(this.maxCount);
61
				List<DataDictCode> dicts = new ArrayList<DataDictCode>();
62
				for(Item item:list){
63
					DataDictCode d = new DataDictCode();
64
					d.setCaption(item.getCaption());
65
					dicts.add(d);
66
				}
67
				this.dataDictService.setHotIndustries(dicts);
68
				
69
				items = this.fillSetValue(con, "SELECT SUBJECT FROM PROFESSOR");
70
				list = items.getItemByDescSort(this.maxCount);
71
				dicts = new ArrayList<DataDictCode>();
72
				for(Item item:list){
73
					DataDictCode d = new DataDictCode();
74
					d.setCaption(item.getCaption());
75
					dicts.add(d);
76
				}
77
				this.dataDictService.setHotSubjects(dicts);
78
				
79
            }catch(Exception e){
80
                try{con.rollback();
81
                }catch(Exception e1){e1.printStackTrace();}
82
            }finally{
83
                try{con.close();
84
                }catch(Exception e){e.printStackTrace();} 
85
            }
86
		} catch (Exception e) {
87
			e.printStackTrace();
88
		}
89
		
90
	}
91
	private Items fillSetValue(Connection con, String sql) throws SQLException {
92
		Items items = new Items();
93
		Statement st = con.createStatement();
94
		try {
95
			ResultSet rs = st.executeQuery(sql);
96
			try {
97
				while (rs.next()) {
98
					mergSet(rs.getString(1), items);
99
				}
100
			} finally {
101
				try {
102
					rs.close();
103
				} catch (Exception e) {
104
				}
105
			}
106
		} finally {
107
			try {
108
				st.close();
109
			} catch (Exception e) {
110
			}
111
		}
112
		return items;
113
	}
114
	private void mergSet(String valList, Items vals) {
115
		if (valList == null)
116
			return;
117
		List<String> ss = ListUtil.splitTrimExcludeEmpty(valList, ',');
118
		for(String str:ss){
119
			if(str!=null && str.length()>0)
120
			vals.add(str);
121
		}
122
	}
123

124
	private static class Items{
125
		private List<Item> items = new ArrayList<Item>();
126
		
127
		public void add(String itemCaption){
128
			for(Item item:this.items){
129
				if(itemCaption.equals(item.getCaption())){
130
					item.incVal();
131
					return;
132
				}
133
			}
134
			this.items.add(new Item(itemCaption));
135
		}
136
		public List<Item> getItemByDescSort(int limit){
137
			Collections.sort(this.items);
138
			if(limit< items.size()) return items;
139
			return items.subList(0, limit);
140
		}
141
	}
142
	private static class Item implements Comparable<Item>{
143
		private String caption;
144
		private long value = 1;
145

146
		public Item(String caption){
147
			this.caption = caption;
148
			this.value=1;
149
		}
150
		public String getCaption() {
151
			return caption;
152
		}
153

154
		public void setCaption(String caption) {
155
			this.caption = caption;
156
		}
157

158
		public void incVal(){
159
			++this.value;
160
		}
161

162
		@Override
163
		public int compareTo(Item o) {
164
			long anVal = o.value;
165
			return this.value>anVal?-1:this.value==anVal?0:1;
166
		}
167
		
168
	}
169
	
170
}

+ 0 - 63
src/main/java/com/ekexiu/portal/job/SchJob.java

@ -169,45 +169,6 @@ public class SchJob implements AfterBeanFactory {
169 169
			}
170 170
		}, 1, 5, TimeUnit.MINUTES);
171 171
		
172
//		this.service.scheduleWithFixedDelay(new Runnable() {
173
//			@Override
174
//			public void run() {
175
//				try {
176
//					Connection con = SchJob.this.dataSource.getConnection();
177
//					try {
178
//						Set<String> provinces = fillSetValue(con, " SELECT DISTINCT PROVINCE FROM PROFESSOR ");
179
//						Set<Map<String, String>> set = new HashSet<Map<String,String>>();
180
//						for (String province : provinces) {
181
//							Map<String, String> map = new HashMap<String, String>();
182
//							Set<String> all = fillSetValue(con, "SELECT DISTINCT ADDRESS FROM PROFESSOR WHERE PROVINCE = '"+province+"'");
183
//							for (String address : all) {
184
//								map.put(address, province);
185
//							}
186
//							set.add(map);
187
//							Set<String> exists = fillSetValue(con, "SELECT CAPTION FROM DATA_DICT WHERE DICT_CODE='ADDRESS'");
188
//							for (String s : exists){
189
//								all.remove(s);
190
//							}
191
//						}
192
//						batchAddCity(con, "ADDRESS", set);
193
//						con.commit();
194
//					} catch (SQLException e) {
195
//						try {
196
//							con.rollback();
197
//						} catch (SQLException ee) {
198
//						}
199
//						throw e;
200
//					} finally {
201
//						try {
202
//							con.close();
203
//						} catch (Exception e) {
204
//						}
205
//					}
206
//				} catch (Throwable th) {
207
//				}
208
//			}
209
//		}, 1, 5, TimeUnit.MINUTES);
210
211 172
	}
212 173
213 174
	private void mergSet(String valList, Set<String> vals) {
@ -260,28 +221,4 @@ public class SchJob implements AfterBeanFactory {
260 221
			}
261 222
		}
262 223
	}
263
//	private void batchAddCity(Connection con, String dictCode, Set<Map<String, String>> vals) throws SQLException {
264
//		if (vals.isEmpty())
265
//			return;
266
//		PreparedStatement ps = con.prepareStatement("INSERT INTO DATA_DICT(DICT_CODE,CODE,CAPTION,PARENT_CODE,ACTIVED) VALUES(?,?,?,?,'1')");
267
//		try {
268
//			for(Map<String, String> map : vals){
269
//				if(!map.isEmpty()){
270
//					for(Entry<String, String> entry : map.entrySet()){
271
//						ps.setString(1, dictCode);
272
//						ps.setString(2, StringUtil.buildUUID());
273
//						ps.setString(3, entry.getKey());
274
//						ps.setString(4, entry.getValue());
275
//						ps.addBatch();
276
//					}
277
//					ps.executeBatch();
278
//				}
279
//			}
280
//		} finally {
281
//			try {
282
//				ps.close();
283
//			} catch (Exception e) {
284
//			}
285
//		}
286
//	}
287 224
}

+ 7 - 2
src/main/java/com/ekexiu/portal/job/TaskJob.java

@ -19,6 +19,8 @@ public class TaskJob implements AfterBeanFactory {
19 19
	public void handle(BeanFactory bf) throws Throwable {
20 20
	
21 21
		TaskJobEntry tje = (TaskJobEntry) bf.getBean("com_ekexiu_portal_job_TaskJobEntry");
22
		UserLogTaskJobEntry ultje = (UserLogTaskJobEntry) bf.getBean("com_ekexiu_portal_job_UserLogTaskJobEntry");
23
		DictTaskJobEntry dtje =(DictTaskJobEntry) bf.getBean("com_ekexiu_portal_job_DictTaskJobEntry");
22 24
		long delayTime = tje.getDelayTime();
23 25
		long task = getTimeMillis(tje.getTaskTime());
24 26
		long taskTime = task - System.currentTimeMillis();
@ -26,8 +28,11 @@ public class TaskJob implements AfterBeanFactory {
26 28
		
27 29
        ScheduledExecutorService service = Executors.newSingleThreadScheduledExecutor();
28 30
        // 第二个参数为首次执行的延时时间,第三个参数为定时执行的间隔时间  
29
//        service.scheduleAtFixedRate(tje, 1, 7200, TimeUnit.SECONDS);
30
        service.scheduleAtFixedRate(tje, taskTime, delayTime, TimeUnit.MILLISECONDS);
31
//		service.scheduleAtFixedRate(tje, 1, 7200, TimeUnit.SECONDS);
32
//		service.scheduleAtFixedRate(ultje, 2, 86400, TimeUnit.SECONDS);
33
		service.scheduleAtFixedRate(tje, taskTime, delayTime, TimeUnit.MILLISECONDS);
34
		service.scheduleAtFixedRate(ultje, taskTime, delayTime, TimeUnit.MILLISECONDS);
35
		service.scheduleAtFixedRate(dtje, 0, dtje.getDelayTime(), TimeUnit.HOURS);
31 36
	}
32 37
	private static long getTimeMillis(String time) {  
33 38
	    try {  

+ 34 - 4
src/main/java/com/ekexiu/portal/service/DataDictService.java

@ -2,6 +2,7 @@ package com.ekexiu.portal.service;
2 2
3 3
import java.sql.Connection;
4 4
import java.sql.SQLException;
5
import java.util.ArrayList;
5 6
import java.util.List;
6 7
7 8
import org.jfw.apt.annotation.Autowrie;
@ -23,6 +24,9 @@ import com.ekexiu.portal.pojo.DataDictCode;
23 24
@Path("/dataDict")
24 25
public class DataDictService {
25 26
	
27
	private volatile List<DataDictCode> hotSubjects = new ArrayList<DataDictCode>();
28
	private volatile List<DataDictCode> hotIndustries = new ArrayList<DataDictCode>();
29
	
26 30
	@Autowrie
27 31
	private DataDictDao dataDictDao;
28 32
	
@ -46,6 +50,22 @@ public class DataDictService {
46 50
		   this.defautLimitQuerySize = defautLimitQuerySize;
47 51
	}
48 52
53
	public List<DataDictCode> getHotSubjects() {
54
		return hotSubjects;
55
	}
56
57
	public void setHotSubjects(List<DataDictCode> hotSubjects) {
58
		this.hotSubjects = hotSubjects;
59
	}
60
61
	public List<DataDictCode> getHotIndustries() {
62
		return hotIndustries;
63
	}
64
65
	public void setHotIndustries(List<DataDictCode> hotIndustries) {
66
		this.hotIndustries = hotIndustries;
67
	}
68
49 69
	@Post
50 70
	@Path
51 71
	public void insert(@JdbcConn(true) Connection con,String dictCode,String code,@Nullable String parentCode,String caption,String descp ) throws SQLException
@ -73,14 +93,24 @@ public class DataDictService {
73 93
	
74 94
	@Get
75 95
	@Path("/qa/{dictCode}")
76
	public List<DataDictCode> queryDict(@JdbcConn(false) Connection con, @PathVar String dictCode) throws SQLException{
77
		return this.dataDictDao.queryDictCode(con, dictCode);
96
	public List<DataDictCode> queryDict( @PathVar String dictCode) throws SQLException{
97
		 return this.queryDictCode(dictCode.equals("SUBJECT"));
78 98
	}
79 99
	
80 100
	@Get
81 101
	@Path("/qaDictCode")
82
	public List<DataDictCode> queryDictCode(@JdbcConn(false) Connection con, String dictCode) throws SQLException{
83
		return this.dataDictDao.queryDictCode(con, dictCode);
102
	public List<DataDictCode> queryDictCode(String dictCode) throws SQLException{
103
		 return this.queryDictCode(dictCode.equals("SUBJECT"));
104
	}
105
	
106
	private List<DataDictCode> queryDictCode(boolean isSubject){
107
		List<DataDictCode> ret = null;
108
		if(isSubject){
109
			ret = this.getHotSubjects();
110
		}else{
111
			ret = this.getHotIndustries();
112
		}
113
		return ret;
84 114
	}
85 115
	
86 116
	@Get