VoHelper
VoHelper
package com.isoftstone.pcis.policy.core.helper;
import com.isoftstone.fwk.dao.CommonDao;
import com.isoftstone.fwk.service.BusinessServiceException;
import com.isoftstone.fwk.util.BeanTool;
import com.isoftstone.fwk.util.SpringUtils;
import com.isoftstone.pcis.policy.core.exception.VoManipulateException;
import com.isoftstone.pcis.policy.vo.AbstractCvrgVO;
import com.isoftstone.pcis.prod.exception.ProductDefinitionException;
import com.isoftstone.pcis.prod.service.ProdService;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.beanutils.PropertyUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.time.DateUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
public class VoHelper
{
public static String VO_TYPE_APP = "App";
public static String VO_TYPE_PLY = "Ply";
public static String ELEMENT_NAME = "Name";
public static String ELEMENT_CAPTION = "Caption";
public static String ELEMENT_NAME_PRODEF = "CNmeEn";
public static String ELEMENT_CAPTION_PRODEF = "CNmeCn";
private static final Log logger = LogFactory.getLog(VoHelper.class);
private static String voPkg = "com.isoftstone.pcis.policy.vo";
private static String voUdrPkg = "com.isoftstone.pcis.policy.app.underwrite.vo";
public static Class getVoClass(String componentName, String voType) {
String className = voPkg + "." + getVoClassName(componentName, voType);
try {
return Class.forName(className);
}
catch (ClassNotFoundException e) {
e.printStackTrace();
}return null;
}
public static Class getAppVoClass(String componentName)
{
String className = voPkg + "." + getAppVoClassName(componentName);
try {
return Class.forName(className);
} catch (ClassNotFoundException e) {
logger.error("Class.forName(" + className + ") 出现异常。");
}return null;
}
public static Class getPlyVoClass(String componentName)
{
String className = voPkg + "." + getPlyVoClassName(componentName);
try {
return Class.forName(className);
} catch (ClassNotFoundException e) {
logger.error("Class.forName(" + className + ") 出现异常。");
}return null;
}
public static Class getUdrVoClass(String componentName)
{
String className = voUdrPkg + "." + getUdrVoClassName(componentName);
try {
return Class.forName(className);
} catch (ClassNotFoundException e) {
logger.error("Class.forName(" + className + ") 出现异常。");
}return null;
}
public static Object createAppEntryVo(String componentName)
{
Class c = getAppVoClass(componentName);
try {
if (c != null) {
return c.newInstance();
}
return null;
} catch (InstantiationException e) {
logger.error(e.getMessage());
return null;
} catch (IllegalAccessException e) {
logger.error(e.getMessage());
}return null;
}
public static Object createPlyEntryVo(String componentName)
{
Class c = getPlyVoClass(componentName);
try {
if (c != null) {
return c.newInstance();
}
return null;
} catch (InstantiationException e) {
logger.error(e.getMessage());
return null;
} catch (IllegalAccessException e) {
logger.error(e.getMessage());
}return null;
}
public static Object createUdrEntryVo(String componentName)
{
Class c = getUdrVoClass(componentName);
try {
if (c != null) {
return c.newInstance();
}
return null;
} catch (InstantiationException e) {
logger.error(e.getMessage());
return null;
} catch (IllegalAccessException e) {
logger.error(e.getMessage());
}return null;
}
public static String getVoClassName(String componentName, String voType)
{
return voType + componentName + "VO";
}
public static String getAppVoClassName(String componentName)
{
return "App" + componentName + "VO";
}
public static String getPlyVoClassName(String componentName)
{
return "Ply" + componentName + "VO";
}
public static String getUdrVoClassName(String componentName)
{
return "Undr" + componentName + "VO";
}
public static String getComponentNameOfVo(Object entry)
{
String[] pathArray = entry.getClass().getName().split("\\.");
String voName = pathArray[(pathArray.length - 1)];
String featureName = null;
if ((voName.matches("^App")) || (!voName.matches("VO$")))
featureName = voName.replaceAll("^App", "").replaceAll("VO$", "");
else if ((voName.matches("^Ply")) || (!voName.matches("VO$"))) {
featureName = voName.replaceAll("^Ply", "").replaceAll("VO$", "");
}
return featureName;
}
public static void serializePlyVo() {
CommonDao dao = (CommonDao)SpringUtils.getSpringBean("commonDao");
}
public static boolean hasPkId(Object vo) throws VoManipulateException
{
try {
Map propertyMap = BeanUtils.describe(vo);
if (propertyMap.containsKey("CPkId")) {
return true;
}
return false;
}
catch (Exception e) {
throw new VoManipulateException("判断vo是否有CPkId字段时出错", e);
}
}
public static String getOrigPkId(Object vo)
throws VoManipulateException
{
try
{
String origRowId = BeanUtils.getProperty(vo, "CRowId");
if (origRowId != null) {
return origRowId;
}
return BeanUtils.getProperty(vo, "CPkId");
}
catch (Exception e)
{
throw new VoManipulateException("获得vo[" + vo.getClass().getName() + "]原始id时出错", e);
}
}
public static Long getSeqNoIgnoreException(Object vo) {
try {
return (Long)PropertyUtils.getProperty(vo, "NSeqNo");
} catch (Exception e) {
logger.warn("忽略获得seqno时出错");
}return null;
}
public static Map<String, Map<String, Object>> compareEntry(Object oldEntry, Object newEntry, Set<String> propSet)
throws VoManipulateException
{
try
{
propSet.remove("class");
Map diffMap = new HashMap();
for (String propName : propSet) {
Object oldValue = PropertyUtils.getProperty(oldEntry, propName);
Object newValue = PropertyUtils.getProperty(newEntry, propName);
if ((oldValue != null) || (newValue != null))
{
if ((oldValue != null) && (newValue != null))
{
if ((oldValue instanceof Date)) {
if (DateUtils.isSameDay((Date)oldValue, (Date)newValue)) {
continue;
}
}
else {
if ((oldValue instanceof Double) ?
Double.compare(((Double)oldValue).doubleValue(), ((Double)newValue).doubleValue()) == 0 :
oldValue.equals(newValue))
{
continue;
}
}
}
Map diff = new HashMap();
diff.put("old", oldValue);
diff.put("new", newValue);
diffMap.put(propName, diff);
}
}
return diffMap;
} catch (Exception e) {
throw new VoManipulateException("比较失败", e);
}
}
public static Map<String, Map<String, Object>> compareEntryEx(Object oldEntry, Object newEntry, Set<String> excludePropSet)
throws VoManipulateException
{
try
{
Map propMap = BeanUtils.describe(oldEntry);
Set propSet = new HashSet();
propSet.addAll((Collection)propMap.keySet());
propSet.removeAll(excludePropSet);
return compareEntry(oldEntry, newEntry, propSet);
} catch (Exception e) {
throw new VoManipulateException("比较失败", e);
}
}
public static Map<String, Map<String, Object>> compareEntry(Object oldEntry, Object newEntry)
throws VoManipulateException
{
try
{
Map propMap = BeanUtils.describe(oldEntry);
Set propSet = new HashSet();
propSet.addAll((Collection)propMap.keySet());
return compareEntry(oldEntry, newEntry, propSet);
} catch (Exception e) {
throw new VoManipulateException("比较失败", e);
}
}
public static List<String> getKeyNameList(String prodNo, String componentName)
throws ProductDefinitionException
{
try
{
ProdService prodService = (ProdService)SpringUtils.getSpringBean("prodService");
return prodService.getProdEleNmeEn(prodNo, componentName);
} catch (BusinessServiceException e) {
throw new ProductDefinitionException("获得保单要素分类关键字异常", e);
}
}
public static List<String> getCoverageKeyNameList(String prodNo, String cvrgNo)
throws ProductDefinitionException
{
try
{
ProdService prodService = (ProdService)SpringUtils.getSpringBean("prodService");
return prodService.getProdEleNmeEn(prodNo, "Cvrg",
cvrgNo);
} catch (BusinessServiceException e) {
throw new ProductDefinitionException("获得保单要素分类关键字异常", e);
}
}
public static List<Map<String, String>> getKeyNameCaptionMapList(String prodNo, String componentName)
throws ProductDefinitionException
{
try
{
ProdService prodService = (ProdService)SpringUtils.getSpringBean("prodService");
List elemNameMapList = prodService.getProdEleNme(prodNo, componentName, null);
List nameLabelMapList = new ArrayList();
for (Map elemNameMap : elemNameMapList) {
String complexName = (String)elemNameMap.get("CNmeEn");
String[] nameSects = complexName.split("\\.");
Map nameLabelMap = new HashMap();
nameLabelMap.put(ELEMENT_NAME_PRODEF, nameSects[1]);
nameLabelMap.put(ELEMENT_CAPTION_PRODEF, (String)elemNameMap.get(ELEMENT_CAPTION_PRODEF));
nameLabelMap.put(ELEMENT_NAME, nameSects[1]);
nameLabelMap.put(ELEMENT_CAPTION, (String)elemNameMap.get(ELEMENT_CAPTION_PRODEF));
nameLabelMapList.add(nameLabelMap);
}
return nameLabelMapList;
} catch (BusinessServiceException e) {
throw new ProductDefinitionException("获得保单要素分类关键字异常", e);
}
}
public static List<Map<String, String>> getCoverageKeyNameCaptionMapList(String prodNo, String cvrgNo)
throws ProductDefinitionException
{
try
{
ProdService prodService = (ProdService)SpringUtils.getSpringBean("prodService");
List elemNameMapList = prodService.getProdEleNme(prodNo,
"Cvrg", cvrgNo);
List nameLabelMapList = new ArrayList();
for (Map elemNameMap : elemNameMapList) {
String complexName = (String)elemNameMap.get("CNmeEn");
String[] nameSects = complexName.split("\\.");
Map nameLabelMap = new HashMap();
nameLabelMap.put(ELEMENT_NAME_PRODEF, nameSects[1]);
nameLabelMap.put(ELEMENT_CAPTION_PRODEF, (String)elemNameMap.get(ELEMENT_CAPTION_PRODEF));
nameLabelMap.put(ELEMENT_NAME, nameSects[1]);
nameLabelMap.put(ELEMENT_CAPTION, (String)elemNameMap.get(ELEMENT_CAPTION_PRODEF));
nameLabelMapList.add(nameLabelMap);
}
return nameLabelMapList;
} catch (BusinessServiceException e) {
throw new ProductDefinitionException("获得保单要素分类关键字异常", e);
}
}
public static String getKeyValueAsStr(Object entry, List<String> keyNameList)
throws VoManipulateException
{
try
{
if ((keyNameList != null) && (!keyNameList.isEmpty())) {
String[] elemValues = new String[keyNameList.size()];
for (int i = 0; i < keyNameList.size(); i++) {
String attrName = ((String)keyNameList.get(i)).substring(
((String)keyNameList.get(i)).indexOf(".") + 1);
String aValue = BeanTool.getAttributeValueAsString(entry, attrName);
elemValues[i] = aValue;
}
return StringUtils.join(elemValues, "-%-");
}
if ((entry instanceof AbstractCvrgVO)) {
return ((AbstractCvrgVO)entry).getCCvrgNo();
}
Long seqNo = getSeqNoIgnoreException(entry);
if (seqNo != null) {
return seqNo.toString();
}
return null;
}
catch (Exception e)
{
throw new VoManipulateException("生成要素关键标识描述时异常", e);
}
}
}
VoHelper的更多相关文章
随机推荐
- AWS 之Load Balance篇
public class CreateELB { /// <summary> /// 连接AWS服务器 /// </summary> /// <param name=&q ...
- UVa 11107 (后缀数组 二分) Life Forms
利用height值对后缀进行分组的方法很常用,好吧,那就先记下了. 题意: 给出n个字符串,求一个长度最大的字符串使得它在超过一半的字符串中出现. 多解的话,按字典序输出全部解. 分析: 在所有输入的 ...
- poj 3694 pku 3694 Network tarjan求割边 lca
题意:给你一个连通图,然后再给你n个询问,每个询问给一个点u,v表示加上u,v之后又多少个桥.一个最容易想到的办法就是先加边找桥,加边找桥,这样可定超时.那么就可以缩点,因为如果一条边不是桥那么无论怎 ...
- UVa 400 Unix Is
题意:给出n个字符串,按照字典序排列,再按照规则输出. ===学习的紫书,题目意思很清楚,求列数和行数最开始看的时候木有看懂啊啊啊 列数:即为(60-M)/(M+2)+1;即为先将最后那一列减去,算普 ...
- BZOJ 3306 树
dfs序建线段树+分类讨论+写的有点长. #include<iostream> #include<cstdio> #include<cstring> #includ ...
- Python [Leetcode 141]Linked List Cycle
题目描述: Given a linked list, determine if it has a cycle in it. 解题思路: 快的指针和慢的指针 代码如下: # Definition for ...
- Javascript高级程序设计
根据叶小钗同学的建议,觉得有必要去读读Javascript高级程序设计,不想装B,只想仔细读读,源代码参考. 偶第一个想法,就是去读面向对象和事件那块,不仅关键,而且是薄弱点儿,所以必须去干掉这个短板 ...
- bootstrap-datetimepicker时间控件
欢迎各种吐槽. 本人小前端,学习过程中,某日遇到做时间控件的需求,于是无休止的召唤了度娘,发现看不太懂.算是为自己做个笔记,也便于菜鸟级别的看的懂. 首先,我们看看点击选择时间的时候的展示页面吧 年 ...
- 看来ms sql server if 中定义个变量出了if 还是可以用的
begin declare @abc int; end print @abc 可以打出1出来
- php 实现 jsonp 数据接口
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 3 ...