| | |
| | | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.alibaba.fastjson.serializer.SerializerFeature; |
| | | import com.vci.base.ui.exception.VCIException; |
| | | import com.vci.corba.common.VCIError; |
| | | import com.vci.corba.framework.data.UserEntityInfo; |
| | | import com.vci.rmip.framework.client.systemConfig.object.UserEntityObject; |
| | | import com.vci.client.bof.ClientBusinessObject; |
| | | import com.vci.client.bof.ClientLinkObject; |
| | | import com.vci.client.common.objects.UserEntityObject; |
| | | import com.vci.common.exception.VciException; |
| | | import com.vci.corba.common.PLException; |
| | | import com.vci.corba.common.data.UserEntityInfo; |
| | | import com.vci.corba.omd.data.AttributeValue; |
| | | import com.vci.corba.omd.data.BusinessObject; |
| | | import com.vci.corba.omd.data.LinkObject; |
| | | import com.vci.starter.revision.bo.TreeWrapperOptions; |
| | | import com.vci.starter.web.annotation.*; |
| | | import com.vci.starter.web.constant.QueryOptionConstant; |
| | |
| | | import com.vci.starter.web.util.*; |
| | | import com.vci.starter.web.wrapper.VciQueryWrapperForDO; |
| | | import com.vci.web.pageModel.*; |
| | | import com.vci.web.properties.WebProperties; |
| | | import com.vci.web.service.impl.WebLoServiceImpl; |
| | | import net.sf.jsqlparser.parser.CCJSqlParserUtil; |
| | | import net.sf.jsqlparser.statement.select.PlainSelect; |
| | | import net.sf.jsqlparser.statement.select.SelectItem; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | | import org.springframework.util.CollectionUtils; |
| | | import plm.bs.bom.clientobject.ClientBusinessObject; |
| | | import plm.bs.bom.clientobject.ClientLinkObject; |
| | | import plm.bs.bom.common.AttributeValue; |
| | | import plm.bs.bom.common.BusinessObject; |
| | | import plm.bs.bom.common.LinkObject; |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import java.beans.IntrospectionException; |
| | |
| | | if (e == null) { |
| | | return errContent; |
| | | } |
| | | if (e instanceof VCIError ) { |
| | | if (e instanceof PLException ) { |
| | | // String error_code = ((VCIError) e).error_code; |
| | | // String[] error_message = ((VCIError) e).error_message; |
| | | // return MessageUtils.get(error_code, error_message); |
| | | return null; |
| | | } else if(e instanceof VciBaseException || e.getClass().getSuperclass().equals(VciBaseException.class)){ |
| | | return LangBaseUtil.getErrorMsg(e); |
| | | }else if (e instanceof VCIException){ |
| | | String error_code = ((VCIException) e).getException_code(); |
| | | Object[] error_message = ((VCIException) e).getException_objArray(); |
| | | }else if (e instanceof VciException){ |
| | | String error_code = ((VciException) e).getCode(); |
| | | Object[] error_message = ((VciException) e).getObjArray(); |
| | | return MessageUtils.get(error_code, error_message); |
| | | }else if (e.getCause() != null |
| | | && !e.getCause().toString().equals("")) { |
| | |
| | | public static UserEntityInfo getUserEntityInfo(String model){ |
| | | SessionInfo si = WebUtil.getCurrentUserSessionInfo(); |
| | | UserEntityInfo ueo = new UserEntityInfo(); |
| | | ueo.ip = si.getIp(); |
| | | // ueo.ip = si.getIp(); |
| | | ueo.modules = model; |
| | | ueo.userName = si.getUserId(); |
| | | return ueo; |
| | |
| | | public static UserEntityObject getUserEntityObject(String model) { |
| | | UserEntityObject entityObject = new UserEntityObject(); |
| | | SessionInfo si = WebUtil.getCurrentUserSessionInfo(); |
| | | entityObject.setIp(si.getIp()); |
| | | // entityObject.setIp(si.getIp()); |
| | | entityObject.setModules(model); |
| | | entityObject.setUserName(si.getUserId()); |
| | | return entityObject; |
| | |
| | | * @param cbo 业务数据 |
| | | * @param obj 对象 |
| | | */ |
| | | public static void copyValueToObjectFromCbos(ClientBusinessObject cbo,Object obj){ |
| | | public static void copyValueToObjectFromCbos(com.vci.client.bof.ClientBusinessObject cbo,Object obj){ |
| | | if(cbo!=null){ |
| | | copyValueToObjectFromBos(cbo.getBusinessObject(),obj); |
| | | } |
| | |
| | | * @param obj 对象 |
| | | * @param fieldAttrMap 属性映射 |
| | | */ |
| | | public static void copyValueToObjectFromCbos(ClientBusinessObject cbo,Object obj,Map<String,String> fieldAttrMap){ |
| | | public static void copyValueToObjectFromCbos(com.vci.client.bof.ClientBusinessObject cbo,Object obj,Map<String,String> fieldAttrMap){ |
| | | if(cbo!=null){ |
| | | copyValueToObjectFromBos(cbo.getBusinessObject(),obj,fieldAttrMap); |
| | | } |
| | |
| | | * @param bo 业务数据 |
| | | * @param obj 对象 |
| | | */ |
| | | public static void copyValueToObjectFromBos(BusinessObject bo ,Object obj){ |
| | | public static void copyValueToObjectFromBos(com.vci.corba.omd.data.BusinessObject bo ,Object obj){ |
| | | copyValueToObjectFromBos(bo,obj,null); |
| | | } |
| | | |
| | |
| | | * @param obj 对象 |
| | | * @param fieldAttrMap 属性映射 |
| | | */ |
| | | public static void copyValueToObjectFromBos(BusinessObject bo ,Object obj,Map<String,String> fieldAttrMap){ |
| | | public static void copyValueToObjectFromBos(com.vci.corba.omd.data.BusinessObject bo , Object obj, Map<String,String> fieldAttrMap){ |
| | | if(bo!=null && obj != null){ |
| | | //先把所有的字段映射找到 |
| | | if(fieldAttrMap == null){ |
| | | fieldAttrMap = getFieldNameMap(obj.getClass()); |
| | | } |
| | | AttributeValue[] newAList = bo.newAttrValList; |
| | | AttributeValue[] hisAList = bo.hisAttrValList; |
| | | com.vci.corba.omd.data.AttributeValue[] newAList = bo.newAttrValList; |
| | | com.vci.corba.omd.data.AttributeValue[] hisAList = bo.hisAttrValList; |
| | | //要先把BO对象上的值拷贝过去 |
| | | List<Field> boFields = getAllFieldForObj(bo.getClass()); |
| | | |
| | |
| | | } |
| | | if(newAList!=null&&newAList.length>0){ |
| | | for(int i = 0 ; i < newAList.length;i++){ |
| | | AttributeValue av = newAList[i]; |
| | | com.vci.corba.omd.data.AttributeValue av = newAList[i]; |
| | | String attrName = av.attrName.toLowerCase(); |
| | | if(fieldAttrMap.containsKey(attrName)) { |
| | | String fieldName = fieldAttrMap.get(attrName); |
| | |
| | | } |
| | | if(hisAList!=null&&hisAList.length>0){ |
| | | for(int i = 0 ; i < hisAList.length;i++){ |
| | | AttributeValue av = hisAList[i]; |
| | | com.vci.corba.omd.data.AttributeValue av = hisAList[i]; |
| | | String attrName = av.attrName.toLowerCase(); |
| | | String fieldName = fieldAttrMap.get(attrName); |
| | | if(fieldName!=null){ |
| | |
| | | * @param cbo 业务数据 |
| | | * @param map map |
| | | */ |
| | | public static void copyValueToMapFromCbos(ClientBusinessObject cbo,Map<String,String> map){ |
| | | public static void copyValueToMapFromCbos(com.vci.client.bof.ClientBusinessObject cbo,Map<String,String> map){ |
| | | if(cbo!=null){ |
| | | copyValueToMapFromBos(cbo.getBusinessObject(),map); |
| | | } |
| | |
| | | * @param bo 业务数据 |
| | | * @param map map |
| | | */ |
| | | public static void copyValueToMapFromBos(BusinessObject bo,Map<String,String> map){ |
| | | public static void copyValueToMapFromBos(com.vci.corba.omd.data.BusinessObject bo, Map<String,String> map){ |
| | | if(bo!=null ){ |
| | | //先把所有的字段映射找到 |
| | | AttributeValue[] newAList = bo.newAttrValList; |
| | | AttributeValue[] hisAList = bo.hisAttrValList; |
| | | com.vci.corba.omd.data.AttributeValue[] newAList = bo.newAttrValList; |
| | | com.vci.corba.omd.data.AttributeValue[] hisAList = bo.hisAttrValList; |
| | | if(hisAList!=null&&hisAList.length>0){// |
| | | for(int i = 0 ; i < hisAList.length;i++){ |
| | | AttributeValue av = hisAList[i]; |
| | | com.vci.corba.omd.data.AttributeValue av = hisAList[i]; |
| | | String attrName = av.attrName.toLowerCase(); |
| | | map.put(attrName, av.attrVal); |
| | | } |
| | | } |
| | | if(newAList!=null&&newAList.length>0){//NEW的优先级高些 |
| | | for(int i = 0 ; i < newAList.length;i++){ |
| | | AttributeValue av = newAList[i]; |
| | | com.vci.corba.omd.data.AttributeValue av = newAList[i]; |
| | | String attrName = av.attrName.toLowerCase(); |
| | | map.put(attrName, av.attrVal); |
| | | } |
| | |
| | | * @param clo 链接类型 |
| | | * @param map map |
| | | */ |
| | | public static void copyValueToMapFromClos(ClientLinkObject clo,Map<String,String> map){ |
| | | public static void copyValueToMapFromClos(com.vci.client.bof.ClientLinkObject clo,Map<String,String> map){ |
| | | if(clo!=null){ |
| | | copyValueToMapFromLos(clo.getLinkObject(),map); |
| | | } |
| | |
| | | * @param lo 链接类型 |
| | | * @param map map |
| | | */ |
| | | public static void copyValueToMapFromLos(LinkObject lo,Map<String,String> map){ |
| | | public static void copyValueToMapFromLos(com.vci.corba.omd.data.LinkObject lo,Map<String,String> map){ |
| | | if(lo!=null){ |
| | | WebLoServiceImpl.LO_BASE_FIELD_MAP.forEach((field,attr)->{ |
| | | map.put(attr.toLowerCase(),getValueFromFieldForCbo(getFieldForObject(field,lo),lo)); |
| | | }); |
| | | //先把所有的字段映射找到 |
| | | AttributeValue[] newAList = lo.newAttrValList; |
| | | AttributeValue[] hisAList = lo.hisAttrValList; |
| | | com.vci.corba.omd.data.AttributeValue[] newAList = lo.newAttrValList; |
| | | com.vci.corba.omd.data.AttributeValue[] hisAList = lo.hisAttrValList; |
| | | if(hisAList!=null&&hisAList.length>0){ |
| | | for(int i = 0 ; i < hisAList.length;i++){ |
| | | AttributeValue av = hisAList[i]; |
| | | com.vci.corba.omd.data.AttributeValue av = hisAList[i]; |
| | | String attrName = av.attrName.toLowerCase(); |
| | | map.put(attrName, av.attrVal); |
| | | } |
| | | } |
| | | if(newAList!=null&&newAList.length>0){ |
| | | for(int i = 0 ; i < newAList.length;i++){ |
| | | AttributeValue av = newAList[i]; |
| | | com.vci.corba.omd.data.AttributeValue av = newAList[i]; |
| | | String attrName = av.attrName.toLowerCase(); |
| | | map.put(attrName, av.attrVal); |
| | | } |
| | |
| | | * @param obj 对象 |
| | | * @param fieldAttrMap 属性map |
| | | */ |
| | | public static void copyValueToObjectFromLos(LinkObject lo ,Object obj,Map<String,String> fieldAttrMap){ |
| | | public static void copyValueToObjectFromLos(LinkObject lo , Object obj, Map<String,String> fieldAttrMap){ |
| | | if(lo!=null && obj != null){ |
| | | //先把所有的字段映射找到 |
| | | if(fieldAttrMap == null){ |
| | |
| | | * @param cbo 链接类型 |
| | | * @param map 对象 |
| | | */ |
| | | public static void copyValueToCboFromMap(ClientBusinessObject cbo,Map<String,String> map) throws VciBaseException{ |
| | | public static void copyValueToCboFromMap(com.vci.client.bof.ClientBusinessObject cbo,Map<String,String> map) throws VciBaseException{ |
| | | if(map!=null){ |
| | | Iterator<String> it = map.keySet().iterator(); |
| | | while(it.hasNext()){ |
| | |
| | | setValueToField(key, cbo, value); |
| | | } |
| | | cbo.setAttributeValueWithNoCheck(key.toLowerCase(), value); |
| | | } catch (VCIError e) { |
| | | } catch (PLException e) { |
| | | throw WebUtil.getVciBaseException(e); |
| | | } |
| | | } |
| | |
| | | }else { |
| | | clo.setAttributeValue(key.toLowerCase(), value); |
| | | } |
| | | } catch (VCIError e) { |
| | | } catch (PLException e) { |
| | | throw WebUtil.getVciBaseException(e); |
| | | } |
| | | } |
| | |
| | | setValueToField(fieldName, cbo, value); |
| | | } |
| | | cbo.setAttributeValue(attrName.toLowerCase(), value); |
| | | } catch (VCIError e) { |
| | | } catch (PLException e) { |
| | | throw WebUtil.getVciBaseException(e); |
| | | } |
| | | } |
| | |
| | | * @param e 异常对象 |
| | | * @return base异常对象 |
| | | */ |
| | | public static VciBaseException getVciBaseException(VCIError e){ |
| | | // return new VciBaseException(e.error_code, e.error_message); |
| | | return null; |
| | | // public static VciBaseException getVciBaseException(PLException e){ |
| | | //// return new VciBaseException(e.error_code, e.error_message); |
| | | // return null; |
| | | // } |
| | | |
| | | /** |
| | | * 转换异常 |
| | | * @param e 异常对象 |
| | | * @return base异常对象 |
| | | */ |
| | | public static VciBaseException getVciBaseException(PLException e){ |
| | | return new VciBaseException(e.code, new java.lang.String[]{e.getMessage()}); |
| | | // return null; |
| | | } |
| | | |
| | | /** |
| | |
| | | * @param e 异常对象 |
| | | * @return base异常对象 |
| | | */ |
| | | public static VciBaseException getVciBaseException(VCIException e){ |
| | | public static VciBaseException getVciBaseException(VciException e){ |
| | | String[] errorMsgs = new String[0]; |
| | | if(e != null && e.getException_objArray() !=null ){ |
| | | errorMsgs = new String[e.getException_objArray().length]; |
| | | if(e != null && e.getObjArray() !=null ){ |
| | | errorMsgs = new String[e.getObjArray().length]; |
| | | for(int i = 0 ; i < errorMsgs.length ; i ++){ |
| | | errorMsgs[i] = e.getException_objArray()[i].toString(); |
| | | errorMsgs[i] = e.getObjArray()[i].toString(); |
| | | } |
| | | } |
| | | return new VciBaseException(e == null ?"com.vci.web.base.unknowerror":e.getException_code(), errorMsgs); |
| | | return new VciBaseException(e == null ?"com.vci.web.base.unknowerror":e.getCode(), errorMsgs); |
| | | } |
| | | |
| | | /** |
| | |
| | | * @param wrapperOptions 封装的信息 |
| | | * @return 树列表 |
| | | */ |
| | | public static <T,R> List<Tree> cboList2Trees(List<? extends ClientBusinessObject> doList, TreeWrapperOptions wrapperOptions, Function<T,R> f){ |
| | | public static <T,R> List<Tree> cboList2Trees(List<? extends com.vci.client.bof.ClientBusinessObject> doList, TreeWrapperOptions wrapperOptions, Function<T,R> f){ |
| | | if(CollectionUtils.isEmpty(doList)){ |
| | | return new ArrayList<>(); |
| | | } |
| | | List<Tree> allTree = new ArrayList<Tree>(); |
| | | List<Tree> children = new ArrayList<Tree>(); |
| | | for (int i = 0 ; i < doList.size();i++) { |
| | | ClientBusinessObject cbo = doList.get(i); |
| | | com.vci.client.bof.ClientBusinessObject cbo = doList.get(i); |
| | | Tree tree =new Tree(); |
| | | List<String> oidFieldNames = VciBaseUtil.str2List(wrapperOptions.getOidFieldName()); |
| | | List<String> oidValues = new LinkedList<>(); |
| | |
| | | new Tree().findChild(allTree,children); |
| | | return allTree; |
| | | } |
| | | |
| | | public static com.vci.client.bof.ClientBusinessObject arryAndSqlToClientBusinessObject(String sqlStr,String[] valueArry) { |
| | | com.vci.client.bof.ClientBusinessObject clientBusinessObject = new com.vci.client.bof.ClientBusinessObject(); |
| | | try { |
| | | PlainSelect select = (PlainSelect) CCJSqlParserUtil.parse(sqlStr); |
| | | com.vci.corba.omd.data.AttributeValue[] attributeValues = new com.vci.corba.omd.data.AttributeValue[valueArry.length]; |
| | | for (int i = 0; i < select.getSelectItems().size(); i++) { |
| | | SelectItem selectItem = select.getSelectItem(i); |
| | | com.vci.corba.omd.data.AttributeValue attributeValue = new com.vci.corba.omd.data.AttributeValue(); |
| | | attributeValue.attrName = selectItem.getAlias().getName(); |
| | | attributeValue.attrVal = valueArry[i]; |
| | | attributeValues[i] = attributeValue; |
| | | } |
| | | clientBusinessObject.getBusinessObject().newAttrValList= attributeValues; |
| | | }catch (Exception e){ |
| | | logger.error("数据解析错误",e); |
| | | return null; |
| | | } |
| | | return clientBusinessObject; |
| | | } |
| | | } |