From caaa37d3f59eeb33d97e0f3497bbf5885865f59d Mon Sep 17 00:00:00 2001 From: dangsn <dangsn@chicecm.com> Date: 星期一, 09 十二月 2024 18:27:17 +0800 Subject: [PATCH] 调整WebBoService中的查询接口。主要是BusinessObject对象属性的赋值,以及BusinessObject和BaseModel之间的属性互相赋值 --- Source/plt-web/plt-web-parent/plt-web-permission/src/main/java/com/vci/web/util/WebUtil.java | 495 ++++++++++++++++++++++++++++++++++++------------------ 1 files changed, 328 insertions(+), 167 deletions(-) diff --git a/Source/plt-web/plt-web-parent/plt-web-permission/src/main/java/com/vci/web/util/WebUtil.java b/Source/plt-web/plt-web-parent/plt-web-permission/src/main/java/com/vci/web/util/WebUtil.java index 0659902..c0f557d 100644 --- a/Source/plt-web/plt-web-parent/plt-web-permission/src/main/java/com/vci/web/util/WebUtil.java +++ b/Source/plt-web/plt-web-parent/plt-web-permission/src/main/java/com/vci/web/util/WebUtil.java @@ -303,7 +303,7 @@ String jsonString = JSONObject.toJSONStringWithDateFormat(o, VciDateUtil.DateTimeMillFormat, SerializerFeature.WriteDateUseDateFormat); if(StringUtils.isNotBlank(jsonString)) { JSONObject jsonObject = JSONObject.parseObject(jsonString); - if(jsonObject!=null){ + if(jsonObject != null){ for(String key : jsonObject.keySet()){ map.put(key,jsonObject.get(key)); } @@ -324,7 +324,7 @@ String jsonString = JSONObject.toJSONStringWithDateFormat(o, VciDateUtil.DateTimeMillFormat, SerializerFeature.WriteDateUseDateFormat); if(StringUtils.isNotBlank(jsonString)) { JSONObject jsonObject = JSONObject.parseObject(jsonString); - if(jsonObject!=null){ + if(jsonObject != null){ for(String key : jsonObject.keySet()){ map.put(key,jsonObject.getString(key)); } @@ -457,7 +457,7 @@ Object key = it.next(); String newKey = key.toString().toLowerCase(); Object value = map.get(key); - if(value !=null){ + if(value != null){ if(value instanceof String && WebUtil.isNotNull(value.toString())){ unNullMap.put(newKey, value); }else if(!(value instanceof String)){ @@ -476,7 +476,7 @@ public static Map<String,String> getReferAttrName(Class c){ Map<String,String> fieldMap = new HashMap<String, String>(); List<Field> allField = getAllFieldForObj(c); - if(allField!=null&&allField.size()>0){ + if(!CollectionUtils.isEmpty(allField)){ for(Field field : allField){ if (field.isAnnotationPresent(Transient.class)){ //鏈夊弬鐓ф垨鑰呮灇涓� @@ -508,7 +508,7 @@ public static List<String> getReferBoAttrName(Class c,boolean isNotHasEnum){ List<String> fieldMap = new ArrayList<String>(); List<Field> allField = getAllFieldForObj(c); - if(allField!=null&&allField.size()>0){ + if(!CollectionUtils.isEmpty(allField)){ for(Field field : allField){ if (field.isAnnotationPresent(Transient.class)){ //鏈夊弬鐓ф垨鑰呮灇涓� @@ -524,18 +524,18 @@ } /** - * 鑾峰彇瀵硅薄涓庝笟鍔$被鍨嬮噷鐨勫睘鎬ф槧灏� - * @param c 瀵硅薄鎵�灞炵被 - * @return Map<String,String> 涓氬姟绫诲瀷鐨勫瓧娈碉細瀵硅薄涓婄殑灞炴�� + * 鑾峰彇DO瀵硅薄涓庝笟鍔$被鍨嬮噷鐨勫睘鎬ф槧灏� + * @param c DO瀵硅薄鎵�灞炵被 + * @return Map<String,String> 涓氬姟绫诲瀷鐨勫瓧娈�(key)锛欴O瀵硅薄涓婄殑灞炴��(value) */ - public static Map<String/*涓氬姟绫诲瀷涓殑瀛楁*/,String/*瀵硅薄涓婄殑灞炴��*/> getFieldNameMap(Class c){ + public static Map<String/*涓氬姟绫诲瀷涓殑瀛楁*/,String/*DO瀵硅薄涓婄殑灞炴��*/> getFieldNameMap(Class c){ Map<String,String> fieldMap = new HashMap<String, String>(); List<Field> allField = getAllFieldForObj(c); - if(allField!=null&&allField.size()>0){ + if(!CollectionUtils.isEmpty(allField)){ for(Field field : allField){ if(!field.getName().equals("serialVersionUID")){ if(!field.isAnnotationPresent(Transient.class) ){ - String clientBoAttrName = getCboAttrNameFromField(field,c); + String clientBoAttrName = getCboAttrNameFromField(field, c); fieldMap.put(clientBoAttrName, field.getName()); if(field.isAnnotationPresent(VciUseEnum.class)){ //杩欎釜鏄灇涓撅紝闇�瑕� @@ -555,10 +555,10 @@ } } if(!CollectionUtils.isEmpty(fieldMap)){ - //鐪嬬湅鏈夋病鏈塶ull + //鐪嬬湅鏈夋病鏈塶ull锛岃繃婊ゆ帀value涓簄ull鐨� Map<String,String> fieldMapNotNull = new HashMap<>(); fieldMap.forEach((key,value)->{ - if(value!=null){ + if(value != null){ fieldMapNotNull.put(key,value); } }); @@ -608,14 +608,14 @@ if(!isFindColumn){ //鎵句竴涓婫et鏂规硶涓�..set鏂规硶涓婅偗瀹氭槸涓嶆敮鎸佺殑锛� Method getMethod = getGetmethod(c, field); - if(getMethod!=null && !getMethod.isAnnotationPresent(Transient.class)){ + if(getMethod != null && !getMethod.isAnnotationPresent(Transient.class)){ if(getMethod.isAnnotationPresent(Column.class)){ String name = ((Column)getMethod.getAnnotation(Column.class)).name(); if(isNotNull(name)){ clientBoAttrName = name.toLowerCase(); } } - }else if(getMethod!=null && getMethod.isAnnotationPresent(Transient.class)){ + }else if(getMethod != null && getMethod.isAnnotationPresent(Transient.class)){ //璇存槑涓嶆槸鎸佷箙鍖栫殑灞炴�э紝浣嗘槸浠庡钩鍙颁腑鏌ヨ鍑烘潵鍚庡彲鑳藉緱闇�瑕佹樉绀� String referColumn = ((Transient)field.getAnnotation(Transient.class)).referColumn(); if(isNotNull(referColumn)){ @@ -623,7 +623,9 @@ } } } - return VciQueryWrapperForDO.BASE_MODEL_COMPATIBILITY_MAP.getOrDefault(clientBoAttrName.toLowerCase(Locale.ROOT),clientBoAttrName); + //濡傛灉鐗堟湰鏈搴忓彿鐨勫睘鎬э紝闇�瑕佷粠灞炴�х殑鏄犲皠涓紝鑾峰彇涓氬姟绫诲瀷涓殑瀛楁鍚嶇О + clientBoAttrName = VciQueryWrapperForDO.BASE_MODEL_COMPATIBILITY_MAP.getOrDefault(clientBoAttrName.toLowerCase(Locale.ROOT),clientBoAttrName); + return clientBoAttrName; } /** @@ -653,7 +655,7 @@ */ public static Field getPkFieldForObj(Class c){ List<Field> allField = getAllFieldForObj(c); - if(allField!=null&&allField.size()>0){ + if(!CollectionUtils.isEmpty(allField)){ for(Field field : allField){ if(field.isAnnotationPresent(Id.class)){ return field; @@ -676,7 +678,7 @@ */ public static Field getTsField(Class c){ List<Field> allField = getAllFieldForObj(c); - if(allField!=null&&allField.size()>0){ + if(!CollectionUtils.isEmpty(allField)){ for(Field field : allField){ if(field.getName().equals("ts")){ return field; @@ -707,10 +709,10 @@ */ public static Field getFieldForObject(String fieldName,Class c){ List<Field> allField = getAllFieldForObj(c); - if(allField!=null&&allField.size()>0){ + if(!CollectionUtils.isEmpty(allField)){ for(Field field : allField){ if(field.getName().toLowerCase().equalsIgnoreCase(fieldName.toLowerCase())){ - return field; + return field; } } } @@ -770,8 +772,8 @@ try { PropertyDescriptor pd = new PropertyDescriptor(fieldName, c); return pd.getReadMethod(); - } catch (SecurityException e) { - } catch (IntrospectionException e) { + } catch (Exception e) { + //TODO 涓嶅仛浠讳綍澶勭悊 } } return null; @@ -815,87 +817,80 @@ public static void setValueForFieldFromCbo(String fieldName,Object obj,String value){ try{ Field field = getFieldForObject(fieldName,obj); - if(field!=null){ - field.setAccessible(true); - Method setMethod = getSetmethod(field.getDeclaringClass(), fieldName); - if(setMethod ==null) { - logger.error(obj.getClass().getName() + "涓睘鎬�" + fieldName + "娌℃湁setter鏂规硶"); - } - Class type = field.getType(); - //浠庡钩鍙拌鍙栧埌鐨勫�间笉浼氫负null锛屼负绌烘椂涓�""锛涙墍浠ヤ笉澶勭悊绌哄�� - if(type.equals(int.class) || type.equals(Integer.class)){ - int valueObj = getInt(value); - if(setMethod !=null) { - setMethod.invoke(obj,valueObj); - }else{ - field.set(obj,valueObj); - } - }else if(type.equals(float.class) || type.equals(Float.class)){ - float valueObj = getFloat(value); - if(setMethod !=null) { - setMethod.invoke(obj, valueObj); - }else{ - field.set(obj,valueObj); - } - }else if(type.equals(long.class) || type.equals(Long.class)){ - long valueObj = getLong(value); - if(setMethod !=null) { - setMethod.invoke(obj, valueObj); - }else{ - field.set(obj,valueObj); - } - }else if(type.equals(Double.class) || type.equals(double.class)){ - double valueObj = getDouble(value); - if(setMethod !=null) { - setMethod.invoke(obj, valueObj); - }else{ - field.set(obj,valueObj); - } - //浠庡钩鍙颁腑鏌ヨ鍑烘潵灏变笉鐢ㄥ鐞嗙簿搴︿簡锛屽洜涓哄钩鍙颁細鑷澶勭悊 - }else if(type.equals(Short.class) || type.equals(short.class)){ - short valueObject = getShort(value); - if(setMethod !=null) { - setMethod.invoke(obj, valueObject); - }else{ - field.set(obj,valueObject); - } - }else if(type.equals(Date.class)){ - //骞冲彴瀹為檯瀛樺偍鐨勯兘鏄疶imestamp,涓嶈鏄棩鏈燂紝鏃ユ湡鏃堕棿锛岄兘鏄�傚鏋滀粎鏄椂闂达紝闇�瑕佺敤瀛楃涓叉潵瀛樺偍銆� - Date d = null; - if(StringUtils.isNotBlank(value)){ - try { - if (value.indexOf("-") > -1 && value.indexOf(".") > -1 && value.indexOf(" ") > -1 && value.substring(value.lastIndexOf(".") + 1).length() == 9) { - //2013-4-19.14.5. 45. 734000000 杩欑鏍煎紡锛岃繖涓湪浣跨敤SQL璇彞鐩存帴鏌ヨ鍑烘椂闂村瓧娈电殑鏃跺�欏氨浼氭樉绀烘垚杩欐牱 - String ymd = value.substring(0, value.indexOf(".")); - value = value.substring(value.indexOf(".") + 1); - if (value.indexOf(".") > -1) { - String hms = value.substring(0, value.lastIndexOf(".")); - String nano = value.substring(value.lastIndexOf(".") + 1).trim(); - hms = hms.replace(".", ":").replace(" ", ""); - Date tempDate = VciDateUtil.str2Date(ymd + " " + hms, "yyyy-M-d h:m:s"); - if (tempDate != null) { - Timestamp ts = Timestamp.valueOf(VciDateUtil.date2Str(tempDate, VciDateUtil.DateTimeFormat) + "." + nano); - d = ts; - } + if(field != null){ + field.setAccessible(true); + Method setMethod = getSetmethod(field.getDeclaringClass(), fieldName); + if(setMethod == null) { + logger.error(obj.getClass().getName() + "涓睘鎬�" + fieldName + "娌℃湁setter鏂规硶"); + } + Class type = field.getType(); + //浠庡钩鍙拌鍙栧埌鐨勫�间笉浼氫负null锛屼负绌烘椂涓�""锛涙墍浠ヤ笉澶勭悊绌哄�� + if(type.equals(int.class) || type.equals(Integer.class)){ + int valueObj = getInt(value); + if(setMethod != null) { + setMethod.invoke(obj,valueObj); + }else{ + field.set(obj,valueObj); + } + }else if(type.equals(float.class) || type.equals(Float.class)){ + float valueObj = getFloat(value); + if(setMethod != null) { + setMethod.invoke(obj, valueObj); + }else{ + field.set(obj,valueObj); + } + }else if(type.equals(long.class) || type.equals(Long.class)){ + long valueObj = getLong(value); + if(setMethod != null) { + setMethod.invoke(obj, valueObj); + }else{ + field.set(obj,valueObj); + } + }else if(type.equals(Double.class) || type.equals(double.class)){ + double valueObj = getDouble(value); + if(setMethod != null) { + setMethod.invoke(obj, valueObj); + }else{ + field.set(obj,valueObj); + } + //浠庡钩鍙颁腑鏌ヨ鍑烘潵灏变笉鐢ㄥ鐞嗙簿搴︿簡锛屽洜涓哄钩鍙颁細鑷澶勭悊 + }else if(type.equals(Short.class) || type.equals(short.class)){ + short valueObject = getShort(value); + if(setMethod != null) { + setMethod.invoke(obj, valueObject); + }else{ + field.set(obj,valueObject); + } + }else if(type.equals(Date.class)){ + //骞冲彴瀹為檯瀛樺偍鐨勯兘鏄疶imestamp,涓嶈鏄棩鏈燂紝鏃ユ湡鏃堕棿锛岄兘鏄�傚鏋滀粎鏄椂闂达紝闇�瑕佺敤瀛楃涓叉潵瀛樺偍銆� + Date d = null; + if(StringUtils.isNotBlank(value)){ + try { + if (value.indexOf("-") > -1 && value.indexOf(".") > -1 && value.indexOf(" ") > -1 && value.substring(value.lastIndexOf(".") + 1).length() == 9) { + //2013-4-19.14.5. 45. 734000000 杩欑鏍煎紡锛岃繖涓湪浣跨敤SQL璇彞鐩存帴鏌ヨ鍑烘椂闂村瓧娈电殑鏃跺�欏氨浼氭樉绀烘垚杩欐牱 + String ymd = value.substring(0, value.indexOf(".")); + value = value.substring(value.indexOf(".") + 1); + if (value.indexOf(".") > -1) { + String hms = value.substring(0, value.lastIndexOf(".")); + String nano = value.substring(value.lastIndexOf(".") + 1).trim(); + hms = hms.replace(".", ":").replace(" ", ""); + Date tempDate = VciDateUtil.str2Date(ymd + " " + hms, "yyyy-M-d h:m:s"); + if (tempDate != null) { + Timestamp ts = Timestamp.valueOf(VciDateUtil.date2Str(tempDate, VciDateUtil.DateTimeFormat) + "." + nano); + d = ts; } - } else if (value.matches("\\d+\\.?\\d*")) { - //杩樻湁鍧戠埞鐨勬槸缁欑殑long鍨嬬殑瀛楃涓� - d = new Date(); - d.setTime(getLong(value)); - } else { - if(field.isAnnotationPresent(VciFieldType.class)) { - VciFieldType vciFieldType = field.getAnnotation(VciFieldType.class); - if(VciFieldTypeEnum.VTDate.equals(vciFieldType.value())) { - d = VciDateUtil.str2Date(value, VciDateUtil.DateFormat); - }else if(VciFieldTypeEnum.VTDateTime.equals(vciFieldType.value())){ - d = VciDateUtil.str2Date(value, VciDateUtil.DateTimeFormat); - }else { - if(value.indexOf("-") > -1 &&value.length() == 10 ) { - d = VciDateUtil.str2Date(value, VciDateUtil.DateFormat); - }else { - d = VciDateUtil.str2Date(value, VciDateUtil.DateTimeMillFormat); - } - } + } + } else if (value.matches("\\d+\\.?\\d*")) { + //杩樻湁鍧戠埞鐨勬槸缁欑殑long鍨嬬殑瀛楃涓� + d = new Date(); + d.setTime(getLong(value)); + } else { + if(field.isAnnotationPresent(VciFieldType.class)) { + VciFieldType vciFieldType = field.getAnnotation(VciFieldType.class); + if(VciFieldTypeEnum.VTDate.equals(vciFieldType.value())) { + d = VciDateUtil.str2Date(value, VciDateUtil.DateFormat); + }else if(VciFieldTypeEnum.VTDateTime.equals(vciFieldType.value())){ + d = VciDateUtil.str2Date(value, VciDateUtil.DateTimeFormat); }else { if(value.indexOf("-") > -1 &&value.length() == 10 ) { d = VciDateUtil.str2Date(value, VciDateUtil.DateFormat); @@ -903,34 +898,41 @@ d = VciDateUtil.str2Date(value, VciDateUtil.DateTimeMillFormat); } } - } - } catch (Exception e) { - try { - d = VciDateUtil.str2Date(value, VciDateUtil.DateTimeMillFormat); - } catch (Exception e1) { - + }else { + if(value.indexOf("-") > -1 &&value.length() == 10 ) { + d = VciDateUtil.str2Date(value, VciDateUtil.DateFormat); + }else { + d = VciDateUtil.str2Date(value, VciDateUtil.DateTimeMillFormat); + } } } - } - try { - if(d != null ){ - if(setMethod !=null) { - setMethod.invoke(obj, d); - }else{ - field.set(obj,d); - } - } - } catch (Exception e) { - } - }else if(type.equals(String.class)){ - if(setMethod != null) { - setMethod.invoke(obj, value); - }else{ - field.set(obj,value); - } - }else{ - logger.info("WebUtil.setValueForFieldForCbo:涓嶆敮鎸佺殑绫诲瀷" + type.toString()); - } + } catch (Exception e) { + try { + d = VciDateUtil.str2Date(value, VciDateUtil.DateTimeMillFormat); + } catch (Exception e1) { + + } + } + } + try { + if(d != null ){ + if(setMethod !=null) { + setMethod.invoke(obj, d); + }else{ + field.set(obj,d); + } + } + } catch (Exception e) { + } + }else if(type.equals(String.class)){ + if(setMethod != null) { + setMethod.invoke(obj, value); + }else{ + field.set(obj,value); + } + }else{ + logger.info("WebUtil.setValueForFieldForCbo:涓嶆敮鎸佺殑绫诲瀷" + type.toString()); + } } }catch (Exception e) { if(logger.isErrorEnabled()){ @@ -1009,7 +1011,7 @@ setMethod.invoke(targetObject, value); }else{ Field field = getFieldForObject(fieldName, targetObject); - if(field !=null){ + if(field != null){ field.setAccessible(true); field.set(targetObject, value); } @@ -1040,12 +1042,12 @@ if(isNotNull(fieldName)){ try { Method getMethod = getGetmethod(sourceObject.getClass(), fieldName); - if(getMethod !=null){ + if(getMethod != null){ return getMethod.invoke(sourceObject); }else{ //璇存槑娌℃湁璁剧疆getter锛屾瘮濡侭O鍜孡O瀵硅薄杩欑 Field field = getFieldForObject(fieldName, sourceObject); - if(field !=null){ + if(field != null){ field.setAccessible(true); return field.get(sourceObject); } @@ -1089,7 +1091,7 @@ * @param fieldAttrMap 灞炴�ф槧灏� */ public static void copyValueToObjectFromCbos(BusinessObject cbo,Object obj,Map<String,String> fieldAttrMap){ - if(cbo!=null){ + if(cbo != null){ copyValueToObjectFromBos(cbo,obj,fieldAttrMap); } } @@ -1140,7 +1142,7 @@ * @param bo 涓氬姟鏁版嵁 * @param obj 瀵硅薄 */ - public static void copyValueToObjectFromBos(com.vci.corba.omd.data.BusinessObject bo ,Object obj){ + public static void copyValueToObjectFromBos(BusinessObject bo ,Object obj){ copyValueToObjectFromBos(bo,obj,null); } @@ -1150,59 +1152,83 @@ * @param obj 瀵硅薄 * @param fieldAttrMap 灞炴�ф槧灏� */ - public static void copyValueToObjectFromBos(com.vci.corba.omd.data.BusinessObject bo , Object obj, Map<String,String> fieldAttrMap){ - if(bo!=null && obj != null){ + public static void copyValueToObjectFromBos(BusinessObject bo , Object obj, Map<String,String> fieldAttrMap){ + if(bo != null && obj != null){ //鍏堟妸鎵�鏈夌殑瀛楁鏄犲皠鎵惧埌 if(fieldAttrMap == null){ fieldAttrMap = getFieldNameMap(obj.getClass()); } - com.vci.corba.omd.data.AttributeValue[] newAList = bo.newAttrValList; - com.vci.corba.omd.data.AttributeValue[] hisAList = bo.hisAttrValList; + AttributeValue[] newAList = bo.newAttrValList; + AttributeValue[] hisAList = bo.hisAttrValList; //瑕佸厛鎶夿O瀵硅薄涓婄殑鍊兼嫹璐濊繃鍘� List<Field> boFields = getAllFieldForObj(bo.getClass()); - - if(boFields!=null){ - for(Field field :boFields){ - if(fieldAttrMap.containsKey(field.getName().toLowerCase())){ - //璇存槑杩欎釜灏辨槸鍦˙O瀵硅薄涓婄殑 - Object value = getValueFromField(field.getName(), bo); - if(value !=null){ - setValueForFieldFromCbo(fieldAttrMap.get(field.getName().toLowerCase()), obj, getStringValueFromObject(value)); + if(!CollectionUtils.isEmpty(boFields)){ + for(Field field : boFields){ + //璇存槑杩欎釜灏辨槸鍦˙O瀵硅薄涓婄殑 + Object value = getValueFromField(field.getName(), bo); + if(value != null){ + //BusinessObject鍜孊aseModel涓紝浠ヤ笅鐨勫睘鎬э紝涓嶇浉鍚岋紝闇�瑕佸崟鐙鐞� + switch (field.getName().toLowerCase()){ + case "revoid": + setValueForFieldFromCbo("revisionOid", obj, getStringValueFromObject(value)); + break; + case "btname": + setValueForFieldFromCbo("btmName", obj, getStringValueFromObject(value)); + break; + case "islastr": + setValueForFieldFromCbo("lastr", obj, getStringValueFromObject(value).equalsIgnoreCase("true")?"1":"0"); + break; + case "isfirstr": + setValueForFieldFromCbo("firstr", obj, getStringValueFromObject(value).equalsIgnoreCase("true")?"1":"0"); + break; + case "islastv": + setValueForFieldFromCbo("lastv", obj, getStringValueFromObject(value).equalsIgnoreCase("true")?"1":"0"); + break; + case "isfirstv": + setValueForFieldFromCbo("firstv", obj, getStringValueFromObject(value).equalsIgnoreCase("true")?"1":"0"); + break; + case "modifytime": + setValueForFieldFromCbo("lastmodifytime", obj, getStringValueFromObject(value)); + break; + case "fromversion": + setValueForFieldFromCbo("copyFromVersion", obj, getStringValueFromObject(value)); + break; + default: + setValueForFieldFromCbo(fieldAttrMap.get(field.getName().toLowerCase()), obj, getStringValueFromObject(value)); + break; } } } } - if(newAList!=null&&newAList.length>0){ + if(newAList != null && newAList.length > 0){ for(int i = 0 ; i < newAList.length;i++){ - com.vci.corba.omd.data.AttributeValue av = newAList[i]; + AttributeValue av = newAList[i]; String attrName = av.name.toLowerCase(); if(fieldAttrMap.containsKey(attrName)) { String fieldName = fieldAttrMap.get(attrName); setValueForFieldFromCbo(fieldName, obj, av.value); }else{ fieldAttrMap.forEach((cboField,fieldName)->{ - if(fieldName!=null && fieldName.equalsIgnoreCase(attrName) && cboField.contains(".")){ + if(fieldName != null && fieldName.equalsIgnoreCase(attrName) && cboField.contains(".")){ //鍙傜収鐨勬椂鍊� setValueForFieldFromCbo(fieldName, obj, av.value); - return; } }); } } } - if(hisAList!=null&&hisAList.length>0){ + if(hisAList != null && hisAList.length > 0){ for(int i = 0 ; i < hisAList.length;i++){ - com.vci.corba.omd.data.AttributeValue av = hisAList[i]; + AttributeValue av = hisAList[i]; String attrName = av.name.toLowerCase(); String fieldName = fieldAttrMap.get(attrName); - if(fieldName!=null){ + if(fieldName != null){ setValueForFieldFromCbo(fieldName, obj, av.value); }else{ fieldAttrMap.forEach((cboField,field)->{ - if(field!=null && field.equalsIgnoreCase(attrName) && cboField.contains(".")){ + if(field != null && field.equalsIgnoreCase(attrName) && cboField.contains(".")){ //鍙傜収鐨勬椂鍊� setValueForFieldFromCbo(field, obj, av.value); - return; } }); } @@ -1217,7 +1243,7 @@ * @param map map */ public static void copyValueToMapFromCbos(BusinessObject cbo,Map<String,String> map){ - if(cbo!=null){ + if(cbo != null){ copyValueToMapFromBos(cbo,map); } } @@ -1227,21 +1253,21 @@ * @param bo 涓氬姟鏁版嵁 * @param map map */ - public static void copyValueToMapFromBos(com.vci.corba.omd.data.BusinessObject bo, Map<String,String> map){ + public static void copyValueToMapFromBos(BusinessObject bo, Map<String,String> map){ if(bo!=null ){ //鍏堟妸鎵�鏈夌殑瀛楁鏄犲皠鎵惧埌 - com.vci.corba.omd.data.AttributeValue[] newAList = bo.newAttrValList; - com.vci.corba.omd.data.AttributeValue[] hisAList = bo.hisAttrValList; - if(hisAList!=null&&hisAList.length>0){// + AttributeValue[] newAList = bo.newAttrValList; + AttributeValue[] hisAList = bo.hisAttrValList; + if(hisAList != null && hisAList.length > 0){// for(int i = 0 ; i < hisAList.length;i++){ - com.vci.corba.omd.data.AttributeValue av = hisAList[i]; + AttributeValue av = hisAList[i]; String attrName = av.name.toLowerCase(); map.put(attrName, av.value); } } - if(newAList!=null&&newAList.length>0){//NEW鐨勪紭鍏堢骇楂樹簺 + if(newAList != null && newAList.length > 0){//NEW鐨勪紭鍏堢骇楂樹簺 for(int i = 0 ; i < newAList.length;i++){ - com.vci.corba.omd.data.AttributeValue av = newAList[i]; + AttributeValue av = newAList[i]; String attrName = av.name.toLowerCase(); map.put(attrName, av.value); } @@ -1358,13 +1384,132 @@ if(value == null){ value = ""; } - if(isDefaultField(key)){ - setValueToField(key, cbo, value); + if(isDefaultField(key.toLowerCase())){ + //閲嶆柊鍗曠嫭澶勭悊銆傚洜涓築aseModel鐨勫熀纭�灞炴�у拰BusinessObject涓殑鏈夋墍宸紓 + setValueToCboField(key.toLowerCase(), cbo, value); } ObjectTool.setBOAttributeValue(cbo,key.toLowerCase(), value); } } } + + /** + * 缁橞usinessObject瀵硅薄涓殑灞炴�ц缃�� + * @param fieldName 琛ㄤ腑瀛楁鎴朌O瀵硅薄涓殑灞炴�� + * @param bo BusinessObject + * @param value 灞炴�у�� + */ + public static void setValueToCboField(String fieldName, BusinessObject bo, String value){ + switch (fieldName){ + case "oid": + bo.oid = value; + break; + case "revisionoid": + bo.revoid = value; + break; + case "nameoid": + bo.nameoid = value; + break; + case "btmname": + bo.btName = value; + break; + case "lastr": + bo.isLastR = "1".equals(value); + break; + case "firstr": + bo.isFirstR = "1".equals(value); + break; + case "lastv": + bo.isLastV = "1".equals(value); + break; + case "firstv": + bo.isFirstV = "1".equals(value); + break; + case "creator": + bo.creator = value; + break; + case "createtime": + try { + long createTime = Long.parseLong(value); + bo.createTime = createTime; + } catch (NumberFormatException e) { + try { + bo.createTime = VciDateUtil.str2Date(value, VciDateUtil.DateTimeFormat).getTime(); + } catch (Exception e2) { + //TODO + } + } + break; + case "lastmodifier": + bo.modifier = value; + break; + case "lastmodifytime": + try { + long lastModifyTime = Long.parseLong(value); + bo.modifyTime = lastModifyTime; + } catch (NumberFormatException e) { + try { + bo.modifyTime = VciDateUtil.str2Date(value, VciDateUtil.DateTimeFormat).getTime(); + } catch (Exception e2) { + //TODO + } + } + break; + case "revisionrule": + bo.revisionRule = value; + break; + case "versionrule": + bo.versionRule = value; + break; + case "revisionseq": + bo.revisionSeq = Short.parseShort(value); + break; + case "revisionvalue": + bo.revisionValue = value; + break; + case "versionseq": + bo.versionSeq = Short.parseShort(value); + break; + case "versionvalue": + bo.versionValue = value; + break; + case "lctid": + bo.lctId = value; + break; + case "lcstatus": + bo.lcStatus = value; + break; + case "ts": + try { + long ts = Long.parseLong(value); + bo.ts = ts; + } catch (NumberFormatException e) { + try { + bo.ts = VciDateUtil.str2Date(value, VciDateUtil.DateTimeFormat).getTime(); + } catch (Exception e2) { + //TODO + } + } + break; + case "id": + bo.id = value; + break; + case "name": + bo.name = value; + break; + case "description": + bo.description = value; + break; + case "owner": + bo.owner = value; + break; + case "copyfromversion": + bo.fromVersion = value; + break; + default: + break; + } + } /** * 鎷疯礉閾炬帴绫诲瀷鐨勫�煎埌map @@ -1380,7 +1525,7 @@ if(value == null){ value = ""; } - if(isDefaultField(key)){ + if(isDefaultField(key.toLowerCase())){ setValueToField(key, clo, value); }else { ObjectTool.setLOAttributeValue(clo,key.toLowerCase(), value); @@ -1420,7 +1565,7 @@ if(value==null){ value = ""; } - if(isDefaultField(fieldName)){ + if(isDefaultField(fieldName.toLowerCase())){ setValueToField(fieldName, cbo, value); } ObjectTool.setBOAttributeValue(cbo,attrName.toLowerCase(), value); @@ -1435,7 +1580,7 @@ */ public static boolean isDefaultField(String fieldNames){ if(VciQueryWrapperForDO.BASIC_FIELD_MAP.containsKey(fieldNames) || VciQueryWrapperForDO.LIFECYCLE_MANAGE_FIELD_MAP.containsKey(fieldNames) - || VciQueryWrapperForDO.REVISION_MANAGE_FIELD_MAP.containsKey(fieldNames) ) { + || VciQueryWrapperForDO.REVISION_MANAGE_FIELD_MAP.containsKey(fieldNames) || VciQueryWrapperForDO.BASE_MODEL_COMPATIBILITY_MAP.containsValue(fieldNames)) { return true; } return false; @@ -1729,4 +1874,20 @@ } return BusinessObject; } + + /** + * 鑾峰彇瀵硅薄涓殑灞炴�ч泦鍚堛�� + * @param tClass 瀵硅薄 + * @return 灞炴�ч泦鍚圡ap銆俴ey锛氬睘鎬у悕绉帮紝value锛氬睘鎬� + */ + public static Map<String, Field> getFieldMapForObject(Class tClass) { + Map<String, Field> fieldMap = new HashMap<>(); + List<Field> allField = getAllFieldForObj(tClass); + if(!CollectionUtils.isEmpty(allField)){ + for(Field field : allField){ + fieldMap.put(field.getName(), field); + } + } + return fieldMap; + } } -- Gitblit v1.9.3