From 370b26066c560f15f6a84caca2be149e48e86556 Mon Sep 17 00:00:00 2001
From: 田源 <tianyuan@vci-tech.com>
Date: 星期二, 07 一月 2025 15:52:05 +0800
Subject: [PATCH] 系统菜单 默认显示&&系统配置、对象建模按钮权限以及按钮图标
---
Source/plt-web/plt-web-parent/plt-web-permission/src/main/java/com/vci/web/util/WebUtil.java | 541 ++++++++++++++++++++++++++++++++++-------------------
1 files changed, 349 insertions(+), 192 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 b797540..367f7e0 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
@@ -33,7 +33,6 @@
import org.springframework.util.CollectionUtils;
import javax.servlet.http.HttpServletRequest;
-import java.beans.IntrospectionException;
import java.beans.PropertyDescriptor;
import java.lang.reflect.*;
import java.math.BigDecimal;
@@ -147,9 +146,23 @@
* @param beanClass Bean鐨勭被
* @return 浠庡垪琛ㄩ噷鑾峰彇绗竴涓璞�
*/
- public static <T> T getFirstObjectFromJson(String jsonString,Class<T> beanClass){
+ public static <T> T getFirstObjectFromJsonArray(String jsonString,Class<T> beanClass){
if(!isNull(jsonString)) {
return JSONObject.parseArray(jsonString, beanClass).get(0);
+ } else {
+ return null;
+ }
+ }
+
+ /**
+ * 浠巎son瀛楃涓蹭腑鑾峰彇绗竴涓璞�
+ * @param jsonString json鐨勫瓧绗︿覆
+ * @param beanClass Bean鐨勭被
+ * @return 浠庡垪琛ㄩ噷鑾峰彇绗竴涓璞�
+ */
+ public static <T> List<T> getObjectListFromJsonArray(String jsonString,Class<T> beanClass){
+ if(!isNull(jsonString)) {
+ return JSONObject.parseArray(jsonString, beanClass);
} else {
return null;
}
@@ -303,7 +316,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 +337,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 +470,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 +489,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 +521,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 +537,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 +568,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 +621,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 +636,9 @@
}
}
}
- 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;
}
/**
@@ -653,7 +668,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 +691,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 +722,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;
}
}
}
@@ -748,12 +763,12 @@
* @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;
@@ -770,8 +785,8 @@
try {
PropertyDescriptor pd = new PropertyDescriptor(fieldName, c);
return pd.getReadMethod();
- } catch (SecurityException e) {
- } catch (IntrospectionException e) {
+ } catch (Exception e) {
+ //TODO 涓嶅仛浠讳綍澶勭悊
}
}
return null;
@@ -813,89 +828,83 @@
* @param value 灞炴�у��
*/
public static void setValueForFieldFromCbo(String fieldName,Object obj,String value){
+ System.out.println("fieldName锛�"+fieldName+"锛寁alue锛�"+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 +912,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 +1025,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 +1056,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 +1105,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 +1156,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 +1166,66 @@
* @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())){
+ if(!CollectionUtils.isEmpty(boFields)){
+ for(Field field : boFields){
+ if(VciQueryWrapperForDO.BASEMODEL_CBO_FIELD_MAP.containsValue(field.getName().toLowerCase())){
//璇存槑杩欎釜灏辨槸鍦˙O瀵硅薄涓婄殑
Object value = getValueFromField(field.getName(), bo);
- if(value !=null){
- setValueForFieldFromCbo(fieldAttrMap.get(field.getName().toLowerCase()), obj, getStringValueFromObject(value));
+ if(value != null){
+ //BusinessObject鍜孊aseModel涓紝鏄惁绗竴鐗堟湰鐗堟鐨勫睘鎬э紝闇�瑕佸崟鐙鐞�
+ String fieldValue;
+ if(VciQueryWrapperForDO.BASE_MODEL_COMPATIBILITY_MAP.containsValue(field.getName().toLowerCase())){
+ fieldValue = getStringValueFromObject(value).equalsIgnoreCase("true")?"1":"0";
+ }else{
+ fieldValue = getStringValueFromObject(value);
+ }
+ String fieldName = fieldAttrMap.get(field.getName().toLowerCase());
+ if(StringUtils.isNotBlank(fieldName)){
+ setValueForFieldFromCbo(fieldName, 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];
- String attrName = av.attrName.toLowerCase();
+ AttributeValue av = newAList[i];
+ String attrName = av.name.toLowerCase();
if(fieldAttrMap.containsKey(attrName)) {
String fieldName = fieldAttrMap.get(attrName);
- setValueForFieldFromCbo(fieldName, obj, av.attrVal);
+ 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.attrVal);
- return;
+ setValueForFieldFromCbo(fieldName, obj, av.value);
}
});
}
}
}
- 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];
- String attrName = av.attrName.toLowerCase();
+ AttributeValue av = hisAList[i];
+ String attrName = av.name.toLowerCase();
String fieldName = fieldAttrMap.get(attrName);
- if(fieldName!=null){
- setValueForFieldFromCbo(fieldName, obj, av.attrVal);
+ 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.attrVal);
- return;
+ setValueForFieldFromCbo(field, obj, av.value);
}
});
}
@@ -1217,7 +1240,7 @@
* @param map map
*/
public static void copyValueToMapFromCbos(BusinessObject cbo,Map<String,String> map){
- if(cbo!=null){
+ if(cbo != null){
copyValueToMapFromBos(cbo,map);
}
}
@@ -1227,23 +1250,23 @@
* @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];
- String attrName = av.attrName.toLowerCase();
- map.put(attrName, av.attrVal);
+ 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];
- String attrName = av.attrName.toLowerCase();
- map.put(attrName, av.attrVal);
+ AttributeValue av = newAList[i];
+ String attrName = av.name.toLowerCase();
+ map.put(attrName, av.value);
}
}
}
@@ -1276,15 +1299,15 @@
if(hisAList!=null&&hisAList.length>0){
for(int i = 0 ; i < hisAList.length;i++){
AttributeValue av = hisAList[i];
- String attrName = av.attrName.toLowerCase();
- map.put(attrName, av.attrVal);
+ String attrName = av.name.toLowerCase();
+ map.put(attrName, av.value);
}
}
if(newAList!=null&&newAList.length>0){
for(int i = 0 ; i < newAList.length;i++){
AttributeValue av = newAList[i];
- String attrName = av.attrName.toLowerCase();
- map.put(attrName, av.attrVal);
+ String attrName = av.name.toLowerCase();
+ map.put(attrName, av.value);
}
}
}
@@ -1327,18 +1350,18 @@
if(newAList!=null&&newAList.length>0){
for(int i = 0 ; i < newAList.length;i++){
AttributeValue av = newAList[i];
- String attrName = av.attrName.toLowerCase();
+ String attrName = av.name.toLowerCase();
String fieldName = fieldAttrMap.get(attrName);
- setValueForFieldFromCbo(fieldName, obj, av.attrVal);//渚濈劧浣跨敤CBO鐨勫鐞嗘柟寮�
+ setValueForFieldFromCbo(fieldName, obj, av.value);//渚濈劧浣跨敤CBO鐨勫鐞嗘柟寮�
}
}
if(hisAList!=null&&hisAList.length>0){
for(int i = 0 ; i < hisAList.length;i++){
AttributeValue av = hisAList[i];
- String attrName = av.attrName.toLowerCase();
+ String attrName = av.name.toLowerCase();
String fieldName = fieldAttrMap.get(attrName);
if(fieldName!=null){
- setValueForFieldFromCbo(fieldName, obj, av.attrVal);
+ setValueForFieldFromCbo(fieldName, obj, av.value);
}
}
}
@@ -1358,13 +1381,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 +1522,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 +1562,7 @@
if(value==null){
value = "";
}
- if(isDefaultField(fieldName)){
+ if(isDefaultField(fieldName.toLowerCase())){
setValueToField(fieldName, cbo, value);
}
ObjectTool.setBOAttributeValue(cbo,attrName.toLowerCase(), value);
@@ -1434,8 +1576,7 @@
* @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;
@@ -1494,7 +1635,7 @@
* @return base寮傚父瀵硅薄
*/
public static VciBaseException getVciBaseException(PLException e){
- return new VciBaseException(e.code, new java.lang.String[]{e.getMessage()});
+ return new VciBaseException(e.code, new String[]{e.getMessage()});
}
/**
@@ -1718,8 +1859,8 @@
for (int i = 0; i < select.getSelectItems().size(); i++) {
SelectItem selectItem = select.getSelectItem(i);
AttributeValue attributeValue = new AttributeValue();
- attributeValue.attrName = selectItem.getAlias().getName();
- attributeValue.attrVal = valueArry[i];
+ attributeValue.name = selectItem.getAlias().getName();
+ attributeValue.value = valueArry[i];
attributeValues[i] = attributeValue;
}
BusinessObject.newAttrValList= attributeValues;
@@ -1729,4 +1870,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