老大工具包补充

main
youHong.ai 2022-11-22 16:33:19 +08:00
parent e9bd4fd92a
commit a11b0b9cf0
7 changed files with 838 additions and 3 deletions

View File

@ -57,7 +57,16 @@ public class GCONST {
private static Properties wsactionProp = null;
private static Properties esbactionProp = null;
private static Properties sapactionProp = null;
/**
* @author youHong.ai
*
*/
private static String systemFilePath = "";
/**
* @author youHong.ai
*
*/
private static String logPath = "";
private static Properties coremailProp = null;
public static String PROP_UTF8 = "UTF-8";
public static String XML_UTF8 = "UTF-8";
@ -177,12 +186,21 @@ public class GCONST {
return propertyPath;
}
public static String setLogPath() {
return ROOT_PATH + "log" + File.separatorChar;
public static void setLogPath(String _logPath) {
logPath = _logPath;
(new BaseBean()).writeLog("systemFilePath:" + getMyGrandpaStackTrace() + " value=" + _logPath);
}
public static String getLogPath() {
return ROOT_PATH + "log" + File.separatorChar;
if("".equals(logPath)){
return ROOT_PATH + "log" + File.separatorChar;
}else{
if(logPath.endsWith(String.valueOf(File.separatorChar))){
return logPath;
}else {
return logPath + File.separatorChar;
}
}
}
public static String getPrintMoudlePath() {

View File

@ -0,0 +1,98 @@
package weaver.zwl.common;
import weaver.common.StringUtil;
import weaver.conn.RecordSetTrans;
import weaver.general.Util;
import weaver.hrm.User;
import weaver.interfaces.workflow.action.Action;
import weaver.soa.workflow.request.RequestInfo;
import weaver.workflow.request.RequestManager;
/**
* Action
* @author bleach
* @date 2019-10-09
* @verion 1.0
*/
public abstract class CusBaseAction extends ToolUtil implements Action {
//当前类名称
private String className = this.getClass().getName();
protected RequestInfo requestInfo;//流程请求信息实体类
protected RecordSetTrans rsts = null;//流程操作事务数据集
protected String tablename;//当前流程表单名称
protected String requestId;//流程请求ID
protected String workflowId;//流程类型ID
protected User user = null;//当前用户
protected int creater = -1;//流程创建人ID
protected RequestManager reqManager = null;
protected String[] baseArray = new String[3];
protected abstract String handle();//Action 具体操作
/**
*
*
* @param requestInfo
* @return
*/
@Override
public String execute(RequestInfo requestInfo) {
this.requestInfo = requestInfo;
this.rsts = requestInfo.getRsTrans();
if (this.rsts == null) {
rsts = new RecordSetTrans();
}
this.initParam();
return handle();
}
/**
*
*/
private void initParam() {
this.requestId = StringUtil.vString(requestInfo.getRequestid());
this.workflowId = StringUtil.vString(requestInfo.getWorkflowid());
this.reqManager = requestInfo.getRequestManager();
this.user = reqManager.getUser();
this.creater = reqManager.getCreater();
this.tablename = requestInfo.getRequestManager().getBillTableName();
//通过系统请求管理类获取表单名称失败,再次查询
if ("".equals(this.tablename)) {
tablename = getBillTableNameByWorkflowId(this.workflowId);
}
//获取流程基础数据
String select_base_sql = "select * from workflow_requestbase where requestid = ?";
try {
if (rsts == null) {
rsts = new RecordSetTrans();
}
String request_name = "";
String request_mark = "";
if (rsts.executeQuery(select_base_sql, requestId)) {
while (rsts.next()) {
request_name = Util.null2String(rsts.getString("requestname"));
request_mark = Util.null2String(rsts.getString("requestmark"));
}
}
baseArray[0] = this.requestId;
baseArray[1] = request_name;
baseArray[2] = request_mark;
this.writeNewDebuggerLog(className, "main_requestname:[" + request_name + "],main_requestmark:[" + request_mark + "],workflowid:[" + workflowId + "],requestid:[" + requestId + "],tablename:[" + tablename + "]");
} catch (Exception e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
this.writeNewDebuggerLog(className, "get workflow dataset error:[" + e1.getMessage() + "/" + e1.toString() + "]");
}
}
}

View File

@ -0,0 +1,501 @@
package weaver.zwl.common;
import weaver.conn.ConnStatementDataSource;
import weaver.conn.RecordSet;
import weaver.general.BaseBean;
import weaver.general.GCONST;
import weaver.general.TimeUtil;
import weaver.general.Util;
import weaver.zwl.common.logging.Logger;
import weaver.zwl.common.logging.LoggerFactory;
import java.io.*;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;
/**
* -
* @author bleach
* @date 2018-01-18
* @version 2.0 Modify By Weilin.Zhu 2018-12-05
* @version 3.0 Modify By Weilin.Zhu 使log4j 2020-03-10
*/
public class ToolUtil extends BaseBean {
Logger logger = LoggerFactory.getLogger("cus");
/**
*
*/
boolean isDebug = true;
/**
* 0[Debugger] 1[Warning] 2[Error]
*/
private int logLevel = 2;
private RecordSet rs = new RecordSet();
/**
*
*/
public ToolUtil() {
// TODO Auto-generated constructor stub
logger = LoggerFactory.getLogger("cus");
//是否开启日志模式
String isopen = getSystemParamValue("Debug_Mode");
//输出日志级别
logLevel = Util.getIntValue(getSystemParamValue("Logger_Level"),-1);
if("1".equals(isopen)){
isDebug = true;
}
}
/**
* ID
* @param workflowid ID
* @return
*/
public String getBillTableNameByWorkflowId(String workflowid){
String tablename = "";
if(!"".equals(workflowid)){
String select_data = "select tablename from workflow_bill where id in (select formid from workflow_base where id = ?)";
if(rs.executeQuery(select_data, workflowid)){
if(rs.next()){
tablename = Util.null2String(rs.getString(1));
}
}
}
return tablename;
}
/**
*
* @param likestr
* @return
*/
public Map<String,String> getSystemParamValueMap(String likestr){
return getSystemParamList(likestr);
}
/**
*
* @return
*/
public Map<String,String> getAllSystemParamValue(){
return getSystemParamList("");
}
/**
*
* @param likestr
* @return
*/
private Map<String,String> getSystemParamList(String likestr){
Map<String,String> param_map = new HashMap<String, String>();
String select_sql = "select uuid,paramvalue from uf_systemconfig";
RecordSet rs = new RecordSet();
if(!"".equals(likestr)){
select_sql += " where uuid like '%" + likestr + "%'";
}
if(rs.execute(select_sql)){
while(rs.next()){
String uuid = Util.null2String(rs.getString(1));
String paramvalue = Util.null2String(rs.getString(2));
param_map.put(uuid, paramvalue);
}
}
return param_map;
}
/**
*
* @param uuid
* @return
*/
public String getSystemParamValue(String uuid){
String paramvalue = "";
if(!"".equals(uuid)){
String select_sql = "select paramvalue from uf_systemconfig where uuid = ?";
RecordSet rs = new RecordSet();
rs.executeQuery(select_sql,uuid);
if(rs.next()){
paramvalue = Util.null2String(rs.getString(1));
}
}
return paramvalue;
}
/**
*
* @param cus_sql SQL
* @param value
* @return
*/
public String getValueByChangeRule(String cus_sql,String value){
return getValueByChangeRule(cus_sql,value,"");
}
/**
*
* @param cus_sql SQL
* @param value
* @param requestid ID
* @return
*/
public String getValueByChangeRule(String cus_sql,String value,String requestid){
return getValueByChangeRule(cus_sql,value,requestid,0);
}
/**
*
* @param cus_sql SQL
* @param value
* @param requestid ID
* @param detailKeyvalue
* @return
*/
public String getValueByChangeRule(String cus_sql,String value,String requestid,int detailKeyvalue){
return getValueByChangeRule(cus_sql,value,requestid,detailKeyvalue,null);
}
/**
*
* @param cus_sql SQL
* @param value
* @param requestid ID
* @param detailKeyvalue
* @pram datasourceid ID
* @return
*/
public String getValueByChangeRule(String cus_sql,String value,String requestid,int detailKeyvalue,String datasourceid){
String endValue = "";
cus_sql = cus_sql.replace("&nbsp;", " ");
cus_sql = cus_sql.replace("{?dt.id}", String.valueOf(detailKeyvalue));
//参数进行替换
String sqlString = cus_sql.replace("{?requestid}", requestid);
sqlString = sqlString.replace("?", value);
sqlString = ToDBC(sqlString);
try {
if(datasourceid != null && !"".equals(datasourceid)){
ConnStatementDataSource csds = new ConnStatementDataSource(datasourceid);
csds.setStatementSql(sqlString);
csds.executeQuery();
if(csds.next()){
endValue = Util.null2String(csds.getString(1));
}
csds.close();
}else{
RecordSet rs = new RecordSet();
if(rs.executeQuery(sqlString)){
rs.next();
endValue = Util.null2String(rs.getString(1));
}
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return endValue;
}
/**
*
* @param cus_sql SQL
* @param value
* @return
*/
public String getValueByChangeRule_SingleParam(String cus_sql,String value){
String endValue = "";
cus_sql = cus_sql.replace("&nbsp;", " ");
RecordSet rs = new RecordSet();
if(rs.executeQuery(cus_sql,value)){
rs.next();
endValue = Util.null2String(rs.getString(1));
}
return endValue;
}
/**
*
* @param input
* @return
*/
public String ToDBC(String input) {
char c[] = input.toCharArray();
for (int i = 0; i < c.length; i++) {
if (c[i] == '\u3000') {
c[i] = ' ';
} else if (c[i] > '\uFF00' && c[i] < '\uFF5F') {
c[i] = (char) (c[i] - 65248);
}
}
String returnString = new String(c);
return returnString;
}
/**
* ID
* @param fieldid
* @return
*/
public String getFieldNameByFieldid(int fieldid){
if(fieldid > 0){
return getFieldNameByFieldid(String.valueOf(fieldid));
}else{
return "";
}
}
/**
* ID
* @param fieldid
* @return
*/
public String getFieldNameByFieldid(String fieldid){
String fieldname = "";
if(!"".equals(fieldid)){
if(fieldid.startsWith(",")){
fieldid = fieldid.substring(1);
}
if(fieldid.endsWith(",")){
fieldid =fieldid.substring(0,fieldid.length() - 1);
}
String select_sql = "select fieldname from workflow_billfield where id in (" + fieldid + ")";
RecordSet rs = new RecordSet();
if(rs.execute(select_sql)){
while(rs.next()){
fieldname += "," + Util.null2String(rs.getString(1));
}
}
}
if(fieldname.startsWith(",")){
fieldname = fieldname.substring(1);
}
return fieldname;
}
/**
*
* @param logstr
*/
public void writeDebuggerLog(String logstr){
if(logLevel >= 0){
logger.info(logstr);
}
}
/**
*
* @param className
* @param logstr
*/
public void writeDebuggerLog(String className,String logstr){
if(logLevel >= 0){
logger.info(logstr);
}
}
/**
*
* @param logstr
*/
public void writeWarningLog(String logstr){
if(logLevel >= 1){
logger.warn(logstr);
}
}
/**
*
* @param className
* @param logstr
*/
public void writeWarningLog(String className,String logstr){
if(logLevel >= 1){
logger.warn(logstr);
}
}
/**
*
* @param logstr
*/
public void writeErrorLog(String logstr){
logger.error(logstr);
}
/**
*
* @param className
* @param logstr
*/
public void writeErrorLog(String className,String logstr){
logger.error(logstr);
}
/**
*
* @param logstr
*/
public void writeDebugLog(Object logstr){
logger.info(logstr);
}
/**
*
* @param logstr
*/
public void writeNewDebuggerLog(Object o,Object logstr){
logger.info(logstr);
}
/**
*
* @param o
* @param s
* @deprecated
*/
protected void writeNewLog(String o,String s){
try {
String filename = "cus_" + TimeUtil.getCurrentDateString() + "_ecology.log";
String folder = GCONST.getRootPath() + "log" + File.separatorChar + "cus";
//this.writeDebugLog("folder:[" + folder + "]");
File f = new File(folder);
// 创建文件夹
if (!f.exists()) {
f.mkdirs();
}
f = new File(folder + File.separatorChar + filename);
//文件不存在,则直接创建
if(!f.exists()){
f.createNewFile();
}
BufferedWriter out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(f, true)));
out.write("[" + o + "][" + TimeUtil.getCurrentTimeString() + "]:"+ s + "\r\n");
//关闭写入流
out.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
writeDebugLog("创建日志文件存在异常:[" + e.getMessage() + "/" + e.toString() + "]");
}
}
/**
* ID
* @param modeid ID
* @return
*/
public String getTableNameByModeID(int modeid){
String modeTableName = "";
if(modeid > 0){
String select_sql = "select tablename from modeinfo m left join workflow_bill wb on m.formid = wb.id " +
"left join ModeFormExtend me on me.formid = wb.id where m.id = ?";
RecordSet rs = new RecordSet();
if(rs.executeQuery(select_sql,modeid)){
if(rs.next()){
modeTableName = Util.null2String(rs.getString(1));
}
}
}
return modeTableName;
}
/**
* ID
* @param requestid
* @return
*/
public String getTableNameByRequestID(int requestid) {
String billTableName = "";
if(requestid > 0) {
String select_sql = "select wbi.tablename from workflow_requestbase wr inner join workflow_base wb on wr.workflowid = wb.id "
+ "inner join workflow_bill wbi on wbi.id = wb.formid where wr.requestid = ?";
RecordSet rs = new RecordSet();
if(rs.executeQuery(select_sql,requestid)){
if(rs.next()){
billTableName = Util.null2String(rs.getString(1));
}
}
}
return billTableName;
}
/**
* @return the isDebug
*/
public boolean isDebug() {
return isDebug;
}
}

View File

@ -0,0 +1,89 @@
package weaver.zwl.common.logging;
/**
* log4j
* @date 2020-03-10
* @version 1.0
*/
public class Log4JLogger implements Logger {
private org.apache.log4j.Logger log;
//类名
private String classname;
@Override
public String getClassname() {
return classname;
}
@Override
public void setClassname(String classname) {
this.classname = classname;
}
@Override
public boolean isDebugEnabled() {
return log.isDebugEnabled();
}
@Override
public boolean isInfoEnabled() {
return log.isInfoEnabled();
}
@Override
public void debug(Object message) {
String method = Thread.currentThread().getStackTrace()[2].getMethodName();
log.debug(classname+"."+method+"() - "+message);
}
@Override
public void debug(Object message, Throwable exception) {
String method = Thread.currentThread().getStackTrace()[2].getMethodName();
log.debug(classname+"."+method+"() - "+message, exception);
}
@Override
public void info(Object message) {
String method = Thread.currentThread().getStackTrace()[2].getMethodName();
log.info(classname+"."+method+"() - "+message);
}
@Override
public void info(Object message, Throwable exception) {
String method = Thread.currentThread().getStackTrace()[2].getMethodName();
log.info(classname+"."+method+"() - "+message, exception);
}
@Override
public void warn(Object message) {
String method = Thread.currentThread().getStackTrace()[2].getMethodName();
log.warn(classname+"."+method+"() - "+message);
}
@Override
public void warn(Object message, Throwable exception) {
String method = Thread.currentThread().getStackTrace()[2].getMethodName();
log.warn(classname+"."+method+"() - "+message, exception);
}
@Override
public void error(Object message) {
String method = Thread.currentThread().getStackTrace()[2].getMethodName();
log.error(classname+"."+method+"() - "+message);
}
@Override
public void error(Object message, Throwable exception) {
String method = Thread.currentThread().getStackTrace()[2].getMethodName();
log.error(classname+"."+method+"() - "+message, exception);
}
@Override
public void init(String name) {
if("".equals(name)) {
name = "cuslog";
}
log = org.apache.log4j.Logger.getLogger(name);
}
}

View File

@ -0,0 +1,78 @@
package weaver.zwl.common.logging;
/**
*
*
* @author zwl
* @date 2020-03-10
*/
public interface Logger {
public boolean isDebugEnabled();
/**
* debug
* @param message
*/
public void debug(Object message);
/**
* debug
* @param message
* @param exception
*/
public void debug(Object message, Throwable exception);
public boolean isInfoEnabled();
/**
* info
* @param message
*/
public void info(Object message);
/**
* info
* @param message
* @param exception
*/
public void info(Object message, Throwable exception);
/**
* warn
* @param message
*/
public void warn(Object message);
/**
* warn
* @param message
* @param exception
*/
public void warn(Object message, Throwable exception);
/**
* error
* @param message
*/
public void error(Object message);
/**
* error
* @param message
* @param exception
*/
public void error(Object message, Throwable exception);
public String getClassname();
public void setClassname(String classname);
/**
*
*
* @param name logger
*/
public void init(String name);
}

View File

@ -0,0 +1,50 @@
package weaver.zwl.common.logging;
/**
*
*
* @author zwl
* @date 2020-03-10
* @version 1.0
*/
public class LoggerFactory {
private static final String loggerName = "cus";
public static Logger getLogger(String LogName, String clazz) {
if("".equals(LogName)) {
LogName = loggerName;
}
Logger logger = new Log4JLogger();
logger.setClassname(clazz);
logger.init(LogName);
return logger;
}
/**
* logger
* @param clazz
* @return
*/
public static Logger getLogger(Class<?> clazz) {
return getLogger(loggerName,clazz.getCanonicalName());
}
/**
* logger
* @param className
* @return
*/
public static Logger getLogger(String className) {
return getLogger(loggerName,className);
}
/**
* logger
* @param
* @return
*/
public static Logger getLogger() {
String className = Thread.currentThread().getStackTrace()[2].getClassName();
return getLogger(loggerName, className);
}
}

View File

@ -18,6 +18,7 @@ public class BaseTest {
GCONST.setServerName("ecology");
GCONST.setRootPath("/Users/aoey.oct.22/company/Fan_wei/code/idea/ecology9-project/src/main/resources/");
GCONST.setSystemFilePath("/Users/aoey.oct.22/company/Fan_wei/code/idea/ecology9-project/file");
GCONST.setLogPath("/Users/aoey.oct.22/company/Fan_wei/code/idea/ecology9-project/log");
}
@Test