DbU.java 57 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489
  1. package ss.db;
  2. import java.io.File;
  3. import java.lang.reflect.Field;
  4. import java.lang.reflect.InvocationTargetException;
  5. import java.lang.reflect.Method;
  6. import java.lang.reflect.Modifier;
  7. import java.sql.Date;
  8. import java.sql.Timestamp;
  9. import java.util.Arrays;
  10. import java.util.HashMap;
  11. import java.util.List;
  12. import java.util.Map;
  13. import java.util.Map.Entry;
  14. import java.util.Objects;
  15. import java.util.Optional;
  16. import java.util.Set;
  17. import java.util.concurrent.atomic.AtomicInteger;
  18. import java.util.stream.Collectors;
  19. import java.util.stream.Stream;
  20. import jakarta.servlet.http.HttpServletRequest;
  21. import com.google.gson.Gson;
  22. import com.google.gson.reflect.TypeToken;
  23. import org.apache.commons.io.FileUtils;
  24. import org.apache.commons.lang3.StringUtils;
  25. import org.apache.logging.log4j.LogManager;
  26. import org.apache.logging.log4j.Logger;
  27. import ss.AppB;
  28. import ss.AppC;
  29. import ss.cb.CbU;
  30. import ss.cmn.lambda.LambdaFunction;
  31. import ss.cms.CmsU;
  32. import ss.editor.EditorU;
  33. import ss.log.SsLog;
  34. import ss.obj.ObjB;
  35. import ss.obj.ObjC;
  36. import ss.obj.ObjFieldB;
  37. import ss.obj.ObjU;
  38. import ss.user.UserRunB;
  39. public class DbU {
  40. // 增加,去掉 e.printStackTrace(),改用 log4j -- 按 IDEA 规范。Lin
  41. private static final Logger log4j = LogManager.getLogger(DbU.class);
  42. /* 去掉,直接写。Lin
  43. private final static int blob_radix = 16;
  44. */
  45. /// **
  46. // * blob数据转换成string
  47. /// *
  48. // 来自 GeneralDBAccess.blobBytesToString(byte[] bytes)。Lin
  49. /* 再去掉,没用到了 -- 数据库不支持 Blob 字段了
  50. public static String toStrByBlob(byte[] bytes) {
  51. return new BigInteger(1, bytes).toString(16); // 16 = blob_radix
  52. }
  53. */
  54. // 来自 GeneralDBAccess.blobStringToBytes(String blobstr)。Lin
  55. /* 再去掉,没用到了 -- 数据库不支持 Blob 字段了
  56. public static byte[] toBlobByStr(String blobstr) {
  57. return new BigInteger(blobstr, 16).toByteArray(); // 16 = blob_radix
  58. }
  59. */
  60. // 来自 SqlParam.obtainParamSqlType()。Lin
  61. // 增加 type 入口参数,原放在 SqlParam 里 -- 可以直接访问 SqlParmB.type
  62. // type 数据类型从 String 改为 int
  63. /* 去掉,parmTypeMap 直接对着 stmt.setXxx() 了。Lin
  64. public static int toSqlType(int type){
  65. /// * 改为 switch,改为 int,改用常量。Lin
  66. // int sqlType = -1;
  67. //
  68. // if( "int".equals(type) ) // TYPE_INT.。Lin
  69. // sqlType = java.sql.Types.INTEGER;
  70. // else if( "float".equals(type) ) // TYPE_FLOAT.。Lin
  71. // sqlType = java.sql.Types.FLOAT;
  72. // else if( "char".equals(type) ) // TYPE_CHAR.。Lin
  73. // sqlType = java.sql.Types.CHAR;
  74. // else if( "time".equals(type) ) // TYPE_DATETIME.。Lin
  75. // sqlType = java.sql.Types.TIMESTAMP;
  76. // else if( "clob".equals(type) ) // TYPE_CLOB.。Lin
  77. // sqlType = java.sql.Types.CLOB;
  78. // else if( "blob".equals(type) ) // TYPE_BLOB.。Lin
  79. // sqlType = java.sql.Types.BLOB;
  80. //
  81. // return sqlType;
  82. /// *
  83. switch (type) {
  84. case DbC.PARM_intType:
  85. return java.sql.Types.INTEGER;
  86. case DbC.PARM_floatType:
  87. return java.sql.Types.FLOAT;
  88. case DbC.PARM_stringType:
  89. return java.sql.Types.CHAR;
  90. case DbC.PARM_timestampType:
  91. return java.sql.Types.TIMESTAMP;
  92. case DbC.PARM_clobType:
  93. return java.sql.Types.CLOB;
  94. case DbC.PARM_blobType:
  95. return java.sql.Types.BLOB;
  96. }
  97. return -1;
  98. }
  99. */
  100. // === Po
  101. // 根据 Po,得到字段的 Type。Lin
  102. // 源自 ViewObjectUtil.readBeanType(BaseBean bean, Field f)
  103. // 入口参数 ObjFieldB 改为 fieldName,并移到前面 -- 统一
  104. // 返回值 String 改为 int
  105. /* 再改为 (int) toFieldTypeByPoType(Integer poType)。Lin
  106. * 再增加,序列化 Po 信息到 "/pmsWs/<项目号>/_cache/po/<对象名>"(PoCacheB)
  107. * 加载 .obj.xml 时,之前读的是 PMS 自己的 Po,不是项目的 Po -- 原项目的 po.jar,无法读取 Po 的信息
  108. public static int rdFieldTypeByPo(String fieldName, Po bean) {
  109. */ public static int toFieldTypeByPoType(Integer poType) {
  110. /* 再改为 (int) toFieldTypeByPoType(Integer poType)。Lin
  111. if (bean == null)
  112. return ObjC.FIELD_txtType; // "text"。Lin
  113. Integer type = bean.fieldTypeMap.get(fieldName); // String。(f.name)。Lin
  114. if (type == null)
  115. return ObjC.FIELD_txtType; // "text"。Lin
  116. */
  117. if (poType == null)
  118. return ObjC.FIELD_txtType; // "text"。Lin
  119. /* Po 增加 int、Integer、long、double、float、Float。Lin
  120. * String 改为 int
  121. * 改为 switch
  122. if ("Timestamp".equals(type)) {
  123. return "time";
  124. } else if ("Long".equals(type)) {
  125. return "number";
  126. } else if ("Double".equals(type)) {
  127. return "number";
  128. }
  129. */
  130. /* 再改为 (int) toFieldTypeByPoType(Integer poType)。Lin
  131. *
  132. switch (type) {
  133. */ return switch (poType) {
  134. case DbC.PO_StringType, DbC.PO_txtType -> ObjC.FIELD_txtType; // "text"。Lin
  135. case DbC.PO_intType, DbC.PO_IntegerType, // "int"/"Integer"。Lin
  136. DbC.PO_longType, DbC.PO_LongType, // "long"/"Long"。Lin
  137. /* 再去掉 float/Float、double/Double,转换为整数 -- 需要时再增加 BigInteger。Lin
  138. case DbC.PO_floatType: // "float"。lin
  139. case DbC.PO_FloatType: // "Float"。lin
  140. case DbC.PO_doubleType: // "double"。Lin
  141. case DbC.PO_DoubleType: // "Double"。Lin
  142. */
  143. /// 再保留浮点,存在无需运算 或 无需精确运算的情况 -- 如,REM。Lin
  144. DbC.PO_floatType, DbC.PO_FloatType, // "float"/"Float"。Lin
  145. DbC.PO_doubleType, DbC.PO_DoubleType -> // "double"/"Double"。Lin
  146. ///
  147. ObjC.FIELD_numType; // "number"。Lin
  148. /// 再增加 DbC.PO_booleanType/DbC.PO_BooleanType。Lin
  149. case DbC.PO_booleanType, DbC.PO_BooleanType -> ObjC.FIELD_boolType;
  150. ///
  151. /// 再增加,保留 ObjC.FIELD_dateType -- 与 Po 一样,保留 DbC.PO_DateType。Lin
  152. case DbC.PO_DateType -> ObjC.FIELD_dateType;
  153. ///
  154. case DbC.PO_TimestampType -> // "Timestamp"。Lin
  155. ObjC.FIELD_timeType; // "time"。Lin
  156. default -> {
  157. SsLog.log("DbU.toFieldTypeByPoType(,DbC.Po_xxxType 少了判断:" + poType);
  158. yield ObjC.FIELD_txtType; // "text"。Lin
  159. }
  160. };
  161. }
  162. // 来自:。Lin
  163. // BeanUtils.(Map<String, Object>) beansToMap(BaseBean bean)
  164. // ZGZ:ReSearchService.(Map<String, Object>) beansToMap(BaseBean bean)
  165. // DesignOutSide.(Map<String, String>) beansToMap(BaseBean... bean)
  166. // GzwjRemoteService.(Map<String, String>) beansToMap(BaseBean bean)
  167. // BeanUtils.beansToMap( 有过滤 null 值的字段
  168. // ZGZ:ReSearchService.beansToMap( 没有过滤 null 值的字段
  169. // DesignOutSide.beansToMap( 支持多个 bean,且把 "csc" 字段里的键值对也拆开写入 Map -- "csc" 本身不写入
  170. // 有过滤 null 值的字段,csc 里的 null 也过滤
  171. // GzwjRemoteService.beansToMap( 有过滤 null 值的字段
  172. // 增加 filterNull -- 区分 BeanUtils.beansToMap()
  173. // contCsc 为 true 时,没意义
  174. // 增加 contCsc -- 区分 DesignOutSide.beansToMap()
  175. /* 再去掉 contCsc,不把 DesignOutSide.beansToMap() 纳入 -- 需要支持多个 bean。Lin
  176. public static Map<String, Object> toMapByPo(Po bean, boolean filterNull, boolean contCsc) {
  177. */ public static Map<String, Object> toMapByPo(Po bean, boolean filterNull) throws InvocationTargetException, NoSuchMethodException, IllegalAccessException {
  178. Map<String, Object> jmap = new HashMap<>();
  179. /* 再去掉 contCsc,不把 DesignOutSide.beansToMap() 纳入 -- 需要支持多个 bean。Lin
  180. Map<String, Object> m; // 增加。Lin
  181. */
  182. /* 去掉 bean.getFieldMap(),直接用 Po.fieldTypeMap。Lin
  183. * Map<String, String[]> 改为 Map<String, String>
  184. for(Map.Entry<String, String[]> entry : (Set<Entry<String, String[]>>)bean.getFieldMap().entrySet()){
  185. String fieldName = entry.getKey();
  186. */ for (String fieldName : bean.fieldTypeMap.keySet()) {
  187. Object v = rdFieldValByPo(fieldName, bean); // BeanUtils.getFieldValue()。Lin
  188. /* 再去掉 contCsc,不把 DesignOutSide.beansToMap() 纳入 -- 需要支持多个 bean。Lin
  189. if (contCsc && fieldName.equals(DbC.PO_cscName)) { // "csc"。Lin
  190. /// 来自 DesignOutSide.(Map<String, String>) beansToMap(BaseBean... bean)。Lin
  191. if (v == null)
  192. continue;
  193. /// * 去掉 DesignOutSide.parseJsonToMap(,用 StrJson.toObjectMap(。Lin
  194. // * 在这加 {}
  195. // Map<String, String> m = parseJsonToMap(v.toString());
  196. /// *
  197. /// * 再,不加左、右的 "{"、"}" -- 在数据库的 参数串 字段里加。Lin
  198. // m = StrJson.toObjectMap("{"+ v.toString() +"}");
  199. /// *
  200. m = StrJson.toObjectMap(v.toString());
  201. if (m != null) {
  202. jmap.putAll(m);
  203. }
  204. ///
  205. //filter null
  206. } else if (!filterNull || v != null) { // 不过滤 null 值的字段。Lin
  207. */ if (!filterNull || v != null) { // 不过滤 null 值的字段。Lin
  208. jmap.put(fieldName, v);
  209. }
  210. }
  211. return jmap;
  212. }
  213. // 来自 DesignOutSide.(Map<String, String>) beansToMap(BaseBean... bean)。Lin
  214. // cont = 包含
  215. public static Map<String, String> toMapByPoContCsc(Po... bean) throws InvocationTargetException, NoSuchMethodException, IllegalAccessException {
  216. Map<String, String> jmap = new HashMap<>();
  217. /* 参数串字段 和 非参数串字段,合并在同一套 for 循环里。Lin
  218. for (int i = 0; i < bean.length; i++) {
  219. for (Map.Entry<String, String[]> entry : (Set<Entry<String, String[]>>) bean[i]
  220. .getFieldMap().entrySet()) {
  221. String fieldName = entry.getKey();
  222. if ("csc".equals(fieldName))
  223. continue;
  224. Object v = BeanUtils.getFieldValue(fieldName, bean[i]);
  225. if (v == null)
  226. continue;
  227. jmap.put(fieldName, v.toString());
  228. }
  229. }
  230. for (int i = 0; i < bean.length; i++) {
  231. for (Map.Entry<String, String[]> entry : (Set<Entry<String, String[]>>) bean[i]
  232. .getFieldMap().entrySet()) {
  233. try {
  234. String fieldName = entry.getKey();
  235. if (!"csc".equals(fieldName))
  236. continue;
  237. Object v = BeanUtils.getFieldValue(fieldName, bean[i]);
  238. if (v == null)
  239. continue;
  240. Map<String, String> m = parseJsonToMap(v.toString());
  241. if (m != null) {
  242. m.putAll(jmap);
  243. jmap = m;
  244. }
  245. } catch (Exception e) {
  246. e.printStackTrace();
  247. }
  248. }
  249. }
  250. */
  251. Gson gson = new Gson(); // 增加,不重复 new。Lin
  252. Object v; // 增加,不重复定义。Lin
  253. Map<String, String> m; // 增加,不重复定义。Lin
  254. /* 再改,IDEA:'for' loop can be replaced with enhanced 'for'。Lin
  255. for (int i = 0; i < bean.length; i++) {
  256. /// * 去掉 bean.getFieldMap(),直接用 Po.fieldTypeMap。Lin
  257. // * Map<String, String[]> 改为 Map<String, String>
  258. // * 去掉 try {}
  259. // for (Map.Entry<String, String[]> entry : (Set<Entry<String, String[]>>) bean[i].getFieldMap().entrySet()) {
  260. // try {
  261. // String fieldName = entry.getKey();
  262. /// *
  263. for (String fieldName : bean[i].fieldTypeMap.keySet()) {
  264. v = rdFieldValByPo(fieldName, bean[i]); // BeanUtils.getFieldValue()。Lin
  265. */
  266. for (Po po : bean) {
  267. for (String fieldName : po.fieldTypeMap.keySet()) {
  268. v = rdFieldValByPo(fieldName, po); // BeanUtils.getFieldValue()。Lin
  269. if (DbC.FIELD_poCscName.equals(fieldName)) { // ("csc".。Lin
  270. if (v == null)
  271. continue;
  272. m = gson.fromJson(String.valueOf(v), new TypeToken<Map<String, String>>() {}.getType());
  273. if (m != null)
  274. jmap.putAll(m);
  275. } else {
  276. if (v == null)
  277. continue;
  278. jmap.put(fieldName, String.valueOf(v));
  279. }
  280. }
  281. }
  282. return jmap;
  283. }
  284. // 来自 ViewObjectUtil.getFieldValue(BaseBean bean, ViewObject viewobject, Field field)。Lin
  285. // 去掉 viewobject,没用到
  286. // field 改为 field.name,并移到第一个位置
  287. public static Object rdFieldValByPo(String name, Po bean) throws InvocationTargetException, NoSuchMethodException, IllegalAccessException {
  288. /* 用 StringUtils.capitalize()。Lin
  289. String methodName = "get" + name.replaceFirst(name.substring(0, 1), name.substring(0, 1).toUpperCase());
  290. */ String methodName = "get"+ StringUtils.capitalize(name);
  291. Method method;
  292. try {
  293. method = bean.getClass().getMethod(methodName);
  294. /* 再改,IDEA:Redundant array creation for calling varargs method。Lin
  295. return method.invoke(bean, new Object[0]);
  296. */ return method.invoke(bean);
  297. } catch (Exception e) {
  298. /* 改,去掉 e.printStackTrace(),改用 log4j -- 按 IDEA 规范。Lin
  299. e.printStackTrace();
  300. */ log4j.error("DbU.rdFieldValByPo( 异常", e);
  301. /* 再改,改为抛出错误。Lin
  302. return null;
  303. */ throw e;
  304. }
  305. }
  306. // 来自 tt.bpm.common.BpmUtil.(String) getFieldValue(Object bean, ViewObject viewobject, Field f)。Lin
  307. // bean(Object) 改为 Po,专门用于 Po -- 用到 Object 再弄
  308. // 去掉 viewobject,没用到 -- 只是用于显示错误信息
  309. // f(ObjFieldB) 移到最前面 -- 统一
  310. public static String rdFieldValByCbByPo(ObjFieldB f, Po bean) throws Exception {
  311. String name = f.name;
  312. String codebook = f.cbName; // .getCodebook()。Lin
  313. /* 用 StringUtils.capitalize()。Lin
  314. String methodName = "get" + name.replaceFirst(name.substring(0, 1), name.substring(0, 1).toUpperCase());
  315. */ String methodName = "get"+ StringUtils.capitalize(name);
  316. Method method;
  317. try {
  318. method = bean.getClass().getMethod(methodName);
  319. /* 再改,IDEA:Redundant array creation for calling varargs method。Lin
  320. Object o = method.invoke(bean, new Object[0]);
  321. */ Object o = method.invoke(bean);
  322. String result = ((o == null)? null : o.toString());
  323. // 翻译codebook
  324. if (StringUtils.isNotBlank(codebook)) { // StringUtil.notNull()。Lin
  325. /* 去掉应用名前缀,不支持多个应用。Lin
  326. String[] a = codebook.split("\\.");
  327. if (a.length != 2) {
  328. throw new Exception("codebook解析失败 >>object:" + viewobject.getName() + ",field:" + f.getName() + ",codebook:" + codebook);
  329. }
  330. String codebookName = a[1];
  331. String appName = a[0];
  332. */
  333. /* 再去掉,直接用 codebook -- IDEA:Local variable 'codebookName' is redundant。Lin
  334. String codebookName = codebook;
  335. */
  336. // "获得codebook的数据"
  337. /* 再改,码本翻译只取那条记录。Lin
  338. /// * 去掉 appName。Lin
  339. // Map<String, Map<String, Object>> codebookData = CodebookUtil.getDataByCodebookName(codebookName, appName, null, null);// 获得codebook的数据
  340. /// *
  341. /// * 再去掉,直接用 codebook -- IDEA:Local variable 'codebookName' is redundant。Lin
  342. // Map<String, Map<String, Object>> codebookData = CbU.rdOpt(codebookName, null, null);
  343. // // null = filter,null = request。Lin
  344. /// *
  345. Map<String, Map<String, Object>> codebookData = CbU.rdOpt(codebook, null, null);
  346. Map<String, Object> oneRowMap = codebookData.get(result);
  347. Entry<String, Object> en = DsU.rdMapByIdx(oneRowMap, 1); // CommonUtils.getMapValueByIndex()。Lin
  348. result = ((en == null)? "" : en.getValue().toString());
  349. */
  350. /* 再改,去掉 fieldName(String) -- 改返回结果为 Map<Integer, Map<String, String>>。Lin
  351. result = CbU.transCb(result, codebook, null);
  352. */ result = CbU.transCb(result, codebook);
  353. }
  354. return result;
  355. } catch (Exception e) {
  356. /* 改,去掉 e.printStackTrace(),改用 log4j -- 按 IDEA 规范。Lin
  357. e.printStackTrace();
  358. */ log4j.error("DbU.rdFieldValByCbByPo( 异常", e);
  359. throw e;
  360. }
  361. // return null;
  362. }
  363. /**
  364. * 设置字段值
  365. *
  366. * @param propertyName
  367. * 字段名
  368. * @param obj
  369. * 实例对象
  370. * @param value
  371. * 新的字段值
  372. */
  373. // 来自 tt.util.BeanUtils.setFieldValue(Object obj, String propertyName, Object value)。Lin
  374. // Object 改为 Po,专门用于 Po
  375. // obj(Po) 移到最后面 -- 统一
  376. public static void wrPoField(String propertyName, Object value, Po obj) {
  377. try {
  378. Class<?> clazz = obj.getClass();
  379. Field field = clazz.getDeclaredField(propertyName);
  380. field.setAccessible(true);
  381. if (value == null || StringUtils.isBlank(value.toString())) { // StringUtil.isNull()。Lin
  382. field.set(obj, null);
  383. } else {
  384. String className = field.getType().getName();
  385. /* 改为 switch。Lin
  386. if ("java.lang.Integer".equals(className)
  387. || "int".equals(className)) {
  388. field.set(obj, Integer.valueOf(value.toString()));
  389. } else if ("java.lang.Long".equals(className)
  390. || "long".equals(className)) {
  391. field.set(obj, Long.valueOf(value.toString()));
  392. } else if ("java.lang.Byte".equals(className)
  393. || "byte".equals(className)) {
  394. field.set(obj, Byte.valueOf(value.toString()));
  395. } else if ("java.lang.Short".equals(className)
  396. || "short".equals(className)) {
  397. field.set(obj, Short.valueOf(value.toString()));
  398. } else if ("java.lang.Float".equals(className)
  399. || "float".equals(className)) {
  400. field.set(obj, Float.valueOf(value.toString()));
  401. } else if ("java.lang.Double".equals(className)
  402. || "double".equals(className)) {
  403. field.set(obj, Double.valueOf(value.toString()));
  404. } else if ("java.lang.Boolean".equals(className)
  405. || "boolean".equals(className)) {
  406. field.set(obj, Boolean.valueOf(value.toString()));
  407. } else if ("java.lang.Character".equals(className)
  408. || "char".equals(className)) {
  409. field.set(obj, Character.valueOf(value.toString().charAt(0)));
  410. } else if ("java.sql.Timestamp".equals(className)) {
  411. field.set(obj,
  412. new Timestamp(CommonUtils.getDateFromStr(value.toString())
  413. .getTime()));
  414. } else {
  415. field.set(obj, value);
  416. }
  417. */
  418. switch (className) {
  419. case "java.lang.String":
  420. field.set(obj, value);
  421. return;
  422. /* 再重构 Po -- 非空字段使用 基本数据类型。Lin
  423. * 去掉 short/Short、char/Character、byte/Byte -- 不支持
  424. case "int":
  425. case "java.lang.Integer":
  426. field.set(obj, Integer.valueOf(value.toString()));
  427. return;
  428. case "long":
  429. case "java.lang.Long":
  430. field.set(obj, Long.valueOf(value.toString()));
  431. return;
  432. case "float":
  433. case "java.lang.Float":
  434. field.set(obj, Float.valueOf(value.toString()));
  435. return;
  436. case "double":
  437. case "java.lang.Double":
  438. field.set(obj, Double.valueOf(value.toString()));
  439. case "short":
  440. case "java.lang.Short":
  441. field.set(obj, Short.valueOf(value.toString()));
  442. return;
  443. case "char":
  444. case "java.lang.Character":
  445. //noinspection UnnecessaryBoxing
  446. field.set(obj, Character.valueOf(value.toString().charAt(0)));
  447. return;
  448. case "byte":
  449. case "java.lang.Byte":
  450. field.set(obj, Byte.valueOf(value.toString()));
  451. return;
  452. case "boolean":
  453. case "java.lang.Boolean":
  454. field.set(obj, Boolean.valueOf(value.toString()));
  455. return;
  456. */
  457. case "int":
  458. field.set(obj, Integer.parseInt(value.toString()));
  459. return;
  460. case "java.lang.Integer":
  461. field.set(obj, Integer.valueOf(value.toString()));
  462. return;
  463. case "long":
  464. field.set(obj, Long.parseLong(value.toString()));
  465. return;
  466. case "java.lang.Long":
  467. field.set(obj, Long.valueOf(value.toString()));
  468. return;
  469. case "float":
  470. field.set(obj, Float.parseFloat(value.toString()));
  471. return;
  472. case "java.lang.Float":
  473. field.set(obj, Float.valueOf(value.toString()));
  474. return;
  475. case "double":
  476. field.set(obj, Double.parseDouble(value.toString()));
  477. return;
  478. case "java.lang.Double":
  479. field.set(obj, Double.valueOf(value.toString()));
  480. return;
  481. case "boolean":
  482. field.set(obj, Boolean.parseBoolean(value.toString()));
  483. return;
  484. case "java.lang.Boolean":
  485. field.set(obj, Boolean.valueOf(value.toString()));
  486. return;
  487. /// 增加 java.sql.Date。Lin
  488. case "java.sql.Date":
  489. /* 再去掉 StrDate.toDate(,只用 java.sql.Date。Lin
  490. field.set(obj, StrDate.toDate(value.toString()));
  491. */ field.set(obj, Date.valueOf(value.toString()));
  492. return;
  493. ///
  494. case "java.sql.Timestamp":
  495. /* 再去掉 StrDate.toDate(,只用 java.sql.Date。Lin
  496. field.set(obj, new Timestamp(StrDate.toDate(value.toString()).getTime()));
  497. */ field.set(obj, Timestamp.valueOf(value.toString()));
  498. return;
  499. default:
  500. field.set(obj, value);
  501. // return; // 再去掉,IDEA:'return' is unnecessary as the last statement in a 'void' method。Lin
  502. }
  503. }
  504. } catch (Exception e) {
  505. throw new RuntimeException(e);
  506. }
  507. }
  508. /**
  509. * 增加创建人员, 管理人员,管理部门
  510. *
  511. * @param bb;
  512. * @param yh;
  513. * @param ispersonal;
  514. * @throws Exception;
  515. */
  516. // 来自 DbService.updateManangeId(BaseBean bb, WdYh yh, boolean ispersonal, GeneralDBAccess gdba)。Lin
  517. // 再从 DbServ.wrSsField( 移到这,并改名为 wrSsFieldByPo(
  518. // 再增加 fieldNameSet(Set<String>) 入口/出口参数,去掉 gdba(Db)
  519. // 去掉方法里的 gdba.doUpdPo(,归入上层的 gdba.doInsPo(、gdba.doUpdPo( 去做
  520. // 把调用 DbU.wrSsFieldByPo( 前移到上层的 .doInsPo(、.doUpdPo( 前面
  521. public static void wrSsFieldByPo(Po bb, Set<String> fieldNameSet, UserRunB yh, boolean ispersonal) throws Exception {
  522. if (yh == null)
  523. return;
  524. /* 再去掉 updatePropertyNames,改为 入口/出口参数 fieldNameSet。Lin
  525. Set<String> updatePropertyNames = new HashSet<>();
  526. */
  527. Long bmid = yh.bmid; // .getBmid()。Lin
  528. Long ryid = yh.ryid; // .getRyid()。Lin
  529. // 创建人员ID
  530. /* 改。Lin
  531. if (bb.getFieldMappingItem("cjryid") != null) {
  532. */ if (bb.fieldTypeMap.get("cjryid") != null) {
  533. Method targetMethod = bb.getClass().getDeclaredMethod("setCjryid", Long.class);
  534. targetMethod.setAccessible(true);
  535. targetMethod.invoke(bb, ryid);
  536. /* 再去掉 updatePropertyNames,改为 入口/出口参数 fieldNameSet。Lin
  537. updatePropertyNames.add("cjryid");
  538. */ fieldNameSet.add("cjryid");
  539. }
  540. // 管理人员
  541. /* 改。Lin
  542. if (bb.getFieldMappingItem("glryid") != null && ispersonal) {
  543. */ if (bb.fieldTypeMap.get("glryid") != null && ispersonal) {
  544. Method targetMethod = bb.getClass().getDeclaredMethod("setGlryid", Long.class);
  545. targetMethod.setAccessible(true);
  546. targetMethod.invoke(bb, ryid);
  547. /* 再去掉 updatePropertyNames,改为 入口/出口参数 fieldNameSet。Lin
  548. updatePropertyNames.add("glryid");
  549. */ fieldNameSet.add("glryid");
  550. }
  551. // 管理部门
  552. /* 改。Lin
  553. if (bb.getFieldMappingItem("glbmid") != null && ispersonal == false) {
  554. */ if (bb.fieldTypeMap.get("glbmid") != null && !ispersonal) {
  555. Method targetMethod = bb.getClass().getDeclaredMethod("setGlbmid", Long.class);
  556. targetMethod.setAccessible(true);
  557. targetMethod.invoke(bb, bmid);
  558. /* 再去掉 updatePropertyNames,改为 入口/出口参数 fieldNameSet。Lin
  559. updatePropertyNames.add("glbmid");
  560. */ fieldNameSet.add("glbmid");
  561. }
  562. /* 再去掉 gdba.doUpdPo(,归入上层的 gdba.doInsPo(、gdba.doUpdPo( 去做。Lin
  563. * 把调用 DbU.wrSsFieldByPo( 前移到上层的 .doInsPo(、.doUpdPo( 前面
  564. * 返回 fieldNameSet
  565. /// * 再改,IDEA:'updatePropertyNames.size() > 0' can be replaced with '!updatePropertyNames.isEmpty()'。Lin
  566. // if (updatePropertyNames.size() > 0)
  567. /// *
  568. if (!(updatePropertyNames.isEmpty()))
  569. gdba.doUpdPo(bb, updatePropertyNames); // .updateById()。Lin
  570. */
  571. }
  572. // 来自 pms-core:Reflects.(<T> boolean) copyProperties(T from, T to,
  573. // boolean copyAllIfNoName, String... names)。Lin
  574. // 去掉 copyAllIfNoName(boolean),共用 names(String[]) -- names 为 null 时,为所有字段
  575. public static <T> void copyPoFieldArr(T from, T to, String... names) {
  576. Objects.requireNonNull(from);
  577. Objects.requireNonNull(to);
  578. Class<?> clazz = from.getClass();
  579. /* 再去掉 并行 -- 有时不能 copy 完整 -- 时行时不行 -- 少了 .forEach(。Lin
  580. * 还是不用 .parallel() -- 并行线程的开销大,数组内容少时,性能不高
  581. return Optional.ofNullable(names)
  582. .filter(LambdaFunction.notEmptyArray()) // (wd.core.util.lambda.Functions.。Lin
  583. .map(Stream::of)
  584. .orElseGet(() -> {
  585. String[] arr;
  586. /// * 改,去掉 copyAllIfNoName,共用 names -- names 为 null 时,为所有字段。Lin
  587. // if (copyAllIfNoName) {
  588. // arr = getAllFieldName(clazz, true);
  589. // } else {
  590. // arr = EMPTY_ARRAY;
  591. // }
  592. /// *
  593. arr = rdPoFieldName(clazz, true);
  594. return Stream.of(arr);})
  595. .parallel()
  596. /// * 去掉 Fields,直接写。Lin
  597. // .map(cn -> Fields.create(clazz, cn))
  598. /// *
  599. .map(cn -> rdPoField(clazz, cn))
  600. .filter(LambdaFunction.notNull()) // (wd.core.util.lambda.Functions.。Lin
  601. /// * 去掉 Reflects 和 Fields,直接写成 copyOnePoField()。Lin
  602. // .filter(field -> field.copyValue(from, to))
  603. // .count() > 0;
  604. /// *
  605. /// * 再改,IDEA:Can be replaced with 'stream.anyMatch()'。Lin
  606. // .filter(field -> copyOnePoField(field, from, to))
  607. // .count() > 0;
  608. /// *
  609. .anyMatch(field -> copyPoField(field, from, to));
  610. */
  611. String[] t = Optional.ofNullable(names)
  612. .filter(LambdaFunction.notEmptyArray())
  613. .orElseGet(() -> {
  614. String[] arr;
  615. arr = rdPoFieldName(clazz, true);
  616. return arr;});
  617. Arrays.stream(t)
  618. .forEach(cn -> {
  619. Field f = rdPoField(clazz, cn);
  620. if (f != null)
  621. copyPoField(f, from, to);
  622. });
  623. }
  624. // 参考自 pms-core:Reflects.(Object) getFieldValue(Field field, Object object) 和
  625. // pms-core:Reflects.(boolean) setFieldValue(Field field, Object object, Object value)。Lin
  626. // 合并为 copy 功能
  627. public static boolean copyPoField(Field field, Object from, Object to) {
  628. Object value;
  629. /// 改自 Reflects.getFieldValue()。Lin
  630. boolean access = field.canAccess(from); // .isAccessible()。已过时,改用 .canAccess(from)。Lin
  631. field.setAccessible(true);
  632. try {
  633. value = field.get(from);
  634. } catch (IllegalArgumentException | IllegalAccessException e) {
  635. /* 改,去掉 e.printStackTrace(),改用 log4j -- 按 IDEA 规范。Lin
  636. e.printStackTrace();
  637. */ log4j.error("DbU.copyOnePoField() 异常", e);
  638. return false;
  639. } finally {
  640. field.setAccessible(access);
  641. }
  642. ///
  643. /// 改自 Reflects.setFieldValue()。Lin
  644. access = field.canAccess(to); // .isAccessible()。已过时,改用 .canAccess(to)。Lin
  645. field.setAccessible(true);
  646. try {
  647. field.set(to, value);
  648. return true;
  649. } catch (IllegalArgumentException | IllegalAccessException e) {
  650. /* 改。Lin
  651. printStackTrace(e);
  652. if (!debug) {
  653. System.out
  654. .println("Failed to set the field value. If you want to know what happened, set reflect.debug =true.Field:"
  655. + field);
  656. }
  657. */
  658. /* 改,去掉 e.printStackTrace(),改用 log4j -- 按 IDEA 规范。Lin
  659. e.printStackTrace();
  660. */ log4j.error("DbU.copyOnePoField() 异常", e);
  661. return false;
  662. } finally {
  663. field.setAccessible(access);
  664. }
  665. ///
  666. }
  667. // 来自 pms-core:Reflects.(String[]) getAllFieldName(Class<? extends Object> clazz, boolean notFinal)。Lin
  668. /* 再改,IDEA:Wildcard type argument '?' explicitly extends 'java.lang.Object'。Lin
  669. public static String[] rdPoFieldName(Class<? extends Object> clazz, boolean notFinal) {
  670. */ public static String[] rdPoFieldName(Class<?> clazz, boolean notFinal) {
  671. return Stream.of(clazz.getDeclaredFields()).parallel()
  672. .filter(f -> !(notFinal && Modifier.isFinal(f.getModifiers())))
  673. .map(Field::getName).distinct().toArray(String[]::new);
  674. }
  675. // 来自 pms-core:Reflects.(Field) getField(Class<?> clazz, String fieldName)。Lin
  676. public static Field rdPoField(Class<?> clazz, String fieldName) {
  677. try {
  678. return clazz.getDeclaredField(fieldName);
  679. } catch (NoSuchFieldException | SecurityException e) {
  680. /* 改,去掉 e.printStackTrace(),改用 log4j -- 按 IDEA 规范。Lin
  681. e.printStackTrace(); // printStackTrace(e)。Lin
  682. */ log4j.error("DbU.rdPoField() 异常", e);
  683. return null;
  684. }
  685. }
  686. // 来自 GeneralDBAccess.getGetMethodName(String fieldName)。Lin
  687. // 根据传入的fieldName返回getXX方法名
  688. /* 去掉,直接用 "get"+ StringUtils.capitalize(fieldName)。Lin
  689. public static String cmptGetField(String fieldName) {
  690. return "get" + fieldName.substring(0, 1).toUpperCase() + fieldName.substring(1, fieldName.length());
  691. }
  692. */
  693. // 把对像o在request中有传值的参数名,返回为一个集合
  694. // 来自 GeneralDBAccess.(Set<String>) propertyInRequest(Object o, HttpServletRequest request)。Lin
  695. // Object 改为 Po,专门给 Po 用
  696. // 不用 ClazzU.rdAtrArrByClazz(c),改为 c.getDeclaredFields() -- XxxPo 不能继承 XxxPo
  697. /* 再去掉,用 DbU.loadPoFieldByReq( 返回的 fieldNameSet(Set<String>)。Lin
  698. * DbU.rdPoFieldNameByReq( 并入 DbU.loadPoFieldByReq(
  699. public static Set<String> rdPoFieldNameByReq(Po o, HttpServletRequest request) {
  700. Set<String> properties = new HashSet<>();
  701. Set<String> paramNames = request.getParameterMap().keySet();
  702. Class<?> c = o.getClass();
  703. /// * 再把 ClazzU.rdAtrArrByClazz(c) 改为 c.getDeclaredFields()。Lin
  704. // Field[] fields = ClazzU.rdAtrArrByClazz(c); // 获得本类和父类的所有属性 // WebUtil.getAllFieldsFromClass()。Lin
  705. /// *
  706. Field[] fields = c.getDeclaredFields(); // 获得本类的所有属性
  707. for (Field field : fields) {
  708. String propertyName = field.getName();
  709. if (paramNames.contains(propertyName)) {
  710. properties.add(propertyName);
  711. }
  712. }
  713. return properties;
  714. }
  715. */
  716. // 来自 WDCore_pms_product:(List<String>) getParamNameFromRequest(HttpServletRequest request, ViewObject vo)。Lin
  717. // vo 移到前面 -- 统一
  718. /* 再去掉,并入 DbU.loadPoFieldByReq( -- DbU.rdPoFieldByReq( 改为 loadPoFieldByReq(,增加返回 fieldNameSet(Set<String>)。Lin
  719. public static List<String> rdObjFieldNameByReq(ObjB vo, HttpServletRequest request) {
  720. List<String> paramNameList = new ArrayList<>();
  721. Map<String, ?> map = request.getParameterMap();
  722. for (ObjFieldB f : vo.fieldMap.values()) { // .getFields()。Lin
  723. String fieldName = f.name;
  724. if (map.containsKey(fieldName)) {
  725. paramNameList.add(fieldName);
  726. }
  727. }
  728. return paramNameList;
  729. }
  730. */
  731. // ===
  732. // private static final Class<?>[] STR_CLS = {String.class}; // 字符串类数组 // 再去掉,没用到。Lin
  733. /**
  734. * 从request中获取参数,放到相应bean的属性内。名称与bean内属性名不一致的request参数将被忽略 前提:request中必须有一个参数
  735. * obj=...,用来指定对像的类名。对象类必须提供无参数的默认构造函数。
  736. *
  737. * @param request http请求的request
  738. * @param objClass 对象类的绝对路径
  739. * isAsString 是否将所有数据全部作为String类型看待,而不区分。 true:
  740. * 全部作为String,对应的对象类的所有对应属性也是String类型;<br>
  741. * false:
  742. * 区分整数(Long)、小数(Double)、日期(Timestamp)和字符串(String)类型,自动匹配。<br>
  743. * 如果前三个类型匹配不到,则自动作为String处理,如果都匹配不到,则放弃本参数。
  744. * @return Object 新创建的bean,保存了request里面的所有相应(与bean属性具有相同名字的)的param。
  745. * @throws Exception;
  746. */
  747. // 来自 WebUtil.(Object) paramsFromRequest(HttpServletRequest request, String objClassName, boolean isAsString)。Lin
  748. // objClassName 移到前面
  749. // 专门给 Po 用
  750. // 返回值改为 Po
  751. // 只获取本类的所有属性 -- XxxPo 不能继承
  752. // 再,objClassName 改为 clazz(Class<? extends Po>)。Lin
  753. // 再,clazz 改为 objClass -- IDEA:Local variable 'objClass' is redundant。Lin
  754. // 再考虑把 objClass.getDeclaredFields() 循环改为 Po.fieldTypeMap.keySet() 循环
  755. // 不能改,Set 方法的入口参数类型与 Po.fieldTypeMap 里的有差异
  756. /* 再去掉 isAsString(boolean),都是 false。Lin
  757. public static Po rdPoByReqField(Class<? extends Po> objClass, HttpServletRequest request, boolean isAsString) throws Exception {
  758. */
  759. /* 再改为 Load,增加返回 fieldNameSet(Set<String>) -- null = 不返回。Lin
  760. * 原返回值的 Po,改为入口/出口参数 obj(Po)
  761. public static Po rdPoFieldByReq(Class<? extends Po> objClass, HttpServletRequest request) throws Exception {
  762. */ public static boolean loadPoFieldByReq(Po obj, Set<String> fieldNameSet,
  763. Class<? extends Po> objClass, HttpServletRequest request) throws Exception {
  764. // 取得类名
  765. // String className = objPkgName + "." + request.getParameter( REQ_OBJ
  766. // );
  767. /* 再,objClassName 改为 po(Po)。Lin
  768. * objClassName 改为 clazz(Class<Po>)
  769. Class<?> objClass = Class.forName(objClassName);
  770. */
  771. /* 再去掉,IDEA:Local variable 'objClass' is redundant。Lin
  772. * 入口参数 clazz 改为 objClass
  773. Class<? extends Po> objClass = clazz;
  774. */
  775. // Field[] fields = objClass.getFields();//获得本类和父类的所有属性
  776. // Field[] fields = objClass.getDeclaredFields();//获得本类和父类的所有属性
  777. /* 再把 ClazzU.rdAtrArrByClazz(objClass) 改为 objClass.getDeclaredFields()。Lin
  778. Field[] fields = ClazzU.rdAtrArrByClazz(objClass);// 获得本类和父类的所有属性 // WebUtil.getAllFieldsFromClass()。Lin
  779. */ Field[] fields = objClass.getDeclaredFields();// 获得本类的所有属性
  780. // 创建类实例
  781. /// 再,objClassName 改为 po(Po)。Lin
  782. // 还需要 new,不能共用 ObjB.po
  783. /* 再去掉,改为 Load 了 -- 增加返回 fieldNameSet(Set<String>)。Lin
  784. * obj(Po),同时也是返回值
  785. Po obj = objClass.getDeclaredConstructor().newInstance(); // Object。Lin
  786. */
  787. ///
  788. Class<?>[] methodParams = new Class[1];
  789. Object[] realParams = new Object[1];
  790. Method method;
  791. // 从request传来的参数必定非null,除非request中不存在指定名称的参数。
  792. // 因此根据request中存在的参数名枚举来获取的参数,必定在request中存在,
  793. // 从而参数值只可能是空串("",在没有输入的时候),或者具体的值。
  794. String fieldName;
  795. String typeName;
  796. String[] paramValueArr;
  797. /* 再改,IDEA:'for' loop can be replaced with enhanced 'for'。Lin
  798. for (int i = 0; i < fields.length; i++) {
  799. String fieldName = fields[i].getName();
  800. */ for (Field field : fields) {
  801. fieldName = field.getName();
  802. typeName = field.getType().getName();
  803. paramValueArr = request.getParameterValues(fieldName);
  804. // 如果参数列表中无与对象名称一致的参数,则忽略
  805. /* 再重构 Po -- 非空字段使用 基本数据类型。Lin
  806. * 值为 "" 时,也不处理 -- 使用 Po 里的默认值 -- Request 返回 "",paramValueArr.length = 1
  807. if (paramValueArr == null || paramValueArr.length == 0)
  808. */
  809. /* 再改,对 String 字段,值为 "" 不能去掉。Lin
  810. * 变动时,删除 地址 的值 -- Request 返回 "",paramValueArr.length = 1
  811. * 对其他字段,如 int,需要去掉 -- 使用 Po 里的默认值
  812. * 需要改为默认值时,需要录入默认值
  813. if (paramValueArr == null || paramValueArr.length == 0 ||
  814. Arrays.stream(paramValueArr).allMatch(StringUtils::isBlank))
  815. */
  816. /* 再改,对下拉列表,值为 "" 不能去掉。Lin
  817. * 变动时,删除下拉列表的值 -- Request 返回 "",paramValueArr.length = 1
  818. * 下面的 ObjU.toValByType( 会把 "" 转为 null -- 字符串的 "",也会转为 null
  819. if (paramValueArr == null || paramValueArr.length == 0 ||
  820. (!"java.lang.String".equals(typeName) && Arrays.stream(paramValueArr).allMatch(StringUtils::isBlank)))
  821. */ if (paramValueArr == null || paramValueArr.length == 0)
  822. continue;
  823. // 排除重复的参数值
  824. /* 再去掉 paramValues(Set<String>),直接用 paramValueArr(String[])。Lin
  825. Set<String> paramValues = new HashSet<>();
  826. /// * 再改,IDEA:Manual array to collection copy 。Lin
  827. // for (String s : paramValueArr) {
  828. // paramValues.add(s);
  829. // }
  830. /// *
  831. Collections.addAll(paramValues, paramValueArr);
  832. */
  833. /* 再改,IDEA:String concatenation '+=' in loop。Lin
  834. * 改为 new StringBuilder(),不出现空指针
  835. String paramFinalValue = null;// 保存到数据库的参数终值
  836. */
  837. /* 再改回 String,多个值里再用 StringBuilder。Lin
  838. StringBuilder paramFinalValue = new StringBuilder();// 保存到数据库的参数终值
  839. */ String paramFinalValue;// 保存到数据库的参数终值
  840. /* 再去掉 paramValues(Set<String>),直接用 paramValueArr(String[])。Lin
  841. if (paramValues.size() == 1) {// 如果只有一个参数值
  842. /// * 再改,IDEA:String concatenation '+=' in loop。Lin
  843. // paramFinalValue = paramValues.iterator().next();
  844. /// *
  845. paramFinalValue = new StringBuilder(paramValues.iterator().next());
  846. */
  847. if (paramValueArr.length == 1) {// 如果只有一个参数值
  848. paramFinalValue = paramValueArr[0];
  849. } else {// 如果有多个参数值
  850. StringBuilder paramValue = new StringBuilder(); // 增加,多个值里再用 StringBuilder。Lin
  851. /* 再改,多个参数的值一致时,当成一个值。Lin
  852. boolean fst = true;
  853. */ String last = null; // 上一个参数值。Lin
  854. // 把多个值拼成用 "|" 分隔的串
  855. /* 再去掉 paramValues(Set<String>),直接用 paramValueArr(String[])。Lin
  856. for (String s : paramValues) {
  857. */ for (String s : paramValueArr) {
  858. if (StringUtils.isBlank(s)) // 去掉 StrU.isNull(),直接用 StringUtils.isBlank()。Lin
  859. continue;
  860. /* 再改,多个参数的值一致时,当成一个值。Lin
  861. if (fst)
  862. fst = false;
  863. */
  864. if (last == null) {
  865. last = s;
  866. /* 再去掉,IDEA:String concatenation '+=' in loop。Lin
  867. * new StringBuilder() 移到上面了
  868. paramFinalValue = "";
  869. */
  870. } else {
  871. /// 再增加,多个参数的值一致时,当成一个值。Lin
  872. if (s.equals(last))
  873. continue;
  874. ///
  875. /* 再改,IDEA:String concatenation '+=' in loop。Lin
  876. paramFinalValue += WebC.SEP_parm; // CoreConstVars.WD_DB_DATA_SEPARATOR。Lin
  877. */
  878. /* 再改,多个值里再用 StringBuilder。Lin
  879. * 改 "|"(DbC.SEP_parm) 为 ","(AppC.SEP_abbrJson) 了 -- 简写 Json 时的分隔符
  880. paramFinalValue.append(DbC.SEP_parm); // CoreConstVars.WD_DB_DATA_SEPARATOR。Lin
  881. */ paramValue.append(AppC.SEP_abbrJson); // CoreConstVars.WD_DB_DATA_SEPARATOR。Lin
  882. }
  883. /* 再改,IDEA:String concatenation '+=' in loop。Lin
  884. paramFinalValue += s;
  885. */
  886. /* 再改,多个值里再用 StringBuilder。Lin
  887. paramFinalValue.append(s);
  888. */ paramValue.append(s);
  889. }
  890. paramFinalValue = paramValue.toString(); // 增加,多个值里再用 StringBuilder。Lin
  891. }
  892. /* 再去掉 isAsString(boolean),都是 false。Lin
  893. if (isAsString) {
  894. methodParams = STR_CLS;
  895. /// * 再改,IDEA:'for' loop can be replaced with enhanced 'for'。Lin
  896. // realParams[0] = request.getParameter(fields[i].getName());
  897. /// *
  898. realParams[0] = request.getParameter(field.getName());
  899. } else {
  900. */
  901. // 对于具体类型的值,如果是空串,则可认为是NULL(字符串则为"")
  902. // 如果是具体的值,则按可转化类型
  903. /* 再改,IDEA:'for' loop can be replaced with enhanced 'for'。Lin
  904. typeName = fields[i].getType().getName();
  905. */
  906. /* 再去掉,上移,上面也要用到了。Lin
  907. typeName = field.getType().getName();
  908. */
  909. /* 再改,IDEA:String concatenation '+=' in loop。Lin
  910. realParams[0] = ObjU.toValByType(paramFinalValue, typeName); // checkParamType()。Lin
  911. */
  912. /* 再改,paramFinalValue 从 StringBuilder 改回 String。Lin
  913. realParams[0] = ObjU.toValByType(paramFinalValue.toString(), typeName); // checkParamType()。Lin
  914. */ realParams[0] = ObjU.toValByType(paramFinalValue, typeName); // checkParamType()。Lin
  915. /* 再改,IDEA:'for' loop can be replaced with enhanced 'for'。Lin
  916. methodParams[0] = fields[i].getType();
  917. */ methodParams[0] = field.getType();
  918. /* 再去掉 isAsString(boolean),都是 false。Lin
  919. }
  920. */
  921. try {
  922. /* 再改,IDEA:'for' loop can be replaced with enhanced 'for'。Lin
  923. method = objClass
  924. .getMethod("set" + fields[i].getName().replaceFirst(fields[i].getName().substring(0, 1),
  925. fields[i].getName().substring(0, 1).toUpperCase()), methodParams);
  926. */
  927. /* 再改用 StringUtils.capitalize(。Lin
  928. method = objClass
  929. .getMethod("set" + field.getName().replaceFirst(field.getName().substring(0, 1),
  930. field.getName().substring(0, 1).toUpperCase()), methodParams);
  931. */ method = objClass.getMethod("set"+ StringUtils.capitalize(field.getName()), methodParams);
  932. method.invoke(obj, realParams);
  933. } catch (NoSuchMethodException e) {
  934. /* 再去掉,IDEA:'continue' is unnecessary as the last statement in a loop。Lin
  935. * > 增加 log4j -- IDEA:Empty 'catch' block
  936. continue;
  937. */ log4j.error("DbU.rdPoByReqField( 异常", e);
  938. }
  939. if (fieldNameSet != null)
  940. fieldNameSet.add(fieldName); // 增加,增加返回 fieldNameSet(Set<String>)。Lin
  941. }
  942. /* 再改,改为 Load 了 -- 增加返回 fieldNameSet(Set<String>)。Lin
  943. return obj;
  944. */ return true;
  945. }
  946. // ===
  947. // 来自 ViewObjectUtil.findWholeBeanMap(ViewObject vo, HttpServletRequest request)。Lin
  948. public static Map<String, Object> rdPoMapByReq(ObjB vo, HttpServletRequest request) throws InvocationTargetException, NoSuchMethodException, IllegalAccessException {
  949. Map<String, Object> result = new HashMap<>();
  950. Po bean = rdPoByReq(vo, request); // ViewObjectUtil.findBeanFromRequest()
  951. if (bean != null)
  952. result = DbU.toMapByPo(bean, true); // tt.util.BeanUtils.beansToMap( -- 有过滤 null 值的字段。Lin
  953. // true = filterNull。Lin
  954. /* 再改,IDEA:'result.size() == 0' can be replaced with 'result.isEmpty()'。Lin
  955. if (result.size() == 0) {
  956. */ if (result.isEmpty()) {
  957. /* 再改,只取 对象ID,有问题再说 -- 解决 大海捞针 问题。Lin
  958. * 没有即返回空的 result
  959. for (String xxa : request.getParameterMap().keySet()) { // ???大海捞针啊!!!Lin
  960. /// * 再改,去掉 ObjC.REQUEST_PLUGIN_POSSIBLE,key= 只需要一个属性及一个值,用于找到 <page 定义。Lin
  961. // * 把 <page key= 分开为 key= 和 def= -- def= 其他的录入页面字段值,支持多个属性及一个值
  962. // if (vo.fieldMap.containsKey(xxa) || ObjC.REQUEST_PLUGIN_POSSIBLE.equals(xxa)) {
  963. // // ViewObjectUtil.REQUEST_PLUGIN_POSSIBLE
  964. /// *
  965. if (vo.fieldMap.containsKey(xxa))
  966. result.put(xxa, request.getParameter(xxa));
  967. }
  968. */
  969. String idStr = request.getParameter(vo.idName);
  970. if (StringUtils.isNotBlank(idStr))
  971. result.put(vo.idName, Long.parseLong(idStr));
  972. }
  973. return result;
  974. }
  975. // 来自 ViewObjectUtil.findBeanFromRequest(ViewObject viewobj, HttpServletRequest request)。Lin
  976. // 调整语句顺序,使清晰。Lin
  977. public static Po rdPoByReq(ObjB viewobj, HttpServletRequest request) {
  978. try {
  979. if (request == null
  980. /* 再,.poName 改为 .poClazz。Lin
  981. || StringUtils.isBlank(viewobj.poName)) // 去掉 StrU.isNull(),直接用 StringUtils.isBlank()。Lin
  982. */ || viewobj.poClazz == null)
  983. return null;
  984. /// * 再去掉,永远取不到了 -- Po 改为 "RyPo" 了,不是 "Ry"。Lin
  985. // * 再不能去掉,对于 学员,写成 "xy" 的 Po(值是 RyPo),不是 "RyPo"
  986. if (request.getAttribute(viewobj.name) != null)
  987. return (Po) request.getAttribute(viewobj.name);
  988. /// *
  989. /* 再改,直接用 viewobj.poClazz,不用转来转去。Lin
  990. /// * 再,.poName 改为 .poClazz。Lin
  991. // Po thisBean = (Po) Class.forName(viewobj.poName).getDeclaredConstructor().newInstance();
  992. /// *
  993. Po thisBean = viewobj.poClazz.getDeclaredConstructor().newInstance();
  994. /// * 再去掉结尾的 "Po" -- 原为 "Ry",改为了 "RyPo" -- 学员(虚拟对象) 的 .clazzName 为 "RyPo"(实体对象)。Lin
  995. // * 再去掉 thisBean.objName 了 -- 不能反过来指定对象名 -- 虚拟对象,反过来是 一对多 了
  996. // * 去掉 StrU.lowerFstChar(),直接用 StringUtils.uncapitalize()
  997. // String key = StrU.lowerFstChar(thisBean.getClass().getSimpleName()); // CommonUtils.lowerFirstChar()。Lin
  998. /// *
  999. /// * 再,不用改了,用回 wrPoByReq() -- 原,去掉 wrPoByReq() 时,用 Po.objName 做为 Request 的 Key -- 导致学员(虚拟对象)取不到 Po。Lin
  1000. // * 再去掉 thisBean.objName 了 -- 不能反过来指定对象名 -- 虚拟对象,反过来是 一对多 了
  1001. // String key = thisBean.getClass().getSimpleName();
  1002. // if (key.endsWith("Po"))
  1003. // key = key.substring(0, key.length() -2);
  1004. // key = StringUtils.uncapitalize(key);
  1005. /// *
  1006. String key = StringUtils.uncapitalize(thisBean.getClass().getSimpleName());
  1007. */ String key = viewobj.poClazz.getSimpleName();
  1008. if (request.getAttribute(key) != null)
  1009. return (Po) request.getAttribute(key);
  1010. } catch (Exception e) {
  1011. /* 改,去掉 e.printStackTrace(),改用 log4j -- 按 IDEA 规范。Lin
  1012. e.printStackTrace();
  1013. */ log4j.error("DbU.rdPoByReq( 异常", e);
  1014. }
  1015. return null;
  1016. }
  1017. // 增加。Lin
  1018. // "XxxPo" 里的 "xxx"
  1019. public static String rdPurePoNameByClazz(Class<? extends Po> poClazz) {
  1020. String poName = poClazz.getSimpleName();
  1021. return poName.substring(0, poName.length() -2).toLowerCase();
  1022. }
  1023. /**
  1024. * 用对象名设置bean
  1025. * @param vo;
  1026. * @param bean;
  1027. * @param request;
  1028. * @return String
  1029. */
  1030. // 来自 BeanUtils.putRequestBean(ViewObject vo, BaseBean bean,HttpServletRequest request)
  1031. // 去掉 vo(ViewObject),Key 直接用 Po.objName(对象名)
  1032. // 也不需要 lowerFirstChar() 了,不用类名
  1033. /* 去掉,直接写 request.setAttribute(bean.objName, bean)。Lin
  1034. * 返回值用 bean.objName
  1035. * 再用回,不能去掉。Lin
  1036. * 不能去掉 vo(ViewObject),即不能直接用 Po.objName(对象名) -- 学员(虚拟对象) 的 Po 是人员(实体对象),但学员的页面用学员(不是人员)
  1037. * 再去掉 bb.objName 了 -- 不能反过来指定对象名 -- 虚拟对象,反过来是 一对多 了
  1038. */
  1039. public static String wrPoByReq(ObjB vo, Po bean, HttpServletRequest request) {
  1040. /* 改了。Lin
  1041. String key = null;
  1042. if(vo!=null){
  1043. key=vo.getName();
  1044. }else{//兼容处理
  1045. key=CommonUtils.lowerFirstChar(bean.getClass().getSimpleName());
  1046. }
  1047. */
  1048. /* 再用回,不能用 bean.objName 做为 Key -- 学员(虚拟对象)的页面用学员,而不是人员。Lin
  1049. * 再去掉 bean.objName 了,不能反过来指定对象名 -- 虚拟对象,反过来是 一对多
  1050. String key = bean.objName;
  1051. */
  1052. String key;
  1053. if (vo != null) {
  1054. key = vo.name;
  1055. } else {//兼容处理
  1056. /* 去掉 CommonUtils.lowerFirstChar(),直接用 StringUtils.uncapitalize()。Lin
  1057. key=CommonUtils.lowerFirstChar(bean.getClass().getSimpleName());
  1058. */
  1059. /* 再改为表名 -- Po 的类名是 <对象名>Po 了,如 RyPo。Lin
  1060. key = StringUtils.uncapitalize(bean.getClass().getSimpleName());
  1061. */ key = bean.tabName;
  1062. }
  1063. request.setAttribute(key, bean);
  1064. return key;
  1065. }
  1066. // 增加。Lin
  1067. /* 再去掉,没用到了 -- ObjB.poName 改为 .poClazz。Lin
  1068. public static Po newPoClazz(String clazzName) throws Exception {
  1069. Po po = null;
  1070. if (StringUtils.isNotBlank(clazzName)) { // 去掉 StrU.notNull(),直接用 StringUtils.isNotBlank()。Lin
  1071. try {
  1072. po = (Po)Class.forName(clazzName).getDeclaredConstructor().newInstance();
  1073. } catch (ClassNotFoundException e) {
  1074. SsLog.print("classNotFound:" + clazzName);
  1075. }
  1076. }
  1077. return po;
  1078. }
  1079. */
  1080. /**
  1081. * 如果html field为空,设置该字段为null
  1082. *
  1083. * @param bean;
  1084. * @param vo;
  1085. */
  1086. // 来自 ViewObjectUtil.(BaseBean) filterHTMLBlankField(BaseBean bean, ViewObject vo)。Lin
  1087. // 去掉返回值,写在入口参数 bean 里
  1088. public static void clearBlankHtmlField(Po bean, ObjB vo) throws Exception {
  1089. if (bean == null || vo == null)
  1090. return; // return bean;。去掉返回值
  1091. /* 去掉 .fields(List<Field>),共用 fieldMap(Map<String, ObjFieldB>)。Lin
  1092. for (Field f : vo.getFields()) {
  1093. */
  1094. /* 再改,增加 ObjB.htmlFieldList 了。Lin
  1095. for (ObjFieldB f : vo.fieldMap.values()) { // 逐一比较,以找出 HTML 的字段,大海捞针啊???Lin
  1096. */ for (ObjFieldB f : vo.htmlFieldSet) {
  1097. try {
  1098. /* type 从 String 改为 int。Lin
  1099. if (Field.TYPE_HTML.equals(f.getType())) {
  1100. */
  1101. /* 再去掉 if,增加 ObjB.cmsFieldList 了。Lin
  1102. if (f.type == ObjC.FIELD_htmlType) {
  1103. */
  1104. /* tt.util.BeanUtils.getFieldValue() 归入了 ObjU.rdClazzAtr(),但这里用 DbU.rdPoField() -- bean 是 Po。Lin
  1105. Object v = BeanUtils.getFieldValue(f.getName(), bean);
  1106. */ Object v = DbU.rdFieldValByPo(f.name, bean);
  1107. /* 改,去掉 appName。Lin
  1108. if (StringUtil.isNull(getFieldDisplayValue(vo.getWebapp().getName(), f, v))) {
  1109. */
  1110. /* 再把 value(Object) 移到最前面。Lin
  1111. if (StringUtils.isBlank(ObjU.makeFieldPlayDesc(f, v))) {
  1112. */ if (StringUtils.isBlank(ObjU.toPlayDescByFieldVal(v, f))) {
  1113. SsLog.print("III,clearBlankHtmlField(,blankContent:"+ v);
  1114. /* tt.util.BeanUtils.setFieldValue()。Lin
  1115. * Object 改为 Po,专门用于 Po
  1116. * bean(Po) 移到最后面 -- 统一
  1117. BeanUtils.setFieldValue(bean, f.getName(), null);
  1118. */ wrPoField(f.name, null, bean); // null = value。Lin
  1119. }
  1120. // } // 再去掉 if,增加 ObjB.cmsFieldList 了。Lin
  1121. } catch (Exception e) {
  1122. /* 改,去掉 e.printStackTrace(),改用 log4j -- 按 IDEA 规范。Lin
  1123. e.printStackTrace();
  1124. */ log4j.error("DbU.clearBlankHtmlField( 异常", e);
  1125. throw e; // 再增加,改为抛出错误。Lin
  1126. }
  1127. }
  1128. /* 再去掉,IDEA:'return' is unnecessary as the last statement in a 'void' method。Lin
  1129. return; // return bean;。去掉返回值
  1130. */
  1131. }
  1132. /**
  1133. * 没有上传 CMS 内容时,删除 内容 表记录并设置 cms 字段为 null
  1134. *
  1135. * @param bean;
  1136. * @param vo;
  1137. */
  1138. // 抄自 clearBlankHtmlField。Lin
  1139. /* 再改,增加处理 -- 有上传时,补写 内容.对象ID 值。Lin
  1140. public static void clearBlankCmsField(Po bean, ObjB vo, Db gdba) {
  1141. */ public static void fixCmsField(Po bean, ObjB vo, Db gdba) {
  1142. if (bean == null || vo == null)
  1143. return; // return bean;。去掉返回值
  1144. for (ObjFieldB f : vo.cmsFieldSet) {
  1145. try {
  1146. Object v = DbU.rdFieldValByPo(f.name, bean);
  1147. if (v == null) // 没有点击过 附件 按钮。Lin
  1148. continue;
  1149. long nrid = Long.parseLong(String.valueOf(v));
  1150. if (CmsU.isBlankDgnFile("T-"+ nrid)) {
  1151. SsLog.print("III,fixCmsField(,内容ID:"+ v);
  1152. /* 再改,用 ObjC.JLZT_inEditStr,不直接用 ObjC.JLZT_inEdit。Lin
  1153. SqlCmd cmd = new SqlCmd("delete from NR where NRID=:nrid and JLZTM="+ ObjC.JLZT_inEdit);
  1154. */ SqlCmd cmd = new SqlCmd("delete from NR where NRID=:nrid and "+ ObjC.JLZT_inEditStr);
  1155. cmd.wrLongParm("nrid", nrid); // .setInt()。Lin
  1156. gdba.doModByC(cmd); // .modify()。Lin
  1157. wrPoField(f.name, null, bean); // null = value。Lin
  1158. /// 再增加,删除 CMS 文件。Lin
  1159. File nrFolder = new File(AppB.appRoot + CmsU.cmptBaseDir("T-"+ nrid));
  1160. FileUtils.deleteDirectory(nrFolder);
  1161. ///
  1162. }
  1163. /// 再增加,有上传时,补写 内容.对象ID 值。Lin
  1164. else {
  1165. /* 再改,用 ObjC.JLZT_inEditStr,不直接用 ObjC.JLZT_inEdit。Lin
  1166. SqlCmd cmd = new SqlCmd("update NR set DXID=:dxid where NRID=:nrid and JLZTM="+ ObjC.JLZT_inEdit);
  1167. */ SqlCmd cmd = new SqlCmd("update NR set DXID=:dxid where NRID=:nrid and "+ ObjC.JLZT_inEditStr);
  1168. cmd.wrLongParm("dxid", bean.rdIdVal());
  1169. cmd.wrLongParm("nrid", nrid);
  1170. gdba.doModByC(cmd); // .modify()。Lin
  1171. }
  1172. ///
  1173. } catch (Exception e) {
  1174. log4j.error("DbU.fixCmsField( 异常", e);
  1175. }
  1176. }
  1177. }
  1178. // 来自 tt.bpm.common.BpmUtil.(Set<String>) updateNameSet(BaseBean bean, String... columnNames)。Lin
  1179. /* 再去掉 DbU.combFieldNameByPo(,直接用 Set.of( -- 空值的字段,也写!--有问题再说???Lin
  1180. public static Set<String> combFieldNameByPo(Po bean, String... columnNames) {
  1181. Set<String> rs = new TreeSet<>();
  1182. for (String name : columnNames) {
  1183. Object v = DbU.rdFieldValByPo(name, bean); // tt.util.BeanUtils.getFieldValue()。Lin
  1184. if (v != null &&
  1185. StringUtils.isNotBlank(v.toString())) { // v.toString().length() > 0。Lin
  1186. rs.add(name);
  1187. }
  1188. }
  1189. // Collections.addAll(rs, columnNames);
  1190. return rs;
  1191. }
  1192. */
  1193. // 来自 tt.bpm.common.BpmUtil.(Set<String>) nameSet(String... columnNames)。Lin
  1194. // 另,只有一个字段名时,直接用 Collections.singleton(。Lin
  1195. /* 再去掉,直接用 Set.of(。Lin
  1196. public static Set<String> combFieldName(String... columnNames) {
  1197. /// * 用新的写法。Lin
  1198. // Set<String> rs = new TreeSet<>();
  1199. // for (String name : columnNames) {
  1200. // rs.add(name);
  1201. // }
  1202. // return rs;
  1203. /// *
  1204. /// * 再改,IDEA:Lin
  1205. // * Local variable 'rs' is redundant
  1206. // * Redundant 'distinct()' call: elements will be distinct anyway when collected to a Set
  1207. // Set<String> rs = Arrays.stream(columnNames).distinct().collect(Collectors.toSet());
  1208. // return rs;
  1209. /// *
  1210. return Arrays.stream(columnNames).collect(Collectors.toSet());
  1211. }
  1212. */
  1213. // 来自 ViewObjectUtil.(Map) _compareObject(int type, ViewObject vo, BaseBean oldObj, BaseBean newObj,
  1214. // List<String> paramNameList)。Lin
  1215. // "比较oldObj和newObj,返回两个对象中的不同字段集合Map"
  1216. // fieldNameList 前移到 type 后面
  1217. /* 再改 fieldNameList(List<String>) 为 fieldNameSet(Set<String>)。Lin
  1218. * DbU.rdObjFieldNameByReq( 并入 DbU.loadPoFieldByReq( -- DbU.rdPoFieldByReq( 改为 loadPoFieldByReq(,增加返回 fieldNameSet(Set<String>)
  1219. public static Map<String, Object> cmpField(int type, List<String> fieldNameList, ObjB vo, Po oldObj, Po newObj) {
  1220. */
  1221. /* 再改为 cmpChgField(,专门用于比较变动时的改动字段 -- 抽取出共用程序,与 JrgwServ 共用。Lin
  1222. * 去掉 type(int),只用到 type = 1
  1223. * 1,返回 Arrays.asList(oValue, nValue);2 返回 newValue
  1224. * ViewObjectUtil.(Map<String, Object>) compareFields(ViewObject vo, BaseBean oldObj, BaseBean newObj, List<String> paramNameList) 没用到
  1225. * "比较oldObj和newObj,返回两个对象中的不同字段集合Map"
  1226. * return (Map<String, Object>) _compareObject(2, vo, oldObj, newObj, paramNameList);
  1227. * 返回值 Map<String, Object> 改为 Map<String, List<String>>
  1228. * 纳入 BpmServ.saveChgField( 里的形成 wdObject(Map<String, List<String>>) 的程序
  1229. * 把入口参数反过来,调整为 newObj(Po)、oldObj(Po)、vo(ObjB)、fieldNameSet(Set<String>)
  1230. public static Map<String, Object> cmpField(int type, Set<String> fieldNameSet, ObjB vo, Po oldObj, Po newObj) {
  1231. */ public static Map<String, List<String>> cmpChgField(Po newObj, Po oldObj, ObjB vo, Set<String> fieldNameSet) throws InvocationTargetException, NoSuchMethodException, IllegalAccessException {
  1232. // ViewObject vo = findViewObject();
  1233. Map<String, Object> result = new HashMap<>();
  1234. /* 改为用 fieldNameList 来 for,提高性能。Lin
  1235. for (Field f : vo.getFields()) {
  1236. if (paramNameList == null) {
  1237. } else if (!paramNameList.contains(f.getName())) {
  1238. continue;
  1239. }
  1240. if (vo.getObjectIdField().equals(f))
  1241. continue;
  1242. */
  1243. for (String fieldName : fieldNameSet) {
  1244. ObjFieldB f = vo.fieldMap.get(fieldName);
  1245. // 比较oldObj和newObj的区别
  1246. /* tt.util.BeanUtils.getFieldValue() 归入了 ObjU.rdClazzAtr(),但这里用 DbU.rdPoField() -- bean 是 Po。Lin
  1247. Object oldValue = BeanUtils.getFieldValue(f.getName(), oldObj);
  1248. Object newValue = BeanUtils.getFieldValue(f.getName(), newObj);
  1249. */
  1250. Object oldValue = DbU.rdFieldValByPo(f.name, oldObj);
  1251. Object newValue = DbU.rdFieldValByPo(f.name, newObj);
  1252. // 空字符""
  1253. /* 再改,IDEA:'equals("")' can be replaced with 'isEmpty()'。Lin
  1254. if (oldValue != null && String.valueOf(oldValue).equals(""))
  1255. */ if (oldValue != null && String.valueOf(oldValue).isEmpty())
  1256. oldValue = null;
  1257. /* 再改,IDEA:'equals("")' can be replaced with 'isEmpty()'。Lin
  1258. if (newValue != null && String.valueOf(newValue).equals(""))
  1259. */ if (newValue != null && String.valueOf(newValue).isEmpty())
  1260. newValue = null;
  1261. // 空值
  1262. if (oldValue == null && newValue == null)
  1263. continue;
  1264. /* 改为 int 了。Lin
  1265. if (Field.TYPE_HTML.equals(f.getType())) {
  1266. */ if (f.type == ObjC.FIELD_htmlType) {
  1267. if (EditorU.cmpEditorFile((String) oldValue, (String) newValue)) // ViewObjectUtil.compareUeditorFile()。Lin
  1268. continue;
  1269. /* 改为 int 了。Lin
  1270. } else if (Field.TYPE_CMS.equals(f.getType())) {
  1271. */ } else if (f.type == ObjC.FIELD_cmsType) {
  1272. if (newValue == null ||
  1273. /* 再改,IDEA:'CmsU.rdChgList(newValue.toString(), null).size() == 0' can be replaced with
  1274. * 'CmsU.rdChgList(newValue.toString(), null).isEmpty()'。Lin
  1275. CmsU.rdChgList(newValue.toString(), null).size() == 0) // NrService.getNrChangeList()。Lin
  1276. */ CmsU.rdChgList(newValue.toString(), null).isEmpty()) // NrService.getNrChangeList()。Lin
  1277. continue;
  1278. }
  1279. /* 改为 int 了。Lin
  1280. if (Field.TYPE_CMS.equals(f.getType()) == false) {
  1281. */ if (f.type != ObjC.FIELD_cmsType) {
  1282. if (oldValue != null && oldValue.equals(newValue)) {
  1283. continue;
  1284. } else if (newValue != null && newValue.equals(oldValue)) {
  1285. continue;
  1286. }
  1287. }
  1288. /* 去掉,去掉 type(int),只用到 type = 1。Lin
  1289. if (type == 1) {
  1290. */
  1291. String oValue = (oldValue == null)? null : oldValue.toString();
  1292. String nValue = (newValue == null)? null : newValue.toString();
  1293. result.put(f.name, Arrays.asList(oValue, nValue));
  1294. /* 去掉,去掉 type(int),只用到 type = 1。Lin
  1295. } else if (type == 2) {
  1296. result.put(f.name, newValue);
  1297. }
  1298. */
  1299. }
  1300. /* 改,纳入 BpmServ.saveChgField( 里的形成 wdObject(Map<String, List<String>>) 的程序。Lin
  1301. return result; // (Map) result。Lin
  1302. */
  1303. /// 来自 BpmServ.saveChgField( 里的形成 wdObject(Map<String, List<String>>) 的程序。Lin
  1304. Map<String, List<String>> wdObject = new HashMap<>();
  1305. /* 改。Lin
  1306. for (Map.Entry<String, List<String>> entry : compareResult.entrySet()) {
  1307. */ for (Entry<String, Object> entry : result.entrySet()) {
  1308. String fieldName = entry.getKey();
  1309. ObjFieldB f = vo.fieldMap.get(fieldName); // .getFieldsMap().。Lin
  1310. if (f == null)
  1311. continue;
  1312. /* 改为 Boolean 了。Lin
  1313. if ("true".equals(f.getEditable())) {
  1314. */ if (f.editable) {
  1315. /* 在这,Object 转回 List<String>。Lin
  1316. wdObject.put(fieldName, entry.getValue());
  1317. */
  1318. //noinspection unchecked
  1319. wdObject.put(fieldName, (List<String>) entry.getValue());
  1320. }
  1321. }
  1322. return wdObject; // 增加,改为新的返回值。Lin
  1323. ///
  1324. }
  1325. // 来自 HDDev_scgl:WJSqlcBuilder.(String)
  1326. // insql(String prefix, SqlCommandImpl sqlc, Stream<?> stream, String sqlPrefix)。Lin
  1327. // sqlPrefix 改为 inStr
  1328. // 顺序调整为 sqlc、inStr、stream、prefix
  1329. public static String makeInSql(SqlCmd sqlc, String inStr, Stream<?> stream, String prefix) {
  1330. AtomicInteger ai = new AtomicInteger();
  1331. return stream.map(o -> {
  1332. int paramIndex = ai.incrementAndGet();
  1333. String paramName = prefix + paramIndex;
  1334. sqlc.wrStrParm(paramName, o); // .setString(。Lin
  1335. return paramName;
  1336. }).map(":"::concat).collect(Collectors.joining(",", inStr +"(", ")"));
  1337. }
  1338. }