提交 b825b9c5 编写于 作者: L ligang

Initial module escheduler-dao commit

上级 e6f14cf3
<?xml version="1.0"?>
<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>cn.analysys</groupId>
<artifactId>escheduler</artifactId>
<version>1.0.0</version>
</parent>
<artifactId>escheduler-dao</artifactId>
<name>escheduler-dao</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-autoconfigure</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<exclusions>
<exclusion>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-jdbc</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.ow2.asm</groupId>
<artifactId>asm</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
</dependency>
<dependency>
<groupId>commons-httpclient</groupId>
<artifactId>commons-httpclient</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.cronutils</groupId>
<artifactId>cron-utils</artifactId>
</dependency>
<dependency>
<groupId>org.quartz-scheduler</groupId>
<artifactId>quartz</artifactId>
</dependency>
<dependency>
<groupId>org.quartz-scheduler</groupId>
<artifactId>quartz-jobs</artifactId>
</dependency>
<dependency>
<groupId>commons-configuration</groupId>
<artifactId>commons-configuration</artifactId>
</dependency>
<dependency>
<groupId>cn.analysys</groupId>
<artifactId>escheduler-common</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
</plugin>
</plugins>
</build>
</project>
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package cn.escheduler.dao;
/**
* base dao
*/
public abstract class AbstractBaseDao {
protected abstract void init();
}
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package cn.escheduler.dao;
import cn.escheduler.common.enums.AlertStatus;
import cn.escheduler.common.enums.AlertType;
import cn.escheduler.common.enums.ShowType;
import cn.escheduler.dao.datasource.ConnectionFactory;
import cn.escheduler.dao.mapper.AlertMapper;
import cn.escheduler.dao.mapper.UserAlertGroupMapper;
import cn.escheduler.dao.model.Alert;
import cn.escheduler.dao.model.User;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.Date;
import java.util.List;
@Component
public class AlertDao extends AbstractBaseDao {
private final Logger logger = LoggerFactory.getLogger(getClass());
@Autowired
private AlertMapper alertMapper;
@Autowired
private UserAlertGroupMapper userAlertGroupMapper;
@Override
protected void init() {
alertMapper = ConnectionFactory.getSqlSession().getMapper(AlertMapper.class);
userAlertGroupMapper = ConnectionFactory.getSqlSession().getMapper(UserAlertGroupMapper.class);
}
/**
* insert alert
* @param alert
* @return
*/
public int addAlert(Alert alert){
return alertMapper.insert(alert);
}
/**
* update alert
* @param alertStatus
* @param log
* @param id
* @return
*/
public int updateAlert(AlertStatus alertStatus,String log,int id){
return alertMapper.update(alertStatus, log, new Date(), id);
}
/**
* query user list by alert group id
* @param alerGroupId
* @return
*/
public List<User> queryUserByAlertGroupId(int alerGroupId){
return userAlertGroupMapper.queryForUser(alerGroupId);
}
/**
* MasterServer or WorkerServer stoped
*/
public void sendServerStopedAlert(int alertgroupId,String host,String serverType){
Alert alert = new Alert();
String content = String.format("[{'type':'%s','host':'%s','event':'服务挂掉','警告级别':'严重'}]",serverType,host);
alert.setTitle("容错告警");
alert.setShowType(ShowType.TABLE);
alert.setContent(content);
alert.setAlertType(AlertType.EMAIL);
alert.setAlertGroupId(alertgroupId);
alert.setCreateTime(new Date());
alert.setUpdateTime(new Date());
alertMapper.insert(alert);
}
/**
* task timeout warn
*/
public void sendTaskTimeoutAlert(int alertgroupId,String receivers,String receiversCc,int taskId,String taskName){
Alert alert = new Alert();
String content = String.format("[{'id':'%d','name':'%s','event':'timeout','warnLevel':'middle'}]",taskId,taskName);
alert.setTitle("Task Timeout Warn");
alert.setShowType(ShowType.TABLE);
alert.setContent(content);
alert.setAlertType(AlertType.EMAIL);
alert.setAlertGroupId(alertgroupId);
if (StringUtils.isNotEmpty(receivers)) {
alert.setReceivers(receivers);
}
if (StringUtils.isNotEmpty(receiversCc)) {
alert.setReceiversCc(receiversCc);
}
alert.setCreateTime(new Date());
alert.setUpdateTime(new Date());
alertMapper.insert(alert);
}
/**
* list the alert information of waiting to be executed
* @return
*/
public List<Alert> listWaitExecutionAlert(){
return alertMapper.listAlertByStatus(AlertStatus.WAIT_EXECUTION);
}
/**
* list user information by alert group id
* @param alergroupId
* @return
*/
public List<User> listUserByAlertgroupId(int alergroupId){
return userAlertGroupMapper.listUserByAlertgroupId(alergroupId);
}
}
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package cn.escheduler.dao;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.lang.reflect.InvocationTargetException;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
/**
* dao factory
*/
public class DaoFactory {
private static final Logger logger = LoggerFactory.getLogger(DaoFactory.class);
private static Map<String, AbstractBaseDao> daoMap = new ConcurrentHashMap<>();
private DaoFactory(){
}
/**
* 获取 Dao 实例
*
* @param clazz
* @return Dao实例
*/
@SuppressWarnings("unchecked")
public static <T extends AbstractBaseDao> T getDaoInstance(Class<T> clazz) {
String className = clazz.getName();
synchronized (daoMap) {
if (!daoMap.containsKey(className)) {
try {
T t = clazz.getConstructor().newInstance();
// 实例初始化
t.init();
daoMap.put(className, t);
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException e) {
logger.error(e.getMessage(), e);
}
}
}
return (T) daoMap.get(className);
}
}
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package cn.escheduler.dao;
import cn.escheduler.dao.mapper.MasterServerMapper;
import cn.escheduler.dao.mapper.WorkerServerMapper;
import cn.escheduler.dao.model.MasterServer;
import cn.escheduler.dao.model.WorkerServer;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.Date;
import static cn.escheduler.dao.datasource.ConnectionFactory.getMapper;
/**
* master server
*/
public class ServerDao extends AbstractBaseDao {
@Autowired
MasterServerMapper masterServerMapper;
@Autowired
WorkerServerMapper workerServerMapper;
@Override
protected void init() {
masterServerMapper = getMapper(MasterServerMapper.class);
workerServerMapper = getMapper(WorkerServerMapper.class);
}
/**
* register master
*
* @param host
* @param port
* @param zkDirectory
* @param resInfo
* @param createTime
* @param lastHeartbeatTime
* @return
*/
public int registerMaster(String host, int port , String zkDirectory , String resInfo ,
Date createTime , Date lastHeartbeatTime) {
MasterServer masterServer = new MasterServer();
masterServer.setHost(host);
masterServer.setPort(port);
masterServer.setZkDirectory(zkDirectory);
masterServer.setResInfo(resInfo);
masterServer.setCreateTime(createTime);
masterServer.setLastHeartbeatTime(lastHeartbeatTime);
return masterServerMapper.insert(masterServer);
}
/**
* update master
*
* @param host
* @param port
* @param resInfo
* @param lastHeartbeatTime
* @return
*/
public int updateMaster(String host, int port , String resInfo , Date lastHeartbeatTime) {
MasterServer masterServer = new MasterServer();
masterServer.setHost(host);
masterServer.setPort(port);
masterServer.setResInfo(resInfo);
masterServer.setLastHeartbeatTime(lastHeartbeatTime);
return masterServerMapper.update(masterServer);
}
/**
* delete master
*
* @param host
* @return
*/
public int deleteMaster(String host) {
return masterServerMapper.deleteWorkerByHost(host);
}
/**
* register master
* @param host
* @param port
* @param zkDirectory
* @param resInfo
* @param createTime
* @param lastHeartbeatTime
* @return
*/
public int registerWorker(String host, int port , String zkDirectory , String resInfo ,
Date createTime , Date lastHeartbeatTime) {
WorkerServer workerServer = new WorkerServer();
workerServer.setHost(host);
workerServer.setPort(port);
workerServer.setZkDirectory(zkDirectory);
workerServer.setResInfo(resInfo);
workerServer.setCreateTime(createTime);
workerServer.setLastHeartbeatTime(lastHeartbeatTime);
return workerServerMapper.insert(workerServer);
}
/**
*
* update worker
* @param host
* @param port
* @param resInfo
* @param lastHeartbeatTime
* @return
*/
public int updateWorker(String host, int port , String resInfo , Date lastHeartbeatTime) {
WorkerServer workerServer = new WorkerServer();
workerServer.setHost(host);
workerServer.setPort(port);
workerServer.setResInfo(resInfo);
workerServer.setLastHeartbeatTime(lastHeartbeatTime);
return workerServerMapper.update(workerServer);
}
/**
* delete worker by host
*
* @param host
* @return
*/
public int deleteWorker(String host) {
return workerServerMapper.deleteWorkerByHost(host);
}
}
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package cn.escheduler.dao;
import cn.escheduler.common.Constants;
import cn.escheduler.dao.model.TaskRecord;
import org.apache.commons.configuration.Configuration;
import org.apache.commons.configuration.ConfigurationException;
import org.apache.commons.configuration.PropertiesConfiguration;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.sql.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
* task record dao
*/
public class TaskRecordDao {
private static Logger logger = LoggerFactory.getLogger(TaskRecordDao.class.getName());
/**
* 加载配置文件
*/
private static Configuration conf;
static {
try {
conf = new PropertiesConfiguration(Constants.TASK_RECORD_PROPERTIES_PATH);
}catch (ConfigurationException e){
logger.error("load configuration excetpion",e);
System.exit(1);
}
}
/**
* create connection
* @return
*/
private static Connection getConn() {
if(!conf.getBoolean(Constants.TASK_RECORD_FLAG)){
return null;
}
String driver = "com.mysql.jdbc.Driver";
String url = conf.getString(Constants.TASK_RECORD_URL);
String username = conf.getString(Constants.TASK_RECORD_USER);
String password = conf.getString(Constants.TASK_RECORD_PWD);
Connection conn = null;
try {
//classLoader,加载对应驱动
Class.forName(driver);
conn = DriverManager.getConnection(url, username, password);
} catch (ClassNotFoundException e) {
logger.error("Exception ", e);
} catch (SQLException e) {
logger.error("Exception ", e);
}
return conn;
}
/**
* generate where sql string
* @param filterMap
* @return
*/
private static String getWhereString(Map<String, String> filterMap)
{
if(filterMap.size() ==0){
return "";
}
String result = " where 1=1 ";
Object taskName = filterMap.get("taskName");
if(taskName != null && StringUtils.isNotEmpty(taskName.toString())){
result += " and PROC_NAME like concat('%', '" + taskName.toString() + "', '%') ";
}
Object taskDate = filterMap.get("taskDate");
if(taskDate != null && StringUtils.isNotEmpty(taskDate.toString())){
result += " and PROC_DATE='" + taskDate.toString() + "'";
}
Object state = filterMap.get("state");
if(state != null && StringUtils.isNotEmpty(state.toString())){
result += " and NOTE='" + state.toString() + "'";
}
Object sourceTable = filterMap.get("sourceTable");
if(sourceTable!= null && StringUtils.isNotEmpty(sourceTable.toString())){
result += " and SOURCE_TAB like concat('%', '" + sourceTable.toString()+ "', '%')";
}
Object targetTable = filterMap.get("targetTable");
if(sourceTable!= null && StringUtils.isNotEmpty(targetTable.toString())){
result += " and TARGET_TAB like concat('%', '"+ targetTable.toString()+"', '%') " ;
}
Object start = filterMap.get("startTime");
if(start != null && StringUtils.isNotEmpty(start.toString())){
result += " and STARTDATE>='" + start.toString() + "'";
}
Object end = filterMap.get("endTime");
if(end != null && StringUtils.isNotEmpty(end.toString())){
result += " and ENDDATE>='" + end.toString()+ "'";
}
return result;
}
/**
* count task record
* @param filterMap
* @return
*/
public static int countTaskRecord(Map<String, String> filterMap){
int count = 0;
Connection conn = null;
try {
conn = getConn();
if(conn == null){
return count;
}
String sql = "select count(1) as count from eamp_hive_log_hd";
sql += getWhereString(filterMap);
PreparedStatement pstmt;
pstmt = conn.prepareStatement(sql);
ResultSet rs = pstmt.executeQuery();
while(rs.next()){
count = rs.getInt("count");
break;
}
} catch (SQLException e) {
logger.error("Exception ", e);
}finally {
try {
if(conn != null){
conn.close();
}
} catch (SQLException e) {
logger.error("Exception ", e);
}
}
return count;
}
/**
* query task record by filter map paging
* @param filterMap
* @return
*/
public static List<TaskRecord> queryAllTaskRecord(Map<String,String> filterMap ) {
String sql = "select * from eamp_hive_log_hd ";
sql += getWhereString(filterMap);
int offset = Integer.parseInt(filterMap.get("offset"));
int pageSize = Integer.parseInt(filterMap.get("pageSize"));
sql += String.format(" order by STARTDATE desc limit %d,%d", offset, pageSize);
List<TaskRecord> recordList = new ArrayList<>();
try{
recordList = getQueryResult(sql);
}catch (Exception e){
logger.error("Exception ", e);
}
return recordList;
}
/**
* convert result set to task record
* @param resultSet
* @return
* @throws SQLException
*/
private static TaskRecord convertToTaskRecord(ResultSet resultSet) throws SQLException {
TaskRecord taskRecord = new TaskRecord();
taskRecord.setId(resultSet.getInt("ID"));
taskRecord.setProcId(resultSet.getInt("PROC_ID"));
taskRecord.setProcName(resultSet.getString("PROC_NAME"));
taskRecord.setProcDate(resultSet.getString("PROC_DATE"));
taskRecord.setStartDate(resultSet.getDate("STARTDATE"));
taskRecord.setEndDate(resultSet.getDate("ENDDATE"));
taskRecord.setResult(resultSet.getString("RESULT"));
taskRecord.setDuration(resultSet.getInt("DURATION"));
taskRecord.setNote(resultSet.getString("NOTE"));
taskRecord.setSchema(resultSet.getString("SCHEMA"));
taskRecord.setJobId(resultSet.getString("JOB_ID"));
taskRecord.setSourceTab(resultSet.getString("SOURCE_TAB"));
taskRecord.setSourceRowCount(resultSet.getLong("SOURCE_ROW_COUNT"));
taskRecord.setTargetTab(resultSet.getString("TARGET_TAB"));
taskRecord.setTargetRowCount(resultSet.getLong("TARGET_ROW_COUNT"));
taskRecord.setErrorCode(resultSet.getString("ERROR_CODE"));
return taskRecord;
}
/**
* query task list by select sql
* @param selectSql
* @return
*/
private static List<TaskRecord> getQueryResult(String selectSql) {
List<TaskRecord> recordList = new ArrayList<>();
Connection conn = null;
try {
conn = getConn();
if(conn == null){
return recordList;
}
PreparedStatement pstmt;
pstmt = conn.prepareStatement(selectSql);
ResultSet rs = pstmt.executeQuery();
while(rs.next()){
TaskRecord taskRecord = convertToTaskRecord(rs);
recordList.add(taskRecord);
}
} catch (SQLException e) {
logger.error("Exception ", e);
}finally {
try {
if(conn != null){
conn.close();
}
} catch (SQLException e) {
logger.error("Exception ", e);
}
}
return recordList;
}
}
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package cn.escheduler.dao.datasource;
import cn.escheduler.common.Constants;
import cn.escheduler.common.utils.CommonUtils;
import cn.escheduler.dao.mapper.ProjectMapper;
import com.alibaba.druid.pool.DruidDataSource;
import org.apache.ibatis.mapping.Environment;
import org.apache.ibatis.session.Configuration;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.apache.ibatis.transaction.TransactionFactory;
import org.apache.ibatis.transaction.jdbc.JdbcTransactionFactory;
import org.mybatis.spring.SqlSessionTemplate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.sql.DataSource;
import java.sql.SQLException;
import static cn.escheduler.dao.utils.PropertyUtils.*;
/**
* data source connection factory
*/
public class ConnectionFactory {
private static final Logger logger = LoggerFactory.getLogger(ConnectionFactory.class);
private static SqlSessionFactory sqlSessionFactory;
/**
* get the data source
*/
public static DruidDataSource getDataSource() {
DruidDataSource druidDataSource = new DruidDataSource();
druidDataSource.setDriverClassName(getString(Constants.SPRING_DATASOURCE_DRIVER_CLASS_NAME));
druidDataSource.setUrl(getString(Constants.SPRING_DATASOURCE_URL));
druidDataSource.setUsername(getString(Constants.SPRING_DATASOURCE_USERNAME));
druidDataSource.setPassword(getString(Constants.SPRING_DATASOURCE_PASSWORD));
druidDataSource.setValidationQuery(getString(Constants.SPRING_DATASOURCE_VALIDATION_QUERY));
druidDataSource.setPoolPreparedStatements(getBoolean(Constants.SPRING_DATASOURCE_POOL_PREPARED_STATEMENTS));
druidDataSource.setTestWhileIdle(getBoolean(Constants.SPRING_DATASOURCE_TEST_WHILE_IDLE));
druidDataSource.setTestOnBorrow(getBoolean(Constants.SPRING_DATASOURCE_TEST_ON_BORROW));
druidDataSource.setTestOnReturn(getBoolean(Constants.SPRING_DATASOURCE_TEST_ON_RETURN));
druidDataSource.setKeepAlive(getBoolean(Constants.SPRING_DATASOURCE_KEEP_ALIVE));
//just for development
if (CommonUtils.isDevelopMode()) {
//Configure filters that are intercepted by monitoring statistics, and SQL can not be counted after removing them.'wall'is used for firewall
try {
druidDataSource.setFilters("stat,wall,log4j");
} catch (SQLException e) {
logger.error(e.getMessage(), e);
}
}
druidDataSource.setMinIdle(getInt(Constants.SPRING_DATASOURCE_MIN_IDLE));
druidDataSource.setMaxActive(getInt(Constants.SPRING_DATASOURCE_MAX_ACTIVE));
druidDataSource.setMaxWait(getInt(Constants.SPRING_DATASOURCE_MAX_WAIT));
druidDataSource.setMaxPoolPreparedStatementPerConnectionSize(getInt(Constants.SPRING_DATASOURCE_MAX_POOL_PREPARED_STATEMENT_PER_CONNECTION_SIZE));
druidDataSource.setInitialSize(getInt(Constants.SPRING_DATASOURCE_INITIAL_SIZE));
druidDataSource.setTimeBetweenEvictionRunsMillis(getLong(Constants.SPRING_DATASOURCE_TIME_BETWEEN_EVICTION_RUNS_MILLIS));
druidDataSource.setTimeBetweenConnectErrorMillis(getLong(Constants.SPRING_DATASOURCE_TIME_BETWEEN_CONNECT_ERROR_MILLIS));
druidDataSource.setMinEvictableIdleTimeMillis(getLong(Constants.SPRING_DATASOURCE_MIN_EVICTABLE_IDLE_TIME_MILLIS));
druidDataSource.setValidationQueryTimeout(getInt(Constants.SPRING_DATASOURCE_VALIDATION_QUERY_TIMEOUT));
//auto commit
druidDataSource.setDefaultAutoCommit(getBoolean(Constants.SPRING_DATASOURCE_DEFAULT_AUTO_COMMIT));
return druidDataSource;
}
/**
* get sql session factory
*/
public static SqlSessionFactory getSqlSessionFactory() {
if (sqlSessionFactory == null) {
synchronized (ConnectionFactory.class) {
if (sqlSessionFactory == null) {
DataSource dataSource = getDataSource();
TransactionFactory transactionFactory = new JdbcTransactionFactory();
Environment environment = new Environment(Constants.DEVELOPMENT, transactionFactory, dataSource);
Configuration configuration = new Configuration(environment);
configuration.setLazyLoadingEnabled(true);
configuration.addMappers(ProjectMapper.class.getPackage().getName());
SqlSessionFactoryBuilder builder = new SqlSessionFactoryBuilder();
sqlSessionFactory = builder.build(configuration);
}
}
}
return sqlSessionFactory;
}
/**
* get sql session
*/
public static SqlSession getSqlSession() {
return new SqlSessionTemplate(getSqlSessionFactory());
}
public static <T> T getMapper(Class<T> type){
return getSqlSession().getMapper(type);
}
}
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package cn.escheduler.dao.datasource;
import com.alibaba.druid.pool.DruidDataSource;
import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.context.annotation.PropertySource;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.transaction.PlatformTransactionManager;
import java.sql.SQLException;
/**
* data base configuration
*/
@Configuration
@PropertySource({"classpath:dao/data_source.properties"})
@MapperScan(basePackages = "cn.escheduler.dao.mapper", sqlSessionFactoryRef = "SqlSessionFactory")
public class DatabaseConfiguration {
/**
* register data source
*/
@Primary
@Bean(name = "DataSource", initMethod = "init", destroyMethod = "close")
public DruidDataSource dataSource() {
return ConnectionFactory.getDataSource();
}
@Primary
@Bean(name = "SqlSessionFactory")
public SqlSessionFactory sqlSessionFactory() throws Exception {
SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();
sqlSessionFactoryBean.setDataSource(dataSource());
return sqlSessionFactoryBean.getObject();
}
@Primary
@Bean(name = "TransactionManager")
public PlatformTransactionManager transactionManager() throws SQLException {
return new DataSourceTransactionManager(dataSource());
}
}
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package cn.escheduler.dao.mapper;
import cn.escheduler.common.enums.AlertType;
import cn.escheduler.dao.model.AlertGroup;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.EnumOrdinalTypeHandler;
import org.apache.ibatis.type.JdbcType;
import java.sql.Timestamp;
import java.util.List;
/**
* alert group mapper
*/
public interface AlertGroupMapper {
/**
* insert warning group
* @param alertGroup
* @return
*/
@InsertProvider(type = AlertGroupMapperProvider.class, method = "insert")
@Options(useGeneratedKeys = true,keyProperty = "alertGroup.id")
@SelectKey(statement = "SELECT LAST_INSERT_ID()", keyProperty = "alertGroup.id", before = false, resultType = int.class)
int insert(@Param("alertGroup") AlertGroup alertGroup);
/**
* delete alert group by id
* @param id
* @return
*/
@DeleteProvider(type = AlertGroupMapperProvider.class, method = "delete")
int delete(@Param("id") int id);
/**
* update alert group information
* @param alertGroup
* @return
*/
@UpdateProvider(type = AlertGroupMapperProvider.class, method = "update")
int update(@Param("alertGroup") AlertGroup alertGroup);
/**
* query alert group by id
* @param alertGroupId
* @return
*/
@Results(value = {@Result(property = "id", column = "id", id = true, javaType = Integer.class, jdbcType = JdbcType.INTEGER),
@Result(property = "groupName", column = "group_name", javaType = String.class, jdbcType = JdbcType.VARCHAR),
@Result(property = "groupType", column = "group_type", typeHandler = EnumOrdinalTypeHandler.class, javaType = AlertType.class, jdbcType = JdbcType.TINYINT),
@Result(property = "desc", column = "desc", javaType = String.class, jdbcType = JdbcType.VARCHAR),
@Result(property = "createTime", column = "create_time", javaType = Timestamp.class, jdbcType = JdbcType.DATE),
@Result(property = "updateTime", column = "update_time", javaType = Timestamp.class, jdbcType = JdbcType.DATE)
})
@SelectProvider(type = AlertGroupMapperProvider.class, method = "queryById")
AlertGroup queryById(@Param("alertGroupId") int alertGroupId);
/**
* query all alert group list
* @return
*/
@Results(value = {@Result(property = "id", column = "id", id = true, javaType = Integer.class, jdbcType = JdbcType.INTEGER),
@Result(property = "groupName", column = "group_name", javaType = String.class, jdbcType = JdbcType.VARCHAR),
@Result(property = "groupType", column = "group_type", typeHandler = EnumOrdinalTypeHandler.class, javaType = AlertType.class, jdbcType = JdbcType.TINYINT),
@Result(property = "desc", column = "desc", javaType = String.class, jdbcType = JdbcType.VARCHAR),
@Result(property = "createTime", column = "create_time", javaType = Timestamp.class, jdbcType = JdbcType.DATE),
@Result(property = "updateTime", column = "update_time", javaType = Timestamp.class, jdbcType = JdbcType.DATE)
})
@SelectProvider(type = AlertGroupMapperProvider.class, method = "queryAllGroupList")
List<AlertGroup> queryAllGroupList();
/**
* count alert group
* @param searchVal
* @return
*/
@SelectProvider(type = AlertGroupMapperProvider.class, method = "countAlertGroupPaging")
Integer countAlertGroupPaging(@Param("searchVal") String searchVal);
/**
* query alert groups paging
* @param searchVal
* @param offset
* @param pageSize
* @return
*/
@Results(value = {@Result(property = "id", column = "id", id = true, javaType = Integer.class, jdbcType = JdbcType.INTEGER),
@Result(property = "groupName", column = "group_name", javaType = String.class, jdbcType = JdbcType.VARCHAR),
@Result(property = "groupType", column = "group_type", typeHandler = EnumOrdinalTypeHandler.class, javaType = AlertType.class, jdbcType = JdbcType.TINYINT),
@Result(property = "desc", column = "desc", javaType = String.class, jdbcType = JdbcType.VARCHAR),
@Result(property = "createTime", column = "create_time", javaType = Timestamp.class, jdbcType = JdbcType.DATE),
@Result(property = "updateTime", column = "update_time", javaType = Timestamp.class, jdbcType = JdbcType.DATE)
})
@SelectProvider(type = AlertGroupMapperProvider.class, method = "queryAlertGroupPaging")
List<AlertGroup> queryAlertGroupPaging(@Param("searchVal") String searchVal,
@Param("offset") Integer offset,
@Param("pageSize") Integer pageSize);
/**
* query alert group by user id
* @param userId
* @return
*/
@Results(value = {@Result(property = "id", column = "id", id = true, javaType = Integer.class, jdbcType = JdbcType.INTEGER),
@Result(property = "groupName", column = "group_name", javaType = String.class, jdbcType = JdbcType.VARCHAR),
@Result(property = "groupType", column = "group_type", typeHandler = EnumOrdinalTypeHandler.class, javaType = AlertType.class, jdbcType = JdbcType.TINYINT),
@Result(property = "desc", column = "desc", javaType = String.class, jdbcType = JdbcType.VARCHAR),
@Result(property = "createTime", column = "create_time", javaType = Timestamp.class, jdbcType = JdbcType.DATE),
@Result(property = "updateTime", column = "update_time", javaType = Timestamp.class, jdbcType = JdbcType.DATE)
})
@SelectProvider(type = AlertGroupMapperProvider.class, method = "queryByUserId")
List<AlertGroup> queryByUserId(@Param("userId") int userId);
/**
* query alert group by name
* @param groupName
* @return
*/
@Results(value = {@Result(property = "id", column = "id", id = true, javaType = Integer.class, jdbcType = JdbcType.INTEGER),
@Result(property = "groupName", column = "group_name", javaType = String.class, jdbcType = JdbcType.VARCHAR),
@Result(property = "groupType", column = "group_type", typeHandler = EnumOrdinalTypeHandler.class, javaType = AlertType.class, jdbcType = JdbcType.TINYINT),
@Result(property = "desc", column = "desc", javaType = String.class, jdbcType = JdbcType.VARCHAR),
@Result(property = "createTime", column = "create_time", javaType = Timestamp.class, jdbcType = JdbcType.DATE),
@Result(property = "updateTime", column = "update_time", javaType = Timestamp.class, jdbcType = JdbcType.DATE)
})
@SelectProvider(type = AlertGroupMapperProvider.class, method = "queryByGroupName")
AlertGroup queryByGroupName(@Param("groupName") String groupName);
}
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package cn.escheduler.dao.mapper;
import cn.escheduler.common.enums.AlertType;
import cn.escheduler.common.utils.EnumFieldUtil;
import org.apache.commons.lang3.StringUtils;
import org.apache.ibatis.jdbc.SQL;
import java.util.Map;
/**
* alert group mapper provider
*/
public class AlertGroupMapperProvider {
private static final String TABLE_NAME = "t_escheduler_alertgroup";
/**
* insert one alert group
* @param parameter
* @return
*/
public String insert(Map<String, Object> parameter) {
return new SQL() {
{
INSERT_INTO(TABLE_NAME);
VALUES("`group_name`", "#{alertGroup.groupName}");
VALUES("`group_type`", EnumFieldUtil.genFieldStr("alertGroup.groupType", AlertType.class));
VALUES("`desc`", "#{alertGroup.desc}");
VALUES("`create_time`", "#{alertGroup.createTime}");
VALUES("`update_time`", "#{alertGroup.updateTime}");
}
}.toString();
}
/**
* delete alert group by id
* @param parameter
* @return
*/
public String delete(Map<String, Object> parameter) {
return new SQL() {
{
DELETE_FROM(TABLE_NAME);
WHERE("`id`=#{id}");
}
}.toString();
}
/**
* update alert group
* @param parameter
* @return
*/
public String update(Map<String, Object> parameter) {
return new SQL() {
{
UPDATE(TABLE_NAME);
SET("`group_name`=#{alertGroup.groupName}");
SET("`group_type`="+EnumFieldUtil.genFieldStr("alertGroup.groupType", AlertType.class));
SET("`desc`=#{alertGroup.desc}");
SET("`update_time`=#{alertGroup.updateTime}");
WHERE("`id`=#{alertGroup.id}");
}
}.toString();
}
/**
* query alert group by id
* @param parameter
* @return
*/
public String queryById(Map<String, Object> parameter) {
return new SQL() {
{
SELECT("*");
FROM(TABLE_NAME);
WHERE("`id` = #{alertGroupId}");
}
}.toString();
}
/**
* query all alert group list
* @param parameter
* @return
*/
public String queryAllGroupList(Map<String, Object> parameter) {
return new SQL() {
{
SELECT("*");
FROM(TABLE_NAME);
ORDER_BY( "update_time desc");
}
}.toString();
}
/**
* count alert group by search key
* @param parameter
* @return
*/
public String countAlertGroupPaging(Map<String, Object> parameter) {
return new SQL() {{
SELECT("count(0)");
FROM(TABLE_NAME);
Object searchVal = parameter.get("searchVal");
if(searchVal != null && StringUtils.isNotEmpty(searchVal.toString())){
WHERE( " group_name like concat('%', #{searchVal}, '%') ");
}
}}.toString();
}
/**
* query alert group list paging by search key
* @param parameter
* @return
*/
public String queryAlertGroupPaging(Map<String, Object> parameter) {
return new SQL() {
{
SELECT("*");
FROM(TABLE_NAME);
Object searchVal = parameter.get("searchVal");
if(searchVal != null && StringUtils.isNotEmpty(searchVal.toString())){
WHERE( " group_name like concat('%', #{searchVal}, '%') ");
}
ORDER_BY(" update_time desc limit #{offset},#{pageSize} ");
}
}.toString();
}
/**
* query alert group by user id
* @param parameter
* @return
*/
public String queryByUserId(Map<String, Object> parameter) {
return new SQL() {
{
SELECT("g.*");
FROM(TABLE_NAME + " g,t_escheduler_relation_user_alertgroup rel");
WHERE("rel.alertgroup_id = g.id and rel.user_id = #{userId}");
}
}.toString();
}
/**
* query alert group by name
* @param parameter
* @return
*/
public String queryByGroupName(Map<String, Object> parameter) {
return new SQL() {
{
SELECT("*");
FROM(TABLE_NAME);
WHERE("group_name = #{groupName}");
}
}.toString();
}
}
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package cn.escheduler.dao.mapper;
import cn.escheduler.common.enums.AlertStatus;
import cn.escheduler.common.enums.AlertType;
import cn.escheduler.common.enums.ShowType;
import cn.escheduler.dao.model.Alert;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.EnumOrdinalTypeHandler;
import org.apache.ibatis.type.JdbcType;
import java.sql.Timestamp;
import java.util.Date;
import java.util.List;
public interface AlertMapper {
/**
* insert alert information
* @param alert
* @return
*/
@InsertProvider(type = AlertMapperProvider.class, method = "insert")
@Options(useGeneratedKeys = true,keyProperty = "alert.id")
@SelectKey(statement = "SELECT LAST_INSERT_ID()", keyProperty = "alert.id", before = false, resultType = int.class)
int insert(@Param("alert") Alert alert);
/**
* query alert list by status
* @param alertStatus
* @return
*/
@Results(value = {@Result(property = "id", column = "id", id = true, javaType = Integer.class, jdbcType = JdbcType.INTEGER),
@Result(property = "title", column = "title", javaType = String.class, jdbcType = JdbcType.VARCHAR),
@Result(property = "showType", column = "show_type", typeHandler = EnumOrdinalTypeHandler.class, javaType = ShowType.class, jdbcType = JdbcType.TINYINT),
@Result(property = "content", column = "content", javaType = String.class, jdbcType = JdbcType.VARCHAR),
@Result(property = "alertType", column = "alert_type", typeHandler = EnumOrdinalTypeHandler.class, javaType = AlertType.class, jdbcType = JdbcType.TINYINT),
@Result(property = "alertStatus", column = "alert_status", typeHandler = EnumOrdinalTypeHandler.class, javaType = AlertStatus.class, jdbcType = JdbcType.TINYINT),
@Result(property = "log", column = "log", javaType = String.class, jdbcType = JdbcType.VARCHAR),
@Result(property = "alertGroupId", column = "alertgroup_id", javaType = Integer.class, jdbcType = JdbcType.INTEGER),
@Result(property = "receivers", column = "receivers", javaType = String.class, jdbcType = JdbcType.VARCHAR),
@Result(property = "receiversCc", column = "receivers_cc", javaType = String.class, jdbcType = JdbcType.VARCHAR),
@Result(property = "createTime", column = "create_time", javaType = Timestamp.class, jdbcType = JdbcType.DATE),
@Result(property = "updateTime", column = "update_time", javaType = Timestamp.class, jdbcType = JdbcType.DATE)
})
@SelectProvider(type = AlertMapperProvider.class, method = "queryAlertByStatus")
List<Alert> queryAlertByStatus(@Param("alertStatus") AlertStatus alertStatus);
/**
* update alert information
* @param alertStatus
* @param log
* @param updateTime
* @param id
* @return
*/
@UpdateProvider(type = AlertMapperProvider.class, method = "update")
int update(@Param("alertStatus") AlertStatus alertStatus,@Param("log") String log,
@Param("updateTime") Date updateTime,@Param("id") int id);
/**
* delete by alert id
* @param alertId
* @return
*/
@UpdateProvider(type = AlertMapperProvider.class, method = "deleteById")
int delete(@Param("alertId") int alertId);
/**
* list alert information by field alertStatus
* @param alertStatus
* @return
*/
@Results(value = {@Result(property = "id", column = "id", id = true, javaType = Integer.class, jdbcType = JdbcType.INTEGER),
@Result(property = "title", column = "title", javaType = String.class, jdbcType = JdbcType.VARCHAR),
@Result(property = "showType", column = "show_type", typeHandler = EnumOrdinalTypeHandler.class, javaType = ShowType.class, jdbcType = JdbcType.TINYINT),
@Result(property = "content", column = "content", javaType = String.class, jdbcType = JdbcType.VARCHAR),
@Result(property = "alertType", column = "alert_type", typeHandler = EnumOrdinalTypeHandler.class, javaType = AlertType.class, jdbcType = JdbcType.TINYINT),
@Result(property = "alertStatus", column = "alert_status", typeHandler = EnumOrdinalTypeHandler.class, javaType = AlertStatus.class, jdbcType = JdbcType.TINYINT),
@Result(property = "log", column = "log", javaType = String.class, jdbcType = JdbcType.VARCHAR),
@Result(property = "alertGroupId", column = "alertgroup_id", javaType = Integer.class, jdbcType = JdbcType.INTEGER),
@Result(property = "receivers", column = "receivers", javaType = String.class, jdbcType = JdbcType.VARCHAR),
@Result(property = "receiversCc", column = "receivers_cc", javaType = String.class, jdbcType = JdbcType.VARCHAR),
@Result(property = "createTime", column = "create_time", javaType = Timestamp.class, jdbcType = JdbcType.DATE),
@Result(property = "updateTime", column = "update_time", javaType = Timestamp.class, jdbcType = JdbcType.DATE)
})
@SelectProvider(type = AlertMapperProvider.class, method = "listAlertByStatus")
List<Alert> listAlertByStatus(@Param("alertStatus") AlertStatus alertStatus);
}
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package cn.escheduler.dao.mapper;
import cn.escheduler.common.enums.AlertStatus;
import cn.escheduler.common.enums.AlertType;
import cn.escheduler.common.enums.ShowType;
import cn.escheduler.common.utils.EnumFieldUtil;
import org.apache.ibatis.jdbc.SQL;
import java.util.Map;
public class AlertMapperProvider {
private static final String TABLE_NAME = "t_escheduler_alert";
/**
* 插入告警信息
*
* @param parameter
* @return
*/
public String insert(Map<String, Object> parameter) {
return new SQL() {
{
INSERT_INTO(TABLE_NAME);
VALUES("`title`", "#{alert.title}");
VALUES("`show_type`", EnumFieldUtil.genFieldStr("alert.showType", ShowType.class));
VALUES("`content`", "#{alert.content}");
VALUES("`alert_type`", EnumFieldUtil.genFieldStr("alert.alertType", AlertType.class));
VALUES("`alertgroup_id`", "#{alert.alertGroupId}");
VALUES("`receivers`", "#{alert.receivers}");
VALUES("`receivers_cc`", "#{alert.receiversCc}");
VALUES("`create_time`", "#{alert.createTime}");
VALUES("`update_time`", "#{alert.updateTime}");
}
}.toString();
}
/**
* 根据告警状态查询
* @param parameter
* @return
*/
public String queryAlertByStatus(Map<String, Object> parameter) {
return new SQL() {
{
SELECT("*");
FROM(TABLE_NAME);
WHERE("`alert_status` = "+EnumFieldUtil.genFieldStr("alertStatus", AlertStatus.class));
}
}.toString();
}
/**
* delete by id
* @param parameter
* @return
*/
public String deleteById(Map<String, Object> parameter){
return new SQL() {
{
DELETE_FROM(TABLE_NAME);
WHERE("`id`=#{alertId}");
}}.toString();
}
/**
* 更新消息信息
*
* @param parameter
* @return
*/
public String update(Map<String, Object> parameter) {
return new SQL() {
{
UPDATE(TABLE_NAME);
SET("`alert_status`="+EnumFieldUtil.genFieldStr("alertStatus", AlertType.class));
SET("`log`=#{log}");
SET("`update_time`=#{updateTime}");
WHERE("`id` = #{id}");
}
}.toString();
}
/**
* list alert information by field alertStatus
* @param parameter
* @return
*/
public String listAlertByStatus(Map<String, Object> parameter) {
return new SQL() {
{
SELECT("*");
FROM(TABLE_NAME);
WHERE("`alert_status` = "+EnumFieldUtil.genFieldStr("alertStatus", AlertStatus.class));
}
}.toString();
}
}
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package cn.escheduler.dao.mapper;
import cn.escheduler.common.enums.*;
import cn.escheduler.dao.model.Command;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.EnumOrdinalTypeHandler;
import org.apache.ibatis.type.JdbcType;
import java.sql.Timestamp;
import java.util.List;
/**
* command mapper
*/
public interface CommandMapper {
/**
* inert command
* @param command
* @return
*/
@InsertProvider(type = CommandMapperProvider.class, method = "insert")
@Options(useGeneratedKeys = true,keyProperty = "command.id")
@SelectKey(statement = "SELECT LAST_INSERT_ID()", keyProperty = "command.id", before = false, resultType = int.class)
int insert(@Param("command") Command command);
/**
* delete command
* @param cmdId
* @return
*/
@DeleteProvider(type = CommandMapperProvider.class, method = "delete")
int delete(@Param("cmdId") int cmdId);
/**
* update command
*
* @param command
* @return
*/
@UpdateProvider(type = CommandMapperProvider.class, method = "update")
int update(@Param("command") Command command);
/**
* query a command that can run normally
* @return
*/
@Results(value = {@Result(property = "id", column = "id", id = true, javaType = Integer.class, jdbcType = JdbcType.INTEGER),
@Result(property = "commandType", column = "command_type", typeHandler = EnumOrdinalTypeHandler.class, javaType = CommandType.class, jdbcType = JdbcType.TINYINT),
@Result(property = "processDefinitionId", column = "process_definition_id", javaType = Integer.class, jdbcType = JdbcType.INTEGER),
@Result(property = "executorId", column = "executor_id", javaType = Integer.class, jdbcType = JdbcType.INTEGER),
@Result(property = "commandParam", column = "command_param", javaType = String.class, jdbcType = JdbcType.VARCHAR),
@Result(property = "taskDependType", column = "task_depend_type", javaType = TaskDependType.class, typeHandler = EnumOrdinalTypeHandler.class, jdbcType = JdbcType.TINYINT),
@Result(property = "failureStrategy", column = "failure_strategy", javaType = FailureStrategy.class, typeHandler = EnumOrdinalTypeHandler.class, jdbcType = JdbcType.TINYINT),
@Result(property = "warningType", column = "warning_type", javaType = WarningType.class, typeHandler = EnumOrdinalTypeHandler.class, jdbcType = JdbcType.TINYINT),
@Result(property = "warningGroupId", column = "warning_group_id", javaType = Integer.class, jdbcType = JdbcType.INTEGER),
@Result(property = "scheduleTime", column = "schedule_time", javaType = Timestamp.class, jdbcType = JdbcType.DATE),
@Result(property = "updateTime", column = "update_time", javaType = Timestamp.class, jdbcType = JdbcType.DATE),
@Result(property = "startTime", column = "start_time", javaType = Timestamp.class, jdbcType = JdbcType.DATE),
@Result(property = "processInstancePriority", column = "process_instance_priority", javaType = Priority.class, typeHandler = EnumOrdinalTypeHandler.class, jdbcType = JdbcType.TINYINT)
})
@SelectProvider(type = CommandMapperProvider.class, method = "queryOneCommand")
Command queryOneCommand();
/**
* query all commands
* @return
*/
@Results(value = {@Result(property = "id", column = "id", id = true, javaType = Integer.class, jdbcType = JdbcType.INTEGER),
@Result(property = "commandType", column = "command_type", typeHandler = EnumOrdinalTypeHandler.class, javaType = CommandType.class, jdbcType = JdbcType.TINYINT),
@Result(property = "processDefinitionId", column = "process_definition_id", javaType = Integer.class, jdbcType = JdbcType.INTEGER),
@Result(property = "executorId", column = "executor_id", javaType = Integer.class, jdbcType = JdbcType.INTEGER),
@Result(property = "commandParam", column = "command_param", javaType = String.class, jdbcType = JdbcType.VARCHAR),
@Result(property = "taskDependType", column = "task_depend_type", javaType = TaskDependType.class, typeHandler = EnumOrdinalTypeHandler.class, jdbcType = JdbcType.TINYINT),
@Result(property = "failureStrategy", column = "failure_strategy", javaType = FailureStrategy.class, typeHandler = EnumOrdinalTypeHandler.class, jdbcType = JdbcType.TINYINT),
@Result(property = "warningType", column = "warning_type", javaType = WarningType.class, typeHandler = EnumOrdinalTypeHandler.class, jdbcType = JdbcType.TINYINT),
@Result(property = "warningGroupId", column = "warning_group_id", javaType = Integer.class, jdbcType = JdbcType.INTEGER),
@Result(property = "scheduleTime", column = "schedule_time", javaType = Timestamp.class, jdbcType = JdbcType.DATE),
@Result(property = "updateTime", column = "update_time", javaType = Timestamp.class, jdbcType = JdbcType.DATE),
@Result(property = "startTime", column = "start_time", javaType = Timestamp.class, jdbcType = JdbcType.DATE),
@Result(property = "processInstancePriority", column = "process_instance_priority", javaType = Priority.class, typeHandler = EnumOrdinalTypeHandler.class, jdbcType = JdbcType.TINYINT)
})
@SelectProvider(type = CommandMapperProvider.class, method = "queryAllCommand")
List<Command> queryAllCommand();
}
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package cn.escheduler.dao.mapper;
import cn.escheduler.common.enums.*;
import cn.escheduler.common.utils.EnumFieldUtil;
import org.apache.ibatis.jdbc.SQL;
import java.util.Map;
/**
* command mapper provider
*/
public class CommandMapperProvider {
private static final String TABLE_NAME = "t_escheduler_command";
private static final String DEFINE_TABLE_NAME = "t_escheduler_process_definition";
/**
* inert command
*
* @param parameter
* @return
*/
public String insert(Map<String, Object> parameter) {
return new SQL() {
{
INSERT_INTO(TABLE_NAME);
VALUES("`command_type`", EnumFieldUtil.genFieldStr("command.commandType", CommandType.class));
VALUES("`process_definition_id`", "#{command.processDefinitionId}");
VALUES("`executor_id`", "#{command.executorId}");
VALUES("`command_param`", "#{command.commandParam}");
VALUES("`task_depend_type`", EnumFieldUtil.genFieldStr("command.taskDependType", TaskDependType.class));
VALUES("`failure_strategy`", EnumFieldUtil.genFieldStr("command.failureStrategy", FailureStrategy.class));
VALUES("`warning_type`", EnumFieldUtil.genFieldStr("command.warningType", WarningType.class));
VALUES("`process_instance_priority`", EnumFieldUtil.genFieldStr("command.processInstancePriority", Priority.class));
VALUES("`warning_group_id`", "#{command.warningGroupId}");
VALUES("`schedule_time`", "#{command.scheduleTime}");
VALUES("`update_time`", "#{command.updateTime}");
VALUES("`start_time`", "#{command.startTime}");
}
}.toString();
}
/**
* delete command
*
* @param parameter
* @return
*/
public String delete(Map<String, Object> parameter) {
return new SQL() {
{
DELETE_FROM(TABLE_NAME);
WHERE("`id`=#{cmdId}");
}
}.toString();
}
/**
* update command
*
* @param parameter
* @return
*/
public String update(Map<String, Object> parameter) {
return new SQL() {
{
UPDATE(TABLE_NAME);
SET("`command_type`=" + EnumFieldUtil.genFieldStr("command.commandType", CommandType.class));
SET("`process_definition_id`=#{command.processDefinitionId}");
SET("`executor_id`=#{command.executorId}");
SET("`command_param`=#{command.commandParam}");
SET("`task_depend_type`="+ EnumFieldUtil.genFieldStr("command.taskDependType", TaskDependType.class));
SET("`failure_strategy`="+ EnumFieldUtil.genFieldStr("command.failureStrategy", FailureStrategy.class));
SET("`warning_type`="+ EnumFieldUtil.genFieldStr("command.warningType", WarningType.class));
SET("`process_instance_priority`="+ EnumFieldUtil.genFieldStr("command.processInstancePriority", Priority.class));
SET("`warning_group_id`=#{command.warningGroupId}");
SET("`schedule_time`=#{command.scheduleTime}");
SET("`update_time`=#{command.updateTime}");
SET("`start_time`=#{command.startTime}");
WHERE("`id`=#{command.id}");
}
}.toString();
}
/**
* query a command that can run normally
* command must be release on line, usable.
* @param parameter
* @return
*/
public String queryOneCommand(Map<String, Object> parameter) {
return new SQL() {
{
SELECT("cmd.*,process_define.id as process_definition_id");
FROM(TABLE_NAME + " cmd");
JOIN( DEFINE_TABLE_NAME + " process_define ON cmd.process_definition_id = process_define.id");
WHERE("process_define.release_state =1 AND process_define.flag = 1");
ORDER_BY("update_time asc");
}
}.toString() + " limit 1";
}
/**
* query all commands
* @param parameter
* @return
*/
public String queryAllCommand(Map<String, Object> parameter) {
return new SQL() {
{
SELECT("cmd.*");
FROM(TABLE_NAME + " cmd");
}
}.toString();
}
}
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package cn.escheduler.dao.mapper;
import cn.escheduler.common.enums.DbType;
import cn.escheduler.dao.model.DataSource;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.EnumOrdinalTypeHandler;
import org.apache.ibatis.type.JdbcType;
import java.sql.Timestamp;
import java.util.List;
/**
* data source mapper
*/
public interface DataSourceMapper {
/**
* insert data source
*
* @param dataSource
* @return
*/
@InsertProvider(type = DataSourceMapperProvider.class, method = "insert")
@SelectKey(statement = "SELECT LAST_INSERT_ID() as id", resultType = Integer.class, keyProperty = "dataSource.id", before = false)
int insert(@Param("dataSource") DataSource dataSource);
/**
* update data source
*
* @param dataSource
* @return
*/
@UpdateProvider(type = DataSourceMapperProvider.class, method = "update")
int update(@Param("dataSource") DataSource dataSource);
/**
* delete data source by id
*
* @param id
* @return
*/
@DeleteProvider(type = DataSourceMapperProvider.class, method = "deleteDataSourceById")
int deleteDataSourceById(@Param("id") int id);
/**
* query data source list by type
* @param userId
* @param type
* @return
*/
@Results(value = {
@Result(property = "id", column = "id", id = true, javaType = Integer.class, jdbcType = JdbcType.INTEGER),
@Result(property = "name", column = "name", javaType = String.class, jdbcType = JdbcType.VARCHAR),
@Result(property = "note", column = "note", javaType = String.class, jdbcType = JdbcType.VARCHAR),
@Result(property = "type", column = "type", typeHandler = EnumOrdinalTypeHandler.class, javaType = DbType.class, jdbcType = JdbcType.INTEGER),
@Result(property = "connectionParams", column = "connection_params", javaType = String.class, jdbcType = JdbcType.VARCHAR),
@Result(property = "createTime", column = "create_time", javaType = Timestamp.class, jdbcType = JdbcType.DATE),
@Result(property = "updateTime", column = "update_time", javaType = Timestamp.class, jdbcType = JdbcType.DATE)
})
@SelectProvider(type = DataSourceMapperProvider.class, method = "queryDataSourceByType")
List<DataSource> queryDataSourceByType(@Param("userId") int userId, @Param("type") Integer type);
/**
* query data source by id
*
* @param id
* @return
*/
@Results(value = {
@Result(property = "id", column = "id", id = true, javaType = Integer.class, jdbcType = JdbcType.INTEGER),
@Result(property = "name", column = "name", javaType = String.class, jdbcType = JdbcType.VARCHAR),
@Result(property = "note", column = "note", javaType = String.class, jdbcType = JdbcType.VARCHAR),
@Result(property = "type", column = "type", typeHandler = EnumOrdinalTypeHandler.class, javaType = DbType.class, jdbcType = JdbcType.INTEGER),
@Result(property = "userName", column = "user_name", javaType = String.class, jdbcType = JdbcType.VARCHAR),
@Result(property = "userId", column = "user_id", javaType = Integer.class, jdbcType = JdbcType.INTEGER),
@Result(property = "projectId", column = "project_id", javaType = Integer.class, jdbcType = JdbcType.INTEGER),
@Result(property = "projectName", column = "project_name", javaType = String.class, jdbcType = JdbcType.VARCHAR),
@Result(property = "connectionParams", column = "connection_params", javaType = String.class, jdbcType = JdbcType.VARCHAR),
@Result(property = "createTime", column = "create_time", javaType = Timestamp.class, jdbcType = JdbcType.DATE),
@Result(property = "updateTime", column = "update_time", javaType = Timestamp.class, jdbcType = JdbcType.DATE)
})
@SelectProvider(type = DataSourceMapperProvider.class, method = "queryById")
DataSource queryById(@Param("id") Integer id);
/**
* count data source by user id
*
* @param userId
* @return
*/
@SelectProvider(type = DataSourceMapperProvider.class, method = "countUserDatasource")
int countUserDatasource(@Param("userId") int userId);
/**
* count data source number
*
* @return
*/
@SelectProvider(type = DataSourceMapperProvider.class, method = "countAllDatasource")
int countAllDatasource();
/**
* query data source list paging
*
* @param userId
* @param searchVal
* @param offset
* @param pageSize
* @return
*/
@Results(value = {
@Result(property = "id", column = "id", id = true, javaType = Integer.class, jdbcType = JdbcType.INTEGER),
@Result(property = "name", column = "name", javaType = String.class, jdbcType = JdbcType.VARCHAR),
@Result(property = "note", column = "note", javaType = String.class, jdbcType = JdbcType.VARCHAR),
@Result(property = "type", column = "type", typeHandler = EnumOrdinalTypeHandler.class, javaType = DbType.class, jdbcType = JdbcType.INTEGER),
@Result(property = "userId", column = "user_id", javaType = Integer.class, jdbcType = JdbcType.INTEGER),
@Result(property = "connectionParams", column = "connection_params", javaType = String.class, jdbcType = JdbcType.VARCHAR),
@Result(property = "createTime", column = "create_time", javaType = Timestamp.class, jdbcType = JdbcType.DATE),
@Result(property = "updateTime", column = "update_time", javaType = Timestamp.class, jdbcType = JdbcType.DATE)
})
@SelectProvider(type = DataSourceMapperProvider.class, method = "queryDataSourcePaging")
List<DataSource> queryDataSourcePaging(@Param("userId") int userId, @Param("searchVal") String searchVal,
@Param("offset") int offset,
@Param("pageSize") int pageSize);
/**
* query data source list paging
*
* @param searchVal
* @param offset
* @param pageSize
* @return
*/
@Results(value = {
@Result(property = "id", column = "id", id = true, javaType = Integer.class, jdbcType = JdbcType.INTEGER),
@Result(property = "name", column = "name", javaType = String.class, jdbcType = JdbcType.VARCHAR),
@Result(property = "note", column = "note", javaType = String.class, jdbcType = JdbcType.VARCHAR),
@Result(property = "type", column = "type", typeHandler = EnumOrdinalTypeHandler.class, javaType = DbType.class, jdbcType = JdbcType.INTEGER),
@Result(property = "userId", column = "user_id", javaType = Integer.class, jdbcType = JdbcType.INTEGER),
@Result(property = "connectionParams", column = "connection_params", javaType = String.class, jdbcType = JdbcType.VARCHAR),
@Result(property = "createTime", column = "create_time", javaType = Timestamp.class, jdbcType = JdbcType.DATE),
@Result(property = "updateTime", column = "update_time", javaType = Timestamp.class, jdbcType = JdbcType.DATE)
})
@SelectProvider(type = DataSourceMapperProvider.class, method = "queryAllDataSourcePaging")
List<DataSource> queryAllDataSourcePaging(@Param("searchVal") String searchVal,
@Param("offset") int offset,
@Param("pageSize") int pageSize);
/**
* query data source by name
* @param name
* @return
*/
@Results(value = {
@Result(property = "id", column = "id", id = true, javaType = Integer.class, jdbcType = JdbcType.INTEGER),
@Result(property = "name", column = "name", javaType = String.class, jdbcType = JdbcType.VARCHAR),
@Result(property = "note", column = "note", javaType = String.class, jdbcType = JdbcType.VARCHAR),
@Result(property = "type", column = "type", typeHandler = EnumOrdinalTypeHandler.class, javaType = DbType.class, jdbcType = JdbcType.INTEGER),
@Result(property = "userId", column = "user_id", javaType = Integer.class, jdbcType = JdbcType.INTEGER),
@Result(property = "connectionParams", column = "connection_params", javaType = String.class, jdbcType = JdbcType.VARCHAR),
@Result(property = "createTime", column = "create_time", javaType = Timestamp.class, jdbcType = JdbcType.DATE),
@Result(property = "updateTime", column = "update_time", javaType = Timestamp.class, jdbcType = JdbcType.DATE)
})
@SelectProvider(type = DataSourceMapperProvider.class, method = "queryDataSourceByName")
List<DataSource> queryDataSourceByName(@Param("name") String name);
/**
* authed data source to user
* @param userId
* @return
*/
@Results(value = {
@Result(property = "id", column = "id", id = true, javaType = Integer.class, jdbcType = JdbcType.INTEGER),
@Result(property = "name", column = "name", javaType = String.class, jdbcType = JdbcType.VARCHAR),
@Result(property = "note", column = "note", javaType = String.class, jdbcType = JdbcType.VARCHAR),
@Result(property = "type", column = "type", typeHandler = EnumOrdinalTypeHandler.class, javaType = DbType.class, jdbcType = JdbcType.INTEGER),
@Result(property = "userId", column = "user_id", javaType = Integer.class, jdbcType = JdbcType.INTEGER),
@Result(property = "connectionParams", column = "connection_params", javaType = String.class, jdbcType = JdbcType.VARCHAR),
@Result(property = "createTime", column = "create_time", javaType = Timestamp.class, jdbcType = JdbcType.DATE),
@Result(property = "updateTime", column = "update_time", javaType = Timestamp.class, jdbcType = JdbcType.DATE)
})
@SelectProvider(type = DataSourceMapperProvider.class, method = "authedDatasource")
List<DataSource> authedDatasource(@Param("userId") int userId);
/**
* query data source except user
* @param userId
* @return
*/
@Results(value = {
@Result(property = "id", column = "id", id = true, javaType = Integer.class, jdbcType = JdbcType.INTEGER),
@Result(property = "name", column = "name", javaType = String.class, jdbcType = JdbcType.VARCHAR),
@Result(property = "note", column = "note", javaType = String.class, jdbcType = JdbcType.VARCHAR),
@Result(property = "type", column = "type", typeHandler = EnumOrdinalTypeHandler.class, javaType = DbType.class, jdbcType = JdbcType.INTEGER),
@Result(property = "userId", column = "user_id", javaType = Integer.class, jdbcType = JdbcType.INTEGER),
@Result(property = "connectionParams", column = "connection_params", javaType = String.class, jdbcType = JdbcType.VARCHAR),
@Result(property = "createTime", column = "create_time", javaType = Timestamp.class, jdbcType = JdbcType.DATE),
@Result(property = "updateTime", column = "update_time", javaType = Timestamp.class, jdbcType = JdbcType.DATE)
})
@SelectProvider(type = DataSourceMapperProvider.class, method = "queryDatasourceExceptUserId")
List<DataSource> queryDatasourceExceptUserId(@Param("userId") int userId);
}
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package cn.escheduler.dao.mapper;
import cn.escheduler.common.enums.DbType;
import cn.escheduler.common.utils.EnumFieldUtil;
import org.apache.commons.lang3.StringUtils;
import org.apache.ibatis.jdbc.SQL;
import java.text.MessageFormat;
import java.util.Map;
/**
* data source mapper provider
*/
public class DataSourceMapperProvider {
public static final String TABLE_NAME = "t_escheduler_datasource";
public static final String USER_TABLE_NAME = "t_escheduler_user";
public static final String PROJECT_TABLE_NAME = "t_escheduler_project";
public static final String USER_DATASOURCE_RELATION_TABLE_NAME = "t_escheduler_relation_datasource_user";
/**
* insert data source
*
* @param parameter
* @return
*/
public String insert(Map<String, Object> parameter) {
return new SQL() {{
INSERT_INTO(TABLE_NAME);
VALUES("`name`", "#{dataSource.name}");
VALUES("`note`", "#{dataSource.note}");
VALUES("`type`", EnumFieldUtil.genFieldStr("dataSource.type", DbType.class));
VALUES("`user_id`", "#{dataSource.userId}");
VALUES("`connection_params`", "#{dataSource.connectionParams}");
VALUES("`create_time`", "#{dataSource.createTime}");
VALUES("`update_time`", "#{dataSource.updateTime}");
}}.toString();
}
/**
*
* update data source
* @param parameter
* @return
*/
public String update(Map<String, Object> parameter) {
return new SQL() {{
UPDATE(TABLE_NAME);
SET("`name` = #{dataSource.name}");
SET("`note` = #{dataSource.note}");
SET("`user_id` = #{dataSource.userId}");
SET("`type` = "+ EnumFieldUtil.genFieldStr("dataSource.type", DbType.class));
SET("`connection_params` = #{dataSource.connectionParams}");
SET("`update_time` = #{dataSource.updateTime}");
WHERE("`id` = #{dataSource.id}");
}}.toString();
}
/**
* delete datasource by id
* @param parameter
* @return
*/
public String deleteDataSourceById(Map<String, Object> parameter) {
return new SQL() {{
DELETE_FROM(TABLE_NAME);
WHERE("`id` = #{id}");
}}.toString();
}
/**
* query datasource list by type
* @param parameter
* @return
*/
public String queryDataSourceByType(Map<String, Object> parameter) {
return new SQL() {{
SELECT("*");
FROM(TABLE_NAME );
WHERE("type = #{type}");
WHERE("id in (select datasource_id from "+USER_DATASOURCE_RELATION_TABLE_NAME+" where user_id=#{userId} union select id as datasource_id from "+TABLE_NAME+" where user_id=#{userId})");
}}.toString();
}
/**
* query data source by id
*
* @param parameter
* @return
*/
public String queryById(Map<String, Object> parameter) {
return new SQL() {{
SELECT("r.*,u.user_name as userName");
FROM(TABLE_NAME + " r");
JOIN(new MessageFormat("{0} as u on u.id = r.user_id").format(new Object[]{USER_TABLE_NAME}));
WHERE("r.id = #{id}");
}}.toString();
}
/**
* query data source paging
* @param parameter
* @return
*/
public String queryDataSourcePaging(Map<String, Object> parameter) {
return new SQL() {{
SELECT("*");
FROM(TABLE_NAME );
WHERE("id in (select datasource_id from "+USER_DATASOURCE_RELATION_TABLE_NAME+" where user_id=#{userId} union select id as datasource_id from "+TABLE_NAME+" where user_id=#{userId})");
Object searchVal = parameter.get("searchVal");
if(searchVal != null && StringUtils.isNotEmpty(searchVal.toString())){
WHERE( " name like concat('%', #{searchVal}, '%') ");
}
ORDER_BY("update_time desc limit #{offset},#{pageSize} ");
}}.toString();
}
/**
*
* query data source list paging
* @param parameter
* @return
*/
public String queryAllDataSourcePaging(Map<String, Object> parameter) {
return new SQL() {{
SELECT("*");
FROM(TABLE_NAME );
Object searchVal = parameter.get("searchVal");
if(searchVal != null && StringUtils.isNotEmpty(searchVal.toString())){
WHERE( " name like concat('%', #{searchVal}, '%') ");
}
ORDER_BY("update_time desc limit #{offset},#{pageSize} ");
}}.toString();
}
/**
* count data source by user id
*
* @param parameter
* @return
*/
public String countUserDatasource(Map<String, Object> parameter) {
return new SQL() {{
SELECT("count(0)");
FROM(TABLE_NAME);
WHERE("id in (select datasource_id from "+USER_DATASOURCE_RELATION_TABLE_NAME+" where user_id=#{userId} union select id as datasource_id from "+TABLE_NAME+" where user_id=#{userId})");
}}.toString();
}
/**
* 查询总的数据源数目
*
* @param parameter
* @return
*/
public String countAllDatasource(Map<String, Object> parameter) {
return new SQL() {{
SELECT("count(0)");
FROM(TABLE_NAME);
}}.toString();
}
/**
* query data source by name
* @param parameter
* @return
*/
public String queryDataSourceByName(Map<String, Object> parameter) {
return new SQL() {{
SELECT("*");
FROM(TABLE_NAME );
WHERE("name = #{name}");
}}.toString();
}
/**
* authed data source to user
*
* @param parameter
* @return
*/
public String authedDatasource(Map<String, Object> parameter) {
return new SQL() {{
SELECT("d.*");
FROM(TABLE_NAME + " d,t_escheduler_relation_datasource_user rel");
WHERE(" d.id = rel.datasource_id AND rel.user_id = #{userId}");
}}.toString();
}
/**
* query data source except user
*
* @param parameter
* @return
*/
public String queryDatasourceExceptUserId(Map<String, Object> parameter) {
return new SQL() {{
SELECT("*");
FROM(TABLE_NAME);
WHERE("user_id <> #{userId}");
}}.toString();
}
}
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package cn.escheduler.dao.mapper;
import cn.escheduler.dao.model.DatasourceUser;
import org.apache.ibatis.annotations.DeleteProvider;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Param;
/**
* data source user relation mapper
*/
public interface DatasourceUserMapper {
/**
* insert data source user relation
*
* @param datasourceUser
* @return
*/
@InsertProvider(type = DatasourceUserMapperProvider.class, method = "insert")
int insert(@Param("datasourceUser") DatasourceUser datasourceUser);
/**
* delete data source user relation by user id
*
* @param userId
* @return
*/
@DeleteProvider(type = DatasourceUserMapperProvider.class, method = "deleteByUserId")
int deleteByUserId(@Param("userId") int userId);
/**
* delete by data source id
* @param datasourceId
* @return
*/
@DeleteProvider(type = DatasourceUserMapperProvider.class, method = "deleteByDatasourceId")
int deleteByDatasourceId(@Param("datasourceId") int datasourceId);
}
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package cn.escheduler.dao.mapper;
import org.apache.ibatis.jdbc.SQL;
import java.util.Map;
public class DatasourceUserMapperProvider {
private static final String TABLE_NAME = "t_escheduler_relation_datasource_user";
/**
*
* @param parameter
* @return
*/
public String insert(Map<String, Object> parameter) {
return new SQL() {{
INSERT_INTO(TABLE_NAME);
VALUES("`datasource_id`", "#{datasourceUser.datasourceId}");
VALUES("`user_id`", "#{datasourceUser.userId}");
VALUES("`perm`", "#{datasourceUser.perm}");
VALUES("`create_time`", "#{datasourceUser.createTime}");
VALUES("`update_time`", "#{datasourceUser.updateTime}");
}}.toString();
}
/**
*
* @param parameter
* @return
*/
public String deleteByUserId(Map<String, Object> parameter) {
return new SQL() {{
DELETE_FROM(TABLE_NAME);
WHERE("`user_id` = #{userId}");
}}.toString();
}
/**
* @param parameter
* @return
*/
public String deleteByDatasourceId(Map<String, Object> parameter) {
return new SQL() {{
DELETE_FROM(TABLE_NAME);
WHERE("`datasource_id` = #{datasourceId}");
}}.toString();
}
}
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package cn.escheduler.dao.mapper;
import cn.escheduler.dao.model.MasterServer;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;
import java.util.Date;
import java.util.List;
public interface MasterServerMapper {
/**
* query all masters
*
* @return
*/
@Results(value = {
@Result(property = "id", column = "id", javaType = Integer.class, jdbcType = JdbcType.INTEGER),
@Result(property = "host", column = "host", javaType = String.class, jdbcType = JdbcType.VARCHAR),
@Result(property = "port", column = "port", javaType = int.class, jdbcType = JdbcType.INTEGER),
@Result(property = "zkDirectory", column = "zk_directory", javaType = String.class, jdbcType = JdbcType.VARCHAR),
@Result(property = "resInfo", column = "res_info", javaType = String.class, jdbcType = JdbcType.VARCHAR),
@Result(property = "createTime", column = "create_time", javaType = Date.class, jdbcType = JdbcType.TIMESTAMP),
@Result(property = "lastHeartbeatTime", column = "last_heartbeat_time", javaType = Date.class, jdbcType = JdbcType.TIMESTAMP)
})
@SelectProvider(type = MasterServerMapperProvider.class, method = "queryAllMaster")
List<MasterServer> queryAllMaster();
/**
* insert one master
*
* @param masterServer
* @return
*/
@InsertProvider(type = MasterServerMapperProvider.class, method = "insert")
@SelectKey(statement = "SELECT LAST_INSERT_ID() as id", resultType = Integer.class, keyProperty = "masterServer.id", before = false)
int insert(@Param("masterServer") MasterServer masterServer);
/**
* update master
*
* @param masterServer
* @return
*/
@UpdateProvider(type = MasterServerMapperProvider.class, method = "update")
int update(@Param("masterServer") MasterServer masterServer);
/**
* delete master
*/
@DeleteProvider(type = MasterServerMapperProvider.class, method = "delete")
void delete();
/**
* delete master by host
*
* @param host
*/
@DeleteProvider(type = MasterServerMapperProvider.class, method = "deleteWorkerByHost")
int deleteWorkerByHost(@Param("host") String host);
}
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package cn.escheduler.dao.mapper;
import org.apache.ibatis.jdbc.SQL;
import java.util.Map;
public class MasterServerMapperProvider {
private static final String TABLE_NAME = "t_escheduler_master_server";
/**
*
* @return
*/
public String queryAllMaster() {
return new SQL() {{
SELECT("*");
FROM(TABLE_NAME);
}}.toString();
}
/**
*
* @param parameter
* @return
*/
public String insert(Map<String, Object> parameter) {
return new SQL() {{
INSERT_INTO(TABLE_NAME);
VALUES("host", "#{masterServer.host}");
VALUES("port", "#{masterServer.port}");
VALUES("zk_directory", "#{masterServer.zkDirectory}");
VALUES("res_info", "#{masterServer.resInfo}");
VALUES("create_time", "#{masterServer.createTime}");
VALUES("last_heartbeat_time", "#{masterServer.lastHeartbeatTime}");
}}.toString();
}
/**
*
* @param parameter
* @return
*/
public String update(Map<String, Object> parameter) {
return new SQL() {{
UPDATE(TABLE_NAME);
SET("last_heartbeat_time = #{masterServer.lastHeartbeatTime}");
SET("port = #{masterServer.port}");
SET("res_info = #{masterServer.resInfo}");
WHERE("host = #{masterServer.host}");
}}.toString();
}
/**
*
* @return
*/
public String delete() {
return new SQL() {{
DELETE_FROM(TABLE_NAME);
}}.toString();
}
/**
*
* @param parameter
* @return
*/
public String deleteWorkerByHost(Map<String, Object> parameter) {
return new SQL() {{
DELETE_FROM(TABLE_NAME);
WHERE("host = #{host}");
}}.toString();
}
}
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package cn.escheduler.dao.mapper;
import cn.escheduler.common.enums.Flag;
import cn.escheduler.common.enums.ReleaseState;
import cn.escheduler.common.enums.UserType;
import cn.escheduler.dao.model.DefinitionGroupByUser;
import cn.escheduler.dao.model.ProcessDefinition;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.EnumOrdinalTypeHandler;
import org.apache.ibatis.type.JdbcType;
import java.sql.Timestamp;
import java.util.List;
/**
* process definition mapper
*/
public interface ProcessDefinitionMapper {
/**
* insert process define
* @param processDefinition
* @return
*/
@InsertProvider(type = ProcessDefinitionMapperProvider.class, method = "insert")
@Options(useGeneratedKeys = true,keyProperty = "processDefinition.id")
@SelectKey(statement = "SELECT LAST_INSERT_ID()", keyProperty = "processDefinition.id", before = false, resultType = int.class)
int insert(@Param("processDefinition") ProcessDefinition processDefinition);
/**
* delete process define
* @param processDefinitionId
* @return
*/
@DeleteProvider(type = ProcessDefinitionMapperProvider.class, method = "delete")
int delete(@Param("processDefinitionId") int processDefinitionId);
/**
* update process define
*
* @param processDefinition
* @return
*/
@UpdateProvider(type = ProcessDefinitionMapperProvider.class, method = "update")
int update(@Param("processDefinition") ProcessDefinition processDefinition);
/**
* update release state
* @param processDefinitionId
* @param releaseState
* @return
*/
@UpdateProvider(type = ProcessDefinitionMapperProvider.class, method = "updateProcessDefinitionReleaseState")
int updateProcessDefinitionReleaseState(@Param("processDefinitionId") int processDefinitionId,
@Param("releaseState") ReleaseState releaseState);
/**
* query definition by id
* @param processDefinitionId
* @return
*/
@Results(value = {@Result(property = "id", column = "id", id = true, javaType = Integer.class, jdbcType = JdbcType.INTEGER),
@Result(property = "name", column = "name", javaType = String.class, jdbcType = JdbcType.VARCHAR),
@Result(property = "version", column = "version", javaType = Integer.class, jdbcType = JdbcType.TINYINT),
@Result(property = "releaseState", column = "release_state", typeHandler = EnumOrdinalTypeHandler.class, javaType = ReleaseState.class, jdbcType = JdbcType.TINYINT),
@Result(property = "projectId", column = "project_id", javaType = Integer.class, jdbcType = JdbcType.INTEGER),
@Result(property = "userId", column = "user_id", javaType = Integer.class, jdbcType = JdbcType.INTEGER),
@Result(property = "processDefinitionJson", column = "process_definition_json", javaType = String.class, jdbcType = JdbcType.VARCHAR),
@Result(property = "desc", column = "desc", javaType = String.class, jdbcType = JdbcType.VARCHAR),
@Result(property = "globalParams", column = "global_params", javaType = String.class, jdbcType = JdbcType.VARCHAR),
@Result(property = "createTime", column = "create_time", javaType = Timestamp.class, jdbcType = JdbcType.DATE),
@Result(property = "updateTime", column = "update_time", javaType = Timestamp.class, jdbcType = JdbcType.DATE),
@Result(property = "flag", column = "flag", typeHandler = EnumOrdinalTypeHandler.class, javaType = Flag.class, jdbcType = JdbcType.TINYINT),
@Result(property = "userName", column = "user_name", javaType = String.class, jdbcType = JdbcType.VARCHAR),
@Result(property = "locations", column = "locations", javaType = String.class, jdbcType = JdbcType.VARCHAR),
@Result(property = "connects", column = "connects", javaType = String.class, jdbcType = JdbcType.VARCHAR),
@Result(property = "projectName", column = "project_name", javaType = String.class, jdbcType = JdbcType.VARCHAR),
@Result(property = "receivers", column = "receivers", javaType = String.class, jdbcType = JdbcType.VARCHAR),
@Result(property = "receiversCc", column = "receivers_cc", javaType = String.class, jdbcType = JdbcType.VARCHAR)
})
@SelectProvider(type = ProcessDefinitionMapperProvider.class, method = "queryByDefineId")
ProcessDefinition queryByDefineId(@Param("processDefinitionId") int processDefinitionId);
/**
* query process definition by project id and name
* @param projectId
* @param name
* @return
*/
@Results(value = {@Result(property = "id", column = "id", id = true, javaType = Integer.class, jdbcType = JdbcType.INTEGER),
@Result(property = "name", column = "name", javaType = String.class, jdbcType = JdbcType.VARCHAR),
@Result(property = "version", column = "version", javaType = Integer.class, jdbcType = JdbcType.TINYINT),
@Result(property = "releaseState", column = "release_state", typeHandler = EnumOrdinalTypeHandler.class, javaType = ReleaseState.class, jdbcType = JdbcType.TINYINT),
@Result(property = "projectId", column = "project_id", javaType = Integer.class, jdbcType = JdbcType.INTEGER),
@Result(property = "userId", column = "user_id", javaType = Integer.class, jdbcType = JdbcType.INTEGER),
@Result(property = "processDefinitionJson", column = "process_definition_json", javaType = String.class, jdbcType = JdbcType.VARCHAR),
@Result(property = "desc", column = "desc", javaType = String.class, jdbcType = JdbcType.VARCHAR),
@Result(property = "createTime", column = "create_time", javaType = Timestamp.class, jdbcType = JdbcType.DATE),
@Result(property = "updateTime", column = "update_time", javaType = Timestamp.class, jdbcType = JdbcType.DATE),
@Result(property = "flag", column = "flag", typeHandler = EnumOrdinalTypeHandler.class, javaType = Flag.class, jdbcType = JdbcType.TINYINT),
@Result(property = "userName", column = "user_name", javaType = String.class, jdbcType = JdbcType.VARCHAR),
@Result(property = "locations", column = "locations", javaType = String.class, jdbcType = JdbcType.VARCHAR),
@Result(property = "connects", column = "connects", javaType = String.class, jdbcType = JdbcType.VARCHAR),
@Result(property = "projectName", column = "project_name", javaType = String.class, jdbcType = JdbcType.VARCHAR)
})
@SelectProvider(type = ProcessDefinitionMapperProvider.class, method = "queryByDefineName")
ProcessDefinition queryByDefineName(@Param("projectId") int projectId,
@Param("processDefinitionName") String name);
/**
* count definition number
* @param projectId
* @param userId
* @param searchVal
* @return
*/
@SelectProvider(type = ProcessDefinitionMapperProvider.class, method = "countDefineNumber")
Integer countDefineNumber(@Param("projectId") int projectId,
@Param("userId") int userId,
@Param("searchVal") String searchVal
);
/**
* query all definition list
* @param projectId
* @return
*/
@Results(value = {@Result(property = "id", column = "id", id = true, javaType = Integer.class, jdbcType = JdbcType.INTEGER),
@Result(property = "name", column = "name", javaType = String.class, jdbcType = JdbcType.VARCHAR),
@Result(property = "version", column = "version", javaType = Integer.class, jdbcType = JdbcType.TINYINT),
@Result(property = "releaseState", column = "release_state", typeHandler = EnumOrdinalTypeHandler.class, javaType = ReleaseState.class, jdbcType = JdbcType.TINYINT),
@Result(property = "projectId", column = "project_id", javaType = Integer.class, jdbcType = JdbcType.INTEGER),
@Result(property = "userId", column = "user_id", javaType = Integer.class, jdbcType = JdbcType.INTEGER),
@Result(property = "desc", column = "desc", javaType = String.class, jdbcType = JdbcType.VARCHAR),
@Result(property = "createTime", column = "create_time", javaType = Timestamp.class, jdbcType = JdbcType.DATE),
@Result(property = "updateTime", column = "update_time", javaType = Timestamp.class, jdbcType = JdbcType.DATE),
@Result(property = "flag", column = "flag", typeHandler = EnumOrdinalTypeHandler.class, javaType = Flag.class, jdbcType = JdbcType.TINYINT),
@Result(property = "userName", column = "user_name", javaType = String.class, jdbcType = JdbcType.VARCHAR),
@Result(property = "projectName", column = "project_name", javaType = String.class, jdbcType = JdbcType.VARCHAR)
})
@SelectProvider(type = ProcessDefinitionMapperProvider.class, method = "queryAllDefinitionList")
List<ProcessDefinition> queryAllDefinitionList(@Param("projectId") int projectId);
/**
* query definition list paging
* @param projectId
* @param searchVal
* @param userId
* @param offset
* @param pageSize
* @return
*/
@Results(value = {@Result(property = "id", column = "id", id = true, javaType = Integer.class, jdbcType = JdbcType.INTEGER),
@Result(property = "name", column = "name", javaType = String.class, jdbcType = JdbcType.VARCHAR),
@Result(property = "version", column = "version", javaType = Integer.class, jdbcType = JdbcType.TINYINT),
@Result(property = "releaseState", column = "release_state", typeHandler = EnumOrdinalTypeHandler.class, javaType = ReleaseState.class, jdbcType = JdbcType.TINYINT),
@Result(property = "projectId", column = "project_id", javaType = Integer.class, jdbcType = JdbcType.INTEGER),
@Result(property = "userId", column = "user_id", javaType = Integer.class, jdbcType = JdbcType.INTEGER),
@Result(property = "desc", column = "desc", javaType = String.class, jdbcType = JdbcType.VARCHAR),
@Result(property = "createTime", column = "create_time", javaType = Timestamp.class, jdbcType = JdbcType.DATE),
@Result(property = "updateTime", column = "update_time", javaType = Timestamp.class, jdbcType = JdbcType.DATE),
@Result(property = "flag", column = "flag", typeHandler = EnumOrdinalTypeHandler.class, javaType = Flag.class, jdbcType = JdbcType.TINYINT),
@Result(property = "userName", column = "user_name", javaType = String.class, jdbcType = JdbcType.VARCHAR),
@Result(property = "scheduleReleaseState", column = "schedule_release_state", typeHandler = EnumOrdinalTypeHandler.class, javaType = ReleaseState.class, jdbcType = JdbcType.TINYINT),
@Result(property = "projectName", column = "project_name", javaType = String.class, jdbcType = JdbcType.VARCHAR)
})
@SelectProvider(type = ProcessDefinitionMapperProvider.class, method = "queryDefineListPaging")
List<ProcessDefinition> queryDefineListPaging(@Param("projectId") int projectId,
@Param("searchVal") String searchVal,
@Param("userId") Integer userId,
@Param("offset") int offset,
@Param("pageSize") int pageSize);
/**
* query definition list by define id list
* @param ids
* @return
*/
@Results(value = {@Result(property = "id", column = "id", id = true, javaType = Integer.class, jdbcType = JdbcType.INTEGER),
@Result(property = "name", column = "name", javaType = String.class, jdbcType = JdbcType.VARCHAR),
@Result(property = "version", column = "version", javaType = Integer.class, jdbcType = JdbcType.TINYINT),
@Result(property = "releaseState", column = "release_state", typeHandler = EnumOrdinalTypeHandler.class, javaType = ReleaseState.class, jdbcType = JdbcType.TINYINT),
@Result(property = "projectId", column = "project_id", javaType = Integer.class, jdbcType = JdbcType.INTEGER),
@Result(property = "userId", column = "user_id", javaType = Integer.class, jdbcType = JdbcType.INTEGER),
@Result(property = "processDefinitionJson", column = "process_definition_json", javaType = String.class, jdbcType = JdbcType.VARCHAR),
@Result(property = "desc", column = "desc", javaType = String.class, jdbcType = JdbcType.VARCHAR),
@Result(property = "createTime", column = "create_time", javaType = Timestamp.class, jdbcType = JdbcType.DATE),
@Result(property = "updateTime", column = "update_time", javaType = Timestamp.class, jdbcType = JdbcType.DATE),
@Result(property = "flag", column = "flag", typeHandler = EnumOrdinalTypeHandler.class, javaType = Flag.class, jdbcType = JdbcType.TINYINT),
@Result(property = "locations", column = "locations", javaType = String.class, jdbcType = JdbcType.VARCHAR),
@Result(property = "connects", column = "connects", javaType = String.class, jdbcType = JdbcType.VARCHAR),
@Result(property = "userName", column = "user_name", javaType = String.class, jdbcType = JdbcType.VARCHAR),
@Result(property = "projectName", column = "project_name", javaType = String.class, jdbcType = JdbcType.VARCHAR)
})
@SelectProvider(type = ProcessDefinitionMapperProvider.class, method = "queryDefinitionListByIdList")
List<ProcessDefinition> queryDefinitionListByIdList(@Param("ids") List<String> ids);
/**
* count definition number group by users
* @param userId
* @param userType
* @param projectId
* @return
*/
@Results(value = {
@Result(property = "userId", column = "user_id", javaType = Integer.class, jdbcType = JdbcType.INTEGER),
@Result(property = "userName", column = "user_name", javaType = String.class, jdbcType = JdbcType.VARCHAR),
@Result(property = "count", column = "count", javaType = Integer.class, jdbcType = JdbcType.INTEGER),
})
@SelectProvider(type = ProcessDefinitionMapperProvider.class, method = "countDefinitionGroupByUser")
List<DefinitionGroupByUser> countDefinitionGroupByUser(
@Param("userId") Integer userId,
@Param("userType") UserType userType,
@Param("projectId") Integer projectId);
/**
* update receivers and cc by definition id
* @param receivers
* @param receiversCc
* @param processDefinitionId
* @return
*/
@UpdateProvider(type = ProcessDefinitionMapperProvider.class, method = "updateReceiversAndCcById")
int updateReceiversAndCcById(@Param("receivers") String receivers,
@Param("receiversCc") String receiversCc,
@Param("processDefinitionId") int processDefinitionId);
}
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package cn.escheduler.dao.mapper;
import cn.escheduler.common.enums.Flag;
import cn.escheduler.common.enums.ReleaseState;
import cn.escheduler.common.utils.EnumFieldUtil;
import org.apache.commons.lang3.StringUtils;
import org.apache.ibatis.jdbc.SQL;
import java.util.List;
import java.util.Map;
/**
* process definition mapper provider
*/
public class ProcessDefinitionMapperProvider {
private static final String TABLE_NAME = "t_escheduler_process_definition";
/**
* 插入流程定义
*
* @param parameter
* @return
*/
public String insert(Map<String, Object> parameter) {
return new SQL() {
{
INSERT_INTO(TABLE_NAME);
VALUES("`name`", "#{processDefinition.name}");
VALUES("`version`", "#{processDefinition.version}");
VALUES("`release_state`", EnumFieldUtil.genFieldStr("processDefinition.releaseState", ReleaseState.class));
VALUES("`project_id`", "#{processDefinition.projectId}");
VALUES("`process_definition_json`", "#{processDefinition.processDefinitionJson}");
VALUES("`desc`", "#{processDefinition.desc}");
VALUES("`global_params`", "#{processDefinition.globalParams}");
VALUES("`locations`", "#{processDefinition.locations}");
VALUES("`connects`", "#{processDefinition.connects}");
VALUES("`create_time`", "#{processDefinition.createTime}");
VALUES("`update_time`", "#{processDefinition.updateTime}");
VALUES("`flag`", EnumFieldUtil.genFieldStr("processDefinition.flag", ReleaseState.class));
VALUES("`user_id`", "#{processDefinition.userId}");
}
}.toString();
}
/**
* 删除流程定义
*
* @param parameter
* @return
*/
public String delete(Map<String, Object> parameter) {
return new SQL() {
{
DELETE_FROM(TABLE_NAME);
WHERE("`id`=#{processDefinitionId}");
}
}.toString();
}
/**
* 更新流程定义
*
* @param parameter
* @return
*/
public String update(Map<String, Object> parameter) {
return new SQL() {
{
UPDATE(TABLE_NAME);
SET("`name`=#{processDefinition.name}");
SET("`version`=#{processDefinition.version}");
SET("`release_state`="+EnumFieldUtil.genFieldStr("processDefinition.releaseState", ReleaseState.class));
SET("`project_id`=#{processDefinition.projectId}");
SET("`process_definition_json`=#{processDefinition.processDefinitionJson}");
SET("`desc`=#{processDefinition.desc}");
SET("`locations`=#{processDefinition.locations}");
SET("`connects`=#{processDefinition.connects}");
SET("`global_params`=#{processDefinition.globalParams}");
SET("`create_time`=#{processDefinition.createTime}");
SET("`update_time`=#{processDefinition.updateTime}");
SET("`flag`="+EnumFieldUtil.genFieldStr("processDefinition.flag", Flag.class));
SET("`user_id`=#{processDefinition.userId}");
WHERE("`id`=#{processDefinition.id}");
}
}.toString();
}
public String updateProcessDefinitionReleaseState(Map<String, Object> parameter) {
return new SQL() {
{
UPDATE(TABLE_NAME);
SET("`release_state`="+EnumFieldUtil.genFieldStr("releaseState", ReleaseState.class));
WHERE("`id`=#{processDefinitionId}");
}
}.toString();
}
/**
* 根据流程定义 id 查询 sql
*
* @param parameter
* @return
*/
public String queryByDefineId(Map<String, Object> parameter) {
return new SQL() {
{
SELECT("pd.*,u.user_name,p.name as projectName");
FROM(TABLE_NAME + " pd");
JOIN("t_escheduler_user u ON pd.user_id = u.id");
JOIN("t_escheduler_project p ON pd.project_id = p.id");
WHERE("pd.id = #{processDefinitionId}");
}
}.toString();
}
/**
* query By Define Name
*
* @param parameter
* @return
*/
public String queryByDefineName(Map<String, Object> parameter) {
return new SQL() {
{
SELECT("pd.*,u.user_name,p.name as project_name,t.tenant_code,t.tenant_name,q.queue,q.queue_name");
FROM(TABLE_NAME + " pd");
JOIN("t_escheduler_user u ON pd.user_id = u.id");
JOIN("t_escheduler_project p ON pd.project_id = p.id");
JOIN("t_escheduler_tenant t ON t.id = u.tenant_id");
JOIN("t_escheduler_queue q ON t.queue_id = q.id");
WHERE("p.id = #{projectId}");
WHERE("pd.name = #{processDefinitionName}");
}
}.toString();
}
/**
* query define list paging
* @param parameter
* @return
*/
public String queryDefineListPaging(Map<String, Object> parameter) {
return new SQL() {{
SELECT("td.id,td.name,td.version,td.release_state,td.project_id,td.user_id,td.`desc`,td.create_time,td.update_time,td.flag,td.global_params,td.receivers,td.receivers_cc,sc.schedule_release_state");
FROM(TABLE_NAME + " td");
LEFT_OUTER_JOIN(" (select process_definition_id,release_state as schedule_release_state from `t_escheduler_schedules` " +
"group by `process_definition_id`,`release_state`) sc on sc.process_definition_id = td.id");
WHERE("td.project_id = #{projectId} ");
Object searchVal = parameter.get("searchVal");
if(searchVal != null && StringUtils.isNotEmpty(searchVal.toString())){
WHERE( " td.name like concat('%', #{searchVal}, '%') ");
}
Object userId = parameter.get("userId");
if(userId != null && 0 != Integer.parseInt(userId.toString())){
WHERE("td.user_id = #{userId}");
}
ORDER_BY(" td.update_time desc limit #{offset},#{pageSize} ");
}}.toString();
}
/**
* query all define list by project id
* @param parameter
* @return
*/
public String queryAllDefinitionList(Map<String, Object> parameter) {
return new SQL() {{
SELECT("id,name,version,release_state,project_id,user_id,`desc`,create_time,update_time,flag,global_params,receivers,receivers_cc");
FROM(TABLE_NAME );
WHERE("project_id = #{projectId}");
ORDER_BY("create_time desc ");
}}.toString();
}
/**
* count definition number group by project id
* @param parameter
* @return
*/
public String countDefineNumber(Map<String, Object> parameter) {
return new SQL() {{
SELECT("count(0)");
FROM(TABLE_NAME);
WHERE("project_id = #{projectId}");
Object searchVal = parameter.get("searchVal");
if(searchVal != null && StringUtils.isNotEmpty(searchVal.toString())){
WHERE( " name like concat('%', #{searchVal}, '%') ");
}
Object userId = parameter.get("userId");
if(userId != null && 0 != Integer.parseInt(userId.toString())){
WHERE("user_id = #{userId}");
}
}}.toString();
}
/**
* count definition number by user type
* @param parameter
* @return
*/
public String countDefinitionGroupByUser(Map<String, Object> parameter) {
return new SQL() {{
SELECT("td.user_id as user_id, tu.user_name as user_name, count(0) as count");
FROM(TABLE_NAME + " td");
JOIN("t_escheduler_user tu on tu.id=td.user_id");
if(parameter.get("projectId") != null && (int)parameter.get("projectId") != 0){
WHERE( "td.project_id = #{projectId} ");
}else{
if(parameter.get("userType") != null && String.valueOf(parameter.get("userType")) == "GENERAL_USER") {
AND();
WHERE("td.project_id in (select id as project_id from t_escheduler_project tp where tp.user_id= #{userId} " +
"union select project_id from t_escheduler_relation_project_user tr where tr.user_id= #{userId} )");
}
}
GROUP_BY("td.user_id");
}}.toString();
}
/**
* query definition list by define id list
* @param parameter
* @return
*/
public String queryDefinitionListByIdList(Map<String, Object> parameter){
List<String> ids = (List<String>) parameter.get("ids");
return new SQL() {{
SELECT("*");
FROM(TABLE_NAME);
WHERE("`id` in (" + String.join(",", ids) + ")");
}}.toString();
}
/**
* update receivers and cc by definition id
*
* @param parameter
* @return
*/
public String updateReceiversAndCcById(Map<String, Object> parameter) {
return new SQL() {
{
UPDATE(TABLE_NAME);
SET("`receivers`=#{receivers}");
SET("`receivers_cc`=#{receiversCc}");
WHERE("`id`=#{processDefinitionId}");
}
}.toString();
}
}
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package cn.escheduler.dao.mapper;
import cn.escheduler.dao.model.ProcessInstanceMap;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;
/**
* work process instance map mapper
*/
public interface ProcessInstanceMapMapper {
/**
* insert process instance relation
* @param processInstanceMap
* @return
*/
@InsertProvider(type = ProcessInstanceMapMapperProvider.class, method = "insert")
@Options(useGeneratedKeys = true,keyProperty = "processInstanceMap.id")
@SelectKey(statement = "SELECT LAST_INSERT_ID()", keyProperty = "processInstanceMap.id", before = false, resultType = int.class)
int insert(@Param("processInstanceMap") ProcessInstanceMap processInstanceMap);
/**
* delete process instance relation by id
* @param processInstanceMapId
* @return
*/
@DeleteProvider(type = ProcessInstanceMapMapperProvider.class, method = "delete")
int delete(@Param("processInstanceMapId") int processInstanceMapId);
/**
* delete process instance relation by parent work process id
* @param parentProcessId
* @return
*/
@DeleteProvider(type = ProcessInstanceMapMapperProvider.class, method = "deleteByParentProcessId")
int deleteByParentProcessId(@Param("parentProcessId") int parentProcessId);
/**
* update process instance relation
*
* @param processInstanceMap
* @return
*/
@UpdateProvider(type = ProcessInstanceMapMapperProvider.class, method = "update")
int update(@Param("processInstanceMap") ProcessInstanceMap processInstanceMap);
/**
* query process instance relation by id
* @param processMapId
* @return
*/
@Results(value = {@Result(property = "id", column = "id", id = true, javaType = Integer.class, jdbcType = JdbcType.INTEGER),
@Result(property = "parentProcessInstanceId", column = "parent_process_instance_id", javaType = Integer.class, jdbcType = JdbcType.INTEGER),
@Result(property = "parentTaskInstanceId", column = "parent_task_instance_id", javaType = Integer.class, jdbcType = JdbcType.INTEGER),
@Result(property = "processInstanceId", column = "process_instance_id", javaType = Integer.class, jdbcType = JdbcType.INTEGER)
})
@SelectProvider(type = ProcessInstanceMapMapperProvider.class, method = "queryById")
ProcessInstanceMap queryById(@Param("processMapId") int processMapId);
/**
* query by parent instance id
* @param parentProcessId
* @param parentTaskId
* @return
*/
@Results(value = {@Result(property = "id", column = "id", id = true, javaType = Integer.class, jdbcType = JdbcType.INTEGER),
@Result(property = "parentProcessInstanceId", column = "parent_process_instance_id", javaType = Integer.class, jdbcType = JdbcType.INTEGER),
@Result(property = "parentTaskInstanceId", column = "parent_task_instance_id", javaType = Integer.class, jdbcType = JdbcType.INTEGER),
@Result(property = "processInstanceId", column = "process_instance_id", javaType = Integer.class, jdbcType = JdbcType.INTEGER)
})
@SelectProvider(type = ProcessInstanceMapMapperProvider.class, method = "queryByParentId")
ProcessInstanceMap queryByParentId(@Param("parentProcessId") int parentProcessId, @Param("parentTaskId") int parentTaskId);
/**
* query relation by sub process id
* @param subProcessId
* @return
*/
@Results(value = {@Result(property = "id", column = "id", id = true, javaType = Integer.class, jdbcType = JdbcType.INTEGER),
@Result(property = "parentProcessInstanceId", column = "parent_process_instance_id", javaType = Integer.class, jdbcType = JdbcType.INTEGER),
@Result(property = "parentTaskInstanceId", column = "parent_task_instance_id", javaType = Integer.class, jdbcType = JdbcType.INTEGER),
@Result(property = "processInstanceId", column = "process_instance_id", javaType = Integer.class, jdbcType = JdbcType.INTEGER)
})
@SelectProvider(type = ProcessInstanceMapMapperProvider.class, method = "queryBySubProcessId")
ProcessInstanceMap queryBySubProcessId(@Param("subProcessId")Integer subProcessId);
}
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package cn.escheduler.dao.mapper;
import org.apache.ibatis.jdbc.SQL;
import java.util.Map;
/**
* process instance map mapper provider
*/
public class ProcessInstanceMapMapperProvider {
private static final String TABLE_NAME = "t_escheduler_relation_process_instance";
/**
* insert process instance relation
*
* @param parameter
* @return
*/
public String insert(Map<String, Object> parameter) {
return new SQL() {
{
INSERT_INTO(TABLE_NAME);
VALUES("`parent_process_instance_id`", "#{processInstanceMap.parentProcessInstanceId}");
VALUES("`parent_task_instance_id`", "#{processInstanceMap.parentTaskInstanceId}");
VALUES("`process_instance_id`", "#{processInstanceMap.processInstanceId}");
}
}.toString();
}
/**
* delete process instance relation
*
* @param parameter
* @return
*/
public String delete(Map<String, Object> parameter) {
return new SQL() {
{
DELETE_FROM(TABLE_NAME);
WHERE("`id`=#{processInstanceMapId}");
}
}.toString();
}
/**
* delete by parent process id
*
* @param parameter
* @return
*/
public String deleteByParentProcessId(Map<String, Object> parameter) {
return new SQL() {
{
DELETE_FROM(TABLE_NAME);
WHERE("`parent_process_instance_id`=#{parentProcessId}");
}
}.toString();
}
/**
* update process map
* @param parameter
* @return
*/
public String update(Map<String, Object> parameter) {
return new SQL() {
{
UPDATE(TABLE_NAME);
SET("`parent_process_instance_id`=#{processInstanceMap.parentProcessInstanceId}");
SET("`parent_task_instance_id`=#{processInstanceMap.parentTaskInstanceId}");
SET("`process_instance_id`=#{processInstanceMap.processInstanceId}");
WHERE("`id`=#{processInstanceMap.id}");
}
}.toString();
}
/**
* query by map id
*
* @param parameter
* @return
*/
public String queryById(Map<String, Object> parameter) {
return new SQL() {
{
SELECT("*");
FROM(TABLE_NAME);
WHERE("`id` = #{processMapId}");
}
}.toString();
}
/**
* query by parent process instance id and parent task id
*
* @param parameter
* @return
*/
public String queryByParentId(Map<String, Object> parameter) {
return new SQL() {
{
SELECT("*");
FROM(TABLE_NAME);
WHERE("`parent_process_instance_id` = #{parentProcessId}");
WHERE("`parent_task_instance_id` = #{parentTaskId}");
}
}.toString();
}
/**
* query by sub process instance id
*
* @param parameter
* @return
*/
public String queryBySubProcessId(Map<String, Object> parameter) {
return new SQL() {
{
SELECT("*");
FROM(TABLE_NAME);
WHERE("`process_instance_id` = #{subProcessId}");
}
}.toString();
}
}
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package cn.escheduler.dao.mapper;
import cn.escheduler.dao.model.ProjectUser;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;
import java.util.Date;
/**
* project user relation mapper
*/
public interface ProjectUserMapper {
/**
* insert project user relation
*
* @param projectUser
* @return
*/
@InsertProvider(type = ProjectUserMapperProvider.class, method = "insert")
int insert(@Param("projectUser") ProjectUser projectUser);
/**
* delete project user relation
* @param projectId
* @param userId
* @return
*/
@DeleteProvider(type = ProjectUserMapperProvider.class, method = "delete")
int delete(@Param("projectId") int projectId, @Param("userId") int userId);
/**
* update project user relation
*
* @param projectUser
* @return
*/
@UpdateProvider(type = ProjectUserMapperProvider.class, method = "update")
int update(@Param("projectUser") ProjectUser projectUser);
/**
* query project user relation by project id and user id
*
* @param projectId
* @param userId
* @return
*/
@Results(value = {@Result(property = "projectId", column = "project_id", javaType = int.class, jdbcType = JdbcType.INTEGER),
@Result(property = "projectName", column = "project_name", javaType = String.class, jdbcType = JdbcType.VARCHAR),
@Result(property = "userId", column = "user_id", javaType = int.class, jdbcType = JdbcType.INTEGER),
@Result(property = "userName", column = "user_name", javaType = String.class, jdbcType = JdbcType.VARCHAR),
@Result(property = "perm", column = "perm", javaType = Integer.class, jdbcType = JdbcType.INTEGER),
@Result(property = "createTime", column = "create_time", javaType = Date.class, jdbcType = JdbcType.TIMESTAMP),
@Result(property = "updateTime", column = "update_time", javaType = Date.class, jdbcType = JdbcType.TIMESTAMP)})
@SelectProvider(type = ProjectUserMapperProvider.class, method = "query")
ProjectUser query(@Param("projectId") int projectId, @Param("userId") int userId);
/**
* delete project relation by user id
* @param userId
* @return
*/
@DeleteProvider(type = ProjectUserMapperProvider.class, method = "deleteByUserId")
int deleteByUserId(@Param("userId") int userId);
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册