Search in sources :

Example 1 with OperationLog

use of com.qlangtech.tis.manage.biz.dal.pojo.OperationLog in project tis by qlangtech.

the class OfflineManager method editDatasourceTable.

public void editDatasourceTable(TISTable table, BasicModule action, IPluginContext pluginContext, Context context) throws Exception {
    String dbName = table.getDbName();
    String tableLogicName = table.getTableName();
    // 检查db是否存在
    DatasourceDbCriteria dbCriteria = new DatasourceDbCriteria();
    dbCriteria.createCriteria().andNameEqualTo(dbName);
    List<DatasourceDb> dbList = workflowDAOFacade.getDatasourceDbDAO().minSelectByExample(dbCriteria);
    if (CollectionUtils.isEmpty(dbList)) {
        action.addErrorMessage(context, "找不到这个数据库");
        return;
    }
    int dbId = dbList.get(0).getId();
    // 检查表是否存在
    DatasourceTableCriteria tableCriteria = new DatasourceTableCriteria();
    tableCriteria.createCriteria().andDbIdEqualTo(dbId).andNameEqualTo(tableLogicName);
    List<DatasourceTable> tableList = workflowDAOFacade.getDatasourceTableDAO().minSelectByExample(tableCriteria);
    if (CollectionUtils.isEmpty(tableList)) {
        action.addErrorMessage(context, "该数据库下没有表" + tableLogicName);
        return;
    }
    int tableId = tableList.get(0).getId();
    DataSourceFactoryPluginStore dbPlugin = TIS.getDataBasePluginStore(new PostedDSProp(dbName));
    dbPlugin.saveTable(tableLogicName);
    // update git
    // String path = dbName + "/" + tableLogicName;
    // GitUtils.$().createTableDaily(table, "edit table " + table.getTableLogicName());
    OperationLog operationLog = new OperationLog();
    operationLog.setUsrName(action.getLoginUserName());
    operationLog.setUsrId(action.getUserId());
    operationLog.setOpType("editDatasourceTable");
    action.addActionMessage(context, "数据库表修改成功");
    action.setBizResult(context, tableId);
}
Also used : OperationLog(com.qlangtech.tis.manage.biz.dal.pojo.OperationLog)

Example 2 with OperationLog

use of com.qlangtech.tis.manage.biz.dal.pojo.OperationLog in project tis by qlangtech.

the class OperationLogDAOImpl method deleteByPrimaryKey.

public int deleteByPrimaryKey(Integer opId) {
    OperationLog key = new OperationLog();
    key.setOpId(opId);
    return this.deleteRecords("operation_log.ibatorgenerated_deleteByPrimaryKey", key);
}
Also used : OperationLog(com.qlangtech.tis.manage.biz.dal.pojo.OperationLog)

Example 3 with OperationLog

use of com.qlangtech.tis.manage.biz.dal.pojo.OperationLog in project tis by qlangtech.

the class OperationLogInterceptor method doIntercept.

@Override
protected String doIntercept(ActionInvocation invocation) throws Exception {
    BasicModule action = (BasicModule) invocation.getAction();
    final Method method = action.getExecuteMethod();
    final String result = invocation.invoke();
    Func func = method.getAnnotation(Func.class);
    if (func != null && !func.sideEffect()) {
        return result;
    }
    AppDomainInfo appDomain = CheckAppDomainExistValve.getAppDomain(daoContext);
    OperationLog log = new OperationLog();
    log.setOpType(BasicModule.parseMehtodName());
    if (StringUtils.startsWith(log.getOpType(), "doGet")) {
        return result;
    }
    log.setCreateTime(new Date());
    if (!(appDomain instanceof Nullable)) {
        log.setAppName(appDomain.getAppName());
    }
    ActionProxy proxy = invocation.getProxy();
    // log.setOpType(proxy.getMethod());
    HttpServletRequest request = ServletActionContext.getRequest();
    if (StringUtils.indexOf(request.getClass().getSimpleName(), "Mock") > -1) {
        // 当前是测试流程的话就不需要记录日志了
        return result;
    }
    IUser user = UserUtils.getUser(request, daoContext);
    if (user == null) {
        throw new IllegalStateException("user can not be null");
    }
    StringBuffer jsonObject = new StringBuffer();
    JSONObject params = null;
    Map<String, String[]> paramsMap = null;
    String url = request.getRequestURL().toString();
    jsonObject.append("request:");
    jsonObject.append(url).append("\n");
    String requestBody = null;
    if (!ConfigFileContext.HTTPMethod.GET.name().equals(request.getMethod())) {
        paramsMap = request.getParameterMap();
        if (paramsMap.size() > 0) {
            params = new JSONObject();
            for (Map.Entry<String, String[]> entry : paramsMap.entrySet()) {
                if (entry.getValue().length == 1) {
                    params.put(entry.getKey(), entry.getValue()[0]);
                } else {
                    params.put(entry.getKey(), entry.getValue());
                }
            }
            jsonObject.append("params:").append("\n");
            jsonObject.append(params.toString(1)).append("\n");
        }
        try (ServletInputStream input = request.getInputStream()) {
            if (!input.isFinished()) {
                requestBody = IOUtils.toString(input, TisUTF8.get());
                jsonObject.append("body:").append("\n");
                jsonObject.append(requestBody).append("\n");
            }
        }
    }
    Context context = new MockContext();
    jsonObject.append("\n=================================");
    jsonObject.append("response:").append("\n");
    jsonObject.append(AjaxValve.buildResultStruct(context));
    log.setTabName(proxy.getActionName());
    log.setUsrId(user.getId());
    log.setUsrName(user.getName());
    log.setOpDesc(jsonObject.toString());
    operationLogDAO.insertSelective(log);
    return result;
}
Also used : Context(com.alibaba.citrus.turbine.Context) ServletActionContext(org.apache.struts2.ServletActionContext) ActionProxy(com.opensymphony.xwork2.ActionProxy) Func(com.qlangtech.tis.manage.spring.aop.Func) BasicModule(com.qlangtech.tis.runtime.module.action.BasicModule) OperationLog(com.qlangtech.tis.manage.biz.dal.pojo.OperationLog) Method(java.lang.reflect.Method) Date(java.util.Date) HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletInputStream(javax.servlet.ServletInputStream) JSONObject(org.json.JSONObject) Map(java.util.Map) Nullable(com.qlangtech.tis.pubhook.common.Nullable)

Example 4 with OperationLog

use of com.qlangtech.tis.manage.biz.dal.pojo.OperationLog in project tis by qlangtech.

the class OperationLogDAOImpl method loadFromWriteDB.

public OperationLog loadFromWriteDB(Integer opId) {
    OperationLog key = new OperationLog();
    key.setOpId(opId);
    OperationLog record = this.loadFromWriterDB("operation_log.ibatorgenerated_selectByPrimaryKey", key);
    return record;
}
Also used : OperationLog(com.qlangtech.tis.manage.biz.dal.pojo.OperationLog)

Example 5 with OperationLog

use of com.qlangtech.tis.manage.biz.dal.pojo.OperationLog in project tis by qlangtech.

the class OperationLogDAOImpl method selectByPrimaryKey.

public OperationLog selectByPrimaryKey(Integer opId) {
    OperationLog key = new OperationLog();
    key.setOpId(opId);
    OperationLog record = this.load("operation_log.ibatorgenerated_selectByPrimaryKey", key);
    return record;
}
Also used : OperationLog(com.qlangtech.tis.manage.biz.dal.pojo.OperationLog)

Aggregations

OperationLog (com.qlangtech.tis.manage.biz.dal.pojo.OperationLog)5 Context (com.alibaba.citrus.turbine.Context)1 ActionProxy (com.opensymphony.xwork2.ActionProxy)1 Func (com.qlangtech.tis.manage.spring.aop.Func)1 Nullable (com.qlangtech.tis.pubhook.common.Nullable)1 BasicModule (com.qlangtech.tis.runtime.module.action.BasicModule)1 Method (java.lang.reflect.Method)1 Date (java.util.Date)1 Map (java.util.Map)1 ServletInputStream (javax.servlet.ServletInputStream)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 ServletActionContext (org.apache.struts2.ServletActionContext)1 JSONObject (org.json.JSONObject)1