package ss.db; import java.io.File; import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.lang.reflect.Modifier; import java.sql.Date; import java.sql.Timestamp; import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.Objects; import java.util.Optional; import java.util.Set; import java.util.concurrent.atomic.AtomicInteger; import java.util.stream.Collectors; import java.util.stream.Stream; import jakarta.servlet.http.HttpServletRequest; import com.google.gson.Gson; import com.google.gson.reflect.TypeToken; import org.apache.commons.io.FileUtils; import org.apache.commons.lang3.StringUtils; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import ss.AppB; import ss.AppC; import ss.cb.CbU; import ss.cmn.lambda.LambdaFunction; import ss.cms.CmsU; import ss.editor.EditorU; import ss.log.SsLog; import ss.obj.ObjB; import ss.obj.ObjC; import ss.obj.ObjFieldB; import ss.obj.ObjU; import ss.user.UserRunB; public class DbU { // 增加,去掉 e.printStackTrace(),改用 log4j -- 按 IDEA 规范。Lin private static final Logger log4j = LogManager.getLogger(DbU.class); /* 去掉,直接写。Lin private final static int blob_radix = 16; */ /// ** // * blob数据转换成string /// * // 来自 GeneralDBAccess.blobBytesToString(byte[] bytes)。Lin /* 再去掉,没用到了 -- 数据库不支持 Blob 字段了 public static String toStrByBlob(byte[] bytes) { return new BigInteger(1, bytes).toString(16); // 16 = blob_radix } */ // 来自 GeneralDBAccess.blobStringToBytes(String blobstr)。Lin /* 再去掉,没用到了 -- 数据库不支持 Blob 字段了 public static byte[] toBlobByStr(String blobstr) { return new BigInteger(blobstr, 16).toByteArray(); // 16 = blob_radix } */ // 来自 SqlParam.obtainParamSqlType()。Lin // 增加 type 入口参数,原放在 SqlParam 里 -- 可以直接访问 SqlParmB.type // type 数据类型从 String 改为 int /* 去掉,parmTypeMap 直接对着 stmt.setXxx() 了。Lin public static int toSqlType(int type){ /// * 改为 switch,改为 int,改用常量。Lin // int sqlType = -1; // // if( "int".equals(type) ) // TYPE_INT.。Lin // sqlType = java.sql.Types.INTEGER; // else if( "float".equals(type) ) // TYPE_FLOAT.。Lin // sqlType = java.sql.Types.FLOAT; // else if( "char".equals(type) ) // TYPE_CHAR.。Lin // sqlType = java.sql.Types.CHAR; // else if( "time".equals(type) ) // TYPE_DATETIME.。Lin // sqlType = java.sql.Types.TIMESTAMP; // else if( "clob".equals(type) ) // TYPE_CLOB.。Lin // sqlType = java.sql.Types.CLOB; // else if( "blob".equals(type) ) // TYPE_BLOB.。Lin // sqlType = java.sql.Types.BLOB; // // return sqlType; /// * switch (type) { case DbC.PARM_intType: return java.sql.Types.INTEGER; case DbC.PARM_floatType: return java.sql.Types.FLOAT; case DbC.PARM_stringType: return java.sql.Types.CHAR; case DbC.PARM_timestampType: return java.sql.Types.TIMESTAMP; case DbC.PARM_clobType: return java.sql.Types.CLOB; case DbC.PARM_blobType: return java.sql.Types.BLOB; } return -1; } */ // === Po // 根据 Po,得到字段的 Type。Lin // 源自 ViewObjectUtil.readBeanType(BaseBean bean, Field f) // 入口参数 ObjFieldB 改为 fieldName,并移到前面 -- 统一 // 返回值 String 改为 int /* 再改为 (int) toFieldTypeByPoType(Integer poType)。Lin * 再增加,序列化 Po 信息到 "/pmsWs/<项目号>/_cache/po/<对象名>"(PoCacheB) * 加载 .obj.xml 时,之前读的是 PMS 自己的 Po,不是项目的 Po -- 原项目的 po.jar,无法读取 Po 的信息 public static int rdFieldTypeByPo(String fieldName, Po bean) { */ public static int toFieldTypeByPoType(Integer poType) { /* 再改为 (int) toFieldTypeByPoType(Integer poType)。Lin if (bean == null) return ObjC.FIELD_txtType; // "text"。Lin Integer type = bean.fieldTypeMap.get(fieldName); // String。(f.name)。Lin if (type == null) return ObjC.FIELD_txtType; // "text"。Lin */ if (poType == null) return ObjC.FIELD_txtType; // "text"。Lin /* Po 增加 int、Integer、long、double、float、Float。Lin * String 改为 int * 改为 switch if ("Timestamp".equals(type)) { return "time"; } else if ("Long".equals(type)) { return "number"; } else if ("Double".equals(type)) { return "number"; } */ /* 再改为 (int) toFieldTypeByPoType(Integer poType)。Lin * switch (type) { */ return switch (poType) { case DbC.PO_StringType, DbC.PO_txtType -> ObjC.FIELD_txtType; // "text"。Lin case DbC.PO_intType, DbC.PO_IntegerType, // "int"/"Integer"。Lin DbC.PO_longType, DbC.PO_LongType, // "long"/"Long"。Lin /* 再去掉 float/Float、double/Double,转换为整数 -- 需要时再增加 BigInteger。Lin case DbC.PO_floatType: // "float"。lin case DbC.PO_FloatType: // "Float"。lin case DbC.PO_doubleType: // "double"。Lin case DbC.PO_DoubleType: // "Double"。Lin */ /// 再保留浮点,存在无需运算 或 无需精确运算的情况 -- 如,REM。Lin DbC.PO_floatType, DbC.PO_FloatType, // "float"/"Float"。Lin DbC.PO_doubleType, DbC.PO_DoubleType -> // "double"/"Double"。Lin /// ObjC.FIELD_numType; // "number"。Lin /// 再增加 DbC.PO_booleanType/DbC.PO_BooleanType。Lin case DbC.PO_booleanType, DbC.PO_BooleanType -> ObjC.FIELD_boolType; /// /// 再增加,保留 ObjC.FIELD_dateType -- 与 Po 一样,保留 DbC.PO_DateType。Lin case DbC.PO_DateType -> ObjC.FIELD_dateType; /// case DbC.PO_TimestampType -> // "Timestamp"。Lin ObjC.FIELD_timeType; // "time"。Lin default -> { SsLog.log("DbU.toFieldTypeByPoType(,DbC.Po_xxxType 少了判断:" + poType); yield ObjC.FIELD_txtType; // "text"。Lin } }; } // 来自:。Lin // BeanUtils.(Map) beansToMap(BaseBean bean) // ZGZ:ReSearchService.(Map) beansToMap(BaseBean bean) // DesignOutSide.(Map) beansToMap(BaseBean... bean) // GzwjRemoteService.(Map) beansToMap(BaseBean bean) // BeanUtils.beansToMap( 有过滤 null 值的字段 // ZGZ:ReSearchService.beansToMap( 没有过滤 null 值的字段 // DesignOutSide.beansToMap( 支持多个 bean,且把 "csc" 字段里的键值对也拆开写入 Map -- "csc" 本身不写入 // 有过滤 null 值的字段,csc 里的 null 也过滤 // GzwjRemoteService.beansToMap( 有过滤 null 值的字段 // 增加 filterNull -- 区分 BeanUtils.beansToMap() // contCsc 为 true 时,没意义 // 增加 contCsc -- 区分 DesignOutSide.beansToMap() /* 再去掉 contCsc,不把 DesignOutSide.beansToMap() 纳入 -- 需要支持多个 bean。Lin public static Map toMapByPo(Po bean, boolean filterNull, boolean contCsc) { */ public static Map toMapByPo(Po bean, boolean filterNull) throws InvocationTargetException, NoSuchMethodException, IllegalAccessException { Map jmap = new HashMap<>(); /* 再去掉 contCsc,不把 DesignOutSide.beansToMap() 纳入 -- 需要支持多个 bean。Lin Map m; // 增加。Lin */ /* 去掉 bean.getFieldMap(),直接用 Po.fieldTypeMap。Lin * Map 改为 Map for(Map.Entry entry : (Set>)bean.getFieldMap().entrySet()){ String fieldName = entry.getKey(); */ for (String fieldName : bean.fieldTypeMap.keySet()) { Object v = rdFieldValByPo(fieldName, bean); // BeanUtils.getFieldValue()。Lin /* 再去掉 contCsc,不把 DesignOutSide.beansToMap() 纳入 -- 需要支持多个 bean。Lin if (contCsc && fieldName.equals(DbC.PO_cscName)) { // "csc"。Lin /// 来自 DesignOutSide.(Map) beansToMap(BaseBean... bean)。Lin if (v == null) continue; /// * 去掉 DesignOutSide.parseJsonToMap(,用 StrJson.toObjectMap(。Lin // * 在这加 {} // Map m = parseJsonToMap(v.toString()); /// * /// * 再,不加左、右的 "{"、"}" -- 在数据库的 参数串 字段里加。Lin // m = StrJson.toObjectMap("{"+ v.toString() +"}"); /// * m = StrJson.toObjectMap(v.toString()); if (m != null) { jmap.putAll(m); } /// //filter null } else if (!filterNull || v != null) { // 不过滤 null 值的字段。Lin */ if (!filterNull || v != null) { // 不过滤 null 值的字段。Lin jmap.put(fieldName, v); } } return jmap; } // 来自 DesignOutSide.(Map) beansToMap(BaseBean... bean)。Lin // cont = 包含 public static Map toMapByPoContCsc(Po... bean) throws InvocationTargetException, NoSuchMethodException, IllegalAccessException { Map jmap = new HashMap<>(); /* 参数串字段 和 非参数串字段,合并在同一套 for 循环里。Lin for (int i = 0; i < bean.length; i++) { for (Map.Entry entry : (Set>) bean[i] .getFieldMap().entrySet()) { String fieldName = entry.getKey(); if ("csc".equals(fieldName)) continue; Object v = BeanUtils.getFieldValue(fieldName, bean[i]); if (v == null) continue; jmap.put(fieldName, v.toString()); } } for (int i = 0; i < bean.length; i++) { for (Map.Entry entry : (Set>) bean[i] .getFieldMap().entrySet()) { try { String fieldName = entry.getKey(); if (!"csc".equals(fieldName)) continue; Object v = BeanUtils.getFieldValue(fieldName, bean[i]); if (v == null) continue; Map m = parseJsonToMap(v.toString()); if (m != null) { m.putAll(jmap); jmap = m; } } catch (Exception e) { e.printStackTrace(); } } } */ Gson gson = new Gson(); // 增加,不重复 new。Lin Object v; // 增加,不重复定义。Lin Map m; // 增加,不重复定义。Lin /* 再改,IDEA:'for' loop can be replaced with enhanced 'for'。Lin for (int i = 0; i < bean.length; i++) { /// * 去掉 bean.getFieldMap(),直接用 Po.fieldTypeMap。Lin // * Map 改为 Map // * 去掉 try {} // for (Map.Entry entry : (Set>) bean[i].getFieldMap().entrySet()) { // try { // String fieldName = entry.getKey(); /// * for (String fieldName : bean[i].fieldTypeMap.keySet()) { v = rdFieldValByPo(fieldName, bean[i]); // BeanUtils.getFieldValue()。Lin */ for (Po po : bean) { for (String fieldName : po.fieldTypeMap.keySet()) { v = rdFieldValByPo(fieldName, po); // BeanUtils.getFieldValue()。Lin if (DbC.FIELD_poCscName.equals(fieldName)) { // ("csc".。Lin if (v == null) continue; m = gson.fromJson(String.valueOf(v), new TypeToken>() {}.getType()); if (m != null) jmap.putAll(m); } else { if (v == null) continue; jmap.put(fieldName, String.valueOf(v)); } } } return jmap; } // 来自 ViewObjectUtil.getFieldValue(BaseBean bean, ViewObject viewobject, Field field)。Lin // 去掉 viewobject,没用到 // field 改为 field.name,并移到第一个位置 public static Object rdFieldValByPo(String name, Po bean) throws InvocationTargetException, NoSuchMethodException, IllegalAccessException { /* 用 StringUtils.capitalize()。Lin String methodName = "get" + name.replaceFirst(name.substring(0, 1), name.substring(0, 1).toUpperCase()); */ String methodName = "get"+ StringUtils.capitalize(name); Method method; try { method = bean.getClass().getMethod(methodName); /* 再改,IDEA:Redundant array creation for calling varargs method。Lin return method.invoke(bean, new Object[0]); */ return method.invoke(bean); } catch (Exception e) { /* 改,去掉 e.printStackTrace(),改用 log4j -- 按 IDEA 规范。Lin e.printStackTrace(); */ log4j.error("DbU.rdFieldValByPo( 异常", e); /* 再改,改为抛出错误。Lin return null; */ throw e; } } // 来自 tt.bpm.common.BpmUtil.(String) getFieldValue(Object bean, ViewObject viewobject, Field f)。Lin // bean(Object) 改为 Po,专门用于 Po -- 用到 Object 再弄 // 去掉 viewobject,没用到 -- 只是用于显示错误信息 // f(ObjFieldB) 移到最前面 -- 统一 public static String rdFieldValByCbByPo(ObjFieldB f, Po bean) throws Exception { String name = f.name; String codebook = f.cbName; // .getCodebook()。Lin /* 用 StringUtils.capitalize()。Lin String methodName = "get" + name.replaceFirst(name.substring(0, 1), name.substring(0, 1).toUpperCase()); */ String methodName = "get"+ StringUtils.capitalize(name); Method method; try { method = bean.getClass().getMethod(methodName); /* 再改,IDEA:Redundant array creation for calling varargs method。Lin Object o = method.invoke(bean, new Object[0]); */ Object o = method.invoke(bean); String result = ((o == null)? null : o.toString()); // 翻译codebook if (StringUtils.isNotBlank(codebook)) { // StringUtil.notNull()。Lin /* 去掉应用名前缀,不支持多个应用。Lin String[] a = codebook.split("\\."); if (a.length != 2) { throw new Exception("codebook解析失败 >>object:" + viewobject.getName() + ",field:" + f.getName() + ",codebook:" + codebook); } String codebookName = a[1]; String appName = a[0]; */ /* 再去掉,直接用 codebook -- IDEA:Local variable 'codebookName' is redundant。Lin String codebookName = codebook; */ // "获得codebook的数据" /* 再改,码本翻译只取那条记录。Lin /// * 去掉 appName。Lin // Map> codebookData = CodebookUtil.getDataByCodebookName(codebookName, appName, null, null);// 获得codebook的数据 /// * /// * 再去掉,直接用 codebook -- IDEA:Local variable 'codebookName' is redundant。Lin // Map> codebookData = CbU.rdOpt(codebookName, null, null); // // null = filter,null = request。Lin /// * Map> codebookData = CbU.rdOpt(codebook, null, null); Map oneRowMap = codebookData.get(result); Entry en = DsU.rdMapByIdx(oneRowMap, 1); // CommonUtils.getMapValueByIndex()。Lin result = ((en == null)? "" : en.getValue().toString()); */ /* 再改,去掉 fieldName(String) -- 改返回结果为 Map>。Lin result = CbU.transCb(result, codebook, null); */ result = CbU.transCb(result, codebook); } return result; } catch (Exception e) { /* 改,去掉 e.printStackTrace(),改用 log4j -- 按 IDEA 规范。Lin e.printStackTrace(); */ log4j.error("DbU.rdFieldValByCbByPo( 异常", e); throw e; } // return null; } /** * 设置字段值 * * @param propertyName * 字段名 * @param obj * 实例对象 * @param value * 新的字段值 */ // 来自 tt.util.BeanUtils.setFieldValue(Object obj, String propertyName, Object value)。Lin // Object 改为 Po,专门用于 Po // obj(Po) 移到最后面 -- 统一 public static void wrPoField(String propertyName, Object value, Po obj) { try { Class clazz = obj.getClass(); Field field = clazz.getDeclaredField(propertyName); field.setAccessible(true); if (value == null || StringUtils.isBlank(value.toString())) { // StringUtil.isNull()。Lin field.set(obj, null); } else { String className = field.getType().getName(); /* 改为 switch。Lin if ("java.lang.Integer".equals(className) || "int".equals(className)) { field.set(obj, Integer.valueOf(value.toString())); } else if ("java.lang.Long".equals(className) || "long".equals(className)) { field.set(obj, Long.valueOf(value.toString())); } else if ("java.lang.Byte".equals(className) || "byte".equals(className)) { field.set(obj, Byte.valueOf(value.toString())); } else if ("java.lang.Short".equals(className) || "short".equals(className)) { field.set(obj, Short.valueOf(value.toString())); } else if ("java.lang.Float".equals(className) || "float".equals(className)) { field.set(obj, Float.valueOf(value.toString())); } else if ("java.lang.Double".equals(className) || "double".equals(className)) { field.set(obj, Double.valueOf(value.toString())); } else if ("java.lang.Boolean".equals(className) || "boolean".equals(className)) { field.set(obj, Boolean.valueOf(value.toString())); } else if ("java.lang.Character".equals(className) || "char".equals(className)) { field.set(obj, Character.valueOf(value.toString().charAt(0))); } else if ("java.sql.Timestamp".equals(className)) { field.set(obj, new Timestamp(CommonUtils.getDateFromStr(value.toString()) .getTime())); } else { field.set(obj, value); } */ switch (className) { case "java.lang.String": field.set(obj, value); return; /* 再重构 Po -- 非空字段使用 基本数据类型。Lin * 去掉 short/Short、char/Character、byte/Byte -- 不支持 case "int": case "java.lang.Integer": field.set(obj, Integer.valueOf(value.toString())); return; case "long": case "java.lang.Long": field.set(obj, Long.valueOf(value.toString())); return; case "float": case "java.lang.Float": field.set(obj, Float.valueOf(value.toString())); return; case "double": case "java.lang.Double": field.set(obj, Double.valueOf(value.toString())); case "short": case "java.lang.Short": field.set(obj, Short.valueOf(value.toString())); return; case "char": case "java.lang.Character": //noinspection UnnecessaryBoxing field.set(obj, Character.valueOf(value.toString().charAt(0))); return; case "byte": case "java.lang.Byte": field.set(obj, Byte.valueOf(value.toString())); return; case "boolean": case "java.lang.Boolean": field.set(obj, Boolean.valueOf(value.toString())); return; */ case "int": field.set(obj, Integer.parseInt(value.toString())); return; case "java.lang.Integer": field.set(obj, Integer.valueOf(value.toString())); return; case "long": field.set(obj, Long.parseLong(value.toString())); return; case "java.lang.Long": field.set(obj, Long.valueOf(value.toString())); return; case "float": field.set(obj, Float.parseFloat(value.toString())); return; case "java.lang.Float": field.set(obj, Float.valueOf(value.toString())); return; case "double": field.set(obj, Double.parseDouble(value.toString())); return; case "java.lang.Double": field.set(obj, Double.valueOf(value.toString())); return; case "boolean": field.set(obj, Boolean.parseBoolean(value.toString())); return; case "java.lang.Boolean": field.set(obj, Boolean.valueOf(value.toString())); return; /// 增加 java.sql.Date。Lin case "java.sql.Date": /* 再去掉 StrDate.toDate(,只用 java.sql.Date。Lin field.set(obj, StrDate.toDate(value.toString())); */ field.set(obj, Date.valueOf(value.toString())); return; /// case "java.sql.Timestamp": /* 再去掉 StrDate.toDate(,只用 java.sql.Date。Lin field.set(obj, new Timestamp(StrDate.toDate(value.toString()).getTime())); */ field.set(obj, Timestamp.valueOf(value.toString())); return; default: field.set(obj, value); // return; // 再去掉,IDEA:'return' is unnecessary as the last statement in a 'void' method。Lin } } } catch (Exception e) { throw new RuntimeException(e); } } /** * 增加创建人员, 管理人员,管理部门 * * @param bb; * @param yh; * @param ispersonal; * @throws Exception; */ // 来自 DbService.updateManangeId(BaseBean bb, WdYh yh, boolean ispersonal, GeneralDBAccess gdba)。Lin // 再从 DbServ.wrSsField( 移到这,并改名为 wrSsFieldByPo( // 再增加 fieldNameSet(Set) 入口/出口参数,去掉 gdba(Db) // 去掉方法里的 gdba.doUpdPo(,归入上层的 gdba.doInsPo(、gdba.doUpdPo( 去做 // 把调用 DbU.wrSsFieldByPo( 前移到上层的 .doInsPo(、.doUpdPo( 前面 public static void wrSsFieldByPo(Po bb, Set fieldNameSet, UserRunB yh, boolean ispersonal) throws Exception { if (yh == null) return; /* 再去掉 updatePropertyNames,改为 入口/出口参数 fieldNameSet。Lin Set updatePropertyNames = new HashSet<>(); */ Long bmid = yh.bmid; // .getBmid()。Lin Long ryid = yh.ryid; // .getRyid()。Lin // 创建人员ID /* 改。Lin if (bb.getFieldMappingItem("cjryid") != null) { */ if (bb.fieldTypeMap.get("cjryid") != null) { Method targetMethod = bb.getClass().getDeclaredMethod("setCjryid", Long.class); targetMethod.setAccessible(true); targetMethod.invoke(bb, ryid); /* 再去掉 updatePropertyNames,改为 入口/出口参数 fieldNameSet。Lin updatePropertyNames.add("cjryid"); */ fieldNameSet.add("cjryid"); } // 管理人员 /* 改。Lin if (bb.getFieldMappingItem("glryid") != null && ispersonal) { */ if (bb.fieldTypeMap.get("glryid") != null && ispersonal) { Method targetMethod = bb.getClass().getDeclaredMethod("setGlryid", Long.class); targetMethod.setAccessible(true); targetMethod.invoke(bb, ryid); /* 再去掉 updatePropertyNames,改为 入口/出口参数 fieldNameSet。Lin updatePropertyNames.add("glryid"); */ fieldNameSet.add("glryid"); } // 管理部门 /* 改。Lin if (bb.getFieldMappingItem("glbmid") != null && ispersonal == false) { */ if (bb.fieldTypeMap.get("glbmid") != null && !ispersonal) { Method targetMethod = bb.getClass().getDeclaredMethod("setGlbmid", Long.class); targetMethod.setAccessible(true); targetMethod.invoke(bb, bmid); /* 再去掉 updatePropertyNames,改为 入口/出口参数 fieldNameSet。Lin updatePropertyNames.add("glbmid"); */ fieldNameSet.add("glbmid"); } /* 再去掉 gdba.doUpdPo(,归入上层的 gdba.doInsPo(、gdba.doUpdPo( 去做。Lin * 把调用 DbU.wrSsFieldByPo( 前移到上层的 .doInsPo(、.doUpdPo( 前面 * 返回 fieldNameSet /// * 再改,IDEA:'updatePropertyNames.size() > 0' can be replaced with '!updatePropertyNames.isEmpty()'。Lin // if (updatePropertyNames.size() > 0) /// * if (!(updatePropertyNames.isEmpty())) gdba.doUpdPo(bb, updatePropertyNames); // .updateById()。Lin */ } // 来自 pms-core:Reflects.( boolean) copyProperties(T from, T to, // boolean copyAllIfNoName, String... names)。Lin // 去掉 copyAllIfNoName(boolean),共用 names(String[]) -- names 为 null 时,为所有字段 public static void copyPoFieldArr(T from, T to, String... names) { Objects.requireNonNull(from); Objects.requireNonNull(to); Class clazz = from.getClass(); /* 再去掉 并行 -- 有时不能 copy 完整 -- 时行时不行 -- 少了 .forEach(。Lin * 还是不用 .parallel() -- 并行线程的开销大,数组内容少时,性能不高 return Optional.ofNullable(names) .filter(LambdaFunction.notEmptyArray()) // (wd.core.util.lambda.Functions.。Lin .map(Stream::of) .orElseGet(() -> { String[] arr; /// * 改,去掉 copyAllIfNoName,共用 names -- names 为 null 时,为所有字段。Lin // if (copyAllIfNoName) { // arr = getAllFieldName(clazz, true); // } else { // arr = EMPTY_ARRAY; // } /// * arr = rdPoFieldName(clazz, true); return Stream.of(arr);}) .parallel() /// * 去掉 Fields,直接写。Lin // .map(cn -> Fields.create(clazz, cn)) /// * .map(cn -> rdPoField(clazz, cn)) .filter(LambdaFunction.notNull()) // (wd.core.util.lambda.Functions.。Lin /// * 去掉 Reflects 和 Fields,直接写成 copyOnePoField()。Lin // .filter(field -> field.copyValue(from, to)) // .count() > 0; /// * /// * 再改,IDEA:Can be replaced with 'stream.anyMatch()'。Lin // .filter(field -> copyOnePoField(field, from, to)) // .count() > 0; /// * .anyMatch(field -> copyPoField(field, from, to)); */ String[] t = Optional.ofNullable(names) .filter(LambdaFunction.notEmptyArray()) .orElseGet(() -> { String[] arr; arr = rdPoFieldName(clazz, true); return arr;}); Arrays.stream(t) .forEach(cn -> { Field f = rdPoField(clazz, cn); if (f != null) copyPoField(f, from, to); }); } // 参考自 pms-core:Reflects.(Object) getFieldValue(Field field, Object object) 和 // pms-core:Reflects.(boolean) setFieldValue(Field field, Object object, Object value)。Lin // 合并为 copy 功能 public static boolean copyPoField(Field field, Object from, Object to) { Object value; /// 改自 Reflects.getFieldValue()。Lin boolean access = field.canAccess(from); // .isAccessible()。已过时,改用 .canAccess(from)。Lin field.setAccessible(true); try { value = field.get(from); } catch (IllegalArgumentException | IllegalAccessException e) { /* 改,去掉 e.printStackTrace(),改用 log4j -- 按 IDEA 规范。Lin e.printStackTrace(); */ log4j.error("DbU.copyOnePoField() 异常", e); return false; } finally { field.setAccessible(access); } /// /// 改自 Reflects.setFieldValue()。Lin access = field.canAccess(to); // .isAccessible()。已过时,改用 .canAccess(to)。Lin field.setAccessible(true); try { field.set(to, value); return true; } catch (IllegalArgumentException | IllegalAccessException e) { /* 改。Lin printStackTrace(e); if (!debug) { System.out .println("Failed to set the field value. If you want to know what happened, set reflect.debug =true.Field:" + field); } */ /* 改,去掉 e.printStackTrace(),改用 log4j -- 按 IDEA 规范。Lin e.printStackTrace(); */ log4j.error("DbU.copyOnePoField() 异常", e); return false; } finally { field.setAccessible(access); } /// } // 来自 pms-core:Reflects.(String[]) getAllFieldName(Class clazz, boolean notFinal)。Lin /* 再改,IDEA:Wildcard type argument '?' explicitly extends 'java.lang.Object'。Lin public static String[] rdPoFieldName(Class clazz, boolean notFinal) { */ public static String[] rdPoFieldName(Class clazz, boolean notFinal) { return Stream.of(clazz.getDeclaredFields()).parallel() .filter(f -> !(notFinal && Modifier.isFinal(f.getModifiers()))) .map(Field::getName).distinct().toArray(String[]::new); } // 来自 pms-core:Reflects.(Field) getField(Class clazz, String fieldName)。Lin public static Field rdPoField(Class clazz, String fieldName) { try { return clazz.getDeclaredField(fieldName); } catch (NoSuchFieldException | SecurityException e) { /* 改,去掉 e.printStackTrace(),改用 log4j -- 按 IDEA 规范。Lin e.printStackTrace(); // printStackTrace(e)。Lin */ log4j.error("DbU.rdPoField() 异常", e); return null; } } // 来自 GeneralDBAccess.getGetMethodName(String fieldName)。Lin // 根据传入的fieldName返回getXX方法名 /* 去掉,直接用 "get"+ StringUtils.capitalize(fieldName)。Lin public static String cmptGetField(String fieldName) { return "get" + fieldName.substring(0, 1).toUpperCase() + fieldName.substring(1, fieldName.length()); } */ // 把对像o在request中有传值的参数名,返回为一个集合 // 来自 GeneralDBAccess.(Set) propertyInRequest(Object o, HttpServletRequest request)。Lin // Object 改为 Po,专门给 Po 用 // 不用 ClazzU.rdAtrArrByClazz(c),改为 c.getDeclaredFields() -- XxxPo 不能继承 XxxPo /* 再去掉,用 DbU.loadPoFieldByReq( 返回的 fieldNameSet(Set)。Lin * DbU.rdPoFieldNameByReq( 并入 DbU.loadPoFieldByReq( public static Set rdPoFieldNameByReq(Po o, HttpServletRequest request) { Set properties = new HashSet<>(); Set paramNames = request.getParameterMap().keySet(); Class c = o.getClass(); /// * 再把 ClazzU.rdAtrArrByClazz(c) 改为 c.getDeclaredFields()。Lin // Field[] fields = ClazzU.rdAtrArrByClazz(c); // 获得本类和父类的所有属性 // WebUtil.getAllFieldsFromClass()。Lin /// * Field[] fields = c.getDeclaredFields(); // 获得本类的所有属性 for (Field field : fields) { String propertyName = field.getName(); if (paramNames.contains(propertyName)) { properties.add(propertyName); } } return properties; } */ // 来自 WDCore_pms_product:(List) getParamNameFromRequest(HttpServletRequest request, ViewObject vo)。Lin // vo 移到前面 -- 统一 /* 再去掉,并入 DbU.loadPoFieldByReq( -- DbU.rdPoFieldByReq( 改为 loadPoFieldByReq(,增加返回 fieldNameSet(Set)。Lin public static List rdObjFieldNameByReq(ObjB vo, HttpServletRequest request) { List paramNameList = new ArrayList<>(); Map map = request.getParameterMap(); for (ObjFieldB f : vo.fieldMap.values()) { // .getFields()。Lin String fieldName = f.name; if (map.containsKey(fieldName)) { paramNameList.add(fieldName); } } return paramNameList; } */ // === // private static final Class[] STR_CLS = {String.class}; // 字符串类数组 // 再去掉,没用到。Lin /** * 从request中获取参数,放到相应bean的属性内。名称与bean内属性名不一致的request参数将被忽略 前提:request中必须有一个参数 * obj=...,用来指定对像的类名。对象类必须提供无参数的默认构造函数。 * * @param request http请求的request * @param objClass 对象类的绝对路径 * isAsString 是否将所有数据全部作为String类型看待,而不区分。 true: * 全部作为String,对应的对象类的所有对应属性也是String类型;
* false: * 区分整数(Long)、小数(Double)、日期(Timestamp)和字符串(String)类型,自动匹配。
* 如果前三个类型匹配不到,则自动作为String处理,如果都匹配不到,则放弃本参数。 * @return Object 新创建的bean,保存了request里面的所有相应(与bean属性具有相同名字的)的param。 * @throws Exception; */ // 来自 WebUtil.(Object) paramsFromRequest(HttpServletRequest request, String objClassName, boolean isAsString)。Lin // objClassName 移到前面 // 专门给 Po 用 // 返回值改为 Po // 只获取本类的所有属性 -- XxxPo 不能继承 // 再,objClassName 改为 clazz(Class)。Lin // 再,clazz 改为 objClass -- IDEA:Local variable 'objClass' is redundant。Lin // 再考虑把 objClass.getDeclaredFields() 循环改为 Po.fieldTypeMap.keySet() 循环 // 不能改,Set 方法的入口参数类型与 Po.fieldTypeMap 里的有差异 /* 再去掉 isAsString(boolean),都是 false。Lin public static Po rdPoByReqField(Class objClass, HttpServletRequest request, boolean isAsString) throws Exception { */ /* 再改为 Load,增加返回 fieldNameSet(Set) -- null = 不返回。Lin * 原返回值的 Po,改为入口/出口参数 obj(Po) public static Po rdPoFieldByReq(Class objClass, HttpServletRequest request) throws Exception { */ public static boolean loadPoFieldByReq(Po obj, Set fieldNameSet, Class objClass, HttpServletRequest request) throws Exception { // 取得类名 // String className = objPkgName + "." + request.getParameter( REQ_OBJ // ); /* 再,objClassName 改为 po(Po)。Lin * objClassName 改为 clazz(Class) Class objClass = Class.forName(objClassName); */ /* 再去掉,IDEA:Local variable 'objClass' is redundant。Lin * 入口参数 clazz 改为 objClass Class objClass = clazz; */ // Field[] fields = objClass.getFields();//获得本类和父类的所有属性 // Field[] fields = objClass.getDeclaredFields();//获得本类和父类的所有属性 /* 再把 ClazzU.rdAtrArrByClazz(objClass) 改为 objClass.getDeclaredFields()。Lin Field[] fields = ClazzU.rdAtrArrByClazz(objClass);// 获得本类和父类的所有属性 // WebUtil.getAllFieldsFromClass()。Lin */ Field[] fields = objClass.getDeclaredFields();// 获得本类的所有属性 // 创建类实例 /// 再,objClassName 改为 po(Po)。Lin // 还需要 new,不能共用 ObjB.po /* 再去掉,改为 Load 了 -- 增加返回 fieldNameSet(Set)。Lin * obj(Po),同时也是返回值 Po obj = objClass.getDeclaredConstructor().newInstance(); // Object。Lin */ /// Class[] methodParams = new Class[1]; Object[] realParams = new Object[1]; Method method; // 从request传来的参数必定非null,除非request中不存在指定名称的参数。 // 因此根据request中存在的参数名枚举来获取的参数,必定在request中存在, // 从而参数值只可能是空串("",在没有输入的时候),或者具体的值。 String fieldName; String typeName; String[] paramValueArr; /* 再改,IDEA:'for' loop can be replaced with enhanced 'for'。Lin for (int i = 0; i < fields.length; i++) { String fieldName = fields[i].getName(); */ for (Field field : fields) { fieldName = field.getName(); typeName = field.getType().getName(); paramValueArr = request.getParameterValues(fieldName); // 如果参数列表中无与对象名称一致的参数,则忽略 /* 再重构 Po -- 非空字段使用 基本数据类型。Lin * 值为 "" 时,也不处理 -- 使用 Po 里的默认值 -- Request 返回 "",paramValueArr.length = 1 if (paramValueArr == null || paramValueArr.length == 0) */ /* 再改,对 String 字段,值为 "" 不能去掉。Lin * 变动时,删除 地址 的值 -- Request 返回 "",paramValueArr.length = 1 * 对其他字段,如 int,需要去掉 -- 使用 Po 里的默认值 * 需要改为默认值时,需要录入默认值 if (paramValueArr == null || paramValueArr.length == 0 || Arrays.stream(paramValueArr).allMatch(StringUtils::isBlank)) */ /* 再改,对下拉列表,值为 "" 不能去掉。Lin * 变动时,删除下拉列表的值 -- Request 返回 "",paramValueArr.length = 1 * 下面的 ObjU.toValByType( 会把 "" 转为 null -- 字符串的 "",也会转为 null if (paramValueArr == null || paramValueArr.length == 0 || (!"java.lang.String".equals(typeName) && Arrays.stream(paramValueArr).allMatch(StringUtils::isBlank))) */ if (paramValueArr == null || paramValueArr.length == 0) continue; // 排除重复的参数值 /* 再去掉 paramValues(Set),直接用 paramValueArr(String[])。Lin Set paramValues = new HashSet<>(); /// * 再改,IDEA:Manual array to collection copy 。Lin // for (String s : paramValueArr) { // paramValues.add(s); // } /// * Collections.addAll(paramValues, paramValueArr); */ /* 再改,IDEA:String concatenation '+=' in loop。Lin * 改为 new StringBuilder(),不出现空指针 String paramFinalValue = null;// 保存到数据库的参数终值 */ /* 再改回 String,多个值里再用 StringBuilder。Lin StringBuilder paramFinalValue = new StringBuilder();// 保存到数据库的参数终值 */ String paramFinalValue;// 保存到数据库的参数终值 /* 再去掉 paramValues(Set),直接用 paramValueArr(String[])。Lin if (paramValues.size() == 1) {// 如果只有一个参数值 /// * 再改,IDEA:String concatenation '+=' in loop。Lin // paramFinalValue = paramValues.iterator().next(); /// * paramFinalValue = new StringBuilder(paramValues.iterator().next()); */ if (paramValueArr.length == 1) {// 如果只有一个参数值 paramFinalValue = paramValueArr[0]; } else {// 如果有多个参数值 StringBuilder paramValue = new StringBuilder(); // 增加,多个值里再用 StringBuilder。Lin /* 再改,多个参数的值一致时,当成一个值。Lin boolean fst = true; */ String last = null; // 上一个参数值。Lin // 把多个值拼成用 "|" 分隔的串 /* 再去掉 paramValues(Set),直接用 paramValueArr(String[])。Lin for (String s : paramValues) { */ for (String s : paramValueArr) { if (StringUtils.isBlank(s)) // 去掉 StrU.isNull(),直接用 StringUtils.isBlank()。Lin continue; /* 再改,多个参数的值一致时,当成一个值。Lin if (fst) fst = false; */ if (last == null) { last = s; /* 再去掉,IDEA:String concatenation '+=' in loop。Lin * new StringBuilder() 移到上面了 paramFinalValue = ""; */ } else { /// 再增加,多个参数的值一致时,当成一个值。Lin if (s.equals(last)) continue; /// /* 再改,IDEA:String concatenation '+=' in loop。Lin paramFinalValue += WebC.SEP_parm; // CoreConstVars.WD_DB_DATA_SEPARATOR。Lin */ /* 再改,多个值里再用 StringBuilder。Lin * 改 "|"(DbC.SEP_parm) 为 ","(AppC.SEP_abbrJson) 了 -- 简写 Json 时的分隔符 paramFinalValue.append(DbC.SEP_parm); // CoreConstVars.WD_DB_DATA_SEPARATOR。Lin */ paramValue.append(AppC.SEP_abbrJson); // CoreConstVars.WD_DB_DATA_SEPARATOR。Lin } /* 再改,IDEA:String concatenation '+=' in loop。Lin paramFinalValue += s; */ /* 再改,多个值里再用 StringBuilder。Lin paramFinalValue.append(s); */ paramValue.append(s); } paramFinalValue = paramValue.toString(); // 增加,多个值里再用 StringBuilder。Lin } /* 再去掉 isAsString(boolean),都是 false。Lin if (isAsString) { methodParams = STR_CLS; /// * 再改,IDEA:'for' loop can be replaced with enhanced 'for'。Lin // realParams[0] = request.getParameter(fields[i].getName()); /// * realParams[0] = request.getParameter(field.getName()); } else { */ // 对于具体类型的值,如果是空串,则可认为是NULL(字符串则为"") // 如果是具体的值,则按可转化类型 /* 再改,IDEA:'for' loop can be replaced with enhanced 'for'。Lin typeName = fields[i].getType().getName(); */ /* 再去掉,上移,上面也要用到了。Lin typeName = field.getType().getName(); */ /* 再改,IDEA:String concatenation '+=' in loop。Lin realParams[0] = ObjU.toValByType(paramFinalValue, typeName); // checkParamType()。Lin */ /* 再改,paramFinalValue 从 StringBuilder 改回 String。Lin realParams[0] = ObjU.toValByType(paramFinalValue.toString(), typeName); // checkParamType()。Lin */ realParams[0] = ObjU.toValByType(paramFinalValue, typeName); // checkParamType()。Lin /* 再改,IDEA:'for' loop can be replaced with enhanced 'for'。Lin methodParams[0] = fields[i].getType(); */ methodParams[0] = field.getType(); /* 再去掉 isAsString(boolean),都是 false。Lin } */ try { /* 再改,IDEA:'for' loop can be replaced with enhanced 'for'。Lin method = objClass .getMethod("set" + fields[i].getName().replaceFirst(fields[i].getName().substring(0, 1), fields[i].getName().substring(0, 1).toUpperCase()), methodParams); */ /* 再改用 StringUtils.capitalize(。Lin method = objClass .getMethod("set" + field.getName().replaceFirst(field.getName().substring(0, 1), field.getName().substring(0, 1).toUpperCase()), methodParams); */ method = objClass.getMethod("set"+ StringUtils.capitalize(field.getName()), methodParams); method.invoke(obj, realParams); } catch (NoSuchMethodException e) { /* 再去掉,IDEA:'continue' is unnecessary as the last statement in a loop。Lin * > 增加 log4j -- IDEA:Empty 'catch' block continue; */ log4j.error("DbU.rdPoByReqField( 异常", e); } if (fieldNameSet != null) fieldNameSet.add(fieldName); // 增加,增加返回 fieldNameSet(Set)。Lin } /* 再改,改为 Load 了 -- 增加返回 fieldNameSet(Set)。Lin return obj; */ return true; } // === // 来自 ViewObjectUtil.findWholeBeanMap(ViewObject vo, HttpServletRequest request)。Lin public static Map rdPoMapByReq(ObjB vo, HttpServletRequest request) throws InvocationTargetException, NoSuchMethodException, IllegalAccessException { Map result = new HashMap<>(); Po bean = rdPoByReq(vo, request); // ViewObjectUtil.findBeanFromRequest() if (bean != null) result = DbU.toMapByPo(bean, true); // tt.util.BeanUtils.beansToMap( -- 有过滤 null 值的字段。Lin // true = filterNull。Lin /* 再改,IDEA:'result.size() == 0' can be replaced with 'result.isEmpty()'。Lin if (result.size() == 0) { */ if (result.isEmpty()) { /* 再改,只取 对象ID,有问题再说 -- 解决 大海捞针 问题。Lin * 没有即返回空的 result for (String xxa : request.getParameterMap().keySet()) { // ???大海捞针啊!!!Lin /// * 再改,去掉 ObjC.REQUEST_PLUGIN_POSSIBLE,key= 只需要一个属性及一个值,用于找到 poClazz) { String poName = poClazz.getSimpleName(); return poName.substring(0, poName.length() -2).toLowerCase(); } /** * 用对象名设置bean * @param vo; * @param bean; * @param request; * @return String */ // 来自 BeanUtils.putRequestBean(ViewObject vo, BaseBean bean,HttpServletRequest request) // 去掉 vo(ViewObject),Key 直接用 Po.objName(对象名) // 也不需要 lowerFirstChar() 了,不用类名 /* 去掉,直接写 request.setAttribute(bean.objName, bean)。Lin * 返回值用 bean.objName * 再用回,不能去掉。Lin * 不能去掉 vo(ViewObject),即不能直接用 Po.objName(对象名) -- 学员(虚拟对象) 的 Po 是人员(实体对象),但学员的页面用学员(不是人员) * 再去掉 bb.objName 了 -- 不能反过来指定对象名 -- 虚拟对象,反过来是 一对多 了 */ public static String wrPoByReq(ObjB vo, Po bean, HttpServletRequest request) { /* 改了。Lin String key = null; if(vo!=null){ key=vo.getName(); }else{//兼容处理 key=CommonUtils.lowerFirstChar(bean.getClass().getSimpleName()); } */ /* 再用回,不能用 bean.objName 做为 Key -- 学员(虚拟对象)的页面用学员,而不是人员。Lin * 再去掉 bean.objName 了,不能反过来指定对象名 -- 虚拟对象,反过来是 一对多 String key = bean.objName; */ String key; if (vo != null) { key = vo.name; } else {//兼容处理 /* 去掉 CommonUtils.lowerFirstChar(),直接用 StringUtils.uncapitalize()。Lin key=CommonUtils.lowerFirstChar(bean.getClass().getSimpleName()); */ /* 再改为表名 -- Po 的类名是 <对象名>Po 了,如 RyPo。Lin key = StringUtils.uncapitalize(bean.getClass().getSimpleName()); */ key = bean.tabName; } request.setAttribute(key, bean); return key; } // 增加。Lin /* 再去掉,没用到了 -- ObjB.poName 改为 .poClazz。Lin public static Po newPoClazz(String clazzName) throws Exception { Po po = null; if (StringUtils.isNotBlank(clazzName)) { // 去掉 StrU.notNull(),直接用 StringUtils.isNotBlank()。Lin try { po = (Po)Class.forName(clazzName).getDeclaredConstructor().newInstance(); } catch (ClassNotFoundException e) { SsLog.print("classNotFound:" + clazzName); } } return po; } */ /** * 如果html field为空,设置该字段为null * * @param bean; * @param vo; */ // 来自 ViewObjectUtil.(BaseBean) filterHTMLBlankField(BaseBean bean, ViewObject vo)。Lin // 去掉返回值,写在入口参数 bean 里 public static void clearBlankHtmlField(Po bean, ObjB vo) throws Exception { if (bean == null || vo == null) return; // return bean;。去掉返回值 /* 去掉 .fields(List),共用 fieldMap(Map)。Lin for (Field f : vo.getFields()) { */ /* 再改,增加 ObjB.htmlFieldList 了。Lin for (ObjFieldB f : vo.fieldMap.values()) { // 逐一比较,以找出 HTML 的字段,大海捞针啊???Lin */ for (ObjFieldB f : vo.htmlFieldSet) { try { /* type 从 String 改为 int。Lin if (Field.TYPE_HTML.equals(f.getType())) { */ /* 再去掉 if,增加 ObjB.cmsFieldList 了。Lin if (f.type == ObjC.FIELD_htmlType) { */ /* tt.util.BeanUtils.getFieldValue() 归入了 ObjU.rdClazzAtr(),但这里用 DbU.rdPoField() -- bean 是 Po。Lin Object v = BeanUtils.getFieldValue(f.getName(), bean); */ Object v = DbU.rdFieldValByPo(f.name, bean); /* 改,去掉 appName。Lin if (StringUtil.isNull(getFieldDisplayValue(vo.getWebapp().getName(), f, v))) { */ /* 再把 value(Object) 移到最前面。Lin if (StringUtils.isBlank(ObjU.makeFieldPlayDesc(f, v))) { */ if (StringUtils.isBlank(ObjU.toPlayDescByFieldVal(v, f))) { SsLog.print("III,clearBlankHtmlField(,blankContent:"+ v); /* tt.util.BeanUtils.setFieldValue()。Lin * Object 改为 Po,专门用于 Po * bean(Po) 移到最后面 -- 统一 BeanUtils.setFieldValue(bean, f.getName(), null); */ wrPoField(f.name, null, bean); // null = value。Lin } // } // 再去掉 if,增加 ObjB.cmsFieldList 了。Lin } catch (Exception e) { /* 改,去掉 e.printStackTrace(),改用 log4j -- 按 IDEA 规范。Lin e.printStackTrace(); */ log4j.error("DbU.clearBlankHtmlField( 异常", e); throw e; // 再增加,改为抛出错误。Lin } } /* 再去掉,IDEA:'return' is unnecessary as the last statement in a 'void' method。Lin return; // return bean;。去掉返回值 */ } /** * 没有上传 CMS 内容时,删除 内容 表记录并设置 cms 字段为 null * * @param bean; * @param vo; */ // 抄自 clearBlankHtmlField。Lin /* 再改,增加处理 -- 有上传时,补写 内容.对象ID 值。Lin public static void clearBlankCmsField(Po bean, ObjB vo, Db gdba) { */ public static void fixCmsField(Po bean, ObjB vo, Db gdba) { if (bean == null || vo == null) return; // return bean;。去掉返回值 for (ObjFieldB f : vo.cmsFieldSet) { try { Object v = DbU.rdFieldValByPo(f.name, bean); if (v == null) // 没有点击过 附件 按钮。Lin continue; long nrid = Long.parseLong(String.valueOf(v)); if (CmsU.isBlankDgnFile("T-"+ nrid)) { SsLog.print("III,fixCmsField(,内容ID:"+ v); /* 再改,用 ObjC.JLZT_inEditStr,不直接用 ObjC.JLZT_inEdit。Lin SqlCmd cmd = new SqlCmd("delete from NR where NRID=:nrid and JLZTM="+ ObjC.JLZT_inEdit); */ SqlCmd cmd = new SqlCmd("delete from NR where NRID=:nrid and "+ ObjC.JLZT_inEditStr); cmd.wrLongParm("nrid", nrid); // .setInt()。Lin gdba.doModByC(cmd); // .modify()。Lin wrPoField(f.name, null, bean); // null = value。Lin /// 再增加,删除 CMS 文件。Lin File nrFolder = new File(AppB.appRoot + CmsU.cmptBaseDir("T-"+ nrid)); FileUtils.deleteDirectory(nrFolder); /// } /// 再增加,有上传时,补写 内容.对象ID 值。Lin else { /* 再改,用 ObjC.JLZT_inEditStr,不直接用 ObjC.JLZT_inEdit。Lin SqlCmd cmd = new SqlCmd("update NR set DXID=:dxid where NRID=:nrid and JLZTM="+ ObjC.JLZT_inEdit); */ SqlCmd cmd = new SqlCmd("update NR set DXID=:dxid where NRID=:nrid and "+ ObjC.JLZT_inEditStr); cmd.wrLongParm("dxid", bean.rdIdVal()); cmd.wrLongParm("nrid", nrid); gdba.doModByC(cmd); // .modify()。Lin } /// } catch (Exception e) { log4j.error("DbU.fixCmsField( 异常", e); } } } // 来自 tt.bpm.common.BpmUtil.(Set) updateNameSet(BaseBean bean, String... columnNames)。Lin /* 再去掉 DbU.combFieldNameByPo(,直接用 Set.of( -- 空值的字段,也写!--有问题再说???Lin public static Set combFieldNameByPo(Po bean, String... columnNames) { Set rs = new TreeSet<>(); for (String name : columnNames) { Object v = DbU.rdFieldValByPo(name, bean); // tt.util.BeanUtils.getFieldValue()。Lin if (v != null && StringUtils.isNotBlank(v.toString())) { // v.toString().length() > 0。Lin rs.add(name); } } // Collections.addAll(rs, columnNames); return rs; } */ // 来自 tt.bpm.common.BpmUtil.(Set) nameSet(String... columnNames)。Lin // 另,只有一个字段名时,直接用 Collections.singleton(。Lin /* 再去掉,直接用 Set.of(。Lin public static Set combFieldName(String... columnNames) { /// * 用新的写法。Lin // Set rs = new TreeSet<>(); // for (String name : columnNames) { // rs.add(name); // } // return rs; /// * /// * 再改,IDEA:Lin // * Local variable 'rs' is redundant // * Redundant 'distinct()' call: elements will be distinct anyway when collected to a Set // Set rs = Arrays.stream(columnNames).distinct().collect(Collectors.toSet()); // return rs; /// * return Arrays.stream(columnNames).collect(Collectors.toSet()); } */ // 来自 ViewObjectUtil.(Map) _compareObject(int type, ViewObject vo, BaseBean oldObj, BaseBean newObj, // List paramNameList)。Lin // "比较oldObj和newObj,返回两个对象中的不同字段集合Map" // fieldNameList 前移到 type 后面 /* 再改 fieldNameList(List) 为 fieldNameSet(Set)。Lin * DbU.rdObjFieldNameByReq( 并入 DbU.loadPoFieldByReq( -- DbU.rdPoFieldByReq( 改为 loadPoFieldByReq(,增加返回 fieldNameSet(Set) public static Map cmpField(int type, List fieldNameList, ObjB vo, Po oldObj, Po newObj) { */ /* 再改为 cmpChgField(,专门用于比较变动时的改动字段 -- 抽取出共用程序,与 JrgwServ 共用。Lin * 去掉 type(int),只用到 type = 1 * 1,返回 Arrays.asList(oValue, nValue);2 返回 newValue * ViewObjectUtil.(Map) compareFields(ViewObject vo, BaseBean oldObj, BaseBean newObj, List paramNameList) 没用到 * "比较oldObj和newObj,返回两个对象中的不同字段集合Map" * return (Map) _compareObject(2, vo, oldObj, newObj, paramNameList); * 返回值 Map 改为 Map> * 纳入 BpmServ.saveChgField( 里的形成 wdObject(Map>) 的程序 * 把入口参数反过来,调整为 newObj(Po)、oldObj(Po)、vo(ObjB)、fieldNameSet(Set) public static Map cmpField(int type, Set fieldNameSet, ObjB vo, Po oldObj, Po newObj) { */ public static Map> cmpChgField(Po newObj, Po oldObj, ObjB vo, Set fieldNameSet) throws InvocationTargetException, NoSuchMethodException, IllegalAccessException { // ViewObject vo = findViewObject(); Map result = new HashMap<>(); /* 改为用 fieldNameList 来 for,提高性能。Lin for (Field f : vo.getFields()) { if (paramNameList == null) { } else if (!paramNameList.contains(f.getName())) { continue; } if (vo.getObjectIdField().equals(f)) continue; */ for (String fieldName : fieldNameSet) { ObjFieldB f = vo.fieldMap.get(fieldName); // 比较oldObj和newObj的区别 /* tt.util.BeanUtils.getFieldValue() 归入了 ObjU.rdClazzAtr(),但这里用 DbU.rdPoField() -- bean 是 Po。Lin Object oldValue = BeanUtils.getFieldValue(f.getName(), oldObj); Object newValue = BeanUtils.getFieldValue(f.getName(), newObj); */ Object oldValue = DbU.rdFieldValByPo(f.name, oldObj); Object newValue = DbU.rdFieldValByPo(f.name, newObj); // 空字符"" /* 再改,IDEA:'equals("")' can be replaced with 'isEmpty()'。Lin if (oldValue != null && String.valueOf(oldValue).equals("")) */ if (oldValue != null && String.valueOf(oldValue).isEmpty()) oldValue = null; /* 再改,IDEA:'equals("")' can be replaced with 'isEmpty()'。Lin if (newValue != null && String.valueOf(newValue).equals("")) */ if (newValue != null && String.valueOf(newValue).isEmpty()) newValue = null; // 空值 if (oldValue == null && newValue == null) continue; /* 改为 int 了。Lin if (Field.TYPE_HTML.equals(f.getType())) { */ if (f.type == ObjC.FIELD_htmlType) { if (EditorU.cmpEditorFile((String) oldValue, (String) newValue)) // ViewObjectUtil.compareUeditorFile()。Lin continue; /* 改为 int 了。Lin } else if (Field.TYPE_CMS.equals(f.getType())) { */ } else if (f.type == ObjC.FIELD_cmsType) { if (newValue == null || /* 再改,IDEA:'CmsU.rdChgList(newValue.toString(), null).size() == 0' can be replaced with * 'CmsU.rdChgList(newValue.toString(), null).isEmpty()'。Lin CmsU.rdChgList(newValue.toString(), null).size() == 0) // NrService.getNrChangeList()。Lin */ CmsU.rdChgList(newValue.toString(), null).isEmpty()) // NrService.getNrChangeList()。Lin continue; } /* 改为 int 了。Lin if (Field.TYPE_CMS.equals(f.getType()) == false) { */ if (f.type != ObjC.FIELD_cmsType) { if (oldValue != null && oldValue.equals(newValue)) { continue; } else if (newValue != null && newValue.equals(oldValue)) { continue; } } /* 去掉,去掉 type(int),只用到 type = 1。Lin if (type == 1) { */ String oValue = (oldValue == null)? null : oldValue.toString(); String nValue = (newValue == null)? null : newValue.toString(); result.put(f.name, Arrays.asList(oValue, nValue)); /* 去掉,去掉 type(int),只用到 type = 1。Lin } else if (type == 2) { result.put(f.name, newValue); } */ } /* 改,纳入 BpmServ.saveChgField( 里的形成 wdObject(Map>) 的程序。Lin return result; // (Map) result。Lin */ /// 来自 BpmServ.saveChgField( 里的形成 wdObject(Map>) 的程序。Lin Map> wdObject = new HashMap<>(); /* 改。Lin for (Map.Entry> entry : compareResult.entrySet()) { */ for (Entry entry : result.entrySet()) { String fieldName = entry.getKey(); ObjFieldB f = vo.fieldMap.get(fieldName); // .getFieldsMap().。Lin if (f == null) continue; /* 改为 Boolean 了。Lin if ("true".equals(f.getEditable())) { */ if (f.editable) { /* 在这,Object 转回 List。Lin wdObject.put(fieldName, entry.getValue()); */ //noinspection unchecked wdObject.put(fieldName, (List) entry.getValue()); } } return wdObject; // 增加,改为新的返回值。Lin /// } // 来自 HDDev_scgl:WJSqlcBuilder.(String) // insql(String prefix, SqlCommandImpl sqlc, Stream stream, String sqlPrefix)。Lin // sqlPrefix 改为 inStr // 顺序调整为 sqlc、inStr、stream、prefix public static String makeInSql(SqlCmd sqlc, String inStr, Stream stream, String prefix) { AtomicInteger ai = new AtomicInteger(); return stream.map(o -> { int paramIndex = ai.incrementAndGet(); String paramName = prefix + paramIndex; sqlc.wrStrParm(paramName, o); // .setString(。Lin return paramName; }).map(":"::concat).collect(Collectors.joining(",", inStr +"(", ")")); } }