Browse Source

搜索页显示城市标签,增加城市数据字典。

zzy.zhiyuan.foxmail 8 years ago
parent
commit
e33c9875be

+ 33 - 0
src/main/java/com/ekexiu/portal/dao/DataDictDao.java

@ -72,6 +72,39 @@ public abstract class DataDictDao {
72 72
                    _result.add(dataDictCode);
73 73
                }
74 74
                return _result;
75
            }finally{
76
                try{rs.close();}catch(Exception e1){}
77
            }
78
        }finally{
79
            try{ps.close();}catch(Exception e2){}
80
        }
81
    }
82
	
83
	/**
84
	 * 按专家表地址字段出现的次数查询数据字典里的城市
85
	 * @param con
86
	 * @param dictCode 数据字典dictCode字段
87
	 * @param province 省份
88
	 * @return 返回数据字典caption
89
	 * @throws SQLException
90
	 */
91
	public List<DataDictCode> queryCity(Connection con,String dictCode,String province) throws SQLException{
92
        String sql = "SELECT "+dictCode+" FROM PROFESSOR LEFT JOIN DATA_DICT ON CAPTION = "+dictCode;
93
        if(province != null){
94
        	sql = sql+" AND PROVINCE = '"+province+"'";
95
        }
96
        sql = sql+" WHERE DICT_CODE = '"+dictCode+"' GROUP BY "+dictCode+" ORDER BY COUNT("+dictCode+") DESC LIMIT 20";
97
        PreparedStatement ps = con.prepareStatement(sql);
98
        try{
99
            ResultSet rs = ps.executeQuery();
100
            try{
101
                List<DataDictCode> _result = new ArrayList<DataDictCode>();
102
                while(rs.next()){
103
                	DataDictCode dataDictCode =  new DataDictCode();
104
                	dataDictCode.setCaption(rs.getString(1));
105
                    _result.add(dataDictCode);
106
                }
107
                return _result;
75 108
            }finally{
76 109
                try{rs.close();}catch(Exception _m_2){}
77 110
            }

+ 92 - 1
src/main/java/com/ekexiu/portal/job/SchJob.java

@ -118,7 +118,35 @@ public class SchJob implements AfterBeanFactory {
118 118
				try {
119 119
					Connection con = SchJob.this.dataSource.getConnection();
120 120
					try {
121
						Set<String> all = fillSetValue(con, "SELECT ADDRESS FROM PROFESSOR");
121
						Set<String> all = fillSetValue(con, "SELECT DISTINCT PROVINCE FROM PROFESSOR");
122
						Set<String> exists = fillSetValue(con, "SELECT CAPTION FROM DATA_DICT WHERE DICT_CODE='PROVINCE'");
123
						for (String s : exists)
124
							all.remove(s);
125
						batchAddCode(con, "PROVINCE", all);
126
						con.commit();
127
					} catch (SQLException e) {
128
						try {
129
							con.rollback();
130
						} catch (SQLException ee) {
131
						}
132
						throw e;
133
					} finally {
134
						try {
135
							con.close();
136
						} catch (Exception e) {
137
						}
138
					}
139
				} catch (Throwable th) {
140
				}
141
			}
142
		}, 1, 5, TimeUnit.MINUTES);
143
		this.service.scheduleWithFixedDelay(new Runnable() {
144
			@Override
145
			public void run() {
146
				try {
147
					Connection con = SchJob.this.dataSource.getConnection();
148
					try {
149
						Set<String> all = fillSetValue(con, "SELECT DISTINCT ADDRESS FROM PROFESSOR");
122 150
						Set<String> exists = fillSetValue(con, "SELECT CAPTION FROM DATA_DICT WHERE DICT_CODE='ADDRESS'");
123 151
						for (String s : exists)
124 152
							all.remove(s);
@ -140,6 +168,45 @@ public class SchJob implements AfterBeanFactory {
140 168
				}
141 169
			}
142 170
		}, 1, 5, TimeUnit.MINUTES);
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);
143 210
144 211
	}
145 212
@ -193,4 +260,28 @@ public class SchJob implements AfterBeanFactory {
193 260
			}
194 261
		}
195 262
	}
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
//	}
196 287
}

+ 6 - 0
src/main/java/com/ekexiu/portal/service/DataDictService.java

@ -77,6 +77,12 @@ public class DataDictService {
77 77
		return this.dataDictDao.queryDictCode(con, dictCode);
78 78
	}
79 79
	
80
	@Get
81
	@Path("/qaCity")
82
	public List<DataDictCode> queryCity(@JdbcConn(false) Connection con,String dictCode,@Nullable String province) throws SQLException{
83
		return this.dataDictDao.queryCity(con, dictCode, province);
84
	}
85
	
80 86
	@Get
81 87
	@Path("/{dictCode}/{code}")
82 88
	public DataDict query(@JdbcConn(false) Connection con,@PathVar String dictCode,@PathVar String code)throws SQLException{