⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 commonutils.java

📁 时间类型转换
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
package com.dtbridge.loan.util;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;

import com.dtbridge.core.domain.screen.FormData;
import com.dtbridge.core.domain.screen.OptionsList;
import com.dtbridge.core.domain.wei.PersonInf;
import com.dtbridge.core.formbean.BeanFactory;
import com.dtbridge.core.service.screen.FormService;
import com.dtbridge.core.struts.BaseFormBean;
import com.dtbridge.core.util.TimeExe;
import com.dtbridge.core.util.Tools;
import com.dtbridge.loan.service.cus.CusComInfoService;
import java.text.SimpleDateFormat;

/**
 * <p>Description: 通用方法实用工具类</p>
 * <p>Company: NCLGroup</p>
 * @author HeYiBo
 * @version 1.0
 */
public class CommonUtils extends BaseFormBean{
	private static CommonUtils instance = null;
	private static final Tools ts = Tools.getInstance();
	private final static FormService formService = (FormService) BeanFactory.getBean("formService");
	private final static CusComInfoService cusComInfoService = (CusComInfoService) BeanFactory.getBean("cusComInfoService");

	public static synchronized CommonUtils getInstance() {
		if (instance == null)
			instance = new CommonUtils();
		return instance;
	}

	private CommonUtils(){}

	public String formatFieldChar(String fieldName,int len){ 	//格式化字段用#填充(企业征信用)
	    	if(fieldName==null){
	    		fieldName="#";
	    	}
	    	String fieldFormatStr=fieldName;
	    	for (int l = byteLength(fieldName); l < len; l++)
	    		fieldFormatStr = fieldFormatStr + "#";

	    	if (byteLength(fieldName)>len){
	    		fieldFormatStr="";
	    		int b=0;
	    		for (int l = 0; l < fieldName.length() ; l++){
	    			if (b>=len){
	    				break;
	    			}
	    			b=b+byteLength(fieldName.substring(l,l+1));
	    			fieldFormatStr = fieldFormatStr + fieldName.substring(l,l+1);
	    		}

	    	}
	    	return fieldFormatStr;
	    }
	    /****************************
	     *
	     * @param dateStr YYYYMMDD
	     * @return		Date
	     * 将YYYYMMDD转换成Date型
	     ****************************/

	    public Date getStrToDate(String dateStr){	//征信用
	    	String dateStrNew="";
	    	dateStrNew=dateStr.substring(0,4)+"-"+dateStr.substring(4,6)+"-"+dateStr.substring(6,8);
	    	return ts.strToDate(dateStrNew);
	    }


	    public String formatFieldZero(String fieldName,int len){ ////征信用格式化字段用0填充
	    	if(fieldName==null){
	    		fieldName="0";
	    	}
	    	String fieldFormatStr=fieldName;
	    	for (int l = byteLength(fieldName); l < len; l++)
	    		fieldFormatStr = "0"+fieldFormatStr;
	    	return fieldFormatStr;
	    }

	    public String formatField(String fieldName,int len){ 	////征信用格式化字段用空格填充
	    	String str="";
	    	if(fieldName==null){
	    		fieldName=" ";
	    	}
	    	if (fieldName.length()>len){
	    		fieldName=fieldName.substring(0,len);
	    	}
	    	String fieldFormatStr=fieldName;
	    	//for (int l = byteLength(fieldName); l < len; l++)
	    	//	fieldFormatStr = fieldFormatStr + " ";
	    	
	    	if (byteLength(fieldName)>len){
	    		fieldFormatStr="";
	    		int b=0;
	    		for (int l = 0; l < fieldName.length() ; l++){
	    			if (b>=len-1){
	    				break;
	    			}
	    			b=b+byteLength(fieldName.substring(l,l+1));
	    			fieldFormatStr = fieldFormatStr + fieldName.substring(l,l+1);
	    		}	
	        		
	    	}
	    	
	    	str=fieldFormatStr;
	    	for (int l = byteLength(fieldFormatStr); l < len; l++)
	    		str = str + " ";
	    	return str;
	    }

		public int byteLength(String s)	//征信用
		{
			if (s == null || s.length() == 0)
			{
				return 0;
			} else
			{
				byte c[] = s.getBytes();
				return c.length;
			}
		}

		/*************************************
	     *
	     * @param dateStr YYYYMMDD 或YYYYMM
	     * @return
	     * 根据输入的年月得到上个年月
	     *************************************/
	    public String getLastYearMonth(String dateStr){//征信用
	    	int year=Integer.parseInt(dateStr.substring(0,4));
			int month=Integer.parseInt(dateStr.substring(4,6));
			int lastYear;
			int lastMonth;
			if(month-1==0){
				lastMonth=12;
				lastYear=year-1;
			}else{
				lastMonth=month-1;
				lastYear=year;
			}
			String lastYearMonth=Integer.toString(lastYear*100+lastMonth);
			return lastYearMonth;
	    }

	  	public String getEndMonth(String rq){	//征信用
	  		//		*********求归属日月末日期YYYYMM
	  		String endMonth="";
	  		String month=rq.substring(4,6);
	  		String year=rq.substring(0,4);
	  		if (month.equals("01")||month.equals("03")||month.equals("05")||month.equals("07")||month.equals("08")||month.equals("10")||month.equals("12"))
	  		{
	  			endMonth=rq+"31";
	  		}else if(month.equals("02"))
	  		{
	  			if (((Integer.parseInt(year)%4==0)&&(Integer.parseInt(year)%100!=0))||((Integer.parseInt(year)%400==0)))
	  			{
	  				endMonth=rq+"29";
	  			}else
	  			{
	  				endMonth=rq+"28";
	  			}
	  		}else
	  		{
	  			endMonth=rq+"30";
	  		}
	  		return endMonth;
	  	}

		/****************************
	    *
	    * @param dateStr1 YYYYMMDD
	    * @param dateStr2 YYYYMMDD
	    * @return
	    * 求两个日期相差的月数
	    ****************************/
	   public long getDiffMonth(String startDateStr,String endDateStr){//征信用
	   	int startYear=Integer.parseInt(startDateStr.substring(0,4));
			int endYear=Integer.parseInt(endDateStr.substring(0,4));
			int startMonth=Integer.parseInt(startDateStr.substring(4,6));
			int endMonth=Integer.parseInt(endDateStr.substring(4,6));
	   	long diffMonth=Math.abs((endYear-startYear)*12+(endMonth-startMonth));
			return diffMonth;
	   }

	   public String getYYYYMMDDHHMMSS(Date date)	//征信用
		{
			SimpleDateFormat formater = new SimpleDateFormat("yyyyMMddHHmmss");
			return formater.format(date);
		}


	    
	    /**DB2中使用此函数转换
		 * <p>Description: 将"a|b|c|d|"格式的字符串转换为"'a','b','c','d'"形式</p>
		 * @return "a,b,c,d"形式
		 * @param oldStr:给定的原数据库中带有"|"的字段
		 */
		public String replaceChar5Field(String oldStr){
	        if(oldStr.equalsIgnoreCase(""))
	            return "";
	        String newStr="";
	        String inter="'";
	        for(int i=0;i<=oldStr.length()-2;i++){
	        	newStr=oldStr.substring(i,i+1);
	        	if (newStr.equals("|")){
	        		newStr="','";
	        	}
	        	inter=inter+newStr;
	        }
	        inter=inter+"'";
		    return inter;
		}

		/**
		 * <p>Description: 将'9.99E10'转换为99900000000.00形式的字符串;与核心通讯用</p>
		 * @return 字符串型double值
		 * @param sourceDoubleValue:给定的原双精度型数据
		 */
		public String formatDouble(double sourceDoubleValue){
			double target = 0.0;
			String str = Double.toString(sourceDoubleValue);
			int index = str.indexOf('E');
			if(index!=-1){
				int bit = Integer.parseInt(str.substring(index+1, str.length()));
				String left = str.substring(0,index);
				if ((int)(left.substring(2,index).length())<=bit){
					String zero="";
					for ( int j=1;j<=(bit-index+4);j++) zero=zero+"0";
					left=left+zero;
				}
				StringBuffer s = new StringBuffer(left);
				s.deleteCharAt(left.indexOf('.'));
				s.insert(bit+1,'.');
				System.out.println("准贷借据金额:" +s.toString());
				return s.toString();
			}else{
				target = sourceDoubleValue;
			}
			System.out.println("准贷借据金额:" +Double.toString(target));
			return Double.toString(target);
		}

	public String DoFormatDate(Date dt_in, boolean bShowTimePart_in) {
		if (bShowTimePart_in){
			return (new SimpleDateFormat("yyyy-MM-dd hh:mm:ss")).format(dt_in);
		}else{
			return (new SimpleDateFormat("yyyy-MM-dd")).format(dt_in);
		}
	}

		 /**
		 * 将字符串转换成一个日期
		 * @param startDate
		 * @return
		 */
		public Date getSwitchDate(String startDate){
		    Date dt=null;
		    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-mm-dd");
		    try{
		        dt = sdf.parse(startDate);
		    }catch(Exception e){
		        e.printStackTrace();
		    }
		    return dt;
		}

	/**
	 * <p>Description: 根据登录用户来显示不同的机构和客户经理(或信贷员)下来列表</p>
	 * @return form:struts中传递来的FORM
	 * @param isShowManagerList:是否显示客户经理列表,managerFieldname:客户经理在form中的字段名... ...
	 */

		public FormData getFormWithDynaOptionList(boolean isShowManagerList,boolean isShowOrgList,PersonInf personInf,FormData form,String orgFieldname,String managerFieldname){
			String userId = personInf.getUserId();
			String jgbm = personInf.getJgbm();
			String orgClass = personInf.getOrgClass();
			if(!cusComInfoService.getUserRole(userId).equalsIgnoreCase("1"))
				orgClass = "subOrgNonCreditor";   // 分社的非信贷员用户
			if(!cusComInfoService.getUserRole(userId).equalsIgnoreCase("1")&&personInf.getOrgClass().equals("1"))
				orgClass = "associatedOrgNonCreditor";   //联社的非信贷员用户
			if(isShowManagerList){
				Map currUser = new HashMap();
				currUser.put("userId", userId);
				currUser.put("branchId", jgbm);
				currUser.put("branchClass", orgClass);
				List cusManagerList = formService.getOtherOption("getCusManagerByOrgClass", currUser);
				setOptions(form, managerFieldname, cusManagerList);		//editById来代替客户经理
			}
			if(isShowOrgList){
				Map currOrgList = new HashMap();
				currOrgList.put("userId", userId);
				currOrgList.put("branchId", jgbm);
				currOrgList.put("branchClass", personInf.getOrgClass());
				List orgList = formService.getOtherOption("getOrgByClass", currOrgList);
				setOptions(form, orgFieldname, orgList);
			}
			return form;
		}

		/**
		public FormData getFormWithDynaOptionList(boolean isShowManagerList,boolean isShowOrgList,PersonInf personInf,FormData form,String orgFieldname,String managerFieldname){
			String userId = personInf.getUserId();
			String jgbm = personInf.getJgbm();
			String orgClass = personInf.getOrgClass();
			if(cusComInfoService.getUserRole(userId).equalsIgnoreCase("1"))
				orgClass = "subOrgCreditor";
			if(!cusComInfoService.getUserRole(userId).equalsIgnoreCase("1"))
				orgClass = "subOrgNonCreditor";   // 分社的非信贷员用户
			if(!cusComInfoService.getUserRole(userId).equalsIgnoreCase("1")&&personInf.getOrgClass().equals("2"))
				orgClass = "associatedOrgNonCreditor";   //联社的非信贷员用户
			if(userId.equals("8888"))
				orgClass = "topOrgNonCreditor";
			System.out.println("orgClass: "+orgClass);
			if(isShowManagerList){

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -