ENDRPrint/.svn/pristine/81/811eefd332415d31703dd21d5377c100c0b123bd.svn-base

442 lines
13 KiB
Plaintext
Raw Normal View History

2024-08-14 10:33:27 +07:00
package th.co.muangthai.endrprint.util;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.text.ParseException;
import java.util.Date;
import java.util.ResourceBundle;
public class TextContent {
public static final String sessionLogin = "@UserBeans";
public static String DEPLOYMENT_VERSION = "";
public static final String sessionPathFile = "@PathFile";
public static final String systemId = "ENDR";
public static final BigDecimal errorFlagER = new BigDecimal("1");
public static final BigDecimal errorFlagOK = new BigDecimal("0");
public static final BigDecimal errorFlagConf = new BigDecimal("2");
public static boolean getChkFormatDate(String data){
if(VSMUtil.isNotEmpty(data)){
if(data.length() != 10 ){
return false;
}else
if( data.contains("00/") ){
return false;
}else
if( data.contains("99/") ){
return false;
}else{
return true;
}
}
return false;
}
public static String getStringObj(Object data){
if(VSMUtil.isNotEmpty(data)){
return data.toString();
}
return "";
}
public static String toTrimData(String data){
if(VSMUtil.isNotEmpty(data)){
return data.trim();
}
return "";
}
public static String toTrimData(BigInteger data){
if(VSMUtil.isNotEmpty(data)){
return data.toString();
}
return "";
}
public static String toTrimData(BigDecimal data){
if(VSMUtil.isNotEmpty(data)){
return data.toString();
}
return "";
}
public static Date toTrimDate(String data) throws ParseException {
String str = toTrimData(data);
if(VSMUtil.isNotEmpty( str ) && getChkFormatDate(str)){
try{
Date xx = DateUtil.toDate(toTrimData(data), "dd/MM/yyyy");
return xx;
}catch (Exception e){
return null;
}
}
return null;
}
public static Date toTrimDate(Integer data) throws ParseException {
if(VSMUtil.isNotEmpty(data)){
String txt = data.toString();
if( txt.length() == 7 ){
String mmdd = txt.substring(3);
String yyy = txt.substring(0,3);
int xx = 1800 + Integer.parseInt(yyy);
//System.out.println(xx+mmdd);
//System.out.println(yyy);
try {
Date xxv = DateUtil.toDate(xx+mmdd,"yyyyMMdd");
return xxv;
}catch (Exception e){
return null;
}
}
}
return null;
}
public static Date toTrimDateddMMyyyy(String data) throws ParseException {
String str = toTrimData(data);
if(VSMUtil.isNotEmpty( str )){
try{
return DateUtil.toDate(toTrimData(data) ,"yyyyMMdd");
}catch (Exception e){
return null;
}
}
return null;
}
public static BigDecimal toTrimBigDecimal(String data) throws ParseException {
if(VSMUtil.isNotEmpty(toTrimData(data))){
return new BigDecimal(toTrimData(data));
}
return null;
}
public static BigDecimal toTrimBigInteger(BigInteger data) throws ParseException {
if(VSMUtil.isNotEmpty(data)){
return new BigDecimal(toTrimData(data.toString()));
}
return null;
}
public static BigDecimal toTrimBigDecimal(Integer data) throws ParseException {
if(VSMUtil.isNotEmpty(data)){
return new BigDecimal(toTrimData(data.toString()));
}
return null;
}
public static BigDecimal toTrimBigDecimal(BigInteger data) throws ParseException {
if(VSMUtil.isNotEmpty(data)){
return new BigDecimal(toTrimData(data.toString()));
}
return null;
}
public static BigDecimal toTrimBigDecimal(Double data) throws ParseException {
if(VSMUtil.isNotEmpty(data)){
return new BigDecimal(toTrimData(data.toString()));
}
return null;
}
public static Date toTrimDateYYYYMMDD(String data) throws ParseException {
// 25571201
String tmp = toTrimData(data);
if(VSMUtil.isNotEmpty(tmp)){
try {
int yy = Integer.parseInt( tmp.substring(0,4) ) - 543;
String mmdd = tmp.substring(4,8);
return DateUtil.toDate(yy+mmdd, "yyyyMMdd");
}catch (Exception e){
}
}
return null;
}
public static BigDecimal toTrimBigDecimalFormatInt(BigDecimal data) throws ParseException {
if(VSMUtil.isNotEmpty(data)){
String x = data.toString();
//String[] xx = x.split(".");
int i = x.indexOf(".");
try {
if(i < 0){
return new BigDecimal(x);
}else{
String xx = x.substring(0,(i));
return new BigDecimal(xx);
}
}catch (Exception e){
}
}
return null;
}
public static BigDecimal toTrimBigDecimalFormatInt(BigInteger data) throws ParseException {
if(VSMUtil.isNotEmpty(data)){
String x = data.toString();
//String[] xx = x.split(".");
int i = x.indexOf(".");
try {
if(i < 0){
return new BigDecimal(x);
}else{
String xx = x.substring(0,(i));
return new BigDecimal(xx);
}
}catch (Exception e){
}
}
return null;
}
// public static String getResourceBundle(String str){
// //ResourceBundle bundle = ResourceBundle.getBundle("message");
// //return bundle.getString(str);
// return SessionUtil.getMsg(str);
// }
public static String getEAppResourceBundle(String str){
ResourceBundle bundle = ResourceBundle.getBundle("eapp");
return bundle.getString(str);
}
public static String getErrorMsg(Exception e){
StringWriter writer = new StringWriter();
PrintWriter pw = new PrintWriter(writer);
e.printStackTrace(pw);
String errorDetail = writer.toString();
String[] f = errorDetail.split("\n");
return f[0];
}
// public static String getMsgErrorBRMS(Exception e){
// return getResourceBundle("error_connect_brms")+" : "+getErrorMsg(e);
// }
// public static String getIpMtem(){
// return getResourceBundle("mtem_ip_client");
// }
public static String getCodeChk0(String code,int length){
String chkCode = "";
int count = 0;
if(VSMUtil.isEmpty(code) || length <= 0){
return "000000";
}
count = length - code.length();
if( count <= 0 ){
return code;
}
for(int i = 1 ; i <= count ; i++){
chkCode = "0"+chkCode;
}
return chkCode+code;
}
public static String getDdopAndAtm(String code){
String chkCode = "0";
if(VSMUtil.isNotEmpty(code)){
if("N".equals(code)){
chkCode = "0";
}else{
chkCode = "1";
}
}else{
chkCode = "0";
}
return chkCode;
}
public static Date toTrimDateLastDayInMM(String data) throws ParseException {
String str = toTrimData(data);
if(VSMUtil.isNotEmpty( str )){
try{
String tmp = toTrimData(data);
if(VSMUtil.isEmpty(tmp)){
return null;
}
Date d1 = DateUtil.toDate("01"+tmp, "ddMMyyyy");
d1 = DateUtil.add("mm", 1, d1);
d1 = DateUtil.add("dd", -1, d1);
return DateUtil.getLastDateInMonth(d1);
}catch (Exception e){
}
}
return null;
}
public static String toConcatStr(String code,String data) {
String strCode = "";
if(VSMUtil.isNotEmpty(code)){
strCode = "("+code+") ";
}
String strDesc = "";
if(VSMUtil.isNotEmpty(data)){
strDesc = data;
}
strCode = (strCode+strDesc).trim();
return strCode;
}
public static Object[] toSubFLNameStr(String fullName) {
String strFName = "";
String strLName = " ";
if(VSMUtil.isNotEmpty(fullName)){
int i = fullName.indexOf(" ");
//System.out.println("" + i);
if(i > 0 ){
strFName = fullName.substring(0,i).trim();
strLName = fullName.substring(i+1).trim();
}else{
strFName = fullName.trim();
}
//System.out.println("strFName > " + strFName);
//System.out.println("strLName > " + strLName);
}
return new Object[]{strFName,strLName};
}
public static Date toDateAS400T2Date(String strDate) {
Date dateData = null;
try{
if(VSMUtil.isNotEmpty(strDate)){
strDate = strDate.trim();
String strYY = strDate.substring(0,3);
int i = Integer.parseInt(strYY) + 1800;
String strMmDd = strDate.substring(3);
dateData = DateUtil.toDate(i+strMmDd,"yyyyMMdd");
}
}catch (Exception e){
}
return dateData;
}
//1800
public static String getFullPlanCode(String planCode ,String rs) {
String planCodeRs = null;
try{
if(VSMUtil.isNotEmpty(planCode) && VSMUtil.isNotEmpty(rs)){
planCodeRs =( planCode.trim()+" ").substring(0,5)+rs.trim();
}
}catch (Exception e){
//
}
return planCodeRs;
}
public static String getClientTypeDesc(String clientTypeCode) {
String planCodeRs = null;
try{
if("I".equals(clientTypeCode)){
planCodeRs = "Insured";
}else if("O".equals(clientTypeCode)){
planCodeRs = "Owner";
}else if("O,I".equals(clientTypeCode)){
planCodeRs = "Owner/Insured";
}else if("O,N".equals(clientTypeCode)){
planCodeRs = "Owner/Insured(Other C#)";
}else if("N".equals(clientTypeCode)){
planCodeRs = "Insured(Other C#)";
}else{
planCodeRs = "Insured";
}
}catch (Exception e){
//
}
return planCodeRs;
}
public static String[] getSubFLName(String fullName) {
String[] planCodeRs = {"",""};
try{
if(VSMUtil.isNotEmpty(fullName)){
int i = fullName.indexOf(" ");
if(i > 0){
planCodeRs[0] = fullName.substring(0,i).trim();
planCodeRs[1] = fullName.substring(i).trim();
}else{
planCodeRs[0] = fullName.trim();
planCodeRs[1] = null;
}
}
}catch (Exception e){
//
}
return planCodeRs;
}
public static String getTypeProcess(String jobProcessCode) {
String typeProcess = null;
try{
if(VSMUtil.isNotEmpty(jobProcessCode)){
if("P0023".equals(jobProcessCode) ||
"P0041".equals(jobProcessCode)){
typeProcess = "E";
}else
if("P0025".equals(jobProcessCode) ||
"P0058".equals(jobProcessCode) ||
"P0059".equals(jobProcessCode)) {
typeProcess = "K";
} else
if("P0020".equals(jobProcessCode) ||
"P0024".equals(jobProcessCode)){
typeProcess = "C";
} else {
typeProcess = null;
}
}
}catch (Exception e){
//
}
return typeProcess;
}
public static void main(String[] args)
{
try {
//System.out.println( toTrimDateYYYYMMDD("25571201") );
/*JobStepPosService b = new JobStepPosService();
RequestQueryJobStepForm requestForm = new RequestQueryJobStepForm();
requestForm.setClientNumber("1201729659");
ResponseQueryJobStepForm c = b.queryJobStep(requestForm);
System.out.println(c.getMessageStatus());*/
//System.out.println(toConcatStr(null,"ll"));
//toSubFLNameStr("hhhh 55fgfg");
//System.out.println(toDateAS400T2Date("2150101"));
//System.out.println(getFullPlanCode("123" ,"9"));
//System.out.println(toTrimDate(Integer.parseInt("1450101")));
System.out.println(getChkFormatDate("00/00/1800"));
} catch (Exception e) {
//e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
}
}
}