?? commonutils.java
字號:
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 + -