diff --git a/com.actionsoft.apps.coe.pal.datamigration/db/1.0/mysql.sql b/com.actionsoft.apps.coe.pal.datamigration/db/1.0/mysql.sql new file mode 100644 index 00000000..24d2625b --- /dev/null +++ b/com.actionsoft.apps.coe.pal.datamigration/db/1.0/mysql.sql @@ -0,0 +1 @@ +CREATE TABLE APP_ACT_COE_PAL_DATAM_LOG(ID CHAR(36) NOT NULL ,WSID CHAR(36),FILENAME VARCHAR(100), FILLPATH VARCHAR(500), LOGPATH VARCHAR(500), CREATEUSER VARCHAR(20),CREATEUSERNAME VARCHAR(20),CREATEDATE DATETIME, STARTDATE DATETIME, ENDTIME DATETIME, RESULTSTATUS SMALLINT(1), MAININFO VARCHAR(500), EXT1 VARCHAR(64),EXT2 VARCHAR(128),EXT3 VARCHAR(255),EXT4 VARCHAR(255) ,CONSTRAINT APP_ACT_COE_PAL_DATAM_LOG_PK PRIMARY KEY (ID)); \ No newline at end of file diff --git a/com.actionsoft.apps.coe.pal.datamigration/db/1.0/oracle.sql b/com.actionsoft.apps.coe.pal.datamigration/db/1.0/oracle.sql new file mode 100644 index 00000000..52a7aa56 --- /dev/null +++ b/com.actionsoft.apps.coe.pal.datamigration/db/1.0/oracle.sql @@ -0,0 +1 @@ +CREATE TABLE APP_ACT_COE_PAL_DATAM_LOG(ID CHAR(36) NOT NULL ,WSID CHAR(36),FILENAME NVARCHAR2(100), FILLPATH NVARCHAR2(500), LOGPATH NVARCHAR2(500), CREATEUSER NVARCHAR2(20),CREATEUSERNAME NVARCHAR2(20), CREATEDATE DATE, STARTDATE DATE, ENDTIME DATE, RESULTSTATUS NUMBER(1), MAININFO NVARCHAR2(500), EXT1 NVARCHAR2(64),EXT2 NVARCHAR2(128),EXT3 NVARCHAR2(255),EXT4 NVARCHAR2(255) ,CONSTRAINT APP_ACT_COE_PAL_DATAM_LOG_PK PRIMARY KEY (ID)); \ No newline at end of file diff --git a/com.actionsoft.apps.coe.pal.datamigration/src/com/actionsoft/apps/coe/pal/datamigration/constant/Constant.java b/com.actionsoft.apps.coe.pal.datamigration/src/com/actionsoft/apps/coe/pal/datamigration/constant/Constant.java index a883bb36..5a202f84 100644 --- a/com.actionsoft.apps.coe.pal.datamigration/src/com/actionsoft/apps/coe/pal/datamigration/constant/Constant.java +++ b/com.actionsoft.apps.coe.pal.datamigration/src/com/actionsoft/apps/coe/pal/datamigration/constant/Constant.java @@ -58,4 +58,16 @@ public class Constant { // 存放与流程同名的角色模型的文件夹名称 public static final String DEFAULT_FOLDER_NAME = "角色模型"; + + + // 日志常量记录 + public static final String LOG_SUCCESS = "成功"; + public static final String LOG_WARNING = "警告"; + public static final String LOG_ERROR = "错误"; + + + + + + } diff --git a/com.actionsoft.apps.coe.pal.datamigration/src/com/actionsoft/apps/coe/pal/datamigration/log/dao/LogDao.java b/com.actionsoft.apps.coe.pal.datamigration/src/com/actionsoft/apps/coe/pal/datamigration/log/dao/LogDao.java new file mode 100644 index 00000000..0b6503b0 --- /dev/null +++ b/com.actionsoft.apps.coe.pal.datamigration/src/com/actionsoft/apps/coe/pal/datamigration/log/dao/LogDao.java @@ -0,0 +1,169 @@ +package com.actionsoft.apps.coe.pal.datamigration.log.dao; + +import com.actionsoft.apps.coe.pal.datamigration.log.model.LogModel; +import com.actionsoft.bpms.commons.database.RowMapper; +import com.actionsoft.bpms.commons.mvc.dao.DaoObject; +import com.actionsoft.bpms.util.DBSql; +import com.actionsoft.bpms.util.UUIDGener; +import com.actionsoft.bpms.util.UtilString; +import com.actionsoft.exception.AWSDataAccessException; + +import java.sql.Connection; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Timestamp; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class LogDao extends DaoObject { + @Override + public int insert(LogModel model) throws AWSDataAccessException { + if (model == null) { + return 0; + } + Connection conn = DBSql.open(); + int r = 0; + if (UtilString.isEmpty(model.getId())) { + model.setId(UUIDGener.getUUID()); + } + Map paraMap = new HashMap(); + paraMap.put(LogModel.ID, model.getId()); + paraMap.put(LogModel.WSID, model.getWsId()); + paraMap.put(LogModel.FILENAME, model.getFileName()); + paraMap.put(LogModel.FILEPATH, model.getFilePath()); + paraMap.put(LogModel.LOGPATH, model.getLogPath()); + paraMap.put(LogModel.CREATEUSER, model.getCreateUser()); + paraMap.put(LogModel.CREATEUSERNAME, model.getCreateUserName()); + paraMap.put(LogModel.CREATEDATE, model.getCreateDate()); + paraMap.put(LogModel.STARTDATE, model.getStartDate()); + paraMap.put(LogModel.ENDDATE, model.getEndDate()); + paraMap.put(LogModel.RESULTTYPE, model.getResultType()); + paraMap.put(LogModel.MAININFO, model.getMainInfo()); + paraMap.put(LogModel.EXT1, model.getExt1()); + paraMap.put(LogModel.EXT2, model.getExt2()); + paraMap.put(LogModel.EXT3, model.getExt3()); + paraMap.put(LogModel.EXT4, model.getExt4()); + String sql = DBSql.getInsertStatement(entityName(), paraMap); + r = DBSql.update(conn, sql, paraMap); + DBSql.close(conn); + return r; + } + + @Override + public int update(LogModel model) throws AWSDataAccessException { + String updateSql = "UPDATE "+ entityName() + + " SET "+ LogModel.WSID +"=?, " + + LogModel.FILENAME +"=?, " + + LogModel.FILEPATH +"=?, " + + LogModel.LOGPATH +"=?, " + + LogModel.CREATEUSER +"=?, " + + LogModel.CREATEUSERNAME +"=?, " + + LogModel.CREATEDATE +"=?, " + + LogModel.STARTDATE +"=?, " + + LogModel.ENDDATE +"=?, " + + LogModel.RESULTTYPE +"=?, " + + LogModel.MAININFO +"=?, " + + LogModel.EXT1 +"=?, " + + LogModel.EXT2 +"=?, " + + LogModel.EXT3 +"=?, " + + LogModel.EXT4 +"=? " + + "WHERE "+ LogModel.ID +"=? "; + return DBSql.update(updateSql, new Object[] {model.getWsId(), model.getFileName(), model.getFilePath(), model.getLogPath(), model.getCreateUser(), model.getCreateUserName(), + model.getCreateDate(), model.getStartDate(), model.getEndDate(), model.getResultType(), model.getMainInfo(), model.getExt1(), model.getExt2(), model.getExt3(), model.getExt4(), model.getId()}); + } + + /** + * 更新关键信息 + * @param id + * @param endDate + * @param resultType + * @param mainInfo + * @return + */ + public int update(String id, Timestamp endDate, int resultType, String mainInfo) { + String updateSql = "UPDATE "+ entityName() + + " SET "+ LogModel.ENDDATE +"=?, " + + LogModel.RESULTTYPE +"=?, " + + LogModel.MAININFO +"=? " + + "WHERE "+ LogModel.ID +"=? "; + return DBSql.update(updateSql, new Object[] {endDate, resultType, mainInfo, id}); + } + + @Override + public String entityName() { + return LogModel.DATABASE_ENTITY; + } + + @Override + public RowMapper rowMapper() { + return new Mapper(); + } + + /** + * 获取单条日志记录信息 + * @param id + * @return + */ + public LogModel getInstance(String id) { + String sql = "SELECT * FROM " + entityName() + " WHERE ID = ?"; + return DBSql.getObject(sql, rowMapper(), id); + } + + /** + * 获取所有日志,按照创建时间倒序查询 + * @return + */ + public List getAllInstance() { + String sql = "SELECT * FROM " + entityName() + " ORDER BY " + LogModel.CREATEDATE + " DESC"; + return DBSql.query(sql, rowMapper()); + } + + /** + * 删除 + * @param id + * @throws AWSDataAccessException + */ + public void remove(String id) throws AWSDataAccessException{ + String sql = "DELETE FROM " + entityName() + + " WHERE " + LogModel.ID + "=?"; + DBSql.update(sql, new Object[]{id}); + } + + /** + * 删除所有 + */ + public void removeAll() throws AWSDataAccessException{ + String sql = "DELETE FROM " + entityName(); + DBSql.update(sql); + } + + private class Mapper implements RowMapper { + public LogModel mapRow(ResultSet rset, int rowNum) throws SQLException { + LogModel model = new LogModel(); + try { + model.setId(rset.getString(LogModel.ID)); + model.setWsId(rset.getString(LogModel.WSID)); + model.setFileName(rset.getString(LogModel.FILENAME)); + model.setFilePath(rset.getString(LogModel.FILEPATH)); + model.setLogPath(rset.getString(LogModel.LOGPATH)); + model.setCreateUser(rset.getString(LogModel.CREATEUSER)); + model.setCreateUserName(rset.getString(LogModel.CREATEUSERNAME)); + model.setCreateDate(rset.getTimestamp(LogModel.CREATEDATE)); + model.setStartDate(rset.getTimestamp(LogModel.STARTDATE)); + model.setEndDate(rset.getTimestamp(LogModel.ENDDATE)); + model.setResultType(rset.getInt(LogModel.RESULTTYPE)); + model.setMainInfo(rset.getString(LogModel.MAININFO)); + model.setExt1(rset.getString(LogModel.EXT1)); + model.setExt2(rset.getString(LogModel.EXT2)); + model.setExt3(rset.getString(LogModel.EXT3)); + model.setExt4(rset.getString(LogModel.EXT4)); + } catch (Exception e) { + e.printStackTrace(); + } + return model; + } + } + + +} diff --git a/com.actionsoft.apps.coe.pal.datamigration/src/com/actionsoft/apps/coe/pal/datamigration/log/model/LogModel.java b/com.actionsoft.apps.coe.pal.datamigration/src/com/actionsoft/apps/coe/pal/datamigration/log/model/LogModel.java new file mode 100644 index 00000000..8cb576f5 --- /dev/null +++ b/com.actionsoft.apps.coe.pal.datamigration/src/com/actionsoft/apps/coe/pal/datamigration/log/model/LogModel.java @@ -0,0 +1,177 @@ +package com.actionsoft.apps.coe.pal.datamigration.log.model; + +import java.sql.Timestamp; + +/** + * 日志记录表 + */ +public class LogModel { + + public static final String DATABASE_ENTITY = "APP_ACT_COE_PAL_DATAM_LOG"; + public static final String ID = "ID"; + public static final String WSID = "WSID"; + public static final String FILENAME = "FILENAME"; + public static final String FILEPATH = "FILEPATH"; + public static final String LOGPATH = "LOGPATH"; + public static final String CREATEUSER = "CREATEUSER"; + public static final String CREATEUSERNAME = "CREATEUSERNAME"; + public static final String CREATEDATE = "CREATEDATE"; + public static final String STARTDATE = "STARTDATE"; + public static final String ENDDATE = "ENDDATE"; + public static final String RESULTTYPE = "RESULTTYPE"; + public static final String MAININFO = "MAININFO"; + public static final String EXT1 = "EXT1"; + public static final String EXT2 = "EXT2"; + public static final String EXT3 = "EXT3"; + public static final String EXT4 = "EXT4"; + + + + private String id; + private String wsId;// 资产库ID + private String fileName;// 上传文件名,若若是多个文件,只写一个文件,例如xxxxx文件等xx个文件 + private String filePath;// dc路径(包含此次上传所有文件的上级文件夹路径) + private String logPath;// dc路径,存储日志文件的路径 + private String createUser;// 创建人userId + private String createUserName;// 创建人中文名称 + private Timestamp createDate;// 上传时间,程序开始导入时间 + private Timestamp startDate;// 上传时间,程序开始导入时间 + private Timestamp endDate;// 最终结束时间,成功/失败都需要记录 + private int resultType;// 结果,0进行中,1成功,2失败 + private String mainInfo;// 一句话简介整个上传结果,内容无限制,示例:若是进行中可描述为:正在上传;若是失败可描述为具体的异常信息;若是成功可描述为:上传多少条,成功多少条信息 + private String ext1;// 扩展字段 + private String ext2;// 扩展字段 + private String ext3;// 扩展字段 + private String ext4;// 扩展字段 + + public LogModel() { + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getWsId() { + return wsId; + } + + public void setWsId(String wsId) { + this.wsId = wsId; + } + + public String getFileName() { + return fileName; + } + + public void setFileName(String fileName) { + this.fileName = fileName; + } + + public String getFilePath() { + return filePath; + } + + public void setFilePath(String filePath) { + this.filePath = filePath; + } + + public String getLogPath() { + return logPath; + } + + public void setLogPath(String logPath) { + this.logPath = logPath; + } + + public String getCreateUser() { + return createUser; + } + + public void setCreateUser(String createUser) { + this.createUser = createUser; + } + + public String getCreateUserName() { + return createUserName; + } + + public void setCreateUserName(String createUserName) { + this.createUserName = createUserName; + } + + public Timestamp getCreateDate() { + return createDate; + } + + public void setCreateDate(Timestamp createDate) { + this.createDate = createDate; + } + + public Timestamp getStartDate() { + return startDate; + } + + public void setStartDate(Timestamp startDate) { + this.startDate = startDate; + } + + public Timestamp getEndDate() { + return endDate; + } + + public void setEndDate(Timestamp endDate) { + this.endDate = endDate; + } + + public int getResultType() { + return resultType; + } + + public void setResultType(int resultType) { + this.resultType = resultType; + } + + public String getMainInfo() { + return mainInfo; + } + + public void setMainInfo(String mainInfo) { + this.mainInfo = mainInfo; + } + + public String getExt1() { + return ext1; + } + + public void setExt1(String ext1) { + this.ext1 = ext1; + } + + public String getExt2() { + return ext2; + } + + public void setExt2(String ext2) { + this.ext2 = ext2; + } + + public String getExt3() { + return ext3; + } + + public void setExt3(String ext3) { + this.ext3 = ext3; + } + + public String getExt4() { + return ext4; + } + + public void setExt4(String ext4) { + this.ext4 = ext4; + } +} diff --git a/com.actionsoft.apps.coe.pal.datamigration/src/com/actionsoft/apps/coe/pal/datamigration/util/LogUtil.java b/com.actionsoft.apps.coe.pal.datamigration/src/com/actionsoft/apps/coe/pal/datamigration/util/LogUtil.java new file mode 100644 index 00000000..42e4b63e --- /dev/null +++ b/com.actionsoft.apps.coe.pal.datamigration/src/com/actionsoft/apps/coe/pal/datamigration/util/LogUtil.java @@ -0,0 +1,166 @@ +package com.actionsoft.apps.coe.pal.datamigration.util; + +import com.actionsoft.apps.coe.pal.datamigration.log.dao.LogDao; +import com.actionsoft.apps.coe.pal.datamigration.log.model.LogModel; +import com.actionsoft.bpms.commons.log.auditing.constant.AuditConst; +import com.actionsoft.bpms.commons.security.logging.model.Level; +import com.actionsoft.bpms.server.UserContext; +import com.actionsoft.sdk.local.SDK; + +import java.io.*; +import java.nio.charset.StandardCharsets; +import java.sql.Timestamp; +import java.util.List; + +public class LogUtil { + + /** + * 追加日志内容 + * @param content 内容 + * @param file 文件 + */ + public static void appendLog(String content, File file) { + try { + String logFilePath = file.getPath(); + // 构造函数中的第二个参数true表示以追加形式写文件 + FileOutputStream fos = new FileOutputStream(logFilePath, true); + OutputStreamWriter osw = new OutputStreamWriter(fos, StandardCharsets.UTF_8); + osw.write(content + "\n"); + osw.close(); + fos.close(); + } catch (IOException e) { + e.printStackTrace(); + System.out.println("文件写入失败!" + e); + } + } + + public static void appendLog(String content, File ... files) { + for (File file : files) { + appendLog(content, file); + } + } + + public static String getStackTrace(Throwable t) { + StringWriter sw = new StringWriter(); + PrintWriter pw = new PrintWriter(sw); + try { + t.printStackTrace(pw); + return sw.toString(); + } finally { + pw.close(); + } + } + + public static String getLogContent(File file) { + StringBuilder builder = new StringBuilder(); + InputStreamReader reader = null; + BufferedReader br = null; + try { + reader = new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8); + br = new BufferedReader(reader); + String s; + while ((s = br.readLine()) != null) { + builder.append(s).append("\n"); + } + + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } finally { + try { + if (reader != null) { + reader.close(); + } + if (br != null) { + br.close(); + } + } catch (IOException e) { + e.printStackTrace(); + } + } + return builder.toString(); + } + + /** + * 记录一条审计日志 + * @param me + * @param op + * @param obj + * @param info + * @param level + */ + public static void recordAuditLog(UserContext me, String op, String obj, String info, Level level) { + SDK.getLogAPI().audit(AuditConst.CHANNEL_CLIENT, AuditConst.CATALOG_PROCESS, me.getUID(), op, obj, info, me.getClientIP(), level); + } + + /* + 创建日志 + 查询日志 + 删除日志 + 更新日志 + */ + + /** + * 创建日志 + * @param model + * @return + */ + public static int createLog(LogModel model) { + return new LogDao().insert(model); + } + + /** + * 查询日志 + * @param id + * @return + */ + public static LogModel queryLog(String id) { + return new LogDao().getInstance(id); + } + + /** + * 删除日志 + * @param id + */ + public static void removeLog(String id) { + new LogDao().remove(id); + } + + /** + * 清空日志 + */ + public static void removeAllLog() { + new LogDao().removeAll(); + } + + /** + * 查询所有日志,按照创建时间倒序 + * @return + */ + public static List queryAllLog() { + return new LogDao().getAllInstance(); + } + + /** + * 更新日志 + * @param model + * @return + */ + public static int updateLog(LogModel model) { + return new LogDao().update(model); + } + + /** + * 更新日志 + * @param id + * @param endDate 结束时间 + * @param resultType 结果状态 + * @param mainInfo 主要信息 + * @return + */ + public static int updateLog(String id, Timestamp endDate, int resultType, String mainInfo) { + return new LogDao().update(id, endDate, resultType, mainInfo); + } + +}