759 lines
30 KiB
Java
759 lines
30 KiB
Java
package com.amarsoft.app.util;
|
||
|
||
import java.io.FileOutputStream;
|
||
import java.util.ArrayList;
|
||
import java.util.HashMap;
|
||
import java.util.Iterator;
|
||
import java.util.List;
|
||
import java.util.Map;
|
||
import java.util.Map.Entry;
|
||
import java.util.Set;
|
||
|
||
import net.sf.json.JSONArray;
|
||
import net.sf.json.JSONNull;
|
||
import net.sf.json.JSONObject;
|
||
|
||
import org.apache.commons.lang3.StringUtils;
|
||
import org.dom4j.Document;
|
||
import org.dom4j.Element;
|
||
import org.dom4j.io.OutputFormat;
|
||
import org.dom4j.io.SAXReader;
|
||
import org.dom4j.io.XMLWriter;
|
||
|
||
import jbo.prd.PRD_SPECIFIC_LIBRARY;
|
||
import jbo.sys.LB_PRODUCT_INFO;
|
||
|
||
import com.amarsoft.app.als.prd.config.loader.ProductConfig;
|
||
import com.amarsoft.app.base.businessobject.BusinessObject;
|
||
import com.amarsoft.app.base.businessobject.BusinessObjectHelper;
|
||
import com.amarsoft.app.base.util.XMLHelper;
|
||
import com.amarsoft.are.jbo.BizObject;
|
||
import com.amarsoft.are.jbo.BizObjectManager;
|
||
import com.amarsoft.are.jbo.JBOException;
|
||
import com.amarsoft.are.jbo.JBOFactory;
|
||
|
||
public class ProductParamUtil {
|
||
|
||
/**
|
||
* 传入产品编号、组件类型编号和参数编号,返回参数对应的值
|
||
* @param productId 产品编号
|
||
* @param componentType 组件类型编号
|
||
* @param parameterId 传入产品编号
|
||
* @return 参数对应的值
|
||
* @throws Exception
|
||
* @author zhulh
|
||
*/
|
||
public static String getProductParameterValue(String productId,String componentType,String parameterId) throws Exception{
|
||
String parameterValue = "";
|
||
String realXmlPath = getProductValueXmlBySql(productId);
|
||
//List<BusinessObject> componentList = XMLHelper.getBusinessObjectList(realXmlPath,"Component||Status='1'","ID");
|
||
//List<BusinessObject> exists = BusinessObjectHelper.getBusinessObjectsBySql(componentList, "Type like :Type", "Type",componentType);
|
||
List<BusinessObject> exists = getBusinessObject(realXmlPath, componentType);
|
||
if(exists.size()==0){
|
||
return parameterValue;
|
||
}
|
||
List<BusinessObject> parameters = exists.get(0).getBusinessObjects("Parameter");
|
||
for(BusinessObject boP:parameters){
|
||
if(parameterId.equals(boP.getString("PARAMETERID"))){
|
||
if(boP.containsAttribute("OPTIONALVALUE")){
|
||
parameterValue = boP.getString("OPTIONALVALUE");
|
||
}else if(boP.containsAttribute("MANDATORYVALUE")){
|
||
parameterValue = boP.getString("MANDATORYVALUE");
|
||
}else if(boP.containsAttribute("VALUE")){
|
||
parameterValue = boP.getString("VALUE");
|
||
}
|
||
}
|
||
}
|
||
return parameterValue;
|
||
}
|
||
|
||
/**
|
||
* 传入产品编号、组件类型编号和参数编号,返回参数对应的最大值
|
||
* @param productId 参数编号
|
||
* @param componentType 组件类型编号
|
||
* @param parameterId 传入产品编号
|
||
* @return 参数对应的最大值
|
||
* @throws Exception
|
||
* @author zhulh
|
||
*/
|
||
public static String getProductParameterMaxValue(String productId,String componentType,String parameterId) throws Exception{
|
||
String parameterValue = "";
|
||
String realXmlPath = getProductValueXmlBySql(productId);
|
||
//List<BusinessObject> componentList = XMLHelper.getBusinessObjectList(realXmlPath,"Component||Status='1'","ID");
|
||
//List<BusinessObject> exists = BusinessObjectHelper.getBusinessObjectsBySql(componentList, "Type like :Type", "Type",componentType);
|
||
List<BusinessObject> exists = getBusinessObject(realXmlPath, componentType);
|
||
if(exists.size()==0){
|
||
return parameterValue;
|
||
}
|
||
List<BusinessObject> parameters = exists.get(0).getBusinessObjects("Parameter");
|
||
for(BusinessObject boP:parameters){
|
||
if(parameterId.equals(boP.getString("PARAMETERID"))){
|
||
if(boP.containsAttribute("MAXIMUMVALUE")){
|
||
parameterValue = boP.getString("MAXIMUMVALUE");
|
||
}
|
||
}
|
||
}
|
||
return parameterValue;
|
||
}
|
||
|
||
/**
|
||
* 传入产品编号、组件类型编号和参数编号,返回参数对应的最小值
|
||
* @param productId 参数编号
|
||
* @param componentType 组件类型编号
|
||
* @param parameterId 传入产品编号
|
||
* @return 参数对应的最小值
|
||
* @throws Exception
|
||
* @author zhulh
|
||
*/
|
||
public static String getProductParameterMinValue(String productId,String componentType,String parameterId) throws Exception{
|
||
String parameterValue = "";
|
||
String realXmlPath = getProductValueXmlBySql(productId);
|
||
//List<BusinessObject> componentList = XMLHelper.getBusinessObjectList(realXmlPath,"Component||Status='1'","ID");
|
||
//List<BusinessObject> exists = BusinessObjectHelper.getBusinessObjectsBySql(componentList, "Type like :Type", "Type",componentType);
|
||
List<BusinessObject> exists = getBusinessObject(realXmlPath, componentType);
|
||
if(exists.size()==0){
|
||
return parameterValue;
|
||
}
|
||
List<BusinessObject> parameters = exists.get(0).getBusinessObjects("Parameter");
|
||
for(BusinessObject boP:parameters){
|
||
if(parameterId.equals(boP.getString("PARAMETERID"))){
|
||
if(boP.containsAttribute("MINIMUMVALUE")){
|
||
parameterValue = boP.getString("MINIMUMVALUE");
|
||
}
|
||
}
|
||
}
|
||
return parameterValue;
|
||
}
|
||
|
||
/**
|
||
* 传入产品编号和组件类别编号,将组件参数封装进map返回
|
||
* @param productId 产品编号
|
||
* @param componentType 组件类别编号
|
||
* @return 组件对应数据的MAP
|
||
* @throws Exception
|
||
* @author zhulh
|
||
*/
|
||
public static Map<String,Map<String,String>> getProductComponentType(String productId,String componentType) throws Exception{
|
||
Map<String,Map<String,String>> productComponent = new HashMap<String,Map<String,String>>();
|
||
String realXmlPath = getProductValueXmlBySql(productId);
|
||
//List<BusinessObject> componentList = XMLHelper.getBusinessObjectList(realXmlPath,"Component||Status='1'","ID");
|
||
/*List<BusinessObject> exists = new ArrayList<BusinessObject>();
|
||
BizObjectManager bomLPI = JBOFactory.getBizObjectManager(LB_PRODUCT_INFO.CLASS_NAME);
|
||
BizObject boLPI = bomLPI.createQuery("ID=:ID").setParameter("ID", realXmlPath).getSingleResult(true);
|
||
String pData = boLPI.getAttribute("PRODUCT_DATA").getString();
|
||
String type = componentType;
|
||
if("".equals(pData)){
|
||
}else{
|
||
JSONArray jsonArray = JSONArray.fromObject(pData);
|
||
Iterator<JSONObject> it = jsonArray.iterator();
|
||
while(it.hasNext()){
|
||
JSONObject jo = (JSONObject)it.next().get("jbo.sample.Component");
|
||
if(type.equals(jo.get("TYPE"))){
|
||
JSONArray ja = JSONArray.fromObject(jo.get("Parameter"));
|
||
BusinessObject b = BusinessObject.createBusinessObject("Component");
|
||
b.setAttributes(jo);
|
||
BusinessObject[] bos = new BusinessObject[ja.size()];
|
||
for(int i=0;i<bos.length;i++){
|
||
BusinessObject bValue = BusinessObject.createBusinessObject("Parameter");
|
||
bValue.setAttributes(ja.getJSONObject(i).getJSONObject("jbo.sample.Parameter"));
|
||
bos[i] = bValue;
|
||
}
|
||
b.setAttributeValue("Parameter", bos);
|
||
exists.add(b);
|
||
break;
|
||
}
|
||
}
|
||
}*/
|
||
//List<BusinessObject> exists = BusinessObjectHelper.getBusinessObjectsBySql(componentList, "Type like :Type", "Type",componentType);
|
||
List<BusinessObject> exists = getBusinessObject(realXmlPath, componentType);
|
||
if(exists.size()==0){
|
||
return productComponent;
|
||
}
|
||
for(BusinessObject bo:exists){
|
||
List<BusinessObject> parameters = bo.getBusinessObjects("Parameter");
|
||
if("ExpenseType".equals(bo.getString("ID"))){
|
||
continue;
|
||
}
|
||
Map<String,String> parameValue = new HashMap<String,String>();
|
||
for(BusinessObject boP:parameters){
|
||
String parameterValue = "";
|
||
String parameterValueMax = "";
|
||
String parameterValueMin = "";
|
||
if(boP.containsAttribute("OPTIONALVALUE")){
|
||
parameterValue = boP.getString("OPTIONALVALUE");
|
||
}else if(boP.containsAttribute("MANDATORYVALUE")){
|
||
parameterValue = boP.getString("MANDATORYVALUE");
|
||
}else if(boP.containsAttribute("VALUE")){
|
||
parameterValue = boP.getString("VALUE");
|
||
}
|
||
if(boP.containsAttribute("MAXIMUMVALUE")){
|
||
parameterValueMax = boP.getString("MAXIMUMVALUE");
|
||
}
|
||
if(boP.containsAttribute("MINIMUMVALUE")){
|
||
parameterValueMin = boP.getString("MINIMUMVALUE");
|
||
}
|
||
parameValue.put(boP.getString("PARAMETERID"), parameterValue);
|
||
if(!"".equals(parameterValueMax)){
|
||
parameValue.put(boP.getString("PARAMETERID")+"-MAX", parameterValueMax);
|
||
}
|
||
if(!"".equals(parameterValueMin)){
|
||
parameValue.put(boP.getString("PARAMETERID")+"-MIN", parameterValueMin);
|
||
}
|
||
}
|
||
productComponent.put(bo.getString("ID"), parameValue);
|
||
}
|
||
return productComponent;
|
||
}
|
||
|
||
/**
|
||
* 传入产品编号、组件类别编号和参数编号,将组件参数封装进map返回
|
||
* @param productId 产品编号
|
||
* @param componentType 组件类别编号
|
||
* @return 组件对应单个参数的MAP
|
||
* @throws Exception
|
||
* @author zhulh
|
||
*/
|
||
public static Map<String,Map<String,String>> getProductComponentTypeOneParam(String productId,String componentType,String parameterId) throws Exception{
|
||
Map<String,Map<String,String>> productComponent = new HashMap<String,Map<String,String>>();
|
||
String realXmlPath = getProductValueXmlBySql(productId);
|
||
//List<BusinessObject> componentList = XMLHelper.getBusinessObjectList(realXmlPath,"Component||Status='1'","ID");
|
||
//List<BusinessObject> exists = BusinessObjectHelper.getBusinessObjectsBySql(componentList, "Type like :Type", "Type",componentType);
|
||
List<BusinessObject> exists = getBusinessObject(realXmlPath, componentType);
|
||
if(exists.size()==0){
|
||
return productComponent;
|
||
}
|
||
for(BusinessObject bo:exists){
|
||
List<BusinessObject> parameters = bo.getBusinessObjects("Parameter");
|
||
if("ExpenseType".equals(bo.getString("ID"))){
|
||
continue;
|
||
}
|
||
Map<String,String> parameValue = new HashMap<String,String>();
|
||
for(BusinessObject boP:parameters){
|
||
String parameterValue = "";
|
||
String parameterValueMax = "";
|
||
String parameterValueMin = "";
|
||
if(parameterId.equals(boP.getString("PARAMETERID"))){
|
||
if(boP.containsAttribute("OPTIONALVALUE")){
|
||
parameterValue = boP.getString("OPTIONALVALUE");
|
||
}else if(boP.containsAttribute("MANDATORYVALUE")){
|
||
parameterValue = boP.getString("MANDATORYVALUE");
|
||
}else if(boP.containsAttribute("VALUE")){
|
||
parameterValue = boP.getString("VALUE");
|
||
}
|
||
if(boP.containsAttribute("MAXIMUMVALUE")){
|
||
parameterValueMax = boP.getString("MAXIMUMVALUE");
|
||
}
|
||
if(boP.containsAttribute("MINIMUMVALUE")){
|
||
parameterValueMin = boP.getString("MINIMUMVALUE");
|
||
}
|
||
parameValue.put(boP.getString("PARAMETERID"), parameterValue);
|
||
if(!"".equals(parameterValueMax)){
|
||
parameValue.put(boP.getString("PARAMETERID")+"-MAX", parameterValueMax);
|
||
}
|
||
if(!"".equals(parameterValueMin)){
|
||
parameValue.put(boP.getString("PARAMETERID")+"-MIN", parameterValueMin);
|
||
}
|
||
}
|
||
}
|
||
productComponent.put(bo.getString("ID"), parameValue);
|
||
}
|
||
return productComponent;
|
||
}
|
||
|
||
/**
|
||
* 获取资料清单数据
|
||
* @param productId 产品编号
|
||
* @param componentType 组件编号
|
||
* @throws Exception
|
||
*/
|
||
public static List<Object> getProductDocInfo(String productId,String componentType) throws Exception{
|
||
List<Object> docInfo = new ArrayList<Object>();
|
||
String realXmlPath = getProductValueXmlBySql(productId);
|
||
/*BizObjectManager bomLPI = JBOFactory.getBizObjectManager(LB_PRODUCT_INFO.CLASS_NAME);
|
||
BizObject boLPI = bomLPI.createQuery("ID=:ID").setParameter("ID", realXmlPath).getSingleResult(true);
|
||
String pData = boLPI.getAttribute("PRODUCT_DATA").getString();*/
|
||
String pData = ProductConfig.getProductData(realXmlPath);
|
||
String type = componentType;
|
||
if(StringUtils.isEmpty(pData)){
|
||
}else{
|
||
JSONArray jsonArray = JSONArray.fromObject(pData);
|
||
Iterator<JSONObject> it = jsonArray.iterator();
|
||
JSONArray docList = null;
|
||
JSONArray docGroupConfig = null;
|
||
while(it.hasNext()){
|
||
JSONObject jo = it.next().getJSONObject("jbo.sample.Component");
|
||
if(type.equals(jo.get("TYPE"))){
|
||
docList = JSONArray.fromObject(jo.get("DecisionTable"));
|
||
}
|
||
if("PRD0413".equals(jo.get("TYPE"))){
|
||
docGroupConfig = JSONArray.fromObject(jo.get("DecisionTable"));
|
||
}
|
||
}
|
||
if(docList.size() != 0){
|
||
for(int i=0;i<docList.size();i++){
|
||
JSONObject jObject = docList.getJSONObject(i);
|
||
JSONObject decisionTable = jObject.getJSONObject("jbo.sample.DecisionTable");
|
||
String docType = decisionTable.optString("VALUE_TYPE");
|
||
String id = decisionTable.optString("ID");
|
||
if("SingleRow".equals(docType)){
|
||
Map<String,String> singleRow = new HashMap<String,String>();
|
||
singleRow.put("FLOW_INFO", decisionTable.optString("VALUE_FLOW_INFO"));
|
||
singleRow.put("DOCLIST", decisionTable.optString("OPTIONALVALUE_DOCLIST"));
|
||
singleRow.put("TYPE", decisionTable.optString("VALUE_TYPE"));
|
||
docInfo.add(singleRow);
|
||
}else if("Combination".equals(docType)){
|
||
Map<String,Object> combination = new HashMap<String,Object>();
|
||
List<Map<String,String>> d = new ArrayList<Map<String,String>>();
|
||
combination.put("FLOW_INFO", decisionTable.optString("VALUE_FLOW_INFO"));
|
||
combination.put("TYPE", decisionTable.optString("VALUE_TYPE"));
|
||
if(docGroupConfig != null){
|
||
for(int j=0;j<docGroupConfig.size();j++){
|
||
Map<String,String> docconfig = new HashMap<String,String>();
|
||
JSONObject dgcObj = docGroupConfig.getJSONObject(j);
|
||
JSONObject dgcValue = dgcObj.getJSONObject("jbo.sample.DecisionTable");
|
||
String dgcId = dgcValue.optString("ID");
|
||
if(dgcId.startsWith(id)){
|
||
docconfig.put("DOCNO", dgcValue.optString("OPTIONALVALUE_DOCLIST"));
|
||
docconfig.put("MAINTYPE", dgcValue.optString("VALUE_MAINTYPE"));
|
||
docconfig.put("POSITION", dgcValue.optString("VALUE_POSITION"));
|
||
}else{
|
||
continue;
|
||
}
|
||
d.add(docconfig);
|
||
}
|
||
}
|
||
combination.put("DOCCONFIG", d);
|
||
docInfo.add(combination);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
/*SAXReader reader = new SAXReader();
|
||
Document doc = reader.read(realXmlPath);
|
||
List<Element> component = doc.selectNodes("//Component[@TYPE='"+componentType+"']");
|
||
for(Element e:component){
|
||
Element el = e.element("DecisionTables");
|
||
List<Element> ets = el.elements("DecisionTable");
|
||
for(Element et:ets){
|
||
String docType = et.attributeValue("VALUE_TYPE");
|
||
if("SingleRow".equals(docType)){
|
||
Map<String,String> singleRow = new HashMap<String,String>();
|
||
singleRow.put("FLOW_INFO", et.attributeValue("VALUE_FLOW_INFO"));
|
||
singleRow.put("DOCLIST", et.attributeValue("OPTIONALVALUE_DOCLIST"));
|
||
singleRow.put("TYPE", et.attributeValue("VALUE_TYPE"));
|
||
docInfo.add(singleRow);
|
||
}else if("Combination".equals(docType)){
|
||
Map<String,Object> combination = new HashMap<String,Object>();
|
||
List<Map<String,String>> d = new ArrayList<Map<String,String>>();
|
||
combination.put("FLOW_INFO", et.attributeValue("VALUE_FLOW_INFO"));
|
||
combination.put("TYPE", et.attributeValue("VALUE_TYPE"));
|
||
List<Element> subComponent = doc.selectNodes("//Component[@TYPE='PRD0413']");
|
||
for(Element sc:subComponent){
|
||
Element sel = sc.element("DecisionTables");
|
||
List<Element> sets = sel.elements("DecisionTable");
|
||
int n = 1;
|
||
for(Element set:sets){
|
||
Map<String,String> docconfig = new HashMap<String,String>();
|
||
if(set.attributeValue("ID").startsWith(et.attributeValue("ID"))){
|
||
docconfig.put("DOCNO", set.attributeValue("OPTIONALVALUE_DOCLIST"));
|
||
docconfig.put("MAINTYPE", set.attributeValue("VALUE_MAINTYPE"));
|
||
docconfig.put("POSITION", set.attributeValue("VALUE_POSITION"));
|
||
}else{
|
||
continue;
|
||
}
|
||
d.add(docconfig);
|
||
n++;
|
||
}
|
||
}
|
||
combination.put("DOCCONFIG", d);
|
||
docInfo.add(combination);
|
||
}
|
||
}
|
||
}*/
|
||
return docInfo;
|
||
}
|
||
|
||
/**
|
||
* 删除决策组的数据
|
||
* @param productId
|
||
* @param componentType
|
||
* @param id
|
||
* @throws Exception
|
||
*/
|
||
public static void removeProductParame(String productId,String componentType,String id) throws Exception{
|
||
String realXmlPath = getProductValueXml(productId);
|
||
SAXReader reader = new SAXReader();
|
||
Document doc = reader.read(realXmlPath);
|
||
List<Element> component = doc.selectNodes("//Component[@TYPE='"+componentType+"']");
|
||
for(Element e:component){
|
||
Element el = e.element("DecisionTables");
|
||
List<Element> ets = el.elements("DecisionTable");
|
||
for(Element et:ets){
|
||
if(et.attributeValue("ID").startsWith(id)){
|
||
el.remove(et);
|
||
}
|
||
}
|
||
}
|
||
OutputFormat xmlFormat = OutputFormat.createPrettyPrint();
|
||
xmlFormat.setEncoding("GBK");
|
||
XMLWriter writer = new XMLWriter(new FileOutputStream(realXmlPath),xmlFormat);
|
||
writer.write(doc);
|
||
writer.close();
|
||
}
|
||
|
||
/**
|
||
* 传入产品编号和组件类别编号,将参数组封装进map返回
|
||
* @param productId 产品编号
|
||
* @param componentType 组件类别编号
|
||
* @return 组件对应数据的MAP
|
||
* @throws Exception
|
||
* @author zhulh
|
||
*/
|
||
public static Map<String,List<Map<String,String>>> getProductComponentDecisionTable(String productId,String componentType,String... paramNames) throws Exception{
|
||
Map<String,List<Map<String,String>>> productComponent = new HashMap<String,List<Map<String,String>>>();
|
||
String realXmlPath = getProductValueXmlBySql(productId);
|
||
//List<BusinessObject> componentList = XMLHelper.getBusinessObjectList(realXmlPath,"Component||Status='1'","ID");
|
||
//List<BusinessObject> exists = BusinessObjectHelper.getBusinessObjectsBySql(componentList, "Type like :Type", "Type",componentType);
|
||
List<BusinessObject> exists = getBusinessObjectWithDecisionTable(realXmlPath,componentType);
|
||
if(exists.size()==0){
|
||
return productComponent;
|
||
}
|
||
for(BusinessObject bo:exists){
|
||
List<BusinessObject> parameters = bo.getBusinessObjects("DecisionTable");
|
||
if("ExpenseType".equals(bo.getString("ID"))){
|
||
continue;
|
||
}
|
||
List<Map<String,String>> parameValues = new ArrayList<Map<String,String>>();
|
||
for(BusinessObject boP:parameters){
|
||
Map<String,String> parameValue = new HashMap<String,String>();
|
||
String paramValue = "";
|
||
for(String paramName : paramNames) {
|
||
if(boP.containsAttribute("OPTIONALVALUE_"+(paramName.toUpperCase()))){
|
||
paramValue = boP.getString("OPTIONALVALUE_"+(paramName.toUpperCase()));
|
||
}else if(boP.containsAttribute("VALUE_"+(paramName.toUpperCase()))){
|
||
paramValue = boP.getString("VALUE_"+(paramName.toUpperCase()));
|
||
}else if(boP.containsAttribute("MANDATORYVALUE_"+(paramName.toUpperCase()))){
|
||
paramValue = boP.getString("MANDATORYVALUE_"+(paramName.toUpperCase()));
|
||
} else {
|
||
paramValue = boP.getString(paramName.toUpperCase());
|
||
}
|
||
parameValue.put(paramName, paramValue);
|
||
}
|
||
parameValues.add(parameValue);
|
||
}
|
||
productComponent.put(bo.getString("ID"), parameValues);
|
||
}
|
||
return productComponent;
|
||
}
|
||
|
||
/**
|
||
* 传入产品编号、组件类型编号和组件ID,寻找唯一参数的值
|
||
* @param productId 产品编号
|
||
* @param componentType 组件类型编号
|
||
* @param id 对应组件的ID
|
||
* @param parameterId 传入参数ID
|
||
* @return 参数对应的值
|
||
* @throws Exception
|
||
* @author zhulh
|
||
*/
|
||
public static String getProductParameterValue(String productId,String componentType,String id,String parameterId) throws Exception{
|
||
/*String realXmlPath = getProductValueXml(productId);
|
||
String parameterValue = "";
|
||
SAXReader reader = new SAXReader();
|
||
Document doc = reader.read(realXmlPath);
|
||
List<Element> component = doc.selectNodes("//Component[@TYPE='"+componentType+"' and @ID='"+id+"']");
|
||
for(Element e:component){
|
||
Element el = e.element("Parameters");
|
||
List<Element> ets = el.elements("Parameter");
|
||
for(Element et:ets){
|
||
if(parameterId.equals(et.attributeValue("PARAMETERID"))){
|
||
if(et.attribute("OPTIONALVALUE") != null){
|
||
parameterValue = et.attributeValue("OPTIONALVALUE");
|
||
}else if(et.attribute("MANDATORYVALUE") != null){
|
||
parameterValue = et.attributeValue("MANDATORYVALUE");
|
||
}else if(et.attribute("VALUE") != null){
|
||
parameterValue = et.attributeValue("VALUE");
|
||
}
|
||
}
|
||
}
|
||
}*/
|
||
String parameterValue = "";
|
||
String realXmlPath = getProductValueXmlBySql(productId);
|
||
/*BizObjectManager bomLPI = JBOFactory.getBizObjectManager(LB_PRODUCT_INFO.CLASS_NAME);
|
||
BizObject boLPI = bomLPI.createQuery("ID=:ID").setParameter("ID", realXmlPath).getSingleResult(true);
|
||
String pData = boLPI.getAttribute("PRODUCT_DATA").getString();*/
|
||
String pData = ProductConfig.getProductData(realXmlPath);
|
||
String type = componentType;
|
||
if(StringUtils.isEmpty(pData)){
|
||
}else{
|
||
JSONArray jsonArray = JSONArray.fromObject(pData);
|
||
Iterator<JSONObject> it = jsonArray.iterator();
|
||
JSONArray param = null;
|
||
while(it.hasNext()){
|
||
JSONObject jo = it.next().getJSONObject("jbo.sample.Component");
|
||
if(type.equals(jo.get("TYPE")) && id.equals(jo.get("ID"))){
|
||
param = JSONArray.fromObject(jo.get("Parameter"));
|
||
}
|
||
}
|
||
if(param != null){
|
||
for(int i=0;i<param.size();i++){
|
||
JSONObject obj = param.getJSONObject(i);
|
||
JSONObject valueObj = obj.getJSONObject("jbo.sample.Parameter");
|
||
String paramId = valueObj.optString("PARAMETERID");
|
||
if(parameterId.equals(paramId)){
|
||
parameterValue = valueObj.optString("VALUE");
|
||
}
|
||
}
|
||
}
|
||
}
|
||
return parameterValue;
|
||
}
|
||
|
||
/**
|
||
* 传入产品编号、组件类型编号和组件ID,返回单个组件所有参数
|
||
* @param productId 产品编号
|
||
* @param componentType 组件类型编号
|
||
* @param id 对应组件的ID
|
||
* @return 参数对应的值
|
||
* @throws Exception
|
||
* @author zhulh
|
||
*/
|
||
public static Map<String,String> getProductComponentAllParameters(String productId,String componentType,String id) throws Exception{
|
||
Map<String,String> parameValue = new HashMap<String,String>();
|
||
String realXmlPath = getProductValueXmlBySql(productId);
|
||
//List<BusinessObject> componentList = XMLHelper.getBusinessObjectList(realXmlPath,"Component||Status='1'","ID");
|
||
/*List<BusinessObject> exists = new ArrayList<BusinessObject>();
|
||
BizObjectManager bomLPI = JBOFactory.getBizObjectManager(LB_PRODUCT_INFO.CLASS_NAME);
|
||
BizObject boLPI = bomLPI.createQuery("ID=:ID").setParameter("ID", realXmlPath).getSingleResult(true);
|
||
String pData = boLPI.getAttribute("PRODUCT_DATA").getString();
|
||
String type = componentType;
|
||
if("".equals(pData)){
|
||
}else{
|
||
JSONArray jsonArray = JSONArray.fromObject(pData);
|
||
Iterator<JSONObject> it = jsonArray.iterator();
|
||
while(it.hasNext()){
|
||
JSONObject jo = (JSONObject)it.next().get("jbo.sample.Component");
|
||
if(type.equals(jo.get("TYPE"))){
|
||
JSONArray ja = JSONArray.fromObject(jo.get("Parameter"));
|
||
BusinessObject b = BusinessObject.createBusinessObject("Component");
|
||
b.setAttributes(jo);
|
||
BusinessObject[] bos = new BusinessObject[ja.size()];
|
||
for(int i=0;i<bos.length;i++){
|
||
BusinessObject bValue = BusinessObject.createBusinessObject("Parameter");
|
||
bValue.setAttributes(ja.getJSONObject(i).getJSONObject("jbo.sample.Parameter"));
|
||
bos[i] = bValue;
|
||
}
|
||
b.setAttributeValue("Parameter", bos);
|
||
exists.add(b);
|
||
break;
|
||
}
|
||
}
|
||
}*/
|
||
//List<BusinessObject> exists = BusinessObjectHelper.getBusinessObjectsBySql(componentList, "Type like :Type", "Type",componentType);
|
||
List<BusinessObject> exists = getBusinessObject(realXmlPath, componentType);
|
||
if(exists.size()==0){
|
||
return parameValue;
|
||
}
|
||
for(BusinessObject bo:exists){
|
||
List<BusinessObject> parameters = bo.getBusinessObjects("Parameter");
|
||
if(!id.equals(bo.getString("ID"))){
|
||
continue;
|
||
}
|
||
for(BusinessObject boP:parameters){
|
||
String parameterValue = "";
|
||
String parameterValueMax = "";
|
||
String parameterValueMin = "";
|
||
if(boP.containsAttribute("OPTIONALVALUE")){
|
||
parameterValue = boP.getString("OPTIONALVALUE");
|
||
}else if(boP.containsAttribute("MANDATORYVALUE")){
|
||
parameterValue = boP.getString("MANDATORYVALUE");
|
||
}else if(boP.containsAttribute("VALUE")){
|
||
parameterValue = boP.getString("VALUE");
|
||
}
|
||
if(boP.containsAttribute("MAXIMUMVALUE")){
|
||
parameterValueMax = boP.getString("MAXIMUMVALUE");
|
||
}
|
||
if(boP.containsAttribute("MINIMUMVALUE")){
|
||
parameterValueMin = boP.getString("MINIMUMVALUE");
|
||
}
|
||
parameValue.put(boP.getString("PARAMETERID"), parameterValue);
|
||
if(!"".equals(parameterValueMax)){
|
||
parameValue.put(boP.getString("PARAMETERID")+"-MAX", parameterValueMax);
|
||
}
|
||
if(!"".equals(parameterValueMin)){
|
||
parameValue.put(boP.getString("PARAMETERID")+"-MIN", parameterValueMin);
|
||
}
|
||
}
|
||
if(!parameValue.isEmpty()) {
|
||
break;
|
||
}
|
||
}
|
||
return parameValue;
|
||
}
|
||
|
||
/**
|
||
* 获取五级分类结果
|
||
* @param productId
|
||
* @param overDays
|
||
* @param paramName1
|
||
* @param paramName2
|
||
* @return
|
||
* @throws Exception
|
||
*/
|
||
public static String getFiveGradeClassification (String productId, String overDays, String paramName1,String paramName2) throws Exception{
|
||
String realXmlPath = getProductValueXmlBySql(productId);
|
||
//List<BusinessObject> componentList = XMLHelper.getBusinessObjectList(realXmlPath,"Component||Status='1'","ID");
|
||
//List<BusinessObject> exists = BusinessObjectHelper.getBusinessObjectsBySql(componentList, "Type like :Type", "Type","PRD0201");
|
||
List<BusinessObject> exists = getBusinessObject(realXmlPath, "PRD0201");
|
||
String result="";
|
||
if(exists.size()==0){
|
||
return result;
|
||
}
|
||
for(BusinessObject bo:exists){
|
||
List<BusinessObject> parameters = bo.getBusinessObjects("DecisionTable");
|
||
if("ExpenseType".equals(bo.getString("ID"))){
|
||
continue;
|
||
}
|
||
for(BusinessObject boP:parameters){
|
||
String maxDays = "";
|
||
String minDays = "";
|
||
if(boP.containsAttribute("MINIMUMVALUE_"+(paramName1.toUpperCase()))){
|
||
minDays = boP.getString("MINIMUMVALUE_"+(paramName1.toUpperCase()));
|
||
}else if(boP.containsAttribute("MINIMUMVALUE_"+(paramName2.toUpperCase()))){
|
||
minDays = boP.getString("MINIMUMVALUE_"+(paramName2.toUpperCase()));
|
||
}
|
||
if(boP.containsAttribute("MAXIMUMVALUE_"+(paramName1.toUpperCase()))){
|
||
maxDays = boP.getString("MAXIMUMVALUE_"+(paramName1.toUpperCase()));
|
||
}else if(boP.containsAttribute("MAXIMUMVALUE_"+(paramName2.toUpperCase()))){
|
||
maxDays = boP.getString("MAXIMUMVALUE_"+(paramName2.toUpperCase()));
|
||
}
|
||
if(Integer.parseInt(minDays)<=Integer.parseInt(overDays)&& Integer.parseInt(maxDays)>=Integer.parseInt(overDays)){
|
||
if(boP.containsAttribute("VALUE_"+(paramName1.toUpperCase()))){
|
||
result = boP.getString("VALUE_"+(paramName1.toUpperCase()));
|
||
}else if(boP.containsAttribute("VALUE_"+(paramName2.toUpperCase()))){
|
||
result = boP.getString("VALUE_"+(paramName2.toUpperCase()));
|
||
}
|
||
return result;
|
||
}
|
||
}
|
||
}
|
||
return result;
|
||
}
|
||
/**
|
||
* 传入产品编号,获取产品对应XML路径
|
||
* @param productId 产品编号
|
||
* @return 产品对应XML路径
|
||
* @throws JBOException
|
||
* @author zhulh
|
||
*/
|
||
public static String getProductValueXmlBySql(String productId) throws JBOException{
|
||
/*BizObject bo = JBOFactory.getBizObjectManager(PRD_SPECIFIC_LIBRARY.CLASS_NAME).createQuery("productid=:ProductId").setParameter("ProductId", productId).getSingleResult(false);
|
||
String realXmlPath = "";
|
||
if(bo != null){
|
||
//String path = ProductParamUtil.class.getResource("/").toString();
|
||
String configfile = bo.getAttribute("configfile").toString();
|
||
if(path.startsWith("file:/home")){
|
||
path = path.substring(5, path.length()-9);
|
||
}else{
|
||
path = path.substring(6, path.length()-9);
|
||
}
|
||
//realXmlPath = path+configfile.substring(configfile.indexOf("/"));
|
||
realXmlPath = configfile;
|
||
}*/
|
||
return productId;
|
||
}
|
||
|
||
public static String getProductValueXml(String productId) throws JBOException{
|
||
BizObject bo = JBOFactory.getBizObjectManager(PRD_SPECIFIC_LIBRARY.CLASS_NAME).createQuery("productid=:ProductId").setParameter("ProductId", productId).getSingleResult(false);
|
||
String realXmlPath = "";
|
||
if(bo != null){
|
||
String path = ProductParamUtil.class.getResource("/").toString();
|
||
String configfile = bo.getAttribute("configfile").toString();
|
||
if(path.startsWith("file:/home")){
|
||
path = path.substring(5, path.length()-9);
|
||
}else{
|
||
path = path.substring(6, path.length()-9);
|
||
}
|
||
realXmlPath = path+configfile.substring(configfile.indexOf("/"));
|
||
}
|
||
return realXmlPath;
|
||
}
|
||
|
||
public static List<BusinessObject> getBusinessObject(String realXmlPath,String componentType) throws Exception{
|
||
List<BusinessObject> exists = new ArrayList<BusinessObject>();
|
||
//BizObjectManager bomLPI = JBOFactory.getBizObjectManager(LB_PRODUCT_INFO.CLASS_NAME);
|
||
//BizObject boLPI = bomLPI.createQuery("ID=:ID").setParameter("ID", realXmlPath).getSingleResult(true);
|
||
//String pData = boLPI.getAttribute("PRODUCT_DATA").getString();
|
||
//切换读取缓存
|
||
String pData = ProductConfig.getProductData(realXmlPath);
|
||
String type = componentType;
|
||
if(StringUtils.isEmpty(pData)){
|
||
}else{
|
||
JSONArray jsonArray = JSONArray.fromObject(pData);
|
||
Iterator<JSONObject> it = jsonArray.iterator();
|
||
while(it.hasNext()){
|
||
JSONObject jo = it.next().getJSONObject("jbo.sample.Component");
|
||
if(type.equals(jo.get("TYPE"))){
|
||
JSONArray ja = JSONArray.fromObject(jo.get("Parameter"));
|
||
BusinessObject b = BusinessObject.createBusinessObject("Component");
|
||
b.setAttributes(jo);
|
||
BusinessObject[] bos = new BusinessObject[ja.size()];
|
||
for(int i=0;i<ja.size();i++){
|
||
if(ja.get(i) instanceof JSONNull){
|
||
continue;
|
||
}
|
||
JSONObject value = ja.getJSONObject(i).getJSONObject("jbo.sample.Parameter");
|
||
Map<String,Object> valMap = new HashMap<String,Object>();
|
||
Set<Entry> vSet = value.entrySet();
|
||
for(Entry v:vSet){
|
||
valMap.put(v.getKey().toString(), v.getValue());
|
||
}
|
||
bos[i] = BusinessObject.createBusinessObject("jbo.sample.Parameter",valMap);
|
||
}
|
||
b.setAttributeValue("Parameter", bos);
|
||
exists.add(b);
|
||
}
|
||
}
|
||
}
|
||
return exists;
|
||
}
|
||
|
||
public static List<BusinessObject> getBusinessObjectWithDecisionTable(String realXmlPath,String componentType) throws Exception{
|
||
List<BusinessObject> exists = new ArrayList<BusinessObject>();
|
||
/*BizObjectManager bomLPI = JBOFactory.getBizObjectManager(LB_PRODUCT_INFO.CLASS_NAME);
|
||
BizObject boLPI = bomLPI.createQuery("ID=:ID").setParameter("ID", realXmlPath).getSingleResult(true);
|
||
String pData = boLPI.getAttribute("PRODUCT_DATA").getString();*/
|
||
String pData = ProductConfig.getProductData(realXmlPath);
|
||
String type = componentType;
|
||
if(StringUtils.isEmpty(pData)){
|
||
}else{
|
||
JSONArray jsonArray = JSONArray.fromObject(pData);
|
||
Iterator<JSONObject> it = jsonArray.iterator();
|
||
while(it.hasNext()){
|
||
JSONObject jo = it.next().getJSONObject("jbo.sample.Component");
|
||
if(type.equals(jo.get("TYPE"))){
|
||
JSONArray ja = JSONArray.fromObject(jo.get("DecisionTable"));
|
||
BusinessObject b = BusinessObject.createBusinessObject("Component");
|
||
b.setAttributes(jo);
|
||
BusinessObject[] bos = new BusinessObject[ja.size()];
|
||
for(int i=0;i<ja.size();i++){
|
||
if(ja.get(i) instanceof JSONNull){
|
||
continue;
|
||
}
|
||
JSONObject value = ja.getJSONObject(i).getJSONObject("jbo.sample.DecisionTable");
|
||
Map<String,Object> valMap = new HashMap<String,Object>();
|
||
Set<Entry> vSet = value.entrySet();
|
||
for(Entry v:vSet){
|
||
valMap.put(v.getKey().toString(), v.getValue());
|
||
}
|
||
bos[i] = BusinessObject.createBusinessObject("jbo.sample.DecisionTable",valMap);
|
||
}
|
||
b.setAttributeValue("DecisionTable", bos);
|
||
exists.add(b);
|
||
}
|
||
}
|
||
}
|
||
return exists;
|
||
}
|
||
}
|