| | |
| | | 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)); |
| | | } |
| | |
| | | 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)); |
| | | } |
| | |
| | | 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)){ |
| | |
| | | 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)){ |
| | | //有参照或者枚举 |
| | |
| | | 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)){ |
| | | //有参照或者枚举 |
| | |
| | | } |
| | | |
| | | /** |
| | | * 获取对象与业务类型里的属性映射 |
| | | * @param c 对象所属类 |
| | | * @return Map<String,String> 业务类型的字段:对象上的属性 |
| | | * 获取DO对象与业务类型里的属性映射 |
| | | * @param c DO对象所属类 |
| | | * @return Map<String,String> 业务类型的字段(key):DO对象上的属性(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)){ |
| | | //这个是枚举,需要 |
| | |
| | | } |
| | | } |
| | | if(!CollectionUtils.isEmpty(fieldMap)){ |
| | | //看看有没有null |
| | | //看看有没有null,过滤掉value为null的 |
| | | Map<String,String> fieldMapNotNull = new HashMap<>(); |
| | | fieldMap.forEach((key,value)->{ |
| | | if(value!=null){ |
| | | if(value != null){ |
| | | fieldMapNotNull.put(key,value); |
| | | } |
| | | }); |
| | |
| | | if(!isFindColumn){ |
| | | //找一下Get方法上..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)){ |
| | |
| | | } |
| | | } |
| | | } |
| | | return VciQueryWrapperForDO.BASE_MODEL_COMPATIBILITY_MAP.getOrDefault(clientBoAttrName.toLowerCase(Locale.ROOT),clientBoAttrName); |
| | | //如果版本本次序号的属性,需要从属性的映射中,获取业务类型中的字段名称 |
| | | clientBoAttrName = VciQueryWrapperForDO.BASEMODEL_CBO_FIELD_MAP.getOrDefault(clientBoAttrName.toLowerCase(Locale.ROOT),clientBoAttrName); |
| | | return clientBoAttrName; |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | 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; |
| | |
| | | */ |
| | | 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; |
| | |
| | | */ |
| | | 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; |
| | | } |
| | | } |
| | | } |
| | |
| | | * @return 方法 |
| | | */ |
| | | public static Method getSetmethod(Class c,String fieldName){ |
| | | if(c!=null&&isNotNull(fieldName)){ |
| | | if(c != null && isNotNull(fieldName)){ |
| | | try { |
| | | PropertyDescriptor pd = new PropertyDescriptor(fieldName, c); |
| | | return pd.getWriteMethod(); |
| | | } catch (SecurityException e) { |
| | | } catch (IntrospectionException e) { |
| | | } catch (Exception e) { |
| | | //TODO 不做处理 |
| | | } |
| | | } |
| | | return null; |
| | |
| | | try { |
| | | PropertyDescriptor pd = new PropertyDescriptor(fieldName, c); |
| | | return pd.getReadMethod(); |
| | | } catch (SecurityException e) { |
| | | } catch (IntrospectionException e) { |
| | | } catch (Exception e) { |
| | | //TODO 不做任何处理 |
| | | } |
| | | } |
| | | return null; |
| | |
| | | * @param value 属性值 |
| | | */ |
| | | public static void setValueForFieldFromCbo(String fieldName,Object obj,String value){ |
| | | System.out.println("fieldName:"+fieldName+",value:"+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)){ |
| | | //平台实际存储的都是Timestamp,不论是日期,日期时间,都是。如果仅是时间,需要用字符串来存储。 |
| | | 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)){ |
| | | //平台实际存储的都是Timestamp,不论是日期,日期时间,都是。如果仅是时间,需要用字符串来存储。 |
| | | 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); |
| | |
| | | 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()){ |
| | |
| | | setMethod.invoke(targetObject, value); |
| | | }else{ |
| | | Field field = getFieldForObject(fieldName, targetObject); |
| | | if(field !=null){ |
| | | if(field != null){ |
| | | field.setAccessible(true); |
| | | field.set(targetObject, value); |
| | | } |
| | |
| | | if(isNotNull(fieldName)){ |
| | | try { |
| | | Method getMethod = getGetmethod(sourceObject.getClass(), fieldName); |
| | | if(getMethod !=null){ |
| | | if(getMethod != null){ |
| | | return getMethod.invoke(sourceObject); |
| | | }else{ |
| | | //说明没有设置getter,比如BO和LO对象这种 |
| | | Field field = getFieldForObject(fieldName, sourceObject); |
| | | if(field !=null){ |
| | | if(field != null){ |
| | | field.setAccessible(true); |
| | | return field.get(sourceObject); |
| | | } |
| | |
| | | * @param fieldAttrMap 属性映射 |
| | | */ |
| | | public static void copyValueToObjectFromCbos(BusinessObject cbo,Object obj,Map<String,String> fieldAttrMap){ |
| | | if(cbo!=null){ |
| | | if(cbo != null){ |
| | | copyValueToObjectFromBos(cbo,obj,fieldAttrMap); |
| | | } |
| | | } |
| | |
| | | * @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); |
| | | } |
| | | |
| | |
| | | * @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; |
| | | //要先把BO对象上的值拷贝过去 |
| | | List<Field> boFields = getAllFieldForObj(bo.getClass()); |
| | | |
| | | if(boFields!=null){ |
| | | for(Field field :boFields){ |
| | | if(fieldAttrMap.containsKey(field.getName().toLowerCase())){ |
| | | if(!CollectionUtils.isEmpty(boFields)){ |
| | | for(Field field : boFields){ |
| | | if(VciQueryWrapperForDO.BASEMODEL_CBO_FIELD_MAP.containsValue(field.getName().toLowerCase())){ |
| | | //说明这个就是在BO对象上的 |
| | | Object value = getValueFromField(field.getName(), bo); |
| | | if(value !=null){ |
| | | setValueForFieldFromCbo(fieldAttrMap.get(field.getName().toLowerCase()), obj, getStringValueFromObject(value)); |
| | | if(value != null){ |
| | | //BusinessObject和BaseModel中,是否第一版本版次的属性,需要单独处理 |
| | | String fieldValue; |
| | | if(VciQueryWrapperForDO.BASE_MODEL_COMPATIBILITY_MAP.containsValue(field.getName().toLowerCase())){ |
| | | fieldValue = getStringValueFromObject(value).equalsIgnoreCase("true")?"1":"0"; |
| | | }else{ |
| | | fieldValue = getStringValueFromObject(value); |
| | | } |
| | | setValueForFieldFromCbo(fieldAttrMap.get(field.getName().toLowerCase()), obj, fieldValue); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | 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; |
| | | } |
| | | }); |
| | | } |
| | |
| | | * @param map map |
| | | */ |
| | | public static void copyValueToMapFromCbos(BusinessObject cbo,Map<String,String> map){ |
| | | if(cbo!=null){ |
| | | if(cbo != null){ |
| | | copyValueToMapFromBos(cbo,map); |
| | | } |
| | | } |
| | |
| | | * @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); |
| | | } |
| | |
| | | if(value == null){ |
| | | value = ""; |
| | | } |
| | | if(isDefaultField(key)){ |
| | | setValueToField(key, cbo, value); |
| | | if(isDefaultField(key.toLowerCase())){ |
| | | //重新单独处理。因为BaseModel的基础属性和BusinessObject中的有所差异 |
| | | setValueToCboField(key.toLowerCase(), cbo, value); |
| | | } |
| | | ObjectTool.setBOAttributeValue(cbo,key.toLowerCase(), value); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 给BusinessObject对象中的属性设置值 |
| | | * @param fieldName 表中字段或DO对象中的属性 |
| | | * @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 |
| | |
| | | if(value == null){ |
| | | value = ""; |
| | | } |
| | | if(isDefaultField(key)){ |
| | | if(isDefaultField(key.toLowerCase())){ |
| | | setValueToField(key, clo, value); |
| | | }else { |
| | | ObjectTool.setLOAttributeValue(clo,key.toLowerCase(), value); |
| | |
| | | if(value==null){ |
| | | value = ""; |
| | | } |
| | | if(isDefaultField(fieldName)){ |
| | | if(isDefaultField(fieldName.toLowerCase())){ |
| | | setValueToField(fieldName, cbo, value); |
| | | } |
| | | ObjectTool.setBOAttributeValue(cbo,attrName.toLowerCase(), value); |
| | |
| | | * @return true为默认 |
| | | */ |
| | | 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) ) { |
| | | if(VciQueryWrapperForDO.BASEMODEL_CBO_FIELD_MAP.containsKey(fieldNames)) { |
| | | return true; |
| | | } |
| | | return false; |
| | |
| | | } |
| | | return BusinessObject; |
| | | } |
| | | |
| | | /** |
| | | * 获取对象中的属性集合。 |
| | | * @param tClass 对象 |
| | | * @return 属性集合Map。key:属性名称,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; |
| | | } |
| | | } |