提交 | 用户 | age
|
a6a76f
|
1 |
// ///////////////////////////////////////////////////////////////////////////////////// |
F |
2 |
// File: DBHelper.java |
|
3 |
// Description: Enter summary here after generation. |
|
4 |
// --------------------- |
|
5 |
// Copyright ? 2010 Our T110203Entity |
|
6 |
// --------------------- |
|
7 |
// History |
|
8 |
// 2010-01-25 14:37:13 Original Version |
|
9 |
// ///////////////////////////////////////////////////////////////////////////////////// |
|
10 |
|
|
11 |
package com.yc.service.impl; |
|
12 |
|
777a1e
|
13 |
import com.yc.action.grid.ExprotType; |
a6a76f
|
14 |
import com.yc.action.grid.GTGrid; |
F |
15 |
import com.yc.entity.attachment.AttachmentEntity; |
|
16 |
import com.yc.factory.FactoryBean; |
|
17 |
import com.yc.pwd.Encrypt; |
|
18 |
import com.yc.sdk.password.action.ChangePassword; |
97a11f
|
19 |
import com.yc.service.customControl.ControlLayoutIfc; |
a6a76f
|
20 |
import com.yc.service.dao.c_sys_cr_pageDao; |
F |
21 |
import com.yc.service.panel.SqlDBHelperIfc; |
|
22 |
import com.yc.utils.SessionKey; |
4257cf
|
23 |
import org.apache.commons.lang.StringUtils; |
a6a76f
|
24 |
import org.slf4j.Logger; |
F |
25 |
import org.slf4j.LoggerFactory; |
|
26 |
|
|
27 |
import javax.servlet.http.HttpServletRequest; |
|
28 |
import javax.servlet.http.HttpSession; |
|
29 |
import java.io.UnsupportedEncodingException; |
|
30 |
import java.math.BigDecimal; |
dc7ad9
|
31 |
import java.net.URLDecoder; |
a6a76f
|
32 |
import java.sql.*; |
F |
33 |
import java.text.SimpleDateFormat; |
|
34 |
import java.util.Date; |
|
35 |
import java.util.*; |
|
36 |
import java.util.regex.Matcher; |
|
37 |
import java.util.regex.Pattern; |
4257cf
|
38 |
import java.util.stream.Collectors; |
a6a76f
|
39 |
|
F |
40 |
/** |
|
41 |
* DBhelper |
|
42 |
* |
|
43 |
* @author PengBei |
|
44 |
*/ |
|
45 |
public class DBHelper { |
|
46 |
public static String path = ""; |
|
47 |
public static Connection connection = null; |
|
48 |
public static PreparedStatement pStatement = null; |
|
49 |
public static Statement statement = null; |
|
50 |
public static ResultSet rSet = null; |
|
51 |
public static ResultSetMetaData rsmd = null; |
|
52 |
public static String panelTitle = ""; |
|
53 |
public static String sql = null; |
|
54 |
public static int resultNum = 0;// 以上编码不再使用 |
|
55 |
public static final c_sys_cr_pageDao cDao = new c_sys_cr_Parent(); |
|
56 |
public static Encrypt encryptHelper = new Encrypt(); |
|
57 |
public static Logger log = LoggerFactory.getLogger("DBHelper"); // Logger.getLogger("DBHelper"); |
|
58 |
// end-- |
|
59 |
/** |
|
60 |
* 把session写成\"+session.getAttribute(key)+\"字符串 |
|
61 |
*/ |
|
62 |
public static final String AT_SESSION_STR = "session_str"; |
|
63 |
/** |
|
64 |
* 把session写成jsp<%=session.getAttribute(key)%>字符串 |
|
65 |
*/ |
|
66 |
public static final String AT_SESSION_JSP_STR = "SESSION_JSP_STR"; |
|
67 |
/** |
|
68 |
* 控制默认时间格式 |
|
69 |
*/ |
|
70 |
private static final String FORMAT_DATA = "yyyy-MM-dd"; |
|
71 |
|
|
72 |
/** |
|
73 |
* 测试连接是否成功 |
|
74 |
* |
|
75 |
* @param drive |
|
76 |
* @param url |
|
77 |
* @param user 用户 |
|
78 |
* @param password 密码 |
|
79 |
* @return 成功:true |
|
80 |
* @throws Exception by danaus 增加错误输出 |
|
81 |
*/ |
|
82 |
public static boolean getConnTest(String drive, String url, String user, String password) |
|
83 |
throws Exception { |
|
84 |
boolean boo = false; |
|
85 |
Connection connection = null; |
|
86 |
try { |
|
87 |
// password = |
|
88 |
// DBHelper.encryptHelper.decrypt(DBHelper.encryptHelper.decrypt(password)); |
|
89 |
if (password != null && !"".equals(password)) { |
|
90 |
// String publicKey = RSAUtils.getPublicKeyFromKeyFile(); |
|
91 |
// byte[] mypassword = Base64Utils.decode(password); |
|
92 |
// byte[] decodedData = RSAUtils.decryptByPublicKey(mypassword, publicKey); |
|
93 |
// password = new String(decodedData); |
|
94 |
//改用私钥解密 xin 2019-9-29 16:31:09 |
|
95 |
password = ChangePassword.getDecryptPassword(password); |
|
96 |
} |
|
97 |
Class.forName(drive); |
|
98 |
connection = DriverManager.getConnection(url, user, password); |
|
99 |
if (connection != null) { |
|
100 |
boo = true; |
|
101 |
} |
|
102 |
} catch (ClassNotFoundException e) { |
|
103 |
throw e; |
|
104 |
} catch (SQLException e) { |
|
105 |
throw e; |
|
106 |
} finally { |
|
107 |
closeConection(connection); |
|
108 |
} |
|
109 |
return boo; |
|
110 |
} |
|
111 |
|
|
112 |
/** |
|
113 |
* 获得连接 |
|
114 |
* |
|
115 |
* @return |
|
116 |
*/ |
|
117 |
public static Connection getConnection() { |
|
118 |
SqlDBHelperIfc sHelperIfc = (SqlDBHelperIfc) FactoryBean.getBean("SqlDBHelper"); |
|
119 |
Connection connection = null; |
|
120 |
try { |
|
121 |
connection = sHelperIfc.getConnection(); |
|
122 |
} catch (SQLException e) { |
|
123 |
e.printStackTrace(); |
|
124 |
} |
|
125 |
return connection; |
|
126 |
} |
|
127 |
|
|
128 |
/** |
|
129 |
* 关闭Conection连接 |
|
130 |
* |
|
131 |
* @param connection |
|
132 |
*/ |
|
133 |
public static void closeConection(Connection connection) { |
|
134 |
if (connection != null) { |
|
135 |
try { |
|
136 |
connection.close(); |
|
137 |
} catch (SQLException e) { |
|
138 |
e.printStackTrace(); |
|
139 |
} |
|
140 |
connection = null; |
|
141 |
} |
|
142 |
} |
|
143 |
|
|
144 |
/** |
|
145 |
* 关闭ResultSet |
|
146 |
* |
|
147 |
* @param rSet |
|
148 |
*/ |
|
149 |
public static void closeResltSet(ResultSet rSet) { |
|
150 |
if (rSet != null) { |
|
151 |
try { |
|
152 |
rSet.close(); |
|
153 |
} catch (SQLException e) { |
|
154 |
e.printStackTrace(); |
|
155 |
} |
|
156 |
rSet = null; |
|
157 |
} |
|
158 |
} |
|
159 |
|
|
160 |
/** |
|
161 |
* 关闭PreparedStatement |
|
162 |
* |
|
163 |
* @param pStatement |
|
164 |
*/ |
|
165 |
public static void closePreparedStatement(PreparedStatement pStatement) { |
|
166 |
if (pStatement != null) { |
|
167 |
try { |
|
168 |
pStatement.close(); |
|
169 |
} catch (SQLException e) { |
|
170 |
e.printStackTrace(); |
|
171 |
} |
|
172 |
pStatement = null; |
|
173 |
} |
|
174 |
} |
|
175 |
|
|
176 |
/** |
|
177 |
* 关闭所有连接,按照关闭次序关闭 |
|
178 |
* |
|
179 |
* @param connection Connection |
|
180 |
* @param pStatement PreparedStatement |
|
181 |
* @param rSet ResultSet |
|
182 |
*/ |
|
183 |
public static void closeAll(Connection connection, PreparedStatement pStatement, ResultSet rSet) { |
|
184 |
if (rSet != null) { |
|
185 |
closeResltSet(rSet); |
|
186 |
} |
|
187 |
if (pStatement != null) { |
|
188 |
closePreparedStatement(pStatement); |
|
189 |
} |
|
190 |
if (connection != null) { |
|
191 |
closeConection(connection); |
|
192 |
} |
|
193 |
} |
|
194 |
|
|
195 |
/** |
|
196 |
* 关闭所有连接 (已经尽量不用) |
|
197 |
*/ |
|
198 |
public static void closeAll() { |
|
199 |
closeAll(connection, pStatement, rSet); |
|
200 |
} |
|
201 |
|
|
202 |
/** |
|
203 |
* @param str 判断的字符 |
|
204 |
* @param returnStr 但str为null或者""时的返回字符 |
|
205 |
* @return |
|
206 |
*/ |
|
207 |
public static String isNull(String str, String returnStr) { |
|
208 |
return isNull(str, returnStr, "UTF-8"); |
|
209 |
} |
|
210 |
|
|
211 |
/** |
|
212 |
* @param str 判断的字符 |
|
213 |
* @param returnStr 但str为null或者""时的返回字符 |
|
214 |
* @param ecoding 编码 用此重新编码字符串 |
|
215 |
* @return |
|
216 |
*/ |
|
217 |
public static String isNull(String str, String returnStr, String ecoding) { |
|
218 |
if (str == null || "".endsWith(str.trim())) { |
|
219 |
return returnStr; |
|
220 |
} else { |
|
221 |
try { |
|
222 |
String eco = "UTF-8"; |
|
223 |
if (!(eco).equals(ecoding)) { |
|
224 |
str = new String(str.getBytes(eco), ecoding);// 解决中文乱码 |
|
225 |
} |
|
226 |
|
|
227 |
} catch (UnsupportedEncodingException e) { |
|
228 |
e.printStackTrace(); |
|
229 |
} |
|
230 |
} |
|
231 |
return str; |
|
232 |
} |
|
233 |
|
|
234 |
/** |
|
235 |
* @param str 判断的字符 |
|
236 |
* @param returnStr 但str为null或者""时的返回字符 |
|
237 |
* @return |
|
238 |
*/ |
|
239 |
public static String isNull(String str, int returnStr) { |
|
240 |
return isNull(str, String.valueOf(returnStr)); |
|
241 |
} |
|
242 |
|
|
243 |
/** |
|
244 |
* 获得dataStr中的日期数 |
|
245 |
* |
|
246 |
* @param dataStr 如:"1988-01-26 00:00:00.0"或"1988-01-26 00:00:000" |
|
247 |
* @return |
|
248 |
*/ |
|
249 |
public static Calendar getData(String dataStr) { |
|
250 |
Calendar calendar = null; |
|
251 |
if (!dataStr.trim().equals("")) { |
|
252 |
calendar = Calendar.getInstance(); |
|
253 |
String[] strs = dataStr.split(" "); |
|
254 |
String[] datas = strs[0].split("-"); |
|
255 |
String[] backDay; |
|
256 |
if (strs.length > 1) { |
|
257 |
backDay = strs[1].split(":"); |
|
258 |
calendar.set(Calendar.HOUR_OF_DAY, Integer.parseInt(backDay[0])); |
|
259 |
calendar.set(Calendar.MINUTE, Integer.parseInt(backDay[1])); |
|
260 |
if (backDay.length > 2) { |
|
261 |
// calendar.set(Calendar.SECOND, |
|
262 |
// Integer.parseInt(backDay[2].replace(".", "")));//28.987 |
|
263 |
// 居然有这这样的值 |
|
264 |
calendar.set(Calendar.SECOND, Integer.parseInt(backDay[2].replace(".", "").substring(0, 2))); |
|
265 |
} |
|
266 |
} |
|
267 |
calendar.set(Calendar.YEAR, Integer.parseInt(datas[0])); |
|
268 |
calendar.set(Calendar.MONTH, Integer.parseInt(datas[1]) - 1); |
|
269 |
calendar.set(Calendar.DATE, Integer.parseInt(datas[2])); |
|
270 |
} |
|
271 |
return calendar; |
|
272 |
} |
|
273 |
|
|
274 |
/** |
|
275 |
* @param map 集合 key为小写 |
|
276 |
* @param col 集合中的key字符 |
|
277 |
* @return int |
|
278 |
*/ |
|
279 |
public static int getValueInt(Map<String, Object> map, String col) { |
|
280 |
return getValue(map, col).trim().equals("") ? 0 : Integer.parseInt(getValue(map, col).trim());// trim()方法不能少 |
|
281 |
// ,出现" |
|
282 |
// 80"这种情况的话,不去空格转换int型会出现错误。2014-7-10 |
|
283 |
// 18:02:49 |
|
284 |
} |
|
285 |
|
|
286 |
/** |
|
287 |
* @param map key为小写 |
|
288 |
* @param col 自动转为小写 |
|
289 |
* @return null或者去除空格为"" 都返回"" |
|
290 |
*/ |
|
291 |
public static String getValue(Map<String, Object> map, String col) { |
|
292 |
col = col.toLowerCase(); |
|
293 |
return (map != null) |
|
294 |
? (map.get(col) == null || ("").equals(map.get(col).toString().trim())) ? "" : map.get(col).toString() |
|
295 |
: ""; |
|
296 |
} |
|
297 |
|
|
298 |
/** |
|
299 |
* @param map 控件值集合 |
|
300 |
* @param col 控件字段名称 |
|
301 |
* @param mapInfo 控件设置集合 |
|
302 |
* @return 按照设置显示值 |
|
303 |
*/ |
|
304 |
public static String getValue(Map<String, Object> map, String col, Map<String, Map<String, String>> mapInfo) { |
|
305 |
col = col.toLowerCase();// 字段名 |
|
306 |
String value = (map.get(col) == null || ("").equals(map.get(col).toString().trim())) ? "" |
|
307 |
: map.get(col).toString(); |
|
308 |
// 权限控制字段 0为只读 |
|
309 |
String _e = (map.get(col + "_expr") == null || ("").equals(map.get(col + "_expr").toString().trim())) ? "" |
|
310 |
: map.get(col + "_expr").toString(); |
|
311 |
|
|
312 |
if (mapInfo != null && mapInfo.get(col) != null) { |
|
313 |
String format = mapInfo.get(col).get("format");// 9082数字格式设置值 |
|
314 |
|
|
315 |
String typeStr = mapInfo.get(col).get("type").trim(); |
|
316 |
typeStr = typeStr.equals("") ? "1" : typeStr;// 判断控件类型为空的情况 |
|
317 |
int type = Integer.parseInt(typeStr); |
|
318 |
if (format != null && !format.trim().equals("")) { |
|
319 |
value = getToFormat(value, format, type); |
|
320 |
} |
|
321 |
if (typeStr.equals("37") && value.indexOf("style") != -1) {// 解决37控件富文本css样式问题--xin |
|
322 |
// 2016-4-7 |
|
323 |
// 19:58:44 |
|
324 |
value = value.replace("'", "");// 把'符号去掉 |
|
325 |
} |
|
326 |
} |
|
327 |
// 检查是否存在“符号,有则吧”符号转译。(如不转译的话“符号后面的信息就被截断,无法显示出来)--xin 2016-6-20 |
|
328 |
// 10:01:43 |
|
329 |
value = value.indexOf("\"") != -1 ? value.replaceAll("\"", """) : value; |
|
330 |
|
|
331 |
if (_e.equals("0")) {// 为0没有权限看改字段值 用*****表示。 |
|
332 |
return value = "******"; |
|
333 |
} else { |
|
334 |
return value; |
|
335 |
} |
|
336 |
|
|
337 |
} |
|
338 |
|
|
339 |
/** |
|
340 |
* 保留两位小数点 |
|
341 |
* |
|
342 |
* @param value |
|
343 |
* @return |
|
344 |
*/ |
|
345 |
public static boolean isDouble(String value) { |
|
346 |
try { |
|
347 |
Double.parseDouble(value);// 是否是数字 |
|
348 |
if (value.contains(".")) |
|
349 |
return true; |
|
350 |
return false; |
|
351 |
} catch (NumberFormatException e) { |
|
352 |
return false; |
|
353 |
} |
|
354 |
} |
|
355 |
|
|
356 |
/** |
|
357 |
* @param map 控件值集合 |
|
358 |
* @param col 控件字段名称 |
|
359 |
* @param mapInfo 控件设置集合 |
|
360 |
* @return 按照设置显示值 |
|
361 |
*/ |
|
362 |
public static String getValueStr(Map<String, String> map, String col, Map<String, Map<String, String>> mapInfo) { |
|
363 |
col = col.toLowerCase(); |
|
364 |
String value = (map.get(col) == null || ("").equals(map.get(col).trim())) ? "" : map.get(col); |
|
365 |
if (mapInfo != null && mapInfo.get(col) != null) { |
|
366 |
String format = mapInfo.get(col).get("format"); |
|
367 |
String typeStr = mapInfo.get(col).get("type").trim(); |
|
368 |
typeStr = typeStr.equals("") ? "1" : typeStr;// 判断控件类型为空的情况 |
|
369 |
int type = Integer.parseInt(typeStr); |
|
370 |
value = getToFormat(value, format, type); |
|
371 |
} |
|
372 |
return value; |
|
373 |
} |
|
374 |
|
|
375 |
/** |
|
376 |
* 将数字numStr(字符形式)保留pointNum位小数,四舍五入 |
|
377 |
* |
|
378 |
* @param numStr 字符形式数字 |
|
379 |
* @param pointNum 保留位数 |
|
380 |
* @return String |
|
381 |
*/ |
|
382 |
public static String formatNum(String numStr, int pointNum) { |
|
383 |
String zero = "0000000000000"; |
|
384 |
String retNum = ""; |
|
385 |
if (!isNum(numStr)) { |
|
386 |
return "不是数字"; |
|
387 |
} |
|
388 |
int len = 0;// 小数点后的长度 |
|
389 |
if (numStr.indexOf(".") != -1) { |
|
390 |
String pointEnd = numStr.substring(numStr.indexOf(".") + 1); |
|
391 |
len = pointEnd.length(); |
|
392 |
if (len <= pointNum) { |
|
393 |
retNum = numStr + zero.substring(0, pointNum - len);// 后面添加零个数 |
|
394 |
} else { |
|
395 |
int numTo = 0; |
|
396 |
if (pointNum < 0) {// 后加控制整数格式化 负数即为格式化成整数 |
|
397 |
retNum = numStr.substring(0, numStr.indexOf(".")); |
|
398 |
numTo = Integer.parseInt(pointEnd.substring(0, 1)); |
|
399 |
} else { |
|
400 |
retNum = numStr.substring(0, numStr.indexOf(".") + 1) + pointEnd.substring(0, pointNum);// 截取到保留位 |
|
401 |
numTo = Integer.parseInt(pointEnd.substring(pointNum, pointNum + 1));// 保留位后的一个数 |
|
402 |
} |
|
403 |
if (numTo > 4) { |
|
404 |
retNum = Add(retNum); |
|
405 |
} |
|
406 |
if (pointNum == 0 && retNum.lastIndexOf(".") != -1) {// 保留零位去点 |
|
407 |
retNum = retNum.substring(0, retNum.indexOf(".")); |
|
408 |
} |
|
409 |
} |
|
410 |
} else { |
|
411 |
retNum = numStr + zero.substring(0, pointNum);// 后面添加零个数 |
|
412 |
} |
|
413 |
return retNum; |
|
414 |
} |
|
415 |
|
|
416 |
/** |
|
417 |
* 将一个数字末位上加1,和大于10就再在前一位上加1 |
|
418 |
* |
|
419 |
* @param doubleNum 数字形式的字符串 |
|
420 |
* @return |
|
421 |
*/ |
|
422 |
private static String Add(String doubleNum) { |
|
423 |
String str = ""; |
|
424 |
int len = doubleNum.length(); |
|
425 |
String retNum = ""; |
|
426 |
String endString = ""; |
|
427 |
for (int i = 0; i < len; i++) { |
|
428 |
retNum = doubleNum.substring(len - 1 - i, len - i);// 截取保留位的数 |
|
429 |
if (".".equals(retNum)) {// 点就继续 |
|
430 |
continue; |
|
431 |
} |
|
432 |
endString = doubleNum.substring(len - i, len); |
|
433 |
double num = Double.parseDouble(retNum) + 1; |
|
434 |
// 实际上就是把要加的数分三部分,前面未动的,中间要计算的,末尾不计算的 |
|
435 |
if (num >= 10) { |
|
436 |
doubleNum = doubleNum.substring(0, len - 1 - i) + String.valueOf(num).substring(1, 2) + endString; |
|
437 |
if (i == len - 1) {// 比原始数加多出一位 |
|
438 |
doubleNum = "1" + doubleNum; |
|
439 |
} |
|
440 |
} else { |
|
441 |
doubleNum = doubleNum.substring(0, len - 1 - i) + String.valueOf(num).substring(0, 1) + endString; |
|
442 |
break; |
|
443 |
} |
|
444 |
} |
|
445 |
if (doubleNum.indexOf(".") == doubleNum.length() - 1) { |
|
446 |
doubleNum = doubleNum.substring(0, doubleNum.length() - 1); |
|
447 |
} |
|
448 |
str = doubleNum; |
|
449 |
return str; |
|
450 |
} |
|
451 |
|
|
452 |
/** |
|
453 |
* 判断此字符能否转成数字double类型 |
|
454 |
* |
|
455 |
* @param num 字符串数字 |
|
456 |
* @return 是数字为True |
|
457 |
*/ |
|
458 |
public static boolean isNum(String num) { |
|
459 |
try { |
|
460 |
Double.parseDouble(num); |
|
461 |
} catch (Exception e) { |
|
462 |
// 只做捕获,不让程序死掉就行了 |
|
463 |
return false; |
|
464 |
} |
|
465 |
return true; |
|
466 |
} |
|
467 |
|
|
468 |
/** |
|
469 |
* @param num 要格式化的值 |
|
470 |
* @param format 设置中的格式 |
|
471 |
* @return 返回格式后的值 |
|
472 |
*/ |
|
473 |
public static String getFormatNum(String num, String format) { |
|
474 |
String numStr = ""; |
|
475 |
// 设置中.后多小位,无为0,整数 |
|
476 |
int endDianNum = 0; |
|
477 |
// 前面的分割,设置,无了就3个一递进 |
|
478 |
String benginStr = ""; |
|
479 |
if (format.lastIndexOf(".") != -1) { |
|
480 |
endDianNum = format.substring((format.lastIndexOf("."))).length(); |
|
481 |
benginStr = format.substring(0, format.lastIndexOf(".")); |
|
482 |
benginStr = benginStr.equals("") ? "0" : benginStr; |
|
483 |
} else { |
|
484 |
benginStr = format; |
|
485 |
} |
|
486 |
num = formatNum(num, endDianNum - 1); |
|
487 |
int fenge = 3;// 3位一分割 |
|
488 |
String charAtStr = ""; |
|
489 |
int j = 0;// 计数 |
|
490 |
if (!isNum(benginStr) || !isNum(num)) {// 即是数字没什么东西分割 |
|
491 |
numStr = num; |
|
492 |
} else { |
|
493 |
if (benginStr.length() == 2) {// 是两位 ,9.00或,#.00设置 |
|
494 |
numStr = (endDianNum != 0) ? num.substring(num.lastIndexOf(".")) : ""; |
|
495 |
for (int i = endDianNum; i < num.length(); i++) { |
|
496 |
charAtStr = String.valueOf(num.charAt(num.length() - i - 1)); |
|
497 |
j++; |
|
498 |
if (j % fenge == 0 && i != num.length() - 1) { |
|
499 |
numStr = benginStr.charAt(0) + charAtStr + numStr; |
|
500 |
} else { |
|
501 |
numStr = charAtStr + numStr; |
|
502 |
} |
|
503 |
} |
|
504 |
} else { |
|
505 |
String oneStr = String.valueOf(benginStr.charAt(benginStr.length() - 1)); |
|
506 |
String charAt1 = ""; |
|
507 |
numStr = (endDianNum != 0) ? num.substring(num.lastIndexOf(".")) : ""; |
|
508 |
j = 0; |
|
509 |
for (int i = 0; i < benginStr.length(); i++) { |
|
510 |
charAt1 = String.valueOf(benginStr.charAt(benginStr.length() - i - 1)); |
|
511 |
if (oneStr.equals(charAt1)) { |
|
512 |
charAtStr = String.valueOf(num.charAt(num.length() - i - 1 - endDianNum + j)); |
|
513 |
numStr = charAtStr + numStr; |
|
514 |
} else { |
|
515 |
j++; |
|
516 |
numStr = charAt1 + numStr; |
|
517 |
} |
|
518 |
if (i == num.length() - 1 - endDianNum + j) {// 格式设置长度大于显示数长度 |
|
519 |
break; |
|
520 |
} |
|
521 |
} |
|
522 |
// 格式设置长度小于显示数长度 |
|
523 |
if (num.length() - endDianNum + j > benginStr.length()) { |
|
524 |
numStr = num.substring(0, num.length() - endDianNum - benginStr.length() + j) + numStr; |
|
525 |
} |
|
526 |
} |
|
527 |
} |
|
528 |
return numStr; |
|
529 |
} |
|
530 |
|
|
531 |
/** |
|
532 |
* @param str 数据字符 |
|
533 |
* @param format 格式设置 |
|
534 |
* @param type 控件类型 |
|
535 |
* @return 放回该空间应该显示的格式化的值 |
|
536 |
*/ |
|
537 |
public static String getToFormat(String str, String format, int type) { |
|
538 |
String returString = ""; |
|
539 |
String retNumStr = ""; |
|
540 |
if (format != null && !"".endsWith(format)) { |
|
541 |
SimpleDateFormat sFormat = new SimpleDateFormat(format); |
|
542 |
if (type == 5) {// 是日期控件 |
|
543 |
returString = getStrToDataFrame(str, sFormat); |
|
544 |
} else { |
|
545 |
try { |
|
546 |
retNumStr = getFormatNum(str, format); |
|
547 |
} catch (Exception e) { |
|
548 |
if (!str.matches("^[-+]?(([0-9]+)([.]([0-9]+))?|([.]([0-9]+))?)$")) { // 确定是科学计算 |
|
549 |
BigDecimal bds = new BigDecimal(str); |
|
550 |
str = bds.toPlainString(); |
|
551 |
retNumStr = getFormatNum(str, format); |
|
552 |
} |
|
553 |
} |
|
554 |
returString = retNumStr;// 没错的情况下就是他的转换格式 |
|
555 |
if (retNumStr.indexOf(".") != -1) { // 是否有小数点 有则不处理 |
|
556 |
// 没有就判断是否是“不是数字” 没有 那就是科学计算 |
|
557 |
// 对科学计算进行处理。 |
|
558 |
} else if ("不是数字".equals(retNumStr)) { |
|
559 |
returString = getStrToDataFrame(str, sFormat); // 格式化 日期字符 |
|
560 |
} else { |
|
561 |
if (!returString.matches("^[-+]?(([0-9]+)([.]([0-9]+))?|([.]([0-9]+))?)$")) { // 确定是科学计算 |
|
562 |
BigDecimal bd = new BigDecimal(str); // 对double类型变成了科学计算的值进行处理,不处理输出的值是科学计算值与数据库值错误。 |
|
563 |
str = bd.toPlainString(); // 转换回小数 不再是科学计算的值 |
|
564 |
returString = getFormatNum(str, format); |
|
565 |
} |
|
566 |
} |
|
567 |
// if ("不是数字".equals(retNumStr)) { 注释掉 |
|
568 |
// 是把这条件写到上面的retNumStr.indexOf(".") !=-1一起判断 |
|
569 |
// returString = getStrToDataFrame(str, sFormat); //格式化 日期字符 |
|
570 |
// } |
|
571 |
} |
|
572 |
} else { |
|
573 |
if (!str.equals("") && type == 5) {// 是日期控件 且不为空 |
|
574 |
returString = getToFormat(str, FORMAT_DATA, 5); |
|
575 |
} else { |
|
576 |
returString = str; |
|
577 |
} |
|
578 |
} |
|
579 |
return (returString == null) ? "" : returString; |
|
580 |
} |
|
581 |
|
|
582 |
/** |
|
583 |
* 格式化 日期字符 |
|
584 |
* |
|
585 |
* @param str 日期形式的字符串 如 1700-10-01 00:00.000 |
|
586 |
* @param sFormat 日期格式化对象 |
|
587 |
* @return |
|
588 |
*/ |
|
589 |
private static String getStrToDataFrame(String str, SimpleDateFormat sFormat) { |
|
590 |
Date date = null; |
|
591 |
try { |
|
592 |
date = getData(str).getTime(); |
|
593 |
if (!str.trim().equals("")) { |
|
594 |
str = sFormat.format(date); |
|
595 |
} |
|
596 |
} catch (Exception e) {// 以时间转换也出错 |
|
597 |
// str = "";//居然直接有str=2012或者str=1谁知道这是什么时间啊,原值返回 |
|
598 |
} |
|
599 |
return str; |
|
600 |
} |
|
601 |
|
|
602 |
/** |
|
603 |
* 去除字符串中的换行符 |
|
604 |
*/ |
|
605 |
public static String replaceBr(String str) { |
|
606 |
if (str == null) { |
|
607 |
return ""; |
|
608 |
} |
|
609 |
Pattern p = Pattern.compile("\r|\n"); |
|
610 |
Matcher m = p.matcher(str); |
|
611 |
return m.replaceAll(""); |
|
612 |
} |
|
613 |
|
|
614 |
/** |
|
615 |
* 替换字符换行符,"\r \n"特殊字符 |
|
616 |
* |
|
617 |
* @param str |
|
618 |
* @return |
|
619 |
*/ |
|
620 |
public static String replaceBlankOnWeb(String str) { |
|
621 |
if (str == null) { |
|
622 |
return ""; |
|
623 |
} |
|
624 |
str = str.replaceAll("\r \n", "\r\n"); |
|
625 |
return str; |
|
626 |
} |
|
627 |
|
|
628 |
/** |
|
629 |
* 去除字符串中的换行符空格等 |
|
630 |
*/ |
|
631 |
public static String replaceBlank(String str) { |
|
632 |
if (str == null) { |
|
633 |
return ""; |
|
634 |
} |
|
635 |
Pattern p = Pattern.compile("\\s*|\t|\r|\n"); |
|
636 |
Matcher m = p.matcher(str); |
|
637 |
return m.replaceAll(""); |
|
638 |
} |
|
639 |
|
|
640 |
/** |
|
641 |
* @param str 字符串 |
|
642 |
* @param tiStr 不区分大小写 被替换的字符 |
|
643 |
* @param tiToString 要替换成的字符 |
|
644 |
* @param addDian 是不是给值加上单一号 true 为加上 |
|
645 |
* @return |
|
646 |
*/ |
|
647 |
public static String getRep(String str, String tiStr, String tiToString, boolean addDian) { |
|
648 |
String retString = str; |
|
649 |
str = str.toLowerCase(); |
|
650 |
String bianStr = ""; |
|
651 |
tiStr = tiStr.toLowerCase(); |
|
652 |
int index = str.indexOf(tiStr);// 确定位置 |
|
653 |
int len = tiStr.length();// 确定长度 |
|
654 |
tiToString = (addDian) ? "'" + tiToString + "'" : tiToString;// 是否要加上单引号 |
|
655 |
while (index != -1) { |
|
656 |
bianStr += retString.substring(0, index) + tiToString; |
|
657 |
str = str.substring(index + len); |
|
658 |
retString = retString.substring(index + len); |
|
659 |
index = str.indexOf(tiStr); |
|
660 |
} |
|
661 |
return bianStr + retString; |
|
662 |
} |
|
663 |
|
|
664 |
/** |
|
665 |
* 储存过程执行替换字符 ---xin 2017-7-3 14:46:58 |
|
666 |
* |
|
667 |
* @param str 字符串 |
|
668 |
* @param tiStr 不区分大小写 被替换的字符 |
|
669 |
* @param tiToString 要替换成的字符 |
|
670 |
* @param addDian 是不是给值加上单一号 true 为加上 |
|
671 |
* @return |
|
672 |
*/ |
|
673 |
public static String getProcess(String str, Map<String, Object> tiTo, boolean addDian) { |
|
674 |
String bianStr = ""; |
|
675 |
String retString = str; |
|
676 |
if (!str.trim().equals("")) { |
|
677 |
String[] retS = {"doccode", "formid"}; |
|
678 |
String str1 = str.toLowerCase().split(" ")[2]; |
|
679 |
retString = str1; |
|
680 |
// Pattern pattern = Pattern.compile("[0-9]*"); |
|
681 |
for (String rets1 : retS) { |
|
682 |
String tiToString = ((tiTo != null && tiTo.get(rets1) != null) ? tiTo.get(rets1).toString() : "''"); |
|
683 |
// Matcher isNum = pattern.matcher(tiToString); |
|
684 |
// if( !isNum.matches() ){ |
|
685 |
// addDian=false; |
|
686 |
// } |
|
687 |
addDian = (rets1.equals("formid") ? false : addDian); |
|
688 |
int index = str1.indexOf(rets1);// 确定位置 |
|
689 |
int len = rets1.length();// 确定长度 |
|
690 |
tiToString = (addDian) ? "'" + tiToString + "'" : tiToString;// 是否要加上单引号 |
|
691 |
while (index != -1) { |
|
692 |
bianStr += retString.substring(0, index) + tiToString; |
|
693 |
str1 = str1.substring(index + len); |
|
694 |
retString = retString.substring(index + len); |
|
695 |
index = str1.indexOf(rets1); |
|
696 |
} |
|
697 |
} |
|
698 |
bianStr = str.toLowerCase().split(" ")[0] + " " + str.toLowerCase().split(" ")[1] + " " + bianStr; |
|
699 |
} |
|
700 |
return bianStr + retString; |
|
701 |
} |
|
702 |
|
|
703 |
/** |
|
704 |
* @param parm 替换参数 key:要替换的对象 value 替换成的对象 |
|
705 |
* @param str 需要替换的字符 |
|
706 |
* @return 返回替换后的字符 |
|
707 |
*/ |
|
708 |
public static String getRep(Map<String, String> parm, String str) { |
|
709 |
String retString = str;// 原字符 |
|
710 |
str = str.toLowerCase();// 处理字符 |
|
711 |
String bianStr = ""; |
|
712 |
String[] r_ = getIndexAndKek(parm, str); |
|
713 |
int index = Integer.parseInt(r_[0]);// 确定位置 |
|
714 |
int len = r_[1].length();// 确定长度 |
|
715 |
while (index != -1) { |
|
716 |
bianStr += retString.substring(0, index) + parm.get(r_[1]); |
|
717 |
str = str.substring(index + len); |
|
718 |
retString = retString.substring(index + len); |
|
719 |
r_ = getIndexAndKek(parm, str); |
|
720 |
index = Integer.parseInt(r_[0]); |
|
721 |
len = r_[1].length();// 确定长度 |
|
722 |
} |
|
723 |
return bianStr + retString; |
|
724 |
} |
|
725 |
|
|
726 |
/** |
|
727 |
* 查找要替换字符最近而且替换字符是最长一个的位置和字符 |
|
728 |
* |
|
729 |
* @param parm 所有要替换的字符 key 为要替换的字符 value要替换成的字符(value此时不需要) |
|
730 |
* @param str 要查找替换的字符 |
|
731 |
* @return String[]{位置,需替换字符} |
|
732 |
*/ |
|
733 |
private static String[] getIndexAndKek(Map<String, String> parm, String str) { |
|
734 |
String[] r_ = new String[]{"-1", ""};// 给初始值 |
|
735 |
int index = 0; |
|
736 |
int indexDan = str.length(); |
|
737 |
String tiStr = ""; |
|
738 |
for (String key : parm.keySet()) { |
|
739 |
tiStr = key.toLowerCase(); |
|
740 |
index = str.indexOf(tiStr); |
|
741 |
if (index != -1 && (indexDan > index || (indexDan == index && r_[1].length() < key.length()))) {// 而且替换最长的先 |
|
742 |
indexDan = index; |
|
743 |
r_[0] = String.valueOf(indexDan); |
|
744 |
r_[1] = key; |
|
745 |
} |
|
746 |
} |
|
747 |
return r_; |
|
748 |
} |
|
749 |
|
|
750 |
/** |
|
751 |
* @param obj 未知对象 |
|
752 |
* @param add 是否为其加单引号 |
|
753 |
* @return String |
|
754 |
*/ |
|
755 |
public static String getAddYin(Object obj, boolean add) { |
|
756 |
String value = (obj != null) ? obj.toString() : ""; |
|
757 |
return add ? "'" + value + "'" : value; |
|
758 |
} |
|
759 |
|
|
760 |
/** |
|
761 |
* 返回session字符的写法 |
|
762 |
* |
|
763 |
* @param key session中的键 |
|
764 |
* @param panString 判断写法 |
|
765 |
* @param sesBoo 不存在session时是否以session形式值获得 true为session中获得key false为key变量值 |
|
766 |
* @return String |
|
767 |
*/ |
|
768 |
private static String getSessionStr(String key, String panString, boolean sesBoo) { |
|
769 |
return getSessionStr(key, panString, sesBoo, null); |
|
770 |
} |
|
771 |
|
|
772 |
/** |
|
773 |
* @param key 处理字段 键或者变量名 |
|
774 |
* @param panString 形式的写法 主要两种\""+key+"\"和<%=key%> |
|
775 |
* @param sesBoo 不存在session时是否以session形式值获得 true为session中获得key false为key变量值 |
|
776 |
* @param session session 有即存在 |
|
777 |
* @return |
|
778 |
*/ |
|
779 |
private static String getSessionStr(String key, String panString, boolean sesBoo, HttpSession session) { |
|
780 |
String string = null; |
|
781 |
if (session == null) { |
|
782 |
if (panString.equals(AT_SESSION_STR)) { |
|
783 |
string = sesBoo ? "\"+session.getAttribute(\"" + key + "\")+\"" : "\"+" + key + "+\""; |
|
784 |
} else if (panString.equals(AT_SESSION_JSP_STR)) { |
|
785 |
string = sesBoo ? "<%=session.getAttribute(\"" + key + "\")%>" : "<%=" + key + "%>"; |
|
786 |
} |
|
787 |
} else { |
|
788 |
string = getAddYin(session.getAttribute(key), false); |
|
789 |
} |
|
790 |
return string; |
|
791 |
} |
|
792 |
|
|
793 |
/** |
|
794 |
* 返回session字符的写法 |
|
795 |
* |
|
796 |
* @param key 变量可以转成对应值 |
|
797 |
* @param panString 判断写法 |
|
798 |
* @return String |
|
799 |
*/ |
|
800 |
private static String getSessionStr(String key, String panString) { |
|
801 |
return getSessionStr(key, panString, false); |
|
802 |
} |
|
803 |
|
|
804 |
/** |
|
805 |
* @param value 字符串 |
|
806 |
* @param add 是否加上单引号 |
|
807 |
* @return String |
|
808 |
*/ |
|
809 |
private static String getAddYin(String value, boolean add) { |
|
810 |
// add = value.equals("") ? true : add;// value是空值的时候add改为true |
|
811 |
// value加上单引号。-xin 2016-3-16 |
|
812 |
// 14:26:53 |
|
813 |
return add ? "'" + value + "'" : value; |
|
814 |
} |
|
815 |
|
|
816 |
/** |
|
817 |
* 替换字符显示在页面 多替换为<%=session.getAttribute(...)%> |
|
818 |
* |
|
819 |
* @param iniv 需要查找替换的字符 |
|
820 |
* @param add 替换字符中需要程序加单引号为true |
|
821 |
* @return 替换后的字符 |
|
822 |
*/ |
|
823 |
public static String getValRep(String iniv, boolean add) {// 替换字符新追加 |
|
824 |
String tet = ""; |
|
825 |
String bl = ""; |
|
826 |
if (iniv != null) { |
|
827 |
Map<String, String> parm = new HashMap<String, String>(); |
|
828 |
parm.put(SessionKey.MASTERCODE, getAddYin("", false)); |
|
829 |
parm.put(SessionKey.AT_DAY, getAddYin(getSessionStr("date", AT_SESSION_JSP_STR), add)); |
|
830 |
parm.put(SessionKey.AT_TODAY, getAddYin(getSessionStr("formatDate.format(now)", AT_SESSION_JSP_STR), add)); |
|
831 |
parm.put(SessionKey.AT_CURFORMID, getAddYin(getSessionStr("formId", AT_SESSION_JSP_STR), false)); |
|
832 |
parm.put(SessionKey.AT_FORMID, getAddYin(getSessionStr("formId", AT_SESSION_JSP_STR), false)); |
|
833 |
parm.put(SessionKey.AT_SPACE, getAddYin(" ", false)); |
|
834 |
parm.putAll(getValRepSession(null, AT_SESSION_JSP_STR, true, add)); |
|
835 |
if (iniv.indexOf("!") != -1) { |
|
836 |
Pattern ps = Pattern.compile("@.*?\\w+");// 匹配以@开头的单词 |
|
837 |
Matcher propsMatchers = ps.matcher(iniv); |
|
838 |
while (propsMatchers.find()) { |
|
839 |
tet = propsMatchers.group(); |
|
840 |
if (bl.indexOf(tet) == -1) { |
|
841 |
iniv = iniv.replaceAll(tet, getRep(parm, tet)); |
|
842 |
bl += tet + ","; |
|
843 |
} |
|
844 |
} |
|
845 |
} else { |
|
846 |
iniv = getRep(parm, iniv); |
|
847 |
} |
|
848 |
} else { |
|
849 |
iniv = ""; |
|
850 |
} |
|
851 |
return iniv; |
|
852 |
} |
|
853 |
|
|
854 |
/** |
|
855 |
* 处理替换问题 |
|
856 |
* |
|
857 |
* @param formid 功能号 |
|
858 |
* @param iniv 替换字符 |
|
859 |
* @param session 回话 |
|
860 |
* @param map 用了替换字符的集合信息 |
|
861 |
* @param add true为给字符加单引号 |
|
862 |
*/ |
|
863 |
public static String getValRepShi(int formid, String iniv, HttpSession session, Map<String, Object> map, |
|
864 |
boolean add) { |
|
865 |
add = false;//都统一由实施开发加不加引号,我们这边不做处理 xin 2019-2-14 10:45:05 |
|
866 |
String replaceId = ""; |
|
867 |
Map<String, String> parm = new HashMap<String, String>(); |
|
868 |
// 是否有&符号需要替换 |
|
869 |
List<String> list = getStrRepInfo(iniv, "&"); |
|
870 |
if (map != null) {// 只有有集合信息,才可以去替换,否则执行下面代码也没有值去替换 |
|
871 |
for (String id : list) { |
|
872 |
String v = getAddYin(getValue(map, id), add); |
|
873 |
parm.put("&" + id + "&", v); |
|
874 |
if (id.toLowerCase().equals("docdate") && v.equals("")) {// 针对个别字段值 |
|
875 |
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");// 设置日期格式 |
|
876 |
parm.put("&" + id + "&", getAddYin(df.format(new Date()), add)); |
|
877 |
} |
|
878 |
} |
|
879 |
} |
|
880 |
// 是否有@符号需要替换 |
|
881 |
while ((iniv.indexOf("@")) != -1) { |
|
882 |
Pattern ps = Pattern.compile("@.*?\\w+");// 匹配以@开头的单词 |
|
883 |
Matcher propsMatchers = ps.matcher(iniv); |
|
884 |
while (propsMatchers.find()) { |
|
885 |
replaceId = propsMatchers.group(); |
|
886 |
} |
|
887 |
String newReplaceId = replaceId.toLowerCase();// by danaus 转为小写 |
|
888 |
//replaceValue不能设置为null,因为有@符号的不一定是会话,也有可能是SQL,declare的属性字段,所以这里@符号替换成#####。 |
|
889 |
//不替换的话会变成死循环,替换后当@循环结束在替换回@符号 xin 2020-5-21 15:17:50 |
|
890 |
String replaceValue = (session.getAttribute(newReplaceId) == null ? newReplaceId.replace("@", "#####") |
|
891 |
: session.getAttribute(newReplaceId).toString()); |
|
892 |
SimpleDateFormat formatter = null; |
|
893 |
switch (newReplaceId) {// 个别@符号替换处理 xin 2019-1-27 13:56:37 |
|
894 |
case "@now": |
|
895 |
formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
|
896 |
replaceValue = formatter.format(new Date()); |
|
897 |
break; |
|
898 |
case "@today": |
|
899 |
formatter = new SimpleDateFormat("yyyy-MM-dd"); |
|
900 |
replaceValue = formatter.format(new Date()); |
|
901 |
break; |
|
902 |
default: |
|
903 |
break; |
|
904 |
} |
|
905 |
iniv = iniv.replaceAll(replaceId, getAddYin(replaceValue, add)); |
|
906 |
|
|
907 |
} |
|
908 |
iniv = iniv.replace("#####", "@"); |
|
909 |
parm.put(SessionKey.MASTERCODE, getAddYin("", add)); |
|
910 |
parm.put(SessionKey.AT_CURFORMID, getAddYin(String.valueOf(formid), add)); |
|
911 |
parm.put(SessionKey.AT_FORMID, getAddYin(String.valueOf(formid), add)); |
|
912 |
parm.putAll(getValRepSession(session, add)); |
|
913 |
iniv = getRep(parm, iniv); |
|
914 |
return iniv; |
|
915 |
} |
|
916 |
|
|
917 |
/** |
|
918 |
* @param formid 功能号 |
|
919 |
* @param iniv 替换字符 |
|
920 |
* @param session 回话 |
|
921 |
* @param map 用了替换字符的集合信息 |
|
922 |
* @param add true为给字符加单引号 |
|
923 |
*/ |
|
924 |
public static String getValRepShiMS(int formid, String iniv, HttpSession session, Map<String, Object> map, |
|
925 |
boolean add) { |
|
926 |
Map<String, String> parm = new HashMap<String, String>(); |
|
927 |
if (map != null) {// 只有有集合信息,才可以去替换,否则执行下面代码也没有值去替换 |
|
928 |
List<String> list = getStrRepInfo(iniv, "&"); |
|
929 |
for (String id : list) { |
|
930 |
parm.put("&" + id + "&", getAddYin(getValue(map, id), false)); |
|
931 |
} |
|
932 |
} |
|
933 |
if ((iniv.indexOf("@")) != -1) { |
|
934 |
int zon = 0; |
|
935 |
while ((iniv.indexOf("@")) != -1) { |
|
936 |
String te = ""; |
|
937 |
String tes = ""; |
|
938 |
boolean bl = false; |
|
939 |
Pattern p = Pattern.compile("'@.*?\\w+'");// 匹配以'@'开头的单词 |
|
940 |
Matcher propsMatcher = p.matcher(iniv); |
|
941 |
while (propsMatcher.find()) { |
|
942 |
te = propsMatcher.group(); |
|
943 |
bl = true; |
|
944 |
} |
|
945 |
|
|
946 |
Pattern ps = Pattern.compile("@.*?\\w+");// 匹配以@开头的单词 |
|
947 |
Matcher propsMatchers = ps.matcher(iniv); |
|
948 |
while (propsMatchers.find()) { |
|
949 |
tes = propsMatchers.group(); |
|
950 |
} |
|
951 |
String se = session.getAttribute(tes.toLowerCase()) == null ? (bl ? te : tes) |
|
952 |
: session.getAttribute(tes.toLowerCase()).toString();// |
|
953 |
if (bl) { |
|
954 |
iniv = iniv.replaceAll(te, se); |
|
955 |
} else { |
|
956 |
iniv = iniv.replaceAll(tes, se); |
|
957 |
|
|
958 |
} |
|
959 |
zon++; |
|
960 |
if (zon > session.getValueNames().length) { |
|
961 |
break; |
|
962 |
} |
|
963 |
} |
|
964 |
} |
|
965 |
parm.put(SessionKey.MASTERCODE, getAddYin("", false)); |
|
966 |
parm.put(SessionKey.AT_CURFORMID, getAddYin(String.valueOf(formid), false)); |
|
967 |
parm.put(SessionKey.AT_FORMID, getAddYin(String.valueOf(formid), false)); |
|
968 |
parm.putAll(getValRepSession(session, add)); |
|
969 |
iniv = getRep(parm, iniv); |
|
970 |
iniv = iniv.replace("''''", "''");// 出现空值的问题。 |
|
971 |
return iniv; |
|
972 |
} |
|
973 |
|
|
974 |
/** |
|
975 |
* 对@符号的会话值进行赋值。 |
|
976 |
* |
|
977 |
* @param iniv带有@符号的语句 |
|
978 |
* @param session |
|
979 |
* @return |
|
980 |
*/ |
|
981 |
public static String getValueShi(String iniv, HttpSession session) { |
|
982 |
int tempPo = -1; |
|
983 |
if ((tempPo = iniv.indexOf("@")) != -1) { |
|
984 |
while ((tempPo = iniv.indexOf("@")) != -1) { |
|
985 |
String te = ""; |
|
986 |
String tes = ""; |
|
987 |
boolean bl = false; |
|
988 |
Pattern p = Pattern.compile("'@.*?\\w+'");// 匹配以'@'开头的单词 |
|
989 |
Matcher propsMatcher = p.matcher(iniv); |
|
990 |
while (propsMatcher.find()) { |
|
991 |
te = propsMatcher.group(); |
|
992 |
bl = true; |
|
993 |
} |
|
994 |
Pattern ps = Pattern.compile("@.*?\\w+");// 匹配以@开头的单词 |
|
995 |
Matcher propsMatchers = ps.matcher(iniv); |
|
996 |
while (propsMatchers.find()) { |
|
997 |
tes = propsMatchers.group(); |
|
998 |
} |
|
999 |
String se = session.getAttribute(tes.toLowerCase()) == null ? "null" |
|
1000 |
: session.getAttribute(tes.toLowerCase()).toString();// |
|
1001 |
if (se == "null" && bl) { |
|
1002 |
iniv = iniv.replaceAll(te, se); |
|
1003 |
} else { |
|
1004 |
iniv = iniv.replaceAll(tes, se); |
|
1005 |
} |
|
1006 |
} |
|
1007 |
} |
|
1008 |
return iniv; |
|
1009 |
} |
|
1010 |
|
|
1011 |
/** |
|
1012 |
* 替换含有@usercode得在session中确定的值 |
|
1013 |
* |
|
1014 |
* @param str 要替换的字符 |
|
1015 |
* @param session session |
|
1016 |
* @param add 是否加单引号 |
|
1017 |
* @return 返回替换后的字符 |
|
1018 |
*/ |
|
1019 |
public static Map<String, String> getValRepSession(HttpSession session, boolean add) { |
|
1020 |
return getValRepSession(session, null, false, add); |
|
1021 |
} |
|
1022 |
|
|
1023 |
/** |
|
1024 |
* 替换含有@usercode得在session中确定的值 |
|
1025 |
* |
|
1026 |
* @param session session |
|
1027 |
* @param panString 判断用 |
|
1028 |
* @param sesBoo |
|
1029 |
* @param add |
|
1030 |
* @return |
|
1031 |
*/ |
|
1032 |
public static Map<String, String> getValRepSession(HttpSession session, String panString, boolean sesBoo, |
|
1033 |
boolean add) { |
|
1034 |
Map<String, String> parm = new HashMap<String, String>(); |
|
1035 |
parm.put(SessionKey.AT_SPACE, getAddYin(" ", false)); |
|
1036 |
parm.put(SessionKey.USERCODE, getAddYin(getSessionStr(SessionKey.USERCODE, panString, sesBoo, session), add)); |
|
1037 |
parm.put(SessionKey.USERNAME, getAddYin(getSessionStr(SessionKey.USERNAME, panString, sesBoo, session), add)); |
|
1038 |
parm.put(SessionKey.COMPANY_ID, |
|
1039 |
getAddYin(getSessionStr(SessionKey.COMPANY_ID, panString, sesBoo, session), add)); |
|
1040 |
parm.put(SessionKey.CCCODE, getAddYin(getSessionStr(SessionKey.CCCODE, panString, sesBoo, session), add)); |
|
1041 |
parm.put(SessionKey.CCNAME, getAddYin(getSessionStr(SessionKey.CCNAME, panString, sesBoo, session), add)); |
|
1042 |
parm.put(SessionKey.HRCODE, getAddYin(getSessionStr(SessionKey.HRCODE, panString, sesBoo, session), add)); |
|
1043 |
parm.put(SessionKey.HRNAME, getAddYin(getSessionStr(SessionKey.HRNAME, panString, sesBoo, session), add)); |
|
1044 |
parm.put(SessionKey.COMPANY_NAME, |
|
1045 |
getAddYin(getSessionStr(SessionKey.COMPANY_NAME, panString, sesBoo, session), add)); |
|
1046 |
parm.put(SessionKey.LOADER_NAME, |
|
1047 |
getAddYin(getSessionStr(SessionKey.LOADER_NAME, panString, sesBoo, session), add)); |
|
1048 |
parm.put(SessionKey.IP_ADDRESS, |
|
1049 |
getAddYin(getSessionStr(SessionKey.IP_ADDRESS, panString, sesBoo, session), add)); |
|
1050 |
parm.put(SessionKey.MAC_ADDRESS, |
|
1051 |
getAddYin(getSessionStr(SessionKey.MAC_ADDRESS, panString, sesBoo, session), add)); |
|
1052 |
parm.put(SessionKey.HOSTNAME, getAddYin(getSessionStr(SessionKey.HOSTNAME, panString, sesBoo, session), add)); |
|
1053 |
// 新增默认值 |
|
1054 |
parm.put(SessionKey.DEFAULT_BRAND, |
|
1055 |
getAddYin(getSessionStr(SessionKey.DEFAULT_BRAND, panString, sesBoo, session), add)); |
|
1056 |
parm.put(SessionKey.CCCODEPERMISSION, |
|
1057 |
getAddYin(getSessionStr(SessionKey.CCCODEPERMISSION, panString, sesBoo, session), add)); |
|
1058 |
parm.put(SessionKey.ISMODIFYPRICEWHENSCANQRCODE, |
|
1059 |
getAddYin(getSessionStr(SessionKey.ISMODIFYPRICEWHENSCANQRCODE, panString, sesBoo, session), add)); |
625716
|
1060 |
parm.put(SessionKey.ISMODIFYPRICEWHENSALESORDER, |
F |
1061 |
getAddYin(getSessionStr(SessionKey.ISMODIFYPRICEWHENSALESORDER, panString, sesBoo, session), add)); |
|
1062 |
parm.put(SessionKey.ISMODIFYPRICEWHENPURCHASEORDER, |
|
1063 |
getAddYin(getSessionStr(SessionKey.ISMODIFYPRICEWHENPURCHASEORDER, panString, sesBoo, session), add)); |
21e5fd
|
1064 |
parm.put(SessionKey.SWITCHTOPAGEWHENLOGONAPP, |
F |
1065 |
getAddYin(getSessionStr(SessionKey.SWITCHTOPAGEWHENLOGONAPP, panString, sesBoo, session), add)); |
4ef865
|
1066 |
parm.put(SessionKey.LISTDISPLAYSTYLEFORTODO, |
F |
1067 |
getAddYin(getSessionStr(SessionKey.LISTDISPLAYSTYLEFORTODO, panString, sesBoo, session), add)); |
fe0a59
|
1068 |
parm.put(SessionKey.SELECTNEXTDOCUMENTWHENAPPROVED, |
F |
1069 |
getAddYin(getSessionStr(SessionKey.SELECTNEXTDOCUMENTWHENAPPROVED, panString, sesBoo, session), add)); |
2f46cc
|
1070 |
parm.put(SessionKey.ISSTARTUPPOPUPMESSAGES, |
F |
1071 |
getAddYin(getSessionStr(SessionKey.ISSTARTUPPOPUPMESSAGES, panString, sesBoo, session), add)); |
a6a76f
|
1072 |
parm.put(SessionKey.USERTYPE, |
F |
1073 |
getAddYin(getSessionStr(SessionKey.USERTYPE, panString, sesBoo, session), add)); |
|
1074 |
parm.put(SessionKey.DEFAULT_STCODE, |
|
1075 |
getAddYin(getSessionStr(SessionKey.DEFAULT_STCODE, panString, sesBoo, session), add)); |
|
1076 |
parm.put(SessionKey.DEFAULT_ACCTCODE, |
|
1077 |
getAddYin(getSessionStr(SessionKey.DEFAULT_ACCTCODE, panString, sesBoo, session), add)); |
|
1078 |
parm.put(SessionKey.UserCodePermission, |
|
1079 |
getAddYin(getSessionStr(SessionKey.UserCodePermission, panString, sesBoo, session), add)); |
|
1080 |
parm.put(SessionKey.AT_TODAY, getAddYin(getSessionStr(SessionKey.AT_TODAY, panString, sesBoo, session), add)); |
|
1081 |
parm.put(SessionKey.AT_NOW, getAddYin(getSessionStr(SessionKey.AT_NOW, panString, sesBoo, session), add)); |
|
1082 |
// add language |
|
1083 |
parm.put(SessionKey.SYSTEM_LANGUAGE, |
|
1084 |
getAddYin(getSessionStr(SessionKey.SYSTEM_LANGUAGE, panString, sesBoo, session), add)); |
|
1085 |
parm.put(SessionKey.ROLE_NAME, getAddYin(getSessionStr(SessionKey.ROLE_NAME, panString, sesBoo, session), add)); |
|
1086 |
parm.put(SessionKey.COMPANY_PERMISSION, getAddYin(getSessionStr(SessionKey.COMPANY_PERMISSION, panString, sesBoo, session), add)); |
|
1087 |
parm.put(SessionKey.OPEN_ID, getAddYin(getSessionStr(SessionKey.OPEN_ID, panString, sesBoo, session), add)); |
|
1088 |
parm.put(SessionKey.CURRENCY, getAddYin(getSessionStr(SessionKey.CURRENCY, panString, sesBoo, session), add)); |
|
1089 |
parm.put(SessionKey.SHOP_CCCDOE, |
|
1090 |
getAddYin(getSessionStr(SessionKey.SHOP_CCCDOE, panString, sesBoo, session), add)); |
|
1091 |
return parm; |
|
1092 |
} |
|
1093 |
|
|
1094 |
/** |
|
1095 |
* 替换在java语句中的字符 替换形式如:"+session.getAttribute(...)+" |
|
1096 |
* |
|
1097 |
* @param iniv 要替换的字符 |
|
1098 |
* @param formid 需要替换的功能号 |
|
1099 |
* @param add 替换字符程序加单引号 true为加上 |
|
1100 |
* @return 替换后的字符 |
|
1101 |
*/ |
|
1102 |
public static String getValLinShi(String iniv, int formid, boolean add) {// 替换字符新追加 |
|
1103 |
String reString = ""; |
|
1104 |
if (iniv != null) { |
|
1105 |
Map<String, String> parm = new HashMap<String, String>(); |
|
1106 |
parm.put(SessionKey.MASTERCODE, getAddYin("", false)); |
|
1107 |
parm.put(SessionKey.AT_DAY, getAddYin(getSessionStr("date", AT_SESSION_STR), add)); |
|
1108 |
parm.put(SessionKey.AT_TODAY, getAddYin(getSessionStr("formatDate.format(now)", AT_SESSION_STR), add)); |
|
1109 |
parm.put(SessionKey.AT_CURFORMID, getAddYin(String.valueOf(formid), false)); |
|
1110 |
parm.put(SessionKey.AT_FORMID, getAddYin(String.valueOf(formid), false)); |
|
1111 |
parm.put(SessionKey.AT_SPACE, getAddYin(" ", false)); |
|
1112 |
parm.putAll(getValRepSession(null, AT_SESSION_STR, true, add)); |
|
1113 |
reString = getRep(parm, iniv); |
|
1114 |
} |
|
1115 |
return reString; |
|
1116 |
} |
|
1117 |
|
|
1118 |
/** |
|
1119 |
* 替换字符串中的值 |
|
1120 |
* |
|
1121 |
* @param iniv 字符串 |
|
1122 |
* @param session 替换一些放在session中的信息 |
|
1123 |
* @param map 要替换的值的集合 |
|
1124 |
* @param add 替换字符两边是不是加‘号 |
|
1125 |
* @return 返回替换后的sql语句 |
|
1126 |
*/ |
|
1127 |
public static String getValRepShi(String iniv, HttpSession session, Map<String, Object> map, boolean add) { |
|
1128 |
return getValRepShi(((map != null && map.get("formid") != null && !("".equals(map.get("formid").toString().trim()))) |
|
1129 |
? Integer.parseInt(map.get("formid").toString().trim()) : 0), |
|
1130 |
iniv, session, map, add); |
|
1131 |
} |
|
1132 |
|
|
1133 |
/** |
|
1134 |
* 替换字符串中的值 |
|
1135 |
* |
|
1136 |
* @param iniv 字符串 |
|
1137 |
* @param session 替换一些放在session中的信息 |
|
1138 |
* @param map 要替换的值的集合 |
|
1139 |
* @param add 替换字符两边是不是加‘号 |
|
1140 |
* @return 返回替换后的sql语句 |
|
1141 |
*/ |
|
1142 |
public static String getValRepShiMS(String iniv, HttpSession session, Map<String, Object> map, boolean add) { |
|
1143 |
return getValRepShiMS( |
|
1144 |
((map != null && map.get("formid") != null && !("".equals(map.get("formid").toString().trim()))) |
|
1145 |
? Integer.parseInt(map.get("formid").toString().trim()) : 0), |
|
1146 |
iniv, session, map, add); |
|
1147 |
} |
|
1148 |
|
|
1149 |
/** |
|
1150 |
* 替换字符串中的值 |
|
1151 |
* |
|
1152 |
* @param iniv 需要替换的字符 |
|
1153 |
* @param session 回话 |
|
1154 |
* @param map 替换用的信息集合 |
|
1155 |
* @param add true加单引号 |
|
1156 |
* @return string 替换后的字符串 |
|
1157 |
*/ |
|
1158 |
public static String getRepAll(String iniv, HttpSession session, Map<String, Object> map, boolean add) { |
|
1159 |
String s = getValRepShi(iniv, session, map, add); |
|
1160 |
s = getRep(s, "doccode", ((map != null && map.get("doccode") != null) ? map.get("doccode").toString() : "''"), |
|
1161 |
true); |
|
1162 |
return s; |
|
1163 |
} |
|
1164 |
|
|
1165 |
/** |
|
1166 |
* 替换字符串中的值。储存过程执行替换字符 ---xin 2017-7-3 14:46:58 |
|
1167 |
* |
|
1168 |
* @param iniv 需要替换的字符 |
|
1169 |
* @param session 回话 |
|
1170 |
* @param map 替换用的信息集合 |
|
1171 |
* @param add true加单引号 |
|
1172 |
* @return string 替换后的字符串 |
|
1173 |
*/ |
|
1174 |
public static String getProcessAll(String iniv, HttpSession session, Map<String, Object> map, boolean add) { |
|
1175 |
String s = getValRepShi(iniv, session, map, add); |
|
1176 |
s = getProcess(s, map, true); |
|
1177 |
return s; |
|
1178 |
} |
|
1179 |
|
|
1180 |
/** |
|
1181 |
* 获得需要替换的字符集合 需要替换的字符用jiefu符合标识 如 &formid& 中formid 需要替换 |
|
1182 |
* |
|
1183 |
* @param str 查找的字符 |
|
1184 |
* @param jieFu 标志字符 |
|
1185 |
* @return List<String> 需要替换的集合 |
|
1186 |
*/ |
|
1187 |
public static List<String> getStrRepInfo(String str, String jieFu) { |
|
1188 |
List<String> list = new ArrayList<String>(); |
|
1189 |
Pattern p = Pattern.compile("&\\b.*?\\b&"); |
|
1190 |
Matcher m = p.matcher(str); |
|
1191 |
while (m.find()) {// |
|
1192 |
list.add(m.group().replaceAll("&", "")); |
|
1193 |
} |
|
1194 |
return list; |
|
1195 |
} |
|
1196 |
|
|
1197 |
/** |
|
1198 |
* 在list集合中是否存在str |
|
1199 |
* |
|
1200 |
* @param str 字符串 |
|
1201 |
* @param list 集合 |
|
1202 |
* @return boolean |
|
1203 |
*/ |
|
1204 |
private static boolean haseSame(String str, List<String> list) { |
|
1205 |
for (String string : list) { |
|
1206 |
if (string.equals(str.trim())) { |
|
1207 |
return true; |
|
1208 |
} |
|
1209 |
} |
|
1210 |
return false; |
|
1211 |
} |
|
1212 |
|
|
1213 |
/** |
|
1214 |
* 用回话判断权限的sql |
|
1215 |
* |
|
1216 |
* @param session 回话 |
|
1217 |
* @return 权限sql |
|
1218 |
*/ |
|
1219 |
public static String getQx(HttpSession session) { |
|
1220 |
return "(( isnull(ReaderUsercodes,'') = '' and isnull(ReaderOrganizations,'') = '' and isnull(ReaderRoles , '' ) = '' ) or ( (readerusercodes like ('%," |
|
1221 |
+ session.getAttribute(SessionKey.USERCODE) + ",%')) or (readerroles like ('%," |
|
1222 |
+ session.getAttribute(SessionKey.ROLE_NAME) + ",%')) or (readerorganizations like ('%," |
|
1223 |
+ session.getAttribute(SessionKey.CCCODE) + ",%'))))";// SessionKey.DEPARTMENT |
|
1224 |
} |
|
1225 |
|
|
1226 |
/** |
|
1227 |
* 组装取得数据组权限 |
|
1228 |
* |
|
1229 |
* @param where |
|
1230 |
* @param request |
|
1231 |
* @param formid 功能号 |
|
1232 |
* @param flag 0 主表,1 从表 |
|
1233 |
* @return |
|
1234 |
*/ |
|
1235 |
public static String getDWFqx(String where, HttpServletRequest request, int formid, int flag) { |
|
1236 |
GTGrid gt = (GTGrid) FactoryBean.getBean("GTGrid"); |
|
1237 |
where = ((where != null && !where.trim().equals("")) ? where : " 1=1 ") |
|
1238 |
+ gt.prossDataGroup(request, formid, flag); |
|
1239 |
return where; |
|
1240 |
} |
|
1241 |
|
|
1242 |
// 针对19,29类型控件添加 |
|
1243 |
private final static String jsMapDownStr = "mapDownStr"; |
|
1244 |
|
|
1245 |
private static String getTypeStr(String id, String type, String isPicStr, AttachmentEntity attachmentEntity) { |
|
1246 |
String reStr = ""; |
|
1247 |
if (type.trim().equals("29")) { |
|
1248 |
reStr = jsMapDownStr + "+=\"" |
|
1249 |
+ (" <a target=\"_blank\" href=\"" + isPicStr + "=" |
|
1250 |
+ EnImageMD5.convertMD5((attachmentEntity.getUnid() + ";" + attachmentEntity.getSeq())) |
|
1251 |
+ "\">" + attachmentEntity.getOriginalFileName() + " " + attachmentEntity.getFileSize() |
|
1252 |
+ "KB</a>").replace("\"", "\\\"") |
|
1253 |
+ "\";"; |
|
1254 |
reStr += "setDoc('" + id + "Up',\".value='更新附件'\");"; |
|
1255 |
} else { |
|
1256 |
reStr = jsMapDownStr + "+=\"" |
|
1257 |
+ (" <a target=\"_blank\" href=\"" + isPicStr + "=" |
|
1258 |
+ EnImageMD5.convertMD5((attachmentEntity.getUnid() + ";" + attachmentEntity.getSeq())) |
|
1259 |
+ "\"><img style=\"width:25px;height:25px;border:0px;\" src=\"/getImage.do?type=2&uuid=" |
|
1260 |
+ EnImageMD5.convertMD5((attachmentEntity.getUnid() + ";" + attachmentEntity.getSeq())) |
|
1261 |
+ "\" alt=\"" // 修改src的调用" + |
|
1262 |
// ("".equals(mapDown.get("smallpicpath")) |
|
1263 |
// ? |
|
1264 |
// "/smallpic/specialpic/unknown.png" |
|
1265 |
// : mapDown.get("smallpicpath")) + |
|
1266 |
// " 2014-11-6 |
|
1267 |
+ attachmentEntity.getOriginalFileName() + " " + attachmentEntity.getFileSize() + "KB" |
|
1268 |
+ "\"/></a> ").replace("\"", "\\\"") |
|
1269 |
+ "\";"; |
|
1270 |
} |
|
1271 |
return reStr; |
|
1272 |
} |
|
1273 |
|
|
1274 |
public static String getTingHTML(List<AttachmentEntity> attachmentEntityList, |
|
1275 |
Map<String, Map<String, String>> mapAll) { |
|
1276 |
String retStr = "var " + jsMapDownStr + "='';"; |
|
1277 |
if (attachmentEntityList != null) { |
|
1278 |
String filed = ""; |
|
1279 |
String filedTi = ""; |
|
1280 |
String filedId = ""; |
|
1281 |
int noShu = 0; |
|
1282 |
String isPicStr = ""; |
|
1283 |
int fiedNo = 0; |
|
1284 |
String type = "0"; |
|
1285 |
for (AttachmentEntity attachmentEntity : attachmentEntityList) { |
|
1286 |
filed = attachmentEntity.getFieldId(); // DBHelper.getValue(mapDown, |
|
1287 |
// "fieldid"); |
|
1288 |
filedId = filed; |
|
1289 |
isPicStr = attachmentEntity.getFileType(); // DBHelper.getValue(mapDown, |
|
1290 |
// "filetype").trim(); |
|
1291 |
|
|
1292 |
if ("#gif#jpeg#jpg#png#bmp#".indexOf(isPicStr) != -1) { |
|
1293 |
isPicStr = "/getImage.do?type=3&uuid";/// 旧版调用方法viewAttchment.do,目前调用最新的 |
|
1294 |
/// 2014-11-6 |
|
1295 |
} else { |
|
1296 |
isPicStr = "/attaDownload.do?type=3&unid"; |
|
1297 |
} |
|
1298 |
|
|
1299 |
type = mapAll.get(filed) != null ? mapAll.get(filed).get("type") : "0"; |
|
1300 |
if (!filedTi.equals(filed) && !filedTi.equals("")) {// 下次只有字段不同时才进入 |
|
1301 |
// ,且已经确定了一个字段 |
|
1302 |
filedId = filedTi + "File"; |
|
1303 |
retStr += setThingHTML(filedId); |
|
1304 |
noShu = 0; |
|
1305 |
filedTi = filed; |
|
1306 |
retStr += "\r\n " + jsMapDownStr + "='';";// 还原 |
|
1307 |
fiedNo++; |
|
1308 |
noShu = 1; |
|
1309 |
retStr += getTypeStr(filed, type, isPicStr, attachmentEntity); |
|
1310 |
} else { // 可能最后个字段不进入这里 |
|
1311 |
fiedNo++; |
|
1312 |
filedTi = filed; |
|
1313 |
noShu = 1; |
|
1314 |
if (fiedNo <= 5) { |
|
1315 |
retStr += getTypeStr(filed, type, isPicStr, attachmentEntity); |
|
1316 |
} else { |
|
1317 |
continue; |
|
1318 |
} |
|
1319 |
} |
|
1320 |
} |
|
1321 |
if (noShu == 1) {// 第一次输出,或者是变量重新变为零 |
|
1322 |
filedId = filedTi + "File"; |
|
1323 |
retStr += setThingHTML(filedId); |
|
1324 |
} |
|
1325 |
} |
|
1326 |
return retStr; |
|
1327 |
} |
|
1328 |
|
|
1329 |
private static String setThingHTML(String filedId) { |
|
1330 |
String retStr = ""; |
|
1331 |
retStr += "\r\nif(getDoc('" + filedId + "','')!=null){"; |
|
1332 |
retStr += "\r\n setDoc('" + filedId + "',\".innerHTML='\"+" + jsMapDownStr + "+\"'\");"; |
|
1333 |
retStr += "\r\n}"; |
|
1334 |
return retStr; |
|
1335 |
} |
|
1336 |
|
|
1337 |
public static boolean getbigimage(Map<String, Object> map, int col) { |
|
1338 |
boolean bol = false; |
|
1339 |
if (getValueInt(map, "ControlType") == 1 && col == 2 |
|
1340 |
&& DBHelper.getValue(map, "initValue").contains("/FangYuanAdmin/myImages/")) { |
|
1341 |
bol = true; |
|
1342 |
} |
|
1343 |
return bol; |
|
1344 |
} |
|
1345 |
|
|
1346 |
/** |
|
1347 |
* 针对31控件sqlWhere设置 xin 2020-1-12 11:22:22 |
|
1348 |
* |
|
1349 |
* @param dysql |
|
1350 |
* @param state |
|
1351 |
* @param sqlWhere |
|
1352 |
* @return |
|
1353 |
*/ |
bc82b6
|
1354 |
public static String getSqlWhere(String dysql, int state, String sqlWhere) { |
X |
1355 |
return getSelectSql((state != 1 ? true : false), dysql, sqlWhere); |
a6a76f
|
1356 |
} |
6e18b5
|
1357 |
|
X |
1358 |
//旧方法,下面的新方法。之后生成的页面都不在调用这个旧方法(如果在这个方法修改参数会导致jsp页面没重新生成的代码执行出现错误,所有在下面重新构造一个新方法) |
bc82b6
|
1359 |
public static String getSqlWhere(String dysql, boolean ReadOnly, String editStatus, String docstatus, String sqlWhere) { |
a6a76f
|
1360 |
try { |
bc82b6
|
1361 |
boolean isIncludeSqlWhere = false;//为false表示不增加where |
X |
1362 |
String[] status = editStatus.split(";"); |
|
1363 |
isIncludeSqlWhere = (!ReadOnly && ("".equals(status) || Arrays.asList(status).contains(docstatus) || "".equals(docstatus)) ? true : isIncludeSqlWhere);//只读作为总开关,是否设置了指定状态可编辑,是否新单 |
a6a76f
|
1364 |
// 有需要组装的sql |
bc82b6
|
1365 |
return getSelectSql(isIncludeSqlWhere, dysql, sqlWhere); |
a6a76f
|
1366 |
} catch (Exception e) { |
F |
1367 |
return dysql; |
|
1368 |
} |
0ce349
|
1369 |
} |
bc82b6
|
1370 |
|
X |
1371 |
public static String getSqlWhere(String dysql, boolean ReadOnly, String showFieldValueExpression, String editStatus, String docstatus, String sqlWhere) { |
6e18b5
|
1372 |
try { |
X |
1373 |
boolean isIncludeSqlWhere = false;//为false表示不增加where |
|
1374 |
boolean FieldValueExpression = false;//权限表达式值:0隐藏;1显示;2可编辑 |
|
1375 |
FieldValueExpression = "2".equals(showFieldValueExpression) ? true : FieldValueExpression; |
|
1376 |
String[] status = editStatus.split(";"); |
|
1377 |
isIncludeSqlWhere = (!ReadOnly && ("".equals(status) || Arrays.asList(status).contains(docstatus) || "".equals(docstatus) || FieldValueExpression) ? true : isIncludeSqlWhere);//只读作为总开关,是否设置了指定状态可编辑,是否新单 |
|
1378 |
// 有需要组装的sql |
|
1379 |
return getSelectSql(isIncludeSqlWhere, dysql, sqlWhere); |
|
1380 |
} catch (Exception e) { |
|
1381 |
return dysql; |
|
1382 |
} |
|
1383 |
} |
bc82b6
|
1384 |
|
X |
1385 |
private static String getSelectSql(boolean isIncludeSqlWhere, String dysql, String sqlWhere) { |
|
1386 |
try { |
|
1387 |
// 有需要组装的sql |
0ce349
|
1388 |
if (isIncludeSqlWhere && sqlWhere != null) { |
bcd2bf
|
1389 |
//(?i)不区分大小写 by danaus 2023-07-19 17:39 |
F |
1390 |
Pattern p = Pattern.compile("(?i)where.*"); |
|
1391 |
Matcher matcher = p.matcher(dysql); |
a6a76f
|
1392 |
if (matcher.find()) { |
F |
1393 |
String where = matcher.group(); |
bcd2bf
|
1394 |
dysql = dysql.replace(where, ""); |
F |
1395 |
p = Pattern.compile("(?i)group by.*"); |
|
1396 |
Matcher matcher1 = p.matcher(where); |
a6a76f
|
1397 |
if (matcher1.find()) { |
F |
1398 |
where = " where (" + where.replace(matcher1.group(), "").replace("where", "") + ") and (" |
|
1399 |
+ sqlWhere + ") " + matcher1.group(); |
|
1400 |
dysql = dysql + where; |
|
1401 |
} else { |
bcd2bf
|
1402 |
p = Pattern.compile("(?i)order by.*"); |
F |
1403 |
Matcher matcher2 = p.matcher(where); |
a6a76f
|
1404 |
if (matcher2.find()) { |
F |
1405 |
where = " where (" + where.replace(matcher2.group(), "").replace("where", "") + ") and (" |
|
1406 |
+ sqlWhere + ") " + matcher2.group(); |
|
1407 |
} else { |
|
1408 |
where = " where (" + where.replace("where", "") + ") and (" + sqlWhere + ") "; |
|
1409 |
} |
|
1410 |
dysql = dysql + where; |
|
1411 |
} |
|
1412 |
} else { |
bcd2bf
|
1413 |
p = Pattern.compile("(?i)group by.*"); |
F |
1414 |
Matcher matcher1 = p.matcher(dysql); |
a6a76f
|
1415 |
if (matcher1.find()) { |
F |
1416 |
dysql = dysql.replace(matcher1.group(), "") + " where (1=1) and (" + sqlWhere + ") " |
|
1417 |
+ matcher1.group(); |
|
1418 |
} else { |
bcd2bf
|
1419 |
p = Pattern.compile("(?i)order by.*"); |
F |
1420 |
Matcher matcher2 = p.matcher(dysql); |
a6a76f
|
1421 |
if (matcher2.find()) { |
F |
1422 |
dysql = dysql.replace(matcher2.group(), "") + " where (1=1) and (" + sqlWhere + ") " |
|
1423 |
+ matcher2.group(); |
|
1424 |
} else { |
|
1425 |
if (sqlWhere.indexOf("order") != -1) { |
|
1426 |
dysql = dysql + " where (1=1) and " + sqlWhere; |
|
1427 |
} else { |
|
1428 |
dysql = dysql + " where (1=1) and (" + sqlWhere + ")"; |
|
1429 |
} |
|
1430 |
} |
|
1431 |
} |
|
1432 |
} |
|
1433 |
} |
|
1434 |
return dysql; |
bc82b6
|
1435 |
} catch (Exception e) { |
X |
1436 |
return dysql; |
|
1437 |
} |
a6a76f
|
1438 |
} |
F |
1439 |
|
|
1440 |
// end--结束 |
4257cf
|
1441 |
|
X |
1442 |
/** |
|
1443 |
* 把list集合的map内某个相同key值组装出来 xin 2021-12-29 09:41:19 |
bc82b6
|
1444 |
* |
X |
1445 |
* @param list 数据信息集合 |
4257cf
|
1446 |
* @param field 字段名(小写),返回的新数据信息集合lit内map的key统一小写,空值时候返回原本list,如果集合里的map都没有field的值也返回原本list |
X |
1447 |
* @return 组装好的新数据信息集合 |
|
1448 |
*/ |
bc82b6
|
1449 |
public static List<Map<String, Object>> getStreamFilter(List<Map<String, Object>> list, String field) { |
4257cf
|
1450 |
try { |
X |
1451 |
List<Map<String, Object>> out = new ArrayList<>(); |
|
1452 |
if (list == null || list.size() == 0) { |
|
1453 |
return null; |
|
1454 |
} |
|
1455 |
if (StringUtils.isBlank(field)) { |
|
1456 |
return list; |
|
1457 |
} |
|
1458 |
String f = field.toLowerCase();//转换成小写 |
|
1459 |
for (Map<String, Object> m : list) { |
|
1460 |
String value = DBHelper.getValue(m, f); |
|
1461 |
if (out.stream().filter(o -> value.equals(DBHelper.getValue(o, f))).count() == 0) {//等于0表示还没有组装到value值 |
|
1462 |
//获取相同value的集合 |
|
1463 |
List<Map<String, Object>> similar = list.stream().filter(l -> value.equals(DBHelper.getValue(l, f))).collect(Collectors.toList()); |
|
1464 |
//创建一个新map存放相同value |
|
1465 |
Map<String, Object> map = new HashMap<>(); |
|
1466 |
map.put(f, value); |
|
1467 |
map.put("list", similar); |
|
1468 |
//把相同的value的map组装到out里 |
|
1469 |
out.add(map); |
|
1470 |
} |
|
1471 |
} |
|
1472 |
if (out == null || out.size() == 0) { |
|
1473 |
out = list; |
|
1474 |
} |
|
1475 |
return out; |
|
1476 |
} catch (Exception e) { |
|
1477 |
return null; |
|
1478 |
} |
|
1479 |
} |
dc7ad9
|
1480 |
|
X |
1481 |
/** |
|
1482 |
* 处理初始值 xin 2022-4-21 15:48:54 |
bc82b6
|
1483 |
* |
dc7ad9
|
1484 |
* @param request |
X |
1485 |
* @param map |
|
1486 |
* @param initValue |
|
1487 |
* @return |
|
1488 |
*/ |
bc82b6
|
1489 |
public static String getInitValue(HttpServletRequest request, Map<String, Object> map, String initValue) { |
dc7ad9
|
1490 |
try { |
X |
1491 |
Map<String, String> parm = new HashMap<>(); |
|
1492 |
if (DBHelper.getValueInt(map, "doc_size") == 0) {// 只有有集合信息,才可以去替换,否则执行下面代码也没有值去替换 |
|
1493 |
String queryString = request.getQueryString(); |
61b9da
|
1494 |
String isNew = request.getParameter("isNew");//判断是否是复单,不是null说明是复单 不进入 xin 2022-6-6 15:10:57 |
X |
1495 |
if (StringUtils.isBlank(isNew) && StringUtils.isNotBlank(queryString)) { |
dc7ad9
|
1496 |
String par = URLDecoder.decode(queryString, "UTF-8"); |
X |
1497 |
String[] p = par.split("&"); |
|
1498 |
if (p.length > 0) { |
|
1499 |
for (String s : p) { |
|
1500 |
String[] v = s.split("="); |
|
1501 |
if (v.length == 2) { |
|
1502 |
map.put(v[0], v[1]); |
|
1503 |
} |
|
1504 |
} |
|
1505 |
} |
|
1506 |
} |
|
1507 |
} |
|
1508 |
List<String> list = getStrRepInfo(initValue, "&"); |
|
1509 |
for (String id : list) { |
|
1510 |
parm.put("&" + id + "&", getAddYin(getValue(map, id), false)); |
|
1511 |
} |
|
1512 |
initValue = getRep(parm, initValue); |
|
1513 |
return initValue; |
|
1514 |
} catch (Exception e) { |
|
1515 |
return initValue; |
|
1516 |
} |
|
1517 |
} |
bc82b6
|
1518 |
|
X |
1519 |
public static String getCustomURLByGrid(HttpServletRequest request, Integer formId, Integer formType, String jsp) { |
97a11f
|
1520 |
String initial = jsp; |
F |
1521 |
try { |
|
1522 |
String userCode = (String) request.getSession().getAttribute(SessionKey.USERCODE); |
|
1523 |
// 判断有没自定义布局 by danaus 2024-03-29 16:55 |
|
1524 |
ControlLayoutIfc controlLayoutIfc = (ControlLayoutIfc) FactoryBean.getBean("controlLayoutImpl"); |
|
1525 |
|
bc82b6
|
1526 |
boolean hasControlLayout = controlLayoutIfc.hasControlLayout(formId + "", formType, userCode); |
97a11f
|
1527 |
if (hasControlLayout) { |
bc82b6
|
1528 |
return formId + "_" + userCode + "_" + jsp; |
97a11f
|
1529 |
} else { |
bc82b6
|
1530 |
return formId + "_" + jsp; |
97a11f
|
1531 |
} |
F |
1532 |
} catch (Exception e) { |
bc82b6
|
1533 |
return formId + "_" + jsp; |
97a11f
|
1534 |
} |
F |
1535 |
} |
bc82b6
|
1536 |
|
X |
1537 |
public static String getCustomURL(HttpServletRequest request, Integer formId, Integer formType, String jsp) { |
ca30ee
|
1538 |
try { |
X |
1539 |
String userCode = (String) request.getSession().getAttribute(SessionKey.USERCODE); |
97a11f
|
1540 |
// 判断有没自定义布局 by danaus 2024-03-29 16:55 |
F |
1541 |
ControlLayoutIfc controlLayoutIfc = (ControlLayoutIfc) FactoryBean.getBean("controlLayoutImpl"); |
bc82b6
|
1542 |
boolean hasControlLayout = false; |
X |
1543 |
if (jsp.indexOf("panel") != -1) {//面板 |
|
1544 |
hasControlLayout = controlLayoutIfc.hasControlLayout(formId + "", userCode, formType, ExprotType.Panel, false); |
|
1545 |
if (hasControlLayout) { |
|
1546 |
return userCode + "_" + jsp; |
|
1547 |
} else { |
|
1548 |
return jsp; |
|
1549 |
} |
ca30ee
|
1550 |
} |
bc82b6
|
1551 |
if (jsp.indexOf("grid") != -1) {//格线 |
X |
1552 |
hasControlLayout = controlLayoutIfc.hasControlLayout(formId + "", userCode, formType, ExprotType.Grid, false); |
|
1553 |
if (hasControlLayout) { |
|
1554 |
return formId + "_" + userCode + "_" + jsp; |
|
1555 |
} else { |
|
1556 |
return formId + "_" + jsp; |
|
1557 |
} |
|
1558 |
} |
|
1559 |
return jsp; |
ca30ee
|
1560 |
} catch (Exception e) { |
777a1e
|
1561 |
return jsp; |
ca30ee
|
1562 |
} |
X |
1563 |
} |
a6a76f
|
1564 |
} |