NC开发笔记——中常用到的公共工具类PubUtils

package bos.vo.pub.tools;

 

import java.lang.reflect.Array;

import java.lang.reflect.InvocationTargetException;

import java.math.BigDecimal;

import java.sql.PreparedStatement;

import java.sql.SQLException;

import java.sql.Types;

import java.text.ParseException;

import java.text.SimpleDateFormat;

import java.util.ArrayList;

import java.util.Calendar;

import java.util.Collection;

import java.util.Date;

import java.util.Enumeration;

import java.util.HashMap;

import java.util.HashSet;

import java.util.Hashtable;

import java.util.Iterator;

import java.util.List;

import java.util.Map;

import java.util.Vector;

 

import nc.bs.framework.common.NCLocator;

import nc.bs.framework.common.RuntimeEnv;

import nc.bs.logging.Logger;

import nc.itf.uap.busibean.ISysInitQry;

import nc.vo.pub.AggregatedValueObject;

import nc.vo.pub.BusinessException;

import nc.vo.pub.CircularlyAccessibleValueObject;

import nc.vo.pub.lang.UFBoolean;

import nc.vo.pub.lang.UFDate;

import nc.vo.pub.lang.UFDateTime;

import nc.vo.pub.lang.UFDouble;

import nc.vo.pub.lang.UFTime;

import nc.vo.pub.query.ConditionVO;

import bos.vo.pub.BOSEnv;

import bos.vo.pub.ScaleKey;

import bos.vo.pub.ScaleValue;

import bos.vo.pub.bill.BOSLightBillVO;

import bos.vo.pub.constant.BosStatusConst;

import bos.vo.pub.constant.PubResBase;

import bos.vo.pub.smart.SmartFieldMeta;

import bos.vo.pub.smart.SmartVO;

import bos.vo.pub.smart.SmartVODataUtils;

import bos.vo.pub.smart.SmartVOMeta;

 

/**

*

*

* <b>公共工具类Public</b>

*

* <ul>

* <li>

* </ul>

*

*

*

*

* @version 1.0

* @since 1.0

* @author 王松涛

* @time 2010-8-21 下午01:33:45

*/

public class PubUtils {

 

       public enum BillAction {

               New, Update, Delete, Audit, CancelAudit

       };

 

       public static final String GENERALCOMPANY = "1001"; // 总公司

 

       public final static String EQ = "="; // 等于

       public final static String BG = ">"; // 大于

       public final static String BQ = ">="; // 大于等于

       public final static String LE = "<"; // 小于

       public final static String LQ = "<="; // 小于等于

       public final static String NQ = "!="; // 不等于

       public final static String DQ = "=="; // 双等于

       public final static String IN = "in";

 

       // 空

       static public String STRING_NULL = "_________N/A________";

 

       // ==============UFDouble

       // 0.0

       public static final UFDouble ZERO = new UFDouble(0.0);

       // 1.0

       public static final UFDouble ONE_UFDOUBLE = new UFDouble(1.0);

       // -1.0

       public static final UFDouble NEGONE_UFDOUBLE = new UFDouble(-1.0);

       // 100.0

       public static final UFDouble HUNDRED_UFDOUBLE = new UFDouble(100.0);

       // ==============Integer

       // 0

       public static final Integer ZERO_INTEGER = Integer.valueOf(0);

       // 1

       public static final Integer ONE_INTEGER = Integer.valueOf(1);

       // ==============Boolean

       public static final UFBoolean UFBOOLEAN_TRUE = new UFBoolean(true);

       public static final UFBoolean UFBOOLEAN_FALSE = new UFBoolean(false);

 

       // 因数据库中可以插入的最大值为12+8,因此对小数点前的位数加入限制

       public static final UFDouble MIN_13DIGIT_NUM = new UFDouble(1000000000000.00);

 

       // 0应税内含 1应税外加 2不计税

       public static final Integer IDISCOUNTTAXTYPE_INNER = Integer.valueOf(0);

       public static final Integer IDISCOUNTTAXTYPE_OUTTER = Integer.valueOf(1);

       public static final Integer IDISCOUNTTAXTYPE_NOCOUNT = Integer.valueOf(2);

 

       /**

        * 数组类型转换 <b>参数说明</b>

        *

        * @param <T>

        *          需要转换的类型

        * @param <O>

        *          被转换的类型

        * @param objs

        *          被转换的数组

        * @param clazz

        *          需要转换的类型的class

        * @return

        * @since 1.0

        * @author 蒋力

        * @time 2010-10-29 上午11:39:50

        */

       @SuppressWarnings("unchecked")

       public static <T, O extends Object> T[] arrayTypeConvert(O[] objs, Class<T> clazz) {

               T[] ts = (T[]) Array.newInstance(clazz, objs.length);

               for (int i = 0; i < objs.length; i++) {

                       ts[i] = (T) objs[i];

               }

               return ts;

       }

 

       public static String getIDISCOUNTTAXTYPE_NAME_INNER() {

               return "应税内含";

       }

 

       public static String getIDISCOUNTTAXTYPE_NAME_OUTTER() {

               return "应税外加";

       }

 

       public static String getIDISCOUNTTAXTYPE_NAME_NOCOUNT() {

               return "不计税";

       }

 

       /**

        *

        * 判断是否传入公司主键是总公司

        *

        * <b>参数说明</b>

        *

        * @param pk_corp

        * @return

        * @since 1.0

        * @author 王松涛

        * @time 2010-9-15 下午01:56:48

        */

       public static Boolean isGeneralCompany(String pk_corp) throws BusinessException {

               if (PubUtils.isNull(pk_corp)) {

                       PubUtils.newBusinessException(PubResBase.getParasErrorByMethodName("isGeneralCompany"));

               }

               if (GENERALCOMPANY.equals(pk_corp)) {

                       return true;

               }

               return false;

       }

 

       // 汇率、金额的最大位数

       public static final int MAXDIGIT_EXCHANGERATE = 8;

       public static final int MAXDIGIT_MONEY = 8;

 

       // normalSize是分组长度:每个Sql语句中OR条件长度

       public static final int NORMAL_SIZE = 40;

 

       // DR

       public static final Integer DR_ZERO = ZERO_INTEGER;

       public static final Integer DR_ONE = ONE_INTEGER;

 

       /**

        * 作者:zjp 功能:根据一个对象的值得到UFBoolean的值,如果为空,返回用户指定的FALSE或TRUE 参数:Object value 对象值

        * 返回:UFBoolean UFBoolean的值 例外:无 日期:(2009-09-02 11:39:21) 修改日期,修改人,修改原因,注释标志:

        */

       public static UFBoolean getUFBoolean_NullAs(Object value, UFBoolean bDefaultValue) {

               if (value == null || value.toString().trim().equals("")) {

                       return bDefaultValue;

               } else if (value instanceof UFBoolean) {

                       return (UFBoolean) value;

               } else {

                       return new UFBoolean(value.toString().trim());

               }

       }

 

       /**

        * 作者:zjp 功能:根据一个对象的值得到UFDate的值,如果为空,返回空 参数:Object value 对象值 返回:UFDate

        * UFDate的值 例外:无 日期:(2009-04-02 11:39:21) 修改日期,修改人,修改原因,注释标志:

        */

       public static UFDate getUFDate(Object value) {

               if (value == null || value.toString().trim().equals("")) {

                       return null;

               } else if (value instanceof UFDate) {

                       return (UFDate) value;

               } else {

                       return new UFDate(value.toString().trim());

               }

       }

 

       /**

        * 作者:zjp 功能:根据一个对象的值得到UFDate的值,如果为空,返回空 参数:Object value 对象值 返回:UFDate

        * UFDate的值 例外:无 日期:(2009-04-02 11:39:21) 修改日期,修改人,修改原因,注释标志:

        */

       public static UFDateTime getUFDateTime(Object value) {

               if (value == null || value.toString().trim().equals("")) {

                       return null;

               } else if (value instanceof UFDateTime) {

                       return (UFDateTime) value;

               } else {

                       return new UFDateTime(value.toString().trim());

               }

       }

 

       /**

        * 作者:zjp 功能:根据一个对象的值得到UFDate的值,如果为空,返回空 参数:Object value 对象值 返回:UFDate

        * UFDate的值 例外:无 日期:(2009-04-02 11:39:21) 修改日期,修改人,修改原因,注释标志:

        */

       public static UFTime getUFTime(Object value) {

               if (value == null || value.toString().trim().equals("")) {

                       return null;

               } else if (value instanceof UFTime) {

                       return (UFTime) value;

               } else {

                       return new UFTime(value.toString().trim());

               }

       }

 

       /**

        * 作者:zjp 功能:根据一个对象的值得到UFDouble的值,如果为空,返回零 参数:Object value 对象值 返回:UFDouble

        * UFDouble的值 例外:无 日期:(2009-03-26 11:39:21) 修改日期,修改人,修改原因,注释标志:

        */

       public static UFDouble getUFDouble_NullAsZero(Object value) {

               if (value == null || value.toString().trim().equals("")) {

                       return ZERO;

               } else if (value instanceof UFDouble) {

                       return (UFDouble) value;

               } else if (value instanceof BigDecimal) {

                       return new UFDouble((BigDecimal) value);

               } else {

                       return new UFDouble(value.toString().trim());

               }

       }

 

       /**

        * 作者:zjp 功能:根据一个double得到UFDouble的值 参数:double dValue 值 返回:UFDouble UFDouble的值

        * 例外:无 日期:(2009-03-26 11:39:21) 修改日期,修改人,修改原因,注释标志:

        */

       public static UFDouble getUFDouble_ValueAsValue(double dValue) {

               if (dValue == 0) {

                       return ZERO;

               } else {

                       return new UFDouble(dValue);

               }

       }

 

       /**

        * 作者:zjp 功能:根据一个对象的值得到UFDouble的值,如果为空,返回零 参数:Object value 对象值 返回:UFDouble

        * UFDouble的值 例外:无 日期:(2009-03-26 11:39:21) 修改日期,修改人,修改原因,注释标志:

        */

       public static UFDouble getUFDouble_ZeroAsNull(double dValue) {

               if (dValue == 0) {

                       return null;

               } else {

                       return new UFDouble(dValue);

               }

       }

 

       /**

        * 作者:zjp 功能:根据一个对象的值得到String的值,如果为空串,返回空 该方法主要可用于setAttrobuteValue()

        * 参数:Object value 对象值 返回:String String的值 例外:无 日期:(2003-06-05 11:39:21)

        * 修改日期,修改人,修改原因,注释标志:

        */

       public static String getString_TrimZeroLenAsNull(Object value) {

               if (value == null || value.toString().trim().length() == 0) {

                       return null;

               }

               return value.toString().trim();

       }

 

       /**

        * 作者:zjp 功能:根据一个对象的值得到String的值,如果为空串,返回"" 该方法主要可用于setAttrobuteValue()

        * 参数:Object value 对象值 返回:String String的值 例外:无 日期:(2003-06-05 11:39:21)

        * 修改日期,修改人,修改原因,注释标志:

        */

       public static String getString_TrimZeroLenAsZeroLen(Object value) {

               if (value == null || value.toString().trim().length() == 0) {

                       return "";

               }

               return value.toString().trim();

       }

 

       /**

        * 作者:zjp 功能:根据一个对象的值得到String的值,如果为空串,返回空 该方法主要可用于setAttrobuteValue()

        * 参数:Object value 对象值 返回:String String的值 例外:无 日期:(2003-06-05 11:39:21)

        * 修改日期,修改人,修改原因,注释标志:

        */

       public static int[] getIntArray(int value) {

               int[] values = null;

               if (value > 0) {

                       values = new int[value];

                       for (int i = 0; i < value; i++) {

                               values[i] = i;

                       }

               }

               return values;

       }

 

       /**

        * 作者:zjp 功能:根据一个对象的值得到Integer的值,如果为空,返回零 参数:Object value 对象值 返回:Integer

        * Integer的值 例外:无 日期:(2009-03-26 11:39:21) 修改日期,修改人,修改原因,注释标志:

        */

       public static Integer getInteger_NullAsZero(Object value) {

               if (value == null || value.toString().trim().equals("")) {

                       return 0;

               } else if (value instanceof Integer) {

                       return (Integer) value;

               } else {

                       return Integer.valueOf(value.toString().trim());

               }

       }

 

       /**

        * 作者:zjp 功能:根据一个对象的值得到Integer的值,如果为空,返回空 参数:Object value 对象值 返回:Integer

        * Integer的值 例外:无 日期:(2009-03-26 11:39:21) 修改日期,修改人,修改原因,注释标志:

        */

       public static Integer getInteger_NullAsNull(Object value) {

               if (value == null || value.toString().trim().equals("")) {

                       return null;

               } else if (value instanceof Integer) {

                       return (Integer) value;

               } else {

                       return Integer.valueOf(value.toString().trim());

               }

       }

 

       /**

        * 作者:zjp 功能:根据一个对象的值得到Integer的值,如果为空,返回-1 参数:Object value 对象值 返回:Integer

        * Integer的值 例外:无 日期:(2009-03-26 11:39:21) 修改日期,修改人,修改原因,注释标志:

        */

       public static Integer getInteger_NullAsfu1(Object value) {

               if (value == null || value.toString().trim().equals("")) {

                       return -1;

               } else if (value instanceof Integer) {

                       return (Integer) value;

               } else {

                       return Integer.valueOf(value.toString().trim());

               }

       }

 

       /**

        * 判断一个或多个对象是否为非空

        *

        * @param values

        *          可变参数,要判断的一个或多个对象

        * @return 只有要判断的一个或多个对象都不为空则返回true,否则返回false

        */

       public static boolean isNotNull(Object... values) {

               if (!PubUtils.isNotNullAndNotEmpty(values)) {

                       return false;

               }

               for (Object value : values) {

                       boolean flag = true;

                       if (value instanceof Object[]) {

                               flag = isNotNullAndNotEmpty((Object[]) value);

                       } else if (value instanceof Collection<?>) {

                               flag = isNotNullAndNotEmpty((Collection<?>) value);

                       } else if (value instanceof String) {

                               flag = !isOEmptyOrNull(value);

                       } else {

                               flag = (null != value);

                       }

                       if (!flag) {

                               return false;

                       }

               }

               return true;

       }

 

       /**

        * 判断一个或多个对象是否为空

        *

        * @param values

        *          可变参数,要判断的一个或多个对象

        * @return 只有要判断的一个对象都为空则返回true,否则返回false

        */

       public static boolean isNull(Object... values) {

               if (!PubUtils.isNotNullAndNotEmpty(values)) {

                       return true;

               }

               for (Object value : values) {

                       boolean flag = false;

                       if (value instanceof Object[]) {

                               flag = !isNotNullAndNotEmpty((Object[]) value);

                       } else if (value instanceof Collection<?>) {

                               flag = !isNotNullAndNotEmpty((Collection<?>) value);

                       } else if (value instanceof String) {

                               flag = isOEmptyOrNull(value);

                       } else {

                               flag = (null == value);

                       }

                       if (flag) {

                               return true;

                       }

               }

               return false;

       }

 

       /**

        * 判断对象数组是否为空并且数量大于0

        *

        * @param value

        * @return

        */

       public static Boolean isNotNullAndNotEmpty(Object[] value) {

               boolean bl = false;

               if (null != value && 0 < value.length) {

                       bl = true;

               }

               return bl;

       }

 

       /**

        * 判断对象集合(List,Set)是否为空并且数量大于0

        *

        * @param value

        * @return

        */

       public static Boolean isNotNullAndNotEmpty(Collection<?> value) {

               boolean bl = false;

               if (null != value && 0 < value.size()) {

                       bl = true;

               }

               return bl;

       }

 

       /**

        * 判断对象数组是否为空并且数量大于size值

        *

        * @param value

        * @return

        */

       public static Boolean isNotNullAndBiggerSize(Object[] value, int size) {

               boolean bl = false;

               if (null != value && size < value.length) {

                       bl = true;

               }

               return bl;

       }

 

       /**

        * 判断对象集合(List,Set)是否为空并且数量大于size值

        *

        * @param value

        * @return

        */

       public static Boolean isNotNullAndBiggerSize(Collection<?> value, int size) {

               boolean bl = false;

               if (null != value && size < value.size()) {

                       bl = true;

               }

               return bl;

       }

 

       /**

        * 判断对象数组是否为空并且数量等于size值

        *

        * @param value

        * @return

        */

       public static Boolean isNotNullAndEqualSize(Object[] value, int size) {

               boolean bl = false;

               if (null != value && size == value.length) {

                       bl = true;

               }

               return bl;

       }

 

       /**

        * 判断对象集合(List,Set)是否为空并且数量等于size值

        *

        * @param value

        * @return

        */

       public static Boolean isNotNullAndEqualSize(Collection<?> value, int size) {

               boolean bl = false;

               if (null != value && size == value.size()) {

                       bl = true;

               }

               return bl;

       }

 

       /**

        * 判断对象数组是否为空并且数量小于size值

        *

        * @param value

        * @return

        */

       public static Boolean isNotNullAndSmallerSize(Object[] value, int size) {

               boolean bl = false;

               if (null != value && size > value.length) {

                       bl = true;

               }

               return bl;

       }

 

       /**

        * 判断对象集合(List,Set)是否为空并且数量小于size值

        *

        * @param value

        * @return

        */

       public static Boolean isNotNullAndSmallerSize(Collection<?> value, int size) {

               boolean bl = false;

               if (null != value && size > value.size()) {

                       bl = true;

               }

               return bl;

       }

 

       /**

        * 作者:WYF 功能:根据一个对象的值得到UFDouble的值,空即返回空,零即返回零 参数:Object value 对象值 返回:UFDouble

        * UFDouble的值 例外:无 日期:(2003-03-26 11:39:21) 修改日期,修改人,修改原因,注释标志:

        */

       public static UFDouble getUFDouble_ValueAsValue(Object value) {

               if (value == null || value.toString().trim().equals("")) {

                       return null;

               } else if (value instanceof UFDouble) {

                       return (UFDouble) value;

               } else if (value instanceof BigDecimal) {

                       return new UFDouble((BigDecimal) value);

               } else {

                       return new UFDouble(value.toString().trim());

               }

 

       }

 

       /**

        * 作者:WYF 功能:根据一个对象的值得到UFDouble的值,如果为零,返回空 参数:Object value 对象值 返回:UFDouble

        * UFDouble的值 例外:无 日期:(2003-03-26 11:39:21) 修改日期,修改人,修改原因,注释标志:

        */

       public static UFDouble getUFDouble_ZeroAsNull(Object value) {

               UFDouble dValue = getUFDouble_NullAsZero(value);

               if (dValue.compareTo(ZERO) == 0) {

                       return null;

               }

               return dValue;

       }

 

       // /**

       // * ?user> 功能: 参数: 返回: 例外: 日期:(2005-1-31 9:34:37) 修改日期,修改人,修改原因,注释标志:

       // *

       // * @return boolean

       // * @param str

       // * java.lang.String

       // */

       // public static boolean isNull(String str) {

       // if (null == str || STRING_NULL.equals(str) || str.trim().length() == 0) {

       // return true;

       // }

       // return false;

       // }

 

       /**

        * ?user> 功能: 参数: 返回: 例外: 日期:(2005-1-31 9:34:37) 修改日期,修改人,修改原因,注释标志:

        *

        * @return boolean

        * @param str

        *          java.lang.String

        */

       public static boolean isStringEqual(String str1, String str2) {

               if (PubUtils.isNull(str1, str2)) {

                       return true;

               } else if (PubUtils.isNull(str1) && PubUtils.isNotNull(str2)) {

                       return false;

               } else if (PubUtils.isNull(str2) && PubUtils.isNotNull(str1)) {

                       return false;

               } else if (str2.trim().equals(str1.trim())) {

                       return true;

               } else {

                       return false;

               }

       }

 

       public static boolean isRunningInServer() {

               return RuntimeEnv.getInstance().isRunningInServer();

       }

 

       public static void setStmtString(PreparedStatement stmt, Object value, int iIndex) throws BusinessException {

               try {

                       if (value == null) { // || value.toString().trim().length()==0) {

                               stmt.setNull(iIndex, Types.CHAR);

                       } else {

                               stmt.setString(iIndex, value.toString());

                       }

               } catch (SQLException e) {

                       handleException(e.getMessage(), e);

               }

       }

 

       public static void setStmtBigDecimal(PreparedStatement stmt, Object value, int iIndex) throws BusinessException {

               try {

                       if (value == null) {

                               stmt.setNull(iIndex, Types.DECIMAL);

                       } else {

                               if (value instanceof UFDouble) {

                                       stmt.setBigDecimal(iIndex, ((UFDouble) value).toBigDecimal());

                               } else if (value instanceof BigDecimal) {

                                       stmt.setBigDecimal(iIndex, (BigDecimal) value);

                               } else {

                                       if (value.toString().trim().length() == 0) {

                                               stmt.setNull(iIndex, Types.DECIMAL);

                                       } else {

                                               stmt.setBigDecimal(iIndex, new BigDecimal(value.toString().trim()));

                                       }

                               }

                       }

               } catch (SQLException e) {

                       handleException(e.getMessage(), e);

               }

       }

 

       public static void setStmtBigDecimalZero(PreparedStatement stmt, Object value, int iIndex) throws BusinessException {

               try {

                       if (value == null) {

                               stmt.setBigDecimal(iIndex, ZERO.toBigDecimal());

                       } else {

                               if (value.getClass() == UFDouble.class) {

                                       stmt.setBigDecimal(iIndex, ((UFDouble) value).toBigDecimal());

                               } else if (value.getClass() == BigDecimal.class) {

                                       stmt.setBigDecimal(iIndex, (BigDecimal) value);

                               } else {

                                       if (value.toString().trim().length() == 0) {

                                               stmt.setNull(iIndex, Types.INTEGER);

                                       } else {

                                               stmt.setBigDecimal(iIndex, new BigDecimal(value.toString().trim()));

                                       }

                               }

                       }

               } catch (SQLException e) {

                       eatException(e.getMessage(), e);

               }

       }

 

       public static void setStmtInteger(PreparedStatement stmt, Object value, int iIndex) throws SQLException {

               if (value == null) {

                       stmt.setNull(iIndex, Types.INTEGER);

               } else {

                       if (value instanceof Integer) {

                               stmt.setInt(iIndex, ((Integer) value).intValue());

                       } else {

                               if (value.toString().trim().length() == 0) {

                                       stmt.setNull(iIndex, Types.INTEGER);

                               } else {

                                       stmt.setInt(iIndex, Integer.valueOf(value.toString().trim()));

                               }

                       }

               }

       }

 

       public static void setScale(CircularlyAccessibleValueObject[] voItems, ScaleKey scalekey, ScaleValue scale) {

               if (voItems == null || voItems.length == 0 || scale == null || scalekey == null) {

                       return;

               }

 

               Object temp = null;

               String[] keys = null;

               for (CircularlyAccessibleValueObject voItem : voItems) {

                       // 数量

                       if (scalekey.getNumKeys() != null) {

                               keys = scalekey.getNumKeys();

                               for (String key : keys) {

                                       temp = voItem.getAttributeValue(key);

                                       if (temp != null && temp instanceof UFDouble) {

                                               voItem.setAttributeValue(key, new UFDouble(((UFDouble) temp).doubleValue(), -scale.getNumScale()));

                                       }

 

                               }

 

                       }

                       // 辅数量

                       if (scalekey.getAssistNumKeys() != null) {

                               keys = scalekey.getAssistNumKeys();

                               for (String key : keys) {

                                       temp = voItem.getAttributeValue(key);

                                       if (temp != null && temp instanceof UFDouble) {

                                               voItem.setAttributeValue(key, new UFDouble(((UFDouble) temp).doubleValue(), -scale.getAssistNumScale()));

                                       }

 

                               }

 

                       }

                       // 金额

                       if (scalekey.getMnyKeys() != null) {

                               keys = scalekey.getMnyKeys();

                               for (String key : keys) {

                                       temp = voItem.getAttributeValue(key);

                                       if (temp != null && temp instanceof UFDouble) {

                                               voItem.setAttributeValue(key, new UFDouble(((UFDouble) temp).doubleValue(), -scale.getMnyScale()));

                                       }

 

                               }

 

                       }

                       // 单价

                       if (scalekey.getPriceKeys() != null) {

                               keys = scalekey.getPriceKeys();

                               for (String key : keys) {

                                       temp = voItem.getAttributeValue(key);

                                       if (temp != null && temp instanceof UFDouble) {

                                               voItem.setAttributeValue(key, new UFDouble(((UFDouble) temp).doubleValue(), -scale.getPriceScale()));

                                       }

 

                               }

 

                       }

                       // 换算率

                       if (scalekey.getHslKeys() != null) {

                               keys = scalekey.getHslKeys();

                               for (String key : keys) {

                                       temp = voItem.getAttributeValue(key);

                                       if (temp != null && temp instanceof UFDouble) {

                                               voItem.setAttributeValue(key, new UFDouble(((UFDouble) temp).doubleValue(), -scale.getHslScale()));

                                       }

 

                               }

 

                       }

               }

       }

 

       public static boolean isNotEqualsZero(Object value) {

               if (value == null) {

                       return false;

               }

               if (value instanceof UFDouble) {

                       if (((UFDouble) value).compareTo(ZERO) != 0) {

                               return true;

                       }

               } else if (value instanceof Integer) {

                       if (((Integer) value).compareTo(ZERO_INTEGER) != 0) {

                               return true;

                       }

               }

               return false;

 

       }

 

       /**

        * 此处插入方法说明。 功能描述:把两个String数组合并 输入参数: 返回值: 异常处理: 日期:

        *

        * @return java.lang.String[]

        * @param ary1

        *          java.lang.String[]

        * @param ary2

        *          java.lang.String[]

        */

       public static String[] combineStringArray(String[] ary1, String[] ary2) {

 

               String[] arycombine = null;

               if ((ary1 != null && ary1.length > 0) && (ary2 != null && ary2.length > 0)) {

                       int ilen1 = ary1.length;

                       int ilen2 = ary2.length;

                       arycombine = new String[ilen1 + ilen2];

 

                       for (int i = 0; i < ilen1; i++) {

                               arycombine[i] = ary1[i];

                       }

                       for (int i = ilen1; i < ilen1 + ilen2; i++) {

                               arycombine[i] = ary2[i - ilen1];

                       }

               } else if (ary1 != null && ary1.length > 0) {

                       return ary1;

               } else if (ary2 != null && ary2.length > 0) {

                       return ary2;

               }

               return arycombine;

       }

 

       public static UFDouble calcAssitNum(UFDouble num, UFDouble hsl) {

               if (num == null || hsl == null) {

                       return null;

               }

 

               return num.div(hsl);

 

       }

 

       public static BusinessException getRealBusiException(Throwable e) {

               return (BusinessException) PubUtils.getRealExceptionFor(BusinessException.class, e);

       }

 

       public static Exception getRealExceptionFor(Class<?> exceptionClass, Throwable e) {

               Exception rete = null;

               if (e == null) {

                       return rete;

               }

 

               if (exceptionClass == null) {

                       if (e instanceof Exception) {

                               return (Exception) e;

                       } else {

                               return rete;

                       }

               }

 

               if (e instanceof InvocationTargetException) {

                       if (exceptionClass == InvocationTargetException.class) {

                               return (InvocationTargetException) e;

                       }

                       e = ((InvocationTargetException) e).getTargetException();

               }

 

               if (exceptionClass.isInstance(e) && e instanceof Exception) {

                       rete = (Exception) e;

               }

 

               Throwable cause = e.getCause();

               if (cause == null) {

                       return rete;

               }

 

               Exception preve = getRealExceptionFor(exceptionClass, cause);

               if (preve != null) {

                       return preve;

               }

               return rete;

 

       }

 

       /**

        *

        * 方法功能描述:返回业务异常。

        *

        * <b>参数说明</b>

        *

        * @param msg

        * @return

        * @since 1.0

        * @author 刘家清

        * @time 2010-9-25 下午01:18:19

        */

       public static void newBusinessException(String msg) throws BusinessException {

               if (isNull(msg)) {

                       return;

               }

               throw new BusinessException(msg);

       }

 

       /**

        *

        * 方法功能描述:吃掉异常,除非有充足的理由才能吃掉异常,不然的话不能调用此方法。

        *

        * <b>参数说明</b>

        *

        * @param msg

        * @param e

        * @throws BusinessException

        *          

        * @since 1.0

        * @author 刘家清

        * @time 2010-9-28 上午08:58:27

        */

       public static void eatException(String msg, Throwable e) {

 

               Logger.error(msg, e);

 

       }

 

       /**

        *

        * 方法功能描述:Public异常处理必须调用此方法,处理业务异常并抛出。

        *

        * <b>参数说明</b>

        *

        * @param msg

        * @param e

        * @throws BusinessException

        *          

        * @since 1.0

        * @author 刘家清

        * @time 2010-9-28 上午08:57:20

        */

       public static void handleException(String msg, Throwable e) throws BusinessException {

 

               Logger.error(msg, e);

 

               BusinessException be = PubUtils.getRealBusiException(e);

               if (null == be) {

                       be = new BusinessException(msg == null ? e.getMessage() : msg, e);

               }

               throw be;

       }

 

       /**

        * 。

        */

       /* 警告:此方法将重新生成。 */

       public static String getStringParam(String pk_corp, String paramcode) {

               if (pk_corp == null || paramcode == null) {

                       return null;

               }

               try {

                       ISysInitQry sysinitqry = (ISysInitQry) NCLocator.getInstance().lookup(ISysInitQry.class.getName());

                       return sysinitqry.getParaString(pk_corp, paramcode);

               } catch (Exception e) {

                       eatException(null, e);

               }

               return null;

       }

 

       /**

        *

        *

        * @

        */

       public static void setBodyValueToHead(AggregatedValueObject[] targetbillvos, String[] headfields, String[] bodyfields) {

               if (targetbillvos == null || targetbillvos.length <= 0 || headfields == null || bodyfields == null || headfields.length != bodyfields.length) {

                       return;

               }

               Object value = null;

               for (AggregatedValueObject targetbillvo : targetbillvos) {

                       if (targetbillvo.getChildrenVO() == null || targetbillvo.getChildrenVO().length <= 0) {

                               continue;

                       }

                       for (int k = 0; k < bodyfields.length; k++) {

                               value = targetbillvo.getChildrenVO()[0].getAttributeValue(bodyfields[k]);

                               if (value != null && value.toString().trim().length() > 0) {

                                       targetbillvo.getParentVO().setAttributeValue(headfields[k], value);

                               }

                       }

               }

       }

 

       /**

        *

        *

        * @

        */

       public static void setHeadValueToBody(AggregatedValueObject[] targetbillvos, String[] headfields, String[] bodyfields) {

               if (targetbillvos == null || targetbillvos.length <= 0 || headfields == null || bodyfields == null || headfields.length != bodyfields.length) {

                       return;

               }

               Object headvalue = null, bodyvalue = null;

               CircularlyAccessibleValueObject[] bodyvos = null;

               for (AggregatedValueObject targetbillvo : targetbillvos) {

                       bodyvos = targetbillvo.getChildrenVO();

                       if (bodyvos == null || bodyvos.length <= 0) {

                               continue;

                       }

                       for (int k = 0; k < bodyfields.length; k++) {

                               headvalue = targetbillvo.getParentVO().getAttributeValue(headfields[k]);

                               if (headvalue != null && headvalue.toString().trim().length() > 0) {

                                       for (CircularlyAccessibleValueObject bodyvo : bodyvos) {

                                               bodyvalue = bodyvo.getAttributeValue(bodyfields[k]);

                                               if (bodyvalue == null || bodyvalue.toString().trim().length() <= 0) {

                                                       bodyvo.setAttributeValue(bodyfields[k], headvalue);

                                               }

                                       }

                               }

                       }

               }

       }

 

       /**

        *

        * @return java.lang.String

        * @param java

        *          .lang.String

        */

       public static String trimAndNullAsEmpty(String s) {

               if (s != null && !s.trim().equals(STRING_NULL)) {

                       return s.trim();

               } else {

                       return "";

               }

               // return s == null ? "" : s.trim();

       }

 

       /**

        *

        * @return java.lang.String

        * @param java

        *          .lang.String

        */

       public static String trimAndEmptyAsNull(String s) {

               if (s == null) {

                       return null;

               }

               s = s.trim();

               return s.length() <= 0 ? null : s;

       }

 

       /**

        *

        * @return boolean

        * @param java

        *          .lang.String

        */

       public static boolean isSEmptyOrNull(String s) {

               return trimAndNullAsEmpty(s).length() <= 0 ? true : false;

       }

 

       /**

        *

        * @return boolean

        * @param java

        *          .lang.String

        */

       public static boolean isOEmptyOrNull(Object o) {

               return o == null ? true : isSEmptyOrNull(o.toString());

       }

 

       /**

        *

        * @return boolean

        * @param java

        *          .lang.String

        */

       public static boolean isGEZero(UFDouble d) {

               return (d != null && d.compareTo(ZERO) >= 0) ? true : false;

       }

 

       /**

        *

        * @return boolean

        * @param java

        *          .lang.String

        */

       public static boolean isGTZero(UFDouble d) {

               return (d != null && d.compareTo(ZERO) > 0) ? true : false;

       }

 

       /**

        *

        * @return boolean

        * @param java

        *          .lang.String

        */

       public static boolean isLTZero(UFDouble d) {

               return (d != null && d.compareTo(ZERO) < 0) ? true : false;

       }

 

       /**

        *

        * @return boolean

        * @param java

        *          .lang.String

        */

       public static boolean isLEZero(UFDouble d) {

               return (d != null && d.compareTo(ZERO) <= 0) ? true : false;

       }

 

       /**

        *

        * @return boolean

        * @param java

        *          .lang.String

        */

       public static boolean isEQZero(UFDouble d) {

               return (d != null && d.compareTo(ZERO) == 0) ? true : false;

       }

 

       /**

        *

        * @return boolean

        * @param java

        *          .lang.String

        */

       public static boolean isEQZeroOrNull(UFDouble d) {

               return (d == null || d.compareTo(ZERO) == 0) ? true : false;

       }

 

       private static HashMap<Class<?>, HashSet<String>> hscltofields = new HashMap<Class<?>, HashSet<String>>(10);

 

       @SuppressWarnings("unchecked")

       public static boolean isVODBField(String sfield, Class<?> smartvometa) {

               if (sfield == null || sfield.trim().length() <= 0 || smartvometa == null) {

                       return false;

               }

               HashSet<String> hsfields = hscltofields.get(smartvometa);

               if (hsfields == null) {

                       try {

                               SmartVOMeta mt = null;

                               mt = (SmartVOMeta) smartvometa.newInstance();

                               Map m = mt.getColumnsIndexByName();

                               Iterator iter = m.values().iterator();

                               SmartFieldMeta smt = null;

                               hsfields = new HashSet<String>(m.size());

                               while (iter.hasNext()) {

                                       smt = (SmartFieldMeta) iter.next();

                                       if (smt.isPersistence()) {

                                               hsfields.add(smt.getName());

                                       }

                               }

                               hscltofields.put(smartvometa, hsfields);

                       } catch (Exception e) {

                               eatException(null, e);

                               return false;

                       }

               }

               sfield = sfield.trim();

               int pos = sfield.indexOf('.');

               if (pos > 0) {

                       sfield = sfield.substring(pos + 1);

               }

               return hsfields.contains(sfield);

       }

 

       public static Object[] mergeArray(Object[]... arr) {

               if (arr == null || arr.length <= 1) {

                       return arr;

               }

               int count = 0;

               Class<?> cl = null;

               for (Object[] e : arr) {

                       if (e == null || e.length <= 0) {

                               continue;

                       }

                       count += e.length;

                       if (cl == null && e[0] != null) {

                               cl = e[0].getClass();

                       }

               }

               if (count <= 0) {

                       return null;

               }

               Object[] ret = (Object[]) Array.newInstance(cl, count);

               int istartpos = 0;

               for (Object[] e : arr) {

                       System.arraycopy(e, 0, ret, istartpos, e.length);

                       istartpos += e.length;

               }

               return ret;

       }

 

       /*

        *

        */

       public static boolean isEqualObject(Object otemp1, Object otemp2) {

               String s1 = null, s2 = null;

               if (otemp1 == null) {

                       s1 = "";

               } else {

                       s1 = otemp1.toString().trim();

               }

               if (otemp2 == null) {

                       s2 = "";

               } else {

                       s2 = otemp2.toString().trim();

               }

               return s1.equals(s2);

       }

 

       /**

        *

        * 比较两个UFDouble的值是否相等

        *

        * <b>参数说明</b>

        *

        * @param d1

        * @param d2

        * @return

        * @since 1.0

        * @author 王松涛

        * @time 2010-8-31 下午08:10:53

        */

       public static boolean isUFDoubleEqual(UFDouble d1, UFDouble d2) {

               if (PubUtils.isNull(d1, d2)) {

                       return true;

               } else if (PubUtils.isNull(d1) && PubUtils.isNotNull(d2)) {

                       return false;

               } else if (PubUtils.isNull(d2) && PubUtils.isNotNull(d1)) {

                       return false;

               } else {

                       return d1.compareTo(d2) == 0 ? true : false;

               }

       }

 

       /**

        *

        * @return boolean

        * @param java

        *          .lang.String

        */

       public static boolean isTrue(Object ufboolean) {

               if (ufboolean == null) {

                       return false;

               }

               if (ufboolean.getClass() == UFBoolean.class) {

                       return ((UFBoolean) ufboolean).booleanValue();

               } else if (ufboolean.getClass() == Boolean.class) {

                       return ((Boolean) ufboolean).booleanValue();

               } else {

                       try {

                               return new UFBoolean(ufboolean.toString().trim()).booleanValue();

                       } catch (Exception e) {

                               return false;

                       }

               }

       }

 

       /**

        * 如果字符串能转换成日期返回true。

        *

        * @return boolean

        * @param strDate

        *          java.lang.String

        */

       public static boolean isAllowDate(String strDate) {

               if (strDate == null || strDate.trim().length() == 0) {

                       return true;

               }

               if (strDate.trim().length() != 10) {

                       return false;

               }

               for (int i = 0; i < 10; i++) {

                       char c = strDate.trim().charAt(i);

                       if (i == 4 || i == 7) {

                               if (c != '-') {

                                       return false;

                               }

                       } else if (c < '0' || c > '9') {

                               return false;

                       }

               }

               int year = Integer.parseInt(strDate.trim().substring(0, 4));

               int month = Integer.parseInt(strDate.trim().substring(5, 7));

               if (month < 1 || month > 12) {

                       return false;

               }

               int day = Integer.parseInt(strDate.trim().substring(8, 10));

               int MONTH_LENGTH[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };

               int LEAP_MONTH_LENGTH[] = { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };

               int daymax = UFDate.isLeapYear(year) ? LEAP_MONTH_LENGTH[month - 1] : MONTH_LENGTH[month - 1];

               if (day < 1 || day > daymax) {

                       return false;

               }

               return true;

       }

 

       /**

        *

        * @return boolean

        * @param java

        *          .lang.String

        */

       public static boolean isStartWithAnd(String swhere) {

               if (swhere == null) {

                       return false;

               }

               String trimwhere = swhere.trim();

               if (trimwhere.length() <= 0) {

                       return false;

               }

               if (trimwhere.startsWith("and") || trimwhere.startsWith("AND") || trimwhere.startsWith("And")) {

                       return true;

               }

               return false;

       }

 

       /**

        *

        * @return boolean

        * @param java

        *          .lang.String

        */

       public static boolean isStartWithOr(String swhere) {

               if (swhere == null) {

                       return false;

               }

               String trimwhere = swhere.trim();

               if (trimwhere.length() <= 0) {

                       return false;

               }

               if (trimwhere.startsWith("or") || trimwhere.startsWith("OR") || trimwhere.startsWith("Or")) {

                       return true;

               }

               return false;

       }

 

       /**

        *

        * @return boolean

        * @param java

        *          .lang.String

        */

       public static boolean isStartWithAndOr(String swhere) {

               return isStartWithAnd(swhere) || isStartWithOr(swhere);

       }

 

       /**

        *

        * @return boolean

        * @param java

        *          .lang.String

        */

       public static String andTowWhere(String swhere1, String swhere2) {

               if (swhere1 == null || swhere1.trim().length() <= 0) {

                       return swhere2;

               }

               if (swhere2 == null || swhere2.trim().length() <= 0) {

                       return swhere1;

               }

               if (isStartWithAndOr(swhere2)) {

                       return swhere1 + " " + swhere2;

               }

               return swhere1 + " and " + swhere2;

       }

 

       /**

        * 方法功能描述:任意十进制的整型、长整型字符串转换为任意进制,最大支持到36进制

        *

        * <b>examples:</b>

        *

        * 使用示例

        *

        * <b>参数说明</b>

        *

        * @param strInt

        * @param JZ

        * @return

        * @author liuzy

        * @time 2009-11-20 下午05:03:48

        */

       public String convertTenTOAnyJZ(String strInt, int JZ) throws BusinessException {

               SqlBuilder resultStr = new SqlBuilder();

               try {

                       long intStr = Long.parseLong(strInt);

                       long[] result = new long[50];

                       long T;

                       resultStr.append("");

                       int i = 0;

                       while (intStr != 0) {

                               result[i] = intStr % JZ;

                               intStr = intStr - result[i];

                               intStr = intStr / JZ;

                               i++;

                       }

                       for (int j1 = 0, j2 = i - 1; j1 < (i / 2); j1++, j2--) {

                               T = result[j1];

                               result[j1] = result[j2];

                               result[j2] = T;

                       }

                       for (int j = 0; j < i; j++) {

                               resultStr.append(intToChar(result[j]));

                       }

               } catch (NumberFormatException e) {

                       // 日志异常

                       BOSEnv.out(e);

                       throw new BusinessException("传入的字符串格式错误,只支持数字的字符串");

               } catch (Exception e) {

                       // 日志异常

                       BOSEnv.out(e);

                       throw new BusinessException(e.getMessage());

               }

               return resultStr.toString();

 

       }

 

       /**

        * 方法功能描述:进制转换

        *

        * <b>examples:</b>

        *

        * 使用示例

        *

        * <b>参数说明</b>

        *

        * @param num

        * @return

        * @author liuzy

        * @time 2009-11-20 下午05:10:59

        */

       private String intToChar(long num) {

               String result = "";

               String S = "";

               if (0 <= num && num <= 9) {

                       result = String.valueOf(num);

               } else if (num > 9) {

                       S = String.valueOf(num);

                       switch (Integer.parseInt(S)) {

                               case 10:

                                       result = "A";

                                       break;

                               case 11:

                                       result = "B";

                                       break;

                               case 12:

                                       result = "C";

                                       break;

                               case 13:

                                       result = "D";

                                       break;

                               case 14:

                                       result = "E";

                                       break;

                               case 15:

                                       result = "F";

                                       break;

                               case 16:

                                       result = "G";

                                       break;

                               case 17:

                                       result = "H";

                                       break;

                               case 18:

                                       result = "I";

                                       break;

                               case 19:

                                       result = "G";

                                       break;

                               case 20:

                                       result = "K";

                                       break;

                               case 21:

                                       result = "L";

                                       break;

                               case 22:

                                       result = "M";

                                       break;

                               case 23:

                                       result = "N";

                                       break;

                               case 24:

                                       result = "O";

                                       break;

                               case 25:

                                       result = "P";

                                       break;

                               case 26:

                                       result = "Q";

                                       break;

                               case 27:

                                       result = "R";

                                       break;

                               case 28:

                                       result = "S";

                                       break;

                               case 29:

                                       result = "T";

                                       break;

                               case 30:

                                       result = "U";

                                       break;

                               case 31:

                                       result = "V";

                                       break;

                               case 32:

                                       result = "W";

                                       break;

                               case 33:

                                       result = "X";

                                       break;

                               case 34:

                                       result = "Y";

                                       break;

                               case 35:

                                       result = "Z";

                                       break;

                       }

               }

               return result;

       }

 

       /**

        *

        * 从源头VO中拷贝字段赋值到目标VO

        *

        * <b>参数说明</b>

        *

        * @param copyFields

        *          需要拷贝的字段名

        * @param sourceVOs

        *          源头VO

        * @param bodyVOs

        *          目标VO

        *          

        * @since 1.0

        * @author 王松涛

        * @time 2010-8-16 上午08:40:28

        */

       public static void copyFieldsFromVOtoVO(String[] srcFields, CircularlyAccessibleValueObject srcVO, CircularlyAccessibleValueObject targetVO)

                       throws BusinessException {

               /**

                * 校验参数是否为空

                */

               if (PubUtils.isNull(srcFields, srcVO, targetVO)) {

                       PubUtils.newBusinessException(PubResBase.getParasErrorByMethodName("copyFieldsFromVOtoVO"));

               }

 

               for (String field : srcFields) {

                       if (!PubUtils.isSEmptyOrNull(field)) {

                               Object value = srcVO.getAttributeValue(field);

                               if (PubUtils.isNotNull(value)) {

                                       targetVO.setAttributeValue(field, value);

                               }

                       }

               }

 

       }

 

       /**

        *

        * 从源头VO中拷贝字段赋值到目标VO

        *

        * <b>参数说明</b>

        *

        * @param srcFields

        *          源头字段

        * @param targetFields

        *          目标字段

        * @param srcVO

        *          源头VO

        * @param targetVO

        *          目标VO

        * @throws BusinessException

        *          

        * @since 1.0

        * @author 王松涛

        * @time 2010-9-6 下午01:08:37

        */

       public static void copyFieldsFromVOtoVO(String[] srcFields, String[] targetFields, CircularlyAccessibleValueObject srcVO,

                       CircularlyAccessibleValueObject targetVO) throws BusinessException {

 

               /**

                * 校验参数是否为空

                */

               if (PubUtils.isNull(srcFields, targetFields, srcVO, targetVO)) {

                       PubUtils.newBusinessException(PubResBase.getParasErrorByMethodName("copyFieldsFromVOtoVO"));

               }

 

               /**

                * 校验参数中,字段名数组的长度是否一致,VO数组长度是否一致

                */

               if (!PubUtils.isNotNullAndEqualSize(targetFields, srcFields.length)) {

                       PubUtils.newBusinessException(PubResBase.Pub_NoSameArrayLength);

               }

 

               for (int i = 0; i < targetFields.length; i++) {

                       if (PubUtils.isNotNull(targetFields[i], srcFields[i])) {

                               Object value = srcVO.getAttributeValue(srcFields[i]);

                               if (PubUtils.isNotNull(value)) {

                                       targetVO.setAttributeValue(targetFields[i], value);

                               }

                       }

               }

 

       }

 

       /**

        *

        * 从源头VO数组中拷贝字段赋值到目标VO数组

        *

        * <b>参数说明</b>

        *

        * @param srcFields

        *          源头字段

        * @param targetFields

        *          目标字段

        * @param srcVOs

        *          源头VO数组

        * @param targetVOs

        *          目标VO数组

        * @throws BusinessException

        *          

        * @since 1.0

        * @author 王松涛

        * @time 2010-9-6 下午01:08:37

        */

       public static void copyFieldsFromVOsToVOs(String[] srcFields, CircularlyAccessibleValueObject[] srcVOs, CircularlyAccessibleValueObject[] targetVOs)

                       throws BusinessException {

               /**

                * 校验参数是否为空

                */

               if (PubUtils.isNull(srcFields, srcVOs, targetVOs)) {

                       PubUtils.newBusinessException(PubResBase.getParasErrorByMethodName("copyFieldsFromVOsToVOs"));

               }

 

               /**

                * 校验参数中,字段名数组的长度是否一致,VO数组长度是否一致

                */

               if (!PubUtils.isNotNullAndEqualSize(targetVOs, srcVOs.length)) {

                       PubUtils.newBusinessException(PubResBase.Pub_NoSameArrayLength);

               }

 

               for (int i = 0; i < targetVOs.length; i++) {

                       if (PubUtils.isNotNull(targetVOs[i], srcVOs[i])) {

                               for (String field : srcFields) {

                                       if (PubUtils.isNotNull(field)) {

                                               Object value = srcVOs[i].getAttributeValue(field);

                                               if (PubUtils.isNotNull(value)) {

                                                       targetVOs[i].setAttributeValue(field, value);

                                               }

                                       }

                               }

                       }

 

               }

 

       }

 

       /**

        *

        * 从源头VO数组中拷贝字段赋值到目标VO数组

        *

        * <b>参数说明</b>

        *

        * @param srcFields

        *          源头字段

        * @param targetFields

        *          目标字段

        * @param srcVOs

        *          源头VO数组

        * @param targetVOs

        *          目标VO数组

        * @throws BusinessException

        *          

        * @since 1.0

        * @author 王松涛

        * @time 2010-9-6 下午01:08:37

        */

       public static void copyFieldsFromVOsToVOs(String[] srcFields, String[] targetFields, CircularlyAccessibleValueObject[] srcVOs,

                       CircularlyAccessibleValueObject[] targetVOs) throws BusinessException {

               /**

                * 校验参数是否为空

                */

               if (PubUtils.isNull(srcFields, targetFields, srcVOs, targetVOs)) {

                       PubUtils.newBusinessException(PubResBase.getParasErrorByMethodName("copyFieldsFromVOsToVOs"));

               }

 

               /**

                * 校验参数中,字段名数组的长度是否一致,VO数组长度是否一致

                */

               if ((!PubUtils.isNotNullAndEqualSize(targetFields, srcFields.length)) || (!PubUtils.isNotNullAndEqualSize(targetVOs, srcVOs.length))) {

                       PubUtils.newBusinessException(PubResBase.Pub_NoSameArrayLength);

               }

 

               for (int i = 0; i < targetVOs.length; i++) {

                       if (PubUtils.isNotNull(targetVOs[i], srcVOs[i])) {

                               for (int j = 0; j < targetFields.length; j++) {

                                       if (PubUtils.isNotNull(targetFields[j], srcFields[j])) {

                                               Object value = srcVOs[i].getAttributeValue(srcFields[j]);

                                               if (PubUtils.isNotNull(value)) {

                                                       targetVOs[i].setAttributeValue(targetFields[j], value);

                                               }

                                       }

                               }

                       }

 

               }

 

       }

 

       /**

        *

        * 将BOSLightBillVO中的数据解压到VO中

        *

        * <b>参数说明</b>

        *

        * @param lightVO

        * @param svo

        *          

        * @since 1.0

        * @author 王松涛

        * @time 2010-8-16 下午04:07:27

        */

       public static void convertLightVOtoBillVO(BOSLightBillVO lightVO, SmartVO svo) {

               if (PubUtils.isNotNull(lightVO) && PubUtils.isNotNull(svo)) {

                       String[] fieldNames = lightVO.getMetaFieldNames();

                       if (PubUtils.isNotNullAndNotEmpty(fieldNames)) {

                               for (String name : fieldNames) {

                                       if (BOSLightBillVO.PK_ID.equals(name)) {

                                               svo.setAttributeValue(name, lightVO.getPrimaryKey());

                                       } else {

                                               svo.setAttributeValue(name, lightVO.getAttributeValue(name));

                                       }

                               }

                       }

 

                       HashMap<String, Integer> updateNames = (HashMap<String, Integer>) lightVO.getUpdateNames();

                       // 指定更新的字段名

                       if (PubUtils.isNotNull(updateNames) && PubUtils.isNotNull(updateNames.keySet())) {

                               for (String updateName : updateNames.keySet()) {

                                       svo.setAttributeValue(updateName, lightVO.getAttributeValue(updateName));

                               }

                       }

               }

       }

 

       /**

        *

        * 将VO中的数据压缩到BOSLightBillVO中

        *

        * <b>参数说明</b>

        *

        * @param lightVO

        * @param svo

        *          

        * @since 1.0

        * @author 王松涛

        * @time 2010-8-16 下午04:07:27

        */

       public static void convertBillVOtoLightVO(BOSLightBillVO lightVO, SmartVO svo) {

               if (PubUtils.isNotNull(lightVO) && PubUtils.isNotNull(svo)) {

                       // 设置表名和主键名

                       lightVO.setTableName(svo.getVOMeta().getTable());

                       lightVO.setPkFieldName(svo.getVOMeta().getPkColName());

                       // 复制相关字段

                       String[] fieldNames = lightVO.getMetaFieldNames();

                       if (PubUtils.isNotNullAndNotEmpty(fieldNames)) {

                               for (String name : fieldNames) {

                                       if (BOSLightBillVO.PK_ID.equals(name)) {

                                               lightVO.setPrimaryKey(svo.getPrimaryKey());

                                       } else {

                                               lightVO.setAttributeValue(name, svo.getAttributeValue(name));

                                       }

                               }

                       }

               }

       }

 

       /**

        *

        * 将VO中的数据压缩到BOSLightBillVO中

        *

        * <b>参数说明</b>

        *

        * @param lightVO

        * @param svo

        * @param updateNames

        *          传入更新的字段,用Map存储,Key为字段名,Value为字段类型(如key =“names”;value =

        *          SmartFieldMeta.JAVATYPE_STRING)

        * @param isReplaceFstatusFlag

        *          是否替换更新原有的fstatusflag等字段,如果为true,则只更新Map中指定的字段,如果为false,则既更新Map中的字段

        *          ,也更新fstatusflag等字段

        *          

        * @since 1.0

        * @author 王松涛

        * @time 2010-8-30 下午04:41:23

        */

       public static void convertBillVOtoLightVO(BOSLightBillVO lightVO, SmartVO svo, Map<String, Integer> updateNames, boolean isReplaceFstatusFlag) {

               if (PubUtils.isNotNull(lightVO) && PubUtils.isNotNull(svo)) {

                       // 设置表名和主键名

                       lightVO.setTableName(svo.getVOMeta().getTable());

                       lightVO.setPkFieldName(svo.getVOMeta().getPkColName());

                       lightVO.setUpdateNames(updateNames);

                       lightVO.setReplaceFstatusFlag(isReplaceFstatusFlag);

                       // 复制相关字段

                       String[] fieldNames = lightVO.getMetaFieldNames();

                       if (PubUtils.isNotNullAndNotEmpty(fieldNames)) {

                               for (String name : fieldNames) {

                                       if (BOSLightBillVO.PK_ID.equals(name)) {

                                               lightVO.setPrimaryKey(svo.getPrimaryKey());

                                       } else {

                                               lightVO.setAttributeValue(name, svo.getAttributeValue(name));

                                       }

                               }

                       }

 

                       // 指定更新的字段名

                       if (PubUtils.isNotNull(updateNames) && PubUtils.isNotNull(updateNames.keySet())) {

                               for (String updateName : updateNames.keySet()) {

                                       lightVO.setAttributeValue(updateName, svo.getAttributeValue(updateName));

                               }

                       }

               }

       }

 

       /**

        *

        * 将日期类型对象转换成上月的字符串“YYYY-MM”形式 <b>参数说明</b>

        *

        * @param date

        * @return

        * @since 1.0

        * @author 蒋力

        * @time 2010-9-26 上午10:43:16

        */

       public static String convertDateLastMonth(Date date) {

               return convertDateSpecifyMonth(date, -1);

       }

 

       /**

        *

        * 将日期形式为"YYYY-MM"的字符串类型对象转换成上月的字符串“YYYY-MM”日期形式,如:"2010-08"转换后为"2010-07"

        * <b>参数说明</b>

        *

        * @param str

        * @return

        * @since 1.0

        * @author 蒋力

        * @time 2010-9-26 上午10:43:16

        */

       public static String convertDateLastMonth(String str) {

               return convertDateSpecifyMonth(str, -1);

       }

 

       /**

        *

        * 将日期类型对象转换成下月的字符串“YYYY-MM”形式 <b>参数说明</b> <b>参数说明</b>

        *

        * @param date

        * @return

        * @since 1.0

        * @author 蒋力

        * @time 2010-10-13 下午02:13:43

        */

       public static String convertDateNextMonth(Date date) {

               return convertDateSpecifyMonth(date, 1);

       }

 

       /**

        *

        * 将日期形式为"YYYY-MM"的字符串类型对象转换成下月的字符串“YYYY-MM”日期形式,如:"2010-08"转换后为"2010-09"

        * <b>参数说明</b>

        *

        * @param str

        * @return

        * @since 1.0

        * @author 蒋力

        * @time 2010-9-26 上午10:43:16

        */

       public static String convertDateNextMonth(String str) {

               return convertDateSpecifyMonth(str, 1);

       }

 

       /**

        *

        * 计算出日期类型对象增加/减去指定月数后的字符串“YYYY-MM”形式 <b>参数说明</b> <b>参数说明</b>

        *

        * @param date

        * @param monthNum

        *          指定要计算的月数,为负表示向上计算,为正表示向后计算

        * @return

        * @since 1.0

        * @author 蒋力

        * @time 2010-10-13 下午02:13:43

        */

       @SuppressWarnings("deprecation")

       public static String convertDateSpecifyMonth(Date date, int monthNum) {

               StringBuffer strbuf = new StringBuffer(date.getYear() + 1900 + "-").append(date.getMonth() + 1);

               Calendar cal = Calendar.getInstance();

               SimpleDateFormat formatDate = new SimpleDateFormat("yyyy-MM");

               try {

                       Date date1 = formatDate.parse(strbuf.toString());

                       cal.setTime(date1);

                       cal.add(Calendar.MONTH, monthNum);

               } catch (ParseException e) {

                       return null;

               }

 

               return formatDate.format(cal.getTime());

       }

 

       /**

        *

        * 方法功能描述:

        *

        * 取昨天同一时间 <b>参数说明</b>

        *

        * @param date

        * @param monthNum

        * @return

        * @since 1.0

        * @author Administrator

        * @time 2010-11-8 下午04:28:31

        */

       public static String getLastDate(String date) {

               Calendar cal = Calendar.getInstance();

               SimpleDateFormat formatDate = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");

               try {

                       Date date1 = formatDate.parse(date);

                       cal.setTime(date1);

                       cal.add(Calendar.DATE, -1);

               } catch (ParseException e) {

                       return null;

               }

 

               return formatDate.format(cal.getTime());

       }

 

       /**

        * 计算年、月的首尾日期 <b>参数说明</b>

        *

        * @param year

        * @param month

        * @return 返回长度为2的String数组

        * @throws ParseException

        *           如果输入的年月格式不正确,则返回ParseException异常

        * @since 1.0

        * @author 蒋力

        * @time 2011-1-12 下午07:24:21

        */

       public static String[] getStartEndDate(int year, int month) throws ParseException {

               // 年月逻辑性

               if (!((year > 0 && month > 0 && month < 13))) {

                       throw new ParseException("年月格式不正确", 0);// 年月不符合逻辑

               }

 

               String[] dateString = new String[2];

               SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

               Date date = sdf.parse(year + "-" + month + "-01");

               Calendar cal = Calendar.getInstance();

 

               dateString[0] = sdf.format(date);

               cal.setTime(date);

               cal.add(Calendar.MONTH, 1);

               cal.add(Calendar.DATE, -1);

               dateString[1] = sdf.format(cal.getTime());

               return dateString;

       }

 

       /**

        *

        * 对于日期形式为"YYYY-MM"的字符串类型对象,计算出增加/减少指定月份后的字符串“YYYY-MM”日期 <b>参数说明</b>

        *

        * @param str

        * @param monthNum

        * @return

        * @since 1.0

        * @author 蒋力

        * @time 2010-9-26 上午10:43:16

        */

       public static String convertDateSpecifyMonth(String str, int monthNum) {

               String returnStr = null;

               Calendar cal = Calendar.getInstance();

               SimpleDateFormat formatDate = new SimpleDateFormat("yyyy-MM");

 

               try {

                       Date date = formatDate.parse(str);

                       cal.setTime(date);

                       cal.add(Calendar.MONTH, monthNum);

                       returnStr = formatDate.format(cal.getTime());

               } catch (ParseException e) {

                       return null;

               }

               return returnStr;

       }

 

       /**

        *

        * 比较两个年月格式的月份差,如:"2010-08"与"2009-08"返回12 <b>参数说明</b>

        *

        * @param str1

        * @param str2

        * @return

        * @since 1.0

        * @author 蒋力

        * @time 2010-10-13 下午02:54:44

        */

       public static Integer equalsDateMonth(String str1, String str2) {

               String data1 = convertDateSpecifyMonth(str1, 0);

               String data2 = convertDateSpecifyMonth(str2, 0);

               // 如果输入的参数格式不正确,则会返回空

               if (isNull(data1, data2)) {

                       return null;

               }

 

               int year1;

               int year2;

               int month1;

               int month2;

               try {

                       year1 = Integer.parseInt(str1.substring(0, 4));

                       year2 = Integer.parseInt(str2.substring(0, 4));

                       month1 = Integer.parseInt(str1.substring(5, 7));

                       month2 = Integer.parseInt(str2.substring(5, 7));

               } catch (Exception e) {

                       return null;

               }

               return (year1 - year2) * 12 + (month1 - month2);

       }

 

       public static Integer equalsDateMonth(Date date1, Date date2) {

               String str1 = convertDateSpecifyMonth(date1, 0);

               String str2 = convertDateSpecifyMonth(date2, 0);

               return equalsDateMonth(str1, str2);

       }

 

       /**

        * 根据分单条件对一组VO进行分单

        *

        * @param sVoName

        *          聚合了VO的类名,如"nc.vo.po.OrderVO"

        * @param sHeadVoName

        *          循环访问类的表头类名,如"nc.vo.po.OrderHeaderVO"

        * @param sBodyVoName

        *          循环访问类的表头类名,如"nc.vo.po.OrderItemVO"

        * @param voSource

        *          需分单的VO,对应类的性质分别与前三个参数对应

        * @param saHeadKey

        *          表头分单依据KEY数组,如new String[]{"cvendid","cbiztype"}

        * @param saBodyKey

        *          表体分单依据KEY数组,如new String[]{"cinvid","cdeptid"}

        * @return 经过分单的聚合VO数组

        * @author 王印芬

        * @since 2002-3-13 11:39:21

        * @modify 2002-05-23 王印芬 修改表体KEY不断重复相加的问题

        */

       public static AggregatedValueObject[] getSplitVO(String sVoName, String sHeadVoName, String sBodyVoName, AggregatedValueObject voSource, String[] saHeadKey,

                       String[] saBodyKey) {

 

               return getSplitVOs(sVoName, sHeadVoName, sBodyVoName, new AggregatedValueObject[] { voSource }, saHeadKey, saBodyKey);

       }

 

       /**

        * 根据分单条件对一组VO进行分单

        *

        * @param sVoName

        *          聚合了VO的类名,如"nc.vo.po.OrderVO"

        * @param sHeadVoName

        *          循环访问类的表头类名,如"nc.vo.po.OrderHeaderVO"

        * @param sBodyVoName

        *          循环访问类的表头类名,如"nc.vo.po.OrderItemVO"

        * @param voaSource

        *          需分单的VO数组,对应类的性质分别与前三个参数对应

        * @param saHeadKey

        *          表头分单依据KEY数组,如new String[]{"cvendid","cbiztype"}

        * @param saBodyKey

        *          表体分单依据KEY数组,如new String[]{"cinvid","cdeptid"}

        * @return 经过分单的聚合VO数组

        * @author 王印芬

        * @since 2002-3-13 11:39:21

        * @modify 2002-05-23 王印芬 修改表体KEY不断重复相加的问题

        */

       public static AggregatedValueObject[] getSplitVOs(String sVoName, String sHeadVoName, String sBodyVoName, AggregatedValueObject[] voaSource,

                       String[] saHeadKey, String[] saBodyKey) {

 

               // 参数正确性检查

               if (sVoName == null || sHeadVoName == null || sBodyVoName == null || voaSource == null) {

                       BOSEnv.out("nc.vo.scm.pub.vosplit.SplitBillVOs.getSplitVOs(String, String, String, AggregatedValueObject [], String [], String [])传入参数不正确!");

                       return null;

               }

 

               // 结构:KEY 分单的所有KEY值相加

               // VALUE 头、体[1...N]

               Hashtable<SqlBuilder, Vector<CircularlyAccessibleValueObject>> hashRetVO = new Hashtable<SqlBuilder, Vector<CircularlyAccessibleValueObject>>();

 

               int iHeadKeyLen = 0;

               int iBodyKeyLen = 0;

               if (saHeadKey != null) {

                       iHeadKeyLen = saHeadKey.length;

               }

               if (saBodyKey != null) {

                       iBodyKeyLen = saBodyKey.length;

               }

               int iLen = voaSource.length;

               for (int i = 0; i < iLen; i++) {

                       // 表头的KEY

                       CircularlyAccessibleValueObject voHead = voaSource[i].getParentVO();

                       SqlBuilder sHeadKey = new SqlBuilder();

                       for (int iKey = 0; iKey < iHeadKeyLen; iKey++) {

                               if (voHead.getAttributeValue(saHeadKey[iKey]) == null || voHead.getAttributeValue(saHeadKey[iKey]).toString().trim().length() < 1) {

                                       sHeadKey.append(PubUtils.STRING_NULL);

                               } else {

                                       sHeadKey.append(voHead.getAttributeValue(saHeadKey[iKey]));

                               }

                       }

 

                       // 表体的KEY

                       CircularlyAccessibleValueObject[] voaItem = voaSource[i].getChildrenVO();

                       int jLen = voaItem == null ? 0 : voaItem.length;

                       for (int j = 0; j < jLen; j++) {

                               SqlBuilder sCurKey = new SqlBuilder(sHeadKey.toString());

                               for (int iKey = 0; iKey < iBodyKeyLen; iKey++) {

                                       if (voaItem[j].getAttributeValue(saBodyKey[iKey]) == null || voaItem[j].getAttributeValue(saBodyKey[iKey]).toString().trim().length() < 1) {

                                               sCurKey.append(PubUtils.STRING_NULL);

                                       } else {

                                               sCurKey.append(voaItem[j].getAttributeValue(saBodyKey[iKey]));

                                       }

                               }

 

                               // 加入到HASH表中

                               if (!hashRetVO.containsKey(sCurKey)) {

                                       Vector<CircularlyAccessibleValueObject> vec = new Vector<CircularlyAccessibleValueObject>();

                                       vec.addElement(voHead);

                                       vec.addElement(voaItem[j]);

                                       hashRetVO.put(sCurKey, vec);

                               } else {

                                       Vector<CircularlyAccessibleValueObject> vec = hashRetVO.get(sCurKey);

                                       vec.addElement(voaItem[j]);

                               }

                       }

               }

 

               // 从哈希表中取出所有VO

               AggregatedValueObject[] voaRet = null;

               try {

                       Class<?> classVO = Class.forName(sVoName);

                       Class<?> classBody = Class.forName(sBodyVoName);

 

                       voaRet = (AggregatedValueObject[]) Array.newInstance(classVO, hashRetVO.size());

                       Enumeration<SqlBuilder> elems = hashRetVO.keys();

                       int i = 0;

                       while (elems.hasMoreElements()) {

                               // 取得VEC

                               Object oCurKey = elems.nextElement();

                               Vector<CircularlyAccessibleValueObject> vec = hashRetVO.get(oCurKey);

 

                               // 申请一个新VO

                               voaRet[i] = (AggregatedValueObject) classVO.newInstance();

                               // 表头

 

                               CircularlyAccessibleValueObject voHead = null;

                               if (vec.elementAt(0) != null) {

                                       voHead = (CircularlyAccessibleValueObject) (vec.elementAt(0)).clone();

                               }

                               // 表体

                               vec.removeElementAt(0);

                               CircularlyAccessibleValueObject[] voaItem = (CircularlyAccessibleValueObject[]) Array.newInstance(classBody, vec.size());

                               vec.copyInto(voaItem);

                               // 设置全VO

                               voaRet[i].setParentVO(voHead);

                               voaRet[i].setChildrenVO(voaItem);

 

                               i++;

                       }

 

               } catch (Exception e) {

                       BOSEnv.out(e);

                       return null;

               }

 

               return voaRet;

       }

 

       /**

        * 根据分单条件对一组CircularlyAccessibleValueObject进行分单

        *

        * @param voaSource

        *          需分单的VO数组

        * @param saKey

        *          分单依据KEY数组,如new String[]{"hid","bid"}

        * @return 经过分单的VO数组

        * @author 王印芬

        * @since 2005-1-29 11:39:21

        */

       public static CircularlyAccessibleValueObject[][] getSplitVOs(CircularlyAccessibleValueObject[] voaSource, String[] saKey) {

 

               // 参数正确性检查

               if (voaSource == null) {

                       BOSEnv.out("nc.vo.scm.pub.vosplit.SplitBillVOs.getSplitVOs(CircularlyAccessibleValueObject[], String [])传入参数不正确!");

                       return null;

               }

 

               // 结构:KEY 分单的所有KEY值相加

               // VALUE ArrayList 体[i]

               HashMap<String, ArrayList<CircularlyAccessibleValueObject>> hmapRetVO = new HashMap<String, ArrayList<CircularlyAccessibleValueObject>>();

 

               // 分单的KEY的个数

               int iKeyNum = (saKey == null ? 0 : saKey.length);

 

               // 按分单值相同的放入同一个HASH中

               int iLen = voaSource.length;

               SqlBuilder sKey = new SqlBuilder();

               String sTempValue = null;

               for (int i = 0; i < iLen; i++) {

                       if (voaSource[i] == null) {

                               continue;

                       }

                       // TODO 这里的分组条件需要清空 add by wangst 2011年1月5日

                       sKey.reset();

                       // 表头的KEY

                       for (int j = 0; j < iKeyNum; j++) {

                               sTempValue = PubUtils.getString_TrimZeroLenAsNull(voaSource[i].getAttributeValue(saKey[j]));

                               sKey.append((sTempValue == null ? "NULL" : sTempValue));

                       }

 

                       // 加入到HASH中

                       if (!hmapRetVO.containsKey(sKey.toString())) {

                               ArrayList<CircularlyAccessibleValueObject> listItem = new ArrayList<CircularlyAccessibleValueObject>();

                               listItem.add(voaSource[i]);

                               hmapRetVO.put(sKey.toString(), listItem);

                       } else {

                               ArrayList<CircularlyAccessibleValueObject> listItem = hmapRetVO.get(sKey.toString());

                               listItem.add(voaSource[i]);

                       }

               }

               if (hmapRetVO.size() == 0) {

                       return null;

               }

 

               // 从HASH中取出所有VO

               CircularlyAccessibleValueObject[][] voaRet = null;

               try {

                       voaRet = (CircularlyAccessibleValueObject[][]) Array.newInstance(voaSource.getClass(), hmapRetVO.size());

 

                       Iterator<ArrayList<CircularlyAccessibleValueObject>> iteror = hmapRetVO.values().iterator();

                       int i = 0;

                       Class<?> classVO = voaSource.getClass().getComponentType();

                       while (iteror.hasNext()) {

                               // 取得VEC

                               ArrayList<CircularlyAccessibleValueObject> listItem = iteror.next();

 

                               // 申请一个新VO

                               voaRet[i] = (CircularlyAccessibleValueObject[]) Array.newInstance(classVO, listItem.size());

                               listItem.toArray(voaRet[i]);

 

                               i++;

                       }

               } catch (Exception e) {

                       BOSEnv.out(e);

                       return null;

               }

 

               return voaRet;

       }

 

       /**

        *

        * 根据表名拆分VO,将VO的表名当做HashMap的Key

        *

        * <b>参数说明</b>

        *

        * @param voaSource

        * @return

        * @since 1.0

        * @author 王松涛

        * @time 2010-8-17 下午02:47:27

        */

       public static HashMap<String, SmartVO[]> getSplitVOsByTableName(SmartVO[] voaSource) {

               HashMap<String, SmartVO[]> retMp = new HashMap<String, SmartVO[]>();

               // 参数正确性检查

               if (!PubUtils.isNotNullAndNotEmpty(voaSource)) {

                       BOSEnv.out("SplitBillVOs.getSplitVOsByTableName(CircularlyAccessibleValueObject[], String [])传入参数不正确!");

                       return null;

               }

               Map<String, List<SmartVO>> hmMap = new HashMap<String, List<SmartVO>>();

 

               for (SmartVO vo : voaSource) {

                       String tablename = vo.getVOMeta().getTable();

                       if (!hmMap.containsKey(tablename)) {

                               List<SmartVO> list = new ArrayList<SmartVO>();

                               list.add(vo);

                               hmMap.put(tablename, list);

                       } else {

                               ArrayList<SmartVO> tempList = (ArrayList<SmartVO>) hmMap.get(tablename);

                               tempList.add(vo);

                               hmMap.put(tablename, tempList);

                       }

               }

 

               // 从HASH中取出所有VO

 

               try {

                       for (Map.Entry<String, List<SmartVO>> mp : hmMap.entrySet()) {

                               String tablename = mp.getKey();

                               List<SmartVO> list = mp.getValue();

                               if (!PubUtils.isNotNullAndNotEmpty(list)) {

                                       continue;

                               }

                               Class<?> classVO = list.get(0).getClass().getComponentType();

                               // 申请一个新VO

                               SmartVO[] voaRet = null;

                               voaRet = (SmartVO[]) Array.newInstance(classVO, list.size());

                               list.toArray(voaRet);

                               retMp.put(tablename, voaRet);

                       }

               } catch (Exception e) {

                       BOSEnv.out(e);

                       return null;

               }

 

               return retMp;

       }

 

       /**

        * 按照指定日期字段时距进行分单 v5.5 zhangcheng

        *

        * @param voName

        * @param headVOName

        * @param bodyVOName

        * @param VOs

        * @param dateKey

        * @param limitDayCount

        * @return

        */

       public static AggregatedValueObject[] getSplitVOsByDate(String voName, String headVOName, String bodyVOName, AggregatedValueObject[] VOs, String dateKey,

                       int limitDayCount) {

 

               try {

                       Vector<AggregatedValueObject> returnVec = new Vector<AggregatedValueObject>();

                       int num = VOs.length;

                       Class<?> bodyVOClass = Class.forName(bodyVOName);

                       Class<?> VOClass = Class.forName(voName);

 

                       for (int i = 0; i < num; i++) {

                               AggregatedValueObject oneVO = VOs[i];

                               CircularlyAccessibleValueObject headVO = (CircularlyAccessibleValueObject) oneVO.getParentVO().clone();

                               CircularlyAccessibleValueObject[] itemVO = oneVO.getChildrenVO();

                               itemVO = getNewOrderVOs(bodyVOName, itemVO, dateKey);

                               Vector<CircularlyAccessibleValueObject> itemVec = new Vector<CircularlyAccessibleValueObject>();

                               String maxDate = SmartVODataUtils.getUFDate(itemVO[0].getAttributeValue(dateKey)).getDateAfter(limitDayCount).toString();

                               String thisDate = "";

                               int rowCount = itemVO.length;

                               for (int j = 0; j < rowCount; j++) {

                                       thisDate = itemVO[j].getAttributeValue(dateKey).toString();

 

                                       if (thisDate.compareTo(maxDate) <= 0) {

                                               itemVec.addElement(itemVO[j]);

                                       } else {

 

                                               AggregatedValueObject oneReturnVO = (AggregatedValueObject) Class.forName(voName).newInstance();

                                               oneReturnVO.setParentVO((CircularlyAccessibleValueObject) headVO.clone());

                                               CircularlyAccessibleValueObject[] bodyVO = (CircularlyAccessibleValueObject[]) Array.newInstance(bodyVOClass, itemVec.size());

                                               itemVec.copyInto(bodyVO);

                                               oneReturnVO.setChildrenVO(bodyVO);

                                               //

                                               returnVec.addElement(oneReturnVO);

                                               itemVec = new Vector<CircularlyAccessibleValueObject>();

                                               itemVec.addElement(itemVO[j]);

                                               maxDate = new UFDate(thisDate).getDateAfter(limitDayCount).toString();

 

                                       }

 

                               }

                               AggregatedValueObject oneReturnVO = (AggregatedValueObject) Class.forName(voName).newInstance();

                               oneReturnVO.setParentVO(headVO);

                               CircularlyAccessibleValueObject[] bodyVO = (CircularlyAccessibleValueObject[]) Array.newInstance(bodyVOClass, itemVec.size());

                               itemVec.copyInto(bodyVO);

                               oneReturnVO.setChildrenVO(bodyVO);

                               //

                               returnVec.addElement(oneReturnVO);

 

                       }

                       AggregatedValueObject[] returnVO = (AggregatedValueObject[]) Array.newInstance(VOClass, returnVec.size());

                       returnVec.copyInto(returnVO);

                       return returnVO;

               } catch (ClassNotFoundException e) {

                       return null;

               } catch (InstantiationException t) {

                       return null;

               } catch (IllegalAccessException r) {

                       return null;

               }

 

       }

 

       /**

        * 表体排序的VO 创建日期:(2001-8-6 11:13:42)

        *

        * @return nc.vo.pub.AggregatedValueObject[]

        * @param VOs

        *          nc.vo.pub.AggregatedValueObject[]

        * @param headKeys

        *          java.lang.String[]

        * @param bodyKeys

        *          java.lang.String[]

        * @param sumKeys

        *          java.lang.String[]

        */

       private static CircularlyAccessibleValueObject[] getNewOrderVOs(String bodyVOName, CircularlyAccessibleValueObject[] itemVOs, String orderKey) {

               int num = itemVOs.length;

               boolean[] app = new boolean[num];

               Vector<CircularlyAccessibleValueObject> returnVec = new Vector<CircularlyAccessibleValueObject>();

 

               try {

 

                       int maxIndex = 0;

                       for (int k = 0; k < num; k++) {

                               String max = "";

 

                               for (int i = 0; i < num; i++) {

                                       if (app[i]) {

                                               continue;

                                       }

                                       Object key = itemVOs[i].getAttributeValue(orderKey) == null ? "&&&" : itemVOs[i].getAttributeValue(orderKey);

                                       if (key.toString().compareTo(max) >= 0) {

                                               max = key.toString();

                                               maxIndex = i;

                                       }

                               }

                               app[maxIndex] = true;

                               returnVec.addElement(itemVOs[maxIndex]);

                       }

               } catch (Exception e) {

                       return null;

               }

               Vector<CircularlyAccessibleValueObject> newVec = new Vector<CircularlyAccessibleValueObject>();

               for (int i = 0; i < num; i++) {

                       newVec.addElement(returnVec.elementAt(num - 1 - i));

               }

               newVec.copyInto(itemVOs);

               return itemVOs;

 

       }

 

       /**

        * 匹配中文正的字符串

        */

       public static final String REGX_CHINESE = "^[\u4e00-\u9fa5]+$";

       /**

        * 匹配由汉字、数字和26个英文字母组成的字符串

        */

       public static final String REGX_LETTER_NUMBER = "^[\u4e00-\u9fa5A-Za-z0-9]+$";

       /**

        * 匹配非负整数(正整数 + 0)

        */

       public static final String REGX_NON_NEGATIVE_INTEGERS = "^\\d+$";

       /**

        * 匹配负浮点数

        */

       public static final String REGX_NEGATIVE_RATIONAL_NUMBERS = "^(-(([0-9]+\\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\\.[0-9]+)|([0-9]*[1-9][0-9]*)))$";

       /**

        * 匹配电话号码

        */

       public static final String REGX_PHONENUM = "([0-9]*[-][0-9]*)|[0-9]*";

       /**

        * 匹配日期时间

        */

       public static final String REGX_DATETIME = "^((\\d{2}(([02468][048])|([13579][26]))[\\-\\/\\s]?((((0?[13578])|"

                       + // 年

                       "(1[02]))[\\-\\/\\s]?((0?[1-9])|"

                       + // 月

                       "([1-2][0-9])|(3[01])))|(((0?[469])|(11))[\\-\\/\\s]?((0?[1-9])|"

                       + // 日

                       "([1-2][0-9])|(30)))|(0?2[\\-\\/\\s]?((0?[1-9])|"

                       + "([1-2][0-9])))))|(\\d{2}(([02468][1235679])|([13579][01345789]))[\\-\\/\\s]?((((0?[13578])|"

                       + "(1[02]))[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\\-\\/\\s]?((0?[1-9])|(1[0-9])|(2[0-8]))))))"

                       +

                       // 时分秒

                       "(\\s(((0?[0-9])|([1][0-9])|([2][0-3]))\\:([0-5]?[0-9])((\\:([0-5]?[0-9])))))";

 

       /**

        * 匹配时间

        */

       public static final String REGX_TIME = "((((0?[0-9])|([1][0-9])|([2][0-3]))\\:([0-5]?[0-9])((\\:([0-5]?[0-9])))))";

 

       /**

        * 匹配年月

        */

       public static final String REGX_YEARDATE = "^([1-2]\\d{3})[\\-](0?[1-9]|10|11|12)";

 

       /**

        * 匹配年

        */

       public static final String REGX_YEAR = "^([1-2]\\d{3})";

 

       /**

        *

        * 匹配时间格式

        *

        * <b>参数说明</b>

        *

        * @param inputStr

        * @return

        * @since 1.0

        * @author 王松涛

        * @time 2010-11-18 上午11:18:51

        */

       public static Boolean isTimeFormat(String inputStr) {

               if (!PubUtils.isNull(inputStr)) {

                       return inputStr.matches(REGX_TIME);

               }

               return false;

       }

 

       /**

        *

        * 匹配年月格式

        *

        * <b>参数说明</b>

        *

        * @param inputStr

        * @return

        * @since 1.0

        * @author 王松涛

        * @time 2010-11-18 上午11:19:03

        */

       public static Boolean isYearDateFormat(String inputStr) {

               if (!PubUtils.isNull(inputStr)) {

                       return inputStr.matches(REGX_YEARDATE);

               }

               return false;

       }

 

       /**

        *

        * 匹配年格式

        *

        * <b>参数说明</b>

        *

        * @param inputStr

        * @return

        * @since 1.0

        * @author 王松涛

        * @time 2010-11-18 上午11:19:03

        */

       public static Boolean isYearFormat(String inputStr) {

               if (!PubUtils.isNull(inputStr)) {

                       return inputStr.matches(REGX_YEAR);

               }

               return false;

       }

 

       /**

        *

        * 匹配是否为日期时间的格式

        *

        * <b>参数说明</b>

        *

        * @param inputStr

        * @return

        * @since 1.0

        * @author 王松涛

        * @time 2010-11-18 上午10:53:38

        */

       public static Boolean isDateTimeFormat(String inputStr) {

               if (!PubUtils.isNull(inputStr)) {

                       return inputStr.matches(REGX_DATETIME);

               }

               return false;

       }

 

       /**

        * 是否非法字符校验此方法只限制中、英、数字的输入,如果是中、英和数字任意组合将返回true

        * 例如:宅急送、宅急送123、ABD宅急送123、123、ABC 都将返回true

        *

        * @since 1.0

        * @author 刘晓辉

        * @time 2010-9-19 下午03:10:04

        */

       public static Boolean isEngChineseNum(String inputStr) {

               if (!PubUtils.isNull(inputStr)) {

                       return inputStr.matches(REGX_LETTER_NUMBER);

               }

               return false;

       }

 

       /**

        *

        * 匹配电话号码(除了数字之外可以含有一个‘-’)

        *

        * <b>参数说明</b>

        *

        * @param inputStr

        * @return

        * @since 1.0

        * @author 王松涛

        * @time 2010-11-18 上午09:23:28

        */

       public static Boolean isLocationNumber(String inputStr) {

               if (!PubUtils.isNull(inputStr)) {

                       return inputStr.matches(REGX_PHONENUM);

               }

               return false;

       }

 

       /**

        * 是否数字 如果是数字将返回true

        *

        * @since 1.0

        * @author 刘晓辉

        * @time 2010-9-19 下午03:31:49

        */

       public static Boolean isNumber(String inputStr) {

               if (!PubUtils.isNull(inputStr)) {

                       return inputStr.matches(REGX_NON_NEGATIVE_INTEGERS);

               }

               return false;

       }

 

       /**

        * 是否是汉字 如果是汉字将返回true

        *

        * @since 1.0

        * @author 刘晓辉

        * @time 2010-9-19 下午03:31:49

        */

       public static Boolean isChinese(String inputStr) {

               if (!PubUtils.isNull(inputStr)) {

                       return inputStr.matches(REGX_CHINESE);

               }

               return false;

       }

 

       /**

        * 是否是负数 包含浮点数,如果是浮点数将返回true,例如:-125.00或-125 都将返回true

        *

        * @since 1.0

        * @author 刘晓辉

        * @time 2010-9-19 下午03:31:49

        */

       public static Boolean isNegative(String inputStr) {

               if (!PubUtils.isNull(inputStr)) {

                       return inputStr.matches(REGX_NEGATIVE_RATIONAL_NUMBERS);

               }

               return false;

       }

 

       /**

        *

        * 全角转半角方法

        *

        * @author 刘晓辉

        * @time 2010-9-19 下午03:24:21

        */

       public static String sbcTodbcChange(String inputStr) {

               if (!PubUtils.isNull(inputStr)) {

                       StringBuffer outBuffer = new StringBuffer();

                       String tempStr = null;

                       byte[] b = null;

 

                       for (int i = 0; i < inputStr.length(); i++) {

                               try {

                                       tempStr = inputStr.substring(i, i + 1);

                                       b = tempStr.getBytes("unicode");

                               } catch (java.io.UnsupportedEncodingException e) {

                                       e.printStackTrace();

                               }

 

                               if (b[2] == -1) {

                                       b[3] = (byte) (b[3] + 32);

                                       b[2] = 0;

 

                                       try {

                                               outBuffer.append(new String(b, "unicode"));

                                       } catch (java.io.UnsupportedEncodingException e) {

                                               e.printStackTrace();

                                       }

                               } else {

                                       outBuffer.append(tempStr);

                               }

                       }

                       return outBuffer.toString();

               }

               return null;

       }

 

       /**

        * 验证工作单号是否是合法的 如果

        *

        * @param vwocode

        * @return 合法返回true,否则返回false

        */

       public static boolean validate(String vwocode) {

               // 如果单号为空,或者位数不为10,或者10个0, 非法

               if (vwocode == null || vwocode.length() != 10 || "0000000000".equals(vwocode)) {

                       return false;

               }

               // 如果单号第2-10位不为 0-9

               for (int i = 1; i < vwocode.length(); i++) {

                       if (vwocode.charAt(i) > '9' || vwocode.charAt(i) < '0') {

                               return false;

                       }

               }

               // 如果单号第1位不为 0-9或"CKPDS"其中一个,非法

               char fC = vwocode.charAt(0);

               boolean bFirstChar = !(fC >= '0' && fC <= '9');// 第一个为字符

 

               if (bFirstChar && !(fC == 'C' || fC == 'K' || fC == 'P' || fC == 'D' || fC == 'S')) {

                       return false;

               }

 

               // 前3位是000或700的不做验证,合法

               if (vwocode.startsWith("000") || vwocode.startsWith("700")) {

                       return true;

               }

 

               int value = Integer.parseInt(vwocode.substring(bFirstChar ? 1 : 0, 9)); // 需要校验的值取1-9或2-9位

               int ten = Integer.parseInt(vwocode.substring(9));// 第10位

 

               return value % 7 == ten; // 取模等于第10位的值

       }

 

       /**

        * 方法功能描述:

        *

        * 计算两工作单号之间的数量 <b>参数说明</b>

        *

        * @param BegCode

        *          起始号段

        * @param endCode

        *          截止号段

        * @return

        * @since 1.0

        * @author luochengyi

        * @time 2010-10-26 下午01:56:43

        */

       @SuppressWarnings("finally")

       public static Long getWorkNum(String BegCode, String endCode) {

               // 如果单号是"CKPDS"其中一个,

               Long counts = Long.valueOf("-1");

               try {

                       Long begNum = null;

                       Long endNum = null;

                       String bworkCode = null;

                       String eworkCode = null;

                       char fC = BegCode.charAt(0);

                       if (fC == 'C' || fC == 'K' || fC == 'P' || fC == 'D' || fC == 'S') {

                               bworkCode = BegCode.substring(1, BegCode.length());

                               eworkCode = endCode.substring(1, endCode.length());

                       } else {

                               bworkCode = BegCode;

                               eworkCode = endCode;

                       }

                       bworkCode = bworkCode.substring(0, bworkCode.length() - 1);

                       eworkCode = eworkCode.substring(0, eworkCode.length() - 1);

                       begNum = Long.parseLong(bworkCode);

                       endNum = Long.parseLong(eworkCode);

                       counts = endNum - begNum + 1;

               } catch (Exception e) {

                       PubUtils.handleException("数据有问题!", e);

               } finally {

                       return counts;

               }

       }

 

       /**

        *

        * 取下一个工作单号

        */

       public static String getNextNum(String workNum) {

               if (PubUtils.isNull(workNum)) {

                       return null;

               }

               char fC = workNum.charAt(0);

               char cend = workNum.charAt(workNum.length() - 1);

               boolean bFirstChar = (fC >= '0' && fC <= '9');// 第一个为字符

               Long lNum = null;

               if (bFirstChar) {

                       lNum = Long.parseLong(workNum);

               } else {

                       lNum = Long.parseLong(workNum.substring(1, workNum.length()));

               }

               if (cend == '6') {

                       lNum = lNum + 4;

               } else {

                       lNum = lNum + 11;

               }

               // 位数不够的补0

               String workCode = lNum.toString();

               if (workCode.length() < workNum.length()) {

                       SqlBuilder sb = new SqlBuilder();

                       int lengTH = workNum.length();

                       if (!bFirstChar) {

                               lengTH = lengTH - 1;

                       }

                       for (int i = workCode.length(); i < lengTH; i++) {

                               sb.append("0");

                       }

                       if (!bFirstChar) {

                               workCode = fC + sb.toString() + workCode;

                       } else {

                               workCode = sb.toString() + workCode;

                       }

               }

               return workCode;

       }

 

       /**

        *

        * 方法功能描述:取得动作名称

        *

        * <b>参数说明</b>

        *

        * @param billStatus

        * @return

        * @since 1.0

        * @author 杜倬

        * @time 2010-10-22 上午10:35:44

        */

       public static String getActionName(int billStatus) {

               switch (billStatus) {

                       case BosStatusConst.AUDITING:

                               return BosStatusConst.SAVE;

                       case BosStatusConst.AUDIT:

                               return BosStatusConst.APPROVE;

                       case BosStatusConst.FREE:

                               return BosStatusConst.UNAPPROVE;

                       default:

                               break;

               }

               return null;

       }

 

       /**

        *

        * 方法功能描述:取ConditionVO数组的某个条件

        *

        * <b>参数说明</b>

        *

        * @param vos

        * @param field

        * @return

        * @since 1.0

        * @author 杜倬

        * @time 2010-10-26 上午11:39:39

        */

       public static String getConditionFromCondVO(ConditionVO[] vos, String field) {

 

               if (!isNotNullAndNotEmpty(vos) || isNull(field)) {

                       return null;

               }

 

               String value = null;

 

               for (ConditionVO vo : vos) {

                       if (field.equals(vo.getFieldCode())) {

                               value = vo.getValue();

                               break;

                       }

               }

 

               return value;

       }

 

       /**

        *

        * 将我们自己的审批流状态转换为UI工厂的审批流状态

        *

        * <b>参数说明</b>

        *

        * @param status

        * @return

        * @since 1.0

        * @author 王松涛

        * @time 2011-3-31 下午03:08:10

        */

       public static int getPFBillStatusFromBillStatus(String status) {

               int billstatus = 0;

               int istatus = Integer.parseInt(status);

               if (istatus == BosStatusConst.AUDIT) {

                       billstatus = BosStatusConst.PF_PASSING;

               } else if (istatus == BosStatusConst.NOPASS) {

                       billstatus = BosStatusConst.PF_NOPASS;

               } else if (istatus == BosStatusConst.AUDITING) {

                       billstatus = BosStatusConst.PF_GOINGON;

               } else if (istatus == BosStatusConst.COMMIT) {

                       billstatus = BosStatusConst.PF_COMMIT;

               } else if (istatus == BosStatusConst.FREE) {

                       billstatus = BosStatusConst.PF_FREE;

               }

               return billstatus;

       }

 

       /**

        *

        * 将UI工厂的审批流状态转换成我们自己的。

        *

        * <b>参数说明</b>

        *

        * @param status

        * @return

        * @since 1.0

        * @author 王松涛

        * @time 2011-3-31 下午03:04:39

        */

       public static int getBillStatusFromPFBillStatus(String status) {

               int billstatus = 0;

               int istatus = Integer.parseInt(status);

               if (istatus == BosStatusConst.PF_PASSING) {

                       billstatus = BosStatusConst.AUDIT;

               } else if (istatus == BosStatusConst.PF_NOPASS) {

                       billstatus = BosStatusConst.NOPASS;

               } else if (istatus == BosStatusConst.PF_GOINGON) {

                       billstatus = BosStatusConst.AUDITING;

               } else if (istatus == BosStatusConst.PF_COMMIT) {

                       billstatus = BosStatusConst.COMMIT;

               } else if (istatus == BosStatusConst.PF_FREE) {

                       billstatus = BosStatusConst.FREE;

               }

               return billstatus;

       }

 

       /**

        * 获取指定时间,N小时前或者后的具体时间;如 (如-3.15小时),表示指定的时间前3.15小时 方法功能描述:

        *

        * <b>参数说明</b>

        *

        * @param ufdatetime

        * @param ufdouble

        * @return

        * @since 1.0

        * @author 周剑平

        * @time 2010-11-25 上午10:27:47

        */

       public static UFDateTime conversionToTime(UFDateTime ufdatetime, UFDouble ufdouble) {

               String strhour = null;

               String strmin = null;

               Integer day = null;

               Integer hour = null;

               String min = null;

 

               if (PubUtils.isNotNull(ufdouble) && ufdouble.compareTo(UFDouble.ZERO_DBL) != 0) {

                       String[] strs = (ufdouble.toString()).split("\\.");

                       strhour = strs[0];

                       strmin = strs[1];

                       day = Integer.valueOf(strhour) / 24;

                       hour = Integer.valueOf(strhour) % 24;

 

                       UFDouble aaaa = new UFDouble("0." + strmin);

                       aaaa = aaaa.multiply(new UFDouble(0.6), 2);

                       String[] minStrs = aaaa.toString().split("\\.");

                       min = minStrs[1];

 

                       Calendar cal = Calendar.getInstance();

                       cal.set(ufdatetime.getYear(), ufdatetime.getMonth() - 1, ufdatetime.getDay(), ufdatetime.getHour(), ufdatetime.getMinute(), ufdatetime.getSecond());

                       if (ufdouble.compareTo(UFDouble.ZERO_DBL) >= 0) {

                               cal.add(Calendar.MINUTE, Integer.valueOf(min));

                               cal.add(Calendar.HOUR, hour);

                               cal.add(Calendar.DATE, day);

                       } else {

                               cal.add(Calendar.MINUTE, Integer.valueOf(min));

                               cal.add(Calendar.HOUR, hour);

                               cal.add(Calendar.DATE, day);

                       }

                       UFDateTime time = new UFDateTime(cal.getTime());

                       return time;

               } else {

                       return ufdatetime;

               }

       }

 

       /**

        *

        * 方法功能描述:

        *

        * <b>参数说明</b>

        *

        * @param strArray

        * @return

        * @since 1.0

        * @author 杜倬

        * @time 2012-9-6 上午09:39:28

        */

       public static String getStrValueFromStrArray(String[] strArray) {

 

               if (!isNotNullAndNotEmpty(strArray)) {

                       return null;

               }

 

               StringBuilder strValue = new StringBuilder();

               for (int i = 0; i < strArray.length; i++) {

                       if (i == strArray.length - 1) {

                               strValue.append("'").append(strArray[i]).append("'");

                       } else {

                               strValue.append("'").append(strArray[i]).append("', ");

                       }

               }

               return strValue.toString();

       }

 

}

  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值